From db20f3f1bb8595633a7e16c8900fd401a453a6b5 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 27 Dec 2016 16:46:08 +0900 Subject: Imported Upstream version 1.0.0.9127 --- src/pal/tests/CMakeLists.txt | 15 +- src/pal/tests/palsuite/c_runtime/CMakeLists.txt | 35 +- .../c_runtime/__iscsym/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/__iscsym/test1/__iscsym.c | 93 --- .../palsuite/c_runtime/__iscsym/test1/__iscsym.cpp | 93 +++ .../c_runtime/_alloca/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_alloca/test1/test1.c | 62 -- .../palsuite/c_runtime/_alloca/test1/test1.cpp | 62 ++ .../palsuite/c_runtime/_ecvt/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_ecvt/test1/test1.c | 135 --- .../tests/palsuite/c_runtime/_ecvt/test1/test1.cpp | 135 +++ .../c_runtime/_fdopen/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_fdopen/test1/test1.c | 112 --- .../palsuite/c_runtime/_fdopen/test1/test1.cpp | 112 +++ .../c_runtime/_finite/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_finite/test1/test1.c | 119 --- .../palsuite/c_runtime/_finite/test1/test1.cpp | 119 +++ .../palsuite/c_runtime/_finitef/CMakeLists.txt | 3 + .../c_runtime/_finitef/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/_finitef/test1/test1.c | 119 +++ .../palsuite/c_runtime/_finitef/test1/testinfo.dat | 13 + .../c_runtime/_fullpath/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_fullpath/test1/test1.c | 181 ---- .../palsuite/c_runtime/_fullpath/test1/test1.cpp | 181 ++++ .../palsuite/c_runtime/_gcvt/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c | 58 -- .../tests/palsuite/c_runtime/_gcvt/test1/_gcvt.cpp | 58 ++ .../palsuite/c_runtime/_gcvt/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_gcvt/test2/test2.c | 83 -- .../tests/palsuite/c_runtime/_gcvt/test2/test2.cpp | 83 ++ .../palsuite/c_runtime/_getw/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_getw/test1/test1.c | 96 --- .../tests/palsuite/c_runtime/_getw/test1/test1.cpp | 96 +++ .../palsuite/c_runtime/_isnan/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_isnan/test1/test1.c | 115 --- .../palsuite/c_runtime/_isnan/test1/test1.cpp | 115 +++ .../palsuite/c_runtime/_isnanf/CMakeLists.txt | 3 + .../c_runtime/_isnanf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/_isnanf/test1/test1.c | 115 +++ .../palsuite/c_runtime/_isnanf/test1/testinfo.dat | 16 + .../palsuite/c_runtime/_itow/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_itow/test1/test1.c | 102 --- .../tests/palsuite/c_runtime/_itow/test1/test1.cpp | 101 +++ .../palsuite/c_runtime/_itow/test1/testinfo.dat | 6 +- .../palsuite/c_runtime/_makepath/CMakeLists.txt | 4 - .../c_runtime/_makepath/test1/CMakeLists.txt | 19 - .../palsuite/c_runtime/_makepath/test1/test1.c | 65 -- .../c_runtime/_makepath/test1/testinfo.dat | 14 - .../c_runtime/_mbsdec/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_mbsdec/test1/test1.c | 77 -- .../palsuite/c_runtime/_mbsdec/test1/test1.cpp | 77 ++ .../c_runtime/_mbsinc/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_mbsinc/test1/test1.c | 62 -- .../palsuite/c_runtime/_mbsinc/test1/test1.cpp | 62 ++ .../palsuite/c_runtime/_mbslen/CMakeLists.txt | 4 - .../c_runtime/_mbslen/test1/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/_mbslen/test1/test1.c | 66 -- .../palsuite/c_runtime/_mbslen/test1/testinfo.dat | 15 - .../c_runtime/_mbsninc/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_mbsninc/test1/test1.c | 65 -- .../palsuite/c_runtime/_mbsninc/test1/test1.cpp | 65 ++ .../c_runtime/_open_osfhandle/test1/CMakeLists.txt | 2 +- .../c_runtime/_open_osfhandle/test1/test1.c | 132 --- .../c_runtime/_open_osfhandle/test1/test1.cpp | 132 +++ .../c_runtime/_open_osfhandle/test2/CMakeLists.txt | 2 +- .../c_runtime/_open_osfhandle/test2/test2.c | 86 -- .../c_runtime/_open_osfhandle/test2/test2.cpp | 86 ++ .../c_runtime/_putenv/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_putenv/test1/test1.c | 99 --- .../palsuite/c_runtime/_putenv/test1/test1.cpp | 99 +++ .../c_runtime/_putenv/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_putenv/test2/test2.c | 76 -- .../palsuite/c_runtime/_putenv/test2/test2.cpp | 76 ++ .../c_runtime/_putenv/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_putenv/test3/test3.c | 102 --- .../palsuite/c_runtime/_putenv/test3/test3.cpp | 102 +++ .../c_runtime/_putenv/test4/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_putenv/test4/test4.c | 75 -- .../palsuite/c_runtime/_putenv/test4/test4.cpp | 75 ++ .../palsuite/c_runtime/_putw/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_putw/test1/test1.c | 112 --- .../tests/palsuite/c_runtime/_putw/test1/test1.cpp | 112 +++ .../palsuite/c_runtime/_snprintf/CMakeLists.txt | 22 - .../tests/palsuite/c_runtime/_snprintf/_snprintf.h | 194 ----- .../c_runtime/_snprintf/test1/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test1/test1.c | 58 -- .../c_runtime/_snprintf/test1/testinfo.dat | 12 - .../c_runtime/_snprintf/test10/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test10/test10.c | 55 -- .../c_runtime/_snprintf/test10/testinfo.dat | 12 - .../c_runtime/_snprintf/test11/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test11/test11.c | 54 -- .../c_runtime/_snprintf/test11/testinfo.dat | 12 - .../c_runtime/_snprintf/test12/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test12/test12.c | 55 -- .../c_runtime/_snprintf/test12/testinfo.dat | 12 - .../c_runtime/_snprintf/test13/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test13/test13.c | 55 -- .../c_runtime/_snprintf/test13/testinfo.dat | 12 - .../c_runtime/_snprintf/test14/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test14/test14.c | 57 -- .../c_runtime/_snprintf/test14/testinfo.dat | 12 - .../c_runtime/_snprintf/test15/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test15/test15.c | 56 -- .../c_runtime/_snprintf/test15/testinfo.dat | 12 - .../c_runtime/_snprintf/test16/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test16/test16.c | 52 -- .../c_runtime/_snprintf/test16/testinfo.dat | 12 - .../c_runtime/_snprintf/test17/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test17/test17.c | 53 -- .../c_runtime/_snprintf/test17/testinfo.dat | 12 - .../c_runtime/_snprintf/test18/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test18/test18.c | 53 -- .../c_runtime/_snprintf/test18/testinfo.dat | 12 - .../c_runtime/_snprintf/test19/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test19/test19.c | 76 -- .../c_runtime/_snprintf/test19/testinfo.dat | 12 - .../c_runtime/_snprintf/test2/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test2/test2.c | 44 - .../c_runtime/_snprintf/test2/testinfo.dat | 12 - .../c_runtime/_snprintf/test3/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test3/test3.c | 45 - .../c_runtime/_snprintf/test3/testinfo.dat | 12 - .../c_runtime/_snprintf/test4/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test4/test4.c | 69 -- .../c_runtime/_snprintf/test4/testinfo.dat | 12 - .../c_runtime/_snprintf/test5/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test5/test5.c | 61 -- .../c_runtime/_snprintf/test5/testinfo.dat | 12 - .../c_runtime/_snprintf/test6/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test6/test6.c | 47 -- .../c_runtime/_snprintf/test6/testinfo.dat | 12 - .../c_runtime/_snprintf/test7/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test7/test7.c | 47 -- .../c_runtime/_snprintf/test7/testinfo.dat | 12 - .../c_runtime/_snprintf/test8/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test8/test8.c | 56 -- .../c_runtime/_snprintf/test8/testinfo.dat | 12 - .../c_runtime/_snprintf/test9/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snprintf/test9/test9.c | 55 -- .../c_runtime/_snprintf/test9/testinfo.dat | 12 - .../palsuite/c_runtime/_snprintf_s/CMakeLists.txt | 21 + .../palsuite/c_runtime/_snprintf_s/_snprintf_s.h | 194 +++++ .../c_runtime/_snprintf_s/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/_snprintf_s/test1/test1.cpp | 58 ++ .../c_runtime/_snprintf_s/test1/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test10/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test10/test10.cpp | 55 ++ .../c_runtime/_snprintf_s/test10/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test11/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test11/test11.cpp | 54 ++ .../c_runtime/_snprintf_s/test11/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test12/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test12/test12.cpp | 55 ++ .../c_runtime/_snprintf_s/test12/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test13/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test13/test13.cpp | 55 ++ .../c_runtime/_snprintf_s/test13/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test14/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test14/test14.cpp | 57 ++ .../c_runtime/_snprintf_s/test14/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test15/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test15/test15.cpp | 56 ++ .../c_runtime/_snprintf_s/test15/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test16/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test16/test16.cpp | 52 ++ .../c_runtime/_snprintf_s/test16/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test17/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test17/test17.cpp | 53 ++ .../c_runtime/_snprintf_s/test17/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test18/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test18/test18.cpp | 53 ++ .../c_runtime/_snprintf_s/test18/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test19/CMakeLists.txt | 19 + .../c_runtime/_snprintf_s/test19/test19.cpp | 70 ++ .../c_runtime/_snprintf_s/test19/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test2/CMakeLists.txt | 19 + .../palsuite/c_runtime/_snprintf_s/test2/test2.cpp | 44 + .../c_runtime/_snprintf_s/test2/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test3/CMakeLists.txt | 19 + .../palsuite/c_runtime/_snprintf_s/test3/test3.cpp | 45 + .../c_runtime/_snprintf_s/test3/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test4/CMakeLists.txt | 19 + .../palsuite/c_runtime/_snprintf_s/test4/test4.cpp | 69 ++ .../c_runtime/_snprintf_s/test4/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test6/CMakeLists.txt | 19 + .../palsuite/c_runtime/_snprintf_s/test6/test6.cpp | 47 ++ .../c_runtime/_snprintf_s/test6/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test7/CMakeLists.txt | 19 + .../palsuite/c_runtime/_snprintf_s/test7/test7.cpp | 47 ++ .../c_runtime/_snprintf_s/test7/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test8/CMakeLists.txt | 19 + .../palsuite/c_runtime/_snprintf_s/test8/test8.cpp | 56 ++ .../c_runtime/_snprintf_s/test8/testinfo.dat | 12 + .../c_runtime/_snprintf_s/test9/CMakeLists.txt | 19 + .../palsuite/c_runtime/_snprintf_s/test9/test9.cpp | 55 ++ .../c_runtime/_snprintf_s/test9/testinfo.dat | 12 + .../palsuite/c_runtime/_snwprintf/CMakeLists.txt | 22 - .../palsuite/c_runtime/_snwprintf/_snwprintf.h | 199 ----- .../c_runtime/_snwprintf/test1/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test1/test1.c | 62 -- .../c_runtime/_snwprintf/test1/testinfo.dat | 12 - .../c_runtime/_snwprintf/test10/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test10/test10.c | 54 -- .../c_runtime/_snwprintf/test10/testinfo.dat | 12 - .../c_runtime/_snwprintf/test11/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test11/test11.c | 54 -- .../c_runtime/_snwprintf/test11/testinfo.dat | 12 - .../c_runtime/_snwprintf/test12/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test12/test12.c | 54 -- .../c_runtime/_snwprintf/test12/testinfo.dat | 12 - .../c_runtime/_snwprintf/test13/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test13/test13.c | 54 -- .../c_runtime/_snwprintf/test13/testinfo.dat | 12 - .../c_runtime/_snwprintf/test14/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test14/test14.c | 66 -- .../c_runtime/_snwprintf/test14/testinfo.dat | 12 - .../c_runtime/_snwprintf/test15/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test15/test15.c | 67 -- .../c_runtime/_snwprintf/test15/testinfo.dat | 12 - .../c_runtime/_snwprintf/test16/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test16/test16.c | 65 -- .../c_runtime/_snwprintf/test16/testinfo.dat | 12 - .../c_runtime/_snwprintf/test17/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test17/test17.c | 68 -- .../c_runtime/_snwprintf/test17/testinfo.dat | 12 - .../c_runtime/_snwprintf/test18/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test18/test18.c | 69 -- .../c_runtime/_snwprintf/test18/testinfo.dat | 12 - .../c_runtime/_snwprintf/test19/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test19/test19.c | 90 -- .../c_runtime/_snwprintf/test19/testinfo.dat | 12 - .../c_runtime/_snwprintf/test2/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test2/test2.c | 44 - .../c_runtime/_snwprintf/test2/testinfo.dat | 12 - .../c_runtime/_snwprintf/test3/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test3/test3.c | 44 - .../c_runtime/_snwprintf/test3/testinfo.dat | 12 - .../c_runtime/_snwprintf/test4/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test4/test4.c | 71 -- .../c_runtime/_snwprintf/test4/testinfo.dat | 12 - .../c_runtime/_snwprintf/test5/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test5/test5.c | 63 -- .../c_runtime/_snwprintf/test5/testinfo.dat | 12 - .../c_runtime/_snwprintf/test6/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test6/test6.c | 46 -- .../c_runtime/_snwprintf/test6/testinfo.dat | 12 - .../c_runtime/_snwprintf/test7/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test7/test7.c | 46 -- .../c_runtime/_snwprintf/test7/testinfo.dat | 12 - .../c_runtime/_snwprintf/test8/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test8/test8.c | 53 -- .../c_runtime/_snwprintf/test8/testinfo.dat | 12 - .../c_runtime/_snwprintf/test9/CMakeLists.txt | 19 - .../palsuite/c_runtime/_snwprintf/test9/test9.c | 53 -- .../c_runtime/_snwprintf/test9/testinfo.dat | 12 - .../palsuite/c_runtime/_snwprintf_s/CMakeLists.txt | 21 + .../palsuite/c_runtime/_snwprintf_s/_snwprintf_s.h | 199 +++++ .../c_runtime/_snwprintf_s/test1/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test1/test1.cpp | 62 ++ .../c_runtime/_snwprintf_s/test1/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test10/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test10/test10.cpp | 54 ++ .../c_runtime/_snwprintf_s/test10/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test11/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test11/test11.cpp | 54 ++ .../c_runtime/_snwprintf_s/test11/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test12/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test12/test12.cpp | 54 ++ .../c_runtime/_snwprintf_s/test12/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test13/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test13/test13.cpp | 54 ++ .../c_runtime/_snwprintf_s/test13/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test14/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test14/test14.cpp | 66 ++ .../c_runtime/_snwprintf_s/test14/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test15/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test15/test15.cpp | 67 ++ .../c_runtime/_snwprintf_s/test15/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test16/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test16/test16.cpp | 65 ++ .../c_runtime/_snwprintf_s/test16/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test17/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test17/test17.cpp | 68 ++ .../c_runtime/_snwprintf_s/test17/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test18/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test18/test18.cpp | 69 ++ .../c_runtime/_snwprintf_s/test18/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test19/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test19/test19.cpp | 82 ++ .../c_runtime/_snwprintf_s/test19/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test2/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test2/test2.cpp | 44 + .../c_runtime/_snwprintf_s/test2/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test3/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test3/test3.cpp | 44 + .../c_runtime/_snwprintf_s/test3/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test4/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test4/test4.cpp | 71 ++ .../c_runtime/_snwprintf_s/test4/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test6/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test6/test6.cpp | 46 ++ .../c_runtime/_snwprintf_s/test6/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test7/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test7/test7.cpp | 46 ++ .../c_runtime/_snwprintf_s/test7/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test8/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test8/test8.cpp | 53 ++ .../c_runtime/_snwprintf_s/test8/testinfo.dat | 12 + .../c_runtime/_snwprintf_s/test9/CMakeLists.txt | 19 + .../c_runtime/_snwprintf_s/test9/test9.cpp | 53 ++ .../c_runtime/_snwprintf_s/test9/testinfo.dat | 12 + .../palsuite/c_runtime/_splitpath/CMakeLists.txt | 4 - .../c_runtime/_splitpath/test1/CMakeLists.txt | 19 - .../palsuite/c_runtime/_splitpath/test1/test1.c | 108 --- .../c_runtime/_splitpath/test1/testinfo.dat | 15 - .../c_runtime/_stricmp/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_stricmp/test1/test1.c | 70 -- .../palsuite/c_runtime/_stricmp/test1/test1.cpp | 70 ++ .../c_runtime/_strlwr/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_strlwr/test1/test1.c | 42 - .../palsuite/c_runtime/_strlwr/test1/test1.cpp | 42 + .../c_runtime/_strnicmp/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_strnicmp/test1/test1.c | 85 -- .../palsuite/c_runtime/_strnicmp/test1/test1.cpp | 85 ++ .../tests/palsuite/c_runtime/_swab/CMakeLists.txt | 4 - .../palsuite/c_runtime/_swab/test1/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/_swab/test1/test1.c | 45 - .../palsuite/c_runtime/_swab/test1/testinfo.dat | 14 - .../palsuite/c_runtime/_vsnprintf/_vsnprintf.h | 14 +- .../c_runtime/_vsnprintf/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test1/test1.c | 55 -- .../palsuite/c_runtime/_vsnprintf/test1/test1.cpp | 55 ++ .../c_runtime/_vsnprintf/test1/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test10/test10.c | 50 -- .../c_runtime/_vsnprintf/test10/test10.cpp | 50 ++ .../c_runtime/_vsnprintf/test10/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test11/test11.c | 50 -- .../c_runtime/_vsnprintf/test11/test11.cpp | 50 ++ .../c_runtime/_vsnprintf/test11/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test12/test12.c | 52 -- .../c_runtime/_vsnprintf/test12/test12.cpp | 52 ++ .../c_runtime/_vsnprintf/test12/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test13/test13.c | 52 -- .../c_runtime/_vsnprintf/test13/test13.cpp | 52 ++ .../c_runtime/_vsnprintf/test13/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test14/test14.c | 50 -- .../c_runtime/_vsnprintf/test14/test14.cpp | 50 ++ .../c_runtime/_vsnprintf/test14/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test15/test15.c | 49 -- .../c_runtime/_vsnprintf/test15/test15.cpp | 49 ++ .../c_runtime/_vsnprintf/test15/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test16/test16.c | 49 -- .../c_runtime/_vsnprintf/test16/test16.cpp | 49 ++ .../c_runtime/_vsnprintf/test16/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test17/test17.c | 50 -- .../c_runtime/_vsnprintf/test17/test17.cpp | 50 ++ .../c_runtime/_vsnprintf/test17/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test18/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test18/test18.c | 50 -- .../c_runtime/_vsnprintf/test18/test18.cpp | 50 ++ .../c_runtime/_vsnprintf/test18/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test19/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test19/test19.c | 103 --- .../c_runtime/_vsnprintf/test19/test19.cpp | 103 +++ .../c_runtime/_vsnprintf/test19/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test2/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test2/test2.c | 44 - .../palsuite/c_runtime/_vsnprintf/test2/test2.cpp | 44 + .../c_runtime/_vsnprintf/test2/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test3/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test3/test3.c | 43 - .../palsuite/c_runtime/_vsnprintf/test3/test3.cpp | 43 + .../c_runtime/_vsnprintf/test3/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test4/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test4/test4.c | 98 --- .../palsuite/c_runtime/_vsnprintf/test4/test4.cpp | 98 +++ .../c_runtime/_vsnprintf/test4/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test5/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test5/test5.c | 78 -- .../palsuite/c_runtime/_vsnprintf/test5/test5.cpp | 78 ++ .../c_runtime/_vsnprintf/test5/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test6/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test6/test6.c | 44 - .../palsuite/c_runtime/_vsnprintf/test6/test6.cpp | 44 + .../c_runtime/_vsnprintf/test6/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test7/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test7/test7.c | 44 - .../palsuite/c_runtime/_vsnprintf/test7/test7.cpp | 44 + .../c_runtime/_vsnprintf/test7/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test8/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test8/test8.c | 52 -- .../palsuite/c_runtime/_vsnprintf/test8/test8.cpp | 52 ++ .../c_runtime/_vsnprintf/test8/testinfo.dat | 2 +- .../c_runtime/_vsnprintf/test9/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_vsnprintf/test9/test9.c | 51 -- .../palsuite/c_runtime/_vsnprintf/test9/test9.cpp | 51 ++ .../c_runtime/_vsnprintf/test9/testinfo.dat | 2 +- .../palsuite/c_runtime/_vsnwprintf/CMakeLists.txt | 22 - .../palsuite/c_runtime/_vsnwprintf/_vsnwprintf.h | 133 --- .../c_runtime/_vsnwprintf/test1/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test1/test1.c | 60 -- .../c_runtime/_vsnwprintf/test1/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test10/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test10/test10.c | 50 -- .../c_runtime/_vsnwprintf/test10/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test11/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test11/test11.c | 50 -- .../c_runtime/_vsnwprintf/test11/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test12/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test12/test12.c | 50 -- .../c_runtime/_vsnwprintf/test12/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test13/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test13/test13.c | 50 -- .../c_runtime/_vsnwprintf/test13/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test14/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test14/test14.c | 63 -- .../c_runtime/_vsnwprintf/test14/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test15/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test15/test15.c | 64 -- .../c_runtime/_vsnwprintf/test15/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test16/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test16/test16.c | 63 -- .../c_runtime/_vsnwprintf/test16/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test17/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test17/test17.c | 65 -- .../c_runtime/_vsnwprintf/test17/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test18/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test18/test18.c | 65 -- .../c_runtime/_vsnwprintf/test18/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test19/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test19/test19.c | 139 ---- .../c_runtime/_vsnwprintf/test19/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test2/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test2/test2.c | 40 - .../c_runtime/_vsnwprintf/test2/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test3/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test3/test3.c | 40 - .../c_runtime/_vsnwprintf/test3/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test4/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test4/test4.c | 121 --- .../c_runtime/_vsnwprintf/test4/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test5/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test5/test5.c | 81 -- .../c_runtime/_vsnwprintf/test5/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test6/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test6/test6.c | 43 - .../c_runtime/_vsnwprintf/test6/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test7/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test7/test7.c | 43 - .../c_runtime/_vsnwprintf/test7/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test8/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test8/test8.c | 49 -- .../c_runtime/_vsnwprintf/test8/testinfo.dat | 14 - .../c_runtime/_vsnwprintf/test9/CMakeLists.txt | 19 - .../palsuite/c_runtime/_vsnwprintf/test9/test9.c | 49 -- .../c_runtime/_vsnwprintf/test9/testinfo.dat | 14 - .../c_runtime/_vsnwprintf_s/CMakeLists.txt | 21 + .../c_runtime/_vsnwprintf_s/_vsnwprintf_s.h | 133 +++ .../c_runtime/_vsnwprintf_s/test1/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test1/test1.cpp | 60 ++ .../c_runtime/_vsnwprintf_s/test1/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test10/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test10/test10.cpp | 50 ++ .../c_runtime/_vsnwprintf_s/test10/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test11/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test11/test11.cpp | 50 ++ .../c_runtime/_vsnwprintf_s/test11/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test12/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test12/test12.cpp | 50 ++ .../c_runtime/_vsnwprintf_s/test12/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test13/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test13/test13.cpp | 50 ++ .../c_runtime/_vsnwprintf_s/test13/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test14/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test14/test14.cpp | 63 ++ .../c_runtime/_vsnwprintf_s/test14/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test15/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test15/test15.cpp | 64 ++ .../c_runtime/_vsnwprintf_s/test15/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test16/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test16/test16.cpp | 63 ++ .../c_runtime/_vsnwprintf_s/test16/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test17/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test17/test17.cpp | 65 ++ .../c_runtime/_vsnwprintf_s/test17/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test18/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test18/test18.cpp | 65 ++ .../c_runtime/_vsnwprintf_s/test18/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test19/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test19/test19.cpp | 139 ++++ .../c_runtime/_vsnwprintf_s/test19/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test2/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test2/test2.cpp | 40 + .../c_runtime/_vsnwprintf_s/test2/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test3/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test3/test3.cpp | 40 + .../c_runtime/_vsnwprintf_s/test3/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test4/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test4/test4.cpp | 121 +++ .../c_runtime/_vsnwprintf_s/test4/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test6/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test6/test6.cpp | 43 + .../c_runtime/_vsnwprintf_s/test6/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test7/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test7/test7.cpp | 43 + .../c_runtime/_vsnwprintf_s/test7/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test8/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test8/test8.cpp | 49 ++ .../c_runtime/_vsnwprintf_s/test8/testinfo.dat | 14 + .../c_runtime/_vsnwprintf_s/test9/CMakeLists.txt | 19 + .../c_runtime/_vsnwprintf_s/test9/test9.cpp | 49 ++ .../c_runtime/_vsnwprintf_s/test9/testinfo.dat | 14 + .../c_runtime/_wcsicmp/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_wcsicmp/test1/test1.c | 68 -- .../palsuite/c_runtime/_wcsicmp/test1/test1.cpp | 68 ++ .../c_runtime/_wcslwr/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_wcslwr/test1/test1.c | 50 -- .../palsuite/c_runtime/_wcslwr/test1/test1.cpp | 50 ++ .../c_runtime/_wcsnicmp/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/_wcsnicmp/test1/test1.c | 95 --- .../palsuite/c_runtime/_wcsnicmp/test1/test1.cpp | 95 +++ .../c_runtime/_wfopen/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_wfopen/test1/test1.c | 79 -- .../palsuite/c_runtime/_wfopen/test1/test1.cpp | 79 ++ .../c_runtime/_wfopen/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_wfopen/test2/test2.c | 68 -- .../palsuite/c_runtime/_wfopen/test2/test2.cpp | 68 ++ .../c_runtime/_wfopen/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_wfopen/test3/test3.c | 70 -- .../palsuite/c_runtime/_wfopen/test3/test3.cpp | 70 ++ .../c_runtime/_wfopen/test4/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_wfopen/test4/test4.c | 87 -- .../palsuite/c_runtime/_wfopen/test4/test4.cpp | 87 ++ .../c_runtime/_wfopen/test5/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_wfopen/test5/test5.c | 82 -- .../palsuite/c_runtime/_wfopen/test5/test5.cpp | 82 ++ .../c_runtime/_wfopen/test6/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_wfopen/test6/test6.c | 152 ---- .../palsuite/c_runtime/_wfopen/test6/test6.cpp | 152 ++++ .../c_runtime/_wfopen/test7/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_wfopen/test7/test7.c | 119 --- .../palsuite/c_runtime/_wfopen/test7/test7.cpp | 119 +++ .../palsuite/c_runtime/_wmakepath/CMakeLists.txt | 4 - .../c_runtime/_wmakepath/test1/CMakeLists.txt | 19 - .../palsuite/c_runtime/_wmakepath/test1/test1.c | 76 -- .../c_runtime/_wmakepath/test1/testinfo.dat | 13 - .../palsuite/c_runtime/_wsplitpath/CMakeLists.txt | 4 - .../c_runtime/_wsplitpath/test1/CMakeLists.txt | 19 - .../palsuite/c_runtime/_wsplitpath/test1/test1.c | 151 ---- .../c_runtime/_wsplitpath/test1/testinfo.dat | 15 - .../palsuite/c_runtime/_wtoi/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/_wtoi/test1/test1.c | 79 -- .../tests/palsuite/c_runtime/_wtoi/test1/test1.cpp | 79 ++ .../palsuite/c_runtime/abs/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/c_runtime/abs/test1/abs.c | 54 -- src/pal/tests/palsuite/c_runtime/abs/test1/abs.cpp | 54 ++ .../palsuite/c_runtime/acos/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/acos/test1/test1.c | 130 --- .../tests/palsuite/c_runtime/acos/test1/test1.cpp | 130 +++ .../tests/palsuite/c_runtime/acosf/CMakeLists.txt | 3 + .../palsuite/c_runtime/acosf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/acosf/test1/test1.c | 129 +++ .../palsuite/c_runtime/acosf/test1/testinfo.dat | 14 + .../palsuite/c_runtime/asin/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/asin/test1/test1.c | 146 ---- .../tests/palsuite/c_runtime/asin/test1/test1.cpp | 146 ++++ .../tests/palsuite/c_runtime/asinf/CMakeLists.txt | 3 + .../palsuite/c_runtime/asinf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/asinf/test1/test1.c | 145 ++++ .../palsuite/c_runtime/asinf/test1/testinfo.dat | 14 + .../palsuite/c_runtime/atan/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/atan/test1/test1.c | 128 --- .../tests/palsuite/c_runtime/atan/test1/test1.cpp | 128 +++ .../palsuite/c_runtime/atan2/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/atan2/test1/test1.c | 148 ---- .../tests/palsuite/c_runtime/atan2/test1/test1.cpp | 148 ++++ .../tests/palsuite/c_runtime/atan2f/CMakeLists.txt | 3 + .../palsuite/c_runtime/atan2f/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/atan2f/test1/test1.c | 147 ++++ .../palsuite/c_runtime/atan2f/test1/testinfo.dat | 14 + .../tests/palsuite/c_runtime/atanf/CMakeLists.txt | 3 + .../palsuite/c_runtime/atanf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/atanf/test1/test1.c | 127 +++ .../palsuite/c_runtime/atanf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/atof/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/atof/test1/test1.c | 75 -- .../tests/palsuite/c_runtime/atof/test1/test1.cpp | 75 ++ .../palsuite/c_runtime/atoi/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/atoi/test1/test1.c | 86 -- .../tests/palsuite/c_runtime/atoi/test1/test1.cpp | 86 ++ .../palsuite/c_runtime/atol/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/atol/test1/test1.c | 88 -- .../tests/palsuite/c_runtime/atol/test1/test1.cpp | 88 ++ .../c_runtime/bsearch/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/bsearch/test1/test1.c | 48 -- .../palsuite/c_runtime/bsearch/test1/test1.cpp | 48 ++ .../c_runtime/bsearch/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/bsearch/test2/test2.c | 57 -- .../palsuite/c_runtime/bsearch/test2/test2.cpp | 57 ++ .../palsuite/c_runtime/ceil/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/ceil/test1/test1.c | 132 --- .../tests/palsuite/c_runtime/ceil/test1/test1.cpp | 132 +++ .../tests/palsuite/c_runtime/ceilf/CMakeLists.txt | 3 + .../palsuite/c_runtime/ceilf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/ceilf/test1/test1.c | 131 +++ .../palsuite/c_runtime/ceilf/test1/testinfo.dat | 14 + .../palsuite/c_runtime/cos/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/c_runtime/cos/test1/test1.c | 131 --- .../tests/palsuite/c_runtime/cos/test1/test1.cpp | 131 +++ .../tests/palsuite/c_runtime/cosf/CMakeLists.txt | 3 + .../palsuite/c_runtime/cosf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/cosf/test1/test1.c | 130 +++ .../palsuite/c_runtime/cosf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/cosh/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/cosh/test1/test1.c | 130 --- .../tests/palsuite/c_runtime/cosh/test1/test1.cpp | 130 +++ .../tests/palsuite/c_runtime/coshf/CMakeLists.txt | 3 + .../palsuite/c_runtime/coshf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/coshf/test1/test1.c | 129 +++ .../palsuite/c_runtime/coshf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/ctime/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/ctime/test1/test1.c | 154 ---- .../tests/palsuite/c_runtime/ctime/test1/test1.cpp | 154 ++++ .../palsuite/c_runtime/errno/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/errno/test1/test1.c | 43 - .../tests/palsuite/c_runtime/errno/test1/test1.cpp | 43 + .../palsuite/c_runtime/errno/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/errno/test2/test2.c | 76 -- .../tests/palsuite/c_runtime/errno/test2/test2.cpp | 76 ++ .../palsuite/c_runtime/exit/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/exit/test1/test1.c | 37 - .../tests/palsuite/c_runtime/exit/test1/test1.cpp | 37 + .../palsuite/c_runtime/exit/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/exit/test2/test2.c | 38 - .../tests/palsuite/c_runtime/exit/test2/test2.cpp | 38 + .../palsuite/c_runtime/exp/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/c_runtime/exp/test1/test1.c | 138 ---- .../tests/palsuite/c_runtime/exp/test1/test1.cpp | 138 ++++ .../tests/palsuite/c_runtime/expf/CMakeLists.txt | 3 + .../palsuite/c_runtime/expf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/expf/test1/test1.c | 137 +++ .../palsuite/c_runtime/expf/test1/testinfo.dat | 12 + .../palsuite/c_runtime/fabs/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fabs/test1/test1.c | 130 --- .../tests/palsuite/c_runtime/fabs/test1/test1.cpp | 130 +++ .../palsuite/c_runtime/fabsf/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fabsf/test1/test1.c | 130 --- .../tests/palsuite/c_runtime/fabsf/test1/test1.cpp | 130 +++ .../palsuite/c_runtime/fclose/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fclose/test1/test1.c | 79 -- .../palsuite/c_runtime/fclose/test1/test1.cpp | 79 ++ .../palsuite/c_runtime/fclose/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fclose/test2/test2.c | 77 -- .../palsuite/c_runtime/fclose/test2/test2.cpp | 77 ++ .../palsuite/c_runtime/feof/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/feof/test1/test1.c | 88 -- .../tests/palsuite/c_runtime/feof/test1/test1.cpp | 88 ++ .../palsuite/c_runtime/ferror/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/ferror/test1/test1.c | 74 -- .../palsuite/c_runtime/ferror/test1/test1.cpp | 74 ++ .../palsuite/c_runtime/ferror/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/ferror/test2/test2.c | 69 -- .../palsuite/c_runtime/ferror/test2/test2.cpp | 69 ++ .../palsuite/c_runtime/fflush/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fflush/test1/test1.c | 80 -- .../palsuite/c_runtime/fflush/test1/test1.cpp | 80 ++ .../palsuite/c_runtime/fgets/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fgets/test1/test1.c | 102 --- .../tests/palsuite/c_runtime/fgets/test1/test1.cpp | 102 +++ .../palsuite/c_runtime/fgets/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fgets/test2/test2.c | 97 --- .../tests/palsuite/c_runtime/fgets/test2/test2.cpp | 97 +++ .../palsuite/c_runtime/fgets/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fgets/test3/test3.c | 73 -- .../tests/palsuite/c_runtime/fgets/test3/test3.cpp | 73 ++ .../palsuite/c_runtime/floor/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/floor/test1/test1.c | 132 --- .../tests/palsuite/c_runtime/floor/test1/test1.cpp | 132 +++ .../tests/palsuite/c_runtime/floorf/CMakeLists.txt | 3 + .../palsuite/c_runtime/floorf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/floorf/test1/test1.c | 131 +++ .../palsuite/c_runtime/floorf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/fmod/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fmod/test1/test1.c | 157 ---- .../tests/palsuite/c_runtime/fmod/test1/test1.cpp | 157 ++++ .../palsuite/c_runtime/fmodf/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fmodf/test1/test1.c | 156 ---- .../tests/palsuite/c_runtime/fmodf/test1/test1.cpp | 156 ++++ .../palsuite/c_runtime/fopen/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fopen/test1/test1.c | 82 -- .../tests/palsuite/c_runtime/fopen/test1/test1.cpp | 82 ++ .../palsuite/c_runtime/fopen/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fopen/test2/test2.c | 65 -- .../tests/palsuite/c_runtime/fopen/test2/test2.cpp | 65 ++ .../palsuite/c_runtime/fopen/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fopen/test3/test3.c | 66 -- .../tests/palsuite/c_runtime/fopen/test3/test3.cpp | 66 ++ .../palsuite/c_runtime/fopen/test4/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fopen/test4/test4.c | 82 -- .../tests/palsuite/c_runtime/fopen/test4/test4.cpp | 82 ++ .../palsuite/c_runtime/fopen/test5/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fopen/test5/test5.c | 78 -- .../tests/palsuite/c_runtime/fopen/test5/test5.cpp | 78 ++ .../palsuite/c_runtime/fopen/test6/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fopen/test6/test6.c | 131 --- .../tests/palsuite/c_runtime/fopen/test6/test6.cpp | 131 +++ .../palsuite/c_runtime/fopen/test7/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fopen/test7/test7.c | 117 --- .../tests/palsuite/c_runtime/fopen/test7/test7.cpp | 117 +++ src/pal/tests/palsuite/c_runtime/fprintf/fprintf.h | 14 +- .../c_runtime/fprintf/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fprintf/test1/test1.c | 80 -- .../palsuite/c_runtime/fprintf/test1/test1.cpp | 80 ++ .../c_runtime/fprintf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test10/test10.c | 49 -- .../palsuite/c_runtime/fprintf/test10/test10.cpp | 49 ++ .../c_runtime/fprintf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test11/test11.c | 49 -- .../palsuite/c_runtime/fprintf/test11/test11.cpp | 49 ++ .../c_runtime/fprintf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test12/test12.c | 50 -- .../palsuite/c_runtime/fprintf/test12/test12.cpp | 50 ++ .../c_runtime/fprintf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test13/test13.c | 50 -- .../palsuite/c_runtime/fprintf/test13/test13.cpp | 50 ++ .../c_runtime/fprintf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test14/test14.c | 49 -- .../palsuite/c_runtime/fprintf/test14/test14.cpp | 49 ++ .../c_runtime/fprintf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test15/test15.c | 49 -- .../palsuite/c_runtime/fprintf/test15/test15.cpp | 49 ++ .../c_runtime/fprintf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test16/test16.c | 48 -- .../palsuite/c_runtime/fprintf/test16/test16.cpp | 48 ++ .../c_runtime/fprintf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test17/test17.c | 49 -- .../palsuite/c_runtime/fprintf/test17/test17.cpp | 49 ++ .../c_runtime/fprintf/test18/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test18/test18.c | 49 -- .../palsuite/c_runtime/fprintf/test18/test18.cpp | 49 ++ .../c_runtime/fprintf/test19/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fprintf/test19/test19.c | 153 ---- .../palsuite/c_runtime/fprintf/test19/test19.cpp | 153 ++++ .../c_runtime/fprintf/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fprintf/test2/test2.c | 43 - .../palsuite/c_runtime/fprintf/test2/test2.cpp | 43 + .../c_runtime/fprintf/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fprintf/test3/test3.c | 43 - .../palsuite/c_runtime/fprintf/test3/test3.cpp | 43 + .../c_runtime/fprintf/test4/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fprintf/test4/test4.c | 110 --- .../palsuite/c_runtime/fprintf/test4/test4.cpp | 110 +++ .../c_runtime/fprintf/test5/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fprintf/test5/test5.c | 131 --- .../palsuite/c_runtime/fprintf/test5/test5.cpp | 131 +++ .../c_runtime/fprintf/test6/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fprintf/test6/test6.c | 46 -- .../palsuite/c_runtime/fprintf/test6/test6.cpp | 46 ++ .../c_runtime/fprintf/test7/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fprintf/test7/test7.c | 44 - .../palsuite/c_runtime/fprintf/test7/test7.cpp | 44 + .../c_runtime/fprintf/test8/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fprintf/test8/test8.c | 49 -- .../palsuite/c_runtime/fprintf/test8/test8.cpp | 49 ++ .../c_runtime/fprintf/test9/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fprintf/test9/test9.c | 49 -- .../palsuite/c_runtime/fprintf/test9/test9.cpp | 49 ++ .../palsuite/c_runtime/fputs/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fputs/test1/test1.c | 100 --- .../tests/palsuite/c_runtime/fputs/test1/test1.cpp | 100 +++ .../palsuite/c_runtime/fputs/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fputs/test2/test2.c | 88 -- .../tests/palsuite/c_runtime/fputs/test2/test2.cpp | 88 ++ .../palsuite/c_runtime/fread/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fread/test1/test1.c | 135 --- .../tests/palsuite/c_runtime/fread/test1/test1.cpp | 135 +++ .../palsuite/c_runtime/fread/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fread/test2/test2.c | 143 ---- .../tests/palsuite/c_runtime/fread/test2/test2.cpp | 143 ++++ .../palsuite/c_runtime/fread/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fread/test3/test3.c | 131 --- .../tests/palsuite/c_runtime/fread/test3/test3.cpp | 131 +++ .../palsuite/c_runtime/free/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/free/test1/test1.c | 62 -- .../tests/palsuite/c_runtime/free/test1/test1.cpp | 62 ++ .../palsuite/c_runtime/fseek/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fseek/test1/test1.c | 193 ----- .../tests/palsuite/c_runtime/fseek/test1/test1.cpp | 193 +++++ .../palsuite/c_runtime/ftell/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/ftell/test1/ftell.c | 145 ---- .../tests/palsuite/c_runtime/ftell/test1/ftell.cpp | 145 ++++ .../tests/palsuite/c_runtime/fwprintf/fwprintf.h | 34 +- .../c_runtime/fwprintf/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test1/test1.c | 71 -- .../palsuite/c_runtime/fwprintf/test1/test1.cpp | 71 ++ .../c_runtime/fwprintf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test10/test10.c | 51 -- .../palsuite/c_runtime/fwprintf/test10/test10.cpp | 51 ++ .../c_runtime/fwprintf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test11/test11.c | 51 -- .../palsuite/c_runtime/fwprintf/test11/test11.cpp | 51 ++ .../c_runtime/fwprintf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test12/test12.c | 52 -- .../palsuite/c_runtime/fwprintf/test12/test12.cpp | 52 ++ .../c_runtime/fwprintf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test13/test13.c | 52 -- .../palsuite/c_runtime/fwprintf/test13/test13.cpp | 52 ++ .../c_runtime/fwprintf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test14/test14.c | 66 -- .../palsuite/c_runtime/fwprintf/test14/test14.cpp | 66 ++ .../c_runtime/fwprintf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test15/test15.c | 66 -- .../palsuite/c_runtime/fwprintf/test15/test15.cpp | 66 ++ .../c_runtime/fwprintf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test16/test16.c | 65 -- .../palsuite/c_runtime/fwprintf/test16/test16.cpp | 65 ++ .../c_runtime/fwprintf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test17/test17.c | 51 -- .../palsuite/c_runtime/fwprintf/test17/test17.cpp | 51 ++ .../c_runtime/fwprintf/test18/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test18/test18.c | 51 -- .../palsuite/c_runtime/fwprintf/test18/test18.cpp | 51 ++ .../c_runtime/fwprintf/test19/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test19/test19.c | 81 -- .../palsuite/c_runtime/fwprintf/test19/test19.cpp | 81 ++ .../c_runtime/fwprintf/test2/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test2/test2.c | 45 - .../palsuite/c_runtime/fwprintf/test2/test2.cpp | 45 + .../c_runtime/fwprintf/test3/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test3/test3.c | 45 - .../palsuite/c_runtime/fwprintf/test3/test3.cpp | 45 + .../c_runtime/fwprintf/test4/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test4/test4.c | 85 -- .../palsuite/c_runtime/fwprintf/test4/test4.cpp | 85 ++ .../c_runtime/fwprintf/test5/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test5/test5.c | 63 -- .../palsuite/c_runtime/fwprintf/test5/test5.cpp | 63 ++ .../c_runtime/fwprintf/test6/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test6/test6.c | 48 -- .../palsuite/c_runtime/fwprintf/test6/test6.cpp | 48 ++ .../c_runtime/fwprintf/test7/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test7/test7.c | 47 -- .../palsuite/c_runtime/fwprintf/test7/test7.cpp | 47 ++ .../c_runtime/fwprintf/test8/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test8/test8.c | 51 -- .../palsuite/c_runtime/fwprintf/test8/test8.cpp | 51 ++ .../c_runtime/fwprintf/test9/CMakeLists.txt | 2 +- .../palsuite/c_runtime/fwprintf/test9/test9.c | 51 -- .../palsuite/c_runtime/fwprintf/test9/test9.cpp | 51 ++ .../palsuite/c_runtime/fwrite/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/fwrite/test1/test1.c | 104 --- .../palsuite/c_runtime/fwrite/test1/test1.cpp | 104 +++ .../palsuite/c_runtime/getc/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/c_runtime/getc/test1/getc.c | 152 ---- .../tests/palsuite/c_runtime/getc/test1/getc.cpp | 152 ++++ .../palsuite/c_runtime/getenv/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/getenv/test1/test1.c | 78 -- .../palsuite/c_runtime/getenv/test1/test1.cpp | 78 ++ .../palsuite/c_runtime/getenv/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/getenv/test2/test2.c | 101 --- .../palsuite/c_runtime/getenv/test2/test2.cpp | 101 +++ .../palsuite/c_runtime/getenv/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/getenv/test3/test3.c | 75 -- .../palsuite/c_runtime/getenv/test3/test3.cpp | 75 ++ .../c_runtime/isalnum/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/isalnum/test1/test1.c | 88 -- .../palsuite/c_runtime/isalnum/test1/test1.cpp | 88 ++ .../c_runtime/isalpha/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/isalpha/test1/test1.c | 86 -- .../palsuite/c_runtime/isalpha/test1/test1.cpp | 86 ++ .../c_runtime/isdigit/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/isdigit/test1/test1.c | 47 -- .../palsuite/c_runtime/isdigit/test1/test1.cpp | 47 ++ .../c_runtime/islower/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/islower/test1/test1.c | 85 -- .../palsuite/c_runtime/islower/test1/test1.cpp | 85 ++ .../c_runtime/isprint/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/isprint/test1/isprint.c | 42 - .../palsuite/c_runtime/isprint/test1/isprint.cpp | 42 + .../c_runtime/isprint/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/isprint/test2/test2.c | 59 -- .../palsuite/c_runtime/isprint/test2/test2.cpp | 59 ++ .../c_runtime/isspace/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/isspace/test1/test1.c | 82 -- .../palsuite/c_runtime/isspace/test1/test1.cpp | 82 ++ .../c_runtime/isupper/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/isupper/test1/test1.c | 88 -- .../palsuite/c_runtime/isupper/test1/test1.cpp | 88 ++ .../c_runtime/iswdigit/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/iswdigit/test1/test1.c | 69 -- .../palsuite/c_runtime/iswdigit/test1/test1.cpp | 69 ++ .../c_runtime/iswprint/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/iswprint/test1/test1.c | 59 -- .../palsuite/c_runtime/iswprint/test1/test1.cpp | 59 ++ .../c_runtime/iswspace/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/iswspace/test1/test1.c | 78 -- .../palsuite/c_runtime/iswspace/test1/test1.cpp | 78 ++ .../c_runtime/iswupper/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/iswupper/test1/test1.c | 91 -- .../palsuite/c_runtime/iswupper/test1/test1.cpp | 91 ++ .../c_runtime/iswxdigit/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/iswxdigit/test1/test1.c | 61 -- .../palsuite/c_runtime/iswxdigit/test1/test1.cpp | 61 ++ .../c_runtime/isxdigit/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/isxdigit/test1/test1.c | 58 -- .../palsuite/c_runtime/isxdigit/test1/test1.cpp | 58 ++ .../palsuite/c_runtime/labs/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/labs/test1/test1.c | 65 -- .../tests/palsuite/c_runtime/labs/test1/test1.cpp | 65 ++ .../palsuite/c_runtime/llabs/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/llabs/test1/test1.c | 65 -- .../tests/palsuite/c_runtime/llabs/test1/test1.cpp | 65 ++ .../c_runtime/localtime/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/localtime/test1/test1.c | 69 -- .../palsuite/c_runtime/localtime/test1/test1.cpp | 69 ++ .../palsuite/c_runtime/log/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/c_runtime/log/test1/test1.c | 140 ---- .../tests/palsuite/c_runtime/log/test1/test1.cpp | 140 ++++ .../palsuite/c_runtime/log10/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/log10/test1/test1.c | 146 ---- .../tests/palsuite/c_runtime/log10/test1/test1.cpp | 146 ++++ .../tests/palsuite/c_runtime/log10f/CMakeLists.txt | 3 + .../palsuite/c_runtime/log10f/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/log10f/test1/test1.c | 144 ++++ .../palsuite/c_runtime/log10f/test1/testinfo.dat | 17 + .../tests/palsuite/c_runtime/logf/CMakeLists.txt | 3 + .../palsuite/c_runtime/logf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/logf/test1/test1.c | 139 ++++ .../palsuite/c_runtime/logf/test1/testinfo.dat | 14 + .../palsuite/c_runtime/malloc/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/malloc/test1/test1.c | 52 -- .../palsuite/c_runtime/malloc/test1/test1.cpp | 52 ++ .../palsuite/c_runtime/malloc/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/malloc/test2/test2.c | 41 - .../palsuite/c_runtime/malloc/test2/test2.cpp | 41 + .../palsuite/c_runtime/memchr/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/memchr/test1/test1.c | 122 --- .../palsuite/c_runtime/memchr/test1/test1.cpp | 122 +++ .../palsuite/c_runtime/memcmp/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/memcmp/test1/test1.c | 57 -- .../palsuite/c_runtime/memcmp/test1/test1.cpp | 57 ++ .../palsuite/c_runtime/memcpy/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/memcpy/test1/test1.c | 87 -- .../palsuite/c_runtime/memcpy/test1/test1.cpp | 87 ++ .../c_runtime/memmove/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/memmove/test1/test1.c | 116 --- .../palsuite/c_runtime/memmove/test1/test1.cpp | 116 +++ .../palsuite/c_runtime/memset/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/memset/test1/test1.c | 60 -- .../palsuite/c_runtime/memset/test1/test1.cpp | 60 ++ .../palsuite/c_runtime/modf/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/modf/test1/test1.c | 136 --- .../tests/palsuite/c_runtime/modf/test1/test1.cpp | 136 +++ .../palsuite/c_runtime/modff/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/modff/test1/test1.c | 135 --- .../tests/palsuite/c_runtime/modff/test1/test1.cpp | 135 +++ .../palsuite/c_runtime/pow/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/c_runtime/pow/test1/test1.c | 230 ------ .../tests/palsuite/c_runtime/pow/test1/test1.cpp | 230 ++++++ .../tests/palsuite/c_runtime/powf/CMakeLists.txt | 3 + .../palsuite/c_runtime/powf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/powf/test1/test1.c | 229 ++++++ .../palsuite/c_runtime/powf/test1/testinfo.dat | 17 + src/pal/tests/palsuite/c_runtime/printf/printf.h | 34 +- .../palsuite/c_runtime/printf/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/printf/test1/test1.c | 43 - .../palsuite/c_runtime/printf/test1/test1.cpp | 43 + .../c_runtime/printf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test10/test10.c | 52 -- .../palsuite/c_runtime/printf/test10/test10.cpp | 52 ++ .../c_runtime/printf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test11/test11.c | 51 -- .../palsuite/c_runtime/printf/test11/test11.cpp | 51 ++ .../c_runtime/printf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test12/test12.c | 53 -- .../palsuite/c_runtime/printf/test12/test12.cpp | 53 ++ .../c_runtime/printf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test13/test13.c | 54 -- .../palsuite/c_runtime/printf/test13/test13.cpp | 54 ++ .../c_runtime/printf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test14/test14.c | 54 -- .../palsuite/c_runtime/printf/test14/test14.cpp | 54 ++ .../c_runtime/printf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test15/test15.c | 54 -- .../palsuite/c_runtime/printf/test15/test15.cpp | 54 ++ .../c_runtime/printf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test16/test16.c | 50 -- .../palsuite/c_runtime/printf/test16/test16.cpp | 50 ++ .../c_runtime/printf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test17/test17.c | 52 -- .../palsuite/c_runtime/printf/test17/test17.cpp | 52 ++ .../c_runtime/printf/test18/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test18/test18.c | 51 -- .../palsuite/c_runtime/printf/test18/test18.cpp | 51 ++ .../c_runtime/printf/test19/CMakeLists.txt | 2 +- .../palsuite/c_runtime/printf/test19/test19.c | 76 -- .../palsuite/c_runtime/printf/test19/test19.cpp | 76 ++ .../palsuite/c_runtime/printf/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/printf/test2/test2.c | 45 - .../palsuite/c_runtime/printf/test2/test2.cpp | 45 + .../palsuite/c_runtime/printf/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/printf/test3/test3.c | 45 - .../palsuite/c_runtime/printf/test3/test3.cpp | 45 + .../palsuite/c_runtime/printf/test4/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/printf/test4/test4.c | 66 -- .../palsuite/c_runtime/printf/test4/test4.cpp | 66 ++ .../palsuite/c_runtime/printf/test5/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/printf/test5/test5.c | 60 -- .../palsuite/c_runtime/printf/test5/test5.cpp | 60 ++ .../palsuite/c_runtime/printf/test6/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/printf/test6/test6.c | 48 -- .../palsuite/c_runtime/printf/test6/test6.cpp | 48 ++ .../palsuite/c_runtime/printf/test7/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/printf/test7/test7.c | 47 -- .../palsuite/c_runtime/printf/test7/test7.cpp | 47 ++ .../palsuite/c_runtime/printf/test8/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/printf/test8/test8.c | 53 -- .../palsuite/c_runtime/printf/test8/test8.cpp | 53 ++ .../palsuite/c_runtime/printf/test9/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/printf/test9/test9.c | 53 -- .../palsuite/c_runtime/printf/test9/test9.cpp | 53 ++ .../palsuite/c_runtime/qsort/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/qsort/test1/test1.c | 48 -- .../tests/palsuite/c_runtime/qsort/test1/test1.cpp | 48 ++ .../palsuite/c_runtime/qsort/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/qsort/test2/test2.c | 49 -- .../tests/palsuite/c_runtime/qsort/test2/test2.cpp | 49 ++ .../c_runtime/rand_srand/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/rand_srand/test1/test1.c | 100 --- .../palsuite/c_runtime/rand_srand/test1/test1.cpp | 100 +++ .../c_runtime/realloc/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/realloc/test1/test1.c | 66 -- .../palsuite/c_runtime/realloc/test1/test1.cpp | 66 ++ .../palsuite/c_runtime/sin/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/c_runtime/sin/test1/test1.c | 131 --- .../tests/palsuite/c_runtime/sin/test1/test1.cpp | 131 +++ .../tests/palsuite/c_runtime/sinf/CMakeLists.txt | 3 + .../palsuite/c_runtime/sinf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/sinf/test1/test1.c | 130 +++ .../palsuite/c_runtime/sinf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/sinh/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/sinh/test1/test1.c | 130 --- .../tests/palsuite/c_runtime/sinh/test1/test1.cpp | 130 +++ .../tests/palsuite/c_runtime/sinhf/CMakeLists.txt | 3 + .../palsuite/c_runtime/sinhf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/sinhf/test1/test1.c | 129 +++ .../palsuite/c_runtime/sinhf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/sprintf/CMakeLists.txt | 22 - src/pal/tests/palsuite/c_runtime/sprintf/sprintf.h | 195 ----- .../c_runtime/sprintf/test1/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sprintf/test1/test1.c | 45 - .../palsuite/c_runtime/sprintf/test1/testinfo.dat | 12 - .../c_runtime/sprintf/test10/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test10/test10.c | 55 -- .../palsuite/c_runtime/sprintf/test10/testinfo.dat | 12 - .../c_runtime/sprintf/test11/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test11/test11.c | 55 -- .../palsuite/c_runtime/sprintf/test11/testinfo.dat | 12 - .../c_runtime/sprintf/test12/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test12/test12.c | 56 -- .../palsuite/c_runtime/sprintf/test12/testinfo.dat | 12 - .../c_runtime/sprintf/test13/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test13/test13.c | 56 -- .../palsuite/c_runtime/sprintf/test13/testinfo.dat | 12 - .../c_runtime/sprintf/test14/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test14/test14.c | 53 -- .../palsuite/c_runtime/sprintf/test14/testinfo.dat | 12 - .../c_runtime/sprintf/test15/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test15/test15.c | 53 -- .../palsuite/c_runtime/sprintf/test15/testinfo.dat | 12 - .../c_runtime/sprintf/test16/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test16/test16.c | 52 -- .../palsuite/c_runtime/sprintf/test16/testinfo.dat | 12 - .../c_runtime/sprintf/test17/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test17/test17.c | 54 -- .../palsuite/c_runtime/sprintf/test17/testinfo.dat | 12 - .../c_runtime/sprintf/test18/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test18/test18.c | 53 -- .../palsuite/c_runtime/sprintf/test18/testinfo.dat | 12 - .../c_runtime/sprintf/test19/CMakeLists.txt | 19 - .../palsuite/c_runtime/sprintf/test19/test19.c | 78 -- .../palsuite/c_runtime/sprintf/test19/testinfo.dat | 12 - .../c_runtime/sprintf/test2/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sprintf/test2/test2.c | 47 -- .../palsuite/c_runtime/sprintf/test2/testinfo.dat | 12 - .../c_runtime/sprintf/test3/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sprintf/test3/test3.c | 47 -- .../palsuite/c_runtime/sprintf/test3/testinfo.dat | 12 - .../c_runtime/sprintf/test4/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sprintf/test4/test4.c | 69 -- .../palsuite/c_runtime/sprintf/test4/testinfo.dat | 12 - .../c_runtime/sprintf/test5/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sprintf/test5/test5.c | 62 -- .../palsuite/c_runtime/sprintf/test5/testinfo.dat | 12 - .../c_runtime/sprintf/test6/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sprintf/test6/test6.c | 50 -- .../palsuite/c_runtime/sprintf/test6/testinfo.dat | 12 - .../c_runtime/sprintf/test7/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sprintf/test7/test7.c | 49 -- .../palsuite/c_runtime/sprintf/test7/testinfo.dat | 12 - .../c_runtime/sprintf/test8/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sprintf/test8/test8.c | 55 -- .../palsuite/c_runtime/sprintf/test8/testinfo.dat | 12 - .../c_runtime/sprintf/test9/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sprintf/test9/test9.c | 55 -- .../palsuite/c_runtime/sprintf/test9/testinfo.dat | 12 - .../palsuite/c_runtime/sprintf_s/CMakeLists.txt | 21 + .../tests/palsuite/c_runtime/sprintf_s/sprintf_s.h | 195 +++++ .../c_runtime/sprintf_s/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test1/test1.cpp | 45 + .../c_runtime/sprintf_s/test1/testinfo.dat | 12 + .../c_runtime/sprintf_s/test10/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test10/test10.cpp | 55 ++ .../c_runtime/sprintf_s/test10/testinfo.dat | 12 + .../c_runtime/sprintf_s/test11/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test11/test11.cpp | 55 ++ .../c_runtime/sprintf_s/test11/testinfo.dat | 12 + .../c_runtime/sprintf_s/test12/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test12/test12.cpp | 56 ++ .../c_runtime/sprintf_s/test12/testinfo.dat | 12 + .../c_runtime/sprintf_s/test13/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test13/test13.cpp | 56 ++ .../c_runtime/sprintf_s/test13/testinfo.dat | 12 + .../c_runtime/sprintf_s/test14/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test14/test14.cpp | 53 ++ .../c_runtime/sprintf_s/test14/testinfo.dat | 12 + .../c_runtime/sprintf_s/test15/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test15/test15.cpp | 53 ++ .../c_runtime/sprintf_s/test15/testinfo.dat | 12 + .../c_runtime/sprintf_s/test16/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test16/test16.cpp | 52 ++ .../c_runtime/sprintf_s/test16/testinfo.dat | 12 + .../c_runtime/sprintf_s/test17/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test17/test17.cpp | 54 ++ .../c_runtime/sprintf_s/test17/testinfo.dat | 12 + .../c_runtime/sprintf_s/test18/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test18/test18.cpp | 53 ++ .../c_runtime/sprintf_s/test18/testinfo.dat | 12 + .../c_runtime/sprintf_s/test19/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test19/test19.cpp | 71 ++ .../c_runtime/sprintf_s/test19/testinfo.dat | 12 + .../c_runtime/sprintf_s/test2/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test2/test2.cpp | 47 ++ .../c_runtime/sprintf_s/test2/testinfo.dat | 12 + .../c_runtime/sprintf_s/test3/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test3/test3.cpp | 47 ++ .../c_runtime/sprintf_s/test3/testinfo.dat | 12 + .../c_runtime/sprintf_s/test4/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test4/test4.cpp | 69 ++ .../c_runtime/sprintf_s/test4/testinfo.dat | 12 + .../c_runtime/sprintf_s/test6/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test6/test6.cpp | 50 ++ .../c_runtime/sprintf_s/test6/testinfo.dat | 12 + .../c_runtime/sprintf_s/test7/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test7/test7.cpp | 49 ++ .../c_runtime/sprintf_s/test7/testinfo.dat | 12 + .../c_runtime/sprintf_s/test8/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test8/test8.cpp | 55 ++ .../c_runtime/sprintf_s/test8/testinfo.dat | 12 + .../c_runtime/sprintf_s/test9/CMakeLists.txt | 19 + .../palsuite/c_runtime/sprintf_s/test9/test9.cpp | 55 ++ .../c_runtime/sprintf_s/test9/testinfo.dat | 12 + .../palsuite/c_runtime/sqrt/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/sqrt/test1/test1.c | 123 --- .../tests/palsuite/c_runtime/sqrt/test1/test1.cpp | 123 +++ .../tests/palsuite/c_runtime/sqrtf/CMakeLists.txt | 4 + .../palsuite/c_runtime/sqrtf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/sqrtf/test1/test1.c | 122 +++ .../palsuite/c_runtime/sqrtf/test1/testinfo.dat | 17 + .../tests/palsuite/c_runtime/sscanf/CMakeLists.txt | 20 - src/pal/tests/palsuite/c_runtime/sscanf/sscanf.h | 246 ------ .../palsuite/c_runtime/sscanf/test1/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sscanf/test1/test1.c | 53 -- .../palsuite/c_runtime/sscanf/test1/testinfo.dat | 12 - .../c_runtime/sscanf/test10/CMakeLists.txt | 19 - .../palsuite/c_runtime/sscanf/test10/test10.c | 37 - .../palsuite/c_runtime/sscanf/test10/testinfo.dat | 12 - .../c_runtime/sscanf/test11/CMakeLists.txt | 19 - .../palsuite/c_runtime/sscanf/test11/test11.c | 36 - .../palsuite/c_runtime/sscanf/test11/testinfo.dat | 12 - .../c_runtime/sscanf/test12/CMakeLists.txt | 19 - .../palsuite/c_runtime/sscanf/test12/test12.c | 35 - .../palsuite/c_runtime/sscanf/test12/testinfo.dat | 12 - .../c_runtime/sscanf/test13/CMakeLists.txt | 19 - .../palsuite/c_runtime/sscanf/test13/test13.c | 37 - .../palsuite/c_runtime/sscanf/test13/testinfo.dat | 12 - .../c_runtime/sscanf/test14/CMakeLists.txt | 19 - .../palsuite/c_runtime/sscanf/test14/test14.c | 36 - .../palsuite/c_runtime/sscanf/test14/testinfo.dat | 12 - .../c_runtime/sscanf/test15/CMakeLists.txt | 19 - .../palsuite/c_runtime/sscanf/test15/test15.c | 36 - .../palsuite/c_runtime/sscanf/test15/testinfo.dat | 12 - .../c_runtime/sscanf/test16/CMakeLists.txt | 19 - .../palsuite/c_runtime/sscanf/test16/test16.c | 37 - .../palsuite/c_runtime/sscanf/test16/testinfo.dat | 12 - .../c_runtime/sscanf/test17/CMakeLists.txt | 19 - .../palsuite/c_runtime/sscanf/test17/test17.c | 37 - .../palsuite/c_runtime/sscanf/test17/testinfo.dat | 12 - .../palsuite/c_runtime/sscanf/test2/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sscanf/test2/test2.c | 44 - .../palsuite/c_runtime/sscanf/test2/testinfo.dat | 12 - .../palsuite/c_runtime/sscanf/test3/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sscanf/test3/test3.c | 35 - .../palsuite/c_runtime/sscanf/test3/testinfo.dat | 12 - .../palsuite/c_runtime/sscanf/test4/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sscanf/test4/test4.c | 44 - .../palsuite/c_runtime/sscanf/test4/testinfo.dat | 12 - .../palsuite/c_runtime/sscanf/test5/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sscanf/test5/test5.c | 43 - .../palsuite/c_runtime/sscanf/test5/testinfo.dat | 12 - .../palsuite/c_runtime/sscanf/test6/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sscanf/test6/test6.c | 43 - .../palsuite/c_runtime/sscanf/test6/testinfo.dat | 12 - .../palsuite/c_runtime/sscanf/test7/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sscanf/test7/test7.c | 43 - .../palsuite/c_runtime/sscanf/test7/testinfo.dat | 12 - .../palsuite/c_runtime/sscanf/test8/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sscanf/test8/test8.c | 43 - .../palsuite/c_runtime/sscanf/test8/testinfo.dat | 12 - .../palsuite/c_runtime/sscanf/test9/CMakeLists.txt | 19 - .../tests/palsuite/c_runtime/sscanf/test9/test9.c | 38 - .../palsuite/c_runtime/sscanf/test9/testinfo.dat | 12 - .../palsuite/c_runtime/sscanf_s/CMakeLists.txt | 20 + .../tests/palsuite/c_runtime/sscanf_s/sscanf_s.h | 246 ++++++ .../c_runtime/sscanf_s/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test1/test1.cpp | 53 ++ .../palsuite/c_runtime/sscanf_s/test1/testinfo.dat | 12 + .../c_runtime/sscanf_s/test10/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test10/test10.cpp | 37 + .../c_runtime/sscanf_s/test10/testinfo.dat | 12 + .../c_runtime/sscanf_s/test11/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test11/test11.cpp | 36 + .../c_runtime/sscanf_s/test11/testinfo.dat | 12 + .../c_runtime/sscanf_s/test12/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test12/test12.cpp | 35 + .../c_runtime/sscanf_s/test12/testinfo.dat | 12 + .../c_runtime/sscanf_s/test13/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test13/test13.cpp | 37 + .../c_runtime/sscanf_s/test13/testinfo.dat | 12 + .../c_runtime/sscanf_s/test14/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test14/test14.cpp | 36 + .../c_runtime/sscanf_s/test14/testinfo.dat | 12 + .../c_runtime/sscanf_s/test15/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test15/test15.cpp | 36 + .../c_runtime/sscanf_s/test15/testinfo.dat | 12 + .../c_runtime/sscanf_s/test16/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test16/test16.cpp | 37 + .../c_runtime/sscanf_s/test16/testinfo.dat | 12 + .../c_runtime/sscanf_s/test17/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test17/test17.cpp | 37 + .../c_runtime/sscanf_s/test17/testinfo.dat | 12 + .../c_runtime/sscanf_s/test2/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test2/test2.cpp | 44 + .../palsuite/c_runtime/sscanf_s/test2/testinfo.dat | 12 + .../c_runtime/sscanf_s/test3/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test3/test3.cpp | 35 + .../palsuite/c_runtime/sscanf_s/test3/testinfo.dat | 12 + .../c_runtime/sscanf_s/test4/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test4/test4.cpp | 44 + .../palsuite/c_runtime/sscanf_s/test4/testinfo.dat | 12 + .../c_runtime/sscanf_s/test5/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test5/test5.cpp | 43 + .../palsuite/c_runtime/sscanf_s/test5/testinfo.dat | 12 + .../c_runtime/sscanf_s/test6/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test6/test6.cpp | 43 + .../palsuite/c_runtime/sscanf_s/test6/testinfo.dat | 12 + .../c_runtime/sscanf_s/test7/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test7/test7.cpp | 43 + .../palsuite/c_runtime/sscanf_s/test7/testinfo.dat | 12 + .../c_runtime/sscanf_s/test8/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test8/test8.cpp | 43 + .../palsuite/c_runtime/sscanf_s/test8/testinfo.dat | 12 + .../c_runtime/sscanf_s/test9/CMakeLists.txt | 19 + .../palsuite/c_runtime/sscanf_s/test9/test9.cpp | 38 + .../palsuite/c_runtime/sscanf_s/test9/testinfo.dat | 12 + .../palsuite/c_runtime/strcat/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strcat/test1/test1.c | 66 -- .../palsuite/c_runtime/strcat/test1/test1.cpp | 66 ++ .../palsuite/c_runtime/strchr/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strchr/test1/test1.c | 86 -- .../palsuite/c_runtime/strchr/test1/test1.cpp | 86 ++ .../palsuite/c_runtime/strcmp/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strcmp/test1/test1.c | 73 -- .../palsuite/c_runtime/strcmp/test1/test1.cpp | 73 ++ .../palsuite/c_runtime/strcpy/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strcpy/test1/test1.c | 51 -- .../palsuite/c_runtime/strcpy/test1/test1.cpp | 51 ++ .../c_runtime/strcspn/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strcspn/test1/test1.c | 59 -- .../palsuite/c_runtime/strcspn/test1/test1.cpp | 59 ++ .../palsuite/c_runtime/strlen/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strlen/test1/test1.c | 33 - .../palsuite/c_runtime/strlen/test1/test1.cpp | 33 + .../c_runtime/strncat/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strncat/test1/test1.c | 77 -- .../palsuite/c_runtime/strncat/test1/test1.cpp | 77 ++ .../c_runtime/strncmp/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strncmp/test1/test1.c | 80 -- .../palsuite/c_runtime/strncmp/test1/test1.cpp | 80 ++ .../c_runtime/strncpy/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strncpy/test1/test1.c | 85 -- .../palsuite/c_runtime/strncpy/test1/test1.cpp | 85 ++ .../c_runtime/strpbrk/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strpbrk/test1/test1.c | 85 -- .../palsuite/c_runtime/strpbrk/test1/test1.cpp | 85 ++ .../c_runtime/strrchr/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strrchr/test1/test1.c | 55 -- .../palsuite/c_runtime/strrchr/test1/test1.cpp | 55 ++ .../palsuite/c_runtime/strspn/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strspn/test1/test1.c | 60 -- .../palsuite/c_runtime/strspn/test1/test1.cpp | 60 ++ .../palsuite/c_runtime/strstr/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strstr/test1/test1.c | 83 -- .../palsuite/c_runtime/strstr/test1/test1.cpp | 83 ++ .../palsuite/c_runtime/strtod/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strtod/test1/test1.c | 93 --- .../palsuite/c_runtime/strtod/test1/test1.cpp | 93 +++ .../palsuite/c_runtime/strtod/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strtod/test2/test2.c | 65 -- .../palsuite/c_runtime/strtod/test2/test2.cpp | 65 ++ .../palsuite/c_runtime/strtok/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strtok/test1/test1.c | 78 -- .../palsuite/c_runtime/strtok/test1/test1.cpp | 78 ++ .../c_runtime/strtoul/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/strtoul/test1/test1.c | 73 -- .../palsuite/c_runtime/strtoul/test1/test1.cpp | 73 ++ .../tests/palsuite/c_runtime/swprintf/swprintf.h | 32 +- .../c_runtime/swprintf/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test1/test1.c | 44 - .../palsuite/c_runtime/swprintf/test1/test1.cpp | 44 + .../c_runtime/swprintf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test10/test10.c | 55 -- .../palsuite/c_runtime/swprintf/test10/test10.cpp | 55 ++ .../c_runtime/swprintf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test11/test11.c | 55 -- .../palsuite/c_runtime/swprintf/test11/test11.cpp | 55 ++ .../c_runtime/swprintf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test12/test12.c | 56 -- .../palsuite/c_runtime/swprintf/test12/test12.cpp | 56 ++ .../c_runtime/swprintf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test13/test13.c | 55 -- .../palsuite/c_runtime/swprintf/test13/test13.cpp | 55 ++ .../c_runtime/swprintf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test14/test14.c | 67 -- .../palsuite/c_runtime/swprintf/test14/test14.cpp | 67 ++ .../c_runtime/swprintf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test15/test15.c | 67 -- .../palsuite/c_runtime/swprintf/test15/test15.cpp | 67 ++ .../c_runtime/swprintf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test16/test16.c | 67 -- .../palsuite/c_runtime/swprintf/test16/test16.cpp | 67 ++ .../c_runtime/swprintf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test17/test17.c | 69 -- .../palsuite/c_runtime/swprintf/test17/test17.cpp | 69 ++ .../c_runtime/swprintf/test18/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test18/test18.c | 69 -- .../palsuite/c_runtime/swprintf/test18/test18.cpp | 69 ++ .../c_runtime/swprintf/test19/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test19/test19.c | 109 --- .../palsuite/c_runtime/swprintf/test19/test19.cpp | 109 +++ .../c_runtime/swprintf/test2/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test2/test2.c | 46 -- .../palsuite/c_runtime/swprintf/test2/test2.cpp | 46 ++ .../c_runtime/swprintf/test3/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test3/test3.c | 43 - .../palsuite/c_runtime/swprintf/test3/test3.cpp | 43 + .../c_runtime/swprintf/test4/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test4/test4.c | 71 -- .../palsuite/c_runtime/swprintf/test4/test4.cpp | 71 ++ .../c_runtime/swprintf/test5/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test5/test5.c | 67 -- .../palsuite/c_runtime/swprintf/test5/test5.cpp | 67 ++ .../c_runtime/swprintf/test6/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test6/test6.c | 47 -- .../palsuite/c_runtime/swprintf/test6/test6.cpp | 47 ++ .../c_runtime/swprintf/test7/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test7/test7.c | 48 -- .../palsuite/c_runtime/swprintf/test7/test7.cpp | 48 ++ .../c_runtime/swprintf/test8/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test8/test8.c | 55 -- .../palsuite/c_runtime/swprintf/test8/test8.cpp | 55 ++ .../c_runtime/swprintf/test9/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swprintf/test9/test9.c | 55 -- .../palsuite/c_runtime/swprintf/test9/test9.cpp | 55 ++ src/pal/tests/palsuite/c_runtime/swscanf/swscanf.h | 22 +- .../c_runtime/swscanf/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/swscanf/test1/test1.c | 53 -- .../palsuite/c_runtime/swscanf/test1/test1.cpp | 53 ++ .../c_runtime/swscanf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swscanf/test10/test10.c | 36 - .../palsuite/c_runtime/swscanf/test10/test10.cpp | 36 + .../c_runtime/swscanf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swscanf/test11/test11.c | 35 - .../palsuite/c_runtime/swscanf/test11/test11.cpp | 35 + .../c_runtime/swscanf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swscanf/test12/test12.c | 35 - .../palsuite/c_runtime/swscanf/test12/test12.cpp | 35 + .../c_runtime/swscanf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swscanf/test13/test13.c | 37 - .../palsuite/c_runtime/swscanf/test13/test13.cpp | 37 + .../c_runtime/swscanf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swscanf/test14/test14.c | 38 - .../palsuite/c_runtime/swscanf/test14/test14.cpp | 38 + .../c_runtime/swscanf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swscanf/test15/test15.c | 37 - .../palsuite/c_runtime/swscanf/test15/test15.cpp | 37 + .../c_runtime/swscanf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swscanf/test16/test16.c | 37 - .../palsuite/c_runtime/swscanf/test16/test16.cpp | 37 + .../c_runtime/swscanf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/swscanf/test17/test17.c | 37 - .../palsuite/c_runtime/swscanf/test17/test17.cpp | 37 + .../c_runtime/swscanf/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/swscanf/test2/test2.c | 43 - .../palsuite/c_runtime/swscanf/test2/test2.cpp | 43 + .../c_runtime/swscanf/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/swscanf/test3/test3.c | 36 - .../palsuite/c_runtime/swscanf/test3/test3.cpp | 36 + .../c_runtime/swscanf/test4/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/swscanf/test4/test4.c | 44 - .../palsuite/c_runtime/swscanf/test4/test4.cpp | 44 + .../c_runtime/swscanf/test5/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/swscanf/test5/test5.c | 44 - .../palsuite/c_runtime/swscanf/test5/test5.cpp | 44 + .../c_runtime/swscanf/test6/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/swscanf/test6/test6.c | 44 - .../palsuite/c_runtime/swscanf/test6/test6.cpp | 44 + .../c_runtime/swscanf/test7/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/swscanf/test7/test7.c | 44 - .../palsuite/c_runtime/swscanf/test7/test7.cpp | 44 + .../c_runtime/swscanf/test8/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/swscanf/test8/test8.c | 44 - .../palsuite/c_runtime/swscanf/test8/test8.cpp | 44 + .../c_runtime/swscanf/test9/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/swscanf/test9/test9.c | 37 - .../palsuite/c_runtime/swscanf/test9/test9.cpp | 37 + .../palsuite/c_runtime/tan/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/c_runtime/tan/test1/test1.c | 137 --- .../tests/palsuite/c_runtime/tan/test1/test1.cpp | 137 +++ .../tests/palsuite/c_runtime/tanf/CMakeLists.txt | 3 + .../palsuite/c_runtime/tanf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/tanf/test1/test1.c | 136 +++ .../palsuite/c_runtime/tanf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/tanh/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/tanh/test1/test1.c | 130 --- .../tests/palsuite/c_runtime/tanh/test1/test1.cpp | 130 +++ .../tests/palsuite/c_runtime/tanhf/CMakeLists.txt | 3 + .../palsuite/c_runtime/tanhf/test1/CMakeLists.txt | 19 + .../tests/palsuite/c_runtime/tanhf/test1/test1.c | 129 +++ .../palsuite/c_runtime/tanhf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/time/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/time/test1/test1.c | 51 -- .../tests/palsuite/c_runtime/time/test1/test1.cpp | 51 ++ .../c_runtime/tolower/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/tolower/test1/test1.c | 79 -- .../palsuite/c_runtime/tolower/test1/test1.cpp | 79 ++ .../c_runtime/toupper/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/toupper/test1/test1.c | 64 -- .../palsuite/c_runtime/toupper/test1/test1.cpp | 64 ++ .../c_runtime/towlower/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/towlower/test1/test1.c | 79 -- .../palsuite/c_runtime/towlower/test1/test1.cpp | 79 ++ .../c_runtime/towupper/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/towupper/test1/test1.c | 65 -- .../palsuite/c_runtime/towupper/test1/test1.cpp | 65 ++ .../palsuite/c_runtime/ungetc/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/ungetc/test1/ungetc.c | 130 --- .../palsuite/c_runtime/ungetc/test1/ungetc.cpp | 130 +++ .../palsuite/c_runtime/ungetc/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/ungetc/test2/ungetc.c | 188 ----- .../palsuite/c_runtime/ungetc/test2/ungetc.cpp | 188 +++++ .../c_runtime/vfprintf/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test1/test1.c | 68 -- .../palsuite/c_runtime/vfprintf/test1/test1.cpp | 68 ++ .../c_runtime/vfprintf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test10/test10.c | 52 -- .../palsuite/c_runtime/vfprintf/test10/test10.cpp | 52 ++ .../c_runtime/vfprintf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test11/test11.c | 51 -- .../palsuite/c_runtime/vfprintf/test11/test11.cpp | 51 ++ .../c_runtime/vfprintf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test12/test12.c | 53 -- .../palsuite/c_runtime/vfprintf/test12/test12.cpp | 53 ++ .../c_runtime/vfprintf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test13/test13.c | 54 -- .../palsuite/c_runtime/vfprintf/test13/test13.cpp | 54 ++ .../c_runtime/vfprintf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test14/test14.c | 54 -- .../palsuite/c_runtime/vfprintf/test14/test14.cpp | 54 ++ .../c_runtime/vfprintf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test15/test15.c | 54 -- .../palsuite/c_runtime/vfprintf/test15/test15.cpp | 54 ++ .../c_runtime/vfprintf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test16/test16.c | 50 -- .../palsuite/c_runtime/vfprintf/test16/test16.cpp | 50 ++ .../c_runtime/vfprintf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test17/test17.c | 52 -- .../palsuite/c_runtime/vfprintf/test17/test17.cpp | 52 ++ .../c_runtime/vfprintf/test18/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test18/test18.c | 51 -- .../palsuite/c_runtime/vfprintf/test18/test18.cpp | 51 ++ .../c_runtime/vfprintf/test19/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test19/test19.c | 76 -- .../palsuite/c_runtime/vfprintf/test19/test19.cpp | 76 ++ .../c_runtime/vfprintf/test2/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test2/test2.c | 45 - .../palsuite/c_runtime/vfprintf/test2/test2.cpp | 45 + .../c_runtime/vfprintf/test3/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test3/test3.c | 45 - .../palsuite/c_runtime/vfprintf/test3/test3.cpp | 45 + .../c_runtime/vfprintf/test4/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test4/test4.c | 70 -- .../palsuite/c_runtime/vfprintf/test4/test4.cpp | 70 ++ .../c_runtime/vfprintf/test5/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test5/test5.c | 60 -- .../palsuite/c_runtime/vfprintf/test5/test5.cpp | 60 ++ .../c_runtime/vfprintf/test6/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test6/test6.c | 48 -- .../palsuite/c_runtime/vfprintf/test6/test6.cpp | 48 ++ .../c_runtime/vfprintf/test7/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test7/test7.c | 47 -- .../palsuite/c_runtime/vfprintf/test7/test7.cpp | 47 ++ .../c_runtime/vfprintf/test8/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test8/test8.c | 53 -- .../palsuite/c_runtime/vfprintf/test8/test8.cpp | 53 ++ .../c_runtime/vfprintf/test9/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vfprintf/test9/test9.c | 53 -- .../palsuite/c_runtime/vfprintf/test9/test9.cpp | 53 ++ .../tests/palsuite/c_runtime/vfprintf/vfprintf.h | 34 +- .../c_runtime/vprintf/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/vprintf/test1/test1.c | 43 - .../palsuite/c_runtime/vprintf/test1/test1.cpp | 43 + .../c_runtime/vprintf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test10/test10.c | 52 -- .../palsuite/c_runtime/vprintf/test10/test10.cpp | 52 ++ .../c_runtime/vprintf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test11/test11.c | 51 -- .../palsuite/c_runtime/vprintf/test11/test11.cpp | 51 ++ .../c_runtime/vprintf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test12/test12.c | 53 -- .../palsuite/c_runtime/vprintf/test12/test12.cpp | 53 ++ .../c_runtime/vprintf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test13/test13.c | 54 -- .../palsuite/c_runtime/vprintf/test13/test13.cpp | 54 ++ .../c_runtime/vprintf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test14/test14.c | 54 -- .../palsuite/c_runtime/vprintf/test14/test14.cpp | 54 ++ .../c_runtime/vprintf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test15/test15.c | 54 -- .../palsuite/c_runtime/vprintf/test15/test15.cpp | 54 ++ .../c_runtime/vprintf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test16/test16.c | 50 -- .../palsuite/c_runtime/vprintf/test16/test16.cpp | 50 ++ .../c_runtime/vprintf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test17/test17.c | 52 -- .../palsuite/c_runtime/vprintf/test17/test17.cpp | 52 ++ .../c_runtime/vprintf/test18/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test18/test18.c | 51 -- .../palsuite/c_runtime/vprintf/test18/test18.cpp | 51 ++ .../c_runtime/vprintf/test19/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vprintf/test19/test19.c | 76 -- .../palsuite/c_runtime/vprintf/test19/test19.cpp | 76 ++ .../c_runtime/vprintf/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/vprintf/test2/test2.c | 45 - .../palsuite/c_runtime/vprintf/test2/test2.cpp | 45 + .../c_runtime/vprintf/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/vprintf/test3/test3.c | 45 - .../palsuite/c_runtime/vprintf/test3/test3.cpp | 45 + .../c_runtime/vprintf/test4/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/vprintf/test4/test4.c | 70 -- .../palsuite/c_runtime/vprintf/test4/test4.cpp | 70 ++ .../c_runtime/vprintf/test5/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/vprintf/test5/test5.c | 60 -- .../palsuite/c_runtime/vprintf/test5/test5.cpp | 60 ++ .../c_runtime/vprintf/test6/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/vprintf/test6/test6.c | 48 -- .../palsuite/c_runtime/vprintf/test6/test6.cpp | 48 ++ .../c_runtime/vprintf/test7/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/vprintf/test7/test7.c | 47 -- .../palsuite/c_runtime/vprintf/test7/test7.cpp | 47 ++ .../c_runtime/vprintf/test8/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/vprintf/test8/test8.c | 53 -- .../palsuite/c_runtime/vprintf/test8/test8.cpp | 53 ++ .../c_runtime/vprintf/test9/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/vprintf/test9/test9.c | 53 -- .../palsuite/c_runtime/vprintf/test9/test9.cpp | 53 ++ src/pal/tests/palsuite/c_runtime/vprintf/vprintf.h | 34 +- .../c_runtime/vsprintf/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test1/test1.c | 55 -- .../palsuite/c_runtime/vsprintf/test1/test1.cpp | 55 ++ .../c_runtime/vsprintf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test10/test10.c | 50 -- .../palsuite/c_runtime/vsprintf/test10/test10.cpp | 50 ++ .../c_runtime/vsprintf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test11/test11.c | 50 -- .../palsuite/c_runtime/vsprintf/test11/test11.cpp | 50 ++ .../c_runtime/vsprintf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test12/test12.c | 52 -- .../palsuite/c_runtime/vsprintf/test12/test12.cpp | 52 ++ .../c_runtime/vsprintf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test13/test13.c | 52 -- .../palsuite/c_runtime/vsprintf/test13/test13.cpp | 52 ++ .../c_runtime/vsprintf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test14/test14.c | 50 -- .../palsuite/c_runtime/vsprintf/test14/test14.cpp | 50 ++ .../c_runtime/vsprintf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test15/test15.c | 64 -- .../palsuite/c_runtime/vsprintf/test15/test15.cpp | 64 ++ .../c_runtime/vsprintf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test16/test16.c | 49 -- .../palsuite/c_runtime/vsprintf/test16/test16.cpp | 49 ++ .../c_runtime/vsprintf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test17/test17.c | 50 -- .../palsuite/c_runtime/vsprintf/test17/test17.cpp | 50 ++ .../c_runtime/vsprintf/test18/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test18/test18.c | 50 -- .../palsuite/c_runtime/vsprintf/test18/test18.cpp | 50 ++ .../c_runtime/vsprintf/test19/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test19/test19.c | 67 -- .../palsuite/c_runtime/vsprintf/test19/test19.cpp | 67 ++ .../c_runtime/vsprintf/test2/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test2/test2.c | 42 - .../palsuite/c_runtime/vsprintf/test2/test2.cpp | 42 + .../c_runtime/vsprintf/test3/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test3/test3.c | 43 - .../palsuite/c_runtime/vsprintf/test3/test3.cpp | 43 + .../c_runtime/vsprintf/test4/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test4/test4.c | 72 -- .../palsuite/c_runtime/vsprintf/test4/test4.cpp | 72 ++ .../c_runtime/vsprintf/test5/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test5/test5.c | 43 - .../palsuite/c_runtime/vsprintf/test5/test5.cpp | 43 + .../c_runtime/vsprintf/test6/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test6/test6.c | 44 - .../palsuite/c_runtime/vsprintf/test6/test6.cpp | 44 + .../c_runtime/vsprintf/test7/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test7/test7.c | 44 - .../palsuite/c_runtime/vsprintf/test7/test7.cpp | 44 + .../c_runtime/vsprintf/test8/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test8/test8.c | 52 -- .../palsuite/c_runtime/vsprintf/test8/test8.cpp | 52 ++ .../c_runtime/vsprintf/test9/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vsprintf/test9/test9.c | 51 -- .../palsuite/c_runtime/vsprintf/test9/test9.cpp | 51 ++ .../tests/palsuite/c_runtime/vsprintf/vsprintf.h | 34 +- .../c_runtime/vswprintf/test1/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test1/test1.c | 41 - .../palsuite/c_runtime/vswprintf/test1/test1.cpp | 41 + .../c_runtime/vswprintf/test10/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test10/test10.c | 48 -- .../palsuite/c_runtime/vswprintf/test10/test10.cpp | 48 ++ .../c_runtime/vswprintf/test11/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test11/test11.c | 48 -- .../palsuite/c_runtime/vswprintf/test11/test11.cpp | 48 ++ .../c_runtime/vswprintf/test12/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test12/test12.c | 48 -- .../palsuite/c_runtime/vswprintf/test12/test12.cpp | 48 ++ .../c_runtime/vswprintf/test13/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test13/test13.c | 48 -- .../palsuite/c_runtime/vswprintf/test13/test13.cpp | 48 ++ .../c_runtime/vswprintf/test14/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test14/test14.c | 61 -- .../palsuite/c_runtime/vswprintf/test14/test14.cpp | 61 ++ .../c_runtime/vswprintf/test15/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test15/test15.c | 62 -- .../palsuite/c_runtime/vswprintf/test15/test15.cpp | 62 ++ .../c_runtime/vswprintf/test16/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test16/test16.c | 61 -- .../palsuite/c_runtime/vswprintf/test16/test16.cpp | 61 ++ .../c_runtime/vswprintf/test17/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test17/test17.c | 63 -- .../palsuite/c_runtime/vswprintf/test17/test17.cpp | 63 ++ .../c_runtime/vswprintf/test18/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test18/test18.c | 63 -- .../palsuite/c_runtime/vswprintf/test18/test18.cpp | 63 ++ .../c_runtime/vswprintf/test19/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test19/test19.c | 137 --- .../palsuite/c_runtime/vswprintf/test19/test19.cpp | 137 +++ .../c_runtime/vswprintf/test2/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test2/test2.c | 40 - .../palsuite/c_runtime/vswprintf/test2/test2.cpp | 40 + .../c_runtime/vswprintf/test3/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test3/test3.c | 40 - .../palsuite/c_runtime/vswprintf/test3/test3.cpp | 40 + .../c_runtime/vswprintf/test4/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test4/test4.c | 118 --- .../palsuite/c_runtime/vswprintf/test4/test4.cpp | 118 +++ .../c_runtime/vswprintf/test5/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test5/test5.c | 79 -- .../palsuite/c_runtime/vswprintf/test5/test5.cpp | 79 ++ .../c_runtime/vswprintf/test6/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test6/test6.c | 41 - .../palsuite/c_runtime/vswprintf/test6/test6.cpp | 41 + .../c_runtime/vswprintf/test7/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test7/test7.c | 41 - .../palsuite/c_runtime/vswprintf/test7/test7.cpp | 41 + .../c_runtime/vswprintf/test8/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test8/test8.c | 47 -- .../palsuite/c_runtime/vswprintf/test8/test8.cpp | 47 ++ .../c_runtime/vswprintf/test9/CMakeLists.txt | 2 +- .../palsuite/c_runtime/vswprintf/test9/test9.c | 47 -- .../palsuite/c_runtime/vswprintf/test9/test9.cpp | 47 ++ .../tests/palsuite/c_runtime/vswprintf/vswprintf.h | 14 +- .../palsuite/c_runtime/wcscat/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcscat/test1/test1.c | 71 -- .../palsuite/c_runtime/wcscat/test1/test1.cpp | 71 ++ .../palsuite/c_runtime/wcschr/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcschr/test1/test1.c | 51 -- .../palsuite/c_runtime/wcschr/test1/test1.cpp | 51 ++ .../palsuite/c_runtime/wcscmp/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcscmp/test1/test1.c | 57 -- .../palsuite/c_runtime/wcscmp/test1/test1.cpp | 57 ++ .../palsuite/c_runtime/wcscpy/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcscpy/test1/test1.c | 47 -- .../palsuite/c_runtime/wcscpy/test1/test1.cpp | 47 ++ .../palsuite/c_runtime/wcslen/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcslen/test1/test1.c | 49 -- .../palsuite/c_runtime/wcslen/test1/test1.cpp | 49 ++ .../c_runtime/wcsncat/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcsncat/test1/test1.c | 77 -- .../palsuite/c_runtime/wcsncat/test1/test1.cpp | 77 ++ .../c_runtime/wcsncmp/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcsncmp/test1/test1.c | 73 -- .../palsuite/c_runtime/wcsncmp/test1/test1.cpp | 73 ++ .../c_runtime/wcsncpy/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcsncpy/test1/test1.c | 84 -- .../palsuite/c_runtime/wcsncpy/test1/test1.cpp | 84 ++ .../c_runtime/wcspbrk/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcspbrk/test1/test1.c | 61 -- .../palsuite/c_runtime/wcspbrk/test1/test1.cpp | 61 ++ .../c_runtime/wcsrchr/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcsrchr/test1/test1.c | 50 -- .../palsuite/c_runtime/wcsrchr/test1/test1.cpp | 50 ++ .../palsuite/c_runtime/wcsstr/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcsstr/test1/test1.c | 62 -- .../palsuite/c_runtime/wcsstr/test1/test1.cpp | 62 ++ .../palsuite/c_runtime/wcstod/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstod/test1/test1.c | 79 -- .../palsuite/c_runtime/wcstod/test1/test1.cpp | 79 ++ .../palsuite/c_runtime/wcstod/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstod/test2/test2.c | 59 -- .../palsuite/c_runtime/wcstod/test2/test2.cpp | 59 ++ .../palsuite/c_runtime/wcstok/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstok/test1/test1.c | 114 --- .../palsuite/c_runtime/wcstok/test1/test1.cpp | 114 +++ .../palsuite/c_runtime/wcstol/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstol/test1/test1.c | 53 -- .../palsuite/c_runtime/wcstol/test1/test1.cpp | 53 ++ .../palsuite/c_runtime/wcstol/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstol/test2/test2.c | 53 -- .../palsuite/c_runtime/wcstol/test2/test2.cpp | 53 ++ .../palsuite/c_runtime/wcstol/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstol/test3/test3.c | 52 -- .../palsuite/c_runtime/wcstol/test3/test3.cpp | 52 ++ .../palsuite/c_runtime/wcstol/test4/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstol/test4/test4.c | 77 -- .../palsuite/c_runtime/wcstol/test4/test4.cpp | 77 ++ .../palsuite/c_runtime/wcstol/test5/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstol/test5/test5.c | 76 -- .../palsuite/c_runtime/wcstol/test5/test5.cpp | 76 ++ .../palsuite/c_runtime/wcstol/test6/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstol/test6/test6.c | 86 -- .../palsuite/c_runtime/wcstol/test6/test6.cpp | 86 ++ .../c_runtime/wcstoul/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstoul/test1/test1.c | 49 -- .../palsuite/c_runtime/wcstoul/test1/test1.cpp | 49 ++ .../c_runtime/wcstoul/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstoul/test2/test2.c | 49 -- .../palsuite/c_runtime/wcstoul/test2/test2.cpp | 49 ++ .../c_runtime/wcstoul/test3/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstoul/test3/test3.c | 49 -- .../palsuite/c_runtime/wcstoul/test3/test3.cpp | 49 ++ .../c_runtime/wcstoul/test4/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstoul/test4/test4.c | 52 -- .../palsuite/c_runtime/wcstoul/test4/test4.cpp | 52 ++ .../c_runtime/wcstoul/test5/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstoul/test5/test5.c | 69 -- .../palsuite/c_runtime/wcstoul/test5/test5.cpp | 69 ++ .../c_runtime/wcstoul/test6/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wcstoul/test6/test6.c | 83 -- .../palsuite/c_runtime/wcstoul/test6/test6.cpp | 83 ++ .../c_runtime/wprintf/test1/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wprintf/test1/test1.c | 47 -- .../palsuite/c_runtime/wprintf/test1/test1.cpp | 47 ++ .../c_runtime/wprintf/test2/CMakeLists.txt | 2 +- .../tests/palsuite/c_runtime/wprintf/test2/test2.c | 45 - .../palsuite/c_runtime/wprintf/test2/test2.cpp | 45 + src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h | 32 +- src/pal/tests/palsuite/common/palsuite.h | 6 +- .../event/nonshared/CMakeLists.txt | 4 +- .../object_management/event/nonshared/event.c | 358 -------- .../object_management/event/nonshared/event.cpp | 358 ++++++++ .../object_management/event/nonshared/main.c | 228 ----- .../object_management/event/nonshared/main.cpp | 228 +++++ .../object_management/event/shared/CMakeLists.txt | 4 +- .../object_management/event/shared/event.c | 373 --------- .../object_management/event/shared/event.cpp | 373 +++++++++ .../object_management/event/shared/main.c | 265 ------ .../object_management/event/shared/main.cpp | 265 ++++++ .../mutex/nonshared/CMakeLists.txt | 4 +- .../object_management/mutex/nonshared/main.c | 230 ------ .../object_management/mutex/nonshared/main.cpp | 230 ++++++ .../object_management/mutex/nonshared/mutex.c | 340 -------- .../object_management/mutex/nonshared/mutex.cpp | 340 ++++++++ .../object_management/mutex/shared/CMakeLists.txt | 4 +- .../object_management/mutex/shared/main.c | 265 ------ .../object_management/mutex/shared/main.cpp | 265 ++++++ .../object_management/mutex/shared/mutex.c | 354 -------- .../object_management/mutex/shared/mutex.cpp | 354 ++++++++ .../semaphore/nonshared/CMakeLists.txt | 4 +- .../object_management/semaphore/nonshared/main.c | 228 ----- .../object_management/semaphore/nonshared/main.cpp | 228 +++++ .../semaphore/nonshared/semaphore.c | 342 -------- .../semaphore/nonshared/semaphore.cpp | 342 ++++++++ .../semaphore/shared/CMakeLists.txt | 4 +- .../object_management/semaphore/shared/main.c | 278 ------- .../object_management/semaphore/shared/main.cpp | 278 +++++++ .../object_management/semaphore/shared/semaphore.c | 351 -------- .../semaphore/shared/semaphore.cpp | 351 ++++++++ .../synchronization/criticalsection/CMakeLists.txt | 4 +- .../criticalsection/criticalsection.c | 418 ---------- .../criticalsection/criticalsection.cpp | 418 ++++++++++ .../synchronization/criticalsection/mainWrapper.c | 255 ------ .../criticalsection/mainWrapper.cpp | 255 ++++++ .../nativecriticalsection/CMakeLists.txt | 2 +- .../pal_composite_native_cs.c | 471 ----------- .../pal_composite_native_cs.cpp | 471 +++++++++++ .../nativecs_interlocked/CMakeLists.txt | 2 +- .../nativecs_interlocked/pal_composite_native_cs.c | 475 ----------- .../pal_composite_native_cs.cpp | 475 +++++++++++ .../threading/threadsuspension/CMakeLists.txt | 4 +- .../threading/threadsuspension/mainWrapper.c | 274 ------ .../threading/threadsuspension/mainWrapper.cpp | 274 ++++++ .../threading/threadsuspension/threadsuspension.c | 907 -------------------- .../threadsuspension/threadsuspension.cpp | 907 ++++++++++++++++++++ .../threadsuspension_switchthread/CMakeLists.txt | 4 +- .../threadsuspension_switchthread/mainWrapper.c | 274 ------ .../threadsuspension_switchthread/mainWrapper.cpp | 274 ++++++ .../threadsuspension.c | 914 --------------------- .../threadsuspension.cpp | 914 +++++++++++++++++++++ .../tests/palsuite/composite/wfmo/CMakeLists.txt | 4 +- src/pal/tests/palsuite/composite/wfmo/main.c | 239 ------ src/pal/tests/palsuite/composite/wfmo/main.cpp | 239 ++++++ src/pal/tests/palsuite/composite/wfmo/mutex.c | 365 -------- src/pal/tests/palsuite/composite/wfmo/mutex.cpp | 365 ++++++++ .../debug_api/DebugBreak/test1/CMakeLists.txt | 2 +- .../palsuite/debug_api/DebugBreak/test1/test1.c | 47 -- .../palsuite/debug_api/DebugBreak/test1/test1.cpp | 47 ++ .../OutputDebugStringA/test1/CMakeLists.txt | 4 +- .../debug_api/OutputDebugStringA/test1/helper.c | 35 - .../debug_api/OutputDebugStringA/test1/helper.cpp | 35 + .../debug_api/OutputDebugStringA/test1/test1.c | 94 --- .../debug_api/OutputDebugStringA/test1/test1.cpp | 94 +++ .../OutputDebugStringW/test1/CMakeLists.txt | 2 +- .../debug_api/OutputDebugStringW/test1/test1.c | 41 - .../debug_api/OutputDebugStringW/test1/test1.cpp | 41 + .../WriteProcessMemory/test1/CMakeLists.txt | 4 +- .../debug_api/WriteProcessMemory/test1/helper.c | 243 ------ .../debug_api/WriteProcessMemory/test1/helper.cpp | 243 ++++++ .../debug_api/WriteProcessMemory/test1/test1.c | 189 ----- .../debug_api/WriteProcessMemory/test1/test1.cpp | 189 +++++ .../WriteProcessMemory/test3/CMakeLists.txt | 4 +- .../debug_api/WriteProcessMemory/test3/helper.c | 256 ------ .../debug_api/WriteProcessMemory/test3/helper.cpp | 256 ++++++ .../debug_api/WriteProcessMemory/test3/test3.c | 205 ----- .../debug_api/WriteProcessMemory/test3/test3.cpp | 205 +++++ .../WriteProcessMemory/test4/CMakeLists.txt | 4 +- .../debug_api/WriteProcessMemory/test4/helper.c | 67 -- .../debug_api/WriteProcessMemory/test4/helper.cpp | 67 ++ .../debug_api/WriteProcessMemory/test4/test4.c | 124 --- .../debug_api/WriteProcessMemory/test4/test4.cpp | 124 +++ .../PAL_EXCEPT_FILTER/test1/CMakeLists.txt | 2 +- .../PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.c | 118 --- .../PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.cpp | 118 +++ .../PAL_EXCEPT_FILTER/test2/CMakeLists.txt | 2 +- .../PAL_EXCEPT_FILTER/test2/pal_except_filter.c | 154 ---- .../PAL_EXCEPT_FILTER/test2/pal_except_filter.cpp | 154 ++++ .../PAL_EXCEPT_FILTER/test3/CMakeLists.txt | 2 +- .../PAL_EXCEPT_FILTER/test3/pal_except_filter.c | 206 ----- .../PAL_EXCEPT_FILTER/test3/pal_except_filter.cpp | 206 +++++ .../PAL_EXCEPT_FILTER_EX/test1/CMakeLists.txt | 2 +- .../test1/PAL_EXCEPT_FILTER_EX.c | 197 ----- .../test1/PAL_EXCEPT_FILTER_EX.cpp | 197 +++++ .../PAL_EXCEPT_FILTER_EX/test2/CMakeLists.txt | 2 +- .../test2/pal_except_filter_ex.c | 142 ---- .../test2/pal_except_filter_ex.cpp | 142 ++++ .../PAL_EXCEPT_FILTER_EX/test3/CMakeLists.txt | 2 +- .../PAL_EXCEPT_FILTER_EX/test3/pal_except_filter.c | 208 ----- .../test3/pal_except_filter.cpp | 208 +++++ .../PAL_TRY_EXCEPT/test1/CMakeLists.txt | 2 +- .../PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.c | 82 -- .../PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.cpp | 82 ++ .../PAL_TRY_EXCEPT/test2/CMakeLists.txt | 2 +- .../PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.c | 68 -- .../PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.cpp | 68 ++ .../PAL_TRY_EXCEPT_EX/test1/CMakeLists.txt | 2 +- .../PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.c | 133 --- .../PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.cpp | 133 +++ .../PAL_TRY_EXCEPT_EX/test2/CMakeLists.txt | 2 +- .../PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.c | 123 --- .../PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.cpp | 123 +++ .../PAL_TRY_EXCEPT_EX/test3/CMakeLists.txt | 2 +- .../PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.c | 130 --- .../PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.cpp | 130 +++ .../PAL_TRY_LEAVE_FINALLY/test1/CMakeLists.txt | 2 +- .../test1/PAL_TRY_LEAVE_FINALLY.c | 77 -- .../test1/PAL_TRY_LEAVE_FINALLY.cpp | 77 ++ .../test1/CMakeLists.txt | 2 +- .../SetUnhandledExceptionFilter/test1/test1.c | 82 -- .../SetUnhandledExceptionFilter/test1/test1.cpp | 82 ++ .../pal_except/test1/CMakeLists.txt | 2 +- .../exception_handling/pal_except/test1/test1.c | 67 -- .../exception_handling/pal_except/test1/test1.cpp | 67 ++ .../pal_except/test2/CMakeLists.txt | 2 +- .../exception_handling/pal_except/test2/test2.c | 111 --- .../exception_handling/pal_except/test2/test2.cpp | 111 +++ .../pal_except/test3/CMakeLists.txt | 2 +- .../exception_handling/pal_except/test3/test3.c | 120 --- .../exception_handling/pal_except/test3/test3.cpp | 120 +++ .../pal_except/test4/CMakeLists.txt | 2 +- .../exception_handling/pal_except/test4/test4.c | 105 --- .../exception_handling/pal_except/test4/test4.cpp | 105 +++ .../pal_except/test5/CMakeLists.txt | 2 +- .../exception_handling/pal_except/test5/test5.c | 112 --- .../exception_handling/pal_except/test5/test5.cpp | 112 +++ .../pal_except/test6/CMakeLists.txt | 2 +- .../exception_handling/pal_except/test6/test6.c | 160 ---- .../exception_handling/pal_except/test6/test6.cpp | 160 ++++ .../pal_except/test7/CMakeLists.txt | 2 +- .../exception_handling/pal_except/test7/test7.c | 67 -- .../exception_handling/pal_except/test7/test7.cpp | 67 ++ .../pal_finally/test1/CMakeLists.txt | 2 +- .../pal_finally/test1/pal_finally.c | 302 ------- .../pal_finally/test1/pal_finally.cpp | 302 +++++++ .../exception_handling/pal_sxs/test1/dlltest1.cpp | 14 +- .../exception_handling/pal_sxs/test1/dlltest2.cpp | 14 +- .../AreFileApisANSI/test1/AreFileApisANSI.c | 40 - .../AreFileApisANSI/test1/AreFileApisANSI.cpp | 40 + .../file_io/AreFileApisANSI/test1/CMakeLists.txt | 2 +- .../file_io/CompareFileTime/test1/CMakeLists.txt | 2 +- .../CompareFileTime/test1/CompareFileTime.c | 68 -- .../CompareFileTime/test1/CompareFileTime.cpp | 68 ++ .../file_io/CopyFileA/test1/CMakeLists.txt | 2 +- .../palsuite/file_io/CopyFileA/test1/CopyFileA.c | 159 ---- .../palsuite/file_io/CopyFileA/test1/CopyFileA.cpp | 159 ++++ .../file_io/CopyFileA/test2/CMakeLists.txt | 2 +- .../tests/palsuite/file_io/CopyFileA/test2/test2.c | 120 --- .../palsuite/file_io/CopyFileA/test2/test2.cpp | 120 +++ .../file_io/CopyFileA/test3/CMakeLists.txt | 2 +- .../tests/palsuite/file_io/CopyFileA/test3/test3.c | 141 ---- .../palsuite/file_io/CopyFileA/test3/test3.cpp | 141 ++++ .../file_io/CopyFileA/test4/CMakeLists.txt | 2 +- .../tests/palsuite/file_io/CopyFileA/test4/test4.c | 180 ---- .../palsuite/file_io/CopyFileA/test4/test4.cpp | 180 ++++ .../file_io/CopyFileW/test1/CMakeLists.txt | 2 +- .../palsuite/file_io/CopyFileW/test1/CopyFileW.c | 155 ---- .../palsuite/file_io/CopyFileW/test1/CopyFileW.cpp | 155 ++++ .../file_io/CopyFileW/test2/CMakeLists.txt | 2 +- .../tests/palsuite/file_io/CopyFileW/test2/test2.c | 124 --- .../palsuite/file_io/CopyFileW/test2/test2.cpp | 124 +++ .../file_io/CopyFileW/test3/CMakeLists.txt | 2 +- .../tests/palsuite/file_io/CopyFileW/test3/test3.c | 196 ----- .../palsuite/file_io/CopyFileW/test3/test3.cpp | 196 +++++ .../file_io/CreateDirectoryA/test1/CMakeLists.txt | 2 +- .../CreateDirectoryA/test1/CreateDirectoryA.c | 296 ------- .../CreateDirectoryA/test1/CreateDirectoryA.cpp | 296 +++++++ .../file_io/CreateDirectoryA/test2/CMakeLists.txt | 2 +- .../CreateDirectoryA/test2/createdirectorya.c | 335 -------- .../CreateDirectoryA/test2/createdirectorya.cpp | 335 ++++++++ .../file_io/CreateDirectoryW/test1/CMakeLists.txt | 2 +- .../CreateDirectoryW/test1/CreateDirectoryW.c | 347 -------- .../CreateDirectoryW/test1/CreateDirectoryW.cpp | 347 ++++++++ .../file_io/CreateDirectoryW/test2/CMakeLists.txt | 2 +- .../CreateDirectoryW/test2/createdirectoryw.c | 345 -------- .../CreateDirectoryW/test2/createdirectoryw.cpp | 345 ++++++++ .../file_io/CreateFileA/test1/CMakeLists.txt | 2 +- .../file_io/CreateFileA/test1/CreateFileA.c | 145 ---- .../file_io/CreateFileA/test1/CreateFileA.cpp | 145 ++++ .../file_io/CreateFileW/test1/CMakeLists.txt | 2 +- .../file_io/CreateFileW/test1/CreateFileW.c | 152 ---- .../file_io/CreateFileW/test1/CreateFileW.cpp | 152 ++++ .../file_io/DeleteFileW/test1/CMakeLists.txt | 2 +- .../file_io/DeleteFileW/test1/DeleteFileW.c | 164 ---- .../file_io/DeleteFileW/test1/DeleteFileW.cpp | 164 ++++ .../file_io/FILECanonicalizePath/CMakeLists.txt | 2 +- .../FILECanonicalizePath/FILECanonicalizePath.c | 83 -- .../FILECanonicalizePath/FILECanonicalizePath.cpp | 83 ++ .../FileTimeToDosDateTime/test1/CMakeLists.txt | 2 +- .../file_io/FileTimeToDosDateTime/test1/test1.c | 116 --- .../file_io/FileTimeToDosDateTime/test1/test1.cpp | 116 +++ .../file_io/FindClose/test1/CMakeLists.txt | 2 +- .../palsuite/file_io/FindClose/test1/FindClose.c | 275 ------- .../palsuite/file_io/FindClose/test1/FindClose.cpp | 275 +++++++ .../file_io/FindFirstFileA/test1/CMakeLists.txt | 2 +- .../file_io/FindFirstFileA/test1/FindFirstFileA.c | 206 ----- .../FindFirstFileA/test1/FindFirstFileA.cpp | 206 +++++ .../file_io/FindFirstFileW/test1/CMakeLists.txt | 2 +- .../file_io/FindFirstFileW/test1/FindFirstFileW.c | 212 ----- .../FindFirstFileW/test1/FindFirstFileW.cpp | 212 +++++ .../file_io/FindNextFileA/test1/CMakeLists.txt | 2 +- .../file_io/FindNextFileA/test1/FindNextFileA.c | 243 ------ .../file_io/FindNextFileA/test1/FindNextFileA.cpp | 243 ++++++ .../file_io/FindNextFileA/test2/CMakeLists.txt | 2 +- .../file_io/FindNextFileA/test2/findnextfilea.c | 107 --- .../file_io/FindNextFileA/test2/findnextfilea.cpp | 107 +++ .../file_io/FindNextFileW/test1/CMakeLists.txt | 2 +- .../file_io/FindNextFileW/test1/FindNextFileW.c | 249 ------ .../file_io/FindNextFileW/test1/FindNextFileW.cpp | 249 ++++++ .../file_io/FindNextFileW/test2/CMakeLists.txt | 2 +- .../file_io/FindNextFileW/test2/findnextfilew.c | 107 --- .../file_io/FindNextFileW/test2/findnextfilew.cpp | 107 +++ .../file_io/FlushFileBuffers/test1/CMakeLists.txt | 2 +- .../FlushFileBuffers/test1/FlushFileBuffers.c | 130 --- .../FlushFileBuffers/test1/FlushFileBuffers.cpp | 130 +++ .../file_io/GetConsoleCP/test1/CMakeLists.txt | 2 +- .../file_io/GetConsoleCP/test1/GetConsoleCP.c | 35 - .../file_io/GetConsoleCP/test1/GetConsoleCP.cpp | 35 + .../GetConsoleOutputCP/test1/CMakeLists.txt | 2 +- .../GetConsoleOutputCP/test1/GetConsoleOutputCP.c | 35 - .../test1/GetConsoleOutputCP.cpp | 35 + .../GetCurrentDirectoryA/test1/CMakeLists.txt | 2 +- .../test1/GetCurrentDirectoryA.c | 97 --- .../test1/GetCurrentDirectoryA.cpp | 97 +++ .../GetCurrentDirectoryW/test1/CMakeLists.txt | 2 +- .../test1/GetCurrentDirectoryW.c | 106 --- .../test1/GetCurrentDirectoryW.cpp | 106 +++ .../file_io/GetDiskFreeSpaceW/test1/CMakeLists.txt | 2 +- .../GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.c | 94 --- .../GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.cpp | 94 +++ .../file_io/GetDiskFreeSpaceW/test2/CMakeLists.txt | 2 +- .../GetDiskFreeSpaceW/test2/getdiskfreespacew.c | 65 -- .../GetDiskFreeSpaceW/test2/getdiskfreespacew.cpp | 65 ++ .../GetFileAttributesA/test1/CMakeLists.txt | 2 +- .../GetFileAttributesA/test1/GetFileAttributesA.c | 340 -------- .../test1/GetFileAttributesA.cpp | 340 ++++++++ .../GetFileAttributesExW/test1/CMakeLists.txt | 2 +- .../file_io/GetFileAttributesExW/test1/test1.c | 227 ----- .../file_io/GetFileAttributesExW/test1/test1.cpp | 227 +++++ .../GetFileAttributesExW/test2/CMakeLists.txt | 2 +- .../file_io/GetFileAttributesExW/test2/test2.c | 170 ---- .../file_io/GetFileAttributesExW/test2/test2.cpp | 170 ++++ .../GetFileAttributesW/test1/CMakeLists.txt | 2 +- .../GetFileAttributesW/test1/GetFileAttributesW.c | 345 -------- .../test1/GetFileAttributesW.cpp | 345 ++++++++ .../file_io/GetFileSize/test1/CMakeLists.txt | 2 +- .../file_io/GetFileSize/test1/GetFileSize.c | 173 ---- .../file_io/GetFileSize/test1/GetFileSize.cpp | 173 ++++ .../file_io/GetFileSizeEx/test1/CMakeLists.txt | 2 +- .../file_io/GetFileSizeEx/test1/GetFileSizeEx.c | 173 ---- .../file_io/GetFileSizeEx/test1/GetFileSizeEx.cpp | 173 ++++ .../file_io/GetFileTime/test1/CMakeLists.txt | 2 +- .../file_io/GetFileTime/test1/GetFileTime.c | 180 ---- .../file_io/GetFileTime/test1/GetFileTime.cpp | 180 ++++ .../file_io/GetFileTime/test2/CMakeLists.txt | 2 +- .../file_io/GetFileTime/test2/GetFileTime.c | 195 ----- .../file_io/GetFileTime/test2/GetFileTime.cpp | 195 +++++ .../file_io/GetFileTime/test3/CMakeLists.txt | 2 +- .../file_io/GetFileTime/test3/GetFileTime.c | 142 ---- .../file_io/GetFileTime/test3/GetFileTime.cpp | 142 ++++ .../file_io/GetFileTime/test4/CMakeLists.txt | 2 +- .../file_io/GetFileTime/test4/GetFileTime.c | 98 --- .../file_io/GetFileTime/test4/GetFileTime.cpp | 98 +++ .../file_io/GetFileTime/test5/CMakeLists.txt | 2 +- .../file_io/GetFileTime/test5/getfiletime.c | 224 ----- .../file_io/GetFileTime/test5/getfiletime.cpp | 224 +++++ .../file_io/GetFileTime/test6/CMakeLists.txt | 2 +- .../file_io/GetFileTime/test6/getfiletime.c | 281 ------- .../file_io/GetFileTime/test6/getfiletime.cpp | 281 +++++++ .../file_io/GetFileTime/test7/CMakeLists.txt | 2 +- .../file_io/GetFileTime/test7/getfiletime.c | 279 ------- .../file_io/GetFileTime/test7/getfiletime.cpp | 279 +++++++ .../file_io/GetFileType/test1/CMakeLists.txt | 2 +- .../file_io/GetFileType/test1/GetFileType.c | 76 -- .../file_io/GetFileType/test1/GetFileType.cpp | 76 ++ .../file_io/GetFileType/test2/CMakeLists.txt | 2 +- .../file_io/GetFileType/test2/getfiletype.c | 95 --- .../file_io/GetFileType/test2/getfiletype.cpp | 95 +++ .../file_io/GetFileType/test3/CMakeLists.txt | 2 +- .../file_io/GetFileType/test3/getfiletype.c | 72 -- .../file_io/GetFileType/test3/getfiletype.cpp | 72 ++ .../file_io/GetFullPathNameA/test1/CMakeLists.txt | 2 +- .../GetFullPathNameA/test1/GetFullPathNameA.c | 122 --- .../GetFullPathNameA/test1/GetFullPathNameA.cpp | 122 +++ .../file_io/GetFullPathNameA/test2/CMakeLists.txt | 2 +- .../file_io/GetFullPathNameA/test2/test2.c | 143 ---- .../file_io/GetFullPathNameA/test2/test2.cpp | 143 ++++ .../file_io/GetFullPathNameA/test3/CMakeLists.txt | 2 +- .../file_io/GetFullPathNameA/test3/test3.c | 241 ------ .../file_io/GetFullPathNameA/test3/test3.cpp | 241 ++++++ .../file_io/GetFullPathNameA/test4/CMakeLists.txt | 2 +- .../file_io/GetFullPathNameA/test4/test4.c | 203 ----- .../file_io/GetFullPathNameA/test4/test4.cpp | 203 +++++ .../file_io/GetFullPathNameW/test1/CMakeLists.txt | 2 +- .../GetFullPathNameW/test1/GetFullPathNameW.c | 157 ---- .../GetFullPathNameW/test1/GetFullPathNameW.cpp | 157 ++++ .../file_io/GetFullPathNameW/test2/CMakeLists.txt | 2 +- .../file_io/GetFullPathNameW/test2/test2.c | 159 ---- .../file_io/GetFullPathNameW/test2/test2.cpp | 159 ++++ .../file_io/GetFullPathNameW/test3/CMakeLists.txt | 2 +- .../file_io/GetFullPathNameW/test3/test3.c | 240 ------ .../file_io/GetFullPathNameW/test3/test3.cpp | 240 ++++++ .../file_io/GetFullPathNameW/test4/CMakeLists.txt | 2 +- .../file_io/GetFullPathNameW/test4/test4.c | 201 ----- .../file_io/GetFullPathNameW/test4/test4.cpp | 201 +++++ .../file_io/GetLongPathNameW/test1/CMakeLists.txt | 2 +- .../GetLongPathNameW/test1/GetLongPathNameW.c | 280 ------- .../GetLongPathNameW/test1/GetLongPathNameW.cpp | 280 +++++++ .../file_io/GetLongPathNameW/test2/CMakeLists.txt | 2 +- .../GetLongPathNameW/test2/getlongpathnamew.c | 266 ------ .../GetLongPathNameW/test2/getlongpathnamew.cpp | 266 ++++++ .../file_io/GetStdHandle/test1/CMakeLists.txt | 2 +- .../file_io/GetStdHandle/test1/GetStdHandle.c | 132 --- .../file_io/GetStdHandle/test1/GetStdHandle.cpp | 132 +++ .../file_io/GetStdHandle/test2/CMakeLists.txt | 2 +- .../file_io/GetStdHandle/test2/GetStdHandle.c | 79 -- .../file_io/GetStdHandle/test2/GetStdHandle.cpp | 79 ++ .../file_io/GetSystemTime/test1/CMakeLists.txt | 2 +- .../palsuite/file_io/GetSystemTime/test1/test.c | 124 --- .../palsuite/file_io/GetSystemTime/test1/test.cpp | 124 +++ .../GetSystemTimeAsFileTime/test1/CMakeLists.txt | 2 +- .../test1/GetSystemTimeAsFileTime.c | 86 -- .../test1/GetSystemTimeAsFileTime.cpp | 86 ++ .../file_io/GetTempFileNameA/test1/CMakeLists.txt | 2 +- .../GetTempFileNameA/test1/GetTempFileNameA.c | 125 --- .../GetTempFileNameA/test1/GetTempFileNameA.cpp | 125 +++ .../file_io/GetTempFileNameA/test2/CMakeLists.txt | 2 +- .../GetTempFileNameA/test2/GetTempFileNameA.c | 80 -- .../GetTempFileNameA/test2/GetTempFileNameA.cpp | 80 ++ .../file_io/GetTempFileNameA/test3/CMakeLists.txt | 2 +- .../GetTempFileNameA/test3/gettempfilenamea.c | 159 ---- .../GetTempFileNameA/test3/gettempfilenamea.cpp | 159 ++++ .../file_io/GetTempFileNameW/test1/CMakeLists.txt | 2 +- .../GetTempFileNameW/test1/GetTempFileNameW.c | 129 --- .../GetTempFileNameW/test1/GetTempFileNameW.cpp | 129 +++ .../file_io/GetTempFileNameW/test2/CMakeLists.txt | 2 +- .../GetTempFileNameW/test2/GetTempFileNameW.c | 84 -- .../GetTempFileNameW/test2/GetTempFileNameW.cpp | 84 ++ .../file_io/GetTempFileNameW/test3/CMakeLists.txt | 2 +- .../GetTempFileNameW/test3/gettempfilenamew.c | 161 ---- .../GetTempFileNameW/test3/gettempfilenamew.cpp | 161 ++++ .../file_io/GetTempPathW/test1/CMakeLists.txt | 2 +- .../file_io/GetTempPathW/test1/GetTempPathW.c | 103 --- .../file_io/GetTempPathW/test1/GetTempPathW.cpp | 103 +++ .../file_io/MoveFileA/test1/CMakeLists.txt | 2 +- .../palsuite/file_io/MoveFileA/test1/MoveFileA.c | 469 ----------- .../palsuite/file_io/MoveFileA/test1/MoveFileA.cpp | 469 +++++++++++ .../file_io/MoveFileExA/test1/CMakeLists.txt | 2 +- .../file_io/MoveFileExA/test1/MoveFileExA.c | 360 -------- .../file_io/MoveFileExA/test1/MoveFileExA.cpp | 360 ++++++++ .../file_io/MoveFileExW/test1/CMakeLists.txt | 2 +- .../file_io/MoveFileExW/test1/MoveFileExW.c | 431 ---------- .../file_io/MoveFileExW/test1/MoveFileExW.cpp | 431 ++++++++++ .../file_io/MoveFileW/test1/CMakeLists.txt | 2 +- .../palsuite/file_io/MoveFileW/test1/MoveFileW.c | 478 ----------- .../palsuite/file_io/MoveFileW/test1/MoveFileW.cpp | 478 +++++++++++ .../palsuite/file_io/ReadFile/test1/CMakeLists.txt | 2 +- .../palsuite/file_io/ReadFile/test1/ReadFile.c | 82 -- .../palsuite/file_io/ReadFile/test1/ReadFile.cpp | 82 ++ .../palsuite/file_io/ReadFile/test2/CMakeLists.txt | 2 +- .../palsuite/file_io/ReadFile/test2/ReadFile.c | 198 ----- .../palsuite/file_io/ReadFile/test2/ReadFile.cpp | 198 +++++ .../palsuite/file_io/ReadFile/test3/CMakeLists.txt | 2 +- .../palsuite/file_io/ReadFile/test3/ReadFile.c | 184 ----- .../palsuite/file_io/ReadFile/test3/ReadFile.cpp | 184 +++++ .../palsuite/file_io/ReadFile/test4/CMakeLists.txt | 2 +- .../palsuite/file_io/ReadFile/test4/readfile.c | 147 ---- .../palsuite/file_io/ReadFile/test4/readfile.cpp | 147 ++++ .../RemoveDirectoryA/test1/RemoveDirectoryA.cpp | 12 +- .../file_io/RemoveDirectoryW/test1/CMakeLists.txt | 2 +- .../RemoveDirectoryW/test1/RemoveDirectoryW.c | 282 ------- .../RemoveDirectoryW/test1/RemoveDirectoryW.cpp | 282 +++++++ .../file_io/SearchPathA/test1/CMakeLists.txt | 2 +- .../file_io/SearchPathA/test1/SearchPathA.c | 144 ---- .../file_io/SearchPathA/test1/SearchPathA.cpp | 139 ++++ .../file_io/SearchPathW/test1/CMakeLists.txt | 2 +- .../file_io/SearchPathW/test1/SearchPathW.c | 198 ----- .../file_io/SearchPathW/test1/SearchPathW.cpp | 193 +++++ .../SetCurrentDirectoryA/test1/CMakeLists.txt | 2 +- .../test1/SetCurrentDirectoryA.c | 215 ----- .../test1/SetCurrentDirectoryA.cpp | 215 +++++ .../SetCurrentDirectoryA/test2/CMakeLists.txt | 2 +- .../test2/setcurrentdirectorya.c | 142 ---- .../test2/setcurrentdirectorya.cpp | 142 ++++ .../SetCurrentDirectoryA/test3/CMakeLists.txt | 2 +- .../test3/setcurrentdirectorya.c | 56 -- .../test3/setcurrentdirectorya.cpp | 56 ++ .../SetCurrentDirectoryW/test1/CMakeLists.txt | 2 +- .../test1/SetCurrentDirectoryW.c | 178 ---- .../test1/SetCurrentDirectoryW.cpp | 178 ++++ .../SetCurrentDirectoryW/test2/CMakeLists.txt | 2 +- .../test2/setcurrentdirectoryw.c | 147 ---- .../test2/setcurrentdirectoryw.cpp | 147 ++++ .../SetCurrentDirectoryW/test3/CMakeLists.txt | 2 +- .../test3/setcurrentdirectoryw.c | 64 -- .../test3/setcurrentdirectoryw.cpp | 64 ++ .../file_io/SetEndOfFile/test1/CMakeLists.txt | 2 +- .../file_io/SetEndOfFile/test1/SetEndOfFile.c | 85 -- .../file_io/SetEndOfFile/test1/SetEndOfFile.cpp | 85 ++ .../file_io/SetEndOfFile/test2/CMakeLists.txt | 2 +- .../file_io/SetEndOfFile/test2/SetEndOfFile.c | 154 ---- .../file_io/SetEndOfFile/test2/SetEndOfFile.cpp | 154 ++++ .../file_io/SetEndOfFile/test3/CMakeLists.txt | 2 +- .../file_io/SetEndOfFile/test3/SetEndOfFile.c | 109 --- .../file_io/SetEndOfFile/test3/SetEndOfFile.cpp | 109 +++ .../file_io/SetEndOfFile/test4/CMakeLists.txt | 2 +- .../file_io/SetEndOfFile/test4/setendoffile.c | 138 ---- .../file_io/SetEndOfFile/test4/setendoffile.cpp | 138 ++++ .../file_io/SetEndOfFile/test5/CMakeLists.txt | 2 +- .../palsuite/file_io/SetEndOfFile/test5/test5.c | 183 ----- .../palsuite/file_io/SetEndOfFile/test5/test5.cpp | 183 +++++ .../SetFileAttributesA/test1/CMakeLists.txt | 2 +- .../SetFileAttributesA/test1/SetFileAttributesA.c | 168 ---- .../test1/SetFileAttributesA.cpp | 168 ++++ .../SetFileAttributesA/test2/CMakeLists.txt | 2 +- .../SetFileAttributesA/test2/SetFileAttributesA.c | 114 --- .../test2/SetFileAttributesA.cpp | 114 +++ .../SetFileAttributesA/test3/CMakeLists.txt | 2 +- .../SetFileAttributesA/test3/SetFileAttributesA.c | 48 -- .../test3/SetFileAttributesA.cpp | 48 ++ .../SetFileAttributesA/test4/CMakeLists.txt | 2 +- .../SetFileAttributesA/test4/SetFileAttributesA.c | 128 --- .../test4/SetFileAttributesA.cpp | 128 +++ .../SetFileAttributesW/test1/CMakeLists.txt | 2 +- .../SetFileAttributesW/test1/SetFileAttributesW.c | 167 ---- .../test1/SetFileAttributesW.cpp | 167 ++++ .../SetFileAttributesW/test2/CMakeLists.txt | 2 +- .../SetFileAttributesW/test2/SetFileAttributesW.c | 121 --- .../test2/SetFileAttributesW.cpp | 121 +++ .../SetFileAttributesW/test3/CMakeLists.txt | 2 +- .../SetFileAttributesW/test3/SetFileAttributesW.c | 57 -- .../test3/SetFileAttributesW.cpp | 57 ++ .../SetFileAttributesW/test4/CMakeLists.txt | 2 +- .../SetFileAttributesW/test4/SetFileAttributesW.c | 133 --- .../test4/SetFileAttributesW.cpp | 133 +++ .../file_io/SetFilePointer/test1/CMakeLists.txt | 2 +- .../file_io/SetFilePointer/test1/SetFilePointer.c | 123 --- .../SetFilePointer/test1/SetFilePointer.cpp | 123 +++ .../file_io/SetFilePointer/test2/CMakeLists.txt | 2 +- .../file_io/SetFilePointer/test2/SetFilePointer.c | 356 -------- .../SetFilePointer/test2/SetFilePointer.cpp | 356 ++++++++ .../file_io/SetFilePointer/test3/CMakeLists.txt | 2 +- .../file_io/SetFilePointer/test3/SetFilePointer.c | 350 -------- .../SetFilePointer/test3/SetFilePointer.cpp | 350 ++++++++ .../file_io/SetFilePointer/test4/CMakeLists.txt | 2 +- .../file_io/SetFilePointer/test4/SetFilePointer.c | 242 ------ .../SetFilePointer/test4/SetFilePointer.cpp | 242 ++++++ .../file_io/SetFilePointer/test5/CMakeLists.txt | 2 +- .../file_io/SetFilePointer/test5/SetFilePointer.c | 182 ---- .../SetFilePointer/test5/SetFilePointer.cpp | 182 ++++ .../file_io/SetFilePointer/test6/CMakeLists.txt | 2 +- .../file_io/SetFilePointer/test6/SetFilePointer.c | 213 ----- .../SetFilePointer/test6/SetFilePointer.cpp | 213 +++++ .../file_io/SetFilePointer/test7/CMakeLists.txt | 2 +- .../file_io/SetFilePointer/test7/SetFilePointer.c | 213 ----- .../SetFilePointer/test7/SetFilePointer.cpp | 213 +++++ .../file_io/SetFileTime/test1/CMakeLists.txt | 2 +- .../file_io/SetFileTime/test1/SetFileTime.c | 129 --- .../file_io/SetFileTime/test1/SetFileTime.cpp | 129 +++ .../file_io/SetFileTime/test2/CMakeLists.txt | 2 +- .../file_io/SetFileTime/test2/SetFileTime.c | 101 --- .../file_io/SetFileTime/test2/SetFileTime.cpp | 101 +++ .../file_io/SetFileTime/test3/CMakeLists.txt | 2 +- .../file_io/SetFileTime/test3/SetFileTime.c | 66 -- .../file_io/SetFileTime/test3/SetFileTime.cpp | 66 ++ .../file_io/SetFileTime/test4/CMakeLists.txt | 2 +- .../file_io/SetFileTime/test4/SetFileTime.c | 108 --- .../file_io/SetFileTime/test4/SetFileTime.cpp | 108 +++ .../file_io/WriteFile/test1/CMakeLists.txt | 2 +- .../palsuite/file_io/WriteFile/test1/WriteFile.c | 114 --- .../palsuite/file_io/WriteFile/test1/WriteFile.cpp | 114 +++ .../file_io/WriteFile/test2/CMakeLists.txt | 2 +- .../palsuite/file_io/WriteFile/test2/WriteFile.c | 109 --- .../palsuite/file_io/WriteFile/test2/WriteFile.cpp | 109 +++ .../file_io/WriteFile/test3/CMakeLists.txt | 2 +- .../palsuite/file_io/WriteFile/test3/WriteFile.c | 136 --- .../palsuite/file_io/WriteFile/test3/WriteFile.cpp | 136 +++ .../file_io/WriteFile/test4/CMakeLists.txt | 2 +- .../palsuite/file_io/WriteFile/test4/writefile.c | 155 ---- .../palsuite/file_io/WriteFile/test4/writefile.cpp | 155 ++++ .../file_io/WriteFile/test5/CMakeLists.txt | 2 +- .../palsuite/file_io/WriteFile/test5/writefile.c | 117 --- .../palsuite/file_io/WriteFile/test5/writefile.cpp | 117 +++ .../file_io/errorpathnotfound/test1/CMakeLists.txt | 2 +- .../file_io/errorpathnotfound/test1/test1.c | 783 ------------------ .../file_io/errorpathnotfound/test1/test1.cpp | 783 ++++++++++++++++++ .../file_io/errorpathnotfound/test2/CMakeLists.txt | 2 +- .../file_io/errorpathnotfound/test2/test2.c | 785 ------------------ .../file_io/errorpathnotfound/test2/test2.cpp | 785 ++++++++++++++++++ .../file_io/errorpathnotfound/test3/CMakeLists.txt | 2 +- .../file_io/errorpathnotfound/test3/test3.c | 244 ------ .../file_io/errorpathnotfound/test3/test3.cpp | 244 ++++++ .../file_io/errorpathnotfound/test4/CMakeLists.txt | 2 +- .../file_io/errorpathnotfound/test4/test4.c | 351 -------- .../file_io/errorpathnotfound/test4/test4.cpp | 351 ++++++++ .../file_io/gettemppatha/test1/CMakeLists.txt | 2 +- .../file_io/gettemppatha/test1/gettemppatha.c | 103 --- .../file_io/gettemppatha/test1/gettemppatha.cpp | 103 +++ .../palsuite/filemapping_memmgt/CMakeLists.txt | 2 +- .../CreateFileMappingA/test1/CMakeLists.txt | 2 +- .../CreateFileMappingA/test1/CreateFileMapping.c | 173 ---- .../CreateFileMappingA/test1/CreateFileMapping.cpp | 173 ++++ .../CreateFileMappingA/test3/CMakeLists.txt | 2 +- .../CreateFileMappingA/test3/CreateFileMapping.c | 155 ---- .../CreateFileMappingA/test3/CreateFileMapping.cpp | 155 ++++ .../CreateFileMappingA/test4/CMakeLists.txt | 2 +- .../CreateFileMappingA/test4/CreateFileMapping.c | 181 ---- .../CreateFileMappingA/test4/CreateFileMapping.cpp | 181 ++++ .../CreateFileMappingA/test5/CMakeLists.txt | 2 +- .../CreateFileMappingA/test5/CreateFileMapping.c | 193 ----- .../CreateFileMappingA/test5/CreateFileMapping.cpp | 193 +++++ .../CreateFileMappingA/test6/CMakeLists.txt | 2 +- .../CreateFileMappingA/test6/CreateFileMapping.c | 164 ---- .../CreateFileMappingA/test6/CreateFileMapping.cpp | 164 ++++ .../CreateFileMappingA/test7/CMakeLists.txt | 2 +- .../CreateFileMappingA/test7/createfilemapping.c | 164 ---- .../CreateFileMappingA/test7/createfilemapping.cpp | 164 ++++ .../CreateFileMappingA/test8/CMakeLists.txt | 2 +- .../CreateFileMappingA/test8/createfilemapping.c | 79 -- .../CreateFileMappingA/test8/createfilemapping.cpp | 79 ++ .../CreateFileMappingA/test9/CMakeLists.txt | 2 +- .../CreateFileMappingA/test9/createfilemapping.c | 150 ---- .../CreateFileMappingA/test9/createfilemapping.cpp | 150 ++++ .../CreateFileMapping_neg1/CMakeLists.txt | 2 +- .../CreateFileMapping_neg1/CreateFileMapping_neg.c | 93 --- .../CreateFileMapping_neg.cpp | 93 +++ .../CreateFileMappingW/test1/CMakeLists.txt | 2 +- .../CreateFileMappingW/test1/CreateFileMappingW.c | 174 ---- .../test1/CreateFileMappingW.cpp | 174 ++++ .../CreateFileMappingW/test2/CMakeLists.txt | 2 +- .../CreateFileMappingW/test2/CreateFileMappingW.c | 124 --- .../test2/CreateFileMappingW.cpp | 124 +++ .../CreateFileMappingW/test3/CMakeLists.txt | 2 +- .../CreateFileMappingW/test3/CreateFileMappingW.c | 156 ---- .../test3/CreateFileMappingW.cpp | 156 ++++ .../CreateFileMappingW/test4/CMakeLists.txt | 2 +- .../CreateFileMappingW/test4/CreateFileMappingW.c | 182 ---- .../test4/CreateFileMappingW.cpp | 182 ++++ .../CreateFileMappingW/test5/CMakeLists.txt | 2 +- .../CreateFileMappingW/test5/CreateFileMappingW.c | 194 ----- .../test5/CreateFileMappingW.cpp | 194 +++++ .../CreateFileMappingW/test6/CMakeLists.txt | 2 +- .../CreateFileMappingW/test6/CreateFileMappingW.c | 165 ---- .../test6/CreateFileMappingW.cpp | 165 ++++ .../CreateFileMappingW/test7/CMakeLists.txt | 2 +- .../CreateFileMappingW/test7/createfilemapping.c | 165 ---- .../CreateFileMappingW/test7/createfilemapping.cpp | 165 ++++ .../CreateFileMappingW/test8/CMakeLists.txt | 2 +- .../CreateFileMappingW/test8/createfilemapping.c | 82 -- .../CreateFileMappingW/test8/createfilemapping.cpp | 82 ++ .../CreateFileMappingW/test9/CMakeLists.txt | 2 +- .../CreateFileMappingW/test9/createfilemapping.c | 151 ---- .../CreateFileMappingW/test9/createfilemapping.cpp | 151 ++++ .../FreeLibrary/test1/CMakeLists.txt | 4 +- .../FreeLibrary/test1/FreeLibrary.c | 128 --- .../FreeLibrary/test1/FreeLibrary.cpp | 128 +++ .../filemapping_memmgt/FreeLibrary/test1/dlltest.c | 32 - .../FreeLibrary/test1/dlltest.cpp | 32 + .../FreeLibrary/test2/CMakeLists.txt | 2 +- .../filemapping_memmgt/FreeLibrary/test2/test2.c | 52 -- .../filemapping_memmgt/FreeLibrary/test2/test2.cpp | 52 ++ .../FreeLibraryAndExitThread/test1/CMakeLists.txt | 4 +- .../FreeLibraryAndExitThread/test1/dlltest.c | 32 - .../FreeLibraryAndExitThread/test1/dlltest.cpp | 32 + .../FreeLibraryAndExitThread/test1/test1.c | 183 ----- .../FreeLibraryAndExitThread/test1/test1.cpp | 183 +++++ .../GetModuleFileNameA/test1/CMakeLists.txt | 2 +- .../GetModuleFileNameA/test1/GetModuleFileNameA.c | 92 --- .../test1/GetModuleFileNameA.cpp | 92 +++ .../GetModuleFileNameA/test2/CMakeLists.txt | 2 +- .../GetModuleFileNameA/test2/GetModuleFileNameA.c | 49 -- .../test2/GetModuleFileNameA.cpp | 49 ++ .../GetModuleFileNameW/test1/CMakeLists.txt | 2 +- .../GetModuleFileNameW/test1/GetModuleFileNameW.c | 112 --- .../test1/GetModuleFileNameW.cpp | 112 +++ .../GetModuleFileNameW/test2/CMakeLists.txt | 2 +- .../GetModuleFileNameW/test2/GetModuleFileNameW.c | 57 -- .../test2/GetModuleFileNameW.cpp | 57 ++ .../GetProcAddress/test1/CMakeLists.txt | 4 +- .../GetProcAddress/test1/test1.c | 111 --- .../GetProcAddress/test1/test1.cpp | 111 +++ .../GetProcAddress/test1/testlib.c | 33 - .../GetProcAddress/test1/testlib.cpp | 33 + .../GetProcAddress/test2/CMakeLists.txt | 4 +- .../GetProcAddress/test2/test2.c | 152 ---- .../GetProcAddress/test2/test2.cpp | 152 ++++ .../GetProcAddress/test2/testlib.c | 33 - .../GetProcAddress/test2/testlib.cpp | 33 + .../GetProcessHeap/test1/CMakeLists.txt | 2 +- .../GetProcessHeap/test1/GetProcessHeap.c | 39 - .../GetProcessHeap/test1/GetProcessHeap.cpp | 39 + .../HeapAlloc/test1/CMakeLists.txt | 2 +- .../filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c | 100 --- .../HeapAlloc/test1/HeapAlloc.cpp | 100 +++ .../HeapAlloc/test2/CMakeLists.txt | 2 +- .../filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c | 59 -- .../HeapAlloc/test2/HeapAlloc.cpp | 59 ++ .../HeapAlloc/test3/CMakeLists.txt | 2 +- .../filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c | 62 -- .../HeapAlloc/test3/HeapAlloc.cpp | 62 ++ .../HeapFree/test1/CMakeLists.txt | 2 +- .../filemapping_memmgt/HeapFree/test1/HeapFree.c | 62 -- .../filemapping_memmgt/HeapFree/test1/HeapFree.cpp | 62 ++ .../HeapReAlloc/test1/CMakeLists.txt | 2 +- .../filemapping_memmgt/HeapReAlloc/test1/test1.c | 72 -- .../filemapping_memmgt/HeapReAlloc/test1/test1.cpp | 72 ++ .../HeapReAlloc/test2/CMakeLists.txt | 2 +- .../filemapping_memmgt/HeapReAlloc/test2/test2.c | 79 -- .../filemapping_memmgt/HeapReAlloc/test2/test2.cpp | 79 ++ .../HeapReAlloc/test3/CMakeLists.txt | 2 +- .../filemapping_memmgt/HeapReAlloc/test3/test3.c | 78 -- .../filemapping_memmgt/HeapReAlloc/test3/test3.cpp | 78 ++ .../HeapReAlloc/test4/CMakeLists.txt | 2 +- .../filemapping_memmgt/HeapReAlloc/test4/test4.c | 80 -- .../filemapping_memmgt/HeapReAlloc/test4/test4.cpp | 80 ++ .../HeapReAlloc/test5/CMakeLists.txt | 2 +- .../filemapping_memmgt/HeapReAlloc/test5/test5.c | 69 -- .../filemapping_memmgt/HeapReAlloc/test5/test5.cpp | 69 ++ .../LocalAlloc/test1/CMakeLists.txt | 2 +- .../LocalAlloc/test1/LocalAlloc.c | 49 -- .../LocalAlloc/test1/LocalAlloc.cpp | 49 ++ .../LocalFree/test1/CMakeLists.txt | 2 +- .../filemapping_memmgt/LocalFree/test1/LocalFree.c | 49 -- .../LocalFree/test1/LocalFree.cpp | 49 ++ .../LocalFree/test2/CMakeLists.txt | 2 +- .../filemapping_memmgt/LocalFree/test2/LocalFree.c | 39 - .../LocalFree/test2/LocalFree.cpp | 39 + .../LockFile/test1/CMakeLists.txt | 4 +- .../filemapping_memmgt/LockFile/test1/helper.c | 86 -- .../filemapping_memmgt/LockFile/test1/helper.cpp | 86 ++ .../filemapping_memmgt/LockFile/test1/test1.c | 140 ---- .../filemapping_memmgt/LockFile/test1/test1.cpp | 140 ++++ .../LockFile/test2/CMakeLists.txt | 2 +- .../filemapping_memmgt/LockFile/test2/test2.c | 94 --- .../filemapping_memmgt/LockFile/test2/test2.cpp | 94 +++ .../LockFile/test3/CMakeLists.txt | 4 +- .../filemapping_memmgt/LockFile/test3/helper.c | 102 --- .../filemapping_memmgt/LockFile/test3/helper.cpp | 102 +++ .../filemapping_memmgt/LockFile/test3/test3.c | 71 -- .../filemapping_memmgt/LockFile/test3/test3.cpp | 71 ++ .../LockFile/test4/CMakeLists.txt | 2 +- .../filemapping_memmgt/LockFile/test4/test4.c | 231 ------ .../filemapping_memmgt/LockFile/test4/test4.cpp | 231 ++++++ .../LockFile/test5/CMakeLists.txt | 4 +- .../filemapping_memmgt/LockFile/test5/helper.c | 122 --- .../filemapping_memmgt/LockFile/test5/helper.cpp | 122 +++ .../filemapping_memmgt/LockFile/test5/test5.c | 161 ---- .../filemapping_memmgt/LockFile/test5/test5.cpp | 161 ++++ .../LockFile/test6/CMakeLists.txt | 4 +- .../filemapping_memmgt/LockFile/test6/helper.c | 71 -- .../filemapping_memmgt/LockFile/test6/helper.cpp | 71 ++ .../filemapping_memmgt/LockFile/test6/test6.c | 146 ---- .../filemapping_memmgt/LockFile/test6/test6.cpp | 146 ++++ .../LockFile/test7/CMakeLists.txt | 2 +- .../filemapping_memmgt/LockFile/test7/test7.c | 135 --- .../filemapping_memmgt/LockFile/test7/test7.cpp | 135 +++ .../MapViewOfFile/test1/CMakeLists.txt | 2 +- .../MapViewOfFile/test1/MapViewOfFile.c | 226 ----- .../MapViewOfFile/test1/MapViewOfFile.cpp | 226 +++++ .../MapViewOfFile/test2/CMakeLists.txt | 2 +- .../MapViewOfFile/test2/MapViewOfFile.c | 203 ----- .../MapViewOfFile/test2/MapViewOfFile.cpp | 203 +++++ .../MapViewOfFile/test3/CMakeLists.txt | 2 +- .../MapViewOfFile/test3/MapViewOfFile.c | 209 ----- .../MapViewOfFile/test3/MapViewOfFile.cpp | 209 +++++ .../MapViewOfFile/test4/CMakeLists.txt | 2 +- .../MapViewOfFile/test4/mapviewoffile.c | 166 ---- .../MapViewOfFile/test4/mapviewoffile.cpp | 166 ++++ .../MapViewOfFile/test5/CMakeLists.txt | 2 +- .../MapViewOfFile/test5/mapviewoffile.c | 131 --- .../MapViewOfFile/test5/mapviewoffile.cpp | 131 +++ .../MapViewOfFile/test6/CMakeLists.txt | 2 +- .../MapViewOfFile/test6/mapviewoffile.c | 85 -- .../MapViewOfFile/test6/mapviewoffile.cpp | 85 ++ .../OpenFileMappingA/test1/CMakeLists.txt | 2 +- .../OpenFileMappingA/test1/OpenFileMappingA.c | 157 ---- .../OpenFileMappingA/test1/OpenFileMappingA.cpp | 157 ++++ .../OpenFileMappingA/test2/CMakeLists.txt | 2 +- .../OpenFileMappingA/test2/OpenFileMappingA.c | 214 ----- .../OpenFileMappingA/test2/OpenFileMappingA.cpp | 214 +++++ .../OpenFileMappingA/test3/CMakeLists.txt | 2 +- .../OpenFileMappingA/test3/OpenFileMappingA.c | 217 ----- .../OpenFileMappingA/test3/OpenFileMappingA.cpp | 217 +++++ .../OpenFileMappingW/test1/CMakeLists.txt | 2 +- .../OpenFileMappingW/test1/OpenFileMappingW.c | 155 ---- .../OpenFileMappingW/test1/OpenFileMappingW.cpp | 155 ++++ .../OpenFileMappingW/test2/CMakeLists.txt | 2 +- .../OpenFileMappingW/test2/OpenFileMappingW.c | 217 ----- .../OpenFileMappingW/test2/OpenFileMappingW.cpp | 217 +++++ .../OpenFileMappingW/test3/CMakeLists.txt | 2 +- .../OpenFileMappingW/test3/OpenFileMappingW.c | 210 ----- .../OpenFileMappingW/test3/OpenFileMappingW.cpp | 210 +++++ .../filemapping_memmgt/ProbeMemory/CMakeLists.txt | 5 + .../ProbeMemory/ProbeMemory_neg1/CMakeLists.txt | 19 + .../ProbeMemory_neg1/ProbeMemory_neg.cpp | 95 +++ .../ProbeMemory/ProbeMemory_neg1/testinfo.dat | 12 + .../ProbeMemory/test1/CMakeLists.txt | 19 + .../ProbeMemory/test1/ProbeMemory.cpp | 94 +++ .../ProbeMemory/test1/testinfo.dat | 12 + .../ReadProcessMemory/CMakeLists.txt | 6 - .../ReadProcessMemory_neg1/CMakeLists.txt | 19 - .../ReadProcessMemory_neg1/ReadProcessMemory_neg.c | 127 --- .../ReadProcessMemory_neg1/testinfo.dat | 12 - .../ReadProcessMemory/test1/CMakeLists.txt | 19 - .../ReadProcessMemory/test1/ReadProcessMemory.c | 126 --- .../ReadProcessMemory/test1/testinfo.dat | 12 - .../ReadProcessMemory/test2/CMakeLists.txt | 36 - .../ReadProcessMemory/test2/commonconsts.h | 48 -- .../ReadProcessMemory/test2/helper.c | 249 ------ .../ReadProcessMemory/test2/test2.c | 258 ------ .../ReadProcessMemory/test2/testinfo.dat | 18 - .../RtlMoveMemory/test1/CMakeLists.txt | 2 +- .../filemapping_memmgt/RtlMoveMemory/test1/test1.c | 56 -- .../RtlMoveMemory/test1/test1.cpp | 56 ++ .../RtlMoveMemory/test3/CMakeLists.txt | 2 +- .../filemapping_memmgt/RtlMoveMemory/test3/test3.c | 72 -- .../RtlMoveMemory/test3/test3.cpp | 72 ++ .../RtlMoveMemory/test4/CMakeLists.txt | 2 +- .../filemapping_memmgt/RtlMoveMemory/test4/test4.c | 76 -- .../RtlMoveMemory/test4/test4.cpp | 76 ++ .../RtlMoveMemory/test5/CMakeLists.txt | 2 +- .../filemapping_memmgt/RtlMoveMemory/test5/test5.c | 63 -- .../RtlMoveMemory/test5/test5.cpp | 63 ++ .../UnlockFile/test1/CMakeLists.txt | 4 +- .../filemapping_memmgt/UnlockFile/test1/helper.c | 92 --- .../filemapping_memmgt/UnlockFile/test1/helper.cpp | 92 +++ .../filemapping_memmgt/UnlockFile/test1/test1.c | 154 ---- .../filemapping_memmgt/UnlockFile/test1/test1.cpp | 154 ++++ .../UnlockFile/test2/CMakeLists.txt | 2 +- .../filemapping_memmgt/UnlockFile/test2/test2.c | 154 ---- .../filemapping_memmgt/UnlockFile/test2/test2.cpp | 154 ++++ .../UnlockFile/test3/CMakeLists.txt | 4 +- .../filemapping_memmgt/UnlockFile/test3/helper.c | 103 --- .../filemapping_memmgt/UnlockFile/test3/helper.cpp | 103 +++ .../filemapping_memmgt/UnlockFile/test3/test3.c | 142 ---- .../filemapping_memmgt/UnlockFile/test3/test3.cpp | 142 ++++ .../UnlockFile/test4/CMakeLists.txt | 2 +- .../filemapping_memmgt/UnlockFile/test4/test4.c | 187 ----- .../filemapping_memmgt/UnlockFile/test4/test4.cpp | 187 +++++ .../UnmapViewOfFile/test1/CMakeLists.txt | 2 +- .../UnmapViewOfFile/test1/UnmapViewOfFile.c | 184 ----- .../UnmapViewOfFile/test1/UnmapViewOfFile.cpp | 184 +++++ .../UnmapViewOfFile/test2/CMakeLists.txt | 2 +- .../UnmapViewOfFile/test2/unmapviewoffile.c | 42 - .../UnmapViewOfFile/test2/unmapviewoffile.cpp | 42 + .../filemapping_memmgt/VirtualAlloc/CMakeLists.txt | 1 + .../VirtualAlloc/test1/CMakeLists.txt | 2 +- .../VirtualAlloc/test1/VirtualAlloc.c | 50 -- .../VirtualAlloc/test1/VirtualAlloc.cpp | 50 ++ .../VirtualAlloc/test10/CMakeLists.txt | 2 +- .../VirtualAlloc/test10/VirtualAlloc.c | 48 -- .../VirtualAlloc/test10/VirtualAlloc.cpp | 48 ++ .../VirtualAlloc/test11/CMakeLists.txt | 2 +- .../VirtualAlloc/test11/VirtualAlloc.c | 49 -- .../VirtualAlloc/test11/VirtualAlloc.cpp | 49 ++ .../VirtualAlloc/test12/CMakeLists.txt | 2 +- .../VirtualAlloc/test12/VirtualAlloc.c | 48 -- .../VirtualAlloc/test12/VirtualAlloc.cpp | 48 ++ .../VirtualAlloc/test13/CMakeLists.txt | 2 +- .../VirtualAlloc/test13/VirtualAlloc.c | 48 -- .../VirtualAlloc/test13/VirtualAlloc.cpp | 48 ++ .../VirtualAlloc/test14/CMakeLists.txt | 2 +- .../VirtualAlloc/test14/VirtualAlloc.c | 48 -- .../VirtualAlloc/test14/VirtualAlloc.cpp | 48 ++ .../VirtualAlloc/test15/CMakeLists.txt | 2 +- .../VirtualAlloc/test15/VirtualAlloc.c | 48 -- .../VirtualAlloc/test15/VirtualAlloc.cpp | 48 ++ .../VirtualAlloc/test16/CMakeLists.txt | 2 +- .../VirtualAlloc/test16/VirtualAlloc.c | 48 -- .../VirtualAlloc/test16/VirtualAlloc.cpp | 48 ++ .../VirtualAlloc/test17/CMakeLists.txt | 2 +- .../VirtualAlloc/test17/VirtualAlloc.c | 49 -- .../VirtualAlloc/test17/VirtualAlloc.cpp | 49 ++ .../VirtualAlloc/test18/CMakeLists.txt | 2 +- .../VirtualAlloc/test18/VirtualAlloc.c | 49 -- .../VirtualAlloc/test18/VirtualAlloc.cpp | 49 ++ .../VirtualAlloc/test19/CMakeLists.txt | 2 +- .../VirtualAlloc/test19/VirtualAlloc.c | 51 -- .../VirtualAlloc/test19/VirtualAlloc.cpp | 51 ++ .../VirtualAlloc/test2/CMakeLists.txt | 2 +- .../VirtualAlloc/test2/VirtualAlloc.c | 49 -- .../VirtualAlloc/test2/VirtualAlloc.cpp | 49 ++ .../VirtualAlloc/test20/CMakeLists.txt | 2 +- .../VirtualAlloc/test20/virtualalloc.c | 50 -- .../VirtualAlloc/test20/virtualalloc.cpp | 50 ++ .../VirtualAlloc/test21/CMakeLists.txt | 2 +- .../VirtualAlloc/test21/virtualalloc.c | 54 -- .../VirtualAlloc/test21/virtualalloc.cpp | 54 ++ .../VirtualAlloc/test22/CMakeLists.txt | 19 + .../VirtualAlloc/test22/VirtualAlloc.cpp | 44 + .../VirtualAlloc/test22/testinfo.dat | 13 + .../VirtualAlloc/test3/CMakeLists.txt | 2 +- .../VirtualAlloc/test3/VirtualAlloc.c | 48 -- .../VirtualAlloc/test3/VirtualAlloc.cpp | 48 ++ .../VirtualAlloc/test4/CMakeLists.txt | 2 +- .../VirtualAlloc/test4/VirtualAlloc.c | 49 -- .../VirtualAlloc/test4/VirtualAlloc.cpp | 49 ++ .../VirtualAlloc/test5/CMakeLists.txt | 2 +- .../VirtualAlloc/test5/VirtualAlloc.c | 50 -- .../VirtualAlloc/test5/VirtualAlloc.cpp | 50 ++ .../VirtualAlloc/test6/CMakeLists.txt | 2 +- .../VirtualAlloc/test6/VirtualAlloc.c | 48 -- .../VirtualAlloc/test6/VirtualAlloc.cpp | 48 ++ .../VirtualAlloc/test7/CMakeLists.txt | 2 +- .../VirtualAlloc/test7/VirtualAlloc.c | 53 -- .../VirtualAlloc/test7/VirtualAlloc.cpp | 53 ++ .../VirtualAlloc/test8/CMakeLists.txt | 2 +- .../VirtualAlloc/test8/VirtualAlloc.c | 48 -- .../VirtualAlloc/test8/VirtualAlloc.cpp | 48 ++ .../VirtualAlloc/test9/CMakeLists.txt | 2 +- .../VirtualAlloc/test9/VirtualAlloc.c | 48 -- .../VirtualAlloc/test9/VirtualAlloc.cpp | 48 ++ .../VirtualFree/test1/CMakeLists.txt | 2 +- .../VirtualFree/test1/VirtualFree.c | 48 -- .../VirtualFree/test1/VirtualFree.cpp | 48 ++ .../VirtualFree/test2/CMakeLists.txt | 2 +- .../VirtualFree/test2/VirtualFree.c | 54 -- .../VirtualFree/test2/VirtualFree.cpp | 54 ++ .../VirtualFree/test3/CMakeLists.txt | 2 +- .../VirtualFree/test3/VirtualFree.c | 53 -- .../VirtualFree/test3/VirtualFree.cpp | 53 ++ .../VirtualProtect/test1/CMakeLists.txt | 2 +- .../VirtualProtect/test1/VirtualProtect.c | 69 -- .../VirtualProtect/test1/VirtualProtect.cpp | 69 ++ .../VirtualProtect/test2/CMakeLists.txt | 2 +- .../VirtualProtect/test2/VirtualProtect.c | 69 -- .../VirtualProtect/test2/VirtualProtect.cpp | 69 ++ .../VirtualProtect/test3/CMakeLists.txt | 2 +- .../VirtualProtect/test3/VirtualProtect.c | 69 -- .../VirtualProtect/test3/VirtualProtect.cpp | 69 ++ .../VirtualProtect/test4/CMakeLists.txt | 2 +- .../VirtualProtect/test4/VirtualProtect.c | 68 -- .../VirtualProtect/test4/VirtualProtect.cpp | 68 ++ .../VirtualProtect/test6/CMakeLists.txt | 2 +- .../VirtualProtect/test6/VirtualProtect.c | 68 -- .../VirtualProtect/test6/VirtualProtect.cpp | 68 ++ .../VirtualProtect/test7/CMakeLists.txt | 2 +- .../VirtualProtect/test7/VirtualProtect.c | 69 -- .../VirtualProtect/test7/VirtualProtect.cpp | 69 ++ .../VirtualQuery/test1/CMakeLists.txt | 2 +- .../VirtualQuery/test1/VirtualQuery.c | 68 -- .../VirtualQuery/test1/VirtualQuery.cpp | 68 ++ .../loader/LoadLibraryA/test1/CMakeLists.txt | 2 +- .../loader/LoadLibraryA/test1/LoadLibraryA.c | 53 -- .../loader/LoadLibraryA/test1/LoadLibraryA.cpp | 53 ++ .../loader/LoadLibraryA/test2/CMakeLists.txt | 2 +- .../loader/LoadLibraryA/test2/LoadLibraryA.c | 52 -- .../loader/LoadLibraryA/test2/LoadLibraryA.cpp | 52 ++ .../palsuite/loader/LoadLibraryA/test2/MyModule.c | 19 - .../loader/LoadLibraryA/test2/MyModule.cpp | 19 + .../loader/LoadLibraryA/test3/CMakeLists.txt | 2 +- .../loader/LoadLibraryA/test3/loadlibrarya.c | 40 - .../loader/LoadLibraryA/test3/loadlibrarya.cpp | 40 + .../loader/LoadLibraryA/test5/CMakeLists.txt | 2 +- .../loader/LoadLibraryA/test5/loadlibrarya.c | 67 -- .../loader/LoadLibraryA/test5/loadlibrarya.cpp | 67 ++ .../loader/LoadLibraryA/test6/CMakeLists.txt | 4 +- .../palsuite/loader/LoadLibraryA/test6/dlltest.c | 72 -- .../palsuite/loader/LoadLibraryA/test6/dlltest.cpp | 72 ++ .../loader/LoadLibraryA/test6/loadlibrarya.c | 172 ---- .../loader/LoadLibraryA/test6/loadlibrarya.cpp | 172 ++++ .../loader/LoadLibraryA/test7/CMakeLists.txt | 2 +- .../loader/LoadLibraryA/test7/LoadLibraryA.c | 83 -- .../loader/LoadLibraryA/test7/LoadLibraryA.cpp | 83 ++ .../loader/LoadLibraryA/test8/CMakeLists.txt | 4 +- .../palsuite/loader/LoadLibraryA/test8/dlltest.c | 72 -- .../palsuite/loader/LoadLibraryA/test8/dlltest.cpp | 72 ++ .../loader/LoadLibraryA/test8/loadlibrarya.c | 235 ------ .../loader/LoadLibraryA/test8/loadlibrarya.cpp | 235 ++++++ .../loader/LoadLibraryW/test1/CMakeLists.txt | 2 +- .../loader/LoadLibraryW/test1/LoadLibraryW.c | 62 -- .../loader/LoadLibraryW/test1/LoadLibraryW.cpp | 62 ++ .../loader/LoadLibraryW/test2/CMakeLists.txt | 2 +- .../loader/LoadLibraryW/test2/loadlibraryw.c | 62 -- .../loader/LoadLibraryW/test2/loadlibraryw.cpp | 62 ++ .../loader/LoadLibraryW/test3/CMakeLists.txt | 2 +- .../loader/LoadLibraryW/test3/loadlibraryw.c | 41 - .../loader/LoadLibraryW/test3/loadlibraryw.cpp | 41 + .../loader/LoadLibraryW/test5/CMakeLists.txt | 2 +- .../loader/LoadLibraryW/test5/loadlibraryw.c | 71 -- .../loader/LoadLibraryW/test5/loadlibraryw.cpp | 71 ++ .../CompareStringA/test1/CMakeLists.txt | 2 +- .../locale_info/CompareStringA/test1/test1.c | 99 --- .../locale_info/CompareStringA/test1/test1.cpp | 99 +++ .../CompareStringW/test1/CMakeLists.txt | 2 +- .../locale_info/CompareStringW/test1/test1.c | 99 --- .../locale_info/CompareStringW/test1/test1.cpp | 99 +++ .../locale_info/GetACP/test1/CMakeLists.txt | 2 +- .../palsuite/locale_info/GetACP/test1/test1.c | 42 - .../palsuite/locale_info/GetACP/test1/test1.cpp | 42 + .../locale_info/GetCPInfo/test1/CMakeLists.txt | 2 +- .../palsuite/locale_info/GetCPInfo/test1/test1.c | 54 -- .../palsuite/locale_info/GetCPInfo/test1/test1.cpp | 54 ++ .../locale_info/GetCPInfo/test2/CMakeLists.txt | 2 +- .../palsuite/locale_info/GetCPInfo/test2/test2.c | 60 -- .../palsuite/locale_info/GetCPInfo/test2/test2.cpp | 60 ++ .../locale_info/GetCPInfo/test3/CMakeLists.txt | 2 +- .../palsuite/locale_info/GetCPInfo/test3/test3.c | 41 - .../palsuite/locale_info/GetCPInfo/test3/test3.cpp | 41 + .../GetLocaleInfoW/test1/CMakeLists.txt | 2 +- .../locale_info/GetLocaleInfoW/test1/test1.c | 89 -- .../locale_info/GetLocaleInfoW/test1/test1.cpp | 89 ++ .../GetLocaleInfoW/test2/CMakeLists.txt | 2 +- .../locale_info/GetLocaleInfoW/test2/test2.c | 51 -- .../locale_info/GetLocaleInfoW/test2/test2.cpp | 51 ++ .../GetStringTypeExW/test1/CMakeLists.txt | 2 +- .../locale_info/GetStringTypeExW/test1/test1.c | 54 -- .../locale_info/GetStringTypeExW/test1/test1.cpp | 54 ++ .../GetStringTypeExW/test2/CMakeLists.txt | 2 +- .../locale_info/GetStringTypeExW/test2/test2.c | 78 -- .../locale_info/GetStringTypeExW/test2/test2.cpp | 78 ++ .../GetSystemDefaultLangID/test1/CMakeLists.txt | 2 +- .../GetSystemDefaultLangID/test1/test1.c | 59 -- .../GetSystemDefaultLangID/test1/test1.cpp | 59 ++ .../GetThreadLocale/test1/CMakeLists.txt | 2 +- .../locale_info/GetThreadLocale/test1/test1.c | 36 - .../locale_info/GetThreadLocale/test1/test1.cpp | 36 + .../GetTimeZoneInformation/test1/CMakeLists.txt | 2 +- .../GetTimeZoneInformation/test1/test1.c | 73 -- .../GetTimeZoneInformation/test1/test1.cpp | 73 ++ .../GetUserDefaultLCID/test1/CMakeLists.txt | 2 +- .../locale_info/GetUserDefaultLCID/test1/test1.c | 52 -- .../locale_info/GetUserDefaultLCID/test1/test1.cpp | 52 ++ .../GetUserDefaultLangID/test1/CMakeLists.txt | 2 +- .../locale_info/GetUserDefaultLangID/test1/test1.c | 60 -- .../GetUserDefaultLangID/test1/test1.cpp | 60 ++ .../IsDBCSLeadByte/test1/CMakeLists.txt | 2 +- .../locale_info/IsDBCSLeadByte/test1/test1.c | 64 -- .../locale_info/IsDBCSLeadByte/test1/test1.cpp | 64 ++ .../IsDBCSLeadByteEx/test1/CMakeLists.txt | 2 +- .../locale_info/IsDBCSLeadByteEx/test1/test1.c | 72 -- .../locale_info/IsDBCSLeadByteEx/test1/test1.cpp | 72 ++ .../IsValidCodePage/test1/CMakeLists.txt | 2 +- .../locale_info/IsValidCodePage/test1/test1.c | 50 -- .../locale_info/IsValidCodePage/test1/test1.cpp | 50 ++ .../IsValidCodePage/test2/CMakeLists.txt | 2 +- .../locale_info/IsValidCodePage/test2/test2.c | 51 -- .../locale_info/IsValidCodePage/test2/test2.cpp | 51 ++ .../locale_info/IsValidLocale/test1/CMakeLists.txt | 2 +- .../locale_info/IsValidLocale/test1/test1.c | 76 -- .../locale_info/IsValidLocale/test1/test1.cpp | 76 ++ .../MultiByteToWideChar/test1/CMakeLists.txt | 2 +- .../locale_info/MultiByteToWideChar/test1/test1.c | 81 -- .../MultiByteToWideChar/test1/test1.cpp | 81 ++ .../MultiByteToWideChar/test2/CMakeLists.txt | 2 +- .../locale_info/MultiByteToWideChar/test2/test2.c | 68 -- .../MultiByteToWideChar/test2/test2.cpp | 68 ++ .../MultiByteToWideChar/test3/CMakeLists.txt | 2 +- .../locale_info/MultiByteToWideChar/test3/test3.c | 73 -- .../MultiByteToWideChar/test3/test3.cpp | 73 ++ .../MultiByteToWideChar/test4/CMakeLists.txt | 2 +- .../locale_info/MultiByteToWideChar/test4/test4.c | 230 ------ .../MultiByteToWideChar/test4/test4.cpp | 230 ++++++ .../SetThreadLocale/test1/CMakeLists.txt | 2 +- .../locale_info/SetThreadLocale/test1/test1.c | 50 -- .../locale_info/SetThreadLocale/test1/test1.cpp | 50 ++ .../WideCharToMultiByte/test1/CMakeLists.txt | 2 +- .../locale_info/WideCharToMultiByte/test1/test1.c | 102 --- .../WideCharToMultiByte/test1/test1.cpp | 102 +++ .../WideCharToMultiByte/test2/CMakeLists.txt | 2 +- .../locale_info/WideCharToMultiByte/test2/test2.c | 88 -- .../WideCharToMultiByte/test2/test2.cpp | 88 ++ .../WideCharToMultiByte/test3/CMakeLists.txt | 2 +- .../locale_info/WideCharToMultiByte/test3/test3.c | 100 --- .../WideCharToMultiByte/test3/test3.cpp | 100 +++ .../WideCharToMultiByte/test4/CMakeLists.txt | 2 +- .../locale_info/WideCharToMultiByte/test4/test4.c | 131 --- .../WideCharToMultiByte/test4/test4.cpp | 131 +++ .../WideCharToMultiByte/test5/CMakeLists.txt | 2 +- .../locale_info/WideCharToMultiByte/test5/test5.c | 154 ---- .../WideCharToMultiByte/test5/test5.cpp | 154 ++++ .../tests/palsuite/miscellaneous/CMakeLists.txt | 6 - .../miscellaneous/CharNextA/test1/CMakeLists.txt | 2 +- .../palsuite/miscellaneous/CharNextA/test1/test.c | 62 -- .../miscellaneous/CharNextA/test1/test.cpp | 62 ++ .../miscellaneous/CharNextA/test2/CMakeLists.txt | 2 +- .../palsuite/miscellaneous/CharNextA/test2/test.c | 67 -- .../miscellaneous/CharNextA/test2/test.cpp | 67 ++ .../miscellaneous/CharNextExA/test1/CMakeLists.txt | 2 +- .../miscellaneous/CharNextExA/test1/test.c | 63 -- .../miscellaneous/CharNextExA/test1/test.cpp | 63 ++ .../miscellaneous/CharNextExA/test2/CMakeLists.txt | 2 +- .../miscellaneous/CharNextExA/test2/test.c | 66 -- .../miscellaneous/CharNextExA/test2/test.cpp | 66 ++ .../miscellaneous/CloseHandle/test1/CMakeLists.txt | 2 +- .../miscellaneous/CloseHandle/test1/test.c | 64 -- .../miscellaneous/CloseHandle/test1/test.cpp | 64 ++ .../miscellaneous/CloseHandle/test2/CMakeLists.txt | 2 +- .../miscellaneous/CloseHandle/test2/test.c | 46 -- .../miscellaneous/CloseHandle/test2/test.cpp | 46 ++ .../miscellaneous/CreatePipe/test1/CMakeLists.txt | 2 +- .../miscellaneous/CreatePipe/test1/test1.c | 113 --- .../miscellaneous/CreatePipe/test1/test1.cpp | 113 +++ .../FlushInstructionCache/test1/CMakeLists.txt | 2 +- .../FlushInstructionCache/test1/test1.c | 66 -- .../FlushInstructionCache/test1/test1.cpp | 66 ++ .../FormatMessageW/test1/CMakeLists.txt | 2 +- .../miscellaneous/FormatMessageW/test1/test.c | 63 -- .../miscellaneous/FormatMessageW/test1/test.cpp | 63 ++ .../FormatMessageW/test2/CMakeLists.txt | 2 +- .../miscellaneous/FormatMessageW/test2/test.c | 581 ------------- .../miscellaneous/FormatMessageW/test2/test.cpp | 581 +++++++++++++ .../FormatMessageW/test3/CMakeLists.txt | 2 +- .../miscellaneous/FormatMessageW/test3/test.c | 85 -- .../miscellaneous/FormatMessageW/test3/test.cpp | 85 ++ .../FormatMessageW/test4/CMakeLists.txt | 2 +- .../miscellaneous/FormatMessageW/test4/test.c | 77 -- .../miscellaneous/FormatMessageW/test4/test.cpp | 77 ++ .../FormatMessageW/test5/CMakeLists.txt | 2 +- .../miscellaneous/FormatMessageW/test5/test.c | 76 -- .../miscellaneous/FormatMessageW/test5/test.cpp | 76 ++ .../FormatMessageW/test6/CMakeLists.txt | 2 +- .../miscellaneous/FormatMessageW/test6/test.c | 78 -- .../miscellaneous/FormatMessageW/test6/test.cpp | 78 ++ .../FreeEnvironmentStringsW/test1/CMakeLists.txt | 2 +- .../FreeEnvironmentStringsW/test1/test.c | 53 -- .../FreeEnvironmentStringsW/test1/test.cpp | 53 ++ .../FreeEnvironmentStringsW/test2/CMakeLists.txt | 2 +- .../FreeEnvironmentStringsW/test2/test.c | 71 -- .../FreeEnvironmentStringsW/test2/test.cpp | 71 ++ .../GetCalendarInfoW/test1/CMakeLists.txt | 2 +- .../GetCalendarInfoW/test1/GetCalendarInfoW.c | 57 -- .../GetCalendarInfoW/test1/GetCalendarInfoW.cpp | 57 ++ .../GetCalendarInfoW/test2/CMakeLists.txt | 2 +- .../GetCalendarInfoW/test2/GetCalendarInfoW.c | 79 -- .../GetCalendarInfoW/test2/GetCalendarInfoW.cpp | 79 ++ .../GetCommandLineW/test1/CMakeLists.txt | 2 +- .../miscellaneous/GetCommandLineW/test1/test.c | 71 -- .../miscellaneous/GetCommandLineW/test1/test.cpp | 71 ++ .../GetComputerNameW/test1/CMakeLists.txt | 2 +- .../miscellaneous/GetComputerNameW/test1/test.c | 53 -- .../miscellaneous/GetComputerNameW/test1/test.cpp | 53 ++ .../GetDateFormatW_neg1/CMakeLists.txt | 2 +- .../GetDateFormatW_neg1/GetDateFormatW_neg.c | 85 -- .../GetDateFormatW_neg1/GetDateFormatW_neg.cpp | 85 ++ .../GetDateFormatW_neg2/CMakeLists.txt | 2 +- .../GetDateFormatW_neg2/GetDateFormatW_neg.c | 98 --- .../GetDateFormatW_neg2/GetDateFormatW_neg.cpp | 98 +++ .../GetDateFormatW/test1/CMakeLists.txt | 2 +- .../GetDateFormatW/test1/GetDateFormatW.c | 100 --- .../GetDateFormatW/test1/GetDateFormatW.cpp | 100 +++ .../GetEnvironmentStringsW/test1/CMakeLists.txt | 2 +- .../GetEnvironmentStringsW/test1/test.c | 81 -- .../GetEnvironmentStringsW/test1/test.cpp | 81 ++ .../GetEnvironmentVariableA/test1/CMakeLists.txt | 2 +- .../GetEnvironmentVariableA/test1/test.c | 84 -- .../GetEnvironmentVariableA/test1/test.cpp | 84 ++ .../GetEnvironmentVariableA/test2/CMakeLists.txt | 2 +- .../GetEnvironmentVariableA/test2/test.c | 56 -- .../GetEnvironmentVariableA/test2/test.cpp | 56 ++ .../GetEnvironmentVariableA/test3/CMakeLists.txt | 2 +- .../GetEnvironmentVariableA/test3/test.c | 67 -- .../GetEnvironmentVariableA/test3/test.cpp | 67 ++ .../GetEnvironmentVariableA/test4/CMakeLists.txt | 2 +- .../GetEnvironmentVariableA/test4/test.c | 75 -- .../GetEnvironmentVariableA/test4/test.cpp | 75 ++ .../GetEnvironmentVariableA/test5/CMakeLists.txt | 2 +- .../GetEnvironmentVariableA/test5/test5.c | 145 ---- .../GetEnvironmentVariableA/test5/test5.cpp | 145 ++++ .../GetEnvironmentVariableA/test6/CMakeLists.txt | 2 +- .../GetEnvironmentVariableA/test6/test6.c | 99 --- .../GetEnvironmentVariableA/test6/test6.cpp | 99 +++ .../GetEnvironmentVariableW/test1/CMakeLists.txt | 2 +- .../GetEnvironmentVariableW/test1/test.c | 79 -- .../GetEnvironmentVariableW/test1/test.cpp | 79 ++ .../GetEnvironmentVariableW/test2/CMakeLists.txt | 2 +- .../GetEnvironmentVariableW/test2/test.c | 56 -- .../GetEnvironmentVariableW/test2/test.cpp | 56 ++ .../GetEnvironmentVariableW/test3/CMakeLists.txt | 2 +- .../GetEnvironmentVariableW/test3/test.c | 71 -- .../GetEnvironmentVariableW/test3/test.cpp | 71 ++ .../GetEnvironmentVariableW/test4/CMakeLists.txt | 2 +- .../GetEnvironmentVariableW/test4/test.c | 63 -- .../GetEnvironmentVariableW/test4/test.cpp | 63 ++ .../GetEnvironmentVariableW/test5/CMakeLists.txt | 2 +- .../GetEnvironmentVariableW/test5/test5.c | 144 ---- .../GetEnvironmentVariableW/test5/test5.cpp | 144 ++++ .../GetEnvironmentVariableW/test6/CMakeLists.txt | 2 +- .../GetEnvironmentVariableW/test6/test6.c | 99 --- .../GetEnvironmentVariableW/test6/test6.cpp | 99 +++ .../GetLastError/test1/CMakeLists.txt | 2 +- .../miscellaneous/GetLastError/test1/test.c | 63 -- .../miscellaneous/GetLastError/test1/test.cpp | 63 ++ .../GetSystemInfo/test1/CMakeLists.txt | 2 +- .../miscellaneous/GetSystemInfo/test1/test.c | 70 -- .../miscellaneous/GetSystemInfo/test1/test.cpp | 70 ++ .../GetTickCount/test1/CMakeLists.txt | 2 +- .../miscellaneous/GetTickCount/test1/test.c | 58 -- .../miscellaneous/GetTickCount/test1/test.cpp | 58 ++ .../GetUserNameW/test1/CMakeLists.txt | 2 +- .../miscellaneous/GetUserNameW/test1/test.c | 52 -- .../miscellaneous/GetUserNameW/test1/test.cpp | 52 ++ .../GetVersionExA/test1/CMakeLists.txt | 2 +- .../miscellaneous/GetVersionExA/test1/test.c | 83 -- .../miscellaneous/GetVersionExA/test1/test.cpp | 83 ++ .../GetVersionExW/test1/CMakeLists.txt | 2 +- .../miscellaneous/GetVersionExW/test1/test.c | 88 -- .../miscellaneous/GetVersionExW/test1/test.cpp | 88 ++ .../IsBadCodePtr/test1/CMakeLists.txt | 2 +- .../miscellaneous/IsBadCodePtr/test1/test1.c | 60 -- .../miscellaneous/IsBadCodePtr/test1/test1.cpp | 60 ++ .../IsBadReadPtr/test1/CMakeLists.txt | 2 +- .../miscellaneous/IsBadReadPtr/test1/test.c | 138 ---- .../miscellaneous/IsBadReadPtr/test1/test.cpp | 138 ++++ .../IsBadWritePtr/test1/CMakeLists.txt | 2 +- .../miscellaneous/IsBadWritePtr/test1/test.c | 81 -- .../miscellaneous/IsBadWritePtr/test1/test.cpp | 81 ++ .../IsBadWritePtr/test2/CMakeLists.txt | 2 +- .../miscellaneous/IsBadWritePtr/test2/test2.c | 128 --- .../miscellaneous/IsBadWritePtr/test2/test2.cpp | 128 +++ .../IsBadWritePtr/test3/CMakeLists.txt | 2 +- .../miscellaneous/IsBadWritePtr/test3/test3.c | 58 -- .../miscellaneous/IsBadWritePtr/test3/test3.cpp | 58 ++ .../miscellaneous/MessageBoxW/test1/CMakeLists.txt | 2 +- .../miscellaneous/MessageBoxW/test1/test.c | 81 -- .../miscellaneous/MessageBoxW/test1/test.cpp | 81 ++ .../miscellaneous/MessageBoxW/test2/CMakeLists.txt | 2 +- .../miscellaneous/MessageBoxW/test2/test.c | 76 -- .../miscellaneous/MessageBoxW/test2/test.cpp | 76 ++ .../SetEnvironmentVariableA/test1/CMakeLists.txt | 2 +- .../SetEnvironmentVariableA/test1/test1.c | 168 ---- .../SetEnvironmentVariableA/test1/test1.cpp | 168 ++++ .../SetEnvironmentVariableA/test2/CMakeLists.txt | 2 +- .../SetEnvironmentVariableA/test2/test2.c | 85 -- .../SetEnvironmentVariableA/test2/test2.cpp | 85 ++ .../SetEnvironmentVariableA/test3/CMakeLists.txt | 2 +- .../SetEnvironmentVariableA/test3/test3.c | 144 ---- .../SetEnvironmentVariableA/test3/test3.cpp | 144 ++++ .../SetEnvironmentVariableA/test4/CMakeLists.txt | 2 +- .../SetEnvironmentVariableA/test4/test4.c | 100 --- .../SetEnvironmentVariableA/test4/test4.cpp | 100 +++ .../SetEnvironmentVariableW/test1/CMakeLists.txt | 2 +- .../SetEnvironmentVariableW/test1/test.c | 142 ---- .../SetEnvironmentVariableW/test1/test.cpp | 142 ++++ .../SetEnvironmentVariableW/test2/CMakeLists.txt | 2 +- .../SetEnvironmentVariableW/test2/test.c | 88 -- .../SetEnvironmentVariableW/test2/test.cpp | 88 ++ .../SetEnvironmentVariableW/test3/CMakeLists.txt | 2 +- .../SetEnvironmentVariableW/test3/test3.c | 143 ---- .../SetEnvironmentVariableW/test3/test3.cpp | 143 ++++ .../SetEnvironmentVariableW/test4/CMakeLists.txt | 2 +- .../SetEnvironmentVariableW/test4/test4.c | 99 --- .../SetEnvironmentVariableW/test4/test4.cpp | 99 +++ .../SetLastError/test1/CMakeLists.txt | 2 +- .../miscellaneous/SetLastError/test1/test.c | 59 -- .../miscellaneous/SetLastError/test1/test.cpp | 59 ++ .../miscellaneous/_i64tow/test1/CMakeLists.txt | 2 +- .../palsuite/miscellaneous/_i64tow/test1/test1.c | 76 -- .../palsuite/miscellaneous/_i64tow/test1/test1.cpp | 76 ++ .../miscellaneous/_i64tow/test1/testinfo.dat | 6 +- .../palsuite/miscellaneous/_ui64tow/CMakeLists.txt | 5 - .../miscellaneous/_ui64tow/test1/CMakeLists.txt | 19 - .../miscellaneous/_ui64tow/test1/_ui64tow.c | 101 --- .../miscellaneous/_ui64tow/test1/testinfo.dat | 12 - .../miscellaneous/_ui64tow/test2/CMakeLists.txt | 19 - .../miscellaneous/_ui64tow/test2/_ui64tow.c | 88 -- .../miscellaneous/_ui64tow/test2/testinfo.dat | 13 - .../palsuite/miscellaneous/lstrcatW/CMakeLists.txt | 7 - .../miscellaneous/lstrcatW/test1/CMakeLists.txt | 19 - .../palsuite/miscellaneous/lstrcatW/test1/test.c | 59 -- .../miscellaneous/lstrcatW/test1/testinfo.dat | 16 - .../miscellaneous/lstrcatW/test2/CMakeLists.txt | 19 - .../palsuite/miscellaneous/lstrcatW/test2/test2.c | 53 -- .../miscellaneous/lstrcatW/test2/testinfo.dat | 12 - .../miscellaneous/lstrcatW/test3/CMakeLists.txt | 19 - .../palsuite/miscellaneous/lstrcatW/test3/test3.c | 46 -- .../miscellaneous/lstrcatW/test3/testinfo.dat | 26 - .../miscellaneous/lstrcatW/test4/CMakeLists.txt | 19 - .../palsuite/miscellaneous/lstrcatW/test4/test4.c | 101 --- .../miscellaneous/lstrcatW/test4/testinfo.dat | 28 - .../palsuite/miscellaneous/lstrcpyW/CMakeLists.txt | 4 - .../miscellaneous/lstrcpyW/test1/CMakeLists.txt | 19 - .../palsuite/miscellaneous/lstrcpyW/test1/test.c | 66 -- .../miscellaneous/lstrcpyW/test1/testinfo.dat | 16 - .../miscellaneous/lstrcpynW/CMakeLists.txt | 4 - .../miscellaneous/lstrcpynW/test1/CMakeLists.txt | 19 - .../palsuite/miscellaneous/lstrcpynW/test1/test.c | 73 -- .../miscellaneous/lstrcpynW/test1/testinfo.dat | 16 - .../miscellaneous/lstrlenA/test1/CMakeLists.txt | 2 +- .../palsuite/miscellaneous/lstrlenA/test1/test.c | 49 -- .../palsuite/miscellaneous/lstrlenA/test1/test.cpp | 49 ++ .../miscellaneous/lstrlenW/test1/CMakeLists.txt | 2 +- .../palsuite/miscellaneous/lstrlenW/test1/test.c | 51 -- .../palsuite/miscellaneous/lstrlenW/test1/test.cpp | 51 ++ .../queryperformancecounter/test1/CMakeLists.txt | 2 +- .../queryperformancecounter/test1/test1.c | 107 --- .../queryperformancecounter/test1/test1.cpp | 107 +++ .../queryperformancefrequency/test1/CMakeLists.txt | 2 +- .../queryperformancefrequency/test1/test1.c | 59 -- .../queryperformancefrequency/test1/test1.cpp | 59 ++ .../miscellaneous/wsprintfA/CMakeLists.txt | 13 - .../miscellaneous/wsprintfA/test1/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test1/test.c | 58 -- .../miscellaneous/wsprintfA/test1/testinfo.dat | 14 - .../miscellaneous/wsprintfA/test11/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test11/test.c | 128 --- .../miscellaneous/wsprintfA/test11/testinfo.dat | 14 - .../miscellaneous/wsprintfA/test12/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test12/test.c | 119 --- .../miscellaneous/wsprintfA/test12/testinfo.dat | 14 - .../miscellaneous/wsprintfA/test13/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test13/test.c | 120 --- .../miscellaneous/wsprintfA/test13/testinfo.dat | 14 - .../miscellaneous/wsprintfA/test2/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test2/test.c | 123 --- .../miscellaneous/wsprintfA/test2/testinfo.dat | 14 - .../miscellaneous/wsprintfA/test3/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test3/test.c | 121 --- .../miscellaneous/wsprintfA/test3/testinfo.dat | 14 - .../miscellaneous/wsprintfA/test6/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test6/test.c | 114 --- .../miscellaneous/wsprintfA/test6/testinfo.dat | 14 - .../miscellaneous/wsprintfA/test7/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test7/test.c | 112 --- .../miscellaneous/wsprintfA/test7/testinfo.dat | 14 - .../miscellaneous/wsprintfA/test8/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test8/test.c | 120 --- .../miscellaneous/wsprintfA/test8/testinfo.dat | 14 - .../miscellaneous/wsprintfA/test9/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfA/test9/test.c | 122 --- .../miscellaneous/wsprintfA/test9/testinfo.dat | 14 - .../miscellaneous/wsprintfW/CMakeLists.txt | 13 - .../miscellaneous/wsprintfW/test1/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test1/test.c | 64 -- .../miscellaneous/wsprintfW/test1/testinfo.dat | 14 - .../miscellaneous/wsprintfW/test11/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test11/test.c | 139 ---- .../miscellaneous/wsprintfW/test11/testinfo.dat | 14 - .../miscellaneous/wsprintfW/test12/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test12/test.c | 128 --- .../miscellaneous/wsprintfW/test12/testinfo.dat | 14 - .../miscellaneous/wsprintfW/test13/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test13/test.c | 126 --- .../miscellaneous/wsprintfW/test13/testinfo.dat | 14 - .../miscellaneous/wsprintfW/test2/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test2/test.c | 108 --- .../miscellaneous/wsprintfW/test2/testinfo.dat | 14 - .../miscellaneous/wsprintfW/test3/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test3/test.c | 127 --- .../miscellaneous/wsprintfW/test3/testinfo.dat | 14 - .../miscellaneous/wsprintfW/test6/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test6/test.c | 115 --- .../miscellaneous/wsprintfW/test6/testinfo.dat | 14 - .../miscellaneous/wsprintfW/test7/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test7/test.c | 117 --- .../miscellaneous/wsprintfW/test7/testinfo.dat | 14 - .../miscellaneous/wsprintfW/test8/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test8/test.c | 128 --- .../miscellaneous/wsprintfW/test8/testinfo.dat | 14 - .../miscellaneous/wsprintfW/test9/CMakeLists.txt | 19 - .../palsuite/miscellaneous/wsprintfW/test9/test.c | 128 --- .../miscellaneous/wsprintfW/test9/testinfo.dat | 14 - .../PAL_GetPALDirectoryW/test1/CMakeLists.txt | 2 +- .../test1/PAL_GetPALDirectoryW.c | 78 -- .../test1/PAL_GetPALDirectoryW.cpp | 78 ++ .../PAL_GetUserTempDirectoryW/test1/CMakeLists.txt | 2 +- .../test1/PAL_GetUserTempDirectoryW.c | 58 -- .../test1/PAL_GetUserTempDirectoryW.cpp | 58 ++ .../PAL_Initialize_Terminate/test1/CMakeLists.txt | 2 +- .../test1/PAL_Initialize_Terminate.c | 33 - .../test1/PAL_Initialize_Terminate.cpp | 33 + .../PAL_Initialize_Terminate/test2/CMakeLists.txt | 2 +- .../test2/pal_initialize_twice.c | 41 - .../test2/pal_initialize_twice.cpp | 41 + .../test1/CMakeLists.txt | 2 +- .../PAL_RegisterLibraryW_UnregisterLibraryW.c | 64 -- .../PAL_RegisterLibraryW_UnregisterLibraryW.cpp | 64 ++ .../test2_neg/CMakeLists.txt | 2 +- .../test2_neg/reg_unreg_libraryw_neg.c | 62 -- .../test2_neg/reg_unreg_libraryw_neg.cpp | 62 ++ .../pal_specific/PAL_errno/test1/CMakeLists.txt | 2 +- .../pal_specific/PAL_errno/test1/PAL_errno.c | 53 -- .../pal_specific/PAL_errno/test1/PAL_errno.cpp | 53 ++ .../PAL_get_stderr/test1/CMakeLists.txt | 2 +- .../PAL_get_stderr/test1/PAL_get_stderr.c | 52 -- .../PAL_get_stderr/test1/PAL_get_stderr.cpp | 52 ++ .../PAL_get_stdin/test1/CMakeLists.txt | 2 +- .../PAL_get_stdin/test1/PAL_get_stdin.c | 68 -- .../PAL_get_stdin/test1/PAL_get_stdin.cpp | 68 ++ .../PAL_get_stdout/test1/CMakeLists.txt | 2 +- .../PAL_get_stdout/test1/PAL_get_stdout.c | 52 -- .../PAL_get_stdout/test1/PAL_get_stdout.cpp | 52 ++ .../pal_entrypoint/test1/CMakeLists.txt | 2 +- .../pal_entrypoint/test1/pal_entrypoint.c | 54 -- .../pal_entrypoint/test1/pal_entrypoint.cpp | 54 ++ .../pal_initializedebug/test1/CMakeLists.txt | 2 +- .../test1/pal_initializedebug.c | 36 - .../test1/pal_initializedebug.cpp | 36 + src/pal/tests/palsuite/paltestlist.txt | 226 +++-- .../tests/palsuite/paltestlist_to_be_reviewed.txt | 9 +- src/pal/tests/palsuite/palverify.dat | 210 ++--- .../tests/palsuite/samples/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/samples/test1/test.c | 41 - src/pal/tests/palsuite/samples/test1/test.cpp | 41 + .../tests/palsuite/samples/test2/CMakeLists.txt | 2 +- src/pal/tests/palsuite/samples/test2/test.c | 48 -- src/pal/tests/palsuite/samples/test2/test.cpp | 48 ++ .../threading/CreateEventA/test1/CMakeLists.txt | 2 +- .../palsuite/threading/CreateEventA/test1/test1.c | 95 --- .../threading/CreateEventA/test1/test1.cpp | 95 +++ .../threading/CreateEventA/test2/CMakeLists.txt | 2 +- .../palsuite/threading/CreateEventA/test2/test2.c | 84 -- .../threading/CreateEventA/test2/test2.cpp | 84 ++ .../threading/CreateEventA/test3/CMakeLists.txt | 2 +- .../palsuite/threading/CreateEventA/test3/test3.c | 219 ----- .../threading/CreateEventA/test3/test3.cpp | 219 +++++ .../threading/CreateEventW/test1/CMakeLists.txt | 2 +- .../palsuite/threading/CreateEventW/test1/test1.c | 93 --- .../threading/CreateEventW/test1/test1.cpp | 93 +++ .../threading/CreateEventW/test2/CMakeLists.txt | 2 +- .../palsuite/threading/CreateEventW/test2/test2.c | 85 -- .../threading/CreateEventW/test2/test2.cpp | 85 ++ .../threading/CreateEventW/test3/CMakeLists.txt | 2 +- .../palsuite/threading/CreateEventW/test3/test3.c | 233 ------ .../threading/CreateEventW/test3/test3.cpp | 233 ++++++ .../CreateMutexA_ReleaseMutex/test1/CMakeLists.txt | 2 +- .../CreateMutexA_ReleaseMutex/test1/CreateMutexA.c | 345 -------- .../test1/CreateMutexA.cpp | 345 ++++++++ .../CreateMutexA_ReleaseMutex/test2/CMakeLists.txt | 2 +- .../CreateMutexA_ReleaseMutex/test2/CreateMutexA.c | 331 -------- .../test2/CreateMutexA.cpp | 331 ++++++++ .../CreateMutexW_ReleaseMutex/test1/CMakeLists.txt | 2 +- .../CreateMutexW_ReleaseMutex/test1/CreateMutexW.c | 345 -------- .../test1/CreateMutexW.cpp | 345 ++++++++ .../CreateMutexW_ReleaseMutex/test2/CMakeLists.txt | 2 +- .../CreateMutexW_ReleaseMutex/test2/CreateMutexW.c | 340 -------- .../test2/CreateMutexW.cpp | 340 ++++++++ .../threading/CreateProcessA/test1/CMakeLists.txt | 4 +- .../threading/CreateProcessA/test1/childProcess.c | 131 --- .../CreateProcessA/test1/childProcess.cpp | 131 +++ .../threading/CreateProcessA/test1/parentProcess.c | 201 ----- .../CreateProcessA/test1/parentProcess.cpp | 201 +++++ .../threading/CreateProcessA/test2/CMakeLists.txt | 4 +- .../threading/CreateProcessA/test2/childprocess.c | 69 -- .../CreateProcessA/test2/childprocess.cpp | 69 ++ .../threading/CreateProcessA/test2/parentprocess.c | 243 ------ .../CreateProcessA/test2/parentprocess.cpp | 243 ++++++ .../threading/CreateProcessW/test1/CMakeLists.txt | 4 +- .../threading/CreateProcessW/test1/childProcess.c | 150 ---- .../CreateProcessW/test1/childProcess.cpp | 150 ++++ .../threading/CreateProcessW/test1/parentProcess.c | 210 ----- .../CreateProcessW/test1/parentProcess.cpp | 210 +++++ .../threading/CreateProcessW/test2/CMakeLists.txt | 4 +- .../threading/CreateProcessW/test2/childprocess.c | 78 -- .../CreateProcessW/test2/childprocess.cpp | 78 ++ .../threading/CreateProcessW/test2/parentprocess.c | 245 ------ .../CreateProcessW/test2/parentprocess.cpp | 245 ++++++ .../test1/CMakeLists.txt | 2 +- .../test1/CreateSemaphore.c | 322 -------- .../test1/CreateSemaphore.cpp | 322 ++++++++ .../test2/CMakeLists.txt | 2 +- .../test2/CreateSemaphore.c | 313 ------- .../test2/CreateSemaphore.cpp | 313 +++++++ .../test3/CMakeLists.txt | 2 +- .../test3/createsemaphore.c | 200 ----- .../test3/createsemaphore.cpp | 200 +++++ .../test1/CMakeLists.txt | 2 +- .../test1/CreateSemaphore.c | 323 -------- .../test1/CreateSemaphore.cpp | 323 ++++++++ .../test2/CMakeLists.txt | 2 +- .../test2/CreateSemaphore.c | 314 ------- .../test2/CreateSemaphore.cpp | 314 +++++++ .../test3/CMakeLists.txt | 2 +- .../test3/createsemaphore.c | 201 ----- .../test3/createsemaphore.cpp | 201 +++++ .../threading/CreateThread/test1/CMakeLists.txt | 2 +- .../palsuite/threading/CreateThread/test1/test1.c | 119 --- .../threading/CreateThread/test1/test1.cpp | 119 +++ .../threading/CreateThread/test2/CMakeLists.txt | 2 +- .../palsuite/threading/CreateThread/test2/test2.c | 184 ----- .../threading/CreateThread/test2/test2.cpp | 184 +++++ .../threading/CreateThread/test3/CMakeLists.txt | 2 +- .../palsuite/threading/CreateThread/test3/test3.c | 101 --- .../threading/CreateThread/test3/test3.cpp | 101 +++ .../CriticalSectionFunctions/test1/CMakeLists.txt | 2 +- .../test1/InitializeCriticalSection.c | 235 ------ .../test1/InitializeCriticalSection.cpp | 235 ++++++ .../CriticalSectionFunctions/test2/CMakeLists.txt | 2 +- .../CriticalSectionFunctions/test2/test2.c | 226 ----- .../CriticalSectionFunctions/test2/test2.cpp | 226 +++++ .../CriticalSectionFunctions/test3/CMakeLists.txt | 2 +- .../CriticalSectionFunctions/test3/test3.c | 376 --------- .../CriticalSectionFunctions/test3/test3.cpp | 376 +++++++++ .../CriticalSectionFunctions/test4/CMakeLists.txt | 2 +- .../CriticalSectionFunctions/test4/test4.c | 241 ------ .../CriticalSectionFunctions/test4/test4.cpp | 241 ++++++ .../CriticalSectionFunctions/test5/CMakeLists.txt | 2 +- .../CriticalSectionFunctions/test5/test5.c | 187 ----- .../CriticalSectionFunctions/test5/test5.cpp | 187 +++++ .../CriticalSectionFunctions/test6/CMakeLists.txt | 2 +- .../CriticalSectionFunctions/test6/test6.c | 190 ----- .../CriticalSectionFunctions/test6/test6.cpp | 190 +++++ .../CriticalSectionFunctions/test7/CMakeLists.txt | 2 +- .../CriticalSectionFunctions/test7/test7.c | 188 ----- .../CriticalSectionFunctions/test7/test7.cpp | 188 +++++ .../CriticalSectionFunctions/test8/CMakeLists.txt | 2 +- .../CriticalSectionFunctions/test8/test8.c | 217 ----- .../CriticalSectionFunctions/test8/test8.cpp | 217 +++++ .../DisableThreadLibraryCalls/test1/test1.c | 145 ---- .../DisableThreadLibraryCalls/test1/test1.cpp | 145 ++++ .../DisableThreadLibraryCalls/test1/testlib.c | 47 -- .../DisableThreadLibraryCalls/test1/testlib.cpp | 47 ++ .../DisableThreadLibraryCalls/test2/dllmain1.c | 66 -- .../DisableThreadLibraryCalls/test2/dllmain1.cpp | 66 ++ .../DisableThreadLibraryCalls/test2/dllmain2.c | 66 -- .../DisableThreadLibraryCalls/test2/dllmain2.cpp | 66 ++ .../DisableThreadLibraryCalls/test2/test2.c | 237 ------ .../DisableThreadLibraryCalls/test2/test2.cpp | 237 ++++++ .../threading/DuplicateHandle/CMakeLists.txt | 1 - .../threading/DuplicateHandle/test1/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test1/test1.c | 152 ---- .../threading/DuplicateHandle/test1/test1.cpp | 152 ++++ .../DuplicateHandle/test10/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test10/test10.c | 239 ------ .../threading/DuplicateHandle/test10/test10.cpp | 239 ++++++ .../DuplicateHandle/test11/CMakeLists.txt | 4 +- .../DuplicateHandle/test11/childprocess.c | 74 -- .../DuplicateHandle/test11/childprocess.cpp | 74 ++ .../threading/DuplicateHandle/test11/test11.c | 364 -------- .../threading/DuplicateHandle/test11/test11.cpp | 364 ++++++++ .../DuplicateHandle/test12/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test12/test12.c | 129 --- .../threading/DuplicateHandle/test12/test12.cpp | 129 +++ .../threading/DuplicateHandle/test2/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test2/test2.c | 96 --- .../threading/DuplicateHandle/test2/test2.cpp | 96 +++ .../threading/DuplicateHandle/test3/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test3/test3.c | 123 --- .../threading/DuplicateHandle/test3/test3.cpp | 123 +++ .../threading/DuplicateHandle/test4/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test4/test4.c | 239 ------ .../threading/DuplicateHandle/test4/test4.cpp | 239 ++++++ .../threading/DuplicateHandle/test5/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test5/test5.c | 145 ---- .../threading/DuplicateHandle/test5/test5.cpp | 145 ++++ .../threading/DuplicateHandle/test6/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test6/test6.c | 146 ---- .../threading/DuplicateHandle/test6/test6.cpp | 146 ++++ .../threading/DuplicateHandle/test7/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test7/test7.c | 149 ---- .../threading/DuplicateHandle/test7/test7.cpp | 149 ++++ .../threading/DuplicateHandle/test8/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test8/test8.c | 164 ---- .../threading/DuplicateHandle/test8/test8.cpp | 164 ++++ .../threading/DuplicateHandle/test9/CMakeLists.txt | 2 +- .../threading/DuplicateHandle/test9/test9.c | 127 --- .../threading/DuplicateHandle/test9/test9.cpp | 127 +++ .../threading/ExitProcess/test1/CMakeLists.txt | 2 +- .../threading/ExitProcess/test1/ExitProcess.c | 32 - .../threading/ExitProcess/test1/ExitProcess.cpp | 32 + .../threading/ExitProcess/test2/CMakeLists.txt | 2 +- .../palsuite/threading/ExitProcess/test2/test2.c | 30 - .../palsuite/threading/ExitProcess/test2/test2.cpp | 30 + .../threading/ExitProcess/test3/CMakeLists.txt | 2 +- .../palsuite/threading/ExitProcess/test3/test3.c | 40 - .../palsuite/threading/ExitProcess/test3/test3.cpp | 40 + .../threading/ExitThread/test1/CMakeLists.txt | 2 +- .../palsuite/threading/ExitThread/test1/test1.c | 114 --- .../palsuite/threading/ExitThread/test1/test1.cpp | 114 +++ .../threading/ExitThread/test2/CMakeLists.txt | 4 +- .../threading/ExitThread/test2/childprocess.c | 41 - .../threading/ExitThread/test2/childprocess.cpp | 41 + .../palsuite/threading/ExitThread/test2/test2.c | 168 ---- .../palsuite/threading/ExitThread/test2/test2.cpp | 168 ++++ .../palsuite/threading/ExitThread/test3/dllmain.c | 65 -- .../threading/ExitThread/test3/dllmain.cpp | 65 ++ .../palsuite/threading/ExitThread/test3/test3.c | 162 ---- .../palsuite/threading/ExitThread/test3/test3.cpp | 162 ++++ .../GetCurrentProcess/test1/CMakeLists.txt | 2 +- .../threading/GetCurrentProcess/test1/process.c | 40 - .../threading/GetCurrentProcess/test1/process.cpp | 40 + .../GetCurrentProcessId/test1/CMakeLists.txt | 2 +- .../GetCurrentProcessId/test1/processId.c | 41 - .../GetCurrentProcessId/test1/processId.cpp | 41 + .../GetCurrentThread/test1/CMakeLists.txt | 2 +- .../threading/GetCurrentThread/test1/thread.c | 93 --- .../threading/GetCurrentThread/test1/thread.cpp | 93 +++ .../GetCurrentThread/test2/CMakeLists.txt | 2 +- .../threading/GetCurrentThread/test2/test2.c | 144 ---- .../threading/GetCurrentThread/test2/test2.cpp | 144 ++++ .../GetCurrentThreadId/test1/CMakeLists.txt | 2 +- .../threading/GetCurrentThreadId/test1/threadId.c | 82 -- .../GetCurrentThreadId/test1/threadId.cpp | 82 ++ .../GetExitCodeProcess/test1/CMakeLists.txt | 4 +- .../GetExitCodeProcess/test1/childProcess.c | 31 - .../GetExitCodeProcess/test1/childProcess.cpp | 31 + .../threading/GetExitCodeProcess/test1/test1.c | 163 ---- .../threading/GetExitCodeProcess/test1/test1.cpp | 163 ++++ .../threading/GetProcessTimes/test2/CMakeLists.txt | 2 +- .../threading/GetProcessTimes/test2/test2.c | 122 --- .../threading/GetProcessTimes/test2/test2.cpp | 122 +++ .../threading/GetThreadTimes/test1/CMakeLists.txt | 2 +- .../threading/GetThreadTimes/test1/test1.c | 102 --- .../threading/GetThreadTimes/test1/test1.cpp | 102 +++ .../threading/NamedMutex/test1/namedmutex.cpp | 12 +- .../threading/OpenEventW/test1/CMakeLists.txt | 2 +- .../palsuite/threading/OpenEventW/test1/test1.c | 134 --- .../palsuite/threading/OpenEventW/test1/test1.cpp | 134 +++ .../threading/OpenEventW/test2/CMakeLists.txt | 2 +- .../palsuite/threading/OpenEventW/test2/test2.c | 194 ----- .../palsuite/threading/OpenEventW/test2/test2.cpp | 194 +++++ .../threading/OpenEventW/test3/CMakeLists.txt | 4 +- .../threading/OpenEventW/test3/childprocess.c | 81 -- .../threading/OpenEventW/test3/childprocess.cpp | 81 ++ .../palsuite/threading/OpenEventW/test3/test3.c | 187 ----- .../palsuite/threading/OpenEventW/test3/test3.cpp | 187 +++++ .../threading/OpenEventW/test4/CMakeLists.txt | 2 +- .../palsuite/threading/OpenEventW/test4/test4.c | 112 --- .../palsuite/threading/OpenEventW/test4/test4.cpp | 112 +++ .../threading/OpenEventW/test5/CMakeLists.txt | 2 +- .../palsuite/threading/OpenEventW/test5/test5.c | 197 ----- .../palsuite/threading/OpenEventW/test5/test5.cpp | 197 +++++ .../threading/OpenProcess/test1/CMakeLists.txt | 4 +- .../threading/OpenProcess/test1/childProcess.c | 75 -- .../threading/OpenProcess/test1/childProcess.cpp | 75 ++ .../palsuite/threading/OpenProcess/test1/test1.c | 282 ------- .../palsuite/threading/OpenProcess/test1/test1.cpp | 282 +++++++ .../QueryThreadCycleTime/test1/CMakeLists.txt | 2 +- .../threading/QueryThreadCycleTime/test1/test1.c | 98 --- .../threading/QueryThreadCycleTime/test1/test1.cpp | 98 +++ .../threading/QueueUserAPC/test1/CMakeLists.txt | 2 +- .../palsuite/threading/QueueUserAPC/test1/test1.c | 313 ------- .../threading/QueueUserAPC/test1/test1.cpp | 313 +++++++ .../threading/QueueUserAPC/test2/CMakeLists.txt | 2 +- .../palsuite/threading/QueueUserAPC/test2/test2.c | 224 ----- .../threading/QueueUserAPC/test2/test2.cpp | 224 +++++ .../threading/QueueUserAPC/test3/CMakeLists.txt | 2 +- .../palsuite/threading/QueueUserAPC/test3/test3.c | 33 - .../threading/QueueUserAPC/test3/test3.cpp | 33 + .../threading/QueueUserAPC/test4/CMakeLists.txt | 2 +- .../palsuite/threading/QueueUserAPC/test4/test4.c | 72 -- .../threading/QueueUserAPC/test4/test4.cpp | 72 ++ .../threading/QueueUserAPC/test5/CMakeLists.txt | 2 +- .../palsuite/threading/QueueUserAPC/test5/test5.c | 200 ----- .../threading/QueueUserAPC/test5/test5.cpp | 200 +++++ .../threading/QueueUserAPC/test6/CMakeLists.txt | 2 +- .../palsuite/threading/QueueUserAPC/test6/test6.c | 129 --- .../threading/QueueUserAPC/test6/test6.cpp | 129 +++ .../threading/QueueUserAPC/test7/CMakeLists.txt | 2 +- .../palsuite/threading/QueueUserAPC/test7/test7.c | 253 ------ .../threading/QueueUserAPC/test7/test7.cpp | 253 ++++++ .../threading/ReleaseMutex/test3/CMakeLists.txt | 2 +- .../threading/ReleaseMutex/test3/ReleaseMutex.c | 103 --- .../threading/ReleaseMutex/test3/ReleaseMutex.cpp | 103 +++ .../threading/ResetEvent/test1/CMakeLists.txt | 2 +- .../palsuite/threading/ResetEvent/test1/test1.c | 99 --- .../palsuite/threading/ResetEvent/test1/test1.cpp | 99 +++ .../threading/ResetEvent/test2/CMakeLists.txt | 2 +- .../palsuite/threading/ResetEvent/test2/test2.c | 89 -- .../palsuite/threading/ResetEvent/test2/test2.cpp | 89 ++ .../threading/ResetEvent/test3/CMakeLists.txt | 2 +- .../palsuite/threading/ResetEvent/test3/test3.c | 86 -- .../palsuite/threading/ResetEvent/test3/test3.cpp | 86 ++ .../threading/ResetEvent/test4/CMakeLists.txt | 2 +- .../palsuite/threading/ResetEvent/test4/test4.c | 161 ---- .../palsuite/threading/ResetEvent/test4/test4.cpp | 161 ++++ .../threading/ResumeThread/test1/CMakeLists.txt | 2 +- .../palsuite/threading/ResumeThread/test1/test1.c | 141 ---- .../threading/ResumeThread/test1/test1.cpp | 141 ++++ .../threading/SetErrorMode/test1/CMakeLists.txt | 2 +- .../palsuite/threading/SetErrorMode/test1/test1.c | 50 -- .../threading/SetErrorMode/test1/test1.cpp | 50 ++ .../threading/SetEvent/test1/CMakeLists.txt | 2 +- .../palsuite/threading/SetEvent/test1/test1.c | 94 --- .../palsuite/threading/SetEvent/test1/test1.cpp | 94 +++ .../threading/SetEvent/test2/CMakeLists.txt | 2 +- .../palsuite/threading/SetEvent/test2/test2.c | 125 --- .../palsuite/threading/SetEvent/test2/test2.cpp | 125 +++ .../threading/SetEvent/test3/CMakeLists.txt | 2 +- .../palsuite/threading/SetEvent/test3/test3.c | 85 -- .../palsuite/threading/SetEvent/test3/test3.cpp | 85 ++ .../threading/SetEvent/test4/CMakeLists.txt | 2 +- .../palsuite/threading/SetEvent/test4/test4.c | 161 ---- .../palsuite/threading/SetEvent/test4/test4.cpp | 161 ++++ .../palsuite/threading/Sleep/test1/CMakeLists.txt | 2 +- .../tests/palsuite/threading/Sleep/test1/Sleep.c | 80 -- .../tests/palsuite/threading/Sleep/test1/Sleep.cpp | 80 ++ .../palsuite/threading/Sleep/test2/CMakeLists.txt | 2 +- .../tests/palsuite/threading/Sleep/test2/sleep.c | 73 -- .../tests/palsuite/threading/Sleep/test2/sleep.cpp | 73 ++ .../threading/SleepEx/test1/CMakeLists.txt | 2 +- .../tests/palsuite/threading/SleepEx/test1/test1.c | 89 -- .../palsuite/threading/SleepEx/test1/test1.cpp | 89 ++ .../threading/SleepEx/test2/CMakeLists.txt | 2 +- .../tests/palsuite/threading/SleepEx/test2/test2.c | 183 ----- .../palsuite/threading/SleepEx/test2/test2.cpp | 183 +++++ .../threading/SwitchToThread/test1/CMakeLists.txt | 2 +- .../threading/SwitchToThread/test1/test1.c | 97 --- .../threading/SwitchToThread/test1/test1.cpp | 97 +++ .../palsuite/threading/TLS/test1/CMakeLists.txt | 2 +- src/pal/tests/palsuite/threading/TLS/test1/TLS.c | 182 ---- src/pal/tests/palsuite/threading/TLS/test1/TLS.cpp | 182 ++++ .../palsuite/threading/TLS/test2/CMakeLists.txt | 2 +- src/pal/tests/palsuite/threading/TLS/test2/TLS.c | 66 -- src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp | 66 ++ .../palsuite/threading/TLS/test3/CMakeLists.txt | 2 +- src/pal/tests/palsuite/threading/TLS/test3/TLS.c | 90 -- src/pal/tests/palsuite/threading/TLS/test3/TLS.cpp | 90 ++ .../palsuite/threading/TLS/test4/CMakeLists.txt | 2 +- src/pal/tests/palsuite/threading/TLS/test4/test4.c | 137 --- .../tests/palsuite/threading/TLS/test4/test4.cpp | 137 +++ .../palsuite/threading/TLS/test5/CMakeLists.txt | 2 +- src/pal/tests/palsuite/threading/TLS/test5/test5.c | 108 --- .../tests/palsuite/threading/TLS/test5/test5.cpp | 108 +++ .../TLS/test6_optimizedtls/CMakeLists.txt | 2 +- .../threading/TLS/test6_optimizedtls/test.c | 190 ----- .../threading/TLS/test6_optimizedtls/test.cpp | 190 +++++ .../TerminateProcess/test1/CMakeLists.txt | 2 +- .../TerminateProcess/test1/TerminateProcess.c | 41 - .../TerminateProcess/test1/TerminateProcess.cpp | 41 + .../threading/ThreadPriority/test1/CMakeLists.txt | 2 +- .../ThreadPriority/test1/ThreadPriority.c | 83 -- .../ThreadPriority/test1/ThreadPriority.cpp | 83 ++ .../WaitForMultipleObjects/test1/CMakeLists.txt | 2 +- .../threading/WaitForMultipleObjects/test1/test1.c | 224 ----- .../WaitForMultipleObjects/test1/test1.cpp | 224 +++++ .../WaitForMultipleObjectsEx/test1/CMakeLists.txt | 2 +- .../WaitForMultipleObjectsEx/test1/test1.c | 226 ----- .../WaitForMultipleObjectsEx/test1/test1.cpp | 226 +++++ .../WaitForMultipleObjectsEx/test2/CMakeLists.txt | 2 +- .../WaitForMultipleObjectsEx/test2/test2.c | 188 ----- .../WaitForMultipleObjectsEx/test2/test2.cpp | 188 +++++ .../WaitForMultipleObjectsEx/test3/CMakeLists.txt | 2 +- .../WaitForMultipleObjectsEx/test3/test3.c | 106 --- .../WaitForMultipleObjectsEx/test3/test3.cpp | 106 +++ .../WaitForMultipleObjectsEx/test4/CMakeLists.txt | 2 +- .../WaitForMultipleObjectsEx/test4/test4.c | 101 --- .../WaitForMultipleObjectsEx/test4/test4.cpp | 101 +++ .../WaitForMultipleObjectsEx/test5/CMakeLists.txt | 4 +- .../WaitForMultipleObjectsEx/test5/helper.c | 122 --- .../WaitForMultipleObjectsEx/test5/helper.cpp | 122 +++ .../WaitForMultipleObjectsEx/test5/test5.c | 506 ------------ .../WaitForMultipleObjectsEx/test5/test5.cpp | 506 ++++++++++++ .../WaitForMultipleObjectsEx/test6/CMakeLists.txt | 4 +- .../WaitForMultipleObjectsEx/test6/child6.c | 211 ----- .../WaitForMultipleObjectsEx/test6/child6.cpp | 211 +++++ .../WaitForMultipleObjectsEx/test6/test6.c | 709 ---------------- .../WaitForMultipleObjectsEx/test6/test6.cpp | 709 ++++++++++++++++ .../WFSOExMutexTest/CMakeLists.txt | 2 +- .../WFSOExMutexTest/WFSOExMutexTest.c | 214 ----- .../WFSOExMutexTest/WFSOExMutexTest.cpp | 214 +++++ .../WFSOExSemaphoreTest/CMakeLists.txt | 2 +- .../WFSOExSemaphoreTest/WFSOExSemaphoreTest.c | 184 ----- .../WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp | 184 +++++ .../WFSOExThreadTest/CMakeLists.txt | 2 +- .../WFSOExThreadTest/WFSOExThreadTest.c | 204 ----- .../WFSOExThreadTest/WFSOExThreadTest.cpp | 204 +++++ .../WFSOMutexTest/CMakeLists.txt | 2 +- .../WFSOMutexTest/WFSOMutexTest.c | 184 ----- .../WFSOMutexTest/WFSOMutexTest.cpp | 184 +++++ .../WFSOProcessTest/CMakeLists.txt | 4 +- .../WFSOProcessTest/ChildProcess.c | 50 -- .../WFSOProcessTest/ChildProcess.cpp | 50 ++ .../WFSOProcessTest/WFSOProcessTest.c | 119 --- .../WFSOProcessTest/WFSOProcessTest.cpp | 119 +++ .../WFSOSemaphoreTest/CMakeLists.txt | 2 +- .../WFSOSemaphoreTest/WFSOSemaphoreTest.c | 183 ----- .../WFSOSemaphoreTest/WFSOSemaphoreTest.cpp | 183 +++++ .../WFSOThreadTest/CMakeLists.txt | 2 +- .../WFSOThreadTest/WFSOThreadTest.c | 179 ---- .../WFSOThreadTest/WFSOThreadTest.cpp | 179 ++++ .../WaitForSingleObject/test1/CMakeLists.txt | 2 +- .../threading/WaitForSingleObject/test1/test1.c | 121 --- .../threading/WaitForSingleObject/test1/test1.cpp | 121 +++ .../threading/YieldProcessor/test1/CMakeLists.txt | 2 +- .../threading/YieldProcessor/test1/test1.c | 92 --- .../threading/YieldProcessor/test1/test1.cpp | 92 +++ .../releasesemaphore/test1/CMakeLists.txt | 2 +- .../threading/releasesemaphore/test1/test.c | 68 -- .../threading/releasesemaphore/test1/test.cpp | 68 ++ 3478 files changed, 115588 insertions(+), 117935 deletions(-) delete mode 100644 src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.c create mode 100644 src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_finite/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_finitef/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_finitef/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_finitef/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_finitef/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c create mode 100644 src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_getw/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_getw/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_isnanf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_isnanf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_isnanf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_isnanf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_itow/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_itow/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_makepath/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_makepath/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_makepath/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_makepath/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_mbslen/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_mbslen/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_mbslen/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_mbslen/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_putw/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_putw/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/_snprintf.h delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test10/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test10/test10.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test10/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test11/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test11/test11.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test11/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test12/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test12/test12.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test12/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test13/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test13/test13.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test13/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test14/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test14/test14.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test14/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test15/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test15/test15.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test15/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test16/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test16/test16.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test16/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test17/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test17/test17.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test17/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test18/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test18/test18.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test18/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test19/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test19/test19.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test19/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test2/test2.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test3/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test3/test3.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test3/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test4/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test4/test4.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test4/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test5/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test5/test5.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test5/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test6/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test6/test6.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test6/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test7/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test7/test7.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test7/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test8/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test8/test8.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test8/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test9/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test9/test9.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf/test9/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/_snprintf_s.h create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/test10.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/test11.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/test12.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/test13.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/test14.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/test15.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/test16.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/test17.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/test18.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/test19.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/test2.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/test3.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/test4.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/test6.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/test7.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/test8.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/test9.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/_snwprintf.h delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test10/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test10/test10.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test10/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test11/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test11/test11.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test11/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test12/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test12/test12.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test12/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test13/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test13/test13.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test13/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test14/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test14/test14.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test14/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test15/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test15/test15.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test15/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test16/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test16/test16.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test16/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test17/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test17/test17.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test17/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test18/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test18/test18.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test18/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test19/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test19/test19.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test19/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test2/test2.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test3/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test3/test3.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test3/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test4/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test4/test4.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test4/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test5/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test5/test5.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test5/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test6/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test6/test6.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test6/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test7/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test7/test7.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test7/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test8/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test8/test8.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test8/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test9/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test9/test9.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf/test9/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/_snwprintf_s.h create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/test10.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/test11.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/test12.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/test13.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/test14.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/test15.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/test16.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/test17.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/test18.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/test19.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/test2.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/test3.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/test4.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/test6.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/test7.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/test8.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/test9.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_splitpath/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_splitpath/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_splitpath/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_splitpath/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_strlwr/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_strlwr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_swab/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_swab/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_swab/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_swab/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/test18.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/test18.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/test19.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/test19.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/_vsnwprintf.h delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/test10.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/test11.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/test12.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/test13.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/test14.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/test15.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/test16.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/test17.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/test18.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/test19.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/test2.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/test3.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/test4.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/test5.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/test6.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/test7.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/test8.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/test9.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/_vsnwprintf_s.h create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/test10.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/test11.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/test12.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/test13.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/test14.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/test15.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/test16.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/test17.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/test18.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/test19.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/test2.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/test3.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/test4.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/test6.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/test7.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/test8.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/test9.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wcslwr/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wcslwr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wfopen/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/_wmakepath/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_wmakepath/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_wmakepath/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_wmakepath/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_wsplitpath/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/_wtoi/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/_wtoi/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/abs/test1/abs.c create mode 100644 src/pal/tests/palsuite/c_runtime/abs/test1/abs.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/acos/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/acos/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/acosf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/acosf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/acosf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/acosf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/asin/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/asin/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/asinf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/asinf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/asinf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/asinf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/atan/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atan/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/atan2/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atan2/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/atan2f/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atan2f/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atan2f/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atan2f/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/atanf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atanf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atanf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atanf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/atof/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atof/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/atoi/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atoi/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/atol/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atol/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/bsearch/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/bsearch/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/bsearch/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/bsearch/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/ceil/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/ceil/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/ceilf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/ceilf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/ceilf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/ceilf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/cos/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/cos/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/cosf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/cosf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/cosf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/cosf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/cosh/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/cosh/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/coshf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/coshf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/coshf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/coshf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/ctime/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/ctime/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/errno/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/errno/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/errno/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/errno/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/exit/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/exit/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/exit/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/exit/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/exp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/exp/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/expf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/expf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/expf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/expf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/fabs/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fabs/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fclose/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fclose/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fclose/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/fclose/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/feof/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/feof/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/ferror/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/ferror/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/ferror/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/ferror/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fflush/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fflush/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fgets/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fgets/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fgets/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/fgets/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fgets/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/floor/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/floor/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/floorf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/floorf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/floorf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/floorf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/fmod/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fmod/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/fopen/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test18/test18.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test18/test18.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test19/test19.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test19/test19.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/fprintf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fputs/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fputs/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fputs/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fread/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fread/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fread/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/fread/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fread/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/fread/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/free/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/free/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fseek/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fseek/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/ftell/test1/ftell.c create mode 100644 src/pal/tests/palsuite/c_runtime/ftell/test1/ftell.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test18/test18.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test18/test18.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test19/test19.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test19/test19.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwprintf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/fwrite/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fwrite/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/getc/test1/getc.c create mode 100644 src/pal/tests/palsuite/c_runtime/getc/test1/getc.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/getenv/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/getenv/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/getenv/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/getenv/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/getenv/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/getenv/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/isalnum/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/isalnum/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/isalpha/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/isalpha/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/isdigit/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/isdigit/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/islower/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/islower/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/isprint/test1/isprint.c create mode 100644 src/pal/tests/palsuite/c_runtime/isprint/test1/isprint.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/isprint/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/isprint/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/isspace/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/isspace/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/isupper/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/isupper/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/iswdigit/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/iswdigit/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/iswprint/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/iswprint/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/iswspace/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/iswspace/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/iswupper/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/iswupper/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/iswxdigit/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/iswxdigit/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/isxdigit/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/isxdigit/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/labs/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/labs/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/llabs/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/llabs/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/localtime/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/localtime/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/log/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/log/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/log10/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/log10/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/log10f/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/log10f/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/log10f/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/log10f/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/logf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/logf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/logf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/logf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/malloc/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/malloc/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/malloc/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/malloc/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/memchr/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/memchr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/memcmp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/memcmp/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/memcpy/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/memcpy/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/memmove/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/memmove/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/memset/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/memset/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/modf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/modf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/modff/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/modff/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/pow/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/pow/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/powf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/powf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/powf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/powf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test18/test18.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test18/test18.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test19/test19.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test19/test19.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/printf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/printf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/qsort/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/qsort/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/qsort/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/qsort/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/rand_srand/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/rand_srand/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/realloc/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/realloc/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/sin/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/sin/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sinf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sinf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sinf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/sinf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sinh/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/sinh/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sinhf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sinhf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sinhf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/sinhf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/sprintf.h delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test10/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test10/test10.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test10/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test11/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test11/test11.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test11/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test12/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test12/test12.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test12/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test13/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test13/test13.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test13/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test14/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test14/test14.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test14/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test15/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test15/test15.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test15/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test16/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test16/test16.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test16/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test17/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test17/test17.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test17/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test18/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test18/test18.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test18/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test19/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test19/test19.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test19/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test2/test2.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test3/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test3/test3.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test3/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test4/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test4/test4.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test4/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test5/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test5/test5.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test5/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test6/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test6/test6.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test6/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test7/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test7/test7.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test7/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test8/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test8/test8.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test8/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test9/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test9/test9.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sprintf/test9/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/sprintf_s.h create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test10/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test10/test10.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test10/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test11/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test11/test11.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test11/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test12/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test12/test12.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test12/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test13/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test13/test13.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test13/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test14/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test14/test14.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test14/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test15/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test15/test15.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test15/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test16/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test16/test16.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test16/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test17/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test17/test17.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test17/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test18/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test18/test18.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test18/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test19/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test19/test19.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test19/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test2/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test2/test2.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test2/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test3/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test3/test3.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test3/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test4/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test4/test4.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test4/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test6/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test6/test6.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test6/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test7/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test7/test7.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test7/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test8/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test8/test8.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test8/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test9/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test9/test9.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sprintf_s/test9/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sqrt/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/sqrt/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sqrtf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sqrtf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sqrtf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/sqrtf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/sscanf.h delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test1/test1.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test10/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test10/test10.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test10/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test11/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test11/test11.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test11/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test12/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test12/test12.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test12/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test13/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test13/test13.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test13/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test14/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test14/test14.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test14/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test15/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test15/test15.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test15/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test16/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test16/test16.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test16/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test17/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test17/test17.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test17/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test2/test2.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test3/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test3/test3.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test3/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test4/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test4/test4.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test4/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test5/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test5/test5.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test5/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test6/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test6/test6.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test6/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test7/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test7/test7.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test7/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test8/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test8/test8.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test8/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test9/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test9/test9.c delete mode 100644 src/pal/tests/palsuite/c_runtime/sscanf/test9/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/sscanf_s.h create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test10/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test10/test10.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test10/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test11/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test11/test11.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test11/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test12/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test12/test12.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test12/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test13/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test13/test13.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test13/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test14/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test14/test14.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test14/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test15/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test15/test15.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test15/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test16/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test16/test16.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test16/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test17/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test17/test17.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test17/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test2/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test2/test2.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test2/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test3/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test3/test3.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test3/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test4/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test4/test4.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test4/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test5/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test5/test5.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test5/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test6/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test6/test6.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test6/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test7/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test7/test7.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test7/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test8/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test8/test8.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test8/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test9/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test9/test9.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/sscanf_s/test9/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/strcat/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strcat/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strchr/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strchr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strcmp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strcmp/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strcpy/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strcpy/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strcspn/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strcspn/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strlen/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strlen/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strncat/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strncat/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strncmp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strncmp/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strncpy/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strncpy/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strpbrk/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strpbrk/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strrchr/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strrchr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strspn/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strspn/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strstr/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strstr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strtod/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strtod/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strtod/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/strtod/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strtok/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strtok/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/strtoul/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/strtoul/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test18/test18.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test18/test18.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test19/test19.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test19/test19.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/swprintf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/swscanf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/tan/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/tan/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/tanf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/tanf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/tanf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/tanf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/tanh/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/tanh/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/tanhf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/tanhf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/tanhf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/tanhf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/time/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/time/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/tolower/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/tolower/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/toupper/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/toupper/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/towlower/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/towlower/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/towupper/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/towupper/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/ungetc/test1/ungetc.c create mode 100644 src/pal/tests/palsuite/c_runtime/ungetc/test1/ungetc.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/ungetc/test2/ungetc.c create mode 100644 src/pal/tests/palsuite/c_runtime/ungetc/test2/ungetc.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test18/test18.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test18/test18.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test19/test19.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test19/test19.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/vfprintf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test18/test18.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test18/test18.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test19/test19.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test19/test19.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/vprintf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test18/test18.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test18/test18.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test19/test19.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test19/test19.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/vsprintf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.c create mode 100644 src/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcscat/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcscat/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcschr/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcschr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcscmp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcscmp/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcscpy/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcscpy/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcslen/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcslen/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcsncat/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcsncat/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcsncmp/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcsncmp/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcsncpy/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcsncpy/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcspbrk/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcspbrk/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcsrchr/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcsrchr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstod/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstod/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstod/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstod/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstok/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstok/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstol/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test4/test4.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test5/test5.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test6/test6.c create mode 100644 src/pal/tests/palsuite/c_runtime/wcstoul/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/event/nonshared/event.c create mode 100644 src/pal/tests/palsuite/composite/object_management/event/nonshared/event.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/event/nonshared/main.c create mode 100644 src/pal/tests/palsuite/composite/object_management/event/nonshared/main.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/event/shared/event.c create mode 100644 src/pal/tests/palsuite/composite/object_management/event/shared/event.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/event/shared/main.c create mode 100644 src/pal/tests/palsuite/composite/object_management/event/shared/main.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/mutex/nonshared/main.c create mode 100644 src/pal/tests/palsuite/composite/object_management/mutex/nonshared/main.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/mutex/nonshared/mutex.c create mode 100644 src/pal/tests/palsuite/composite/object_management/mutex/nonshared/mutex.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/mutex/shared/main.c create mode 100644 src/pal/tests/palsuite/composite/object_management/mutex/shared/main.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/mutex/shared/mutex.c create mode 100644 src/pal/tests/palsuite/composite/object_management/mutex/shared/mutex.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/main.c create mode 100644 src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/main.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/semaphore.c create mode 100644 src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/semaphore.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/semaphore/shared/main.c create mode 100644 src/pal/tests/palsuite/composite/object_management/semaphore/shared/main.cpp delete mode 100644 src/pal/tests/palsuite/composite/object_management/semaphore/shared/semaphore.c create mode 100644 src/pal/tests/palsuite/composite/object_management/semaphore/shared/semaphore.cpp delete mode 100644 src/pal/tests/palsuite/composite/synchronization/criticalsection/criticalsection.c create mode 100644 src/pal/tests/palsuite/composite/synchronization/criticalsection/criticalsection.cpp delete mode 100644 src/pal/tests/palsuite/composite/synchronization/criticalsection/mainWrapper.c create mode 100644 src/pal/tests/palsuite/composite/synchronization/criticalsection/mainWrapper.cpp delete mode 100644 src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/pal_composite_native_cs.c create mode 100644 src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/pal_composite_native_cs.cpp delete mode 100644 src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/pal_composite_native_cs.c create mode 100644 src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/pal_composite_native_cs.cpp delete mode 100644 src/pal/tests/palsuite/composite/threading/threadsuspension/mainWrapper.c create mode 100644 src/pal/tests/palsuite/composite/threading/threadsuspension/mainWrapper.cpp delete mode 100644 src/pal/tests/palsuite/composite/threading/threadsuspension/threadsuspension.c create mode 100644 src/pal/tests/palsuite/composite/threading/threadsuspension/threadsuspension.cpp delete mode 100644 src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/mainWrapper.c create mode 100644 src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/mainWrapper.cpp delete mode 100644 src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/threadsuspension.c create mode 100644 src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/threadsuspension.cpp delete mode 100644 src/pal/tests/palsuite/composite/wfmo/main.c create mode 100644 src/pal/tests/palsuite/composite/wfmo/main.cpp delete mode 100644 src/pal/tests/palsuite/composite/wfmo/mutex.c create mode 100644 src/pal/tests/palsuite/composite/wfmo/mutex.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/DebugBreak/test1/test1.c create mode 100644 src/pal/tests/palsuite/debug_api/DebugBreak/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/helper.c create mode 100644 src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/helper.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/test1.c create mode 100644 src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/test1.c create mode 100644 src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/helper.c create mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/helper.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/test1.c create mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/helper.c create mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/helper.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/test3.c create mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/helper.c create mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/helper.cpp delete mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/test4.c create mode 100644 src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/pal_except_filter.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/pal_except_filter.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/pal_except_filter.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/pal_except_filter.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/PAL_EXCEPT_FILTER_EX.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/PAL_EXCEPT_FILTER_EX.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/pal_except_filter_ex.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/pal_except_filter_ex.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/pal_except_filter.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/pal_except_filter.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/PAL_TRY_LEAVE_FINALLY.c create mode 100644 src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/PAL_TRY_LEAVE_FINALLY.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/test1.c create mode 100644 src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test1/test1.c create mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test2/test2.c create mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test3/test3.c create mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test4/test4.c create mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test5/test5.c create mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test6/test6.c create mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test7/test7.c create mode 100644 src/pal/tests/palsuite/exception_handling/pal_except/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/exception_handling/pal_finally/test1/pal_finally.c create mode 100644 src/pal/tests/palsuite/exception_handling/pal_finally/test1/pal_finally.cpp delete mode 100644 src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/AreFileApisANSI.c create mode 100644 src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/AreFileApisANSI.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CompareFileTime/test1/CompareFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/CompareFileTime/test1/CompareFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.c create mode 100644 src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CopyFileA/test2/test2.c create mode 100644 src/pal/tests/palsuite/file_io/CopyFileA/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CopyFileA/test3/test3.c create mode 100644 src/pal/tests/palsuite/file_io/CopyFileA/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CopyFileA/test4/test4.c create mode 100644 src/pal/tests/palsuite/file_io/CopyFileA/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CopyFileW/test1/CopyFileW.c create mode 100644 src/pal/tests/palsuite/file_io/CopyFileW/test1/CopyFileW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CopyFileW/test2/test2.c create mode 100644 src/pal/tests/palsuite/file_io/CopyFileW/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CopyFileW/test3/test3.c create mode 100644 src/pal/tests/palsuite/file_io/CopyFileW/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c create mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/createdirectorya.c create mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/createdirectorya.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.c create mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.c create mode 100644 src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CreateFileA/test1/CreateFileA.c create mode 100644 src/pal/tests/palsuite/file_io/CreateFileA/test1/CreateFileA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.c create mode 100644 src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/DeleteFileW/test1/DeleteFileW.c create mode 100644 src/pal/tests/palsuite/file_io/DeleteFileW/test1/DeleteFileW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FILECanonicalizePath/FILECanonicalizePath.c create mode 100644 src/pal/tests/palsuite/file_io/FILECanonicalizePath/FILECanonicalizePath.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/test1.c create mode 100644 src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FindClose/test1/FindClose.c create mode 100644 src/pal/tests/palsuite/file_io/FindClose/test1/FindClose.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FindFirstFileA/test1/FindFirstFileA.c create mode 100644 src/pal/tests/palsuite/file_io/FindFirstFileA/test1/FindFirstFileA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FindFirstFileW/test1/FindFirstFileW.c create mode 100644 src/pal/tests/palsuite/file_io/FindFirstFileW/test1/FindFirstFileW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FindNextFileA/test1/FindNextFileA.c create mode 100644 src/pal/tests/palsuite/file_io/FindNextFileA/test1/FindNextFileA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FindNextFileA/test2/findnextfilea.c create mode 100644 src/pal/tests/palsuite/file_io/FindNextFileA/test2/findnextfilea.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.c create mode 100644 src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.c create mode 100644 src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.cpp delete mode 100644 src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/FlushFileBuffers.c create mode 100644 src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/FlushFileBuffers.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetConsoleCP/test1/GetConsoleCP.c create mode 100644 src/pal/tests/palsuite/file_io/GetConsoleCP/test1/GetConsoleCP.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/GetConsoleOutputCP.c create mode 100644 src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/GetConsoleOutputCP.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/GetCurrentDirectoryA.c create mode 100644 src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/GetCurrentDirectoryA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/GetCurrentDirectoryW.c create mode 100644 src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/GetCurrentDirectoryW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.c create mode 100644 src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/getdiskfreespacew.c create mode 100644 src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/getdiskfreespacew.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/GetFileAttributesA.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/GetFileAttributesA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/test1.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/test2.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/GetFileAttributesW.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/GetFileAttributesW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/GetFileSizeEx.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/GetFileSizeEx.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test1/GetFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test1/GetFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test2/GetFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test2/GetFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test4/GetFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test4/GetFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test5/getfiletime.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test5/getfiletime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test6/getfiletime.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test6/getfiletime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test7/getfiletime.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileTime/test7/getfiletime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileType/test1/GetFileType.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileType/test1/GetFileType.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileType/test2/getfiletype.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileType/test2/getfiletype.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFileType/test3/getfiletype.c create mode 100644 src/pal/tests/palsuite/file_io/GetFileType/test3/getfiletype.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.c create mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/test2.c create mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/test3.c create mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/test4.c create mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/GetFullPathNameW.c create mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/GetFullPathNameW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.c create mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.c create mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.c create mode 100644 src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/GetLongPathNameW.c create mode 100644 src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/GetLongPathNameW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/getlongpathnamew.c create mode 100644 src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/getlongpathnamew.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetStdHandle/test1/GetStdHandle.c create mode 100644 src/pal/tests/palsuite/file_io/GetStdHandle/test1/GetStdHandle.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetStdHandle/test2/GetStdHandle.c create mode 100644 src/pal/tests/palsuite/file_io/GetStdHandle/test2/GetStdHandle.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.c create mode 100644 src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.c create mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.c create mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.c create mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.c create mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.c create mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.c create mode 100644 src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.cpp delete mode 100644 src/pal/tests/palsuite/file_io/GetTempPathW/test1/GetTempPathW.c create mode 100644 src/pal/tests/palsuite/file_io/GetTempPathW/test1/GetTempPathW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/MoveFileA/test1/MoveFileA.c create mode 100644 src/pal/tests/palsuite/file_io/MoveFileA/test1/MoveFileA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/MoveFileExA/test1/MoveFileExA.c create mode 100644 src/pal/tests/palsuite/file_io/MoveFileExA/test1/MoveFileExA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/MoveFileExW/test1/MoveFileExW.c create mode 100644 src/pal/tests/palsuite/file_io/MoveFileExW/test1/MoveFileExW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/MoveFileW/test1/MoveFileW.c create mode 100644 src/pal/tests/palsuite/file_io/MoveFileW/test1/MoveFileW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/ReadFile/test1/ReadFile.c create mode 100644 src/pal/tests/palsuite/file_io/ReadFile/test1/ReadFile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.c create mode 100644 src/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/ReadFile/test3/ReadFile.c create mode 100644 src/pal/tests/palsuite/file_io/ReadFile/test3/ReadFile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/ReadFile/test4/readfile.c create mode 100644 src/pal/tests/palsuite/file_io/ReadFile/test4/readfile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/RemoveDirectoryW.c create mode 100644 src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/RemoveDirectoryW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.c create mode 100644 src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SearchPathW/test1/SearchPathW.c create mode 100644 src/pal/tests/palsuite/file_io/SearchPathW/test1/SearchPathW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/SetCurrentDirectoryA.c create mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/SetCurrentDirectoryA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/setcurrentdirectorya.c create mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/setcurrentdirectorya.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/setcurrentdirectorya.c create mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/setcurrentdirectorya.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/SetCurrentDirectoryW.c create mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/SetCurrentDirectoryW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/setcurrentdirectoryw.c create mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/setcurrentdirectoryw.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/setcurrentdirectoryw.c create mode 100644 src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/setcurrentdirectoryw.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.c create mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test2/SetEndOfFile.c create mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test2/SetEndOfFile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test3/SetEndOfFile.c create mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test3/SetEndOfFile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c create mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test5/test5.c create mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/SetFileAttributesA.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/SetFileAttributesA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/SetFileAttributesA.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/SetFileAttributesA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/SetFileAttributesA.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/SetFileAttributesA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/SetFileAttributesA.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/SetFileAttributesA.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.c create mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test2/SetFilePointer.c create mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test2/SetFilePointer.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test3/SetFilePointer.c create mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test3/SetFilePointer.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test4/SetFilePointer.c create mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test4/SetFilePointer.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test5/SetFilePointer.c create mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test5/SetFilePointer.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test6/SetFilePointer.c create mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test6/SetFilePointer.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test7/SetFilePointer.c create mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test7/SetFilePointer.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.c create mode 100644 src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.cpp delete mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test1/WriteFile.c create mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test1/WriteFile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test2/WriteFile.c create mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test2/WriteFile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test3/WriteFile.c create mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test3/WriteFile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test4/writefile.c create mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test4/writefile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test5/writefile.c create mode 100644 src/pal/tests/palsuite/file_io/WriteFile/test5/writefile.cpp delete mode 100644 src/pal/tests/palsuite/file_io/errorpathnotfound/test1/test1.c create mode 100644 src/pal/tests/palsuite/file_io/errorpathnotfound/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/file_io/errorpathnotfound/test2/test2.c create mode 100644 src/pal/tests/palsuite/file_io/errorpathnotfound/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/file_io/errorpathnotfound/test3/test3.c create mode 100644 src/pal/tests/palsuite/file_io/errorpathnotfound/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/file_io/errorpathnotfound/test4/test4.c create mode 100644 src/pal/tests/palsuite/file_io/errorpathnotfound/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.c create mode 100644 src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/mapviewoffile.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/mapviewoffile.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/OpenFileMappingA.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/OpenFileMappingA.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.cpp create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/ProbeMemory_neg.cpp create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/testinfo.dat create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/ProbeMemory.cpp create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/ReadProcessMemory_neg.c delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/ReadProcessMemory.c delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/commonconsts.h delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/helper.c delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/test2.c delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/test1.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/test3.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/test4.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/test5.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/helper.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/helper.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.cpp create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.cpp delete mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.c create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test1/LoadLibraryA.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test1/LoadLibraryA.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test2/LoadLibraryA.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test2/LoadLibraryA.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test2/MyModule.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test2/MyModule.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test3/loadlibrarya.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test3/loadlibrarya.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test5/loadlibrarya.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test5/loadlibrarya.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test6/dlltest.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test6/dlltest.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test7/LoadLibraryA.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test7/LoadLibraryA.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test8/dlltest.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test8/dlltest.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test8/loadlibrarya.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryA/test8/loadlibrarya.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryW/test1/LoadLibraryW.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryW/test1/LoadLibraryW.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryW/test3/loadlibraryw.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryW/test3/loadlibraryw.cpp delete mode 100644 src/pal/tests/palsuite/loader/LoadLibraryW/test5/loadlibraryw.c create mode 100644 src/pal/tests/palsuite/loader/LoadLibraryW/test5/loadlibraryw.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/CompareStringA/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/CompareStringA/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/CompareStringW/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/CompareStringW/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetACP/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/GetACP/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetCPInfo/test2/test2.c create mode 100644 src/pal/tests/palsuite/locale_info/GetCPInfo/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetCPInfo/test3/test3.c create mode 100644 src/pal/tests/palsuite/locale_info/GetCPInfo/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test2/test2.c create mode 100644 src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetStringTypeExW/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/GetStringTypeExW/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetStringTypeExW/test2/test2.c create mode 100644 src/pal/tests/palsuite/locale_info/GetStringTypeExW/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetSystemDefaultLangID/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/GetSystemDefaultLangID/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/IsValidCodePage/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/IsValidCodePage/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/IsValidCodePage/test2/test2.c create mode 100644 src/pal/tests/palsuite/locale_info/IsValidCodePage/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/IsValidLocale/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/IsValidLocale/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.c create mode 100644 src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.c create mode 100644 src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.c create mode 100644 src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/test1.c create mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/test2.c create mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/test3.c create mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/test4.c create mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/test5.c create mode 100644 src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/CharNextA/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/CharNextA/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/CharNextA/test2/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/CharNextA/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.c create mode 100644 src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/test1.c create mode 100644 src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/GetCalendarInfoW.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/GetCalendarInfoW.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/GetCalendarInfoW.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/GetCalendarInfoW.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetComputerNameW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetComputerNameW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/test5.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/test6.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetLastError/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetLastError/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/test1.c create mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/test2.c create mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/test3.c create mode 100644 src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/test1.c create mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/test2.c create mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.c create mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/test4.c create mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/test3.c create mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/test4.c create mode 100644 src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/SetLastError/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/SetLastError/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/_i64tow/test1/test1.c create mode 100644 src/pal/tests/palsuite/miscellaneous/_i64tow/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/_ui64tow/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/_ui64tow/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/_ui64tow/test1/_ui64tow.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/_ui64tow/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/_ui64tow.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/test2.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/test3.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/test4.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcpyW/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcpynW/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/test.c create mode 100644 src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/test1.c create mode 100644 src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/test1.c create mode 100644 src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/testinfo.dat delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/CMakeLists.txt delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/test.c delete mode 100644 src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/testinfo.dat delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/PAL_Initialize_Terminate.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/PAL_Initialize_Terminate.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/PAL_RegisterLibraryW_UnregisterLibraryW.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/PAL_RegisterLibraryW_UnregisterLibraryW.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/reg_unreg_libraryw_neg.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/reg_unreg_libraryw_neg.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.c create mode 100644 src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/pal_entrypoint.c create mode 100644 src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/pal_entrypoint.cpp delete mode 100644 src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/pal_initializedebug.c create mode 100644 src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/pal_initializedebug.cpp delete mode 100644 src/pal/tests/palsuite/samples/test1/test.c create mode 100644 src/pal/tests/palsuite/samples/test1/test.cpp delete mode 100644 src/pal/tests/palsuite/samples/test2/test.c create mode 100644 src/pal/tests/palsuite/samples/test2/test.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateEventA/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/CreateEventA/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateEventA/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/CreateEventA/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateEventA/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/CreateEventA/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateEventW/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/CreateEventW/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateEventW/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/CreateEventW/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateEventW/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/CreateEventW/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test1/CreateMutexA.c create mode 100644 src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test1/CreateMutexA.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test2/CreateMutexA.c create mode 100644 src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test2/CreateMutexA.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test1/CreateMutexW.c create mode 100644 src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test1/CreateMutexW.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test2/CreateMutexW.c create mode 100644 src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test2/CreateMutexW.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateProcessA/test1/childProcess.c create mode 100644 src/pal/tests/palsuite/threading/CreateProcessA/test1/childProcess.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateProcessA/test1/parentProcess.c create mode 100644 src/pal/tests/palsuite/threading/CreateProcessA/test1/parentProcess.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateProcessA/test2/childprocess.c create mode 100644 src/pal/tests/palsuite/threading/CreateProcessA/test2/childprocess.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateProcessA/test2/parentprocess.c create mode 100644 src/pal/tests/palsuite/threading/CreateProcessA/test2/parentprocess.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateProcessW/test1/childProcess.c create mode 100644 src/pal/tests/palsuite/threading/CreateProcessW/test1/childProcess.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateProcessW/test1/parentProcess.c create mode 100644 src/pal/tests/palsuite/threading/CreateProcessW/test1/parentProcess.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateProcessW/test2/childprocess.c create mode 100644 src/pal/tests/palsuite/threading/CreateProcessW/test2/childprocess.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateProcessW/test2/parentprocess.c create mode 100644 src/pal/tests/palsuite/threading/CreateProcessW/test2/parentprocess.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CreateSemaphore.c create mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CreateSemaphore.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CreateSemaphore.c create mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CreateSemaphore.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/createsemaphore.c create mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/createsemaphore.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.c create mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CreateSemaphore.c create mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CreateSemaphore.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/createsemaphore.c create mode 100644 src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/createsemaphore.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateThread/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/CreateThread/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateThread/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/CreateThread/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/CreateThread/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/CreateThread/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/InitializeCriticalSection.c create mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/InitializeCriticalSection.cpp delete mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/test4.c create mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/test5.c create mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/test6.c create mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/test7.c create mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test8/test8.c create mode 100644 src/pal/tests/palsuite/threading/CriticalSectionFunctions/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/testlib.c create mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/testlib.cpp delete mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain1.c create mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain1.cpp delete mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain2.c create mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain2.cpp delete mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test10/test10.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test10/test10.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test11/childprocess.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test11/childprocess.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test11/test11.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test11/test11.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test12/test12.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test12/test12.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test4/test4.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test5/test5.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test6/test6.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test8/test8.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test8/test8.cpp delete mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test9/test9.c create mode 100644 src/pal/tests/palsuite/threading/DuplicateHandle/test9/test9.cpp delete mode 100644 src/pal/tests/palsuite/threading/ExitProcess/test1/ExitProcess.c create mode 100644 src/pal/tests/palsuite/threading/ExitProcess/test1/ExitProcess.cpp delete mode 100644 src/pal/tests/palsuite/threading/ExitProcess/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/ExitProcess/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/ExitProcess/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/ExitProcess/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/ExitThread/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/ExitThread/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/ExitThread/test2/childprocess.c create mode 100644 src/pal/tests/palsuite/threading/ExitThread/test2/childprocess.cpp delete mode 100644 src/pal/tests/palsuite/threading/ExitThread/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/ExitThread/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/ExitThread/test3/dllmain.c create mode 100644 src/pal/tests/palsuite/threading/ExitThread/test3/dllmain.cpp delete mode 100644 src/pal/tests/palsuite/threading/ExitThread/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/ExitThread/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/GetCurrentProcess/test1/process.c create mode 100644 src/pal/tests/palsuite/threading/GetCurrentProcess/test1/process.cpp delete mode 100644 src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/processId.c create mode 100644 src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/processId.cpp delete mode 100644 src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.c create mode 100644 src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.cpp delete mode 100644 src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.c create mode 100644 src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.cpp delete mode 100644 src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/childProcess.c create mode 100644 src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/childProcess.cpp delete mode 100644 src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/GetProcessTimes/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/GetProcessTimes/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/GetThreadTimes/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/GetThreadTimes/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test3/childprocess.c create mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test3/childprocess.cpp delete mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test4/test4.c create mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test5/test5.c create mode 100644 src/pal/tests/palsuite/threading/OpenEventW/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/threading/OpenProcess/test1/childProcess.c create mode 100644 src/pal/tests/palsuite/threading/OpenProcess/test1/childProcess.cpp delete mode 100644 src/pal/tests/palsuite/threading/OpenProcess/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/OpenProcess/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test4/test4.c create mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test5/test5.c create mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test6/test6.c create mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test7/test7.c create mode 100644 src/pal/tests/palsuite/threading/QueueUserAPC/test7/test7.cpp delete mode 100644 src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.c create mode 100644 src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp delete mode 100644 src/pal/tests/palsuite/threading/ResetEvent/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/ResetEvent/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/ResetEvent/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/ResetEvent/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/ResetEvent/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/ResetEvent/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/ResetEvent/test4/test4.c create mode 100644 src/pal/tests/palsuite/threading/ResetEvent/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/threading/ResumeThread/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/ResumeThread/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/SetErrorMode/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/SetErrorMode/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/SetEvent/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/SetEvent/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/SetEvent/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/SetEvent/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/SetEvent/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/SetEvent/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/SetEvent/test4/test4.c create mode 100644 src/pal/tests/palsuite/threading/SetEvent/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/threading/Sleep/test1/Sleep.c create mode 100644 src/pal/tests/palsuite/threading/Sleep/test1/Sleep.cpp delete mode 100644 src/pal/tests/palsuite/threading/Sleep/test2/sleep.c create mode 100644 src/pal/tests/palsuite/threading/Sleep/test2/sleep.cpp delete mode 100644 src/pal/tests/palsuite/threading/SleepEx/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/SleepEx/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/SleepEx/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/SleepEx/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/TLS/test1/TLS.c create mode 100644 src/pal/tests/palsuite/threading/TLS/test1/TLS.cpp delete mode 100644 src/pal/tests/palsuite/threading/TLS/test2/TLS.c create mode 100644 src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp delete mode 100644 src/pal/tests/palsuite/threading/TLS/test3/TLS.c create mode 100644 src/pal/tests/palsuite/threading/TLS/test3/TLS.cpp delete mode 100644 src/pal/tests/palsuite/threading/TLS/test4/test4.c create mode 100644 src/pal/tests/palsuite/threading/TLS/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/threading/TLS/test5/test5.c create mode 100644 src/pal/tests/palsuite/threading/TLS/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/test.c create mode 100644 src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/test.cpp delete mode 100644 src/pal/tests/palsuite/threading/TerminateProcess/test1/TerminateProcess.c create mode 100644 src/pal/tests/palsuite/threading/TerminateProcess/test1/TerminateProcess.cpp delete mode 100644 src/pal/tests/palsuite/threading/ThreadPriority/test1/ThreadPriority.c create mode 100644 src/pal/tests/palsuite/threading/ThreadPriority/test1/ThreadPriority.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.c create mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/test3.c create mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/test3.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c create mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/helper.c create mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/helper.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.c create mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/child6.c create mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/child6.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/test6.c create mode 100644 src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/test6.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.c create mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.c create mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.c create mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOMutexTest/WFSOMutexTest.c create mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOMutexTest/WFSOMutexTest.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/ChildProcess.c create mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/ChildProcess.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/WFSOProcessTest.c create mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/WFSOProcessTest.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOSemaphoreTest/WFSOSemaphoreTest.c create mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOSemaphoreTest/WFSOSemaphoreTest.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOThreadTest/WFSOThreadTest.c create mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOThreadTest/WFSOThreadTest.cpp delete mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/WaitForSingleObject/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/YieldProcessor/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/YieldProcessor/test1/test1.cpp delete mode 100644 src/pal/tests/palsuite/threading/releasesemaphore/test1/test.c create mode 100644 src/pal/tests/palsuite/threading/releasesemaphore/test1/test.cpp (limited to 'src/pal/tests') diff --git a/src/pal/tests/CMakeLists.txt b/src/pal/tests/CMakeLists.txt index a6d1ba4d5b..39d5852889 100644 --- a/src/pal/tests/CMakeLists.txt +++ b/src/pal/tests/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 2.8.12.2) -if(CLR_CMAKE_PLATFORM_ARCH_AMD64) +if(CLR_CMAKE_PLATFORM_ARCH_I386) + set(PAL_CMAKE_PLATFORM_ARCH_I386 1) +elseif(CLR_CMAKE_PLATFORM_ARCH_AMD64) set(PAL_CMAKE_PLATFORM_ARCH_AMD64 1) elseif(CLR_CMAKE_PLATFORM_ARCH_ARM) set(PAL_CMAKE_PLATFORM_ARCH_ARM 1) @@ -14,7 +16,9 @@ add_definitions(-DLP64COMPATIBLE=1) add_definitions(-DFEATURE_PAL=1) add_definitions(-DCORECLR=1) add_definitions(-DPIC=1) -if(PAL_CMAKE_PLATFORM_ARCH_AMD64) +if(PAL_CMAKE_PLATFORM_ARCH_I386) + add_definitions(-DBIT32=1) +elseif(PAL_CMAKE_PLATFORM_ARCH_AMD64) add_definitions(-DBIT64=1) add_definitions(-D_WIN64=1) elseif(PAL_CMAKE_PLATFORM_ARCH_ARM) @@ -23,10 +27,15 @@ elseif(PAL_CMAKE_PLATFORM_ARCH_ARM64) add_definitions(-DBIT64=1) add_definitions(-D_WIN64=1) else() - message(FATAL_ERROR "Only ARM, ARM64 and AMD64 is supported") + message(FATAL_ERROR "Only ARM, ARM64, I386, and AMD64 is supported") endif() +# C++ emits errors and warnings for c-string literal fed into char* parameter +# this is just to take care of the warnings +add_compile_options(-Wno-writable-strings) + add_compile_options(-Wno-empty-body) add_subdirectory(palsuite) + diff --git a/src/pal/tests/palsuite/c_runtime/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/CMakeLists.txt index 533454c285..cf062530eb 100644 --- a/src/pal/tests/palsuite/c_runtime/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/CMakeLists.txt @@ -2,16 +2,23 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(abs) add_subdirectory(acos) +add_subdirectory(acosf) add_subdirectory(asin) +add_subdirectory(asinf) add_subdirectory(atan) add_subdirectory(atan2) +add_subdirectory(atan2f) +add_subdirectory(atanf) add_subdirectory(atof) add_subdirectory(atoi) add_subdirectory(atol) add_subdirectory(bsearch) add_subdirectory(ceil) +add_subdirectory(ceilf) add_subdirectory(cos) +add_subdirectory(cosf) add_subdirectory(cosh) +add_subdirectory(coshf) # TODO: make this test compile # add_subdirectory(ctime) @@ -19,6 +26,7 @@ add_subdirectory(cosh) add_subdirectory(errno) add_subdirectory(exit) add_subdirectory(exp) +add_subdirectory(expf) add_subdirectory(fabs) add_subdirectory(fabsf) add_subdirectory(fclose) @@ -27,6 +35,7 @@ add_subdirectory(ferror) add_subdirectory(fflush) add_subdirectory(fgets) add_subdirectory(floor) +add_subdirectory(floorf) add_subdirectory(fmod) add_subdirectory(fmodf) add_subdirectory(fopen) @@ -57,6 +66,8 @@ add_subdirectory(llabs) add_subdirectory(localtime) add_subdirectory(log) add_subdirectory(log10) +add_subdirectory(log10f) +add_subdirectory(logf) add_subdirectory(malloc) add_subdirectory(memchr) add_subdirectory(memcmp) @@ -66,15 +77,19 @@ add_subdirectory(memset) add_subdirectory(modf) add_subdirectory(modff) add_subdirectory(pow) +add_subdirectory(powf) add_subdirectory(printf) add_subdirectory(qsort) add_subdirectory(rand_srand) add_subdirectory(realloc) add_subdirectory(sin) +add_subdirectory(sinf) add_subdirectory(sinh) -add_subdirectory(sprintf) +add_subdirectory(sinhf) +add_subdirectory(sprintf_s) add_subdirectory(sqrt) -add_subdirectory(sscanf) +add_subdirectory(sqrtf) +add_subdirectory(sscanf_s) add_subdirectory(strcat) add_subdirectory(strchr) add_subdirectory(strcmp) @@ -94,7 +109,9 @@ add_subdirectory(strtoul) add_subdirectory(swprintf) add_subdirectory(swscanf) add_subdirectory(tan) +add_subdirectory(tanf) add_subdirectory(tanh) +add_subdirectory(tanhf) add_subdirectory(time) add_subdirectory(tolower) add_subdirectory(toupper) @@ -125,6 +142,7 @@ add_subdirectory(_alloca) add_subdirectory(_ecvt) add_subdirectory(_fdopen) add_subdirectory(_finite) +add_subdirectory(_finitef) add_subdirectory(_fullpath) # TODO: make this test compile @@ -132,31 +150,26 @@ add_subdirectory(_fullpath) add_subdirectory(_getw) add_subdirectory(_isnan) +add_subdirectory(_isnanf) add_subdirectory(_itow) -add_subdirectory(_makepath) add_subdirectory(_mbsdec) add_subdirectory(_mbsinc) -add_subdirectory(_mbslen) add_subdirectory(_mbsninc) add_subdirectory(_open_osfhandle) add_subdirectory(_putenv) add_subdirectory(_putw) add_subdirectory(_rotl) add_subdirectory(_rotr) -add_subdirectory(_snprintf) -add_subdirectory(_snwprintf) -add_subdirectory(_splitpath) +add_subdirectory(_snprintf_s) +add_subdirectory(_snwprintf_s) add_subdirectory(_stricmp) add_subdirectory(_strlwr) add_subdirectory(_strnicmp) -add_subdirectory(_swab) add_subdirectory(_vsnprintf) -add_subdirectory(_vsnwprintf) +add_subdirectory(_vsnwprintf_s) add_subdirectory(_wcsicmp) add_subdirectory(_wcslwr) add_subdirectory(_wcsnicmp) add_subdirectory(_wfopen) -add_subdirectory(_wmakepath) -add_subdirectory(_wsplitpath) add_subdirectory(_wtoi) add_subdirectory(__iscsym) diff --git a/src/pal/tests/palsuite/c_runtime/__iscsym/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/CMakeLists.txt index a283161f7d..b4421e77a1 100644 --- a/src/pal/tests/palsuite/c_runtime/__iscsym/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - __iscsym.c + __iscsym.cpp ) add_executable(paltest_iscsym_test1 diff --git a/src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.c b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.c deleted file mode 100644 index 9c8f1d0f25..0000000000 --- a/src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.c +++ /dev/null @@ -1,93 +0,0 @@ -// 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: __iscsym.c -** -** Purpose: Positive test the __iscsym API. -** Call __iscsym to letter, digit and underscore -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - int index; - char non_letter_set[]= - {'~','`','!','@','#','$','%','^','&','*','(',')',')', - '-','+','=','|','\\',';',':','"','\'','<','>', - ',','.','?','/','\0'}; - char errBuffer[200]; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*To check if the parameter passed in is a character*/ - for(index = 'a'; index <= 'z'; index++) - { - err = __iscsym(index); - if(0 == err) - { - Fail("\n__iscsym failed to recognize a " - "lower-case letter:%c!\n", index); - } - } - - /*To check if the parameter passed in is a character*/ - for(index = 'A'; index <= 'Z'; index++) - { - err = __iscsym(index); - if(0 == err) - { - Fail("\n__iscsym failed to recognize an " - "upper-case letter: %c!\n", index); - } - } - - /*To check if the parameter passed in is a digit*/ - for(index = '0'; index <= '9'; index++) - { - err = __iscsym(index); - if(0 == err) - { - Fail("\n__iscsym failed to recognize a digit %c!\n", - index); - } - } - - /*To check if the parameter passed in is a underscore*/ - err = __iscsym('_'); - if(0 == err) - { - Fail("\n__iscsym failed to recognize an underscore!\n"); - } - - memset(errBuffer, 0, 200); - - for(index = 0; non_letter_set[index]; index++) - { - err = __iscsym(non_letter_set[index]); - if(0 != err) - { - strncat(errBuffer, &non_letter_set[index], 1); - strcat(errBuffer, ", "); - } - } - - if(strlen(errBuffer) > 0) - { - Fail("\n__iscsym failed to identify the characters '%s' " - "as not letters, digits " - "or underscores\n", errBuffer); - } - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.cpp b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.cpp new file mode 100644 index 0000000000..9c8f1d0f25 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.cpp @@ -0,0 +1,93 @@ +// 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: __iscsym.c +** +** Purpose: Positive test the __iscsym API. +** Call __iscsym to letter, digit and underscore +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + int index; + char non_letter_set[]= + {'~','`','!','@','#','$','%','^','&','*','(',')',')', + '-','+','=','|','\\',';',':','"','\'','<','>', + ',','.','?','/','\0'}; + char errBuffer[200]; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*To check if the parameter passed in is a character*/ + for(index = 'a'; index <= 'z'; index++) + { + err = __iscsym(index); + if(0 == err) + { + Fail("\n__iscsym failed to recognize a " + "lower-case letter:%c!\n", index); + } + } + + /*To check if the parameter passed in is a character*/ + for(index = 'A'; index <= 'Z'; index++) + { + err = __iscsym(index); + if(0 == err) + { + Fail("\n__iscsym failed to recognize an " + "upper-case letter: %c!\n", index); + } + } + + /*To check if the parameter passed in is a digit*/ + for(index = '0'; index <= '9'; index++) + { + err = __iscsym(index); + if(0 == err) + { + Fail("\n__iscsym failed to recognize a digit %c!\n", + index); + } + } + + /*To check if the parameter passed in is a underscore*/ + err = __iscsym('_'); + if(0 == err) + { + Fail("\n__iscsym failed to recognize an underscore!\n"); + } + + memset(errBuffer, 0, 200); + + for(index = 0; non_letter_set[index]; index++) + { + err = __iscsym(non_letter_set[index]); + if(0 != err) + { + strncat(errBuffer, &non_letter_set[index], 1); + strcat(errBuffer, ", "); + } + } + + if(strlen(errBuffer) > 0) + { + Fail("\n__iscsym failed to identify the characters '%s' " + "as not letters, digits " + "or underscores\n", errBuffer); + } + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_alloca/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_alloca/test1/CMakeLists.txt index 236b356185..434633be20 100644 --- a/src/pal/tests/palsuite/c_runtime/_alloca/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_alloca/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_alloca_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.c deleted file mode 100644 index c533d84234..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: test1.c -** -** Purpose: Checks that _alloca allocates memory, and that the memory is -** readable and writeable. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - char *testA = NULL; - int i = 0; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - - /* check that _alloca really gives us addressable memory */ - testA = (char *)_alloca(20 * sizeof(char)); - if (testA == NULL) - { - Fail ("The call to _alloca failed\n"); - } - - memset(testA, 'a', 20); - - for (i = 0; i < 20; i++) - { - if (testA[i] != 'a') - { - Fail ("The memory returned by _alloca doesn't seem to be" - " properly allocated\n"); - } - } - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.cpp new file mode 100644 index 0000000000..c533d84234 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.cpp @@ -0,0 +1,62 @@ +// 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: test1.c +** +** Purpose: Checks that _alloca allocates memory, and that the memory is +** readable and writeable. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + char *testA = NULL; + int i = 0; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + + /* check that _alloca really gives us addressable memory */ + testA = (char *)_alloca(20 * sizeof(char)); + if (testA == NULL) + { + Fail ("The call to _alloca failed\n"); + } + + memset(testA, 'a', 20); + + for (i = 0; i < 20; i++) + { + if (testA[i] != 'a') + { + Fail ("The memory returned by _alloca doesn't seem to be" + " properly allocated\n"); + } + } + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/_ecvt/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/CMakeLists.txt index 86f4547b2b..e78a802723 100644 --- a/src/pal/tests/palsuite/c_runtime/_ecvt/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_ecvt_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.c deleted file mode 100644 index fbcf11ecfc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.c +++ /dev/null @@ -1,135 +0,0 @@ -// 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: c_runtime/_ecvt/test1/test1.c -** -** Purpose: Call the _ecvt function on a number of cases. Check that it -** handles negatives, positives and double bounds correctly. Also check that -** the 'digit' specification works. -** -** -**===================================================================*/ - -#include - -#define INT64_TO_DOUBLE(a) (*(double*)&a) - -INT64 NaN = 0x7ff8000000000000; -INT64 NegativeInfinity = 0xfff0000000000000; -INT64 NegativeSmall = 0x8000000000000001; -INT64 PositiveInfinity = 0x7ff0000000000000; -INT64 PositiveSmall = 0x0000000000000001; - -struct testCase -{ - double value; /* number to be converted */ - int precision; /* number of digits to be stored */ - int decimal; /* (expected) decimal point position for stored - * number */ - int sign; /* (expected) return value */ - char expResult[256]; /* (expected) character array to be returned - * NOTE: this necessarily limits precision - * to a value between 0 and 255 */ - char bsdExpResult[256]; /* (expected) character array to be returned - * NOTE: this necessarily limits precision - * to a value between 0 and 255 */ -}; - -int __cdecl main(int argc, char **argv) -{ - char *result; - int testDecimal; - int testSign; - int i=0; - - struct testCase testCases[] = - { - /* odd ball values */ - {INT64_TO_DOUBLE(NaN), 7, 1, 0, "1#QNAN0" }, - /* positive values */ - {0, 0, 0, 0, ""}, - {INT64_TO_DOUBLE(PositiveSmall), 17, -323, 0, - "49406564584124654"}, - {.00123, 3, -2, 0, "123"}, - {.123, 3, 0, 0, "123"}, - {123, 3, 3, 0, "123"}, - {3.1415926535, 9, 1, 0, "314159265"}, - {3.1415926535, 10, 1, 0, "3141592654"}, - {3.1415926535, 11, 1, 0, "31415926535"}, - {3.1415926535, 12, 1, 0, "314159265350"}, - {184467444073709570000.0, 21, 21, 0, "184467444073709570000", - "184467444073709568000" }, - {184467444073709570000.0, 22, 21, 0, "1844674440737095700000", - "1844674440737095680000" }, - {INT64_TO_DOUBLE(PositiveInfinity), 7, 1, 0, "1#INF00" }, - /* negative values */ - {-0, 0, 0, 0, ""}, - {INT64_TO_DOUBLE(NegativeSmall), 17, -323, 1, - "49406564584124654"}, - {-.00123, 3, -2, 1, "123"}, - {-.123, 3, 0, 1, "123"}, - {-123, 3, 3, 1, "123"}, - {-3.1415926535, 9, 1, 1, "314159265"}, - {-3.1415926535, 10, 1, 1, "3141592654"}, - {-3.1415926535, 11, 1, 1, "31415926535"}, - {-3.1415926535, 12, 1, 1, "314159265350"}, - {-184467444073709570000.0, 21, 21, 1, "184467444073709570000", - "184467444073709568000" }, - {-184467444073709570000.0, 22, 21, 1, "1844674440737095700000", - "1844674440737095680000" }, - {INT64_TO_DOUBLE(NegativeInfinity), 7, 1, 1, "1#INF00"} - - }; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Loop through each case. Call _ecvt on each test case and check the - result. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - result = _ecvt(testCases[i].value, - testCases[i].precision, - &testDecimal, - &testSign); - - if (( strcmp(testCases[i].expResult, result) != 0 && - strcmp(testCases[i].bsdExpResult, result) != 0 ) || - - ( testCases[i].sign != testSign ) || - ( testCases[i].decimal != testDecimal )) - - { - Fail("PALSUITE ERROR: Test %d\n" - "-----------------------\n" - "testCases[i].value = '%f'\n" - "testCases[i].precision = '%d'\n" - "testCases[i].decimal = '%d'\n" - "testCases[i].sign = '%d'\n" - "testCases[i].expResult = '%s'\n" - "result = '%s'\n" - "testDecimal = '%d'\n" - "testSign = '%d'\n\n", - i, - testCases[i].value, - testCases[i].precision, - testCases[i].decimal, - testCases[i].sign, - testCases[i].expResult, - result, - testDecimal, - testSign); - } - - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.cpp new file mode 100644 index 0000000000..fbcf11ecfc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.cpp @@ -0,0 +1,135 @@ +// 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: c_runtime/_ecvt/test1/test1.c +** +** Purpose: Call the _ecvt function on a number of cases. Check that it +** handles negatives, positives and double bounds correctly. Also check that +** the 'digit' specification works. +** +** +**===================================================================*/ + +#include + +#define INT64_TO_DOUBLE(a) (*(double*)&a) + +INT64 NaN = 0x7ff8000000000000; +INT64 NegativeInfinity = 0xfff0000000000000; +INT64 NegativeSmall = 0x8000000000000001; +INT64 PositiveInfinity = 0x7ff0000000000000; +INT64 PositiveSmall = 0x0000000000000001; + +struct testCase +{ + double value; /* number to be converted */ + int precision; /* number of digits to be stored */ + int decimal; /* (expected) decimal point position for stored + * number */ + int sign; /* (expected) return value */ + char expResult[256]; /* (expected) character array to be returned + * NOTE: this necessarily limits precision + * to a value between 0 and 255 */ + char bsdExpResult[256]; /* (expected) character array to be returned + * NOTE: this necessarily limits precision + * to a value between 0 and 255 */ +}; + +int __cdecl main(int argc, char **argv) +{ + char *result; + int testDecimal; + int testSign; + int i=0; + + struct testCase testCases[] = + { + /* odd ball values */ + {INT64_TO_DOUBLE(NaN), 7, 1, 0, "1#QNAN0" }, + /* positive values */ + {0, 0, 0, 0, ""}, + {INT64_TO_DOUBLE(PositiveSmall), 17, -323, 0, + "49406564584124654"}, + {.00123, 3, -2, 0, "123"}, + {.123, 3, 0, 0, "123"}, + {123, 3, 3, 0, "123"}, + {3.1415926535, 9, 1, 0, "314159265"}, + {3.1415926535, 10, 1, 0, "3141592654"}, + {3.1415926535, 11, 1, 0, "31415926535"}, + {3.1415926535, 12, 1, 0, "314159265350"}, + {184467444073709570000.0, 21, 21, 0, "184467444073709570000", + "184467444073709568000" }, + {184467444073709570000.0, 22, 21, 0, "1844674440737095700000", + "1844674440737095680000" }, + {INT64_TO_DOUBLE(PositiveInfinity), 7, 1, 0, "1#INF00" }, + /* negative values */ + {-0, 0, 0, 0, ""}, + {INT64_TO_DOUBLE(NegativeSmall), 17, -323, 1, + "49406564584124654"}, + {-.00123, 3, -2, 1, "123"}, + {-.123, 3, 0, 1, "123"}, + {-123, 3, 3, 1, "123"}, + {-3.1415926535, 9, 1, 1, "314159265"}, + {-3.1415926535, 10, 1, 1, "3141592654"}, + {-3.1415926535, 11, 1, 1, "31415926535"}, + {-3.1415926535, 12, 1, 1, "314159265350"}, + {-184467444073709570000.0, 21, 21, 1, "184467444073709570000", + "184467444073709568000" }, + {-184467444073709570000.0, 22, 21, 1, "1844674440737095700000", + "1844674440737095680000" }, + {INT64_TO_DOUBLE(NegativeInfinity), 7, 1, 1, "1#INF00"} + + }; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Call _ecvt on each test case and check the + result. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + result = _ecvt(testCases[i].value, + testCases[i].precision, + &testDecimal, + &testSign); + + if (( strcmp(testCases[i].expResult, result) != 0 && + strcmp(testCases[i].bsdExpResult, result) != 0 ) || + + ( testCases[i].sign != testSign ) || + ( testCases[i].decimal != testDecimal )) + + { + Fail("PALSUITE ERROR: Test %d\n" + "-----------------------\n" + "testCases[i].value = '%f'\n" + "testCases[i].precision = '%d'\n" + "testCases[i].decimal = '%d'\n" + "testCases[i].sign = '%d'\n" + "testCases[i].expResult = '%s'\n" + "result = '%s'\n" + "testDecimal = '%d'\n" + "testSign = '%d'\n\n", + i, + testCases[i].value, + testCases[i].precision, + testCases[i].decimal, + testCases[i].sign, + testCases[i].expResult, + result, + testDecimal, + testSign); + } + + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_fdopen/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/CMakeLists.txt index 441d32bd5c..60b036f44d 100644 --- a/src/pal/tests/palsuite/c_runtime/_fdopen/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fdopen_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.c deleted file mode 100644 index b88267c6e4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.c +++ /dev/null @@ -1,112 +0,0 @@ -// 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: test1.c (fdopen) -** -** Purpose: Tests the PAL implementation of the fdopen function. -** This will test fdopen in r (read) mode. This test -** creates and opens a test pipe, to write and read -** from. fdopen requires a file handle(int), therefore -** _open_osfhandle is used to get that handle. -** _open_osfhandle is only used with CreatePipe. The -** test will write and read from the pipe comparing -** the results. -** -** See /tests/palsuite/README.txt for more information. -** -** -**===================================================================*/ - -#include - -const char* cTestString = "one fish, two fish, read fish, blue fish."; - -int __cdecl main(int argc, char **argv) -{ - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - BOOL bRetVal = FALSE; - int iFiledes = 0; - DWORD dwBytesWritten; - char buffer[45]; - FILE *fp; - - SECURITY_ATTRIBUTES lpPipeAttributes; - - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /*Create a Pipe*/ - bRetVal = CreatePipe(&hReadPipe, // read handle - &hWritePipe, // write handle - &lpPipeAttributes, // security attributes - 0); // pipe size - - if (bRetVal == FALSE) - { - Fail("ERROR: unable to create pipe"); - } - - /*Write to the write pipe handle*/ - bRetVal = WriteFile(hWritePipe, // handle to file - cTestString, // data buffer - (DWORD)strlen(cTestString), // number of bytes to write - &dwBytesWritten, // number of bytes written - NULL); // overlapped buffer - - if (bRetVal == FALSE) - { - Fail("ERROR: unable to write to pipe write handle " - "hWritePipe=0x%lx", hWritePipe); - } - - /*Get a file descriptor for the read pipe handle*/ - iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); - - if (iFiledes == -1) - { - Fail("ERROR: _open_osfhandle failed to open " - " hReadPipe=0x%lx", hReadPipe); - } - - /*Open read pipe handle in read mode*/ - fp = _fdopen(iFiledes, "r"); - - if (fp == NULL) - { - Fail("ERROR: unable to fdopen file descriptor" - " iFiledes=%d", iFiledes); - } - - /*Read from the read pipe handle*/ - if((fread(buffer, sizeof(char), strlen(cTestString), fp)) == 0) - { - Fail("ERROR: Unable to read from file stream fp=0x%lx\n", fp); - } - - /*Compare what was read with what was written.*/ - if ((memcmp(cTestString, buffer, strlen(cTestString))) != 0) - { - Fail("ERROR: read \"%s\" expected \"%s\" \n", buffer, cTestString); - } - - /*Close the file handle*/ - if (_close(iFiledes) != 0) - { - Fail("ERROR: Unable to close file handle iFiledes=%d\n", iFiledes); - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.cpp new file mode 100644 index 0000000000..b88267c6e4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.cpp @@ -0,0 +1,112 @@ +// 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: test1.c (fdopen) +** +** Purpose: Tests the PAL implementation of the fdopen function. +** This will test fdopen in r (read) mode. This test +** creates and opens a test pipe, to write and read +** from. fdopen requires a file handle(int), therefore +** _open_osfhandle is used to get that handle. +** _open_osfhandle is only used with CreatePipe. The +** test will write and read from the pipe comparing +** the results. +** +** See /tests/palsuite/README.txt for more information. +** +** +**===================================================================*/ + +#include + +const char* cTestString = "one fish, two fish, read fish, blue fish."; + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + int iFiledes = 0; + DWORD dwBytesWritten; + char buffer[45]; + FILE *fp; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, // read handle + &hWritePipe, // write handle + &lpPipeAttributes, // security attributes + 0); // pipe size + + if (bRetVal == FALSE) + { + Fail("ERROR: unable to create pipe"); + } + + /*Write to the write pipe handle*/ + bRetVal = WriteFile(hWritePipe, // handle to file + cTestString, // data buffer + (DWORD)strlen(cTestString), // number of bytes to write + &dwBytesWritten, // number of bytes written + NULL); // overlapped buffer + + if (bRetVal == FALSE) + { + Fail("ERROR: unable to write to pipe write handle " + "hWritePipe=0x%lx", hWritePipe); + } + + /*Get a file descriptor for the read pipe handle*/ + iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); + + if (iFiledes == -1) + { + Fail("ERROR: _open_osfhandle failed to open " + " hReadPipe=0x%lx", hReadPipe); + } + + /*Open read pipe handle in read mode*/ + fp = _fdopen(iFiledes, "r"); + + if (fp == NULL) + { + Fail("ERROR: unable to fdopen file descriptor" + " iFiledes=%d", iFiledes); + } + + /*Read from the read pipe handle*/ + if((fread(buffer, sizeof(char), strlen(cTestString), fp)) == 0) + { + Fail("ERROR: Unable to read from file stream fp=0x%lx\n", fp); + } + + /*Compare what was read with what was written.*/ + if ((memcmp(cTestString, buffer, strlen(cTestString))) != 0) + { + Fail("ERROR: read \"%s\" expected \"%s\" \n", buffer, cTestString); + } + + /*Close the file handle*/ + if (_close(iFiledes) != 0) + { + Fail("ERROR: Unable to close file handle iFiledes=%d\n", iFiledes); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt index 8aca58a8dc..ac2f25d85a 100644 --- a/src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_finite_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c deleted file mode 100644 index c815055b38..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c +++ /dev/null @@ -1,119 +0,0 @@ -// 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: test1.c -** -** Purpose: Checks that _finite correctly classifies all types -** of floating point numbers (NaN, -Infinity, Infinity, -** finite nonzero, unnormalized, 0, and -0) -** -**==========================================================================*/ - -#include - -/* -The IEEE double precision floating point standard looks like this: - - S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - 0 1 11 12 63 - -S is the sign bit. The E bits are the exponent, and the 52 F bits are -the fraction. These represent a value, V. - -If E=2047 and F is nonzero, then V=NaN ("Not a number") -If E=2047 and F is zero and S is 1, then V=-Infinity -If E=2047 and F is zero and S is 0, then V=Infinity -If 0 + +/* +The IEEE double precision floating point standard looks like this: + + S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + 0 1 11 12 63 + +S is the sign bit. The E bits are the exponent, and the 52 F bits are +the fraction. These represent a value, V. + +If E=2047 and F is nonzero, then V=NaN ("Not a number") +If E=2047 and F is zero and S is 1, then V=-Infinity +If E=2047 and F is zero and S is 0, then V=Infinity +If 0 + +/* +The IEEE single precision floating point standard looks like this: + + S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF + 0 1 8 9 31 + +S is the sign bit. The E bits are the exponent, and the 23 F bits are +the fraction. These represent a value, V. + +If E=255 and F is nonzero, then V=NaN ("Not a number") +If E=255 and F is zero and S is 1, then V=-Infinity +If E=255 and F is zero and S is 0, then V=Infinity +If 0 - -struct testcase -{ - char relPath[50]; /* relative path array */ - int maxLength; /* pathlength to pass */ - BOOL bRet; /* TRUE if testcase expects function to return NULL */ -}; - -int __cdecl main( int argc, char **argv ) -{ - - DWORD dwOrigDirLength; - DWORD dwNewDirLength; - DWORD dwRetStrLength; - BOOL bRet; - char *retPath; - char szAbsPath[_MAX_PATH + 1]; - char szDirNameOWD[_MAX_DIR]; - char szDirNameNWD[_MAX_DIR]; - int i; - - struct testcase testcases[]= - { - {"." , _MAX_PATH, FALSE}, - {".." , _MAX_PATH, FALSE}, - {"..\\..", _MAX_PATH, FALSE}, - {"..\\..\\..", _MAX_PATH, FALSE}, - {"..", 1, TRUE} - }; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - for (i = 0; i < sizeof(testcases)/sizeof(struct testcase) ; i++) - { - - /* reset variables */ - memset(szAbsPath, 0, _MAX_PATH + 1); - memset(szDirNameOWD, 0, _MAX_DIR); - memset(szDirNameNWD, 0, _MAX_DIR); - - dwOrigDirLength = 0; - dwNewDirLength = 0; - dwRetStrLength = 0; - - /* Get the current directory name */ - dwOrigDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameOWD); - if (0 == dwOrigDirLength) - { - Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." - "\nGetCurrentDirectory (%d, %s) call failed. GetLastError" - " returned '%d'\n", testcases[i].relPath, - testcases[i].maxLength, _MAX_PATH, szDirNameOWD, - GetLastError()); - } - - /* - * Set the current directory to relPath. - */ - bRet = SetCurrentDirectory(testcases[i].relPath); - if (0 == bRet) - { - Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." - "\nSetCurrentDirectory (%s) call failed. GetLastError" - " returned '%d'\n", testcases[i].relPath, - testcases[i].maxLength, testcases[i].relPath, - GetLastError()); - } - - /* Get the new current directory name */ - dwNewDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameNWD); - if (0 == dwNewDirLength) - { - Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." - "\nGetCurrentDirectory(%d, %s) call failed. GetLastError" - " returned '%d'\n", testcases[i].relPath, - testcases[i].maxLength, _MAX_PATH, szDirNameNWD, - GetLastError()); - } - - /* Set the current directory back to the original one */ - bRet = SetCurrentDirectory(szDirNameOWD); - if (0 == bRet) - { - Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." - "\nSetCurrentDirectory(%s) call failed. GetLastError" - " returned '%d'\n", testcases[i].relPath, - testcases[i].maxLength, szDirNameOWD, GetLastError()); - } - - retPath = _fullpath( szAbsPath, - testcases[i].relPath, - testcases[i].maxLength ); - - if ( NULL == retPath ) - { - /* The function returned NULL when a value was expected */ - if ( FALSE == testcases[i].bRet ) - { - Fail("PALSUITE ERROR: test failed.\n" - "_fullpath (char *, %s, %d) returned NULL\n" - "when '%s' was expected\n", testcases[i].relPath, - testcases[i].maxLength, szDirNameNWD ); - } - } - else - { - dwRetStrLength = strlen ( szAbsPath ); - - /* Check that the path lengths are identical. */ - if ( dwRetStrLength != dwNewDirLength ) - { - Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." - "\ndwRetStringLength '%d' is not equal to " - "dwNewDirLength '%d'.\nszAbsPath is '%s' retPath is '%s'\n" - "szDirNameNWD is '%s'\n" , testcases[i].relPath, - testcases[i].maxLength, dwRetStrLength ,dwNewDirLength - ,szAbsPath ,retPath ,szDirNameNWD); - } - - /* - * Perform a string comparison on the path provided by - * GetCurrentDirectory and the path provided by _fullpath - * to ensure they are identical. - */ - if ( 0 != strncmp( szDirNameNWD, szAbsPath, dwNewDirLength )) - { - Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." - "strncmp ( %s, %s, %d ) call failed.\n", - testcases[i].relPath, testcases[i].maxLength, - szDirNameNWD, szAbsPath, dwNewDirLength ); - } - - /* - * Perform a string comparison on both paths provided by - * _fullpath to ensure they are identical. - */ - if ( 0 != strncmp( retPath, szAbsPath, dwNewDirLength )) - { - Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." - "strncmp ( %s, %s, %d ) call failed.\n", - testcases[i].relPath, testcases[i].maxLength, - szDirNameNWD, szAbsPath, dwNewDirLength ); - } - } - } - - PAL_Terminate(); - return ( PASS ); -} - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.cpp new file mode 100644 index 0000000000..f390f4309b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.cpp @@ -0,0 +1,181 @@ +// 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: _fullpath/test1/test1.c +** +** Purpose: Test to see if the _fullpath function returns the +** proper values. A check is done to ensure NULL is returned +** by _fullpath only for the condition where the length of the +** created absolute path name (absPath) is greater than +** maxLength. +** +** Dependencies: strlen +** strncmp +** SetCurrentDirectory +** GetCurrentDirectory +** + +** +**=========================================================*/ + +#include + +struct testcase +{ + char relPath[50]; /* relative path array */ + int maxLength; /* pathlength to pass */ + BOOL bRet; /* TRUE if testcase expects function to return NULL */ +}; + +int __cdecl main( int argc, char **argv ) +{ + + DWORD dwOrigDirLength; + DWORD dwNewDirLength; + DWORD dwRetStrLength; + BOOL bRet; + char *retPath; + char szAbsPath[_MAX_PATH + 1]; + char szDirNameOWD[_MAX_DIR]; + char szDirNameNWD[_MAX_DIR]; + int i; + + struct testcase testcases[]= + { + {"." , _MAX_PATH, FALSE}, + {".." , _MAX_PATH, FALSE}, + {"..\\..", _MAX_PATH, FALSE}, + {"..\\..\\..", _MAX_PATH, FALSE}, + {"..", 1, TRUE} + }; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + for (i = 0; i < sizeof(testcases)/sizeof(struct testcase) ; i++) + { + + /* reset variables */ + memset(szAbsPath, 0, _MAX_PATH + 1); + memset(szDirNameOWD, 0, _MAX_DIR); + memset(szDirNameNWD, 0, _MAX_DIR); + + dwOrigDirLength = 0; + dwNewDirLength = 0; + dwRetStrLength = 0; + + /* Get the current directory name */ + dwOrigDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameOWD); + if (0 == dwOrigDirLength) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\nGetCurrentDirectory (%d, %s) call failed. GetLastError" + " returned '%d'\n", testcases[i].relPath, + testcases[i].maxLength, _MAX_PATH, szDirNameOWD, + GetLastError()); + } + + /* + * Set the current directory to relPath. + */ + bRet = SetCurrentDirectory(testcases[i].relPath); + if (0 == bRet) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\nSetCurrentDirectory (%s) call failed. GetLastError" + " returned '%d'\n", testcases[i].relPath, + testcases[i].maxLength, testcases[i].relPath, + GetLastError()); + } + + /* Get the new current directory name */ + dwNewDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameNWD); + if (0 == dwNewDirLength) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\nGetCurrentDirectory(%d, %s) call failed. GetLastError" + " returned '%d'\n", testcases[i].relPath, + testcases[i].maxLength, _MAX_PATH, szDirNameNWD, + GetLastError()); + } + + /* Set the current directory back to the original one */ + bRet = SetCurrentDirectory(szDirNameOWD); + if (0 == bRet) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\nSetCurrentDirectory(%s) call failed. GetLastError" + " returned '%d'\n", testcases[i].relPath, + testcases[i].maxLength, szDirNameOWD, GetLastError()); + } + + retPath = _fullpath( szAbsPath, + testcases[i].relPath, + testcases[i].maxLength ); + + if ( NULL == retPath ) + { + /* The function returned NULL when a value was expected */ + if ( FALSE == testcases[i].bRet ) + { + Fail("PALSUITE ERROR: test failed.\n" + "_fullpath (char *, %s, %d) returned NULL\n" + "when '%s' was expected\n", testcases[i].relPath, + testcases[i].maxLength, szDirNameNWD ); + } + } + else + { + dwRetStrLength = strlen ( szAbsPath ); + + /* Check that the path lengths are identical. */ + if ( dwRetStrLength != dwNewDirLength ) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\ndwRetStringLength '%d' is not equal to " + "dwNewDirLength '%d'.\nszAbsPath is '%s' retPath is '%s'\n" + "szDirNameNWD is '%s'\n" , testcases[i].relPath, + testcases[i].maxLength, dwRetStrLength ,dwNewDirLength + ,szAbsPath ,retPath ,szDirNameNWD); + } + + /* + * Perform a string comparison on the path provided by + * GetCurrentDirectory and the path provided by _fullpath + * to ensure they are identical. + */ + if ( 0 != strncmp( szDirNameNWD, szAbsPath, dwNewDirLength )) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "strncmp ( %s, %s, %d ) call failed.\n", + testcases[i].relPath, testcases[i].maxLength, + szDirNameNWD, szAbsPath, dwNewDirLength ); + } + + /* + * Perform a string comparison on both paths provided by + * _fullpath to ensure they are identical. + */ + if ( 0 != strncmp( retPath, szAbsPath, dwNewDirLength )) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "strncmp ( %s, %s, %d ) call failed.\n", + testcases[i].relPath, testcases[i].maxLength, + szDirNameNWD, szAbsPath, dwNewDirLength ); + } + } + } + + PAL_Terminate(); + return ( PASS ); +} + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt index 33eb5cf19c..47dcb95754 100644 --- a/src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - _gcvt.c + _gcvt.cpp ) add_executable(paltest_gcvt_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c deleted file mode 100644 index ccfc286898..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c +++ /dev/null @@ -1,58 +0,0 @@ -// 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: _gcvt.c -** -** Purpose: Positive test the _gcvt API. -** Call _gcvt to convert a floatable value to a string -** with specified sigficant digits stored -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - double dValue = -3.1415926535; - char buffer[1024]; - char *pChar7 = "-3.141593"; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - - /* zero the buffer */ - memset(buffer, 0, 1024); - - - /* - - Testing - ======= - - To convert a floating-point value to - a string to save 7 significant digits - */ - _gcvt(dValue, 7, buffer); - if(strcmp(pChar7, buffer)) - { - Fail("\nFailed to call _gcvt to convert a floating-point value " - "to a string with 7 sigficants digits stored\n"); - } - - - /* - Clean up and exit - */ - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.cpp b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.cpp new file mode 100644 index 0000000000..ccfc286898 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.cpp @@ -0,0 +1,58 @@ +// 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: _gcvt.c +** +** Purpose: Positive test the _gcvt API. +** Call _gcvt to convert a floatable value to a string +** with specified sigficant digits stored +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + double dValue = -3.1415926535; + char buffer[1024]; + char *pChar7 = "-3.141593"; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + + /* zero the buffer */ + memset(buffer, 0, 1024); + + + /* + + Testing + ======= + + To convert a floating-point value to + a string to save 7 significant digits + */ + _gcvt(dValue, 7, buffer); + if(strcmp(pChar7, buffer)) + { + Fail("\nFailed to call _gcvt to convert a floating-point value " + "to a string with 7 sigficants digits stored\n"); + } + + + /* + Clean up and exit + */ + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt index 05641b9b78..5b0f5608f3 100644 --- a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_gcvt_test2 diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c deleted file mode 100644 index 7ac9a4fcf0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c +++ /dev/null @@ -1,83 +0,0 @@ -// 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: test2.c -** -** Purpose: Call the _gcvt function on a number of cases. Check that it -** handles negatives, exponents and hex digits properly. Also check that -** the 'digit' specification works. (And that it doesn't truncate negative -** signs or decimals) -** -** -**===================================================================*/ - -#include - -struct testCase -{ - double Value; - int Digits; - char WinCorrectResult[128]; - char BsdCorrectResult[128]; /* for the odd case where bsd sprintf - varies from windows sprintf */ -}; - -int __cdecl main(int argc, char **argv) -{ - char result[128]; - int i=0; - - struct testCase testCases[] = - { - {1234567, 7, "1234567"}, - {1234.123, 7, "1234.123"}, - {1234.1234, 7, "1234.123"}, - {12.325678e+2, 7, "1232.568"}, - {-12.3233333, 8, "-12.323333"}, - {-12.32, 8, "-12.32"}, - {-12.32e+2, 8, "-1232.", "-1232" }, - {0x21DDFABC, 8, "5.6819577e+008", "5.6819577e+08" }, - {123456789012345.0, 15, "123456789012345" }, - {12340000.0, 8, "12340000"}, - {12340000000000000.0, 15, "1.234e+016", "1.234e+16" }, - {12340000000000000.0, 17, "12340000000000000" }, - - }; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Loop through each case. Call _gcvt on each test case and check the - result. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - _gcvt(testCases[i].Value, testCases[i].Digits, result); - - if (strcmp(testCases[i].WinCorrectResult, result) != 0 && - - ( testCases[i].BsdCorrectResult && - strcmp(testCases[i].BsdCorrectResult, result) != 0 ) ) - { - Fail("ERROR: _gcvt attempted to convert %f with %d digits " - "signifigant, which resulted in " - "the string '%s' instead of the correct(Win) string '%s' or the" - "correct(bsd) string '%s'.\n", - testCases[i].Value, - testCases[i].Digits, - result, - testCases[i].WinCorrectResult, - testCases[i].BsdCorrectResult); - } - - memset(result, '\0', 128); - } - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.cpp new file mode 100644 index 0000000000..7ac9a4fcf0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.cpp @@ -0,0 +1,83 @@ +// 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: test2.c +** +** Purpose: Call the _gcvt function on a number of cases. Check that it +** handles negatives, exponents and hex digits properly. Also check that +** the 'digit' specification works. (And that it doesn't truncate negative +** signs or decimals) +** +** +**===================================================================*/ + +#include + +struct testCase +{ + double Value; + int Digits; + char WinCorrectResult[128]; + char BsdCorrectResult[128]; /* for the odd case where bsd sprintf + varies from windows sprintf */ +}; + +int __cdecl main(int argc, char **argv) +{ + char result[128]; + int i=0; + + struct testCase testCases[] = + { + {1234567, 7, "1234567"}, + {1234.123, 7, "1234.123"}, + {1234.1234, 7, "1234.123"}, + {12.325678e+2, 7, "1232.568"}, + {-12.3233333, 8, "-12.323333"}, + {-12.32, 8, "-12.32"}, + {-12.32e+2, 8, "-1232.", "-1232" }, + {0x21DDFABC, 8, "5.6819577e+008", "5.6819577e+08" }, + {123456789012345.0, 15, "123456789012345" }, + {12340000.0, 8, "12340000"}, + {12340000000000000.0, 15, "1.234e+016", "1.234e+16" }, + {12340000000000000.0, 17, "12340000000000000" }, + + }; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Call _gcvt on each test case and check the + result. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + _gcvt(testCases[i].Value, testCases[i].Digits, result); + + if (strcmp(testCases[i].WinCorrectResult, result) != 0 && + + ( testCases[i].BsdCorrectResult && + strcmp(testCases[i].BsdCorrectResult, result) != 0 ) ) + { + Fail("ERROR: _gcvt attempted to convert %f with %d digits " + "signifigant, which resulted in " + "the string '%s' instead of the correct(Win) string '%s' or the" + "correct(bsd) string '%s'.\n", + testCases[i].Value, + testCases[i].Digits, + result, + testCases[i].WinCorrectResult, + testCases[i].BsdCorrectResult); + } + + memset(result, '\0', 128); + } + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_getw/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_getw/test1/CMakeLists.txt index d44477b232..4f763bed6b 100644 --- a/src/pal/tests/palsuite/c_runtime/_getw/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_getw/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getw_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_getw/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_getw/test1/test1.c deleted file mode 100644 index 34ce4ee7de..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_getw/test1/test1.c +++ /dev/null @@ -1,96 +0,0 @@ -// 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: test1.c -** -** Purpose: Several integers are read from a previously written file -** using _getw. The test passes if the values read match those known to -** be in the file. -** -** -**==========================================================================*/ - -#include - -/*Tests _getw using a previously written data file */ -int __cdecl main(int argc, char **argv) -{ - const int testValues[] = - { - 0, - 1, - -1, - 0x7FFFFFFF, /* largest positive integer on 32 bit systems */ - 0x80000000, /* largest negative integer on 32 bit systems */ - 0xFFFFFFFF, - 0xFFFFAAAA - }; - - int i = 0; - int input = 0; - - const char filename[] = "test.dat"; - - - FILE *fp = NULL; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* write the file that we will use to test */ - - - /* - Don't uncomment this code, it was used to create the data file - initially on windows, but if it is run on all test platforms, the - tests will always pass. - - fp = fopen(filename, "w"); - if (fp == NULL) - { - Fail("Unable to open file for write.\n"); - } - for (i = 0; i < sizeof(testValues) / sizeof(testValues[0]); i++) - { - _putw(testValues[i], fp); - } - - if (fclose(fp) != 0) - { - Fail("Error closing file after writing to it with _putw.\n"); - } - */ - - - /*Now read values back from the file and see if they match.*/ - fp = fopen(filename, "r"); - if (fp == NULL) - { - Fail ("Unable to open file for read.\n"); - } - for (i = 0; i < sizeof(testValues) / sizeof(testValues[0]); i++) - { - input = _getw(fp); - if (VAL32(input) != testValues[i]) - { - Fail ("_getw did not get the expected values when reading " - "from a file.\n"); - } - } - - if (fclose(fp) != 0) - { - Fail ("Error closing file after reading from it with _getw\n"); - } - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_getw/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_getw/test1/test1.cpp new file mode 100644 index 0000000000..34ce4ee7de --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_getw/test1/test1.cpp @@ -0,0 +1,96 @@ +// 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: test1.c +** +** Purpose: Several integers are read from a previously written file +** using _getw. The test passes if the values read match those known to +** be in the file. +** +** +**==========================================================================*/ + +#include + +/*Tests _getw using a previously written data file */ +int __cdecl main(int argc, char **argv) +{ + const int testValues[] = + { + 0, + 1, + -1, + 0x7FFFFFFF, /* largest positive integer on 32 bit systems */ + 0x80000000, /* largest negative integer on 32 bit systems */ + 0xFFFFFFFF, + 0xFFFFAAAA + }; + + int i = 0; + int input = 0; + + const char filename[] = "test.dat"; + + + FILE *fp = NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* write the file that we will use to test */ + + + /* + Don't uncomment this code, it was used to create the data file + initially on windows, but if it is run on all test platforms, the + tests will always pass. + + fp = fopen(filename, "w"); + if (fp == NULL) + { + Fail("Unable to open file for write.\n"); + } + for (i = 0; i < sizeof(testValues) / sizeof(testValues[0]); i++) + { + _putw(testValues[i], fp); + } + + if (fclose(fp) != 0) + { + Fail("Error closing file after writing to it with _putw.\n"); + } + */ + + + /*Now read values back from the file and see if they match.*/ + fp = fopen(filename, "r"); + if (fp == NULL) + { + Fail ("Unable to open file for read.\n"); + } + for (i = 0; i < sizeof(testValues) / sizeof(testValues[0]); i++) + { + input = _getw(fp); + if (VAL32(input) != testValues[i]) + { + Fail ("_getw did not get the expected values when reading " + "from a file.\n"); + } + } + + if (fclose(fp) != 0) + { + Fail ("Error closing file after reading from it with _getw\n"); + } + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_isnan/test1/CMakeLists.txt index e14d0cc64b..106ccb93d7 100644 --- a/src/pal/tests/palsuite/c_runtime/_isnan/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_isnan/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isnan_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c deleted file mode 100644 index d793c9b371..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c +++ /dev/null @@ -1,115 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Test _isnan with a number of trivial values, to ensure they indicated that -** they are numbers. Then try with Positive/Negative Infinite, which should -** also be numbers. Finally set the least and most significant bits of -** the fraction to positive and negative, at which point it should return -** the true value. -** -**==========================================================================*/ - -#include - -#define TO_DOUBLE(x) (*((double*)((void*)&x))) -#define TO_I64(x) (*((INT64*)((void*)&x))) - -/* - * NaN: any double with maximum exponent (0x7ff) and non-zero fraction - */ -int __cdecl main(int argc, char *argv[]) -{ - /* - * Initialize the PAL and return FAIL if this fails - */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - /* - * Try some trivial values - */ - if (_isnan(0.0)) - { - Fail("_isnan() incorrectly identified %f as NaN!\n", 0.0); - } - - if (_isnan(1.23456)) - { - Fail("_isnan() incorrectly identified %f as NaN!\n", 1.234567); - } - - if (_isnan(42.0)) - { - Fail("_isnan() incorrectly identified %f as NaN!\n", 42.0); - } - - UINT64 lneginf = UI64(0xfff0000000000000); - UINT64 lposinf = UI64(0x7ff0000000000000); - - double neginf = TO_DOUBLE(lneginf); - double posinf = TO_DOUBLE(lposinf); - - /* - * Try positive and negative infinity - */ - if (_isnan(neginf)) - { - Fail("_isnan() incorrectly identified negative infinity as NaN!\n"); - } - - if (_isnan(posinf)) - { - Fail("_isnan() incorrectly identified infinity as NaN!\n"); - } - - /* - * Try setting the least significant bit of the fraction, - * positive and negative - */ - UINT64 lsnan = UI64(0xfff0000000000001); - double snan = TO_DOUBLE(lsnan); - - if (!_isnan(snan)) - { - Fail("_isnan() failed to identify %I64x as NaN!\n", lsnan); - } - - UINT64 lqnan = UI64(0x7ff0000000000001); - double qnan = TO_DOUBLE(lqnan); - - if (!_isnan(qnan)) - { - Fail("_isnan() failed to identify %I64x as NaN!\n", lqnan); - } - - /* - * Try setting the most significant bit of the fraction, - * positive and negative - */ - lsnan = UI64(0xfff8000000000000); - snan = TO_DOUBLE(lsnan); - - if (!_isnan(snan)) - { - Fail ("_isnan() failed to identify %I64x as NaN!\n", lsnan); - } - - lqnan = UI64(0x7ff8000000000000); - qnan = TO_DOUBLE(lqnan); - - if (!_isnan(qnan)) - { - Fail ("_isnan() failed to identify %I64x as NaN!\n", lqnan); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.cpp new file mode 100644 index 0000000000..d793c9b371 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.cpp @@ -0,0 +1,115 @@ +// 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: test1.c +** +** Purpose: +** Test _isnan with a number of trivial values, to ensure they indicated that +** they are numbers. Then try with Positive/Negative Infinite, which should +** also be numbers. Finally set the least and most significant bits of +** the fraction to positive and negative, at which point it should return +** the true value. +** +**==========================================================================*/ + +#include + +#define TO_DOUBLE(x) (*((double*)((void*)&x))) +#define TO_I64(x) (*((INT64*)((void*)&x))) + +/* + * NaN: any double with maximum exponent (0x7ff) and non-zero fraction + */ +int __cdecl main(int argc, char *argv[]) +{ + /* + * Initialize the PAL and return FAIL if this fails + */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + /* + * Try some trivial values + */ + if (_isnan(0.0)) + { + Fail("_isnan() incorrectly identified %f as NaN!\n", 0.0); + } + + if (_isnan(1.23456)) + { + Fail("_isnan() incorrectly identified %f as NaN!\n", 1.234567); + } + + if (_isnan(42.0)) + { + Fail("_isnan() incorrectly identified %f as NaN!\n", 42.0); + } + + UINT64 lneginf = UI64(0xfff0000000000000); + UINT64 lposinf = UI64(0x7ff0000000000000); + + double neginf = TO_DOUBLE(lneginf); + double posinf = TO_DOUBLE(lposinf); + + /* + * Try positive and negative infinity + */ + if (_isnan(neginf)) + { + Fail("_isnan() incorrectly identified negative infinity as NaN!\n"); + } + + if (_isnan(posinf)) + { + Fail("_isnan() incorrectly identified infinity as NaN!\n"); + } + + /* + * Try setting the least significant bit of the fraction, + * positive and negative + */ + UINT64 lsnan = UI64(0xfff0000000000001); + double snan = TO_DOUBLE(lsnan); + + if (!_isnan(snan)) + { + Fail("_isnan() failed to identify %I64x as NaN!\n", lsnan); + } + + UINT64 lqnan = UI64(0x7ff0000000000001); + double qnan = TO_DOUBLE(lqnan); + + if (!_isnan(qnan)) + { + Fail("_isnan() failed to identify %I64x as NaN!\n", lqnan); + } + + /* + * Try setting the most significant bit of the fraction, + * positive and negative + */ + lsnan = UI64(0xfff8000000000000); + snan = TO_DOUBLE(lsnan); + + if (!_isnan(snan)) + { + Fail ("_isnan() failed to identify %I64x as NaN!\n", lsnan); + } + + lqnan = UI64(0x7ff8000000000000); + qnan = TO_DOUBLE(lqnan); + + if (!_isnan(qnan)) + { + Fail ("_isnan() failed to identify %I64x as NaN!\n", lqnan); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_isnanf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_isnanf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnanf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/_isnanf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_isnanf/test1/CMakeLists.txt new file mode 100644 index 0000000000..a8d42aa975 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnanf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_isnanf_test1 + ${SOURCES} +) + +add_dependencies(paltest_isnanf_test1 coreclrpal) + +target_link_libraries(paltest_isnanf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_isnanf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_isnanf/test1/test1.c new file mode 100644 index 0000000000..9b75a7236d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnanf/test1/test1.c @@ -0,0 +1,115 @@ +// 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: test1.c +** +** Purpose: +** Test _isnanf with a number of trivial values, to ensure they indicated that +** they are numbers. Then try with Positive/Negative Infinite, which should +** also be numbers. Finally set the least and most significant bits of +** the fraction to positive and negative, at which point it should return +** the true value. +** +**==========================================================================*/ + +#include + +#define TO_FLOAT(x) (*((float*)((void*)&x))) +#define TO_I32(x) (*((INT32*)((void*)&x))) + +/* + * NaN: any float with maximum exponent (0x7f8) and non-zero fraction + */ +int __cdecl main(int argc, char *argv[]) +{ + /* + * Initialize the PAL and return FAIL if this fails + */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + /* + * Try some trivial values + */ + if (_isnanf(0.0f)) + { + Fail("_isnanf() incorrectly identified %f as NaN!\n", 0.0f); + } + + if (_isnanf(1.234567f)) + { + Fail("_isnanf() incorrectly identified %f as NaN!\n", 1.234567f); + } + + if (_isnanf(42.0f)) + { + Fail("_isnanf() incorrectly identified %f as NaN!\n", 42.0f); + } + + UINT32 lneginf = 0xff800000u; + UINT32 lposinf = 0x7f800000u; + + float neginf = TO_FLOAT(lneginf); + float posinf = TO_FLOAT(lposinf); + + /* + * Try positive and negative infinity + */ + if (_isnanf(neginf)) + { + Fail("_isnanf() incorrectly identified negative infinity as NaN!\n"); + } + + if (_isnanf(posinf)) + { + Fail("_isnanf() incorrectly identified infinity as NaN!\n"); + } + + /* + * Try setting the least significant bit of the fraction, + * positive and negative + */ + UINT32 lsnan = 0xff800001u; + float snan = TO_FLOAT(lsnan); + + if (!_isnanf(snan)) + { + Fail("_isnanf() failed to identify %I32x as NaN!\n", lsnan); + } + + UINT32 lqnan = 0x7f800001u; + float qnan = TO_FLOAT(lqnan); + + if (!_isnanf(qnan)) + { + Fail("_isnanf() failed to identify %I32x as NaN!\n", lqnan); + } + + /* + * Try setting the most significant bit of the fraction, + * positive and negative + */ + lsnan = 0xffc00000u; + snan = TO_FLOAT(lsnan); + + if (!_isnanf(snan)) + { + Fail ("_isnanf() failed to identify %I32x as NaN!\n", lsnan); + } + + lqnan = 0x7fc00000u; + qnan = TO_FLOAT(lqnan); + + if (!_isnanf(qnan)) + { + Fail ("_isnanf() failed to identify %I32x as NaN!\n", lqnan); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_isnanf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_isnanf/test1/testinfo.dat new file mode 100644 index 0000000000..22b0edbd74 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnanf/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 = C Runtime +Function = _isnanf +Name = Test #1 for _isnanf +TYPE = DEFAULT +EXE1 = test1 +Description += Test _isnanf with a number of trivial values, to ensure they indicated that += they are numbers. Then try with Positive/Negative Infinite, which should += also be numbers. Finally set the least and most significant bits of += the fraction to positive and negative, at which point it should return += the true value. diff --git a/src/pal/tests/palsuite/c_runtime/_itow/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_itow/test1/CMakeLists.txt index bd37f31216..2c5d57bd34 100644 --- a/src/pal/tests/palsuite/c_runtime/_itow/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_itow/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_itow_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_itow/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_itow/test1/test1.c deleted file mode 100644 index 745ce4acaa..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_itow/test1/test1.c +++ /dev/null @@ -1,102 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the _itow function. -** Test a number of ints with different radix on each, -** to ensure that the string returned is correct. -** -** -**===================================================================*/ - -#define UNICODE - -#include - -struct testCase -{ - wchar_t *CorrectResult; - int value; - int radix; -}; - -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++) - { - pResult = _itow(testCases[i].value,result,testCases[i].radix); - - if(pResult != &result[0]) - { - Fail("ERROR: _itow didn't return a correct pointer to the " - "newly formed string.\n"); - } - - if (0 != wcscmp(testCases[i].CorrectResult,pResult)) - { - PrintResult = convertC(pResult); - PrintCorrectResult = convertC(testCases[i].CorrectResult); - Fail("ERROR: _itow 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; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/_itow/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_itow/test1/test1.cpp new file mode 100644 index 0000000000..01f32f2520 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_itow/test1/test1.cpp @@ -0,0 +1,101 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the _itow_s function. +** Test a number of ints with different radix on each, +** to ensure that the string returned is correct. +** +** +**===================================================================*/ + +#define UNICODE + +#include + +struct testCase +{ + wchar_t *CorrectResult; + int value; + int radix; +}; + +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; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/_itow/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_itow/test1/testinfo.dat index 394c34dff3..91f0e62e09 100644 --- a/src/pal/tests/palsuite/c_runtime/_itow/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_itow/test1/testinfo.dat @@ -4,12 +4,12 @@ Version = 1.0 Section = C Runtime -Function = _itow -Name = Positive Test for _itow +Function = _itow_s +Name = Positive Test for _itow_s TYPE = DEFAULT EXE1 = test1 Description -= Tests the PAL implementation of the _itow function. += Tests the PAL implementation of the _itow_s function. = Test a number of ints with different radix on each, to ensure that the = string returned is correct. diff --git a/src/pal/tests/palsuite/c_runtime/_makepath/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_makepath/CMakeLists.txt deleted file mode 100644 index f6aa0cb2d9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_makepath/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/_makepath/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_makepath/test1/CMakeLists.txt deleted file mode 100644 index 9fd81cce1a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_makepath/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_makepath_test1 - ${SOURCES} -) - -add_dependencies(paltest_makepath_test1 coreclrpal) - -target_link_libraries(paltest_makepath_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_makepath/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_makepath/test1/test1.c deleted file mode 100644 index 94b366a7bb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_makepath/test1/test1.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the _makepath function. -** Create a path, and ensure that it builds how it is -** supposed to. -** -** -** -**===================================================================*/ - -#if WIN32 -#define PATHNAME "C:\\test\\test.txt" -#else -#define PATHNAME "/test/test.txt" -#endif - -#include - -int __cdecl main(int argc, char **argv) -{ - char FullPath[128]; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc,argv))) - { - return FAIL; - } - -#if WIN32 - _makepath(FullPath,"C","\\test","test","txt"); -#else - _makepath(FullPath,NULL,"/test","test","txt"); -#endif - - if(strcmp(FullPath,PATHNAME) != 0) - { - Fail("ERROR: The pathname which was created turned out to be %s " - "when it was supposed to be %s.\n",FullPath,PATHNAME); - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/_makepath/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_makepath/test1/testinfo.dat deleted file mode 100644 index 2aed8e549b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_makepath/test1/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _makepath -Name = Positive Test for _makepath -TYPE = DEFAULT -EXE1 = test1 -Description -= Purpose: Tests the PAL implementation of the _makepath function. -= Create a path, and ensure that it builds how it is supposed to. - diff --git a/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt index 064f241f24..b016f27982 100644 --- a/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_mbsdec_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.c deleted file mode 100644 index 1cd7513293..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Ensure that this function moves the string pointer back one character. -** First do a basic test to check that the pointer gets moved back the one -** character, given str1 and str+1 as params. Then try with both -** params being the same pointer, which should return NULL. Also test -** when the first pointer is past the second pointer, which should -** return null. Finally try this function on an array of single bytes, -** which it assumes are characters and should work in the same fashion. -** -** -**==========================================================================*/ - -#include - -/* - * Note: it seems like these functions would only be useful if they - * didn't assume a character was equivalent to a single byte. Be that - * as it may, I haven't seen a way to get it to behave otherwise. - */ - -int __cdecl main(int argc, char *argv[]) -{ - unsigned char *str1 = (unsigned char*) "foo"; - unsigned char str2[] = {0xC0, 0x80, 0xC0, 0x80, 0}; - unsigned char str3[] = {0}; - unsigned char *ret = NULL; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ret = _mbsdec(str1,str1+1); - if (ret != str1) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str1); - } - - ret = _mbsdec(str1,str1); - if (ret != NULL) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, NULL); - } - - ret = _mbsdec(str1+100,str1); - if (ret != NULL) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, NULL); - } - - ret = _mbsdec(str2,str2+1); - if (ret != str2) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str2+1); - } - - ret = _mbsdec(str3,str3+10); - if (ret != str3+9) - { - Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str3+9); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.cpp new file mode 100644 index 0000000000..1cd7513293 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.cpp @@ -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: test1.c +** +** Purpose: +** Ensure that this function moves the string pointer back one character. +** First do a basic test to check that the pointer gets moved back the one +** character, given str1 and str+1 as params. Then try with both +** params being the same pointer, which should return NULL. Also test +** when the first pointer is past the second pointer, which should +** return null. Finally try this function on an array of single bytes, +** which it assumes are characters and should work in the same fashion. +** +** +**==========================================================================*/ + +#include + +/* + * Note: it seems like these functions would only be useful if they + * didn't assume a character was equivalent to a single byte. Be that + * as it may, I haven't seen a way to get it to behave otherwise. + */ + +int __cdecl main(int argc, char *argv[]) +{ + unsigned char *str1 = (unsigned char*) "foo"; + unsigned char str2[] = {0xC0, 0x80, 0xC0, 0x80, 0}; + unsigned char str3[] = {0}; + unsigned char *ret = NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ret = _mbsdec(str1,str1+1); + if (ret != str1) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str1); + } + + ret = _mbsdec(str1,str1); + if (ret != NULL) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, NULL); + } + + ret = _mbsdec(str1+100,str1); + if (ret != NULL) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, NULL); + } + + ret = _mbsdec(str2,str2+1); + if (ret != str2) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str2+1); + } + + ret = _mbsdec(str3,str3+10); + if (ret != str3+9) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str3+9); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt index 531ba8e793..c7325b9513 100644 --- a/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_mbsinc_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.c deleted file mode 100644 index 95a5041af2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Ensure that this function moves the string pointer ahead one character. -** First do a basic test to check that the pointer gets moved ahead the one -** character. Then try with an array of bytes and a NULL array. Each of -** these should still work by returning a pointer to thePointer+1. -** -** -**==========================================================================*/ - -#include - -/* - * Note: it seems like these functions would only be useful if they - * didn't assume a character was equivalent to a single byte. Be that - * as it may, I haven't seen a way to get it to behave otherwise. - */ - -int __cdecl main(int argc, char *argv[]) -{ - unsigned char *str1 = (unsigned char*) "foo"; - unsigned char str2[] = {0xC0, 0x80, 0xC0, 0x80, 0}; - unsigned char str3[] = {0}; - unsigned char *ret=NULL; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ret = _mbsinc(str1); - if (ret != str1 + 1) - { - Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); - } - - ret = _mbsinc(str2); - if (ret != str2 + 1) - { - Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); - } - - ret = _mbsinc(str3); - if (ret != str3 + 1) - { - Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.cpp new file mode 100644 index 0000000000..95a5041af2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.cpp @@ -0,0 +1,62 @@ +// 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: test1.c +** +** Purpose: +** Ensure that this function moves the string pointer ahead one character. +** First do a basic test to check that the pointer gets moved ahead the one +** character. Then try with an array of bytes and a NULL array. Each of +** these should still work by returning a pointer to thePointer+1. +** +** +**==========================================================================*/ + +#include + +/* + * Note: it seems like these functions would only be useful if they + * didn't assume a character was equivalent to a single byte. Be that + * as it may, I haven't seen a way to get it to behave otherwise. + */ + +int __cdecl main(int argc, char *argv[]) +{ + unsigned char *str1 = (unsigned char*) "foo"; + unsigned char str2[] = {0xC0, 0x80, 0xC0, 0x80, 0}; + unsigned char str3[] = {0}; + unsigned char *ret=NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ret = _mbsinc(str1); + if (ret != str1 + 1) + { + Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); + } + + ret = _mbsinc(str2); + if (ret != str2 + 1) + { + Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); + } + + ret = _mbsinc(str3); + if (ret != str3 + 1) + { + Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_mbslen/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbslen/CMakeLists.txt deleted file mode 100644 index f6aa0cb2d9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_mbslen/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/_mbslen/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbslen/test1/CMakeLists.txt deleted file mode 100644 index 38aa6fb16e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_mbslen/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_mbslen_test1 - ${SOURCES} -) - -add_dependencies(paltest_mbslen_test1 coreclrpal) - -target_link_libraries(paltest_mbslen_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_mbslen/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_mbslen/test1/test1.c deleted file mode 100644 index fa24c77d8a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_mbslen/test1/test1.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Check the length of a number of arrays. The first is a normal string -** which should return its length. The second has two bytes and a null -** character, which only returns a size of 2, and the last is just a NULL -** array which should return 0. -** -** -**========================================================================*/ - -#include - -/* - * Note: it seems like these functions would only be useful if they - * didn't assume a character was equivalent to a single byte. Be that - * as it may, I haven't seen a way to get it to behave otherwise - * (eg locale) - */ - -int __cdecl main(int argc, char *argv[]) -{ - unsigned char *str1 = (unsigned char*) "foo"; - unsigned char str2[] = {0xC0, 0x80, 0}; /* the char U+0080 */ - unsigned char str3[] = {0}; - int ret=0; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ret = _mbslen(str1); - if (ret != 3) - { - Fail ("ERROR: _mbslen(\"%s\") returned %d. Expected %d\n", - str1, ret, 3); - } - - ret = _mbslen(str2); - if (ret != 2) - { - Fail ("ERROR: _mbslen(\"%s\") returned %d. Expected %d\n", - str2, ret, 2); - } - - ret = _mbslen(str3); - if (ret != 0) - { - Fail ("ERROR: _mbslen(\"%s\") returned %d. Expected %d\n", - str3, ret, 0); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_mbslen/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_mbslen/test1/testinfo.dat deleted file mode 100644 index cf830a7539..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_mbslen/test1/testinfo.dat +++ /dev/null @@ -1,15 +0,0 @@ -# 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 = C Runtime -Function = _mbsinc -Name = Positive Test for _mbslen -TYPE = DEFAULT -EXE1 = test1 -Description -= Check the length of a number of arrays. The first is a normal string -= which should return its length. The second has two bytes and a null -= character, which only returns a size of 2, and the last is just a NULL -= array which should return 0. diff --git a/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt index 7285ce229e..81c6c23a53 100644 --- a/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_mbsninc_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.c deleted file mode 100644 index 59ef50dcc3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Ensure that this functions increases a string pointer by n characters. -** Use a for loop, and increase the pointer by a different number of characters -** on each iteration, ensure that it is indeed pointing to the correct location -** each time. The second test checks to see if you attempt to increase the -** pointer past the end of the string, the pointer should just point at the -** last character. -** -** -**==========================================================================*/ - -#include - -/* - * Note: it seems like these functions would only be useful if they - * didn't assume a character was equivalent to a single byte. Be that - * as it may, I haven't seen a way to get it to behave otherwise. - */ - -int __cdecl main(int argc, char *argv[]) -{ - unsigned char str[] = {0xC0, 0x80, 0xC0, 0x80, 0}; - int i=0; - unsigned char *ret=NULL; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - for (i=0; i<5; i++) - { - ret = _mbsninc(str, i); - if (ret != str + i) - { - Fail ("ERROR: _mbsninc returned %p. Expected %p\n", ret, str+i); - } - } - - /* - * trying to advance past the end of the string should just - * return the end. - */ - ret = _mbsninc(str, 5); - if (ret != str + 4) - { - Fail ("ERROR: _mbsninc returned %p. Expected %p\n", ret, str+4); - } - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.cpp new file mode 100644 index 0000000000..59ef50dcc3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.cpp @@ -0,0 +1,65 @@ +// 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: test1.c +** +** Purpose: +** Ensure that this functions increases a string pointer by n characters. +** Use a for loop, and increase the pointer by a different number of characters +** on each iteration, ensure that it is indeed pointing to the correct location +** each time. The second test checks to see if you attempt to increase the +** pointer past the end of the string, the pointer should just point at the +** last character. +** +** +**==========================================================================*/ + +#include + +/* + * Note: it seems like these functions would only be useful if they + * didn't assume a character was equivalent to a single byte. Be that + * as it may, I haven't seen a way to get it to behave otherwise. + */ + +int __cdecl main(int argc, char *argv[]) +{ + unsigned char str[] = {0xC0, 0x80, 0xC0, 0x80, 0}; + int i=0; + unsigned char *ret=NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + for (i=0; i<5; i++) + { + ret = _mbsninc(str, i); + if (ret != str + i) + { + Fail ("ERROR: _mbsninc returned %p. Expected %p\n", ret, str+i); + } + } + + /* + * trying to advance past the end of the string should just + * return the end. + */ + ret = _mbsninc(str, 5); + if (ret != str + 4) + { + Fail ("ERROR: _mbsninc returned %p. Expected %p\n", ret, str+4); + } + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/CMakeLists.txt index e9a3e29192..f4fedb61ae 100644 --- a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_open_osfhandle_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.c deleted file mode 100644 index ee2c8ea418..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.c +++ /dev/null @@ -1,132 +0,0 @@ -// 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: test1.c (_open_osfhandle) -** -** Purpose: Tests the PAL implementation of the _open_osfhandle function. -** This API accepts a OS Handle returned from CreatePipe() and -** a flag of _O_RDONLY and returns a C Run-Time handle. The test -** will write to the pipe and pass the C Run-Time handle to _fdopen -** to open the Read Handle to compare what was written with what -** was wrote. They should be the same. -** -** Depends: CreatePipe -** WriteFile -** _fdopen -** fread -** memcmp -** fclose -** strlen -** CloseHandle -** -** -**===================================================================*/ - -#include - -const char* cTestString = "one fish, two fish, red fish, blue fish."; - -int __cdecl main(int argc, char **argv) -{ - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - BOOL bRetVal = FALSE; - int iFiledes = 0; - DWORD dwBytesWritten; - char buffer[45]; - FILE *fp; - size_t len; - - SECURITY_ATTRIBUTES lpPipeAttributes; - - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /*Create a Pipe*/ - bRetVal = CreatePipe(&hReadPipe, /* read handle*/ - &hWritePipe, /* write handle */ - &lpPipeAttributes, /* security attributes*/ - 0); /* pipe size*/ - if (bRetVal == FALSE) - { - Fail("ERROR: unable to create pipe"); - } - - /*Write to the write pipe handle*/ - bRetVal = WriteFile(hWritePipe, /* handle to file*/ - cTestString, /* data buffer*/ - strlen(cTestString),/* number of bytes to write*/ - &dwBytesWritten, /* number of bytes written*/ - NULL); /* overlapped buffer*/ - if (bRetVal == FALSE) - { - Fail("ERROR: unable to write to pipe write handle " - "hWritePipe=0x%lx", hWritePipe); - } - - /*Test to see if the WriteFile wrote the correct amount*/ - if(dwBytesWritten != strlen(cTestString)) - { - Fail("Error: WriteFile wrote \"%d\", should have written \"%d\\n", - dwBytesWritten, strlen(cTestString)); - } - - /*Get a file descriptor for the read pipe handle. - *This is what we are testing.*/ - iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); - if (iFiledes == -1) - { - Fail("ERROR: _open_osfhandle failed to open " - " hReadPipe=0x%lx", hReadPipe); - } - - /*Open read pipe handle in read mode. - *Verify that we have returned a correct, - *C Run-time handle*/ - fp = _fdopen(iFiledes, "r"); - if (fp == NULL) - { - Fail("ERROR: unable to fdopen file descriptor" - " iFiledes=%d", iFiledes); - } - - /*Read from the read pipe handle*/ - len = fread(buffer, sizeof(char), strlen(cTestString), fp); - if((len == 0) || (len != strlen(cTestString))) - { - Fail("ERROR: Unable to read from file stream fp=0x%lx\n", fp); - } - - /*Compare what was read with what was written.*/ - if ((memcmp(cTestString, buffer, strlen(cTestString))) != 0) - { - Fail("ERROR: read \"%s\" expected \"%s\" \n", buffer, cTestString); - } - - /*Close write pipe handle*/ - if (CloseHandle(hWritePipe) == 0) - { - Fail("ERROR: Unable to close write pipe handle " - "hWritePipe=0x%lx", hWritePipe); - } - - if ((fclose(fp)) != 0) - { - Fail("ERROR: Unable to close C-Runtime handle " - "iFilesdes=%d", iFiledes); - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.cpp new file mode 100644 index 0000000000..ee2c8ea418 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.cpp @@ -0,0 +1,132 @@ +// 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: test1.c (_open_osfhandle) +** +** Purpose: Tests the PAL implementation of the _open_osfhandle function. +** This API accepts a OS Handle returned from CreatePipe() and +** a flag of _O_RDONLY and returns a C Run-Time handle. The test +** will write to the pipe and pass the C Run-Time handle to _fdopen +** to open the Read Handle to compare what was written with what +** was wrote. They should be the same. +** +** Depends: CreatePipe +** WriteFile +** _fdopen +** fread +** memcmp +** fclose +** strlen +** CloseHandle +** +** +**===================================================================*/ + +#include + +const char* cTestString = "one fish, two fish, red fish, blue fish."; + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + int iFiledes = 0; + DWORD dwBytesWritten; + char buffer[45]; + FILE *fp; + size_t len; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, /* read handle*/ + &hWritePipe, /* write handle */ + &lpPipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + if (bRetVal == FALSE) + { + Fail("ERROR: unable to create pipe"); + } + + /*Write to the write pipe handle*/ + bRetVal = WriteFile(hWritePipe, /* handle to file*/ + cTestString, /* data buffer*/ + strlen(cTestString),/* number of bytes to write*/ + &dwBytesWritten, /* number of bytes written*/ + NULL); /* overlapped buffer*/ + if (bRetVal == FALSE) + { + Fail("ERROR: unable to write to pipe write handle " + "hWritePipe=0x%lx", hWritePipe); + } + + /*Test to see if the WriteFile wrote the correct amount*/ + if(dwBytesWritten != strlen(cTestString)) + { + Fail("Error: WriteFile wrote \"%d\", should have written \"%d\\n", + dwBytesWritten, strlen(cTestString)); + } + + /*Get a file descriptor for the read pipe handle. + *This is what we are testing.*/ + iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); + if (iFiledes == -1) + { + Fail("ERROR: _open_osfhandle failed to open " + " hReadPipe=0x%lx", hReadPipe); + } + + /*Open read pipe handle in read mode. + *Verify that we have returned a correct, + *C Run-time handle*/ + fp = _fdopen(iFiledes, "r"); + if (fp == NULL) + { + Fail("ERROR: unable to fdopen file descriptor" + " iFiledes=%d", iFiledes); + } + + /*Read from the read pipe handle*/ + len = fread(buffer, sizeof(char), strlen(cTestString), fp); + if((len == 0) || (len != strlen(cTestString))) + { + Fail("ERROR: Unable to read from file stream fp=0x%lx\n", fp); + } + + /*Compare what was read with what was written.*/ + if ((memcmp(cTestString, buffer, strlen(cTestString))) != 0) + { + Fail("ERROR: read \"%s\" expected \"%s\" \n", buffer, cTestString); + } + + /*Close write pipe handle*/ + if (CloseHandle(hWritePipe) == 0) + { + Fail("ERROR: Unable to close write pipe handle " + "hWritePipe=0x%lx", hWritePipe); + } + + if ((fclose(fp)) != 0) + { + Fail("ERROR: Unable to close C-Runtime handle " + "iFilesdes=%d", iFiledes); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/CMakeLists.txt index 1031ec1df9..6086868de2 100644 --- a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_open_osfhandle_test2 diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.c deleted file mode 100644 index 6c756b177a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.c +++ /dev/null @@ -1,86 +0,0 @@ -// 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: test2.c (_open_osfhandle) -** -** Purpose: Tests the PAL implementation of the _open_osfhandle function. -** This API accepts a OS Handle returned from CreatePipe() and -** a flag of _O_RDONLY and returns a C Run-Time handle. The test -** will pass a NULL handle, and unsupported flags. All cases -** should fail. -** -** Depends: CreatePipe -** CloseHandle -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - BOOL bRetVal = FALSE; - int iFiledes = 0; - - SECURITY_ATTRIBUTES lpPipeAttributes; - - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /*Create a Pipe*/ - bRetVal = CreatePipe(&hReadPipe, /* read handle*/ - &hWritePipe, /* write handle */ - &lpPipeAttributes, /* security attributes*/ - 0); /* pipe size*/ - if (bRetVal == FALSE) - { - Fail("ERROR: unable to create pipe"); - } - - /*Close write pipe handle*/ - if (CloseHandle(hWritePipe) == 0) - { - Fail("ERROR: Unable to close write pipe handle " - "hWritePipe=0x%lx", hWritePipe); - } - - /*Close read pipe handle*/ - if (CloseHandle(hReadPipe) == 0) - { - Fail("ERROR: Unable to close read pipe handle " - "hReadPipe=0x%lx", hReadPipe); - } - - /*Test with a Closed handle and supported flag _O_RDONLY*/ - iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); - if (iFiledes != -1) - { - Fail("ERROR: _open_osfhandle successfullly opened " - " hReadPipe which was closed, with _O_RDONLY"); - } - - /*Test with a NULL handle and supported flag _O_RDONLY*/ - hReadPipe = NULL; - iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); - if (iFiledes != -1) - { - Fail("ERROR: _open_osfhandle successfullly opened " - " hReadPipe=NULL with _O_RDONLY"); - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.cpp new file mode 100644 index 0000000000..6c756b177a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.cpp @@ -0,0 +1,86 @@ +// 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: test2.c (_open_osfhandle) +** +** Purpose: Tests the PAL implementation of the _open_osfhandle function. +** This API accepts a OS Handle returned from CreatePipe() and +** a flag of _O_RDONLY and returns a C Run-Time handle. The test +** will pass a NULL handle, and unsupported flags. All cases +** should fail. +** +** Depends: CreatePipe +** CloseHandle +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + int iFiledes = 0; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, /* read handle*/ + &hWritePipe, /* write handle */ + &lpPipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + if (bRetVal == FALSE) + { + Fail("ERROR: unable to create pipe"); + } + + /*Close write pipe handle*/ + if (CloseHandle(hWritePipe) == 0) + { + Fail("ERROR: Unable to close write pipe handle " + "hWritePipe=0x%lx", hWritePipe); + } + + /*Close read pipe handle*/ + if (CloseHandle(hReadPipe) == 0) + { + Fail("ERROR: Unable to close read pipe handle " + "hReadPipe=0x%lx", hReadPipe); + } + + /*Test with a Closed handle and supported flag _O_RDONLY*/ + iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); + if (iFiledes != -1) + { + Fail("ERROR: _open_osfhandle successfullly opened " + " hReadPipe which was closed, with _O_RDONLY"); + } + + /*Test with a NULL handle and supported flag _O_RDONLY*/ + hReadPipe = NULL; + iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); + if (iFiledes != -1) + { + Fail("ERROR: _open_osfhandle successfullly opened " + " hReadPipe=NULL with _O_RDONLY"); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putenv/test1/CMakeLists.txt index 0a75b41113..9096bc1033 100644 --- a/src/pal/tests/palsuite/c_runtime/_putenv/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_putenv_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.c deleted file mode 100644 index 2d096adc78..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.c +++ /dev/null @@ -1,99 +0,0 @@ -// 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: test1.c -** -** Purpose: Create an environment variable with _putenv and then use getenv -** to check it. Check that we get the expected errors with invalid input. -** -** -**===================================================================*/ - -#include - -struct TestElement -{ - char _putenvString[1024]; /* argument string sent to putenv */ - char varName[1024]; /* variable component of argument string */ - char varValue[1024]; /* value component of argument string */ - BOOL bValidString; /* valid argument string identifier */ -}; - -struct TestElement TestCases[] = -{ - {"PalTestingEnvironmentVariable=A value", "PalTestingEnvironmentVariable", - "A value", TRUE}, - {"AnotherVariable=", "AnotherVariable", "", TRUE}, - {"YetAnotherVariable", "", "", FALSE}, - {"=ADifferentVariable", "", "ADifferentVariable", FALSE}, - {"", "", "", FALSE} - -}; - -int __cdecl main(int argc, char **argv) -{ - - int i; - char *variableValue; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - for (i = 0; i < (sizeof(TestCases)/sizeof(struct TestElement)) ; i++) - { - if((_putenv(TestCases[i]._putenvString) == -1) && - ( TestCases[i].bValidString == TRUE)) - { - Fail("ERROR: _putenv failed to set an environment " - "variable with a valid format.\n Call was" - "_putenv(%s)\n", TestCases[i]._putenvString); - } - /* - * For valid _putenvString values, check to see the variable was set - */ - if (TestCases[i].bValidString == TRUE) - { - variableValue = getenv(TestCases[i].varName); - - if (variableValue == NULL) - { - if (*TestCases[i].varValue != '\0') - { - Fail("ERROR: getenv(%s) call returned NULL.\nThe call " - "should have returned \"%s\"\n", TestCases[i].varName - , TestCases[i].varValue); - } - } - else if ( strcmp(variableValue, TestCases[i].varValue) != 0) - { - Fail("ERROR: _putenv(%s)\nshould have set the variable " - "%s\n to \"%s\".\nA subsequent call to getenv(%s)\n" - "returned \"%s\" instead.\n", TestCases[i]._putenvString - , TestCases[i].varName, TestCases[i].varValue - , TestCases[i].varName, variableValue); - } - } - else - /* - * Check to see that putenv fails for malformed _putenvString values - */ - { - variableValue = getenv(TestCases[i].varName); - - if (variableValue != NULL) - { - Fail("ERROR: getenv(%s) call should have returned NULL.\n" - "Instead it returned \"%s\".\n", TestCases[i].varName - , TestCases[i].varValue); - } - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.cpp new file mode 100644 index 0000000000..2d096adc78 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.cpp @@ -0,0 +1,99 @@ +// 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: test1.c +** +** Purpose: Create an environment variable with _putenv and then use getenv +** to check it. Check that we get the expected errors with invalid input. +** +** +**===================================================================*/ + +#include + +struct TestElement +{ + char _putenvString[1024]; /* argument string sent to putenv */ + char varName[1024]; /* variable component of argument string */ + char varValue[1024]; /* value component of argument string */ + BOOL bValidString; /* valid argument string identifier */ +}; + +struct TestElement TestCases[] = +{ + {"PalTestingEnvironmentVariable=A value", "PalTestingEnvironmentVariable", + "A value", TRUE}, + {"AnotherVariable=", "AnotherVariable", "", TRUE}, + {"YetAnotherVariable", "", "", FALSE}, + {"=ADifferentVariable", "", "ADifferentVariable", FALSE}, + {"", "", "", FALSE} + +}; + +int __cdecl main(int argc, char **argv) +{ + + int i; + char *variableValue; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + for (i = 0; i < (sizeof(TestCases)/sizeof(struct TestElement)) ; i++) + { + if((_putenv(TestCases[i]._putenvString) == -1) && + ( TestCases[i].bValidString == TRUE)) + { + Fail("ERROR: _putenv failed to set an environment " + "variable with a valid format.\n Call was" + "_putenv(%s)\n", TestCases[i]._putenvString); + } + /* + * For valid _putenvString values, check to see the variable was set + */ + if (TestCases[i].bValidString == TRUE) + { + variableValue = getenv(TestCases[i].varName); + + if (variableValue == NULL) + { + if (*TestCases[i].varValue != '\0') + { + Fail("ERROR: getenv(%s) call returned NULL.\nThe call " + "should have returned \"%s\"\n", TestCases[i].varName + , TestCases[i].varValue); + } + } + else if ( strcmp(variableValue, TestCases[i].varValue) != 0) + { + Fail("ERROR: _putenv(%s)\nshould have set the variable " + "%s\n to \"%s\".\nA subsequent call to getenv(%s)\n" + "returned \"%s\" instead.\n", TestCases[i]._putenvString + , TestCases[i].varName, TestCases[i].varValue + , TestCases[i].varName, variableValue); + } + } + else + /* + * Check to see that putenv fails for malformed _putenvString values + */ + { + variableValue = getenv(TestCases[i].varName); + + if (variableValue != NULL) + { + Fail("ERROR: getenv(%s) call should have returned NULL.\n" + "Instead it returned \"%s\".\n", TestCases[i].varName + , TestCases[i].varValue); + } + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putenv/test2/CMakeLists.txt index e0539681cd..ad99eba373 100644 --- a/src/pal/tests/palsuite/c_runtime/_putenv/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_putenv_test2 diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.c deleted file mode 100644 index 39be4f68b4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: test2.c -** -** Purpose: Create an environment variable with _putenv and then use getenv -** to check it. This test resets an environment variable. -** -** -**===================================================================*/ - -#include - -const char *_putenvString0 = "AnUnusualVariable=AnUnusualValue"; -const char *_putenvString1 = "AnUnusualVariable="; -const char *variable = "AnUnusualVariable"; -const char *value = "AnUnusualValue"; - -int __cdecl main(int argc, char **argv) -{ - - char *variableValue; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if(_putenv(_putenvString0) == -1) - { - Fail("ERROR: _putenv failed to set an environment " - "variable with a valid format.\n Call was" - "_putenv(%s)\n", _putenvString0); - } - - variableValue = getenv(variable); - - if (variableValue == NULL) - { - Fail("ERROR: getenv(%s) call returned NULL\nThe call " - "should have returned '%s'\n", variable, value); - } - else - { - if ( strcmp(variableValue, value) != 0 ) - { - Fail("ERROR: _putenv(%s)\nshould have set the variable " - "'%s'\n to '%s'.\nA subsequent call to getenv(%s)\n" - "returned '%s' instead.\n", _putenvString0, - variable, value, variable, variableValue); - } - else - { - if(_putenv(_putenvString1) == -1) - { - Fail("ERROR: _putenv failed to set an environment " - "variable with a valid format.\n Call was" - "_putenv(%s)\n", _putenvString1); - } - - variableValue = getenv(variable); - - if (variableValue != NULL) - { - Fail("ERROR: getenv(%s) call did not return NULL.\nThe call " - "returned '%s'.\n", variable, value); - } - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.cpp new file mode 100644 index 0000000000..39be4f68b4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.cpp @@ -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: test2.c +** +** Purpose: Create an environment variable with _putenv and then use getenv +** to check it. This test resets an environment variable. +** +** +**===================================================================*/ + +#include + +const char *_putenvString0 = "AnUnusualVariable=AnUnusualValue"; +const char *_putenvString1 = "AnUnusualVariable="; +const char *variable = "AnUnusualVariable"; +const char *value = "AnUnusualValue"; + +int __cdecl main(int argc, char **argv) +{ + + char *variableValue; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + if(_putenv(_putenvString0) == -1) + { + Fail("ERROR: _putenv failed to set an environment " + "variable with a valid format.\n Call was" + "_putenv(%s)\n", _putenvString0); + } + + variableValue = getenv(variable); + + if (variableValue == NULL) + { + Fail("ERROR: getenv(%s) call returned NULL\nThe call " + "should have returned '%s'\n", variable, value); + } + else + { + if ( strcmp(variableValue, value) != 0 ) + { + Fail("ERROR: _putenv(%s)\nshould have set the variable " + "'%s'\n to '%s'.\nA subsequent call to getenv(%s)\n" + "returned '%s' instead.\n", _putenvString0, + variable, value, variable, variableValue); + } + else + { + if(_putenv(_putenvString1) == -1) + { + Fail("ERROR: _putenv failed to set an environment " + "variable with a valid format.\n Call was" + "_putenv(%s)\n", _putenvString1); + } + + variableValue = getenv(variable); + + if (variableValue != NULL) + { + Fail("ERROR: getenv(%s) call did not return NULL.\nThe call " + "returned '%s'.\n", variable, value); + } + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putenv/test3/CMakeLists.txt index a67241022b..fc97b951b3 100644 --- a/src/pal/tests/palsuite/c_runtime/_putenv/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_putenv_test3 diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.c b/src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.c deleted file mode 100644 index 8aa6777307..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.c +++ /dev/null @@ -1,102 +0,0 @@ -// 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: test3.c -** -** Purpose: Create environment variables that differ only in Case, and -** verify that the BSD operating system treats the variables -** differently. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ -#if WIN32 - - return PASS; - -#else - - const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; - const char* SecondVariable = "PALTESTINGEnvironmentVariable=Different value"; - const char* FirstVarName = "PalTestingEnvironmentVariable"; - const char* FirstVarValue = "The value"; - char* result; - - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Use _putenv to set an environment variable. This ensures that the - variable we're testing on is always present. - */ - - if(_putenv(FirstVariable) != 0) - { - Fail("ERROR: _putenv failed to set an environment variable that " - "getenv will be using for testing.\n"); - } - - - /* Call getenv -- ensure it doesn't return NULL and the string it returns - is the value we set above. Also make sure that each environment variable, - differing only by case, returns it's own value. - */ - - result = getenv(FirstVarName); - if(result == NULL) - { - Fail("ERROR: The result of getenv on a valid Environment Variable " - "was NULL, which indicates the environment varaible was not " - "found.\n"); - } - - if(strcmp(result, FirstVarValue) != 0) - { - Fail("ERROR: The value obtained by getenv() was not equal to the " - "correct value of the environment variable. The correct " - "value is '%s' and the function returned '%s'.\n", - FirstVarValue, - result); - } - - /* Set the second environment variable, which only differs in Case */ - if(_putenv(SecondVariable) != 0) - { - Fail("ERROR: _putenv failed to set an environment variable that " - "getenv will be using for testing.\n"); - } - - /* Verify that the environment variables - */ - - result = getenv(FirstVarName); - if(result == NULL) - { - Fail("ERROR: The result of getenv on a valid Environment Variable " - "was NULL, which indicates the environment varaible was not " - "found.\n"); - } - - if(strcmp(result, FirstVarValue) != 0) - { - Fail("ERROR: The value obtained by getenv() was not equal to the " - "correct value of the environment variable. The correct " - "value is '%s' and the function returned '%s'.\n", - FirstVarValue, - result); - } - - PAL_Terminate(); - return PASS; - -#endif -} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.cpp new file mode 100644 index 0000000000..8aa6777307 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.cpp @@ -0,0 +1,102 @@ +// 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: test3.c +** +** Purpose: Create environment variables that differ only in Case, and +** verify that the BSD operating system treats the variables +** differently. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ +#if WIN32 + + return PASS; + +#else + + const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; + const char* SecondVariable = "PALTESTINGEnvironmentVariable=Different value"; + const char* FirstVarName = "PalTestingEnvironmentVariable"; + const char* FirstVarValue = "The value"; + char* result; + + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Use _putenv to set an environment variable. This ensures that the + variable we're testing on is always present. + */ + + if(_putenv(FirstVariable) != 0) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + + /* Call getenv -- ensure it doesn't return NULL and the string it returns + is the value we set above. Also make sure that each environment variable, + differing only by case, returns it's own value. + */ + + result = getenv(FirstVarName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, FirstVarValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + FirstVarValue, + result); + } + + /* Set the second environment variable, which only differs in Case */ + if(_putenv(SecondVariable) != 0) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + /* Verify that the environment variables + */ + + result = getenv(FirstVarName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, FirstVarValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + FirstVarValue, + result); + } + + PAL_Terminate(); + return PASS; + +#endif +} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putenv/test4/CMakeLists.txt index 518282ccc7..3881626d01 100644 --- a/src/pal/tests/palsuite/c_runtime/_putenv/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_putenv_test4 diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.c b/src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.c deleted file mode 100644 index 48d7ba963c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.c +++ /dev/null @@ -1,75 +0,0 @@ -// 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: test4.c -** -** Purpose: Create an environment variable and try to retrieve -** it using the same name but with different case. This -** is to show that the Win32 representation of _putenv -** is case insensitive. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ -#if WIN32 - - const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; - const char* ModifiedName = "PALTESTINGEnvironmentVariable"; - const char* FirstVarValue = "The value"; - char* result; - - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Use _putenv to set an environment variable. This ensures that the - variable we're testing on is always present. - */ - - if(_putenv(FirstVariable) != 0) - { - Fail("ERROR: _putenv failed to set an environment variable that " - "getenv will be using for testing.\n"); - } - - - /* Call getenv -- ensure it doesn't return NULL and the string it returns - is the value we set above. Also make sure that each environment variable, - differing only by case, doesn't affect the return value. - */ - - result = getenv(ModifiedName); - if(result == NULL) - { - Fail("ERROR: The result of getenv on a valid Environment Variable " - "was NULL, which indicates the environment varaible was not " - "found.\n"); - } - - if(strcmp(result, FirstVarValue) != 0) - { - Fail("ERROR: The value obtained by getenv() was not equal to the " - "correct value of the environment variable. The correct " - "value is '%s' and the function returned '%s'.\n", - FirstVarValue, - result); - } - - - PAL_Terminate(); - return PASS; - -#else - return PASS; - -#endif -} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.cpp new file mode 100644 index 0000000000..48d7ba963c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.cpp @@ -0,0 +1,75 @@ +// 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: test4.c +** +** Purpose: Create an environment variable and try to retrieve +** it using the same name but with different case. This +** is to show that the Win32 representation of _putenv +** is case insensitive. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ +#if WIN32 + + const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; + const char* ModifiedName = "PALTESTINGEnvironmentVariable"; + const char* FirstVarValue = "The value"; + char* result; + + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Use _putenv to set an environment variable. This ensures that the + variable we're testing on is always present. + */ + + if(_putenv(FirstVariable) != 0) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + + /* Call getenv -- ensure it doesn't return NULL and the string it returns + is the value we set above. Also make sure that each environment variable, + differing only by case, doesn't affect the return value. + */ + + result = getenv(ModifiedName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, FirstVarValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + FirstVarValue, + result); + } + + + PAL_Terminate(); + return PASS; + +#else + return PASS; + +#endif +} diff --git a/src/pal/tests/palsuite/c_runtime/_putw/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putw/test1/CMakeLists.txt index c3018ad322..78833d4e13 100644 --- a/src/pal/tests/palsuite/c_runtime/_putw/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_putw/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_putw_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_putw/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_putw/test1/test1.c deleted file mode 100644 index ecfc9046ac..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_putw/test1/test1.c +++ /dev/null @@ -1,112 +0,0 @@ -// 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: test1.c -** -** Purpose: Writes a series of integers to a file, test.dat, -** then verifies the results. -** -** Dependency: fopen(...) -** fclose(...) -** CloseHandle(...) -** DeleteFileA(...) -** _getw(...) -** -** -** -**==========================================================================*/ - - -#include - -const char testFileName[] = "test.dat"; - -static void Cleanup(HANDLE hFile) -{ - if (fclose(hFile)) - { - Trace("_putw: ERROR -> Unable to close file \"%s\".\n", - testFileName); - } - if (!DeleteFileA(testFileName)) - { - Trace("_putw: ERROR -> Unable to delete file \"%s\". ", - "GetLastError returned %u.\n", - testFileName, - GetLastError()); - } -} - - -int __cdecl main(int argc, char **argv) -{ - - FILE * pfTest = NULL; - int testArray[] = {0,1,-1,0x7FFFFFFF,0x80000000,0xFFFFFFFF,0xFFFFAAAA}; - int i = 0; - int retValue = 0; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /*write the file that we will use to test */ - pfTest = fopen(testFileName, "w"); - if (pfTest == NULL) - { - Fail ("Unable to write test file.\n"); - } - - for (i = 0; i < sizeof(testArray)/sizeof(int) ; i++) - { - _putw(testArray[i], pfTest); - - if( ferror( pfTest ) ) - { - Cleanup(pfTest); - Fail( "Error:in _putw -> error has occurred in the " - "stream while writing to the file: \"test.dat\"\n"); - } - - } - - if (fclose(pfTest) != 0) - { - Cleanup(pfTest); - Fail ("Error closing file after writing with _putw(..).\n"); - } - - /*open the new test file and compare*/ - pfTest = fopen(testFileName, "r"); - if (pfTest == NULL) - { - Fail ("Error opening \"%s\", which is odd, since I just finished " - "creating that file.\n", testFileName); - } - retValue =_getw( pfTest ); - i = 0; - while(retValue != EOF) - { - if(retValue != testArray[i]) - { - Cleanup(pfTest); - Fail ("Integers written by _putw are not in the correct format\n", - testFileName); - } - retValue = _getw( pfTest ); - i++ ; - } - - Cleanup(pfTest); - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/_putw/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_putw/test1/test1.cpp new file mode 100644 index 0000000000..02b7cc7a49 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putw/test1/test1.cpp @@ -0,0 +1,112 @@ +// 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: test1.c +** +** Purpose: Writes a series of integers to a file, test.dat, +** then verifies the results. +** +** Dependency: fopen(...) +** fclose(...) +** CloseHandle(...) +** DeleteFileA(...) +** _getw(...) +** +** +** +**==========================================================================*/ + + +#include + +const char testFileName[] = "test.dat"; + +static void Cleanup(HANDLE hFile) +{ + if (fclose((PAL_FILE*)hFile)) + { + Trace("_putw: ERROR -> Unable to close file \"%s\".\n", + testFileName); + } + if (!DeleteFileA(testFileName)) + { + Trace("_putw: ERROR -> Unable to delete file \"%s\". ", + "GetLastError returned %u.\n", + testFileName, + GetLastError()); + } +} + + +int __cdecl main(int argc, char **argv) +{ + + FILE * pfTest = NULL; + int testArray[] = {0,1,-1,0x7FFFFFFF,0x80000000,0xFFFFFFFF,0xFFFFAAAA}; + int i = 0; + int retValue = 0; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /*write the file that we will use to test */ + pfTest = fopen(testFileName, "w"); + if (pfTest == NULL) + { + Fail ("Unable to write test file.\n"); + } + + for (i = 0; i < sizeof(testArray)/sizeof(int) ; i++) + { + _putw(testArray[i], pfTest); + + if( ferror( pfTest ) ) + { + Cleanup(pfTest); + Fail( "Error:in _putw -> error has occurred in the " + "stream while writing to the file: \"test.dat\"\n"); + } + + } + + if (fclose(pfTest) != 0) + { + Cleanup(pfTest); + Fail ("Error closing file after writing with _putw(..).\n"); + } + + /*open the new test file and compare*/ + pfTest = fopen(testFileName, "r"); + if (pfTest == NULL) + { + Fail ("Error opening \"%s\", which is odd, since I just finished " + "creating that file.\n", testFileName); + } + retValue =_getw( pfTest ); + i = 0; + while(retValue != EOF) + { + if(retValue != testArray[i]) + { + Cleanup(pfTest); + Fail ("Integers written by _putw are not in the correct format\n", + testFileName); + } + retValue = _getw( pfTest ); + i++ ; + } + + Cleanup(pfTest); + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/CMakeLists.txt deleted file mode 100644 index cafb9536b0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) -add_subdirectory(test10) -add_subdirectory(test11) -add_subdirectory(test12) -add_subdirectory(test13) -add_subdirectory(test14) -add_subdirectory(test15) -add_subdirectory(test16) -add_subdirectory(test17) -add_subdirectory(test18) -add_subdirectory(test19) -add_subdirectory(test2) -add_subdirectory(test3) -add_subdirectory(test4) -add_subdirectory(test5) -add_subdirectory(test6) -add_subdirectory(test7) -add_subdirectory(test8) -add_subdirectory(test9) - diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/_snprintf.h b/src/pal/tests/palsuite/c_runtime/_snprintf/_snprintf.h deleted file mode 100644 index 84abf62f0b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/_snprintf.h +++ /dev/null @@ -1,194 +0,0 @@ -// 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: _snprintf.h -** -** Purpose: Containts common testing functions for _snprintf -** -** -**==========================================================================*/ - -#ifndef __STRINGTEST_H__ -#define __STRINGTEST_H__ - -void DoStrTest(char *formatstr, char* param, char *checkstr) -{ - char buf[256] = { 0 }; - - _snprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert string \"%s\" into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - param, formatstr, checkstr, buf); - } -} - -void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) -{ - char buf[256] = { 0 }; - - _snprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert wide string \"%s\" into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - convertC(param), formatstr, checkstr, buf); - } -} - - -void DoPointerTest(char *formatstr, void* param, char* paramstr, char - *checkstr1) -{ - char buf[256] = { 0 }; - - _snprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\"\n" - "Expected \"%s\", got \"%s\".\n", - paramstr, formatstr, checkstr1, buf); - } -} - -void DoCountTest(char *formatstr, int param, char *checkstr) -{ - char buf[512] = { 0 }; - int n = -1; - - _snprintf(buf, 512, formatstr, &n); - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - param, n); - } - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); - } -} - -void DoShortCountTest(char *formatstr, int param, char *checkstr) -{ - char buf[256] = { 0 }; - short int n = -1; - - _snprintf(buf, 256, formatstr, &n); - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - param, n); - } - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); - } -} - -void DoCharTest(char *formatstr, char param, char *checkstr) -{ - char buf[256] = { 0 }; - - _snprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - param, param, formatstr, checkstr, buf); - } -} - -void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) -{ - char buf[256] = { 0 }; - - _snprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - (char)param, param, formatstr, checkstr, buf); - } -} - -void DoNumTest(char *formatstr, int value, char *checkstr) -{ - char buf[256] = { 0 }; - - _snprintf(buf, 256, formatstr, value); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert %#x into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - value, formatstr, checkstr, buf); - } -} - -void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr1) -{ - char buf[256] = { 0 }; - - _snprintf(buf, 256, formatstr, value); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\"\n" - "Expected \"%s\", got \"%s\".\n", - valuestr, formatstr, checkstr1, buf); - } -} - -void DoDoubleTest(char *formatstr, double value, char *checkstr1, char -*checkstr2) -{ - char buf[256] = { 0 }; - - _snprintf(buf, 256, formatstr, value); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 - && memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) - { - Fail("ERROR: failed to insert %f into \"%s\"\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - value, formatstr, checkstr1, checkstr2, buf); - } -} - -void DoArgumentPrecTest(char *formatstr, int precision, void *param, char -*paramstr, char *checkstr1, char*checkstr2) -{ - char buf[256]; - - _snprintf(buf, 256, formatstr, precision, param); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && - memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - paramstr, formatstr, precision, checkstr1, checkstr2, buf); - } - -} - -void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param, -char *checkstr1, char *checkstr2) -{ - char buf[256]; - - _snprintf(buf, 256, formatstr, precision, param); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && - memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) - { - Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - param, formatstr, precision, checkstr1, checkstr2, buf); - } - -} - -#endif - diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test1/CMakeLists.txt deleted file mode 100644 index ab126fc59d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_snprintf_test1 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test1 coreclrpal) - -target_link_libraries(paltest_snprintf_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test1/test1.c deleted file mode 100644 index eef7406baa..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test1/test1.c +++ /dev/null @@ -1,58 +0,0 @@ -// 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: test1.c -** -** Purpose: General test to see if _snprintf works correctly -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - char checkstr[] = "hello world"; - char buf[256] = { 0 }; - int ret; - - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - _snprintf(buf, 256, "hello world"); - if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) - { - Fail("ERROR: expected \"%s\" (up to %d chars), got \"%s\"\n", - checkstr, 256, buf); - } - - _snprintf(buf, 256, "xxxxxxxxxxxxxxxxx"); - ret = _snprintf(buf, 8, "hello world"); - - if (ret >= 0) - { - Fail("ERROR: expected negative return value, got %d", ret); - } - if (memcmp(checkstr, buf, 8) != 0 || buf[8] != 'x') - { - Fail("ERROR: expected %s (up to %d chars), got %s\n", - checkstr, 8, buf); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test1/testinfo.dat deleted file mode 100644 index c15ce1dcba..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test1/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test1 -Description -= General test to see if _snprintf works correctly diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test10/CMakeLists.txt deleted file mode 100644 index e8e9308849..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test10/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test10.c -) - -add_executable(paltest_snprintf_test10 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test10 coreclrpal) - -target_link_libraries(paltest_snprintf_test10 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test10/test10.c deleted file mode 100644 index 9191ccef27..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test10/test10.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test10.c -** -** Purpose: Tests _snprintf with octal numbers -** -** -**==========================================================================*/ - - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %o", pos, "foo 52"); - DoNumTest("foo %lo", 0xFFFF, "foo 177777"); - DoNumTest("foo %ho", 0xFFFF, "foo 177777"); - DoNumTest("foo %Lo", pos, "foo 52"); - DoI64Test("foo %I64o", l, "42", "foo 52"); - DoNumTest("foo %3o", pos, "foo 52"); - DoNumTest("foo %-3o", pos, "foo 52 "); - DoNumTest("foo %.1o", pos, "foo 52"); - DoNumTest("foo %.3o", pos, "foo 052"); - DoNumTest("foo %03o", pos, "foo 052"); - DoNumTest("foo %#o", pos, "foo 052"); - DoNumTest("foo %+o", pos, "foo 52"); - DoNumTest("foo % o", pos, "foo 52"); - DoNumTest("foo %+o", neg, "foo 37777777726"); - DoNumTest("foo % o", neg, "foo 37777777726"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test10/testinfo.dat deleted file mode 100644 index 44ff48e030..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test10/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test10 -Description -= Tests _snprintf with octal numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test11/CMakeLists.txt deleted file mode 100644 index ccf3dc2572..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test11/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test11.c -) - -add_executable(paltest_snprintf_test11 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test11 coreclrpal) - -target_link_libraries(paltest_snprintf_test11 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test11/test11.c deleted file mode 100644 index 9d9302dee0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test11/test11.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test11.c -** -** Purpose: Tests _snprintf with unsigned numbers -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %u", pos, "foo 42"); - DoNumTest("foo %lu", 0xFFFF, "foo 65535"); - DoNumTest("foo %hu", 0xFFFF, "foo 65535"); - DoNumTest("foo %Lu", pos, "foo 42"); - DoI64Test("foo %I64u", l, "42", "foo 42"); - DoNumTest("foo %3u", pos, "foo 42"); - DoNumTest("foo %-3u", pos, "foo 42 "); - DoNumTest("foo %.1u", pos, "foo 42"); - DoNumTest("foo %.3u", pos, "foo 042"); - DoNumTest("foo %03u", pos, "foo 042"); - DoNumTest("foo %#u", pos, "foo 42"); - DoNumTest("foo %+u", pos, "foo 42"); - DoNumTest("foo % u", pos, "foo 42"); - DoNumTest("foo %+u", neg, "foo 4294967254"); - DoNumTest("foo % u", neg, "foo 4294967254"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test11/testinfo.dat deleted file mode 100644 index 1a77077950..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test11/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test11 -Description -= Tests _snprintf with unsigned numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test12/CMakeLists.txt deleted file mode 100644 index 68b442f1d9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test12/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test12.c -) - -add_executable(paltest_snprintf_test12 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test12 coreclrpal) - -target_link_libraries(paltest_snprintf_test12 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test12/test12.c deleted file mode 100644 index d782fce788..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test12/test12.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test12.c -** -** Purpose: Tests _snprintf with hex numbers (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %x", pos, "foo 1234ab"); - DoNumTest("foo %lx", pos, "foo 1234ab"); - DoNumTest("foo %hx", pos, "foo 34ab"); - DoNumTest("foo %Lx", pos, "foo 1234ab"); - DoI64Test("foo %I64x", l, "0x1234567887654321", "foo 1234567887654321"); - DoNumTest("foo %7x", pos, "foo 1234ab"); - DoNumTest("foo %-7x", pos, "foo 1234ab "); - DoNumTest("foo %.1x", pos, "foo 1234ab"); - DoNumTest("foo %.7x", pos, "foo 01234ab"); - DoNumTest("foo %07x", pos, "foo 01234ab"); - DoNumTest("foo %#x", pos, "foo 0x1234ab"); - DoNumTest("foo %+x", pos, "foo 1234ab"); - DoNumTest("foo % x", pos, "foo 1234ab"); - DoNumTest("foo %+x", neg, "foo ffffffd6"); - DoNumTest("foo % x", neg, "foo ffffffd6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test12/testinfo.dat deleted file mode 100644 index 6801c7417e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test12/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test12 -Description -= Tests _snprintf with hex numbers (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test13/CMakeLists.txt deleted file mode 100644 index 832b3fefbf..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test13/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test13.c -) - -add_executable(paltest_snprintf_test13 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test13 coreclrpal) - -target_link_libraries(paltest_snprintf_test13 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test13/test13.c deleted file mode 100644 index 68ba554d93..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test13/test13.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test13.c -** -** Purpose: Tests _snprintf with hex numbers (uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234AB; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %X", pos, "foo 1234AB"); - DoNumTest("foo %lX", pos, "foo 1234AB"); - DoNumTest("foo %hX", pos, "foo 34AB"); - DoNumTest("foo %LX", pos, "foo 1234AB"); - DoI64Test("foo %I64X", l, "0x1234567887654321", "foo 1234567887654321"); - DoNumTest("foo %7X", pos, "foo 1234AB"); - DoNumTest("foo %-7X", pos, "foo 1234AB "); - DoNumTest("foo %.1X", pos, "foo 1234AB"); - DoNumTest("foo %.7X", pos, "foo 01234AB"); - DoNumTest("foo %07X", pos, "foo 01234AB"); - DoNumTest("foo %#X", pos, "foo 0X1234AB"); - DoNumTest("foo %+X", pos, "foo 1234AB"); - DoNumTest("foo % X", pos, "foo 1234AB"); - DoNumTest("foo %+X", neg, "foo FFFFFFD6"); - DoNumTest("foo % X", neg, "foo FFFFFFD6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test13/testinfo.dat deleted file mode 100644 index 6901589a1b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test13/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test13 -Description -= Tests _snprintf with hex numbers (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test14/CMakeLists.txt deleted file mode 100644 index c2e3be148d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test14/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test14.c -) - -add_executable(paltest_snprintf_test14 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test14 coreclrpal) - -target_link_libraries(paltest_snprintf_test14 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test14/test14.c deleted file mode 100644 index d874690ba4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test14/test14.c +++ /dev/null @@ -1,57 +0,0 @@ -// 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: test14.c -** -** Purpose: Tests _snprintf with exponential format doubles (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %14e", val, "foo 2.560000e+002", - "foo 2.560000e+02"); - DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", - "foo 2.560000e+02 "); - DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); - DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", - "foo 2.56000000e+02"); - DoDoubleTest("foo %014e", val, "foo 02.560000e+002", - "foo 002.560000e+02"); - DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); - DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test14/testinfo.dat deleted file mode 100644 index 0f32b9b59a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test14/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test14 -Description -= Tests _snprintf with exponential format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test15/CMakeLists.txt deleted file mode 100644 index 1bd24d5ccd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test15/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test15.c -) - -add_executable(paltest_snprintf_test15 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test15 coreclrpal) - -target_link_libraries(paltest_snprintf_test15 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test15/test15.c deleted file mode 100644 index a637a706f5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test15/test15.c +++ /dev/null @@ -1,56 +0,0 @@ -// 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: test15.c -** -** Purpose: Tests _snprintf with exponential format doubles (uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %14E", val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", - "foo 2.560000E+02 "); - DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); - DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", - "foo 2.56000000E+02"); - DoDoubleTest("foo %014E", val, "foo 02.560000E+002", - "foo 002.560000E+02"); - DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); - DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test15/testinfo.dat deleted file mode 100644 index 8008cff0b5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test15/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test15 -Description -= Tests _snprintf with exponential format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test16/CMakeLists.txt deleted file mode 100644 index 952192e560..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test16/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test16.c -) - -add_executable(paltest_snprintf_test16 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test16 coreclrpal) - -target_link_libraries(paltest_snprintf_test16 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test16/test16.c deleted file mode 100644 index 6793019383..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test16/test16.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test16.c -** -** Purpose: Test #15 for the _snprintf function -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); - DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); - DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); - DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); - DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); - DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); - DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test16/testinfo.dat deleted file mode 100644 index e7a7df8f53..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test16/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test16 -Description -= Tests _snprintf with decimal point format doubles diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test17/CMakeLists.txt deleted file mode 100644 index ce5cc1623e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test17/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test17.c -) - -add_executable(paltest_snprintf_test17 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test17 coreclrpal) - -target_link_libraries(paltest_snprintf_test17 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test17/test17.c deleted file mode 100644 index 9981b44619..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test17/test17.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test17.c -** -** Purpose: Tests _snprintf with compact format doubles (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); - DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); - DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test17/testinfo.dat deleted file mode 100644 index 4756bd0d78..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test17/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test17 -Description -= Tests _snprintf with compact format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test18/CMakeLists.txt deleted file mode 100644 index bb9c9c37cc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test18/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test18.c -) - -add_executable(paltest_snprintf_test18 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test18 coreclrpal) - -target_link_libraries(paltest_snprintf_test18 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test18/test18.c deleted file mode 100644 index d28aec57d0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test18/test18.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test18.c -** -** Purpose: Tests _snprintf with compact format doubles (uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); - DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); - DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test18/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test18/testinfo.dat deleted file mode 100644 index 819d28cec9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test18/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test18 -Description -= Tests _snprintf with compact format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test19/CMakeLists.txt deleted file mode 100644 index f3fbb95013..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test19/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test19.c -) - -add_executable(paltest_snprintf_test19 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test19 coreclrpal) - -target_link_libraries(paltest_snprintf_test19 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test19/test19.c deleted file mode 100644 index 26dffd9214..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test19/test19.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: test19.c -** -** Purpose:Tests _snprintf with argument specified precision -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int n = -1; - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoArgumentPrecTest("%.*s", 2, "bar", "bar", "ba", "ba"); - DoArgumentPrecTest("%.*S", 2, convert("bar"), "bar", "ba", "ba"); - DoArgumentPrecTest("%.*n", 3, &n, "pointer to int", "", ""); - if (n != 0) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - 0, n); - } - - DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); - DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); - DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); - DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42") ; - DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); - - - DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); - DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); - DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); - DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); - DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); - DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); - DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); - DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); - DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); - DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test19/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test19/testinfo.dat deleted file mode 100644 index 875abf7071..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test19/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test19 -Description -= Tests _snprintf with argument specified precision diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test2/CMakeLists.txt deleted file mode 100644 index 8c617df108..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test2/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test2.c -) - -add_executable(paltest_snprintf_test2 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test2 coreclrpal) - -target_link_libraries(paltest_snprintf_test2 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test2/test2.c deleted file mode 100644 index 3ccb66c23e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test2/test2.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test2.c -** -** Purpose:Tests _snprintf with strings -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoStrTest("foo %s", "bar", "foo bar"); - DoStrTest("foo %hs", "bar", "foo bar"); - DoWStrTest("foo %ls", convert("bar"), "foo bar"); - DoWStrTest("foo %ws", convert("bar"), "foo bar"); - DoStrTest("foo %Ls", "bar", "foo bar"); - DoStrTest("foo %I64s", "bar", "foo bar"); - DoStrTest("foo %5s", "bar", "foo bar"); - DoStrTest("foo %.2s", "bar", "foo ba"); - DoStrTest("foo %5.2s", "bar", "foo ba"); - DoStrTest("foo %-5s", "bar", "foo bar "); - DoStrTest("foo %05s", "bar", "foo 00bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test2/testinfo.dat deleted file mode 100644 index 40a1ede3d5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test2/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test2 -Description -= Tests _snprintf with strings diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test3/CMakeLists.txt deleted file mode 100644 index 13330464a7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test3/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test3.c -) - -add_executable(paltest_snprintf_test3 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test3 coreclrpal) - -target_link_libraries(paltest_snprintf_test3 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test3/test3.c deleted file mode 100644 index 496159c51e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test3/test3.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests _snprintf with wide strings -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoWStrTest("foo %S", convert("bar"), "foo bar"); - DoStrTest("foo %hS", "bar", "foo bar"); - DoWStrTest("foo %lS", convert("bar"), "foo bar"); - DoWStrTest("foo %wS", convert("bar"), "foo bar"); - DoWStrTest("foo %LS", convert("bar"), "foo bar"); - DoWStrTest("foo %I64S", convert("bar"), "foo bar"); - DoWStrTest("foo %5S", convert("bar"), "foo bar"); - DoWStrTest("foo %.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %-5S", convert("bar"), "foo bar "); - DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test3/testinfo.dat deleted file mode 100644 index fa53224510..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test3/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test3 -Description -= Tests _snprintf with wide strings diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test4/CMakeLists.txt deleted file mode 100644 index 5132aa02de..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test4/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test4.c -) - -add_executable(paltest_snprintf_test4 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test4 coreclrpal) - -target_link_libraries(paltest_snprintf_test4 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test4/test4.c deleted file mode 100644 index 8c39f222cc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test4/test4.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests _snprintf with pointers -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - /* - ** Run only on 64 bit platforms - */ - #if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "0000000000000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); - #else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "00000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); - #endif //defined(BIT64) && defined(PLATFORM_UNIX) - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test4/testinfo.dat deleted file mode 100644 index 5d822d160b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test4/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test4 -Description -= Tests _snprintf with pointers diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test5/CMakeLists.txt deleted file mode 100644 index 07e441cee0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test5/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test5.c -) - -add_executable(paltest_snprintf_test5 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test5 coreclrpal) - -target_link_libraries(paltest_snprintf_test5 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test5/test5.c deleted file mode 100644 index 46ab1dd35e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test5/test5.c +++ /dev/null @@ -1,61 +0,0 @@ -// 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: test5.c -** -** Purpose: Tests _snprintf with the count specifier -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - char *longStr = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - "%n bar"; - char *longResult = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - " bar"; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoCountTest("foo %n bar", 4, "foo bar"); - DoCountTest(longStr, 257, longResult); - DoCountTest("fo%n bar", 2, "fo bar"); - DoCountTest("%n", 0, ""); - DoCountTest("foo %#n bar", 4, "foo bar"); - DoCountTest("foo % n bar", 4, "foo bar"); - DoCountTest("foo %+n bar", 4, "foo bar"); - DoCountTest("foo %-n bar", 4, "foo bar"); - DoCountTest("foo %0n bar", 4, "foo bar"); - DoShortCountTest("foo %hn bar", 4, "foo bar"); - DoCountTest("foo %ln bar", 4, "foo bar"); - DoCountTest("foo %Ln bar", 4, "foo bar"); - DoCountTest("foo %I64n bar", 4, "foo bar"); - DoCountTest("foo %20.3n bar", 4, "foo bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test5/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test5/testinfo.dat deleted file mode 100644 index 33056defd8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test5/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test5 -Description -= Tests _snprintf with the count specifier diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test6/CMakeLists.txt deleted file mode 100644 index 9ee5d90544..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test6/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test6.c -) - -add_executable(paltest_snprintf_test6 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test6 coreclrpal) - -target_link_libraries(paltest_snprintf_test6 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test6/test6.c deleted file mode 100644 index 32001c2d20..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test6/test6.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test6.c -** -** Purpose: Tests _snprintf with characters -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoCharTest("foo %c", 'b', "foo b"); - DoCharTest("foo %hc", 'b', "foo b"); - DoWCharTest("foo %lc", wc, "foo c"); - DoCharTest("foo %Lc", 'b', "foo b"); - DoCharTest("foo %I64c", 'b', "foo b"); - DoCharTest("foo %5c", 'b', "foo b"); - DoCharTest("foo %.0c", 'b', "foo b"); - DoCharTest("foo %-5c", 'b', "foo b "); - DoCharTest("foo %05c", 'b', "foo 0000b"); - DoCharTest("foo % c", 'b', "foo b"); - DoCharTest("foo %#c", 'b', "foo b"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test6/testinfo.dat deleted file mode 100644 index ba2ff818aa..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test6/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name =Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test6 -Description -= Tests _snprintf with characters diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test7/CMakeLists.txt deleted file mode 100644 index f7651218e0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test7/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test7.c -) - -add_executable(paltest_snprintf_test7 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test7 coreclrpal) - -target_link_libraries(paltest_snprintf_test7 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test7/test7.c deleted file mode 100644 index bfd5c3f4f1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test7/test7.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test7.c -** -** Purpose: Tests _snprintf with wide characters -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoWCharTest("foo %C", wb, "foo b"); - DoWCharTest("foo %hC", wb, "foo b"); - DoCharTest("foo %lC", 'c', "foo c"); - DoWCharTest("foo %LC", wb, "foo b"); - DoWCharTest("foo %I64C", wb, "foo b"); - DoWCharTest("foo %5C", wb, "foo b"); - DoWCharTest("foo %.0C", wb, "foo b"); - DoWCharTest("foo %-5C", wb, "foo b "); - DoWCharTest("foo %05C", wb, "foo 0000b"); - DoWCharTest("foo % C", wb, "foo b"); - DoWCharTest("foo %#C", wb, "foo b"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test7/testinfo.dat deleted file mode 100644 index 5c2406c7b2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test7/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test7 -Description -= Tests _snprintf with wide characters diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test8/CMakeLists.txt deleted file mode 100644 index 26af119852..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test8/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test8.c -) - -add_executable(paltest_snprintf_test8 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test8 coreclrpal) - -target_link_libraries(paltest_snprintf_test8 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test8/test8.c deleted file mode 100644 index 60ff1b05b8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test8/test8.c +++ /dev/null @@ -1,56 +0,0 @@ -// 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: test8.c -** -** Purpose: Tests _snprintf with decimal numbers -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %d", pos, "foo 42"); - DoNumTest("foo %ld", 0xFFFF, "foo 65535"); - DoNumTest("foo %hd", 0xFFFF, "foo -1"); - DoNumTest("foo %Ld", pos, "foo 42"); - DoI64Test("foo %I64d", l, "42", "foo 42"); - DoNumTest("foo %3d", pos, "foo 42"); - DoNumTest("foo %-3d", pos, "foo 42 "); - DoNumTest("foo %.1d", pos, "foo 42"); - DoNumTest("foo %.3d", pos, "foo 042"); - DoNumTest("foo %03d", pos, "foo 042"); - DoNumTest("foo %#d", pos, "foo 42"); - DoNumTest("foo %+d", pos, "foo +42"); - DoNumTest("foo % d", pos, "foo 42"); - DoNumTest("foo %+d", neg, "foo -42"); - DoNumTest("foo % d", neg, "foo -42"); - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test8/testinfo.dat deleted file mode 100644 index f6520d8dde..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test8/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test8 -Description -= Tests _snprintf with decimal numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf/test9/CMakeLists.txt deleted file mode 100644 index 484075919e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test9/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test9.c -) - -add_executable(paltest_snprintf_test9 - ${SOURCES} -) - -add_dependencies(paltest_snprintf_test9 coreclrpal) - -target_link_libraries(paltest_snprintf_test9 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/_snprintf/test9/test9.c deleted file mode 100644 index e836bcaee3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test9/test9.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test9.c -** -** Purpose: Tests _snprintf with integer numbers -** -** -**==========================================================================*/ - - - -#include -#include "../_snprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %i", pos, "foo 42"); - DoNumTest("foo %li", 0xFFFF, "foo 65535"); - DoNumTest("foo %hi", 0xFFFF, "foo -1"); - DoNumTest("foo %Li", pos, "foo 42"); - DoI64Test("foo %I64i", l, "42", "foo 42"); - DoNumTest("foo %3i", pos, "foo 42"); - DoNumTest("foo %-3i", pos, "foo 42 "); - DoNumTest("foo %.1i", pos, "foo 42"); - DoNumTest("foo %.3i", pos, "foo 042"); - DoNumTest("foo %03i", pos, "foo 042"); - DoNumTest("foo %#i", pos, "foo 42"); - DoNumTest("foo %+i", pos, "foo +42"); - DoNumTest("foo % i", pos, "foo 42"); - DoNumTest("foo %+i", neg, "foo -42"); - DoNumTest("foo % i", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf/test9/testinfo.dat deleted file mode 100644 index 2a64b26030..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snprintf/test9/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snprintf -Name = Positive Test for _snprintf -TYPE = DEFAULT -EXE1 = test9 -Description -= Tests _snprintf with integer numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/CMakeLists.txt new file mode 100644 index 0000000000..8fe1cb60ac --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test10) +add_subdirectory(test11) +add_subdirectory(test12) +add_subdirectory(test13) +add_subdirectory(test14) +add_subdirectory(test15) +add_subdirectory(test16) +add_subdirectory(test17) +add_subdirectory(test18) +add_subdirectory(test19) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) +add_subdirectory(test6) +add_subdirectory(test7) +add_subdirectory(test8) +add_subdirectory(test9) + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/_snprintf_s.h b/src/pal/tests/palsuite/c_runtime/_snprintf_s/_snprintf_s.h new file mode 100644 index 0000000000..9ed5209bea --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/_snprintf_s.h @@ -0,0 +1,194 @@ +// 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: sprintf_s.h +** +** Purpose: Containts common testing functions for sprintf_s +** +** +**==========================================================================*/ + +#ifndef __STRINGTEST_H__ +#define __STRINGTEST_H__ + +void DoStrTest(const char *formatstr, char* param, const char *checkstr) +{ + char buf[256] = { 0 }; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert string \"%s\" into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + param, formatstr, checkstr, buf); + } +} + +void DoWStrTest(const char *formatstr, WCHAR* param, const char *checkstr) +{ + char buf[256] = { 0 }; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + convertC(param), formatstr, checkstr, buf); + } +} + + +void DoPointerTest(const char *formatstr, void* param, char* paramstr, char + *checkstr1) +{ + char buf[256] = { 0 }; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", + paramstr, formatstr, checkstr1, buf); + } +} + +void DoCountTest(const char *formatstr, int param, const char *checkstr) +{ + char buf[512] = { 0 }; + int n = -1; + + sprintf_s(buf, 512, formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + param, n); + } + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); + } +} + +void DoShortCountTest(const char *formatstr, int param, const char *checkstr) +{ + char buf[256] = { 0 }; + short int n = -1; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + param, n); + } + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); + } +} + +void DoCharTest(const char *formatstr, char param, const char *checkstr) +{ + char buf[256] = { 0 }; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + param, param, formatstr, checkstr, buf); + } +} + +void DoWCharTest(const char *formatstr, WCHAR param, const char *checkstr) +{ + char buf[256] = { 0 }; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + (char)param, param, formatstr, checkstr, buf); + } +} + +void DoNumTest(const char *formatstr, int value, const char *checkstr) +{ + char buf[256] = { 0 }; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, value); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert %#x into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + value, formatstr, checkstr, buf); + } +} + +void DoI64Test(const char *formatstr, INT64 value, char *valuestr, const char *checkstr1) +{ + char buf[256] = { 0 }; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, value); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", + valuestr, formatstr, checkstr1, buf); + } +} + +void DoDoubleTest(const char *formatstr, double value, const char *checkstr1, char +*checkstr2) +{ + char buf[256] = { 0 }; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, value); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 + && memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\"\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + value, formatstr, checkstr1, checkstr2, buf); + } +} + +void DoArgumentPrecTest(const char *formatstr, int precision, void *param, char +*paramstr, const char *checkstr1, const char *checkstr2) +{ + char buf[256]; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, precision, param); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && + memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + paramstr, formatstr, precision, checkstr1, checkstr2, buf); + } + +} + +void DoArgumentPrecDoubleTest(const char *formatstr, int precision, double param, +const char *checkstr1, const char *checkstr2) +{ + char buf[256]; + + _snprintf_s(buf, 256, _TRUNCATE, formatstr, precision, param); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && + memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + param, formatstr, precision, checkstr1, checkstr2, buf); + } + +} + +#endif + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/CMakeLists.txt new file mode 100644 index 0000000000..9e4c671ec8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_snprintf_test1 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test1 coreclrpal) + +target_link_libraries(paltest_snprintf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/test1.cpp new file mode 100644 index 0000000000..d180b05df5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/test1.cpp @@ -0,0 +1,58 @@ +// 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: test1.c +** +** Purpose: General test to see if sprintf_s works correctly +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + char checkstr[] = "hello world"; + char buf[256] = { 0 }; + int ret; + + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + _snprintf_s(buf, 256, _TRUNCATE, "hello world"); + if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) + { + Fail("ERROR: expected \"%s\" (up to %d chars), got \"%s\"\n", + checkstr, 256, buf); + } + + _snprintf_s(buf, 256, _TRUNCATE, "xxxxxxxxxxxxxxxxx"); + ret = _snprintf_s(buf, 8, _TRUNCATE, "hello world"); + + if (ret >= 0) + { + Fail("ERROR: expected negative return value, got %d", ret); + } + if (memcmp(checkstr, buf, 7) != 0 || buf[7] != 0 || buf[8] != 'x') + { + Fail("ERROR: expected %s (up to %d chars), got %s\n", + checkstr, 8, buf); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/testinfo.dat new file mode 100644 index 0000000000..255c534cdf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test1/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test1 +Description += General test to see if sprintf_s works correctly diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/CMakeLists.txt new file mode 100644 index 0000000000..57e7fb16d3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test10.cpp +) + +add_executable(paltest_snprintf_test10 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test10 coreclrpal) + +target_link_libraries(paltest_snprintf_test10 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/test10.cpp new file mode 100644 index 0000000000..7ecb9102e4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/test10.cpp @@ -0,0 +1,55 @@ +// 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: test10.c +** +** Purpose: Tests sprintf_s with octal numbers +** +** +**==========================================================================*/ + + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %o", pos, "foo 52"); + DoNumTest("foo %lo", 0xFFFF, "foo 177777"); + DoNumTest("foo %ho", 0xFFFF, "foo 177777"); + DoNumTest("foo %Lo", pos, "foo 52"); + DoI64Test("foo %I64o", l, "42", "foo 52"); + DoNumTest("foo %3o", pos, "foo 52"); + DoNumTest("foo %-3o", pos, "foo 52 "); + DoNumTest("foo %.1o", pos, "foo 52"); + DoNumTest("foo %.3o", pos, "foo 052"); + DoNumTest("foo %03o", pos, "foo 052"); + DoNumTest("foo %#o", pos, "foo 052"); + DoNumTest("foo %+o", pos, "foo 52"); + DoNumTest("foo % o", pos, "foo 52"); + DoNumTest("foo %+o", neg, "foo 37777777726"); + DoNumTest("foo % o", neg, "foo 37777777726"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/testinfo.dat new file mode 100644 index 0000000000..25ed554ea3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test10/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test10 +Description += Tests sprintf_s with octal numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/CMakeLists.txt new file mode 100644 index 0000000000..4fc179c5a8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test11.cpp +) + +add_executable(paltest_snprintf_test11 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test11 coreclrpal) + +target_link_libraries(paltest_snprintf_test11 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/test11.cpp new file mode 100644 index 0000000000..c2ac015698 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/test11.cpp @@ -0,0 +1,54 @@ +// 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: test11.c +** +** Purpose: Tests sprintf_s with unsigned numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %u", pos, "foo 42"); + DoNumTest("foo %lu", 0xFFFF, "foo 65535"); + DoNumTest("foo %hu", 0xFFFF, "foo 65535"); + DoNumTest("foo %Lu", pos, "foo 42"); + DoI64Test("foo %I64u", l, "42", "foo 42"); + DoNumTest("foo %3u", pos, "foo 42"); + DoNumTest("foo %-3u", pos, "foo 42 "); + DoNumTest("foo %.1u", pos, "foo 42"); + DoNumTest("foo %.3u", pos, "foo 042"); + DoNumTest("foo %03u", pos, "foo 042"); + DoNumTest("foo %#u", pos, "foo 42"); + DoNumTest("foo %+u", pos, "foo 42"); + DoNumTest("foo % u", pos, "foo 42"); + DoNumTest("foo %+u", neg, "foo 4294967254"); + DoNumTest("foo % u", neg, "foo 4294967254"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/testinfo.dat new file mode 100644 index 0000000000..3144f1290e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test11/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test11 +Description += Tests sprintf_s with unsigned numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/CMakeLists.txt new file mode 100644 index 0000000000..a35609eb57 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test12.cpp +) + +add_executable(paltest_snprintf_test12 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test12 coreclrpal) + +target_link_libraries(paltest_snprintf_test12 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/test12.cpp new file mode 100644 index 0000000000..52171838cc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/test12.cpp @@ -0,0 +1,55 @@ +// 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: test12.c +** +** Purpose: Tests sprintf_s with hex numbers (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %x", pos, "foo 1234ab"); + DoNumTest("foo %lx", pos, "foo 1234ab"); + DoNumTest("foo %hx", pos, "foo 34ab"); + DoNumTest("foo %Lx", pos, "foo 1234ab"); + DoI64Test("foo %I64x", l, "0x1234567887654321", "foo 1234567887654321"); + DoNumTest("foo %7x", pos, "foo 1234ab"); + DoNumTest("foo %-7x", pos, "foo 1234ab "); + DoNumTest("foo %.1x", pos, "foo 1234ab"); + DoNumTest("foo %.7x", pos, "foo 01234ab"); + DoNumTest("foo %07x", pos, "foo 01234ab"); + DoNumTest("foo %#x", pos, "foo 0x1234ab"); + DoNumTest("foo %+x", pos, "foo 1234ab"); + DoNumTest("foo % x", pos, "foo 1234ab"); + DoNumTest("foo %+x", neg, "foo ffffffd6"); + DoNumTest("foo % x", neg, "foo ffffffd6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/testinfo.dat new file mode 100644 index 0000000000..ed91cecc46 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test12/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test12 +Description += Tests sprintf_s with hex numbers (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/CMakeLists.txt new file mode 100644 index 0000000000..3bf986e851 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test13.cpp +) + +add_executable(paltest_snprintf_test13 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test13 coreclrpal) + +target_link_libraries(paltest_snprintf_test13 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/test13.cpp new file mode 100644 index 0000000000..15e47558b0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/test13.cpp @@ -0,0 +1,55 @@ +// 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: test13.c +** +** Purpose: Tests sprintf_s with hex numbers (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234AB; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %X", pos, "foo 1234AB"); + DoNumTest("foo %lX", pos, "foo 1234AB"); + DoNumTest("foo %hX", pos, "foo 34AB"); + DoNumTest("foo %LX", pos, "foo 1234AB"); + DoI64Test("foo %I64X", l, "0x1234567887654321", "foo 1234567887654321"); + DoNumTest("foo %7X", pos, "foo 1234AB"); + DoNumTest("foo %-7X", pos, "foo 1234AB "); + DoNumTest("foo %.1X", pos, "foo 1234AB"); + DoNumTest("foo %.7X", pos, "foo 01234AB"); + DoNumTest("foo %07X", pos, "foo 01234AB"); + DoNumTest("foo %#X", pos, "foo 0X1234AB"); + DoNumTest("foo %+X", pos, "foo 1234AB"); + DoNumTest("foo % X", pos, "foo 1234AB"); + DoNumTest("foo %+X", neg, "foo FFFFFFD6"); + DoNumTest("foo % X", neg, "foo FFFFFFD6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/testinfo.dat new file mode 100644 index 0000000000..fd5f53017c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test13/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test13 +Description += Tests sprintf_s with hex numbers (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/CMakeLists.txt new file mode 100644 index 0000000000..985303ecf8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test14.cpp +) + +add_executable(paltest_snprintf_test14 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test14 coreclrpal) + +target_link_libraries(paltest_snprintf_test14 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/test14.cpp new file mode 100644 index 0000000000..331475e962 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/test14.cpp @@ -0,0 +1,57 @@ +// 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: test14.c +** +** Purpose: Tests sprintf_s with exponential format doubles (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %14e", val, "foo 2.560000e+002", + "foo 2.560000e+02"); + DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", + "foo 2.560000e+02 "); + DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); + DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", + "foo 2.56000000e+02"); + DoDoubleTest("foo %014e", val, "foo 02.560000e+002", + "foo 002.560000e+02"); + DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); + DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/testinfo.dat new file mode 100644 index 0000000000..23cf423354 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test14/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test14 +Description += Tests sprintf_s with exponential format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/CMakeLists.txt new file mode 100644 index 0000000000..c7f5796089 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test15.cpp +) + +add_executable(paltest_snprintf_test15 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test15 coreclrpal) + +target_link_libraries(paltest_snprintf_test15 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/test15.cpp new file mode 100644 index 0000000000..d43613b6cf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/test15.cpp @@ -0,0 +1,56 @@ +// 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: test15.c +** +** Purpose: Tests sprintf_s with exponential format doubles (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %14E", val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", + "foo 2.560000E+02 "); + DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); + DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", + "foo 2.56000000E+02"); + DoDoubleTest("foo %014E", val, "foo 02.560000E+002", + "foo 002.560000E+02"); + DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); + DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/testinfo.dat new file mode 100644 index 0000000000..537e6d1db2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test15/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test15 +Description += Tests sprintf_s with exponential format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/CMakeLists.txt new file mode 100644 index 0000000000..9a224bc23b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test16.cpp +) + +add_executable(paltest_snprintf_test16 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test16 coreclrpal) + +target_link_libraries(paltest_snprintf_test16 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/test16.cpp new file mode 100644 index 0000000000..21cbb1ed30 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/test16.cpp @@ -0,0 +1,52 @@ +// 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: test16.c +** +** Purpose: Test #15 for the sprintf_s function +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); + DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); + DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); + DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); + DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); + DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); + DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/testinfo.dat new file mode 100644 index 0000000000..4e98eccac2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test16/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test16 +Description += Tests sprintf_s with decimal point format doubles diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/CMakeLists.txt new file mode 100644 index 0000000000..3a8a349c84 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test17.cpp +) + +add_executable(paltest_snprintf_test17 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test17 coreclrpal) + +target_link_libraries(paltest_snprintf_test17 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/test17.cpp new file mode 100644 index 0000000000..d161270b84 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/test17.cpp @@ -0,0 +1,53 @@ +// 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: test17.c +** +** Purpose: Tests sprintf_s with compact format doubles (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); + DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); + DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/testinfo.dat new file mode 100644 index 0000000000..5e41e20d44 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test17/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test17 +Description += Tests sprintf_s with compact format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/CMakeLists.txt new file mode 100644 index 0000000000..96e39e8f41 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test18.cpp +) + +add_executable(paltest_snprintf_test18 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test18 coreclrpal) + +target_link_libraries(paltest_snprintf_test18 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/test18.cpp new file mode 100644 index 0000000000..46ec287cc1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/test18.cpp @@ -0,0 +1,53 @@ +// 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: test18.c +** +** Purpose: Tests sprintf_s with compact format doubles (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); + DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); + DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/testinfo.dat new file mode 100644 index 0000000000..06ae3a632e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test18/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test18 +Description += Tests sprintf_s with compact format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/CMakeLists.txt new file mode 100644 index 0000000000..be3570f163 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test19.cpp +) + +add_executable(paltest_snprintf_test19 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test19 coreclrpal) + +target_link_libraries(paltest_snprintf_test19 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/test19.cpp new file mode 100644 index 0000000000..91b1dae583 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/test19.cpp @@ -0,0 +1,70 @@ +// 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: test19.c +** +** Purpose:Tests sprintf_s with argument specified precision +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int n = -1; + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoArgumentPrecTest("%.*s", 2, (void*)"bar", "bar", "ba", "ba"); + DoArgumentPrecTest("%.*S", 2, (void*)convert("bar"), "bar", "ba", "ba"); + + DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); + DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); + DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); + DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42") ; + DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); + + + DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); + DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); + DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); + DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); + DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); + DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); + DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); + DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); + DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); + DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/testinfo.dat new file mode 100644 index 0000000000..7064c01771 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test19/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test19 +Description += Tests sprintf_s with argument specified precision diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/CMakeLists.txt new file mode 100644 index 0000000000..11d18e61c3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.cpp +) + +add_executable(paltest_snprintf_test2 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test2 coreclrpal) + +target_link_libraries(paltest_snprintf_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/test2.cpp new file mode 100644 index 0000000000..e58669466f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/test2.cpp @@ -0,0 +1,44 @@ +// 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: test2.c +** +** Purpose:Tests sprintf_s with strings +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoStrTest("foo %s", "bar", "foo bar"); + DoStrTest("foo %hs", "bar", "foo bar"); + DoWStrTest("foo %ls", convert("bar"), "foo bar"); + DoWStrTest("foo %ws", convert("bar"), "foo bar"); + DoStrTest("foo %Ls", "bar", "foo bar"); + DoStrTest("foo %I64s", "bar", "foo bar"); + DoStrTest("foo %5s", "bar", "foo bar"); + DoStrTest("foo %.2s", "bar", "foo ba"); + DoStrTest("foo %5.2s", "bar", "foo ba"); + DoStrTest("foo %-5s", "bar", "foo bar "); + DoStrTest("foo %05s", "bar", "foo 00bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/testinfo.dat new file mode 100644 index 0000000000..cce2dc67e7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test2/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test2 +Description += Tests sprintf_s with strings diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/CMakeLists.txt new file mode 100644 index 0000000000..b8d4178962 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.cpp +) + +add_executable(paltest_snprintf_test3 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test3 coreclrpal) + +target_link_libraries(paltest_snprintf_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/test3.cpp new file mode 100644 index 0000000000..3c52b44246 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/test3.cpp @@ -0,0 +1,45 @@ +// 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: test3.c +** +** Purpose: Tests sprintf_s with wide strings +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoWStrTest("foo %S", convert("bar"), "foo bar"); + DoStrTest("foo %hS", "bar", "foo bar"); + DoWStrTest("foo %lS", convert("bar"), "foo bar"); + DoWStrTest("foo %wS", convert("bar"), "foo bar"); + DoWStrTest("foo %LS", convert("bar"), "foo bar"); + DoWStrTest("foo %I64S", convert("bar"), "foo bar"); + DoWStrTest("foo %5S", convert("bar"), "foo bar"); + DoWStrTest("foo %.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %-5S", convert("bar"), "foo bar "); + DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/testinfo.dat new file mode 100644 index 0000000000..cc8de0eae5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test3/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test3 +Description += Tests sprintf_s with wide strings diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/CMakeLists.txt new file mode 100644 index 0000000000..568b7122de --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test4.cpp +) + +add_executable(paltest_snprintf_test4 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test4 coreclrpal) + +target_link_libraries(paltest_snprintf_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/test4.cpp new file mode 100644 index 0000000000..216557f10a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/test4.cpp @@ -0,0 +1,69 @@ +// 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: test4.c +** +** Purpose: Tests sprintf_s with pointers +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + /* + ** Run only on 64 bit platforms + */ + #if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "0000000000000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); + #else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "00000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); + #endif //defined(BIT64) && defined(PLATFORM_UNIX) + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/testinfo.dat new file mode 100644 index 0000000000..f53f784991 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test4/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test4 +Description += Tests sprintf_s with pointers diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/CMakeLists.txt new file mode 100644 index 0000000000..820cc66d55 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test6.cpp +) + +add_executable(paltest_snprintf_test6 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test6 coreclrpal) + +target_link_libraries(paltest_snprintf_test6 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/test6.cpp new file mode 100644 index 0000000000..45c9e2b79b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/test6.cpp @@ -0,0 +1,47 @@ +// 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: test6.c +** +** Purpose: Tests sprintf_s with characters +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoCharTest("foo %c", 'b', "foo b"); + DoCharTest("foo %hc", 'b', "foo b"); + DoWCharTest("foo %lc", wc, "foo c"); + DoCharTest("foo %Lc", 'b', "foo b"); + DoCharTest("foo %I64c", 'b', "foo b"); + DoCharTest("foo %5c", 'b', "foo b"); + DoCharTest("foo %.0c", 'b', "foo b"); + DoCharTest("foo %-5c", 'b', "foo b "); + DoCharTest("foo %05c", 'b', "foo 0000b"); + DoCharTest("foo % c", 'b', "foo b"); + DoCharTest("foo %#c", 'b', "foo b"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/testinfo.dat new file mode 100644 index 0000000000..06e31e85d6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test6/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 = C Runtime +Function = sprintf_s +Name =Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test6 +Description += Tests sprintf_s with characters diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/CMakeLists.txt new file mode 100644 index 0000000000..a2af7c4a8c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test7.cpp +) + +add_executable(paltest_snprintf_test7 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test7 coreclrpal) + +target_link_libraries(paltest_snprintf_test7 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/test7.cpp new file mode 100644 index 0000000000..5c10fc8ea7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/test7.cpp @@ -0,0 +1,47 @@ +// 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: test7.c +** +** Purpose: Tests sprintf_s with wide characters +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoWCharTest("foo %C", wb, "foo b"); + DoWCharTest("foo %hC", wb, "foo b"); + DoCharTest("foo %lC", 'c', "foo c"); + DoWCharTest("foo %LC", wb, "foo b"); + DoWCharTest("foo %I64C", wb, "foo b"); + DoWCharTest("foo %5C", wb, "foo b"); + DoWCharTest("foo %.0C", wb, "foo b"); + DoWCharTest("foo %-5C", wb, "foo b "); + DoWCharTest("foo %05C", wb, "foo 0000b"); + DoWCharTest("foo % C", wb, "foo b"); + DoWCharTest("foo %#C", wb, "foo b"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/testinfo.dat new file mode 100644 index 0000000000..647c9d80fd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test7/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test7 +Description += Tests sprintf_s with wide characters diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/CMakeLists.txt new file mode 100644 index 0000000000..53545c5dbf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test8.cpp +) + +add_executable(paltest_snprintf_test8 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test8 coreclrpal) + +target_link_libraries(paltest_snprintf_test8 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/test8.cpp new file mode 100644 index 0000000000..416e357e1e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/test8.cpp @@ -0,0 +1,56 @@ +// 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: test8.c +** +** Purpose: Tests sprintf_s with decimal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %d", pos, "foo 42"); + DoNumTest("foo %ld", 0xFFFF, "foo 65535"); + DoNumTest("foo %hd", 0xFFFF, "foo -1"); + DoNumTest("foo %Ld", pos, "foo 42"); + DoI64Test("foo %I64d", l, "42", "foo 42"); + DoNumTest("foo %3d", pos, "foo 42"); + DoNumTest("foo %-3d", pos, "foo 42 "); + DoNumTest("foo %.1d", pos, "foo 42"); + DoNumTest("foo %.3d", pos, "foo 042"); + DoNumTest("foo %03d", pos, "foo 042"); + DoNumTest("foo %#d", pos, "foo 42"); + DoNumTest("foo %+d", pos, "foo +42"); + DoNumTest("foo % d", pos, "foo 42"); + DoNumTest("foo %+d", neg, "foo -42"); + DoNumTest("foo % d", neg, "foo -42"); + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/testinfo.dat new file mode 100644 index 0000000000..524834e53e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test8/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test8 +Description += Tests sprintf_s with decimal numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/CMakeLists.txt new file mode 100644 index 0000000000..33ca9db7a8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test9.cpp +) + +add_executable(paltest_snprintf_test9 + ${SOURCES} +) + +add_dependencies(paltest_snprintf_test9 coreclrpal) + +target_link_libraries(paltest_snprintf_test9 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/test9.cpp new file mode 100644 index 0000000000..18b1cb7830 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/test9.cpp @@ -0,0 +1,55 @@ +// 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: test9.c +** +** Purpose: Tests sprintf_s with integer numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snprintf_s.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %i", pos, "foo 42"); + DoNumTest("foo %li", 0xFFFF, "foo 65535"); + DoNumTest("foo %hi", 0xFFFF, "foo -1"); + DoNumTest("foo %Li", pos, "foo 42"); + DoI64Test("foo %I64i", l, "42", "foo 42"); + DoNumTest("foo %3i", pos, "foo 42"); + DoNumTest("foo %-3i", pos, "foo 42 "); + DoNumTest("foo %.1i", pos, "foo 42"); + DoNumTest("foo %.3i", pos, "foo 042"); + DoNumTest("foo %03i", pos, "foo 042"); + DoNumTest("foo %#i", pos, "foo 42"); + DoNumTest("foo %+i", pos, "foo +42"); + DoNumTest("foo % i", pos, "foo 42"); + DoNumTest("foo %+i", neg, "foo -42"); + DoNumTest("foo % i", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/testinfo.dat new file mode 100644 index 0000000000..7c51443a3d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snprintf_s/test9/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test9 +Description += Tests sprintf_s with integer numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/CMakeLists.txt deleted file mode 100644 index cafb9536b0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) -add_subdirectory(test10) -add_subdirectory(test11) -add_subdirectory(test12) -add_subdirectory(test13) -add_subdirectory(test14) -add_subdirectory(test15) -add_subdirectory(test16) -add_subdirectory(test17) -add_subdirectory(test18) -add_subdirectory(test19) -add_subdirectory(test2) -add_subdirectory(test3) -add_subdirectory(test4) -add_subdirectory(test5) -add_subdirectory(test6) -add_subdirectory(test7) -add_subdirectory(test8) -add_subdirectory(test9) - diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/_snwprintf.h b/src/pal/tests/palsuite/c_runtime/_snwprintf/_snwprintf.h deleted file mode 100644 index 73bf4d6c12..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/_snwprintf.h +++ /dev/null @@ -1,199 +0,0 @@ -// 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: _snwprintf.h -** -** Purpose: Containts common testing functions for _snwprintf -** -** -**==========================================================================*/ - -#ifndef ___SNWPRINTF_H__ -#define ___SNWPRINTF_H__ - -void DoWStrTest(WCHAR *formatstr, WCHAR *param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - - _snwprintf(buf, 256, formatstr, param); - - if (memcmp(buf, checkstr, wcslen(checkstr) * 2 + 2) != 0) - { - Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" - "Expected \"%s\", got \"%s\".\n", convertC(param), - convertC(formatstr), convertC(checkstr), convertC(buf)); - } -} - -void DoStrTest(WCHAR *formatstr, char *param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - - _snwprintf(buf, 256, formatstr, param); - - if (memcmp(buf, checkstr, wcslen(checkstr) * 2 + 2) != 0) - { - Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" - "Expected \"%s\", got \"%s\".\n", - param, convertC(formatstr), convertC(checkstr), convertC(buf)); - } -} - -void DoPointerTest(WCHAR *formatstr, void* param, WCHAR *checkstr1) -{ - WCHAR buf[256] = { 0 }; - - _snwprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0) - { - Fail("ERROR: failed to insert pointer to %#p into \"%s\"\n" - "Expected \"%s\", got \"%s\".\n", param, convertC(formatstr), - convertC(checkstr1), convertC(buf)); - } -} - -void DoCountTest(WCHAR *formatstr, int param, WCHAR *checkstr) -{ - WCHAR buf[512] = { 0 }; - int n = -1; - - _snwprintf(buf, 512, formatstr, &n); - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %d\n", - param, n); - } - - if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", - convertC(checkstr), convertC(buf)); - } -} - -void DoShortCountTest(WCHAR *formatstr, int param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - short int n = -1; - - _snwprintf(buf, 256, formatstr, &n); - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %d\n", - param, n); - } - - if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", - convertC(checkstr), convertC(buf)); - } -} - -void DoCharTest(WCHAR *formatstr, char param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - - _snwprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) - { - Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", param, param, - convertC(formatstr), convertC(checkstr), convertC(buf)); - } -} - -void DoWCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - - _snwprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) - { - Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", (char) param, param, - convertC(formatstr), convertC(checkstr), convertC(buf)); - } -} - -void DoNumTest(WCHAR *formatstr, int value, WCHAR*checkstr) -{ - WCHAR buf[256] = { 0 }; - - _snwprintf(buf, 256, formatstr, value); - if (memcmp(buf, checkstr, wcslen(checkstr)* 2 + 2) != 0) - { - Fail("ERROR: failed to insert %#x into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", value, convertC(formatstr), - convertC(checkstr), convertC(buf)); - } -} - - -void DoI64Test(WCHAR *formatstr, INT64 param, char *paramdesc, - WCHAR *checkstr1) -{ - WCHAR buf[256] = { 0 }; - - _snwprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\"\n" - "Expected \"%s\", got \"%s\".\n", paramdesc, - convertC(formatstr), convertC(checkstr1), convertC(buf)); - } -} - -void DoDoubleTest(WCHAR *formatstr, double value, WCHAR *checkstr1, - WCHAR *checkstr2) -{ - WCHAR buf[256] = { 0 }; - - _snwprintf(buf, 256, formatstr, value); - if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0 && - memcmp(buf, checkstr2, wcslen(checkstr2)*2 + 2) != 0) - { - Fail("ERROR: failed to insert %f into \"%s\"\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - value, convertC(formatstr), convertC(checkstr1), - convertC(checkstr2), convertC(buf)); - } -} - -void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, - char *paramstr, WCHAR *checkstr1, WCHAR *checkstr2) -{ - WCHAR buf[256]; - - _snwprintf(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 %s into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - paramstr, convertC(formatstr), precision, - convertC(checkstr1), convertC(checkstr2) ,convertC(buf)); - } -} - -void DoArgumentPrecDoubleTest(WCHAR *formatstr, int precision, double param, - WCHAR *checkstr) -{ - WCHAR buf[256]; - - _snwprintf(buf, 256, formatstr, precision, param); - if (memcmp(buf, checkstr, wcslen(checkstr) + 2) != 0) - { - Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" - "Expected \"%s\", got \"%s\".\n", param, convertC(formatstr), - precision, convertC(checkstr), convertC(buf)); - } -} - -#endif - diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test1/CMakeLists.txt deleted file mode 100644 index b4ab6d5161..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_snwprintf_test1 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test1 coreclrpal) - -target_link_libraries(paltest_snwprintf_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test1/test1.c deleted file mode 100644 index 5d13aaf05d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test1/test1.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: test1.c -** -** Purpose: General test to see if _snwprintf works correctly -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -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"); - _snwprintf(buf, 256, checkstr); - if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0) - { - Fail("ERROR: Expected \"%s\", got \"%s\"\n", - convertC(checkstr), convertC(buf)); - } - - _snwprintf(buf, 256, convert("xxxxxxxxxxxxxxxxx")); - ret = _snwprintf(buf, 8, checkstr); - if (memcmp(checkstr, buf, 16) != 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; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test1/testinfo.dat deleted file mode 100644 index 079a3b3989..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test1/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test1 -Description -= General test to see if _snwprintf works correctly diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test10/CMakeLists.txt deleted file mode 100644 index 27aaca3bb9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test10/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test10.c -) - -add_executable(paltest_snwprintf_test10 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test10 coreclrpal) - -target_link_libraries(paltest_snwprintf_test10 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test10/test10.c deleted file mode 100644 index e8a6d93ea3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test10/test10.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test10.c -** -** Purpose: Tests _snwprintf with octal numbers -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %o"), pos, convert("foo 52")); - DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); - DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); - DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); - DoI64Test(convert("foo %I64o"), l, "42", convert("foo 52")); - DoNumTest(convert("foo %3o"), pos, convert("foo 52")); - DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); - DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); - DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); - DoNumTest(convert("foo %03o"), pos, convert("foo 052")); - DoNumTest(convert("foo %#o"), pos, convert("foo 052")); - DoNumTest(convert("foo %+o"), pos, convert("foo 52")); - DoNumTest(convert("foo % o"), pos, convert("foo 52")); - DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); - DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test10/testinfo.dat deleted file mode 100644 index 2c07cc6e45..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test10/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test10 -Description -= Tests _snwprintf with octal numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test11/CMakeLists.txt deleted file mode 100644 index e18ad4a31b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test11/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test11.c -) - -add_executable(paltest_snwprintf_test11 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test11 coreclrpal) - -target_link_libraries(paltest_snwprintf_test11 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test11/test11.c deleted file mode 100644 index 95f7f53210..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test11/test11.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test11.c -** -** Purpose: Tests _snwprintf with unsigned numbers -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %u"), pos, convert("foo 42")); - DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); - DoI64Test(convert("foo %I64u"), l, "42", convert("foo 42")); - DoNumTest(convert("foo %3u"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); - DoNumTest(convert("foo %03u"), pos, convert("foo 042")); - DoNumTest(convert("foo %#u"), pos, convert("foo 42")); - DoNumTest(convert("foo %+u"), pos, convert("foo 42")); - DoNumTest(convert("foo % u"), pos, convert("foo 42")); - DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); - DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test11/testinfo.dat deleted file mode 100644 index f81a7861bf..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test11/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test11 -Description -= Tests _snwprintf with unsigned numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test12/CMakeLists.txt deleted file mode 100644 index f2ae07c1b0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test12/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test12.c -) - -add_executable(paltest_snwprintf_test12 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test12 coreclrpal) - -target_link_libraries(paltest_snwprintf_test12 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test12/test12.c deleted file mode 100644 index ab58fa345f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test12/test12.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test12.c -** -** Purpose: Tests _snwprintf with hex numbers (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); - DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); - DoI64Test(convert("foo %I64x"), l, "0x1234567887654321", - convert("foo 1234567887654321")); - DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); - DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); - DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); - DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); - DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); - DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test12/testinfo.dat deleted file mode 100644 index 653babae84..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test12/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test12 -Description -= Tests _snwprintf with hex numbers (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test13/CMakeLists.txt deleted file mode 100644 index 42847b6bcd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test13/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test13.c -) - -add_executable(paltest_snwprintf_test13 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test13 coreclrpal) - -target_link_libraries(paltest_snwprintf_test13 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test13/test13.c deleted file mode 100644 index 5a3e22802d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test13/test13.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test13.c -** -** Purpose: Tests _snwprintf with hex numbers (uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); - DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); - DoI64Test(convert("foo %I64X"), l, "0x1234567887654321", - convert("foo 1234567887654321")); - DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); - DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); - DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); - DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); - DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); - DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test13/testinfo.dat deleted file mode 100644 index cdeced6654..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test13/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test13 -Description -= Tests _snwprintf with hex numbers (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test14/CMakeLists.txt deleted file mode 100644 index e5cdbfad87..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test14/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test14.c -) - -add_executable(paltest_snwprintf_test14 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test14 coreclrpal) - -target_link_libraries(paltest_snwprintf_test14 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test14/test14.c deleted file mode 100644 index c34875246d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test14/test14.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: test14.c -** -** Purpose: Tests _snwprintf with exponential format doubles (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), - convert("foo 2.560000e+02 ")); - DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), - convert("foo 2.6e+02")); - DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), - convert("foo 2.56000000e+02")); - DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), - convert("foo 002.560000e+02")); - DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), - convert("foo +2.560000e+02")); - DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), - convert("foo -2.560000e+02")); - DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), - convert("foo -2.560000e+02")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test14/testinfo.dat deleted file mode 100644 index b47611aa44..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test14/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test14 -Description -= Tests _snwprintf with exponential format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test15/CMakeLists.txt deleted file mode 100644 index dc7b4d66e9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test15/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test15.c -) - -add_executable(paltest_snwprintf_test15 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test15 coreclrpal) - -target_link_libraries(paltest_snwprintf_test15 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test15/test15.c deleted file mode 100644 index f45005b758..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test15/test15.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: test15.c -** -** Purpose: Tests _snwprintf with exponential format doubles (uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), - convert("foo 2.560000E+02 ")); - DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), - convert("foo 2.6E+02")); - DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), - convert("foo 2.56000000E+02")); - DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), - convert("foo 002.560000E+02")); - DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), - convert("foo +2.560000E+02")); - DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), - convert("foo -2.560000E+02")); - DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), - convert("foo -2.560000E+02")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test15/testinfo.dat deleted file mode 100644 index 2c81391689..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test15/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test15 -Description -= Tests _snwprintf with exponential format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test16/CMakeLists.txt deleted file mode 100644 index f147ad7e67..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test16/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test16.c -) - -add_executable(paltest_snwprintf_test16 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test16 coreclrpal) - -target_link_libraries(paltest_snwprintf_test16 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test16/test16.c deleted file mode 100644 index 88f55bdc10..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test16/test16.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test16.c -** -** Purpose: Tests _snwprintf with decimal point format doubles -** -** -**==========================================================================*/ - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), - convert("foo 2560.001000 ")); - DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), - convert("foo 2560.0")); - DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), - convert("foo 2560.00100000")); - DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), - convert("foo 02560.001000")); - DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), - convert("foo +2560.001000")); - DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), - convert("foo -2560.001000")); - DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), - convert("foo -2560.001000")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test16/testinfo.dat deleted file mode 100644 index 8d844e0b18..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test16/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test16 -Description -= Tests _snwprintf with decimal point format doubles diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test17/CMakeLists.txt deleted file mode 100644 index e40d3f4106..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test17/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test17.c -) - -add_executable(paltest_snwprintf_test17 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test17 coreclrpal) - -target_link_libraries(paltest_snwprintf_test17 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test17/test17.c deleted file mode 100644 index 82f2330b48..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test17/test17.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: test17.c -** -** Purpose: Tests _snwprintf with compact format doubles (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), - convert("foo 2560 ")); - DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), - convert("foo 3e+03")); - DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), - convert("foo 2.6e+03")); - DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), - convert("foo 2560.001")); - DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), - convert("foo 002560")); - DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), - convert("foo 2560.00")); - DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), - convert("foo +2560")); - DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), - convert("foo -2560")); - DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), - convert("foo -2560")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test17/testinfo.dat deleted file mode 100644 index 6b01fb3d7d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test17/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test17 -Description -= Tests _snwprintf with compact format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test18/CMakeLists.txt deleted file mode 100644 index 68a014cb66..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test18/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test18.c -) - -add_executable(paltest_snwprintf_test18 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test18 coreclrpal) - -target_link_libraries(paltest_snwprintf_test18 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test18/test18.c deleted file mode 100644 index dbb6233061..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test18/test18.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test18.c -** -** Purpose: Tests _snwprintf with compact format doubles (uppercase) -** -** -**==========================================================================*/ - - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), - convert("foo 2560 ")); - DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), - convert("foo 3E+03")); - DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), - convert("foo 2.6E+03")); - DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), - convert("foo 2560.001")); - DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), - convert("foo 002560")); - DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), - convert("foo 2560.00")); - DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), - convert("foo +2560")); - DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), - convert("foo -2560")); - DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), - convert("foo -2560")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test18/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test18/testinfo.dat deleted file mode 100644 index 480087f560..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test18/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test18 -Description -= Tests _snwprintf with compact format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test19/CMakeLists.txt deleted file mode 100644 index 6dc30b4d33..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test19/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test19.c -) - -add_executable(paltest_snwprintf_test19 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test19 coreclrpal) - -target_link_libraries(paltest_snwprintf_test19 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test19/test19.c deleted file mode 100644 index efb222c6ba..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test19/test19.c +++ /dev/null @@ -1,90 +0,0 @@ -// 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: test19.c -** -** Purpose: Tests _snwprintf with argument specified precision -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -int __cdecl main(int argc, char *argv[]) -{ - int n = -1; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoArgumentPrecTest(convert("%.*s"), 2, convert("bar"), "bar", - convert("ba"), convert("ba")); - DoArgumentPrecTest(convert("%.*S"), 2, "bar", "bar", - convert("ba"), convert("ba")); - DoArgumentPrecTest(convert("%.*n"), 3, &n, "pointer to int", - convert(""), convert("")); - if (n != 0) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - 0, n); - } - - DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', "a", - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', "a", - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, "42", - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, "42", - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, "42", - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, "42", - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, "42", - convert("52"), convert("52")); - DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, "42", - convert("052"), convert("052")); - DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, "42", - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, "42", - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, "0x42", - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, "0x42", - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, "0x42", - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, "0x42", - convert("042"), convert("042")); - DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000")); - DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000")); - DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000")); - DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000")); - DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0")); - DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010")); - DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002")); - DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256")); - DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256")); - DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01")); - DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002")); - DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256")); - DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256")); - DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01")); - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test19/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test19/testinfo.dat deleted file mode 100644 index 376cbc84d1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test19/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test19 -Description -= Tests _snwprintf with argument specified precision diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test2/CMakeLists.txt deleted file mode 100644 index 9e0d950885..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test2/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test2.c -) - -add_executable(paltest_snwprintf_test2 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test2 coreclrpal) - -target_link_libraries(paltest_snwprintf_test2 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test2/test2.c deleted file mode 100644 index 974b7967f2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test2/test2.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test2.c -** -** Purpose:Tests _snwprintf with strings -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); - DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); - DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); - DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); - DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); - DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test2/testinfo.dat deleted file mode 100644 index 9c65c93e5a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test2/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test2 -Description -= Tests _snwprintf with strings diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test3/CMakeLists.txt deleted file mode 100644 index 4d5a28b0fe..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test3/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test3.c -) - -add_executable(paltest_snwprintf_test3 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test3 coreclrpal) - -target_link_libraries(paltest_snwprintf_test3 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test3/test3.c deleted file mode 100644 index bfb75ce323..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test3/test3.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests _snwprintf with wide strings -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoStrTest(convert("foo %S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); - DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); - DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); - DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); - DoStrTest(convert("foo %5.2S"), "bar", convert("foo ba")); - DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); - DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test3/testinfo.dat deleted file mode 100644 index b39f4f56b7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test3/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test3 -Description -= Tests _snwprintf with wide strings diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test4/CMakeLists.txt deleted file mode 100644 index 0102b0acea..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test4/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test4.c -) - -add_executable(paltest_snwprintf_test4 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test4 coreclrpal) - -target_link_libraries(paltest_snwprintf_test4 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test4/test4.c deleted file mode 100644 index 28f7998591..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test4/test4.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests _snwprintf with pointers -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, convert("0000000000000000")); - DoPointerTest(convert("%p"), ptr, convert("0000000000123456")); - DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); - DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); - DoPointerTest(convert("%-17p"), ptr, convert("0000000000123456 ")); - DoPointerTest(convert("%+p"), ptr, convert("0000000000123456")); - DoPointerTest(convert("% p"), ptr, convert("0000000000123456")); - DoPointerTest(convert("%#p"), ptr, convert("0X0000000000123456")); - DoPointerTest(convert("%lp"), ptr, convert("00123456")); - DoPointerTest(convert("%hp"), ptr, convert("00003456")); - DoPointerTest(convert("%Lp"), ptr, convert("00123456")); - DoI64Test(convert("%I64p"), lptr, "1234567887654321", - convert("1234567887654321")); -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, convert("00000000")); - DoPointerTest(convert("%p"), ptr, convert("00123456")); - DoPointerTest(convert("%9p"), ptr, convert(" 00123456")); - DoPointerTest(convert("%09p"), ptr, convert(" 00123456")); - DoPointerTest(convert("%-9p"), ptr, convert("00123456 ")); - DoPointerTest(convert("%+p"), ptr, convert("00123456")); - DoPointerTest(convert("% p"), ptr, convert("00123456")); - DoPointerTest(convert("%#p"), ptr, convert("0X00123456")); - DoPointerTest(convert("%lp"), ptr, convert("00123456")); - DoPointerTest(convert("%hp"), ptr, convert("00003456")); - DoPointerTest(convert("%Lp"), ptr, convert("00123456")); - DoI64Test(convert("%I64p"), lptr, "1234567887654321", - convert("1234567887654321")); -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test4/testinfo.dat deleted file mode 100644 index 3f3600160f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test4/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test4 -Description -= Tests _snwprintf with pointers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test5/CMakeLists.txt deleted file mode 100644 index c835c94845..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test5/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test5.c -) - -add_executable(paltest_snwprintf_test5 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test5 coreclrpal) - -target_link_libraries(paltest_snwprintf_test5 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test5/test5.c deleted file mode 100644 index bbe459751b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test5/test5.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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: test5.c -** -** Purpose: Tests _snwprintf with the count specifier -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR *longStr; - WCHAR *longResult; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - longStr = convert("really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - "%n bar"); - longResult = convert("really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - " bar"); - DoCountTest(convert("foo %n bar"), 4, convert("foo bar")); - DoCountTest(longStr, 257, longResult); - DoCountTest(convert("fo%n bar"), 2, convert("fo bar")); - DoCountTest(convert("%n"), 0, convert("")); - DoCountTest(convert("foo %#n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo % n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %+n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %-n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %0n bar"), 4, convert("foo bar")); - DoShortCountTest(convert("foo %hn bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %ln bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %Ln bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %I64n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %20.3n bar"), 4, convert("foo bar")); - - free(longStr); - free(longResult); - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test5/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test5/testinfo.dat deleted file mode 100644 index 2180b81cf5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test5/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test5 -Description -= Tests _snwprintf with the count specifier diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test6/CMakeLists.txt deleted file mode 100644 index 37a415ed86..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test6/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test6.c -) - -add_executable(paltest_snwprintf_test6 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test6 coreclrpal) - -target_link_libraries(paltest_snwprintf_test6 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test6/test6.c deleted file mode 100644 index 3d4ed3f882..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test6/test6.c +++ /dev/null @@ -1,46 +0,0 @@ -// 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: test6.c -** -** Purpose: Tests _snwprintf with characters -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoWCharTest(convert("foo %c"), wc, convert("foo c")); - DoCharTest(convert("foo %hc"), 'b', convert("foo b")); - DoWCharTest(convert("foo %lc"), wc, convert("foo c")); - DoWCharTest(convert("foo %Lc"), wc, convert("foo c")); - DoWCharTest(convert("foo %I64c"), wc, convert("foo c")); - DoWCharTest(convert("foo %5c"), wc, convert("foo c")); - DoWCharTest(convert("foo %.0c"), wc, convert("foo c")); - DoWCharTest(convert("foo %-5c"), wc, convert("foo c ")); - DoWCharTest(convert("foo %05c"), wc, convert("foo 0000c")); - DoWCharTest(convert("foo % c"), wc, convert("foo c")); - DoWCharTest(convert("foo %#c"), wc, convert("foo c")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test6/testinfo.dat deleted file mode 100644 index 6a170cd549..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test6/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test6 -Description -= Tests _snwprintf with characters diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test7/CMakeLists.txt deleted file mode 100644 index b1a07eeaa4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test7/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test7.c -) - -add_executable(paltest_snwprintf_test7 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test7 coreclrpal) - -target_link_libraries(paltest_snwprintf_test7 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test7/test7.c deleted file mode 100644 index 7954ff71ca..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test7/test7.c +++ /dev/null @@ -1,46 +0,0 @@ -// 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: test7.c -** -** Purpose: Tests _snwprintf with wide characters -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoCharTest(convert("foo %C"), 'b', convert("foo b")); - DoWCharTest(convert("foo %hC"), wc, convert("foo c")); - DoCharTest(convert("foo %lC"), 'b', convert("foo b")); - DoCharTest(convert("foo %LC"), 'b', convert("foo b")); - DoCharTest(convert("foo %I64C"), 'b', convert("foo b")); - DoCharTest(convert("foo %5C"), 'b', convert("foo b")); - DoCharTest(convert("foo %.0C"), 'b', convert("foo b")); - DoCharTest(convert("foo %-5C"), 'b', convert("foo b ")); - DoCharTest(convert("foo %05C"), 'b', convert("foo 0000b")); - DoCharTest(convert("foo % C"), 'b', convert("foo b")); - DoCharTest(convert("foo %#C"), 'b', convert("foo b")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test7/testinfo.dat deleted file mode 100644 index 5749539e3f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test7/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test7 -Description -= Tests _snwprintf with wide characters diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test8/CMakeLists.txt deleted file mode 100644 index 063ee2b9b6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test8/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test8.c -) - -add_executable(paltest_snwprintf_test8 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test8 coreclrpal) - -target_link_libraries(paltest_snwprintf_test8 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test8/test8.c deleted file mode 100644 index 91c2820076..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test8/test8.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test8.c -** -** Purpose: Tests _snwprintf with decimal numbers -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %d"), pos, convert("foo 42")); - DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); - DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); - DoI64Test(convert("foo %I64d"), l, "42", convert("foo 42")); - DoNumTest(convert("foo %3d"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); - DoNumTest(convert("foo %03d"), pos, convert("foo 042")); - DoNumTest(convert("foo %#d"), pos, convert("foo 42")); - DoNumTest(convert("foo %+d"), pos, convert("foo +42")); - DoNumTest(convert("foo % d"), pos, convert("foo 42")); - DoNumTest(convert("foo %+d"), neg, convert("foo -42")); - DoNumTest(convert("foo % d"), neg, convert("foo -42")); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test8/testinfo.dat deleted file mode 100644 index 6398f60183..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test8/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test8 -Description -= Tests _snwprintf with decimal numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf/test9/CMakeLists.txt deleted file mode 100644 index 8d5e41131d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test9/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test9.c -) - -add_executable(paltest_snwprintf_test9 - ${SOURCES} -) - -add_dependencies(paltest_snwprintf_test9 coreclrpal) - -target_link_libraries(paltest_snwprintf_test9 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/_snwprintf/test9/test9.c deleted file mode 100644 index f8f994fdcc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test9/test9.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test9.c -** -** Purpose: Tests _snwprintf with integer numbers -** -** -**==========================================================================*/ - - - -#include -#include "../_snwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %i"), pos, convert("foo 42")); - DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); - DoNumTest(convert("foo %Li"), pos, convert("foo 42")); - DoI64Test(convert("foo %I64i"), l, "42", convert("foo 42")); - DoNumTest(convert("foo %3i"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); - DoNumTest(convert("foo %03i"), pos, convert("foo 042")); - DoNumTest(convert("foo %#i"), pos, convert("foo 42")); - DoNumTest(convert("foo %+i"), pos, convert("foo +42")); - DoNumTest(convert("foo % i"), pos, convert("foo 42")); - DoNumTest(convert("foo %+i"), neg, convert("foo -42")); - DoNumTest(convert("foo % i"), neg, convert("foo -42")); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf/test9/testinfo.dat deleted file mode 100644 index 287de4a9e9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_snwprintf/test9/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = _snwprintf -Name = Positive Test for _snwprintf -TYPE = DEFAULT -EXE1 = test9 -Description -= Tests _snwprintf with integer numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/CMakeLists.txt new file mode 100644 index 0000000000..8fe1cb60ac --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test10) +add_subdirectory(test11) +add_subdirectory(test12) +add_subdirectory(test13) +add_subdirectory(test14) +add_subdirectory(test15) +add_subdirectory(test16) +add_subdirectory(test17) +add_subdirectory(test18) +add_subdirectory(test19) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) +add_subdirectory(test6) +add_subdirectory(test7) +add_subdirectory(test8) +add_subdirectory(test9) + diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/_snwprintf_s.h b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/_snwprintf_s.h new file mode 100644 index 0000000000..19d192114b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/_snwprintf_s.h @@ -0,0 +1,199 @@ +// 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: swprintf_s.h +** +** Purpose: Containts common testing functions for swprintf_s +** +** +**==========================================================================*/ + +#ifndef ___SNWPRINTF_H__ +#define ___SNWPRINTF_H__ + +void DoWStrTest(const WCHAR *formatstr, WCHAR *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + + if (memcmp(buf, checkstr, wcslen(checkstr) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", convertC(param), + convertC(formatstr), convertC(checkstr), convertC(buf)); + } +} + +void DoStrTest(const WCHAR *formatstr, char *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + + if (memcmp(buf, checkstr, wcslen(checkstr) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", + param, convertC(formatstr), convertC(checkstr), convertC(buf)); + } +} + +void DoPointerTest(const WCHAR *formatstr, void* param, const WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0) + { + Fail("ERROR: failed to insert pointer to %#p into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", param, convertC(formatstr), + convertC(checkstr1), convertC(buf)); + } +} + +void DoCountTest(const WCHAR *formatstr, int param, const WCHAR *checkstr) +{ + WCHAR buf[512] = { 0 }; + int n = -1; + + swprintf_s(buf, 512, formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %d\n", + param, n); + } + + if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", + convertC(checkstr), convertC(buf)); + } +} + +void DoShortCountTest(const WCHAR *formatstr, int param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + short int n = -1; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %d\n", + param, n); + } + + if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", + convertC(checkstr), convertC(buf)); + } +} + +void DoCharTest(const WCHAR *formatstr, char param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) + { + Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", param, param, + convertC(formatstr), convertC(checkstr), convertC(buf)); + } +} + +void DoWCharTest(const WCHAR *formatstr, WCHAR param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) + { + Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", (char) param, param, + convertC(formatstr), convertC(checkstr), convertC(buf)); + } +} + +void DoNumTest(const WCHAR *formatstr, int value, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, value); + if (memcmp(buf, checkstr, wcslen(checkstr)* 2 + 2) != 0) + { + Fail("ERROR: failed to insert %#x into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", value, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} + + +void DoI64Test(const WCHAR *formatstr, INT64 param, char *paramdesc, + const WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", paramdesc, + convertC(formatstr), convertC(checkstr1), convertC(buf)); + } +} + +void DoDoubleTest(const WCHAR *formatstr, double value, const WCHAR *checkstr1, + const WCHAR *checkstr2) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, value); + if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2)*2 + 2) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\"\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + value, convertC(formatstr), convertC(checkstr1), + convertC(checkstr2), convertC(buf)); + } +} + +void DoArgumentPrecTest(const WCHAR *formatstr, int precision, void *param, + char *paramstr, const WCHAR *checkstr1, const WCHAR *checkstr2) +{ + WCHAR buf[256]; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, precision, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + paramstr, convertC(formatstr), precision, + convertC(checkstr1), convertC(checkstr2) ,convertC(buf)); + } +} + +void DoArgumentPrecDoubleTest(const WCHAR *formatstr, int precision, double param, + const WCHAR *checkstr) +{ + WCHAR buf[256]; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, precision, param); + if (memcmp(buf, checkstr, wcslen(checkstr) + 2) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" + "Expected \"%s\", got \"%s\".\n", param, convertC(formatstr), + precision, convertC(checkstr), convertC(buf)); + } +} + +#endif + diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/CMakeLists.txt new file mode 100644 index 0000000000..eac86f30e4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_snwprintf_test1 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test1 coreclrpal) + +target_link_libraries(paltest_snwprintf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/test1.cpp new file mode 100644 index 0000000000..ba85103cb1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/test1.cpp @@ -0,0 +1,62 @@ +// 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: test1.c +** +** Purpose: General test to see if swprintf_s works correctly +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +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"); + _snwprintf_s(buf, 256, _TRUNCATE, checkstr); + if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0) + { + Fail("ERROR: Expected \"%s\", got \"%s\"\n", + convertC(checkstr), convertC(buf)); + } + + _snwprintf_s(buf, 256, _TRUNCATE, convert("xxxxxxxxxxxxxxxxx")); + ret = _snwprintf_s(buf, 8, _TRUNCATE, 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; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/testinfo.dat new file mode 100644 index 0000000000..96d7914ce0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test1 +Description += General test to see if swprintf_s works correctly diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/CMakeLists.txt new file mode 100644 index 0000000000..82ee739587 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test10.cpp +) + +add_executable(paltest_snwprintf_test10 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test10 coreclrpal) + +target_link_libraries(paltest_snwprintf_test10 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/test10.cpp new file mode 100644 index 0000000000..298f82b002 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/test10.cpp @@ -0,0 +1,54 @@ +// 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: test10.c +** +** Purpose: Tests swprintf_s with octal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %o"), pos, convert("foo 52")); + DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); + DoI64Test(convert("foo %I64o"), l, "42", convert("foo 52")); + DoNumTest(convert("foo %3o"), pos, convert("foo 52")); + DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); + DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); + DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); + DoNumTest(convert("foo %03o"), pos, convert("foo 052")); + DoNumTest(convert("foo %#o"), pos, convert("foo 052")); + DoNumTest(convert("foo %+o"), pos, convert("foo 52")); + DoNumTest(convert("foo % o"), pos, convert("foo 52")); + DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); + DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/testinfo.dat new file mode 100644 index 0000000000..887bbf76c8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test10 +Description += Tests swprintf_s with octal numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/CMakeLists.txt new file mode 100644 index 0000000000..f7d7845571 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test11.cpp +) + +add_executable(paltest_snwprintf_test11 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test11 coreclrpal) + +target_link_libraries(paltest_snwprintf_test11 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/test11.cpp new file mode 100644 index 0000000000..519668791b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/test11.cpp @@ -0,0 +1,54 @@ +// 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: test11.c +** +** Purpose: Tests swprintf_s with unsigned numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %u"), pos, convert("foo 42")); + DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); + DoI64Test(convert("foo %I64u"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3u"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); + DoNumTest(convert("foo %03u"), pos, convert("foo 042")); + DoNumTest(convert("foo %#u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), pos, convert("foo 42")); + DoNumTest(convert("foo % u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); + DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/testinfo.dat new file mode 100644 index 0000000000..3bda85e335 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test11 +Description += Tests swprintf_s with unsigned numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/CMakeLists.txt new file mode 100644 index 0000000000..5b926fb548 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test12.cpp +) + +add_executable(paltest_snwprintf_test12 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test12 coreclrpal) + +target_link_libraries(paltest_snwprintf_test12 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/test12.cpp new file mode 100644 index 0000000000..52780aff0a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/test12.cpp @@ -0,0 +1,54 @@ +// 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: test12.c +** +** Purpose: Tests swprintf_s with hex numbers (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); + DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); + DoI64Test(convert("foo %I64x"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); + DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); + DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); + DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/testinfo.dat new file mode 100644 index 0000000000..d808a3b8f4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test12 +Description += Tests swprintf_s with hex numbers (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/CMakeLists.txt new file mode 100644 index 0000000000..52a3c75a15 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test13.cpp +) + +add_executable(paltest_snwprintf_test13 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test13 coreclrpal) + +target_link_libraries(paltest_snwprintf_test13 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/test13.cpp new file mode 100644 index 0000000000..fa948b3a1b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/test13.cpp @@ -0,0 +1,54 @@ +// 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: test13.c +** +** Purpose: Tests swprintf_s with hex numbers (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); + DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); + DoI64Test(convert("foo %I64X"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); + DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); + DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); + DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/testinfo.dat new file mode 100644 index 0000000000..2e5800ec31 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test13 +Description += Tests swprintf_s with hex numbers (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/CMakeLists.txt new file mode 100644 index 0000000000..d557a30b42 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test14.cpp +) + +add_executable(paltest_snwprintf_test14 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test14 coreclrpal) + +target_link_libraries(paltest_snwprintf_test14 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/test14.cpp new file mode 100644 index 0000000000..aea289d1a1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/test14.cpp @@ -0,0 +1,66 @@ +// 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: test14.c +** +** Purpose: Tests swprintf_s with exponential format doubles (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), + convert("foo 2.560000e+02 ")); + DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), + convert("foo 2.6e+02")); + DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), + convert("foo 2.56000000e+02")); + DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), + convert("foo 002.560000e+02")); + DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), + convert("foo +2.560000e+02")); + DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/testinfo.dat new file mode 100644 index 0000000000..25bd5099c9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test14 +Description += Tests swprintf_s with exponential format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/CMakeLists.txt new file mode 100644 index 0000000000..2e5ee362fc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test15.cpp +) + +add_executable(paltest_snwprintf_test15 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test15 coreclrpal) + +target_link_libraries(paltest_snwprintf_test15 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/test15.cpp new file mode 100644 index 0000000000..14db14b498 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/test15.cpp @@ -0,0 +1,67 @@ +// 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: test15.c +** +** Purpose: Tests swprintf_s with exponential format doubles (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), + convert("foo 2.560000E+02 ")); + DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), + convert("foo 2.6E+02")); + DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), + convert("foo 2.56000000E+02")); + DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), + convert("foo 002.560000E+02")); + DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), + convert("foo +2.560000E+02")); + DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/testinfo.dat new file mode 100644 index 0000000000..95d90e82e7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test15 +Description += Tests swprintf_s with exponential format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/CMakeLists.txt new file mode 100644 index 0000000000..f4ce409dcb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test16.cpp +) + +add_executable(paltest_snwprintf_test16 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test16 coreclrpal) + +target_link_libraries(paltest_snwprintf_test16 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/test16.cpp new file mode 100644 index 0000000000..4d9a717f24 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/test16.cpp @@ -0,0 +1,65 @@ +// 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: test16.c +** +** Purpose: Tests swprintf_s with decimal point format doubles +** +** +**==========================================================================*/ + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), + convert("foo 2560.001000 ")); + DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), + convert("foo 2560.0")); + DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), + convert("foo 2560.00100000")); + DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), + convert("foo 02560.001000")); + DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), + convert("foo +2560.001000")); + DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/testinfo.dat new file mode 100644 index 0000000000..b81c847c69 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test16 +Description += Tests swprintf_s with decimal point format doubles diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/CMakeLists.txt new file mode 100644 index 0000000000..159e15dafe --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test17.cpp +) + +add_executable(paltest_snwprintf_test17 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test17 coreclrpal) + +target_link_libraries(paltest_snwprintf_test17 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/test17.cpp new file mode 100644 index 0000000000..6af1815b85 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/test17.cpp @@ -0,0 +1,68 @@ +// 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: test17.c +** +** Purpose: Tests swprintf_s with compact format doubles (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), + convert("foo 3e+03")); + DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), + convert("foo 2.6e+03")); + DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/testinfo.dat new file mode 100644 index 0000000000..d64366702a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test17 +Description += Tests swprintf_s with compact format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/CMakeLists.txt new file mode 100644 index 0000000000..5964e849a4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test18.cpp +) + +add_executable(paltest_snwprintf_test18 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test18 coreclrpal) + +target_link_libraries(paltest_snwprintf_test18 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/test18.cpp new file mode 100644 index 0000000000..020a885090 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/test18.cpp @@ -0,0 +1,69 @@ +// 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: test18.c +** +** Purpose: Tests swprintf_s with compact format doubles (uppercase) +** +** +**==========================================================================*/ + + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), + convert("foo 3E+03")); + DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), + convert("foo 2.6E+03")); + DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/testinfo.dat new file mode 100644 index 0000000000..dfc2cd5f43 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test18 +Description += Tests swprintf_s with compact format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/CMakeLists.txt new file mode 100644 index 0000000000..5d84847ec1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test19.cpp +) + +add_executable(paltest_snwprintf_test19 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test19 coreclrpal) + +target_link_libraries(paltest_snwprintf_test19 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/test19.cpp new file mode 100644 index 0000000000..d335d1d10c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/test19.cpp @@ -0,0 +1,82 @@ +// 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: test19.c +** +** Purpose: Tests swprintf_s with argument specified precision +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + int n = -1; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoArgumentPrecTest(convert("%.*s"), 2, (void*)convert("bar"), "bar", + convert("ba"), convert("ba")); + DoArgumentPrecTest(convert("%.*S"), 2, (void*)"bar", "bar", + convert("ba"), convert("ba")); + DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', "a", + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', "a", + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, "42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, "42", + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, "42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, "42", + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, "42", + convert("52"), convert("52")); + DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, "42", + convert("052"), convert("052")); + DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, "42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, "42", + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, "0x42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, "0x42", + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, "0x42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, "0x42", + convert("042"), convert("042")); + DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000")); + DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000")); + DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000")); + DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000")); + DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0")); + DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010")); + DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002")); + DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01")); + DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002")); + DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01")); + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/testinfo.dat new file mode 100644 index 0000000000..95269cdd39 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test19 +Description += Tests swprintf_s with argument specified precision diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/CMakeLists.txt new file mode 100644 index 0000000000..ea33d48bd5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.cpp +) + +add_executable(paltest_snwprintf_test2 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test2 coreclrpal) + +target_link_libraries(paltest_snwprintf_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/test2.cpp new file mode 100644 index 0000000000..86bfdc9839 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/test2.cpp @@ -0,0 +1,44 @@ +// 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: test2.c +** +** Purpose:Tests swprintf_s with strings +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); + DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/testinfo.dat new file mode 100644 index 0000000000..88f1981609 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test2 +Description += Tests swprintf_s with strings diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/CMakeLists.txt new file mode 100644 index 0000000000..5095b1a12e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.cpp +) + +add_executable(paltest_snwprintf_test3 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test3 coreclrpal) + +target_link_libraries(paltest_snwprintf_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/test3.cpp new file mode 100644 index 0000000000..f6db6f265d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/test3.cpp @@ -0,0 +1,44 @@ +// 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: test3.c +** +** Purpose: Tests swprintf_s with wide strings +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoStrTest(convert("foo %S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); + DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %5.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); + DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/testinfo.dat new file mode 100644 index 0000000000..5ed59e61ac --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test3 +Description += Tests swprintf_s with wide strings diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/CMakeLists.txt new file mode 100644 index 0000000000..9cf81ea1bd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test4.cpp +) + +add_executable(paltest_snwprintf_test4 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test4 coreclrpal) + +target_link_libraries(paltest_snwprintf_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/test4.cpp new file mode 100644 index 0000000000..02d4781bd3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/test4.cpp @@ -0,0 +1,71 @@ +// 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: test4.c +** +** Purpose: Tests swprintf_s with pointers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("0000000000000000")); + DoPointerTest(convert("%p"), ptr, convert("0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); + DoPointerTest(convert("%-17p"), ptr, convert("0000000000123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("0000000000123456")); + DoPointerTest(convert("% p"), ptr, convert("0000000000123456")); + DoPointerTest(convert("%#p"), ptr, convert("0X0000000000123456")); + DoPointerTest(convert("%lp"), ptr, convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("00123456")); + DoI64Test(convert("%I64p"), lptr, "1234567887654321", + convert("1234567887654321")); +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("00000000")); + DoPointerTest(convert("%p"), ptr, convert("00123456")); + DoPointerTest(convert("%9p"), ptr, convert(" 00123456")); + DoPointerTest(convert("%09p"), ptr, convert(" 00123456")); + DoPointerTest(convert("%-9p"), ptr, convert("00123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("00123456")); + DoPointerTest(convert("% p"), ptr, convert("00123456")); + DoPointerTest(convert("%#p"), ptr, convert("0X00123456")); + DoPointerTest(convert("%lp"), ptr, convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("00123456")); + DoI64Test(convert("%I64p"), lptr, "1234567887654321", + convert("1234567887654321")); +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/testinfo.dat new file mode 100644 index 0000000000..2b35f2d0d3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test4 +Description += Tests swprintf_s with pointers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/CMakeLists.txt new file mode 100644 index 0000000000..4996c7716f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test6.cpp +) + +add_executable(paltest_snwprintf_test6 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test6 coreclrpal) + +target_link_libraries(paltest_snwprintf_test6 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/test6.cpp new file mode 100644 index 0000000000..576e061acd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/test6.cpp @@ -0,0 +1,46 @@ +// 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: test6.c +** +** Purpose: Tests swprintf_s with characters +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoWCharTest(convert("foo %c"), wc, convert("foo c")); + DoCharTest(convert("foo %hc"), 'b', convert("foo b")); + DoWCharTest(convert("foo %lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %Lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %I64c"), wc, convert("foo c")); + DoWCharTest(convert("foo %5c"), wc, convert("foo c")); + DoWCharTest(convert("foo %.0c"), wc, convert("foo c")); + DoWCharTest(convert("foo %-5c"), wc, convert("foo c ")); + DoWCharTest(convert("foo %05c"), wc, convert("foo 0000c")); + DoWCharTest(convert("foo % c"), wc, convert("foo c")); + DoWCharTest(convert("foo %#c"), wc, convert("foo c")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/testinfo.dat new file mode 100644 index 0000000000..d8db7f8335 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test6 +Description += Tests swprintf_s with characters diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/CMakeLists.txt new file mode 100644 index 0000000000..0e55fbf4d7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test7.cpp +) + +add_executable(paltest_snwprintf_test7 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test7 coreclrpal) + +target_link_libraries(paltest_snwprintf_test7 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/test7.cpp new file mode 100644 index 0000000000..54dd32b433 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/test7.cpp @@ -0,0 +1,46 @@ +// 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: test7.c +** +** Purpose: Tests swprintf_s with wide characters +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoCharTest(convert("foo %C"), 'b', convert("foo b")); + DoWCharTest(convert("foo %hC"), wc, convert("foo c")); + DoCharTest(convert("foo %lC"), 'b', convert("foo b")); + DoCharTest(convert("foo %LC"), 'b', convert("foo b")); + DoCharTest(convert("foo %I64C"), 'b', convert("foo b")); + DoCharTest(convert("foo %5C"), 'b', convert("foo b")); + DoCharTest(convert("foo %.0C"), 'b', convert("foo b")); + DoCharTest(convert("foo %-5C"), 'b', convert("foo b ")); + DoCharTest(convert("foo %05C"), 'b', convert("foo 0000b")); + DoCharTest(convert("foo % C"), 'b', convert("foo b")); + DoCharTest(convert("foo %#C"), 'b', convert("foo b")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/testinfo.dat new file mode 100644 index 0000000000..fa5bd30008 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test7 +Description += Tests swprintf_s with wide characters diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/CMakeLists.txt new file mode 100644 index 0000000000..8f7fbda5a0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test8.cpp +) + +add_executable(paltest_snwprintf_test8 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test8 coreclrpal) + +target_link_libraries(paltest_snwprintf_test8 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/test8.cpp new file mode 100644 index 0000000000..9f1b555e3c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/test8.cpp @@ -0,0 +1,53 @@ +// 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: test8.c +** +** Purpose: Tests swprintf_s with decimal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %d"), pos, convert("foo 42")); + DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); + DoI64Test(convert("foo %I64d"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3d"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); + DoNumTest(convert("foo %03d"), pos, convert("foo 042")); + DoNumTest(convert("foo %#d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), pos, convert("foo +42")); + DoNumTest(convert("foo % d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), neg, convert("foo -42")); + DoNumTest(convert("foo % d"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/testinfo.dat new file mode 100644 index 0000000000..d76a421ea3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test8 +Description += Tests swprintf_s with decimal numbers diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/CMakeLists.txt new file mode 100644 index 0000000000..f769c9eaa5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test9.cpp +) + +add_executable(paltest_snwprintf_test9 + ${SOURCES} +) + +add_dependencies(paltest_snwprintf_test9 coreclrpal) + +target_link_libraries(paltest_snwprintf_test9 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/test9.cpp new file mode 100644 index 0000000000..76d60631a2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/test9.cpp @@ -0,0 +1,53 @@ +// 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: test9.c +** +** Purpose: Tests swprintf_s with integer numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %i"), pos, convert("foo 42")); + DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Li"), pos, convert("foo 42")); + DoI64Test(convert("foo %I64i"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3i"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); + DoNumTest(convert("foo %03i"), pos, convert("foo 042")); + DoNumTest(convert("foo %#i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), pos, convert("foo +42")); + DoNumTest(convert("foo % i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), neg, convert("foo -42")); + DoNumTest(convert("foo % i"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/testinfo.dat new file mode 100644 index 0000000000..b2a038df62 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/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 = C Runtime +Function = swprintf_s +Name = Positive Test for swprintf_s +TYPE = DEFAULT +EXE1 = test9 +Description += Tests swprintf_s with integer numbers diff --git a/src/pal/tests/palsuite/c_runtime/_splitpath/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_splitpath/CMakeLists.txt deleted file mode 100644 index f6aa0cb2d9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_splitpath/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/_splitpath/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_splitpath/test1/CMakeLists.txt deleted file mode 100644 index 361b9084d7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_splitpath/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_splitpath_test1 - ${SOURCES} -) - -add_dependencies(paltest_splitpath_test1 coreclrpal) - -target_link_libraries(paltest_splitpath_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_splitpath/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_splitpath/test1/test1.c deleted file mode 100644 index e98354c2ee..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_splitpath/test1/test1.c +++ /dev/null @@ -1,108 +0,0 @@ -// 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: test1.c -** -** Purpose: Passes _splitpath() a series of sample paths and checks that it -** parses them as expected. -** -** -**==========================================================================*/ - - -#include - -struct testCase -{ - const char path[_MAX_PATH]; /* The path to parse. */ - const char drive[_MAX_DRIVE]; /* The expected values... */ - const char dir[_MAX_DIR]; - const char fname[_MAX_FNAME]; - const char ext[_MAX_EXT]; -}; - - -int __cdecl main(int argc, char **argv) -{ - struct testCase testCases[] = - { -#if WIN32 - {"c:\\foo\\bar\\foo.bar", "c:", "\\foo\\bar\\", "foo", ".bar"}, - {"c:/foo/bar/foo.bar", "c:", "/foo/bar/", "foo", ".bar"}, - {"c:/foo/bar/foo", "c:", "/foo/bar/", "foo", ""}, - {"c:/foo/bar/.bar", "c:", "/foo/bar/", "", ".bar"}, - {"c:/foo/bar/", "c:", "/foo/bar/", "", ""}, - {"/foo/bar/foo.bar", "", "/foo/bar/", "foo", ".bar"}, - {"c:foo.bar", "c:", "", "foo", ".bar"} -#else - {"c:\\foo\\bar\\foo.bar", "","c:/foo/bar/", "foo", ".bar"}, - {"c:/foo/bar/foo.bar", "", "c:/foo/bar/", "foo", ".bar"}, - {"c:/foo/bar/foo", "", "c:/foo/bar/", "foo", ""}, - {"c:/foo/bar/.bar", "", "c:/foo/bar/", ".bar", ""}, - {"c:/foo/bar/", "", "c:/foo/bar/", "", ""}, - {"/foo/bar/foo.bar", "", "/foo/bar/", "foo", ".bar"}, - {"c:foo.bar", "", "", "c:foo", ".bar"} -#endif - }; - char drive[_MAX_DRIVE]; - char dir[_MAX_DIR]; - char fname[_MAX_FNAME]; - char ext[_MAX_EXT]; - - int i=0; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) - { - _splitpath(testCases[i].path, drive, dir, fname, ext); - - - /*on platforms that don't support drive letters, the drive - returned should always be "" */ - if (strcmp(drive, testCases[i].drive) != 0) - { - Fail("_splitpath read the path \"%s\" and thought the drive was " - "\"%s\" instead of \"%s\"\n" - , testCases[i].path, drive, testCases[i].drive); - } - - if (strcmp(dir, testCases[i].dir) != 0) - { - Fail("_splitpath read the path \"%s\" and thought the directory " - "was \"%s\" instead of \"%s\"\n" - , testCases[i].path, dir, testCases[i].dir); - } - - if (strcmp(fname, testCases[i].fname) != 0) - { - Fail("_splitpath read the path \"%s\" and thought the filename " - "was \"%s\" instead of \"%s\"\n" - , testCases[i].path, fname, testCases[i].fname); - } - - if (strcmp(ext, testCases[i].ext) != 0) - { - Fail("_splitpath read the path \"%s\" and thought the file " - "extension was \"%s\" instead of \"%s\"\n" - , testCases[i].path, ext, testCases[i].ext); - } - } - PAL_Terminate(); - return PASS; -} - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/_splitpath/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_splitpath/test1/testinfo.dat deleted file mode 100644 index 0a93e27456..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_splitpath/test1/testinfo.dat +++ /dev/null @@ -1,15 +0,0 @@ -# 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 = C Runtime -Function = _splitpath -Name = Positive Test for _splitpath -TYPE = DEFAULT -EXE1 = test1 -Description -= Passes _splitpath() a series of sample paths and checks that it -= parses them as expected. - - diff --git a/src/pal/tests/palsuite/c_runtime/_stricmp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_stricmp/test1/CMakeLists.txt index 766660ccfc..03aa3a523e 100644 --- a/src/pal/tests/palsuite/c_runtime/_stricmp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_stricmp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_stricmp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.c deleted file mode 100644 index 60e2f9eb8b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.c +++ /dev/null @@ -1,70 +0,0 @@ -// 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: test1.c -** -** Purpose: Do a lower case compare. Check two strings, only different -** because they have different capitalization, and they should return 0. Try -** two strings which will return less than 0 (one is smaller than the other). -** Also try the opposite, to get a return value greater than 0. -** -** -**==========================================================================*/ - -#include - -/* - * Note: The _stricmp is dependent on the LC_CTYPE category of the locale, - * and this is ignored by these tests. - */ -int __cdecl main(int argc, char *argv[]) -{ - char *str1 = "foo"; - char *str2 = "fOo"; - char *str3 = "foo_bar"; - char *str4 = "foobar"; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if (_stricmp(str1, str2) != 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") != 0\n", str1, str2); - } - - if (_stricmp(str2, str3) >= 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") >= 0\n", str2, str3); - } - - if (_stricmp(str3, str4) >= 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") >= 0\n", str3, str4); - } - - if (_stricmp(str4, str1) <= 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") <= 0\n", str4, str1); - } - - if (_stricmp(str3, str2) <= 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") <= 0\n", str2, str3); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.cpp new file mode 100644 index 0000000000..60e2f9eb8b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.cpp @@ -0,0 +1,70 @@ +// 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: test1.c +** +** Purpose: Do a lower case compare. Check two strings, only different +** because they have different capitalization, and they should return 0. Try +** two strings which will return less than 0 (one is smaller than the other). +** Also try the opposite, to get a return value greater than 0. +** +** +**==========================================================================*/ + +#include + +/* + * Note: The _stricmp is dependent on the LC_CTYPE category of the locale, + * and this is ignored by these tests. + */ +int __cdecl main(int argc, char *argv[]) +{ + char *str1 = "foo"; + char *str2 = "fOo"; + char *str3 = "foo_bar"; + char *str4 = "foobar"; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + if (_stricmp(str1, str2) != 0) + { + Fail ("ERROR: _stricmp returning incorrect value:\n" + "_stricmp(\"%s\", \"%s\") != 0\n", str1, str2); + } + + if (_stricmp(str2, str3) >= 0) + { + Fail ("ERROR: _stricmp returning incorrect value:\n" + "_stricmp(\"%s\", \"%s\") >= 0\n", str2, str3); + } + + if (_stricmp(str3, str4) >= 0) + { + Fail ("ERROR: _stricmp returning incorrect value:\n" + "_stricmp(\"%s\", \"%s\") >= 0\n", str3, str4); + } + + if (_stricmp(str4, str1) <= 0) + { + Fail ("ERROR: _stricmp returning incorrect value:\n" + "_stricmp(\"%s\", \"%s\") <= 0\n", str4, str1); + } + + if (_stricmp(str3, str2) <= 0) + { + Fail ("ERROR: _stricmp returning incorrect value:\n" + "_stricmp(\"%s\", \"%s\") <= 0\n", str2, str3); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_strlwr/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_strlwr/test1/CMakeLists.txt index 3a9394ca60..ca26961b3c 100644 --- a/src/pal/tests/palsuite/c_runtime/_strlwr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_strlwr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strlwr_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_strlwr/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_strlwr/test1/test1.c deleted file mode 100644 index 1c4015e3e2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_strlwr/test1/test1.c +++ /dev/null @@ -1,42 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Using memcmp, check to see that after changing a string into all lowercase -** that it is the lowercase string that was expected. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - char string[] = "aASdff"; - char checkstr[] = "aasdff"; - char *ret=NULL; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ret = _strlwr(string); - - if (memcmp(ret, checkstr, sizeof(checkstr)) != 0) - { - Fail ("ERROR: _strlwr returning incorrect value\n" - "Expected %s, got %s\n", checkstr, ret); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_strlwr/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_strlwr/test1/test1.cpp new file mode 100644 index 0000000000..1c4015e3e2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_strlwr/test1/test1.cpp @@ -0,0 +1,42 @@ +// 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: test1.c +** +** Purpose: +** Using memcmp, check to see that after changing a string into all lowercase +** that it is the lowercase string that was expected. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + char string[] = "aASdff"; + char checkstr[] = "aasdff"; + char *ret=NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ret = _strlwr(string); + + if (memcmp(ret, checkstr, sizeof(checkstr)) != 0) + { + Fail ("ERROR: _strlwr returning incorrect value\n" + "Expected %s, got %s\n", checkstr, ret); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/CMakeLists.txt index 6a38747592..03f9992198 100644 --- a/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strnicmp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.c deleted file mode 100644 index 3c915dc621..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the _strnicmp function -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char str1[] = "foo"; - char str2[] = "foox"; - char str3[] = "fOo"; - char str4[] = "ABCDE"; - char str5[] = "ABCD["; - char str6[] = "abcde"; - char str7[] = "abcd^"; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if (_strnicmp(str1, str2, strlen(str2)) >= 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned >= 0\n", - str1, str2, strlen(str2)); - } - - if (_strnicmp(str2, str1, strlen(str2)) <= 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned <= 0\n", - str2, str1, strlen(str2)); - } - - if (_strnicmp(str1, str2, strlen(str1)) != 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned != 0\n", - str1, str2, strlen(str1)); - } - - if (_strnicmp(str1, str3, strlen(str1)) != 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned != 0\n", - str1, str3, strlen(str3)); - } - - if (_strnicmp(str3, str1, strlen(str1)) != 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned != 0\n", - str3, str1, strlen(str1)); - } - - /* new testing */ - - /* str4 should be greater than str5 */ - if (_strnicmp(str4, str5, strlen(str4)) <= 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned >= 0\n", - str4, str5, strlen(str4)); - } - - /* str6 should be greater than str7 */ - if (_strnicmp(str6, str7, strlen(str6)) <= 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned <= 0\n", - str6, str7, strlen(str6)); - } - - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.cpp new file mode 100644 index 0000000000..3c915dc621 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.cpp @@ -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: test1.c +** +** Purpose: Test #1 for the _strnicmp function +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char str1[] = "foo"; + char str2[] = "foox"; + char str3[] = "fOo"; + char str4[] = "ABCDE"; + char str5[] = "ABCD["; + char str6[] = "abcde"; + char str7[] = "abcd^"; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + if (_strnicmp(str1, str2, strlen(str2)) >= 0) + { + Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned >= 0\n", + str1, str2, strlen(str2)); + } + + if (_strnicmp(str2, str1, strlen(str2)) <= 0) + { + Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned <= 0\n", + str2, str1, strlen(str2)); + } + + if (_strnicmp(str1, str2, strlen(str1)) != 0) + { + Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned != 0\n", + str1, str2, strlen(str1)); + } + + if (_strnicmp(str1, str3, strlen(str1)) != 0) + { + Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned != 0\n", + str1, str3, strlen(str3)); + } + + if (_strnicmp(str3, str1, strlen(str1)) != 0) + { + Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned != 0\n", + str3, str1, strlen(str1)); + } + + /* new testing */ + + /* str4 should be greater than str5 */ + if (_strnicmp(str4, str5, strlen(str4)) <= 0) + { + Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned >= 0\n", + str4, str5, strlen(str4)); + } + + /* str6 should be greater than str7 */ + if (_strnicmp(str6, str7, strlen(str6)) <= 0) + { + Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned <= 0\n", + str6, str7, strlen(str6)); + } + + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_swab/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_swab/CMakeLists.txt deleted file mode 100644 index f6aa0cb2d9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_swab/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/_swab/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_swab/test1/CMakeLists.txt deleted file mode 100644 index fc7fbef8b4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_swab/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_swab_test1 - ${SOURCES} -) - -add_dependencies(paltest_swab_test1 coreclrpal) - -target_link_libraries(paltest_swab_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_swab/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_swab/test1/test1.c deleted file mode 100644 index 203e3b3a06..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_swab/test1/test1.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test1.c -** -** Purpose: Calls _swab on a buffer, and checks that it has correctly -** swapped adjacent bytes -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - char before[] = "abcdefghijklmn"; - char after[] = "--------------"; - const char check[] = "badcfehgjilknm"; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - _swab(before, after, sizeof(before)); - if (memcmp(after, check, sizeof(after)) != 0) - { - Fail ("_swab did not correctly swap adjacent bytes in a buffer.\n"); - } - - PAL_Terminate(); - return PASS; - -} - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/_swab/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_swab/test1/testinfo.dat deleted file mode 100644 index c59b017762..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_swab/test1/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _swab -Name = Positive Test for _swab -TYPE = DEFAULT -EXE1 = test1 -Description -= Calls _swab on a buffer, and checks that it has correctly swapped -= adjacent bytes - diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/_vsnprintf.h b/src/pal/tests/palsuite/c_runtime/_vsnprintf/_vsnprintf.h index 240a72f017..30e70648c3 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/_vsnprintf.h +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/_vsnprintf.h @@ -28,7 +28,7 @@ int Testvsnprintf(char* buf, size_t count, const char* format, ...) } -void DoStrTest(char *formatstr, char* param, char *checkstr) +void DoStrTest(const char *formatstr, char* param, const char *checkstr) { char buf[256] = { 0 }; @@ -41,7 +41,7 @@ void DoStrTest(char *formatstr, char* param, char *checkstr) } } -void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) +void DoWStrTest(const char *formatstr, WCHAR* param, const char *checkstr) { char buf[256] = { 0 }; @@ -55,7 +55,7 @@ void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) } -void DoCharTest(char *formatstr, char param, char *checkstr) +void DoCharTest(const char *formatstr, char param, const char *checkstr) { char buf[256] = { 0 }; @@ -68,7 +68,7 @@ void DoCharTest(char *formatstr, char param, char *checkstr) } } -void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) +void DoWCharTest(const char *formatstr, WCHAR param, const char *checkstr) { char buf[256] = { 0 }; @@ -81,7 +81,7 @@ void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) } } -void DoNumTest(char *formatstr, int value, char *checkstr) +void DoNumTest(const char *formatstr, int value, const char *checkstr) { char buf[256] = { 0 }; @@ -94,7 +94,7 @@ void DoNumTest(char *formatstr, int value, char *checkstr) } } -void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr) +void DoI64Test(const char *formatstr, INT64 value, char *valuestr, const char *checkstr) { char buf[256] = { 0 }; @@ -106,7 +106,7 @@ void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr) valuestr, formatstr, checkstr, buf); } } -void DoDoubleTest(char *formatstr, double value, char *checkstr1, char +void DoDoubleTest(const char *formatstr, double value, const char *checkstr1, char *checkstr2) { char buf[256] = { 0 }; diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/CMakeLists.txt index 7c346a4638..489b7bf566 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_vsnprintf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/test1.c deleted file mode 100644 index 88aeec27a5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/test1.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - char checkstr[] = "hello world"; - char buf[256] = { 0 }; - int ret; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - Testvsnprintf(buf, 256, "hello world"); - - if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) - { - Fail("ERROR: expected \"%s\" (up to %d chars), got \"%s\"\n", - checkstr, 256, buf); - } - - Testvsnprintf(buf, 256, "xxxxxxxxxxxxxxxxx"); - - ret = Testvsnprintf(buf, 8, "hello world"); - - if (ret >= 0) - { - Fail("ERROR: expected negative return value, got %d", ret); - } - if (memcmp(checkstr, buf, 8) != 0 || buf[8] != 'x') - { - Fail("ERROR: expected %s (up to %d chars), got %s\n", checkstr, 8, buf); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/test1.cpp new file mode 100644 index 0000000000..88aeec27a5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/test1.cpp @@ -0,0 +1,55 @@ +// 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: test1.c +** +** Purpose: Test #1 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + char checkstr[] = "hello world"; + char buf[256] = { 0 }; + int ret; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + Testvsnprintf(buf, 256, "hello world"); + + if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) + { + Fail("ERROR: expected \"%s\" (up to %d chars), got \"%s\"\n", + checkstr, 256, buf); + } + + Testvsnprintf(buf, 256, "xxxxxxxxxxxxxxxxx"); + + ret = Testvsnprintf(buf, 8, "hello world"); + + if (ret >= 0) + { + Fail("ERROR: expected negative return value, got %d", ret); + } + if (memcmp(checkstr, buf, 8) != 0 || buf[8] != 'x') + { + Fail("ERROR: expected %s (up to %d chars), got %s\n", checkstr, 8, buf); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/testinfo.dat index 0e97856927..f96bf084f2 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test1/testinfo.dat @@ -10,4 +10,4 @@ TYPE = DEFAULT EXE1 = test1 Description = Tests the PAL implementation of the _vsnprintf function. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/CMakeLists.txt index 00dccc260d..bc35dbd0c2 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_vsnprintf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/test10.c deleted file mode 100644 index 3099957ab7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/test10.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test10.c -** -** Purpose: Test #10 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %o", pos, "foo 52"); - DoNumTest("foo %lo", 0xFFFF, "foo 177777"); - DoNumTest("foo %ho", 0xFFFF, "foo 177777"); - DoNumTest("foo %Lo", pos, "foo 52"); - DoI64Test("foo %I64o", l, "42", "foo 52"); - DoNumTest("foo %3o", pos, "foo 52"); - DoNumTest("foo %-3o", pos, "foo 52 "); - DoNumTest("foo %.1o", pos, "foo 52"); - DoNumTest("foo %.3o", pos, "foo 052"); - DoNumTest("foo %03o", pos, "foo 052"); - DoNumTest("foo %#o", pos, "foo 052"); - DoNumTest("foo %+o", pos, "foo 52"); - DoNumTest("foo % o", pos, "foo 52"); - DoNumTest("foo %+o", neg, "foo 37777777726"); - DoNumTest("foo % o", neg, "foo 37777777726"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/test10.cpp new file mode 100644 index 0000000000..3099957ab7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/test10.cpp @@ -0,0 +1,50 @@ +// 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: test10.c +** +** Purpose: Test #10 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %o", pos, "foo 52"); + DoNumTest("foo %lo", 0xFFFF, "foo 177777"); + DoNumTest("foo %ho", 0xFFFF, "foo 177777"); + DoNumTest("foo %Lo", pos, "foo 52"); + DoI64Test("foo %I64o", l, "42", "foo 52"); + DoNumTest("foo %3o", pos, "foo 52"); + DoNumTest("foo %-3o", pos, "foo 52 "); + DoNumTest("foo %.1o", pos, "foo 52"); + DoNumTest("foo %.3o", pos, "foo 052"); + DoNumTest("foo %03o", pos, "foo 052"); + DoNumTest("foo %#o", pos, "foo 052"); + DoNumTest("foo %+o", pos, "foo 52"); + DoNumTest("foo % o", pos, "foo 52"); + DoNumTest("foo %+o", neg, "foo 37777777726"); + DoNumTest("foo % o", neg, "foo 37777777726"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/testinfo.dat index 1399afae05..a3d8eca54e 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test10/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test10 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with octal numbers. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/CMakeLists.txt index fd709f2a31..bf3dd9a534 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_vsnprintf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/test11.c deleted file mode 100644 index 74b0435c6d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/test11.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test11.c -** -** Purpose: Test #11 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %u", pos, "foo 42"); - DoNumTest("foo %lu", 0xFFFF, "foo 65535"); - DoNumTest("foo %hu", 0xFFFF, "foo 65535"); - DoNumTest("foo %Lu", pos, "foo 42"); - DoI64Test("foo %I64u", l, "42", "foo 42"); - DoNumTest("foo %3u", pos, "foo 42"); - DoNumTest("foo %-3u", pos, "foo 42 "); - DoNumTest("foo %.1u", pos, "foo 42"); - DoNumTest("foo %.3u", pos, "foo 042"); - DoNumTest("foo %03u", pos, "foo 042"); - DoNumTest("foo %#u", pos, "foo 42"); - DoNumTest("foo %+u", pos, "foo 42"); - DoNumTest("foo % u", pos, "foo 42"); - DoNumTest("foo %+u", neg, "foo 4294967254"); - DoNumTest("foo % u", neg, "foo 4294967254"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/test11.cpp new file mode 100644 index 0000000000..74b0435c6d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/test11.cpp @@ -0,0 +1,50 @@ +// 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: test11.c +** +** Purpose: Test #11 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %u", pos, "foo 42"); + DoNumTest("foo %lu", 0xFFFF, "foo 65535"); + DoNumTest("foo %hu", 0xFFFF, "foo 65535"); + DoNumTest("foo %Lu", pos, "foo 42"); + DoI64Test("foo %I64u", l, "42", "foo 42"); + DoNumTest("foo %3u", pos, "foo 42"); + DoNumTest("foo %-3u", pos, "foo 42 "); + DoNumTest("foo %.1u", pos, "foo 42"); + DoNumTest("foo %.3u", pos, "foo 042"); + DoNumTest("foo %03u", pos, "foo 042"); + DoNumTest("foo %#u", pos, "foo 42"); + DoNumTest("foo %+u", pos, "foo 42"); + DoNumTest("foo % u", pos, "foo 42"); + DoNumTest("foo %+u", neg, "foo 4294967254"); + DoNumTest("foo % u", neg, "foo 4294967254"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/testinfo.dat index faa7428eff..17e9f04946 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test11/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test11 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with unsigned numbers. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/CMakeLists.txt index 02dac0cb91..9fceeaf7a5 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_vsnprintf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/test12.c deleted file mode 100644 index 3718620971..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/test12.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test12.c -** -** Purpose: Test #12 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return (FAIL); - } - - DoNumTest("foo %x", pos, "foo 1234ab"); - DoNumTest("foo %lx", pos, "foo 1234ab"); - DoNumTest("foo %hx", pos, "foo 34ab"); - DoNumTest("foo %Lx", pos, "foo 1234ab"); - DoI64Test("foo %I64x", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7x", pos, "foo 1234ab"); - DoNumTest("foo %-7x", pos, "foo 1234ab "); - DoNumTest("foo %.1x", pos, "foo 1234ab"); - DoNumTest("foo %.7x", pos, "foo 01234ab"); - DoNumTest("foo %07x", pos, "foo 01234ab"); - DoNumTest("foo %#x", pos, "foo 0x1234ab"); - DoNumTest("foo %+x", pos, "foo 1234ab"); - DoNumTest("foo % x", pos, "foo 1234ab"); - DoNumTest("foo %+x", neg, "foo ffffffd6"); - DoNumTest("foo % x", neg, "foo ffffffd6"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/test12.cpp new file mode 100644 index 0000000000..3718620971 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/test12.cpp @@ -0,0 +1,52 @@ +// 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: test12.c +** +** Purpose: Test #12 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return (FAIL); + } + + DoNumTest("foo %x", pos, "foo 1234ab"); + DoNumTest("foo %lx", pos, "foo 1234ab"); + DoNumTest("foo %hx", pos, "foo 34ab"); + DoNumTest("foo %Lx", pos, "foo 1234ab"); + DoI64Test("foo %I64x", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7x", pos, "foo 1234ab"); + DoNumTest("foo %-7x", pos, "foo 1234ab "); + DoNumTest("foo %.1x", pos, "foo 1234ab"); + DoNumTest("foo %.7x", pos, "foo 01234ab"); + DoNumTest("foo %07x", pos, "foo 01234ab"); + DoNumTest("foo %#x", pos, "foo 0x1234ab"); + DoNumTest("foo %+x", pos, "foo 1234ab"); + DoNumTest("foo % x", pos, "foo 1234ab"); + DoNumTest("foo %+x", neg, "foo ffffffd6"); + DoNumTest("foo % x", neg, "foo ffffffd6"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/testinfo.dat index d48a5cc60d..82f58e4371 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test12/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test12 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with hex numbers (lowercase). -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/CMakeLists.txt index 52562c99f8..7e805f6ad4 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_vsnprintf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/test13.c deleted file mode 100644 index 1abada4033..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/test13.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test13.c -** -** Purpose: Test #13 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234AB; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %X", pos, "foo 1234AB"); - DoNumTest("foo %lX", pos, "foo 1234AB"); - DoNumTest("foo %hX", pos, "foo 34AB"); - DoNumTest("foo %LX", pos, "foo 1234AB"); - DoI64Test("foo %I64X", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7X", pos, "foo 1234AB"); - DoNumTest("foo %-7X", pos, "foo 1234AB "); - DoNumTest("foo %.1X", pos, "foo 1234AB"); - DoNumTest("foo %.7X", pos, "foo 01234AB"); - DoNumTest("foo %07X", pos, "foo 01234AB"); - DoNumTest("foo %#X", pos, "foo 0X1234AB"); - DoNumTest("foo %+X", pos, "foo 1234AB"); - DoNumTest("foo % X", pos, "foo 1234AB"); - DoNumTest("foo %+X", neg, "foo FFFFFFD6"); - DoNumTest("foo % X", neg, "foo FFFFFFD6"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/test13.cpp new file mode 100644 index 0000000000..1abada4033 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/test13.cpp @@ -0,0 +1,52 @@ +// 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: test13.c +** +** Purpose: Test #13 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234AB; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %X", pos, "foo 1234AB"); + DoNumTest("foo %lX", pos, "foo 1234AB"); + DoNumTest("foo %hX", pos, "foo 34AB"); + DoNumTest("foo %LX", pos, "foo 1234AB"); + DoI64Test("foo %I64X", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7X", pos, "foo 1234AB"); + DoNumTest("foo %-7X", pos, "foo 1234AB "); + DoNumTest("foo %.1X", pos, "foo 1234AB"); + DoNumTest("foo %.7X", pos, "foo 01234AB"); + DoNumTest("foo %07X", pos, "foo 01234AB"); + DoNumTest("foo %#X", pos, "foo 0X1234AB"); + DoNumTest("foo %+X", pos, "foo 1234AB"); + DoNumTest("foo % X", pos, "foo 1234AB"); + DoNumTest("foo %+X", neg, "foo FFFFFFD6"); + DoNumTest("foo % X", neg, "foo FFFFFFD6"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/testinfo.dat index a3f14c21dc..d308edf871 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test13/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test13 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with hex numbers (uppercase). -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/CMakeLists.txt index 3fc8c814a6..6e4566b577 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_vsnprintf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/test14.c deleted file mode 100644 index 2e98f6ad4e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/test14.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test14.c -** -** Purpose: Test #14 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", "foo 2.560000e+02 "); - DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); - DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", "foo 2.56000000e+02"); - DoDoubleTest("foo %014e", val, "foo 02.560000e+002", "foo 002.560000e+02"); - DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); - DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/test14.cpp new file mode 100644 index 0000000000..2e98f6ad4e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/test14.cpp @@ -0,0 +1,50 @@ +// 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: test14.c +** +** Purpose: Test #14 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", "foo 2.560000e+02 "); + DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); + DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", "foo 2.56000000e+02"); + DoDoubleTest("foo %014e", val, "foo 02.560000e+002", "foo 002.560000e+02"); + DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); + DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/testinfo.dat index f4d921c139..8d11b1d6ff 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test14/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test14 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with exponential format doubles (lowercase). -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/CMakeLists.txt index f6bdc83779..d9039b39b7 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_vsnprintf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/test15.c deleted file mode 100644 index 4d32e9c638..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/test15.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test15.c -** -** Purpose: Test #15 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", "foo 2.560000E+02 "); - DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); - DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", "foo 2.56000000E+02"); - DoDoubleTest("foo %014E", val, "foo 02.560000E+002", "foo 002.560000E+02"); - DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); - DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/test15.cpp new file mode 100644 index 0000000000..4d32e9c638 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/test15.cpp @@ -0,0 +1,49 @@ +// 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: test15.c +** +** Purpose: Test #15 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", "foo 2.560000E+02 "); + DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); + DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", "foo 2.56000000E+02"); + DoDoubleTest("foo %014E", val, "foo 02.560000E+002", "foo 002.560000E+02"); + DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); + DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/testinfo.dat index 3a6620ba46..913912508e 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test15/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test15 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with exponential format doubles (uppercase). -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/CMakeLists.txt index b7b06d19bb..b298df318b 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_vsnprintf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/test16.c deleted file mode 100644 index 118ba1453c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/test16.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test16.c -** -** Purpose: Test #16 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); - DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); - DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); - DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); - DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); - DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); - DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/test16.cpp new file mode 100644 index 0000000000..118ba1453c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/test16.cpp @@ -0,0 +1,49 @@ +// 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: test16.c +** +** Purpose: Test #16 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); + DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); + DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); + DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); + DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); + DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); + DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/testinfo.dat index 6363f294af..fc2f13071b 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test16/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test16 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with decimal point format doubles. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/CMakeLists.txt index 2c91cccd4a..b195f334d3 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_vsnprintf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/test17.c deleted file mode 100644 index 9b5063ddf0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/test17.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test17.c -** -** Purpose: Test #17 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); - DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); - DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/test17.cpp new file mode 100644 index 0000000000..9b5063ddf0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/test17.cpp @@ -0,0 +1,50 @@ +// 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: test17.c +** +** Purpose: Test #17 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); + DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); + DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/testinfo.dat index ecec515de3..aeb924495c 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test17/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test17 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with compact format doubles (lowercase). -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/CMakeLists.txt index 1a06ce01ee..f0f6d1124e 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test18.c + test18.cpp ) add_executable(paltest_vsnprintf_test18 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/test18.c deleted file mode 100644 index 5232befc7f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/test18.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); - DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); - DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/test18.cpp new file mode 100644 index 0000000000..5232befc7f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/test18.cpp @@ -0,0 +1,50 @@ +// 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: test18.c +** +** Purpose: Test #18 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); + DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); + DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/testinfo.dat index 34fd7ae2ff..57aaed5953 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test18/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test18 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with compact format doubles (uppercase). -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/CMakeLists.txt index 6f2e42cc6b..44b38902ef 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test19.c + test19.cpp ) add_executable(paltest_vsnprintf_test19 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/test19.c deleted file mode 100644 index 075a528aba..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/test19.c +++ /dev/null @@ -1,103 +0,0 @@ -// 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: test19.c -** -** Purpose: Test #19 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -#define DOTEST(a,b,c,d,e) DoTest(a,b,(void*)c,d,e) - -void DoArgumentPrecTest(char *formatstr, int precision, void *param, - char *paramstr, char *checkstr1, char *checkstr2) -{ - char buf[256]; - - Testvsnprintf(buf,256,formatstr, precision, param); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && - memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - paramstr, formatstr, precision, checkstr1, checkstr2, buf); - } - -} - -void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param, - char *checkstr1, char *checkstr2) -{ - char buf[256]; - - Testvsnprintf(buf,256,formatstr, precision, param); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && - memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) - { - Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - param, formatstr, precision, checkstr1, checkstr2, buf); - } - -} - - - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - - DoArgumentPrecTest("%.*s", 2, "bar", "bar", "ba", "ba"); - DoArgumentPrecTest("%.*S", 2, convert("bar"), "bar", "ba", "ba"); - DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); - DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); - DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); - DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); - - - DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); - DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); - DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); - DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); - DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); - DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); - DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); - DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); - DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); - DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/test19.cpp new file mode 100644 index 0000000000..211354bc3a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/test19.cpp @@ -0,0 +1,103 @@ +// 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: test19.c +** +** Purpose: Test #19 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +#define DOTEST(a,b,c,d,e) DoTest(a,b,(void*)c,d,e) + +void DoArgumentPrecTest(char *formatstr, int precision, void *param, + char *paramstr, char *checkstr1, char *checkstr2) +{ + char buf[256]; + + Testvsnprintf(buf,256,formatstr, precision, param); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && + memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + paramstr, formatstr, precision, checkstr1, checkstr2, buf); + } + +} + +void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param, + char *checkstr1, char *checkstr2) +{ + char buf[256]; + + Testvsnprintf(buf,256,formatstr, precision, param); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && + memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + param, formatstr, precision, checkstr1, checkstr2, buf); + } + +} + + + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + + DoArgumentPrecTest("%.*s", 2, (void*)"bar", "bar", "ba", "ba"); + DoArgumentPrecTest("%.*S", 2, (void*)convert("bar"), "bar", "ba", "ba"); + DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); + DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); + DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); + DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); + + + DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); + DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); + DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); + DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); + DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); + DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); + DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); + DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); + DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); + DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/testinfo.dat index 05f4b5bd87..cda8966865 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test19/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test19 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with argument specified precision. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/CMakeLists.txt index a3871d64cf..1d3910e70c 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_vsnprintf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/test2.c deleted file mode 100644 index 4bac4d2c83..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/test2.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR szwStr[] = {'b','a','r','\0'}; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoStrTest("foo %s", "bar", "foo bar"); - DoStrTest("foo %hs", "bar", "foo bar"); - DoWStrTest("foo %ls", szwStr, "foo bar"); - DoWStrTest("foo %ws", szwStr, "foo bar"); - DoStrTest("foo %Ls", "bar", "foo bar"); - DoStrTest("foo %I64s", "bar", "foo bar"); - DoStrTest("foo %5s", "bar", "foo bar"); - DoStrTest("foo %.2s", "bar", "foo ba"); - DoStrTest("foo %5.2s", "bar", "foo ba"); - DoStrTest("foo %-5s", "bar", "foo bar "); - DoStrTest("foo %05s", "bar", "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/test2.cpp new file mode 100644 index 0000000000..4bac4d2c83 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/test2.cpp @@ -0,0 +1,44 @@ +// 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: test2.c +** +** Purpose: Test #2 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR szwStr[] = {'b','a','r','\0'}; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoStrTest("foo %s", "bar", "foo bar"); + DoStrTest("foo %hs", "bar", "foo bar"); + DoWStrTest("foo %ls", szwStr, "foo bar"); + DoWStrTest("foo %ws", szwStr, "foo bar"); + DoStrTest("foo %Ls", "bar", "foo bar"); + DoStrTest("foo %I64s", "bar", "foo bar"); + DoStrTest("foo %5s", "bar", "foo bar"); + DoStrTest("foo %.2s", "bar", "foo ba"); + DoStrTest("foo %5.2s", "bar", "foo ba"); + DoStrTest("foo %-5s", "bar", "foo bar "); + DoStrTest("foo %05s", "bar", "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/testinfo.dat index 5ee925e3f6..6e8f03e639 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test2/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test2 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with strings. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/CMakeLists.txt index 1beae06277..62d765ec5f 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_vsnprintf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/test3.c deleted file mode 100644 index 2b30c9ad99..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/test3.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoWStrTest("foo %S", convert("bar"), "foo bar"); - DoStrTest("foo %hS", "bar", "foo bar"); - DoWStrTest("foo %lS", convert("bar"), "foo bar"); - DoWStrTest("foo %wS", convert("bar"), "foo bar"); - DoWStrTest("foo %LS", convert("bar"), "foo bar"); - DoWStrTest("foo %I64S", convert("bar"), "foo bar"); - DoWStrTest("foo %5S", convert("bar"), "foo bar"); - DoWStrTest("foo %.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %-5S", convert("bar"), "foo bar "); - DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/test3.cpp new file mode 100644 index 0000000000..2b30c9ad99 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/test3.cpp @@ -0,0 +1,43 @@ +// 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: test3.c +** +** Purpose: Test #3 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoWStrTest("foo %S", convert("bar"), "foo bar"); + DoStrTest("foo %hS", "bar", "foo bar"); + DoWStrTest("foo %lS", convert("bar"), "foo bar"); + DoWStrTest("foo %wS", convert("bar"), "foo bar"); + DoWStrTest("foo %LS", convert("bar"), "foo bar"); + DoWStrTest("foo %I64S", convert("bar"), "foo bar"); + DoWStrTest("foo %5S", convert("bar"), "foo bar"); + DoWStrTest("foo %.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %-5S", convert("bar"), "foo bar "); + DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/testinfo.dat index 626949c7c8..638cef69ef 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test3/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test3 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with wide strings. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/CMakeLists.txt index daf7757ddb..5662bd57ad 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_vsnprintf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/test4.c deleted file mode 100644 index 33fc49deba..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/test4.c +++ /dev/null @@ -1,98 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -static void DoPointerTest(char *formatstr, void* param, char* paramstr, - char *checkstr1) -{ - char buf[256] = { 0 }; - - Testvsnprintf(buf,256, formatstr, param); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - paramstr, formatstr, checkstr1, buf); - } -} - -static void DoI64DoubleTest(char *formatstr, INT64 value, char *valuestr, char -*checkstr1) -{ - char buf[256] = { 0 }; - - Testvsnprintf(buf,256,formatstr, value); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\"\n" - "Expected \"%s\", got \"%s\".\n", - valuestr, formatstr, checkstr1, buf); - } -} - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - - /* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "0000000000000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64DoubleTest("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); - -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "00000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64DoubleTest("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); -#endif - - - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/test4.cpp new file mode 100644 index 0000000000..33fc49deba --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/test4.cpp @@ -0,0 +1,98 @@ +// 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: test4.c +** +** Purpose: Test #4 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +static void DoPointerTest(char *formatstr, void* param, char* paramstr, + char *checkstr1) +{ + char buf[256] = { 0 }; + + Testvsnprintf(buf,256, formatstr, param); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + paramstr, formatstr, checkstr1, buf); + } +} + +static void DoI64DoubleTest(char *formatstr, INT64 value, char *valuestr, char +*checkstr1) +{ + char buf[256] = { 0 }; + + Testvsnprintf(buf,256,formatstr, value); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", + valuestr, formatstr, checkstr1, buf); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + + /* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "0000000000000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64DoubleTest("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); + +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "00000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64DoubleTest("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); +#endif + + + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/testinfo.dat index bdfdef85ae..03ff2931bc 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test4/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test4 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with pointers. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/CMakeLists.txt index c255b07b42..92540541f3 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_vsnprintf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/test5.c deleted file mode 100644 index 534e42e293..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/test5.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -static void DoTest(char *formatstr, int param, char *checkstr) -{ - char buf[256] = { 0 }; - int n = -1; - - Testvsnprintf(buf, 256, formatstr, &n); - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - param, n); - } - if (memcmp(buf, checkstr, strlen(buf) + 1) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); - } -} - -static void DoShortTest(char *formatstr, int param, char *checkstr) -{ - char buf[256] = { 0 }; - short int n = -1; - - Testvsnprintf(buf, 256, formatstr, &n); - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - param, n); - } - if (memcmp(buf, checkstr, strlen(buf) + 1) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); - } -} - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoTest("foo %n bar", 4, "foo bar"); - DoTest("foo %#n bar", 4, "foo bar"); - DoTest("foo % n bar", 4, "foo bar"); - DoTest("foo %+n bar", 4, "foo bar"); - DoTest("foo %-n bar", 4, "foo bar"); - DoTest("foo %0n bar", 4, "foo bar"); - DoShortTest("foo %hn bar", 4, "foo bar"); - DoTest("foo %ln bar", 4, "foo bar"); - DoTest("foo %Ln bar", 4, "foo bar"); - DoTest("foo %I64n bar", 4, "foo bar"); - DoTest("foo %20.3n bar", 4, "foo bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/test5.cpp new file mode 100644 index 0000000000..534e42e293 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/test5.cpp @@ -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: test5.c +** +** Purpose: Test #5 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +static void DoTest(char *formatstr, int param, char *checkstr) +{ + char buf[256] = { 0 }; + int n = -1; + + Testvsnprintf(buf, 256, formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + param, n); + } + if (memcmp(buf, checkstr, strlen(buf) + 1) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); + } +} + +static void DoShortTest(char *formatstr, int param, char *checkstr) +{ + char buf[256] = { 0 }; + short int n = -1; + + Testvsnprintf(buf, 256, formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + param, n); + } + if (memcmp(buf, checkstr, strlen(buf) + 1) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoTest("foo %n bar", 4, "foo bar"); + DoTest("foo %#n bar", 4, "foo bar"); + DoTest("foo % n bar", 4, "foo bar"); + DoTest("foo %+n bar", 4, "foo bar"); + DoTest("foo %-n bar", 4, "foo bar"); + DoTest("foo %0n bar", 4, "foo bar"); + DoShortTest("foo %hn bar", 4, "foo bar"); + DoTest("foo %ln bar", 4, "foo bar"); + DoTest("foo %Ln bar", 4, "foo bar"); + DoTest("foo %I64n bar", 4, "foo bar"); + DoTest("foo %20.3n bar", 4, "foo bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/testinfo.dat index 3cd3f7ee86..c3848824f1 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test5/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test5 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with the count specifier. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/CMakeLists.txt index 8e041f4af8..d80d433c22 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_vsnprintf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/test6.c deleted file mode 100644 index 103d1181c2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/test6.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoCharTest("foo %c", 'b', "foo b"); - DoCharTest("foo %hc", 'b', "foo b"); - DoWCharTest("foo %lc", wc, "foo c"); - DoCharTest("foo %Lc", 'b', "foo b"); - DoCharTest("foo %I64c", 'b', "foo b"); - DoCharTest("foo %5c", 'b', "foo b"); - DoCharTest("foo %.0c", 'b', "foo b"); - DoCharTest("foo %-5c", 'b', "foo b "); - DoCharTest("foo %05c", 'b', "foo 0000b"); - DoCharTest("foo % c", 'b', "foo b"); - DoCharTest("foo %#c", 'b', "foo b"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/test6.cpp new file mode 100644 index 0000000000..103d1181c2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/test6.cpp @@ -0,0 +1,44 @@ +// 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: test6.c +** +** Purpose: Test #6 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoCharTest("foo %c", 'b', "foo b"); + DoCharTest("foo %hc", 'b', "foo b"); + DoWCharTest("foo %lc", wc, "foo c"); + DoCharTest("foo %Lc", 'b', "foo b"); + DoCharTest("foo %I64c", 'b', "foo b"); + DoCharTest("foo %5c", 'b', "foo b"); + DoCharTest("foo %.0c", 'b', "foo b"); + DoCharTest("foo %-5c", 'b', "foo b "); + DoCharTest("foo %05c", 'b', "foo 0000b"); + DoCharTest("foo % c", 'b', "foo b"); + DoCharTest("foo %#c", 'b', "foo b"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/testinfo.dat index e379e0b3b8..e375f9238d 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test6/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test6 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with characters. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/CMakeLists.txt index 01f9620184..a1dc0a7c2c 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_vsnprintf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/test7.c deleted file mode 100644 index c7e45d67fa..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/test7.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test7.c -** -** Purpose: Test #7 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoWCharTest("foo %c", wb, "foo b"); - DoWCharTest("foo %hc", wb, "foo b"); - DoCharTest("foo %lc", 'c', "foo c"); - DoWCharTest("foo %Lc", wb, "foo b"); - DoWCharTest("foo %I64c", wb, "foo b"); - DoWCharTest("foo %5c", wb, "foo b"); - DoWCharTest("foo %.0c", wb, "foo b"); - DoWCharTest("foo %-5c", wb, "foo b "); - DoWCharTest("foo %05c", wb, "foo 0000b"); - DoWCharTest("foo % c", wb, "foo b"); - DoWCharTest("foo %#c", wb, "foo b"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/test7.cpp new file mode 100644 index 0000000000..c7e45d67fa --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/test7.cpp @@ -0,0 +1,44 @@ +// 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: test7.c +** +** Purpose: Test #7 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoWCharTest("foo %c", wb, "foo b"); + DoWCharTest("foo %hc", wb, "foo b"); + DoCharTest("foo %lc", 'c', "foo c"); + DoWCharTest("foo %Lc", wb, "foo b"); + DoWCharTest("foo %I64c", wb, "foo b"); + DoWCharTest("foo %5c", wb, "foo b"); + DoWCharTest("foo %.0c", wb, "foo b"); + DoWCharTest("foo %-5c", wb, "foo b "); + DoWCharTest("foo %05c", wb, "foo 0000b"); + DoWCharTest("foo % c", wb, "foo b"); + DoWCharTest("foo %#c", wb, "foo b"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/testinfo.dat index 90749400a5..09eb481b59 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test7/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test7 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with wide characters. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/CMakeLists.txt index 9c525de15a..1ca4732492 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_vsnprintf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/test8.c deleted file mode 100644 index 2cefbeac25..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/test8.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test8.c -** -** Purpose: Test #8 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %d", pos, "foo 42"); - DoNumTest("foo %ld", 0xFFFF, "foo 65535"); - DoNumTest("foo %hd", 0xFFFF, "foo -1"); - DoNumTest("foo %Ld", pos, "foo 42"); - DoI64Test("foo %I64d", l, "42", "foo 42"); - DoNumTest("foo %3d", pos, "foo 42"); - DoNumTest("foo %-3d", pos, "foo 42 "); - DoNumTest("foo %.1d", pos, "foo 42"); - DoNumTest("foo %.3d", pos, "foo 042"); - DoNumTest("foo %03d", pos, "foo 042"); - DoNumTest("foo %#d", pos, "foo 42"); - DoNumTest("foo %+d", pos, "foo +42"); - DoNumTest("foo % d", pos, "foo 42"); - DoNumTest("foo %+d", neg, "foo -42"); - DoNumTest("foo % d", neg, "foo -42"); - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/test8.cpp new file mode 100644 index 0000000000..2cefbeac25 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/test8.cpp @@ -0,0 +1,52 @@ +// 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: test8.c +** +** Purpose: Test #8 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %d", pos, "foo 42"); + DoNumTest("foo %ld", 0xFFFF, "foo 65535"); + DoNumTest("foo %hd", 0xFFFF, "foo -1"); + DoNumTest("foo %Ld", pos, "foo 42"); + DoI64Test("foo %I64d", l, "42", "foo 42"); + DoNumTest("foo %3d", pos, "foo 42"); + DoNumTest("foo %-3d", pos, "foo 42 "); + DoNumTest("foo %.1d", pos, "foo 42"); + DoNumTest("foo %.3d", pos, "foo 042"); + DoNumTest("foo %03d", pos, "foo 042"); + DoNumTest("foo %#d", pos, "foo 42"); + DoNumTest("foo %+d", pos, "foo +42"); + DoNumTest("foo % d", pos, "foo 42"); + DoNumTest("foo %+d", neg, "foo -42"); + DoNumTest("foo % d", neg, "foo -42"); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/testinfo.dat index 0afc334a67..1bdf411983 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test8/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test8 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with decimal numbers. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/CMakeLists.txt index bfe2572a6d..583971fe5a 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_vsnprintf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/test9.c deleted file mode 100644 index d2cd8165c0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/test9.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test9.c -** -** Purpose: Test #9 for the _vsnprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %i", pos, "foo 42"); - DoNumTest("foo %li", 0xFFFF, "foo 65535"); - DoNumTest("foo %hi", 0xFFFF, "foo -1"); - DoNumTest("foo %Li", pos, "foo 42"); - DoI64Test("foo %I64i", l, "42", "foo 42"); - DoNumTest("foo %3i", pos, "foo 42"); - DoNumTest("foo %-3i", pos, "foo 42 "); - DoNumTest("foo %.1i", pos, "foo 42"); - DoNumTest("foo %.3i", pos, "foo 042"); - DoNumTest("foo %03i", pos, "foo 042"); - DoNumTest("foo %#i", pos, "foo 42"); - DoNumTest("foo %+i", pos, "foo +42"); - DoNumTest("foo % i", pos, "foo 42"); - DoNumTest("foo %+i", neg, "foo -42"); - DoNumTest("foo % i", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/test9.cpp new file mode 100644 index 0000000000..d2cd8165c0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/test9.cpp @@ -0,0 +1,51 @@ +// 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: test9.c +** +** Purpose: Test #9 for the _vsnprintf function. +** +** +**===================================================================*/ + +#include +#include "../_vsnprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %i", pos, "foo 42"); + DoNumTest("foo %li", 0xFFFF, "foo 65535"); + DoNumTest("foo %hi", 0xFFFF, "foo -1"); + DoNumTest("foo %Li", pos, "foo 42"); + DoI64Test("foo %I64i", l, "42", "foo 42"); + DoNumTest("foo %3i", pos, "foo 42"); + DoNumTest("foo %-3i", pos, "foo 42 "); + DoNumTest("foo %.1i", pos, "foo 42"); + DoNumTest("foo %.3i", pos, "foo 042"); + DoNumTest("foo %03i", pos, "foo 042"); + DoNumTest("foo %#i", pos, "foo 42"); + DoNumTest("foo %+i", pos, "foo +42"); + DoNumTest("foo % i", pos, "foo 42"); + DoNumTest("foo %+i", neg, "foo -42"); + DoNumTest("foo % i", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/testinfo.dat index 125724a36b..bdaae87ce8 100644 --- a/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/_vsnprintf/test9/testinfo.dat @@ -11,4 +11,4 @@ EXE1 = test9 Description = Tests the PAL implementation of the _vsnprintf function. = Tests _vsnprintf with integer numbers. -= This test is modeled after _snprintf. += This test is modeled after sprintf_s. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/CMakeLists.txt deleted file mode 100644 index cafb9536b0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) -add_subdirectory(test10) -add_subdirectory(test11) -add_subdirectory(test12) -add_subdirectory(test13) -add_subdirectory(test14) -add_subdirectory(test15) -add_subdirectory(test16) -add_subdirectory(test17) -add_subdirectory(test18) -add_subdirectory(test19) -add_subdirectory(test2) -add_subdirectory(test3) -add_subdirectory(test4) -add_subdirectory(test5) -add_subdirectory(test6) -add_subdirectory(test7) -add_subdirectory(test8) -add_subdirectory(test9) - diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/_vsnwprintf.h b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/_vsnwprintf.h deleted file mode 100644 index a3a932f822..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/_vsnwprintf.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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: _vsnwprintf.h -** -** Purpose: Containts common testing functions for _vsnwprintf -** -** -**==========================================================================*/ - -#ifndef ___VSNWPRINTF_H__ -#define ___VSNWPRINTF_H__ - -/* These functions leaks memory like crazy. C'est la vie. */ -int TestVsnwprintf(wchar_t* buf, size_t count, const wchar_t* format, ...) -{ - int retVal = 0; - va_list arglist; - - va_start(arglist, format); - retVal = _vsnwprintf(buf, count, format, arglist); - va_end(arglist); - - return( retVal); -} - - -void DoWStrTest(WCHAR *formatstr, WCHAR *param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - - TestVsnwprintf(buf, 256, formatstr, param); - - if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0) - { - Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" - "Expected \"%s\", got \"%s\".\n", - convertC(param), convertC(formatstr), - convertC(checkstr), convertC(buf)); - } -} - -void DoStrTest(WCHAR *formatstr, char *param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - - TestVsnwprintf(buf, 256, formatstr, param); - - if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0) - { - Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" - "Expected \"%s\", got \"%s\".\n", - param, convertC(formatstr), convertC(checkstr), - convertC(buf)); - } -} - -void DoCharTest(WCHAR *formatstr, char param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - - TestVsnwprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0) - { - Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - param, param, convertC(formatstr), convertC(checkstr), - convertC(buf)); - } -} - -void DoWCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - - TestVsnwprintf(buf, 256, formatstr, param); - if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0) - { - Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - (char) param, param, convertC(formatstr), - convertC(checkstr), convertC(buf)); - } -} - -void DoNumTest(WCHAR *formatstr, int value, WCHAR*checkstr) -{ - WCHAR buf[256] = { 0 }; - - TestVsnwprintf(buf, 256, formatstr, value); - if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0) - { - Fail("ERROR: failed to insert %#x into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", value, convertC(formatstr), - convertC(checkstr), convertC(buf)); - } -} - -void DoI64NumTest(WCHAR *formatstr, INT64 value, char *valuestr, WCHAR*checkstr) -{ - WCHAR buf[256] = { 0 }; - - TestVsnwprintf(buf, 256, formatstr, value); - if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", valuestr, convertC(formatstr), - convertC(checkstr), convertC(buf)); - } -} -void DoDoubleTest(WCHAR *formatstr, double value, - WCHAR *checkstr1, WCHAR *checkstr2) -{ - WCHAR buf[256] = { 0 }; - - TestVsnwprintf(buf, 256, formatstr, value); - if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && - memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) - { - Fail("ERROR: failed to insert %f into \"%s\"\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - value, - convertC(formatstr), - convertC(checkstr1), - convertC(checkstr2), - convertC(buf)); - } -} - -#endif diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/CMakeLists.txt deleted file mode 100644 index 52c442d572..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_vsnwprintf_test1 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test1 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/test1.c deleted file mode 100644 index 0238e42611..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/test1.c +++ /dev/null @@ -1,60 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -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(buf, 256, checkstr); - if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0) - { - Fail("ERROR: Expected \"%s\", got \"%s\"\n", - convertC(checkstr), convertC(buf)); - } - - TestVsnwprintf(buf, 256, convert("xxxxxxxxxxxxxxxxx")); - ret = TestVsnwprintf(buf, 8, checkstr); - if (memcmp(checkstr, buf, 16) != 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; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/testinfo.dat deleted file mode 100644 index d806fb8ed8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test1/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test1 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= General test to see if _vsnwprintf works correctly. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/CMakeLists.txt deleted file mode 100644 index 86ea1a3160..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test10.c -) - -add_executable(paltest_vsnwprintf_test10 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test10 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test10 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/test10.c deleted file mode 100644 index 6e188e56ff..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/test10.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test10.c -** -** Purpose: Test #10 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %o"), pos, convert("foo 52")); - DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); - DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); - DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); - DoI64NumTest(convert("foo %I64o"), l, "42", convert("foo 52")); - DoNumTest(convert("foo %3o"), pos, convert("foo 52")); - DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); - DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); - DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); - DoNumTest(convert("foo %03o"), pos, convert("foo 052")); - DoNumTest(convert("foo %#o"), pos, convert("foo 052")); - DoNumTest(convert("foo %+o"), pos, convert("foo 52")); - DoNumTest(convert("foo % o"), pos, convert("foo 52")); - DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); - DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/testinfo.dat deleted file mode 100644 index beb5b41be9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test10/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test10 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with octal numbers. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/CMakeLists.txt deleted file mode 100644 index c6011dc1de..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test11.c -) - -add_executable(paltest_vsnwprintf_test11 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test11 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test11 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/test11.c deleted file mode 100644 index af54985bdc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/test11.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test11.c -** -** Purpose: Test #11 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %u"), pos, convert("foo 42")); - DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); - DoI64NumTest(convert("foo %I64u"), l, "42", convert("foo 42")); - DoNumTest(convert("foo %3u"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); - DoNumTest(convert("foo %03u"), pos, convert("foo 042")); - DoNumTest(convert("foo %#u"), pos, convert("foo 42")); - DoNumTest(convert("foo %+u"), pos, convert("foo 42")); - DoNumTest(convert("foo % u"), pos, convert("foo 42")); - DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); - DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/testinfo.dat deleted file mode 100644 index 083b0fa5af..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test11/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test11 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with unsigned numbers. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/CMakeLists.txt deleted file mode 100644 index bd9652c2fb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test12.c -) - -add_executable(paltest_vsnwprintf_test12 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test12 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test12 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/test12.c deleted file mode 100644 index b593a82b4b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/test12.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test12.c -** -** Purpose: Test #12 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); - DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); - DoI64NumTest(convert("foo %I64x"), l, "0x1234567887654321", - convert("foo 1234567887654321")); - DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); - DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); - DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); - DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); - DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); - DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/testinfo.dat deleted file mode 100644 index a4450ed8d0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test12/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test12 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with hex numbers (lowercase). -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/CMakeLists.txt deleted file mode 100644 index c608ab84e3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test13.c -) - -add_executable(paltest_vsnwprintf_test13 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test13 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test13 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/test13.c deleted file mode 100644 index 59a9dc496f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/test13.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test13.c -** -** Purpose: Test #13 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); - DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); - DoI64NumTest(convert("foo %I64X"), l, "0x1234567887654321", - convert("foo 1234567887654321")); - DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); - DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); - DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); - DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); - DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); - DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/testinfo.dat deleted file mode 100644 index fa54ae8a62..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test13/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test13 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with hex numbers (uppercase). -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/CMakeLists.txt deleted file mode 100644 index 3bf157a2b3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test14.c -) - -add_executable(paltest_vsnwprintf_test14 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test14 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test14 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/test14.c deleted file mode 100644 index 633f9d68ae..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/test14.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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: test14.c -** -** Purpose: Test #14 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), - convert("foo 2.560000e+02 ")); - DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), - convert("foo 2.6e+02")); - DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), - convert("foo 2.56000000e+02")); - DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), - convert("foo 002.560000e+02")); - DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), - convert("foo +2.560000e+02")); - DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), - convert("foo -2.560000e+02")); - DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), - convert("foo -2.560000e+02")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/testinfo.dat deleted file mode 100644 index 0796f5e81c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test14/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test14 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with exponential format doubles (lowercase). -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/CMakeLists.txt deleted file mode 100644 index eedc7bb9db..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test15.c -) - -add_executable(paltest_vsnwprintf_test15 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test15 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test15 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/test15.c deleted file mode 100644 index 0af41fe1dc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/test15.c +++ /dev/null @@ -1,64 +0,0 @@ -// 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: test15.c -** -** Purpose: Test #15 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), - convert("foo 2.560000E+02 ")); - DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), - convert("foo 2.6E+02")); - DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), - convert("foo 2.56000000E+02")); - DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), - convert("foo 002.560000E+02")); - DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), - convert("foo +2.560000E+02")); - DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), - convert("foo -2.560000E+02")); - DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), - convert("foo -2.560000E+002")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/testinfo.dat deleted file mode 100644 index 9de3c83b8a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test15/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test15 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with exponential format doubles (uppercase). -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/CMakeLists.txt deleted file mode 100644 index a469c497e9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test16.c -) - -add_executable(paltest_vsnwprintf_test16 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test16 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test16 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/test16.c deleted file mode 100644 index 77571b01b3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/test16.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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: test16.c -** -** Purpose: Test #16 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), - convert("foo 2560.001000 ")); - DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), - convert("foo 2560.0")); - DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), - convert("foo 2560.00100000")); - DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), - convert("foo 02560.001000")); - DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), - convert("foo +2560.001000")); - DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), - convert("foo -2560.001000")); - DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), - convert("foo -2560.001000")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/testinfo.dat deleted file mode 100644 index b7134c785b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test16/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test16 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with decimal point format doubles. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/CMakeLists.txt deleted file mode 100644 index f429e94417..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test17.c -) - -add_executable(paltest_vsnwprintf_test17 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test17 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test17 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/test17.c deleted file mode 100644 index 3a9d70ad03..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/test17.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test17.c -** -** Purpose: Test #17 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), - convert("foo 2560 ")); - DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), - convert("foo 3e+03")); - DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), - convert("foo 2.6e+03")); - DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), - convert("foo 2560.001")); - DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), - convert("foo 002560")); - DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), - convert("foo 2560.00")); - DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), - convert("foo +2560")); - DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), - convert("foo -2560")); - DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), - convert("foo -2560")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/testinfo.dat deleted file mode 100644 index 5d5553151e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test17/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test17 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with compact format doubles (lowercase). -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/CMakeLists.txt deleted file mode 100644 index 25dd6a2c5b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test18.c -) - -add_executable(paltest_vsnwprintf_test18 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test18 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test18 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/test18.c deleted file mode 100644 index 03f9870113..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/test18.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), - convert("foo 2560 ")); - DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), - convert("foo 3E+03")); - DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), - convert("foo 2.6E+03")); - DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), - convert("foo 2560.001")); - DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), - convert("foo 002560")); - DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), - convert("foo 2560.00")); - DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), - convert("foo +2560")); - DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), - convert("foo -2560")); - DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), - convert("foo -2560")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/testinfo.dat deleted file mode 100644 index f56c80980d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test18/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test18 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with compact format doubles (uppercase). -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/CMakeLists.txt deleted file mode 100644 index 9c636b8b0a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test19.c -) - -add_executable(paltest_vsnwprintf_test19 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test19 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test19 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/test19.c deleted file mode 100644 index fea275a242..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/test19.c +++ /dev/null @@ -1,139 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -#define DOTEST(a,b,c,d,e) DoTest(a,b,(void*)c,d,e) - -void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, - WCHAR *paramstr, 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 %s into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - paramstr, - convertC(formatstr), - precision, - convertC(checkstr1), - convertC(checkstr2), - convertC(buf)); - } -} -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)); - } -} - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoArgumentPrecTest(convert("%.*s"), 2, convert("bar"), convert("bar"), - convert("ba"), convert("ba")); - DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', convert("a"), - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', convert("a"), - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', convert("a"), - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', convert("a"), - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, convert("42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, convert("42"), - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, convert("42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, convert("42"), - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, convert("42"), - convert("52"), convert("52")); - DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, convert("42"), - convert("052"), convert("052")); - DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, convert("42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, convert("42"), - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, convert("0x42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, convert("0x42"), - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, convert("0x42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, convert("0x42"), - convert("042"), convert("042")); - - - DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000"), - convert("2.0e+00")); - DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000"), - convert("2.010e+00")); - DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000"), - convert("2.0E+00")); - DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000"), - convert("2.010E+00")); - DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0"), - convert("2.0")); - DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010"), - convert("2.010")); - DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002"), - convert("3e+02")); - DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01"), - convert("256.01")); - DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002"), - convert("3E+02")); - DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01"), - convert("256.01")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/testinfo.dat deleted file mode 100644 index 77178f1471..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test19/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test19 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with argument specified precision. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/CMakeLists.txt deleted file mode 100644 index 817657ea61..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test2.c -) - -add_executable(paltest_vsnwprintf_test2 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test2 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test2 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/test2.c deleted file mode 100644 index 20499954db..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/test2.c +++ /dev/null @@ -1,40 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); - DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); - DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); - DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); - DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); - DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/testinfo.dat deleted file mode 100644 index 429911bd83..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test2/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test2 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with strings. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/CMakeLists.txt deleted file mode 100644 index 4af3e36f3b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test3.c -) - -add_executable(paltest_vsnwprintf_test3 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test3 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test3 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/test3.c deleted file mode 100644 index 9a37d3fc4b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/test3.c +++ /dev/null @@ -1,40 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoStrTest(convert("foo %S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); - DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); - DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); - DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); - DoStrTest(convert("foo %5.2S"), "bar", convert("foo ba")); - DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); - DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/testinfo.dat deleted file mode 100644 index d4e2686763..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test3/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test3 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with wide strings. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/CMakeLists.txt deleted file mode 100644 index b7ff9e7bb3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test4.c -) - -add_executable(paltest_vsnwprintf_test4 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test4 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test4 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/test4.c deleted file mode 100644 index 6f39be2a80..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/test4.c +++ /dev/null @@ -1,121 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ -static void DoPointerTest(WCHAR *formatstr, void* param, WCHAR* paramstr, - WCHAR *checkstr1) -{ - WCHAR buf[256] = { 0 }; - - TestVsnwprintf(buf, 256, 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)); - } -} - -static void DoI64DoubleTest(WCHAR *formatstr, INT64 value, WCHAR *valuestr, - WCHAR *checkstr1) -{ - WCHAR buf[256] = { 0 }; - - TestVsnwprintf(buf, 256, 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[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000")); - DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), - convert("0000000000123456")); - DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), - convert(" 0000000000123456")); - DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), - convert(" 0000000000123456")); - DoPointerTest(convert("%-17p"), ptr, convert("pointer to 0x123456"), - convert("0000000000123456 ")); - DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), - convert("0000000000123456")); - DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), - convert("0X0000000000123456")); - DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), - convert("00003456")); - DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoI64DoubleTest(convert("%I64p"), lptr, - convert("pointer to 0x1234567887654321"), - convert("1234567887654321")); - -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000")); - DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoPointerTest(convert("%9p"), ptr, convert("pointer to 0x123456"), - convert(" 00123456")); - DoPointerTest(convert("%09p"), ptr, convert("pointer to 0x123456"), - convert(" 00123456")); - DoPointerTest(convert("%-9p"), ptr, convert("pointer to 0x123456"), - convert("00123456 ")); - DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), - convert("0X00123456")); - DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), - convert("00003456")); - DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoI64DoubleTest(convert("%I64p"), lptr, - convert("pointer to 0x1234567887654321"), - convert("1234567887654321")); -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/testinfo.dat deleted file mode 100644 index 56f488a66a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test4/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test4 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with pointers. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/CMakeLists.txt deleted file mode 100644 index 9b316b9f90..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test5.c -) - -add_executable(paltest_vsnwprintf_test5 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test5 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test5 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/test5.c deleted file mode 100644 index 224db766ff..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/test5.c +++ /dev/null @@ -1,81 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -static void DoTest(WCHAR *formatstr, int param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - int n = -1; - - TestVsnwprintf(buf, 256, 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)); - } -} - -static void DoShortTest(WCHAR *formatstr, int param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - short int n = -1; - - TestVsnwprintf(buf, 256, 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[]) -{ - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoTest(convert("foo %n bar"), 4, convert("foo bar")); - DoTest(convert("foo %#n bar"), 4, convert("foo bar")); - DoTest(convert("foo % n bar"), 4, convert("foo bar")); - DoTest(convert("foo %+n bar"), 4, convert("foo bar")); - DoTest(convert("foo %-n bar"), 4, convert("foo bar")); - DoTest(convert("foo %0n bar"), 4, convert("foo bar")); - DoShortTest(convert("foo %hn bar"), 4, convert("foo bar")); - DoTest(convert("foo %ln bar"), 4, convert("foo bar")); - DoTest(convert("foo %Ln bar"), 4, convert("foo bar")); - DoTest(convert("foo %I64n bar"), 4, convert("foo bar")); - DoTest(convert("foo %20.3n bar"), 4, convert("foo bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/testinfo.dat deleted file mode 100644 index 35d3816a76..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test5/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test5 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with the count specifier. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/CMakeLists.txt deleted file mode 100644 index d3fad03597..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test6.c -) - -add_executable(paltest_vsnwprintf_test6 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test6 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test6 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/test6.c deleted file mode 100644 index 1bd83ea85c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/test6.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoWCharTest(convert("foo %c"), wc, convert("foo c")); - DoCharTest(convert("foo %hc"), 'b', convert("foo b")); - DoWCharTest(convert("foo %lc"), wc, convert("foo c")); - DoWCharTest(convert("foo %Lc"), wc, convert("foo c")); - DoWCharTest(convert("foo %I64c"), wc, convert("foo c")); - DoWCharTest(convert("foo %5c"), wc, convert("foo c")); - DoWCharTest(convert("foo %.0c"), wc, convert("foo c")); - DoWCharTest(convert("foo %-5c"), wc, convert("foo c ")); - DoWCharTest(convert("foo %05c"), wc, convert("foo 0000c")); - DoWCharTest(convert("foo % c"), wc, convert("foo c")); - DoWCharTest(convert("foo %#c"), wc, convert("foo c")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/testinfo.dat deleted file mode 100644 index 6afe96d1cd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test6/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test6 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with characters. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/CMakeLists.txt deleted file mode 100644 index cede861358..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test7.c -) - -add_executable(paltest_vsnwprintf_test7 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test7 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test7 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/test7.c deleted file mode 100644 index e13798b784..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/test7.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test7.c -** -** Purpose: Test #7 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoCharTest(convert("foo %C"), 'b', convert("foo b")); - DoWCharTest(convert("foo %hC"), wc, convert("foo c")); - DoCharTest(convert("foo %lC"), 'b', convert("foo b")); - DoCharTest(convert("foo %LC"), 'b', convert("foo b")); - DoCharTest(convert("foo %I64C"), 'b', convert("foo b")); - DoCharTest(convert("foo %5C"), 'b', convert("foo b")); - DoCharTest(convert("foo %.0C"), 'b', convert("foo b")); - DoCharTest(convert("foo %-5C"), 'b', convert("foo b ")); - DoCharTest(convert("foo %05C"), 'b', convert("foo 0000b")); - DoCharTest(convert("foo % C"), 'b', convert("foo b")); - DoCharTest(convert("foo %#C"), 'b', convert("foo b")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/testinfo.dat deleted file mode 100644 index ece40aa195..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test7/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test7 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with wide characters. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/CMakeLists.txt deleted file mode 100644 index 846e7b9219..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test8.c -) - -add_executable(paltest_vsnwprintf_test8 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test8 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test8 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/test8.c deleted file mode 100644 index 8f02412eb0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/test8.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test8.c -** -** Purpose: Test #8 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %d"), pos, convert("foo 42")); - DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); - DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); - DoI64NumTest(convert("foo %I64d"), l, "42", convert("foo 42")); - DoNumTest(convert("foo %3d"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); - DoNumTest(convert("foo %03d"), pos, convert("foo 042")); - DoNumTest(convert("foo %#d"), pos, convert("foo 42")); - DoNumTest(convert("foo %+d"), pos, convert("foo +42")); - DoNumTest(convert("foo % d"), pos, convert("foo 42")); - DoNumTest(convert("foo %+d"), neg, convert("foo -42")); - DoNumTest(convert("foo % d"), neg, convert("foo -42")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/testinfo.dat deleted file mode 100644 index d7a567a6d6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test8/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test8 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with decimal numbers. -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/CMakeLists.txt deleted file mode 100644 index e25eded172..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test9.c -) - -add_executable(paltest_vsnwprintf_test9 - ${SOURCES} -) - -add_dependencies(paltest_vsnwprintf_test9 coreclrpal) - -target_link_libraries(paltest_vsnwprintf_test9 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/test9.c deleted file mode 100644 index 7b5b6cd8a6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/test9.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test9.c -** -** Purpose: Test #9 for the _vsnwprintf function. -** -** -**===================================================================*/ - -#include -#include "../_vsnwprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %i"), pos, convert("foo 42")); - DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); - DoNumTest(convert("foo %Li"), pos, convert("foo 42")); - DoI64NumTest(convert("foo %I64i"), l, "42", convert("foo 42")); - DoNumTest(convert("foo %3i"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); - DoNumTest(convert("foo %03i"), pos, convert("foo 042")); - DoNumTest(convert("foo %#i"), pos, convert("foo 42")); - DoNumTest(convert("foo %+i"), pos, convert("foo +42")); - DoNumTest(convert("foo % i"), pos, convert("foo 42")); - DoNumTest(convert("foo %+i"), neg, convert("foo -42")); - DoNumTest(convert("foo % i"), neg, convert("foo -42")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/testinfo.dat deleted file mode 100644 index 726b060240..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_vsnwprintf/test9/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = C Runtime -Function = _vsnwprintf -Name = Positive Test for _vsnwprintf -TYPE = DEFAULT -EXE1 = test9 -Description -= Tests the PAL implementation of the _vsnwprintf function. -= Tests _vsnwprintf with integer numbers -= This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/CMakeLists.txt new file mode 100644 index 0000000000..8fe1cb60ac --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test10) +add_subdirectory(test11) +add_subdirectory(test12) +add_subdirectory(test13) +add_subdirectory(test14) +add_subdirectory(test15) +add_subdirectory(test16) +add_subdirectory(test17) +add_subdirectory(test18) +add_subdirectory(test19) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) +add_subdirectory(test6) +add_subdirectory(test7) +add_subdirectory(test8) +add_subdirectory(test9) + diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/_vsnwprintf_s.h b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/_vsnwprintf_s.h new file mode 100644 index 0000000000..34cf411c25 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/_vsnwprintf_s.h @@ -0,0 +1,133 @@ +// 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: _vsnwprintf_s.h +** +** Purpose: Containts common testing functions for _vsnwprintf_s +** +** +**==========================================================================*/ + +#ifndef ___VSNWPRINTF_H__ +#define ___VSNWPRINTF_H__ + +/* These functions leaks memory like crazy. C'est la vie. */ +int TestVsnwprintf_s(wchar_t* buf, size_t count, const wchar_t* format, ...) +{ + int retVal = 0; + va_list arglist; + + va_start(arglist, format); + retVal = _vsnwprintf_s(buf, count, _TRUNCATE, format, arglist); + va_end(arglist); + + return( retVal); +} + + +void DoWStrTest(const WCHAR *formatstr, WCHAR *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, param); + + if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", + convertC(param), convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} + +void DoStrTest(const WCHAR *formatstr, char *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, param); + + if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", + param, convertC(formatstr), convertC(checkstr), + convertC(buf)); + } +} + +void DoCharTest(const WCHAR *formatstr, char param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, param); + if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0) + { + Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + param, param, convertC(formatstr), convertC(checkstr), + convertC(buf)); + } +} + +void DoWCharTest(const WCHAR *formatstr, WCHAR param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, param); + if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0) + { + Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + (char) param, param, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} + +void DoNumTest(const WCHAR *formatstr, int value, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, value); + if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0) + { + Fail("ERROR: failed to insert %#x into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", value, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} + +void DoI64NumTest(const WCHAR *formatstr, INT64 value, char *valuestr, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, value); + if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", valuestr, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} +void DoDoubleTest(const WCHAR *formatstr, double value, + const WCHAR *checkstr1, const WCHAR *checkstr2) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, value); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\"\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + value, + convertC(formatstr), + convertC(checkstr1), + convertC(checkstr2), + convertC(buf)); + } +} + +#endif diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/CMakeLists.txt new file mode 100644 index 0000000000..d1245168f3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_vsnwprintf_test1 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test1 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/test1.cpp new file mode 100644 index 0000000000..4a7a02e778 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/test1.cpp @@ -0,0 +1,60 @@ +// 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: test1.c +** +** Purpose: Test #1 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +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; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/testinfo.dat new file mode 100644 index 0000000000..450c5b9034 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test1 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += General test to see if _vsnwprintf_s works correctly. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/CMakeLists.txt new file mode 100644 index 0000000000..6367964f1d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test10.cpp +) + +add_executable(paltest_vsnwprintf_test10 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test10 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test10 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/test10.cpp new file mode 100644 index 0000000000..e33f2281df --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/test10.cpp @@ -0,0 +1,50 @@ +// 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: test10.c +** +** Purpose: Test #10 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %o"), pos, convert("foo 52")); + DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); + DoI64NumTest(convert("foo %I64o"), l, "42", convert("foo 52")); + DoNumTest(convert("foo %3o"), pos, convert("foo 52")); + DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); + DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); + DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); + DoNumTest(convert("foo %03o"), pos, convert("foo 052")); + DoNumTest(convert("foo %#o"), pos, convert("foo 052")); + DoNumTest(convert("foo %+o"), pos, convert("foo 52")); + DoNumTest(convert("foo % o"), pos, convert("foo 52")); + DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); + DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/testinfo.dat new file mode 100644 index 0000000000..59af082f49 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test10 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with octal numbers. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/CMakeLists.txt new file mode 100644 index 0000000000..b45fd0ed1e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test11.cpp +) + +add_executable(paltest_vsnwprintf_test11 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test11 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test11 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/test11.cpp new file mode 100644 index 0000000000..4e860bbc21 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/test11.cpp @@ -0,0 +1,50 @@ +// 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: test11.c +** +** Purpose: Test #11 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %u"), pos, convert("foo 42")); + DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64u"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3u"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); + DoNumTest(convert("foo %03u"), pos, convert("foo 042")); + DoNumTest(convert("foo %#u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), pos, convert("foo 42")); + DoNumTest(convert("foo % u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); + DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/testinfo.dat new file mode 100644 index 0000000000..10c0014fca --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test11 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with unsigned numbers. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/CMakeLists.txt new file mode 100644 index 0000000000..2a15b198c0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test12.cpp +) + +add_executable(paltest_vsnwprintf_test12 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test12 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test12 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/test12.cpp new file mode 100644 index 0000000000..2dcfcf5998 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/test12.cpp @@ -0,0 +1,50 @@ +// 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: test12.c +** +** Purpose: Test #12 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); + DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); + DoI64NumTest(convert("foo %I64x"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); + DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); + DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); + DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/testinfo.dat new file mode 100644 index 0000000000..de089895b9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test12 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with hex numbers (lowercase). += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/CMakeLists.txt new file mode 100644 index 0000000000..01ab97cc62 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test13.cpp +) + +add_executable(paltest_vsnwprintf_test13 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test13 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test13 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/test13.cpp new file mode 100644 index 0000000000..c95278a56b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/test13.cpp @@ -0,0 +1,50 @@ +// 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: test13.c +** +** Purpose: Test #13 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); + DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); + DoI64NumTest(convert("foo %I64X"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); + DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); + DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); + DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/testinfo.dat new file mode 100644 index 0000000000..94479d527c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test13 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with hex numbers (uppercase). += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/CMakeLists.txt new file mode 100644 index 0000000000..c6c990312f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test14.cpp +) + +add_executable(paltest_vsnwprintf_test14 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test14 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test14 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/test14.cpp new file mode 100644 index 0000000000..cab1b247df --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/test14.cpp @@ -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: test14.c +** +** Purpose: Test #14 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), + convert("foo 2.560000e+02 ")); + DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), + convert("foo 2.6e+02")); + DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), + convert("foo 2.56000000e+02")); + DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), + convert("foo 002.560000e+02")); + DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), + convert("foo +2.560000e+02")); + DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/testinfo.dat new file mode 100644 index 0000000000..0d46d97649 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test14 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with exponential format doubles (lowercase). += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/CMakeLists.txt new file mode 100644 index 0000000000..e1a32b1825 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test15.cpp +) + +add_executable(paltest_vsnwprintf_test15 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test15 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test15 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/test15.cpp new file mode 100644 index 0000000000..d5738991a6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/test15.cpp @@ -0,0 +1,64 @@ +// 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: test15.c +** +** Purpose: Test #15 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), + convert("foo 2.560000E+02 ")); + DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), + convert("foo 2.6E+02")); + DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), + convert("foo 2.56000000E+02")); + DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), + convert("foo 002.560000E+02")); + DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), + convert("foo +2.560000E+02")); + DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+002")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/testinfo.dat new file mode 100644 index 0000000000..7737f49a35 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test15 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with exponential format doubles (uppercase). += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/CMakeLists.txt new file mode 100644 index 0000000000..9e2b25b308 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test16.cpp +) + +add_executable(paltest_vsnwprintf_test16 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test16 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test16 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/test16.cpp new file mode 100644 index 0000000000..72c546eb63 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/test16.cpp @@ -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: test16.c +** +** Purpose: Test #16 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), + convert("foo 2560.001000 ")); + DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), + convert("foo 2560.0")); + DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), + convert("foo 2560.00100000")); + DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), + convert("foo 02560.001000")); + DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), + convert("foo +2560.001000")); + DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/testinfo.dat new file mode 100644 index 0000000000..9aec1c008a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test16 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with decimal point format doubles. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/CMakeLists.txt new file mode 100644 index 0000000000..2d8ba31a08 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test17.cpp +) + +add_executable(paltest_vsnwprintf_test17 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test17 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test17 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/test17.cpp new file mode 100644 index 0000000000..e6860b930f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/test17.cpp @@ -0,0 +1,65 @@ +// 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: test17.c +** +** Purpose: Test #17 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), + convert("foo 3e+03")); + DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), + convert("foo 2.6e+03")); + DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/testinfo.dat new file mode 100644 index 0000000000..1487b7a17e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test17 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with compact format doubles (lowercase). += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/CMakeLists.txt new file mode 100644 index 0000000000..503856c2f3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test18.cpp +) + +add_executable(paltest_vsnwprintf_test18 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test18 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test18 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/test18.cpp new file mode 100644 index 0000000000..a164edbc0f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/test18.cpp @@ -0,0 +1,65 @@ +// 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: test18.c +** +** Purpose: Test #18 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), + convert("foo 3E+03")); + DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), + convert("foo 2.6E+03")); + DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/testinfo.dat new file mode 100644 index 0000000000..54c4e87c89 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test18 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with compact format doubles (uppercase). += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/CMakeLists.txt new file mode 100644 index 0000000000..68485eff12 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test19.cpp +) + +add_executable(paltest_vsnwprintf_test19 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test19 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test19 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/test19.cpp new file mode 100644 index 0000000000..c2a85478ae --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/test19.cpp @@ -0,0 +1,139 @@ +// 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: test18.c +** +** Purpose: Test #18 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +#define DOTEST(a,b,c,d,e) DoTest(a,b,(void*)c,d,e) + +void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, + WCHAR *paramstr, WCHAR *checkstr1, WCHAR *checkstr2) +{ + WCHAR buf[256]; + + TestVsnwprintf_s(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 %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + paramstr, + convertC(formatstr), + precision, + convertC(checkstr1), + convertC(checkstr2), + convertC(buf)); + } +} +void DoArgumentPrecDoubleTest(WCHAR *formatstr, int precision, double param, + WCHAR *checkstr1, WCHAR *checkstr2) +{ + WCHAR buf[256]; + + TestVsnwprintf_s(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)); + } +} + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoArgumentPrecTest(convert("%.*s"), 2, (void*)convert("bar"), convert("bar"), + convert("ba"), convert("ba")); + DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, convert("42"), + convert("52"), convert("52")); + DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, convert("42"), + convert("052"), convert("052")); + DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, convert("0x42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, convert("0x42"), + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, convert("0x42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, convert("0x42"), + convert("042"), convert("042")); + + + DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000"), + convert("2.0e+00")); + DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000"), + convert("2.010e+00")); + DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000"), + convert("2.0E+00")); + DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000"), + convert("2.010E+00")); + DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0"), + convert("2.0")); + DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010"), + convert("2.010")); + DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002"), + convert("3e+02")); + DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01"), + convert("256.01")); + DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002"), + convert("3E+02")); + DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01"), + convert("256.01")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/testinfo.dat new file mode 100644 index 0000000000..2913e30406 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test19 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with argument specified precision. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/CMakeLists.txt new file mode 100644 index 0000000000..a512be6e47 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.cpp +) + +add_executable(paltest_vsnwprintf_test2 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test2 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/test2.cpp new file mode 100644 index 0000000000..18e5adffd3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/test2.cpp @@ -0,0 +1,40 @@ +// 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: test2.c +** +** Purpose: Test #2 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); + DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/testinfo.dat new file mode 100644 index 0000000000..5b9b6292dc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test2 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with strings. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/CMakeLists.txt new file mode 100644 index 0000000000..7991c25afc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.cpp +) + +add_executable(paltest_vsnwprintf_test3 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test3 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/test3.cpp new file mode 100644 index 0000000000..5e2bfa21a0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/test3.cpp @@ -0,0 +1,40 @@ +// 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: test3.c +** +** Purpose: Test #3 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoStrTest(convert("foo %S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); + DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %5.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); + DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/testinfo.dat new file mode 100644 index 0000000000..62160695e6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test3 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with wide strings. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/CMakeLists.txt new file mode 100644 index 0000000000..18f5d02df2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test4.cpp +) + +add_executable(paltest_vsnwprintf_test4 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test4 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/test4.cpp new file mode 100644 index 0000000000..3627ff8bc8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/test4.cpp @@ -0,0 +1,121 @@ +// 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: test4.c +** +** Purpose: Test #4 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ +static void DoPointerTest(WCHAR *formatstr, void* param, WCHAR* paramstr, + WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, 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)); + } +} + +static void DoI64DoubleTest(WCHAR *formatstr, INT64 value, WCHAR *valuestr, + WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, 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[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000")); + DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), + convert(" 0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), + convert(" 0000000000123456")); + DoPointerTest(convert("%-17p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456")); + DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), + convert("0X0000000000123456")); + DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), + convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoI64DoubleTest(convert("%I64p"), lptr, + convert("pointer to 0x1234567887654321"), + convert("1234567887654321")); + +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000")); + DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%9p"), ptr, convert("pointer to 0x123456"), + convert(" 00123456")); + DoPointerTest(convert("%09p"), ptr, convert("pointer to 0x123456"), + convert(" 00123456")); + DoPointerTest(convert("%-9p"), ptr, convert("pointer to 0x123456"), + convert("00123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), + convert("0X00123456")); + DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), + convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoI64DoubleTest(convert("%I64p"), lptr, + convert("pointer to 0x1234567887654321"), + convert("1234567887654321")); +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/testinfo.dat new file mode 100644 index 0000000000..9fbfcba5cf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test4 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with pointers. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/CMakeLists.txt new file mode 100644 index 0000000000..c431da4a00 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test6.cpp +) + +add_executable(paltest_vsnwprintf_test6 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test6 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test6 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/test6.cpp new file mode 100644 index 0000000000..ecba5853a6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/test6.cpp @@ -0,0 +1,43 @@ +// 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: test6.c +** +** Purpose: Test #6 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoWCharTest(convert("foo %c"), wc, convert("foo c")); + DoCharTest(convert("foo %hc"), 'b', convert("foo b")); + DoWCharTest(convert("foo %lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %Lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %I64c"), wc, convert("foo c")); + DoWCharTest(convert("foo %5c"), wc, convert("foo c")); + DoWCharTest(convert("foo %.0c"), wc, convert("foo c")); + DoWCharTest(convert("foo %-5c"), wc, convert("foo c ")); + DoWCharTest(convert("foo %05c"), wc, convert("foo 0000c")); + DoWCharTest(convert("foo % c"), wc, convert("foo c")); + DoWCharTest(convert("foo %#c"), wc, convert("foo c")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/testinfo.dat new file mode 100644 index 0000000000..1b411d7982 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test6 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with characters. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/CMakeLists.txt new file mode 100644 index 0000000000..5759b836b5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test7.cpp +) + +add_executable(paltest_vsnwprintf_test7 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test7 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test7 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/test7.cpp new file mode 100644 index 0000000000..519657a202 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/test7.cpp @@ -0,0 +1,43 @@ +// 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: test7.c +** +** Purpose: Test #7 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoCharTest(convert("foo %C"), 'b', convert("foo b")); + DoWCharTest(convert("foo %hC"), wc, convert("foo c")); + DoCharTest(convert("foo %lC"), 'b', convert("foo b")); + DoCharTest(convert("foo %LC"), 'b', convert("foo b")); + DoCharTest(convert("foo %I64C"), 'b', convert("foo b")); + DoCharTest(convert("foo %5C"), 'b', convert("foo b")); + DoCharTest(convert("foo %.0C"), 'b', convert("foo b")); + DoCharTest(convert("foo %-5C"), 'b', convert("foo b ")); + DoCharTest(convert("foo %05C"), 'b', convert("foo 0000b")); + DoCharTest(convert("foo % C"), 'b', convert("foo b")); + DoCharTest(convert("foo %#C"), 'b', convert("foo b")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/testinfo.dat new file mode 100644 index 0000000000..8f2ccf0b58 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test7 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with wide characters. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/CMakeLists.txt new file mode 100644 index 0000000000..5e8a6284a5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test8.cpp +) + +add_executable(paltest_vsnwprintf_test8 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test8 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test8 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/test8.cpp new file mode 100644 index 0000000000..15641f7b9e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/test8.cpp @@ -0,0 +1,49 @@ +// 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: test8.c +** +** Purpose: Test #8 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %d"), pos, convert("foo 42")); + DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64d"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3d"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); + DoNumTest(convert("foo %03d"), pos, convert("foo 042")); + DoNumTest(convert("foo %#d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), pos, convert("foo +42")); + DoNumTest(convert("foo % d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), neg, convert("foo -42")); + DoNumTest(convert("foo % d"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/testinfo.dat new file mode 100644 index 0000000000..905740c1bb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test8 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with decimal numbers. += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/CMakeLists.txt new file mode 100644 index 0000000000..323365dcd9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test9.cpp +) + +add_executable(paltest_vsnwprintf_test9 + ${SOURCES} +) + +add_dependencies(paltest_vsnwprintf_test9 coreclrpal) + +target_link_libraries(paltest_vsnwprintf_test9 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/test9.cpp new file mode 100644 index 0000000000..38f6be21e7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/test9.cpp @@ -0,0 +1,49 @@ +// 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: test9.c +** +** Purpose: Test #9 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %i"), pos, convert("foo 42")); + DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Li"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64i"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3i"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); + DoNumTest(convert("foo %03i"), pos, convert("foo 042")); + DoNumTest(convert("foo %#i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), pos, convert("foo +42")); + DoNumTest(convert("foo % i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), neg, convert("foo -42")); + DoNumTest(convert("foo % i"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/testinfo.dat new file mode 100644 index 0000000000..974efdb4cf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = _vsnwprintf_s +Name = Positive Test for _vsnwprintf_s +TYPE = DEFAULT +EXE1 = test9 +Description += Tests the PAL implementation of the _vsnwprintf_s function. += Tests _vsnwprintf_s with integer numbers += This test is modeled after _snwprintf. diff --git a/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/CMakeLists.txt index 5f085cc723..023b777cab 100644 --- a/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcsicmp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/test1.c deleted file mode 100644 index dd4bb54680..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/test1.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that _wcsicmp correctly compares two strings with -** case insensitivity. -** -** -**==========================================================================*/ - -#include - -/* - * Note: The _wcsicmp is dependent on the LC_CTYPE category of the locale, - * and this is ignored by these tests. - */ -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str1[] = {'f','o','o',0}; - WCHAR str2[] = {'f','O','o',0}; - WCHAR str3[] = {'f','o','o','_','b','a','r',0}; - WCHAR str4[] = {'f','o','o','b','a','r',0}; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if (_wcsicmp(str1, str2) != 0) - { - Fail ("ERROR: _wcsicmp returning incorrect value:\n" - "_wcsicmp(\"%S\", \"%S\") != 0\n", str1, str2); - } - - if (_wcsicmp(str2, str3) >= 0) - { - Fail ("ERROR: _wcsicmp returning incorrect value:\n" - "_wcsicmp(\"%S\", \"%S\") >= 0\n", str2, str3); - } - - if (_wcsicmp(str3, str4) >= 0) - { - Fail ("ERROR: _wcsicmp returning incorrect value:\n" - "_wcsicmp(\"%S\", \"%S\") >= 0\n", str3, str4); - } - - if (_wcsicmp(str4, str1) <= 0) - { - Fail ("ERROR: _wcsicmp returning incorrect value:\n" - "_wcsicmp(\"%S\", \"%S\") <= 0\n", str4, str1); - } - - if (_wcsicmp(str3, str2) <= 0) - { - Fail ("ERROR: _wcsicmp returning incorrect value:\n" - "_wcsicmp(\"%S\", \"%S\") <= 0\n", str2, str3); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/test1.cpp new file mode 100644 index 0000000000..dd4bb54680 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wcsicmp/test1/test1.cpp @@ -0,0 +1,68 @@ +// 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: test1.c +** +** Purpose: Tests that _wcsicmp correctly compares two strings with +** case insensitivity. +** +** +**==========================================================================*/ + +#include + +/* + * Note: The _wcsicmp is dependent on the LC_CTYPE category of the locale, + * and this is ignored by these tests. + */ +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str1[] = {'f','o','o',0}; + WCHAR str2[] = {'f','O','o',0}; + WCHAR str3[] = {'f','o','o','_','b','a','r',0}; + WCHAR str4[] = {'f','o','o','b','a','r',0}; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + if (_wcsicmp(str1, str2) != 0) + { + Fail ("ERROR: _wcsicmp returning incorrect value:\n" + "_wcsicmp(\"%S\", \"%S\") != 0\n", str1, str2); + } + + if (_wcsicmp(str2, str3) >= 0) + { + Fail ("ERROR: _wcsicmp returning incorrect value:\n" + "_wcsicmp(\"%S\", \"%S\") >= 0\n", str2, str3); + } + + if (_wcsicmp(str3, str4) >= 0) + { + Fail ("ERROR: _wcsicmp returning incorrect value:\n" + "_wcsicmp(\"%S\", \"%S\") >= 0\n", str3, str4); + } + + if (_wcsicmp(str4, str1) <= 0) + { + Fail ("ERROR: _wcsicmp returning incorrect value:\n" + "_wcsicmp(\"%S\", \"%S\") <= 0\n", str4, str1); + } + + if (_wcsicmp(str3, str2) <= 0) + { + Fail ("ERROR: _wcsicmp returning incorrect value:\n" + "_wcsicmp(\"%S\", \"%S\") <= 0\n", str2, str3); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/CMakeLists.txt index a78098f86a..b9df132d29 100644 --- a/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcslwr_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/test1.c deleted file mode 100644 index 3a758de39b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/test1.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test1.c -** -** Purpose: Using memcmp to check the result, convert a wide character string -** with capitals, to all lowercase using this function. Test #1 for the -** wcslwr function -** -** -**==========================================================================*/ - -#include - -/* uses memcmp,wcslen */ - -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; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/test1.cpp new file mode 100644 index 0000000000..3a758de39b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wcslwr/test1/test1.cpp @@ -0,0 +1,50 @@ +// 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: test1.c +** +** Purpose: Using memcmp to check the result, convert a wide character string +** with capitals, to all lowercase using this function. Test #1 for the +** wcslwr function +** +** +**==========================================================================*/ + +#include + +/* uses memcmp,wcslen */ + +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; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/CMakeLists.txt index afd3560b10..ea22daa477 100644 --- a/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcsnicmp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/test1.c deleted file mode 100644 index 0271bcc60d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/test1.c +++ /dev/null @@ -1,95 +0,0 @@ -// 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: test1.c -** -** Purpose: Take two wide strings and compare them, giving different lengths. -** Comparing str1 and str2 with str2 length, should return <0 -** Comparing str2 and str1 with str2 length, should return >0 -** Comparing str1 and str2 with str1 lenght, should return 0 -** Bring in str3, which has a capital, but this function is doing a lower -** case compare. Just ensure that two strings which differ only by capitals -** return 0. -** -** -**==========================================================================*/ - -#include - -/* - * Notes: uses wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str1[] = {'f','o','o',0}; - WCHAR str2[] = {'f','o','o','x',0}; - WCHAR str3[] = {'f','O','o',0}; - WCHAR str4[] = {'A','B','C','D','E',0}; - WCHAR str5[] = {'A','B','C','D',']',0}; - WCHAR str6[] = {'a','b','c','d','e',0}; - WCHAR str7[] = {'a','b','c','d',']',0}; - char cstr1[] = "foo"; - char cstr2[] = "foox"; - char cstr3[] = "fOo"; - char cstr4[] = "ABCDE"; - char cstr5[] = "ABCD]"; - char cstr6[] = "abcde"; - char cstr7[] = "abcd]"; - - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if (_wcsnicmp(str1, str2, wcslen(str2)) >= 0) - { - Fail ("ERROR: wcsnicmp(\"%s\", \"%s\", %d) returned >= 0\n", cstr1, - cstr2, wcslen(str2)); - } - - if (_wcsnicmp(str2, str1, wcslen(str2)) <= 0) - { - Fail ("ERROR: wcsnicmp(\"%s\", \"%s\", %d) returned <= 0\n", cstr2, - cstr1, wcslen(str2)); - } - - if (_wcsnicmp(str1, str2, wcslen(str1)) != 0) - { - Fail ("ERROR: wcsnicmp(\"%s\", \"%s\", %d) returned != 0\n", cstr1, - cstr2, wcslen(str1)); - } - - if (_wcsnicmp(str1, str3, wcslen(str1)) != 0) - { - Fail ("ERROR: wcsnicmp(\"%s\", \"%s\", %d) returned != 0\n", cstr1, - cstr3, wcslen(str1)); - } - - /* new testing */ - - /* str4 should be greater than str5 */ - if (_wcsnicmp(str4, str5, wcslen(str4)) <= 0) - { - Fail ("ERROR: _wcsnicmp(\"%s\", \"%s\", %d) returned >= 0\n", - cstr4, cstr5, wcslen(str4)); - } - - /* str6 should be greater than str7 */ - if (_wcsnicmp(str6, str7, wcslen(str6)) <= 0) - { - Fail ("ERROR: _wcsnicmp(\"%s\", \"%s\", %d) returned <= 0\n", - cstr6, cstr7, wcslen(str6)); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/test1.cpp new file mode 100644 index 0000000000..0271bcc60d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wcsnicmp/test1/test1.cpp @@ -0,0 +1,95 @@ +// 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: test1.c +** +** Purpose: Take two wide strings and compare them, giving different lengths. +** Comparing str1 and str2 with str2 length, should return <0 +** Comparing str2 and str1 with str2 length, should return >0 +** Comparing str1 and str2 with str1 lenght, should return 0 +** Bring in str3, which has a capital, but this function is doing a lower +** case compare. Just ensure that two strings which differ only by capitals +** return 0. +** +** +**==========================================================================*/ + +#include + +/* + * Notes: uses wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str1[] = {'f','o','o',0}; + WCHAR str2[] = {'f','o','o','x',0}; + WCHAR str3[] = {'f','O','o',0}; + WCHAR str4[] = {'A','B','C','D','E',0}; + WCHAR str5[] = {'A','B','C','D',']',0}; + WCHAR str6[] = {'a','b','c','d','e',0}; + WCHAR str7[] = {'a','b','c','d',']',0}; + char cstr1[] = "foo"; + char cstr2[] = "foox"; + char cstr3[] = "fOo"; + char cstr4[] = "ABCDE"; + char cstr5[] = "ABCD]"; + char cstr6[] = "abcde"; + char cstr7[] = "abcd]"; + + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + if (_wcsnicmp(str1, str2, wcslen(str2)) >= 0) + { + Fail ("ERROR: wcsnicmp(\"%s\", \"%s\", %d) returned >= 0\n", cstr1, + cstr2, wcslen(str2)); + } + + if (_wcsnicmp(str2, str1, wcslen(str2)) <= 0) + { + Fail ("ERROR: wcsnicmp(\"%s\", \"%s\", %d) returned <= 0\n", cstr2, + cstr1, wcslen(str2)); + } + + if (_wcsnicmp(str1, str2, wcslen(str1)) != 0) + { + Fail ("ERROR: wcsnicmp(\"%s\", \"%s\", %d) returned != 0\n", cstr1, + cstr2, wcslen(str1)); + } + + if (_wcsnicmp(str1, str3, wcslen(str1)) != 0) + { + Fail ("ERROR: wcsnicmp(\"%s\", \"%s\", %d) returned != 0\n", cstr1, + cstr3, wcslen(str1)); + } + + /* new testing */ + + /* str4 should be greater than str5 */ + if (_wcsnicmp(str4, str5, wcslen(str4)) <= 0) + { + Fail ("ERROR: _wcsnicmp(\"%s\", \"%s\", %d) returned >= 0\n", + cstr4, cstr5, wcslen(str4)); + } + + /* str6 should be greater than str7 */ + if (_wcsnicmp(str6, str7, wcslen(str6)) <= 0) + { + Fail ("ERROR: _wcsnicmp(\"%s\", \"%s\", %d) returned <= 0\n", + cstr6, cstr7, wcslen(str6)); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wfopen/test1/CMakeLists.txt index 96df58ee54..f7aa22d5b2 100644 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wfopen_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.c deleted file mode 100644 index 81d2502cd5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the _wfopen function. -** This test simply attempts to open a number of files with -** different modes. It checks to ensure a valid file -** pointer is returned. It doesn't do any checking to -** ensure the mode is really what it claims. -** - -** -**===================================================================*/ - - -#define UNICODE -#include - -struct testCase -{ - int CorrectResult; - WCHAR mode[20]; -}; - -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'}}, {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; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp new file mode 100644 index 0000000000..81d2502cd5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp @@ -0,0 +1,79 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the _wfopen function. +** This test simply attempts to open a number of files with +** different modes. It checks to ensure a valid file +** pointer is returned. It doesn't do any checking to +** ensure the mode is really what it claims. +** + +** +**===================================================================*/ + + +#define UNICODE +#include + +struct testCase +{ + int CorrectResult; + WCHAR mode[20]; +}; + +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'}}, {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; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wfopen/test2/CMakeLists.txt index 47203d86d5..3159889f0a 100644 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_wfopen_test2 diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_wfopen/test2/test2.c deleted file mode 100644 index 921ffef19d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test2/test2.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests the PAL implementation of the _wfopen function. -** Test to ensure that you can write to a 'w' mode file. -** And that you can't read from a 'w' mode file. -** -** Depends: -** fprintf -** fseek -** fgets -** - -** -**===================================================================*/ - -#define UNICODE -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; - WCHAR write[] = {'w','\0'}; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - if( (fp = _wfopen( filename, write )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w' mode.\n" ); - } - - /* Test that you can write */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Test that you can't read */ - if(fgets(buffer,10,fp) != NULL) - { - Fail("ERROR: Tried to READ from a file with only 'w' mode set. " - "This should fail, but fgets didn't return NULL. " - "Either fgets or fopen is broken."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/_wfopen/test2/test2.cpp new file mode 100644 index 0000000000..921ffef19d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test2/test2.cpp @@ -0,0 +1,68 @@ +// 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: test2.c +** +** Purpose: Tests the PAL implementation of the _wfopen function. +** Test to ensure that you can write to a 'w' mode file. +** And that you can't read from a 'w' mode file. +** +** Depends: +** fprintf +** fseek +** fgets +** + +** +**===================================================================*/ + +#define UNICODE +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; + WCHAR write[] = {'w','\0'}; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + if( (fp = _wfopen( filename, write )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'w' mode.\n" ); + } + + /* Test that you can write */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Test that you can't read */ + if(fgets(buffer,10,fp) != NULL) + { + Fail("ERROR: Tried to READ from a file with only 'w' mode set. " + "This should fail, but fgets didn't return NULL. " + "Either fgets or fopen is broken."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wfopen/test3/CMakeLists.txt index deec8bbfe6..06d0941471 100644 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_wfopen_test3 diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test3/test3.c b/src/pal/tests/palsuite/c_runtime/_wfopen/test3/test3.c deleted file mode 100644 index 3b67818bc5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test3/test3.c +++ /dev/null @@ -1,70 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests the PAL implementation of the _wfopen function. -** Test to ensure that you can write to a 'w+' mode file. -** And that you can read from a 'w+' mode file. -** -** Depends: -** fprintf -** fseek -** fgets -** - -** -**===================================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; - WCHAR writeplus[] = {'w','+','\0'}; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'w+' mode */ - if( (fp = _wfopen( filename, writeplus )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w+' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'w+' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'w+' only file, should pass */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'w+' mode set. " - "This should succeed, but fgets returned NULL. Either fgets " - "or fopen is broken."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/_wfopen/test3/test3.cpp new file mode 100644 index 0000000000..3b67818bc5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test3/test3.cpp @@ -0,0 +1,70 @@ +// 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: test3.c +** +** Purpose: Tests the PAL implementation of the _wfopen function. +** Test to ensure that you can write to a 'w+' mode file. +** And that you can read from a 'w+' mode file. +** +** Depends: +** fprintf +** fseek +** fgets +** + +** +**===================================================================*/ + +#define UNICODE + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; + WCHAR writeplus[] = {'w','+','\0'}; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file with 'w+' mode */ + if( (fp = _wfopen( filename, writeplus )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'w+' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'w+' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read from the 'w+' only file, should pass */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'w+' mode set. " + "This should succeed, but fgets returned NULL. Either fgets " + "or fopen is broken."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wfopen/test4/CMakeLists.txt index e93cdd58de..8253d75d8d 100644 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_wfopen_test4 diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test4/test4.c b/src/pal/tests/palsuite/c_runtime/_wfopen/test4/test4.c deleted file mode 100644 index 0948fa11cc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test4/test4.c +++ /dev/null @@ -1,87 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests the PAL implementation of the _wfopen function. -** Test to ensure that you can't write to a 'r' mode file. -** And that you can read from a 'r' mode file. -** -** Depends: -** fprintf -** fclose -** fgets -** - -** -**===================================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; - WCHAR write[] = {'w','\0'}; - WCHAR read[] = {'r','\0'}; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'w' mode */ - if( (fp = _wfopen( filename, write )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fclose(fp)) - { - Fail("ERROR: Attempted to close a file, but fclose failed. " - "This test depends upon it."); - } - - /* Open a file with 'r' mode */ - if( (fp = _wfopen( filename, read )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'r' mode.\n" ); - } - - /* Attempt to read from the 'r' only file, should pass */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'r' mode set. " - "This should succeed, but fgets returned NULL. Either fgets " - "or fopen is broken."); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") > 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'r' mode " - "but fprintf succeeded It should have failed. " - "Either fopen or fprintf have problems."); - } - - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/_wfopen/test4/test4.cpp new file mode 100644 index 0000000000..0948fa11cc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test4/test4.cpp @@ -0,0 +1,87 @@ +// 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: test4.c +** +** Purpose: Tests the PAL implementation of the _wfopen function. +** Test to ensure that you can't write to a 'r' mode file. +** And that you can read from a 'r' mode file. +** +** Depends: +** fprintf +** fclose +** fgets +** + +** +**===================================================================*/ + +#define UNICODE + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; + WCHAR write[] = {'w','\0'}; + WCHAR read[] = {'r','\0'}; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file with 'w' mode */ + if( (fp = _wfopen( filename, write )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'w' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fclose(fp)) + { + Fail("ERROR: Attempted to close a file, but fclose failed. " + "This test depends upon it."); + } + + /* Open a file with 'r' mode */ + if( (fp = _wfopen( filename, read )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'r' mode.\n" ); + } + + /* Attempt to read from the 'r' only file, should pass */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'r' mode set. " + "This should succeed, but fgets returned NULL. Either fgets " + "or fopen is broken."); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") > 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'r' mode " + "but fprintf succeeded It should have failed. " + "Either fopen or fprintf have problems."); + } + + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wfopen/test5/CMakeLists.txt index 1530416795..8b3d064ec6 100644 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_wfopen_test5 diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test5/test5.c b/src/pal/tests/palsuite/c_runtime/_wfopen/test5/test5.c deleted file mode 100644 index 21e5ec84ed..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test5/test5.c +++ /dev/null @@ -1,82 +0,0 @@ -// 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: test5.c -** -** Purpose: Tests the PAL implementation of the _wfopen function. -** Test to ensure that you can write to a 'r+' mode file. -** And that you can read from a 'r+' mode file. -** -** Depends: -** fprintf -** fclose -** fgets -** fseek -** - -** -**===================================================================*/ -#define UNICODE - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; - WCHAR write[] = {'w','\0'}; - WCHAR readplus[] = {'r','+','\0'}; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'w' mode */ - if( (fp = _wfopen( filename,write )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w' mode.\n" ); - } - - if(fclose(fp)) - { - Fail("ERROR: Attempted to close a file, but fclose failed. " - "This test depends upon it."); - } - - if( (fp = _wfopen( filename, readplus )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'r+' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'r+' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'r+' only file, should pass */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'r+' mode set. " - "This should succeed, but fgets returned NULL. Either fgets " - "or fopen is broken."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/_wfopen/test5/test5.cpp new file mode 100644 index 0000000000..21e5ec84ed --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test5/test5.cpp @@ -0,0 +1,82 @@ +// 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: test5.c +** +** Purpose: Tests the PAL implementation of the _wfopen function. +** Test to ensure that you can write to a 'r+' mode file. +** And that you can read from a 'r+' mode file. +** +** Depends: +** fprintf +** fclose +** fgets +** fseek +** + +** +**===================================================================*/ +#define UNICODE + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; + WCHAR write[] = {'w','\0'}; + WCHAR readplus[] = {'r','+','\0'}; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file with 'w' mode */ + if( (fp = _wfopen( filename,write )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'w' mode.\n" ); + } + + if(fclose(fp)) + { + Fail("ERROR: Attempted to close a file, but fclose failed. " + "This test depends upon it."); + } + + if( (fp = _wfopen( filename, readplus )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'r+' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'r+' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read from the 'r+' only file, should pass */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'r+' mode set. " + "This should succeed, but fgets returned NULL. Either fgets " + "or fopen is broken."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wfopen/test6/CMakeLists.txt index c401c6f40f..bf1eaeca27 100644 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_wfopen_test6 diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test6/test6.c b/src/pal/tests/palsuite/c_runtime/_wfopen/test6/test6.c deleted file mode 100644 index 17d36a0c50..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test6/test6.c +++ /dev/null @@ -1,152 +0,0 @@ -// 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: test6.c -** -** Purpose: Tests the PAL implementation of the _wfopen function. -** Test to ensure that you can write to an 'a' mode file. -** And that you can't read from a 'a' mode file. -** -** Depends: -** fprintf -** fgets -** fseek -** - -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - FILE *fp; - char buffer[128]; - WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; - WCHAR filename2[] = {'t','e','s','t','f','i','l','e','2','\0'}; - WCHAR append[] = {'a','\0'}; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open a file with 'a' mode */ - if( (fp = _wfopen( filename, append )) == NULL ) - { - Fail( "ERROR: file failed to open with 'a' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'a' only file, should fail */ - if(fgets(buffer,10,fp) != NULL) - { - Fail("ERROR: Tried to READ from a file with 'a' mode set. " - "This should fail, but fgets returned success. Either fgets " - "or fopen is broken."); - } - - // Delete the file now that we're done with it. - if (fclose(fp) != 0) - { - Fail("ERROR: fclose failed to close \"testfile\".\n"); - } - - if (!DeleteFileA("testfile")) - { - Fail("ERROR: Failed to delete \"testfile\".\n" - " Error is %d\n", - GetLastError()); - } - - /* Attempt to write to a file after using 'a' and fseek */ - fp = _wfopen(filename2, append); - if(fp == NULL) - { - Fail("ERROR: _wfopen failed to be created with 'a' mode.\n"); - } - - /* write text to the file initially */ - if(fprintf(fp,"%s","abcd") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " - "but fprintf failed. Either fopen or fprintf have problems.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* using 'a' should still write to the end of the file, not the front */ - if(fputs("efgh", fp) < 0) - { - Fail("ERROR: Attempt to WRITE with fputs to the beginning of a file " - "opened with 'a' mode succeeded.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* a file with 'a' mode can only write, so close the file before reading */ - if(fclose(fp)) - { - Fail("ERROR: fclose failed when it should have succeeded.\n"); - } - - /* open the file again to read */ - fp = fopen("testfile2","r"); - if(fp == NULL) - { - Fail("ERROR: fopen failed to open the file using 'r' mode"); - } - - /* Attempt to read from the 'a' only file, should succeed */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'a' mode set. " - "This should pass, but fgets returned failure. Either fgets " - "or fopen is broken.\n"); - } - - /* Compare what was read and what should have been in the file */ - if(memcmp(buffer,"abcdefgh",8)) - { - Fail("ERROR: The string read should have equaled 'abcdefgh' " - "but instead it is %s\n", buffer); - } - - // Delete the file now that we're done with it. - if (fclose(fp) != 0) - { - Fail("ERROR: fclose failed to close \"testfile\".\n"); - } - - if (!DeleteFileA("testfile2")) - { - Fail("ERROR: Failed to delete \"testfile2\".\n"); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/_wfopen/test6/test6.cpp new file mode 100644 index 0000000000..17d36a0c50 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test6/test6.cpp @@ -0,0 +1,152 @@ +// 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: test6.c +** +** Purpose: Tests the PAL implementation of the _wfopen function. +** Test to ensure that you can write to an 'a' mode file. +** And that you can't read from a 'a' mode file. +** +** Depends: +** fprintf +** fgets +** fseek +** + +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + FILE *fp; + char buffer[128]; + WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; + WCHAR filename2[] = {'t','e','s','t','f','i','l','e','2','\0'}; + WCHAR append[] = {'a','\0'}; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Open a file with 'a' mode */ + if( (fp = _wfopen( filename, append )) == NULL ) + { + Fail( "ERROR: file failed to open with 'a' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read from the 'a' only file, should fail */ + if(fgets(buffer,10,fp) != NULL) + { + Fail("ERROR: Tried to READ from a file with 'a' mode set. " + "This should fail, but fgets returned success. Either fgets " + "or fopen is broken."); + } + + // Delete the file now that we're done with it. + if (fclose(fp) != 0) + { + Fail("ERROR: fclose failed to close \"testfile\".\n"); + } + + if (!DeleteFileA("testfile")) + { + Fail("ERROR: Failed to delete \"testfile\".\n" + " Error is %d\n", + GetLastError()); + } + + /* Attempt to write to a file after using 'a' and fseek */ + fp = _wfopen(filename2, append); + if(fp == NULL) + { + Fail("ERROR: _wfopen failed to be created with 'a' mode.\n"); + } + + /* write text to the file initially */ + if(fprintf(fp,"%s","abcd") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " + "but fprintf failed. Either fopen or fprintf have problems.\n"); + } + + /* set the pointer to the front of the file */ + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it.\n"); + } + + /* using 'a' should still write to the end of the file, not the front */ + if(fputs("efgh", fp) < 0) + { + Fail("ERROR: Attempt to WRITE with fputs to the beginning of a file " + "opened with 'a' mode succeeded.\n"); + } + + /* set the pointer to the front of the file */ + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it.\n"); + } + + /* a file with 'a' mode can only write, so close the file before reading */ + if(fclose(fp)) + { + Fail("ERROR: fclose failed when it should have succeeded.\n"); + } + + /* open the file again to read */ + fp = fopen("testfile2","r"); + if(fp == NULL) + { + Fail("ERROR: fopen failed to open the file using 'r' mode"); + } + + /* Attempt to read from the 'a' only file, should succeed */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'a' mode set. " + "This should pass, but fgets returned failure. Either fgets " + "or fopen is broken.\n"); + } + + /* Compare what was read and what should have been in the file */ + if(memcmp(buffer,"abcdefgh",8)) + { + Fail("ERROR: The string read should have equaled 'abcdefgh' " + "but instead it is %s\n", buffer); + } + + // Delete the file now that we're done with it. + if (fclose(fp) != 0) + { + Fail("ERROR: fclose failed to close \"testfile\".\n"); + } + + if (!DeleteFileA("testfile2")) + { + Fail("ERROR: Failed to delete \"testfile2\".\n"); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wfopen/test7/CMakeLists.txt index 47f4804b43..5d04528a21 100644 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_wfopen_test7 diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test7/test7.c b/src/pal/tests/palsuite/c_runtime/_wfopen/test7/test7.c deleted file mode 100644 index 0a889adc8a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wfopen/test7/test7.c +++ /dev/null @@ -1,119 +0,0 @@ -// 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: test7.c -** -** Purpose: Tests the PAL implementation of the _wfopen function. -** Test to ensure that you can write to an 'a+' mode file. -** And that you can read from a 'a+' mode file. -** -** Depends: -** fprintf -** fgets -** fseek -** - -** -**===================================================================*/ -#define UNICODE - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; - WCHAR filename2[] = {'t','e','s','t','f','i','l','e','2','\0'}; - WCHAR appendplus[] = {'a','+','\0'}; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'a+' mode */ - if( (fp = _wfopen( filename, appendplus )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'a+' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'a+' only file, should succeed */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'a+' mode set. " - "This should pass, but fgets returned failure. Either fgets " - "or fopen is broken."); - } - - - /* Attempt to write to a file after using 'a+' and fseek */ - fp = _wfopen(filename2, appendplus); - if(fp == NULL) - { - Fail("ERROR: _wfopen failed to be created with 'a+' mode.\n"); - } - - /* write text to the file initially */ - if(fprintf(fp,"%s","abcd") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " - "but fprintf failed. Either fopen or fprintf have problems.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* using 'a+' should still write to the end of the file, not the front */ - if(fputs("efgh",fp) < 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " - "but fputs failed.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* Attempt to read from the 'a+' only file, should succeed */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'a+' mode set. " - "This should pass, but fgets returned failure. Either fgets " - "or fopen is broken.\n"); - } - - /* Compare what was read and what should have been in the file */ - if(memcmp(buffer,"abcdefgh",8)) - { - Fail("ERROR: The string read should have equaled 'abcdefgh' " - "but instead it is %s\n", buffer); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/_wfopen/test7/test7.cpp new file mode 100644 index 0000000000..0a889adc8a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test7/test7.cpp @@ -0,0 +1,119 @@ +// 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: test7.c +** +** Purpose: Tests the PAL implementation of the _wfopen function. +** Test to ensure that you can write to an 'a+' mode file. +** And that you can read from a 'a+' mode file. +** +** Depends: +** fprintf +** fgets +** fseek +** + +** +**===================================================================*/ +#define UNICODE + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + WCHAR filename[] = {'t','e','s','t','f','i','l','e','\0'}; + WCHAR filename2[] = {'t','e','s','t','f','i','l','e','2','\0'}; + WCHAR appendplus[] = {'a','+','\0'}; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file with 'a+' mode */ + if( (fp = _wfopen( filename, appendplus )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'a+' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read from the 'a+' only file, should succeed */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'a+' mode set. " + "This should pass, but fgets returned failure. Either fgets " + "or fopen is broken."); + } + + + /* Attempt to write to a file after using 'a+' and fseek */ + fp = _wfopen(filename2, appendplus); + if(fp == NULL) + { + Fail("ERROR: _wfopen failed to be created with 'a+' mode.\n"); + } + + /* write text to the file initially */ + if(fprintf(fp,"%s","abcd") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " + "but fprintf failed. Either fopen or fprintf have problems.\n"); + } + + /* set the pointer to the front of the file */ + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it.\n"); + } + + /* using 'a+' should still write to the end of the file, not the front */ + if(fputs("efgh",fp) < 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " + "but fputs failed.\n"); + } + + /* set the pointer to the front of the file */ + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it.\n"); + } + + /* Attempt to read from the 'a+' only file, should succeed */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'a+' mode set. " + "This should pass, but fgets returned failure. Either fgets " + "or fopen is broken.\n"); + } + + /* Compare what was read and what should have been in the file */ + if(memcmp(buffer,"abcdefgh",8)) + { + Fail("ERROR: The string read should have equaled 'abcdefgh' " + "but instead it is %s\n", buffer); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/_wmakepath/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wmakepath/CMakeLists.txt deleted file mode 100644 index f6aa0cb2d9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wmakepath/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/_wmakepath/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wmakepath/test1/CMakeLists.txt deleted file mode 100644 index 343cb41f51..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wmakepath/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_wmakepath_test1 - ${SOURCES} -) - -add_dependencies(paltest_wmakepath_test1 coreclrpal) - -target_link_libraries(paltest_wmakepath_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_wmakepath/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_wmakepath/test1/test1.c deleted file mode 100644 index eb79dc6286..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wmakepath/test1/test1.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the _wmakepath function. -** Create a path, and ensure that it builds how it is -** supposed to. -** -** -**===================================================================*/ - -#define UNICODE - -#include - -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; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/_wmakepath/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_wmakepath/test1/testinfo.dat deleted file mode 100644 index 6720d342ce..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wmakepath/test1/testinfo.dat +++ /dev/null @@ -1,13 +0,0 @@ -# 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 = C Runtime -Function = _wmakepath -Name = Positive Test for _wmakepath -TYPE = DEFAULT -EXE1 = test1 -Description -= Purpose: Tests the PAL implementation of the _wmakepath function. -= Create a path, and ensure that it builds how it is supposed to. diff --git a/src/pal/tests/palsuite/c_runtime/_wsplitpath/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wsplitpath/CMakeLists.txt deleted file mode 100644 index f6aa0cb2d9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wsplitpath/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/CMakeLists.txt deleted file mode 100644 index ee9a7a8e96..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_wsplitpath_test1 - ${SOURCES} -) - -add_dependencies(paltest_wsplitpath_test1 coreclrpal) - -target_link_libraries(paltest_wsplitpath_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/test1.c deleted file mode 100644 index 305768e53a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/test1.c +++ /dev/null @@ -1,151 +0,0 @@ -// 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: test1.c -** -** Purpose: Passes _wsplitpath() a series of sample paths and checks -** that it parses them as expected. -** -** -**==========================================================================*/ - - -#include - -struct testCase -{ - char path[_MAX_PATH]; /* The path to parse. */ - char drive[_MAX_DRIVE]; /* The expected values... */ - char dir[_MAX_DIR]; - char fname[_MAX_FNAME]; - char ext[_MAX_EXT]; -}; - -struct wTestCase -{ - WCHAR *path; /* The path to parse. */ - WCHAR *drive; /* The expected values... */ - WCHAR *dir; - WCHAR *fname; - WCHAR *ext; -}; - - - -int __cdecl main(int argc, char **argv) -{ - struct testCase testCases[] = - { -#if WIN32 - {"c:\\foo\\bar\\foo.bar", "c:", "\\foo\\bar\\", "foo", ".bar"}, - {"c:/foo/bar/foo.bar", "c:", "/foo/bar/", "foo", ".bar"}, - {"c:/foo/bar/foo", "c:", "/foo/bar/", "foo", ""}, - {"c:/foo/bar/.bar", "c:", "/foo/bar/", "", ".bar"}, - {"c:/foo/bar/", "c:", "/foo/bar/", "", ""}, - {"/foo/bar/foo.bar", "", "/foo/bar/", "foo", ".bar"}, - {"c:foo.bar", "c:", "", "foo", ".bar"} -#else - {"c:\\foo\\bar\\foo.bar", "","c:/foo/bar/", "foo", ".bar"}, - {"c:/foo/bar/foo.bar", "", "c:/foo/bar/", "foo", ".bar"}, - {"c:/foo/bar/foo", "", "c:/foo/bar/", "foo", ""}, - {"c:/foo/bar/.bar", "", "c:/foo/bar/", ".bar", ""}, - {"c:/foo/bar/", "", "c:/foo/bar/", "", ""}, - {"/foo/bar/foo.bar", "", "/foo/bar/", "foo", ".bar"}, - {"c:foo.bar", "", "", "c:foo", ".bar"} -#endif - }; - - struct wTestCase wTestCases[sizeof(testCases)/sizeof(struct testCase)]; - - wchar_t wDrive[_MAX_DRIVE]; - wchar_t wDir[_MAX_DIR]; - wchar_t wFname[_MAX_FNAME]; - wchar_t wExt[_MAX_EXT]; - - char *drive; - char *dir; - char *fname; - char *ext; - - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /*create wide character versions of the test cases*/ - for(i = 0; i < sizeof(testCases)/sizeof(struct testCase); i ++) - { - wTestCases[i].path = convert(testCases[i].path); - wTestCases[i].drive = convert(testCases[i].drive); - wTestCases[i].dir = convert(testCases[i].dir); - wTestCases[i].fname = convert(testCases[i].fname); - wTestCases[i].ext = convert(testCases[i].ext); - } - - - for (i = 0; i < sizeof(wTestCases)/sizeof(struct wTestCase); i++) - { - _wsplitpath(wTestCases[i].path, wDrive, wDir, wFname, wExt); - - /*Convert the results to regular ANSI strings.*/ - drive = convertC(wDrive); - dir = convertC(wDir); - fname = convertC(wFname); - ext = convertC(wExt); - - - /*on platforms that don't support drive letters, the drive - returned should always be "" */ - if (wcscmp(wDrive, wTestCases[i].drive) != 0) - { - Fail("_wsplitpath read the path \"%s\" and thought the drive was " - "\"%s\" instead of \"%s\"" - , testCases[i].path, drive, testCases[i].drive); - } - - if (wcscmp(wDir, wTestCases[i].dir) != 0) - { - Fail("_wsplitpath read the path \"%s\" and thought the directory " - "was \"%s\" instead of \"%s\"" - , testCases[i].path, dir, testCases[i].dir); - } - - if (wcscmp(wFname, wTestCases[i].fname) != 0) - { - Fail("_wsplitpath read the path \"%s\" and thought the filename " - "was \"%s\" instead of \"%s\"" - , testCases[i].path, fname, testCases[i].fname); - } - - if (wcscmp(wExt, wTestCases[i].ext) != 0) - { - Fail("_wsplitpath read the path \"%s\" and thought the file " - "extension was \"%s\" instead of \"%s\"" - , testCases[i].path, ext, testCases[i].ext); - } - - free(drive); - free(dir); - free(fname); - free(ext); - } - - for(i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) - { - free(wTestCases[i].path); - free(wTestCases[i].drive); - free(wTestCases[i].dir); - free(wTestCases[i].fname); - free(wTestCases[i].ext); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/testinfo.dat deleted file mode 100644 index 30be680bb4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/testinfo.dat +++ /dev/null @@ -1,15 +0,0 @@ -# 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 = C Runtime -Function = _wsplitpath -Name = Positive Test for _wsplitpath -TYPE = DEFAULT -EXE1 = test1 -Description -= Passes _wsplitpath() a series of sample paths and checks that it -= parses them as expected. - - diff --git a/src/pal/tests/palsuite/c_runtime/_wtoi/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wtoi/test1/CMakeLists.txt index 9e6610fc0f..ed02fec3af 100644 --- a/src/pal/tests/palsuite/c_runtime/_wtoi/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/_wtoi/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wtoi_test1 diff --git a/src/pal/tests/palsuite/c_runtime/_wtoi/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_wtoi/test1/test1.c deleted file mode 100644 index 0b14dedd60..0000000000 --- a/src/pal/tests/palsuite/c_runtime/_wtoi/test1/test1.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the _wtoi function. -** Check to ensure that the different ints are handled properly. -** Exponents and decimals should be treated as invalid characters, -** causing the conversion to quit. Whitespace before the int is valid. -** Check would-be octal/hex digits to ensure they're treated no -** differently than other strings. -** -** -**===================================================================*/ - -#include - - -struct testCase -{ - int IntValue; - char avalue[20]; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result=0; - int i=0; - WCHAR* temp; - - struct testCase testCases[] = - { - {1234, "1234"}, - {-1234, "-1234"}, - {1234, "+1234"}, - {1234, "1234.44"}, - {1234, "1234e-5"}, - {1234, "1234e+5"}, - {1234, "1234E5"}, - {1234, "\t1234"}, - {0, "0x21"}, - {17, "017"}, - {1234, "1234.657e-8"}, - {1234567, " 1234567e-8 foo"}, - {0, "foo 32 bar"} - }; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Loop through each case. Convert the wide string to an int - and then compare to ensure that it is the correct value. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /* Convert to a wide string, then call _wtoi to convert to an int */ - temp = convert(testCases[i].avalue); - result = _wtoi(temp); - free(temp); - if (testCases[i].IntValue != result) - { - Fail("ERROR: _wtoi misinterpreted \"%s\" as %i instead of %i.\n", - testCases[i].avalue, - result, - testCases[i].IntValue); - } - - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/_wtoi/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_wtoi/test1/test1.cpp new file mode 100644 index 0000000000..0b14dedd60 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_wtoi/test1/test1.cpp @@ -0,0 +1,79 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the _wtoi function. +** Check to ensure that the different ints are handled properly. +** Exponents and decimals should be treated as invalid characters, +** causing the conversion to quit. Whitespace before the int is valid. +** Check would-be octal/hex digits to ensure they're treated no +** differently than other strings. +** +** +**===================================================================*/ + +#include + + +struct testCase +{ + int IntValue; + char avalue[20]; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result=0; + int i=0; + WCHAR* temp; + + struct testCase testCases[] = + { + {1234, "1234"}, + {-1234, "-1234"}, + {1234, "+1234"}, + {1234, "1234.44"}, + {1234, "1234e-5"}, + {1234, "1234e+5"}, + {1234, "1234E5"}, + {1234, "\t1234"}, + {0, "0x21"}, + {17, "017"}, + {1234, "1234.657e-8"}, + {1234567, " 1234567e-8 foo"}, + {0, "foo 32 bar"} + }; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Convert the wide string to an int + and then compare to ensure that it is the correct value. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /* Convert to a wide string, then call _wtoi to convert to an int */ + temp = convert(testCases[i].avalue); + result = _wtoi(temp); + free(temp); + if (testCases[i].IntValue != result) + { + Fail("ERROR: _wtoi misinterpreted \"%s\" as %i instead of %i.\n", + testCases[i].avalue, + result, + testCases[i].IntValue); + } + + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/abs/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/abs/test1/CMakeLists.txt index c8a8595d01..b01d97ff2f 100644 --- a/src/pal/tests/palsuite/c_runtime/abs/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/abs/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - abs.c + abs.cpp ) add_executable(paltest_abs_test1 diff --git a/src/pal/tests/palsuite/c_runtime/abs/test1/abs.c b/src/pal/tests/palsuite/c_runtime/abs/test1/abs.c deleted file mode 100644 index 233a5dcb30..0000000000 --- a/src/pal/tests/palsuite/c_runtime/abs/test1/abs.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: abs.c (test 1) -** -** Purpose: Tests the PAL implementation of the abs function. -** -** -**===================================================================*/ - -#include - -struct TESTS -{ - int nTest; - int nResult; -}; - -int __cdecl main(int argc, char *argv[]) -{ - int i = 0; - int nRc = 0; - struct TESTS testCase[] = - { - {0, 0}, - {1, 1}, - {-1, 1} - }; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - for (i = 0; i < (sizeof(testCase)/sizeof(struct TESTS)); i++) - { - nRc = abs(testCase[i].nTest); - if (nRc != testCase[i].nResult) - { - Fail("abs: ERROR -> abs(%d) returned %d " - "when it was expected to return %d \n", - testCase[i].nTest, - nRc, - testCase[i].nResult); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/abs/test1/abs.cpp b/src/pal/tests/palsuite/c_runtime/abs/test1/abs.cpp new file mode 100644 index 0000000000..233a5dcb30 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/abs/test1/abs.cpp @@ -0,0 +1,54 @@ +// 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: abs.c (test 1) +** +** Purpose: Tests the PAL implementation of the abs function. +** +** +**===================================================================*/ + +#include + +struct TESTS +{ + int nTest; + int nResult; +}; + +int __cdecl main(int argc, char *argv[]) +{ + int i = 0; + int nRc = 0; + struct TESTS testCase[] = + { + {0, 0}, + {1, 1}, + {-1, 1} + }; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + for (i = 0; i < (sizeof(testCase)/sizeof(struct TESTS)); i++) + { + nRc = abs(testCase[i].nTest); + if (nRc != testCase[i].nResult) + { + Fail("abs: ERROR -> abs(%d) returned %d " + "when it was expected to return %d \n", + testCase[i].nTest, + nRc, + testCase[i].nResult); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/acos/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acos/test1/CMakeLists.txt index 978ab427e8..5bd3ae06e8 100644 --- a/src/pal/tests/palsuite/c_runtime/acos/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/acos/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_acos_test1 diff --git a/src/pal/tests/palsuite/c_runtime/acos/test1/test1.c b/src/pal/tests/palsuite/c_runtime/acos/test1/test1.c deleted file mode 100644 index c6ed0692c7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/acos/test1/test1.c +++ /dev/null @@ -1,130 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that acos return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = acos(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("acos(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = acos(value); - - if (!_isnan(result)) - { - Fail("acos(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { -1, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi - { -0.91173391478696510, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e - { -0.66820151019031295, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) - { 0, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 - { 0.12775121753523991, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) - { 0.15594369476537447, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) - { 0.42812514788535792, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) - { 0.54030230586813972, 1, PAL_EPSILON * 10 }, - { 0.70710678118654752, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4, value: 1 / sqrt(2) - { 0.76024459707563015, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) - { 0.76923890136397213, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) - { 0.80410982822879171, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi - { 0.90716712923909839, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) - { 0.94976571538163866, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi - { 1, 0, PAL_EPSILON }, - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate(tests[i].value, tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NEGINF); - validate_isnan(PAL_NAN); - validate_isnan(PAL_POSINF); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/acos/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/acos/test1/test1.cpp new file mode 100644 index 0000000000..c6ed0692c7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acos/test1/test1.cpp @@ -0,0 +1,130 @@ +// 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: test1.c +** +** Purpose: Test to ensure that acos return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = acos(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("acos(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = acos(value); + + if (!_isnan(result)) + { + Fail("acos(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { -1, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi + { -0.91173391478696510, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e + { -0.66820151019031295, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) + { 0, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + { 0.12775121753523991, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) + { 0.15594369476537447, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) + { 0.42812514788535792, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) + { 0.54030230586813972, 1, PAL_EPSILON * 10 }, + { 0.70710678118654752, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4, value: 1 / sqrt(2) + { 0.76024459707563015, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) + { 0.76923890136397213, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) + { 0.80410982822879171, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi + { 0.90716712923909839, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) + { 0.94976571538163866, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi + { 1, 0, PAL_EPSILON }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/acosf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acosf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/acosf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acosf/test1/CMakeLists.txt new file mode 100644 index 0000000000..2643647438 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_acosf_test1 + ${SOURCES} +) + +add_dependencies(paltest_acosf_test1 coreclrpal) + +target_link_libraries(paltest_acosf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/acosf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/acosf/test1/test1.c new file mode 100644 index 0000000000..3d8668cebb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosf/test1/test1.c @@ -0,0 +1,129 @@ +// 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: test1.c +** +** Purpose: Test to ensure that acosf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = acosf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("acosf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = acosf(value); + + if (!_isnanf(result)) + { + Fail("acosf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { -1, 3.14159265f, PAL_EPSILON * 10 }, // expected: pi + { -0.911733915f, 2.71828183f, PAL_EPSILON * 10 }, // expected: e + { -0.668201510f, 2.30258509f, PAL_EPSILON * 10 }, // expected: ln(10) + { 0, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + { 0.127751218f, 1.44269504f, PAL_EPSILON * 10 }, // expected: logf2(e) + { 0.155943695f, 1.41421356f, PAL_EPSILON * 10 }, // expected: sqrtf(2) + { 0.428125148f, 1.12837917f, PAL_EPSILON * 10 }, // expected: 2 / sqrtf(pi) + { 0.540302306f, 1, PAL_EPSILON * 10 }, + { 0.707106781f, 0.785398163f, PAL_EPSILON }, // expected: pi / 4, value: 1 / sqrtf(2) + { 0.760244597f, 0.707106781f, PAL_EPSILON }, // expected: 1 / sqrtf(2) + { 0.769238901f, 0.693147181f, PAL_EPSILON }, // expected: ln(2) + { 0.804109828f, 0.636619772f, PAL_EPSILON }, // expected: 2 / pi + { 0.907167129f, 0.434294482f, PAL_EPSILON }, // expected: logf10f(e) + { 0.949765715f, 0.318309886f, PAL_EPSILON }, // expected: 1 / pi + { 1, 0, PAL_EPSILON }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/acosf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/acosf/test1/testinfo.dat new file mode 100644 index 0000000000..41cead33bb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = acosf +Name = Positive Test for acosf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the acosf() function, += checking each for the expfected result. Also checks += for proper handling of out-of-range values. diff --git a/src/pal/tests/palsuite/c_runtime/asin/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asin/test1/CMakeLists.txt index a3aec3f60f..510b543a59 100644 --- a/src/pal/tests/palsuite/c_runtime/asin/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/asin/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_asin_test1 diff --git a/src/pal/tests/palsuite/c_runtime/asin/test1/test1.c b/src/pal/tests/palsuite/c_runtime/asin/test1/test1.c deleted file mode 100644 index 0a63356ed0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/asin/test1/test1.c +++ /dev/null @@ -1,146 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that asin return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = asin(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("asin(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = asin(value); - - if (!_isnan(result)) - { - Fail("asin(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * validate - * - * test validation function for values returning +INF - */ -void __cdecl validate_isinf_positive(double value) -{ - double result = asin(value); - - if (result != PAL_POSINF) - { - Fail("asin(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_POSINF); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, 0, PAL_EPSILON }, - { 0.31296179620778659, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi - { 0.41078129050290870, 0.42331082513074800, PAL_EPSILON }, // expected: pi - e - { 0.42077048331375735, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) - { 0.59448076852482208, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi - { 0.63896127631363480, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) - { 0.64963693908006244, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) - { 0.70710678118654752, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4, value: 1 / sqrt(2) - { 0.74398033695749319, 0.83900756059574755, PAL_EPSILON }, // expected: pi - ln(10) - { 0.84147098480789651, 1, PAL_EPSILON * 10 }, - { 0.90371945743584630, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) - { 0.98776594599273553, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) - { 0.99180624439366372, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) - { 1, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, -tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NEGINF); - validate_isnan(PAL_NAN); - validate_isnan(PAL_POSINF); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/asin/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/asin/test1/test1.cpp new file mode 100644 index 0000000000..0a63356ed0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asin/test1/test1.cpp @@ -0,0 +1,146 @@ +// 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: test1.c +** +** Purpose: Test to ensure that asin return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = asin(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("asin(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = asin(value); + + if (!_isnan(result)) + { + Fail("asin(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * validate + * + * test validation function for values returning +INF + */ +void __cdecl validate_isinf_positive(double value) +{ + double result = asin(value); + + if (result != PAL_POSINF) + { + Fail("asin(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_POSINF); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.31296179620778659, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi + { 0.41078129050290870, 0.42331082513074800, PAL_EPSILON }, // expected: pi - e + { 0.42077048331375735, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) + { 0.59448076852482208, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi + { 0.63896127631363480, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) + { 0.64963693908006244, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) + { 0.70710678118654752, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4, value: 1 / sqrt(2) + { 0.74398033695749319, 0.83900756059574755, PAL_EPSILON }, // expected: pi - ln(10) + { 0.84147098480789651, 1, PAL_EPSILON * 10 }, + { 0.90371945743584630, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) + { 0.98776594599273553, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) + { 0.99180624439366372, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) + { 1, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/asinf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asinf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/asinf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asinf/test1/CMakeLists.txt new file mode 100644 index 0000000000..b167bd8715 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_asinf_test1 + ${SOURCES} +) + +add_dependencies(paltest_asinf_test1 coreclrpal) + +target_link_libraries(paltest_asinf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/asinf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/asinf/test1/test1.c new file mode 100644 index 0000000000..773015eec0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinf/test1/test1.c @@ -0,0 +1,145 @@ +// 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: test1.c +** +** Purpose: Test to ensure that asinf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = asinf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("asinf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = asinf(value); + + if (!_isnanf(result)) + { + Fail("asinf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * validate + * + * test validation function for values returning +INF + */ +void __cdecl validate_isinf_positive(float value) +{ + float result = asinf(value); + + if (result != PAL_POSINF) + { + Fail("asinf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_POSINF); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.312961796f, 0.318309886f, PAL_EPSILON }, // expected: 1 / pi + { 0.410781291f, 0.423310825f, PAL_EPSILON }, // expected: pi - e + { 0.420770483f, 0.434294482f, PAL_EPSILON }, // expected: logf10f(e) + { 0.594480769f, 0.636619772f, PAL_EPSILON }, // expected: 2 / pi + { 0.638961276f, 0.693147181f, PAL_EPSILON }, // expected: ln(2) + { 0.649636939f, 0.707106781f, PAL_EPSILON }, // expected: 1 / sqrtf(2) + { 0.707106781f, 0.785398163f, PAL_EPSILON }, // expected: pi / 4, value: 1 / sqrtf(2) + { 0.743980337f, 0.839007561f, PAL_EPSILON }, // expected: pi - ln(10) + { 0.841470985f, 1, PAL_EPSILON * 10 }, + { 0.903719457f, 1.12837917f, PAL_EPSILON * 10 }, // expected: 2 / sqrtf(pi) + { 0.987765946f, 1.41421356f, PAL_EPSILON * 10 }, // expected: sqrtf(2) + { 0.991806244f, 1.44269504f, PAL_EPSILON * 10 }, // expected: logf2(e) + { 1, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/asinf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/asinf/test1/testinfo.dat new file mode 100644 index 0000000000..ca2dd42150 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = asinf +Name = Positive Test for asinf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the asinf() function, += checking each for the expected result. Also checks += for proper handling of out-of-range values. diff --git a/src/pal/tests/palsuite/c_runtime/atan/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atan/test1/CMakeLists.txt index b0b84e7c07..ace64e48bc 100644 --- a/src/pal/tests/palsuite/c_runtime/atan/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/atan/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_atan_test1 diff --git a/src/pal/tests/palsuite/c_runtime/atan/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atan/test1/test1.c deleted file mode 100644 index 6840d46172..0000000000 --- a/src/pal/tests/palsuite/c_runtime/atan/test1/test1.c +++ /dev/null @@ -1,128 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that atan return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = atan(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("atan(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = atan(value); - - if (!_isnan(result)) - { - Fail("atan(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, 0, PAL_EPSILON }, - { 0.32951473309607836, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi - { 0.45054953406980750, 0.42331082513074800, PAL_EPSILON }, // expected: pi - e - { 0.46382906716062964, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) - { 0.73930295048660405, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi - { 0.83064087786078395, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) - { 0.85451043200960189, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) - { 1, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 - { 1.1134071468135374, 0.83900756059574755, PAL_EPSILON }, // expected: pi - ln(10) - { 1.5574077246549022, 1, PAL_EPSILON * 10 }, - { 2.1108768356626451, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) - { 6.3341191670421916, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) - { 7.7635756709721848, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) - { PAL_POSINF, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, -tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/atan/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/atan/test1/test1.cpp new file mode 100644 index 0000000000..6840d46172 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan/test1/test1.cpp @@ -0,0 +1,128 @@ +// 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: test1.c +** +** Purpose: Test to ensure that atan return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = atan(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("atan(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = atan(value); + + if (!_isnan(result)) + { + Fail("atan(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.32951473309607836, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi + { 0.45054953406980750, 0.42331082513074800, PAL_EPSILON }, // expected: pi - e + { 0.46382906716062964, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) + { 0.73930295048660405, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi + { 0.83064087786078395, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) + { 0.85451043200960189, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) + { 1, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 + { 1.1134071468135374, 0.83900756059574755, PAL_EPSILON }, // expected: pi - ln(10) + { 1.5574077246549022, 1, PAL_EPSILON * 10 }, + { 2.1108768356626451, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) + { 6.3341191670421916, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) + { 7.7635756709721848, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) + { PAL_POSINF, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/atan2/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atan2/test1/CMakeLists.txt index 8bd69da2fa..cafa09f7fe 100644 --- a/src/pal/tests/palsuite/c_runtime/atan2/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/atan2/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_atan2_test1 diff --git a/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.c deleted file mode 100644 index 15aa8f53b9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.c +++ /dev/null @@ -1,148 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that atan2 returns correct values for a subset of values. -** Tests with positive and negative values of x and y to ensure -** atan2 is returning results from the correct quadrant. -** -**===================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -struct test -{ - double y; /* second component of the value to test the function with */ - double x; /* first component of the value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double y, double x, double expected, double variance) -{ - double result = atan2(y, x); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("atan2(%g, %g) returned %20.17g when it should have returned %20.17g", - y, x, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double y, double x) -{ - double result = atan2(y, x); - - if (!_isnan(result)) - { - Fail("atan2(%g, %g) returned %20.17g when it should have returned %20.17g", - y, x, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* y x expected variance */ - { 0, PAL_POSINF, 0, PAL_EPSILON }, - { 0, 0, 0, PAL_EPSILON }, - { 0.31296179620778659, 0.94976571538163866, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi - { 0.42077048331375735, 0.90716712923909839, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) - { 0.59448076852482208, 0.80410982822879171, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi - { 0.63896127631363480, 0.76923890136397213, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) - { 0.64963693908006244, 0.76024459707563015, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) - { 0.70710678118654752, 0.70710678118654752, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4, value: 1 / sqrt(2) - { 1, 1, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 - { PAL_POSINF, PAL_POSINF, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 - { 0.84147098480789651, 0.54030230586813972, 1, PAL_EPSILON * 10 }, - { 0.90371945743584630, 0.42812514788535792, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) - { 0.98776594599273553, 0.15594369476537447, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) - { 0.99180624439366372, 0.12775121753523991, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) - { 1, 0, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 - { PAL_POSINF, 0, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 - { PAL_POSINF, 1, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 - { 0.74398033695749319, -0.66820151019031295, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) - { 0.41078129050290870, -0.91173391478696510, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e - { 0, -1, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi - { 1, PAL_POSINF, 0, PAL_EPSILON }, - }; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - const double pi = 3.1415926535897932; - - validate( tests[i].y, tests[i].x, tests[i].expected, tests[i].variance); - validate(-tests[i].y, tests[i].x, -tests[i].expected, tests[i].variance); - validate( tests[i].y, -tests[i].x, pi - tests[i].expected, tests[i].variance); - validate(-tests[i].y, -tests[i].x, tests[i].expected - pi, tests[i].variance); - } - - validate_isnan(PAL_NEGINF, PAL_NAN); - validate_isnan(PAL_NAN, PAL_NEGINF); - validate_isnan(PAL_NAN, PAL_POSINF); - validate_isnan(PAL_POSINF, PAL_NAN); - - validate_isnan(PAL_NAN, -1); - validate_isnan(PAL_NAN, -0.0); - validate_isnan(PAL_NAN, 0); - validate_isnan(PAL_NAN, 1); - - validate_isnan(-1, PAL_NAN); - validate_isnan(-0.0, PAL_NAN); - validate_isnan( 0, PAL_NAN); - validate_isnan( 1, PAL_NAN); - - validate_isnan(PAL_NAN, PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.cpp new file mode 100644 index 0000000000..15aa8f53b9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.cpp @@ -0,0 +1,148 @@ +// 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: test1.c +** +** Purpose: Tests that atan2 returns correct values for a subset of values. +** Tests with positive and negative values of x and y to ensure +** atan2 is returning results from the correct quadrant. +** +**===================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +struct test +{ + double y; /* second component of the value to test the function with */ + double x; /* first component of the value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double y, double x, double expected, double variance) +{ + double result = atan2(y, x); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("atan2(%g, %g) returned %20.17g when it should have returned %20.17g", + y, x, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double y, double x) +{ + double result = atan2(y, x); + + if (!_isnan(result)) + { + Fail("atan2(%g, %g) returned %20.17g when it should have returned %20.17g", + y, x, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* y x expected variance */ + { 0, PAL_POSINF, 0, PAL_EPSILON }, + { 0, 0, 0, PAL_EPSILON }, + { 0.31296179620778659, 0.94976571538163866, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi + { 0.42077048331375735, 0.90716712923909839, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) + { 0.59448076852482208, 0.80410982822879171, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi + { 0.63896127631363480, 0.76923890136397213, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) + { 0.64963693908006244, 0.76024459707563015, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) + { 0.70710678118654752, 0.70710678118654752, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4, value: 1 / sqrt(2) + { 1, 1, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 + { PAL_POSINF, PAL_POSINF, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 + { 0.84147098480789651, 0.54030230586813972, 1, PAL_EPSILON * 10 }, + { 0.90371945743584630, 0.42812514788535792, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) + { 0.98776594599273553, 0.15594369476537447, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) + { 0.99180624439366372, 0.12775121753523991, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) + { 1, 0, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + { PAL_POSINF, 0, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + { PAL_POSINF, 1, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + { 0.74398033695749319, -0.66820151019031295, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) + { 0.41078129050290870, -0.91173391478696510, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e + { 0, -1, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi + { 1, PAL_POSINF, 0, PAL_EPSILON }, + }; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + const double pi = 3.1415926535897932; + + validate( tests[i].y, tests[i].x, tests[i].expected, tests[i].variance); + validate(-tests[i].y, tests[i].x, -tests[i].expected, tests[i].variance); + validate( tests[i].y, -tests[i].x, pi - tests[i].expected, tests[i].variance); + validate(-tests[i].y, -tests[i].x, tests[i].expected - pi, tests[i].variance); + } + + validate_isnan(PAL_NEGINF, PAL_NAN); + validate_isnan(PAL_NAN, PAL_NEGINF); + validate_isnan(PAL_NAN, PAL_POSINF); + validate_isnan(PAL_POSINF, PAL_NAN); + + validate_isnan(PAL_NAN, -1); + validate_isnan(PAL_NAN, -0.0); + validate_isnan(PAL_NAN, 0); + validate_isnan(PAL_NAN, 1); + + validate_isnan(-1, PAL_NAN); + validate_isnan(-0.0, PAL_NAN); + validate_isnan( 0, PAL_NAN); + validate_isnan( 1, PAL_NAN); + + validate_isnan(PAL_NAN, PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/atan2f/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atan2f/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan2f/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/atan2f/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atan2f/test1/CMakeLists.txt new file mode 100644 index 0000000000..d71a61b17b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan2f/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_atan2f_test1 + ${SOURCES} +) + +add_dependencies(paltest_atan2f_test1 coreclrpal) + +target_link_libraries(paltest_atan2f_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/atan2f/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atan2f/test1/test1.c new file mode 100644 index 0000000000..2ee641e8d4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan2f/test1/test1.c @@ -0,0 +1,147 @@ +// 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: test1.c +** +** Purpose: Tests that atan2f returns correct values for a subset of values. +** Tests with positive and negative values of x and y to ensure +** atan2f is returning results from the correct quadrant. +** +**===================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +struct test +{ + float y; /* second component of the value to test the function with */ + float x; /* first component of the value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float y, float x, float expected, float variance) +{ + float result = atan2f(y, x); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("atan2f(%g, %g) returned %10.9g when it should have returned %10.9g", + y, x, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float y, float x) +{ + float result = atan2f(y, x); + + if (!_isnanf(result)) + { + Fail("atan2f(%g, %g) returned %10.9g when it should have returned %10.9g", + y, x, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* y x expected variance */ + { 0, PAL_POSINF, 0, PAL_EPSILON }, + { 0, 0, 0, PAL_EPSILON }, + { 0.312961796f, 0.949765715f, 0.318309886f, PAL_EPSILON }, // expected: 1 / pi + { 0.420770483f, 0.907167129f, 0.434294482f, PAL_EPSILON }, // expected: logf10f(e) + { 0.594480769f, 0.804109828f, 0.636619772f, PAL_EPSILON }, // expected: 2 / pi + { 0.638961276f, 0.769238901f, 0.693147181f, PAL_EPSILON }, // expected: ln(2) + { 0.649636939f, 0.760244597f, 0.707106781f, PAL_EPSILON }, // expected: 1 / sqrtf(2) + { 0.707106781f, 0.707106781f, 0.785398163f, PAL_EPSILON }, // expected: pi / 4, value: 1 / sqrtf(2) + { 1, 1, 0.785398163f, PAL_EPSILON }, // expected: pi / 4 + { PAL_POSINF, PAL_POSINF, 0.785398163f, PAL_EPSILON }, // expected: pi / 4 + { 0.841470985f, 0.540302306f, 1, PAL_EPSILON * 10 }, + { 0.903719457f, 0.428125148f, 1.12837917f, PAL_EPSILON * 10 }, // expected: 2 / sqrtf(pi) + { 0.987765946f, 0.155943695f, 1.41421356f, PAL_EPSILON * 10 }, // expected: sqrtf(2) + { 0.991806244f, 0.127751218f, 1.44269504f, PAL_EPSILON * 10 }, // expected: logf2(e) + { 1, 0, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + { PAL_POSINF, 0, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + { PAL_POSINF, 1, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + { 0.743980337f, -0.668201510f, 2.30258509f, PAL_EPSILON * 10 }, // expected: ln(10) + { 0.410781291f, -0.911733915f, 2.71828183f, PAL_EPSILON * 10 }, // expected: e + { 0, -1, 3.14159265f, PAL_EPSILON * 10 }, // expected: pi + { 1, PAL_POSINF, 0, PAL_EPSILON }, + }; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + const float pi = 3.14159265f; + + validate( tests[i].y, tests[i].x, tests[i].expected, tests[i].variance); + validate(-tests[i].y, tests[i].x, -tests[i].expected, tests[i].variance); + validate( tests[i].y, -tests[i].x, pi - tests[i].expected, tests[i].variance); + validate(-tests[i].y, -tests[i].x, tests[i].expected - pi, tests[i].variance); + } + + validate_isnan(PAL_NEGINF, PAL_NAN); + validate_isnan(PAL_NAN, PAL_NEGINF); + validate_isnan(PAL_NAN, PAL_POSINF); + validate_isnan(PAL_POSINF, PAL_NAN); + + validate_isnan(PAL_NAN, -1); + validate_isnan(PAL_NAN, -0.0f); + validate_isnan(PAL_NAN, 0); + validate_isnan(PAL_NAN, 1); + + validate_isnan(-1, PAL_NAN); + validate_isnan(-0.0f, PAL_NAN); + validate_isnan( 0, PAL_NAN); + validate_isnan( 1, PAL_NAN); + + validate_isnan(PAL_NAN, PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/atan2f/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/atan2f/test1/testinfo.dat new file mode 100644 index 0000000000..bd9a9d9b93 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan2f/test1/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = atan2f +Name = Test #1 for atan2f +Type = DEFAULT +EXE1 = test1 +Description +=Tests that atan2f returns correct values for a subset of values. +=Tests with positive and negative values of x and y to ensure +=atan2f is returning results from the correct quadrant. diff --git a/src/pal/tests/palsuite/c_runtime/atanf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atanf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/atanf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atanf/test1/CMakeLists.txt new file mode 100644 index 0000000000..b71b1cf40c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_atanf_test1 + ${SOURCES} +) + +add_dependencies(paltest_atanf_test1 coreclrpal) + +target_link_libraries(paltest_atanf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/atanf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atanf/test1/test1.c new file mode 100644 index 0000000000..543a0a8168 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanf/test1/test1.c @@ -0,0 +1,127 @@ +// 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: test1.c +** +** Purpose: Test to ensure that atanf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = atanf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("atanf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = atanf(value); + + if (!_isnanf(result)) + { + Fail("atanf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.329514733f, 0.318309886f, PAL_EPSILON }, // expected: 1 / pi + { 0.450549534f, 0.423310825f, PAL_EPSILON }, // expected: pi - e + { 0.463829067f, 0.434294482f, PAL_EPSILON }, // expected: logf10f(e) + { 0.739302950f, 0.636619772f, PAL_EPSILON }, // expected: 2 / pi + { 0.830640878f, 0.693147181f, PAL_EPSILON }, // expected: ln(2) + { 0.854510432f, 0.707106781f, PAL_EPSILON }, // expected: 1 / sqrtf(2) + { 1, 0.785398163f, PAL_EPSILON }, // expected: pi / 4 + { 1.11340715f, 0.839007561f, PAL_EPSILON }, // expected: pi - ln(10) + { 1.55740772f, 1, PAL_EPSILON * 10 }, + { 2.11087684f, 1.12837917f, PAL_EPSILON * 10 }, // expected: 2 / sqrtf(pi) + { 6.33411917f, 1.41421356f, PAL_EPSILON * 10 }, // expected: sqrtf(2) + { 7.76357567f, 1.44269504f, PAL_EPSILON * 10 }, // expected: logf2(e) + { PAL_POSINF, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/atanf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/atanf/test1/testinfo.dat new file mode 100644 index 0000000000..0d184272a2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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 = C Runtime +Function = atanf +Name = Positive Test for atanf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the atanf() function, += checking each for the expected result. diff --git a/src/pal/tests/palsuite/c_runtime/atof/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atof/test1/CMakeLists.txt index 1f34b7ebf5..12e584b9a0 100644 --- a/src/pal/tests/palsuite/c_runtime/atof/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/atof/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_atof_test1 diff --git a/src/pal/tests/palsuite/c_runtime/atof/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atof/test1/test1.c deleted file mode 100644 index a973133f9e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/atof/test1/test1.c +++ /dev/null @@ -1,75 +0,0 @@ -// 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: test1.c -** -** Purpose: Passes to atof() a series of strings containing floats, -** checking that each one is correctly extracted. -** -** -**==========================================================================*/ - -#include -#include - -struct testCase -{ - float fvalue; - char avalue[20]; -}; - -int __cdecl main(int argc, char **argv) -{ - int i = 0; - double f = 0; - struct testCase testCases[] = - { - {1234, "1234"}, - {-1234, "-1234"}, - {1234e-5, "1234e-5"}, - {1234e+5, "1234e+5"}, - {1234e5, "1234E5"}, - {1234.567e-8, "1234.567e-8"}, - {1234.567e-8, " 1234.567e-8 foo"}, - {0,"a12"} - }; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /*Convert the string to a float.*/ - f = atof(testCases[i].avalue); - double result = f - testCases[i].fvalue; - - if (fabs(result) > FLT_EPSILON) - { - Fail ("atof misinterpreted \"%s\" as %g instead of %g. result %g fabs %g\n", - testCases[i].avalue, f, testCases[i].fvalue, result, fabs(result)); - } - } - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/atof/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/atof/test1/test1.cpp new file mode 100644 index 0000000000..a973133f9e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atof/test1/test1.cpp @@ -0,0 +1,75 @@ +// 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: test1.c +** +** Purpose: Passes to atof() a series of strings containing floats, +** checking that each one is correctly extracted. +** +** +**==========================================================================*/ + +#include +#include + +struct testCase +{ + float fvalue; + char avalue[20]; +}; + +int __cdecl main(int argc, char **argv) +{ + int i = 0; + double f = 0; + struct testCase testCases[] = + { + {1234, "1234"}, + {-1234, "-1234"}, + {1234e-5, "1234e-5"}, + {1234e+5, "1234e+5"}, + {1234e5, "1234E5"}, + {1234.567e-8, "1234.567e-8"}, + {1234.567e-8, " 1234.567e-8 foo"}, + {0,"a12"} + }; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /*Convert the string to a float.*/ + f = atof(testCases[i].avalue); + double result = f - testCases[i].fvalue; + + if (fabs(result) > FLT_EPSILON) + { + Fail ("atof misinterpreted \"%s\" as %g instead of %g. result %g fabs %g\n", + testCases[i].avalue, f, testCases[i].fvalue, result, fabs(result)); + } + } + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/atoi/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atoi/test1/CMakeLists.txt index 3549aca737..225052213f 100644 --- a/src/pal/tests/palsuite/c_runtime/atoi/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/atoi/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_atoi_test1 diff --git a/src/pal/tests/palsuite/c_runtime/atoi/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atoi/test1/test1.c deleted file mode 100644 index 2554d4c353..0000000000 --- a/src/pal/tests/palsuite/c_runtime/atoi/test1/test1.c +++ /dev/null @@ -1,86 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the atoi function. -** Check to ensure that the different ints (normal, -** negative, decimal,exponent), all work as expected with -** this function. -** -** -**===================================================================*/ - -#include - - -struct testCase -{ - int IntValue; - char avalue[20]; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result=0; - int i=0; - - struct testCase testCases[] = - { - {1234, "1234"}, - {-1234, "-1234"}, - {1234, "1234.44"}, - {1234, "1234e-5"}, - {1234, "1234e+5"}, - {1234, "1234E5"}, - {1234, "1234.657e-8"}, - {1234567, " 1234567e-8 foo"}, - {0, "aaa 32 test"} - }; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Loop through each case. Convert the string to an int - and then compare to ensure that it is the correct value. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /*Convert the string to an int.*/ - result = atoi(testCases[i].avalue); - - if (testCases[i].IntValue != result) - { - Fail("ERROR: atoi misinterpreted \"%s\" as %i instead of %i.\n" - , testCases[i].avalue, result, testCases[i].IntValue); - } - - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/atoi/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/atoi/test1/test1.cpp new file mode 100644 index 0000000000..2554d4c353 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atoi/test1/test1.cpp @@ -0,0 +1,86 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the atoi function. +** Check to ensure that the different ints (normal, +** negative, decimal,exponent), all work as expected with +** this function. +** +** +**===================================================================*/ + +#include + + +struct testCase +{ + int IntValue; + char avalue[20]; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result=0; + int i=0; + + struct testCase testCases[] = + { + {1234, "1234"}, + {-1234, "-1234"}, + {1234, "1234.44"}, + {1234, "1234e-5"}, + {1234, "1234e+5"}, + {1234, "1234E5"}, + {1234, "1234.657e-8"}, + {1234567, " 1234567e-8 foo"}, + {0, "aaa 32 test"} + }; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Convert the string to an int + and then compare to ensure that it is the correct value. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /*Convert the string to an int.*/ + result = atoi(testCases[i].avalue); + + if (testCases[i].IntValue != result) + { + Fail("ERROR: atoi misinterpreted \"%s\" as %i instead of %i.\n" + , testCases[i].avalue, result, testCases[i].IntValue); + } + + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/atol/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atol/test1/CMakeLists.txt index 4fea187ad8..29643aae6b 100644 --- a/src/pal/tests/palsuite/c_runtime/atol/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/atol/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_atol_test1 diff --git a/src/pal/tests/palsuite/c_runtime/atol/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atol/test1/test1.c deleted file mode 100644 index 5ad85d873f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/atol/test1/test1.c +++ /dev/null @@ -1,88 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the atol function. -** Check to ensure that the different ints (normal, -** negative, decimal,exponent), all work as expected with -** this function. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - LONG LongValue; - char avalue[20]; -}; - -int __cdecl main(int argc, char **argv) -{ - - LONG result=0; - int i=0; - - struct testCase testCases[] = - { - {1234, "1234"}, - {-1234, "-1234"}, - {1234, "1234.44"}, - {1234, "1234e-5"}, - {1234, "1234e+5"}, - {1234, "1234E5"}, - {1234, "1234.657e-8"}, - {1234, "1234d-5"}, - {1234, "1234d+5"}, - {1234, "1234D5"}, - {1234567, " 1234567e-8 foo"}, - {0, "aaa 32 test"} - }; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Loop through each case. Convert the string to a LONG - and then compare to ensure that it is the correct value. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /*Convert the string to a LONG.*/ - result = atol(testCases[i].avalue); - - if (testCases[i].LongValue != result) - { - Fail("ERROR: atol misinterpreted \"%s\" as %d instead of %d.\n" - , testCases[i].avalue, result, testCases[i].LongValue); - } - - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/atol/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/atol/test1/test1.cpp new file mode 100644 index 0000000000..5ad85d873f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atol/test1/test1.cpp @@ -0,0 +1,88 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the atol function. +** Check to ensure that the different ints (normal, +** negative, decimal,exponent), all work as expected with +** this function. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + LONG LongValue; + char avalue[20]; +}; + +int __cdecl main(int argc, char **argv) +{ + + LONG result=0; + int i=0; + + struct testCase testCases[] = + { + {1234, "1234"}, + {-1234, "-1234"}, + {1234, "1234.44"}, + {1234, "1234e-5"}, + {1234, "1234e+5"}, + {1234, "1234E5"}, + {1234, "1234.657e-8"}, + {1234, "1234d-5"}, + {1234, "1234d+5"}, + {1234, "1234D5"}, + {1234567, " 1234567e-8 foo"}, + {0, "aaa 32 test"} + }; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Convert the string to a LONG + and then compare to ensure that it is the correct value. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /*Convert the string to a LONG.*/ + result = atol(testCases[i].avalue); + + if (testCases[i].LongValue != result) + { + Fail("ERROR: atol misinterpreted \"%s\" as %d instead of %d.\n" + , testCases[i].avalue, result, testCases[i].LongValue); + } + + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/bsearch/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/bsearch/test1/CMakeLists.txt index d2018f3325..c5aab7b84d 100644 --- a/src/pal/tests/palsuite/c_runtime/bsearch/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/bsearch/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_bsearch_test1 diff --git a/src/pal/tests/palsuite/c_runtime/bsearch/test1/test1.c b/src/pal/tests/palsuite/c_runtime/bsearch/test1/test1.c deleted file mode 100644 index c4b91738eb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/bsearch/test1/test1.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test1.c -** -** Purpose: Calls bsearch to find a character in a sorted buffer, and -** verifies that the correct position is returned. -** -** -**==========================================================================*/ - -#include - -int __cdecl charcmp(const void *pa, const void *pb) -{ - return memcmp(pa, pb, 1); -} - -int __cdecl main(int argc, char **argv) -{ - - const char array[] = "abcdefghij"; - char * found=NULL; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - found = (char *)bsearch(&"d", array, sizeof(array) - 1, (sizeof(char)) - , charcmp); - if (found != array + 3) - { - Fail ("bsearch was unable to find a specified character in a " - "sorted list.\n"); - } - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/bsearch/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/bsearch/test1/test1.cpp new file mode 100644 index 0000000000..c4b91738eb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/bsearch/test1/test1.cpp @@ -0,0 +1,48 @@ +// 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: test1.c +** +** Purpose: Calls bsearch to find a character in a sorted buffer, and +** verifies that the correct position is returned. +** +** +**==========================================================================*/ + +#include + +int __cdecl charcmp(const void *pa, const void *pb) +{ + return memcmp(pa, pb, 1); +} + +int __cdecl main(int argc, char **argv) +{ + + const char array[] = "abcdefghij"; + char * found=NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + found = (char *)bsearch(&"d", array, sizeof(array) - 1, (sizeof(char)) + , charcmp); + if (found != array + 3) + { + Fail ("bsearch was unable to find a specified character in a " + "sorted list.\n"); + } + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/bsearch/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/bsearch/test2/CMakeLists.txt index dc65560196..7ad33b12e5 100644 --- a/src/pal/tests/palsuite/c_runtime/bsearch/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/bsearch/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_bsearch_test2 diff --git a/src/pal/tests/palsuite/c_runtime/bsearch/test2/test2.c b/src/pal/tests/palsuite/c_runtime/bsearch/test2/test2.c deleted file mode 100644 index 6de1b3fada..0000000000 --- a/src/pal/tests/palsuite/c_runtime/bsearch/test2/test2.c +++ /dev/null @@ -1,57 +0,0 @@ -// 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: test1.c -** -** Purpose: Calls bsearch to find a character in a sorted buffer, -** that does not exist. -** -** -**==========================================================================*/ - -#include - -int __cdecl charcmp(const void *pa, const void *pb) -{ - return *(const char *)pa - *(const char *)pb; -} - -int __cdecl main(int argc, char **argv) -{ - - const char array[] = "abcefghij"; - const char missing[] = "0dz"; - char * found=NULL; - const char * candidate = missing; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - while (*candidate) { - found = (char *)bsearch(candidate, array, sizeof(array) - 1, - (sizeof(char)), charcmp); - if (found != NULL) - { - Fail ("ERROR: bsearch was able to find a specified character '%c' " - "in a sorted list '%s' as '%c' " - "even though the character is not in the list.\n", - *candidate, array, *found); - } - - candidate++; - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/bsearch/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/bsearch/test2/test2.cpp new file mode 100644 index 0000000000..6de1b3fada --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/bsearch/test2/test2.cpp @@ -0,0 +1,57 @@ +// 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: test1.c +** +** Purpose: Calls bsearch to find a character in a sorted buffer, +** that does not exist. +** +** +**==========================================================================*/ + +#include + +int __cdecl charcmp(const void *pa, const void *pb) +{ + return *(const char *)pa - *(const char *)pb; +} + +int __cdecl main(int argc, char **argv) +{ + + const char array[] = "abcefghij"; + const char missing[] = "0dz"; + char * found=NULL; + const char * candidate = missing; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + while (*candidate) { + found = (char *)bsearch(candidate, array, sizeof(array) - 1, + (sizeof(char)), charcmp); + if (found != NULL) + { + Fail ("ERROR: bsearch was able to find a specified character '%c' " + "in a sorted list '%s' as '%c' " + "even though the character is not in the list.\n", + *candidate, array, *found); + } + + candidate++; + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/ceil/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ceil/test1/CMakeLists.txt index c73ad1dbbe..f834914545 100644 --- a/src/pal/tests/palsuite/c_runtime/ceil/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/ceil/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_ceil_test1 diff --git a/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.c b/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.c deleted file mode 100644 index e6e36e6e33..0000000000 --- a/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.c +++ /dev/null @@ -1,132 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests ceil with simple positive and negative values. Also tests -** extreme cases like extremely small values and positive and -** negative infinity. Makes sure that calling ceil on NaN returns -** NaN -** -**==========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = ceil(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("ceil(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = ceil(value); - - if (!_isnan(result)) - { - Fail("ceil(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char *argv[]) -{ - struct test tests[] = - { - /* value expected variance */ - { 0.31830988618379067, 1, PAL_EPSILON * 10 }, // value: 1 / pi - { 0.43429448190325183, 1, PAL_EPSILON * 10 }, // value: log10(e) - { 0.63661977236758134, 1, PAL_EPSILON * 10 }, // value: 2 / pi - { 0.69314718055994531, 1, PAL_EPSILON * 10 }, // value: ln(2) - { 0.70710678118654752, 1, PAL_EPSILON * 10 }, // value: 1 / sqrt(2) - { 0.78539816339744831, 1, PAL_EPSILON * 10 }, // value: pi / 4 - { 1.1283791670955126, 2, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 2, PAL_EPSILON * 10 }, // value: sqrt(2) - { 1.4426950408889634, 2, PAL_EPSILON * 10 }, // value: log2(e) - { 1.5707963267948966, 2, PAL_EPSILON * 10 }, // value: pi / 2 - { 2.3025850929940457, 3, PAL_EPSILON * 10 }, // value: ln(10) - { 2.7182818284590452, 3, PAL_EPSILON * 10 }, // value: e - { 3.1415926535897932, 4, PAL_EPSILON * 10 }, // value: pi - { PAL_POSINF, PAL_POSINF, 0 } - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - validate( 0, 0, PAL_EPSILON); - validate(-0.0, 0, PAL_EPSILON); - - validate( 1, 1, PAL_EPSILON * 10); - validate(-1.0, -1, PAL_EPSILON * 10); - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, 1 - tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.cpp new file mode 100644 index 0000000000..e6e36e6e33 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.cpp @@ -0,0 +1,132 @@ +// 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: test1.c +** +** Purpose: Tests ceil with simple positive and negative values. Also tests +** extreme cases like extremely small values and positive and +** negative infinity. Makes sure that calling ceil on NaN returns +** NaN +** +**==========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = ceil(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("ceil(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = ceil(value); + + if (!_isnan(result)) + { + Fail("ceil(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char *argv[]) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.31830988618379067, 1, PAL_EPSILON * 10 }, // value: 1 / pi + { 0.43429448190325183, 1, PAL_EPSILON * 10 }, // value: log10(e) + { 0.63661977236758134, 1, PAL_EPSILON * 10 }, // value: 2 / pi + { 0.69314718055994531, 1, PAL_EPSILON * 10 }, // value: ln(2) + { 0.70710678118654752, 1, PAL_EPSILON * 10 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 1, PAL_EPSILON * 10 }, // value: pi / 4 + { 1.1283791670955126, 2, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 2, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.4426950408889634, 2, PAL_EPSILON * 10 }, // value: log2(e) + { 1.5707963267948966, 2, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.3025850929940457, 3, PAL_EPSILON * 10 }, // value: ln(10) + { 2.7182818284590452, 3, PAL_EPSILON * 10 }, // value: e + { 3.1415926535897932, 4, PAL_EPSILON * 10 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate( 0, 0, PAL_EPSILON); + validate(-0.0, 0, PAL_EPSILON); + + validate( 1, 1, PAL_EPSILON * 10); + validate(-1.0, -1, PAL_EPSILON * 10); + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, 1 - tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/ceilf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ceilf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ceilf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/ceilf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ceilf/test1/CMakeLists.txt new file mode 100644 index 0000000000..64f14cda9a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ceilf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_ceilf_test1 + ${SOURCES} +) + +add_dependencies(paltest_ceilf_test1 coreclrpal) + +target_link_libraries(paltest_ceilf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/ceilf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/ceilf/test1/test1.c new file mode 100644 index 0000000000..4939fb7ccf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ceilf/test1/test1.c @@ -0,0 +1,131 @@ +// 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: test1.c +** +** Purpose: Tests ceilf with simple positive and negative values. Also tests +** extreme cases like extremely small values and positive and +** negative infinity. Makes sure that calling ceilf on NaN returns +** NaN +** +**==========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = ceilf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("ceilf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = ceilf(value); + + if (!_isnanf(result)) + { + Fail("ceilf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char *argv[]) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.318309886f, 1, PAL_EPSILON * 10 }, // value: 1 / pi + { 0.434294482f, 1, PAL_EPSILON * 10 }, // value: log10f(e) + { 0.636619772f, 1, PAL_EPSILON * 10 }, // value: 2 / pi + { 0.693147181f, 1, PAL_EPSILON * 10 }, // value: ln(2) + { 0.707106781f, 1, PAL_EPSILON * 10 }, // value: 1 / sqrtf(2) + { 0.785398163f, 1, PAL_EPSILON * 10 }, // value: pi / 4 + { 1.12837917f, 2, PAL_EPSILON * 10 }, // value: 2 / sqrtf(pi) + { 1.41421356f, 2, PAL_EPSILON * 10 }, // value: sqrtf(2) + { 1.44269504f, 2, PAL_EPSILON * 10 }, // value: logf2(e) + { 1.57079633f, 2, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.30258509f, 3, PAL_EPSILON * 10 }, // value: ln(10) + { 2.71828183f, 3, PAL_EPSILON * 10 }, // value: e + { 3.14159265f, 4, PAL_EPSILON * 10 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate( 0, 0, PAL_EPSILON); + validate(-0.0f, 0, PAL_EPSILON); + + validate( 1, 1, PAL_EPSILON * 10); + validate(-1.0f, -1, PAL_EPSILON * 10); + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, 1 - tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/ceilf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/ceilf/test1/testinfo.dat new file mode 100644 index 0000000000..095b8b216a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ceilf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = ceilf +Name = Test #1 for ceilf +TYPE = DEFAULT +EXE1 = test1 +Description +=Tests ceilf with simple positive and negative values. Also tests +=extreme cases like extremely small values and positive and negative +=infinity. Makes sure that calling ceilf on NaN returns NaN diff --git a/src/pal/tests/palsuite/c_runtime/cos/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cos/test1/CMakeLists.txt index 1dda9a2563..536664c128 100644 --- a/src/pal/tests/palsuite/c_runtime/cos/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/cos/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_cos_test1 diff --git a/src/pal/tests/palsuite/c_runtime/cos/test1/test1.c b/src/pal/tests/palsuite/c_runtime/cos/test1/test1.c deleted file mode 100644 index 8c1c7300e6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/cos/test1/test1.c +++ /dev/null @@ -1,131 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that cos return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = cos(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("cos(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = cos(value); - - if (!_isnan(result)) - { - Fail("cos(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, 1, PAL_EPSILON * 10 }, - { 0.31830988618379067, 0.94976571538163866, PAL_EPSILON }, // value: 1 / pi - { 0.43429448190325183, 0.90716712923909839, PAL_EPSILON }, // value: log10(e) - { 0.63661977236758134, 0.80410982822879171, PAL_EPSILON }, // value: 2 / pi - { 0.69314718055994531, 0.76923890136397213, PAL_EPSILON }, // value: ln(2) - { 0.70710678118654752, 0.76024459707563015, PAL_EPSILON }, // value: 1 / sqrt(2) - { 0.78539816339744831, 0.70710678118654752, PAL_EPSILON }, // value: pi / 4, expected: 1 / sqrt(2) - { 1, 0.54030230586813972, PAL_EPSILON }, - { 1.1283791670955126, 0.42812514788535792, PAL_EPSILON }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 0.15594369476537447, PAL_EPSILON }, // value: sqrt(2) - { 1.4426950408889634, 0.12775121753523991, PAL_EPSILON }, // value: log2(e) - { 1.5707963267948966, 0, PAL_EPSILON }, // value: pi / 2 - { 2.3025850929940457, -0.66820151019031295, PAL_EPSILON }, // value: ln(10) - { 2.7182818284590452, -0.91173391478696510, PAL_EPSILON }, // value: e - { 3.1415926535897932, -1, PAL_EPSILON * 10 }, // value: pi - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NEGINF); - validate_isnan(PAL_NAN); - validate_isnan(PAL_POSINF); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/cos/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/cos/test1/test1.cpp new file mode 100644 index 0000000000..8c1c7300e6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cos/test1/test1.cpp @@ -0,0 +1,131 @@ +// 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: test1.c +** +** Purpose: Test to ensure that cos return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = cos(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("cos(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = cos(value); + + if (!_isnan(result)) + { + Fail("cos(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 1, PAL_EPSILON * 10 }, + { 0.31830988618379067, 0.94976571538163866, PAL_EPSILON }, // value: 1 / pi + { 0.43429448190325183, 0.90716712923909839, PAL_EPSILON }, // value: log10(e) + { 0.63661977236758134, 0.80410982822879171, PAL_EPSILON }, // value: 2 / pi + { 0.69314718055994531, 0.76923890136397213, PAL_EPSILON }, // value: ln(2) + { 0.70710678118654752, 0.76024459707563015, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.70710678118654752, PAL_EPSILON }, // value: pi / 4, expected: 1 / sqrt(2) + { 1, 0.54030230586813972, PAL_EPSILON }, + { 1.1283791670955126, 0.42812514788535792, PAL_EPSILON }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 0.15594369476537447, PAL_EPSILON }, // value: sqrt(2) + { 1.4426950408889634, 0.12775121753523991, PAL_EPSILON }, // value: log2(e) + { 1.5707963267948966, 0, PAL_EPSILON }, // value: pi / 2 + { 2.3025850929940457, -0.66820151019031295, PAL_EPSILON }, // value: ln(10) + { 2.7182818284590452, -0.91173391478696510, PAL_EPSILON }, // value: e + { 3.1415926535897932, -1, PAL_EPSILON * 10 }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/cosf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cosf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cosf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/cosf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cosf/test1/CMakeLists.txt new file mode 100644 index 0000000000..b3a18ea271 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cosf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_cosf_test1 + ${SOURCES} +) + +add_dependencies(paltest_cosf_test1 coreclrpal) + +target_link_libraries(paltest_cosf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/cosf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/cosf/test1/test1.c new file mode 100644 index 0000000000..210851a2fa --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cosf/test1/test1.c @@ -0,0 +1,130 @@ +// 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: test1.c +** +** Purpose: Test to ensure that cosf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = cosf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("cosf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = cosf(value); + + if (!_isnanf(result)) + { + Fail("cosf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 1, PAL_EPSILON * 10 }, + { 0.318309886f, 0.949765715f, PAL_EPSILON }, // value: 1 / pi + { 0.434294482f, 0.907167129f, PAL_EPSILON }, // value: log10f(e) + { 0.636619772f, 0.804109828f, PAL_EPSILON }, // value: 2 / pi + { 0.693147181f, 0.769238901f, PAL_EPSILON }, // value: ln(2) + { 0.707106781f, 0.760244597f, PAL_EPSILON }, // value: 1 / sqrtf(2) + { 0.785398163f, 0.707106781f, PAL_EPSILON }, // value: pi / 4, expected: 1 / sqrtf(2) + { 1, 0.540302306f, PAL_EPSILON }, + { 1.12837917f, 0.428125148f, PAL_EPSILON }, // value: 2 / sqrtf(pi) + { 1.41421356f, 0.155943695f, PAL_EPSILON }, // value: sqrtf(2) + { 1.44269504f, 0.127751218f, PAL_EPSILON }, // value: logf2(e) + { 1.57079633f, 0, PAL_EPSILON }, // value: pi / 2 + { 2.30258509f, -0.668201510f, PAL_EPSILON }, // value: ln(10) + { 2.71828183f, -0.911733918f, PAL_EPSILON }, // value: e + { 3.14159265f, -1, PAL_EPSILON * 10 }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/cosf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/cosf/test1/testinfo.dat new file mode 100644 index 0000000000..a0265add2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cosf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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 = C Runtime +Function = cosf +Name = Positive Test for cosf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to cosf() a series of angle value, checking that += each one return the correct value. diff --git a/src/pal/tests/palsuite/c_runtime/cosh/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cosh/test1/CMakeLists.txt index bea7b7a3b7..e1fff0e9f1 100644 --- a/src/pal/tests/palsuite/c_runtime/cosh/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/cosh/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_cosh_test1 diff --git a/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.c b/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.c deleted file mode 100644 index 40c2fca85d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.c +++ /dev/null @@ -1,130 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that cosh return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = cosh(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("cosh(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning PAL_NAN - */ -void __cdecl validate_isnan(double value) -{ - double result = cosh(value); - - if (!_isnan(result)) - { - Fail("cosh(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, 1, PAL_EPSILON * 10 }, - { 0.31830988618379067, 1.0510897883672876, PAL_EPSILON * 10 }, // value: 1 / pi - { 0.43429448190325183, 1.0957974645564909, PAL_EPSILON * 10 }, // value: log10(e) - { 0.63661977236758134, 1.2095794864199787, PAL_EPSILON * 10 }, // value: 2 / pi - { 0.69314718055994531, 1.25, PAL_EPSILON * 10 }, // value: ln(2) - { 0.70710678118654752, 1.2605918365213561, PAL_EPSILON * 10 }, // value: 1 / sqrt(2) - { 0.78539816339744831, 1.3246090892520058, PAL_EPSILON * 10 }, // value: pi / 4 - { 1, 1.5430806348152438, PAL_EPSILON * 10 }, - { 1.1283791670955126, 1.7071001431069344, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 2.1781835566085709, PAL_EPSILON * 10 }, // value: sqrt(2) - { 1.4426950408889634, 2.2341880974508023, PAL_EPSILON * 10 }, // value: log2(e) - { 1.5707963267948966, 2.5091784786580568, PAL_EPSILON * 10 }, // value: pi / 2 - { 2.3025850929940457, 5.05, PAL_EPSILON * 10 }, // value: ln(10) - { 2.7182818284590452, 7.6101251386622884, PAL_EPSILON * 10 }, // value: e - { 3.1415926535897932, 11.591953275521521, PAL_EPSILON * 100 }, // value: pi - { PAL_POSINF, PAL_POSINF, 0 }, - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.cpp new file mode 100644 index 0000000000..40c2fca85d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.cpp @@ -0,0 +1,130 @@ +// 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: test1.c +** +** Purpose: Test to ensure that cosh return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = cosh(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("cosh(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning PAL_NAN + */ +void __cdecl validate_isnan(double value) +{ + double result = cosh(value); + + if (!_isnan(result)) + { + Fail("cosh(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 1, PAL_EPSILON * 10 }, + { 0.31830988618379067, 1.0510897883672876, PAL_EPSILON * 10 }, // value: 1 / pi + { 0.43429448190325183, 1.0957974645564909, PAL_EPSILON * 10 }, // value: log10(e) + { 0.63661977236758134, 1.2095794864199787, PAL_EPSILON * 10 }, // value: 2 / pi + { 0.69314718055994531, 1.25, PAL_EPSILON * 10 }, // value: ln(2) + { 0.70710678118654752, 1.2605918365213561, PAL_EPSILON * 10 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 1.3246090892520058, PAL_EPSILON * 10 }, // value: pi / 4 + { 1, 1.5430806348152438, PAL_EPSILON * 10 }, + { 1.1283791670955126, 1.7071001431069344, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 2.1781835566085709, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.4426950408889634, 2.2341880974508023, PAL_EPSILON * 10 }, // value: log2(e) + { 1.5707963267948966, 2.5091784786580568, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.3025850929940457, 5.05, PAL_EPSILON * 10 }, // value: ln(10) + { 2.7182818284590452, 7.6101251386622884, PAL_EPSILON * 10 }, // value: e + { 3.1415926535897932, 11.591953275521521, PAL_EPSILON * 100 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/coshf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/coshf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/coshf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/coshf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/coshf/test1/CMakeLists.txt new file mode 100644 index 0000000000..92fcfdea6d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/coshf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_coshf_test1 + ${SOURCES} +) + +add_dependencies(paltest_coshf_test1 coreclrpal) + +target_link_libraries(paltest_coshf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/coshf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/coshf/test1/test1.c new file mode 100644 index 0000000000..e1ab745acb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/coshf/test1/test1.c @@ -0,0 +1,129 @@ +// 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: test1.c +** +** Purpose: Test to ensure that coshf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = coshf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("coshf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning PAL_NAN + */ +void __cdecl validate_isnan(float value) +{ + float result = coshf(value); + + if (!_isnanf(result)) + { + Fail("coshf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 1, PAL_EPSILON * 10 }, + { 0.318309886f, 1.05108979f, PAL_EPSILON * 10 }, // value: 1 / pi + { 0.434294482f, 1.09579746f, PAL_EPSILON * 10 }, // value: log10f(e) + { 0.636619772f, 1.20957949f, PAL_EPSILON * 10 }, // value: 2 / pi + { 0.693147181f, 1.25f, PAL_EPSILON * 10 }, // value: ln(2) + { 0.707106781f, 1.26059184f, PAL_EPSILON * 10 }, // value: 1 / sqrtf(2) + { 0.785398163f, 1.32460909f, PAL_EPSILON * 10 }, // value: pi / 4 + { 1, 1.54308063f, PAL_EPSILON * 10 }, + { 1.12837917f, 1.70710014f, PAL_EPSILON * 10 }, // value: 2 / sqrtf(pi) + { 1.41421356f, 2.17818356f, PAL_EPSILON * 10 }, // value: sqrtf(2) + { 1.44269504f, 2.23418810f, PAL_EPSILON * 10 }, // value: logf2(e) + { 1.57079633f, 2.50917848f, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.30258509f, 5.05f, PAL_EPSILON * 10 }, // value: ln(10) + { 2.71828183f, 7.61012514f, PAL_EPSILON * 10 }, // value: e + { 3.14159265f, 11.5919533f, PAL_EPSILON * 100 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/coshf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/coshf/test1/testinfo.dat new file mode 100644 index 0000000000..814ed98698 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/coshf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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 = C Runtime +Function = coshf +Name = Positive Test for coshf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to coshf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/ctime/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ctime/test1/CMakeLists.txt index aa64a71d1e..3eeffb0e39 100644 --- a/src/pal/tests/palsuite/c_runtime/ctime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/ctime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_ctime_test1 diff --git a/src/pal/tests/palsuite/c_runtime/ctime/test1/test1.c b/src/pal/tests/palsuite/c_runtime/ctime/test1/test1.c deleted file mode 100644 index 5d5e22ce89..0000000000 --- a/src/pal/tests/palsuite/c_runtime/ctime/test1/test1.c +++ /dev/null @@ -1,154 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that ctime return a valid -** string when it received a valid number of second. -** Test to ensure that ctime return null when it -** receives a invalid number of second. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** IsBadReadPtr -** strcmp -** - -** -**===========================================================================*/ - -#include - -/* - * Date strings generated under win2000/WinXP, times & Strings are GMT - */ -const time_t VAL_SUN_JAN_17_2038 = 2147383647; -const char *STR_SUN_JAN_17_2038 = "Sun Jan 17 23:27:27 2038\n"; - -/* Note, there are two acceptable strings for this date. */ -/* The day can have a leading 0 under Windows. */ -const time_t VAL_FRI_JAN_02_1970 = 100000; -const char *STR_FRI_JAN_02_1970 = "Fri Jan 02 03:46:40 1970\n"; -const char *STR_FRI_JAN__2_1970 = "Fri Jan 2 03:46:40 1970\n"; - -const int STR_TIME_SIZE = 26; /* returned date size in byte*/ - - - -int __cdecl main(int argc, char **argv) -{ - time_t LTime; - char *DateResult; - TIME_ZONE_INFORMATION tzInformation; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - // Get the current timezone information - GetTimeZoneInformation(&tzInformation); - - /* - * Test #1 - */ - - /* set the valid date in time_t format, adjusted for current time zone*/ - LTime = VAL_SUN_JAN_17_2038 + (tzInformation.Bias * 60); - - /* convert it to string using ctime*/ - DateResult = ctime( <ime ); - - /* if it's null, ctime failed*/ - if (DateResult == NULL) - { - Fail ("ERROR: (Test #1) ctime returned NULL. Expected string\n"); - } - - /* test if the entire string can ba access normaly */ - if(IsBadReadPtr(DateResult, STR_TIME_SIZE)==0) - { - /* compare result with win2000 result */ - if(strcmp( DateResult, STR_SUN_JAN_17_2038)!=0) - { - Fail("ERROR: (Test #1) ctime returned an unexpected string " - "%s, expexted string is %s\n" - ,DateResult, STR_SUN_JAN_17_2038); - } - } - else - { - Fail ("ERROR: (Test #1) ctime returned a bad pointer.\n"); - } - - - /* - * Test #2 - */ - - /* Set the valid date in time_t format, adjusted for current time zone */ - LTime = VAL_FRI_JAN_02_1970 + (tzInformation.Bias * 60); - - /* convert it to string using ctime */ - DateResult = ctime( <ime ); - - /* if it's null, ctime failed*/ - if (DateResult == NULL) - { - Fail ("ERROR: (Test #2) ctime returned NULL. Expected string\n"); - } - - /* test if the entire string can ba access normaly */ - if(IsBadReadPtr(DateResult, STR_TIME_SIZE)==0) - { - /* compare result with win2000 result */ - if (strcmp(DateResult, STR_FRI_JAN_02_1970) != 0 - && strcmp(DateResult, STR_FRI_JAN__2_1970) != 0) - { - Fail("ERROR: (Test #2) ctime returned an unexpected string " - "%s, expected string is %s\n" - ,DateResult, STR_FRI_JAN_02_1970); - } - } - else - { - Fail ("ERROR: (Test #2) ctime returned a bad pointer.\n"); - } - - - - /* - * Test #3 - */ - - /* specify an invalid time */ - LTime = -1; - - /* try to convert it */ - DateResult = ctime( <ime ); - - /* Check the result for errors, should fail in this case */ - if (DateResult != NULL) - { - Fail ("ERROR: (Test #3) ctime returned something different from NULL.:" - "Expected NULL\n"); - } - - - PAL_Terminate(); - return PASS; -} - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/ctime/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/ctime/test1/test1.cpp new file mode 100644 index 0000000000..5d5e22ce89 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ctime/test1/test1.cpp @@ -0,0 +1,154 @@ +// 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: test1.c +** +** Purpose: Test to ensure that ctime return a valid +** string when it received a valid number of second. +** Test to ensure that ctime return null when it +** receives a invalid number of second. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** IsBadReadPtr +** strcmp +** + +** +**===========================================================================*/ + +#include + +/* + * Date strings generated under win2000/WinXP, times & Strings are GMT + */ +const time_t VAL_SUN_JAN_17_2038 = 2147383647; +const char *STR_SUN_JAN_17_2038 = "Sun Jan 17 23:27:27 2038\n"; + +/* Note, there are two acceptable strings for this date. */ +/* The day can have a leading 0 under Windows. */ +const time_t VAL_FRI_JAN_02_1970 = 100000; +const char *STR_FRI_JAN_02_1970 = "Fri Jan 02 03:46:40 1970\n"; +const char *STR_FRI_JAN__2_1970 = "Fri Jan 2 03:46:40 1970\n"; + +const int STR_TIME_SIZE = 26; /* returned date size in byte*/ + + + +int __cdecl main(int argc, char **argv) +{ + time_t LTime; + char *DateResult; + TIME_ZONE_INFORMATION tzInformation; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + // Get the current timezone information + GetTimeZoneInformation(&tzInformation); + + /* + * Test #1 + */ + + /* set the valid date in time_t format, adjusted for current time zone*/ + LTime = VAL_SUN_JAN_17_2038 + (tzInformation.Bias * 60); + + /* convert it to string using ctime*/ + DateResult = ctime( <ime ); + + /* if it's null, ctime failed*/ + if (DateResult == NULL) + { + Fail ("ERROR: (Test #1) ctime returned NULL. Expected string\n"); + } + + /* test if the entire string can ba access normaly */ + if(IsBadReadPtr(DateResult, STR_TIME_SIZE)==0) + { + /* compare result with win2000 result */ + if(strcmp( DateResult, STR_SUN_JAN_17_2038)!=0) + { + Fail("ERROR: (Test #1) ctime returned an unexpected string " + "%s, expexted string is %s\n" + ,DateResult, STR_SUN_JAN_17_2038); + } + } + else + { + Fail ("ERROR: (Test #1) ctime returned a bad pointer.\n"); + } + + + /* + * Test #2 + */ + + /* Set the valid date in time_t format, adjusted for current time zone */ + LTime = VAL_FRI_JAN_02_1970 + (tzInformation.Bias * 60); + + /* convert it to string using ctime */ + DateResult = ctime( <ime ); + + /* if it's null, ctime failed*/ + if (DateResult == NULL) + { + Fail ("ERROR: (Test #2) ctime returned NULL. Expected string\n"); + } + + /* test if the entire string can ba access normaly */ + if(IsBadReadPtr(DateResult, STR_TIME_SIZE)==0) + { + /* compare result with win2000 result */ + if (strcmp(DateResult, STR_FRI_JAN_02_1970) != 0 + && strcmp(DateResult, STR_FRI_JAN__2_1970) != 0) + { + Fail("ERROR: (Test #2) ctime returned an unexpected string " + "%s, expected string is %s\n" + ,DateResult, STR_FRI_JAN_02_1970); + } + } + else + { + Fail ("ERROR: (Test #2) ctime returned a bad pointer.\n"); + } + + + + /* + * Test #3 + */ + + /* specify an invalid time */ + LTime = -1; + + /* try to convert it */ + DateResult = ctime( <ime ); + + /* Check the result for errors, should fail in this case */ + if (DateResult != NULL) + { + Fail ("ERROR: (Test #3) ctime returned something different from NULL.:" + "Expected NULL\n"); + } + + + PAL_Terminate(); + return PASS; +} + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/errno/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/errno/test1/CMakeLists.txt index 89b25a4fac..91b8d094b1 100644 --- a/src/pal/tests/palsuite/c_runtime/errno/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/errno/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_errno_test1 diff --git a/src/pal/tests/palsuite/c_runtime/errno/test1/test1.c b/src/pal/tests/palsuite/c_runtime/errno/test1/test1.c deleted file mode 100644 index 3ae25fb02a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/errno/test1/test1.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test1.c -** -** Purpose: Test that errno begins as 0, and sets to ERANGE when that -** error is forced with wcstoul. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR overstr[] = {'4','2','9','4','9','6','7','2','9','6',0}; - WCHAR *end; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* - From rotor.doc: The only value that must be supported is - ERANGE, in the event that wcstoul() fails due to overflow. - */ - - wcstoul(overstr, &end, 10); - - if (errno != ERANGE) - { - Fail("ERROR: wcstoul did not set errno to ERANGE. Instead " - "the value of errno is %d\n", errno); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/errno/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/errno/test1/test1.cpp new file mode 100644 index 0000000000..3ae25fb02a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/errno/test1/test1.cpp @@ -0,0 +1,43 @@ +// 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: test1.c +** +** Purpose: Test that errno begins as 0, and sets to ERANGE when that +** error is forced with wcstoul. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR overstr[] = {'4','2','9','4','9','6','7','2','9','6',0}; + WCHAR *end; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* + From rotor.doc: The only value that must be supported is + ERANGE, in the event that wcstoul() fails due to overflow. + */ + + wcstoul(overstr, &end, 10); + + if (errno != ERANGE) + { + Fail("ERROR: wcstoul did not set errno to ERANGE. Instead " + "the value of errno is %d\n", errno); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/errno/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/errno/test2/CMakeLists.txt index edd4cf7975..ab7c4a27f2 100644 --- a/src/pal/tests/palsuite/c_runtime/errno/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/errno/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_errno_test2 diff --git a/src/pal/tests/palsuite/c_runtime/errno/test2/test2.c b/src/pal/tests/palsuite/c_runtime/errno/test2/test2.c deleted file mode 100644 index f418d2f199..0000000000 --- a/src/pal/tests/palsuite/c_runtime/errno/test2/test2.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: test2.c -** -** Purpose: Test that errno is 'per-thread' as noted in the documentation. -** -** -**==========================================================================*/ - -#include - -/* - This thread function just checks that errno is initially 0 and then sets - it to a new value before returning. -*/ -DWORD PALAPI ThreadFunc( LPVOID lpParam ) -{ - - if(errno != 0) - { - *((DWORD*)lpParam) = 1; - } - - errno = 20; - - return 0; -} - - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwThreadId, dwThrdParam = 0; - HANDLE hThread; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Set errno to a value within this thread */ - - errno = 50; - - hThread = CreateThread(NULL, 0, ThreadFunc, &dwThrdParam, 0, &dwThreadId); - - if (hThread == NULL) - { - Fail("ERROR: CreateThread failed to create a thread. " - "GetLastError() returned %d.\n",GetLastError()); - } - - WaitForSingleObject(hThread, INFINITE); - - /* This checks the result of calling the thread */ - if(dwThrdParam) - { - Fail("ERROR: errno was not set to 0 in the new thread. Each " - "thread should have its own value for errno.\n"); - } - - /* Check to make sure errno is still set to 50 */ - if(errno != 50) - { - Fail("ERROR: errno should be 50 in the main thread, even though " - "it was set to 20 in another thread. Currently it is %d.\n", - errno); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/errno/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/errno/test2/test2.cpp new file mode 100644 index 0000000000..f418d2f199 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/errno/test2/test2.cpp @@ -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: test2.c +** +** Purpose: Test that errno is 'per-thread' as noted in the documentation. +** +** +**==========================================================================*/ + +#include + +/* + This thread function just checks that errno is initially 0 and then sets + it to a new value before returning. +*/ +DWORD PALAPI ThreadFunc( LPVOID lpParam ) +{ + + if(errno != 0) + { + *((DWORD*)lpParam) = 1; + } + + errno = 20; + + return 0; +} + + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwThreadId, dwThrdParam = 0; + HANDLE hThread; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Set errno to a value within this thread */ + + errno = 50; + + hThread = CreateThread(NULL, 0, ThreadFunc, &dwThrdParam, 0, &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: CreateThread failed to create a thread. " + "GetLastError() returned %d.\n",GetLastError()); + } + + WaitForSingleObject(hThread, INFINITE); + + /* This checks the result of calling the thread */ + if(dwThrdParam) + { + Fail("ERROR: errno was not set to 0 in the new thread. Each " + "thread should have its own value for errno.\n"); + } + + /* Check to make sure errno is still set to 50 */ + if(errno != 50) + { + Fail("ERROR: errno should be 50 in the main thread, even though " + "it was set to 20 in another thread. Currently it is %d.\n", + errno); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/exit/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/exit/test1/CMakeLists.txt index eb9ca4e780..bb2cbccb9b 100644 --- a/src/pal/tests/palsuite/c_runtime/exit/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/exit/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_exit_test1 diff --git a/src/pal/tests/palsuite/c_runtime/exit/test1/test1.c b/src/pal/tests/palsuite/c_runtime/exit/test1/test1.c deleted file mode 100644 index 87c9d22b8a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/exit/test1/test1.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test1.c -** -** Purpose: Calls exit, and verifies that it actually stops program execution. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /*should return 0*/ - exit(0); - - Fail ("Exit didn't actually stop execution.\n"); - - return FAIL; -} - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/exit/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/exit/test1/test1.cpp new file mode 100644 index 0000000000..87c9d22b8a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/exit/test1/test1.cpp @@ -0,0 +1,37 @@ +// 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: test1.c +** +** Purpose: Calls exit, and verifies that it actually stops program execution. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /*should return 0*/ + exit(0); + + Fail ("Exit didn't actually stop execution.\n"); + + return FAIL; +} + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/exit/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/exit/test2/CMakeLists.txt index 47d3a44c85..8a74e75ed5 100644 --- a/src/pal/tests/palsuite/c_runtime/exit/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/exit/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_exit_test2 diff --git a/src/pal/tests/palsuite/c_runtime/exit/test2/test2.c b/src/pal/tests/palsuite/c_runtime/exit/test2/test2.c deleted file mode 100644 index 16fbdfed2f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/exit/test2/test2.c +++ /dev/null @@ -1,38 +0,0 @@ -// 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: test2.c -** -** Purpose: Calls exit on fail, and verifies that it actually -** stops program execution and return 1. - -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /*should return 1*/ - exit(1); - -} - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/exit/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/exit/test2/test2.cpp new file mode 100644 index 0000000000..16fbdfed2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/exit/test2/test2.cpp @@ -0,0 +1,38 @@ +// 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: test2.c +** +** Purpose: Calls exit on fail, and verifies that it actually +** stops program execution and return 1. + +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /*should return 1*/ + exit(1); + +} + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/exp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/exp/test1/CMakeLists.txt index 9cdd4ec5ed..3377ed22f2 100644 --- a/src/pal/tests/palsuite/c_runtime/exp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/exp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_exp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/exp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/exp/test1/test1.c deleted file mode 100644 index 20e071aa68..0000000000 --- a/src/pal/tests/palsuite/c_runtime/exp/test1/test1.c +++ /dev/null @@ -1,138 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests exp with a normal set of values. -** -**===================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = exp(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("exp(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = exp(value); - - if (!_isnan(result)) - { - Fail("exp(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { PAL_NEGINF, 0, PAL_EPSILON }, - { -3.1415926535897932, 0.043213918263772250, PAL_EPSILON / 10 }, // value: -(pi) - { -2.7182818284590452, 0.065988035845312537, PAL_EPSILON / 10 }, // value: -(e) - { -2.3025850929940457, 0.1, PAL_EPSILON }, // value: -(ln(10)) - { -1.5707963267948966, 0.20787957635076191, PAL_EPSILON }, // value: -(pi / 2) - { -1.4426950408889634, 0.23629008834452270, PAL_EPSILON }, // value: -(log2(e)) - { -1.4142135623730950, 0.24311673443421421, PAL_EPSILON }, // value: -(sqrt(2)) - { -1.1283791670955126, 0.32355726390307110, PAL_EPSILON }, // value: -(2 / sqrt(pi)) - { -1, 0.36787944117144232, PAL_EPSILON }, // value: -(1) - { -0.78539816339744831, 0.45593812776599624, PAL_EPSILON }, // value: -(pi / 4) - { -0.70710678118654752, 0.49306869139523979, PAL_EPSILON }, // value: -(1 / sqrt(2)) - { -0.69314718055994531, 0.5, PAL_EPSILON }, // value: -(ln(2)) - { -0.63661977236758134, 0.52907780826773535, PAL_EPSILON }, // value: -(2 / pi) - { -0.43429448190325183, 0.64772148514180065, PAL_EPSILON }, // value: -(log10(e)) - { -0.31830988618379067, 0.72737734929521647, PAL_EPSILON }, // value: -(1 / pi) - { 0, 1, PAL_EPSILON * 10 }, - { 0.31830988618379067, 1.3748022274393586, PAL_EPSILON * 10 }, // value: 1 / pi - { 0.43429448190325183, 1.5438734439711811, PAL_EPSILON * 10 }, // value: log10(e) - { 0.63661977236758134, 1.8900811645722220, PAL_EPSILON * 10 }, // value: 2 / pi - { 0.69314718055994531, 2, PAL_EPSILON * 10 }, // value: ln(2) - { 0.70710678118654752, 2.0281149816474725, PAL_EPSILON * 10 }, // value: 1 / sqrt(2) - { 0.78539816339744831, 2.1932800507380155, PAL_EPSILON * 10 }, // value: pi / 4 - { 1, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e - { 1.1283791670955126, 3.0906430223107976, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 4.1132503787829275, PAL_EPSILON * 10 }, // value: sqrt(2) - { 1.4426950408889634, 4.2320861065570819, PAL_EPSILON * 10 }, // value: log2(e) - { 1.5707963267948966, 4.8104773809653517, PAL_EPSILON * 10 }, // value: pi / 2 - { 2.3025850929940457, 10, PAL_EPSILON * 100 }, // value: ln(10) - { 2.7182818284590452, 15.154262241479264, PAL_EPSILON * 100 }, // value: e - { 3.1415926535897932, 23.140692632779269, PAL_EPSILON * 100 }, // value: pi - { PAL_POSINF, PAL_POSINF, 0 }, - }; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate(tests[i].value, tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/exp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/exp/test1/test1.cpp new file mode 100644 index 0000000000..20e071aa68 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/exp/test1/test1.cpp @@ -0,0 +1,138 @@ +// 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: test1.c +** +** Purpose: Tests exp with a normal set of values. +** +**===================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = exp(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("exp(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = exp(value); + + if (!_isnan(result)) + { + Fail("exp(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { PAL_NEGINF, 0, PAL_EPSILON }, + { -3.1415926535897932, 0.043213918263772250, PAL_EPSILON / 10 }, // value: -(pi) + { -2.7182818284590452, 0.065988035845312537, PAL_EPSILON / 10 }, // value: -(e) + { -2.3025850929940457, 0.1, PAL_EPSILON }, // value: -(ln(10)) + { -1.5707963267948966, 0.20787957635076191, PAL_EPSILON }, // value: -(pi / 2) + { -1.4426950408889634, 0.23629008834452270, PAL_EPSILON }, // value: -(log2(e)) + { -1.4142135623730950, 0.24311673443421421, PAL_EPSILON }, // value: -(sqrt(2)) + { -1.1283791670955126, 0.32355726390307110, PAL_EPSILON }, // value: -(2 / sqrt(pi)) + { -1, 0.36787944117144232, PAL_EPSILON }, // value: -(1) + { -0.78539816339744831, 0.45593812776599624, PAL_EPSILON }, // value: -(pi / 4) + { -0.70710678118654752, 0.49306869139523979, PAL_EPSILON }, // value: -(1 / sqrt(2)) + { -0.69314718055994531, 0.5, PAL_EPSILON }, // value: -(ln(2)) + { -0.63661977236758134, 0.52907780826773535, PAL_EPSILON }, // value: -(2 / pi) + { -0.43429448190325183, 0.64772148514180065, PAL_EPSILON }, // value: -(log10(e)) + { -0.31830988618379067, 0.72737734929521647, PAL_EPSILON }, // value: -(1 / pi) + { 0, 1, PAL_EPSILON * 10 }, + { 0.31830988618379067, 1.3748022274393586, PAL_EPSILON * 10 }, // value: 1 / pi + { 0.43429448190325183, 1.5438734439711811, PAL_EPSILON * 10 }, // value: log10(e) + { 0.63661977236758134, 1.8900811645722220, PAL_EPSILON * 10 }, // value: 2 / pi + { 0.69314718055994531, 2, PAL_EPSILON * 10 }, // value: ln(2) + { 0.70710678118654752, 2.0281149816474725, PAL_EPSILON * 10 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 2.1932800507380155, PAL_EPSILON * 10 }, // value: pi / 4 + { 1, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e + { 1.1283791670955126, 3.0906430223107976, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 4.1132503787829275, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.4426950408889634, 4.2320861065570819, PAL_EPSILON * 10 }, // value: log2(e) + { 1.5707963267948966, 4.8104773809653517, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.3025850929940457, 10, PAL_EPSILON * 100 }, // value: ln(10) + { 2.7182818284590452, 15.154262241479264, PAL_EPSILON * 100 }, // value: e + { 3.1415926535897932, 23.140692632779269, PAL_EPSILON * 100 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/expf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/expf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/expf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/expf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/expf/test1/CMakeLists.txt new file mode 100644 index 0000000000..fb12b65c2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/expf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_expf_test1 + ${SOURCES} +) + +add_dependencies(paltest_expf_test1 coreclrpal) + +target_link_libraries(paltest_expf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/expf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/expf/test1/test1.c new file mode 100644 index 0000000000..32f4e8d26c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/expf/test1/test1.c @@ -0,0 +1,137 @@ +// 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: test1.c +** +** Purpose: Tests expf with a normal set of values. +** +**===================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = expf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("expf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = expf(value); + + if (!_isnanf(result)) + { + Fail("expf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { PAL_NEGINF, 0, PAL_EPSILON }, + { -3.14159265f, 0.0432139183f, PAL_EPSILON / 10 }, // value: -(pi) + { -2.71828183f, 0.0659880358f, PAL_EPSILON / 10 }, // value: -(e) + { -2.30258509f, 0.1f, PAL_EPSILON }, // value: -(ln(10)) + { -1.57079633f, 0.207879576f, PAL_EPSILON }, // value: -(pi / 2) + { -1.44269504f, 0.236290088f, PAL_EPSILON }, // value: -(logf2(e)) + { -1.41421356f, 0.243116734f, PAL_EPSILON }, // value: -(sqrtf(2)) + { -1.12837917f, 0.323557264f, PAL_EPSILON }, // value: -(2 / sqrtf(pi)) + { -1, 0.367879441f, PAL_EPSILON }, // value: -(1) + { -0.785398163f, 0.455938128f, PAL_EPSILON }, // value: -(pi / 4) + { -0.707106781f, 0.493068691f, PAL_EPSILON }, // value: -(1 / sqrtf(2)) + { -0.693147181f, 0.5f, PAL_EPSILON }, // value: -(ln(2)) + { -0.636619772f, 0.529077808f, PAL_EPSILON }, // value: -(2 / pi) + { -0.434294482f, 0.647721485f, PAL_EPSILON }, // value: -(log10f(e)) + { -0.318309886f, 0.727377349f, PAL_EPSILON }, // value: -(1 / pi) + { 0, 1, PAL_EPSILON * 10 }, + { 0.318309886f, 1.37480223f, PAL_EPSILON * 10 }, // value: 1 / pi + { 0.434294482f, 1.54387344f, PAL_EPSILON * 10 }, // value: log10f(e) + { 0.636619772f, 1.89008116f, PAL_EPSILON * 10 }, // value: 2 / pi + { 0.693147181f, 2, PAL_EPSILON * 10 }, // value: ln(2) + { 0.707106781f, 2.02811498f, PAL_EPSILON * 10 }, // value: 1 / sqrtf(2) + { 0.785398163f, 2.19328005f, PAL_EPSILON * 10 }, // value: pi / 4 + { 1, 2.71828183f, PAL_EPSILON * 10 }, // expected: e + { 1.12837917f, 3.09064302f, PAL_EPSILON * 10 }, // value: 2 / sqrtf(pi) + { 1.41421356f, 4.11325038f, PAL_EPSILON * 10 }, // value: sqrtf(2) + { 1.44269504f, 4.23208611f, PAL_EPSILON * 10 }, // value: logf2(e) + { 1.57079633f, 4.81047738f, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.30258509f, 10, PAL_EPSILON * 100 }, // value: ln(10) + { 2.71828183f, 15.1542622f, PAL_EPSILON * 100 }, // value: e + { 3.14159265f, 23.1406926f, PAL_EPSILON * 100 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/expf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/expf/test1/testinfo.dat new file mode 100644 index 0000000000..c35928501e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/expf/test1/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 = C Runtime +Function = expf +Name = Test #1 for expf +Type = DEFAULT +EXE1 = test1 +Description +=Tests expf with a normal set of values. diff --git a/src/pal/tests/palsuite/c_runtime/fabs/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fabs/test1/CMakeLists.txt index ab27230ac2..fa01a34dd9 100644 --- a/src/pal/tests/palsuite/c_runtime/fabs/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fabs/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fabs_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.c deleted file mode 100644 index 0a74d5c1c5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.c +++ /dev/null @@ -1,130 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that fabs return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = fabs(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("fabs(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = fabs(value); - - if (!_isnan(result)) - { - Fail("fabs(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -INT __cdecl main(INT argc, CHAR **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { PAL_NEGINF, PAL_POSINF, 0 }, - { -3.1415926535897932, 3.1415926535897932, PAL_EPSILON * 10 }, // value: -(pi) expected: pi - { -2.7182818284590452, 2.7182818284590452, PAL_EPSILON * 10 }, // value: -(e) expected: e - { -2.3025850929940457, 2.3025850929940457, PAL_EPSILON * 10 }, // value: -(ln(10)) expected: ln(10) - { -1.5707963267948966, 1.5707963267948966, PAL_EPSILON * 10 }, // value: -(pi / 2) expected: pi / 2 - { -1.4426950408889634, 1.4426950408889634, PAL_EPSILON * 10 }, // value: -(log2(e)) expected: log2(e) - { -1.4142135623730950, 1.4142135623730950, PAL_EPSILON * 10 }, // value: -(sqrt(2)) expected: sqrt(2) - { -1.1283791670955126, 1.1283791670955126, PAL_EPSILON * 10 }, // value: -(2 / sqrt(pi)) expected: 2 / sqrt(pi) - { -1, 1, PAL_EPSILON * 10 }, - { -0.78539816339744831, 0.78539816339744831, PAL_EPSILON }, // value: -(pi / 4) expected: pi / 4 - { -0.70710678118654752, 0.70710678118654752, PAL_EPSILON }, // value: -(1 / sqrt(2)) expected: 1 / sqrt(2) - { -0.69314718055994531, 0.69314718055994531, PAL_EPSILON }, // value: -(ln(2)) expected: ln(2) - { -0.63661977236758134, 0.63661977236758134, PAL_EPSILON }, // value: -(2 / pi) expected: 2 / pi - { -0.43429448190325183, 0.43429448190325183, PAL_EPSILON }, // value: -(log10(e)) expected: log10(e) - { -0.31830988618379067, 0.31830988618379067, PAL_EPSILON }, // value: -(1 / pi) expected: 1 / pi - { -0.0, 0, PAL_EPSILON }, - }; - - - // PAL initialization - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.cpp new file mode 100644 index 0000000000..0a74d5c1c5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.cpp @@ -0,0 +1,130 @@ +// 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: test1.c +** +** Purpose: Test to ensure that fabs return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = fabs(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("fabs(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = fabs(value); + + if (!_isnan(result)) + { + Fail("fabs(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +INT __cdecl main(INT argc, CHAR **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { PAL_NEGINF, PAL_POSINF, 0 }, + { -3.1415926535897932, 3.1415926535897932, PAL_EPSILON * 10 }, // value: -(pi) expected: pi + { -2.7182818284590452, 2.7182818284590452, PAL_EPSILON * 10 }, // value: -(e) expected: e + { -2.3025850929940457, 2.3025850929940457, PAL_EPSILON * 10 }, // value: -(ln(10)) expected: ln(10) + { -1.5707963267948966, 1.5707963267948966, PAL_EPSILON * 10 }, // value: -(pi / 2) expected: pi / 2 + { -1.4426950408889634, 1.4426950408889634, PAL_EPSILON * 10 }, // value: -(log2(e)) expected: log2(e) + { -1.4142135623730950, 1.4142135623730950, PAL_EPSILON * 10 }, // value: -(sqrt(2)) expected: sqrt(2) + { -1.1283791670955126, 1.1283791670955126, PAL_EPSILON * 10 }, // value: -(2 / sqrt(pi)) expected: 2 / sqrt(pi) + { -1, 1, PAL_EPSILON * 10 }, + { -0.78539816339744831, 0.78539816339744831, PAL_EPSILON }, // value: -(pi / 4) expected: pi / 4 + { -0.70710678118654752, 0.70710678118654752, PAL_EPSILON }, // value: -(1 / sqrt(2)) expected: 1 / sqrt(2) + { -0.69314718055994531, 0.69314718055994531, PAL_EPSILON }, // value: -(ln(2)) expected: ln(2) + { -0.63661977236758134, 0.63661977236758134, PAL_EPSILON }, // value: -(2 / pi) expected: 2 / pi + { -0.43429448190325183, 0.43429448190325183, PAL_EPSILON }, // value: -(log10(e)) expected: log10(e) + { -0.31830988618379067, 0.31830988618379067, PAL_EPSILON }, // value: -(1 / pi) expected: 1 / pi + { -0.0, 0, PAL_EPSILON }, + }; + + + // PAL initialization + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fabsf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fabsf/test1/CMakeLists.txt index 06512ebd7c..a1823e25e5 100644 --- a/src/pal/tests/palsuite/c_runtime/fabsf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fabsf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fabsf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.c deleted file mode 100644 index 0b020729b8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.c +++ /dev/null @@ -1,130 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that fabsf return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** -**===========================================================================*/ - -#include - -// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (6-9 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON -// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use -// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. -#define PAL_EPSILON 4.76837158e-07 - - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - float value; /* value to test the function with */ - float expected; /* expected result */ - float variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(float value, float expected, float variance) -{ - float result = fabsf(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - float delta = fabsf(result - expected); - - if (delta > variance) - { - Fail("fabsf(%g) returned %10.9g when it should have returned %10.9g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(float value) -{ - float result = fabsf(value); - - if (!_isnan(result)) - { - Fail("fabsf(%g) returned %10.9g when it should have returned %10.9g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -INT __cdecl main(INT argc, CHAR **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { PAL_NEGINF, PAL_POSINF, 0 }, - { -3.14159265f, 3.14159265f, PAL_EPSILON * 10 }, // value: -(pi) expected: pi - { -2.71828183f, 2.71828183f, PAL_EPSILON * 10 }, // value: -(e) expected: e - { -2.30258509f, 2.30258509f, PAL_EPSILON * 10 }, // value: -(ln(10)) expected: ln(10) - { -1.57079633f, 1.57079633f, PAL_EPSILON * 10 }, // value: -(pi / 2) expected: pi / 2 - { -1.44269504f, 1.44269504f, PAL_EPSILON * 10 }, // value: -(log2(e)) expected: log2(e) - { -1.41421356f, 1.41421356f, PAL_EPSILON * 10 }, // value: -(sqrt(2)) expected: sqrt(2) - { -1.12837917f, 1.12837917f, PAL_EPSILON * 10 }, // value: -(2 / sqrt(pi)) expected: 2 / sqrt(pi) - { -1, 1, PAL_EPSILON * 10 }, - { -0.785398163f, 0.785398163f, PAL_EPSILON }, // value: -(pi / 4) expected: pi / 4 - { -0.707106781f, 0.707106781f, PAL_EPSILON }, // value: -(1 / sqrt(2)) expected: 1 / sqrt(2) - { -0.693147181f, 0.693147181f, PAL_EPSILON }, // value: -(ln(2)) expected: ln(2) - { -0.636619772f, 0.636619772f, PAL_EPSILON }, // value: -(2 / pi) expected: 2 / pi - { -0.434294482f, 0.434294482f, PAL_EPSILON }, // value: -(log10(e)) expected: log10(e) - { -0.318309886f, 0.318309886f, PAL_EPSILON }, // value: -(1 / pi) expected: 1 / pi - { -0.0f, 0, PAL_EPSILON }, - }; - - - // PAL initialization - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.cpp new file mode 100644 index 0000000000..0b020729b8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.cpp @@ -0,0 +1,130 @@ +// 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: test1.c +** +** Purpose: Test to ensure that fabsf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = fabsf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("fabsf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = fabsf(value); + + if (!_isnan(result)) + { + Fail("fabsf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +INT __cdecl main(INT argc, CHAR **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { PAL_NEGINF, PAL_POSINF, 0 }, + { -3.14159265f, 3.14159265f, PAL_EPSILON * 10 }, // value: -(pi) expected: pi + { -2.71828183f, 2.71828183f, PAL_EPSILON * 10 }, // value: -(e) expected: e + { -2.30258509f, 2.30258509f, PAL_EPSILON * 10 }, // value: -(ln(10)) expected: ln(10) + { -1.57079633f, 1.57079633f, PAL_EPSILON * 10 }, // value: -(pi / 2) expected: pi / 2 + { -1.44269504f, 1.44269504f, PAL_EPSILON * 10 }, // value: -(log2(e)) expected: log2(e) + { -1.41421356f, 1.41421356f, PAL_EPSILON * 10 }, // value: -(sqrt(2)) expected: sqrt(2) + { -1.12837917f, 1.12837917f, PAL_EPSILON * 10 }, // value: -(2 / sqrt(pi)) expected: 2 / sqrt(pi) + { -1, 1, PAL_EPSILON * 10 }, + { -0.785398163f, 0.785398163f, PAL_EPSILON }, // value: -(pi / 4) expected: pi / 4 + { -0.707106781f, 0.707106781f, PAL_EPSILON }, // value: -(1 / sqrt(2)) expected: 1 / sqrt(2) + { -0.693147181f, 0.693147181f, PAL_EPSILON }, // value: -(ln(2)) expected: ln(2) + { -0.636619772f, 0.636619772f, PAL_EPSILON }, // value: -(2 / pi) expected: 2 / pi + { -0.434294482f, 0.434294482f, PAL_EPSILON }, // value: -(log10(e)) expected: log10(e) + { -0.318309886f, 0.318309886f, PAL_EPSILON }, // value: -(1 / pi) expected: 1 / pi + { -0.0f, 0, PAL_EPSILON }, + }; + + + // PAL initialization + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fclose/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fclose/test1/CMakeLists.txt index 55ed7c674e..64cfef0e18 100644 --- a/src/pal/tests/palsuite/c_runtime/fclose/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fclose/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fclose_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fclose/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fclose/test1/test1.c deleted file mode 100644 index 0a8463823d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fclose/test1/test1.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: test1.c (fclose) -** -** Purpose: Tests the PAL implementation of the fclose function. -** This test will use fdopen to create a file stream, -** that will be used to test fclose. fclose will also -** be passed a closed file handle to make sure it handle -** it accordingly. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - BOOL bRetVal = FALSE; - int iFiledes = 0; - FILE *fp; - - SECURITY_ATTRIBUTES lpPipeAttributes; - - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /*Create a Pipe*/ - bRetVal = CreatePipe(&hReadPipe, // read handle - &hWritePipe, // write handle - &lpPipeAttributes,// security attributes - 0); // pipe size - - if (bRetVal == FALSE) - { - Fail("ERROR: Unable to create pipe; returned error code %ld" - , GetLastError()); - } - - /*Get a file descriptor for the read pipe handle*/ - iFiledes = _open_osfhandle((long)hReadPipe,_O_RDONLY); - - if (iFiledes == -1) - { - Fail("ERROR: _open_osfhandle failed to open " - " hReadPipe=0x%lx", hReadPipe); - } - - /*Open read pipe handle in read mode*/ - fp = _fdopen(iFiledes, "r"); - - if (fp == NULL) - { - Fail("ERROR: unable to fdopen file descriptor" - " iFiledes=%d", iFiledes); - } - - /*Attempt to close the file stream*/ - if (fclose(fp) != 0) - { - Fail("ERROR: Unable to fclose file stream fp=0x%lx\n",fp); - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/c_runtime/fclose/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fclose/test1/test1.cpp new file mode 100644 index 0000000000..0a8463823d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fclose/test1/test1.cpp @@ -0,0 +1,79 @@ +// 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: test1.c (fclose) +** +** Purpose: Tests the PAL implementation of the fclose function. +** This test will use fdopen to create a file stream, +** that will be used to test fclose. fclose will also +** be passed a closed file handle to make sure it handle +** it accordingly. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + int iFiledes = 0; + FILE *fp; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, // read handle + &hWritePipe, // write handle + &lpPipeAttributes,// security attributes + 0); // pipe size + + if (bRetVal == FALSE) + { + Fail("ERROR: Unable to create pipe; returned error code %ld" + , GetLastError()); + } + + /*Get a file descriptor for the read pipe handle*/ + iFiledes = _open_osfhandle((long)hReadPipe,_O_RDONLY); + + if (iFiledes == -1) + { + Fail("ERROR: _open_osfhandle failed to open " + " hReadPipe=0x%lx", hReadPipe); + } + + /*Open read pipe handle in read mode*/ + fp = _fdopen(iFiledes, "r"); + + if (fp == NULL) + { + Fail("ERROR: unable to fdopen file descriptor" + " iFiledes=%d", iFiledes); + } + + /*Attempt to close the file stream*/ + if (fclose(fp) != 0) + { + Fail("ERROR: Unable to fclose file stream fp=0x%lx\n",fp); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/fclose/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fclose/test2/CMakeLists.txt index 178dc7d19a..3b5538608f 100644 --- a/src/pal/tests/palsuite/c_runtime/fclose/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fclose/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_fclose_test2 diff --git a/src/pal/tests/palsuite/c_runtime/fclose/test2/test2.c b/src/pal/tests/palsuite/c_runtime/fclose/test2/test2.c deleted file mode 100644 index f4da535535..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fclose/test2/test2.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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: test2.c (fclose) -** -** Purpose: Tests the PAL implementation of the fclose function. -** fclose will be passed a closed file handle to make -** sure it handles it accordingly. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - BOOL bRetVal = FALSE; - int iFiledes = 0; - FILE *fp; - - SECURITY_ATTRIBUTES lpPipeAttributes; - - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /*Create a Pipe*/ - bRetVal = CreatePipe(&hReadPipe, /* read handle */ - &hWritePipe, /* write handle */ - &lpPipeAttributes,/* security attributes */ - 0); /* pipe size */ - - if (bRetVal == FALSE) - { - Fail("ERROR: Unable to create pipe; returned error code %ld" - , GetLastError()); - } - - /*Get a file descriptor for the read pipe handle*/ - iFiledes = _open_osfhandle((long)hReadPipe,_O_RDONLY); - - if (iFiledes == -1) - { - Fail("ERROR: _open_osfhandle failed to open " - " hReadPipe=0x%lx", hReadPipe); - } - - /*Open read pipe handle in read mode*/ - fp = _fdopen(iFiledes, "r"); - - if (fp == NULL) - { - Fail("ERROR: unable to fdopen file descriptor" - " iFiledes=%d", iFiledes); - } - - /*Attempt to close the file stream*/ - if (fclose(fp) != 0) - { - Fail("ERROR: Unable to fclose file stream fp=0x%lx\n", fp); - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/c_runtime/fclose/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/fclose/test2/test2.cpp new file mode 100644 index 0000000000..f4da535535 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fclose/test2/test2.cpp @@ -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: test2.c (fclose) +** +** Purpose: Tests the PAL implementation of the fclose function. +** fclose will be passed a closed file handle to make +** sure it handles it accordingly. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + int iFiledes = 0; + FILE *fp; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, /* read handle */ + &hWritePipe, /* write handle */ + &lpPipeAttributes,/* security attributes */ + 0); /* pipe size */ + + if (bRetVal == FALSE) + { + Fail("ERROR: Unable to create pipe; returned error code %ld" + , GetLastError()); + } + + /*Get a file descriptor for the read pipe handle*/ + iFiledes = _open_osfhandle((long)hReadPipe,_O_RDONLY); + + if (iFiledes == -1) + { + Fail("ERROR: _open_osfhandle failed to open " + " hReadPipe=0x%lx", hReadPipe); + } + + /*Open read pipe handle in read mode*/ + fp = _fdopen(iFiledes, "r"); + + if (fp == NULL) + { + Fail("ERROR: unable to fdopen file descriptor" + " iFiledes=%d", iFiledes); + } + + /*Attempt to close the file stream*/ + if (fclose(fp) != 0) + { + Fail("ERROR: Unable to fclose file stream fp=0x%lx\n", fp); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/feof/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/feof/test1/CMakeLists.txt index ee1389deb0..9f689503e6 100644 --- a/src/pal/tests/palsuite/c_runtime/feof/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/feof/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_feof_test1 diff --git a/src/pal/tests/palsuite/c_runtime/feof/test1/test1.c b/src/pal/tests/palsuite/c_runtime/feof/test1/test1.c deleted file mode 100644 index ba018aa91d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/feof/test1/test1.c +++ /dev/null @@ -1,88 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the feof function. -** Open a file, and read some characters. Check that -** feof states that it hasn't gone by the EOF. Then -** read enough characters to go beyond the EOF, and check -** that feof states this is so. -** -** Depends: -** fopen -** fread -** -** -** -**===================================================================*/ - -/* The file 'testfile' should exist with 15 characters in it. If not, - something has been lost ... -*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - const char filename[] = "testfile"; - char buffer[128]; - FILE * fp = NULL; - int result; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file in READ mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading. Is the file " - "in the directory? It should be."); - } - - /* Read 10 characters from the file. The file has 15 - characters in it. - */ - - if((result = fread(buffer,1,10,fp)) == 0) - { - Fail("ERROR: Zero characters read from the file. It should have " - "read 10 character in it."); - } - - if(feof(fp)) - { - Fail("ERROR: feof returned a value greater than 0. No read " - "operation has gone beyond the EOF yet, and feof should " - "return 0 still."); - } - - /* Read 10 characters from the file. The file has 15 - characters in it. The file pointer should have no passed - the end of file. - */ - - if((result = fread(buffer,1,10,fp)) == 0) - { - Fail("ERROR: Zero characters read from the file. It should have " - "read 5 character in it."); - } - - if(feof(fp) == 0) - { - Fail("ERROR: feof returned 0. The file pointer has gone beyond " - "the EOF and this function should return positive now."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/feof/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/feof/test1/test1.cpp new file mode 100644 index 0000000000..ba018aa91d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/feof/test1/test1.cpp @@ -0,0 +1,88 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the feof function. +** Open a file, and read some characters. Check that +** feof states that it hasn't gone by the EOF. Then +** read enough characters to go beyond the EOF, and check +** that feof states this is so. +** +** Depends: +** fopen +** fread +** +** +** +**===================================================================*/ + +/* The file 'testfile' should exist with 15 characters in it. If not, + something has been lost ... +*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + const char filename[] = "testfile"; + char buffer[128]; + FILE * fp = NULL; + int result; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file in READ mode */ + + if((fp = fopen(filename, "r")) == NULL) + { + Fail("Unable to open a file for reading. Is the file " + "in the directory? It should be."); + } + + /* Read 10 characters from the file. The file has 15 + characters in it. + */ + + if((result = fread(buffer,1,10,fp)) == 0) + { + Fail("ERROR: Zero characters read from the file. It should have " + "read 10 character in it."); + } + + if(feof(fp)) + { + Fail("ERROR: feof returned a value greater than 0. No read " + "operation has gone beyond the EOF yet, and feof should " + "return 0 still."); + } + + /* Read 10 characters from the file. The file has 15 + characters in it. The file pointer should have no passed + the end of file. + */ + + if((result = fread(buffer,1,10,fp)) == 0) + { + Fail("ERROR: Zero characters read from the file. It should have " + "read 5 character in it."); + } + + if(feof(fp) == 0) + { + Fail("ERROR: feof returned 0. The file pointer has gone beyond " + "the EOF and this function should return positive now."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ferror/test1/CMakeLists.txt index 2ab12b5db3..cd1fe52381 100644 --- a/src/pal/tests/palsuite/c_runtime/ferror/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/ferror/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_ferror_test1 diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test1/test1.c b/src/pal/tests/palsuite/c_runtime/ferror/test1/test1.c deleted file mode 100644 index 516f2531ed..0000000000 --- a/src/pal/tests/palsuite/c_runtime/ferror/test1/test1.c +++ /dev/null @@ -1,74 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the ferror function. -** -** Depends: -** fopen -** fread -** fclose -** -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - const char filename[] = "testfile"; - char buffer[128]; - FILE * fp = NULL; - int result; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file in READ mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading. Is the file " - "in the directory? It should be."); - } - - /* Read 10 characters from the file. The file has 15 - characters in it. - */ - - if((result = fread(buffer,1,10,fp)) == 0) - { - Fail("ERROR: Zero characters read from the file. It should have " - "read 10 character in from a 15 character file."); - } - - if(ferror(fp) != 0) - { - Fail("ERROR: ferror returned a value not equal to 0. The read " - "operation shouldn't have caused an error, and ferror should " - "return 0 still."); - } - - /* - Close the open file and end the test. - */ - - if(fclose(fp) != 0) - { - Fail("ERROR: fclose failed when trying to close a file pointer. " - "This test depends on fclose working properly."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/ferror/test1/test1.cpp new file mode 100644 index 0000000000..516f2531ed --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/test1/test1.cpp @@ -0,0 +1,74 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the ferror function. +** +** Depends: +** fopen +** fread +** fclose +** +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + const char filename[] = "testfile"; + char buffer[128]; + FILE * fp = NULL; + int result; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file in READ mode */ + + if((fp = fopen(filename, "r")) == NULL) + { + Fail("Unable to open a file for reading. Is the file " + "in the directory? It should be."); + } + + /* Read 10 characters from the file. The file has 15 + characters in it. + */ + + if((result = fread(buffer,1,10,fp)) == 0) + { + Fail("ERROR: Zero characters read from the file. It should have " + "read 10 character in from a 15 character file."); + } + + if(ferror(fp) != 0) + { + Fail("ERROR: ferror returned a value not equal to 0. The read " + "operation shouldn't have caused an error, and ferror should " + "return 0 still."); + } + + /* + Close the open file and end the test. + */ + + if(fclose(fp) != 0) + { + Fail("ERROR: fclose failed when trying to close a file pointer. " + "This test depends on fclose working properly."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ferror/test2/CMakeLists.txt index 077dde0bc6..05bd7fd2f1 100644 --- a/src/pal/tests/palsuite/c_runtime/ferror/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/ferror/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_ferror_test2 diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test2/test2.c b/src/pal/tests/palsuite/c_runtime/ferror/test2/test2.c deleted file mode 100644 index fdf9e032c8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/ferror/test2/test2.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test2.c -** -** Purpose: Open a read-only file and attempt to write some data to it. -** Check to ensure that an ferror occurs. -** -** Depends: -** fopen -** fwrite -** fclose -** -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - const char filename[] = "testfile"; - FILE * fp = NULL; - int result; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open a file in READONLY mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading."); - } - - /* Attempt to write 14 characters to the file. */ - - if((result = fwrite("This is a test",1,14,fp)) != 0) - { - Fail("ERROR: %d characters written. 0 characters should " - "have been written, since this file is read-only.", result); - } - - if(ferror(fp) == 0) - { - Fail("ERROR: ferror should have generated an error when " - "write was called on a read-only file. But, it " - "retured 0, indicating no error.\n"); - } - - /* Close the file. */ - - if(fclose(fp) != 0) - { - Fail("ERROR: fclose failed when trying to close a file pointer. " - "This test depends on fclose working properly."); - } - - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/ferror/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/ferror/test2/test2.cpp new file mode 100644 index 0000000000..fdf9e032c8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ferror/test2/test2.cpp @@ -0,0 +1,69 @@ +// 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: test2.c +** +** Purpose: Open a read-only file and attempt to write some data to it. +** Check to ensure that an ferror occurs. +** +** Depends: +** fopen +** fwrite +** fclose +** +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + const char filename[] = "testfile"; + FILE * fp = NULL; + int result; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Open a file in READONLY mode */ + + if((fp = fopen(filename, "r")) == NULL) + { + Fail("Unable to open a file for reading."); + } + + /* Attempt to write 14 characters to the file. */ + + if((result = fwrite("This is a test",1,14,fp)) != 0) + { + Fail("ERROR: %d characters written. 0 characters should " + "have been written, since this file is read-only.", result); + } + + if(ferror(fp) == 0) + { + Fail("ERROR: ferror should have generated an error when " + "write was called on a read-only file. But, it " + "retured 0, indicating no error.\n"); + } + + /* Close the file. */ + + if(fclose(fp) != 0) + { + Fail("ERROR: fclose failed when trying to close a file pointer. " + "This test depends on fclose working properly."); + } + + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fflush/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fflush/test1/CMakeLists.txt index 743f1d2111..58c7c5a3a4 100644 --- a/src/pal/tests/palsuite/c_runtime/fflush/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fflush/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fflush_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fflush/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fflush/test1/test1.c deleted file mode 100644 index 7baf9ba5b9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fflush/test1/test1.c +++ /dev/null @@ -1,80 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests to see that fflush is working properly. Flushes a couple -** buffers and checks the return value. Can't figure out a way to test -** and ensure it is really dropping the buffers, since the system -** does this automatically most of the time ... -** -** -**==========================================================================*/ - -/* This function is really tough to test. Right now it just tests - a bunch of return values. No solid way to ensure that it is really - flushing a buffer or not -- might have to be a manual test someday. -*/ - -#include - - -int __cdecl main(int argc, char **argv) -{ - - int TheReturn; - FILE* TheFile; - FILE* AnotherFile = NULL; - - PAL_Initialize(argc,argv); - - TheFile = fopen("theFile","w+"); - - if(TheFile == NULL) - { - Fail("ERROR: fopen failed. Test depends on this function."); - } - - TheReturn = fwrite("foo",3,3,TheFile); - - if(TheReturn != 3) - { - Fail("ERROR: fwrite failed. Test depends on this function."); - } - - /* Test to see that FlushFileBuffers returns a success value */ - TheReturn = fflush(TheFile); - - if(TheReturn != 0) - { - Fail("ERROR: The fflush function returned non-zero, which " - "indicates failure, when trying to flush a buffer."); - } - - /* Test to see that FlushFileBuffers returns a success value */ - TheReturn = fflush(NULL); - - if(TheReturn != 0) - { - Fail("ERROR: The fflush function returned non-zero, which " - "indicates failure, when trying to flush all buffers."); - } - - /* Test to see that FlushFileBuffers returns a success value */ - TheReturn = fflush(AnotherFile); - - if(TheReturn != 0) - { - Fail("ERROR: The fflush function returned non-zero, which " - "indicates failure, when trying to flush a stream not " - "associated with a file."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fflush/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fflush/test1/test1.cpp new file mode 100644 index 0000000000..7baf9ba5b9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fflush/test1/test1.cpp @@ -0,0 +1,80 @@ +// 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: test1.c +** +** Purpose: Tests to see that fflush is working properly. Flushes a couple +** buffers and checks the return value. Can't figure out a way to test +** and ensure it is really dropping the buffers, since the system +** does this automatically most of the time ... +** +** +**==========================================================================*/ + +/* This function is really tough to test. Right now it just tests + a bunch of return values. No solid way to ensure that it is really + flushing a buffer or not -- might have to be a manual test someday. +*/ + +#include + + +int __cdecl main(int argc, char **argv) +{ + + int TheReturn; + FILE* TheFile; + FILE* AnotherFile = NULL; + + PAL_Initialize(argc,argv); + + TheFile = fopen("theFile","w+"); + + if(TheFile == NULL) + { + Fail("ERROR: fopen failed. Test depends on this function."); + } + + TheReturn = fwrite("foo",3,3,TheFile); + + if(TheReturn != 3) + { + Fail("ERROR: fwrite failed. Test depends on this function."); + } + + /* Test to see that FlushFileBuffers returns a success value */ + TheReturn = fflush(TheFile); + + if(TheReturn != 0) + { + Fail("ERROR: The fflush function returned non-zero, which " + "indicates failure, when trying to flush a buffer."); + } + + /* Test to see that FlushFileBuffers returns a success value */ + TheReturn = fflush(NULL); + + if(TheReturn != 0) + { + Fail("ERROR: The fflush function returned non-zero, which " + "indicates failure, when trying to flush all buffers."); + } + + /* Test to see that FlushFileBuffers returns a success value */ + TheReturn = fflush(AnotherFile); + + if(TheReturn != 0) + { + Fail("ERROR: The fflush function returned non-zero, which " + "indicates failure, when trying to flush a stream not " + "associated with a file."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fgets/test1/CMakeLists.txt index 672d910c85..d327d6882a 100644 --- a/src/pal/tests/palsuite/c_runtime/fgets/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fgets/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fgets_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fgets/test1/test1.c deleted file mode 100644 index 5e0e62dece..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fgets/test1/test1.c +++ /dev/null @@ -1,102 +0,0 @@ -// 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: test1.c -** -** Purpose: Writes a simple file and calls fgets() to get a string shorter -** than the first line of the file. Verifies that the correct -** string is returned. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - const char outBuf1[] = "This is a test.\n"; - const char outBuf2[] = "This is too."; - char inBuf[sizeof(outBuf1) + sizeof(outBuf2)]; - const char filename[] = "testfile.tmp"; - const int offset = 5; /* value chosen arbitrarily */ - int actualLen; - int expectedLen; - FILE * fp; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /*write the file that we will use to test */ - fp = fopen(filename, "w"); - if (fp == NULL) - { - Fail("Unable to open file for write.\n"); - } - - fwrite(outBuf1, sizeof(outBuf1[0]), sizeof(outBuf1), fp); - fwrite(outBuf2, sizeof(outBuf2[0]), sizeof(outBuf2), fp); - - if (fclose(fp) != 0) - { - Fail("Error closing a file opened for write.\n"); - } - - - /*now read back the entire first string*/ - fp = fopen(filename, "r"); - if (fp == NULL) - { - Fail("Unable to open file for read.\n"); - } - - /*note: +1 because strlen() returns the length of a string _not_ - including the NULL, while fgets() returns a string of specified - maximum length _including_ the NULL.*/ - if (fgets(inBuf, strlen(outBuf1) - offset + 1, fp) != inBuf) - { - Fail("Error reading from file using fgets.\n"); - } - - - expectedLen = strlen(outBuf1) - offset; - actualLen = strlen(inBuf); - - if (actualLen < expectedLen) - { - Fail("fgets() was asked to read a one-line string and given the " - "length of the string as a parameter. The string it has " - "read is too short.\n"); - } - if (actualLen > expectedLen) - { - Fail("fgets() was asked to read a one-line string and given the " - "length of the string as a parameter. The string it has " - "read is too long.\n"); - } - if (memcmp(inBuf, outBuf1, actualLen) != 0) - { - /*We didn't read back exactly outBuf1*/ - Fail("fgets() was asked to read a one-line string, and given the " - "length of the string as an parameter. It has returned a " - "string of the correct length, but the contents are not " - "correct.\n"); - } - - if (fclose(fp) != 0) - { - Fail("Error closing file after using fgets().\n"); - } - - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fgets/test1/test1.cpp new file mode 100644 index 0000000000..5e0e62dece --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fgets/test1/test1.cpp @@ -0,0 +1,102 @@ +// 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: test1.c +** +** Purpose: Writes a simple file and calls fgets() to get a string shorter +** than the first line of the file. Verifies that the correct +** string is returned. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + const char outBuf1[] = "This is a test.\n"; + const char outBuf2[] = "This is too."; + char inBuf[sizeof(outBuf1) + sizeof(outBuf2)]; + const char filename[] = "testfile.tmp"; + const int offset = 5; /* value chosen arbitrarily */ + int actualLen; + int expectedLen; + FILE * fp; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /*write the file that we will use to test */ + fp = fopen(filename, "w"); + if (fp == NULL) + { + Fail("Unable to open file for write.\n"); + } + + fwrite(outBuf1, sizeof(outBuf1[0]), sizeof(outBuf1), fp); + fwrite(outBuf2, sizeof(outBuf2[0]), sizeof(outBuf2), fp); + + if (fclose(fp) != 0) + { + Fail("Error closing a file opened for write.\n"); + } + + + /*now read back the entire first string*/ + fp = fopen(filename, "r"); + if (fp == NULL) + { + Fail("Unable to open file for read.\n"); + } + + /*note: +1 because strlen() returns the length of a string _not_ + including the NULL, while fgets() returns a string of specified + maximum length _including_ the NULL.*/ + if (fgets(inBuf, strlen(outBuf1) - offset + 1, fp) != inBuf) + { + Fail("Error reading from file using fgets.\n"); + } + + + expectedLen = strlen(outBuf1) - offset; + actualLen = strlen(inBuf); + + if (actualLen < expectedLen) + { + Fail("fgets() was asked to read a one-line string and given the " + "length of the string as a parameter. The string it has " + "read is too short.\n"); + } + if (actualLen > expectedLen) + { + Fail("fgets() was asked to read a one-line string and given the " + "length of the string as a parameter. The string it has " + "read is too long.\n"); + } + if (memcmp(inBuf, outBuf1, actualLen) != 0) + { + /*We didn't read back exactly outBuf1*/ + Fail("fgets() was asked to read a one-line string, and given the " + "length of the string as an parameter. It has returned a " + "string of the correct length, but the contents are not " + "correct.\n"); + } + + if (fclose(fp) != 0) + { + Fail("Error closing file after using fgets().\n"); + } + + + PAL_Terminate(); + return PASS; + +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fgets/test2/CMakeLists.txt index d39401536b..23bcdef686 100644 --- a/src/pal/tests/palsuite/c_runtime/fgets/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fgets/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_fgets_test2 diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test2/test2.c b/src/pal/tests/palsuite/c_runtime/fgets/test2/test2.c deleted file mode 100644 index fa37cdbc13..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fgets/test2/test2.c +++ /dev/null @@ -1,97 +0,0 @@ -// 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: test2.c -** -** Purpose: Calls fgets to read a full line from a file. A maximum length -** parameter greater than the length of the line is passed. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - const char outBuf1[] = "This is a test.\n"; - const char outBuf2[] = "This is too."; - - char inBuf[sizeof(outBuf1) + sizeof(outBuf2)]; - const char filename[] = "testfile.tmp"; - const int offset = 5; /*value chosen arbitrarily*/ - int expectedLen; - int actualLen; - - FILE * fp; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /*write the file that we will use to test */ - fp = fopen(filename, "w"); - if (fp == NULL) - { - Fail("Unable to open file for write.\n"); - } - - fwrite(outBuf1, sizeof(outBuf1[0]), sizeof(outBuf1), fp); - fwrite(outBuf2, sizeof(outBuf2[0]), sizeof(outBuf2), fp); - - if (fclose(fp) != 0) - { - Fail("error closing stream opened for write.\n"); - } - - /*Read until the first linebreak*/ - fp = fopen(filename, "r"); - if (fp == NULL) - { - Fail("Unable to open file for read.\n"); - } - - - if (fgets(inBuf, sizeof(outBuf1) + offset , fp) != inBuf) - { - Fail("Error reading from file using fgets.\n"); - } - - /*note: -1 because strlen returns the length of a string _not_ - including the NULL, while fgets returns a string of specified - maximum length _including_ the NULL.*/ - expectedLen = strlen(outBuf1); - actualLen = strlen(inBuf); - if (actualLen > expectedLen) - { - Fail("fgets() was asked to read the first line of a file, but did " - "not stop at the end of the line.\n"); - } - else if (actualLen < expectedLen) - { - Fail("fgets() was asked to read the first line of a file, but did " - "not read the entire line.\n"); - } - else if (memcmp(inBuf, outBuf1, actualLen) != 0) - { - /*We didn't read back exactly outBuf1*/ - Fail("fgets() was asked to read the first line of a file. It " - "has read back a string of the correct length, but the" - " contents are not correct.\n"); - } - - if (fclose(fp) != 0) - { - Fail("Error closing file after using fgets().\n"); - } - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/fgets/test2/test2.cpp new file mode 100644 index 0000000000..fa37cdbc13 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fgets/test2/test2.cpp @@ -0,0 +1,97 @@ +// 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: test2.c +** +** Purpose: Calls fgets to read a full line from a file. A maximum length +** parameter greater than the length of the line is passed. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + const char outBuf1[] = "This is a test.\n"; + const char outBuf2[] = "This is too."; + + char inBuf[sizeof(outBuf1) + sizeof(outBuf2)]; + const char filename[] = "testfile.tmp"; + const int offset = 5; /*value chosen arbitrarily*/ + int expectedLen; + int actualLen; + + FILE * fp; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /*write the file that we will use to test */ + fp = fopen(filename, "w"); + if (fp == NULL) + { + Fail("Unable to open file for write.\n"); + } + + fwrite(outBuf1, sizeof(outBuf1[0]), sizeof(outBuf1), fp); + fwrite(outBuf2, sizeof(outBuf2[0]), sizeof(outBuf2), fp); + + if (fclose(fp) != 0) + { + Fail("error closing stream opened for write.\n"); + } + + /*Read until the first linebreak*/ + fp = fopen(filename, "r"); + if (fp == NULL) + { + Fail("Unable to open file for read.\n"); + } + + + if (fgets(inBuf, sizeof(outBuf1) + offset , fp) != inBuf) + { + Fail("Error reading from file using fgets.\n"); + } + + /*note: -1 because strlen returns the length of a string _not_ + including the NULL, while fgets returns a string of specified + maximum length _including_ the NULL.*/ + expectedLen = strlen(outBuf1); + actualLen = strlen(inBuf); + if (actualLen > expectedLen) + { + Fail("fgets() was asked to read the first line of a file, but did " + "not stop at the end of the line.\n"); + } + else if (actualLen < expectedLen) + { + Fail("fgets() was asked to read the first line of a file, but did " + "not read the entire line.\n"); + } + else if (memcmp(inBuf, outBuf1, actualLen) != 0) + { + /*We didn't read back exactly outBuf1*/ + Fail("fgets() was asked to read the first line of a file. It " + "has read back a string of the correct length, but the" + " contents are not correct.\n"); + } + + if (fclose(fp) != 0) + { + Fail("Error closing file after using fgets().\n"); + } + + PAL_Terminate(); + return PASS; + +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fgets/test3/CMakeLists.txt index 50f0901ee1..0833ad0130 100644 --- a/src/pal/tests/palsuite/c_runtime/fgets/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fgets/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_fgets_test3 diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.c b/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.c deleted file mode 100644 index 525ba9327f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.c +++ /dev/null @@ -1,73 +0,0 @@ -// 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: test3.c -** -** Purpose: Tries to read from an empty file using fgets(), to verify -** handling of EOF condition. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - char inBuf[10]; - const char filename[] = "testfile.tmp"; - - FILE * fp; - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /*write the empty file that we will use to test */ - fp = fopen(filename, "w"); - if (fp == NULL) - { - Fail("Unable to open file for write.\n"); - } - - /*Don't write anything*/ - - if (fclose(fp) != 0) - { - Fail("Error closing stream opened for write.\n"); - } - - - /*Open the file and try to read.*/ - fp = fopen(filename, "r"); - if (fp == NULL) - { - Fail("Unable to open file for read.\n"); - } - - - if (fgets(inBuf, sizeof(inBuf) , fp) != NULL) - { - /*NULL could also mean an error condition, but since the PAL - doesn't supply feof or ferror, we can't distinguish between - the two.*/ - Fail("fgets doesn't handle EOF properly. When asked to read from " - "an empty file, it didn't return NULL as it should have.\n"); - } - - if (fclose(fp) != 0) - { - Fail("Error closing an empty file after trying to use fgets().\n"); - } - PAL_Terminate(); - return PASS; - -} - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp new file mode 100644 index 0000000000..525ba9327f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp @@ -0,0 +1,73 @@ +// 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: test3.c +** +** Purpose: Tries to read from an empty file using fgets(), to verify +** handling of EOF condition. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + char inBuf[10]; + const char filename[] = "testfile.tmp"; + + FILE * fp; + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /*write the empty file that we will use to test */ + fp = fopen(filename, "w"); + if (fp == NULL) + { + Fail("Unable to open file for write.\n"); + } + + /*Don't write anything*/ + + if (fclose(fp) != 0) + { + Fail("Error closing stream opened for write.\n"); + } + + + /*Open the file and try to read.*/ + fp = fopen(filename, "r"); + if (fp == NULL) + { + Fail("Unable to open file for read.\n"); + } + + + if (fgets(inBuf, sizeof(inBuf) , fp) != NULL) + { + /*NULL could also mean an error condition, but since the PAL + doesn't supply feof or ferror, we can't distinguish between + the two.*/ + Fail("fgets doesn't handle EOF properly. When asked to read from " + "an empty file, it didn't return NULL as it should have.\n"); + } + + if (fclose(fp) != 0) + { + Fail("Error closing an empty file after trying to use fgets().\n"); + } + PAL_Terminate(); + return PASS; + +} + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/floor/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/floor/test1/CMakeLists.txt index dbc5abde5b..3222ed8ba3 100644 --- a/src/pal/tests/palsuite/c_runtime/floor/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/floor/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_floor_test1 diff --git a/src/pal/tests/palsuite/c_runtime/floor/test1/test1.c b/src/pal/tests/palsuite/c_runtime/floor/test1/test1.c deleted file mode 100644 index dba320919b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/floor/test1/test1.c +++ /dev/null @@ -1,132 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests floor with simple positive and negative values. Also tests -** extreme cases like extremely small values and positive and -** negative infinity. Makes sure that calling floor on NaN returns -** NaN -** -**==========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = floor(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("floor(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = floor(value); - - if (!_isnan(result)) - { - Fail("floor(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char *argv[]) -{ - struct test tests[] = - { - /* value expected variance */ - { 0.31830988618379067, 0, PAL_EPSILON }, // value: 1 / pi - { 0.43429448190325183, 0, PAL_EPSILON }, // value: log10(e) - { 0.63661977236758134, 0, PAL_EPSILON }, // value: 2 / pi - { 0.69314718055994531, 0, PAL_EPSILON }, // value: ln(2) - { 0.70710678118654752, 0, PAL_EPSILON }, // value: 1 / sqrt(2) - { 0.78539816339744831, 0, PAL_EPSILON }, // value: pi / 4 - { 1.1283791670955126, 1, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 1, PAL_EPSILON * 10 }, // value: sqrt(2) - { 1.4426950408889634, 1, PAL_EPSILON * 10 }, // value: log2(e) - { 1.5707963267948966, 1, PAL_EPSILON * 10 }, // value: pi / 2 - { 2.3025850929940457, 2, PAL_EPSILON * 10 }, // value: ln(10) - { 2.7182818284590452, 2, PAL_EPSILON * 10 }, // value: e - { 3.1415926535897932, 3, PAL_EPSILON * 10 }, // value: pi - { PAL_POSINF, PAL_POSINF, 0 } - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - validate( 0, 0, PAL_EPSILON); - validate(-0.0, 0, PAL_EPSILON); - - validate( 1, 1, PAL_EPSILON * 10); - validate(-1.0, -1, PAL_EPSILON * 10); - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, -(tests[i].expected + 1), tests[i].variance); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/floor/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/floor/test1/test1.cpp new file mode 100644 index 0000000000..dba320919b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/floor/test1/test1.cpp @@ -0,0 +1,132 @@ +// 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: test1.c +** +** Purpose: Tests floor with simple positive and negative values. Also tests +** extreme cases like extremely small values and positive and +** negative infinity. Makes sure that calling floor on NaN returns +** NaN +** +**==========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = floor(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("floor(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = floor(value); + + if (!_isnan(result)) + { + Fail("floor(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char *argv[]) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.31830988618379067, 0, PAL_EPSILON }, // value: 1 / pi + { 0.43429448190325183, 0, PAL_EPSILON }, // value: log10(e) + { 0.63661977236758134, 0, PAL_EPSILON }, // value: 2 / pi + { 0.69314718055994531, 0, PAL_EPSILON }, // value: ln(2) + { 0.70710678118654752, 0, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0, PAL_EPSILON }, // value: pi / 4 + { 1.1283791670955126, 1, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 1, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.4426950408889634, 1, PAL_EPSILON * 10 }, // value: log2(e) + { 1.5707963267948966, 1, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.3025850929940457, 2, PAL_EPSILON * 10 }, // value: ln(10) + { 2.7182818284590452, 2, PAL_EPSILON * 10 }, // value: e + { 3.1415926535897932, 3, PAL_EPSILON * 10 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate( 0, 0, PAL_EPSILON); + validate(-0.0, 0, PAL_EPSILON); + + validate( 1, 1, PAL_EPSILON * 10); + validate(-1.0, -1, PAL_EPSILON * 10); + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -(tests[i].expected + 1), tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/floorf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/floorf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/floorf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/floorf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/floorf/test1/CMakeLists.txt new file mode 100644 index 0000000000..f6e24adcd9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/floorf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_floorf_test1 + ${SOURCES} +) + +add_dependencies(paltest_floorf_test1 coreclrpal) + +target_link_libraries(paltest_floorf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/floorf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/floorf/test1/test1.c new file mode 100644 index 0000000000..57dca21382 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/floorf/test1/test1.c @@ -0,0 +1,131 @@ +// 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: test1.c +** +** Purpose: Tests floorf with simple positive and negative values. Also tests +** extreme cases like extremely small values and positive and +** negative infinity. Makes sure that calling floorf on NaN returns +** NaN +** +**==========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = floorf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("floorf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = floorf(value); + + if (!_isnanf(result)) + { + Fail("floorf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char *argv[]) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.318309886f, 0, PAL_EPSILON }, // value: 1 / pi + { 0.434294482f, 0, PAL_EPSILON }, // value: log10f(e) + { 0.636619772f, 0, PAL_EPSILON }, // value: 2 / pi + { 0.693147181f, 0, PAL_EPSILON }, // value: ln(2) + { 0.707106781f, 0, PAL_EPSILON }, // value: 1 / sqrtf(2) + { 0.785398163f, 0, PAL_EPSILON }, // value: pi / 4 + { 1.12837917f, 1, PAL_EPSILON * 10 }, // value: 2 / sqrtf(pi) + { 1.41421356f, 1, PAL_EPSILON * 10 }, // value: sqrtf(2) + { 1.44269504f, 1, PAL_EPSILON * 10 }, // value: logf2(e) + { 1.57079633f, 1, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.30258509f, 2, PAL_EPSILON * 10 }, // value: ln(10) + { 2.71828183f, 2, PAL_EPSILON * 10 }, // value: e + { 3.14159265f, 3, PAL_EPSILON * 10 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate( 0, 0, PAL_EPSILON); + validate(-0.0f, 0, PAL_EPSILON); + + validate( 1, 1, PAL_EPSILON * 10); + validate(-1.0f, -1, PAL_EPSILON * 10); + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -(tests[i].expected + 1), tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/floorf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/floorf/test1/testinfo.dat new file mode 100644 index 0000000000..006540141a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/floorf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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 = C Runtime +Function = floorf +Name = Positive Test for floorf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to floorf() a series of value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/fmod/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fmod/test1/CMakeLists.txt index c76df1f0bf..33fbfb2653 100644 --- a/src/pal/tests/palsuite/c_runtime/fmod/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fmod/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fmod_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.c deleted file mode 100644 index fd69ca52cb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.c +++ /dev/null @@ -1,157 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that fmod return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double numerator; /* second component of the value to test the function with */ - double denominator; /* first component of the value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double numerator, double denominator, double expected, double variance) -{ - double result = fmod(numerator, denominator); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("fmod(%g, %g) returned %20.17g when it should have returned %20.17g", - numerator, denominator, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double numerator, double denominator) -{ - double result = fmod(numerator, denominator); - - if (!_isnan(result)) - { - Fail("fmod(%g, %g) returned %20.17g when it should have returned %20.17g", - numerator, denominator, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -INT __cdecl main(INT argc, CHAR **argv) -{ - struct test tests[] = - { - /* numerator denominator expected variance */ - { 0, PAL_POSINF, 0, PAL_EPSILON }, - { 0.31296179620778659, 0.94976571538163866, 0.31296179620778658, PAL_EPSILON }, - { 0.42077048331375735, 0.90716712923909839, 0.42077048331375733, PAL_EPSILON }, - { 0.59448076852482208, 0.80410982822879171, 0.59448076852482212, PAL_EPSILON }, - { 0.63896127631363480, 0.76923890136397213, 0.63896127631363475, PAL_EPSILON }, - { 0.64963693908006244, 0.76024459707563015, 0.64963693908006248, PAL_EPSILON }, - { 0.70710678118654752, 0.70710678118654752, 0, PAL_EPSILON }, - { 1, 1, 0, PAL_EPSILON }, - { 0.84147098480789651, 0.54030230586813972, 0.30116867893975674, PAL_EPSILON }, - { 0.90371945743584630, 0.42812514788535792, 0.047469161665130377, PAL_EPSILON / 10 }, - { 0.98776594599273553, 0.15594369476537447, 0.052103777400488605, PAL_EPSILON / 10 }, - { 0.99180624439366372, 0.12775121753523991, 0.097547721646984359, PAL_EPSILON / 10 }, - { 0.74398033695749319, -0.66820151019031295, 0.075778826767180285, PAL_EPSILON / 10 }, - { 0.41078129050290870, -0.91173391478696510, 0.41078129050290868, PAL_EPSILON }, - { 0, -1, 0, PAL_EPSILON }, - { 1, PAL_POSINF, 1, PAL_EPSILON * 10 }, - }; - - - // PAL initialization - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].numerator, tests[i].denominator, tests[i].expected, tests[i].variance); - validate(-tests[i].numerator, tests[i].denominator, -tests[i].expected, tests[i].variance); - validate( tests[i].numerator, -tests[i].denominator, tests[i].expected, tests[i].variance); - validate(-tests[i].numerator, -tests[i].denominator, -tests[i].expected, tests[i].variance); - } - - validate_isnan( 0, 0); - validate_isnan(-0.0, 0); - validate_isnan( 0, -0.0); - validate_isnan(-0.0, -0.0); - - validate_isnan( 1, 0); - validate_isnan(-1.0, 0); - validate_isnan( 1, -0.0); - validate_isnan(-1.0, -0.0); - - validate_isnan(PAL_POSINF, PAL_POSINF); - validate_isnan(PAL_NEGINF, PAL_POSINF); - validate_isnan(PAL_POSINF, PAL_NEGINF); - validate_isnan(PAL_NEGINF, PAL_NEGINF); - - validate_isnan(PAL_POSINF, 0); - validate_isnan(PAL_NEGINF, 0); - validate_isnan(PAL_POSINF, -0.0); - validate_isnan(PAL_NEGINF, -0.0); - - validate_isnan(PAL_POSINF, 1); - validate_isnan(PAL_NEGINF, 1); - validate_isnan(PAL_POSINF, -1.0); - validate_isnan(PAL_NEGINF, -1.0); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.cpp new file mode 100644 index 0000000000..fd69ca52cb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.cpp @@ -0,0 +1,157 @@ +// 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: test1.c +** +** Purpose: Test to ensure that fmod return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double numerator; /* second component of the value to test the function with */ + double denominator; /* first component of the value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double numerator, double denominator, double expected, double variance) +{ + double result = fmod(numerator, denominator); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("fmod(%g, %g) returned %20.17g when it should have returned %20.17g", + numerator, denominator, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double numerator, double denominator) +{ + double result = fmod(numerator, denominator); + + if (!_isnan(result)) + { + Fail("fmod(%g, %g) returned %20.17g when it should have returned %20.17g", + numerator, denominator, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +INT __cdecl main(INT argc, CHAR **argv) +{ + struct test tests[] = + { + /* numerator denominator expected variance */ + { 0, PAL_POSINF, 0, PAL_EPSILON }, + { 0.31296179620778659, 0.94976571538163866, 0.31296179620778658, PAL_EPSILON }, + { 0.42077048331375735, 0.90716712923909839, 0.42077048331375733, PAL_EPSILON }, + { 0.59448076852482208, 0.80410982822879171, 0.59448076852482212, PAL_EPSILON }, + { 0.63896127631363480, 0.76923890136397213, 0.63896127631363475, PAL_EPSILON }, + { 0.64963693908006244, 0.76024459707563015, 0.64963693908006248, PAL_EPSILON }, + { 0.70710678118654752, 0.70710678118654752, 0, PAL_EPSILON }, + { 1, 1, 0, PAL_EPSILON }, + { 0.84147098480789651, 0.54030230586813972, 0.30116867893975674, PAL_EPSILON }, + { 0.90371945743584630, 0.42812514788535792, 0.047469161665130377, PAL_EPSILON / 10 }, + { 0.98776594599273553, 0.15594369476537447, 0.052103777400488605, PAL_EPSILON / 10 }, + { 0.99180624439366372, 0.12775121753523991, 0.097547721646984359, PAL_EPSILON / 10 }, + { 0.74398033695749319, -0.66820151019031295, 0.075778826767180285, PAL_EPSILON / 10 }, + { 0.41078129050290870, -0.91173391478696510, 0.41078129050290868, PAL_EPSILON }, + { 0, -1, 0, PAL_EPSILON }, + { 1, PAL_POSINF, 1, PAL_EPSILON * 10 }, + }; + + + // PAL initialization + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].numerator, tests[i].denominator, tests[i].expected, tests[i].variance); + validate(-tests[i].numerator, tests[i].denominator, -tests[i].expected, tests[i].variance); + validate( tests[i].numerator, -tests[i].denominator, tests[i].expected, tests[i].variance); + validate(-tests[i].numerator, -tests[i].denominator, -tests[i].expected, tests[i].variance); + } + + validate_isnan( 0, 0); + validate_isnan(-0.0, 0); + validate_isnan( 0, -0.0); + validate_isnan(-0.0, -0.0); + + validate_isnan( 1, 0); + validate_isnan(-1.0, 0); + validate_isnan( 1, -0.0); + validate_isnan(-1.0, -0.0); + + validate_isnan(PAL_POSINF, PAL_POSINF); + validate_isnan(PAL_NEGINF, PAL_POSINF); + validate_isnan(PAL_POSINF, PAL_NEGINF); + validate_isnan(PAL_NEGINF, PAL_NEGINF); + + validate_isnan(PAL_POSINF, 0); + validate_isnan(PAL_NEGINF, 0); + validate_isnan(PAL_POSINF, -0.0); + validate_isnan(PAL_NEGINF, -0.0); + + validate_isnan(PAL_POSINF, 1); + validate_isnan(PAL_NEGINF, 1); + validate_isnan(PAL_POSINF, -1.0); + validate_isnan(PAL_NEGINF, -1.0); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fmodf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fmodf/test1/CMakeLists.txt index d1ea238a98..487b3adda4 100644 --- a/src/pal/tests/palsuite/c_runtime/fmodf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fmodf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fmodf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.c deleted file mode 100644 index 31b45d3606..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.c +++ /dev/null @@ -1,156 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that fmodf return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabsf -** -**===========================================================================*/ - -#include - -// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (6-9 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON -// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use -// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. -#define PAL_EPSILON 4.76837158e-07 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - float numerator; /* second component of the value to test the function with */ - float denominator; /* first component of the value to test the function with */ - float expected; /* expected result */ - float variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(float numerator, float denominator, float expected, float variance) -{ - float result = fmodf(numerator, denominator); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - float delta = fabsf(result - expected); - - if (delta > variance) - { - Fail("fmodf(%g, %g) returned %10.9g when it should have returned %10.9g", - numerator, denominator, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(float numerator, float denominator) -{ - float result = fmodf(numerator, denominator); - - if (!_isnan(result)) - { - Fail("fmodf(%g, %g) returned %10.9g when it should have returned %10.9g", - numerator, denominator, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -INT __cdecl main(INT argc, CHAR **argv) -{ - struct test tests[] = - { - /* numerator denominator expected variance */ - { 0, PAL_POSINF, 0, PAL_EPSILON }, - { 0.312961796f, 0.949765715f, 0.312961796f, PAL_EPSILON }, - { 0.420770483f, 0.907167129f, 0.420770483f, PAL_EPSILON }, - { 0.594480769f, 0.804109828f, 0.594480769f, PAL_EPSILON }, - { 0.638961276f, 0.769238901f, 0.638961276f, PAL_EPSILON }, - { 0.649636939f, 0.760244597f, 0.649636939f, PAL_EPSILON }, - { 0.707106781f, 0.707106781f, 0, PAL_EPSILON }, - { 1, 1, 0, PAL_EPSILON }, - { 0.841470985f, 0.540302306f, 0.301168679f, PAL_EPSILON }, - { 0.903719457f, 0.428125148f, 0.0474691617f, PAL_EPSILON / 10 }, - { 0.987765946f, 0.155943695f, 0.0521037774f, PAL_EPSILON / 10 }, - { 0.991806244f, 0.127751218f, 0.0975477216f, PAL_EPSILON / 10 }, - { 0.743980337f, -0.668201510f, 0.0757788268f, PAL_EPSILON / 10 }, - { 0.410781291f, -0.911733915f, 0.410781291f, PAL_EPSILON }, - { 0, -1, 0, PAL_EPSILON }, - { 1, PAL_POSINF, 1, PAL_EPSILON * 10 }, - }; - - - // PAL initialization - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].numerator, tests[i].denominator, tests[i].expected, tests[i].variance); - validate(-tests[i].numerator, tests[i].denominator, -tests[i].expected, tests[i].variance); - validate( tests[i].numerator, -tests[i].denominator, tests[i].expected, tests[i].variance); - validate(-tests[i].numerator, -tests[i].denominator, -tests[i].expected, tests[i].variance); - } - - validate_isnan( 0, 0); - validate_isnan(-0.0f, 0); - validate_isnan( 0, -0.0f); - validate_isnan(-0.0f, -0.0f); - - validate_isnan( 1, 0); - validate_isnan(-1, 0); - validate_isnan( 1, -0.0f); - validate_isnan(-1, -0.0f); - - validate_isnan(PAL_POSINF, PAL_POSINF); - validate_isnan(PAL_NEGINF, PAL_POSINF); - validate_isnan(PAL_POSINF, PAL_NEGINF); - validate_isnan(PAL_NEGINF, PAL_NEGINF); - - validate_isnan(PAL_POSINF, 0); - validate_isnan(PAL_NEGINF, 0); - validate_isnan(PAL_POSINF, -0.0f); - validate_isnan(PAL_NEGINF, -0.0f); - - validate_isnan(PAL_POSINF, 1); - validate_isnan(PAL_NEGINF, 1); - validate_isnan(PAL_POSINF, -1); - validate_isnan(PAL_NEGINF, -1); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.cpp new file mode 100644 index 0000000000..31b45d3606 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.cpp @@ -0,0 +1,156 @@ +// 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: test1.c +** +** Purpose: Test to ensure that fmodf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + float numerator; /* second component of the value to test the function with */ + float denominator; /* first component of the value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float numerator, float denominator, float expected, float variance) +{ + float result = fmodf(numerator, denominator); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("fmodf(%g, %g) returned %10.9g when it should have returned %10.9g", + numerator, denominator, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float numerator, float denominator) +{ + float result = fmodf(numerator, denominator); + + if (!_isnan(result)) + { + Fail("fmodf(%g, %g) returned %10.9g when it should have returned %10.9g", + numerator, denominator, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +INT __cdecl main(INT argc, CHAR **argv) +{ + struct test tests[] = + { + /* numerator denominator expected variance */ + { 0, PAL_POSINF, 0, PAL_EPSILON }, + { 0.312961796f, 0.949765715f, 0.312961796f, PAL_EPSILON }, + { 0.420770483f, 0.907167129f, 0.420770483f, PAL_EPSILON }, + { 0.594480769f, 0.804109828f, 0.594480769f, PAL_EPSILON }, + { 0.638961276f, 0.769238901f, 0.638961276f, PAL_EPSILON }, + { 0.649636939f, 0.760244597f, 0.649636939f, PAL_EPSILON }, + { 0.707106781f, 0.707106781f, 0, PAL_EPSILON }, + { 1, 1, 0, PAL_EPSILON }, + { 0.841470985f, 0.540302306f, 0.301168679f, PAL_EPSILON }, + { 0.903719457f, 0.428125148f, 0.0474691617f, PAL_EPSILON / 10 }, + { 0.987765946f, 0.155943695f, 0.0521037774f, PAL_EPSILON / 10 }, + { 0.991806244f, 0.127751218f, 0.0975477216f, PAL_EPSILON / 10 }, + { 0.743980337f, -0.668201510f, 0.0757788268f, PAL_EPSILON / 10 }, + { 0.410781291f, -0.911733915f, 0.410781291f, PAL_EPSILON }, + { 0, -1, 0, PAL_EPSILON }, + { 1, PAL_POSINF, 1, PAL_EPSILON * 10 }, + }; + + + // PAL initialization + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].numerator, tests[i].denominator, tests[i].expected, tests[i].variance); + validate(-tests[i].numerator, tests[i].denominator, -tests[i].expected, tests[i].variance); + validate( tests[i].numerator, -tests[i].denominator, tests[i].expected, tests[i].variance); + validate(-tests[i].numerator, -tests[i].denominator, -tests[i].expected, tests[i].variance); + } + + validate_isnan( 0, 0); + validate_isnan(-0.0f, 0); + validate_isnan( 0, -0.0f); + validate_isnan(-0.0f, -0.0f); + + validate_isnan( 1, 0); + validate_isnan(-1, 0); + validate_isnan( 1, -0.0f); + validate_isnan(-1, -0.0f); + + validate_isnan(PAL_POSINF, PAL_POSINF); + validate_isnan(PAL_NEGINF, PAL_POSINF); + validate_isnan(PAL_POSINF, PAL_NEGINF); + validate_isnan(PAL_NEGINF, PAL_NEGINF); + + validate_isnan(PAL_POSINF, 0); + validate_isnan(PAL_NEGINF, 0); + validate_isnan(PAL_POSINF, -0.0f); + validate_isnan(PAL_NEGINF, -0.0f); + + validate_isnan(PAL_POSINF, 1); + validate_isnan(PAL_NEGINF, 1); + validate_isnan(PAL_POSINF, -1); + validate_isnan(PAL_NEGINF, -1); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test1/CMakeLists.txt index 6578c43659..7603fc623e 100644 --- a/src/pal/tests/palsuite/c_runtime/fopen/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fopen/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fopen_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fopen/test1/test1.c deleted file mode 100644 index 565b4eb77d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fopen/test1/test1.c +++ /dev/null @@ -1,82 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** This test simply attempts to open a number of files -** with different modes. It checks to ensure a valid -** file pointer is returned. It doesn't do any checking -** to ensure the mode is really what it claims. And checks -** for a NULL pointer when attempts to open a directory. -** - -** -**===================================================================*/ - -#include - -struct testCase -{ - int CorrectResult; - char mode[20]; -}; - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char name[128]; - int i; - - struct testCase testCases[] = - { - {0, "r"}, {1, "w"}, {1, "a"}, - {0, "r+"}, {1, "w+"}, {1, "a+"}, - {1, "wt"}, {1, "wb"}, {1, "wS"}, - {1, "w+c"}, {1, "w+n"}, {1, "wR"}, - {1, "wT"}, {0, "tw"} - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - strcpy(name,"testfiles"); - strcat(name,testCases[i].mode); - - fp = fopen(name,testCases[i].mode); - - if ((fp == 0 && testCases[i].CorrectResult != 0) || - (testCases[i].CorrectResult == 0 && fp != 0) ) - { - 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?",testCases[i].mode); - } - - memset(name, '\0', 128); - - } - - /* When attempt to open a directory fopen should returned NULL */ - if ( fopen(".", "r") != NULL) - { - Fail("ERROR: fopen returned non-NULL when trying to open a directory" - " the returned value was %d\n", fp); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fopen/test1/test1.cpp new file mode 100644 index 0000000000..565b4eb77d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fopen/test1/test1.cpp @@ -0,0 +1,82 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the fopen function. +** This test simply attempts to open a number of files +** with different modes. It checks to ensure a valid +** file pointer is returned. It doesn't do any checking +** to ensure the mode is really what it claims. And checks +** for a NULL pointer when attempts to open a directory. +** + +** +**===================================================================*/ + +#include + +struct testCase +{ + int CorrectResult; + char mode[20]; +}; + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char name[128]; + int i; + + struct testCase testCases[] = + { + {0, "r"}, {1, "w"}, {1, "a"}, + {0, "r+"}, {1, "w+"}, {1, "a+"}, + {1, "wt"}, {1, "wb"}, {1, "wS"}, + {1, "w+c"}, {1, "w+n"}, {1, "wR"}, + {1, "wT"}, {0, "tw"} + }; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + strcpy(name,"testfiles"); + strcat(name,testCases[i].mode); + + fp = fopen(name,testCases[i].mode); + + if ((fp == 0 && testCases[i].CorrectResult != 0) || + (testCases[i].CorrectResult == 0 && fp != 0) ) + { + 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?",testCases[i].mode); + } + + memset(name, '\0', 128); + + } + + /* When attempt to open a directory fopen should returned NULL */ + if ( fopen(".", "r") != NULL) + { + Fail("ERROR: fopen returned non-NULL when trying to open a directory" + " the returned value was %d\n", fp); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test2/CMakeLists.txt index 4458ed21d8..b8569921de 100644 --- a/src/pal/tests/palsuite/c_runtime/fopen/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fopen/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_fopen_test2 diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test2/test2.c b/src/pal/tests/palsuite/c_runtime/fopen/test2/test2.c deleted file mode 100644 index 4026efe89a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fopen/test2/test2.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to a 'w' mode file. -** And that you can't read from a 'w' mode file. -** -** Depends: -** fprintf -** fseek -** fgets -** - -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - if( (fp = fopen( "testfile", "w" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w' mode.\n" ); - } - - /* Test that you can write */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Test that you can't read */ - if(fgets(buffer,10,fp) != NULL) - { - Fail("ERROR: Tried to READ from a file with only 'w' mode set. " - "This should fail, but fgets didn't return NULL. Either " - "fgets or fopen is broken."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/fopen/test2/test2.cpp new file mode 100644 index 0000000000..4026efe89a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fopen/test2/test2.cpp @@ -0,0 +1,65 @@ +// 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: test2.c +** +** Purpose: Tests the PAL implementation of the fopen function. +** Test to ensure that you can write to a 'w' mode file. +** And that you can't read from a 'w' mode file. +** +** Depends: +** fprintf +** fseek +** fgets +** + +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + if( (fp = fopen( "testfile", "w" )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'w' mode.\n" ); + } + + /* Test that you can write */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Test that you can't read */ + if(fgets(buffer,10,fp) != NULL) + { + Fail("ERROR: Tried to READ from a file with only 'w' mode set. " + "This should fail, but fgets didn't return NULL. Either " + "fgets or fopen is broken."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test3/CMakeLists.txt index 2c80f72ae7..5b28caf4ba 100644 --- a/src/pal/tests/palsuite/c_runtime/fopen/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fopen/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_fopen_test3 diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test3/test3.c b/src/pal/tests/palsuite/c_runtime/fopen/test3/test3.c deleted file mode 100644 index f3af42dc8a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fopen/test3/test3.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to a 'w+' mode file. -** And that you can read from a 'w+' mode file. -** -** Depends: -** fprintf -** fseek -** fgets -** - -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'w+' mode */ - if( (fp = fopen( "testfile", "w+" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w+' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'w+' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'w+' only file, should pass */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'w+' mode set. " - "This should succeed, but fgets returned NULL. Either fgets " - "or fopen is broken."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/fopen/test3/test3.cpp new file mode 100644 index 0000000000..f3af42dc8a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fopen/test3/test3.cpp @@ -0,0 +1,66 @@ +// 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: test3.c +** +** Purpose: Tests the PAL implementation of the fopen function. +** Test to ensure that you can write to a 'w+' mode file. +** And that you can read from a 'w+' mode file. +** +** Depends: +** fprintf +** fseek +** fgets +** + +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file with 'w+' mode */ + if( (fp = fopen( "testfile", "w+" )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'w+' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'w+' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read from the 'w+' only file, should pass */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'w+' mode set. " + "This should succeed, but fgets returned NULL. Either fgets " + "or fopen is broken."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test4/CMakeLists.txt index 92e0ef0bd8..db5779f282 100644 --- a/src/pal/tests/palsuite/c_runtime/fopen/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fopen/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_fopen_test4 diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test4/test4.c b/src/pal/tests/palsuite/c_runtime/fopen/test4/test4.c deleted file mode 100644 index 04683d52c5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fopen/test4/test4.c +++ /dev/null @@ -1,82 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can't write to a 'r' mode file. -** And that you can read from a 'r' mode file. -** -** Depends: -** fprintf -** fclose -** fgets -** - -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'w' mode */ - if( (fp = fopen( "testfile", "w" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fclose(fp)) - { - Fail("ERROR: Attempted to close a file, but fclose failed. " - "This test depends upon it."); - } - - /* Open a file with 'r' mode */ - if( (fp = fopen( "testfile", "r" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'r' mode.\n" ); - } - - /* Attempt to read from the 'r' only file, should pass */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'r' mode set. " - "This should succeed, but fgets returned NULL. Either fgets " - "or fopen is broken."); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") > 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'r' mode " - "but fprintf succeeded It should have failed. " - "Either fopen or fprintf have problems."); - } - - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/fopen/test4/test4.cpp new file mode 100644 index 0000000000..04683d52c5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fopen/test4/test4.cpp @@ -0,0 +1,82 @@ +// 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: test4.c +** +** Purpose: Tests the PAL implementation of the fopen function. +** Test to ensure that you can't write to a 'r' mode file. +** And that you can read from a 'r' mode file. +** +** Depends: +** fprintf +** fclose +** fgets +** + +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file with 'w' mode */ + if( (fp = fopen( "testfile", "w" )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'w' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fclose(fp)) + { + Fail("ERROR: Attempted to close a file, but fclose failed. " + "This test depends upon it."); + } + + /* Open a file with 'r' mode */ + if( (fp = fopen( "testfile", "r" )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'r' mode.\n" ); + } + + /* Attempt to read from the 'r' only file, should pass */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'r' mode set. " + "This should succeed, but fgets returned NULL. Either fgets " + "or fopen is broken."); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") > 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'r' mode " + "but fprintf succeeded It should have failed. " + "Either fopen or fprintf have problems."); + } + + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test5/CMakeLists.txt index 82529b9aab..6341e4a7d2 100644 --- a/src/pal/tests/palsuite/c_runtime/fopen/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fopen/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_fopen_test5 diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test5/test5.c b/src/pal/tests/palsuite/c_runtime/fopen/test5/test5.c deleted file mode 100644 index 0a760314e1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fopen/test5/test5.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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: test5.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to a 'r+' mode file. -** And that you can read from a 'r+' mode file. -** -** Depends: -** fprintf -** fclose -** fgets -** fseek -** - -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'w' mode */ - if( (fp = fopen( "testfile", "w" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w' mode.\n" ); - } - - if(fclose(fp)) - { - Fail("ERROR: Attempted to close a file, but fclose failed. " - "This test depends upon it."); - } - - if( (fp = fopen( "testfile", "r+" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'r+' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'r+' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'r+' only file, should pass */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'r+' mode set. " - "This should succeed, but fgets returned NULL. Either fgets " - "or fopen is broken."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/fopen/test5/test5.cpp new file mode 100644 index 0000000000..0a760314e1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fopen/test5/test5.cpp @@ -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: test5.c +** +** Purpose: Tests the PAL implementation of the fopen function. +** Test to ensure that you can write to a 'r+' mode file. +** And that you can read from a 'r+' mode file. +** +** Depends: +** fprintf +** fclose +** fgets +** fseek +** + +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file with 'w' mode */ + if( (fp = fopen( "testfile", "w" )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'w' mode.\n" ); + } + + if(fclose(fp)) + { + Fail("ERROR: Attempted to close a file, but fclose failed. " + "This test depends upon it."); + } + + if( (fp = fopen( "testfile", "r+" )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'r+' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'r+' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read from the 'r+' only file, should pass */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'r+' mode set. " + "This should succeed, but fgets returned NULL. Either fgets " + "or fopen is broken."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test6/CMakeLists.txt index 9a01cfb9a8..39cf9158bb 100644 --- a/src/pal/tests/palsuite/c_runtime/fopen/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fopen/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_fopen_test6 diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test6/test6.c b/src/pal/tests/palsuite/c_runtime/fopen/test6/test6.c deleted file mode 100644 index 03b6067fdd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fopen/test6/test6.c +++ /dev/null @@ -1,131 +0,0 @@ -// 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: test6.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to an 'a' mode file. -** And that you can't read from a 'a' mode file. Also ensure -** that you can use fseek and still write to the end of a file. -** -** Depends: -** fprintf -** fgets -** fseek -** fclose -** - -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'a+' mode */ - if( (fp = fopen( "testfile", "a" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'a' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'a' only file, should fail */ - if(fgets(buffer,10,fp) != NULL) - { - Fail("ERROR: Tried to READ from a file with 'a' mode set. " - "This should fail, but fgets returned success. Either fgets " - "or fopen is broken."); - } - - - /* Attempt to write to a file after using 'a' and fseek */ - fp = fopen("testfile2", "a"); - if(fp == NULL) - { - Fail("ERROR: The file failed to be created with 'a' mode.\n"); - } - - /* write text to the file initially */ - if(fprintf(fp,"%s","abcd") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " - "but fprintf failed. Either fopen or fprintf have problems.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* using 'a' should still write to the end of the file, not the front */ - if(fputs("efgh",fp) < 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " - "but fputs failed.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* a file with 'a' mode can only write, so close the file before reading */ - if(fclose(fp)) - { - Fail("ERROR: fclose failed when it should have succeeded.\n"); - } - - /* open the file again to read */ - fp = fopen("testfile2","r"); - if(fp == NULL) - { - Fail("ERROR: fopen failed to open the file using 'r' mode"); - } - - /* Attempt to read from the 'a' only file, should succeed */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'a' mode set. " - "This should pass, but fgets returned failure. Either fgets " - "or fopen is broken.\n"); - } - - /* Compare what was read and what should have been in the file */ - if(memcmp(buffer,"abcdefgh",8)) - { - Fail("ERROR: The string read should have equaled 'abcdefgh' " - "but instead it is %s\n", buffer); - } - - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/fopen/test6/test6.cpp new file mode 100644 index 0000000000..03b6067fdd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fopen/test6/test6.cpp @@ -0,0 +1,131 @@ +// 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: test6.c +** +** Purpose: Tests the PAL implementation of the fopen function. +** Test to ensure that you can write to an 'a' mode file. +** And that you can't read from a 'a' mode file. Also ensure +** that you can use fseek and still write to the end of a file. +** +** Depends: +** fprintf +** fgets +** fseek +** fclose +** + +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file with 'a+' mode */ + if( (fp = fopen( "testfile", "a" )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'a' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " + "but fprintf failed. Either fopen or fprintf have problems."); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read from the 'a' only file, should fail */ + if(fgets(buffer,10,fp) != NULL) + { + Fail("ERROR: Tried to READ from a file with 'a' mode set. " + "This should fail, but fgets returned success. Either fgets " + "or fopen is broken."); + } + + + /* Attempt to write to a file after using 'a' and fseek */ + fp = fopen("testfile2", "a"); + if(fp == NULL) + { + Fail("ERROR: The file failed to be created with 'a' mode.\n"); + } + + /* write text to the file initially */ + if(fprintf(fp,"%s","abcd") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " + "but fprintf failed. Either fopen or fprintf have problems.\n"); + } + + /* set the pointer to the front of the file */ + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it.\n"); + } + + /* using 'a' should still write to the end of the file, not the front */ + if(fputs("efgh",fp) < 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " + "but fputs failed.\n"); + } + + /* set the pointer to the front of the file */ + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it.\n"); + } + + /* a file with 'a' mode can only write, so close the file before reading */ + if(fclose(fp)) + { + Fail("ERROR: fclose failed when it should have succeeded.\n"); + } + + /* open the file again to read */ + fp = fopen("testfile2","r"); + if(fp == NULL) + { + Fail("ERROR: fopen failed to open the file using 'r' mode"); + } + + /* Attempt to read from the 'a' only file, should succeed */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'a' mode set. " + "This should pass, but fgets returned failure. Either fgets " + "or fopen is broken.\n"); + } + + /* Compare what was read and what should have been in the file */ + if(memcmp(buffer,"abcdefgh",8)) + { + Fail("ERROR: The string read should have equaled 'abcdefgh' " + "but instead it is %s\n", buffer); + } + + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fopen/test7/CMakeLists.txt index 168a5aff53..ee22e347d6 100644 --- a/src/pal/tests/palsuite/c_runtime/fopen/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fopen/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_fopen_test7 diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test7/test7.c b/src/pal/tests/palsuite/c_runtime/fopen/test7/test7.c deleted file mode 100644 index 3ef8602ddb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fopen/test7/test7.c +++ /dev/null @@ -1,117 +0,0 @@ -// 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: test7.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to an 'a+' mode file. -** And that you can read from a 'a+' mode file. Also ensure -** that you can use fseek and still write to the end of a file. -** -** Depends: -** fprintf -** fgets -** fseek -** fclose -** - -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'a+' mode */ - if( (fp = fopen( "testfile", "a+" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'a+' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " - "but fprintf failed. Either fopen or fprintf have problems.\n"); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* Attempt to read from the 'a+' only file, should succeed */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'a+' mode set. " - "This should pass, but fgets returned failure. Either fgets " - "or fopen is broken.\n"); - } - - - /* Attempt to write to a file after using 'a+' and fseek */ - fp = fopen("testfile2", "a+"); - if(fp == NULL) - { - Fail("ERROR: The file failed to be created with 'a+' mode.\n"); - } - - /* write text to the file initially */ - if(fprintf(fp,"%s","abcd") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " - "but fprintf failed. Either fopen or fprintf have problems.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* using 'a+' should still write to the end of the file, not the front */ - if(fputs("efgh",fp) < 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " - "but fputs failed.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* Attempt to read from the 'a+' only file, should succeed */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'a+' mode set. " - "This should pass, but fgets returned failure. Either fgets " - "or fopen is broken.\n"); - } - - /* Compare what was read and what should have been in the file */ - if(memcmp(buffer,"abcdefgh",8)) - { - Fail("ERROR: The string read should have equaled 'abcdefgh' " - "but instead it is %s\n", buffer); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fopen/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/fopen/test7/test7.cpp new file mode 100644 index 0000000000..3ef8602ddb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fopen/test7/test7.cpp @@ -0,0 +1,117 @@ +// 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: test7.c +** +** Purpose: Tests the PAL implementation of the fopen function. +** Test to ensure that you can write to an 'a+' mode file. +** And that you can read from a 'a+' mode file. Also ensure +** that you can use fseek and still write to the end of a file. +** +** Depends: +** fprintf +** fgets +** fseek +** fclose +** + +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE *fp; + char buffer[128]; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Open a file with 'a+' mode */ + if( (fp = fopen( "testfile", "a+" )) == NULL ) + { + Fail( "ERROR: The file failed to open with 'a+' mode.\n" ); + } + + /* Write some text to the file */ + if(fprintf(fp,"%s","some text") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " + "but fprintf failed. Either fopen or fprintf have problems.\n"); + } + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it.\n"); + } + + /* Attempt to read from the 'a+' only file, should succeed */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'a+' mode set. " + "This should pass, but fgets returned failure. Either fgets " + "or fopen is broken.\n"); + } + + + /* Attempt to write to a file after using 'a+' and fseek */ + fp = fopen("testfile2", "a+"); + if(fp == NULL) + { + Fail("ERROR: The file failed to be created with 'a+' mode.\n"); + } + + /* write text to the file initially */ + if(fprintf(fp,"%s","abcd") <= 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " + "but fprintf failed. Either fopen or fprintf have problems.\n"); + } + + /* set the pointer to the front of the file */ + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it.\n"); + } + + /* using 'a+' should still write to the end of the file, not the front */ + if(fputs("efgh",fp) < 0) + { + Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " + "but fputs failed.\n"); + } + + /* set the pointer to the front of the file */ + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it.\n"); + } + + /* Attempt to read from the 'a+' only file, should succeed */ + if(fgets(buffer,10,fp) == NULL) + { + Fail("ERROR: Tried to READ from a file with 'a+' mode set. " + "This should pass, but fgets returned failure. Either fgets " + "or fopen is broken.\n"); + } + + /* Compare what was read and what should have been in the file */ + if(memcmp(buffer,"abcdefgh",8)) + { + Fail("ERROR: The string read should have equaled 'abcdefgh' " + "but instead it is %s\n", buffer); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/fprintf.h b/src/pal/tests/palsuite/c_runtime/fprintf/fprintf.h index 380eb0a0b3..87ee0d1232 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/fprintf.h +++ b/src/pal/tests/palsuite/c_runtime/fprintf/fprintf.h @@ -11,7 +11,7 @@ function with this as a return type. #ifndef __FPRINTF_H__ #define __FPRINTF_H__ -void DoStrTest(char *formatstr, char* param, char *checkstr) +void DoStrTest(const char *formatstr, char* param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -34,7 +34,7 @@ void DoStrTest(char *formatstr, char* param, char *checkstr) fclose(fp); } -void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) +void DoWStrTest(const char *formatstr, WCHAR* param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -58,7 +58,7 @@ void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) } -void DoCharTest(char *formatstr, char param, char *checkstr) +void DoCharTest(const char *formatstr, char param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -81,7 +81,7 @@ void DoCharTest(char *formatstr, char param, char *checkstr) fclose(fp); } -void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) +void DoWCharTest(const char *formatstr, WCHAR param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -104,7 +104,7 @@ void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) fclose(fp); } -void DoNumTest(char *formatstr, int value, char *checkstr) +void DoNumTest(const char *formatstr, int value, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -127,7 +127,7 @@ void DoNumTest(char *formatstr, int value, char *checkstr) fclose(fp); } -void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr1, char *checkstr2) +void DoI64Test(const char *formatstr, INT64 value, char *valuestr, const char *checkstr1, const char *checkstr2) { FILE *fp; char buf[256] = { 0 }; @@ -151,7 +151,7 @@ void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr1, ch fclose(fp); } -void DoDoubleTest(char *formatstr, double value, char *checkstr1, char *checkstr2) +void DoDoubleTest(const char *formatstr, double value, const char *checkstr1, const char *checkstr2) { FILE *fp; char buf[256] = { 0 }; diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test1/CMakeLists.txt index ab4176563d..60ffd49cf5 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fprintf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fprintf/test1/test1.c deleted file mode 100644 index d55fc2534c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test1/test1.c +++ /dev/null @@ -1,80 +0,0 @@ -// 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: test1.c (fprintf) -** -** Purpose: A single, basic, test case with no formatting. -** Test modeled after the sprintf series. -** - -** -**==========================================================================*/ - -#include - -/* - * Depends on memcmp, strlen, fopen, fgets, fseek and fclose. - */ - -int __cdecl main(int argc, char *argv[]) -{ - FILE *fp; - char testfile[] = "testfile.txt"; - char checkstr[] = "hello world"; - char buf[256]; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - if ((fp = fopen(testfile, "w+")) == NULL) - { - Fail("ERROR: fopen failed to create \"%s\"\n", testfile); - } - - if ((fprintf(fp, "hello world")) < 0) - { - Fail("ERROR: fprintf failed to print to \"%s\"\n", testfile); - } - - if ((fseek( fp, 0, SEEK_SET)) != 0) - - { - - Fail("ERROR: Fseek failed to set pointer to beginning of file\n" ); - - } - - - - if ((fgets( buf, 100, fp )) == NULL) - - { - - Fail("ERROR: fgets failed\n"); - - } - - - if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) - { - Fail("ERROR: expected %s, got %s\n", checkstr, buf); - } - - - - if ((fclose( fp )) != 0) - - { - - Fail("ERROR: fclose failed to close \"%s\"\n", testfile); - - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test1/test1.cpp new file mode 100644 index 0000000000..d55fc2534c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test1/test1.cpp @@ -0,0 +1,80 @@ +// 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: test1.c (fprintf) +** +** Purpose: A single, basic, test case with no formatting. +** Test modeled after the sprintf series. +** + +** +**==========================================================================*/ + +#include + +/* + * Depends on memcmp, strlen, fopen, fgets, fseek and fclose. + */ + +int __cdecl main(int argc, char *argv[]) +{ + FILE *fp; + char testfile[] = "testfile.txt"; + char checkstr[] = "hello world"; + char buf[256]; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + if ((fp = fopen(testfile, "w+")) == NULL) + { + Fail("ERROR: fopen failed to create \"%s\"\n", testfile); + } + + if ((fprintf(fp, "hello world")) < 0) + { + Fail("ERROR: fprintf failed to print to \"%s\"\n", testfile); + } + + if ((fseek( fp, 0, SEEK_SET)) != 0) + + { + + Fail("ERROR: Fseek failed to set pointer to beginning of file\n" ); + + } + + + + if ((fgets( buf, 100, fp )) == NULL) + + { + + Fail("ERROR: fgets failed\n"); + + } + + + if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) + { + Fail("ERROR: expected %s, got %s\n", checkstr, buf); + } + + + + if ((fclose( fp )) != 0) + + { + + Fail("ERROR: fclose failed to close \"%s\"\n", testfile); + + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test10/CMakeLists.txt index f718ad7934..3fb57c217c 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_fprintf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/fprintf/test10/test10.c deleted file mode 100644 index 5988e8da74..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test10/test10.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test10.c (fprintf) -** -** Purpose: Tests the octal specifier (%o). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest("foo %o", pos, "foo 52"); - DoNumTest("foo %lo", 0xFFFF, "foo 177777"); - DoNumTest("foo %ho", 0xFFFF, "foo 177777"); - DoNumTest("foo %Lo", pos, "foo 52"); - DoI64Test("foo %I64o", l, "42", "foo 52", "foo 52"); - DoNumTest("foo %3o", pos, "foo 52"); - DoNumTest("foo %-3o", pos, "foo 52 "); - DoNumTest("foo %.1o", pos, "foo 52"); - DoNumTest("foo %.3o", pos, "foo 052"); - DoNumTest("foo %03o", pos, "foo 052"); - DoNumTest("foo %#o", pos, "foo 052"); - DoNumTest("foo %+o", pos, "foo 52"); - DoNumTest("foo % o", pos, "foo 52"); - DoNumTest("foo %+o", neg, "foo 37777777726"); - DoNumTest("foo % o", neg, "foo 37777777726"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test10/test10.cpp new file mode 100644 index 0000000000..5988e8da74 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test10/test10.cpp @@ -0,0 +1,49 @@ +// 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: test10.c (fprintf) +** +** Purpose: Tests the octal specifier (%o). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest("foo %o", pos, "foo 52"); + DoNumTest("foo %lo", 0xFFFF, "foo 177777"); + DoNumTest("foo %ho", 0xFFFF, "foo 177777"); + DoNumTest("foo %Lo", pos, "foo 52"); + DoI64Test("foo %I64o", l, "42", "foo 52", "foo 52"); + DoNumTest("foo %3o", pos, "foo 52"); + DoNumTest("foo %-3o", pos, "foo 52 "); + DoNumTest("foo %.1o", pos, "foo 52"); + DoNumTest("foo %.3o", pos, "foo 052"); + DoNumTest("foo %03o", pos, "foo 052"); + DoNumTest("foo %#o", pos, "foo 052"); + DoNumTest("foo %+o", pos, "foo 52"); + DoNumTest("foo % o", pos, "foo 52"); + DoNumTest("foo %+o", neg, "foo 37777777726"); + DoNumTest("foo % o", neg, "foo 37777777726"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test11/CMakeLists.txt index 6ccd58ddd2..d325ce225e 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_fprintf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/fprintf/test11/test11.c deleted file mode 100644 index 01880552b7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test11/test11.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test11.c (fprintf) -** -** Purpose: Test the unsigned int specifier (%u). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest("foo %u", pos, "foo 42"); - DoNumTest("foo %lu", 0xFFFF, "foo 65535"); - DoNumTest("foo %hu", 0xFFFF, "foo 65535"); - DoNumTest("foo %Lu", pos, "foo 42"); - DoI64Test("foo %I64u", l, "42", "foo 42", "foo 42"); - DoNumTest("foo %3u", pos, "foo 42"); - DoNumTest("foo %-3u", pos, "foo 42 "); - DoNumTest("foo %.1u", pos, "foo 42"); - DoNumTest("foo %.3u", pos, "foo 042"); - DoNumTest("foo %03u", pos, "foo 042"); - DoNumTest("foo %#u", pos, "foo 42"); - DoNumTest("foo %+u", pos, "foo 42"); - DoNumTest("foo % u", pos, "foo 42"); - DoNumTest("foo %+u", neg, "foo 4294967254"); - DoNumTest("foo % u", neg, "foo 4294967254"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test11/test11.cpp new file mode 100644 index 0000000000..01880552b7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test11/test11.cpp @@ -0,0 +1,49 @@ +// 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: test11.c (fprintf) +** +** Purpose: Test the unsigned int specifier (%u). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest("foo %u", pos, "foo 42"); + DoNumTest("foo %lu", 0xFFFF, "foo 65535"); + DoNumTest("foo %hu", 0xFFFF, "foo 65535"); + DoNumTest("foo %Lu", pos, "foo 42"); + DoI64Test("foo %I64u", l, "42", "foo 42", "foo 42"); + DoNumTest("foo %3u", pos, "foo 42"); + DoNumTest("foo %-3u", pos, "foo 42 "); + DoNumTest("foo %.1u", pos, "foo 42"); + DoNumTest("foo %.3u", pos, "foo 042"); + DoNumTest("foo %03u", pos, "foo 042"); + DoNumTest("foo %#u", pos, "foo 42"); + DoNumTest("foo %+u", pos, "foo 42"); + DoNumTest("foo % u", pos, "foo 42"); + DoNumTest("foo %+u", neg, "foo 4294967254"); + DoNumTest("foo % u", neg, "foo 4294967254"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test12/CMakeLists.txt index 17bc7f100b..8bd3970e80 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_fprintf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/fprintf/test12/test12.c deleted file mode 100644 index 0292e15014..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test12/test12.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test12.c -** -** Purpose: Tests the (lowercase) hexadecimal specifier (%x). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest("foo %x", pos, "foo 1234ab"); - DoNumTest("foo %lx", pos, "foo 1234ab"); - DoNumTest("foo %hx", pos, "foo 34ab"); - DoNumTest("foo %Lx", pos, "foo 1234ab"); - DoI64Test("foo %I64x", l, "0x1234567887654321", - "foo 1234567887654321", "foo 0x1234567887654321"); - DoNumTest("foo %7x", pos, "foo 1234ab"); - DoNumTest("foo %-7x", pos, "foo 1234ab "); - DoNumTest("foo %.1x", pos, "foo 1234ab"); - DoNumTest("foo %.7x", pos, "foo 01234ab"); - DoNumTest("foo %07x", pos, "foo 01234ab"); - DoNumTest("foo %#x", pos, "foo 0x1234ab"); - DoNumTest("foo %+x", pos, "foo 1234ab"); - DoNumTest("foo % x", pos, "foo 1234ab"); - DoNumTest("foo %+x", neg, "foo ffffffd6"); - DoNumTest("foo % x", neg, "foo ffffffd6"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test12/test12.cpp new file mode 100644 index 0000000000..0292e15014 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test12/test12.cpp @@ -0,0 +1,50 @@ +// 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: test12.c +** +** Purpose: Tests the (lowercase) hexadecimal specifier (%x). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest("foo %x", pos, "foo 1234ab"); + DoNumTest("foo %lx", pos, "foo 1234ab"); + DoNumTest("foo %hx", pos, "foo 34ab"); + DoNumTest("foo %Lx", pos, "foo 1234ab"); + DoI64Test("foo %I64x", l, "0x1234567887654321", + "foo 1234567887654321", "foo 0x1234567887654321"); + DoNumTest("foo %7x", pos, "foo 1234ab"); + DoNumTest("foo %-7x", pos, "foo 1234ab "); + DoNumTest("foo %.1x", pos, "foo 1234ab"); + DoNumTest("foo %.7x", pos, "foo 01234ab"); + DoNumTest("foo %07x", pos, "foo 01234ab"); + DoNumTest("foo %#x", pos, "foo 0x1234ab"); + DoNumTest("foo %+x", pos, "foo 1234ab"); + DoNumTest("foo % x", pos, "foo 1234ab"); + DoNumTest("foo %+x", neg, "foo ffffffd6"); + DoNumTest("foo % x", neg, "foo ffffffd6"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test13/CMakeLists.txt index c6eb0f9075..702058b797 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_fprintf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/fprintf/test13/test13.c deleted file mode 100644 index e171aeacce..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test13/test13.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test13.c (fprintf) -** -** Purpose: Tests the (uppercase) hexadecimal specifier (%X). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234AB; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest("foo %X", pos, "foo 1234AB"); - DoNumTest("foo %lX", pos, "foo 1234AB"); - DoNumTest("foo %hX", pos, "foo 34AB"); - DoNumTest("foo %LX", pos, "foo 1234AB"); - DoI64Test("foo %I64X", l, "0x1234567887654321", - "foo 1234567887654321", "foo 0x1234567887654321"); - DoNumTest("foo %7X", pos, "foo 1234AB"); - DoNumTest("foo %-7X", pos, "foo 1234AB "); - DoNumTest("foo %.1X", pos, "foo 1234AB"); - DoNumTest("foo %.7X", pos, "foo 01234AB"); - DoNumTest("foo %07X", pos, "foo 01234AB"); - DoNumTest("foo %#X", pos, "foo 0X1234AB"); - DoNumTest("foo %+X", pos, "foo 1234AB"); - DoNumTest("foo % X", pos, "foo 1234AB"); - DoNumTest("foo %+X", neg, "foo FFFFFFD6"); - DoNumTest("foo % X", neg, "foo FFFFFFD6"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test13/test13.cpp new file mode 100644 index 0000000000..e171aeacce --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test13/test13.cpp @@ -0,0 +1,50 @@ +// 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: test13.c (fprintf) +** +** Purpose: Tests the (uppercase) hexadecimal specifier (%X). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234AB; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest("foo %X", pos, "foo 1234AB"); + DoNumTest("foo %lX", pos, "foo 1234AB"); + DoNumTest("foo %hX", pos, "foo 34AB"); + DoNumTest("foo %LX", pos, "foo 1234AB"); + DoI64Test("foo %I64X", l, "0x1234567887654321", + "foo 1234567887654321", "foo 0x1234567887654321"); + DoNumTest("foo %7X", pos, "foo 1234AB"); + DoNumTest("foo %-7X", pos, "foo 1234AB "); + DoNumTest("foo %.1X", pos, "foo 1234AB"); + DoNumTest("foo %.7X", pos, "foo 01234AB"); + DoNumTest("foo %07X", pos, "foo 01234AB"); + DoNumTest("foo %#X", pos, "foo 0X1234AB"); + DoNumTest("foo %+X", pos, "foo 1234AB"); + DoNumTest("foo % X", pos, "foo 1234AB"); + DoNumTest("foo %+X", neg, "foo FFFFFFD6"); + DoNumTest("foo % X", neg, "foo FFFFFFD6"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test14/CMakeLists.txt index 6bb281bc62..b92ede7c87 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_fprintf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/fprintf/test14/test14.c deleted file mode 100644 index 5d7d77387d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test14/test14.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test14.c (fprintf) -** -** Purpose: Tests the lowercase exponential -** notation double specifier (%e). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", "foo 2.560000e+02 "); - DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); - DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", "foo 2.56000000e+02"); - DoDoubleTest("foo %014e", val, "foo 02.560000e+002", "foo 002.560000e+02"); - DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); - DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test14/test14.cpp new file mode 100644 index 0000000000..5d7d77387d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test14/test14.cpp @@ -0,0 +1,49 @@ +// 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: test14.c (fprintf) +** +** Purpose: Tests the lowercase exponential +** notation double specifier (%e). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", "foo 2.560000e+02 "); + DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); + DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", "foo 2.56000000e+02"); + DoDoubleTest("foo %014e", val, "foo 02.560000e+002", "foo 002.560000e+02"); + DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); + DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test15/CMakeLists.txt index ce1a8b6111..20f1e42aab 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_fprintf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/fprintf/test15/test15.c deleted file mode 100644 index d024bdbd8a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test15/test15.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test15.c (fprintf) -** -** Purpose: Tests the uppercase exponential -** notation double specifier (%E). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", "foo 2.560000E+02 "); - DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); - DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", "foo 2.56000000E+02"); - DoDoubleTest("foo %014E", val, "foo 02.560000E+002", "foo 002.560000E+02"); - DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); - DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test15/test15.cpp new file mode 100644 index 0000000000..d024bdbd8a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test15/test15.cpp @@ -0,0 +1,49 @@ +// 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: test15.c (fprintf) +** +** Purpose: Tests the uppercase exponential +** notation double specifier (%E). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", "foo 2.560000E+02 "); + DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); + DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", "foo 2.56000000E+02"); + DoDoubleTest("foo %014E", val, "foo 02.560000E+002", "foo 002.560000E+02"); + DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); + DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test16/CMakeLists.txt index 011cd13fb1..8d72421210 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_fprintf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/fprintf/test16/test16.c deleted file mode 100644 index 079faeaf59..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test16/test16.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test16.c (fprintf) -** -** Purpose: Tests the decimal notation double specifier (%f). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); - DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); - DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); - DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); - DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); - DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); - DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test16/test16.cpp new file mode 100644 index 0000000000..079faeaf59 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test16/test16.cpp @@ -0,0 +1,48 @@ +// 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: test16.c (fprintf) +** +** Purpose: Tests the decimal notation double specifier (%f). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); + DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); + DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); + DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); + DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); + DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); + DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test17/CMakeLists.txt index 4516f4b769..82d1f84f31 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_fprintf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/fprintf/test17/test17.c deleted file mode 100644 index 7bd817d7db..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test17/test17.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test17.c (fprintf) -** -** Purpose: Tests the lowercase shorthand notation double specifier (%g). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); - DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); - DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test17/test17.cpp new file mode 100644 index 0000000000..7bd817d7db --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test17/test17.cpp @@ -0,0 +1,49 @@ +// 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: test17.c (fprintf) +** +** Purpose: Tests the lowercase shorthand notation double specifier (%g). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); + DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); + DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test18/CMakeLists.txt index fc035020ca..1ca54e42b7 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test18.c + test18.cpp ) add_executable(paltest_fprintf_test18 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/fprintf/test18/test18.c deleted file mode 100644 index 6582c41e0f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test18/test18.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test18.c (fprintf) -** -** Purpose: Tests the uppercase shorthand notation double specifier (%G). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); - DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); - DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test18/test18.cpp new file mode 100644 index 0000000000..6582c41e0f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test18/test18.cpp @@ -0,0 +1,49 @@ +// 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: test18.c (fprintf) +** +** Purpose: Tests the uppercase shorthand notation double specifier (%G). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); + DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); + DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test19/CMakeLists.txt index 3781b426f2..2c66239801 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test19.c + test19.cpp ) add_executable(paltest_fprintf_test19 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/fprintf/test19/test19.c deleted file mode 100644 index 9d9a28c325..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test19/test19.c +++ /dev/null @@ -1,153 +0,0 @@ -// 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: test19.c (fprintf) -** -** Purpose: Tests the variable length precision argument. -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -#define DOTEST(a,b,c,d,e,f) DoTest(a,b,(void*)c,d,e,f) - -void DoTest(char *formatstr, int precision, void *param, - char *paramstr, char *checkstr1, char *checkstr2) -{ - FILE *fp; - char buf[256]; - - if ((fp = fopen("testfile.txt", "w+")) == NULL ) - { - Fail("ERROR: fopen failed to create testfile\n"); - } - - if ((fprintf(fp, formatstr, precision, param)) < 0) - { - Fail("ERROR: fprintf failed\n"); - } - - if ((fseek(fp, 0, SEEK_SET)) != 0) - { - Fail("ERROR: fseek failed\n"); - } - - if ((fgets(buf, 100, fp)) == NULL) - { - Fail("ERROR: fseek failed\n"); - } - - if (memcmp(buf, checkstr1, strlen(buf) + 1) != 0 && - memcmp(buf, checkstr2, strlen(buf) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", paramstr, formatstr, - precision, - checkstr1, checkstr2, buf); - } - - if ((fclose( fp )) != 0) - - { - Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); - } - -} - -void DoublePrecTest(char *formatstr, int precision, - double param, char *checkstr1, char *checkstr2) -{ - FILE *fp; - char buf[256]; - - if ((fp = fopen("testfile.txt", "w+")) == NULL ) - { - Fail("ERROR: fopen failed to create testfile\n"); - } - - if ((fprintf(fp, formatstr, precision, param)) < 0) - { - Fail("ERROR: fprintf failed\n"); - } - - if ((fseek(fp, 0, SEEK_SET)) != 0) - { - Fail("ERROR: fseek failed\n"); - } - - if ((fgets(buf, 100, fp)) == NULL) - { - Fail("ERROR: fseek failed\n"); - } - - if (memcmp(buf, checkstr1, strlen(buf) + 1) != 0 && - memcmp(buf, checkstr2, strlen(buf) + 1) != 0) - { - Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - param, formatstr, precision, checkstr1, checkstr2, buf); - } - - if ((fclose( fp )) != 0) - { - Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); - } - -} - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DOTEST("%.*s", 2, "bar", "bar", "ba", "ba"); - DOTEST("%.*S", 2, convert("bar"), "bar", "ba", "ba"); - - //DOTEST("%.*n", 4, 2, "2", "0002"); - DOTEST("%.*c", 0, 'a', "a", "a", "a"); - DOTEST("%.*c", 4, 'a', "a", "a", "a"); - DOTEST("%.*C", 0, (WCHAR)'a', "a", "a", "a"); - DOTEST("%.*C", 4, (WCHAR)'a', "a", "a", "a"); - DOTEST("%.*d", 1, 42, "42", "42", "42"); - DOTEST("%.*d", 3, 42, "42", "042", "042"); - DOTEST("%.*i", 1, 42, "42", "42", "42"); - DOTEST("%.*i", 3, 42, "42", "042", "042"); - DOTEST("%.*o", 1, 42, "42", "52", "52"); - DOTEST("%.*o", 3, 42, "42", "052", "052"); - DOTEST("%.*u", 1, 42, "42", "42", "42"); - DOTEST("%.*u", 3, 42, "42", "042", "042"); - DOTEST("%.*x", 1, 0x42, "0x42", "42", "42"); - DOTEST("%.*x", 3, 0x42, "0x42", "042", "042"); - DOTEST("%.*X", 1, 0x42, "0x42", "42", "42"); - DOTEST("%.*X", 3, 0x42, "0x42", "042", "042"); - - - DoublePrecTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); - DoublePrecTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); - DoublePrecTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); - DoublePrecTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); - DoublePrecTest("%.*f", 1, 2.01, "2.0", "2.0"); - DoublePrecTest("%.*f", 3, 2.01, "2.010", "2.010"); - DoublePrecTest("%.*g", 1, 256.01, "3e+002", "3e+02"); - DoublePrecTest("%.*g", 3, 256.01, "256", "256"); - DoublePrecTest("%.*g", 4, 256.01, "256", "256"); - DoublePrecTest("%.*g", 6, 256.01, "256.01", "256.01"); - DoublePrecTest("%.*G", 1, 256.01, "3E+002", "3E+02"); - DoublePrecTest("%.*G", 3, 256.01, "256", "256"); - DoublePrecTest("%.*G", 4, 256.01, "256", "256"); - DoublePrecTest("%.*G", 6, 256.01, "256.01", "256.01"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test19/test19.cpp new file mode 100644 index 0000000000..9d9a28c325 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test19/test19.cpp @@ -0,0 +1,153 @@ +// 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: test19.c (fprintf) +** +** Purpose: Tests the variable length precision argument. +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +#define DOTEST(a,b,c,d,e,f) DoTest(a,b,(void*)c,d,e,f) + +void DoTest(char *formatstr, int precision, void *param, + char *paramstr, char *checkstr1, char *checkstr2) +{ + FILE *fp; + char buf[256]; + + if ((fp = fopen("testfile.txt", "w+")) == NULL ) + { + Fail("ERROR: fopen failed to create testfile\n"); + } + + if ((fprintf(fp, formatstr, precision, param)) < 0) + { + Fail("ERROR: fprintf failed\n"); + } + + if ((fseek(fp, 0, SEEK_SET)) != 0) + { + Fail("ERROR: fseek failed\n"); + } + + if ((fgets(buf, 100, fp)) == NULL) + { + Fail("ERROR: fseek failed\n"); + } + + if (memcmp(buf, checkstr1, strlen(buf) + 1) != 0 && + memcmp(buf, checkstr2, strlen(buf) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", paramstr, formatstr, + precision, + checkstr1, checkstr2, buf); + } + + if ((fclose( fp )) != 0) + + { + Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); + } + +} + +void DoublePrecTest(char *formatstr, int precision, + double param, char *checkstr1, char *checkstr2) +{ + FILE *fp; + char buf[256]; + + if ((fp = fopen("testfile.txt", "w+")) == NULL ) + { + Fail("ERROR: fopen failed to create testfile\n"); + } + + if ((fprintf(fp, formatstr, precision, param)) < 0) + { + Fail("ERROR: fprintf failed\n"); + } + + if ((fseek(fp, 0, SEEK_SET)) != 0) + { + Fail("ERROR: fseek failed\n"); + } + + if ((fgets(buf, 100, fp)) == NULL) + { + Fail("ERROR: fseek failed\n"); + } + + if (memcmp(buf, checkstr1, strlen(buf) + 1) != 0 && + memcmp(buf, checkstr2, strlen(buf) + 1) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + param, formatstr, precision, checkstr1, checkstr2, buf); + } + + if ((fclose( fp )) != 0) + { + Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); + } + +} + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DOTEST("%.*s", 2, "bar", "bar", "ba", "ba"); + DOTEST("%.*S", 2, convert("bar"), "bar", "ba", "ba"); + + //DOTEST("%.*n", 4, 2, "2", "0002"); + DOTEST("%.*c", 0, 'a', "a", "a", "a"); + DOTEST("%.*c", 4, 'a', "a", "a", "a"); + DOTEST("%.*C", 0, (WCHAR)'a', "a", "a", "a"); + DOTEST("%.*C", 4, (WCHAR)'a', "a", "a", "a"); + DOTEST("%.*d", 1, 42, "42", "42", "42"); + DOTEST("%.*d", 3, 42, "42", "042", "042"); + DOTEST("%.*i", 1, 42, "42", "42", "42"); + DOTEST("%.*i", 3, 42, "42", "042", "042"); + DOTEST("%.*o", 1, 42, "42", "52", "52"); + DOTEST("%.*o", 3, 42, "42", "052", "052"); + DOTEST("%.*u", 1, 42, "42", "42", "42"); + DOTEST("%.*u", 3, 42, "42", "042", "042"); + DOTEST("%.*x", 1, 0x42, "0x42", "42", "42"); + DOTEST("%.*x", 3, 0x42, "0x42", "042", "042"); + DOTEST("%.*X", 1, 0x42, "0x42", "42", "42"); + DOTEST("%.*X", 3, 0x42, "0x42", "042", "042"); + + + DoublePrecTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); + DoublePrecTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); + DoublePrecTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); + DoublePrecTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); + DoublePrecTest("%.*f", 1, 2.01, "2.0", "2.0"); + DoublePrecTest("%.*f", 3, 2.01, "2.010", "2.010"); + DoublePrecTest("%.*g", 1, 256.01, "3e+002", "3e+02"); + DoublePrecTest("%.*g", 3, 256.01, "256", "256"); + DoublePrecTest("%.*g", 4, 256.01, "256", "256"); + DoublePrecTest("%.*g", 6, 256.01, "256.01", "256.01"); + DoublePrecTest("%.*G", 1, 256.01, "3E+002", "3E+02"); + DoublePrecTest("%.*G", 3, 256.01, "256", "256"); + DoublePrecTest("%.*G", 4, 256.01, "256", "256"); + DoublePrecTest("%.*G", 6, 256.01, "256.01", "256.01"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test2/CMakeLists.txt index 0ef44b6b7d..ae1d9dc64d 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_fprintf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/fprintf/test2/test2.c deleted file mode 100644 index 1ed7f3fd23..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test2/test2.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test2.c (fprintf) -** -** Purpose: Tests the string specifier (%s). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoStrTest("foo %s", "bar", "foo bar"); - DoStrTest("foo %hs", "bar", "foo bar"); - DoWStrTest("foo %ls", convert("bar"), "foo bar"); - DoWStrTest("foo %ws", convert("bar"), "foo bar"); - DoStrTest("foo %Ls", "bar", "foo bar"); - DoStrTest("foo %I64s", "bar", "foo bar"); - DoStrTest("foo %5s", "bar", "foo bar"); - DoStrTest("foo %.2s", "bar", "foo ba"); - DoStrTest("foo %5.2s", "bar", "foo ba"); - DoStrTest("foo %-5s", "bar", "foo bar "); - DoStrTest("foo %05s", "bar", "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test2/test2.cpp new file mode 100644 index 0000000000..1ed7f3fd23 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test2/test2.cpp @@ -0,0 +1,43 @@ +// 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: test2.c (fprintf) +** +** Purpose: Tests the string specifier (%s). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoStrTest("foo %s", "bar", "foo bar"); + DoStrTest("foo %hs", "bar", "foo bar"); + DoWStrTest("foo %ls", convert("bar"), "foo bar"); + DoWStrTest("foo %ws", convert("bar"), "foo bar"); + DoStrTest("foo %Ls", "bar", "foo bar"); + DoStrTest("foo %I64s", "bar", "foo bar"); + DoStrTest("foo %5s", "bar", "foo bar"); + DoStrTest("foo %.2s", "bar", "foo ba"); + DoStrTest("foo %5.2s", "bar", "foo ba"); + DoStrTest("foo %-5s", "bar", "foo bar "); + DoStrTest("foo %05s", "bar", "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test3/CMakeLists.txt index adfd36fce7..4b10c4c407 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_fprintf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/fprintf/test3/test3.c deleted file mode 100644 index 6185135581..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test3/test3.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test3.c (fprintf) -** -** Purpose: Tests the wide string specifier (%S). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoWStrTest("foo %S", convert("bar"), "foo bar"); - DoStrTest("foo %hS", "bar", "foo bar"); - DoWStrTest("foo %lS", convert("bar"), "foo bar"); - DoWStrTest("foo %wS", convert("bar"), "foo bar"); - DoWStrTest("foo %LS", convert("bar"), "foo bar"); - DoWStrTest("foo %I64S", convert("bar"), "foo bar"); - DoWStrTest("foo %5S", convert("bar"), "foo bar"); - DoWStrTest("foo %.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %-5S", convert("bar"), "foo bar "); - DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test3/test3.cpp new file mode 100644 index 0000000000..6185135581 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test3/test3.cpp @@ -0,0 +1,43 @@ +// 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: test3.c (fprintf) +** +** Purpose: Tests the wide string specifier (%S). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoWStrTest("foo %S", convert("bar"), "foo bar"); + DoStrTest("foo %hS", "bar", "foo bar"); + DoWStrTest("foo %lS", convert("bar"), "foo bar"); + DoWStrTest("foo %wS", convert("bar"), "foo bar"); + DoWStrTest("foo %LS", convert("bar"), "foo bar"); + DoWStrTest("foo %I64S", convert("bar"), "foo bar"); + DoWStrTest("foo %5S", convert("bar"), "foo bar"); + DoWStrTest("foo %.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %-5S", convert("bar"), "foo bar "); + DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test4/CMakeLists.txt index 7d471b1b9c..292bdb6625 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_fprintf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c deleted file mode 100644 index 51ec1f099c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c +++ /dev/null @@ -1,110 +0,0 @@ -// 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: test4.c (fprintf) -** -** Purpose: Tests the pointer specifier (%p). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -static void DoTest(char *formatstr, void* param, char* paramstr, - char *checkstr1, char *checkstr2) -{ - FILE *fp; - char buf[256] = { 0 }; - - if ((fp = fopen("testfile.txt", "w+")) == NULL ) - { - Fail("ERROR: fopen failed to create testfile\n"); - } - - if ((fprintf(fp, formatstr, param)) < 0) - { - Fail("ERROR: fprintf failed\n"); - } - - if ((fseek(fp, 0, SEEK_SET)) != 0) - { - Fail("ERROR: fseek failed\n"); - } - - if ((fgets(buf, 100, fp)) == NULL) - { - Fail("ERROR: fseek failed\n"); - } - - if (memcmp(buf, checkstr1, strlen(buf) + 1) != 0 && - memcmp(buf, checkstr2, strlen(buf) + 1) != 0 ) - { - Fail("ERROR: failed to insert %s into \"%s\"\n" - "Expected \"%s\" or \"%s\" got \"%s\".\n", - paramstr, formatstr, checkstr1, checkstr2, buf); - } - - if ((fclose( fp )) != 0) - - { - - Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); - - } -} - - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoTest("%p", NULL, "NULL", "0000000000000000", "0x0"); - DoTest("%p", ptr, "pointer to 0x123456", "0000000000123456", "0x123456"); - DoTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456", " 0x123456"); - DoTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456", "0x0123456"); - DoTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 ", "0x123456 "); - DoTest("%+p", ptr, "pointer to 0x123456", "0000000000123456", "0x123456"); - DoTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456", "0x123456"); - DoTest("%lp", ptr, "pointer to 0x123456", "00123456", "0x123456"); - DoTest("%hp", ptr, "pointer to 0x123456", "00003456", "0x3456"); - DoTest("%Lp", ptr, "pointer to 0x123456", "00123456", "0x123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321", "0x1234567887654321"); -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoTest("%p", NULL, "NULL", "00000000", "0x0"); - DoTest("%p", ptr, "pointer to 0x123456", "00123456", "0x123456"); - DoTest("%9p", ptr, "pointer to 0x123456", " 00123456", " 0x123456"); - DoTest("%09p", ptr, "pointer to 0x123456", " 00123456", "0x0123456"); - DoTest("%-9p", ptr, "pointer to 0x123456", "00123456 ", "0x123456 "); - DoTest("%+p", ptr, "pointer to 0x123456", "00123456", "0x123456"); - DoTest("%#p", ptr, "pointer to 0x123456", "0X00123456", "0x123456"); - DoTest("%lp", ptr, "pointer to 0x123456", "00123456", "0x123456"); - DoTest("%hp", ptr, "pointer to 0x123456", "00003456", "0x3456"); - DoTest("%Lp", ptr, "pointer to 0x123456", "00123456", "0x123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321", "0x1234567887654321"); -#endif - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.cpp new file mode 100644 index 0000000000..51ec1f099c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.cpp @@ -0,0 +1,110 @@ +// 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: test4.c (fprintf) +** +** Purpose: Tests the pointer specifier (%p). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +static void DoTest(char *formatstr, void* param, char* paramstr, + char *checkstr1, char *checkstr2) +{ + FILE *fp; + char buf[256] = { 0 }; + + if ((fp = fopen("testfile.txt", "w+")) == NULL ) + { + Fail("ERROR: fopen failed to create testfile\n"); + } + + if ((fprintf(fp, formatstr, param)) < 0) + { + Fail("ERROR: fprintf failed\n"); + } + + if ((fseek(fp, 0, SEEK_SET)) != 0) + { + Fail("ERROR: fseek failed\n"); + } + + if ((fgets(buf, 100, fp)) == NULL) + { + Fail("ERROR: fseek failed\n"); + } + + if (memcmp(buf, checkstr1, strlen(buf) + 1) != 0 && + memcmp(buf, checkstr2, strlen(buf) + 1) != 0 ) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\" or \"%s\" got \"%s\".\n", + paramstr, formatstr, checkstr1, checkstr2, buf); + } + + if ((fclose( fp )) != 0) + + { + + Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); + + } +} + + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoTest("%p", NULL, "NULL", "0000000000000000", "0x0"); + DoTest("%p", ptr, "pointer to 0x123456", "0000000000123456", "0x123456"); + DoTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456", " 0x123456"); + DoTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456", "0x0123456"); + DoTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 ", "0x123456 "); + DoTest("%+p", ptr, "pointer to 0x123456", "0000000000123456", "0x123456"); + DoTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456", "0x123456"); + DoTest("%lp", ptr, "pointer to 0x123456", "00123456", "0x123456"); + DoTest("%hp", ptr, "pointer to 0x123456", "00003456", "0x3456"); + DoTest("%Lp", ptr, "pointer to 0x123456", "00123456", "0x123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321", "0x1234567887654321"); +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoTest("%p", NULL, "NULL", "00000000", "0x0"); + DoTest("%p", ptr, "pointer to 0x123456", "00123456", "0x123456"); + DoTest("%9p", ptr, "pointer to 0x123456", " 00123456", " 0x123456"); + DoTest("%09p", ptr, "pointer to 0x123456", " 00123456", "0x0123456"); + DoTest("%-9p", ptr, "pointer to 0x123456", "00123456 ", "0x123456 "); + DoTest("%+p", ptr, "pointer to 0x123456", "00123456", "0x123456"); + DoTest("%#p", ptr, "pointer to 0x123456", "0X00123456", "0x123456"); + DoTest("%lp", ptr, "pointer to 0x123456", "00123456", "0x123456"); + DoTest("%hp", ptr, "pointer to 0x123456", "00003456", "0x3456"); + DoTest("%Lp", ptr, "pointer to 0x123456", "00123456", "0x123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321", "0x1234567887654321"); +#endif + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test5/CMakeLists.txt index 1e3a568513..370ed3329a 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_fprintf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/fprintf/test5/test5.c deleted file mode 100644 index c53e3f45b4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test5/test5.c +++ /dev/null @@ -1,131 +0,0 @@ -// 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: test5.c (fprintf) -** -** Purpose: Tests the count specifier (%n). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -static void DoTest(char *formatstr, int param, char *checkstr) -{ - FILE *fp; - char buf[256] = { 0 }; - int n = -1; - - if ((fp = fopen("testfile.txt", "w+")) == NULL ) - { - Fail("ERROR: fopen failed to create testfile\n"); - } - - if ((fprintf(fp, formatstr, &n)) < 0) - { - Fail("ERROR: fprintf failed\n"); - } - - if ((fseek(fp, 0, SEEK_SET)) != 0) - { - Fail("ERROR: fseek failed\n"); - } - - if ((fgets(buf, 100, fp)) == NULL) - { - Fail("ERROR: fseek failed\n"); - } - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - param, n); - } - - if (memcmp(buf, checkstr, strlen(buf) + 1) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); - } - - - if ((fclose( fp )) != 0) - - { - - Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); - - } -} - -static void DoShortTest(char *formatstr, int param, char *checkstr) -{ - FILE *fp; - char buf[256] = { 0 }; - short int n = -1; - - if ((fp = fopen("testfile.txt", "w+")) == NULL ) - { - Fail("ERROR: fopen failed to create testfile\n"); - } - - if ((fprintf(fp, formatstr, &n)) < 0) - { - Fail("ERROR: fprintf failed\n"); - } - - if ((fseek(fp, 0, SEEK_SET)) != 0) - { - Fail("ERROR: fseek failed\n"); - } - - if ((fgets(buf, 100, fp)) == NULL) - { - Fail("ERROR: fseek failed\n"); - } - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - param, n); - } - - if (memcmp(buf, checkstr, strlen(buf) + 1) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); - } - - if ((fclose( fp )) != 0) - { - Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); - } -} - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoTest("foo %n bar", 4, "foo bar"); - DoTest("foo %#n bar", 4, "foo bar"); - DoTest("foo % n bar", 4, "foo bar"); - DoTest("foo %+n bar", 4, "foo bar"); - DoTest("foo %-n bar", 4, "foo bar"); - DoTest("foo %0n bar", 4, "foo bar"); - DoShortTest("foo %hn bar", 4, "foo bar"); - DoTest("foo %ln bar", 4, "foo bar"); - DoTest("foo %Ln bar", 4, "foo bar"); - DoTest("foo %I64n bar", 4, "foo bar"); - DoTest("foo %20.3n bar", 4, "foo bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test5/test5.cpp new file mode 100644 index 0000000000..c53e3f45b4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test5/test5.cpp @@ -0,0 +1,131 @@ +// 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: test5.c (fprintf) +** +** Purpose: Tests the count specifier (%n). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +static void DoTest(char *formatstr, int param, char *checkstr) +{ + FILE *fp; + char buf[256] = { 0 }; + int n = -1; + + if ((fp = fopen("testfile.txt", "w+")) == NULL ) + { + Fail("ERROR: fopen failed to create testfile\n"); + } + + if ((fprintf(fp, formatstr, &n)) < 0) + { + Fail("ERROR: fprintf failed\n"); + } + + if ((fseek(fp, 0, SEEK_SET)) != 0) + { + Fail("ERROR: fseek failed\n"); + } + + if ((fgets(buf, 100, fp)) == NULL) + { + Fail("ERROR: fseek failed\n"); + } + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + param, n); + } + + if (memcmp(buf, checkstr, strlen(buf) + 1) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); + } + + + if ((fclose( fp )) != 0) + + { + + Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); + + } +} + +static void DoShortTest(char *formatstr, int param, char *checkstr) +{ + FILE *fp; + char buf[256] = { 0 }; + short int n = -1; + + if ((fp = fopen("testfile.txt", "w+")) == NULL ) + { + Fail("ERROR: fopen failed to create testfile\n"); + } + + if ((fprintf(fp, formatstr, &n)) < 0) + { + Fail("ERROR: fprintf failed\n"); + } + + if ((fseek(fp, 0, SEEK_SET)) != 0) + { + Fail("ERROR: fseek failed\n"); + } + + if ((fgets(buf, 100, fp)) == NULL) + { + Fail("ERROR: fseek failed\n"); + } + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + param, n); + } + + if (memcmp(buf, checkstr, strlen(buf) + 1) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); + } + + if ((fclose( fp )) != 0) + { + Fail("ERROR: fclose failed to close \"testfile.txt\"\n"); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoTest("foo %n bar", 4, "foo bar"); + DoTest("foo %#n bar", 4, "foo bar"); + DoTest("foo % n bar", 4, "foo bar"); + DoTest("foo %+n bar", 4, "foo bar"); + DoTest("foo %-n bar", 4, "foo bar"); + DoTest("foo %0n bar", 4, "foo bar"); + DoShortTest("foo %hn bar", 4, "foo bar"); + DoTest("foo %ln bar", 4, "foo bar"); + DoTest("foo %Ln bar", 4, "foo bar"); + DoTest("foo %I64n bar", 4, "foo bar"); + DoTest("foo %20.3n bar", 4, "foo bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test6/CMakeLists.txt index 89620dd453..bd1cbda924 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_fprintf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/fprintf/test6/test6.c deleted file mode 100644 index 0a8bc6b103..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test6/test6.c +++ /dev/null @@ -1,46 +0,0 @@ -// 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: test6.c (fprintf) -** -** Purpose: Tests the char specifier (%c). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoCharTest("foo %c", 'b', "foo b"); - DoCharTest("foo %hc", 'b', "foo b"); - DoWCharTest("foo %lc", wc, "foo c"); - DoCharTest("foo %Lc", 'b', "foo b"); - DoCharTest("foo %I64c", 'b', "foo b"); - DoCharTest("foo %5c", 'b', "foo b"); - DoCharTest("foo %.0c", 'b', "foo b"); - DoCharTest("foo %-5c", 'b', "foo b "); - DoCharTest("foo %05c", 'b', "foo 0000b"); - DoCharTest("foo % c", 'b', "foo b"); - DoCharTest("foo %#c", 'b', "foo b"); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test6/test6.cpp new file mode 100644 index 0000000000..0a8bc6b103 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test6/test6.cpp @@ -0,0 +1,46 @@ +// 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: test6.c (fprintf) +** +** Purpose: Tests the char specifier (%c). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoCharTest("foo %c", 'b', "foo b"); + DoCharTest("foo %hc", 'b', "foo b"); + DoWCharTest("foo %lc", wc, "foo c"); + DoCharTest("foo %Lc", 'b', "foo b"); + DoCharTest("foo %I64c", 'b', "foo b"); + DoCharTest("foo %5c", 'b', "foo b"); + DoCharTest("foo %.0c", 'b', "foo b"); + DoCharTest("foo %-5c", 'b', "foo b "); + DoCharTest("foo %05c", 'b', "foo 0000b"); + DoCharTest("foo % c", 'b', "foo b"); + DoCharTest("foo %#c", 'b', "foo b"); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test7/CMakeLists.txt index 3dc10dd6dc..38429e7900 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_fprintf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/fprintf/test7/test7.c deleted file mode 100644 index 088e328de5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test7/test7.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test7.c (fprintf) -** -** Purpose: Tests the wide char specifier (%C). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoWCharTest("foo %C", wb, "foo b"); - DoWCharTest("foo %hC", wb, "foo b"); - DoCharTest("foo %lC", 'c', "foo c"); - DoWCharTest("foo %LC", wb, "foo b"); - DoWCharTest("foo %I64C", wb, "foo b"); - DoWCharTest("foo %5C", wb, "foo b"); - DoWCharTest("foo %.0C", wb, "foo b"); - DoWCharTest("foo %-5C", wb, "foo b "); - DoWCharTest("foo %05C", wb, "foo 0000b"); - DoWCharTest("foo % C", wb, "foo b"); - DoWCharTest("foo %#C", wb, "foo b"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test7/test7.cpp new file mode 100644 index 0000000000..088e328de5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test7/test7.cpp @@ -0,0 +1,44 @@ +// 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: test7.c (fprintf) +** +** Purpose: Tests the wide char specifier (%C). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoWCharTest("foo %C", wb, "foo b"); + DoWCharTest("foo %hC", wb, "foo b"); + DoCharTest("foo %lC", 'c', "foo c"); + DoWCharTest("foo %LC", wb, "foo b"); + DoWCharTest("foo %I64C", wb, "foo b"); + DoWCharTest("foo %5C", wb, "foo b"); + DoWCharTest("foo %.0C", wb, "foo b"); + DoWCharTest("foo %-5C", wb, "foo b "); + DoWCharTest("foo %05C", wb, "foo 0000b"); + DoWCharTest("foo % C", wb, "foo b"); + DoWCharTest("foo %#C", wb, "foo b"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test8/CMakeLists.txt index f6dd984af9..990eca26b0 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_fprintf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/fprintf/test8/test8.c deleted file mode 100644 index c781abc968..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test8/test8.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test8.c (fprintf) -** -** Purpose: Tests the decimal specifier (%d). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest("foo %d", pos, "foo 42"); - DoNumTest("foo %ld", 0xFFFF, "foo 65535"); - DoNumTest("foo %hd", 0xFFFF, "foo -1"); - DoNumTest("foo %Ld", pos, "foo 42"); - DoI64Test("foo %I64d", l, "42", "foo 42", "foo 42"); - DoNumTest("foo %3d", pos, "foo 42"); - DoNumTest("foo %-3d", pos, "foo 42 "); - DoNumTest("foo %.1d", pos, "foo 42"); - DoNumTest("foo %.3d", pos, "foo 042"); - DoNumTest("foo %03d", pos, "foo 042"); - DoNumTest("foo %#d", pos, "foo 42"); - DoNumTest("foo %+d", pos, "foo +42"); - DoNumTest("foo % d", pos, "foo 42"); - DoNumTest("foo %+d", neg, "foo -42"); - DoNumTest("foo % d", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test8/test8.cpp new file mode 100644 index 0000000000..c781abc968 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test8/test8.cpp @@ -0,0 +1,49 @@ +// 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: test8.c (fprintf) +** +** Purpose: Tests the decimal specifier (%d). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest("foo %d", pos, "foo 42"); + DoNumTest("foo %ld", 0xFFFF, "foo 65535"); + DoNumTest("foo %hd", 0xFFFF, "foo -1"); + DoNumTest("foo %Ld", pos, "foo 42"); + DoI64Test("foo %I64d", l, "42", "foo 42", "foo 42"); + DoNumTest("foo %3d", pos, "foo 42"); + DoNumTest("foo %-3d", pos, "foo 42 "); + DoNumTest("foo %.1d", pos, "foo 42"); + DoNumTest("foo %.3d", pos, "foo 042"); + DoNumTest("foo %03d", pos, "foo 042"); + DoNumTest("foo %#d", pos, "foo 42"); + DoNumTest("foo %+d", pos, "foo +42"); + DoNumTest("foo % d", pos, "foo 42"); + DoNumTest("foo %+d", neg, "foo -42"); + DoNumTest("foo % d", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fprintf/test9/CMakeLists.txt index 62aa85e6ff..715d38a431 100644 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_fprintf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/fprintf/test9/test9.c deleted file mode 100644 index 3b06daec48..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fprintf/test9/test9.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test9.c (fprintf) -** -** Purpose: Tests the integer specifier (%i). -** This test is modeled after the fprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest("foo %i", pos, "foo 42"); - DoNumTest("foo %li", 0xFFFF, "foo 65535"); - DoNumTest("foo %hi", 0xFFFF, "foo -1"); - DoNumTest("foo %Li", pos, "foo 42"); - DoI64Test("foo %I64i", l, "42", "foo 42", "foo 42"); - DoNumTest("foo %3i", pos, "foo 42"); - DoNumTest("foo %-3i", pos, "foo 42 "); - DoNumTest("foo %.1i", pos, "foo 42"); - DoNumTest("foo %.3i", pos, "foo 042"); - DoNumTest("foo %03i", pos, "foo 042"); - DoNumTest("foo %#i", pos, "foo 42"); - DoNumTest("foo %+i", pos, "foo +42"); - DoNumTest("foo % i", pos, "foo 42"); - DoNumTest("foo %+i", neg, "foo -42"); - DoNumTest("foo % i", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/fprintf/test9/test9.cpp new file mode 100644 index 0000000000..3b06daec48 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fprintf/test9/test9.cpp @@ -0,0 +1,49 @@ +// 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: test9.c (fprintf) +** +** Purpose: Tests the integer specifier (%i). +** This test is modeled after the fprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest("foo %i", pos, "foo 42"); + DoNumTest("foo %li", 0xFFFF, "foo 65535"); + DoNumTest("foo %hi", 0xFFFF, "foo -1"); + DoNumTest("foo %Li", pos, "foo 42"); + DoI64Test("foo %I64i", l, "42", "foo 42", "foo 42"); + DoNumTest("foo %3i", pos, "foo 42"); + DoNumTest("foo %-3i", pos, "foo 42 "); + DoNumTest("foo %.1i", pos, "foo 42"); + DoNumTest("foo %.3i", pos, "foo 042"); + DoNumTest("foo %03i", pos, "foo 042"); + DoNumTest("foo %#i", pos, "foo 42"); + DoNumTest("foo %+i", pos, "foo +42"); + DoNumTest("foo % i", pos, "foo 42"); + DoNumTest("foo %+i", neg, "foo -42"); + DoNumTest("foo % i", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fputs/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fputs/test1/CMakeLists.txt index e4a92d5966..d0f1aca0e6 100644 --- a/src/pal/tests/palsuite/c_runtime/fputs/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fputs/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fputs_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fputs/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fputs/test1/test1.c deleted file mode 100644 index b90ea082e9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fputs/test1/test1.c +++ /dev/null @@ -1,100 +0,0 @@ -// 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: test1.c -** -** Purpose: Call fputs twice and write two strings to a file. Then -** call fread on the file and check that the data which was written is what -** we expect it to be. -** - -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char **argv) -{ - - FILE* TheFile; - char* StringOne = "FooBar"; - char* StringTwo = "BarFoo"; - char* CompleteString = "FooBarBarFoo"; - char ReadBuffer[64]; - int ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open the file that we'll be working with */ - - TheFile = fopen("TestFile", "w+"); - - if(TheFile == NULL) - { - Fail("ERROR: fopen failed to open the file 'TestFile' in read/write " - "mode.\n"); - } - - /* Call fputs twice to write two strings to the file stream */ - - if(fputs(StringOne, TheFile) < 0) - { - Fail("ERROR: fputs returned a negative value when attempting to " - "put the string '%s' to the file.\n",StringOne); - } - - if(fputs(StringTwo, TheFile) < 0) - { - Fail("ERROR: fputs returned a negative value when attempting to " - "put the string '%s' to the file.\n",StringTwo); - } - - /* Flush the buffers */ - if(fflush(TheFile) != 0) - { - Fail("ERROR: fflush failed to properly flush the buffers.\n"); - } - - /* Now read from the file to ensure the data was written correctly. - Note: We read more than what was written to make sure nothing extra - was written. - */ - - if(fseek(TheFile, 0, SEEK_SET) != 0) - { - Fail("ERROR: fseek failed to set the file pointer back to the start " - "of the file.\n"); - } - - - if((ret = fread(ReadBuffer, 1, 20, TheFile)) != 12) - { - Fail("ERROR: fread should have returned that it read in 12 characters " - "from the file, but instead it returned %d.\n", ret); - } - - ReadBuffer[ret] = '\0'; - - if(strcmp(ReadBuffer, CompleteString) != 0) - { - Fail("ERROR: The data read back from the file is not exactly the same " - "as the data that was written by fputs. The file contains '%s' " - "instead of '%s'.\n",ReadBuffer, CompleteString); - } - - if(fclose(TheFile) != 0) - { - Fail("ERROR: fclose failed to close the file stream.\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fputs/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fputs/test1/test1.cpp new file mode 100644 index 0000000000..b90ea082e9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fputs/test1/test1.cpp @@ -0,0 +1,100 @@ +// 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: test1.c +** +** Purpose: Call fputs twice and write two strings to a file. Then +** call fread on the file and check that the data which was written is what +** we expect it to be. +** + +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char **argv) +{ + + FILE* TheFile; + char* StringOne = "FooBar"; + char* StringTwo = "BarFoo"; + char* CompleteString = "FooBarBarFoo"; + char ReadBuffer[64]; + int ret; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Open the file that we'll be working with */ + + TheFile = fopen("TestFile", "w+"); + + if(TheFile == NULL) + { + Fail("ERROR: fopen failed to open the file 'TestFile' in read/write " + "mode.\n"); + } + + /* Call fputs twice to write two strings to the file stream */ + + if(fputs(StringOne, TheFile) < 0) + { + Fail("ERROR: fputs returned a negative value when attempting to " + "put the string '%s' to the file.\n",StringOne); + } + + if(fputs(StringTwo, TheFile) < 0) + { + Fail("ERROR: fputs returned a negative value when attempting to " + "put the string '%s' to the file.\n",StringTwo); + } + + /* Flush the buffers */ + if(fflush(TheFile) != 0) + { + Fail("ERROR: fflush failed to properly flush the buffers.\n"); + } + + /* Now read from the file to ensure the data was written correctly. + Note: We read more than what was written to make sure nothing extra + was written. + */ + + if(fseek(TheFile, 0, SEEK_SET) != 0) + { + Fail("ERROR: fseek failed to set the file pointer back to the start " + "of the file.\n"); + } + + + if((ret = fread(ReadBuffer, 1, 20, TheFile)) != 12) + { + Fail("ERROR: fread should have returned that it read in 12 characters " + "from the file, but instead it returned %d.\n", ret); + } + + ReadBuffer[ret] = '\0'; + + if(strcmp(ReadBuffer, CompleteString) != 0) + { + Fail("ERROR: The data read back from the file is not exactly the same " + "as the data that was written by fputs. The file contains '%s' " + "instead of '%s'.\n",ReadBuffer, CompleteString); + } + + if(fclose(TheFile) != 0) + { + Fail("ERROR: fclose failed to close the file stream.\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fputs/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fputs/test2/CMakeLists.txt index 6e939f3346..9242ea16e5 100644 --- a/src/pal/tests/palsuite/c_runtime/fputs/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fputs/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_fputs_test2 diff --git a/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.c b/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.c deleted file mode 100644 index b8e2f410bb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.c +++ /dev/null @@ -1,88 +0,0 @@ -// 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: test2.c -** -** Purpose: Check to see that fputs fails and returns EOF when called on -** a closed file stream and a read-only file stream. -** - -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - FILE* TheFile; - char* StringOne = "FooBar"; - int ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file with read/write access */ - - TheFile = fopen("TestFile", "w+"); - - if(TheFile == NULL) - { - Fail("ERROR: fopen failed to open the file 'TestFile' in read/write " - "mode.\n"); - } - - /* Then close that file we just opened */ - - if(fclose(TheFile) != 0) - { - Fail("ERROR: fclose failed to close the file.\n"); - } - - /* Check that calling fputs on this closed file stream fails. */ - - if((ret = fputs(StringOne, TheFile)) >= 0) - { - Fail("ERROR: fputs should have failed to write to a closed " - "file stream, but it didn't return a negative value.\n"); - } - - if(ret != EOF) - { - Fail("ERROR: fputs should have returned EOF on an error, but instead " - "returned %d.\n",ret); - } - - /* Open a file as Readonly */ - - TheFile = fopen("TestFile", "r"); - - if(TheFile == NULL) - { - Fail("ERROR: fopen failed to open the file 'TestFile' in read/write " - "mode.\n"); - } - - /* Check that fputs fails when trying to write to a read-only stream */ - - if((ret = fputs(StringOne, TheFile)) >= 0) - { - Fail("ERROR: fputs should have failed to write to a read-only " - "file stream, but it didn't return a negative value.\n"); - } - - if(ret != EOF) - { - Fail("ERROR: fputs should have returned EOF when writing to a " - "read-only filestream, but instead " - "returned %d.\n",ret); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp new file mode 100644 index 0000000000..b8e2f410bb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp @@ -0,0 +1,88 @@ +// 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: test2.c +** +** Purpose: Check to see that fputs fails and returns EOF when called on +** a closed file stream and a read-only file stream. +** + +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + FILE* TheFile; + char* StringOne = "FooBar"; + int ret; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file with read/write access */ + + TheFile = fopen("TestFile", "w+"); + + if(TheFile == NULL) + { + Fail("ERROR: fopen failed to open the file 'TestFile' in read/write " + "mode.\n"); + } + + /* Then close that file we just opened */ + + if(fclose(TheFile) != 0) + { + Fail("ERROR: fclose failed to close the file.\n"); + } + + /* Check that calling fputs on this closed file stream fails. */ + + if((ret = fputs(StringOne, TheFile)) >= 0) + { + Fail("ERROR: fputs should have failed to write to a closed " + "file stream, but it didn't return a negative value.\n"); + } + + if(ret != EOF) + { + Fail("ERROR: fputs should have returned EOF on an error, but instead " + "returned %d.\n",ret); + } + + /* Open a file as Readonly */ + + TheFile = fopen("TestFile", "r"); + + if(TheFile == NULL) + { + Fail("ERROR: fopen failed to open the file 'TestFile' in read/write " + "mode.\n"); + } + + /* Check that fputs fails when trying to write to a read-only stream */ + + if((ret = fputs(StringOne, TheFile)) >= 0) + { + Fail("ERROR: fputs should have failed to write to a read-only " + "file stream, but it didn't return a negative value.\n"); + } + + if(ret != EOF) + { + Fail("ERROR: fputs should have returned EOF when writing to a " + "read-only filestream, but instead " + "returned %d.\n",ret); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fread/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fread/test1/CMakeLists.txt index a2e09579b1..1bd84b5c62 100644 --- a/src/pal/tests/palsuite/c_runtime/fread/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fread/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fread_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fread/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fread/test1/test1.c deleted file mode 100644 index b706b2e91c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fread/test1/test1.c +++ /dev/null @@ -1,135 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the fread function. -** Open a file in READ mode, and then try to read all -** the characters, more than all the characters, -** 0 characters and 0 sized characters and check that -** the return values are correct. -** -** Depends: -** fopen -** fseek -** fclose -** -** -**===================================================================*/ - -/* Note: testfile should exist in the directory with 15 characters - in it ... something got lost if it isn't here. -*/ - -/* Note: Under win32, fread() crashes when passed NULL. The test to ensure that - it returns 0 has been removed to reflect this. -*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - const char filename[] = "testfile"; - char buffer[128]; - FILE * fp = NULL; - int result; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open a file in READ mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading. Is the file " - "in the directory? It should be."); - } - - /* Read 15 characters from the file. The file has exactly this many - in it. - */ - if((result = fread(buffer,1,15,fp)) == 0) - { - Fail("ERROR: Zero characters read from the file. It should have " - "15 characters in it."); - } - - if(result != 15) - { - Fail("ERROR: The fread function should have returned that it read " - "in 15 characters from the file. But it indicates having " - "read %i characters.",result); - } - - /* Go back to the start of the file */ - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read 17 characters, the return should still be 15 */ - - if((result = fread(buffer,1,17,fp)) == 0) - { - Fail("ERROR: Zero characters read from the file. It should have " - "15 characters in it. Though, it attempted to read 17."); - } - - if(result != 15) - { - Fail("ERROR: The fread function should have returned that it read " - "in 15 characters from the file. " - "But it indicates having read %i characters.",result); - } - - /* Back to the start of the file */ - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Read 0 characters and ensure the function returns 0 */ - - if((result = fread(buffer,1,0,fp)) != 0) - { - Fail("ERROR: The return value should be 0, as we attempted to " - "read 0 characters."); - } - - /* Read characters of 0 size and ensure the return value is 0 */ - - if((result = fread(buffer,0,5,fp)) != 0) - { - Fail("ERROR: The return value should be 0, as we attempted to " - "read 0 sized data."); - } - - /* Close the file */ - - if(fclose(fp)) - { - Fail("ERROR: fclose failed. Test depends on it."); - } - - /* Read 5 characters of 1 size from a closed file pointer - and ensure the return value is 0 - */ - - if((result = fread(buffer,1,5,fp)) != 0) - { - Fail("ERROR: The return value should be 0, as we attempted to " - "read data from a closed file pointer."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fread/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fread/test1/test1.cpp new file mode 100644 index 0000000000..b706b2e91c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fread/test1/test1.cpp @@ -0,0 +1,135 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the fread function. +** Open a file in READ mode, and then try to read all +** the characters, more than all the characters, +** 0 characters and 0 sized characters and check that +** the return values are correct. +** +** Depends: +** fopen +** fseek +** fclose +** +** +**===================================================================*/ + +/* Note: testfile should exist in the directory with 15 characters + in it ... something got lost if it isn't here. +*/ + +/* Note: Under win32, fread() crashes when passed NULL. The test to ensure that + it returns 0 has been removed to reflect this. +*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + const char filename[] = "testfile"; + char buffer[128]; + FILE * fp = NULL; + int result; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Open a file in READ mode */ + + if((fp = fopen(filename, "r")) == NULL) + { + Fail("Unable to open a file for reading. Is the file " + "in the directory? It should be."); + } + + /* Read 15 characters from the file. The file has exactly this many + in it. + */ + if((result = fread(buffer,1,15,fp)) == 0) + { + Fail("ERROR: Zero characters read from the file. It should have " + "15 characters in it."); + } + + if(result != 15) + { + Fail("ERROR: The fread function should have returned that it read " + "in 15 characters from the file. But it indicates having " + "read %i characters.",result); + } + + /* Go back to the start of the file */ + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read 17 characters, the return should still be 15 */ + + if((result = fread(buffer,1,17,fp)) == 0) + { + Fail("ERROR: Zero characters read from the file. It should have " + "15 characters in it. Though, it attempted to read 17."); + } + + if(result != 15) + { + Fail("ERROR: The fread function should have returned that it read " + "in 15 characters from the file. " + "But it indicates having read %i characters.",result); + } + + /* Back to the start of the file */ + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Read 0 characters and ensure the function returns 0 */ + + if((result = fread(buffer,1,0,fp)) != 0) + { + Fail("ERROR: The return value should be 0, as we attempted to " + "read 0 characters."); + } + + /* Read characters of 0 size and ensure the return value is 0 */ + + if((result = fread(buffer,0,5,fp)) != 0) + { + Fail("ERROR: The return value should be 0, as we attempted to " + "read 0 sized data."); + } + + /* Close the file */ + + if(fclose(fp)) + { + Fail("ERROR: fclose failed. Test depends on it."); + } + + /* Read 5 characters of 1 size from a closed file pointer + and ensure the return value is 0 + */ + + if((result = fread(buffer,1,5,fp)) != 0) + { + Fail("ERROR: The return value should be 0, as we attempted to " + "read data from a closed file pointer."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fread/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fread/test2/CMakeLists.txt index 0538e0c3af..93e0394832 100644 --- a/src/pal/tests/palsuite/c_runtime/fread/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fread/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_fread_test2 diff --git a/src/pal/tests/palsuite/c_runtime/fread/test2/test2.c b/src/pal/tests/palsuite/c_runtime/fread/test2/test2.c deleted file mode 100644 index d7262a9321..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fread/test2/test2.c +++ /dev/null @@ -1,143 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests the PAL implementation of the fread function. -** Open a file in READ mode, and then try to read all -** the characters, more than all the characters, -** 0 characters and 0 sized characters and check that -** the strings read in are correct. -** -** Depends: -** fopen -** fseek -** fclose -** strcmp -** memset -** -** -**===================================================================*/ - -/* Note: testfile should exist in the directory with 15 characters - in it ... something got lost if it isn't here. -*/ - -/* Note: The behaviour in win32 is to crash if a NULL pointer is passed to - fread, so the test to check that it returns 0 has been removed. -*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - const char filename[] = "testfile"; - char buffer[128]; - FILE * fp = NULL; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open a file in READ mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading. Is the file " - "in the directory? It should be."); - } - - /* Read 15 characters from the file. The file has exactly this many - in it. Then check to see that the data read in is correct. - Note: The 'testfile' should have "This is a test." written in it. - */ - memset(buffer,'\0',128); - fread(buffer,1,15,fp); - - if(strcmp(buffer,"This is a test.") != 0) - { - Fail("ERROR: The data read in should have been " - "'This is a test.' but, the buffer contains '%s'.", - buffer); - } - - /* Go back to the start of the file */ - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read 17 characters. The same 15 characters should - be in the buffer. - */ - - memset(buffer,'\0',128); - fread(buffer,1,17,fp); - - if(strcmp(buffer,"This is a test.") != 0) - { - Fail("ERROR: The data read in should have been " - "'This is a test.' but, the buffer contains '%s'.", - buffer); - } - - /* Back to the start of the file */ - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Read 0 characters and ensure the buffer is empty */ - - memset(buffer,'\0',128); - fread(buffer,1,0,fp); - - if(strcmp(buffer,"\0") != 0) - { - Fail("ERROR: The data read in should have been " - "NULL but, the buffer contains '%s'.", - buffer); - } - - /* Read characters of 0 size and ensure the buffer is empty */ - - memset(buffer,'\0',128); - fread(buffer,0,5,fp); - - if(strcmp(buffer,"\0") != 0) - { - Fail("ERROR: The data read in should have been " - "NULL but, the buffer contains '%s'.", - buffer); - } - - /* Close the file */ - - if(fclose(fp)) - { - Fail("ERROR: fclose failed. Test depends on it."); - } - - /* Read 5 characters of 1 size from a closed file pointer - and ensure the buffer is empty - */ - memset(buffer,'\0',128); - fread(buffer,1,5,fp); - if(strcmp(buffer,"\0") != 0) - { - Fail("ERROR: The data read in should have been " - "NULL but, the buffer contains '%s'.", - buffer); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fread/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/fread/test2/test2.cpp new file mode 100644 index 0000000000..d7262a9321 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fread/test2/test2.cpp @@ -0,0 +1,143 @@ +// 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: test2.c +** +** Purpose: Tests the PAL implementation of the fread function. +** Open a file in READ mode, and then try to read all +** the characters, more than all the characters, +** 0 characters and 0 sized characters and check that +** the strings read in are correct. +** +** Depends: +** fopen +** fseek +** fclose +** strcmp +** memset +** +** +**===================================================================*/ + +/* Note: testfile should exist in the directory with 15 characters + in it ... something got lost if it isn't here. +*/ + +/* Note: The behaviour in win32 is to crash if a NULL pointer is passed to + fread, so the test to check that it returns 0 has been removed. +*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + const char filename[] = "testfile"; + char buffer[128]; + FILE * fp = NULL; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Open a file in READ mode */ + + if((fp = fopen(filename, "r")) == NULL) + { + Fail("Unable to open a file for reading. Is the file " + "in the directory? It should be."); + } + + /* Read 15 characters from the file. The file has exactly this many + in it. Then check to see that the data read in is correct. + Note: The 'testfile' should have "This is a test." written in it. + */ + memset(buffer,'\0',128); + fread(buffer,1,15,fp); + + if(strcmp(buffer,"This is a test.") != 0) + { + Fail("ERROR: The data read in should have been " + "'This is a test.' but, the buffer contains '%s'.", + buffer); + } + + /* Go back to the start of the file */ + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read 17 characters. The same 15 characters should + be in the buffer. + */ + + memset(buffer,'\0',128); + fread(buffer,1,17,fp); + + if(strcmp(buffer,"This is a test.") != 0) + { + Fail("ERROR: The data read in should have been " + "'This is a test.' but, the buffer contains '%s'.", + buffer); + } + + /* Back to the start of the file */ + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Read 0 characters and ensure the buffer is empty */ + + memset(buffer,'\0',128); + fread(buffer,1,0,fp); + + if(strcmp(buffer,"\0") != 0) + { + Fail("ERROR: The data read in should have been " + "NULL but, the buffer contains '%s'.", + buffer); + } + + /* Read characters of 0 size and ensure the buffer is empty */ + + memset(buffer,'\0',128); + fread(buffer,0,5,fp); + + if(strcmp(buffer,"\0") != 0) + { + Fail("ERROR: The data read in should have been " + "NULL but, the buffer contains '%s'.", + buffer); + } + + /* Close the file */ + + if(fclose(fp)) + { + Fail("ERROR: fclose failed. Test depends on it."); + } + + /* Read 5 characters of 1 size from a closed file pointer + and ensure the buffer is empty + */ + memset(buffer,'\0',128); + fread(buffer,1,5,fp); + if(strcmp(buffer,"\0") != 0) + { + Fail("ERROR: The data read in should have been " + "NULL but, the buffer contains '%s'.", + buffer); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fread/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fread/test3/CMakeLists.txt index f3c636f3df..285608bc3d 100644 --- a/src/pal/tests/palsuite/c_runtime/fread/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fread/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_fread_test3 diff --git a/src/pal/tests/palsuite/c_runtime/fread/test3/test3.c b/src/pal/tests/palsuite/c_runtime/fread/test3/test3.c deleted file mode 100644 index 8c79bee582..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fread/test3/test3.c +++ /dev/null @@ -1,131 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests the PAL implementation of the fread function. -** Open a file in READ mode, then try to read from the file with -** different 'size' params. Check to ensure the return values and -** the text in the buffer is correct. -** -** Depends: -** fopen -** fseek -** strcmp -** memset -** -** -**===================================================================*/ - -/* Note: testfile should exist in the directory with 15 characters - in it ... something got lost if it isn't here. -*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - const char filename[] = "testfile"; - char buffer[128]; - FILE * fp = NULL; - int result; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open a file in READ mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading. Is the file " - "in the directory? It should be."); - } - - memset(buffer,'x',128); - - /* Put the null one character past the end of the text that was read - in, to ensure that it wasn't reading in 0 - */ - - buffer[16] = '\0'; - - /* Attempt to read in 5 bytes at a time. This should return 3 and - contain the full string in the buffer. - */ - - if((result = fread(buffer,5,3,fp)) != 3) - { - Fail("ERROR: Attempted to read in data of size 5. The file has " - "15 bytes in it so 3 items should have been read. But the value " - "returned was %d.",result); - } - - if(strcmp(buffer, "This is a test.x") != 0) - { - Fail("ERROR: The buffer should have contained the text " - "'This is a test.x' but instead contained '%s'.",buffer); - } - - memset(buffer,'x',128); - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - buffer[16] = '\0'; - - /* Attempt to read in 6 bytes at a time. The return should be 2. The - full string should still be in the buffer. - */ - - if((result = fread(buffer,6,3,fp)) != 2) - { - Fail("ERROR: Attempted to read in data of size 6. The file has " - "15 bytes in it, so 2 items should have been read. But the " - "value returned was %d.",result); - } - - if(strcmp(buffer, "This is a test.x") != 0) - { - Fail("ERROR: The buffer should have contained the text " - "'This is a test.x' but instead contained '%s'.",buffer); - } - - memset(buffer,'x',128); - - buffer[7] = '\0'; - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read in 6 bytes at a time but only one item max. - The return should be 1. The first 6 characters should be in the - buffer. - */ - - if((result = fread(buffer,6,1,fp)) != 1) - { - Fail("ERROR: Attempted to read in data of size 6 with a max count " - "of 1. Thus, one item should have been read, but the " - "value returned was %d.",result); - } - - if(strcmp(buffer, "This ix") != 0) - { - Fail("ERROR: The buffer should have contained the text " - "'This ix.' but instead contained '%s'.",buffer); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fread/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/fread/test3/test3.cpp new file mode 100644 index 0000000000..8c79bee582 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fread/test3/test3.cpp @@ -0,0 +1,131 @@ +// 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: test3.c +** +** Purpose: Tests the PAL implementation of the fread function. +** Open a file in READ mode, then try to read from the file with +** different 'size' params. Check to ensure the return values and +** the text in the buffer is correct. +** +** Depends: +** fopen +** fseek +** strcmp +** memset +** +** +**===================================================================*/ + +/* Note: testfile should exist in the directory with 15 characters + in it ... something got lost if it isn't here. +*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + const char filename[] = "testfile"; + char buffer[128]; + FILE * fp = NULL; + int result; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Open a file in READ mode */ + + if((fp = fopen(filename, "r")) == NULL) + { + Fail("Unable to open a file for reading. Is the file " + "in the directory? It should be."); + } + + memset(buffer,'x',128); + + /* Put the null one character past the end of the text that was read + in, to ensure that it wasn't reading in 0 + */ + + buffer[16] = '\0'; + + /* Attempt to read in 5 bytes at a time. This should return 3 and + contain the full string in the buffer. + */ + + if((result = fread(buffer,5,3,fp)) != 3) + { + Fail("ERROR: Attempted to read in data of size 5. The file has " + "15 bytes in it so 3 items should have been read. But the value " + "returned was %d.",result); + } + + if(strcmp(buffer, "This is a test.x") != 0) + { + Fail("ERROR: The buffer should have contained the text " + "'This is a test.x' but instead contained '%s'.",buffer); + } + + memset(buffer,'x',128); + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + buffer[16] = '\0'; + + /* Attempt to read in 6 bytes at a time. The return should be 2. The + full string should still be in the buffer. + */ + + if((result = fread(buffer,6,3,fp)) != 2) + { + Fail("ERROR: Attempted to read in data of size 6. The file has " + "15 bytes in it, so 2 items should have been read. But the " + "value returned was %d.",result); + } + + if(strcmp(buffer, "This is a test.x") != 0) + { + Fail("ERROR: The buffer should have contained the text " + "'This is a test.x' but instead contained '%s'.",buffer); + } + + memset(buffer,'x',128); + + buffer[7] = '\0'; + + if(fseek(fp, 0, SEEK_SET)) + { + Fail("ERROR: fseek failed, and this test depends on it."); + } + + /* Attempt to read in 6 bytes at a time but only one item max. + The return should be 1. The first 6 characters should be in the + buffer. + */ + + if((result = fread(buffer,6,1,fp)) != 1) + { + Fail("ERROR: Attempted to read in data of size 6 with a max count " + "of 1. Thus, one item should have been read, but the " + "value returned was %d.",result); + } + + if(strcmp(buffer, "This ix") != 0) + { + Fail("ERROR: The buffer should have contained the text " + "'This ix.' but instead contained '%s'.",buffer); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/free/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/free/test1/CMakeLists.txt index bd94cb5733..92ee9896c7 100644 --- a/src/pal/tests/palsuite/c_runtime/free/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/free/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_free_test1 diff --git a/src/pal/tests/palsuite/c_runtime/free/test1/test1.c b/src/pal/tests/palsuite/c_runtime/free/test1/test1.c deleted file mode 100644 index 4ff8dfb094..0000000000 --- a/src/pal/tests/palsuite/c_runtime/free/test1/test1.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: test1.c -** -** Purpose: Repeatedly allocates and frees a chunk of memory, to verify -** that free is really returning memory to the heap -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - char *testA; - - long i; - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* check that free really returns memory to the heap. */ - for(i=1; i<1000000; i++) - { - testA = (char *)malloc(1000*sizeof(char)); - if (testA==NULL) - { - Fail("Either free is failing to return memory to the heap, or" - " the system is running out of memory for some other " - "reason.\n"); - } - free(testA); - } - - free(NULL); /*should do nothing*/ - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/free/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/free/test1/test1.cpp new file mode 100644 index 0000000000..4ff8dfb094 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/free/test1/test1.cpp @@ -0,0 +1,62 @@ +// 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: test1.c +** +** Purpose: Repeatedly allocates and frees a chunk of memory, to verify +** that free is really returning memory to the heap +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + char *testA; + + long i; + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* check that free really returns memory to the heap. */ + for(i=1; i<1000000; i++) + { + testA = (char *)malloc(1000*sizeof(char)); + if (testA==NULL) + { + Fail("Either free is failing to return memory to the heap, or" + " the system is running out of memory for some other " + "reason.\n"); + } + free(testA); + } + + free(NULL); /*should do nothing*/ + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/fseek/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fseek/test1/CMakeLists.txt index fb55bd1051..59ee8b4563 100644 --- a/src/pal/tests/palsuite/c_runtime/fseek/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fseek/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fseek_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fseek/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fseek/test1/test1.c deleted file mode 100644 index 8496289a01..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fseek/test1/test1.c +++ /dev/null @@ -1,193 +0,0 @@ -// 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: test1.c -** -** Purpose: Call fseek to move a file pointer to the start of a file, -** a position offset from the start, a position offset from the -** current position, and a position offset from the end of the -** file. Check that the file pointer is at the correct position -** after each seek. -** -** -**==========================================================================*/ - -#include - -const char filename[] = "testfile.txt"; - -static BOOL Cleanup(HANDLE hFile) -{ - BOOL result= TRUE; - - if (fclose(hFile)) - { - Trace("fseek: ERROR -> Unable to close file \"%s\".\n", - filename); - result= FALSE; - } - if (!DeleteFileA(filename)) - { - result= FALSE; - Trace("fseek: ERROR -> Unable to delete file \"%s\". ", - "GetLastError returned %u.\n", - filename, - GetLastError()); - } - return result; -} - -int __cdecl main(int argc, char **argv) -{ - char outBuf[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char inBuf[20]; - FILE * fp; - int size = ( sizeof(outBuf)/sizeof(char) ) - 1; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /*create the file*/ - fp = fopen(filename, "w"); - if (fp == NULL) - { - Fail("Unable to open a file for write.\n"); - } - if(fprintf(fp, outBuf) != size) - { - Trace("Unable to write to %s.\n", filename); - Cleanup(fp); - Fail(""); - } - - if (fclose(fp) != 0) - { - Trace("Unable to close newly written file.\n"); - if (!DeleteFileA(filename)) - { - Trace("fseek: ERROR -> Unable to delete file \"%s\". ", - "GetLastError returned %u.\n", - filename, - GetLastError()); - } - Fail(""); - } - - fp = fopen(filename, "r"); - if (fp == NULL) - { - if (!DeleteFileA(filename)) - { - Trace("_putw: ERROR -> Unable to delete file \"%s\". ", - "GetLastError returned %u.\n", - filename, - GetLastError()); - } - Fail("Unable to open a file for read.\n"); - } - - /*seek to the start*/ - if (fseek(fp, 0, SEEK_SET) != 0) - { - Cleanup(fp); - Fail("fseek failed when seeking the start of a file.\n"); - } - if (fgets(inBuf, 11, fp) != inBuf) - { - Cleanup(fp); - Fail("Unable to read from file after using fseek to move to the start.\n"); - } - if (strncmp(inBuf, outBuf, 10) != 0) - { - Cleanup(fp); - Fail("fseek was asked to seek the start of a file," - "but didn't get there.\n"); - } - - /*Seek with an offset from the start*/ - - if (fseek(fp, 10, SEEK_SET) != 0) - { - Cleanup(fp); - Fail("fseek failed when called with SEEK_SET and a positive offset.\n"); - } - - if (fgets(inBuf, 6, fp) != inBuf) - { - Cleanup(fp); - Fail("fgets failed after feek was called with SEEK_SET" - "and a positive offset.\n"); - } - - - if (strncmp(inBuf, "ABCDE", 5) != 0) - { - Cleanup(fp); - Fail("fseek did not move to the correct position when passed SEEK_SET" - " and a positive offset.\n"); - } - - /*now move backwards and read the same string*/ - if (fseek(fp, -5, SEEK_CUR) != 0) - { - Cleanup(fp); - Fail("fseek failed when passed SEEK_CUR and a negative offset.\n"); - } - - if (fgets(inBuf, 6, fp) != inBuf) - { - Cleanup(fp); - Fail("fgets failed after fseek was called with SEEK_CUR and a " - "negative offset.\n"); - } - - if (strncmp(inBuf, "ABCDE", 5) != 0) - { - Cleanup(fp); - Fail("fseek did not move to the correct position when called with" - " SEEK_CUR and a negative offset.\n"); - } - - /*Try seeking relative to the end of the file.*/ - if (fseek(fp, -10, SEEK_END) != 0) - { - Cleanup(fp); - Fail("fseek failed when called with SEEK_END and a negative" - " offset.\n"); - } - if (fgets(inBuf, 2, fp) != inBuf) - { - Cleanup(fp); - Fail("fgets failed after fseek was called with SEEK_END and a " - "negative offset\n"); - } - - if (strncmp(inBuf, "Q", 1) != 0) - { - Cleanup(fp); - Fail("fseek did not move to the correct position when called with " - "SEEK_END and a negative offset.\n"); - } - - - /*close the file*/ - if(!Cleanup(fp)) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; -} - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/fseek/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fseek/test1/test1.cpp new file mode 100644 index 0000000000..dd1e87ea8d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fseek/test1/test1.cpp @@ -0,0 +1,193 @@ +// 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: test1.c +** +** Purpose: Call fseek to move a file pointer to the start of a file, +** a position offset from the start, a position offset from the +** current position, and a position offset from the end of the +** file. Check that the file pointer is at the correct position +** after each seek. +** +** +**==========================================================================*/ + +#include + +const char filename[] = "testfile.txt"; + +static BOOL Cleanup(HANDLE hFile) +{ + BOOL result= TRUE; + + if (fclose((PAL_FILE*)hFile)) + { + Trace("fseek: ERROR -> Unable to close file \"%s\".\n", + filename); + result= FALSE; + } + if (!DeleteFileA(filename)) + { + result= FALSE; + Trace("fseek: ERROR -> Unable to delete file \"%s\". ", + "GetLastError returned %u.\n", + filename, + GetLastError()); + } + return result; +} + +int __cdecl main(int argc, char **argv) +{ + char outBuf[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + char inBuf[20]; + FILE * fp; + int size = ( sizeof(outBuf)/sizeof(char) ) - 1; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /*create the file*/ + fp = fopen(filename, "w"); + if (fp == NULL) + { + Fail("Unable to open a file for write.\n"); + } + if(fprintf(fp, outBuf) != size) + { + Trace("Unable to write to %s.\n", filename); + Cleanup(fp); + Fail(""); + } + + if (fclose(fp) != 0) + { + Trace("Unable to close newly written file.\n"); + if (!DeleteFileA(filename)) + { + Trace("fseek: ERROR -> Unable to delete file \"%s\". ", + "GetLastError returned %u.\n", + filename, + GetLastError()); + } + Fail(""); + } + + fp = fopen(filename, "r"); + if (fp == NULL) + { + if (!DeleteFileA(filename)) + { + Trace("_putw: ERROR -> Unable to delete file \"%s\". ", + "GetLastError returned %u.\n", + filename, + GetLastError()); + } + Fail("Unable to open a file for read.\n"); + } + + /*seek to the start*/ + if (fseek(fp, 0, SEEK_SET) != 0) + { + Cleanup(fp); + Fail("fseek failed when seeking the start of a file.\n"); + } + if (fgets(inBuf, 11, fp) != inBuf) + { + Cleanup(fp); + Fail("Unable to read from file after using fseek to move to the start.\n"); + } + if (strncmp(inBuf, outBuf, 10) != 0) + { + Cleanup(fp); + Fail("fseek was asked to seek the start of a file," + "but didn't get there.\n"); + } + + /*Seek with an offset from the start*/ + + if (fseek(fp, 10, SEEK_SET) != 0) + { + Cleanup(fp); + Fail("fseek failed when called with SEEK_SET and a positive offset.\n"); + } + + if (fgets(inBuf, 6, fp) != inBuf) + { + Cleanup(fp); + Fail("fgets failed after feek was called with SEEK_SET" + "and a positive offset.\n"); + } + + + if (strncmp(inBuf, "ABCDE", 5) != 0) + { + Cleanup(fp); + Fail("fseek did not move to the correct position when passed SEEK_SET" + " and a positive offset.\n"); + } + + /*now move backwards and read the same string*/ + if (fseek(fp, -5, SEEK_CUR) != 0) + { + Cleanup(fp); + Fail("fseek failed when passed SEEK_CUR and a negative offset.\n"); + } + + if (fgets(inBuf, 6, fp) != inBuf) + { + Cleanup(fp); + Fail("fgets failed after fseek was called with SEEK_CUR and a " + "negative offset.\n"); + } + + if (strncmp(inBuf, "ABCDE", 5) != 0) + { + Cleanup(fp); + Fail("fseek did not move to the correct position when called with" + " SEEK_CUR and a negative offset.\n"); + } + + /*Try seeking relative to the end of the file.*/ + if (fseek(fp, -10, SEEK_END) != 0) + { + Cleanup(fp); + Fail("fseek failed when called with SEEK_END and a negative" + " offset.\n"); + } + if (fgets(inBuf, 2, fp) != inBuf) + { + Cleanup(fp); + Fail("fgets failed after fseek was called with SEEK_END and a " + "negative offset\n"); + } + + if (strncmp(inBuf, "Q", 1) != 0) + { + Cleanup(fp); + Fail("fseek did not move to the correct position when called with " + "SEEK_END and a negative offset.\n"); + } + + + /*close the file*/ + if(!Cleanup(fp)) + { + Fail(""); + } + + PAL_Terminate(); + return PASS; +} + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/ftell/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ftell/test1/CMakeLists.txt index 7ea9a51111..a1f350d0c2 100644 --- a/src/pal/tests/palsuite/c_runtime/ftell/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/ftell/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - ftell.c + ftell.cpp ) add_executable(paltest_ftell_test1 diff --git a/src/pal/tests/palsuite/c_runtime/ftell/test1/ftell.c b/src/pal/tests/palsuite/c_runtime/ftell/test1/ftell.c deleted file mode 100644 index 66e0854847..0000000000 --- a/src/pal/tests/palsuite/c_runtime/ftell/test1/ftell.c +++ /dev/null @@ -1,145 +0,0 @@ -// 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: ftell.c (test 1) -** -** Purpose: Tests the PAL implementation of the ftell function. -** -** -**===================================================================*/ - -#include - -FILE* pFile; -struct TESTS -{ - long lDist; - int nFrom; - long lPosition; -}; - - -/************************************************* -** -** Validate -** -** Purpose: -** Tests whether the move was successful. If -** it passes, it returns TRUE. If it fails -** it outputs some error messages and returns -** FALSE. -** -*************************************************/ -BOOL Validate(long lExpected) -{ - long lPos = -2; - - if (((lPos = ftell(pFile)) == -1) || (lPos != lExpected)) - { - Trace("ftell: ERROR -> ftell returned %ld when expecting %ld.\n", - lPos, - lExpected); - if (fclose(pFile) != 0) - { - Trace("ftell: ERROR -> fclose failed to close the file.\n"); - } - return FALSE; - } - return TRUE; -} - - -/************************************************* -** -** MovePointer -** -** Purpose: -** Accepts the distance to move and the -** distance and calls fseek to move the file -** pointer. If the fseek fails, error messages -** are displayed and FALSE is returned. TRUE -** is returned on a successful fseek. -** -*************************************************/ -BOOL MovePointer(long lDist, int nFrom) -{ - /* move the file pointer*/ - if (fseek(pFile, lDist, nFrom) != 0) - { - Trace("ftell: ERROR -> fseek failed to move the file pointer " - "%l characters.\n", - lDist); - if (fclose(pFile) != 0) - { - Trace("ftell: ERROR -> fclose failed to close the file.\n"); - } - return FALSE; - } - return TRUE; -} - - - -int __cdecl main(int argc, char *argv[]) -{ - const char szFileName[] = {"testfile.txt"}; - long lPos = -1; - int i; - char szTempBuffer[256]; - struct TESTS testCase[] = - { - {0, SEEK_SET, 0}, - {10, SEEK_CUR, 10}, - {-5, SEEK_CUR, 5}, - {-2, SEEK_END, 50} - }; - - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - memset(szTempBuffer, 0, 256); - - - /* open the test file */ - pFile = fopen(szFileName, "r"); - if (pFile == NULL) - { - Fail("ftell: ERROR -> fopen failed to open the file \"%s\".\n"); - } - - /* loop through the test cases */ - for (i = 0; i < (sizeof(testCase)/sizeof(struct TESTS)); i++) - { - if (MovePointer(testCase[i].lDist, testCase[i].nFrom) != TRUE) - { - Fail(""); - } - else if (Validate(testCase[i].lPosition) != TRUE) - { - Fail(""); - } - } - - if (fclose(pFile) != 0) - { - Fail("ftell: ERROR -> fclose failed to close the file.\n"); - } - - /* lets just see if we can find out where we are in a closed stream... */ - if ((lPos = ftell(pFile)) != -1) - { - Fail("ftell: ERROR -> ftell returned a valid position (%ld) on a " - "closed file handle\n", - lPos); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/ftell/test1/ftell.cpp b/src/pal/tests/palsuite/c_runtime/ftell/test1/ftell.cpp new file mode 100644 index 0000000000..66e0854847 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ftell/test1/ftell.cpp @@ -0,0 +1,145 @@ +// 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: ftell.c (test 1) +** +** Purpose: Tests the PAL implementation of the ftell function. +** +** +**===================================================================*/ + +#include + +FILE* pFile; +struct TESTS +{ + long lDist; + int nFrom; + long lPosition; +}; + + +/************************************************* +** +** Validate +** +** Purpose: +** Tests whether the move was successful. If +** it passes, it returns TRUE. If it fails +** it outputs some error messages and returns +** FALSE. +** +*************************************************/ +BOOL Validate(long lExpected) +{ + long lPos = -2; + + if (((lPos = ftell(pFile)) == -1) || (lPos != lExpected)) + { + Trace("ftell: ERROR -> ftell returned %ld when expecting %ld.\n", + lPos, + lExpected); + if (fclose(pFile) != 0) + { + Trace("ftell: ERROR -> fclose failed to close the file.\n"); + } + return FALSE; + } + return TRUE; +} + + +/************************************************* +** +** MovePointer +** +** Purpose: +** Accepts the distance to move and the +** distance and calls fseek to move the file +** pointer. If the fseek fails, error messages +** are displayed and FALSE is returned. TRUE +** is returned on a successful fseek. +** +*************************************************/ +BOOL MovePointer(long lDist, int nFrom) +{ + /* move the file pointer*/ + if (fseek(pFile, lDist, nFrom) != 0) + { + Trace("ftell: ERROR -> fseek failed to move the file pointer " + "%l characters.\n", + lDist); + if (fclose(pFile) != 0) + { + Trace("ftell: ERROR -> fclose failed to close the file.\n"); + } + return FALSE; + } + return TRUE; +} + + + +int __cdecl main(int argc, char *argv[]) +{ + const char szFileName[] = {"testfile.txt"}; + long lPos = -1; + int i; + char szTempBuffer[256]; + struct TESTS testCase[] = + { + {0, SEEK_SET, 0}, + {10, SEEK_CUR, 10}, + {-5, SEEK_CUR, 5}, + {-2, SEEK_END, 50} + }; + + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + memset(szTempBuffer, 0, 256); + + + /* open the test file */ + pFile = fopen(szFileName, "r"); + if (pFile == NULL) + { + Fail("ftell: ERROR -> fopen failed to open the file \"%s\".\n"); + } + + /* loop through the test cases */ + for (i = 0; i < (sizeof(testCase)/sizeof(struct TESTS)); i++) + { + if (MovePointer(testCase[i].lDist, testCase[i].nFrom) != TRUE) + { + Fail(""); + } + else if (Validate(testCase[i].lPosition) != TRUE) + { + Fail(""); + } + } + + if (fclose(pFile) != 0) + { + Fail("ftell: ERROR -> fclose failed to close the file.\n"); + } + + /* lets just see if we can find out where we are in a closed stream... */ + if ((lPos = ftell(pFile)) != -1) + { + Fail("ftell: ERROR -> ftell returned a valid position (%ld) on a " + "closed file handle\n", + lPos); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/fwprintf.h b/src/pal/tests/palsuite/c_runtime/fwprintf/fwprintf.h index 36756636cf..eed0e76484 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/fwprintf.h +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/fwprintf.h @@ -14,7 +14,7 @@ #ifndef __fwprintf_H__ #define __fwprintf_H__ -void DoStrTest(WCHAR *formatstr, char* param, char *checkstr) +void DoStrTest(const WCHAR *formatstr, char* param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -45,7 +45,7 @@ void DoStrTest(WCHAR *formatstr, char* param, char *checkstr) fclose(fp); } -void DoWStrTest(WCHAR *formatstr, WCHAR* param, char *checkstr) +void DoWStrTest(const WCHAR *formatstr, WCHAR* param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -77,8 +77,8 @@ void DoWStrTest(WCHAR *formatstr, WCHAR* param, char *checkstr) } -void DoPointerTest(WCHAR *formatstr, void* param, char* paramstr, - char *checkstr1, char *checkstr2) +void DoPointerTest(const WCHAR *formatstr, void* param, char* paramstr, + const char *checkstr1, const char *checkstr2) { FILE *fp; char buf[256] = { 0 }; @@ -119,7 +119,7 @@ void DoPointerTest(WCHAR *formatstr, void* param, char* paramstr, -void DoCountTest(WCHAR *formatstr, int param, char *checkstr) +void DoCountTest(const WCHAR *formatstr, int param, const char *checkstr) { FILE *fp; char buf[512] = { 0 }; @@ -162,7 +162,7 @@ void DoCountTest(WCHAR *formatstr, int param, char *checkstr) } } -void DoShortCountTest(WCHAR *formatstr, int param, char *checkstr) +void DoShortCountTest(const WCHAR *formatstr, int param, const char *checkstr) { FILE *fp; char buf[512] = { 0 }; @@ -206,7 +206,7 @@ void DoShortCountTest(WCHAR *formatstr, int param, char *checkstr) } -void DoCharTest(WCHAR *formatstr, char param, char *checkstr) +void DoCharTest(const WCHAR *formatstr, char param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -237,7 +237,7 @@ void DoCharTest(WCHAR *formatstr, char param, char *checkstr) fclose(fp); } -void DoWCharTest(WCHAR *formatstr, WCHAR param, char *checkstr) +void DoWCharTest(const WCHAR *formatstr, WCHAR param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -268,7 +268,7 @@ void DoWCharTest(WCHAR *formatstr, WCHAR param, char *checkstr) fclose(fp); } -void DoNumTest(WCHAR *formatstr, int value, char *checkstr) +void DoNumTest(const WCHAR *formatstr, int value, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -299,8 +299,8 @@ void DoNumTest(WCHAR *formatstr, int value, char *checkstr) fclose(fp); } -void DoI64Test(WCHAR *formatstr, INT64 value, char *valuestr, char *checkstr1, - char *checkstr2) +void DoI64Test(const WCHAR *formatstr, INT64 value, char *valuestr, const char *checkstr1, + const char *checkstr2) { FILE *fp; char buf[256] = { 0 }; @@ -332,8 +332,8 @@ void DoI64Test(WCHAR *formatstr, INT64 value, char *valuestr, char *checkstr1, fclose(fp); } -void DoDoubleTest(WCHAR *formatstr, double value, char *checkstr1, - char *checkstr2) +void DoDoubleTest(const WCHAR *formatstr, double value, const char *checkstr1, + const char *checkstr2) { FILE *fp; char buf[256] = { 0 }; @@ -367,8 +367,8 @@ void DoDoubleTest(WCHAR *formatstr, double value, char *checkstr1, } -void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, - char *paramstr, char *checkstr1, char *checkstr2) +void DoArgumentPrecTest(const WCHAR *formatstr, int precision, void *param, + char *paramstr, const char *checkstr1, const char *checkstr2) { FILE *fp; char buf[256]; @@ -409,8 +409,8 @@ void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, } -void DoArgumentPrecDoubleTest(WCHAR *formatstr, int precision, double param, - char *checkstr1, char *checkstr2) +void DoArgumentPrecDoubleTest(const WCHAR *formatstr, int precision, double param, + const char *checkstr1, const char *checkstr2) { FILE *fp; char buf[256]; diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test1/CMakeLists.txt index ce4271edb2..519860b877 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fwprintf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test1/test1.c deleted file mode 100644 index 8a171db52a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test1/test1.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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: test1.c -** -** Purpose: A single, basic, test case with no formatting. -** Test modeled after the sprintf series. -** - -** -**==========================================================================*/ - -#include - -/* - * Depends on memcmp, strlen, fopen, fgets, fseek and fclose. - */ - -int __cdecl main(int argc, char *argv[]) -{ - FILE *fp; - char testfile[] = "testfile.txt"; - - WCHAR *outstr; - char checkstr[] = "hello world"; - char buf[256]; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - outstr = convert(checkstr); - if ((fp = fopen(testfile, "w+")) == NULL) - { - Fail("ERROR: fopen failed to create \"%s\"\n", testfile); - } - - if ((fwprintf(fp, outstr)) < 0) - { - Fail("ERROR: fwprintf failed to print to \"%s\"\n", testfile); - } - - if ((fseek( fp, 0, SEEK_SET)) != 0) - { - Fail("ERROR: Fseek failed to set pointer to beginning of file\n" ); - } - - - if ((fgets( buf, 100, fp )) == NULL) - { - Fail("ERROR: fgets failed\n"); - } - - if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) - { - Fail("ERROR: expected %s, got %s\n", checkstr, buf); - } - - - if ((fclose( fp )) != 0) - { - Fail("ERROR: fclose failed to close \"%s\"\n", testfile); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test1/test1.cpp new file mode 100644 index 0000000000..8a171db52a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test1/test1.cpp @@ -0,0 +1,71 @@ +// 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: test1.c +** +** Purpose: A single, basic, test case with no formatting. +** Test modeled after the sprintf series. +** + +** +**==========================================================================*/ + +#include + +/* + * Depends on memcmp, strlen, fopen, fgets, fseek and fclose. + */ + +int __cdecl main(int argc, char *argv[]) +{ + FILE *fp; + char testfile[] = "testfile.txt"; + + WCHAR *outstr; + char checkstr[] = "hello world"; + char buf[256]; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + outstr = convert(checkstr); + if ((fp = fopen(testfile, "w+")) == NULL) + { + Fail("ERROR: fopen failed to create \"%s\"\n", testfile); + } + + if ((fwprintf(fp, outstr)) < 0) + { + Fail("ERROR: fwprintf failed to print to \"%s\"\n", testfile); + } + + if ((fseek( fp, 0, SEEK_SET)) != 0) + { + Fail("ERROR: Fseek failed to set pointer to beginning of file\n" ); + } + + + if ((fgets( buf, 100, fp )) == NULL) + { + Fail("ERROR: fgets failed\n"); + } + + if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) + { + Fail("ERROR: expected %s, got %s\n", checkstr, buf); + } + + + if ((fclose( fp )) != 0) + { + Fail("ERROR: fclose failed to close \"%s\"\n", testfile); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test10/CMakeLists.txt index a8323b4fc7..e604e03dff 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_fwprintf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test10/test10.c deleted file mode 100644 index 3aa2c45c7c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test10/test10.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test10.c -** -** Purpose: Tests the octal specifier (%o). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %o"), pos, "foo 52"); - DoNumTest(convert("foo %lo"), 0xFFFF, "foo 177777"); - DoNumTest(convert("foo %ho"), 0xFFFF, "foo 177777"); - DoNumTest(convert("foo %Lo"), pos, "foo 52"); - DoI64Test(convert("foo %I64o"), l, "42", "foo 52", "foo 52"); - DoNumTest(convert("foo %3o"), pos, "foo 52"); - DoNumTest(convert("foo %-3o"), pos, "foo 52 "); - DoNumTest(convert("foo %.1o"), pos, "foo 52"); - DoNumTest(convert("foo %.3o"), pos, "foo 052"); - DoNumTest(convert("foo %03o"), pos, "foo 052"); - DoNumTest(convert("foo %#o"), pos, "foo 052"); - DoNumTest(convert("foo %+o"), pos, "foo 52"); - DoNumTest(convert("foo % o"), pos, "foo 52"); - DoNumTest(convert("foo %+o"), neg, "foo 37777777726"); - DoNumTest(convert("foo % o"), neg, "foo 37777777726"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test10/test10.cpp new file mode 100644 index 0000000000..3aa2c45c7c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test10/test10.cpp @@ -0,0 +1,51 @@ +// 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: test10.c +** +** Purpose: Tests the octal specifier (%o). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %o"), pos, "foo 52"); + DoNumTest(convert("foo %lo"), 0xFFFF, "foo 177777"); + DoNumTest(convert("foo %ho"), 0xFFFF, "foo 177777"); + DoNumTest(convert("foo %Lo"), pos, "foo 52"); + DoI64Test(convert("foo %I64o"), l, "42", "foo 52", "foo 52"); + DoNumTest(convert("foo %3o"), pos, "foo 52"); + DoNumTest(convert("foo %-3o"), pos, "foo 52 "); + DoNumTest(convert("foo %.1o"), pos, "foo 52"); + DoNumTest(convert("foo %.3o"), pos, "foo 052"); + DoNumTest(convert("foo %03o"), pos, "foo 052"); + DoNumTest(convert("foo %#o"), pos, "foo 052"); + DoNumTest(convert("foo %+o"), pos, "foo 52"); + DoNumTest(convert("foo % o"), pos, "foo 52"); + DoNumTest(convert("foo %+o"), neg, "foo 37777777726"); + DoNumTest(convert("foo % o"), neg, "foo 37777777726"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test11/CMakeLists.txt index 1b7987400a..18be522823 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_fwprintf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test11/test11.c deleted file mode 100644 index 5867cd64fb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test11/test11.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test11.c -** -** Purpose: Test the unsigned int specifier (%u). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %u"), pos, "foo 42"); - DoNumTest(convert("foo %lu"), 0xFFFF, "foo 65535"); - DoNumTest(convert("foo %hu"), 0xFFFF, "foo 65535"); - DoNumTest(convert("foo %Lu"), pos, "foo 42"); - DoI64Test(convert("foo %I64u"), l, "42", "foo 42", "foo 42"); - DoNumTest(convert("foo %3u"), pos, "foo 42"); - DoNumTest(convert("foo %-3u"), pos, "foo 42 "); - DoNumTest(convert("foo %.1u"), pos, "foo 42"); - DoNumTest(convert("foo %.3u"), pos, "foo 042"); - DoNumTest(convert("foo %03u"), pos, "foo 042"); - DoNumTest(convert("foo %#u"), pos, "foo 42"); - DoNumTest(convert("foo %+u"), pos, "foo 42"); - DoNumTest(convert("foo % u"), pos, "foo 42"); - DoNumTest(convert("foo %+u"), neg, "foo 4294967254"); - DoNumTest(convert("foo % u"), neg, "foo 4294967254"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test11/test11.cpp new file mode 100644 index 0000000000..5867cd64fb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test11/test11.cpp @@ -0,0 +1,51 @@ +// 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: test11.c +** +** Purpose: Test the unsigned int specifier (%u). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %u"), pos, "foo 42"); + DoNumTest(convert("foo %lu"), 0xFFFF, "foo 65535"); + DoNumTest(convert("foo %hu"), 0xFFFF, "foo 65535"); + DoNumTest(convert("foo %Lu"), pos, "foo 42"); + DoI64Test(convert("foo %I64u"), l, "42", "foo 42", "foo 42"); + DoNumTest(convert("foo %3u"), pos, "foo 42"); + DoNumTest(convert("foo %-3u"), pos, "foo 42 "); + DoNumTest(convert("foo %.1u"), pos, "foo 42"); + DoNumTest(convert("foo %.3u"), pos, "foo 042"); + DoNumTest(convert("foo %03u"), pos, "foo 042"); + DoNumTest(convert("foo %#u"), pos, "foo 42"); + DoNumTest(convert("foo %+u"), pos, "foo 42"); + DoNumTest(convert("foo % u"), pos, "foo 42"); + DoNumTest(convert("foo %+u"), neg, "foo 4294967254"); + DoNumTest(convert("foo % u"), neg, "foo 4294967254"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test12/CMakeLists.txt index 1e43a4c906..6ea739b28f 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_fwprintf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test12/test12.c deleted file mode 100644 index 48a6123423..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test12/test12.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test12.c -** -** Purpose: Tests the (lowercase) hexadecimal specifier (%x). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %x"), pos, "foo 1234ab"); - DoNumTest(convert("foo %lx"), pos, "foo 1234ab"); - DoNumTest(convert("foo %hx"), pos, "foo 34ab"); - DoNumTest(convert("foo %Lx"), pos, "foo 1234ab"); - DoI64Test(convert("foo %I64x"), l, "0x1234567887654321", - "foo 1234567887654321", "foo 0x1234567887654321"); - DoNumTest(convert("foo %7x"), pos, "foo 1234ab"); - DoNumTest(convert("foo %-7x"), pos, "foo 1234ab "); - DoNumTest(convert("foo %.1x"), pos, "foo 1234ab"); - DoNumTest(convert("foo %.7x"), pos, "foo 01234ab"); - DoNumTest(convert("foo %07x"), pos, "foo 01234ab"); - DoNumTest(convert("foo %#x"), pos, "foo 0x1234ab"); - DoNumTest(convert("foo %+x"), pos, "foo 1234ab"); - DoNumTest(convert("foo % x"), pos, "foo 1234ab"); - DoNumTest(convert("foo %+x"), neg, "foo ffffffd6"); - DoNumTest(convert("foo % x"), neg, "foo ffffffd6"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test12/test12.cpp new file mode 100644 index 0000000000..48a6123423 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test12/test12.cpp @@ -0,0 +1,52 @@ +// 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: test12.c +** +** Purpose: Tests the (lowercase) hexadecimal specifier (%x). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %x"), pos, "foo 1234ab"); + DoNumTest(convert("foo %lx"), pos, "foo 1234ab"); + DoNumTest(convert("foo %hx"), pos, "foo 34ab"); + DoNumTest(convert("foo %Lx"), pos, "foo 1234ab"); + DoI64Test(convert("foo %I64x"), l, "0x1234567887654321", + "foo 1234567887654321", "foo 0x1234567887654321"); + DoNumTest(convert("foo %7x"), pos, "foo 1234ab"); + DoNumTest(convert("foo %-7x"), pos, "foo 1234ab "); + DoNumTest(convert("foo %.1x"), pos, "foo 1234ab"); + DoNumTest(convert("foo %.7x"), pos, "foo 01234ab"); + DoNumTest(convert("foo %07x"), pos, "foo 01234ab"); + DoNumTest(convert("foo %#x"), pos, "foo 0x1234ab"); + DoNumTest(convert("foo %+x"), pos, "foo 1234ab"); + DoNumTest(convert("foo % x"), pos, "foo 1234ab"); + DoNumTest(convert("foo %+x"), neg, "foo ffffffd6"); + DoNumTest(convert("foo % x"), neg, "foo ffffffd6"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test13/CMakeLists.txt index c84dc3ea41..8505ccbd82 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_fwprintf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test13/test13.c deleted file mode 100644 index 6eabec6c77..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test13/test13.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test13.c -** -** Purpose: Tests the (uppercase) hexadecimal specifier (%X). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234AB; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %X"), pos, "foo 1234AB"); - DoNumTest(convert("foo %lX"), pos, "foo 1234AB"); - DoNumTest(convert("foo %hX"), pos, "foo 34AB"); - DoNumTest(convert("foo %LX"), pos, "foo 1234AB"); - DoI64Test(convert("foo %I64X"), l, "0x1234567887654321", - "foo 1234567887654321", "foo 0x1234567887654321"); - DoNumTest(convert("foo %7X"), pos, "foo 1234AB"); - DoNumTest(convert("foo %-7X"), pos, "foo 1234AB "); - DoNumTest(convert("foo %.1X"), pos, "foo 1234AB"); - DoNumTest(convert("foo %.7X"), pos, "foo 01234AB"); - DoNumTest(convert("foo %07X"), pos, "foo 01234AB"); - DoNumTest(convert("foo %#X"), pos, "foo 0X1234AB"); - DoNumTest(convert("foo %+X"), pos, "foo 1234AB"); - DoNumTest(convert("foo % X"), pos, "foo 1234AB"); - DoNumTest(convert("foo %+X"), neg, "foo FFFFFFD6"); - DoNumTest(convert("foo % X"), neg, "foo FFFFFFD6"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test13/test13.cpp new file mode 100644 index 0000000000..6eabec6c77 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test13/test13.cpp @@ -0,0 +1,52 @@ +// 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: test13.c +** +** Purpose: Tests the (uppercase) hexadecimal specifier (%X). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234AB; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %X"), pos, "foo 1234AB"); + DoNumTest(convert("foo %lX"), pos, "foo 1234AB"); + DoNumTest(convert("foo %hX"), pos, "foo 34AB"); + DoNumTest(convert("foo %LX"), pos, "foo 1234AB"); + DoI64Test(convert("foo %I64X"), l, "0x1234567887654321", + "foo 1234567887654321", "foo 0x1234567887654321"); + DoNumTest(convert("foo %7X"), pos, "foo 1234AB"); + DoNumTest(convert("foo %-7X"), pos, "foo 1234AB "); + DoNumTest(convert("foo %.1X"), pos, "foo 1234AB"); + DoNumTest(convert("foo %.7X"), pos, "foo 01234AB"); + DoNumTest(convert("foo %07X"), pos, "foo 01234AB"); + DoNumTest(convert("foo %#X"), pos, "foo 0X1234AB"); + DoNumTest(convert("foo %+X"), pos, "foo 1234AB"); + DoNumTest(convert("foo % X"), pos, "foo 1234AB"); + DoNumTest(convert("foo %+X"), neg, "foo FFFFFFD6"); + DoNumTest(convert("foo % X"), neg, "foo FFFFFFD6"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test14/CMakeLists.txt index 97824c76b7..548e60fdb8 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_fwprintf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test14/test14.c deleted file mode 100644 index 001cf72689..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test14/test14.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: test14.c -** -** Purpose: Tests the lowercase exponential -** notation double specifier (%e). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %e"), val, "foo 2.560000e+002", - "foo 2.560000e+02"); - DoDoubleTest(convert("foo %le"), val, "foo 2.560000e+002", - "foo 2.560000e+02"); - DoDoubleTest(convert("foo %he"), val, "foo 2.560000e+002", - "foo 2.560000e+02"); - DoDoubleTest(convert("foo %Le"), val, "foo 2.560000e+002", - "foo 2.560000e+02"); - DoDoubleTest(convert("foo %I64e"), val, "foo 2.560000e+002", - "foo 2.560000e+02"); - DoDoubleTest(convert("foo %14e"), val, "foo 2.560000e+002", - "foo 2.560000e+02"); - DoDoubleTest(convert("foo %-14e"), val, "foo 2.560000e+002 ", - "foo 2.560000e+02 "); - DoDoubleTest(convert("foo %.1e"), val, "foo 2.6e+002", - "foo 2.6e+02"); - DoDoubleTest(convert("foo %.8e"), val, "foo 2.56000000e+002", - "foo 2.56000000e+02"); - DoDoubleTest(convert("foo %014e"), val, "foo 02.560000e+002", - "foo 002.560000e+02"); - DoDoubleTest(convert("foo %#e"), val, "foo 2.560000e+002", - "foo 2.560000e+02"); - DoDoubleTest(convert("foo %+e"), val, "foo +2.560000e+002", - "foo +2.560000e+02"); - DoDoubleTest(convert("foo % e"), val, "foo 2.560000e+002", - "foo 2.560000e+02"); - DoDoubleTest(convert("foo %+e"), neg, "foo -2.560000e+002", - "foo -2.560000e+02"); - DoDoubleTest(convert("foo % e"), neg, "foo -2.560000e+002", - "foo -2.560000e+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test14/test14.cpp new file mode 100644 index 0000000000..001cf72689 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test14/test14.cpp @@ -0,0 +1,66 @@ +// 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: test14.c +** +** Purpose: Tests the lowercase exponential +** notation double specifier (%e). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %e"), val, "foo 2.560000e+002", + "foo 2.560000e+02"); + DoDoubleTest(convert("foo %le"), val, "foo 2.560000e+002", + "foo 2.560000e+02"); + DoDoubleTest(convert("foo %he"), val, "foo 2.560000e+002", + "foo 2.560000e+02"); + DoDoubleTest(convert("foo %Le"), val, "foo 2.560000e+002", + "foo 2.560000e+02"); + DoDoubleTest(convert("foo %I64e"), val, "foo 2.560000e+002", + "foo 2.560000e+02"); + DoDoubleTest(convert("foo %14e"), val, "foo 2.560000e+002", + "foo 2.560000e+02"); + DoDoubleTest(convert("foo %-14e"), val, "foo 2.560000e+002 ", + "foo 2.560000e+02 "); + DoDoubleTest(convert("foo %.1e"), val, "foo 2.6e+002", + "foo 2.6e+02"); + DoDoubleTest(convert("foo %.8e"), val, "foo 2.56000000e+002", + "foo 2.56000000e+02"); + DoDoubleTest(convert("foo %014e"), val, "foo 02.560000e+002", + "foo 002.560000e+02"); + DoDoubleTest(convert("foo %#e"), val, "foo 2.560000e+002", + "foo 2.560000e+02"); + DoDoubleTest(convert("foo %+e"), val, "foo +2.560000e+002", + "foo +2.560000e+02"); + DoDoubleTest(convert("foo % e"), val, "foo 2.560000e+002", + "foo 2.560000e+02"); + DoDoubleTest(convert("foo %+e"), neg, "foo -2.560000e+002", + "foo -2.560000e+02"); + DoDoubleTest(convert("foo % e"), neg, "foo -2.560000e+002", + "foo -2.560000e+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test15/CMakeLists.txt index 6786c5b774..c5b53461a7 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_fwprintf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test15/test15.c deleted file mode 100644 index 9dfe82eccc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test15/test15.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: test15.c -** -** Purpose: Tests the uppercase exponential -** notation double specifier (%E). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %E"), val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest(convert("foo %lE"), val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest(convert("foo %hE"), val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest(convert("foo %LE"), val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest(convert("foo %I64E"), val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest(convert("foo %14E"), val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest(convert("foo %-14E"), val, "foo 2.560000E+002 ", - "foo 2.560000E+02 "); - DoDoubleTest(convert("foo %.1E"), val, "foo 2.6E+002", - "foo 2.6E+02"); - DoDoubleTest(convert("foo %.8E"), val, "foo 2.56000000E+002", - "foo 2.56000000E+02"); - DoDoubleTest(convert("foo %014E"), val, "foo 02.560000E+002", - "foo 002.560000E+02"); - DoDoubleTest(convert("foo %#E"), val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest(convert("foo %+E"), val, "foo +2.560000E+002", - "foo +2.560000E+02"); - DoDoubleTest(convert("foo % E"), val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest(convert("foo %+E"), neg, "foo -2.560000E+002", - "foo -2.560000E+02"); - DoDoubleTest(convert("foo % E"), neg, "foo -2.560000E+002", - "foo -2.560000E+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test15/test15.cpp new file mode 100644 index 0000000000..9dfe82eccc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test15/test15.cpp @@ -0,0 +1,66 @@ +// 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: test15.c +** +** Purpose: Tests the uppercase exponential +** notation double specifier (%E). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %E"), val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest(convert("foo %lE"), val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest(convert("foo %hE"), val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest(convert("foo %LE"), val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest(convert("foo %I64E"), val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest(convert("foo %14E"), val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest(convert("foo %-14E"), val, "foo 2.560000E+002 ", + "foo 2.560000E+02 "); + DoDoubleTest(convert("foo %.1E"), val, "foo 2.6E+002", + "foo 2.6E+02"); + DoDoubleTest(convert("foo %.8E"), val, "foo 2.56000000E+002", + "foo 2.56000000E+02"); + DoDoubleTest(convert("foo %014E"), val, "foo 02.560000E+002", + "foo 002.560000E+02"); + DoDoubleTest(convert("foo %#E"), val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest(convert("foo %+E"), val, "foo +2.560000E+002", + "foo +2.560000E+02"); + DoDoubleTest(convert("foo % E"), val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest(convert("foo %+E"), neg, "foo -2.560000E+002", + "foo -2.560000E+02"); + DoDoubleTest(convert("foo % E"), neg, "foo -2.560000E+002", + "foo -2.560000E+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test16/CMakeLists.txt index be14870863..51af0a0d60 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_fwprintf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test16/test16.c deleted file mode 100644 index 1969be1824..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test16/test16.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test16.c -** -** Purpose: Tests the decimal notation double specifier (%f). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %f"), val, "foo 2560.001000", - "foo 2560.001000"); - DoDoubleTest(convert("foo %lf"), val, "foo 2560.001000", - "foo 2560.001000"); - DoDoubleTest(convert("foo %hf"), val, "foo 2560.001000", - "foo 2560.001000"); - DoDoubleTest(convert("foo %Lf"), val, "foo 2560.001000", - "foo 2560.001000"); - DoDoubleTest(convert("foo %I64f"), val, "foo 2560.001000", - "foo 2560.001000"); - DoDoubleTest(convert("foo %12f"), val, "foo 2560.001000", - "foo 2560.001000"); - DoDoubleTest(convert("foo %-12f"), val, "foo 2560.001000 ", - "foo 2560.001000 "); - DoDoubleTest(convert("foo %.1f"), val, "foo 2560.0", - "foo 2560.0"); - DoDoubleTest(convert("foo %.8f"), val, "foo 2560.00100000", - "foo 2560.00100000"); - DoDoubleTest(convert("foo %012f"), val, "foo 02560.001000", - "foo 02560.001000"); - DoDoubleTest(convert("foo %#f"), val, "foo 2560.001000", - "foo 2560.001000"); - DoDoubleTest(convert("foo %+f"), val, "foo +2560.001000", - "foo +2560.001000"); - DoDoubleTest(convert("foo % f"), val, "foo 2560.001000", - "foo 2560.001000"); - DoDoubleTest(convert("foo %+f"), neg, "foo -2560.001000", - "foo -2560.001000"); - DoDoubleTest(convert("foo % f"), neg, "foo -2560.001000", - "foo -2560.001000"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test16/test16.cpp new file mode 100644 index 0000000000..1969be1824 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test16/test16.cpp @@ -0,0 +1,65 @@ +// 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: test16.c +** +** Purpose: Tests the decimal notation double specifier (%f). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %f"), val, "foo 2560.001000", + "foo 2560.001000"); + DoDoubleTest(convert("foo %lf"), val, "foo 2560.001000", + "foo 2560.001000"); + DoDoubleTest(convert("foo %hf"), val, "foo 2560.001000", + "foo 2560.001000"); + DoDoubleTest(convert("foo %Lf"), val, "foo 2560.001000", + "foo 2560.001000"); + DoDoubleTest(convert("foo %I64f"), val, "foo 2560.001000", + "foo 2560.001000"); + DoDoubleTest(convert("foo %12f"), val, "foo 2560.001000", + "foo 2560.001000"); + DoDoubleTest(convert("foo %-12f"), val, "foo 2560.001000 ", + "foo 2560.001000 "); + DoDoubleTest(convert("foo %.1f"), val, "foo 2560.0", + "foo 2560.0"); + DoDoubleTest(convert("foo %.8f"), val, "foo 2560.00100000", + "foo 2560.00100000"); + DoDoubleTest(convert("foo %012f"), val, "foo 02560.001000", + "foo 02560.001000"); + DoDoubleTest(convert("foo %#f"), val, "foo 2560.001000", + "foo 2560.001000"); + DoDoubleTest(convert("foo %+f"), val, "foo +2560.001000", + "foo +2560.001000"); + DoDoubleTest(convert("foo % f"), val, "foo 2560.001000", + "foo 2560.001000"); + DoDoubleTest(convert("foo %+f"), neg, "foo -2560.001000", + "foo -2560.001000"); + DoDoubleTest(convert("foo % f"), neg, "foo -2560.001000", + "foo -2560.001000"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test17/CMakeLists.txt index b390d15620..9ed8a390e7 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_fwprintf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test17/test17.c deleted file mode 100644 index 66b12716d0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test17/test17.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test17.c -** -** Purpose: Tests the lowercase shorthand notation double specifier (%g). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %g"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %lg"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %hg"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %Lg"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %I64g"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %5g"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %-5g"), val, "foo 2560 ", "foo 2560 "); - DoDoubleTest(convert("foo %.1g"), val, "foo 3e+003", "foo 3e+03"); - DoDoubleTest(convert("foo %.2g"), val, "foo 2.6e+003", "foo 2.6e+03"); - DoDoubleTest(convert("foo %.12g"), val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest(convert("foo %06g"), val, "foo 002560", "foo 002560"); - DoDoubleTest(convert("foo %#g"), val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest(convert("foo %+g"), val, "foo +2560", "foo +2560"); - DoDoubleTest(convert("foo % g"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %+g"), neg, "foo -2560", "foo -2560"); - DoDoubleTest(convert("foo % g"), neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test17/test17.cpp new file mode 100644 index 0000000000..66b12716d0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test17/test17.cpp @@ -0,0 +1,51 @@ +// 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: test17.c +** +** Purpose: Tests the lowercase shorthand notation double specifier (%g). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %g"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %lg"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %hg"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %Lg"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %I64g"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %5g"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %-5g"), val, "foo 2560 ", "foo 2560 "); + DoDoubleTest(convert("foo %.1g"), val, "foo 3e+003", "foo 3e+03"); + DoDoubleTest(convert("foo %.2g"), val, "foo 2.6e+003", "foo 2.6e+03"); + DoDoubleTest(convert("foo %.12g"), val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest(convert("foo %06g"), val, "foo 002560", "foo 002560"); + DoDoubleTest(convert("foo %#g"), val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest(convert("foo %+g"), val, "foo +2560", "foo +2560"); + DoDoubleTest(convert("foo % g"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %+g"), neg, "foo -2560", "foo -2560"); + DoDoubleTest(convert("foo % g"), neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test18/CMakeLists.txt index 6f6d79bce5..3e3ba4efc7 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test18.c + test18.cpp ) add_executable(paltest_fwprintf_test18 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test18/test18.c deleted file mode 100644 index a33dea39b3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test18/test18.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test18.c -** -** Purpose: Tests the uppercase shorthand notation double specifier (%G). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest(convert("foo %G"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %lG"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %hG"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %LG"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %I64G"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %5G"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %-5G"), val, "foo 2560 ", "foo 2560 "); - DoDoubleTest(convert("foo %.1G"), val, "foo 3E+003", "foo 3E+03"); - DoDoubleTest(convert("foo %.2G"), val, "foo 2.6E+003", "foo 2.6E+03"); - DoDoubleTest(convert("foo %.12G"), val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest(convert("foo %06G"), val, "foo 002560", "foo 002560"); - DoDoubleTest(convert("foo %#G"), val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest(convert("foo %+G"), val, "foo +2560", "foo +2560"); - DoDoubleTest(convert("foo % G"), val, "foo 2560", "foo 2560"); - DoDoubleTest(convert("foo %+G"), neg, "foo -2560", "foo -2560"); - DoDoubleTest(convert("foo % G"), neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test18/test18.cpp new file mode 100644 index 0000000000..a33dea39b3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test18/test18.cpp @@ -0,0 +1,51 @@ +// 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: test18.c +** +** Purpose: Tests the uppercase shorthand notation double specifier (%G). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %G"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %lG"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %hG"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %LG"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %I64G"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %5G"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %-5G"), val, "foo 2560 ", "foo 2560 "); + DoDoubleTest(convert("foo %.1G"), val, "foo 3E+003", "foo 3E+03"); + DoDoubleTest(convert("foo %.2G"), val, "foo 2.6E+003", "foo 2.6E+03"); + DoDoubleTest(convert("foo %.12G"), val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest(convert("foo %06G"), val, "foo 002560", "foo 002560"); + DoDoubleTest(convert("foo %#G"), val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest(convert("foo %+G"), val, "foo +2560", "foo +2560"); + DoDoubleTest(convert("foo % G"), val, "foo 2560", "foo 2560"); + DoDoubleTest(convert("foo %+G"), neg, "foo -2560", "foo -2560"); + DoDoubleTest(convert("foo % G"), neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test19/CMakeLists.txt index bc10825ce1..fbb7370ba3 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test19.c + test19.cpp ) add_executable(paltest_fwprintf_test19 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test19/test19.c deleted file mode 100644 index 4600de7fa9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test19/test19.c +++ /dev/null @@ -1,81 +0,0 @@ -// 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: test19.c -** -** Purpose: Tests the variable length precision argument. -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - - - -int __cdecl main(int argc, char *argv[]) -{ - int n = -1; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoArgumentPrecTest(convert("%.*s"), 2, convert("bar"), "bar", "ba", "ba"); - DoArgumentPrecTest(convert("%.*S"), 2, "bar", "bar", "ba", "ba"); - DoArgumentPrecTest(convert("foo %.*n"), 3, &n, "pointer to int", "foo ", - "foo "); - if (n != 4) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - 4, n); - } - - DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, "42", "52", "52"); - DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, "42", "052", "052"); - DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, "0x42", "042", "042"); - DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, "0x42", "042", "042"); - - - DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, "2.0e+000", "2.0e+00"); - DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, "2.010e+000", - "2.010e+00"); - DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, "2.0E+000", "2.0E+00"); - DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, "2.010E+000", - "2.010E+00"); - DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, "2.0", "2.0"); - DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, "2.010", "2.010"); - DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, "3e+002", "3e+02"); - DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, "256.01", "256.01"); - DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, "3E+002", "3E+02"); - DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, "256.01", "256.01"); - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test19/test19.cpp new file mode 100644 index 0000000000..a407c9f4bd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test19/test19.cpp @@ -0,0 +1,81 @@ +// 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: test19.c +** +** Purpose: Tests the variable length precision argument. +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + + + +int __cdecl main(int argc, char *argv[]) +{ + int n = -1; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoArgumentPrecTest(convert("%.*s"), 2, (void*)convert("bar"), "bar", "ba", "ba"); + DoArgumentPrecTest(convert("%.*S"), 2, (void*)"bar", "bar", "ba", "ba"); + DoArgumentPrecTest(convert("foo %.*n"), 3, (void*)&n, "pointer to int", "foo ", + "foo "); + if (n != 4) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + 4, n); + } + + DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, "42", "52", "52"); + DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, "42", "052", "052"); + DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, "0x42", "042", "042"); + DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, "0x42", "042", "042"); + + + DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, "2.0e+000", "2.0e+00"); + DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, "2.010e+000", + "2.010e+00"); + DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, "2.0E+000", "2.0E+00"); + DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, "2.010E+000", + "2.010E+00"); + DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, "2.0", "2.0"); + DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, "2.010", "2.010"); + DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, "3e+002", "3e+02"); + DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, "256.01", "256.01"); + DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, "3E+002", "3E+02"); + DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, "256.01", "256.01"); + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test2/CMakeLists.txt index 64314651c0..e65a396862 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_fwprintf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test2/test2.c deleted file mode 100644 index ecd3c513df..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test2/test2.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests the string specifier (%s). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoWStrTest(convert("foo %s"), convert("bar"), "foo bar"); - DoStrTest(convert("foo %hs"), "bar", "foo bar"); - DoWStrTest(convert("foo %ls"), convert("bar"), "foo bar"); - DoWStrTest(convert("foo %ws"), convert("bar"), "foo bar"); - DoWStrTest(convert("foo %Ls"), convert("bar"), "foo bar"); - DoWStrTest(convert("foo %I64s"), convert("bar"), "foo bar"); - DoWStrTest(convert("foo %5s"), convert("bar"), "foo bar"); - DoWStrTest(convert("foo %.2s"), convert("bar"), "foo ba"); - DoWStrTest(convert("foo %5.2s"), convert("bar"), "foo ba"); - DoWStrTest(convert("foo %-5s"), convert("bar"), "foo bar "); - DoWStrTest(convert("foo %05s"), convert("bar"), "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test2/test2.cpp new file mode 100644 index 0000000000..ecd3c513df --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test2/test2.cpp @@ -0,0 +1,45 @@ +// 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: test2.c +** +** Purpose: Tests the string specifier (%s). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoWStrTest(convert("foo %s"), convert("bar"), "foo bar"); + DoStrTest(convert("foo %hs"), "bar", "foo bar"); + DoWStrTest(convert("foo %ls"), convert("bar"), "foo bar"); + DoWStrTest(convert("foo %ws"), convert("bar"), "foo bar"); + DoWStrTest(convert("foo %Ls"), convert("bar"), "foo bar"); + DoWStrTest(convert("foo %I64s"), convert("bar"), "foo bar"); + DoWStrTest(convert("foo %5s"), convert("bar"), "foo bar"); + DoWStrTest(convert("foo %.2s"), convert("bar"), "foo ba"); + DoWStrTest(convert("foo %5.2s"), convert("bar"), "foo ba"); + DoWStrTest(convert("foo %-5s"), convert("bar"), "foo bar "); + DoWStrTest(convert("foo %05s"), convert("bar"), "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test3/CMakeLists.txt index 6906722cde..53c46369de 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_fwprintf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test3/test3.c deleted file mode 100644 index d718a19067..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test3/test3.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests the wide string specifier (%S). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoStrTest(convert("foo %S"), "bar", "foo bar"); - DoStrTest(convert("foo %hS"), "bar", "foo bar"); - DoWStrTest(convert("foo %lS"), convert("bar"), "foo bar"); - DoWStrTest(convert("foo %wS"), convert("bar"), "foo bar"); - DoStrTest(convert("foo %LS"), "bar", "foo bar"); - DoStrTest(convert("foo %I64S"), "bar", "foo bar"); - DoStrTest(convert("foo %5S"), "bar", "foo bar"); - DoStrTest(convert("foo %.2S"), "bar", "foo ba"); - DoStrTest(convert("foo %5.2S"),"bar", "foo ba"); - DoStrTest(convert("foo %-5S"), "bar", "foo bar "); - DoStrTest(convert("foo %05S"), "bar", "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test3/test3.cpp new file mode 100644 index 0000000000..d718a19067 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test3/test3.cpp @@ -0,0 +1,45 @@ +// 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: test3.c +** +** Purpose: Tests the wide string specifier (%S). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoStrTest(convert("foo %S"), "bar", "foo bar"); + DoStrTest(convert("foo %hS"), "bar", "foo bar"); + DoWStrTest(convert("foo %lS"), convert("bar"), "foo bar"); + DoWStrTest(convert("foo %wS"), convert("bar"), "foo bar"); + DoStrTest(convert("foo %LS"), "bar", "foo bar"); + DoStrTest(convert("foo %I64S"), "bar", "foo bar"); + DoStrTest(convert("foo %5S"), "bar", "foo bar"); + DoStrTest(convert("foo %.2S"), "bar", "foo ba"); + DoStrTest(convert("foo %5.2S"),"bar", "foo ba"); + DoStrTest(convert("foo %-5S"), "bar", "foo bar "); + DoStrTest(convert("foo %05S"), "bar", "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test4/CMakeLists.txt index b91bc87195..9dbb46283e 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_fwprintf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test4/test4.c deleted file mode 100644 index 96fb472c3e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test4/test4.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests the pointer specifier (%p). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, "NULL", "0000000000000000", "0x0"); - DoPointerTest(convert("%p"), ptr, "pointer to 0x123456", "0000000000123456", - "0x123456"); - DoPointerTest(convert("%17p"), ptr, "pointer to 0x123456", " 0000000000123456", - " 0x123456"); - DoPointerTest(convert("%17p"), ptr, "pointer to 0x123456", " 0000000000123456", - "0x0123456"); - DoPointerTest(convert("%-17p"), ptr, "pointer to 0x123456", "0000000000123456 ", - "0x123456 "); - DoPointerTest(convert("%+p"), ptr, "pointer to 0x123456", "0000000000123456", - "0x123456"); - DoPointerTest(convert("%#p"), ptr, "pointer to 0x123456", "0X0000000000123456", - "0x123456"); - DoPointerTest(convert("%lp"), ptr, "pointer to 0x123456", "00123456", - "0x123456"); - DoPointerTest(convert("%hp"), ptr, "pointer to 0x123456", "00003456", - "0x3456"); - DoPointerTest(convert("%Lp"), ptr, "pointer to 0x123456", "00123456", - "0x123456"); - DoI64Test(convert("%I64p"), lptr, "pointer to 0x1234567887654321", - "1234567887654321", "0x1234567887654321"); -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, "NULL", "00000000", "0x0"); - DoPointerTest(convert("%p"), ptr, "pointer to 0x123456", "00123456", - "0x123456"); - DoPointerTest(convert("%9p"), ptr, "pointer to 0x123456", " 00123456", - " 0x123456"); - DoPointerTest(convert("%09p"), ptr, "pointer to 0x123456", " 00123456", - "0x0123456"); - DoPointerTest(convert("%-9p"), ptr, "pointer to 0x123456", "00123456 ", - "0x123456 "); - DoPointerTest(convert("%+p"), ptr, "pointer to 0x123456", "00123456", - "0x123456"); - DoPointerTest(convert("%#p"), ptr, "pointer to 0x123456", "0X00123456", - "0x123456"); - DoPointerTest(convert("%lp"), ptr, "pointer to 0x123456", "00123456", - "0x123456"); - DoPointerTest(convert("%hp"), ptr, "pointer to 0x123456", "00003456", - "0x3456"); - DoPointerTest(convert("%Lp"), ptr, "pointer to 0x123456", "00123456", - "0x123456"); - DoI64Test(convert("%I64p"), lptr, "pointer to 0x1234567887654321", - "1234567887654321", "0x1234567887654321"); -#endif - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test4/test4.cpp new file mode 100644 index 0000000000..96fb472c3e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test4/test4.cpp @@ -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: test4.c +** +** Purpose: Tests the pointer specifier (%p). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, "NULL", "0000000000000000", "0x0"); + DoPointerTest(convert("%p"), ptr, "pointer to 0x123456", "0000000000123456", + "0x123456"); + DoPointerTest(convert("%17p"), ptr, "pointer to 0x123456", " 0000000000123456", + " 0x123456"); + DoPointerTest(convert("%17p"), ptr, "pointer to 0x123456", " 0000000000123456", + "0x0123456"); + DoPointerTest(convert("%-17p"), ptr, "pointer to 0x123456", "0000000000123456 ", + "0x123456 "); + DoPointerTest(convert("%+p"), ptr, "pointer to 0x123456", "0000000000123456", + "0x123456"); + DoPointerTest(convert("%#p"), ptr, "pointer to 0x123456", "0X0000000000123456", + "0x123456"); + DoPointerTest(convert("%lp"), ptr, "pointer to 0x123456", "00123456", + "0x123456"); + DoPointerTest(convert("%hp"), ptr, "pointer to 0x123456", "00003456", + "0x3456"); + DoPointerTest(convert("%Lp"), ptr, "pointer to 0x123456", "00123456", + "0x123456"); + DoI64Test(convert("%I64p"), lptr, "pointer to 0x1234567887654321", + "1234567887654321", "0x1234567887654321"); +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, "NULL", "00000000", "0x0"); + DoPointerTest(convert("%p"), ptr, "pointer to 0x123456", "00123456", + "0x123456"); + DoPointerTest(convert("%9p"), ptr, "pointer to 0x123456", " 00123456", + " 0x123456"); + DoPointerTest(convert("%09p"), ptr, "pointer to 0x123456", " 00123456", + "0x0123456"); + DoPointerTest(convert("%-9p"), ptr, "pointer to 0x123456", "00123456 ", + "0x123456 "); + DoPointerTest(convert("%+p"), ptr, "pointer to 0x123456", "00123456", + "0x123456"); + DoPointerTest(convert("%#p"), ptr, "pointer to 0x123456", "0X00123456", + "0x123456"); + DoPointerTest(convert("%lp"), ptr, "pointer to 0x123456", "00123456", + "0x123456"); + DoPointerTest(convert("%hp"), ptr, "pointer to 0x123456", "00003456", + "0x3456"); + DoPointerTest(convert("%Lp"), ptr, "pointer to 0x123456", "00123456", + "0x123456"); + DoI64Test(convert("%I64p"), lptr, "pointer to 0x1234567887654321", + "1234567887654321", "0x1234567887654321"); +#endif + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test5/CMakeLists.txt index 53bf482b6f..4e72e3ca88 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_fwprintf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test5/test5.c deleted file mode 100644 index 9d95989090..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test5/test5.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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: test5.c -** -** Purpose: Tests the count specifier (%n). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR *longStr; - char *longResult = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - " bar"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - longStr = - convert("really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - "%n bar"); - DoCountTest(convert("foo %n bar"), 4, "foo bar"); - DoCountTest(longStr, 257, longResult); - DoCountTest(convert("fo%n bar"), 2, "fo bar"); - DoCountTest(convert("%n foo"), 0, " foo"); - DoCountTest(convert("foo %#n bar"), 4, "foo bar"); - DoCountTest(convert("foo % n bar"), 4, "foo bar"); - DoCountTest(convert("foo %+n bar"), 4, "foo bar"); - DoCountTest(convert("foo %-n bar"), 4, "foo bar"); - DoCountTest(convert("foo %0n bar"), 4, "foo bar"); - DoShortCountTest(convert("foo %hn bar"), 4, "foo bar"); - DoCountTest(convert("foo %ln bar"), 4, "foo bar"); - DoCountTest(convert("foo %Ln bar"), 4, "foo bar"); - DoCountTest(convert("foo %I64n bar"), 4, "foo bar"); - DoCountTest(convert("foo %20.3n bar"), 4, "foo bar"); - - PAL_Terminate(); - - free(longStr); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test5/test5.cpp new file mode 100644 index 0000000000..9d95989090 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test5/test5.cpp @@ -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: test5.c +** +** Purpose: Tests the count specifier (%n). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR *longStr; + char *longResult = + "really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + " bar"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + longStr = + convert("really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + "%n bar"); + DoCountTest(convert("foo %n bar"), 4, "foo bar"); + DoCountTest(longStr, 257, longResult); + DoCountTest(convert("fo%n bar"), 2, "fo bar"); + DoCountTest(convert("%n foo"), 0, " foo"); + DoCountTest(convert("foo %#n bar"), 4, "foo bar"); + DoCountTest(convert("foo % n bar"), 4, "foo bar"); + DoCountTest(convert("foo %+n bar"), 4, "foo bar"); + DoCountTest(convert("foo %-n bar"), 4, "foo bar"); + DoCountTest(convert("foo %0n bar"), 4, "foo bar"); + DoShortCountTest(convert("foo %hn bar"), 4, "foo bar"); + DoCountTest(convert("foo %ln bar"), 4, "foo bar"); + DoCountTest(convert("foo %Ln bar"), 4, "foo bar"); + DoCountTest(convert("foo %I64n bar"), 4, "foo bar"); + DoCountTest(convert("foo %20.3n bar"), 4, "foo bar"); + + PAL_Terminate(); + + free(longStr); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test6/CMakeLists.txt index bf7d7cccb8..d57f07fafa 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_fwprintf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test6/test6.c deleted file mode 100644 index 160ff524e0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test6/test6.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test6.c -** -** Purpose: Tests the char specifier (%c). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoWCharTest(convert("foo %c"), wb, "foo b"); - DoCharTest(convert("foo %hc"), 'c', "foo c"); - DoWCharTest(convert("foo %lc"), wb, "foo b"); - DoWCharTest(convert("foo %Lc"), wb, "foo b"); - DoWCharTest(convert("foo %I64c"), wb, "foo b"); - DoWCharTest(convert("foo %5c"), wb, "foo b"); - DoWCharTest(convert("foo %.0c"), wb, "foo b"); - DoWCharTest(convert("foo %-5c"), wb, "foo b "); - DoWCharTest(convert("foo %05c"), wb, "foo 0000b"); - DoWCharTest(convert("foo % c"), wb, "foo b"); - DoWCharTest(convert("foo %#c"), wb, "foo b"); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test6/test6.cpp new file mode 100644 index 0000000000..160ff524e0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test6/test6.cpp @@ -0,0 +1,48 @@ +// 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: test6.c +** +** Purpose: Tests the char specifier (%c). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoWCharTest(convert("foo %c"), wb, "foo b"); + DoCharTest(convert("foo %hc"), 'c', "foo c"); + DoWCharTest(convert("foo %lc"), wb, "foo b"); + DoWCharTest(convert("foo %Lc"), wb, "foo b"); + DoWCharTest(convert("foo %I64c"), wb, "foo b"); + DoWCharTest(convert("foo %5c"), wb, "foo b"); + DoWCharTest(convert("foo %.0c"), wb, "foo b"); + DoWCharTest(convert("foo %-5c"), wb, "foo b "); + DoWCharTest(convert("foo %05c"), wb, "foo 0000b"); + DoWCharTest(convert("foo % c"), wb, "foo b"); + DoWCharTest(convert("foo %#c"), wb, "foo b"); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test7/CMakeLists.txt index 68bcc9ca65..314ca353e5 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_fwprintf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test7/test7.c deleted file mode 100644 index c5515a8640..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test7/test7.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test7.c -** -** Purpose: Tests the wide char specifier (%C). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoCharTest(convert("foo %C"), 'c', "foo c"); - DoWCharTest(convert("foo %hc"), wb, "foo b"); - DoCharTest(convert("foo %lC"), 'c', "foo c"); - DoCharTest(convert("foo %LC"), 'c', "foo c"); - DoCharTest(convert("foo %I64C"), 'c', "foo c"); - DoCharTest(convert("foo %5C"), 'c', "foo c"); - DoCharTest(convert("foo %.0C"), 'c', "foo c"); - DoCharTest(convert("foo %-5C"), 'c', "foo c "); - DoCharTest(convert("foo %05C"), 'c', "foo 0000c"); - DoCharTest(convert("foo % C"), 'c', "foo c"); - DoCharTest(convert("foo %#C"), 'c', "foo c"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test7/test7.cpp new file mode 100644 index 0000000000..c5515a8640 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test7/test7.cpp @@ -0,0 +1,47 @@ +// 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: test7.c +** +** Purpose: Tests the wide char specifier (%C). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoCharTest(convert("foo %C"), 'c', "foo c"); + DoWCharTest(convert("foo %hc"), wb, "foo b"); + DoCharTest(convert("foo %lC"), 'c', "foo c"); + DoCharTest(convert("foo %LC"), 'c', "foo c"); + DoCharTest(convert("foo %I64C"), 'c', "foo c"); + DoCharTest(convert("foo %5C"), 'c', "foo c"); + DoCharTest(convert("foo %.0C"), 'c', "foo c"); + DoCharTest(convert("foo %-5C"), 'c', "foo c "); + DoCharTest(convert("foo %05C"), 'c', "foo 0000c"); + DoCharTest(convert("foo % C"), 'c', "foo c"); + DoCharTest(convert("foo %#C"), 'c', "foo c"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test8/CMakeLists.txt index e07cbb9119..e818df2eb2 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_fwprintf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test8/test8.c deleted file mode 100644 index efc81a954a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test8/test8.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test8.c -** -** Purpose: Tests the decimal specifier (%d). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %d"), pos, "foo 42"); - DoNumTest(convert("foo %ld"), 0xFFFF, "foo 65535"); - DoNumTest(convert("foo %hd"), 0xFFFF, "foo -1"); - DoNumTest(convert("foo %Ld"), pos, "foo 42"); - DoI64Test(convert("foo %I64d"), l, "42", "foo 42", "foo 42"); - DoNumTest(convert("foo %3d"), pos, "foo 42"); - DoNumTest(convert("foo %-3d"), pos, "foo 42 "); - DoNumTest(convert("foo %.1d"), pos, "foo 42"); - DoNumTest(convert("foo %.3d"), pos, "foo 042"); - DoNumTest(convert("foo %03d"), pos, "foo 042"); - DoNumTest(convert("foo %#d"), pos, "foo 42"); - DoNumTest(convert("foo %+d"), pos, "foo +42"); - DoNumTest(convert("foo % d"), pos, "foo 42"); - DoNumTest(convert("foo %+d"), neg, "foo -42"); - DoNumTest(convert("foo % d"), neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test8/test8.cpp new file mode 100644 index 0000000000..efc81a954a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test8/test8.cpp @@ -0,0 +1,51 @@ +// 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: test8.c +** +** Purpose: Tests the decimal specifier (%d). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %d"), pos, "foo 42"); + DoNumTest(convert("foo %ld"), 0xFFFF, "foo 65535"); + DoNumTest(convert("foo %hd"), 0xFFFF, "foo -1"); + DoNumTest(convert("foo %Ld"), pos, "foo 42"); + DoI64Test(convert("foo %I64d"), l, "42", "foo 42", "foo 42"); + DoNumTest(convert("foo %3d"), pos, "foo 42"); + DoNumTest(convert("foo %-3d"), pos, "foo 42 "); + DoNumTest(convert("foo %.1d"), pos, "foo 42"); + DoNumTest(convert("foo %.3d"), pos, "foo 042"); + DoNumTest(convert("foo %03d"), pos, "foo 042"); + DoNumTest(convert("foo %#d"), pos, "foo 42"); + DoNumTest(convert("foo %+d"), pos, "foo +42"); + DoNumTest(convert("foo % d"), pos, "foo 42"); + DoNumTest(convert("foo %+d"), neg, "foo -42"); + DoNumTest(convert("foo % d"), neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwprintf/test9/CMakeLists.txt index 898da1a64f..28b6b86921 100644 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_fwprintf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/fwprintf/test9/test9.c deleted file mode 100644 index 23db2d8971..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwprintf/test9/test9.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test9.c -** -** Purpose: Tests the integer specifier (%i). -** This test is modeled after the sprintf series. -** -** -**==========================================================================*/ - -#include -#include "../fwprintf.h" - -/* - * Depends on memcmp, strlen, fopen, fseek and fgets. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest(convert("foo %i"), pos, "foo 42"); - DoNumTest(convert("foo %li"), 0xFFFF, "foo 65535"); - DoNumTest(convert("foo %hi"), 0xFFFF, "foo -1"); - DoNumTest(convert("foo %Li"), pos, "foo 42"); - DoI64Test(convert("foo %I64i"), l, "42", "foo 42", "foo 42"); - DoNumTest(convert("foo %3i"), pos, "foo 42"); - DoNumTest(convert("foo %-3i"), pos, "foo 42 "); - DoNumTest(convert("foo %.1i"), pos, "foo 42"); - DoNumTest(convert("foo %.3i"), pos, "foo 042"); - DoNumTest(convert("foo %03i"), pos, "foo 042"); - DoNumTest(convert("foo %#i"), pos, "foo 42"); - DoNumTest(convert("foo %+i"), pos, "foo +42"); - DoNumTest(convert("foo % i"), pos, "foo 42"); - DoNumTest(convert("foo %+i"), neg, "foo -42"); - DoNumTest(convert("foo % i"), neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/fwprintf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/fwprintf/test9/test9.cpp new file mode 100644 index 0000000000..23db2d8971 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwprintf/test9/test9.cpp @@ -0,0 +1,51 @@ +// 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: test9.c +** +** Purpose: Tests the integer specifier (%i). +** This test is modeled after the sprintf series. +** +** +**==========================================================================*/ + +#include +#include "../fwprintf.h" + +/* + * Depends on memcmp, strlen, fopen, fseek and fgets. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %i"), pos, "foo 42"); + DoNumTest(convert("foo %li"), 0xFFFF, "foo 65535"); + DoNumTest(convert("foo %hi"), 0xFFFF, "foo -1"); + DoNumTest(convert("foo %Li"), pos, "foo 42"); + DoI64Test(convert("foo %I64i"), l, "42", "foo 42", "foo 42"); + DoNumTest(convert("foo %3i"), pos, "foo 42"); + DoNumTest(convert("foo %-3i"), pos, "foo 42 "); + DoNumTest(convert("foo %.1i"), pos, "foo 42"); + DoNumTest(convert("foo %.3i"), pos, "foo 042"); + DoNumTest(convert("foo %03i"), pos, "foo 042"); + DoNumTest(convert("foo %#i"), pos, "foo 42"); + DoNumTest(convert("foo %+i"), pos, "foo +42"); + DoNumTest(convert("foo % i"), pos, "foo 42"); + DoNumTest(convert("foo %+i"), neg, "foo -42"); + DoNumTest(convert("foo % i"), neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fwrite/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fwrite/test1/CMakeLists.txt index 701e56acb5..5c8b7449f2 100644 --- a/src/pal/tests/palsuite/c_runtime/fwrite/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fwrite/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_fwrite_test1 diff --git a/src/pal/tests/palsuite/c_runtime/fwrite/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fwrite/test1/test1.c deleted file mode 100644 index 392522879f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/fwrite/test1/test1.c +++ /dev/null @@ -1,104 +0,0 @@ -// 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: test1.c -** -** Purpose: Write a short string to a file and check that it was written -** properly. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - const char filename[] = "testfile.tmp"; - const char outBuffer[] = "This is a test."; - char inBuffer[sizeof(outBuffer) + 10]; - int itemsExpected; - int itemsWritten; - FILE * fp = NULL; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - if((fp = fopen(filename, "w")) == NULL) - { - Fail("Unable to open a file for write.\n"); - } - - itemsExpected = sizeof(outBuffer); - itemsWritten = fwrite(outBuffer, - sizeof(outBuffer[0]), - sizeof(outBuffer), - fp); - - if (itemsWritten == 0) - { - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - Fail("fwrite() couldn't write to a stream at all\n"); - } - else if (itemsWritten != itemsExpected) - { - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - Fail("fwrite() produced errors writing to a stream.\n"); - } - - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - /* open the file to verify what was written to the file */ - if ((fp = fopen(filename, "r")) == NULL) - { - Fail("Couldn't open newly written file for read.\n"); - } - - if (fgets(inBuffer, sizeof(inBuffer), fp) == NULL) - { - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - Fail("We wrote something to a file using fwrite() and got errors" - " when we tried to read it back using fgets(). Either " - "fwrite() or fgets() is broken.\n"); - } - - if (strcmp(inBuffer, outBuffer) != 0) - { - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - Fail("fwrite() (or fgets()) is broken. The string read back from" - " the file does not match the string written.\n"); - } - - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/fwrite/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/fwrite/test1/test1.cpp new file mode 100644 index 0000000000..392522879f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fwrite/test1/test1.cpp @@ -0,0 +1,104 @@ +// 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: test1.c +** +** Purpose: Write a short string to a file and check that it was written +** properly. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + const char filename[] = "testfile.tmp"; + const char outBuffer[] = "This is a test."; + char inBuffer[sizeof(outBuffer) + 10]; + int itemsExpected; + int itemsWritten; + FILE * fp = NULL; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + if((fp = fopen(filename, "w")) == NULL) + { + Fail("Unable to open a file for write.\n"); + } + + itemsExpected = sizeof(outBuffer); + itemsWritten = fwrite(outBuffer, + sizeof(outBuffer[0]), + sizeof(outBuffer), + fp); + + if (itemsWritten == 0) + { + if(fclose(fp) != 0) + { + Fail("fwrite: Error occurred during the closing of a file.\n"); + } + + Fail("fwrite() couldn't write to a stream at all\n"); + } + else if (itemsWritten != itemsExpected) + { + if(fclose(fp) != 0) + { + Fail("fwrite: Error occurred during the closing of a file.\n"); + } + + Fail("fwrite() produced errors writing to a stream.\n"); + } + + if(fclose(fp) != 0) + { + Fail("fwrite: Error occurred during the closing of a file.\n"); + } + + /* open the file to verify what was written to the file */ + if ((fp = fopen(filename, "r")) == NULL) + { + Fail("Couldn't open newly written file for read.\n"); + } + + if (fgets(inBuffer, sizeof(inBuffer), fp) == NULL) + { + if(fclose(fp) != 0) + { + Fail("fwrite: Error occurred during the closing of a file.\n"); + } + + Fail("We wrote something to a file using fwrite() and got errors" + " when we tried to read it back using fgets(). Either " + "fwrite() or fgets() is broken.\n"); + } + + if (strcmp(inBuffer, outBuffer) != 0) + { + if(fclose(fp) != 0) + { + Fail("fwrite: Error occurred during the closing of a file.\n"); + } + + Fail("fwrite() (or fgets()) is broken. The string read back from" + " the file does not match the string written.\n"); + } + + if(fclose(fp) != 0) + { + Fail("fwrite: Error occurred during the closing of a file.\n"); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/getc/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/getc/test1/CMakeLists.txt index 2a29e8af0a..68ecaa9abb 100644 --- a/src/pal/tests/palsuite/c_runtime/getc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/getc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - getc.c + getc.cpp ) add_executable(paltest_getc_test1 diff --git a/src/pal/tests/palsuite/c_runtime/getc/test1/getc.c b/src/pal/tests/palsuite/c_runtime/getc/test1/getc.c deleted file mode 100644 index dfe10d6160..0000000000 --- a/src/pal/tests/palsuite/c_runtime/getc/test1/getc.c +++ /dev/null @@ -1,152 +0,0 @@ -// 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: getc.c (test 1) -** -** Purpose: Tests the PAL implementation of the getc function. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - const char szFileName[] = {"testfile.tmp"}; - const char szTestString[] = - {"The quick brown fox jumped over the lazy dog's back."}; - FILE* pFile = NULL; - int nCount = 0; - int nChar = 0; - char szBuiltString[256]; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - memset(szBuiltString, 0, 256); - - - /* create/open a file for read and write */ - pFile = fopen(szFileName, "w+"); - if (pFile == NULL) - { - Fail("getc: ERROR -> fopen failed to create the file %s with the " - "error code %ld\n", - szFileName, - GetLastError()); - } - - /* try reading from an empty file */ - if ((nChar = getc(pFile)) != EOF) - { - Trace("getc: ERROR -> getc returned \"%c\" when run on " - "an empty file.\n", nChar); - if (fclose(pFile) != 0) - { - Trace("getc: ERROR -> fclose failed to close the file. " - "GetLastError returned %ld\n", - GetLastError()); - } - Fail(""); - } - - // Move the file pointer back to the beginning of the file. Some - // platforms require an fseek() between a getc() that returns EOF - // and any subsequent output to the file. - if (fseek(pFile, 0, SEEK_SET) != 0) - { - Trace("getc: ERROR -> fseek failed to move the file pointer to the " - "beginning of the file. GetLastError returned %ld\n", - GetLastError()); - if (fclose(pFile) != 0) - { - Trace("getc: ERROR -> fclose failed to close the file. " - "GetLastError returned %ld\n", - GetLastError()); - } - Fail(""); - } - - /* populate the file with a known string */ - nCount = fprintf(pFile, szTestString); - if (nCount != strlen(szTestString)) - { - Fail("getc: ERROR -> fprintf failed to write %s. The string is %d " - "characters long but fprintf apparently only wrote %d characters." - " GetLastError returned %ld\n", - szTestString, - strlen(szTestString), - nCount, - GetLastError()); - } - - /* move the file pointer back to the beginning of the file */ - if (fseek(pFile, 0, SEEK_SET) != 0) - { - Trace("getc: ERROR -> fseek failed to move the file pointer to the " - "beginning of the file. GetLastError returned %ld\n", - GetLastError()); - if (fclose(pFile) != 0) - { - Trace("getc: ERROR -> fclose failed to close the file. " - "GetLastError returned %ld\n", - GetLastError()); - } - Fail(""); - } - - /* now get the characters one at a time */ - nCount = 0; - while ((nChar = getc(pFile)) != EOF) - { - szBuiltString[nCount++] = nChar; - } - - /* now, let's see if it worked */ - if (strcmp(szBuiltString, szTestString) != 0) - { - Trace("getc: ERROR -> Reading one char at a time, getc built \"%s\" " - "however it should have built \"%s\".\n", - szBuiltString, - szTestString); - if (fclose(pFile) != 0) - { - Trace("getc: ERROR -> fclose failed to close the file. " - "GetLastError returned %ld\n", - GetLastError()); - } - Fail(""); - } - - /* with the file pointer at EOF, try reading past EOF*/ - if ((nChar = getc(pFile)) != EOF) - { - Trace("getc: ERROR -> getc returned \"%c\" when reading past " - "the end of the file.\n", nChar); - if (fclose(pFile) != 0) - { - Trace("getc: ERROR -> fclose failed to close the file. " - "GetLastError returned %ld\n", - GetLastError()); - } - Fail(""); - } - - if (fclose(pFile) != 0) - { - Fail("getc: ERROR -> fclose failed to close the file. " - "GetLastError returned %ld\n", - GetLastError()); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/getc/test1/getc.cpp b/src/pal/tests/palsuite/c_runtime/getc/test1/getc.cpp new file mode 100644 index 0000000000..dfe10d6160 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/getc/test1/getc.cpp @@ -0,0 +1,152 @@ +// 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: getc.c (test 1) +** +** Purpose: Tests the PAL implementation of the getc function. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + const char szFileName[] = {"testfile.tmp"}; + const char szTestString[] = + {"The quick brown fox jumped over the lazy dog's back."}; + FILE* pFile = NULL; + int nCount = 0; + int nChar = 0; + char szBuiltString[256]; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + memset(szBuiltString, 0, 256); + + + /* create/open a file for read and write */ + pFile = fopen(szFileName, "w+"); + if (pFile == NULL) + { + Fail("getc: ERROR -> fopen failed to create the file %s with the " + "error code %ld\n", + szFileName, + GetLastError()); + } + + /* try reading from an empty file */ + if ((nChar = getc(pFile)) != EOF) + { + Trace("getc: ERROR -> getc returned \"%c\" when run on " + "an empty file.\n", nChar); + if (fclose(pFile) != 0) + { + Trace("getc: ERROR -> fclose failed to close the file. " + "GetLastError returned %ld\n", + GetLastError()); + } + Fail(""); + } + + // Move the file pointer back to the beginning of the file. Some + // platforms require an fseek() between a getc() that returns EOF + // and any subsequent output to the file. + if (fseek(pFile, 0, SEEK_SET) != 0) + { + Trace("getc: ERROR -> fseek failed to move the file pointer to the " + "beginning of the file. GetLastError returned %ld\n", + GetLastError()); + if (fclose(pFile) != 0) + { + Trace("getc: ERROR -> fclose failed to close the file. " + "GetLastError returned %ld\n", + GetLastError()); + } + Fail(""); + } + + /* populate the file with a known string */ + nCount = fprintf(pFile, szTestString); + if (nCount != strlen(szTestString)) + { + Fail("getc: ERROR -> fprintf failed to write %s. The string is %d " + "characters long but fprintf apparently only wrote %d characters." + " GetLastError returned %ld\n", + szTestString, + strlen(szTestString), + nCount, + GetLastError()); + } + + /* move the file pointer back to the beginning of the file */ + if (fseek(pFile, 0, SEEK_SET) != 0) + { + Trace("getc: ERROR -> fseek failed to move the file pointer to the " + "beginning of the file. GetLastError returned %ld\n", + GetLastError()); + if (fclose(pFile) != 0) + { + Trace("getc: ERROR -> fclose failed to close the file. " + "GetLastError returned %ld\n", + GetLastError()); + } + Fail(""); + } + + /* now get the characters one at a time */ + nCount = 0; + while ((nChar = getc(pFile)) != EOF) + { + szBuiltString[nCount++] = nChar; + } + + /* now, let's see if it worked */ + if (strcmp(szBuiltString, szTestString) != 0) + { + Trace("getc: ERROR -> Reading one char at a time, getc built \"%s\" " + "however it should have built \"%s\".\n", + szBuiltString, + szTestString); + if (fclose(pFile) != 0) + { + Trace("getc: ERROR -> fclose failed to close the file. " + "GetLastError returned %ld\n", + GetLastError()); + } + Fail(""); + } + + /* with the file pointer at EOF, try reading past EOF*/ + if ((nChar = getc(pFile)) != EOF) + { + Trace("getc: ERROR -> getc returned \"%c\" when reading past " + "the end of the file.\n", nChar); + if (fclose(pFile) != 0) + { + Trace("getc: ERROR -> fclose failed to close the file. " + "GetLastError returned %ld\n", + GetLastError()); + } + Fail(""); + } + + if (fclose(pFile) != 0) + { + Fail("getc: ERROR -> fclose failed to close the file. " + "GetLastError returned %ld\n", + GetLastError()); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/getenv/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/getenv/test1/CMakeLists.txt index 6243c032ab..9c52c2890e 100644 --- a/src/pal/tests/palsuite/c_runtime/getenv/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/getenv/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getenv_test1 diff --git a/src/pal/tests/palsuite/c_runtime/getenv/test1/test1.c b/src/pal/tests/palsuite/c_runtime/getenv/test1/test1.c deleted file mode 100644 index 0fb9025c8f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/getenv/test1/test1.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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: test1.c -** -** Purpose: Create an environment variable and then use getenv to get -** a pointer to it. Check that the pointer is valid and that the string -** is what we expected. Also check that searching for a non-existent -** variable will cause getenv to return NULL. Also check that function -** passes when the parameter has it's casing changed (e.g upper case) -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - const char* SetVariable = "PalTestingEnvironmentVariable=The value"; - const char* VariableName = "PalTestingEnvironmentVariable"; - const char* VariableValue = "The value"; - char* result; - - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Use _putenv to set an environment variable. This ensures that the - variable we're testing on is always present. - */ - - if(_putenv(SetVariable) == -1) - { - Fail("ERROR: _putenv failed to set an environment variable that " - "getenv will be using for testing.\n"); - } - - /* Call getenv -- ensure it doesn't return NULL and the string it returns - is the value we set above. - */ - - result = getenv(VariableName); - if(result == NULL) - { - Fail("ERROR: The result of getenv on a valid Environment Variable " - "was NULL, which indicates the environment varaible was not " - "found.\n"); - } - - if(strcmp(result, VariableValue) != 0) - { - Fail("ERROR: The value obtained by getenv() was not equal to the " - "correct value of the environment variable. The correct " - "value is '%s' and the function returned '%s'.\n", - VariableValue, - result); - } - - /* Try calling getenv on an environment variable which doesn't - exist. - */ - result = getenv("SomeEnvironmentVariableThatReallyDoesNotExist"); - - if(result != NULL) - { - Fail("ERROR: Called getenv on an environment variable which " - "doesn't exist and it returned '%s' instead of NULL.\n",result); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/getenv/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/getenv/test1/test1.cpp new file mode 100644 index 0000000000..0fb9025c8f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/getenv/test1/test1.cpp @@ -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: test1.c +** +** Purpose: Create an environment variable and then use getenv to get +** a pointer to it. Check that the pointer is valid and that the string +** is what we expected. Also check that searching for a non-existent +** variable will cause getenv to return NULL. Also check that function +** passes when the parameter has it's casing changed (e.g upper case) +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + const char* SetVariable = "PalTestingEnvironmentVariable=The value"; + const char* VariableName = "PalTestingEnvironmentVariable"; + const char* VariableValue = "The value"; + char* result; + + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Use _putenv to set an environment variable. This ensures that the + variable we're testing on is always present. + */ + + if(_putenv(SetVariable) == -1) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + /* Call getenv -- ensure it doesn't return NULL and the string it returns + is the value we set above. + */ + + result = getenv(VariableName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, VariableValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + VariableValue, + result); + } + + /* Try calling getenv on an environment variable which doesn't + exist. + */ + result = getenv("SomeEnvironmentVariableThatReallyDoesNotExist"); + + if(result != NULL) + { + Fail("ERROR: Called getenv on an environment variable which " + "doesn't exist and it returned '%s' instead of NULL.\n",result); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/getenv/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/getenv/test2/CMakeLists.txt index 7a301a5ca6..971a836239 100644 --- a/src/pal/tests/palsuite/c_runtime/getenv/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/getenv/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_getenv_test2 diff --git a/src/pal/tests/palsuite/c_runtime/getenv/test2/test2.c b/src/pal/tests/palsuite/c_runtime/getenv/test2/test2.c deleted file mode 100644 index 26f245fcce..0000000000 --- a/src/pal/tests/palsuite/c_runtime/getenv/test2/test2.c +++ /dev/null @@ -1,101 +0,0 @@ -// 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: test2.c -** -** Purpose: Create environment variables that differ only in Case, and -** verify that the BSD operating system treats the variables -** differently. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ -#if WIN32 - - return PASS; - -#else - - const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; - const char* SecondVariable = "PALTESTINGEnvironmentVariable=Different value"; - const char* FirstVarName = "PalTestingEnvironmentVariable"; - const char* SecondVarName = "PALTESTINGEnvironmentVariable"; - const char* FirstVarValue = "The value"; - const char* SecondVarValue = "Different value"; - char* result; - - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Use _putenv to set the environment variables. This ensures that the - variables we're testing with are always present. - */ - if(_putenv(FirstVariable) != 0) - { - Fail("ERROR: _putenv failed to set an environment variable that " - "getenv will be using for testing.\n"); - } - - if(_putenv(SecondVariable) != 0) - { - Fail("ERROR: _putenv failed to set an environment variable that " - "getenv will be using for testing.\n"); - } - - - /* Call getenv -- ensure it doesn't return NULL and the string it returns - is the value we set above. Also make sure that each environment variable, - differing only by case, returns it's own value. - */ - - result = getenv(FirstVarName); - if(result == NULL) - { - Fail("ERROR: The result of getenv on a valid Environment Variable " - "was NULL, which indicates the environment varaible was not " - "found.\n"); - } - - if(strcmp(result, FirstVarValue) != 0) - { - Fail("ERROR: The value obtained by getenv() was not equal to the " - "correct value of the environment variable. The correct " - "value is '%s' and the function returned '%s'.\n", - FirstVarValue, - result); - } - - - result = getenv(SecondVarName); - if(result == NULL) - { - Fail("ERROR: The result of getenv on a valid Environment Variable " - "was NULL, which indicates the environment varaible was not " - "found.\n"); - } - - if(strcmp(result, SecondVarValue) != 0) - { - Fail("ERROR: The value obtained by getenv() was not equal to the " - "correct value of the environment variable. The correct " - "value is '%s' and the function returned '%s'.\n", - SecondVarValue, - result); - } - - - PAL_Terminate(); - return PASS; - -#endif -} diff --git a/src/pal/tests/palsuite/c_runtime/getenv/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/getenv/test2/test2.cpp new file mode 100644 index 0000000000..26f245fcce --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/getenv/test2/test2.cpp @@ -0,0 +1,101 @@ +// 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: test2.c +** +** Purpose: Create environment variables that differ only in Case, and +** verify that the BSD operating system treats the variables +** differently. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ +#if WIN32 + + return PASS; + +#else + + const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; + const char* SecondVariable = "PALTESTINGEnvironmentVariable=Different value"; + const char* FirstVarName = "PalTestingEnvironmentVariable"; + const char* SecondVarName = "PALTESTINGEnvironmentVariable"; + const char* FirstVarValue = "The value"; + const char* SecondVarValue = "Different value"; + char* result; + + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Use _putenv to set the environment variables. This ensures that the + variables we're testing with are always present. + */ + if(_putenv(FirstVariable) != 0) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + if(_putenv(SecondVariable) != 0) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + + /* Call getenv -- ensure it doesn't return NULL and the string it returns + is the value we set above. Also make sure that each environment variable, + differing only by case, returns it's own value. + */ + + result = getenv(FirstVarName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, FirstVarValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + FirstVarValue, + result); + } + + + result = getenv(SecondVarName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, SecondVarValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + SecondVarValue, + result); + } + + + PAL_Terminate(); + return PASS; + +#endif +} diff --git a/src/pal/tests/palsuite/c_runtime/getenv/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/getenv/test3/CMakeLists.txt index 2cbe472221..620ccd1003 100644 --- a/src/pal/tests/palsuite/c_runtime/getenv/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/getenv/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_getenv_test3 diff --git a/src/pal/tests/palsuite/c_runtime/getenv/test3/test3.c b/src/pal/tests/palsuite/c_runtime/getenv/test3/test3.c deleted file mode 100644 index 1eefd9d40c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/getenv/test3/test3.c +++ /dev/null @@ -1,75 +0,0 @@ -// 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: test3.c -** -** Purpose: Create an environment variable and try to retrieve -** it using the same name but with different case. This -** is to show that the Win32 representation of getenv -** is case insensitive. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ -#if WIN32 - - const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; - const char* ModifiedName = "PALTESTINGEnvironmentVariable"; - const char* FirstVarValue = "The value"; - char* result; - - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Use _putenv to set an environment variable. This ensures that the - variable we're testing on is always present. - */ - - if(_putenv(FirstVariable) != 0) - { - Fail("ERROR: _putenv failed to set an environment variable that " - "getenv will be using for testing.\n"); - } - - - /* Call getenv -- ensure it doesn't return NULL and the string it returns - is the value we set above. Also make sure that each environment variable, - differing only by case, doesn't affect the return value. - */ - - result = getenv(ModifiedName); - if(result == NULL) - { - Fail("ERROR: The result of getenv on a valid Environment Variable " - "was NULL, which indicates the environment varaible was not " - "found.\n"); - } - - if(strcmp(result, FirstVarValue) != 0) - { - Fail("ERROR: The value obtained by getenv() was not equal to the " - "correct value of the environment variable. The correct " - "value is '%s' and the function returned '%s'.\n", - FirstVarValue, - result); - } - - - PAL_Terminate(); - return PASS; - -#else - return PASS; - -#endif -} diff --git a/src/pal/tests/palsuite/c_runtime/getenv/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/getenv/test3/test3.cpp new file mode 100644 index 0000000000..1eefd9d40c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/getenv/test3/test3.cpp @@ -0,0 +1,75 @@ +// 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: test3.c +** +** Purpose: Create an environment variable and try to retrieve +** it using the same name but with different case. This +** is to show that the Win32 representation of getenv +** is case insensitive. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ +#if WIN32 + + const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; + const char* ModifiedName = "PALTESTINGEnvironmentVariable"; + const char* FirstVarValue = "The value"; + char* result; + + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Use _putenv to set an environment variable. This ensures that the + variable we're testing on is always present. + */ + + if(_putenv(FirstVariable) != 0) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + + /* Call getenv -- ensure it doesn't return NULL and the string it returns + is the value we set above. Also make sure that each environment variable, + differing only by case, doesn't affect the return value. + */ + + result = getenv(ModifiedName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, FirstVarValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + FirstVarValue, + result); + } + + + PAL_Terminate(); + return PASS; + +#else + return PASS; + +#endif +} diff --git a/src/pal/tests/palsuite/c_runtime/isalnum/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isalnum/test1/CMakeLists.txt index 3879bb7902..af65f32cbf 100644 --- a/src/pal/tests/palsuite/c_runtime/isalnum/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/isalnum/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isalnum_test1 diff --git a/src/pal/tests/palsuite/c_runtime/isalnum/test1/test1.c b/src/pal/tests/palsuite/c_runtime/isalnum/test1/test1.c deleted file mode 100644 index d9cdfcadf6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/isalnum/test1/test1.c +++ /dev/null @@ -1,88 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the isalnum function -** Check that a number of characters return the correct -** values for whether they are alpha/numeric or not. -** -** -**===================================================================*/ - -#include - - -struct testCase -{ - int CorrectResult; - int character; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - struct testCase testCases[] = - { - {1, 'a'}, - {1, 'z'}, - {1, 'B'}, - {1, '5'}, - {1, '0'}, - {0, '?'}, - {0, 230} - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through each case. Check to see if each is alpha/numeric or - not. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - - result = isalnum(testCases[i].character); - - /* The return value is 'non-zero' for success. This if condition - * will still work if that non-zero isn't just 1 - */ - if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || - ( (testCases[i].CorrectResult == 0) && (result != 0) )) - { - Fail("ERROR: isalnum returned %i instead of %i for character " - " %c.\n", - result, - testCases[i].CorrectResult, - testCases[i].character); - } - - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/isalnum/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/isalnum/test1/test1.cpp new file mode 100644 index 0000000000..d9cdfcadf6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isalnum/test1/test1.cpp @@ -0,0 +1,88 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the isalnum function +** Check that a number of characters return the correct +** values for whether they are alpha/numeric or not. +** +** +**===================================================================*/ + +#include + + +struct testCase +{ + int CorrectResult; + int character; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + struct testCase testCases[] = + { + {1, 'a'}, + {1, 'z'}, + {1, 'B'}, + {1, '5'}, + {1, '0'}, + {0, '?'}, + {0, 230} + }; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through each case. Check to see if each is alpha/numeric or + not. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + + result = isalnum(testCases[i].character); + + /* The return value is 'non-zero' for success. This if condition + * will still work if that non-zero isn't just 1 + */ + if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || + ( (testCases[i].CorrectResult == 0) && (result != 0) )) + { + Fail("ERROR: isalnum returned %i instead of %i for character " + " %c.\n", + result, + testCases[i].CorrectResult, + testCases[i].character); + } + + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/isalpha/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isalpha/test1/CMakeLists.txt index 44fb72d7fe..82f19ad383 100644 --- a/src/pal/tests/palsuite/c_runtime/isalpha/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/isalpha/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isalpha_test1 diff --git a/src/pal/tests/palsuite/c_runtime/isalpha/test1/test1.c b/src/pal/tests/palsuite/c_runtime/isalpha/test1/test1.c deleted file mode 100644 index b494d14a92..0000000000 --- a/src/pal/tests/palsuite/c_runtime/isalpha/test1/test1.c +++ /dev/null @@ -1,86 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the isalpha function -** Check that a number of characters return the correct -** values for whether they are alpha or not. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - int CorrectResult; - int character; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - struct testCase testCases[] = - { - {1, 'a'}, - {1, 'z'}, - {1, 'B'}, - {0, '5'}, - {0, '?'}, - {0, 230} - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through each case. Check to see if each is alpha or - not. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - - result = isalpha(testCases[i].character); - - /* The return value is 'non-zero' for success. This if condition - * will still work if that non-zero isn't just 1 - */ - if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || - ( (testCases[i].CorrectResult == 0) && (result != 0) )) - { - Fail("ERROR: isalpha returned %i instead of %i for character " - "%c.\n", - result, - testCases[i].CorrectResult, - testCases[i].character); - } - - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/isalpha/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/isalpha/test1/test1.cpp new file mode 100644 index 0000000000..b494d14a92 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isalpha/test1/test1.cpp @@ -0,0 +1,86 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the isalpha function +** Check that a number of characters return the correct +** values for whether they are alpha or not. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + int CorrectResult; + int character; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + struct testCase testCases[] = + { + {1, 'a'}, + {1, 'z'}, + {1, 'B'}, + {0, '5'}, + {0, '?'}, + {0, 230} + }; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through each case. Check to see if each is alpha or + not. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + + result = isalpha(testCases[i].character); + + /* The return value is 'non-zero' for success. This if condition + * will still work if that non-zero isn't just 1 + */ + if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || + ( (testCases[i].CorrectResult == 0) && (result != 0) )) + { + Fail("ERROR: isalpha returned %i instead of %i for character " + "%c.\n", + result, + testCases[i].CorrectResult, + testCases[i].character); + } + + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/isdigit/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isdigit/test1/CMakeLists.txt index dd03b238e1..b96b7aa706 100644 --- a/src/pal/tests/palsuite/c_runtime/isdigit/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/isdigit/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isdigit_test1 diff --git a/src/pal/tests/palsuite/c_runtime/isdigit/test1/test1.c b/src/pal/tests/palsuite/c_runtime/isdigit/test1/test1.c deleted file mode 100644 index ad2344827f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/isdigit/test1/test1.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test1.c -** -** Purpose: Checks every character against the known range of digits. -** -** -**==========================================================================*/ - - -#include - -int __cdecl main(int argc, char *argv[]) -{ - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - for (i=0; i<256; i++) - { - if (isdigit(i)) - { - if (i < '0' || i > '9') - { - Fail("ERROR: isdigit returned true for '%c' (%d)!\n", i, i); - } - } - else - { - if (i >= '0' && i <= '9') - { - Fail("ERROR: isdigit returned false for '%c' (%d)!\n", i, i); - } - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/isdigit/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/isdigit/test1/test1.cpp new file mode 100644 index 0000000000..ad2344827f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isdigit/test1/test1.cpp @@ -0,0 +1,47 @@ +// 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: test1.c +** +** Purpose: Checks every character against the known range of digits. +** +** +**==========================================================================*/ + + +#include + +int __cdecl main(int argc, char *argv[]) +{ + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + for (i=0; i<256; i++) + { + if (isdigit(i)) + { + if (i < '0' || i > '9') + { + Fail("ERROR: isdigit returned true for '%c' (%d)!\n", i, i); + } + } + else + { + if (i >= '0' && i <= '9') + { + Fail("ERROR: isdigit returned false for '%c' (%d)!\n", i, i); + } + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/islower/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/islower/test1/CMakeLists.txt index b7f5ad069f..d071d4bb65 100644 --- a/src/pal/tests/palsuite/c_runtime/islower/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/islower/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_islower_test1 diff --git a/src/pal/tests/palsuite/c_runtime/islower/test1/test1.c b/src/pal/tests/palsuite/c_runtime/islower/test1/test1.c deleted file mode 100644 index c8e877b705..0000000000 --- a/src/pal/tests/palsuite/c_runtime/islower/test1/test1.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the islower function -** Check that a number of characters return the correct -** values for whether they are lower case or not. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - int CorrectResult; - int character; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - struct testCase testCases[] = - { - {1, 'a'}, /* Basic cases */ - {1, 'z'}, - {0, 'B'}, /* Lower case */ - {0, '?'}, /* Characters without case */ - {0, 230}, - {0, '5'} - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through each case. Check to see if each is lower case or - not. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - - result = islower(testCases[i].character); - - /* The return value is 'non-zero' for success. This if condition - * will still work if that non-zero isn't just 1 - */ - if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || - ( (testCases[i].CorrectResult == 0) && (result != 0) )) - { - Fail("ERROR: islower returned %i instead of %i for " - "character %c.\n", - result, testCases[i].CorrectResult, - testCases[i].character); - } - - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/islower/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/islower/test1/test1.cpp new file mode 100644 index 0000000000..c8e877b705 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/islower/test1/test1.cpp @@ -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: test1.c +** +** Purpose: Tests the PAL implementation of the islower function +** Check that a number of characters return the correct +** values for whether they are lower case or not. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + int CorrectResult; + int character; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + struct testCase testCases[] = + { + {1, 'a'}, /* Basic cases */ + {1, 'z'}, + {0, 'B'}, /* Lower case */ + {0, '?'}, /* Characters without case */ + {0, 230}, + {0, '5'} + }; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through each case. Check to see if each is lower case or + not. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + + result = islower(testCases[i].character); + + /* The return value is 'non-zero' for success. This if condition + * will still work if that non-zero isn't just 1 + */ + if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || + ( (testCases[i].CorrectResult == 0) && (result != 0) )) + { + Fail("ERROR: islower returned %i instead of %i for " + "character %c.\n", + result, testCases[i].CorrectResult, + testCases[i].character); + } + + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/isprint/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isprint/test1/CMakeLists.txt index 365777ab5a..91410a02ab 100644 --- a/src/pal/tests/palsuite/c_runtime/isprint/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/isprint/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - isprint.c + isprint.cpp ) add_executable(paltest_isprint_test1 diff --git a/src/pal/tests/palsuite/c_runtime/isprint/test1/isprint.c b/src/pal/tests/palsuite/c_runtime/isprint/test1/isprint.c deleted file mode 100644 index 54db666bf2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/isprint/test1/isprint.c +++ /dev/null @@ -1,42 +0,0 @@ -// 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: isprint.c -** -** Purpose: Positive test the isprint API. -** Call isprint to test if a character is printable -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - int index; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*check if the character is printable*/ - for(index = 0x20; index<=0x7E;index++) - { - err = isprint(index); - if(0 == err) - { - Fail("\nFailed to call isprint API to check " - "printable character from 0x20 to 0x7E!\n"); - } - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/isprint/test1/isprint.cpp b/src/pal/tests/palsuite/c_runtime/isprint/test1/isprint.cpp new file mode 100644 index 0000000000..54db666bf2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isprint/test1/isprint.cpp @@ -0,0 +1,42 @@ +// 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: isprint.c +** +** Purpose: Positive test the isprint API. +** Call isprint to test if a character is printable +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + int index; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*check if the character is printable*/ + for(index = 0x20; index<=0x7E;index++) + { + err = isprint(index); + if(0 == err) + { + Fail("\nFailed to call isprint API to check " + "printable character from 0x20 to 0x7E!\n"); + } + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/isprint/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isprint/test2/CMakeLists.txt index a7ad75cc04..53ad94273c 100644 --- a/src/pal/tests/palsuite/c_runtime/isprint/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/isprint/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_isprint_test2 diff --git a/src/pal/tests/palsuite/c_runtime/isprint/test2/test2.c b/src/pal/tests/palsuite/c_runtime/isprint/test2/test2.c deleted file mode 100644 index 2170c47a14..0000000000 --- a/src/pal/tests/palsuite/c_runtime/isprint/test2/test2.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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: isprint.c -** -** Purpose: Negative test for the isprint API. Call isprint -** to test if out of range characters are -** not printable. -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*check that function fails for values that are not printable*/ - err = isprint(0x15); - if(err) - { - Fail("\nSucceeded when it should have failed because 0x15 " - "is not in the range of printable characters\n"); - } - - err = isprint(0xAA); - if(err) - { - Fail("\nSucceeded when it should have failed because 0xAA " - "is not in the range of printable characters\n"); - } - - /* check carriage return */ - if(0 != isprint(0x0d)) - { - Fail("\nSucceeded when it should have failed because 0x0d " - "is not in the range of printable characters\n"); - } - - /* check line feed */ - if(0 != isprint(0x0a)) - { - Fail("\nSucceeded when it should have failed because 0x0a " - "is not in the range of printable characters\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/isprint/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/isprint/test2/test2.cpp new file mode 100644 index 0000000000..2170c47a14 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isprint/test2/test2.cpp @@ -0,0 +1,59 @@ +// 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: isprint.c +** +** Purpose: Negative test for the isprint API. Call isprint +** to test if out of range characters are +** not printable. +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*check that function fails for values that are not printable*/ + err = isprint(0x15); + if(err) + { + Fail("\nSucceeded when it should have failed because 0x15 " + "is not in the range of printable characters\n"); + } + + err = isprint(0xAA); + if(err) + { + Fail("\nSucceeded when it should have failed because 0xAA " + "is not in the range of printable characters\n"); + } + + /* check carriage return */ + if(0 != isprint(0x0d)) + { + Fail("\nSucceeded when it should have failed because 0x0d " + "is not in the range of printable characters\n"); + } + + /* check line feed */ + if(0 != isprint(0x0a)) + { + Fail("\nSucceeded when it should have failed because 0x0a " + "is not in the range of printable characters\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/isspace/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isspace/test1/CMakeLists.txt index 34ad70d328..c3cc525145 100644 --- a/src/pal/tests/palsuite/c_runtime/isspace/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/isspace/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isspace_test1 diff --git a/src/pal/tests/palsuite/c_runtime/isspace/test1/test1.c b/src/pal/tests/palsuite/c_runtime/isspace/test1/test1.c deleted file mode 100644 index 6cd1ce878b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/isspace/test1/test1.c +++ /dev/null @@ -1,82 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the isspace function -** -** -**==========================================================================*/ - - - -#include - -struct testCase -{ - long result; - char avalue; -}; - - - -int __cdecl main(int argc, char *argv[]) -{ - int i=0; - long result = 0; - - /* - * A structures of the testcases to be tested with - * isspace function - */ - struct testCase testCases[] = - { - {1,'\n'}, - {1,'\t'}, - {1,'\r'}, - {1,'\v'}, - {1,'\f'}, - {1,' '}, - {0,'a'}, - {0,'A'}, - {0,'z'}, - {0,'Z'}, - {0,'r'}, - {0,'R'}, - {0,'0'}, - {0,'*'}, - {0,3} - }; - - /* - * Initialize the PAL - */ - if ( 0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through the testcases */ - for (i=0; i + +struct testCase +{ + long result; + char avalue; +}; + + + +int __cdecl main(int argc, char *argv[]) +{ + int i=0; + long result = 0; + + /* + * A structures of the testcases to be tested with + * isspace function + */ + struct testCase testCases[] = + { + {1,'\n'}, + {1,'\t'}, + {1,'\r'}, + {1,'\v'}, + {1,'\f'}, + {1,' '}, + {0,'a'}, + {0,'A'}, + {0,'z'}, + {0,'Z'}, + {0,'r'}, + {0,'R'}, + {0,'0'}, + {0,'*'}, + {0,3} + }; + + /* + * Initialize the PAL + */ + if ( 0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through the testcases */ + for (i=0; i - -struct testCase -{ - int CorrectResult; - int character; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - /* Note: 1 iff char = A..Z - 0 iff char =~ A..Z - */ - - struct testCase testCases[] = - { - {1, 'A'}, /* Basic cases */ - {1, 'Z'}, - {0, 'b'}, /* Lower case */ - {0, '?'}, /* Characters without case */ - {0, 230}, - {0, '5'} - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through each case. Check to see if each is upper case or - not. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - result = isupper(testCases[i].character); - - /* The return value is 'non-zero' for success. This if condition - * will still work if that non-zero isn't just 1 - */ - if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || - ( (testCases[i].CorrectResult == 0) && (result != 0) )) - { - Fail("ERROR: isupper returned %i instead of %i for " - "character %c.\n", - result,testCases[i].CorrectResult, - testCases[i].character); - } - - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/isupper/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/isupper/test1/test1.cpp new file mode 100644 index 0000000000..b88bcc4a7e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isupper/test1/test1.cpp @@ -0,0 +1,88 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the isupper function +** Check that a number of characters return the correct +** values for whether they are upper case or not. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + int CorrectResult; + int character; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + /* Note: 1 iff char = A..Z + 0 iff char =~ A..Z + */ + + struct testCase testCases[] = + { + {1, 'A'}, /* Basic cases */ + {1, 'Z'}, + {0, 'b'}, /* Lower case */ + {0, '?'}, /* Characters without case */ + {0, 230}, + {0, '5'} + }; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through each case. Check to see if each is upper case or + not. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + result = isupper(testCases[i].character); + + /* The return value is 'non-zero' for success. This if condition + * will still work if that non-zero isn't just 1 + */ + if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || + ( (testCases[i].CorrectResult == 0) && (result != 0) )) + { + Fail("ERROR: isupper returned %i instead of %i for " + "character %c.\n", + result,testCases[i].CorrectResult, + testCases[i].character); + } + + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/iswdigit/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/iswdigit/test1/CMakeLists.txt index b35dd5ed6d..4074abbe76 100644 --- a/src/pal/tests/palsuite/c_runtime/iswdigit/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/iswdigit/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_iswdigit_test1 diff --git a/src/pal/tests/palsuite/c_runtime/iswdigit/test1/test1.c b/src/pal/tests/palsuite/c_runtime/iswdigit/test1/test1.c deleted file mode 100644 index 1cf94c5d13..0000000000 --- a/src/pal/tests/palsuite/c_runtime/iswdigit/test1/test1.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test1.c (iswdigit) -** -** Purpose: Tests the PAL implementation of the iswdigit function. -** Tests the passed parameter to iswdigit for being a -** digit ('0' - '9'). Also passes non-digits to make sure -** iswdigit picks them up. -** NOTE: There are three ASCII values that under Windows, -** iswdigit will return non-zero, indicating a digit. -** These values are quite apparently not digits: -** 178, 179, 185. -** These are not tested. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - wchar_t passTestCases[] = {'1','2','3','4','5','6','7','8','9'}; - wchar_t failTestCases[] = {'a','b','p','$','?',234}; - - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /* Loop through each case. Testing if each is a digit. */ - for(i = 0; i < sizeof(passTestCases) / sizeof(wchar_t); i++) - { - result = iswdigit(passTestCases[i]); - - /* The return value is 'non-zero' indicates digit*/ - if (result == 0) - { - Fail("ERROR: iswdigit returned \"%d\" instead indicating" - " \"%c\" is not a digit\n", - result, - passTestCases[i]); - } - } - - /* Loop through each case. Testing if each is a not a digit. */ - for(i = 0; i < sizeof(failTestCases) / sizeof(wchar_t); i++) - { - result = iswdigit(failTestCases[i]); - - /* The return value is 'zero' indicates non-digit*/ - if (result != 0) - { - Fail("ERROR: iswdigit returned \"%d\", indicating" - " \"%c\" is a digit\n", - result, - failTestCases[i]); - } - } - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/c_runtime/iswdigit/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/iswdigit/test1/test1.cpp new file mode 100644 index 0000000000..1cf94c5d13 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/iswdigit/test1/test1.cpp @@ -0,0 +1,69 @@ +// 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: test1.c (iswdigit) +** +** Purpose: Tests the PAL implementation of the iswdigit function. +** Tests the passed parameter to iswdigit for being a +** digit ('0' - '9'). Also passes non-digits to make sure +** iswdigit picks them up. +** NOTE: There are three ASCII values that under Windows, +** iswdigit will return non-zero, indicating a digit. +** These values are quite apparently not digits: +** 178, 179, 185. +** These are not tested. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + wchar_t passTestCases[] = {'1','2','3','4','5','6','7','8','9'}; + wchar_t failTestCases[] = {'a','b','p','$','?',234}; + + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /* Loop through each case. Testing if each is a digit. */ + for(i = 0; i < sizeof(passTestCases) / sizeof(wchar_t); i++) + { + result = iswdigit(passTestCases[i]); + + /* The return value is 'non-zero' indicates digit*/ + if (result == 0) + { + Fail("ERROR: iswdigit returned \"%d\" instead indicating" + " \"%c\" is not a digit\n", + result, + passTestCases[i]); + } + } + + /* Loop through each case. Testing if each is a not a digit. */ + for(i = 0; i < sizeof(failTestCases) / sizeof(wchar_t); i++) + { + result = iswdigit(failTestCases[i]); + + /* The return value is 'zero' indicates non-digit*/ + if (result != 0) + { + Fail("ERROR: iswdigit returned \"%d\", indicating" + " \"%c\" is a digit\n", + result, + failTestCases[i]); + } + } + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/iswprint/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/iswprint/test1/CMakeLists.txt index 5e436c3ca2..d21c232133 100644 --- a/src/pal/tests/palsuite/c_runtime/iswprint/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/iswprint/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_iswprint_test1 diff --git a/src/pal/tests/palsuite/c_runtime/iswprint/test1/test1.c b/src/pal/tests/palsuite/c_runtime/iswprint/test1/test1.c deleted file mode 100644 index 08a985b2d6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/iswprint/test1/test1.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests iswprint with all wide characters, ensuring they are -** consistent with GetStringTypeExW. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - WORD Info; - int ret; - int i; - WCHAR ch; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i<=0xFFFF; i++) - { - ch = i; - ret = GetStringTypeExW(LOCALE_USER_DEFAULT, CT_CTYPE1, &ch, 1, &Info); - if (!ret) - { - Fail("GetStringTypeExW failed to get information for %#X!\n", ch); - } - - ret = iswprint(ch); - if (Info & (C1_BLANK|C1_PUNCT|C1_ALPHA|C1_DIGIT)) - { - if (!ret) - { - Fail("iswprint returned incorrect results for %#X: " - "expected printable\n", ch); - } - } - else - { - if (ret) - { - Fail("iswprint returned incorrect results for %#X: " - "expected non-printable\n", ch); - } - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/iswprint/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/iswprint/test1/test1.cpp new file mode 100644 index 0000000000..08a985b2d6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/iswprint/test1/test1.cpp @@ -0,0 +1,59 @@ +// 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: test1.c +** +** Purpose: Tests iswprint with all wide characters, ensuring they are +** consistent with GetStringTypeExW. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + WORD Info; + int ret; + int i; + WCHAR ch; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i<=0xFFFF; i++) + { + ch = i; + ret = GetStringTypeExW(LOCALE_USER_DEFAULT, CT_CTYPE1, &ch, 1, &Info); + if (!ret) + { + Fail("GetStringTypeExW failed to get information for %#X!\n", ch); + } + + ret = iswprint(ch); + if (Info & (C1_BLANK|C1_PUNCT|C1_ALPHA|C1_DIGIT)) + { + if (!ret) + { + Fail("iswprint returned incorrect results for %#X: " + "expected printable\n", ch); + } + } + else + { + if (ret) + { + Fail("iswprint returned incorrect results for %#X: " + "expected non-printable\n", ch); + } + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/iswspace/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/iswspace/test1/CMakeLists.txt index 1368e55ccc..1f9a54fb17 100644 --- a/src/pal/tests/palsuite/c_runtime/iswspace/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/iswspace/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_iswspace_test1 diff --git a/src/pal/tests/palsuite/c_runtime/iswspace/test1/test1.c b/src/pal/tests/palsuite/c_runtime/iswspace/test1/test1.c deleted file mode 100644 index c58997812e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/iswspace/test1/test1.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests iswspace with a range of wide characters. -** -** -** -**==========================================================================*/ - - - -#include - -int __cdecl main(int argc, char *argv[]) -{ - int ret; - int i; - - struct testChars - { - WCHAR charValue; - int result; - }; - - /* create an array of chars that test the range of possible characters */ - struct testChars testChars1[] = - { - {0x00,0}, /* null */ - {0x09,1}, /* open circle */ - {0x0D,1}, /* musical note */ - {0x20,1}, /* space */ - {0x3F,0}, /* ? */ - {0x5E,0}, /* ^ */ - {0x7B,0}, /* { */ - {0x86,0}, /* a with circle on top */ - {0x9F,0}, /* slanted f */ - {0xC4,0}, /* long dash */ - {0xE5,0} /* sigma */ - }; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i = 0; i < (sizeof(testChars1) / sizeof(struct testChars)); i++) - { - - ret = iswspace(testChars1[i].charValue); - - if((ret==0) && (testChars1[i].result != 0)) - { - Fail("ERROR: wide character %#X IS considered a space, " - "but iswspace did NOT indicate it was one with error %u.\n", - testChars1[i].charValue, - GetLastError()); - } - - if((ret!=0) && (testChars1[i].result == 0)) - { - Fail("ERROR: wide character %#X is NOT considered a space, " - "but iswspace DID indicate it was a space with error %u.\n", - testChars1[i].charValue, - GetLastError()); - } - } - - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/iswspace/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/iswspace/test1/test1.cpp new file mode 100644 index 0000000000..c58997812e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/iswspace/test1/test1.cpp @@ -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: test1.c +** +** Purpose: Tests iswspace with a range of wide characters. +** +** +** +**==========================================================================*/ + + + +#include + +int __cdecl main(int argc, char *argv[]) +{ + int ret; + int i; + + struct testChars + { + WCHAR charValue; + int result; + }; + + /* create an array of chars that test the range of possible characters */ + struct testChars testChars1[] = + { + {0x00,0}, /* null */ + {0x09,1}, /* open circle */ + {0x0D,1}, /* musical note */ + {0x20,1}, /* space */ + {0x3F,0}, /* ? */ + {0x5E,0}, /* ^ */ + {0x7B,0}, /* { */ + {0x86,0}, /* a with circle on top */ + {0x9F,0}, /* slanted f */ + {0xC4,0}, /* long dash */ + {0xE5,0} /* sigma */ + }; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i = 0; i < (sizeof(testChars1) / sizeof(struct testChars)); i++) + { + + ret = iswspace(testChars1[i].charValue); + + if((ret==0) && (testChars1[i].result != 0)) + { + Fail("ERROR: wide character %#X IS considered a space, " + "but iswspace did NOT indicate it was one with error %u.\n", + testChars1[i].charValue, + GetLastError()); + } + + if((ret!=0) && (testChars1[i].result == 0)) + { + Fail("ERROR: wide character %#X is NOT considered a space, " + "but iswspace DID indicate it was a space with error %u.\n", + testChars1[i].charValue, + GetLastError()); + } + } + + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/iswupper/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/iswupper/test1/CMakeLists.txt index 8b8fae6d72..1da5fbaa75 100644 --- a/src/pal/tests/palsuite/c_runtime/iswupper/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/iswupper/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_iswupper_test1 diff --git a/src/pal/tests/palsuite/c_runtime/iswupper/test1/test1.c b/src/pal/tests/palsuite/c_runtime/iswupper/test1/test1.c deleted file mode 100644 index a01686be44..0000000000 --- a/src/pal/tests/palsuite/c_runtime/iswupper/test1/test1.c +++ /dev/null @@ -1,91 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the iswupper function -** Check that a number of characters return the correct -** values for whether they are upper case or not. -** -** -**===================================================================*/ - -#define UNICODE -#include - - -struct testCase -{ - int CorrectResult; - WCHAR character; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - /* Note: 1 iff char = A..Z - 0 iff char =~ A..Z - */ - - struct testCase testCases[] = - { - {1, 'A'}, /* Basic cases */ - {1, 'Z'}, - {0, 'b'}, /* Lower case */ - {0, '?'}, /* Characters without case */ - {0, 230} - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through each case. Check to see if each is upper case or - not. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - - result = iswupper(testCases[i].character); - - /* The return value is 'non-zero' for success. This if condition - * will still work if that non-zero isn't just 1 - */ - if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || - ( (testCases[i].CorrectResult == 0) && (result != 0) )) - { - Fail("ERROR: iswupper returned %i instead of %i for " - "character %c.\n", - result, - testCases[i].CorrectResult, - testCases[i].character); - } - - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/iswupper/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/iswupper/test1/test1.cpp new file mode 100644 index 0000000000..a01686be44 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/iswupper/test1/test1.cpp @@ -0,0 +1,91 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the iswupper function +** Check that a number of characters return the correct +** values for whether they are upper case or not. +** +** +**===================================================================*/ + +#define UNICODE +#include + + +struct testCase +{ + int CorrectResult; + WCHAR character; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + /* Note: 1 iff char = A..Z + 0 iff char =~ A..Z + */ + + struct testCase testCases[] = + { + {1, 'A'}, /* Basic cases */ + {1, 'Z'}, + {0, 'b'}, /* Lower case */ + {0, '?'}, /* Characters without case */ + {0, 230} + }; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through each case. Check to see if each is upper case or + not. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + + result = iswupper(testCases[i].character); + + /* The return value is 'non-zero' for success. This if condition + * will still work if that non-zero isn't just 1 + */ + if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || + ( (testCases[i].CorrectResult == 0) && (result != 0) )) + { + Fail("ERROR: iswupper returned %i instead of %i for " + "character %c.\n", + result, + testCases[i].CorrectResult, + testCases[i].character); + } + + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/CMakeLists.txt index 3a726eced9..ae55976128 100644 --- a/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_iswxdigit_test1 diff --git a/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/test1.c b/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/test1.c deleted file mode 100644 index 73ad495856..0000000000 --- a/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/test1.c +++ /dev/null @@ -1,61 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests iswxdigit with every possible wide character, ensuring it -** returns the correct results. -** -** -**===================================================================*/ - -#include - -/* - * These are the only wide characters Win2000 recogonizes as valid hex digits. - */ -WCHAR ValidHexDigits[] = -{ - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 97, 98, 99, 100, - 101, 102, 65296, 65297, 65298, 65299, 65300, 65301, 65302, 65303, 65304, 65305, - 65313, 65314, 65315, 65316, 65317, 65318, 65345, 65346, 65347, 65348, 65349, 65350, - 0 -}; - -int __cdecl main(int argc, char **argv) -{ - int i; - WCHAR c; - int ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i<=0xFFFF; i++) - { - ret = iswxdigit(i); - c = (WCHAR) i; - - if (ret) - { - if (wcschr(ValidHexDigits, c) == NULL) - { - /* iswxdigit says its a hex digit. We know better */ - Fail("iswxdigit incorrectly found %#x to be a hex digit!\n", c); - } - } - else if (wcschr(ValidHexDigits, c) != NULL && c != 0) - { - /* iswxdigit says it isn't a hex digit. We know better */ - Fail("iswxdigit failed to find %#x to be a hex digit!\n", c); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/test1.cpp new file mode 100644 index 0000000000..73ad495856 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/iswxdigit/test1/test1.cpp @@ -0,0 +1,61 @@ +// 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: test1.c +** +** Purpose: Tests iswxdigit with every possible wide character, ensuring it +** returns the correct results. +** +** +**===================================================================*/ + +#include + +/* + * These are the only wide characters Win2000 recogonizes as valid hex digits. + */ +WCHAR ValidHexDigits[] = +{ + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 97, 98, 99, 100, + 101, 102, 65296, 65297, 65298, 65299, 65300, 65301, 65302, 65303, 65304, 65305, + 65313, 65314, 65315, 65316, 65317, 65318, 65345, 65346, 65347, 65348, 65349, 65350, + 0 +}; + +int __cdecl main(int argc, char **argv) +{ + int i; + WCHAR c; + int ret; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i<=0xFFFF; i++) + { + ret = iswxdigit(i); + c = (WCHAR) i; + + if (ret) + { + if (wcschr(ValidHexDigits, c) == NULL) + { + /* iswxdigit says its a hex digit. We know better */ + Fail("iswxdigit incorrectly found %#x to be a hex digit!\n", c); + } + } + else if (wcschr(ValidHexDigits, c) != NULL && c != 0) + { + /* iswxdigit says it isn't a hex digit. We know better */ + Fail("iswxdigit failed to find %#x to be a hex digit!\n", c); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/isxdigit/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isxdigit/test1/CMakeLists.txt index 8919b36e42..4fd46c93d8 100644 --- a/src/pal/tests/palsuite/c_runtime/isxdigit/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/isxdigit/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isxdigit_test1 diff --git a/src/pal/tests/palsuite/c_runtime/isxdigit/test1/test1.c b/src/pal/tests/palsuite/c_runtime/isxdigit/test1/test1.c deleted file mode 100644 index be25af233c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/isxdigit/test1/test1.c +++ /dev/null @@ -1,58 +0,0 @@ -// 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: test1.c -** -** Purpose: Run through every possible character. For each time that -** isxdigit returns: -** 1, check through a list of the known hex characters to ensure that it -** is really a hex char. Also, when it returns 0, ensure that that character -** isn't a hex character. -** -** -**==========================================================================*/ - - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - int i; - - /* Initialize the PAL */ - if ( 0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through each character and call isxdigit for each character */ - for (i=1; i<256; i++) - { - - if (isxdigit(i) == 0) - { - if( ((i>=48) && (i<=57)) || ((i>=97) && (i<=102)) || - ((i>=65) && (i<=70)) ) - { - Fail("ERROR: isxdigit() returns true for '%c' (%d)\n", i, i); - } - } - else - { - if( ((i<48) && (i>58)) || ((i<97) && (i>102)) || - ((i<65) && (i>70)) ) - { - Fail("ERROR: isxdigit() returns false for '%c' (%d)\n", i, i); - } - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/isxdigit/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/isxdigit/test1/test1.cpp new file mode 100644 index 0000000000..be25af233c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isxdigit/test1/test1.cpp @@ -0,0 +1,58 @@ +// 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: test1.c +** +** Purpose: Run through every possible character. For each time that +** isxdigit returns: +** 1, check through a list of the known hex characters to ensure that it +** is really a hex char. Also, when it returns 0, ensure that that character +** isn't a hex character. +** +** +**==========================================================================*/ + + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + int i; + + /* Initialize the PAL */ + if ( 0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through each character and call isxdigit for each character */ + for (i=1; i<256; i++) + { + + if (isxdigit(i) == 0) + { + if( ((i>=48) && (i<=57)) || ((i>=97) && (i<=102)) || + ((i>=65) && (i<=70)) ) + { + Fail("ERROR: isxdigit() returns true for '%c' (%d)\n", i, i); + } + } + else + { + if( ((i<48) && (i>58)) || ((i<97) && (i>102)) || + ((i<65) && (i>70)) ) + { + Fail("ERROR: isxdigit() returns false for '%c' (%d)\n", i, i); + } + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/labs/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/labs/test1/CMakeLists.txt index cf0f0999a9..2ffb3cd641 100644 --- a/src/pal/tests/palsuite/c_runtime/labs/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/labs/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_labs_test1 diff --git a/src/pal/tests/palsuite/c_runtime/labs/test1/test1.c b/src/pal/tests/palsuite/c_runtime/labs/test1/test1.c deleted file mode 100644 index 41f85226e1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/labs/test1/test1.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test1.c -** -** Purpose: Call labs on a series of values -- negative, positive, zero, -** and the largest negative value of a LONG. Ensure that they are all -** changed properly to their absoulte value. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - LONG LongValue; - LONG AbsoluteLongValue; -}; - -int __cdecl main(int argc, char **argv) -{ - - LONG result=0; - int i=0; - - struct testCase testCases[] = - { - {1234, 1234}, - {-1234, 1234}, - {0, 0}, - {-2147483647, 2147483647}, /* Max value to abs */ - {2147483647, 2147483647} - }; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Loop through each case. Call labs on each LONG and ensure that - the resulting value is correct. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /* Absolute value on a LONG */ - result = labs(testCases[i].LongValue); - - if (testCases[i].AbsoluteLongValue != result) - { - Fail("ERROR: labs took the absoulte value of '%d' to be '%d' " - "instead of %d.\n", - testCases[i].LongValue, - result, - testCases[i].AbsoluteLongValue); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/labs/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/labs/test1/test1.cpp new file mode 100644 index 0000000000..41f85226e1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/labs/test1/test1.cpp @@ -0,0 +1,65 @@ +// 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: test1.c +** +** Purpose: Call labs on a series of values -- negative, positive, zero, +** and the largest negative value of a LONG. Ensure that they are all +** changed properly to their absoulte value. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + LONG LongValue; + LONG AbsoluteLongValue; +}; + +int __cdecl main(int argc, char **argv) +{ + + LONG result=0; + int i=0; + + struct testCase testCases[] = + { + {1234, 1234}, + {-1234, 1234}, + {0, 0}, + {-2147483647, 2147483647}, /* Max value to abs */ + {2147483647, 2147483647} + }; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Call labs on each LONG and ensure that + the resulting value is correct. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /* Absolute value on a LONG */ + result = labs(testCases[i].LongValue); + + if (testCases[i].AbsoluteLongValue != result) + { + Fail("ERROR: labs took the absoulte value of '%d' to be '%d' " + "instead of %d.\n", + testCases[i].LongValue, + result, + testCases[i].AbsoluteLongValue); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/llabs/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/llabs/test1/CMakeLists.txt index 8f5bdbe097..3adc3cc737 100644 --- a/src/pal/tests/palsuite/c_runtime/llabs/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/llabs/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_llabs_test1 diff --git a/src/pal/tests/palsuite/c_runtime/llabs/test1/test1.c b/src/pal/tests/palsuite/c_runtime/llabs/test1/test1.c deleted file mode 100644 index 044e22f134..0000000000 --- a/src/pal/tests/palsuite/c_runtime/llabs/test1/test1.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test1.c -** -** Purpose: Call llabs on a series of values -- negative, positive, -** zero, and the largest negative value of an __int64. Ensure that -** they are all changed properly to their absoulte value. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - __int64 LongLongValue; - __int64 AbsoluteLongLongValue; -}; - -int __cdecl main(int argc, char **argv) -{ - - __int64 result=0; - int i=0; - - struct testCase testCases[] = - { - {1234, 1234}, - {-1234, 1234}, - {0, 0}, - {-9223372036854775807LL, 9223372036854775807LL}, /* Max value to abs */ - {9223372036854775807LL, 9223372036854775807LL} - }; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Loop through each case. Call llabs on each __int64 and ensure that - the resulting value is correct. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /* Absolute value on an __int64 */ - result = llabs(testCases[i].LongLongValue); - - if (testCases[i].AbsoluteLongLongValue != result) - { - Fail("ERROR: llabs took the absoulte value of '%d' to be '%d' " - "instead of %d.\n", - testCases[i].LongLongValue, - result, - testCases[i].AbsoluteLongLongValue); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/llabs/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/llabs/test1/test1.cpp new file mode 100644 index 0000000000..044e22f134 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/llabs/test1/test1.cpp @@ -0,0 +1,65 @@ +// 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: test1.c +** +** Purpose: Call llabs on a series of values -- negative, positive, +** zero, and the largest negative value of an __int64. Ensure that +** they are all changed properly to their absoulte value. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + __int64 LongLongValue; + __int64 AbsoluteLongLongValue; +}; + +int __cdecl main(int argc, char **argv) +{ + + __int64 result=0; + int i=0; + + struct testCase testCases[] = + { + {1234, 1234}, + {-1234, 1234}, + {0, 0}, + {-9223372036854775807LL, 9223372036854775807LL}, /* Max value to abs */ + {9223372036854775807LL, 9223372036854775807LL} + }; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Call llabs on each __int64 and ensure that + the resulting value is correct. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /* Absolute value on an __int64 */ + result = llabs(testCases[i].LongLongValue); + + if (testCases[i].AbsoluteLongLongValue != result) + { + Fail("ERROR: llabs took the absoulte value of '%d' to be '%d' " + "instead of %d.\n", + testCases[i].LongLongValue, + result, + testCases[i].AbsoluteLongLongValue); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/localtime/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/localtime/test1/CMakeLists.txt index 25acf48749..698699f821 100644 --- a/src/pal/tests/palsuite/c_runtime/localtime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/localtime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_localtime_test1 diff --git a/src/pal/tests/palsuite/c_runtime/localtime/test1/test1.c b/src/pal/tests/palsuite/c_runtime/localtime/test1/test1.c deleted file mode 100644 index a993a17f69..0000000000 --- a/src/pal/tests/palsuite/c_runtime/localtime/test1/test1.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test1.c (localtime) -** -** Purpose: Tests the PAL implementation of the localtime function. -** localtime() is passed a date in seconds, since January 01 -** 1970 midnight, UTC. localtime() converts the time to the -** tm struct, those values are tested for validity. -** -** -**===================================================================*/ -#include - -int __cdecl main(int argc, char **argv) -{ - time_t dates[] ={1003327482, // Oct 17, 2001 10:04:42 am - 701307301, // March 22, 1992 6:35:01 pm - 973620900, // Nov 07, 2000 1:15:00 pm - 924632589, // April 20, 1999 2:23:09 pm - 951934989}; // March 01, 2000 1:23:09 pm - struct tm * converted_date; - int i; - - if (PAL_Initialize(argc, argv) != 0) - - return (FAIL); - - /*Convert from time_t to struct tm*/ - for ( i=0; i < (sizeof(dates)/sizeof(time_t)); i++) - { - converted_date = localtime(&dates[i]); - - if ((converted_date->tm_hour < 0) || (converted_date->tm_hour > 23)) - { - Fail("ERROR: localtime returned %d for tm_hour\n", converted_date->tm_hour); - } - if ((converted_date->tm_mday < 1) || (converted_date->tm_mday > 31)) - { - Fail("ERROR: localtime returned %d for tm_mday\n",converted_date->tm_mday); - } - if ((converted_date->tm_min < 0) || (converted_date->tm_min > 59)) - { - Fail("ERROR: localtime returned %d for tm_min\n",converted_date->tm_min); - } - if ((converted_date->tm_mon < 0) || (converted_date->tm_mon > 11)) - { - Fail("ERROR: localtime returned %d for tm_mon\n",converted_date->tm_mon); - } - if ((converted_date->tm_sec < 0) || (converted_date->tm_sec > 59)) - { - Fail("ERROR: localtime returned %d for tm_sec\n",converted_date->tm_sec); - } - if ((converted_date->tm_wday < 0) || (converted_date->tm_wday > 6 )) - { - Fail("ERROR: localtime returned %d for tm_wday\n",converted_date->tm_wday); - } - if ((converted_date->tm_yday < 0) || (converted_date->tm_yday > 365)) - { - Fail("ERROR: localtime returned %d for tm_yday\n",converted_date->tm_yday); - } - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/c_runtime/localtime/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/localtime/test1/test1.cpp new file mode 100644 index 0000000000..a993a17f69 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/localtime/test1/test1.cpp @@ -0,0 +1,69 @@ +// 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: test1.c (localtime) +** +** Purpose: Tests the PAL implementation of the localtime function. +** localtime() is passed a date in seconds, since January 01 +** 1970 midnight, UTC. localtime() converts the time to the +** tm struct, those values are tested for validity. +** +** +**===================================================================*/ +#include + +int __cdecl main(int argc, char **argv) +{ + time_t dates[] ={1003327482, // Oct 17, 2001 10:04:42 am + 701307301, // March 22, 1992 6:35:01 pm + 973620900, // Nov 07, 2000 1:15:00 pm + 924632589, // April 20, 1999 2:23:09 pm + 951934989}; // March 01, 2000 1:23:09 pm + struct tm * converted_date; + int i; + + if (PAL_Initialize(argc, argv) != 0) + + return (FAIL); + + /*Convert from time_t to struct tm*/ + for ( i=0; i < (sizeof(dates)/sizeof(time_t)); i++) + { + converted_date = localtime(&dates[i]); + + if ((converted_date->tm_hour < 0) || (converted_date->tm_hour > 23)) + { + Fail("ERROR: localtime returned %d for tm_hour\n", converted_date->tm_hour); + } + if ((converted_date->tm_mday < 1) || (converted_date->tm_mday > 31)) + { + Fail("ERROR: localtime returned %d for tm_mday\n",converted_date->tm_mday); + } + if ((converted_date->tm_min < 0) || (converted_date->tm_min > 59)) + { + Fail("ERROR: localtime returned %d for tm_min\n",converted_date->tm_min); + } + if ((converted_date->tm_mon < 0) || (converted_date->tm_mon > 11)) + { + Fail("ERROR: localtime returned %d for tm_mon\n",converted_date->tm_mon); + } + if ((converted_date->tm_sec < 0) || (converted_date->tm_sec > 59)) + { + Fail("ERROR: localtime returned %d for tm_sec\n",converted_date->tm_sec); + } + if ((converted_date->tm_wday < 0) || (converted_date->tm_wday > 6 )) + { + Fail("ERROR: localtime returned %d for tm_wday\n",converted_date->tm_wday); + } + if ((converted_date->tm_yday < 0) || (converted_date->tm_yday > 365)) + { + Fail("ERROR: localtime returned %d for tm_yday\n",converted_date->tm_yday); + } + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/log/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/log/test1/CMakeLists.txt index dd19002904..c8f991b997 100644 --- a/src/pal/tests/palsuite/c_runtime/log/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/log/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_log_test1 diff --git a/src/pal/tests/palsuite/c_runtime/log/test1/test1.c b/src/pal/tests/palsuite/c_runtime/log/test1/test1.c deleted file mode 100644 index eea592dd45..0000000000 --- a/src/pal/tests/palsuite/c_runtime/log/test1/test1.c +++ /dev/null @@ -1,140 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests log with a normal set of values. -** -**===================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = log(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("log(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = log(value); - - if (!_isnan(result)) - { - Fail("log(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, PAL_NEGINF, 0 }, - { 0.043213918263772250, -3.1415926535897932, PAL_EPSILON * 10 }, // expected: -(pi) - { 0.065988035845312537, -2.7182818284590452, PAL_EPSILON * 10 }, // expected: -(e) - { 0.1, -2.3025850929940457, PAL_EPSILON * 10 }, // expected: -(ln(10)) - { 0.20787957635076191, -1.5707963267948966, PAL_EPSILON * 10 }, // expected: -(pi / 2) - { 0.23629008834452270, -1.4426950408889634, PAL_EPSILON * 10 }, // expected: -(log2(e)) - { 0.24311673443421421, -1.4142135623730950, PAL_EPSILON * 10 }, // expected: -(sqrt(2)) - { 0.32355726390307110, -1.1283791670955126, PAL_EPSILON * 10 }, // expected: -(2 / sqrt(pi)) - { 0.36787944117144232, -1, PAL_EPSILON * 10 }, // expected: -(1) - { 0.45593812776599624, -0.78539816339744831, PAL_EPSILON }, // expected: -(pi / 4) - { 0.49306869139523979, -0.70710678118654752, PAL_EPSILON }, // expected: -(1 / sqrt(2)) - { 0.5, -0.69314718055994531, PAL_EPSILON }, // expected: -(ln(2)) - { 0.52907780826773535, -0.63661977236758134, PAL_EPSILON }, // expected: -(2 / pi) - { 0.64772148514180065, -0.43429448190325183, PAL_EPSILON }, // expected: -(log10(e)) - { 0.72737734929521647, -0.31830988618379067, PAL_EPSILON }, // expected: -(1 / pi) - { 1, 0, PAL_EPSILON }, - { 1.3748022274393586, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi - { 1.5438734439711811, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) - { 1.8900811645722220, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi - { 2, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) - { 2.0281149816474725, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) - { 2.1932800507380155, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 - { 2.7182818284590452, 1, PAL_EPSILON * 10 }, // value: e - { 3.0906430223107976, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) - { 4.1132503787829275, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) - { 4.2320861065570819, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) - { 4.8104773809653517, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 - { 10, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) - { 15.154262241479264, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e - { 23.140692632779269, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi - { PAL_POSINF, PAL_POSINF, 0 }, - }; - - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate(tests[i].value, tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NEGINF); - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/log/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/log/test1/test1.cpp new file mode 100644 index 0000000000..eea592dd45 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/log/test1/test1.cpp @@ -0,0 +1,140 @@ +// 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: test1.c +** +** Purpose: Tests log with a normal set of values. +** +**===================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = log(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("log(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = log(value); + + if (!_isnan(result)) + { + Fail("log(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, PAL_NEGINF, 0 }, + { 0.043213918263772250, -3.1415926535897932, PAL_EPSILON * 10 }, // expected: -(pi) + { 0.065988035845312537, -2.7182818284590452, PAL_EPSILON * 10 }, // expected: -(e) + { 0.1, -2.3025850929940457, PAL_EPSILON * 10 }, // expected: -(ln(10)) + { 0.20787957635076191, -1.5707963267948966, PAL_EPSILON * 10 }, // expected: -(pi / 2) + { 0.23629008834452270, -1.4426950408889634, PAL_EPSILON * 10 }, // expected: -(log2(e)) + { 0.24311673443421421, -1.4142135623730950, PAL_EPSILON * 10 }, // expected: -(sqrt(2)) + { 0.32355726390307110, -1.1283791670955126, PAL_EPSILON * 10 }, // expected: -(2 / sqrt(pi)) + { 0.36787944117144232, -1, PAL_EPSILON * 10 }, // expected: -(1) + { 0.45593812776599624, -0.78539816339744831, PAL_EPSILON }, // expected: -(pi / 4) + { 0.49306869139523979, -0.70710678118654752, PAL_EPSILON }, // expected: -(1 / sqrt(2)) + { 0.5, -0.69314718055994531, PAL_EPSILON }, // expected: -(ln(2)) + { 0.52907780826773535, -0.63661977236758134, PAL_EPSILON }, // expected: -(2 / pi) + { 0.64772148514180065, -0.43429448190325183, PAL_EPSILON }, // expected: -(log10(e)) + { 0.72737734929521647, -0.31830988618379067, PAL_EPSILON }, // expected: -(1 / pi) + { 1, 0, PAL_EPSILON }, + { 1.3748022274393586, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi + { 1.5438734439711811, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) + { 1.8900811645722220, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi + { 2, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) + { 2.0281149816474725, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) + { 2.1932800507380155, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 + { 2.7182818284590452, 1, PAL_EPSILON * 10 }, // value: e + { 3.0906430223107976, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) + { 4.1132503787829275, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) + { 4.2320861065570819, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) + { 4.8104773809653517, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + { 10, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) + { 15.154262241479264, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e + { 23.140692632779269, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/log10/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/log10/test1/CMakeLists.txt index 31e750df3e..31025fbd04 100644 --- a/src/pal/tests/palsuite/c_runtime/log10/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/log10/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_log10_test1 diff --git a/src/pal/tests/palsuite/c_runtime/log10/test1/test1.c b/src/pal/tests/palsuite/c_runtime/log10/test1/test1.c deleted file mode 100644 index 13711a752e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/log10/test1/test1.c +++ /dev/null @@ -1,146 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that log10 returns correct values. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** _isnan -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = log10(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("log10(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = log10(value); - - if (!_isnan(result)) - { - Fail("log10(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, PAL_NEGINF, 0 }, - { 0.00072178415907472774, -3.1415926535897932, PAL_EPSILON * 10 }, // expected: -(pi) - { 0.0019130141022243176, -2.7182818284590452, PAL_EPSILON * 10 }, // expected: -(e) - { 0.0049821282964407206, -2.3025850929940457, PAL_EPSILON * 10 }, // expected: -(ln(10)) - { 0.026866041001136132, -1.5707963267948966, PAL_EPSILON * 10 }, // expected: -(pi / 2) - { 0.036083192820787210, -1.4426950408889634, PAL_EPSILON * 10 }, // expected: -(log2(e)) - { 0.038528884700322026, -1.4142135623730950, PAL_EPSILON * 10 }, // expected: -(sqrt(2)) - { 0.074408205860642723, -1.1283791670955126, PAL_EPSILON * 10 }, // expected: -(2 / sqrt(pi)) - { 0.1, -1, PAL_EPSILON * 10 }, // expected: -(1) - { 0.16390863613957665, -0.78539816339744831, PAL_EPSILON }, // expected: -(pi / 4) - { 0.19628775993505562, -0.70710678118654752, PAL_EPSILON }, // expected: -(1 / sqrt(2)) - { 0.20269956628651730, -0.69314718055994531, PAL_EPSILON }, // expected: -(ln(2)) - { 0.23087676451600055, -0.63661977236758134, PAL_EPSILON }, // expected: -(2 / pi) - { 0.36787944117144232, -0.43429448190325183, PAL_EPSILON }, // expected: -(log10(e)) - { 0.48049637305186868, -0.31830988618379067, PAL_EPSILON }, // expected: -(1 / pi) - { 1, 0, PAL_EPSILON }, - { 2.0811811619898573, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi - { 2.7182818284590452, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) value: e - { 4.3313150290214525, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi - { 4.9334096679145963, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) - { 5.0945611704512962, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) - { 6.1009598002416937, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 - { 10, 1, PAL_EPSILON * 10 }, - { 13.439377934644400, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) - { 25.954553519470081, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) - { 27.713733786437790, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) - { 37.221710484165167, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 - { 200.71743249053009, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) - { 522.73529967043665, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e - { 1385.4557313670111, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi - { PAL_POSINF, PAL_POSINF, 0 }, - }; - - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate(tests[i].value, tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NEGINF); - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/log10/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/log10/test1/test1.cpp new file mode 100644 index 0000000000..13711a752e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/log10/test1/test1.cpp @@ -0,0 +1,146 @@ +// 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: test1.c +** +** Purpose: Test to ensure that log10 returns correct values. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** _isnan +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = log10(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("log10(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = log10(value); + + if (!_isnan(result)) + { + Fail("log10(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, PAL_NEGINF, 0 }, + { 0.00072178415907472774, -3.1415926535897932, PAL_EPSILON * 10 }, // expected: -(pi) + { 0.0019130141022243176, -2.7182818284590452, PAL_EPSILON * 10 }, // expected: -(e) + { 0.0049821282964407206, -2.3025850929940457, PAL_EPSILON * 10 }, // expected: -(ln(10)) + { 0.026866041001136132, -1.5707963267948966, PAL_EPSILON * 10 }, // expected: -(pi / 2) + { 0.036083192820787210, -1.4426950408889634, PAL_EPSILON * 10 }, // expected: -(log2(e)) + { 0.038528884700322026, -1.4142135623730950, PAL_EPSILON * 10 }, // expected: -(sqrt(2)) + { 0.074408205860642723, -1.1283791670955126, PAL_EPSILON * 10 }, // expected: -(2 / sqrt(pi)) + { 0.1, -1, PAL_EPSILON * 10 }, // expected: -(1) + { 0.16390863613957665, -0.78539816339744831, PAL_EPSILON }, // expected: -(pi / 4) + { 0.19628775993505562, -0.70710678118654752, PAL_EPSILON }, // expected: -(1 / sqrt(2)) + { 0.20269956628651730, -0.69314718055994531, PAL_EPSILON }, // expected: -(ln(2)) + { 0.23087676451600055, -0.63661977236758134, PAL_EPSILON }, // expected: -(2 / pi) + { 0.36787944117144232, -0.43429448190325183, PAL_EPSILON }, // expected: -(log10(e)) + { 0.48049637305186868, -0.31830988618379067, PAL_EPSILON }, // expected: -(1 / pi) + { 1, 0, PAL_EPSILON }, + { 2.0811811619898573, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi + { 2.7182818284590452, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) value: e + { 4.3313150290214525, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi + { 4.9334096679145963, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) + { 5.0945611704512962, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) + { 6.1009598002416937, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 + { 10, 1, PAL_EPSILON * 10 }, + { 13.439377934644400, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) + { 25.954553519470081, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) + { 27.713733786437790, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) + { 37.221710484165167, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + { 200.71743249053009, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) + { 522.73529967043665, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e + { 1385.4557313670111, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/log10f/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/log10f/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/log10f/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/log10f/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/log10f/test1/CMakeLists.txt new file mode 100644 index 0000000000..b2c0835451 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/log10f/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_log10f_test1 + ${SOURCES} +) + +add_dependencies(paltest_log10f_test1 coreclrpal) + +target_link_libraries(paltest_log10f_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/log10f/test1/test1.c b/src/pal/tests/palsuite/c_runtime/log10f/test1/test1.c new file mode 100644 index 0000000000..e7c8c2f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/log10f/test1/test1.c @@ -0,0 +1,144 @@ +// 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: test1.c +** +** Purpose: Test to ensure that log10f returns correct values. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** _isnanf +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = log10f(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("log10f(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = log10f(value); + + if (!_isnanf(result)) + { + Fail("log10f(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, PAL_NEGINF, 0 }, + { 0.000721784159f, -3.14159265f, PAL_EPSILON * 10 }, // expected: -(pi) + { 0.00191301410f, -2.71828183f, PAL_EPSILON * 10 }, // expected: -(e) + { 0.00498212830f, -2.30258509f, PAL_EPSILON * 10 }, // expected: -(ln(10)) + { 0.0268660410f, -1.57079633f, PAL_EPSILON * 10 }, // expected: -(pi / 2) + { 0.0360831928f, -1.44269504f, PAL_EPSILON * 10 }, // expected: -(logf2(e)) + { 0.0385288847f, -1.41421356f, PAL_EPSILON * 10 }, // expected: -(sqrtf(2)) + { 0.0744082059f, -1.12837917f, PAL_EPSILON * 10 }, // expected: -(2 / sqrtf(pi)) + { 0.1f, -1, PAL_EPSILON * 10 }, // expected: -(1) + { 0.163908636f, -0.785398163f, PAL_EPSILON }, // expected: -(pi / 4) + { 0.196287760f, -0.707106781f, PAL_EPSILON }, // expected: -(1 / sqrtf(2)) + { 0.202699566f, -0.693147181f, PAL_EPSILON }, // expected: -(ln(2)) + { 0.230876765f, -0.636619772f, PAL_EPSILON }, // expected: -(2 / pi) + { 0.367879441f, -0.434294482f, PAL_EPSILON }, // expected: -(log10f(e)) + { 0.480496373f, -0.318309886f, PAL_EPSILON }, // expected: -(1 / pi) + { 1, 0, PAL_EPSILON }, + { 2.08118116f, 0.318309886f, PAL_EPSILON }, // expected: 1 / pi + { 2.71828183f, 0.434294482f, PAL_EPSILON }, // expected: log10f(e) value: e + { 4.33131503f, 0.636619772f, PAL_EPSILON }, // expected: 2 / pi + { 4.93340967f, 0.693147181f, PAL_EPSILON }, // expected: ln(2) + { 5.09456117f, 0.707106781f, PAL_EPSILON }, // expected: 1 / sqrtf(2) + { 6.10095980f, 0.785398163f, PAL_EPSILON }, // expected: pi / 4 + { 10, 1, PAL_EPSILON * 10 }, + { 13.4393779f, 1.12837917f, PAL_EPSILON * 10 }, // expected: 2 / sqrtf(pi) + { 25.9545535f, 1.41421356f, PAL_EPSILON * 10 }, // expected: sqrtf(2) + { 27.7137338f, 1.44269504f, PAL_EPSILON * 10 }, // expected: logf2(e) + { 37.2217105f, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + { 200.717432f, 2.30258509f, PAL_EPSILON * 10 }, // expected: ln(10) + { 522.735300f, 2.71828183f, PAL_EPSILON * 10 }, // expected: e + { 1385.45573f, 3.14159265f, PAL_EPSILON * 10 }, // expected: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/log10f/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/log10f/test1/testinfo.dat new file mode 100644 index 0000000000..175ee3ab09 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/log10f/test1/testinfo.dat @@ -0,0 +1,17 @@ +# 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 = C Runtime +Function = log10f +Name = Positive Test for log10f +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the log10f() function, += checking each for the expected result. Also checks += for proper handling of out-of-range values. + + + diff --git a/src/pal/tests/palsuite/c_runtime/logf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/logf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/logf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/logf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/logf/test1/CMakeLists.txt new file mode 100644 index 0000000000..550f572bc7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/logf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_logf_test1 + ${SOURCES} +) + +add_dependencies(paltest_logf_test1 coreclrpal) + +target_link_libraries(paltest_logf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/logf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/logf/test1/test1.c new file mode 100644 index 0000000000..499778e992 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/logf/test1/test1.c @@ -0,0 +1,139 @@ +// 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: test1.c +** +** Purpose: Tests logf with a normal set of values. +** +**===================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = logf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("logf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = logf(value); + + if (!_isnanf(result)) + { + Fail("logf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, PAL_NEGINF, 0 }, + { 0.0432139183f, -3.14159265f, PAL_EPSILON * 10 }, // expected: -(pi) + { 0.0659880358f, -2.71828183f, PAL_EPSILON * 10 }, // expected: -(e) + { 0.1f, -2.30258509f, PAL_EPSILON * 10 }, // expected: -(ln(10)) + { 0.207879576f, -1.57079633f, PAL_EPSILON * 10 }, // expected: -(pi / 2) + { 0.236290088f, -1.44269504f, PAL_EPSILON * 10 }, // expected: -(logf2(e)) + { 0.243116734f, -1.41421356f, PAL_EPSILON * 10 }, // expected: -(sqrtf(2)) + { 0.323557264f, -1.12837917f, PAL_EPSILON * 10 }, // expected: -(2 / sqrtf(pi)) + { 0.367879441f, -1, PAL_EPSILON * 10 }, // expected: -(1) + { 0.455938128f, -0.785398163f, PAL_EPSILON }, // expected: -(pi / 4) + { 0.493068691f, -0.707106781f, PAL_EPSILON }, // expected: -(1 / sqrtf(2)) + { 0.5f, -0.693147181f, PAL_EPSILON }, // expected: -(ln(2)) + { 0.529077808f, -0.636619772f, PAL_EPSILON }, // expected: -(2 / pi) + { 0.647721485f, -0.434294482f, PAL_EPSILON }, // expected: -(log10f(e)) + { 0.727377349f, -0.318309886f, PAL_EPSILON }, // expected: -(1 / pi) + { 1, 0, PAL_EPSILON }, + { 1.37480223f, 0.318309886f, PAL_EPSILON }, // expected: 1 / pi + { 1.54387344f, 0.434294482f, PAL_EPSILON }, // expected: log10f(e) + { 1.89008116f, 0.636619772f, PAL_EPSILON }, // expected: 2 / pi + { 2, 0.693147181f, PAL_EPSILON }, // expected: ln(2) + { 2.02811498f, 0.707106781f, PAL_EPSILON }, // expected: 1 / sqrtf(2) + { 2.19328005f, 0.785398163f, PAL_EPSILON }, // expected: pi / 4 + { 2.71828183f, 1, PAL_EPSILON * 10 }, // value: e + { 3.09064302f, 1.12837917f, PAL_EPSILON * 10 }, // expected: 2 / sqrtf(pi) + { 4.11325038f, 1.41421356f, PAL_EPSILON * 10 }, // expected: sqrtf(2) + { 4.23208611f, 1.44269504f, PAL_EPSILON * 10 }, // expected: logf2(e) + { 4.81047738f, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + { 10, 2.30258509f, PAL_EPSILON * 10 }, // expected: ln(10) + { 15.1542622f, 2.71828183f, PAL_EPSILON * 10 }, // expected: e + { 23.1406926f, 3.14159265f, PAL_EPSILON * 10 }, // expected: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/logf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/logf/test1/testinfo.dat new file mode 100644 index 0000000000..aadfee6c11 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/logf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# 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 = C Runtime +Function = logf +Name = Positive Test for logf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the logf() function, += checking each for the expected result. Also checks += for proper handling of out-of-range values. diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/malloc/test1/CMakeLists.txt index 4a388ad3d7..f475730973 100644 --- a/src/pal/tests/palsuite/c_runtime/malloc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/malloc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_malloc_test1 diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test1/test1.c b/src/pal/tests/palsuite/c_runtime/malloc/test1/test1.c deleted file mode 100644 index 7ea4dd068f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/malloc/test1/test1.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test1.c -** -** Purpose: Test that malloc returns useable memory -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char **argv) -{ - - char *testA; - int i; - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* check that malloc really gives us addressable memory */ - testA = (char *)malloc(20 * sizeof(char)); - if (testA == NULL) - { - Fail("Call to malloc failed.\n"); - } - for (i = 0; i < 20; i++) - { - testA[i] = 'a'; - } - for (i = 0; i < 20; i++) - { - if (testA[i] != 'a') - { - Fail("The memory doesn't seem to be properly allocated.\n"); - } - } - free(testA); - - PAL_Terminate(); - - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/malloc/test1/test1.cpp new file mode 100644 index 0000000000..7ea4dd068f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/malloc/test1/test1.cpp @@ -0,0 +1,52 @@ +// 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: test1.c +** +** Purpose: Test that malloc returns useable memory +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char **argv) +{ + + char *testA; + int i; + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* check that malloc really gives us addressable memory */ + testA = (char *)malloc(20 * sizeof(char)); + if (testA == NULL) + { + Fail("Call to malloc failed.\n"); + } + for (i = 0; i < 20; i++) + { + testA[i] = 'a'; + } + for (i = 0; i < 20; i++) + { + if (testA[i] != 'a') + { + Fail("The memory doesn't seem to be properly allocated.\n"); + } + } + free(testA); + + PAL_Terminate(); + + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/malloc/test2/CMakeLists.txt index abbed2aa62..663e104d0e 100644 --- a/src/pal/tests/palsuite/c_runtime/malloc/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/malloc/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_malloc_test2 diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test2/test2.c b/src/pal/tests/palsuite/c_runtime/malloc/test2/test2.c deleted file mode 100644 index 5deee0eddb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/malloc/test2/test2.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: test2.c -** -** Purpose: Test that malloc(0) returns non-zero value -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char **argv) -{ - - char *testA; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* check that malloc(0) returns non-zero value */ - testA = (char *)malloc(0); - if (testA == NULL) - { - Fail("Call to malloc(0) failed.\n"); - } - - free(testA); - - PAL_Terminate(); - - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/malloc/test2/test2.cpp new file mode 100644 index 0000000000..5deee0eddb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/malloc/test2/test2.cpp @@ -0,0 +1,41 @@ +// 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: test2.c +** +** Purpose: Test that malloc(0) returns non-zero value +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char **argv) +{ + + char *testA; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* check that malloc(0) returns non-zero value */ + testA = (char *)malloc(0); + if (testA == NULL) + { + Fail("Call to malloc(0) failed.\n"); + } + + free(testA); + + PAL_Terminate(); + + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/memchr/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/memchr/test1/CMakeLists.txt index 4e33a8fc04..959fd2a3bc 100644 --- a/src/pal/tests/palsuite/c_runtime/memchr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/memchr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_memchr_test1 diff --git a/src/pal/tests/palsuite/c_runtime/memchr/test1/test1.c b/src/pal/tests/palsuite/c_runtime/memchr/test1/test1.c deleted file mode 100644 index 043a6789d8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/memchr/test1/test1.c +++ /dev/null @@ -1,122 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the memchr function. -** Create a string buffer, and check for a number of -** characters in it. Test to ensure it returns NULL if -** it can't find the character, and that the size argument -** works properly. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - char *result; - char string[50]; - int character; - int length; -}; - - -int __cdecl main(int argc, char *argv[]) -{ - int i = 0; - char *result = NULL; - - /* - * this structure includes several strings to be tested with - * memchr function and the expected results - */ - - struct testCase testCases[]= - { - {"st","corn cup cat cream coast",'s',23}, - /* single instance of char */ - {"st","corn cup cat cream coast",'s',24}, - /* single inst, inst< exact length */ - {"q","corn cup cat cream coastq",'q',25}, - /* single inst at end, inst=exact length */ - {"q","corn cup cat cream coastq",'q',26}, - /* single inst at end, instlen(string) */ - {"st","corn cup cat cream coast",115,24}, - /* single int inst, instlength */ - }; - - - /* Initialize the PAL */ - if ( 0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Loop through the testcases in the structure */ - for (i=0; i< sizeof(testCases)/sizeof(struct testCase); i++) - { - /* Need to type cast function in order to compare the result */ - result = (char *)memchr(testCases[i].string, - testCases[i].character,testCases[i].length); - - if (result==NULL) - { - if (testCases[i].result != NULL) - { - Fail("ERROR: Expected memcmp to return \"%s\" instead of" - " NULL\n", testCases[i].result); - } - } - else - { - if (strcmp(result,testCases[i].result)!=0 ) - - { - Fail("ERROR: Expected memcmp to return \"%s\" instead of" - " \"%s\"\n", testCases[i].result, result); - } - - } - } - - PAL_Terminate(); - - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/memchr/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/memchr/test1/test1.cpp new file mode 100644 index 0000000000..043a6789d8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/memchr/test1/test1.cpp @@ -0,0 +1,122 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the memchr function. +** Create a string buffer, and check for a number of +** characters in it. Test to ensure it returns NULL if +** it can't find the character, and that the size argument +** works properly. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + char *result; + char string[50]; + int character; + int length; +}; + + +int __cdecl main(int argc, char *argv[]) +{ + int i = 0; + char *result = NULL; + + /* + * this structure includes several strings to be tested with + * memchr function and the expected results + */ + + struct testCase testCases[]= + { + {"st","corn cup cat cream coast",'s',23}, + /* single instance of char */ + {"st","corn cup cat cream coast",'s',24}, + /* single inst, inst< exact length */ + {"q","corn cup cat cream coastq",'q',25}, + /* single inst at end, inst=exact length */ + {"q","corn cup cat cream coastq",'q',26}, + /* single inst at end, instlen(string) */ + {"st","corn cup cat cream coast",115,24}, + /* single int inst, instlength */ + }; + + + /* Initialize the PAL */ + if ( 0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Loop through the testcases in the structure */ + for (i=0; i< sizeof(testCases)/sizeof(struct testCase); i++) + { + /* Need to type cast function in order to compare the result */ + result = (char *)memchr(testCases[i].string, + testCases[i].character,testCases[i].length); + + if (result==NULL) + { + if (testCases[i].result != NULL) + { + Fail("ERROR: Expected memcmp to return \"%s\" instead of" + " NULL\n", testCases[i].result); + } + } + else + { + if (strcmp(result,testCases[i].result)!=0 ) + + { + Fail("ERROR: Expected memcmp to return \"%s\" instead of" + " \"%s\"\n", testCases[i].result, result); + } + + } + } + + PAL_Terminate(); + + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/memcmp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/memcmp/test1/CMakeLists.txt index b61f208f34..43d8fdd7f7 100644 --- a/src/pal/tests/palsuite/c_runtime/memcmp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/memcmp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_memcmp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/memcmp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/memcmp/test1/test1.c deleted file mode 100644 index 7b63173e22..0000000000 --- a/src/pal/tests/palsuite/c_runtime/memcmp/test1/test1.c +++ /dev/null @@ -1,57 +0,0 @@ -// 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: test1.c -** -** Purpose: Check that memcmp find identical buffers to be identical, -** and that it correctly orders different buffers. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - char testA[] = "aaaaaaaaaaaaaaaaaaaa"; - char testB[] = "aaaaaaaaaaaaaaaaaaaa"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - if (!(memcmp(testA, testB, 20) == 0)) - { - Fail("memcmp compared two identical buffers and found them to " - "differ.\n"); - } - testB[3] = 'b'; - - if (!(memcmp(testA, testB, 20) < 0) - || !(memcmp(testB, testA, 20) >0 )) - { - Fail("memcmp compared two buffers with different contents, and" - " did not order them correctly.\n"); - } - - if (memcmp(testA, testB, 0) != 0) - { - Fail("memcmp didn't return 0 when comparing buffers of length 0.\n"); - } - - PAL_Terminate(); - return PASS; -} - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/memcmp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/memcmp/test1/test1.cpp new file mode 100644 index 0000000000..7b63173e22 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/memcmp/test1/test1.cpp @@ -0,0 +1,57 @@ +// 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: test1.c +** +** Purpose: Check that memcmp find identical buffers to be identical, +** and that it correctly orders different buffers. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + char testA[] = "aaaaaaaaaaaaaaaaaaaa"; + char testB[] = "aaaaaaaaaaaaaaaaaaaa"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + if (!(memcmp(testA, testB, 20) == 0)) + { + Fail("memcmp compared two identical buffers and found them to " + "differ.\n"); + } + testB[3] = 'b'; + + if (!(memcmp(testA, testB, 20) < 0) + || !(memcmp(testB, testA, 20) >0 )) + { + Fail("memcmp compared two buffers with different contents, and" + " did not order them correctly.\n"); + } + + if (memcmp(testA, testB, 0) != 0) + { + Fail("memcmp didn't return 0 when comparing buffers of length 0.\n"); + } + + PAL_Terminate(); + return PASS; +} + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/memcpy/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/memcpy/test1/CMakeLists.txt index d846bfc62d..14db0df60e 100644 --- a/src/pal/tests/palsuite/c_runtime/memcpy/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/memcpy/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_memcpy_test1 diff --git a/src/pal/tests/palsuite/c_runtime/memcpy/test1/test1.c b/src/pal/tests/palsuite/c_runtime/memcpy/test1/test1.c deleted file mode 100644 index 9da98d6573..0000000000 --- a/src/pal/tests/palsuite/c_runtime/memcpy/test1/test1.c +++ /dev/null @@ -1,87 +0,0 @@ -// 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: test1.c -** -** Purpose: Calls memcpy and verifies that the buffer was copied correctly. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - char testA[20]; - char testB[20]; - void *retVal; - long i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - memset(testA, 'a', 20); - memset(testB, 'b', 20); - - retVal = (char *)memcpy(testB, testA, 0); - if (retVal != testB) - { - Fail("memcpy should return a pointer to the destination buffer, " - "but doesn't.\n"); - } - for(i = 0; i<20; i++) - { - if (testB[i]!= 'b') - { - Fail("The destination buffer overflowed by memcpy.\n"); - } - } - - retVal = (char *)memcpy(testB+1, testA, 18); - if (retVal != testB+1) - { - Fail("memcpy should return a pointer to the destination buffer, " - "but doesn't.\n"); - } - - if (testB[0] != 'b' || testB[19] != 'b') - { - Fail("The destination buffer was written out of bounds by memcpy!\n"); - } - - for(i = 1; i<19; i++) - { - if (testB[i]!= 'a') - { - Fail("The destination buffer copied to by memcpy doesn't match " - "the source buffer.\n"); - } - } - - PAL_Terminate(); - - return PASS; -} - - - - - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/memcpy/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/memcpy/test1/test1.cpp new file mode 100644 index 0000000000..9da98d6573 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/memcpy/test1/test1.cpp @@ -0,0 +1,87 @@ +// 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: test1.c +** +** Purpose: Calls memcpy and verifies that the buffer was copied correctly. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + char testA[20]; + char testB[20]; + void *retVal; + long i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + memset(testA, 'a', 20); + memset(testB, 'b', 20); + + retVal = (char *)memcpy(testB, testA, 0); + if (retVal != testB) + { + Fail("memcpy should return a pointer to the destination buffer, " + "but doesn't.\n"); + } + for(i = 0; i<20; i++) + { + if (testB[i]!= 'b') + { + Fail("The destination buffer overflowed by memcpy.\n"); + } + } + + retVal = (char *)memcpy(testB+1, testA, 18); + if (retVal != testB+1) + { + Fail("memcpy should return a pointer to the destination buffer, " + "but doesn't.\n"); + } + + if (testB[0] != 'b' || testB[19] != 'b') + { + Fail("The destination buffer was written out of bounds by memcpy!\n"); + } + + for(i = 1; i<19; i++) + { + if (testB[i]!= 'a') + { + Fail("The destination buffer copied to by memcpy doesn't match " + "the source buffer.\n"); + } + } + + PAL_Terminate(); + + return PASS; +} + + + + + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/memmove/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/memmove/test1/CMakeLists.txt index cf50ec01b7..db6f65e48b 100644 --- a/src/pal/tests/palsuite/c_runtime/memmove/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/memmove/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_memmove_test1 diff --git a/src/pal/tests/palsuite/c_runtime/memmove/test1/test1.c b/src/pal/tests/palsuite/c_runtime/memmove/test1/test1.c deleted file mode 100644 index c1af871f4a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/memmove/test1/test1.c +++ /dev/null @@ -1,116 +0,0 @@ -// 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: test1.c -** -** Purpose: Test that memmove correctly copies text from one buffer -** to another even when the buffers overlap. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - char testA[11] = "abcdefghij"; - char testB[15] = "aabbccddeeffgg"; - char testC[15] = "aabbccddeeffgg"; - char testD[15] = "aabbccddeeffgg"; - char insString[3] = "zzz"; - char *retVal; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* move a string onto itself */ - retVal = (char *)memmove(testA + 2, testA, 8); - if (retVal != testA + 2) - { - Fail("The return value should have been the value of the destination" - "pointer, but wasn't\n"); - } - - /*Check the most likely error*/ - if (memcmp(testA, "ababababab", 11) == 0) - { - Fail("memmove should have saved the characters in the region of" - " overlap between source and destination, but didn't.\n"); - } - - if (memcmp(testA, "ababcdefgh", 11) != 0) - { - /* not sure what exactly went wrong. */ - Fail("memmove was called on a region containing the characters" - " \"abcdefghij\". It was to move the first 8 positions to" - " the last 8 positions, giving the result \"ababcdefgh\". " - " Instead, it gave the result \"%s\".\n", testA); - } - - /* move a string to the front of testB */ - retVal = (char *)memmove(testB, insString, 3); - if(retVal != testB) - { - Fail("memmove: The function did not return the correct " - "string.\n"); - } - - if(memcmp(testB, "zzzbccddeeffgg",15) != 0) - { - Fail("memmove: The function failed to move the string " - "correctly.\n"); - } - - - /* move a string to the middle of testC */ - retVal = memmove(testC+5, insString, 3); - if(retVal != testC+5) - { - Fail("memmove: The function did not return the correct " - "string.\n"); - } - - if(memcmp(testC, "aabbczzzeeffgg",15) != 0) - { - Fail("memmove: The function failed to move the string " - "correctly.\n"); - } - - - /* move a string to the end of testD */ - retVal = memmove(testD+11, insString, 3); - if(retVal != testD+11) - { - Fail("memmove: The function did not return the correct " - "string.\n"); - } - - if(memcmp(testD, "aabbccddeefzzz",15) != 0) - { - Fail("memmove: The function failed to move the string " - "correctly.\n"); - } - - PAL_Terminate(); - return PASS; - -} - - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/memmove/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/memmove/test1/test1.cpp new file mode 100644 index 0000000000..8279d67139 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/memmove/test1/test1.cpp @@ -0,0 +1,116 @@ +// 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: test1.c +** +** Purpose: Test that memmove correctly copies text from one buffer +** to another even when the buffers overlap. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + char testA[11] = "abcdefghij"; + char testB[15] = "aabbccddeeffgg"; + char testC[15] = "aabbccddeeffgg"; + char testD[15] = "aabbccddeeffgg"; + char insString[4] = "zzz"; + char *retVal; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* move a string onto itself */ + retVal = (char *)memmove(testA + 2, testA, 8); + if (retVal != testA + 2) + { + Fail("The return value should have been the value of the destination" + "pointer, but wasn't\n"); + } + + /*Check the most likely error*/ + if (memcmp(testA, "ababababab", 11) == 0) + { + Fail("memmove should have saved the characters in the region of" + " overlap between source and destination, but didn't.\n"); + } + + if (memcmp(testA, "ababcdefgh", 11) != 0) + { + /* not sure what exactly went wrong. */ + Fail("memmove was called on a region containing the characters" + " \"abcdefghij\". It was to move the first 8 positions to" + " the last 8 positions, giving the result \"ababcdefgh\". " + " Instead, it gave the result \"%s\".\n", testA); + } + + /* move a string to the front of testB */ + retVal = (char *)memmove(testB, insString, 3); + if(retVal != testB) + { + Fail("memmove: The function did not return the correct " + "string.\n"); + } + + if(memcmp(testB, "zzzbccddeeffgg",15) != 0) + { + Fail("memmove: The function failed to move the string " + "correctly.\n"); + } + + + /* move a string to the middle of testC */ + retVal = (char*)memmove(testC+5, insString, 3); + if(retVal != testC+5) + { + Fail("memmove: The function did not return the correct " + "string.\n"); + } + + if(memcmp(testC, "aabbczzzeeffgg",15) != 0) + { + Fail("memmove: The function failed to move the string " + "correctly.\n"); + } + + + /* move a string to the end of testD */ + retVal = (char*)memmove(testD+11, insString, 3); + if(retVal != testD+11) + { + Fail("memmove: The function did not return the correct " + "string.\n"); + } + + if(memcmp(testD, "aabbccddeefzzz",15) != 0) + { + Fail("memmove: The function failed to move the string " + "correctly.\n"); + } + + PAL_Terminate(); + return PASS; + +} + + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/memset/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/memset/test1/CMakeLists.txt index 78b5a6bc00..bc3d6251cb 100644 --- a/src/pal/tests/palsuite/c_runtime/memset/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/memset/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_memset_test1 diff --git a/src/pal/tests/palsuite/c_runtime/memset/test1/test1.c b/src/pal/tests/palsuite/c_runtime/memset/test1/test1.c deleted file mode 100644 index 67cde8756b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/memset/test1/test1.c +++ /dev/null @@ -1,60 +0,0 @@ -// 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: test1.c -** -** Purpose: Check that memset correctly fills a destination buffer -** without overflowing it. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - - char testA[22] = "bbbbbbbbbbbbbbbbbbbbb"; - char *retVal; - - int i; - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - retVal = (char *)memset(testA, 'a', 20); - if (retVal != testA) - { - Fail("memset should have returned the value of the destination" - "pointer, but didn't"); - } - - for(i = 0; i<20; i++) - { - if (testA[i]!= 'a') - { - Fail("memset didn't set the destination bytes.\n"); - } - } - if (testA[20] == 'a') - { - Fail("memset overfilled the destination buffer.\n"); - } - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/memset/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/memset/test1/test1.cpp new file mode 100644 index 0000000000..67cde8756b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/memset/test1/test1.cpp @@ -0,0 +1,60 @@ +// 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: test1.c +** +** Purpose: Check that memset correctly fills a destination buffer +** without overflowing it. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + + char testA[22] = "bbbbbbbbbbbbbbbbbbbbb"; + char *retVal; + + int i; + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + retVal = (char *)memset(testA, 'a', 20); + if (retVal != testA) + { + Fail("memset should have returned the value of the destination" + "pointer, but didn't"); + } + + for(i = 0; i<20; i++) + { + if (testA[i]!= 'a') + { + Fail("memset didn't set the destination bytes.\n"); + } + } + if (testA[20] == 'a') + { + Fail("memset overfilled the destination buffer.\n"); + } + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/modf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/modf/test1/CMakeLists.txt index 4b65ba7a6f..3fe7bc7c46 100644 --- a/src/pal/tests/palsuite/c_runtime/modf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/modf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_modf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/modf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/modf/test1/test1.c deleted file mode 100644 index 389d079253..0000000000 --- a/src/pal/tests/palsuite/c_runtime/modf/test1/test1.c +++ /dev/null @@ -1,136 +0,0 @@ -// 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: test1.c (modf) -** -** Purpose: Test to ensure that modf return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ - double expected_intpart; /* expected result */ - double variance_intpart; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance, double expected_intpart, double variance_intpart) -{ - double result_intpart; - double result = modf(value, &result_intpart); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - double delta_intpart = fabs(result_intpart - expected_intpart); - - if ((delta > variance) || (delta_intpart > variance_intpart)) - { - Fail("modf(%g) returned %20.17g with an intpart of %20.17g when it should have returned %20.17g with an intpart of %20.17g", - value, result, result_intpart, expected, expected_intpart); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result_intpart; - double result = modf(value, &result_intpart); - - if (!_isnan(result) || !_isnan(result_intpart)) - { - Fail("modf(%g) returned %20.17g with an intpart of %20.17g when it should have returned %20.17g with an intpart of %20.17g", - value, result, result_intpart, PAL_NAN, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance expected_intpart variance_intpart */ - { 0, 0, PAL_EPSILON, 0, PAL_EPSILON }, - { 0.31830988618379067, 0.31830988618379067, PAL_EPSILON, 0, PAL_EPSILON }, // value: 1 / pi - { 0.43429448190325183, 0.43429448190325183, PAL_EPSILON, 0, PAL_EPSILON }, // value: log10(e) - { 0.63661977236758134, 0.63661977236758134, PAL_EPSILON, 0, PAL_EPSILON }, // value: 2 / pi - { 0.69314718055994531, 0.69314718055994531, PAL_EPSILON, 0, PAL_EPSILON }, // value: ln(2) - { 0.70710678118654752, 0.70710678118654752, PAL_EPSILON, 0, PAL_EPSILON }, // value: 1 / sqrt(2) - { 0.78539816339744831, 0.78539816339744831, PAL_EPSILON, 0, PAL_EPSILON }, // value: pi / 4 - { 1, 0, PAL_EPSILON, 1, PAL_EPSILON * 10 }, - { 1.1283791670955126, 0.1283791670955126, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 0.4142135623730950, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: sqrt(2) - { 1.4426950408889634, 0.4426950408889634, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: log2(e) - { 1.5707963267948966, 0.5707963267948966, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: pi / 2 - { 2.3025850929940457, 0.3025850929940457, PAL_EPSILON, 2, PAL_EPSILON * 10 }, // value: ln(10) - { 2.7182818284590452, 0.7182818284590452, PAL_EPSILON, 2, PAL_EPSILON * 10 }, // value: e - { 3.1415926535897932, 0.1415926535897932, PAL_EPSILON, 3, PAL_EPSILON * 10 }, // value: pi - { PAL_POSINF, 0, PAL_EPSILON, PAL_POSINF, 0 } - - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance, tests[i].expected_intpart, tests[i].variance_intpart); - validate(-tests[i].value, -tests[i].expected, tests[i].variance, -tests[i].expected_intpart, tests[i].variance_intpart); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/modf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/modf/test1/test1.cpp new file mode 100644 index 0000000000..389d079253 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/modf/test1/test1.cpp @@ -0,0 +1,136 @@ +// 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: test1.c (modf) +** +** Purpose: Test to ensure that modf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ + double expected_intpart; /* expected result */ + double variance_intpart; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance, double expected_intpart, double variance_intpart) +{ + double result_intpart; + double result = modf(value, &result_intpart); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + double delta_intpart = fabs(result_intpart - expected_intpart); + + if ((delta > variance) || (delta_intpart > variance_intpart)) + { + Fail("modf(%g) returned %20.17g with an intpart of %20.17g when it should have returned %20.17g with an intpart of %20.17g", + value, result, result_intpart, expected, expected_intpart); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result_intpart; + double result = modf(value, &result_intpart); + + if (!_isnan(result) || !_isnan(result_intpart)) + { + Fail("modf(%g) returned %20.17g with an intpart of %20.17g when it should have returned %20.17g with an intpart of %20.17g", + value, result, result_intpart, PAL_NAN, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance expected_intpart variance_intpart */ + { 0, 0, PAL_EPSILON, 0, PAL_EPSILON }, + { 0.31830988618379067, 0.31830988618379067, PAL_EPSILON, 0, PAL_EPSILON }, // value: 1 / pi + { 0.43429448190325183, 0.43429448190325183, PAL_EPSILON, 0, PAL_EPSILON }, // value: log10(e) + { 0.63661977236758134, 0.63661977236758134, PAL_EPSILON, 0, PAL_EPSILON }, // value: 2 / pi + { 0.69314718055994531, 0.69314718055994531, PAL_EPSILON, 0, PAL_EPSILON }, // value: ln(2) + { 0.70710678118654752, 0.70710678118654752, PAL_EPSILON, 0, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.78539816339744831, PAL_EPSILON, 0, PAL_EPSILON }, // value: pi / 4 + { 1, 0, PAL_EPSILON, 1, PAL_EPSILON * 10 }, + { 1.1283791670955126, 0.1283791670955126, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 0.4142135623730950, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.4426950408889634, 0.4426950408889634, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: log2(e) + { 1.5707963267948966, 0.5707963267948966, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.3025850929940457, 0.3025850929940457, PAL_EPSILON, 2, PAL_EPSILON * 10 }, // value: ln(10) + { 2.7182818284590452, 0.7182818284590452, PAL_EPSILON, 2, PAL_EPSILON * 10 }, // value: e + { 3.1415926535897932, 0.1415926535897932, PAL_EPSILON, 3, PAL_EPSILON * 10 }, // value: pi + { PAL_POSINF, 0, PAL_EPSILON, PAL_POSINF, 0 } + + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance, tests[i].expected_intpart, tests[i].variance_intpart); + validate(-tests[i].value, -tests[i].expected, tests[i].variance, -tests[i].expected_intpart, tests[i].variance_intpart); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/modff/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/modff/test1/CMakeLists.txt index 812cd1c47b..10e5e99267 100644 --- a/src/pal/tests/palsuite/c_runtime/modff/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/modff/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_modff_test1 diff --git a/src/pal/tests/palsuite/c_runtime/modff/test1/test1.c b/src/pal/tests/palsuite/c_runtime/modff/test1/test1.c deleted file mode 100644 index 6b7a50be39..0000000000 --- a/src/pal/tests/palsuite/c_runtime/modff/test1/test1.c +++ /dev/null @@ -1,135 +0,0 @@ -// 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: test1.c (modf) -** -** Purpose: Test to ensure that modf return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (6-9 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON -// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use -// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. -#define PAL_EPSILON 4.76837158e-07 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - float value; /* value to test the function with */ - float expected; /* expected result */ - float variance; /* maximum delta between the expected and actual result */ - float expected_intpart; /* expected result */ - float variance_intpart; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(float value, float expected, float variance, float expected_intpart, float variance_intpart) -{ - float result_intpart; - float result = modff(value, &result_intpart); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - float delta = fabsf(result - expected); - float delta_intpart = fabsf(result_intpart - expected_intpart); - - if ((delta > variance) || (delta_intpart > variance_intpart)) - { - Fail("modff(%g) returned %10.9g with an intpart of %10.9g when it should have returned %10.9g with an intpart of %10.9g", - value, result, result_intpart, expected, expected_intpart); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(float value) -{ - float result_intpart; - float result = modff(value, &result_intpart); - - if (!_isnan(result) || !_isnan(result_intpart)) - { - Fail("modff(%g) returned %10.9g with an intpart of %10.9g when it should have returned %10.9g with an intpart of %10.9g", - value, result, result_intpart, PAL_NAN, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance expected_intpart variance_intpart */ - { 0, 0, PAL_EPSILON, 0, PAL_EPSILON }, - { 0.318309886f, 0.318309886f, PAL_EPSILON, 0, PAL_EPSILON }, // value: 1 / pi - { 0.434294482f, 0.434294482f, PAL_EPSILON, 0, PAL_EPSILON }, // value: log10(e) - { 0.636619772f, 0.636619772f, PAL_EPSILON, 0, PAL_EPSILON }, // value: 2 / pi - { 0.693147181f, 0.693147181f, PAL_EPSILON, 0, PAL_EPSILON }, // value: ln(2) - { 0.707106781f, 0.707106781f, PAL_EPSILON, 0, PAL_EPSILON }, // value: 1 / sqrt(2) - { 0.785398163f, 0.785398163f, PAL_EPSILON, 0, PAL_EPSILON }, // value: pi / 4 - { 1, 0, PAL_EPSILON, 1, PAL_EPSILON * 10 }, - { 1.12837917f, 0.128379167f, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) - { 1.41421356f, 0.414213562f, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: sqrt(2) - { 1.44269504f, 0.442695041f, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: log2(e) - { 1.57079633f, 0.570796327f, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: pi / 2 - { 2.30258509f, 0.302585093f, PAL_EPSILON, 2, PAL_EPSILON * 10 }, // value: ln(10) - { 2.71828183f, 0.718281828f, PAL_EPSILON, 2, PAL_EPSILON * 10 }, // value: e - { 3.14159265f, 0.141592654f, PAL_EPSILON, 3, PAL_EPSILON * 10 }, // value: pi - { PAL_POSINF, 0, PAL_EPSILON, PAL_POSINF, 0 } - - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance, tests[i].expected_intpart, tests[i].variance_intpart); - validate(-tests[i].value, -tests[i].expected, tests[i].variance, -tests[i].expected_intpart, tests[i].variance_intpart); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/modff/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/modff/test1/test1.cpp new file mode 100644 index 0000000000..6b7a50be39 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/modff/test1/test1.cpp @@ -0,0 +1,135 @@ +// 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: test1.c (modf) +** +** Purpose: Test to ensure that modf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ + float expected_intpart; /* expected result */ + float variance_intpart; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance, float expected_intpart, float variance_intpart) +{ + float result_intpart; + float result = modff(value, &result_intpart); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + float delta_intpart = fabsf(result_intpart - expected_intpart); + + if ((delta > variance) || (delta_intpart > variance_intpart)) + { + Fail("modff(%g) returned %10.9g with an intpart of %10.9g when it should have returned %10.9g with an intpart of %10.9g", + value, result, result_intpart, expected, expected_intpart); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result_intpart; + float result = modff(value, &result_intpart); + + if (!_isnan(result) || !_isnan(result_intpart)) + { + Fail("modff(%g) returned %10.9g with an intpart of %10.9g when it should have returned %10.9g with an intpart of %10.9g", + value, result, result_intpart, PAL_NAN, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance expected_intpart variance_intpart */ + { 0, 0, PAL_EPSILON, 0, PAL_EPSILON }, + { 0.318309886f, 0.318309886f, PAL_EPSILON, 0, PAL_EPSILON }, // value: 1 / pi + { 0.434294482f, 0.434294482f, PAL_EPSILON, 0, PAL_EPSILON }, // value: log10(e) + { 0.636619772f, 0.636619772f, PAL_EPSILON, 0, PAL_EPSILON }, // value: 2 / pi + { 0.693147181f, 0.693147181f, PAL_EPSILON, 0, PAL_EPSILON }, // value: ln(2) + { 0.707106781f, 0.707106781f, PAL_EPSILON, 0, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.785398163f, 0.785398163f, PAL_EPSILON, 0, PAL_EPSILON }, // value: pi / 4 + { 1, 0, PAL_EPSILON, 1, PAL_EPSILON * 10 }, + { 1.12837917f, 0.128379167f, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.41421356f, 0.414213562f, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.44269504f, 0.442695041f, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: log2(e) + { 1.57079633f, 0.570796327f, PAL_EPSILON, 1, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.30258509f, 0.302585093f, PAL_EPSILON, 2, PAL_EPSILON * 10 }, // value: ln(10) + { 2.71828183f, 0.718281828f, PAL_EPSILON, 2, PAL_EPSILON * 10 }, // value: e + { 3.14159265f, 0.141592654f, PAL_EPSILON, 3, PAL_EPSILON * 10 }, // value: pi + { PAL_POSINF, 0, PAL_EPSILON, PAL_POSINF, 0 } + + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance, tests[i].expected_intpart, tests[i].variance_intpart); + validate(-tests[i].value, -tests[i].expected, tests[i].variance, -tests[i].expected_intpart, tests[i].variance_intpart); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/pow/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/pow/test1/CMakeLists.txt index 69ba02af17..f94210d5b7 100644 --- a/src/pal/tests/palsuite/c_runtime/pow/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/pow/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_pow_test1 diff --git a/src/pal/tests/palsuite/c_runtime/pow/test1/test1.c b/src/pal/tests/palsuite/c_runtime/pow/test1/test1.c deleted file mode 100644 index 0a05cd5a47..0000000000 --- a/src/pal/tests/palsuite/c_runtime/pow/test1/test1.c +++ /dev/null @@ -1,230 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that atan2 returns correct values for a subset of values. -** Tests with positive and negative values of x and y to ensure -** atan2 is returning results from the correct quadrant. -** -**===================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double x; /* first component of the value to test the function with */ - double y; /* second component of the value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double x, double y, double expected, double variance) -{ - double result = pow(x, y); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("pow(%g, %g) returned %20.17g when it should have returned %20.17g", - x, y, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double x, double y) -{ - double result = pow(x, y); - - if (!_isnan(result)) - { - Fail("pow(%g, %g) returned %20.17g when it should have returned %20.17g", - x, y, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* x y expected variance */ - { PAL_NEGINF, PAL_NEGINF, 0, PAL_EPSILON }, - { PAL_NEGINF, PAL_POSINF, PAL_POSINF, 0 }, - - { -10, PAL_NEGINF, 0, PAL_EPSILON }, - { -10, -1, -0.1, PAL_EPSILON }, - { -10, 0, 1, PAL_EPSILON * 10 }, - { -10, 1, -10, PAL_EPSILON * 100 }, - { -10, PAL_POSINF, PAL_POSINF, 0 }, - - { -2.7182818284590452, PAL_NEGINF, 0, PAL_EPSILON }, // x: -(e) - { -2.7182818284590452, -1, -0.36787944117144232, PAL_EPSILON }, // x: -(e) - { -2.7182818284590452, 0, 1, PAL_EPSILON * 10 }, // x: -(e) - { -2.7182818284590452, 1, -2.7182818284590452, PAL_EPSILON * 10 }, // x: -(e) expected: e - { -2.7182818284590452, PAL_POSINF, PAL_POSINF, 0 }, // x: -(e) - - { -0.0, PAL_NEGINF, PAL_POSINF, 0 }, - { -0.0, -1, PAL_NEGINF, 0 }, - { -0.0, -0.0, 1, PAL_EPSILON * 10 }, - { -0.0, 0, 1, PAL_EPSILON * 10 }, - { -0.0, 1, -0.0, PAL_EPSILON }, - { -0.0, PAL_POSINF, 0, PAL_EPSILON }, - - { 0.0, PAL_NEGINF, PAL_POSINF, 0 }, - { 0.0, -1, PAL_POSINF, 0 }, - { 0, -0.0, 1, PAL_EPSILON * 10 }, - { 0, 0, 1, PAL_EPSILON * 10 }, - { 0.0, 1, 0, PAL_EPSILON }, - { 0.0, PAL_POSINF, 0, PAL_EPSILON }, - - { 1, PAL_NEGINF, 1, PAL_EPSILON * 10 }, - { 1, PAL_POSINF, 1, PAL_EPSILON * 10 }, - - { 2.7182818284590452, PAL_NEGINF, 0, PAL_EPSILON }, - { 2.7182818284590452, -3.1415926535897932, 0.043213918263772250, PAL_EPSILON / 10 }, // x: e y: -(pi) - { 2.7182818284590452, -2.7182818284590452, 0.065988035845312537, PAL_EPSILON / 10 }, // x: e y: -(e) - { 2.7182818284590452, -2.3025850929940457, 0.1, PAL_EPSILON }, // x: e y: -(ln(10)) - { 2.7182818284590452, -1.5707963267948966, 0.20787957635076191, PAL_EPSILON }, // x: e y: -(pi / 2) - { 2.7182818284590452, -1.4426950408889634, 0.23629008834452270, PAL_EPSILON }, // x: e y: -(log2(e)) - { 2.7182818284590452, -1.4142135623730950, 0.24311673443421421, PAL_EPSILON }, // x: e y: -(sqrt(2)) - { 2.7182818284590452, -1.1283791670955126, 0.32355726390307110, PAL_EPSILON }, // x: e y: -(2 / sqrt(pi)) - { 2.7182818284590452, -1, 0.36787944117144232, PAL_EPSILON }, // x: e y: -(1) - { 2.7182818284590452, -0.78539816339744831, 0.45593812776599624, PAL_EPSILON }, // x: e y: -(pi / 4) - { 2.7182818284590452, -0.70710678118654752, 0.49306869139523979, PAL_EPSILON }, // x: e y: -(1 / sqrt(2)) - { 2.7182818284590452, -0.69314718055994531, 0.5, PAL_EPSILON }, // x: e y: -(ln(2)) - { 2.7182818284590452, -0.63661977236758134, 0.52907780826773535, PAL_EPSILON }, // x: e y: -(2 / pi) - { 2.7182818284590452, -0.43429448190325183, 0.64772148514180065, PAL_EPSILON }, // x: e y: -(log10(e)) - { 2.7182818284590452, -0.31830988618379067, 0.72737734929521647, PAL_EPSILON }, // x: e y: -(1 / pi) - { 2.7182818284590452, 0, 1, PAL_EPSILON * 10 }, // x: e - { 2.7182818284590452, 0.31830988618379067, 1.3748022274393586, PAL_EPSILON * 10 }, // x: e y: 1 / pi - { 2.7182818284590452, 0.43429448190325183, 1.5438734439711811, PAL_EPSILON * 10 }, // x: e y: log10(e) - { 2.7182818284590452, 0.63661977236758134, 1.8900811645722220, PAL_EPSILON * 10 }, // x: e y: 2 / pi - { 2.7182818284590452, 0.69314718055994531, 2, PAL_EPSILON * 10 }, // x: e y: ln(2) - { 2.7182818284590452, 0.70710678118654752, 2.0281149816474725, PAL_EPSILON * 10 }, // x: e y: 1 / sqrt(2) - { 2.7182818284590452, 0.78539816339744831, 2.1932800507380155, PAL_EPSILON * 10 }, // x: e y: pi / 4 - { 2.7182818284590452, 1, 2.7182818284590452, PAL_EPSILON * 10 }, // x: e expected: e - { 2.7182818284590452, 1.1283791670955126, 3.0906430223107976, PAL_EPSILON * 10 }, // x: e y: 2 / sqrt(pi) - { 2.7182818284590452, 1.4142135623730950, 4.1132503787829275, PAL_EPSILON * 10 }, // x: e y: sqrt(2) - { 2.7182818284590452, 1.4426950408889634, 4.2320861065570819, PAL_EPSILON * 10 }, // x: e y: log2(e) - { 2.7182818284590452, 1.5707963267948966, 4.8104773809653517, PAL_EPSILON * 10 }, // x: e y: pi / 2 - { 2.7182818284590452, 2.3025850929940457, 10, PAL_EPSILON * 100 }, // x: e y: ln(10) - { 2.7182818284590452, 2.7182818284590452, 15.154262241479264, PAL_EPSILON * 100 }, // x: e y: e - { 2.7182818284590452, 3.1415926535897932, 23.140692632779269, PAL_EPSILON * 100 }, // x: e y: pi - { 2.7182818284590452, PAL_POSINF, PAL_POSINF, 0 }, // x: e - - { 10, PAL_NEGINF, 0, 0 }, - { 10, -3.1415926535897932, 0.00072178415907472774, PAL_EPSILON / 1000 }, // y: -(pi) - { 10, -2.7182818284590452, 0.0019130141022243176, PAL_EPSILON / 100 }, // y: -(e) - { 10, -2.3025850929940457, 0.0049821282964407206, PAL_EPSILON / 100 }, // y: -(ln(10)) - { 10, -1.5707963267948966, 0.026866041001136132, PAL_EPSILON / 10 }, // y: -(pi / 2) - { 10, -1.4426950408889634, 0.036083192820787210, PAL_EPSILON / 10 }, // y: -(log2(e)) - { 10, -1.4142135623730950, 0.038528884700322026, PAL_EPSILON / 10 }, // y: -(sqrt(2)) - { 10, -1.1283791670955126, 0.074408205860642723, PAL_EPSILON / 10 }, // y: -(2 / sqrt(pi)) - { 10, -1, 0.1, PAL_EPSILON }, // y: -(1) - { 10, -0.78539816339744831, 0.16390863613957665, PAL_EPSILON }, // y: -(pi / 4) - { 10, -0.70710678118654752, 0.19628775993505562, PAL_EPSILON }, // y: -(1 / sqrt(2)) - { 10, -0.69314718055994531, 0.20269956628651730, PAL_EPSILON }, // y: -(ln(2)) - { 10, -0.63661977236758134, 0.23087676451600055, PAL_EPSILON }, // y: -(2 / pi) - { 10, -0.43429448190325183, 0.36787944117144232, PAL_EPSILON }, // y: -(log10(e)) - { 10, -0.31830988618379067, 0.48049637305186868, PAL_EPSILON }, // y: -(1 / pi) - { 10, 0, 1, PAL_EPSILON * 10 }, - { 10, 0.31830988618379067, 2.0811811619898573, PAL_EPSILON * 10 }, // y: 1 / pi - { 10, 0.43429448190325183, 2.7182818284590452, PAL_EPSILON * 10 }, // y: log10(e) expected: e - { 10, 0.63661977236758134, 4.3313150290214525, PAL_EPSILON * 10 }, // y: 2 / pi - { 10, 0.69314718055994531, 4.9334096679145963, PAL_EPSILON * 10 }, // y: ln(2) - { 10, 0.70710678118654752, 5.0945611704512962, PAL_EPSILON * 10 }, // y: 1 / sqrt(2) - { 10, 0.78539816339744831, 6.1009598002416937, PAL_EPSILON * 10 }, // y: pi / 4 - { 10, 1, 10, PAL_EPSILON * 100 }, - { 10, 1.1283791670955126, 13.439377934644400, PAL_EPSILON * 100 }, // y: 2 / sqrt(pi) - { 10, 1.4142135623730950, 25.954553519470081, PAL_EPSILON * 100 }, // y: sqrt(2) - { 10, 1.4426950408889634, 27.713733786437790, PAL_EPSILON * 100 }, // y: log2(e) - { 10, 1.5707963267948966, 37.221710484165167, PAL_EPSILON * 100 }, // y: pi / 2 - { 10, 2.3025850929940457, 200.71743249053009, PAL_EPSILON * 1000 }, // y: ln(10) - { 10, 2.7182818284590452, 522.73529967043665, PAL_EPSILON * 1000 }, // y: e - { 10, 3.1415926535897932, 1385.4557313670111, PAL_EPSILON * 10000 }, // y: pi - { 10, PAL_POSINF, PAL_POSINF, 0 }, - - { PAL_POSINF, PAL_NEGINF, 0, PAL_EPSILON }, - { PAL_POSINF, PAL_POSINF, PAL_POSINF, 0 }, - }; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate(tests[i].x, tests[i].y, tests[i].expected, tests[i].variance); - } - - validate_isnan(-10, -1.5707963267948966); // y: -(pi / 2) - validate_isnan(-10, -0.78539816339744828); // y: -(pi / 4) - validate_isnan(-10, 0.78539816339744828); // y: pi / 4 - validate_isnan(-10, 1.5707963267948966); // y: pi / 2 - - validate_isnan(-2.7182818284590452, -1.5707963267948966); // x: -(e) y: -(pi / 2) - validate_isnan(-2.7182818284590452, -0.78539816339744828); // x: -(e) y: -(pi / 4) - validate_isnan(-2.7182818284590452, 0.78539816339744828); // x: -(e) y: pi / 4 - validate_isnan(-2.7182818284590452, 1.5707963267948966); // x: -(e) y: pi / 2 - - validate_isnan(-1, PAL_NEGINF); - validate_isnan(-1, PAL_POSINF); - - validate_isnan(PAL_NAN, -0.0); - validate_isnan(PAL_NAN, 0); - - validate_isnan(PAL_NEGINF, PAL_NAN); - validate_isnan(PAL_NAN, PAL_NEGINF); - - validate_isnan(PAL_POSINF, PAL_NAN); - validate_isnan(PAL_NAN, PAL_POSINF); - - validate_isnan(PAL_NAN, PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/pow/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/pow/test1/test1.cpp new file mode 100644 index 0000000000..0a05cd5a47 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/pow/test1/test1.cpp @@ -0,0 +1,230 @@ +// 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: test1.c +** +** Purpose: Tests that atan2 returns correct values for a subset of values. +** Tests with positive and negative values of x and y to ensure +** atan2 is returning results from the correct quadrant. +** +**===================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double x; /* first component of the value to test the function with */ + double y; /* second component of the value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double x, double y, double expected, double variance) +{ + double result = pow(x, y); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("pow(%g, %g) returned %20.17g when it should have returned %20.17g", + x, y, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double x, double y) +{ + double result = pow(x, y); + + if (!_isnan(result)) + { + Fail("pow(%g, %g) returned %20.17g when it should have returned %20.17g", + x, y, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* x y expected variance */ + { PAL_NEGINF, PAL_NEGINF, 0, PAL_EPSILON }, + { PAL_NEGINF, PAL_POSINF, PAL_POSINF, 0 }, + + { -10, PAL_NEGINF, 0, PAL_EPSILON }, + { -10, -1, -0.1, PAL_EPSILON }, + { -10, 0, 1, PAL_EPSILON * 10 }, + { -10, 1, -10, PAL_EPSILON * 100 }, + { -10, PAL_POSINF, PAL_POSINF, 0 }, + + { -2.7182818284590452, PAL_NEGINF, 0, PAL_EPSILON }, // x: -(e) + { -2.7182818284590452, -1, -0.36787944117144232, PAL_EPSILON }, // x: -(e) + { -2.7182818284590452, 0, 1, PAL_EPSILON * 10 }, // x: -(e) + { -2.7182818284590452, 1, -2.7182818284590452, PAL_EPSILON * 10 }, // x: -(e) expected: e + { -2.7182818284590452, PAL_POSINF, PAL_POSINF, 0 }, // x: -(e) + + { -0.0, PAL_NEGINF, PAL_POSINF, 0 }, + { -0.0, -1, PAL_NEGINF, 0 }, + { -0.0, -0.0, 1, PAL_EPSILON * 10 }, + { -0.0, 0, 1, PAL_EPSILON * 10 }, + { -0.0, 1, -0.0, PAL_EPSILON }, + { -0.0, PAL_POSINF, 0, PAL_EPSILON }, + + { 0.0, PAL_NEGINF, PAL_POSINF, 0 }, + { 0.0, -1, PAL_POSINF, 0 }, + { 0, -0.0, 1, PAL_EPSILON * 10 }, + { 0, 0, 1, PAL_EPSILON * 10 }, + { 0.0, 1, 0, PAL_EPSILON }, + { 0.0, PAL_POSINF, 0, PAL_EPSILON }, + + { 1, PAL_NEGINF, 1, PAL_EPSILON * 10 }, + { 1, PAL_POSINF, 1, PAL_EPSILON * 10 }, + + { 2.7182818284590452, PAL_NEGINF, 0, PAL_EPSILON }, + { 2.7182818284590452, -3.1415926535897932, 0.043213918263772250, PAL_EPSILON / 10 }, // x: e y: -(pi) + { 2.7182818284590452, -2.7182818284590452, 0.065988035845312537, PAL_EPSILON / 10 }, // x: e y: -(e) + { 2.7182818284590452, -2.3025850929940457, 0.1, PAL_EPSILON }, // x: e y: -(ln(10)) + { 2.7182818284590452, -1.5707963267948966, 0.20787957635076191, PAL_EPSILON }, // x: e y: -(pi / 2) + { 2.7182818284590452, -1.4426950408889634, 0.23629008834452270, PAL_EPSILON }, // x: e y: -(log2(e)) + { 2.7182818284590452, -1.4142135623730950, 0.24311673443421421, PAL_EPSILON }, // x: e y: -(sqrt(2)) + { 2.7182818284590452, -1.1283791670955126, 0.32355726390307110, PAL_EPSILON }, // x: e y: -(2 / sqrt(pi)) + { 2.7182818284590452, -1, 0.36787944117144232, PAL_EPSILON }, // x: e y: -(1) + { 2.7182818284590452, -0.78539816339744831, 0.45593812776599624, PAL_EPSILON }, // x: e y: -(pi / 4) + { 2.7182818284590452, -0.70710678118654752, 0.49306869139523979, PAL_EPSILON }, // x: e y: -(1 / sqrt(2)) + { 2.7182818284590452, -0.69314718055994531, 0.5, PAL_EPSILON }, // x: e y: -(ln(2)) + { 2.7182818284590452, -0.63661977236758134, 0.52907780826773535, PAL_EPSILON }, // x: e y: -(2 / pi) + { 2.7182818284590452, -0.43429448190325183, 0.64772148514180065, PAL_EPSILON }, // x: e y: -(log10(e)) + { 2.7182818284590452, -0.31830988618379067, 0.72737734929521647, PAL_EPSILON }, // x: e y: -(1 / pi) + { 2.7182818284590452, 0, 1, PAL_EPSILON * 10 }, // x: e + { 2.7182818284590452, 0.31830988618379067, 1.3748022274393586, PAL_EPSILON * 10 }, // x: e y: 1 / pi + { 2.7182818284590452, 0.43429448190325183, 1.5438734439711811, PAL_EPSILON * 10 }, // x: e y: log10(e) + { 2.7182818284590452, 0.63661977236758134, 1.8900811645722220, PAL_EPSILON * 10 }, // x: e y: 2 / pi + { 2.7182818284590452, 0.69314718055994531, 2, PAL_EPSILON * 10 }, // x: e y: ln(2) + { 2.7182818284590452, 0.70710678118654752, 2.0281149816474725, PAL_EPSILON * 10 }, // x: e y: 1 / sqrt(2) + { 2.7182818284590452, 0.78539816339744831, 2.1932800507380155, PAL_EPSILON * 10 }, // x: e y: pi / 4 + { 2.7182818284590452, 1, 2.7182818284590452, PAL_EPSILON * 10 }, // x: e expected: e + { 2.7182818284590452, 1.1283791670955126, 3.0906430223107976, PAL_EPSILON * 10 }, // x: e y: 2 / sqrt(pi) + { 2.7182818284590452, 1.4142135623730950, 4.1132503787829275, PAL_EPSILON * 10 }, // x: e y: sqrt(2) + { 2.7182818284590452, 1.4426950408889634, 4.2320861065570819, PAL_EPSILON * 10 }, // x: e y: log2(e) + { 2.7182818284590452, 1.5707963267948966, 4.8104773809653517, PAL_EPSILON * 10 }, // x: e y: pi / 2 + { 2.7182818284590452, 2.3025850929940457, 10, PAL_EPSILON * 100 }, // x: e y: ln(10) + { 2.7182818284590452, 2.7182818284590452, 15.154262241479264, PAL_EPSILON * 100 }, // x: e y: e + { 2.7182818284590452, 3.1415926535897932, 23.140692632779269, PAL_EPSILON * 100 }, // x: e y: pi + { 2.7182818284590452, PAL_POSINF, PAL_POSINF, 0 }, // x: e + + { 10, PAL_NEGINF, 0, 0 }, + { 10, -3.1415926535897932, 0.00072178415907472774, PAL_EPSILON / 1000 }, // y: -(pi) + { 10, -2.7182818284590452, 0.0019130141022243176, PAL_EPSILON / 100 }, // y: -(e) + { 10, -2.3025850929940457, 0.0049821282964407206, PAL_EPSILON / 100 }, // y: -(ln(10)) + { 10, -1.5707963267948966, 0.026866041001136132, PAL_EPSILON / 10 }, // y: -(pi / 2) + { 10, -1.4426950408889634, 0.036083192820787210, PAL_EPSILON / 10 }, // y: -(log2(e)) + { 10, -1.4142135623730950, 0.038528884700322026, PAL_EPSILON / 10 }, // y: -(sqrt(2)) + { 10, -1.1283791670955126, 0.074408205860642723, PAL_EPSILON / 10 }, // y: -(2 / sqrt(pi)) + { 10, -1, 0.1, PAL_EPSILON }, // y: -(1) + { 10, -0.78539816339744831, 0.16390863613957665, PAL_EPSILON }, // y: -(pi / 4) + { 10, -0.70710678118654752, 0.19628775993505562, PAL_EPSILON }, // y: -(1 / sqrt(2)) + { 10, -0.69314718055994531, 0.20269956628651730, PAL_EPSILON }, // y: -(ln(2)) + { 10, -0.63661977236758134, 0.23087676451600055, PAL_EPSILON }, // y: -(2 / pi) + { 10, -0.43429448190325183, 0.36787944117144232, PAL_EPSILON }, // y: -(log10(e)) + { 10, -0.31830988618379067, 0.48049637305186868, PAL_EPSILON }, // y: -(1 / pi) + { 10, 0, 1, PAL_EPSILON * 10 }, + { 10, 0.31830988618379067, 2.0811811619898573, PAL_EPSILON * 10 }, // y: 1 / pi + { 10, 0.43429448190325183, 2.7182818284590452, PAL_EPSILON * 10 }, // y: log10(e) expected: e + { 10, 0.63661977236758134, 4.3313150290214525, PAL_EPSILON * 10 }, // y: 2 / pi + { 10, 0.69314718055994531, 4.9334096679145963, PAL_EPSILON * 10 }, // y: ln(2) + { 10, 0.70710678118654752, 5.0945611704512962, PAL_EPSILON * 10 }, // y: 1 / sqrt(2) + { 10, 0.78539816339744831, 6.1009598002416937, PAL_EPSILON * 10 }, // y: pi / 4 + { 10, 1, 10, PAL_EPSILON * 100 }, + { 10, 1.1283791670955126, 13.439377934644400, PAL_EPSILON * 100 }, // y: 2 / sqrt(pi) + { 10, 1.4142135623730950, 25.954553519470081, PAL_EPSILON * 100 }, // y: sqrt(2) + { 10, 1.4426950408889634, 27.713733786437790, PAL_EPSILON * 100 }, // y: log2(e) + { 10, 1.5707963267948966, 37.221710484165167, PAL_EPSILON * 100 }, // y: pi / 2 + { 10, 2.3025850929940457, 200.71743249053009, PAL_EPSILON * 1000 }, // y: ln(10) + { 10, 2.7182818284590452, 522.73529967043665, PAL_EPSILON * 1000 }, // y: e + { 10, 3.1415926535897932, 1385.4557313670111, PAL_EPSILON * 10000 }, // y: pi + { 10, PAL_POSINF, PAL_POSINF, 0 }, + + { PAL_POSINF, PAL_NEGINF, 0, PAL_EPSILON }, + { PAL_POSINF, PAL_POSINF, PAL_POSINF, 0 }, + }; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].x, tests[i].y, tests[i].expected, tests[i].variance); + } + + validate_isnan(-10, -1.5707963267948966); // y: -(pi / 2) + validate_isnan(-10, -0.78539816339744828); // y: -(pi / 4) + validate_isnan(-10, 0.78539816339744828); // y: pi / 4 + validate_isnan(-10, 1.5707963267948966); // y: pi / 2 + + validate_isnan(-2.7182818284590452, -1.5707963267948966); // x: -(e) y: -(pi / 2) + validate_isnan(-2.7182818284590452, -0.78539816339744828); // x: -(e) y: -(pi / 4) + validate_isnan(-2.7182818284590452, 0.78539816339744828); // x: -(e) y: pi / 4 + validate_isnan(-2.7182818284590452, 1.5707963267948966); // x: -(e) y: pi / 2 + + validate_isnan(-1, PAL_NEGINF); + validate_isnan(-1, PAL_POSINF); + + validate_isnan(PAL_NAN, -0.0); + validate_isnan(PAL_NAN, 0); + + validate_isnan(PAL_NEGINF, PAL_NAN); + validate_isnan(PAL_NAN, PAL_NEGINF); + + validate_isnan(PAL_POSINF, PAL_NAN); + validate_isnan(PAL_NAN, PAL_POSINF); + + validate_isnan(PAL_NAN, PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/powf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/powf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/powf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/powf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/powf/test1/CMakeLists.txt new file mode 100644 index 0000000000..8ea040f9a4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/powf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_powf_test1 + ${SOURCES} +) + +add_dependencies(paltest_powf_test1 coreclrpal) + +target_link_libraries(paltest_powf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/powf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/powf/test1/test1.c new file mode 100644 index 0000000000..ca738e8c8d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/powf/test1/test1.c @@ -0,0 +1,229 @@ +// 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: test1.c +** +** Purpose: Tests that atan2f returns correct values for a subset of values. +** Tests with positive and negative values of x and y to ensure +** atan2f is returning results from the correct quadrant. +** +**===================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float x; /* first component of the value to test the function with */ + float y; /* second component of the value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float x, float y, float expected, float variance) +{ + float result = powf(x, y); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("powf(%g, %g) returned %10.9g when it should have returned %10.9g", + x, y, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float x, float y) +{ + float result = powf(x, y); + + if (!_isnanf(result)) + { + Fail("powf(%g, %g) returned %10.9g when it should have returned %10.9g", + x, y, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* x y expected variance */ + { PAL_NEGINF, PAL_NEGINF, 0, PAL_EPSILON }, + { PAL_NEGINF, PAL_POSINF, PAL_POSINF, 0 }, + + { -10, PAL_NEGINF, 0, PAL_EPSILON }, + { -10, -1, -0.1f, PAL_EPSILON }, + { -10, 0, 1, PAL_EPSILON * 10 }, + { -10, 1, -10, PAL_EPSILON * 100 }, + { -10, PAL_POSINF, PAL_POSINF, 0 }, + + { -2.71828183f, PAL_NEGINF, 0, PAL_EPSILON }, // x: -(e) + { -2.71828183f, -1, -0.367879441f, PAL_EPSILON }, // x: -(e) + { -2.71828183f, 0, 1, PAL_EPSILON * 10 }, // x: -(e) + { -2.71828183f, 1, -2.71828183f, PAL_EPSILON * 10 }, // x: -(e) expected: e + { -2.71828183f, PAL_POSINF, PAL_POSINF, 0 }, // x: -(e) + + { -0.0, PAL_NEGINF, PAL_POSINF, 0 }, + { -0.0, -1, PAL_NEGINF, 0 }, + { -0.0f, -0.0f, 1, PAL_EPSILON * 10 }, + { -0.0f, 0, 1, PAL_EPSILON * 10 }, + { -0.0, 1, -0.0, PAL_EPSILON }, + { -0.0, PAL_POSINF, 0, PAL_EPSILON }, + + { 0.0, PAL_NEGINF, PAL_POSINF, 0 }, + { 0.0, -1, PAL_POSINF, 0 }, + { 0, -0.0f, 1, PAL_EPSILON * 10 }, + { 0, 0, 1, PAL_EPSILON * 10 }, + { 0.0, 1, 0, PAL_EPSILON }, + { 0.0, PAL_POSINF, 0, PAL_EPSILON }, + + { 1, PAL_NEGINF, 1, PAL_EPSILON * 10 }, + { 1, PAL_POSINF, 1, PAL_EPSILON * 10 }, + + { 2.71828183f, PAL_NEGINF, 0, PAL_EPSILON }, + { 2.71828183f, -3.14159265f, 0.0432139183f, PAL_EPSILON / 10 }, // x: e y: -(pi) + { 2.71828183f, -2.71828183f, 0.0659880358f, PAL_EPSILON / 10 }, // x: e y: -(e) + { 2.71828183f, -2.30258509f, 0.1f, PAL_EPSILON }, // x: e y: -(ln(10)) + { 2.71828183f, -1.57079633f, 0.207879576f, PAL_EPSILON }, // x: e y: -(pi / 2) + { 2.71828183f, -1.44269504f, 0.236290088f, PAL_EPSILON }, // x: e y: -(logf2(e)) + { 2.71828183f, -1.41421356f, 0.243116734f, PAL_EPSILON }, // x: e y: -(sqrtf(2)) + { 2.71828183f, -1.12837917f, 0.323557264f, PAL_EPSILON }, // x: e y: -(2 / sqrtf(pi)) + { 2.71828183f, -1, 0.367879441f, PAL_EPSILON }, // x: e y: -(1) + { 2.71828183f, -0.785398163f, 0.455938128f, PAL_EPSILON }, // x: e y: -(pi / 4) + { 2.71828183f, -0.707106781f, 0.493068691f, PAL_EPSILON }, // x: e y: -(1 / sqrtf(2)) + { 2.71828183f, -0.693147181f, 0.5f, PAL_EPSILON }, // x: e y: -(ln(2)) + { 2.71828183f, -0.636619772f, 0.529077808f, PAL_EPSILON }, // x: e y: -(2 / pi) + { 2.71828183f, -0.434294482f, 0.647721485f, PAL_EPSILON }, // x: e y: -(log10f(e)) + { 2.71828183f, -0.318309886f, 0.727377349f, PAL_EPSILON }, // x: e y: -(1 / pi) + { 2.71828183f, 0, 1, PAL_EPSILON * 10 }, // x: e + { 2.71828183f, 0.318309886f, 1.37480223f, PAL_EPSILON * 10 }, // x: e y: 1 / pi + { 2.71828183f, 0.434294482f, 1.54387344f, PAL_EPSILON * 10 }, // x: e y: log10f(e) + { 2.71828183f, 0.636619772f, 1.89008116f, PAL_EPSILON * 10 }, // x: e y: 2 / pi + { 2.71828183f, 0.693147181f, 2, PAL_EPSILON * 10 }, // x: e y: ln(2) + { 2.71828183f, 0.707106781f, 2.02811498f, PAL_EPSILON * 10 }, // x: e y: 1 / sqrtf(2) + { 2.71828183f, 0.785398163f, 2.19328005f, PAL_EPSILON * 10 }, // x: e y: pi / 4 + { 2.71828183f, 1, 2.71828183f, PAL_EPSILON * 10 }, // x: e expected: e + { 2.71828183f, 1.12837917f, 3.09064302f, PAL_EPSILON * 10 }, // x: e y: 2 / sqrtf(pi) + { 2.71828183f, 1.41421356f, 4.11325038f, PAL_EPSILON * 10 }, // x: e y: sqrtf(2) + { 2.71828183f, 1.44269504f, 4.23208611f, PAL_EPSILON * 10 }, // x: e y: logf2(e) + { 2.71828183f, 1.57079633f, 4.81047738f, PAL_EPSILON * 10 }, // x: e y: pi / 2 + { 2.71828183f, 2.30258509f, 10, PAL_EPSILON * 100 }, // x: e y: ln(10) + { 2.71828183f, 2.71828183f, 15.1542622f, PAL_EPSILON * 100 }, // x: e y: e + { 2.71828183f, 3.14159265f, 23.1406926f, PAL_EPSILON * 100 }, // x: e y: pi + { 2.71828183f, PAL_POSINF, PAL_POSINF, 0 }, // x: e + + { 10, PAL_NEGINF, 0, 0 }, + { 10, -3.14159265f, 0.000721784159f, PAL_EPSILON / 1000 }, // y: -(pi) + { 10, -2.71828183f, 0.00191301410f, PAL_EPSILON / 100 }, // y: -(e) + { 10, -2.30258509f, 0.00498212830f, PAL_EPSILON / 100 }, // y: -(ln(10)) + { 10, -1.57079633f, 0.0268660410f, PAL_EPSILON / 10 }, // y: -(pi / 2) + { 10, -1.44269504f, 0.0360831928f, PAL_EPSILON / 10 }, // y: -(logf2(e)) + { 10, -1.41421356f, 0.0385288847f, PAL_EPSILON / 10 }, // y: -(sqrtf(2)) + { 10, -1.12837917f, 0.0744082059f, PAL_EPSILON / 10 }, // y: -(2 / sqrtf(pi)) + { 10, -1, 0.1f, PAL_EPSILON }, // y: -(1) + { 10, -0.785398163f, 0.163908636f, PAL_EPSILON }, // y: -(pi / 4) + { 10, -0.707106781f, 0.196287760f, PAL_EPSILON }, // y: -(1 / sqrtf(2)) + { 10, -0.693147181f, 0.202699566f, PAL_EPSILON }, // y: -(ln(2)) + { 10, -0.636619772f, 0.230876765f, PAL_EPSILON }, // y: -(2 / pi) + { 10, -0.434294482f, 0.367879441f, PAL_EPSILON }, // y: -(log10f(e)) + { 10, -0.318309886f, 0.480496373f, PAL_EPSILON }, // y: -(1 / pi) + { 10, 0, 1, PAL_EPSILON * 10 }, + { 10, 0.318309886f, 2.08118116f, PAL_EPSILON * 10 }, // y: 1 / pi + { 10, 0.434294482f, 2.71828183f, PAL_EPSILON * 10 }, // y: log10f(e) expected: e + { 10, 0.636619772f, 4.33131503f, PAL_EPSILON * 10 }, // y: 2 / pi + { 10, 0.693147181f, 4.93340967f, PAL_EPSILON * 10 }, // y: ln(2) + { 10, 0.707106781f, 5.09456117f, PAL_EPSILON * 10 }, // y: 1 / sqrtf(2) + { 10, 0.785398163f, 6.10095980f, PAL_EPSILON * 10 }, // y: pi / 4 + { 10, 1, 10, PAL_EPSILON * 100 }, + { 10, 1.12837917f, 13.4393779f, PAL_EPSILON * 100 }, // y: 2 / sqrtf(pi) + { 10, 1.41421356f, 25.9545535f, PAL_EPSILON * 100 }, // y: sqrtf(2) + { 10, 1.44269504f, 27.7137338f, PAL_EPSILON * 100 }, // y: logf2(e) + { 10, 1.57079633f, 37.2217105f, PAL_EPSILON * 100 }, // y: pi / 2 + { 10, 2.30258509f, 200.717432f, PAL_EPSILON * 1000 }, // y: ln(10) + { 10, 2.71828183f, 522.735300f, PAL_EPSILON * 1000 }, // y: e + { 10, 3.14159265f, 1385.45573f, PAL_EPSILON * 10000 }, // y: pi + { 10, PAL_POSINF, PAL_POSINF, 0 }, + + { PAL_POSINF, PAL_NEGINF, 0, PAL_EPSILON }, + { PAL_POSINF, PAL_POSINF, PAL_POSINF, 0 }, + }; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].x, tests[i].y, tests[i].expected, tests[i].variance); + } + + validate_isnan(-10, -1.57079633f); // y: -(pi / 2) + validate_isnan(-10, -0.785398163f); // y: -(pi / 4) + validate_isnan(-10, 0.785398163f); // y: pi / 4 + validate_isnan(-10, 1.57079633f); // y: pi / 2 + + validate_isnan(-2.71828183f, -1.57079633f); // x: -(e) y: -(pi / 2) + validate_isnan(-2.71828183f, -0.785398163f); // x: -(e) y: -(pi / 4) + validate_isnan(-2.71828183f, 0.785398163f); // x: -(e) y: pi / 4 + validate_isnan(-2.71828183f, 1.57079633f); // x: -(e) y: pi / 2 + + validate_isnan(-1, PAL_NEGINF); + validate_isnan(-1, PAL_POSINF); + + validate_isnan(PAL_NAN, -0.0); + validate_isnan(PAL_NAN, 0); + + validate_isnan(PAL_NEGINF, PAL_NAN); + validate_isnan(PAL_NAN, PAL_NEGINF); + + validate_isnan(PAL_POSINF, PAL_NAN); + validate_isnan(PAL_NAN, PAL_POSINF); + + validate_isnan(PAL_NAN, PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/powf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/powf/test1/testinfo.dat new file mode 100644 index 0000000000..778c042025 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/powf/test1/testinfo.dat @@ -0,0 +1,17 @@ +# 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 = C Runtime +Function = powf +Name = Call powf with some std input/output. +TYPE = DEFAULT +EXE1 = test1 +Description += Call the powf function with various num/expfonent pairs += that should produce std answers. + + + + diff --git a/src/pal/tests/palsuite/c_runtime/printf/printf.h b/src/pal/tests/palsuite/c_runtime/printf/printf.h index 2eaa984bad..8ef725f305 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/printf.h +++ b/src/pal/tests/palsuite/c_runtime/printf/printf.h @@ -14,7 +14,7 @@ #ifndef __printf_H__ #define __printf_H__ -void DoStrTest(char *formatstr, char* param, char *checkstr) +void DoStrTest(const char *formatstr, char* param, const char *checkstr) { int ret; @@ -26,7 +26,7 @@ void DoStrTest(char *formatstr, char* param, char *checkstr) } } -void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) +void DoWStrTest(const char *formatstr, WCHAR* param, const char *checkstr) { int ret; @@ -38,8 +38,8 @@ void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) } } -void DoPointerTest(char *formatstr, void* param, char* paramstr, - char *checkstr1) +void DoPointerTest(const char *formatstr, void* param, char* paramstr, + const char *checkstr1) { int ret; @@ -51,7 +51,7 @@ void DoPointerTest(char *formatstr, void* param, char* paramstr, } } -void DoCountTest(char *formatstr, int param, char *checkstr) +void DoCountTest(const char *formatstr, int param, const char *checkstr) { int ret; int n = -1; @@ -70,7 +70,7 @@ void DoCountTest(char *formatstr, int param, char *checkstr) } } -void DoShortCountTest(char *formatstr, int param, char *checkstr) +void DoShortCountTest(const char *formatstr, int param, const char *checkstr) { int ret; short int n = -1; @@ -90,7 +90,7 @@ void DoShortCountTest(char *formatstr, int param, char *checkstr) } -void DoCharTest(char *formatstr, char param, char *checkstr) +void DoCharTest(const char *formatstr, char param, const char *checkstr) { int ret; @@ -102,7 +102,7 @@ void DoCharTest(char *formatstr, char param, char *checkstr) } } -void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) +void DoWCharTest(const char *formatstr, WCHAR param, const char *checkstr) { int ret; @@ -114,7 +114,7 @@ void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) } } -void DoNumTest(char *formatstr, int param, char *checkstr) +void DoNumTest(const char *formatstr, int param, const char *checkstr) { int ret; @@ -126,8 +126,8 @@ void DoNumTest(char *formatstr, int param, char *checkstr) } } -void DoI64Test(char *formatstr, INT64 param, char *valuestr, - char *checkstr1) +void DoI64Test(const char *formatstr, INT64 param, char *valuestr, + const char *checkstr1) { int ret; @@ -139,8 +139,8 @@ void DoI64Test(char *formatstr, INT64 param, char *valuestr, } } -void DoDoubleTest(char *formatstr, double param, - char *checkstr1, char *checkstr2) +void DoDoubleTest(const char *formatstr, double param, + const char *checkstr1, const char *checkstr2) { int ret; @@ -152,8 +152,8 @@ void DoDoubleTest(char *formatstr, double param, } } -void DoArgumentPrecTest(char *formatstr, int precision, void *param, - char *paramstr, char *checkstr1, char *checkstr2) +void DoArgumentPrecTest(const char *formatstr, int precision, void *param, + char *paramstr, const char *checkstr1, const char *checkstr2) { int ret; @@ -165,8 +165,8 @@ void DoArgumentPrecTest(char *formatstr, int precision, void *param, } } -void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param, - char *checkstr1, char *checkstr2) +void DoArgumentPrecDoubleTest(const char *formatstr, int precision, double param, + const char *checkstr1, const char *checkstr2) { int ret; diff --git a/src/pal/tests/palsuite/c_runtime/printf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test1/CMakeLists.txt index bea9151ed7..2dace14f90 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_printf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/printf/test1/test1.c deleted file mode 100644 index 31b7014343..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test1/test1.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the printf function. A single, basic, test -** case with no formatting. -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - -int __cdecl main(int argc, char *argv[]) -{ - char checkstr[] = "hello world"; - int ret; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - ret = printf("hello world"); - - if (ret != strlen(checkstr)) - { - Fail("Expected printf to return %d, got %d.\n", - strlen(checkstr), ret); - - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/printf/test1/test1.cpp new file mode 100644 index 0000000000..31b7014343 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test1/test1.cpp @@ -0,0 +1,43 @@ +// 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: test1.c +** +** Purpose: Test #1 for the printf function. A single, basic, test +** case with no formatting. +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + +int __cdecl main(int argc, char *argv[]) +{ + char checkstr[] = "hello world"; + int ret; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + ret = printf("hello world"); + + if (ret != strlen(checkstr)) + { + Fail("Expected printf to return %d, got %d.\n", + strlen(checkstr), ret); + + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test10/CMakeLists.txt index 89ff2e0190..75e30c8599 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_printf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/printf/test10/test10.c deleted file mode 100644 index 5e69175b07..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test10/test10.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test10.c -** -** Purpose: Test #10 for the printf function. Tests the octal specifier -** (%o). -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %o", pos, "foo 52"); - DoNumTest("foo %lo", 0xFFFF, "foo 177777"); - DoNumTest("foo %ho", 0xFFFF, "foo 177777"); - DoNumTest("foo %Lo", pos, "foo 52"); - DoI64Test("foo %I64o", l, "42", "foo 52"); - DoNumTest("foo %3o", pos, "foo 52"); - DoNumTest("foo %-3o", pos, "foo 52 "); - DoNumTest("foo %.1o", pos, "foo 52"); - DoNumTest("foo %.3o", pos, "foo 052"); - DoNumTest("foo %03o", pos, "foo 052"); - DoNumTest("foo %#o", pos, "foo 052"); - DoNumTest("foo %+o", pos, "foo 52"); - DoNumTest("foo % o", pos, "foo 52"); - DoNumTest("foo %+o", neg, "foo 37777777726"); - DoNumTest("foo % o", neg, "foo 37777777726"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/printf/test10/test10.cpp new file mode 100644 index 0000000000..5e69175b07 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test10/test10.cpp @@ -0,0 +1,52 @@ +// 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: test10.c +** +** Purpose: Test #10 for the printf function. Tests the octal specifier +** (%o). +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %o", pos, "foo 52"); + DoNumTest("foo %lo", 0xFFFF, "foo 177777"); + DoNumTest("foo %ho", 0xFFFF, "foo 177777"); + DoNumTest("foo %Lo", pos, "foo 52"); + DoI64Test("foo %I64o", l, "42", "foo 52"); + DoNumTest("foo %3o", pos, "foo 52"); + DoNumTest("foo %-3o", pos, "foo 52 "); + DoNumTest("foo %.1o", pos, "foo 52"); + DoNumTest("foo %.3o", pos, "foo 052"); + DoNumTest("foo %03o", pos, "foo 052"); + DoNumTest("foo %#o", pos, "foo 052"); + DoNumTest("foo %+o", pos, "foo 52"); + DoNumTest("foo % o", pos, "foo 52"); + DoNumTest("foo %+o", neg, "foo 37777777726"); + DoNumTest("foo % o", neg, "foo 37777777726"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test11/CMakeLists.txt index 349f154a8d..4ee12dc21d 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_printf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/printf/test11/test11.c deleted file mode 100644 index 788be8b2db..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test11/test11.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test11.c -** -** Purpose: Test #11 for the printf function. Test the unsigned int -** specifier (%u). -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %u", pos, "foo 42"); - DoNumTest("foo %lu", 0xFFFF, "foo 65535"); - DoNumTest("foo %hu", 0xFFFF, "foo 65535"); - DoNumTest("foo %Lu", pos, "foo 42"); - DoI64Test("foo %I64u", l, "42", "foo 42"); - DoNumTest("foo %3u", pos, "foo 42"); - DoNumTest("foo %-3u", pos, "foo 42 "); - DoNumTest("foo %.1u", pos, "foo 42"); - DoNumTest("foo %.3u", pos, "foo 042"); - DoNumTest("foo %03u", pos, "foo 042"); - DoNumTest("foo %#u", pos, "foo 42"); - DoNumTest("foo %+u", pos, "foo 42"); - DoNumTest("foo % u", pos, "foo 42"); - DoNumTest("foo %+u", neg, "foo 4294967254"); - DoNumTest("foo % u", neg, "foo 4294967254"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/printf/test11/test11.cpp new file mode 100644 index 0000000000..788be8b2db --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test11/test11.cpp @@ -0,0 +1,51 @@ +// 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: test11.c +** +** Purpose: Test #11 for the printf function. Test the unsigned int +** specifier (%u). +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %u", pos, "foo 42"); + DoNumTest("foo %lu", 0xFFFF, "foo 65535"); + DoNumTest("foo %hu", 0xFFFF, "foo 65535"); + DoNumTest("foo %Lu", pos, "foo 42"); + DoI64Test("foo %I64u", l, "42", "foo 42"); + DoNumTest("foo %3u", pos, "foo 42"); + DoNumTest("foo %-3u", pos, "foo 42 "); + DoNumTest("foo %.1u", pos, "foo 42"); + DoNumTest("foo %.3u", pos, "foo 042"); + DoNumTest("foo %03u", pos, "foo 042"); + DoNumTest("foo %#u", pos, "foo 42"); + DoNumTest("foo %+u", pos, "foo 42"); + DoNumTest("foo % u", pos, "foo 42"); + DoNumTest("foo %+u", neg, "foo 4294967254"); + DoNumTest("foo % u", neg, "foo 4294967254"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test12/CMakeLists.txt index 0d32ee1690..3b2e39d640 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_printf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/printf/test12/test12.c deleted file mode 100644 index b4006f2405..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test12/test12.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test12.c -** -** Purpose: Test #12 for the printf function. Tests the (lowercase) -** hexadecimal specifier (%x) -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %x", pos, "foo 1234ab"); - DoNumTest("foo %lx", pos, "foo 1234ab"); - DoNumTest("foo %hx", pos, "foo 34ab"); - DoNumTest("foo %Lx", pos, "foo 1234ab"); - DoI64Test("foo %I64x", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7x", pos, "foo 1234ab"); - DoNumTest("foo %-7x", pos, "foo 1234ab "); - DoNumTest("foo %.1x", pos, "foo 1234ab"); - DoNumTest("foo %.7x", pos, "foo 01234ab"); - DoNumTest("foo %07x", pos, "foo 01234ab"); - DoNumTest("foo %#x", pos, "foo 0x1234ab"); - DoNumTest("foo %+x", pos, "foo 1234ab"); - DoNumTest("foo % x", pos, "foo 1234ab"); - DoNumTest("foo %+x", neg, "foo ffffffd6"); - DoNumTest("foo % x", neg, "foo ffffffd6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/printf/test12/test12.cpp new file mode 100644 index 0000000000..b4006f2405 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test12/test12.cpp @@ -0,0 +1,53 @@ +// 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: test12.c +** +** Purpose: Test #12 for the printf function. Tests the (lowercase) +** hexadecimal specifier (%x) +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %x", pos, "foo 1234ab"); + DoNumTest("foo %lx", pos, "foo 1234ab"); + DoNumTest("foo %hx", pos, "foo 34ab"); + DoNumTest("foo %Lx", pos, "foo 1234ab"); + DoI64Test("foo %I64x", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7x", pos, "foo 1234ab"); + DoNumTest("foo %-7x", pos, "foo 1234ab "); + DoNumTest("foo %.1x", pos, "foo 1234ab"); + DoNumTest("foo %.7x", pos, "foo 01234ab"); + DoNumTest("foo %07x", pos, "foo 01234ab"); + DoNumTest("foo %#x", pos, "foo 0x1234ab"); + DoNumTest("foo %+x", pos, "foo 1234ab"); + DoNumTest("foo % x", pos, "foo 1234ab"); + DoNumTest("foo %+x", neg, "foo ffffffd6"); + DoNumTest("foo % x", neg, "foo ffffffd6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test13/CMakeLists.txt index 348d25b22d..b6af021d48 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_printf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/printf/test13/test13.c deleted file mode 100644 index ccd16b50d2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test13/test13.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test13.c -** -** Purpose: Test #13 for the printf function. Tests the (uppercase) -** hexadecimal specifier (%X) -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234AB; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %X", pos, "foo 1234AB"); - DoNumTest("foo %lX", pos, "foo 1234AB"); - DoNumTest("foo %hX", pos, "foo 34AB"); - DoNumTest("foo %LX", pos, "foo 1234AB"); - DoI64Test("foo %I64X", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7X", pos, "foo 1234AB"); - DoNumTest("foo %-7X", pos, "foo 1234AB "); - DoNumTest("foo %.1X", pos, "foo 1234AB"); - DoNumTest("foo %.7X", pos, "foo 01234AB"); - DoNumTest("foo %07X", pos, "foo 01234AB"); - DoNumTest("foo %#X", pos, "foo 0X1234AB"); - DoNumTest("foo %+X", pos, "foo 1234AB"); - DoNumTest("foo % X", pos, "foo 1234AB"); - DoNumTest("foo %+X", neg, "foo FFFFFFD6"); - DoNumTest("foo % X", neg, "foo FFFFFFD6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/printf/test13/test13.cpp new file mode 100644 index 0000000000..ccd16b50d2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test13/test13.cpp @@ -0,0 +1,54 @@ +// 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: test13.c +** +** Purpose: Test #13 for the printf function. Tests the (uppercase) +** hexadecimal specifier (%X) +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234AB; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %X", pos, "foo 1234AB"); + DoNumTest("foo %lX", pos, "foo 1234AB"); + DoNumTest("foo %hX", pos, "foo 34AB"); + DoNumTest("foo %LX", pos, "foo 1234AB"); + DoI64Test("foo %I64X", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7X", pos, "foo 1234AB"); + DoNumTest("foo %-7X", pos, "foo 1234AB "); + DoNumTest("foo %.1X", pos, "foo 1234AB"); + DoNumTest("foo %.7X", pos, "foo 01234AB"); + DoNumTest("foo %07X", pos, "foo 01234AB"); + DoNumTest("foo %#X", pos, "foo 0X1234AB"); + DoNumTest("foo %+X", pos, "foo 1234AB"); + DoNumTest("foo % X", pos, "foo 1234AB"); + DoNumTest("foo %+X", neg, "foo FFFFFFD6"); + DoNumTest("foo % X", neg, "foo FFFFFFD6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test14/CMakeLists.txt index 659ea78cc6..5a6cf8a180 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_printf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/printf/test14/test14.c deleted file mode 100644 index 10577db67d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test14/test14.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test14.c -** -** Purpose: Test #14 for the printf function. Tests the lowercase -** exponential notation double specifier (%e) -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", - "foo 2.560000e+02 "); - DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); - DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", - "foo 2.56000000e+02"); - DoDoubleTest("foo %014e", val, "foo 02.560000e+002", - "foo 002.560000e+02"); - DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); - DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/printf/test14/test14.cpp new file mode 100644 index 0000000000..10577db67d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test14/test14.cpp @@ -0,0 +1,54 @@ +// 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: test14.c +** +** Purpose: Test #14 for the printf function. Tests the lowercase +** exponential notation double specifier (%e) +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", + "foo 2.560000e+02 "); + DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); + DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", + "foo 2.56000000e+02"); + DoDoubleTest("foo %014e", val, "foo 02.560000e+002", + "foo 002.560000e+02"); + DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); + DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test15/CMakeLists.txt index 9e4e310304..b1466a387d 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_printf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/printf/test15/test15.c deleted file mode 100644 index 2acfc436a3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test15/test15.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test15.c -** -** Purpose: Test #15 for the printf function. Tests the uppercase -** exponential notation double specifier (%E) -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", - "foo 2.560000E+02 "); - DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); - DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", - "foo 2.56000000E+02"); - DoDoubleTest("foo %014E", val, "foo 02.560000E+002", - "foo 002.560000E+02"); - DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); - DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/printf/test15/test15.cpp new file mode 100644 index 0000000000..2acfc436a3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test15/test15.cpp @@ -0,0 +1,54 @@ +// 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: test15.c +** +** Purpose: Test #15 for the printf function. Tests the uppercase +** exponential notation double specifier (%E) +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", + "foo 2.560000E+02 "); + DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); + DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", + "foo 2.56000000E+02"); + DoDoubleTest("foo %014E", val, "foo 02.560000E+002", + "foo 002.560000E+02"); + DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); + DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test16/CMakeLists.txt index 7e477a3059..c81da10ec9 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_printf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/printf/test16/test16.c deleted file mode 100644 index 50c952f959..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test16/test16.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test16.c -** -** Purpose: Test #16 for the printf function. Tests the decimal notation -** double specifier (%f) -** -** -**==========================================================================*/ - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); - DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); - DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); - DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); - DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); - DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); - DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/printf/test16/test16.cpp new file mode 100644 index 0000000000..50c952f959 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test16/test16.cpp @@ -0,0 +1,50 @@ +// 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: test16.c +** +** Purpose: Test #16 for the printf function. Tests the decimal notation +** double specifier (%f) +** +** +**==========================================================================*/ + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); + DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); + DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); + DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); + DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); + DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); + DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test17/CMakeLists.txt index c18450c2aa..9d40e54ca6 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_printf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/printf/test17/test17.c deleted file mode 100644 index 96ddd5c1e4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test17/test17.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test17.c -** -** Purpose: Test #17 for the printf function. Tests the lowercase -** shorthand notation double specifier (%g) -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); - DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); - DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/printf/test17/test17.cpp new file mode 100644 index 0000000000..96ddd5c1e4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test17/test17.cpp @@ -0,0 +1,52 @@ +// 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: test17.c +** +** Purpose: Test #17 for the printf function. Tests the lowercase +** shorthand notation double specifier (%g) +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); + DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); + DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test18/CMakeLists.txt index b0468314a3..6ab11f4be1 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test18.c + test18.cpp ) add_executable(paltest_printf_test18 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/printf/test18/test18.c deleted file mode 100644 index 6c05e40f42..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test18/test18.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the printf function. Tests the uppercase -** shorthand notation double specifier (%G) -** -** -**==========================================================================*/ - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); - DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); - DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/printf/test18/test18.cpp new file mode 100644 index 0000000000..6c05e40f42 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test18/test18.cpp @@ -0,0 +1,51 @@ +// 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: test18.c +** +** Purpose: Test #18 for the printf function. Tests the uppercase +** shorthand notation double specifier (%G) +** +** +**==========================================================================*/ + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); + DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); + DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test19/CMakeLists.txt index efd47563d4..f022938e32 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test19.c + test19.cpp ) add_executable(paltest_printf_test19 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/printf/test19/test19.c deleted file mode 100644 index 1e09398f7c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test19/test19.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: test19.c -** -** Purpose: Test #19 for the printf function. Tests the variable length -** precision argument. -** -** -**==========================================================================*/ - - -#include -#include "../printf.h" - - - - -int __cdecl main(int argc, char *argv[]) -{ - int n = -1; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoArgumentPrecTest("%.*s", 2, "bar", "bar", "ba", "ba"); - DoArgumentPrecTest("%.*S", 2, convert("bar"), "bar", "ba", "ba"); - - DoArgumentPrecTest("%.*n", 3, &n, "pointer to int", "", ""); - if (n != 0) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - 0, n); - } - - DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); - DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); - DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); - DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); - - - DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); - DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); - DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); - DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); - DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); - DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); - DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); - DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); - DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); - DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/printf/test19/test19.cpp new file mode 100644 index 0000000000..a3ce0e7ad8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test19/test19.cpp @@ -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: test19.c +** +** Purpose: Test #19 for the printf function. Tests the variable length +** precision argument. +** +** +**==========================================================================*/ + + +#include +#include "../printf.h" + + + + +int __cdecl main(int argc, char *argv[]) +{ + int n = -1; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoArgumentPrecTest("%.*s", 2, (void*)"bar", "bar", "ba", "ba"); + DoArgumentPrecTest("%.*S", 2, (void*)convert("bar"), "bar", "ba", "ba"); + + DoArgumentPrecTest("%.*n", 3, (void*)&n, "pointer to int", "", ""); + if (n != 0) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + 0, n); + } + + DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); + DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); + DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); + DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); + + + DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); + DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); + DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); + DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); + DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); + DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); + DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); + DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); + DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); + DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test2/CMakeLists.txt index c303a69134..e92b6b09f3 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_printf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/printf/test2/test2.c deleted file mode 100644 index e766ef4a90..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test2/test2.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the printf function. Tests the string specifier -** (%s). -** -** -**==========================================================================*/ - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoStrTest("foo %s", "bar", "foo bar"); - DoStrTest("foo %hs", "bar", "foo bar"); - DoWStrTest("foo %ls", convert("bar"), "foo bar"); - DoWStrTest("foo %ws", convert("bar"), "foo bar"); - DoStrTest("foo %Ls", "bar", "foo bar"); - DoStrTest("foo %I64s", "bar", "foo bar"); - DoStrTest("foo %5s", "bar", "foo bar"); - DoStrTest("foo %.2s", "bar", "foo ba"); - DoStrTest("foo %5.2s", "bar", "foo ba"); - DoStrTest("foo %-5s", "bar", "foo bar "); - DoStrTest("foo %05s", "bar", "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/printf/test2/test2.cpp new file mode 100644 index 0000000000..e766ef4a90 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test2/test2.cpp @@ -0,0 +1,45 @@ +// 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: test2.c +** +** Purpose: Test #2 for the printf function. Tests the string specifier +** (%s). +** +** +**==========================================================================*/ + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoStrTest("foo %s", "bar", "foo bar"); + DoStrTest("foo %hs", "bar", "foo bar"); + DoWStrTest("foo %ls", convert("bar"), "foo bar"); + DoWStrTest("foo %ws", convert("bar"), "foo bar"); + DoStrTest("foo %Ls", "bar", "foo bar"); + DoStrTest("foo %I64s", "bar", "foo bar"); + DoStrTest("foo %5s", "bar", "foo bar"); + DoStrTest("foo %.2s", "bar", "foo ba"); + DoStrTest("foo %5.2s", "bar", "foo ba"); + DoStrTest("foo %-5s", "bar", "foo bar "); + DoStrTest("foo %05s", "bar", "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test3/CMakeLists.txt index 8bc7479797..fcfd779a0c 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_printf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/printf/test3/test3.c deleted file mode 100644 index 5cc530948c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test3/test3.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the printf function. Tests the wide string -** specifier (%S). -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoWStrTest("foo %S", convert("bar"), "foo bar"); - DoStrTest("foo %hS", "bar", "foo bar"); - DoWStrTest("foo %lS", convert("bar"), "foo bar"); - DoWStrTest("foo %wS", convert("bar"), "foo bar"); - DoWStrTest("foo %LS", convert("bar"), "foo bar"); - DoWStrTest("foo %I64S", convert("bar"), "foo bar"); - DoWStrTest("foo %5S", convert("bar"), "foo bar"); - DoWStrTest("foo %.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %-5S", convert("bar"), "foo bar "); - DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/printf/test3/test3.cpp new file mode 100644 index 0000000000..5cc530948c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test3/test3.cpp @@ -0,0 +1,45 @@ +// 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: test3.c +** +** Purpose: Test #3 for the printf function. Tests the wide string +** specifier (%S). +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoWStrTest("foo %S", convert("bar"), "foo bar"); + DoStrTest("foo %hS", "bar", "foo bar"); + DoWStrTest("foo %lS", convert("bar"), "foo bar"); + DoWStrTest("foo %wS", convert("bar"), "foo bar"); + DoWStrTest("foo %LS", convert("bar"), "foo bar"); + DoWStrTest("foo %I64S", convert("bar"), "foo bar"); + DoWStrTest("foo %5S", convert("bar"), "foo bar"); + DoWStrTest("foo %.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %-5S", convert("bar"), "foo bar "); + DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test4/CMakeLists.txt index 55e5700fe3..7311bbea69 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_printf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/printf/test4/test4.c deleted file mode 100644 index bcdc201d4f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test4/test4.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the printf function. Tests the pointer -** specifier (%p). -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "0000000000000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "00000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); - -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/printf/test4/test4.cpp new file mode 100644 index 0000000000..bcdc201d4f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test4/test4.cpp @@ -0,0 +1,66 @@ +// 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: test4.c +** +** Purpose: Test #4 for the printf function. Tests the pointer +** specifier (%p). +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "0000000000000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "00000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); + +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test5/CMakeLists.txt index d091bca2dc..bfe185c44f 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_printf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/printf/test5/test5.c deleted file mode 100644 index 9f8baa74da..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test5/test5.c +++ /dev/null @@ -1,60 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the printf function. Tests the count specifier (%n). -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - - -int __cdecl main(int argc, char *argv[]) -{ - char *longStr = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - "%n bar"; - char *longResult = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - " bar"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoCountTest("foo %n bar", 4, "foo bar"); - DoCountTest(longStr, 257, longResult); - DoCountTest("fo%n bar", 2, "fo bar"); - DoCountTest("%n", 0, ""); - DoCountTest("foo %#n bar", 4, "foo bar"); - DoCountTest("foo % n bar", 4, "foo bar"); - DoCountTest("foo %+n bar", 4, "foo bar"); - DoCountTest("foo %-n bar", 4, "foo bar"); - DoCountTest("foo %0n bar", 4, "foo bar"); - DoShortCountTest("foo %hn bar", 4, "foo bar"); - DoCountTest("foo %ln bar", 4, "foo bar"); - DoCountTest("foo %Ln bar", 4, "foo bar"); - DoCountTest("foo %I64n bar", 4, "foo bar"); - DoCountTest("foo %20.3n bar", 4, "foo bar"); - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/printf/test5/test5.cpp new file mode 100644 index 0000000000..9f8baa74da --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test5/test5.cpp @@ -0,0 +1,60 @@ +// 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: test5.c +** +** Purpose: Test #5 for the printf function. Tests the count specifier (%n). +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + + +int __cdecl main(int argc, char *argv[]) +{ + char *longStr = + "really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + "%n bar"; + char *longResult = + "really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + " bar"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoCountTest("foo %n bar", 4, "foo bar"); + DoCountTest(longStr, 257, longResult); + DoCountTest("fo%n bar", 2, "fo bar"); + DoCountTest("%n", 0, ""); + DoCountTest("foo %#n bar", 4, "foo bar"); + DoCountTest("foo % n bar", 4, "foo bar"); + DoCountTest("foo %+n bar", 4, "foo bar"); + DoCountTest("foo %-n bar", 4, "foo bar"); + DoCountTest("foo %0n bar", 4, "foo bar"); + DoShortCountTest("foo %hn bar", 4, "foo bar"); + DoCountTest("foo %ln bar", 4, "foo bar"); + DoCountTest("foo %Ln bar", 4, "foo bar"); + DoCountTest("foo %I64n bar", 4, "foo bar"); + DoCountTest("foo %20.3n bar", 4, "foo bar"); + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/printf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test6/CMakeLists.txt index c004e353e9..842ebfedc6 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_printf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/printf/test6/test6.c deleted file mode 100644 index edc65b6b9b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test6/test6.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the printf function. Tests the char specifier (%c). -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoCharTest("foo %c", 'b', "foo b"); - DoCharTest("foo %hc", 'b', "foo b"); - DoWCharTest("foo %lc", wc, "foo c"); - DoCharTest("foo %Lc", 'b', "foo b"); - DoCharTest("foo %I64c", 'b', "foo b"); - DoCharTest("foo %5c", 'b', "foo b"); - DoCharTest("foo %.0c", 'b', "foo b"); - DoCharTest("foo %-5c", 'b', "foo b "); - DoCharTest("foo %05c", 'b', "foo 0000b"); - DoCharTest("foo % c", 'b', "foo b"); - DoCharTest("foo %#c", 'b', "foo b"); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/printf/test6/test6.cpp new file mode 100644 index 0000000000..edc65b6b9b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test6/test6.cpp @@ -0,0 +1,48 @@ +// 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: test6.c +** +** Purpose: Test #6 for the printf function. Tests the char specifier (%c). +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoCharTest("foo %c", 'b', "foo b"); + DoCharTest("foo %hc", 'b', "foo b"); + DoWCharTest("foo %lc", wc, "foo c"); + DoCharTest("foo %Lc", 'b', "foo b"); + DoCharTest("foo %I64c", 'b', "foo b"); + DoCharTest("foo %5c", 'b', "foo b"); + DoCharTest("foo %.0c", 'b', "foo b"); + DoCharTest("foo %-5c", 'b', "foo b "); + DoCharTest("foo %05c", 'b', "foo 0000b"); + DoCharTest("foo % c", 'b', "foo b"); + DoCharTest("foo %#c", 'b', "foo b"); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test7/CMakeLists.txt index ff6b647ccd..16e39198ba 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_printf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/printf/test7/test7.c deleted file mode 100644 index 3aeb58f7dc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test7/test7.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test7.c -** -** Purpose: Test #7 for the printf function. Tests the wide char -** specifier (%C). -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoWCharTest("foo %C", wb, "foo b"); - DoWCharTest("foo %hC", wb, "foo b"); - DoCharTest("foo %lC", 'c', "foo c"); - DoWCharTest("foo %LC", wb, "foo b"); - DoWCharTest("foo %I64C", wb, "foo b"); - DoWCharTest("foo %5C", wb, "foo b"); - DoWCharTest("foo %.0C", wb, "foo b"); - DoWCharTest("foo %-5C", wb, "foo b "); - DoWCharTest("foo %05C", wb, "foo 0000b"); - DoWCharTest("foo % C", wb, "foo b"); - DoWCharTest("foo %#C", wb, "foo b"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/printf/test7/test7.cpp new file mode 100644 index 0000000000..3aeb58f7dc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test7/test7.cpp @@ -0,0 +1,47 @@ +// 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: test7.c +** +** Purpose: Test #7 for the printf function. Tests the wide char +** specifier (%C). +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoWCharTest("foo %C", wb, "foo b"); + DoWCharTest("foo %hC", wb, "foo b"); + DoCharTest("foo %lC", 'c', "foo c"); + DoWCharTest("foo %LC", wb, "foo b"); + DoWCharTest("foo %I64C", wb, "foo b"); + DoWCharTest("foo %5C", wb, "foo b"); + DoWCharTest("foo %.0C", wb, "foo b"); + DoWCharTest("foo %-5C", wb, "foo b "); + DoWCharTest("foo %05C", wb, "foo 0000b"); + DoWCharTest("foo % C", wb, "foo b"); + DoWCharTest("foo %#C", wb, "foo b"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test8/CMakeLists.txt index 5ee387f5b8..4a40fee6d9 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_printf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/printf/test8/test8.c deleted file mode 100644 index daa4674b92..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test8/test8.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test8.c -** -** Purpose: Test #8 for the printf function. Tests the decimal -** specifier (%d). -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %d", pos, "foo 42"); - DoNumTest("foo %ld", 0xFFFF, "foo 65535"); - DoNumTest("foo %hd", 0xFFFF, "foo -1"); - DoNumTest("foo %Ld", pos, "foo 42"); - DoI64Test("foo %I64d", l, "42", "foo 42"); - DoNumTest("foo %3d", pos, "foo 42"); - DoNumTest("foo %-3d", pos, "foo 42 "); - DoNumTest("foo %.1d", pos, "foo 42"); - DoNumTest("foo %.3d", pos, "foo 042"); - DoNumTest("foo %03d", pos, "foo 042"); - DoNumTest("foo %#d", pos, "foo 42"); - DoNumTest("foo %+d", pos, "foo +42"); - DoNumTest("foo % d", pos, "foo 42"); - DoNumTest("foo %+d", neg, "foo -42"); - DoNumTest("foo % d", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/printf/test8/test8.cpp new file mode 100644 index 0000000000..daa4674b92 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test8/test8.cpp @@ -0,0 +1,53 @@ +// 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: test8.c +** +** Purpose: Test #8 for the printf function. Tests the decimal +** specifier (%d). +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %d", pos, "foo 42"); + DoNumTest("foo %ld", 0xFFFF, "foo 65535"); + DoNumTest("foo %hd", 0xFFFF, "foo -1"); + DoNumTest("foo %Ld", pos, "foo 42"); + DoI64Test("foo %I64d", l, "42", "foo 42"); + DoNumTest("foo %3d", pos, "foo 42"); + DoNumTest("foo %-3d", pos, "foo 42 "); + DoNumTest("foo %.1d", pos, "foo 42"); + DoNumTest("foo %.3d", pos, "foo 042"); + DoNumTest("foo %03d", pos, "foo 042"); + DoNumTest("foo %#d", pos, "foo 42"); + DoNumTest("foo %+d", pos, "foo +42"); + DoNumTest("foo % d", pos, "foo 42"); + DoNumTest("foo %+d", neg, "foo -42"); + DoNumTest("foo % d", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/printf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/printf/test9/CMakeLists.txt index baf46c1065..df8f75d2fd 100644 --- a/src/pal/tests/palsuite/c_runtime/printf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/printf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_printf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/printf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/printf/test9/test9.c deleted file mode 100644 index 22c60d04f2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/printf/test9/test9.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test9.c -** -** Purpose: Test #9 for the printf function. Tests the integer -** specifier (%i). -** -** -**==========================================================================*/ - - - -#include -#include "../printf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %i", pos, "foo 42"); - DoNumTest("foo %li", 0xFFFF, "foo 65535"); - DoNumTest("foo %hi", 0xFFFF, "foo -1"); - DoNumTest("foo %Li", pos, "foo 42"); - DoI64Test("foo %I64i", l, "42", "foo 42"); - DoNumTest("foo %3i", pos, "foo 42"); - DoNumTest("foo %-3i", pos, "foo 42 "); - DoNumTest("foo %.1i", pos, "foo 42"); - DoNumTest("foo %.3i", pos, "foo 042"); - DoNumTest("foo %03i", pos, "foo 042"); - DoNumTest("foo %#i", pos, "foo 42"); - DoNumTest("foo %+i", pos, "foo +42"); - DoNumTest("foo % i", pos, "foo 42"); - DoNumTest("foo %+i", neg, "foo -42"); - DoNumTest("foo % i", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/printf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/printf/test9/test9.cpp new file mode 100644 index 0000000000..22c60d04f2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/printf/test9/test9.cpp @@ -0,0 +1,53 @@ +// 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: test9.c +** +** Purpose: Test #9 for the printf function. Tests the integer +** specifier (%i). +** +** +**==========================================================================*/ + + + +#include +#include "../printf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %i", pos, "foo 42"); + DoNumTest("foo %li", 0xFFFF, "foo 65535"); + DoNumTest("foo %hi", 0xFFFF, "foo -1"); + DoNumTest("foo %Li", pos, "foo 42"); + DoI64Test("foo %I64i", l, "42", "foo 42"); + DoNumTest("foo %3i", pos, "foo 42"); + DoNumTest("foo %-3i", pos, "foo 42 "); + DoNumTest("foo %.1i", pos, "foo 42"); + DoNumTest("foo %.3i", pos, "foo 042"); + DoNumTest("foo %03i", pos, "foo 042"); + DoNumTest("foo %#i", pos, "foo 42"); + DoNumTest("foo %+i", pos, "foo +42"); + DoNumTest("foo % i", pos, "foo 42"); + DoNumTest("foo %+i", neg, "foo -42"); + DoNumTest("foo % i", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/qsort/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/qsort/test1/CMakeLists.txt index 105a727e91..ff215b8dc6 100644 --- a/src/pal/tests/palsuite/c_runtime/qsort/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/qsort/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_qsort_test1 diff --git a/src/pal/tests/palsuite/c_runtime/qsort/test1/test1.c b/src/pal/tests/palsuite/c_runtime/qsort/test1/test1.c deleted file mode 100644 index c65fb18e68..0000000000 --- a/src/pal/tests/palsuite/c_runtime/qsort/test1/test1.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test1.c -** -** Purpose: Calls qsort to sort a buffer, and verifies that it has done -** the job correctly. -** -** -**==========================================================================*/ - -#include - -int __cdecl charcmp(const void *pa, const void *pb) -{ - return memcmp(pa, pb, 1); -} - -int __cdecl main(int argc, char **argv) -{ - char before[] = "cgaiehdbjf"; - const char after[] = "abcdefghij"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - qsort(before, sizeof(before) - 1, sizeof(char), charcmp); - - if (memcmp(before, after, sizeof(before)) != 0) - { - Fail("qsort did not correctly sort an array of characters.\n"); - } - - PAL_Terminate(); - return PASS; - -} - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/qsort/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/qsort/test1/test1.cpp new file mode 100644 index 0000000000..c65fb18e68 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/qsort/test1/test1.cpp @@ -0,0 +1,48 @@ +// 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: test1.c +** +** Purpose: Calls qsort to sort a buffer, and verifies that it has done +** the job correctly. +** +** +**==========================================================================*/ + +#include + +int __cdecl charcmp(const void *pa, const void *pb) +{ + return memcmp(pa, pb, 1); +} + +int __cdecl main(int argc, char **argv) +{ + char before[] = "cgaiehdbjf"; + const char after[] = "abcdefghij"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + qsort(before, sizeof(before) - 1, sizeof(char), charcmp); + + if (memcmp(before, after, sizeof(before)) != 0) + { + Fail("qsort did not correctly sort an array of characters.\n"); + } + + PAL_Terminate(); + return PASS; + +} + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/qsort/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/qsort/test2/CMakeLists.txt index 09e3f6db1e..cdd9642779 100644 --- a/src/pal/tests/palsuite/c_runtime/qsort/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/qsort/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_qsort_test2 diff --git a/src/pal/tests/palsuite/c_runtime/qsort/test2/test2.c b/src/pal/tests/palsuite/c_runtime/qsort/test2/test2.c deleted file mode 100644 index 8110dcd2c2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/qsort/test2/test2.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test2.c -** -** Purpose: Calls qsort to sort a buffer, and verifies that it has done -** the job correctly. -** -** -**==========================================================================*/ - -#include - -int __cdecl twocharcmp(const void *pa, const void *pb) -{ - return memcmp(pa, pb, 2); -} - -int __cdecl main(int argc, char **argv) -{ - char before[] = "ccggaaiieehhddbbjjff"; - const char after[] = "aabbccddeeffgghhiijj"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - qsort(before, (sizeof(before) - 1) / 2, 2 * sizeof(char), twocharcmp); - - if (memcmp(before, after, sizeof(before)) != 0) - { - Fail("qsort did not correctly sort an array of 2-character " - "buffers.\n"); - } - - PAL_Terminate(); - return PASS; - -} - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/qsort/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/qsort/test2/test2.cpp new file mode 100644 index 0000000000..8110dcd2c2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/qsort/test2/test2.cpp @@ -0,0 +1,49 @@ +// 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: test2.c +** +** Purpose: Calls qsort to sort a buffer, and verifies that it has done +** the job correctly. +** +** +**==========================================================================*/ + +#include + +int __cdecl twocharcmp(const void *pa, const void *pb) +{ + return memcmp(pa, pb, 2); +} + +int __cdecl main(int argc, char **argv) +{ + char before[] = "ccggaaiieehhddbbjjff"; + const char after[] = "aabbccddeeffgghhiijj"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + qsort(before, (sizeof(before) - 1) / 2, 2 * sizeof(char), twocharcmp); + + if (memcmp(before, after, sizeof(before)) != 0) + { + Fail("qsort did not correctly sort an array of 2-character " + "buffers.\n"); + } + + PAL_Terminate(); + return PASS; + +} + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/rand_srand/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/rand_srand/test1/CMakeLists.txt index 939914662a..6728f402ff 100644 --- a/src/pal/tests/palsuite/c_runtime/rand_srand/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/rand_srand/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_rand_srand_test1 diff --git a/src/pal/tests/palsuite/c_runtime/rand_srand/test1/test1.c b/src/pal/tests/palsuite/c_runtime/rand_srand/test1/test1.c deleted file mode 100644 index 34154cb6d2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/rand_srand/test1/test1.c +++ /dev/null @@ -1,100 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that srand provide random -** number to rand. Also make sure that rand result from a -** srand with seed 1 and no call to srand are the same. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** srand() -** - -** -**===========================================================================*/ - -#include - - -int __cdecl main(int argc, char **argv) -{ - int RandNumber[10]; - int TempRandNumber; - int i; - int SRAND_SEED; - int SRAND_REINIT = 1; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - SRAND_SEED = time(NULL); - - /* does not initialize srand and call rand. */ - for (i=0; i<10; i++) - { - /* keep the value in a array */ - RandNumber[i]=rand(); - if (RandNumber[i] < 0 || RandNumber[i] > RAND_MAX) - { - Fail("1) ERROR: random generated an invalid value: %d", RandNumber[i]); - } - } - - - /* initialize random generator */ - srand(SRAND_SEED); - - - /* choose 10 numbers with a different seed. - the numbers should be different than - those the previously generated one */ - for(i = 0; i < 10; i++) - { - TempRandNumber=rand(); - if (TempRandNumber < 0 || TempRandNumber > RAND_MAX) - { - Fail("2) ERROR: random generated an invalid value: %d", TempRandNumber); - } - } - - - - /* renitialize the srand with 1 */ - srand(SRAND_REINIT); - - - - /* choose 10 numbers with seed 1, - the number should be the same as those we kept in the array. */ - for( i = 0; i < 10;i++ ) - { - /* pick the random number*/ - TempRandNumber=rand(); - /* test if it is the same number generated in the first sequences*/ - if(RandNumber[i]!=TempRandNumber) - { - Fail ("ERROR: rand should return the same value when srand " - "is initialized with 1 or not initialized at all"); - } - if (TempRandNumber < 0 || TempRandNumber > RAND_MAX) - { - Fail("3) ERROR: random generated an invalid value: %d", TempRandNumber); - } - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/rand_srand/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/rand_srand/test1/test1.cpp new file mode 100644 index 0000000000..34154cb6d2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/rand_srand/test1/test1.cpp @@ -0,0 +1,100 @@ +// 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: test1.c +** +** Purpose: Test to ensure that srand provide random +** number to rand. Also make sure that rand result from a +** srand with seed 1 and no call to srand are the same. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** srand() +** + +** +**===========================================================================*/ + +#include + + +int __cdecl main(int argc, char **argv) +{ + int RandNumber[10]; + int TempRandNumber; + int i; + int SRAND_SEED; + int SRAND_REINIT = 1; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + SRAND_SEED = time(NULL); + + /* does not initialize srand and call rand. */ + for (i=0; i<10; i++) + { + /* keep the value in a array */ + RandNumber[i]=rand(); + if (RandNumber[i] < 0 || RandNumber[i] > RAND_MAX) + { + Fail("1) ERROR: random generated an invalid value: %d", RandNumber[i]); + } + } + + + /* initialize random generator */ + srand(SRAND_SEED); + + + /* choose 10 numbers with a different seed. + the numbers should be different than + those the previously generated one */ + for(i = 0; i < 10; i++) + { + TempRandNumber=rand(); + if (TempRandNumber < 0 || TempRandNumber > RAND_MAX) + { + Fail("2) ERROR: random generated an invalid value: %d", TempRandNumber); + } + } + + + + /* renitialize the srand with 1 */ + srand(SRAND_REINIT); + + + + /* choose 10 numbers with seed 1, + the number should be the same as those we kept in the array. */ + for( i = 0; i < 10;i++ ) + { + /* pick the random number*/ + TempRandNumber=rand(); + /* test if it is the same number generated in the first sequences*/ + if(RandNumber[i]!=TempRandNumber) + { + Fail ("ERROR: rand should return the same value when srand " + "is initialized with 1 or not initialized at all"); + } + if (TempRandNumber < 0 || TempRandNumber > RAND_MAX) + { + Fail("3) ERROR: random generated an invalid value: %d", TempRandNumber); + } + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/realloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/realloc/test1/CMakeLists.txt index 0a9f34fc3b..62830a0fe8 100644 --- a/src/pal/tests/palsuite/c_runtime/realloc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/realloc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_realloc_test1 diff --git a/src/pal/tests/palsuite/c_runtime/realloc/test1/test1.c b/src/pal/tests/palsuite/c_runtime/realloc/test1/test1.c deleted file mode 100644 index d0dd128cc1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/realloc/test1/test1.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: test1.c -** -** Purpose: Uses realloc to allocate and realloate memory, checking -** that memory contents are copied when the memory is reallocated. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - char *testA; - const int len1 = 10; - const char str1[] = "aaaaaaaaaa"; - - const int len2 = 20; - const char str2[] = "bbbbbbbbbbbbbbbbbbbb"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* this should work like malloc */ - testA = (char *)realloc(NULL, len1*sizeof(char)); - memcpy(testA, str1, len1); - if (testA == NULL) - { - Fail("We ran out of memory (unlikely), or realloc is broken.\n"); - } - - if (memcmp(testA, str1, len1) != 0) - { - Fail("realloc doesn't properly allocate new memory.\n"); - } - - testA = (char *)realloc(testA, len2*sizeof(char)); - if (memcmp(testA, str1, len1) != 0) - { - Fail("realloc doesn't move the contents of the original memory " - "block to the newly allocated block.\n"); - } - - memcpy(testA, str2, len2); - if (memcmp(testA, str2, len2) != 0) - { - Fail("Couldn't write to memory allocated by realloc.\n"); - } - - /* free the buffer */ - testA = realloc(testA, 0); - if (testA != NULL) - { - Fail("Realloc didn't return NULL when called with a length " - "of zero.\n"); - } - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/realloc/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/realloc/test1/test1.cpp new file mode 100644 index 0000000000..64a9270eab --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/realloc/test1/test1.cpp @@ -0,0 +1,66 @@ +// 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: test1.c +** +** Purpose: Uses realloc to allocate and realloate memory, checking +** that memory contents are copied when the memory is reallocated. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + char *testA; + const int len1 = 10; + const char str1[] = "aaaaaaaaaa"; + + const int len2 = 20; + const char str2[] = "bbbbbbbbbbbbbbbbbbbb"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* this should work like malloc */ + testA = (char *)realloc(NULL, len1*sizeof(char)); + memcpy(testA, str1, len1); + if (testA == NULL) + { + Fail("We ran out of memory (unlikely), or realloc is broken.\n"); + } + + if (memcmp(testA, str1, len1) != 0) + { + Fail("realloc doesn't properly allocate new memory.\n"); + } + + testA = (char *)realloc(testA, len2*sizeof(char)); + if (memcmp(testA, str1, len1) != 0) + { + Fail("realloc doesn't move the contents of the original memory " + "block to the newly allocated block.\n"); + } + + memcpy(testA, str2, len2); + if (memcmp(testA, str2, len2) != 0) + { + Fail("Couldn't write to memory allocated by realloc.\n"); + } + + /* free the buffer */ + testA = (char*)realloc(testA, 0); + if (testA != NULL) + { + Fail("Realloc didn't return NULL when called with a length " + "of zero.\n"); + } + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sin/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sin/test1/CMakeLists.txt index e074337452..74a0e78f52 100644 --- a/src/pal/tests/palsuite/c_runtime/sin/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/sin/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_sin_test1 diff --git a/src/pal/tests/palsuite/c_runtime/sin/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sin/test1/test1.c deleted file mode 100644 index bec58d4dd9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sin/test1/test1.c +++ /dev/null @@ -1,131 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that sin return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = sin(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("sin(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = sin(value); - - if (!_isnan(result)) - { - Fail("sin(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, 0, PAL_EPSILON }, - { 0.31830988618379067, 0.31296179620778659, PAL_EPSILON }, // value: 1 / pi - { 0.43429448190325183, 0.42077048331375735, PAL_EPSILON }, // value: log10(e) - { 0.63661977236758134, 0.59448076852482208, PAL_EPSILON }, // value: 2 / pi - { 0.69314718055994531, 0.63896127631363480, PAL_EPSILON }, // value: ln(2) - { 0.70710678118654752, 0.64963693908006244, PAL_EPSILON }, // value: 1 / sqrt(2) - { 0.78539816339744831, 0.70710678118654752, PAL_EPSILON }, // value: pi / 4, expected: 1 / sqrt(2) - { 1, 0.84147098480789651, PAL_EPSILON }, - { 1.1283791670955126, 0.90371945743584630, PAL_EPSILON }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 0.98776594599273553, PAL_EPSILON }, // value: sqrt(2) - { 1.4426950408889634, 0.99180624439366372, PAL_EPSILON }, // value: log2(e) - { 1.5707963267948966, 1, PAL_EPSILON * 10 }, // value: pi / 2 - { 2.3025850929940457, 0.74398033695749319, PAL_EPSILON }, // value: ln(10) - { 2.7182818284590452, 0.41078129050290870, PAL_EPSILON }, // value: e - { 3.1415926535897932, 0, PAL_EPSILON }, // value: pi - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, -tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NEGINF); - validate_isnan(PAL_NAN); - validate_isnan(PAL_POSINF); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sin/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/sin/test1/test1.cpp new file mode 100644 index 0000000000..bec58d4dd9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sin/test1/test1.cpp @@ -0,0 +1,131 @@ +// 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: test1.c +** +** Purpose: Test to ensure that sin return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = sin(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("sin(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = sin(value); + + if (!_isnan(result)) + { + Fail("sin(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.31830988618379067, 0.31296179620778659, PAL_EPSILON }, // value: 1 / pi + { 0.43429448190325183, 0.42077048331375735, PAL_EPSILON }, // value: log10(e) + { 0.63661977236758134, 0.59448076852482208, PAL_EPSILON }, // value: 2 / pi + { 0.69314718055994531, 0.63896127631363480, PAL_EPSILON }, // value: ln(2) + { 0.70710678118654752, 0.64963693908006244, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.70710678118654752, PAL_EPSILON }, // value: pi / 4, expected: 1 / sqrt(2) + { 1, 0.84147098480789651, PAL_EPSILON }, + { 1.1283791670955126, 0.90371945743584630, PAL_EPSILON }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 0.98776594599273553, PAL_EPSILON }, // value: sqrt(2) + { 1.4426950408889634, 0.99180624439366372, PAL_EPSILON }, // value: log2(e) + { 1.5707963267948966, 1, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.3025850929940457, 0.74398033695749319, PAL_EPSILON }, // value: ln(10) + { 2.7182818284590452, 0.41078129050290870, PAL_EPSILON }, // value: e + { 3.1415926535897932, 0, PAL_EPSILON }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sinf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/sinf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinf/test1/CMakeLists.txt new file mode 100644 index 0000000000..0651b43d1d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_sinf_test1 + ${SOURCES} +) + +add_dependencies(paltest_sinf_test1 coreclrpal) + +target_link_libraries(paltest_sinf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sinf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sinf/test1/test1.c new file mode 100644 index 0000000000..d5bd248935 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinf/test1/test1.c @@ -0,0 +1,130 @@ +// 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: test1.c +** +** Purpose: Test to ensure that sinf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = sinf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("sinf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = sinf(value); + + if (!_isnanf(result)) + { + Fail("sinf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.318309886f, 0.312961796f, PAL_EPSILON }, // value: 1 / pi + { 0.434294482f, 0.420770483f, PAL_EPSILON }, // value: log10f(e) + { 0.636619772f, 0.594480769f, PAL_EPSILON }, // value: 2 / pi + { 0.693147181f, 0.638961276f, PAL_EPSILON }, // value: ln(2) + { 0.707106781f, 0.649636939f, PAL_EPSILON }, // value: 1 / sqrtf(2) + { 0.785398163f, 0.707106781f, PAL_EPSILON }, // value: pi / 4, expected: 1 / sqrtf(2) + { 1, 0.841470985f, PAL_EPSILON }, + { 1.12837917f, 0.903719457f, PAL_EPSILON }, // value: 2 / sqrtf(pi) + { 1.41421356f, 0.987765946f, PAL_EPSILON }, // value: sqrtf(2) + { 1.44269504f, 0.991806244f, PAL_EPSILON }, // value: logf2(e) + { 1.57079633f, 1, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.30258509f, 0.743980337f, PAL_EPSILON }, // value: ln(10) + { 2.71828183f, 0.410781291f, PAL_EPSILON }, // value: e + { 3.14159265f, 0, PAL_EPSILON }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sinf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sinf/test1/testinfo.dat new file mode 100644 index 0000000000..08ff6026cb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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 = C Runtime +Function = sinf +Name = Positive Test for sinf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to sinf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/sinh/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinh/test1/CMakeLists.txt index 66cc691d92..b0101ba808 100644 --- a/src/pal/tests/palsuite/c_runtime/sinh/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/sinh/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_sinh_test1 diff --git a/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.c deleted file mode 100644 index e790b16fb4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.c +++ /dev/null @@ -1,130 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that sinh return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = sinh(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("sinh(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = sinh(value); - - if (!_isnan(result)) - { - Fail("sinh(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, 0, PAL_EPSILON }, - { 0.31830988618379067, 0.32371243907207108, PAL_EPSILON }, // value: 1 / pi - { 0.43429448190325183, 0.44807597941469025, PAL_EPSILON }, // value: log10(e) - { 0.63661977236758134, 0.68050167815224332, PAL_EPSILON }, // value: 2 / pi - { 0.69314718055994531, 0.75, PAL_EPSILON }, // value: ln(2) - { 0.70710678118654752, 0.76752314512611633, PAL_EPSILON }, // value: 1 / sqrt(2) - { 0.78539816339744831, 0.86867096148600961, PAL_EPSILON }, // value: pi / 4 - { 1, 1.1752011936438015, PAL_EPSILON * 10 }, - { 1.1283791670955126, 1.3835428792038633, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 1.9350668221743567, PAL_EPSILON * 10 }, // value: sqrt(2) - { 1.4426950408889634, 1.9978980091062796, PAL_EPSILON * 10 }, // value: log2(e) - { 1.5707963267948966, 2.3012989023072949, PAL_EPSILON * 10 }, // value: pi / 2 - { 2.3025850929940457, 4.95, PAL_EPSILON * 10 }, // value: ln(10) - { 2.7182818284590452, 7.5441371028169758, PAL_EPSILON * 10 }, // value: e - { 3.1415926535897932, 11.548739357257748, PAL_EPSILON * 100 }, // value: pi - { PAL_POSINF, PAL_POSINF, 0 }, - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, -tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.cpp new file mode 100644 index 0000000000..e790b16fb4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.cpp @@ -0,0 +1,130 @@ +// 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: test1.c +** +** Purpose: Test to ensure that sinh return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = sinh(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("sinh(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = sinh(value); + + if (!_isnan(result)) + { + Fail("sinh(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.31830988618379067, 0.32371243907207108, PAL_EPSILON }, // value: 1 / pi + { 0.43429448190325183, 0.44807597941469025, PAL_EPSILON }, // value: log10(e) + { 0.63661977236758134, 0.68050167815224332, PAL_EPSILON }, // value: 2 / pi + { 0.69314718055994531, 0.75, PAL_EPSILON }, // value: ln(2) + { 0.70710678118654752, 0.76752314512611633, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.86867096148600961, PAL_EPSILON }, // value: pi / 4 + { 1, 1.1752011936438015, PAL_EPSILON * 10 }, + { 1.1283791670955126, 1.3835428792038633, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 1.9350668221743567, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.4426950408889634, 1.9978980091062796, PAL_EPSILON * 10 }, // value: log2(e) + { 1.5707963267948966, 2.3012989023072949, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.3025850929940457, 4.95, PAL_EPSILON * 10 }, // value: ln(10) + { 2.7182818284590452, 7.5441371028169758, PAL_EPSILON * 10 }, // value: e + { 3.1415926535897932, 11.548739357257748, PAL_EPSILON * 100 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sinhf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinhf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinhf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/sinhf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinhf/test1/CMakeLists.txt new file mode 100644 index 0000000000..72cce43460 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinhf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_sinhf_test1 + ${SOURCES} +) + +add_dependencies(paltest_sinhf_test1 coreclrpal) + +target_link_libraries(paltest_sinhf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sinhf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sinhf/test1/test1.c new file mode 100644 index 0000000000..4e706a2f71 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinhf/test1/test1.c @@ -0,0 +1,129 @@ +// 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: test1.c +** +** Purpose: Test to ensure that sinhf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = sinhf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("sinhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = sinhf(value); + + if (!_isnanf(result)) + { + Fail("sinhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.318309886f, 0.323712439f, PAL_EPSILON }, // value: 1 / pi + { 0.434294482f, 0.448075979f, PAL_EPSILON }, // value: log10f(e) + { 0.636619772f, 0.680501678f, PAL_EPSILON }, // value: 2 / pi + { 0.693147181f, 0.75, PAL_EPSILON }, // value: ln(2) + { 0.707106781f, 0.767523145f, PAL_EPSILON }, // value: 1 / sqrtf(2) + { 0.785398163f, 0.868670961f, PAL_EPSILON }, // value: pi / 4 + { 1, 1.17520119f, PAL_EPSILON * 10 }, + { 1.12837917f, 1.38354288f, PAL_EPSILON * 10 }, // value: 2 / sqrtf(pi) + { 1.41421356f, 1.93506682f, PAL_EPSILON * 10 }, // value: sqrtf(2) + { 1.44269504f, 1.99789801f, PAL_EPSILON * 10 }, // value: logf2(e) + { 1.57079633f, 2.30129890f, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.30258509f, 4.95f, PAL_EPSILON * 10 }, // value: ln(10) + { 2.71828183f, 7.54413710f, PAL_EPSILON * 10 }, // value: e + { 3.14159265f, 11.5487394f, PAL_EPSILON * 100 }, // value: pi + { PAL_POSINF, PAL_POSINF, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sinhf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sinhf/test1/testinfo.dat new file mode 100644 index 0000000000..cfb27f5427 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinhf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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 = C Runtime +Function = sinhf +Name = Positive Test for sinhf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to sinhf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/CMakeLists.txt deleted file mode 100644 index cafb9536b0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) -add_subdirectory(test10) -add_subdirectory(test11) -add_subdirectory(test12) -add_subdirectory(test13) -add_subdirectory(test14) -add_subdirectory(test15) -add_subdirectory(test16) -add_subdirectory(test17) -add_subdirectory(test18) -add_subdirectory(test19) -add_subdirectory(test2) -add_subdirectory(test3) -add_subdirectory(test4) -add_subdirectory(test5) -add_subdirectory(test6) -add_subdirectory(test7) -add_subdirectory(test8) -add_subdirectory(test9) - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/sprintf.h b/src/pal/tests/palsuite/c_runtime/sprintf/sprintf.h deleted file mode 100644 index 411ae66d54..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/sprintf.h +++ /dev/null @@ -1,195 +0,0 @@ -// 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: sprintf.h -** -** Purpose: Containts common testing functions for sprintf -** -** -**==========================================================================*/ - -#ifndef __SPRINTF_H__ -#define __SPRINTF_H__ - -void DoStrTest(char *formatstr, char* param, char *checkstr) -{ - char buf[256] = { 0 }; - - sprintf(buf, formatstr, param); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert string \"%s\" into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - param, formatstr, checkstr, buf); - } -} - -void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) -{ - char buf[256] = { 0 }; - - sprintf(buf, formatstr, param); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert wide string \"%s\" into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - convertC(param), formatstr, checkstr, buf); - } -} - -void DoPointerTest(char *formatstr, void* param, char* paramstr, - char *checkstr1) -{ - char buf[256] = { 0 }; - - sprintf(buf, formatstr, param); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - paramstr, formatstr, checkstr1, buf); - } -} - -void DoCountTest(char *formatstr, int param, char *checkstr) -{ - char buf[512] = { 0 }; - int n = -1; - - sprintf(buf, formatstr, &n); - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - param, n); - } - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); - } -} - -void DoShortCountTest(char *formatstr, int param, char *checkstr) -{ - char buf[256] = { 0 }; - short int n = -1; - - sprintf(buf, formatstr, &n); - - if (n != param) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - param, n); - } - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); - } -} - - -void DoCharTest(char *formatstr, char param, char *checkstr) -{ - char buf[256] = { 0 }; - - sprintf(buf, formatstr, param); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - param, param, formatstr, checkstr, buf); - } -} - -void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) -{ - char buf[256] = { 0 }; - - sprintf(buf, formatstr, param); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - (char)param, param, formatstr, checkstr, buf); - } -} - -void DoNumTest(char *formatstr, int value, char *checkstr) -{ - char buf[256] = { 0 }; - - sprintf(buf, formatstr, value); - if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: failed to insert %#x into \"%s\"\n" - "Expected \"%s\" got \"%s\".\n", - value, formatstr, checkstr, buf); - } -} - -void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr1) -{ - char buf[256] = { 0 }; - - sprintf(buf, formatstr, value); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\"\n" - "Expected \"%s\", got \"%s\".\n", - valuestr, formatstr, checkstr1, buf); - } -} - -void DoDoubleTest(char *formatstr, double value, char *checkstr1, - char *checkstr2) -{ - char buf[256] = { 0 }; - - sprintf(buf, formatstr, value); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && - memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) - { - Fail("ERROR: failed to insert %f into \"%s\"\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - value, formatstr, checkstr1, checkstr2, buf); - } -} - -void DoArgumentPrecTest(char *formatstr, int precision, void *param, - char *paramstr, char *checkstr1, char *checkstr2) -{ - char buf[256]; - - sprintf(buf, formatstr, precision, param); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && - memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", paramstr, formatstr, - precision, checkstr1, checkstr2, buf); - } - -} - -void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param, - char *checkstr1, char *checkstr2) -{ - char buf[256]; - - sprintf(buf, formatstr, precision, param); - if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && - memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) - { - Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", param, formatstr, - precision, checkstr1, checkstr2, buf); - } - -} - -#endif - - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test1/CMakeLists.txt deleted file mode 100644 index bdec045af9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_sprintf_test1 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test1 coreclrpal) - -target_link_libraries(paltest_sprintf_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sprintf/test1/test1.c deleted file mode 100644 index 42e27f263b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test1/test1.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the sprintf function. A single, basic, test -** case with no formatting. -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - char checkstr[] = "hello world"; - char buf[256]; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - sprintf(buf, "hello world"); - - if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) - { - Fail("ERROR: expected %s, got %s\n", checkstr, buf); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test1/testinfo.dat deleted file mode 100644 index abe07445cc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test1/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test1 -Description -= General test to see if sprintf works correctly diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test10/CMakeLists.txt deleted file mode 100644 index 91e9db8ccc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test10/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test10.c -) - -add_executable(paltest_sprintf_test10 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test10 coreclrpal) - -target_link_libraries(paltest_sprintf_test10 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/sprintf/test10/test10.c deleted file mode 100644 index ae7dbfb177..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test10/test10.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test10.c -** -** Purpose: Test #10 for the sprintf function. Tests the octal specifier -** (%o). -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %o", pos, "foo 52"); - DoNumTest("foo %lo", 0xFFFF, "foo 177777"); - DoNumTest("foo %ho", 0xFFFF, "foo 177777"); - DoNumTest("foo %Lo", pos, "foo 52"); - DoI64Test("foo %I64o", l, "42", "foo 52"); - DoNumTest("foo %3o", pos, "foo 52"); - DoNumTest("foo %-3o", pos, "foo 52 "); - DoNumTest("foo %.1o", pos, "foo 52"); - DoNumTest("foo %.3o", pos, "foo 052"); - DoNumTest("foo %03o", pos, "foo 052"); - DoNumTest("foo %#o", pos, "foo 052"); - DoNumTest("foo %+o", pos, "foo 52"); - DoNumTest("foo % o", pos, "foo 52"); - DoNumTest("foo %+o", neg, "foo 37777777726"); - DoNumTest("foo % o", neg, "foo 37777777726"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test10/testinfo.dat deleted file mode 100644 index 70b7f3ab75..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test10/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test10 -Description -= Tests sprintf with octal numbers diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test11/CMakeLists.txt deleted file mode 100644 index b14c8be04d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test11/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test11.c -) - -add_executable(paltest_sprintf_test11 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test11 coreclrpal) - -target_link_libraries(paltest_sprintf_test11 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/sprintf/test11/test11.c deleted file mode 100644 index 0b5b5ab93d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test11/test11.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test11.c -** -** Purpose: Test #11 for the sprintf function. Test the unsigned int -** specifier (%u). -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %u", pos, "foo 42"); - DoNumTest("foo %lu", 0xFFFF, "foo 65535"); - DoNumTest("foo %hu", 0xFFFF, "foo 65535"); - DoNumTest("foo %Lu", pos, "foo 42"); - DoI64Test("foo %I64u", l, "42", "foo 42"); - DoNumTest("foo %3u", pos, "foo 42"); - DoNumTest("foo %-3u", pos, "foo 42 "); - DoNumTest("foo %.1u", pos, "foo 42"); - DoNumTest("foo %.3u", pos, "foo 042"); - DoNumTest("foo %03u", pos, "foo 042"); - DoNumTest("foo %#u", pos, "foo 42"); - DoNumTest("foo %+u", pos, "foo 42"); - DoNumTest("foo % u", pos, "foo 42"); - DoNumTest("foo %+u", neg, "foo 4294967254"); - DoNumTest("foo % u", neg, "foo 4294967254"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test11/testinfo.dat deleted file mode 100644 index 852bd3e7b6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test11/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test11 -Description -= Tests sprintf with unsigned numbers diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test12/CMakeLists.txt deleted file mode 100644 index 1e517495bd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test12/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test12.c -) - -add_executable(paltest_sprintf_test12 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test12 coreclrpal) - -target_link_libraries(paltest_sprintf_test12 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/sprintf/test12/test12.c deleted file mode 100644 index c2e778e494..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test12/test12.c +++ /dev/null @@ -1,56 +0,0 @@ -// 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: test12.c -** -** Purpose: Test #12 for the sprintf function. Tests the (lowercase) -** hexadecimal specifier (%x) -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %x", pos, "foo 1234ab"); - DoNumTest("foo %lx", pos, "foo 1234ab"); - DoNumTest("foo %hx", pos, "foo 34ab"); - DoNumTest("foo %Lx", pos, "foo 1234ab"); - DoI64Test("foo %I64x", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7x", pos, "foo 1234ab"); - DoNumTest("foo %-7x", pos, "foo 1234ab "); - DoNumTest("foo %.1x", pos, "foo 1234ab"); - DoNumTest("foo %.7x", pos, "foo 01234ab"); - DoNumTest("foo %07x", pos, "foo 01234ab"); - DoNumTest("foo %#x", pos, "foo 0x1234ab"); - DoNumTest("foo %+x", pos, "foo 1234ab"); - DoNumTest("foo % x", pos, "foo 1234ab"); - DoNumTest("foo %+x", neg, "foo ffffffd6"); - DoNumTest("foo % x", neg, "foo ffffffd6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test12/testinfo.dat deleted file mode 100644 index 5df91d0e6a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test12/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test12 -Description -= Tests sprintf with hex numbers (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test13/CMakeLists.txt deleted file mode 100644 index 25b033fe82..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test13/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test13.c -) - -add_executable(paltest_sprintf_test13 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test13 coreclrpal) - -target_link_libraries(paltest_sprintf_test13 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/sprintf/test13/test13.c deleted file mode 100644 index 0b4b7ed9ae..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test13/test13.c +++ /dev/null @@ -1,56 +0,0 @@ -// 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: test13.c -** -** Purpose: Test #13 for the sprintf function. Tests the (uppercase) -** hexadecimal specifier (%X) -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234AB; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %X", pos, "foo 1234AB"); - DoNumTest("foo %lX", pos, "foo 1234AB"); - DoNumTest("foo %hX", pos, "foo 34AB"); - DoNumTest("foo %LX", pos, "foo 1234AB"); - DoI64Test("foo %I64X", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7X", pos, "foo 1234AB"); - DoNumTest("foo %-7X", pos, "foo 1234AB "); - DoNumTest("foo %.1X", pos, "foo 1234AB"); - DoNumTest("foo %.7X", pos, "foo 01234AB"); - DoNumTest("foo %07X", pos, "foo 01234AB"); - DoNumTest("foo %#X", pos, "foo 0X1234AB"); - DoNumTest("foo %+X", pos, "foo 1234AB"); - DoNumTest("foo % X", pos, "foo 1234AB"); - DoNumTest("foo %+X", neg, "foo FFFFFFD6"); - DoNumTest("foo % X", neg, "foo FFFFFFD6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test13/testinfo.dat deleted file mode 100644 index 634817a791..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test13/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test13 -Description -= Tests sprintf with hex numbers (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test14/CMakeLists.txt deleted file mode 100644 index 5eae306e16..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test14/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test14.c -) - -add_executable(paltest_sprintf_test14 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test14 coreclrpal) - -target_link_libraries(paltest_sprintf_test14 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/sprintf/test14/test14.c deleted file mode 100644 index 20e986a9c3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test14/test14.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test14.c -** -** Purpose: Test #14 for the sprintf function. Tests the lowercase -** exponential notation double specifier (%e) -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", "foo 2.560000e+02 "); - DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); - DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", "foo 2.56000000e+02"); - DoDoubleTest("foo %014e", val, "foo 02.560000e+002", "foo 002.560000e+02"); - DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); - DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test14/testinfo.dat deleted file mode 100644 index c7086efdbc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test14/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test14 -Description -= Tests sprintf with exponential format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test15/CMakeLists.txt deleted file mode 100644 index 1fff23fc89..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test15/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test15.c -) - -add_executable(paltest_sprintf_test15 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test15 coreclrpal) - -target_link_libraries(paltest_sprintf_test15 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/sprintf/test15/test15.c deleted file mode 100644 index 34199b2eb3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test15/test15.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test15.c -** -** Purpose: Test #15 for the sprintf function. Tests the uppercase -** exponential notation double specifier (%E) -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", "foo 2.560000E+02 "); - DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); - DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", "foo 2.56000000E+02"); - DoDoubleTest("foo %014E", val, "foo 02.560000E+002", "foo 002.560000E+02"); - DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); - DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test15/testinfo.dat deleted file mode 100644 index 0a47c5321a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test15/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test15 -Description -= Tests sprintf with exponential format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test16/CMakeLists.txt deleted file mode 100644 index 2065c576d9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test16/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test16.c -) - -add_executable(paltest_sprintf_test16 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test16 coreclrpal) - -target_link_libraries(paltest_sprintf_test16 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/sprintf/test16/test16.c deleted file mode 100644 index c93b68bc2d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test16/test16.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test16.c -** -** Purpose: Test #16 for the sprintf function. Tests the decimal notation -** double specifier (%f) -** -** -**==========================================================================*/ - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); - DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); - DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); - DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); - DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); - DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); - DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test16/testinfo.dat deleted file mode 100644 index e18fab1ad8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test16/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test16 -Description -= Tests sprintf with decimal point format doubles diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test17/CMakeLists.txt deleted file mode 100644 index ce3a8ad048..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test17/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test17.c -) - -add_executable(paltest_sprintf_test17 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test17 coreclrpal) - -target_link_libraries(paltest_sprintf_test17 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/sprintf/test17/test17.c deleted file mode 100644 index 643215b8f5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test17/test17.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test17.c -** -** Purpose: Test #17 for the sprintf function. Tests the lowercase -** shorthand notation double specifier (%g) -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); - DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); - DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test17/testinfo.dat deleted file mode 100644 index a723103e02..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test17/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test17 -Description -= Tests sprintf with compact format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test18/CMakeLists.txt deleted file mode 100644 index 6f69e1c7c2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test18/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test18.c -) - -add_executable(paltest_sprintf_test18 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test18 coreclrpal) - -target_link_libraries(paltest_sprintf_test18 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/sprintf/test18/test18.c deleted file mode 100644 index fa88152479..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test18/test18.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the sprintf function. Tests the uppercase -** shorthand notation double specifier (%G) -** -** -**==========================================================================*/ - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); - DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); - DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test18/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test18/testinfo.dat deleted file mode 100644 index dfafa4bcf4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test18/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test18 -Description -= Tests sprintf with compact format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test19/CMakeLists.txt deleted file mode 100644 index a2917b27dc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test19/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test19.c -) - -add_executable(paltest_sprintf_test19 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test19 coreclrpal) - -target_link_libraries(paltest_sprintf_test19 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/sprintf/test19/test19.c deleted file mode 100644 index aee731cb74..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test19/test19.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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: test19.c -** -** Purpose: Test #19 for the sprintf function. Tests the variable length -** precision argument. -** -** -**==========================================================================*/ - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int n = -1; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoArgumentPrecTest("%.*s", 2, "bar", "bar", "ba", "ba"); - DoArgumentPrecTest("%.*S", 2, convert("bar"), "bar", "ba", "ba"); - - DoArgumentPrecTest("%.*n", 3, &n, "pointer to int", "", ""); - if (n != 0) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - 0, n); - } - - DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); - DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); - DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); - DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); - - - DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); - DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); - DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); - DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); - DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); - DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); - DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); - DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); - DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); - DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test19/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test19/testinfo.dat deleted file mode 100644 index ebd13025f6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test19/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test19 -Description -= Tests sprintf with argument specified precision diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test2/CMakeLists.txt deleted file mode 100644 index 8af1c53a30..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test2/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test2.c -) - -add_executable(paltest_sprintf_test2 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test2 coreclrpal) - -target_link_libraries(paltest_sprintf_test2 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/sprintf/test2/test2.c deleted file mode 100644 index d50679a5a3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test2/test2.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the sprintf function. Tests the string specifier -** (%s). -** -** -**==========================================================================*/ - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoStrTest("foo %s", "bar", "foo bar"); - DoStrTest("foo %hs", "bar", "foo bar"); - DoWStrTest("foo %ls", convert("bar"), "foo bar"); - DoWStrTest("foo %ws", convert("bar"), "foo bar"); - DoStrTest("foo %Ls", "bar", "foo bar"); - DoStrTest("foo %I64s", "bar", "foo bar"); - DoStrTest("foo %5s", "bar", "foo bar"); - DoStrTest("foo %.2s", "bar", "foo ba"); - DoStrTest("foo %5.2s", "bar", "foo ba"); - DoStrTest("foo %-5s", "bar", "foo bar "); - DoStrTest("foo %05s", "bar", "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test2/testinfo.dat deleted file mode 100644 index e8d0f53ff3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test2/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test2 -Description -= Tests sprintf with strings diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test3/CMakeLists.txt deleted file mode 100644 index b7b7e0a579..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test3/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test3.c -) - -add_executable(paltest_sprintf_test3 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test3 coreclrpal) - -target_link_libraries(paltest_sprintf_test3 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/sprintf/test3/test3.c deleted file mode 100644 index ae52dbed08..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test3/test3.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the sprintf function. Tests the wide string -** specifier (%S). -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoWStrTest("foo %S", convert("bar"), "foo bar"); - DoStrTest("foo %hS", "bar", "foo bar"); - DoWStrTest("foo %lS", convert("bar"), "foo bar"); - DoWStrTest("foo %wS", convert("bar"), "foo bar"); - DoWStrTest("foo %LS", convert("bar"), "foo bar"); - DoWStrTest("foo %I64S", convert("bar"), "foo bar"); - DoWStrTest("foo %5S", convert("bar"), "foo bar"); - DoWStrTest("foo %.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %-5S", convert("bar"), "foo bar "); - DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test3/testinfo.dat deleted file mode 100644 index 12e0a9cfb0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test3/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test3 -Description -= Tests sprintf with wide strings diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test4/CMakeLists.txt deleted file mode 100644 index 3478867b7c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test4/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test4.c -) - -add_executable(paltest_sprintf_test4 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test4 coreclrpal) - -target_link_libraries(paltest_sprintf_test4 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/sprintf/test4/test4.c deleted file mode 100644 index 9660ffaa3a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test4/test4.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the sprintf function. Tests the pointer -** specifier (%p). -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "0000000000000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "00000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test4/testinfo.dat deleted file mode 100644 index bf7236dc32..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test4/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test4 -Description -= Tests sprintf with pointers diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test5/CMakeLists.txt deleted file mode 100644 index dfa7583766..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test5/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test5.c -) - -add_executable(paltest_sprintf_test5 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test5 coreclrpal) - -target_link_libraries(paltest_sprintf_test5 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/sprintf/test5/test5.c deleted file mode 100644 index 1b52da77b6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test5/test5.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the sprintf function. Tests the count specifier (%n). -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - - -int __cdecl main(int argc, char *argv[]) -{ - char *longStr = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - "%n bar"; - char *longResult = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - " bar"; - - if (PAL_Initialize(argc, argv)!= 0) - { - return FAIL; - } - - DoCountTest("foo %n bar", 4, "foo bar"); - DoCountTest(longStr, 257, longResult); - DoCountTest("fo%n bar", 2, "fo bar"); - DoCountTest("%n", 0, ""); - DoCountTest("foo %#n bar", 4, "foo bar"); - DoCountTest("foo % n bar", 4, "foo bar"); - DoCountTest("foo %+n bar", 4, "foo bar"); - DoCountTest("foo %-n bar", 4, "foo bar"); - DoCountTest("foo %0n bar", 4, "foo bar"); - DoShortCountTest("foo %hn bar", 4, "foo bar"); - DoCountTest("foo %ln bar", 4, "foo bar"); - DoCountTest("foo %Ln bar", 4, "foo bar"); - DoCountTest("foo %I64n bar", 4, "foo bar"); - DoCountTest("foo %20.3n bar", 4, "foo bar"); - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test5/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test5/testinfo.dat deleted file mode 100644 index 31e0537bd0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test5/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test5 -Description -= Tests sprintf with the count specifier diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test6/CMakeLists.txt deleted file mode 100644 index 7a9a5fc856..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test6/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test6.c -) - -add_executable(paltest_sprintf_test6 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test6 coreclrpal) - -target_link_libraries(paltest_sprintf_test6 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/sprintf/test6/test6.c deleted file mode 100644 index c14e075475..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test6/test6.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the sprintf function. Tests the char specifier (%c). -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoCharTest("foo %c", 'b', "foo b"); - DoCharTest("foo %hc", 'b', "foo b"); - DoWCharTest("foo %lc", wc, "foo c"); - DoCharTest("foo %Lc", 'b', "foo b"); - DoCharTest("foo %I64c", 'b', "foo b"); - DoCharTest("foo %5c", 'b', "foo b"); - DoCharTest("foo %.0c", 'b', "foo b"); - DoCharTest("foo %-5c", 'b', "foo b "); - DoCharTest("foo %05c", 'b', "foo 0000b"); - DoCharTest("foo % c", 'b', "foo b"); - DoCharTest("foo %#c", 'b', "foo b"); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test6/testinfo.dat deleted file mode 100644 index 037e4106ff..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test6/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test6 -Description -= Tests sprintf with characters diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test7/CMakeLists.txt deleted file mode 100644 index a539a59ab9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test7/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test7.c -) - -add_executable(paltest_sprintf_test7 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test7 coreclrpal) - -target_link_libraries(paltest_sprintf_test7 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/sprintf/test7/test7.c deleted file mode 100644 index 082bd20e6d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test7/test7.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test7.c -** -** Purpose: Test #7 for the sprintf function. Tests the wide char -** specifier (%C). -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoWCharTest("foo %C", wb, "foo b"); - DoWCharTest("foo %hC", wb, "foo b"); - DoCharTest("foo %lC", 'c', "foo c"); - DoWCharTest("foo %LC", wb, "foo b"); - DoWCharTest("foo %I64C", wb, "foo b"); - DoWCharTest("foo %5C", wb, "foo b"); - DoWCharTest("foo %.0C", wb, "foo b"); - DoWCharTest("foo %-5C", wb, "foo b "); - DoWCharTest("foo %05C", wb, "foo 0000b"); - DoWCharTest("foo % C", wb, "foo b"); - DoWCharTest("foo %#C", wb, "foo b"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test7/testinfo.dat deleted file mode 100644 index a2730bc97c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test7/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test7 -Description -= Tests sprintf with wide characters diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test8/CMakeLists.txt deleted file mode 100644 index 7a92c5072a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test8/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test8.c -) - -add_executable(paltest_sprintf_test8 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test8 coreclrpal) - -target_link_libraries(paltest_sprintf_test8 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/sprintf/test8/test8.c deleted file mode 100644 index 9587c82c94..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test8/test8.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test8.c -** -** Purpose: Test #8 for the sprintf function. Tests the decimal -** specifier (%d). -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %d", pos, "foo 42"); - DoNumTest("foo %ld", 0xFFFF, "foo 65535"); - DoNumTest("foo %hd", 0xFFFF, "foo -1"); - DoNumTest("foo %Ld", pos, "foo 42"); - DoI64Test("foo %I64d", l, "42", "foo 42"); - DoNumTest("foo %3d", pos, "foo 42"); - DoNumTest("foo %-3d", pos, "foo 42 "); - DoNumTest("foo %.1d", pos, "foo 42"); - DoNumTest("foo %.3d", pos, "foo 042"); - DoNumTest("foo %03d", pos, "foo 042"); - DoNumTest("foo %#d", pos, "foo 42"); - DoNumTest("foo %+d", pos, "foo +42"); - DoNumTest("foo % d", pos, "foo 42"); - DoNumTest("foo %+d", neg, "foo -42"); - DoNumTest("foo % d", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test8/testinfo.dat deleted file mode 100644 index adc0b66f06..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test8/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test8 -Description -= Tests sprintf with decimal numbers diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf/test9/CMakeLists.txt deleted file mode 100644 index 2a91658bd4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test9/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test9.c -) - -add_executable(paltest_sprintf_test9 - ${SOURCES} -) - -add_dependencies(paltest_sprintf_test9 coreclrpal) - -target_link_libraries(paltest_sprintf_test9 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/sprintf/test9/test9.c deleted file mode 100644 index 98f5db6ec1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test9/test9.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test9.c -** -** Purpose: Test #9 for the sprintf function. Tests the integer -** specifier (%i). -** -** -**==========================================================================*/ - - - -#include -#include "../sprintf.h" - -/* - * Depends on memcmp and strlen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest("foo %i", pos, "foo 42"); - DoNumTest("foo %li", 0xFFFF, "foo 65535"); - DoNumTest("foo %hi", 0xFFFF, "foo -1"); - DoNumTest("foo %Li", pos, "foo 42"); - DoI64Test("foo %I64i", l, "42", "foo 42"); - DoNumTest("foo %3i", pos, "foo 42"); - DoNumTest("foo %-3i", pos, "foo 42 "); - DoNumTest("foo %.1i", pos, "foo 42"); - DoNumTest("foo %.3i", pos, "foo 042"); - DoNumTest("foo %03i", pos, "foo 042"); - DoNumTest("foo %#i", pos, "foo 42"); - DoNumTest("foo %+i", pos, "foo +42"); - DoNumTest("foo % i", pos, "foo 42"); - DoNumTest("foo %+i", neg, "foo -42"); - DoNumTest("foo % i", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/sprintf/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf/test9/testinfo.dat deleted file mode 100644 index e569e789cd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sprintf/test9/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sprintf -Name = Positive Test for sprintf -TYPE = DEFAULT -EXE1 = test9 -Description -= Tests sprintf with integer numbers diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/CMakeLists.txt new file mode 100644 index 0000000000..8fe1cb60ac --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test10) +add_subdirectory(test11) +add_subdirectory(test12) +add_subdirectory(test13) +add_subdirectory(test14) +add_subdirectory(test15) +add_subdirectory(test16) +add_subdirectory(test17) +add_subdirectory(test18) +add_subdirectory(test19) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) +add_subdirectory(test6) +add_subdirectory(test7) +add_subdirectory(test8) +add_subdirectory(test9) + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/sprintf_s.h b/src/pal/tests/palsuite/c_runtime/sprintf_s/sprintf_s.h new file mode 100644 index 0000000000..129b9db727 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/sprintf_s.h @@ -0,0 +1,195 @@ +// 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: sprintf_s.h +** +** Purpose: Containts common testing functions for sprintf_s +** +** +**==========================================================================*/ + +#ifndef __SPRINTF_S_H__ +#define __SPRINTF_S_H__ + +void DoStrTest(const char *formatstr, char* param, const char *checkstr) +{ + char buf[256] = { 0 }; + + sprintf_s(buf, _countof(buf), formatstr, param); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert string \"%s\" into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + param, formatstr, checkstr, buf); + } +} + +void DoWStrTest(const char *formatstr, WCHAR* param, const char *checkstr) +{ + char buf[256] = { 0 }; + + sprintf_s(buf, _countof(buf), formatstr, param); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + convertC(param), formatstr, checkstr, buf); + } +} + +void DoPointerTest(const char *formatstr, void* param, char* paramstr, + const char *checkstr1) +{ + char buf[256] = { 0 }; + + sprintf_s(buf, _countof(buf), formatstr, param); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + paramstr, formatstr, checkstr1, buf); + } +} + +void DoCountTest(const char *formatstr, int param, const char *checkstr) +{ + char buf[512] = { 0 }; + int n = -1; + + sprintf_s(buf, _countof(buf), formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + param, n); + } + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); + } +} + +void DoShortCountTest(const char *formatstr, int param, const char *checkstr) +{ + char buf[256] = { 0 }; + short int n = -1; + + sprintf_s(buf, _countof(buf), formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + param, n); + } + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf); + } +} + + +void DoCharTest(const char *formatstr, char param, const char *checkstr) +{ + char buf[256] = { 0 }; + + sprintf_s(buf, _countof(buf), formatstr, param); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + param, param, formatstr, checkstr, buf); + } +} + +void DoWCharTest(const char *formatstr, WCHAR param, const char *checkstr) +{ + char buf[256] = { 0 }; + + sprintf_s(buf, _countof(buf), formatstr, param); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + (char)param, param, formatstr, checkstr, buf); + } +} + +void DoNumTest(const char *formatstr, int value, const char *checkstr) +{ + char buf[256] = { 0 }; + + sprintf_s(buf, _countof(buf), formatstr, value); + if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: failed to insert %#x into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + value, formatstr, checkstr, buf); + } +} + +void DoI64Test(const char *formatstr, INT64 value, char *valuestr, const char *checkstr1) +{ + char buf[256] = { 0 }; + + sprintf_s(buf, _countof(buf), formatstr, value); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", + valuestr, formatstr, checkstr1, buf); + } +} + +void DoDoubleTest(const char *formatstr, double value, const char *checkstr1, + const char *checkstr2) +{ + char buf[256] = { 0 }; + + sprintf_s(buf, _countof(buf), formatstr, value); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && + memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\"\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + value, formatstr, checkstr1, checkstr2, buf); + } +} + +void DoArgumentPrecTest(const char *formatstr, int precision, void *param, + char *paramstr, const char *checkstr1, const char *checkstr2) +{ + char buf[256]; + + sprintf_s(buf, _countof(buf), formatstr, precision, param); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && + memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", paramstr, formatstr, + precision, checkstr1, checkstr2, buf); + } + +} + +void DoArgumentPrecDoubleTest(const char *formatstr, int precision, double param, + const char *checkstr1, const char *checkstr2) +{ + char buf[256]; + + sprintf_s(buf, _countof(buf), formatstr, precision, param); + if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 && + memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", param, formatstr, + precision, checkstr1, checkstr2, buf); + } + +} + +#endif + + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test1/CMakeLists.txt new file mode 100644 index 0000000000..ee0d90fe7f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_sprintf_test1 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test1 coreclrpal) + +target_link_libraries(paltest_sprintf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test1/test1.cpp new file mode 100644 index 0000000000..a289c07716 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test1/test1.cpp @@ -0,0 +1,45 @@ +// 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: test1.c +** +** Purpose: Test #1 for the sprintf_s function. A single, basic, test +** case with no formatting. +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + char checkstr[] = "hello world"; + char buf[256]; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + sprintf_s(buf, _countof(buf), "hello world"); + + if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) + { + Fail("ERROR: expected %s, got %s\n", checkstr, buf); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test1/testinfo.dat new file mode 100644 index 0000000000..255c534cdf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test1/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test1 +Description += General test to see if sprintf_s works correctly diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test10/CMakeLists.txt new file mode 100644 index 0000000000..1efad19dee --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test10/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test10.cpp +) + +add_executable(paltest_sprintf_test10 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test10 coreclrpal) + +target_link_libraries(paltest_sprintf_test10 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test10/test10.cpp new file mode 100644 index 0000000000..bbda15a331 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test10/test10.cpp @@ -0,0 +1,55 @@ +// 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: test10.c +** +** Purpose: Test #10 for the sprintf_s function. Tests the octal specifier +** (%o). +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %o", pos, "foo 52"); + DoNumTest("foo %lo", 0xFFFF, "foo 177777"); + DoNumTest("foo %ho", 0xFFFF, "foo 177777"); + DoNumTest("foo %Lo", pos, "foo 52"); + DoI64Test("foo %I64o", l, "42", "foo 52"); + DoNumTest("foo %3o", pos, "foo 52"); + DoNumTest("foo %-3o", pos, "foo 52 "); + DoNumTest("foo %.1o", pos, "foo 52"); + DoNumTest("foo %.3o", pos, "foo 052"); + DoNumTest("foo %03o", pos, "foo 052"); + DoNumTest("foo %#o", pos, "foo 052"); + DoNumTest("foo %+o", pos, "foo 52"); + DoNumTest("foo % o", pos, "foo 52"); + DoNumTest("foo %+o", neg, "foo 37777777726"); + DoNumTest("foo % o", neg, "foo 37777777726"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test10/testinfo.dat new file mode 100644 index 0000000000..25ed554ea3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test10/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test10 +Description += Tests sprintf_s with octal numbers diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test11/CMakeLists.txt new file mode 100644 index 0000000000..f2f4da694c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test11/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test11.cpp +) + +add_executable(paltest_sprintf_test11 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test11 coreclrpal) + +target_link_libraries(paltest_sprintf_test11 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test11/test11.cpp new file mode 100644 index 0000000000..7f4fca9f32 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test11/test11.cpp @@ -0,0 +1,55 @@ +// 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: test11.c +** +** Purpose: Test #11 for the sprintf_s function. Test the unsigned int +** specifier (%u). +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %u", pos, "foo 42"); + DoNumTest("foo %lu", 0xFFFF, "foo 65535"); + DoNumTest("foo %hu", 0xFFFF, "foo 65535"); + DoNumTest("foo %Lu", pos, "foo 42"); + DoI64Test("foo %I64u", l, "42", "foo 42"); + DoNumTest("foo %3u", pos, "foo 42"); + DoNumTest("foo %-3u", pos, "foo 42 "); + DoNumTest("foo %.1u", pos, "foo 42"); + DoNumTest("foo %.3u", pos, "foo 042"); + DoNumTest("foo %03u", pos, "foo 042"); + DoNumTest("foo %#u", pos, "foo 42"); + DoNumTest("foo %+u", pos, "foo 42"); + DoNumTest("foo % u", pos, "foo 42"); + DoNumTest("foo %+u", neg, "foo 4294967254"); + DoNumTest("foo % u", neg, "foo 4294967254"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test11/testinfo.dat new file mode 100644 index 0000000000..3144f1290e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test11/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test11 +Description += Tests sprintf_s with unsigned numbers diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test12/CMakeLists.txt new file mode 100644 index 0000000000..361e91f9ae --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test12/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test12.cpp +) + +add_executable(paltest_sprintf_test12 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test12 coreclrpal) + +target_link_libraries(paltest_sprintf_test12 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test12/test12.cpp new file mode 100644 index 0000000000..759a41105b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test12/test12.cpp @@ -0,0 +1,56 @@ +// 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: test12.c +** +** Purpose: Test #12 for the sprintf_s function. Tests the (lowercase) +** hexadecimal specifier (%x) +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %x", pos, "foo 1234ab"); + DoNumTest("foo %lx", pos, "foo 1234ab"); + DoNumTest("foo %hx", pos, "foo 34ab"); + DoNumTest("foo %Lx", pos, "foo 1234ab"); + DoI64Test("foo %I64x", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7x", pos, "foo 1234ab"); + DoNumTest("foo %-7x", pos, "foo 1234ab "); + DoNumTest("foo %.1x", pos, "foo 1234ab"); + DoNumTest("foo %.7x", pos, "foo 01234ab"); + DoNumTest("foo %07x", pos, "foo 01234ab"); + DoNumTest("foo %#x", pos, "foo 0x1234ab"); + DoNumTest("foo %+x", pos, "foo 1234ab"); + DoNumTest("foo % x", pos, "foo 1234ab"); + DoNumTest("foo %+x", neg, "foo ffffffd6"); + DoNumTest("foo % x", neg, "foo ffffffd6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test12/testinfo.dat new file mode 100644 index 0000000000..ed91cecc46 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test12/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test12 +Description += Tests sprintf_s with hex numbers (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test13/CMakeLists.txt new file mode 100644 index 0000000000..d08e13b2ba --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test13/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test13.cpp +) + +add_executable(paltest_sprintf_test13 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test13 coreclrpal) + +target_link_libraries(paltest_sprintf_test13 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test13/test13.cpp new file mode 100644 index 0000000000..76250d058c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test13/test13.cpp @@ -0,0 +1,56 @@ +// 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: test13.c +** +** Purpose: Test #13 for the sprintf_s function. Tests the (uppercase) +** hexadecimal specifier (%X) +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234AB; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %X", pos, "foo 1234AB"); + DoNumTest("foo %lX", pos, "foo 1234AB"); + DoNumTest("foo %hX", pos, "foo 34AB"); + DoNumTest("foo %LX", pos, "foo 1234AB"); + DoI64Test("foo %I64X", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7X", pos, "foo 1234AB"); + DoNumTest("foo %-7X", pos, "foo 1234AB "); + DoNumTest("foo %.1X", pos, "foo 1234AB"); + DoNumTest("foo %.7X", pos, "foo 01234AB"); + DoNumTest("foo %07X", pos, "foo 01234AB"); + DoNumTest("foo %#X", pos, "foo 0X1234AB"); + DoNumTest("foo %+X", pos, "foo 1234AB"); + DoNumTest("foo % X", pos, "foo 1234AB"); + DoNumTest("foo %+X", neg, "foo FFFFFFD6"); + DoNumTest("foo % X", neg, "foo FFFFFFD6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test13/testinfo.dat new file mode 100644 index 0000000000..fd5f53017c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test13/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test13 +Description += Tests sprintf_s with hex numbers (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test14/CMakeLists.txt new file mode 100644 index 0000000000..60ac2922d7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test14/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test14.cpp +) + +add_executable(paltest_sprintf_test14 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test14 coreclrpal) + +target_link_libraries(paltest_sprintf_test14 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test14/test14.cpp new file mode 100644 index 0000000000..668edda433 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test14/test14.cpp @@ -0,0 +1,53 @@ +// 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: test14.c +** +** Purpose: Test #14 for the sprintf_s function. Tests the lowercase +** exponential notation double specifier (%e) +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", "foo 2.560000e+02 "); + DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); + DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", "foo 2.56000000e+02"); + DoDoubleTest("foo %014e", val, "foo 02.560000e+002", "foo 002.560000e+02"); + DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); + DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test14/testinfo.dat new file mode 100644 index 0000000000..23cf423354 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test14/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test14 +Description += Tests sprintf_s with exponential format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test15/CMakeLists.txt new file mode 100644 index 0000000000..57bba40e6c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test15/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test15.cpp +) + +add_executable(paltest_sprintf_test15 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test15 coreclrpal) + +target_link_libraries(paltest_sprintf_test15 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test15/test15.cpp new file mode 100644 index 0000000000..61e0e362a1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test15/test15.cpp @@ -0,0 +1,53 @@ +// 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: test15.c +** +** Purpose: Test #15 for the sprintf_s function. Tests the uppercase +** exponential notation double specifier (%E) +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", "foo 2.560000E+02 "); + DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); + DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", "foo 2.56000000E+02"); + DoDoubleTest("foo %014E", val, "foo 02.560000E+002", "foo 002.560000E+02"); + DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); + DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test15/testinfo.dat new file mode 100644 index 0000000000..537e6d1db2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test15/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test15 +Description += Tests sprintf_s with exponential format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test16/CMakeLists.txt new file mode 100644 index 0000000000..fc93e1a67d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test16/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test16.cpp +) + +add_executable(paltest_sprintf_test16 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test16 coreclrpal) + +target_link_libraries(paltest_sprintf_test16 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test16/test16.cpp new file mode 100644 index 0000000000..b237c98d5c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test16/test16.cpp @@ -0,0 +1,52 @@ +// 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: test16.c +** +** Purpose: Test #16 for the sprintf_s function. Tests the decimal notation +** double specifier (%f) +** +** +**==========================================================================*/ + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); + DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); + DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); + DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); + DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); + DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); + DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test16/testinfo.dat new file mode 100644 index 0000000000..4e98eccac2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test16/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test16 +Description += Tests sprintf_s with decimal point format doubles diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test17/CMakeLists.txt new file mode 100644 index 0000000000..dc5ff2bb30 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test17/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test17.cpp +) + +add_executable(paltest_sprintf_test17 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test17 coreclrpal) + +target_link_libraries(paltest_sprintf_test17 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test17/test17.cpp new file mode 100644 index 0000000000..220555e5d4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test17/test17.cpp @@ -0,0 +1,54 @@ +// 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: test17.c +** +** Purpose: Test #17 for the sprintf_s function. Tests the lowercase +** shorthand notation double specifier (%g) +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); + DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); + DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test17/testinfo.dat new file mode 100644 index 0000000000..5e41e20d44 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test17/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test17 +Description += Tests sprintf_s with compact format doubles (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test18/CMakeLists.txt new file mode 100644 index 0000000000..f6e1b09efa --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test18/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test18.cpp +) + +add_executable(paltest_sprintf_test18 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test18 coreclrpal) + +target_link_libraries(paltest_sprintf_test18 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test18/test18.cpp new file mode 100644 index 0000000000..2135a6f1e7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test18/test18.cpp @@ -0,0 +1,53 @@ +// 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: test18.c +** +** Purpose: Test #18 for the sprintf_s function. Tests the uppercase +** shorthand notation double specifier (%G) +** +** +**==========================================================================*/ + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); + DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); + DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test18/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test18/testinfo.dat new file mode 100644 index 0000000000..06ae3a632e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test18/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test18 +Description += Tests sprintf_s with compact format doubles (uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test19/CMakeLists.txt new file mode 100644 index 0000000000..757288b694 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test19/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test19.cpp +) + +add_executable(paltest_sprintf_test19 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test19 coreclrpal) + +target_link_libraries(paltest_sprintf_test19 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test19/test19.cpp new file mode 100644 index 0000000000..483c7167b1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test19/test19.cpp @@ -0,0 +1,71 @@ +// 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: test19.c +** +** Purpose: Test #19 for the sprintf_s function. Tests the variable length +** precision argument. +** +** +**==========================================================================*/ + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int n = -1; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoArgumentPrecTest("%.*s", 2, (void*)"bar", "bar", "ba", "ba"); + DoArgumentPrecTest("%.*S", 2, (void*)convert("bar"), "bar", "ba", "ba"); + + DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); + DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); + DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); + DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); + + + DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); + DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); + DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); + DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); + DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); + DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); + DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); + DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); + DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); + DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test19/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test19/testinfo.dat new file mode 100644 index 0000000000..7064c01771 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test19/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test19 +Description += Tests sprintf_s with argument specified precision diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test2/CMakeLists.txt new file mode 100644 index 0000000000..d569263da4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.cpp +) + +add_executable(paltest_sprintf_test2 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test2 coreclrpal) + +target_link_libraries(paltest_sprintf_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test2/test2.cpp new file mode 100644 index 0000000000..990f4f04a8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test2/test2.cpp @@ -0,0 +1,47 @@ +// 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: test2.c +** +** Purpose: Test #2 for the sprintf_s function. Tests the string specifier +** (%s). +** +** +**==========================================================================*/ + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoStrTest("foo %s", "bar", "foo bar"); + DoStrTest("foo %hs", "bar", "foo bar"); + DoWStrTest("foo %ls", convert("bar"), "foo bar"); + DoWStrTest("foo %ws", convert("bar"), "foo bar"); + DoStrTest("foo %Ls", "bar", "foo bar"); + DoStrTest("foo %I64s", "bar", "foo bar"); + DoStrTest("foo %5s", "bar", "foo bar"); + DoStrTest("foo %.2s", "bar", "foo ba"); + DoStrTest("foo %5.2s", "bar", "foo ba"); + DoStrTest("foo %-5s", "bar", "foo bar "); + DoStrTest("foo %05s", "bar", "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test2/testinfo.dat new file mode 100644 index 0000000000..cce2dc67e7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test2/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test2 +Description += Tests sprintf_s with strings diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test3/CMakeLists.txt new file mode 100644 index 0000000000..518c3f847a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.cpp +) + +add_executable(paltest_sprintf_test3 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test3 coreclrpal) + +target_link_libraries(paltest_sprintf_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test3/test3.cpp new file mode 100644 index 0000000000..c0dc8e1716 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test3/test3.cpp @@ -0,0 +1,47 @@ +// 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: test3.c +** +** Purpose: Test #3 for the sprintf_s function. Tests the wide string +** specifier (%S). +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoWStrTest("foo %S", convert("bar"), "foo bar"); + DoStrTest("foo %hS", "bar", "foo bar"); + DoWStrTest("foo %lS", convert("bar"), "foo bar"); + DoWStrTest("foo %wS", convert("bar"), "foo bar"); + DoWStrTest("foo %LS", convert("bar"), "foo bar"); + DoWStrTest("foo %I64S", convert("bar"), "foo bar"); + DoWStrTest("foo %5S", convert("bar"), "foo bar"); + DoWStrTest("foo %.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %-5S", convert("bar"), "foo bar "); + DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test3/testinfo.dat new file mode 100644 index 0000000000..cc8de0eae5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test3/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test3 +Description += Tests sprintf_s with wide strings diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test4/CMakeLists.txt new file mode 100644 index 0000000000..260def44aa --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test4.cpp +) + +add_executable(paltest_sprintf_test4 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test4 coreclrpal) + +target_link_libraries(paltest_sprintf_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test4/test4.cpp new file mode 100644 index 0000000000..46115ad5ae --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test4/test4.cpp @@ -0,0 +1,69 @@ +// 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: test4.c +** +** Purpose: Test #4 for the sprintf_s function. Tests the pointer +** specifier (%p). +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "0000000000000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "00000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test4/testinfo.dat new file mode 100644 index 0000000000..f53f784991 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test4/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test4 +Description += Tests sprintf_s with pointers diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test6/CMakeLists.txt new file mode 100644 index 0000000000..fce1f204fd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test6/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test6.cpp +) + +add_executable(paltest_sprintf_test6 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test6 coreclrpal) + +target_link_libraries(paltest_sprintf_test6 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test6/test6.cpp new file mode 100644 index 0000000000..c5fc804071 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test6/test6.cpp @@ -0,0 +1,50 @@ +// 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: test6.c +** +** Purpose: Test #6 for the sprintf_s function. Tests the char specifier (%c). +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoCharTest("foo %c", 'b', "foo b"); + DoCharTest("foo %hc", 'b', "foo b"); + DoWCharTest("foo %lc", wc, "foo c"); + DoCharTest("foo %Lc", 'b', "foo b"); + DoCharTest("foo %I64c", 'b', "foo b"); + DoCharTest("foo %5c", 'b', "foo b"); + DoCharTest("foo %.0c", 'b', "foo b"); + DoCharTest("foo %-5c", 'b', "foo b "); + DoCharTest("foo %05c", 'b', "foo 0000b"); + DoCharTest("foo % c", 'b', "foo b"); + DoCharTest("foo %#c", 'b', "foo b"); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test6/testinfo.dat new file mode 100644 index 0000000000..c5b93fc78c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test6/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test6 +Description += Tests sprintf_s with characters diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test7/CMakeLists.txt new file mode 100644 index 0000000000..72a831ec89 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test7/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test7.cpp +) + +add_executable(paltest_sprintf_test7 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test7 coreclrpal) + +target_link_libraries(paltest_sprintf_test7 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test7/test7.cpp new file mode 100644 index 0000000000..fd46ae9674 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test7/test7.cpp @@ -0,0 +1,49 @@ +// 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: test7.c +** +** Purpose: Test #7 for the sprintf_s function. Tests the wide char +** specifier (%C). +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoWCharTest("foo %C", wb, "foo b"); + DoWCharTest("foo %hC", wb, "foo b"); + DoCharTest("foo %lC", 'c', "foo c"); + DoWCharTest("foo %LC", wb, "foo b"); + DoWCharTest("foo %I64C", wb, "foo b"); + DoWCharTest("foo %5C", wb, "foo b"); + DoWCharTest("foo %.0C", wb, "foo b"); + DoWCharTest("foo %-5C", wb, "foo b "); + DoWCharTest("foo %05C", wb, "foo 0000b"); + DoWCharTest("foo % C", wb, "foo b"); + DoWCharTest("foo %#C", wb, "foo b"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test7/testinfo.dat new file mode 100644 index 0000000000..647c9d80fd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test7/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test7 +Description += Tests sprintf_s with wide characters diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test8/CMakeLists.txt new file mode 100644 index 0000000000..c9522c1c9d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test8/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test8.cpp +) + +add_executable(paltest_sprintf_test8 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test8 coreclrpal) + +target_link_libraries(paltest_sprintf_test8 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test8/test8.cpp new file mode 100644 index 0000000000..db02627bb0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test8/test8.cpp @@ -0,0 +1,55 @@ +// 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: test8.c +** +** Purpose: Test #8 for the sprintf_s function. Tests the decimal +** specifier (%d). +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %d", pos, "foo 42"); + DoNumTest("foo %ld", 0xFFFF, "foo 65535"); + DoNumTest("foo %hd", 0xFFFF, "foo -1"); + DoNumTest("foo %Ld", pos, "foo 42"); + DoI64Test("foo %I64d", l, "42", "foo 42"); + DoNumTest("foo %3d", pos, "foo 42"); + DoNumTest("foo %-3d", pos, "foo 42 "); + DoNumTest("foo %.1d", pos, "foo 42"); + DoNumTest("foo %.3d", pos, "foo 042"); + DoNumTest("foo %03d", pos, "foo 042"); + DoNumTest("foo %#d", pos, "foo 42"); + DoNumTest("foo %+d", pos, "foo +42"); + DoNumTest("foo % d", pos, "foo 42"); + DoNumTest("foo %+d", neg, "foo -42"); + DoNumTest("foo % d", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test8/testinfo.dat new file mode 100644 index 0000000000..524834e53e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test8/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test8 +Description += Tests sprintf_s with decimal numbers diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sprintf_s/test9/CMakeLists.txt new file mode 100644 index 0000000000..e76fed4784 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test9/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test9.cpp +) + +add_executable(paltest_sprintf_test9 + ${SOURCES} +) + +add_dependencies(paltest_sprintf_test9 coreclrpal) + +target_link_libraries(paltest_sprintf_test9 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/sprintf_s/test9/test9.cpp new file mode 100644 index 0000000000..2e1c78ce68 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test9/test9.cpp @@ -0,0 +1,55 @@ +// 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: test9.c +** +** Purpose: Test #9 for the sprintf_s function. Tests the integer +** specifier (%i). +** +** +**==========================================================================*/ + + + +#include +#include "../sprintf_s.h" + +/* + * Depends on memcmp and strlen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest("foo %i", pos, "foo 42"); + DoNumTest("foo %li", 0xFFFF, "foo 65535"); + DoNumTest("foo %hi", 0xFFFF, "foo -1"); + DoNumTest("foo %Li", pos, "foo 42"); + DoI64Test("foo %I64i", l, "42", "foo 42"); + DoNumTest("foo %3i", pos, "foo 42"); + DoNumTest("foo %-3i", pos, "foo 42 "); + DoNumTest("foo %.1i", pos, "foo 42"); + DoNumTest("foo %.3i", pos, "foo 042"); + DoNumTest("foo %03i", pos, "foo 042"); + DoNumTest("foo %#i", pos, "foo 42"); + DoNumTest("foo %+i", pos, "foo +42"); + DoNumTest("foo % i", pos, "foo 42"); + DoNumTest("foo %+i", neg, "foo -42"); + DoNumTest("foo % i", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/sprintf_s/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sprintf_s/test9/testinfo.dat new file mode 100644 index 0000000000..7c51443a3d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sprintf_s/test9/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 = C Runtime +Function = sprintf_s +Name = Positive Test for sprintf_s +TYPE = DEFAULT +EXE1 = test9 +Description += Tests sprintf_s with integer numbers diff --git a/src/pal/tests/palsuite/c_runtime/sqrt/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sqrt/test1/CMakeLists.txt index 4347c44e46..d4aefe6ca8 100644 --- a/src/pal/tests/palsuite/c_runtime/sqrt/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/sqrt/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_sqrt_test1 diff --git a/src/pal/tests/palsuite/c_runtime/sqrt/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sqrt/test1/test1.c deleted file mode 100644 index 62d2251d61..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sqrt/test1/test1.c +++ /dev/null @@ -1,123 +0,0 @@ -// 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: test1.c -** -** Purpose: Call the sqrt function on a positive value, a positive value -** with a decimal and on the maxium possible double value. -** -** -**===================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = sqrt(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("sqrt(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = sqrt(value); - - if (!_isnan(result)) - { - Fail("sqrt(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0.31830988618379067, 0.56418958354775629, PAL_EPSILON }, // value: 1 / pi - { 0.43429448190325183, 0.65901022898226081, PAL_EPSILON }, // value: log10(e) - { 0.63661977236758134, 0.79788456080286536, PAL_EPSILON }, // value: 2 / pi - { 0.69314718055994531, 0.83255461115769776, PAL_EPSILON }, // value: ln(2) - { 0.70710678118654752, 0.84089641525371454, PAL_EPSILON }, // value: 1 / sqrt(2) - { 0.78539816339744831, 0.88622692545275801, PAL_EPSILON }, // value: pi / 4 - { 1, 1, PAL_EPSILON * 10 }, - { 1.1283791670955126, 1.0622519320271969, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 1.1892071150027211, PAL_EPSILON * 10 }, // value: sqrt(2) - { 1.4426950408889634, 1.2011224087864498, PAL_EPSILON * 10 }, // value: log2(e) - { 1.5707963267948966, 1.2533141373155003, PAL_EPSILON * 10 }, // value: pi / 2 - { 2.3025850929940457, 1.5174271293851464, PAL_EPSILON * 10 }, // value: ln(10) - { 2.7182818284590452, 1.6487212707001281, PAL_EPSILON * 10 }, // value: e - { 3.1415926535897932, 1.7724538509055160, PAL_EPSILON * 10 }, // value: pi - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - validate(-0.0, -0.0, PAL_EPSILON); - validate( 0.0, 0.0, PAL_EPSILON); - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate(tests[i].value, tests[i].expected, tests[i].variance); - validate_isnan(-tests[i].value); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sqrt/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/sqrt/test1/test1.cpp new file mode 100644 index 0000000000..62d2251d61 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sqrt/test1/test1.cpp @@ -0,0 +1,123 @@ +// 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: test1.c +** +** Purpose: Call the sqrt function on a positive value, a positive value +** with a decimal and on the maxium possible double value. +** +** +**===================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = sqrt(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("sqrt(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = sqrt(value); + + if (!_isnan(result)) + { + Fail("sqrt(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.31830988618379067, 0.56418958354775629, PAL_EPSILON }, // value: 1 / pi + { 0.43429448190325183, 0.65901022898226081, PAL_EPSILON }, // value: log10(e) + { 0.63661977236758134, 0.79788456080286536, PAL_EPSILON }, // value: 2 / pi + { 0.69314718055994531, 0.83255461115769776, PAL_EPSILON }, // value: ln(2) + { 0.70710678118654752, 0.84089641525371454, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.88622692545275801, PAL_EPSILON }, // value: pi / 4 + { 1, 1, PAL_EPSILON * 10 }, + { 1.1283791670955126, 1.0622519320271969, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 1.1892071150027211, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.4426950408889634, 1.2011224087864498, PAL_EPSILON * 10 }, // value: log2(e) + { 1.5707963267948966, 1.2533141373155003, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.3025850929940457, 1.5174271293851464, PAL_EPSILON * 10 }, // value: ln(10) + { 2.7182818284590452, 1.6487212707001281, PAL_EPSILON * 10 }, // value: e + { 3.1415926535897932, 1.7724538509055160, PAL_EPSILON * 10 }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate(-0.0, -0.0, PAL_EPSILON); + validate( 0.0, 0.0, PAL_EPSILON); + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + validate_isnan(-tests[i].value); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sqrtf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sqrtf/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sqrtf/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/sqrtf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sqrtf/test1/CMakeLists.txt new file mode 100644 index 0000000000..96b6ffa998 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sqrtf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_sqrtf_test1 + ${SOURCES} +) + +add_dependencies(paltest_sqrtf_test1 coreclrpal) + +target_link_libraries(paltest_sqrtf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sqrtf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sqrtf/test1/test1.c new file mode 100644 index 0000000000..cb1ac9e7df --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sqrtf/test1/test1.c @@ -0,0 +1,122 @@ +// 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: test1.c +** +** Purpose: Call the sqrtf function on a positive value, a positive value +** with a decimal and on the maxium possible float value. +** +** +**===================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = sqrtf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("sqrtf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = sqrtf(value); + + if (!_isnanf(result)) + { + Fail("sqrtf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.318309886f, 0.564189584f, PAL_EPSILON }, // value: 1 / pi + { 0.434294482f, 0.659010229f, PAL_EPSILON }, // value: log10f(e) + { 0.636619772f, 0.797884561f, PAL_EPSILON }, // value: 2 / pi + { 0.693147181f, 0.832554611f, PAL_EPSILON }, // value: ln(2) + { 0.707106781f, 0.840896415f, PAL_EPSILON }, // value: 1 / sqrtf(2) + { 0.785398163f, 0.886226925f, PAL_EPSILON }, // value: pi / 4 + { 1, 1, PAL_EPSILON * 10 }, + { 1.12837917f, 1.06225193f, PAL_EPSILON * 10 }, // value: 2 / sqrtf(pi) + { 1.41421356f, 1.18920712f, PAL_EPSILON * 10 }, // value: sqrtf(2) + { 1.44269504f, 1.20112241f, PAL_EPSILON * 10 }, // value: logf2(e) + { 1.57079633f, 1.25331414f, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.30258509f, 1.51742713f, PAL_EPSILON * 10 }, // value: ln(10) + { 2.71828183f, 1.64872127f, PAL_EPSILON * 10 }, // value: e + { 3.14159265f, 1.77245385F, PAL_EPSILON * 10 }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate(-0.0f, -0.0f, PAL_EPSILON); + validate( 0.0f, 0.0f, PAL_EPSILON); + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + validate_isnan(-tests[i].value); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sqrtf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sqrtf/test1/testinfo.dat new file mode 100644 index 0000000000..00d8ab2e43 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sqrtf/test1/testinfo.dat @@ -0,0 +1,17 @@ +# 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 = C Runtime +Function = sqrtf +Name = Call sqrtf on positive values and zero. +TYPE = DEFAULT +EXE1 = test1 +Description += Call the sqrtf function on a positive value, a positive value += with a decimal and on the maxium possible float value. + + + + diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/CMakeLists.txt deleted file mode 100644 index 59f39a5f58..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) -add_subdirectory(test10) -add_subdirectory(test11) -add_subdirectory(test12) -add_subdirectory(test13) -add_subdirectory(test14) -add_subdirectory(test15) -add_subdirectory(test16) -add_subdirectory(test17) -add_subdirectory(test2) -add_subdirectory(test3) -add_subdirectory(test4) -add_subdirectory(test5) -add_subdirectory(test6) -add_subdirectory(test7) -add_subdirectory(test8) -add_subdirectory(test9) - diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/sscanf.h b/src/pal/tests/palsuite/c_runtime/sscanf/sscanf.h deleted file mode 100644 index 675a67aed2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/sscanf.h +++ /dev/null @@ -1,246 +0,0 @@ -// 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: sscanf.h -** -** Purpose: Contains common testing functions for sscanf.h -** -** -**==========================================================================*/ - -#ifndef __SSCANF_H__ -#define __SSCANF_H__ - -void DoVoidTest(char *inputstr, char *formatstr) -{ - char buf[256] = { 0 }; - int i; - int ret; - - ret = sscanf(inputstr, formatstr, buf); - if (ret != 0) - { - Fail("ERROR: Expected sscanf to return 0, got %d.\n" - "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); - } - - for (i=0; i<256; i++) - { - if (buf[i] != 0) - { - Fail("ERROR: Parameter unexpectedly modified scanning \"%s\" " - "using \"%s\".\n", inputstr, formatstr); - } - } - -} - -void DoStrTest(char *inputstr, char *formatstr, char *checkstr) -{ - char buf[256] = { 0 }; - int ret; - - ret = sscanf(inputstr, formatstr, buf); - if (ret != 1) - { - Fail("ERROR: Expected sscanf to return 1, got %d.\n" - "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); - } - - if (memcmp(checkstr, buf, strlen(checkstr) + 1) != 0) - { - Fail("ERROR: scanned string incorrectly from \"%s\" using \"%s\".\n" - "Expected \"%s\", got \"%s\".\n", inputstr, formatstr, checkstr, - buf); - } - -} - -void DoWStrTest(char *inputstr, char *formatstr, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - int ret; - - ret = sscanf(inputstr, formatstr, buf); - if (ret != 1) - { - Fail("ERROR: Expected sscanf to return 1, got %d.\n" - "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); - } - - if (memcmp(checkstr, buf, wcslen(checkstr)*2 + 2) != 0) - { - Fail("ERROR: scanned wide string incorrectly from \"%s\" using \"%s\".\n" - "Expected \"%s\", got \"%s\".\n", inputstr, formatstr, - convertC(checkstr), convertC(buf)); - } - -} - -void DoNumTest(char *inputstr, char *formatstr, int checknum) -{ - int num; - int ret; - - ret = sscanf(inputstr, formatstr, &num); - if (ret != 1) - { - Fail("ERROR: Expected sscanf to return 1, got %d.\n" - "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); - } - - if (checknum != num) - { - Fail("ERROR: scanned number incorrectly from \"%s\" using \"%s\".\n" - "Expected %d, got %d.\n", inputstr, formatstr, checknum, num); - } -} - -void DoShortNumTest(char *inputstr, char *formatstr, short checknum) -{ - short num; - int ret; - - ret = sscanf(inputstr, formatstr, &num); - if (ret != 1) - { - Fail("ERROR: Expected sscanf to return 1, got %d.\n" - "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); - } - - if (checknum != num) - { - Fail("ERROR: scanned number incorrectly from \"%s\" using \"%s\".\n" - "Expected %hd, got %hd.\n", inputstr, formatstr, checknum, num); - } -} - -void DoI64NumTest(char *inputstr, char *formatstr, INT64 checknum) -{ - char buf[256]; - char check[256]; - INT64 num; - int ret; - - ret = sscanf(inputstr, formatstr, &num); - if (ret != 1) - { - Fail("ERROR: Expected sscanf to return 1, got %d.\n" - "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); - } - - if (checknum != num) - { - sprintf(buf, "%I64d", num); - sprintf(check, "%I64d", checknum); - Fail("ERROR: scanned I64 number incorrectly from \"%s\" using \"%s\".\n" - "Expected %s, got %s.\n", inputstr, formatstr, check, buf); - } -} - -void DoCharTest(char *inputstr, char *formatstr, char* checkchars, int numchars) -{ - char buf[256]; - int ret; - int i; - - for (i=0; i<256; i++) - buf[i] = (char)-1; - - ret = sscanf(inputstr, formatstr, buf); - if (ret != 1) - { - Fail("ERROR: Expected sscanf to return 1, got %d.\n" - "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); - } - - if (memcmp(buf, checkchars, numchars) != 0) - { - buf[numchars] = 0; - - Fail("ERROR: scanned character(s) incorrectly from \"%s\" using \"%s\".\n" - "Expected %s, got %s.\n", inputstr, formatstr, checkchars, - buf); - } - - if (buf[numchars] != (char)-1) - { - Fail("ERROR: overflow occurred in scanning character(s) from \"%s\" " - "using \"%s\".\nExpected %d character(s)\n", inputstr, formatstr, - numchars); - } -} - -void DoWCharTest(char *inputstr, char *formatstr, WCHAR* checkchars, int numchars) -{ - WCHAR buf[256]; - int ret; - int i; - - for (i=0; i<256; i++) - buf[i] = (WCHAR)-1; - - ret = sscanf(inputstr, formatstr, buf); - if (ret != 1) - { - Fail("ERROR: Expected sscanf to return 1, got %d.\n" - "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); - } - - if (memcmp(buf, checkchars, numchars) != 0) - { - buf[numchars] = 0; - - Fail("ERROR: scanned wide character(s) incorrectly from \"%s\" using \"%s\".\n" - "Expected %s, got %s.\n", inputstr, formatstr, convertC(checkchars), - convertC(buf)); - } - - if (buf[numchars] != (WCHAR)-1) - { - Fail("ERROR: overflow occurred in scanning wide character(s) from \"%s\" " - "using \"%s\".\nExpected %d character(s)\n", inputstr, formatstr, - numchars); - } -} - - -void DoFloatTest(char *inputstr, char *formatstr, float checkval) -{ - char buf[256] = { 0 }; - float val; - int ret; - int i; - - for (i=0; i<256; i++) - buf[i] = (char)-1; - - ret = sscanf(inputstr, formatstr, buf); - val = *(float*)buf; - - if (ret != 1) - { - Fail("ERROR: Expected sscanf to return 1, got %d.\n" - "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); - } - - if (val != checkval) - { - Fail("ERROR: scanned float incorrectly from \"%s\" using \"%s\".\n" - "Expected \"%f\", got \"%f\".\n", inputstr, formatstr, checkval, - val); - } - - if (buf[4] != (char)-1) - { - Fail("ERROR: overflow occurred in scanning float from \"%s\" " - "using \"%s\".\n", inputstr, formatstr); - - } -} - - -#endif diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test1/CMakeLists.txt deleted file mode 100644 index dce6d1de87..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test1.c -) - -add_executable(paltest_sscanf_test1 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test1 coreclrpal) - -target_link_libraries(paltest_sscanf_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sscanf/test1/test1.c deleted file mode 100644 index c6f66a1d20..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test1/test1.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test1.c -** -** Purpose: General test of sscanf -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int num; - int ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoVoidTest("foo bar", "foo "); - DoVoidTest("foo bar", "baz"); - DoVoidTest("foo bar", "foo %*s"); - - DoStrTest("foo % bar", "foo %% %s", "bar"); - DoStrTest("foo bar baz", "foo %bar %s", "baz"); - - DoVoidTest("foo bar baz", "foo % bar %s"); - DoVoidTest("foo baz bar", "foo% baz %s"); - - ret = sscanf("foo bar baz", "foo bar %n", &num); - if (ret != 0 || num != 8) - { - Fail("ERROR: Got incorrect values in scanning \"%s\" using \"%s\".\n" - "Expected to get a value of %d with return value of %d, " - "got %d with return %d\n", "foo bar baz", "foo bar %n", 8, 0, - num, ret); - - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test1/testinfo.dat deleted file mode 100644 index ef33ba9e13..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test1/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test1 -Description -= General test of sscanf diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test10/CMakeLists.txt deleted file mode 100644 index c27e4ce33a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test10/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test10.c -) - -add_executable(paltest_sscanf_test10 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test10 coreclrpal) - -target_link_libraries(paltest_sscanf_test10 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/sscanf/test10/test10.c deleted file mode 100644 index aac5be43ae..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test10/test10.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test10.c -** -** Purpose: Tests sscanf with wide charactersn -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoWCharTest("1234d", "%C", convert("1"), 1); - DoWCharTest("1234d", "%C", convert("1"), 1); - DoWCharTest("abc", "%2C", convert("ab"), 2); - DoWCharTest(" ab", "%C", convert(" "), 1); - DoCharTest("ab", "%hC", "a", 1); - DoWCharTest("ab", "%lC", convert("a"), 1); - DoWCharTest("ab", "%LC", convert("a"), 1); - DoWCharTest("ab", "%I64C", convert("a"), 1); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test10/testinfo.dat deleted file mode 100644 index 7e854ed235..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test10/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test10 -Description -= Tests sscanf with wide characters diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test11/CMakeLists.txt deleted file mode 100644 index 7570e990bf..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test11/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test11.c -) - -add_executable(paltest_sscanf_test11 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test11 coreclrpal) - -target_link_libraries(paltest_sscanf_test11 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/sscanf/test11/test11.c deleted file mode 100644 index 0e3db6cca0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test11/test11.c +++ /dev/null @@ -1,36 +0,0 @@ -// 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: test11.c -** -** Purpose: Tests sscanf with strings -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoStrTest("foo bar", "foo %s", "bar"); - DoStrTest("foo bar", "foo %2s", "ba"); - DoStrTest("foo bar", "foo %hs", "bar"); - DoWStrTest("foo bar", "foo %ls", convert("bar")); - DoStrTest("foo bar", "foo %Ls", "bar"); - DoStrTest("foo bar", "foo %I64s", "bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test11/testinfo.dat deleted file mode 100644 index 60f5cc46a4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test11/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test11 -Description -= Tests sscanf with strings diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test12/CMakeLists.txt deleted file mode 100644 index b6509e46d4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test12/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test12.c -) - -add_executable(paltest_sscanf_test12 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test12 coreclrpal) - -target_link_libraries(paltest_sscanf_test12 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/sscanf/test12/test12.c deleted file mode 100644 index f800e452c0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test12/test12.c +++ /dev/null @@ -1,35 +0,0 @@ -// 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: test12.c -** -** Purpose: Tests sscanf with wide strings -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoWStrTest("foo bar", "foo %S", convert("bar")); - DoWStrTest("foo bar", "foo %2S", convert("ba")); - DoStrTest("foo bar", "foo %hS", "bar"); - DoWStrTest("foo bar", "foo %lS", convert("bar")); - DoWStrTest("foo bar", "foo %LS", convert("bar")); - DoWStrTest("foo bar", "foo %I64S", convert("bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test12/testinfo.dat deleted file mode 100644 index 3c453bf53a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test12/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test12 -Description -= Tests sscanf with wide strings diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test13/CMakeLists.txt deleted file mode 100644 index 6fb4094f00..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test13/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test13.c -) - -add_executable(paltest_sscanf_test13 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test13 coreclrpal) - -target_link_libraries(paltest_sscanf_test13 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/sscanf/test13/test13.c deleted file mode 100644 index 314604e3ac..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test13/test13.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test13.c -** -** Purpose: Tests sscanf with floats (decimal notation) -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest("123.0", "%f", 123.0f); - DoFloatTest("123.0", "%2f", 12.0f); - DoFloatTest("10E1", "%f", 100.0f); - DoFloatTest("-12.01e-2", "%f", -0.1201f); - DoFloatTest("+12.01e-2", "%f", 0.1201f); - DoFloatTest("-12.01e+2", "%f", -1201.0f); - DoFloatTest("+12.01e+2", "%f", 1201.0f); - DoFloatTest("1234567890.0123456789f", "%f", 1234567936); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test13/testinfo.dat deleted file mode 100644 index 1c4c2fc26e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test13/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test13 -Description -= Tests sscanf with floats (decimal notation) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test14/CMakeLists.txt deleted file mode 100644 index 373a75fbda..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test14/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test14.c -) - -add_executable(paltest_sscanf_test14 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test14 coreclrpal) - -target_link_libraries(paltest_sscanf_test14 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/sscanf/test14/test14.c deleted file mode 100644 index d1291a3b65..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test14/test14.c +++ /dev/null @@ -1,36 +0,0 @@ -// 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: test14.c -** -** Purpose: Tests sscanf with floats (exponential notation, lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest("123.0", "%e", 123.0f); - DoFloatTest("123.0", "%2e", 12.0f); - DoFloatTest("10E1", "%e", 100.0f); - DoFloatTest("-12.01e-2", "%e", -0.1201f); - DoFloatTest("+12.01e-2", "%e", 0.1201f); - DoFloatTest("-12.01e+2", "%e", -1201.0f); - DoFloatTest("+12.01e+2", "%e", 1201.0f); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test14/testinfo.dat deleted file mode 100644 index 97db6e4ffd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test14/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test14 -Description -= Tests sscanf with floats (exponential notation, lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test15/CMakeLists.txt deleted file mode 100644 index d500901782..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test15/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test15.c -) - -add_executable(paltest_sscanf_test15 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test15 coreclrpal) - -target_link_libraries(paltest_sscanf_test15 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/sscanf/test15/test15.c deleted file mode 100644 index fa51467d85..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test15/test15.c +++ /dev/null @@ -1,36 +0,0 @@ -// 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: test15.c -** -** Purpose: Tests sscanf with floats (exponential notation, uppercase -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest("123.0", "%E", 123.0f); - DoFloatTest("123.0", "%2E", 12.0f); - DoFloatTest("10E1", "%E", 100.0f); - DoFloatTest("-12.01e-2", "%E", -0.1201f); - DoFloatTest("+12.01e-2", "%E", 0.1201f); - DoFloatTest("-12.01e+2", "%E", -1201.0f); - DoFloatTest("+12.01e+2", "%E", 1201.0f); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test15/testinfo.dat deleted file mode 100644 index 30c2cf4b30..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test15/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test15 -Description -= Tests sscanf with floats (exponential notation, uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test16/CMakeLists.txt deleted file mode 100644 index c5e18ec061..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test16/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test16.c -) - -add_executable(paltest_sscanf_test16 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test16 coreclrpal) - -target_link_libraries(paltest_sscanf_test16 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/sscanf/test16/test16.c deleted file mode 100644 index 787b72ed0a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test16/test16.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test16.c -** -** Purpose:Tests sscanf with floats (compact notation, lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest("123.0", "%g", 123.0f); - DoFloatTest("123.0", "%2g", 12.0f); - DoFloatTest("10E1", "%g", 100.0f); - DoFloatTest("-12.01e-2", "%g", -0.1201f); - DoFloatTest("+12.01e-2", "%g", 0.1201f); - DoFloatTest("-12.01e+2", "%g", -1201.0f); - DoFloatTest("+12.01e+2", "%g", 1201.0f); - DoFloatTest("1234567890.0123456789g", "%g", 1234567936); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test16/testinfo.dat deleted file mode 100644 index 2c1dd42b70..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test16/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test16 -Description -= Tests sscanf with floats (compact notation, lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test17/CMakeLists.txt deleted file mode 100644 index 7d908ab832..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test17/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test17.c -) - -add_executable(paltest_sscanf_test17 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test17 coreclrpal) - -target_link_libraries(paltest_sscanf_test17 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/sscanf/test17/test17.c deleted file mode 100644 index c0dfd1699c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test17/test17.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test17.c -** -** Purpose: Tests sscanf with floats (compact notation, uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest("123.0", "%G", 123.0f); - DoFloatTest("123.0", "%2G", 12.0f); - DoFloatTest("10E1", "%G", 100.0f); - DoFloatTest("-12.01e-2", "%G", -0.1201f); - DoFloatTest("+12.01e-2", "%G", 0.1201f); - DoFloatTest("-12.01e+2", "%G", -1201.0f); - DoFloatTest("+12.01e+2", "%G", 1201.0f); - DoFloatTest("1234567890.0123456789G", "%G", 1234567936); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test17/testinfo.dat deleted file mode 100644 index e23be8541e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test17/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test17 -Description -= Tests sscanf with floats (compact notation, uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test2/CMakeLists.txt deleted file mode 100644 index 571d773a88..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test2/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test2.c -) - -add_executable(paltest_sscanf_test2 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test2 coreclrpal) - -target_link_libraries(paltest_sscanf_test2 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/sscanf/test2/test2.c deleted file mode 100644 index 1221124e3a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test2/test2.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test2.c -** -** Purpose: Test to see if sscanf handles whitespace correctly -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - - -/* - * Tests out how it handles whitespace. Seems to accept anything that qualifies - * as isspace (space, tab, vertical tab, line feed, carriage return and form - * feed), even if it says it only wants spaces tabs and newlines. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoStrTest("foo bar", "foo %s", "bar"); - DoStrTest("foo\tbar", "foo %s", "bar"); - DoStrTest("foo\nbar", "foo %s", "bar"); - DoStrTest("foo\rbar", "foo %s", "bar"); - DoStrTest("foo\vbar", "foo %s", "bar"); - DoStrTest("foo\fbar", "foo %s", "bar"); - DoStrTest("foo \t\n\r\v\fbar", "foo %s", "bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test2/testinfo.dat deleted file mode 100644 index f5ee4b52d4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test2/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test2 -Description -= Test to see if sscanf handles whitespace correctly diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test3/CMakeLists.txt deleted file mode 100644 index ced8d5f8da..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test3/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test3.c -) - -add_executable(paltest_sscanf_test3 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test3 coreclrpal) - -target_link_libraries(paltest_sscanf_test3 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/sscanf/test3/test3.c deleted file mode 100644 index 9d18991070..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test3/test3.c +++ /dev/null @@ -1,35 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests sscanf with bracketed set strings -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoStrTest("bar1", "%[a-z]", "bar"); - DoStrTest("bar1", "%[z-a]", "bar"); - DoStrTest("bar1", "%[ab]", "ba"); - DoStrTest("bar1", "%[ar1b]", "bar1"); - DoStrTest("bar1", "%[^4]", "bar1"); - DoStrTest("bar1", "%[^4a]", "b"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test3/testinfo.dat deleted file mode 100644 index c38a498225..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test3/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test3 -Description -= Tests sscanf with bracketed set strings diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test4/CMakeLists.txt deleted file mode 100644 index 3e70d6dae2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test4/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test4.c -) - -add_executable(paltest_sscanf_test4 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test4 coreclrpal) - -target_link_libraries(paltest_sscanf_test4 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/sscanf/test4/test4.c deleted file mode 100644 index dd0538bcfe..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test4/test4.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests sscanf with decimal numbers -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest("1234d", "%d", 1234); - DoNumTest("1234d", "%2d", 12); - DoNumTest("-1", "%d", -1); - DoNumTest("0x1234", "%d", 0); - DoNumTest("012", "%d", 12); - DoShortNumTest("-1", "%hd", n65535); - DoShortNumTest("65536", "%hd", 0); - DoNumTest("-1", "%ld", -1); - DoNumTest("65536", "%ld", 65536); - DoNumTest("-1", "%Ld", -1); - DoNumTest("65536", "%Ld", 65536); - DoI64NumTest("4294967296", "%I64d", I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test4/testinfo.dat deleted file mode 100644 index 868056a6a5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test4/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test4 -Description -= Tests sscanf with decimal numbers diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test5/CMakeLists.txt deleted file mode 100644 index 391e51baa2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test5/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test5.c -) - -add_executable(paltest_sscanf_test5 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test5 coreclrpal) - -target_link_libraries(paltest_sscanf_test5 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/sscanf/test5/test5.c deleted file mode 100644 index 0d45248af3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test5/test5.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test5.c -** -** Purpose: Tests sscanf with integer numbers -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest("1234d", "%i", 1234); - DoNumTest("1234d", "%2i", 12); - DoNumTest("-1", "%i", -1); - DoNumTest("0x1234", "%i", 0x1234); - DoNumTest("012", "%i", 10); - DoShortNumTest("-1", "%hi", n65535); - DoShortNumTest("65536", "%hi", 0); - DoNumTest("-1", "%li", -1); - DoNumTest("65536", "%li", 65536); - DoNumTest("-1", "%Li", -1); - DoNumTest("65536", "%Li", 65536); - DoI64NumTest("4294967296", "%I64i", I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test5/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test5/testinfo.dat deleted file mode 100644 index 8678dc8f5a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test5/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test5 -Description -= Tests sscanf with integer numbers diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test6/CMakeLists.txt deleted file mode 100644 index c0b21bfd0d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test6/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test6.c -) - -add_executable(paltest_sscanf_test6 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test6 coreclrpal) - -target_link_libraries(paltest_sscanf_test6 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/sscanf/test6/test6.c deleted file mode 100644 index c45ea31b04..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test6/test6.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test6.c -** -** Purpose: Tests sscanf with octal numbers -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest("1234d", "%o", 668); - DoNumTest("1234d", "%2o", 10); - DoNumTest("-1", "%o", -1); - DoNumTest("0x1234", "%o", 0); - DoNumTest("012", "%o", 10); - DoShortNumTest("-1", "%ho", n65535); - DoShortNumTest("200000", "%ho", 0); - DoNumTest("-1", "%lo", -1); - DoNumTest("200000", "%lo", 65536); - DoNumTest("-1", "%Lo", -1); - DoNumTest("200000", "%Lo", 65536); - DoI64NumTest("40000000000", "%I64o", I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test6/testinfo.dat deleted file mode 100644 index b2547a776a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test6/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test6 -Description -= Tests sscanf with octal numbers diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test7/CMakeLists.txt deleted file mode 100644 index bcbd268011..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test7/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test7.c -) - -add_executable(paltest_sscanf_test7 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test7 coreclrpal) - -target_link_libraries(paltest_sscanf_test7 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/sscanf/test7/test7.c deleted file mode 100644 index 0899671d64..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test7/test7.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test7.c -** -** Purpose: Tests sscanf with hex numbers (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest("1234i", "%x", 0x1234); - DoNumTest("1234i", "%2x", 0x12); - DoNumTest("-1", "%x", -1); - DoNumTest("0x1234", "%x", 0x1234); - DoNumTest("012", "%x", 0x12); - DoShortNumTest("-1", "%hx", n65535); - DoShortNumTest("10000", "%hx", 0); - DoNumTest("-1", "%lx", -1); - DoNumTest("10000", "%lx", 65536); - DoNumTest("-1", "%Lx", -1); - DoNumTest("10000", "%Lx", 65536); - DoI64NumTest("100000000", "%I64x", I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test7/testinfo.dat deleted file mode 100644 index 614333e650..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test7/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test7 -Description -= Tests sscanf with hex numbers (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test8/CMakeLists.txt deleted file mode 100644 index 211e9e4df6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test8/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test8.c -) - -add_executable(paltest_sscanf_test8 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test8 coreclrpal) - -target_link_libraries(paltest_sscanf_test8 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/sscanf/test8/test8.c deleted file mode 100644 index 53252f8929..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test8/test8.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test8.c -** -** Purpose:Tests sscanf with unsigned number -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest("1234d", "%u", 1234); - DoNumTest("1234d", "%2u", 12); - DoNumTest("-1", "%u", -1); - DoNumTest("0x1234", "%u", 0); - DoNumTest("012", "%u", 12); - DoShortNumTest("-1", "%hu", n65535); - DoShortNumTest("65536", "%hu", 0); - DoNumTest("-1", "%lu", -1); - DoNumTest("65536", "%lu", 65536); - DoNumTest("-1", "%Lu", -1); - DoNumTest("65536", "%Lu", 65536); - DoI64NumTest("4294967296", "%I64u", I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test8/testinfo.dat deleted file mode 100644 index 2cbc31ad2a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test8/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test8 -Description -= Tests sscanf with unsigned numbers diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf/test9/CMakeLists.txt deleted file mode 100644 index 77c269aeaa..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test9/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test9.c -) - -add_executable(paltest_sscanf_test9 - ${SOURCES} -) - -add_dependencies(paltest_sscanf_test9 coreclrpal) - -target_link_libraries(paltest_sscanf_test9 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/sscanf/test9/test9.c deleted file mode 100644 index c5a2e0de5d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test9/test9.c +++ /dev/null @@ -1,38 +0,0 @@ -// 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: test9.c -** -** Purpose: Tests sscanf with characters -** -** -**==========================================================================*/ - - - -#include -#include "../sscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoCharTest("1234d", "%c", "1", 1); - DoCharTest("1234d", "%c", "1", 1); - DoCharTest("abc", "%2c", "ab", 2); - DoCharTest(" ab", "%c", " ", 1); - DoCharTest("ab", "%hc", "a", 1); - DoWCharTest("ab", "%lc", convert("a"), 1); - DoCharTest("ab", "%Lc", "a", 1); - DoCharTest("ab", "%I64c", "a", 1); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf/test9/testinfo.dat deleted file mode 100644 index c0ccc8a4c9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/sscanf/test9/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 =C Runtime -Function = sscanf -Name = Positive Test for sscanf -TYPE = DEFAULT -EXE1 = test9 -Description -= Tests sscanf with characters diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/CMakeLists.txt new file mode 100644 index 0000000000..59f39a5f58 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test10) +add_subdirectory(test11) +add_subdirectory(test12) +add_subdirectory(test13) +add_subdirectory(test14) +add_subdirectory(test15) +add_subdirectory(test16) +add_subdirectory(test17) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) +add_subdirectory(test5) +add_subdirectory(test6) +add_subdirectory(test7) +add_subdirectory(test8) +add_subdirectory(test9) + diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/sscanf_s.h b/src/pal/tests/palsuite/c_runtime/sscanf_s/sscanf_s.h new file mode 100644 index 0000000000..8a99d87cb4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/sscanf_s.h @@ -0,0 +1,246 @@ +// 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: sscanf_s.h +** +** Purpose: Contains common testing functions for sscanf_s +** +** +**==========================================================================*/ + +#ifndef __SSCANF_S_H__ +#define __SSCANF_S_H__ + +void DoVoidTest(char *inputstr, const char *formatstr) +{ + char buf[256] = { 0 }; + int i; + int ret; + + ret = sscanf_s(inputstr, formatstr, buf); + if (ret != 0) + { + Fail("ERROR: Expected sscanf_s to return 0, got %d.\n" + "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); + } + + for (i=0; i<256; i++) + { + if (buf[i] != 0) + { + Fail("ERROR: Parameter unexpectedly modified scanning \"%s\" " + "using \"%s\".\n", inputstr, formatstr); + } + } + +} + +void DoStrTest(char *inputstr, const char *formatstr, const char *checkstr) +{ + char buf[256] = { 0 }; + int ret; + + ret = sscanf_s(inputstr, formatstr, buf, _countof(buf)); + if (ret != 1) + { + Fail("ERROR: Expected sscanf_s to return 1, got %d.\n" + "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); + } + + if (memcmp(checkstr, buf, strlen(checkstr) + 1) != 0) + { + Fail("ERROR: scanned string incorrectly from \"%s\" using \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", inputstr, formatstr, checkstr, + buf); + } + +} + +void DoWStrTest(char *inputstr, const char *formatstr, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + int ret; + + ret = sscanf_s(inputstr, formatstr, buf, _countof(buf)); + if (ret != 1) + { + Fail("ERROR: Expected sscanf_s to return 1, got %d.\n" + "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); + } + + if (memcmp(checkstr, buf, wcslen(checkstr)*2 + 2) != 0) + { + Fail("ERROR: scanned wide string incorrectly from \"%s\" using \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", inputstr, formatstr, + convertC(checkstr), convertC(buf)); + } + +} + +void DoNumTest(char *inputstr, const char *formatstr, int checknum) +{ + int num; + int ret; + + ret = sscanf_s(inputstr, formatstr, &num); + if (ret != 1) + { + Fail("ERROR: Expected sscanf_s to return 1, got %d.\n" + "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); + } + + if (checknum != num) + { + Fail("ERROR: scanned number incorrectly from \"%s\" using \"%s\".\n" + "Expected %d, got %d.\n", inputstr, formatstr, checknum, num); + } +} + +void DoShortNumTest(char *inputstr, const char *formatstr, short checknum) +{ + short num; + int ret; + + ret = sscanf_s(inputstr, formatstr, &num); + if (ret != 1) + { + Fail("ERROR: Expected sscanf_s to return 1, got %d.\n" + "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); + } + + if (checknum != num) + { + Fail("ERROR: scanned number incorrectly from \"%s\" using \"%s\".\n" + "Expected %hd, got %hd.\n", inputstr, formatstr, checknum, num); + } +} + +void DoI64NumTest(char *inputstr, const char *formatstr, INT64 checknum) +{ + char buf[256]; + char check[256]; + INT64 num; + int ret; + + ret = sscanf_s(inputstr, formatstr, &num); + if (ret != 1) + { + Fail("ERROR: Expected sscanf_s to return 1, got %d.\n" + "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); + } + + if (checknum != num) + { + sprintf_s(buf, _countof(buf), "%I64d", num); + sprintf_s(check, _countof(check), "%I64d", checknum); + Fail("ERROR: scanned I64 number incorrectly from \"%s\" using \"%s\".\n" + "Expected %s, got %s.\n", inputstr, formatstr, check, buf); + } +} + +void DoCharTest(char *inputstr, const char *formatstr, char* checkchars, int numchars) +{ + char buf[256]; + int ret; + int i; + + for (i=0; i<256; i++) + buf[i] = (char)-1; + + ret = sscanf_s(inputstr, formatstr, buf, _countof(buf)); + if (ret != 1) + { + Fail("ERROR: Expected sscanf_s to return 1, got %d.\n" + "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); + } + + if (memcmp(buf, checkchars, numchars) != 0) + { + buf[numchars] = 0; + + Fail("ERROR: scanned character(s) incorrectly from \"%s\" using \"%s\".\n" + "Expected %s, got %s.\n", inputstr, formatstr, checkchars, + buf); + } + + if (buf[numchars] != (char)-1) + { + Fail("ERROR: overflow occurred in scanning character(s) from \"%s\" " + "using \"%s\".\nExpected %d character(s)\n", inputstr, formatstr, + numchars); + } +} + +void DoWCharTest(char *inputstr, const char *formatstr, WCHAR* checkchars, int numchars) +{ + WCHAR buf[256]; + int ret; + int i; + + for (i=0; i<256; i++) + buf[i] = (WCHAR)-1; + + ret = sscanf_s(inputstr, formatstr, buf, _countof(buf)); + if (ret != 1) + { + Fail("ERROR: Expected sscanf_s to return 1, got %d.\n" + "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); + } + + if (memcmp(buf, checkchars, numchars) != 0) + { + buf[numchars] = 0; + + Fail("ERROR: scanned wide character(s) incorrectly from \"%s\" using \"%s\".\n" + "Expected %s, got %s.\n", inputstr, formatstr, convertC(checkchars), + convertC(buf)); + } + + if (buf[numchars] != (WCHAR)-1) + { + Fail("ERROR: overflow occurred in scanning wide character(s) from \"%s\" " + "using \"%s\".\nExpected %d character(s)\n", inputstr, formatstr, + numchars); + } +} + + +void DoFloatTest(char *inputstr, const char *formatstr, float checkval) +{ + char buf[256] = { 0 }; + float val; + int ret; + int i; + + for (i=0; i<256; i++) + buf[i] = (char)-1; + + ret = sscanf_s(inputstr, formatstr, buf); + val = *(float*)buf; + + if (ret != 1) + { + Fail("ERROR: Expected sscanf_s to return 1, got %d.\n" + "Using \"%s\" in \"%s\".\n", ret, inputstr, formatstr); + } + + if (val != checkval) + { + Fail("ERROR: scanned float incorrectly from \"%s\" using \"%s\".\n" + "Expected \"%f\", got \"%f\".\n", inputstr, formatstr, checkval, + val); + } + + if (buf[4] != (char)-1) + { + Fail("ERROR: overflow occurred in scanning float from \"%s\" " + "using \"%s\".\n", inputstr, formatstr); + + } +} + + +#endif diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test1/CMakeLists.txt new file mode 100644 index 0000000000..97b8f570e3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_sscanf_test1 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test1 coreclrpal) + +target_link_libraries(paltest_sscanf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test1/test1.cpp new file mode 100644 index 0000000000..61313146e5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test1/test1.cpp @@ -0,0 +1,53 @@ +// 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: test1.c +** +** Purpose: General test of sscanf_s +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int num; + int ret; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoVoidTest("foo bar", "foo "); + DoVoidTest("foo bar", "baz"); + DoVoidTest("foo bar", "foo %*s"); + + DoStrTest("foo % bar", "foo %% %s", "bar"); + DoStrTest("foo bar baz", "foo %bar %s", "baz"); + + DoVoidTest("foo bar baz", "foo % bar %s"); + DoVoidTest("foo baz bar", "foo% baz %s"); + + ret = sscanf_s("foo bar baz", "foo bar %n", &num); + if (ret != 0 || num != 8) + { + Fail("ERROR: Got incorrect values in scanning \"%s\" using \"%s\".\n" + "Expected to get a value of %d with return value of %d, " + "got %d with return %d\n", "foo bar baz", "foo bar %n", 8, 0, + num, ret); + + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test1/testinfo.dat new file mode 100644 index 0000000000..76f592769f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test1/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test1 +Description += General test of sscanf_s diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test10/CMakeLists.txt new file mode 100644 index 0000000000..afda216c6b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test10/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test10.cpp +) + +add_executable(paltest_sscanf_test10 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test10 coreclrpal) + +target_link_libraries(paltest_sscanf_test10 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test10/test10.cpp new file mode 100644 index 0000000000..0c63c864ed --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test10/test10.cpp @@ -0,0 +1,37 @@ +// 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: test10.c +** +** Purpose: Tests sscanf_s with wide characters +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoWCharTest("1234d", "%C", convert("1"), 1); + DoWCharTest("1234d", "%C", convert("1"), 1); + DoWCharTest("abc", "%2C", convert("ab"), 2); + DoWCharTest(" ab", "%C", convert(" "), 1); + DoCharTest("ab", "%hC", "a", 1); + DoWCharTest("ab", "%lC", convert("a"), 1); + DoWCharTest("ab", "%LC", convert("a"), 1); + DoWCharTest("ab", "%I64C", convert("a"), 1); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test10/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test10/testinfo.dat new file mode 100644 index 0000000000..e048e700a0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test10/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test10 +Description += Tests sscanf_s with wide characters diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test11/CMakeLists.txt new file mode 100644 index 0000000000..c8f98aeeef --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test11/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test11.cpp +) + +add_executable(paltest_sscanf_test11 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test11 coreclrpal) + +target_link_libraries(paltest_sscanf_test11 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test11/test11.cpp new file mode 100644 index 0000000000..8279f4b3f4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test11/test11.cpp @@ -0,0 +1,36 @@ +// 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: test11.c +** +** Purpose: Tests sscanf_s with strings +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoStrTest("foo bar", "foo %s", "bar"); + DoStrTest("foo bar", "foo %2s", "ba"); + DoStrTest("foo bar", "foo %hs", "bar"); + DoWStrTest("foo bar", "foo %ls", convert("bar")); + DoStrTest("foo bar", "foo %Ls", "bar"); + DoStrTest("foo bar", "foo %I64s", "bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test11/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test11/testinfo.dat new file mode 100644 index 0000000000..5a906ddf51 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test11/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test11 +Description += Tests sscanf_s with strings diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test12/CMakeLists.txt new file mode 100644 index 0000000000..0ecedc3285 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test12/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test12.cpp +) + +add_executable(paltest_sscanf_test12 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test12 coreclrpal) + +target_link_libraries(paltest_sscanf_test12 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test12/test12.cpp new file mode 100644 index 0000000000..e599534270 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test12/test12.cpp @@ -0,0 +1,35 @@ +// 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: test12.c +** +** Purpose: Tests sscanf_s with wide strings +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoWStrTest("foo bar", "foo %S", convert("bar")); + DoWStrTest("foo bar", "foo %2S", convert("ba")); + DoStrTest("foo bar", "foo %hS", "bar"); + DoWStrTest("foo bar", "foo %lS", convert("bar")); + DoWStrTest("foo bar", "foo %LS", convert("bar")); + DoWStrTest("foo bar", "foo %I64S", convert("bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test12/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test12/testinfo.dat new file mode 100644 index 0000000000..569be983c0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test12/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test12 +Description += Tests sscanf_s with wide strings diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test13/CMakeLists.txt new file mode 100644 index 0000000000..4566ec3338 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test13/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test13.cpp +) + +add_executable(paltest_sscanf_test13 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test13 coreclrpal) + +target_link_libraries(paltest_sscanf_test13 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test13/test13.cpp new file mode 100644 index 0000000000..4fc12bb751 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test13/test13.cpp @@ -0,0 +1,37 @@ +// 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: test13.c +** +** Purpose: Tests sscanf_s with floats (decimal notation) +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest("123.0", "%f", 123.0f); + DoFloatTest("123.0", "%2f", 12.0f); + DoFloatTest("10E1", "%f", 100.0f); + DoFloatTest("-12.01e-2", "%f", -0.1201f); + DoFloatTest("+12.01e-2", "%f", 0.1201f); + DoFloatTest("-12.01e+2", "%f", -1201.0f); + DoFloatTest("+12.01e+2", "%f", 1201.0f); + DoFloatTest("1234567890.0123456789f", "%f", 1234567936); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test13/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test13/testinfo.dat new file mode 100644 index 0000000000..651577befd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test13/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test13 +Description += Tests sscanf_s with floats (decimal notation) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test14/CMakeLists.txt new file mode 100644 index 0000000000..557acf5bf8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test14/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test14.cpp +) + +add_executable(paltest_sscanf_test14 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test14 coreclrpal) + +target_link_libraries(paltest_sscanf_test14 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test14/test14.cpp new file mode 100644 index 0000000000..fc2fa2ee15 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test14/test14.cpp @@ -0,0 +1,36 @@ +// 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: test14.c +** +** Purpose: Tests sscanf_s with floats (exponential notation, lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest("123.0", "%e", 123.0f); + DoFloatTest("123.0", "%2e", 12.0f); + DoFloatTest("10E1", "%e", 100.0f); + DoFloatTest("-12.01e-2", "%e", -0.1201f); + DoFloatTest("+12.01e-2", "%e", 0.1201f); + DoFloatTest("-12.01e+2", "%e", -1201.0f); + DoFloatTest("+12.01e+2", "%e", 1201.0f); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test14/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test14/testinfo.dat new file mode 100644 index 0000000000..8e7338fd46 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test14/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test14 +Description += Tests sscanf_s with floats (exponential notation, lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test15/CMakeLists.txt new file mode 100644 index 0000000000..efde5c4a21 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test15/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test15.cpp +) + +add_executable(paltest_sscanf_test15 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test15 coreclrpal) + +target_link_libraries(paltest_sscanf_test15 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test15/test15.cpp new file mode 100644 index 0000000000..1eff995b86 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test15/test15.cpp @@ -0,0 +1,36 @@ +// 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: test15.c +** +** Purpose: Tests sscanf_s with floats (exponential notation, uppercase +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest("123.0", "%E", 123.0f); + DoFloatTest("123.0", "%2E", 12.0f); + DoFloatTest("10E1", "%E", 100.0f); + DoFloatTest("-12.01e-2", "%E", -0.1201f); + DoFloatTest("+12.01e-2", "%E", 0.1201f); + DoFloatTest("-12.01e+2", "%E", -1201.0f); + DoFloatTest("+12.01e+2", "%E", 1201.0f); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test15/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test15/testinfo.dat new file mode 100644 index 0000000000..d713a73d81 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test15/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test15 +Description += Tests sscanf_s with floats (exponential notation, uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test16/CMakeLists.txt new file mode 100644 index 0000000000..6757b0d78a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test16/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test16.cpp +) + +add_executable(paltest_sscanf_test16 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test16 coreclrpal) + +target_link_libraries(paltest_sscanf_test16 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test16/test16.cpp new file mode 100644 index 0000000000..f202767448 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test16/test16.cpp @@ -0,0 +1,37 @@ +// 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: test16.c +** +** Purpose:Tests sscanf_s with floats (compact notation, lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest("123.0", "%g", 123.0f); + DoFloatTest("123.0", "%2g", 12.0f); + DoFloatTest("10E1", "%g", 100.0f); + DoFloatTest("-12.01e-2", "%g", -0.1201f); + DoFloatTest("+12.01e-2", "%g", 0.1201f); + DoFloatTest("-12.01e+2", "%g", -1201.0f); + DoFloatTest("+12.01e+2", "%g", 1201.0f); + DoFloatTest("1234567890.0123456789g", "%g", 1234567936); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test16/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test16/testinfo.dat new file mode 100644 index 0000000000..669611945d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test16/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test16 +Description += Tests sscanf_s with floats (compact notation, lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test17/CMakeLists.txt new file mode 100644 index 0000000000..8ea4d5e3f6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test17/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test17.cpp +) + +add_executable(paltest_sscanf_test17 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test17 coreclrpal) + +target_link_libraries(paltest_sscanf_test17 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test17/test17.cpp new file mode 100644 index 0000000000..a18c3caff1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test17/test17.cpp @@ -0,0 +1,37 @@ +// 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: test17.c +** +** Purpose: Tests sscanf_s with floats (compact notation, uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest("123.0", "%G", 123.0f); + DoFloatTest("123.0", "%2G", 12.0f); + DoFloatTest("10E1", "%G", 100.0f); + DoFloatTest("-12.01e-2", "%G", -0.1201f); + DoFloatTest("+12.01e-2", "%G", 0.1201f); + DoFloatTest("-12.01e+2", "%G", -1201.0f); + DoFloatTest("+12.01e+2", "%G", 1201.0f); + DoFloatTest("1234567890.0123456789G", "%G", 1234567936); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test17/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test17/testinfo.dat new file mode 100644 index 0000000000..8ce4e93e1a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test17/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test17 +Description += Tests sscanf_s with floats (compact notation, uppercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test2/CMakeLists.txt new file mode 100644 index 0000000000..4e36223a1d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.cpp +) + +add_executable(paltest_sscanf_test2 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test2 coreclrpal) + +target_link_libraries(paltest_sscanf_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test2/test2.cpp new file mode 100644 index 0000000000..c9c79f67ea --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test2/test2.cpp @@ -0,0 +1,44 @@ +// 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: test2.c +** +** Purpose: Test to see if sscanf_s handles whitespace correctly +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + + +/* + * Tests out how it handles whitespace. Seems to accept anything that qualifies + * as isspace (space, tab, vertical tab, line feed, carriage return and form + * feed), even if it says it only wants spaces tabs and newlines. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoStrTest("foo bar", "foo %s", "bar"); + DoStrTest("foo\tbar", "foo %s", "bar"); + DoStrTest("foo\nbar", "foo %s", "bar"); + DoStrTest("foo\rbar", "foo %s", "bar"); + DoStrTest("foo\vbar", "foo %s", "bar"); + DoStrTest("foo\fbar", "foo %s", "bar"); + DoStrTest("foo \t\n\r\v\fbar", "foo %s", "bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test2/testinfo.dat new file mode 100644 index 0000000000..85fed244f9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test2/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test2 +Description += Test to see if sscanf_s handles whitespace correctly diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test3/CMakeLists.txt new file mode 100644 index 0000000000..053a96ca0f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.cpp +) + +add_executable(paltest_sscanf_test3 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test3 coreclrpal) + +target_link_libraries(paltest_sscanf_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test3/test3.cpp new file mode 100644 index 0000000000..e1e45bdd70 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test3/test3.cpp @@ -0,0 +1,35 @@ +// 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: test3.c +** +** Purpose: Tests sscanf_s with bracketed set strings +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoStrTest("bar1", "%[a-z]", "bar"); + DoStrTest("bar1", "%[z-a]", "bar"); + DoStrTest("bar1", "%[ab]", "ba"); + DoStrTest("bar1", "%[ar1b]", "bar1"); + DoStrTest("bar1", "%[^4]", "bar1"); + DoStrTest("bar1", "%[^4a]", "b"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test3/testinfo.dat new file mode 100644 index 0000000000..523d31e82e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test3/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test3 +Description += Tests sscanf_s with bracketed set strings diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test4/CMakeLists.txt new file mode 100644 index 0000000000..ae04bfef57 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test4.cpp +) + +add_executable(paltest_sscanf_test4 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test4 coreclrpal) + +target_link_libraries(paltest_sscanf_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test4/test4.cpp new file mode 100644 index 0000000000..f8413ea7fd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test4/test4.cpp @@ -0,0 +1,44 @@ +// 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: test4.c +** +** Purpose: Tests sscanf_s with decimal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest("1234d", "%d", 1234); + DoNumTest("1234d", "%2d", 12); + DoNumTest("-1", "%d", -1); + DoNumTest("0x1234", "%d", 0); + DoNumTest("012", "%d", 12); + DoShortNumTest("-1", "%hd", n65535); + DoShortNumTest("65536", "%hd", 0); + DoNumTest("-1", "%ld", -1); + DoNumTest("65536", "%ld", 65536); + DoNumTest("-1", "%Ld", -1); + DoNumTest("65536", "%Ld", 65536); + DoI64NumTest("4294967296", "%I64d", I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test4/testinfo.dat new file mode 100644 index 0000000000..2065f2bea2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test4/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test4 +Description += Tests sscanf_s with decimal numbers diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test5/CMakeLists.txt new file mode 100644 index 0000000000..33dcaffec3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test5/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test5.cpp +) + +add_executable(paltest_sscanf_test5 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test5 coreclrpal) + +target_link_libraries(paltest_sscanf_test5 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test5/test5.cpp new file mode 100644 index 0000000000..cdfefd860b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test5/test5.cpp @@ -0,0 +1,43 @@ +// 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: test5.c +** +** Purpose: Tests sscanf_s with integer numbers +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest("1234d", "%i", 1234); + DoNumTest("1234d", "%2i", 12); + DoNumTest("-1", "%i", -1); + DoNumTest("0x1234", "%i", 0x1234); + DoNumTest("012", "%i", 10); + DoShortNumTest("-1", "%hi", n65535); + DoShortNumTest("65536", "%hi", 0); + DoNumTest("-1", "%li", -1); + DoNumTest("65536", "%li", 65536); + DoNumTest("-1", "%Li", -1); + DoNumTest("65536", "%Li", 65536); + DoI64NumTest("4294967296", "%I64i", I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test5/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test5/testinfo.dat new file mode 100644 index 0000000000..cb687c15cd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test5 +Description += Tests sscanf_s with integer numbers diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test6/CMakeLists.txt new file mode 100644 index 0000000000..1dd23c3cb1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test6/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test6.cpp +) + +add_executable(paltest_sscanf_test6 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test6 coreclrpal) + +target_link_libraries(paltest_sscanf_test6 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test6/test6.cpp new file mode 100644 index 0000000000..507b100e15 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test6/test6.cpp @@ -0,0 +1,43 @@ +// 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: test6.c +** +** Purpose: Tests sscanf_s with octal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest("1234d", "%o", 668); + DoNumTest("1234d", "%2o", 10); + DoNumTest("-1", "%o", -1); + DoNumTest("0x1234", "%o", 0); + DoNumTest("012", "%o", 10); + DoShortNumTest("-1", "%ho", n65535); + DoShortNumTest("200000", "%ho", 0); + DoNumTest("-1", "%lo", -1); + DoNumTest("200000", "%lo", 65536); + DoNumTest("-1", "%Lo", -1); + DoNumTest("200000", "%Lo", 65536); + DoI64NumTest("40000000000", "%I64o", I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test6/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test6/testinfo.dat new file mode 100644 index 0000000000..9e518dddf2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test6/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test6 +Description += Tests sscanf_s with octal numbers diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test7/CMakeLists.txt new file mode 100644 index 0000000000..015a27b776 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test7/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test7.cpp +) + +add_executable(paltest_sscanf_test7 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test7 coreclrpal) + +target_link_libraries(paltest_sscanf_test7 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test7/test7.cpp new file mode 100644 index 0000000000..4093e009e1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test7/test7.cpp @@ -0,0 +1,43 @@ +// 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: test7.c +** +** Purpose: Tests sscanf_s with hex numbers (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest("1234i", "%x", 0x1234); + DoNumTest("1234i", "%2x", 0x12); + DoNumTest("-1", "%x", -1); + DoNumTest("0x1234", "%x", 0x1234); + DoNumTest("012", "%x", 0x12); + DoShortNumTest("-1", "%hx", n65535); + DoShortNumTest("10000", "%hx", 0); + DoNumTest("-1", "%lx", -1); + DoNumTest("10000", "%lx", 65536); + DoNumTest("-1", "%Lx", -1); + DoNumTest("10000", "%Lx", 65536); + DoI64NumTest("100000000", "%I64x", I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test7/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test7/testinfo.dat new file mode 100644 index 0000000000..8d6c182c90 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test7/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test7 +Description += Tests sscanf_s with hex numbers (lowercase) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test8/CMakeLists.txt new file mode 100644 index 0000000000..aa41ab42a6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test8/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test8.cpp +) + +add_executable(paltest_sscanf_test8 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test8 coreclrpal) + +target_link_libraries(paltest_sscanf_test8 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test8/test8.cpp new file mode 100644 index 0000000000..23ef22a56a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test8/test8.cpp @@ -0,0 +1,43 @@ +// 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: test8.c +** +** Purpose:Tests sscanf_s with unsigned number +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest("1234d", "%u", 1234); + DoNumTest("1234d", "%2u", 12); + DoNumTest("-1", "%u", -1); + DoNumTest("0x1234", "%u", 0); + DoNumTest("012", "%u", 12); + DoShortNumTest("-1", "%hu", n65535); + DoShortNumTest("65536", "%hu", 0); + DoNumTest("-1", "%lu", -1); + DoNumTest("65536", "%lu", 65536); + DoNumTest("-1", "%Lu", -1); + DoNumTest("65536", "%Lu", 65536); + DoI64NumTest("4294967296", "%I64u", I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test8/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test8/testinfo.dat new file mode 100644 index 0000000000..0287a495d2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test8/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 = C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test8 +Description += Tests sscanf_s with unsigned numbers diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sscanf_s/test9/CMakeLists.txt new file mode 100644 index 0000000000..b631fd40ea --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test9/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test9.cpp +) + +add_executable(paltest_sscanf_test9 + ${SOURCES} +) + +add_dependencies(paltest_sscanf_test9 coreclrpal) + +target_link_libraries(paltest_sscanf_test9 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/sscanf_s/test9/test9.cpp new file mode 100644 index 0000000000..2c99c40e5d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test9/test9.cpp @@ -0,0 +1,38 @@ +// 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: test9.c +** +** Purpose: Tests sscanf_s with characters +** +** +**==========================================================================*/ + + + +#include +#include "../sscanf_s.h" + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoCharTest("1234d", "%c", "1", 1); + DoCharTest("1234d", "%c", "1", 1); + DoCharTest("abc", "%2c", "ab", 2); + DoCharTest(" ab", "%c", " ", 1); + DoCharTest("ab", "%hc", "a", 1); + DoWCharTest("ab", "%lc", convert("a"), 1); + DoCharTest("ab", "%Lc", "a", 1); + DoCharTest("ab", "%I64c", "a", 1); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sscanf_s/test9/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sscanf_s/test9/testinfo.dat new file mode 100644 index 0000000000..95f6c74ee2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sscanf_s/test9/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 =C Runtime +Function = sscanf_s +Name = Positive Test for sscanf_s +TYPE = DEFAULT +EXE1 = test9 +Description += Tests sscanf_s with characters diff --git a/src/pal/tests/palsuite/c_runtime/strcat/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strcat/test1/CMakeLists.txt index 4a0f0be32d..fd62627db6 100644 --- a/src/pal/tests/palsuite/c_runtime/strcat/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strcat/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strcat_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strcat/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strcat/test1/test1.c deleted file mode 100644 index 532d84621e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strcat/test1/test1.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Concatenate three strings into one string. Each time, check to ensure -** the pointer returned was what we expected. When finished, compare the -** newly formed string to what it should be to ensure no characters were -** lost. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char dest[80]; - char *test = "foo bar baz"; - char *str1 = "foo "; - char *str2 = "bar "; - char *str3 = "baz"; - char *ptr; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - dest[0] = 0; - - ptr = strcat(dest, str1); - if (ptr != dest) - { - Fail("ERROR: Expected strcat to return ptr to %p, got %p", dest, ptr); - } - - ptr = strcat(dest, str2); - if (ptr != dest) - { - Fail("ERROR: Expected strcat to return ptr to %p, got %p", dest, ptr); - } - - ptr = strcat(dest, str3); - if (ptr != dest) - { - Fail("ERROR: Expected strcat to return ptr to %p, got %p", dest, ptr); - } - - if (strcmp(dest, test) != 0) - { - Fail("ERROR: Expected strcat to give \"%s\", got \"%s\"\n", - test, dest); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strcat/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strcat/test1/test1.cpp new file mode 100644 index 0000000000..532d84621e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strcat/test1/test1.cpp @@ -0,0 +1,66 @@ +// 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: test1.c +** +** Purpose: +** Concatenate three strings into one string. Each time, check to ensure +** the pointer returned was what we expected. When finished, compare the +** newly formed string to what it should be to ensure no characters were +** lost. +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char dest[80]; + char *test = "foo bar baz"; + char *str1 = "foo "; + char *str2 = "bar "; + char *str3 = "baz"; + char *ptr; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + dest[0] = 0; + + ptr = strcat(dest, str1); + if (ptr != dest) + { + Fail("ERROR: Expected strcat to return ptr to %p, got %p", dest, ptr); + } + + ptr = strcat(dest, str2); + if (ptr != dest) + { + Fail("ERROR: Expected strcat to return ptr to %p, got %p", dest, ptr); + } + + ptr = strcat(dest, str3); + if (ptr != dest) + { + Fail("ERROR: Expected strcat to return ptr to %p, got %p", dest, ptr); + } + + if (strcmp(dest, test) != 0) + { + Fail("ERROR: Expected strcat to give \"%s\", got \"%s\"\n", + test, dest); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strchr/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strchr/test1/CMakeLists.txt index 1d248f3f56..f3ffe3bc15 100644 --- a/src/pal/tests/palsuite/c_runtime/strchr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strchr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strchr_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strchr/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strchr/test1/test1.c deleted file mode 100644 index 9190c4f7ce..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strchr/test1/test1.c +++ /dev/null @@ -1,86 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Test this on a character which is in a string, and ensure the pointer -** points to that character. Then check the string for the null character, -** which the return pointer should point to. Then search for a character not -** in the string and check that the return value is NULL. -** -** -**==========================================================================*/ - -#include - -struct testCase -{ - int result; - char string[50]; - int character; -}; - - - -int __cdecl main(int argc, char *argv[]) -{ - int i = 0; - char *result; - - /* - * this structure includes several strings to be tested with - * strchr function and the expected results - */ - - struct testCase testCases[]= - { - {22,"corn cup cat cream coast",'s'}, - {10,"corn cup cat cream coast",'a'}, - {2,"This is a test",'i'}, - {10,"This is a test",'t'}, - {'\0',"This is a test",'b'},/* zero used instead of NULL */ - {'\0',"This is a test",121},/* zero used instead of NULL */ - {4,"This is a test of the function",' '}, - {25,"This is a test of the function",'c'}, - {'\0',"This is a test of the function",'C'}, - {24,"corn cup cat cream coast", '\0'}/* zero used instead of NULL */ - }; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through the structure and test each case */ - - for (i=0; i< sizeof(testCases)/sizeof(struct testCase); i++) - { - result = strchr(testCases[i].string,testCases[i].character); - if (result==NULL) - { - if (testCases[i].result != (int) NULL) - { - Fail("Expected strchr() to return \"%s\" instead of NULL!\n", - testCases[i].string + testCases[i].result); - } - } - else - { - if (result != testCases[i].string + testCases[i].result) - { - Fail("Expected strchr() to return \"%s\" instead of \"%s\"!\n", - testCases[i].string + testCases[i].result, result); - } - } - - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strchr/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strchr/test1/test1.cpp new file mode 100644 index 0000000000..9190c4f7ce --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strchr/test1/test1.cpp @@ -0,0 +1,86 @@ +// 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: test1.c +** +** Purpose: +** Test this on a character which is in a string, and ensure the pointer +** points to that character. Then check the string for the null character, +** which the return pointer should point to. Then search for a character not +** in the string and check that the return value is NULL. +** +** +**==========================================================================*/ + +#include + +struct testCase +{ + int result; + char string[50]; + int character; +}; + + + +int __cdecl main(int argc, char *argv[]) +{ + int i = 0; + char *result; + + /* + * this structure includes several strings to be tested with + * strchr function and the expected results + */ + + struct testCase testCases[]= + { + {22,"corn cup cat cream coast",'s'}, + {10,"corn cup cat cream coast",'a'}, + {2,"This is a test",'i'}, + {10,"This is a test",'t'}, + {'\0',"This is a test",'b'},/* zero used instead of NULL */ + {'\0',"This is a test",121},/* zero used instead of NULL */ + {4,"This is a test of the function",' '}, + {25,"This is a test of the function",'c'}, + {'\0',"This is a test of the function",'C'}, + {24,"corn cup cat cream coast", '\0'}/* zero used instead of NULL */ + }; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through the structure and test each case */ + + for (i=0; i< sizeof(testCases)/sizeof(struct testCase); i++) + { + result = strchr(testCases[i].string,testCases[i].character); + if (result==NULL) + { + if (testCases[i].result != (int) NULL) + { + Fail("Expected strchr() to return \"%s\" instead of NULL!\n", + testCases[i].string + testCases[i].result); + } + } + else + { + if (result != testCases[i].string + testCases[i].result) + { + Fail("Expected strchr() to return \"%s\" instead of \"%s\"!\n", + testCases[i].string + testCases[i].result, result); + } + } + + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strcmp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strcmp/test1/CMakeLists.txt index b953dfa034..3b0f89c2a5 100644 --- a/src/pal/tests/palsuite/c_runtime/strcmp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strcmp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strcmp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strcmp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strcmp/test1/test1.c deleted file mode 100644 index 49428fd624..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strcmp/test1/test1.c +++ /dev/null @@ -1,73 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Compare a number of different strings against each other, ensure that the -** three return values are given at the appropriate times. -** -** -**==========================================================================*/ - -#include - -typedef struct -{ - int result; - char string1[50]; - char string2[50]; -} testCase; - -testCase testCases[]= -{ - {0,"Hello","Hello"}, - {1,"hello","Hello"}, - {-1,"Hello","hello"}, - {0,"0Test","0Test"}, - {0,"***???","***???"}, - {0,"Testing the string for string comparison","Testing the string for " - "string comparison"}, - {-1,"Testing the string for string comparison","Testing the string for " - "string comparsioa"}, - {1,"Testing the string for string comparison","Testing the string for " - "comparison"}, - {-1,"aaaabbbbb","aabcdefeccg"} -}; - -int __cdecl main(int argc, char *argv[]) -{ - int i = 0; - int result = 0; - - /* - * Initialize the PAL - */ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Loop through structure and test each case */ - for (i=0; i < sizeof(testCases)/sizeof(testCase); i++) - { - result = strcmp(testCases[i].string1,testCases[i].string2); - - /* Compare returned value */ - if( ((result == 0) && (testCases[i].result !=0)) || - ((result <0) && (testCases[i].result !=-1)) || - ((result >0) && (testCases[i].result !=1)) ) - { - Fail("ERROR: strcmp returned %d instead of %d\n", - result, testCases[i].result); - } - - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strcmp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strcmp/test1/test1.cpp new file mode 100644 index 0000000000..49428fd624 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strcmp/test1/test1.cpp @@ -0,0 +1,73 @@ +// 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: test1.c +** +** Purpose: +** Compare a number of different strings against each other, ensure that the +** three return values are given at the appropriate times. +** +** +**==========================================================================*/ + +#include + +typedef struct +{ + int result; + char string1[50]; + char string2[50]; +} testCase; + +testCase testCases[]= +{ + {0,"Hello","Hello"}, + {1,"hello","Hello"}, + {-1,"Hello","hello"}, + {0,"0Test","0Test"}, + {0,"***???","***???"}, + {0,"Testing the string for string comparison","Testing the string for " + "string comparison"}, + {-1,"Testing the string for string comparison","Testing the string for " + "string comparsioa"}, + {1,"Testing the string for string comparison","Testing the string for " + "comparison"}, + {-1,"aaaabbbbb","aabcdefeccg"} +}; + +int __cdecl main(int argc, char *argv[]) +{ + int i = 0; + int result = 0; + + /* + * Initialize the PAL + */ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Loop through structure and test each case */ + for (i=0; i < sizeof(testCases)/sizeof(testCase); i++) + { + result = strcmp(testCases[i].string1,testCases[i].string2); + + /* Compare returned value */ + if( ((result == 0) && (testCases[i].result !=0)) || + ((result <0) && (testCases[i].result !=-1)) || + ((result >0) && (testCases[i].result !=1)) ) + { + Fail("ERROR: strcmp returned %d instead of %d\n", + result, testCases[i].result); + } + + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strcpy/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strcpy/test1/CMakeLists.txt index 043ec57d98..4369d37a40 100644 --- a/src/pal/tests/palsuite/c_runtime/strcpy/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strcpy/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strcpy_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strcpy/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strcpy/test1/test1.c deleted file mode 100644 index 43069e59a6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strcpy/test1/test1.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Call the function to copy into an empty buffer. Check that the return value -** is pointing at the destination buffer. Also compare the string copied to -** the origional string, to ensure they are the same. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char dest[80]; - char *result = "foo"; - char str[] = {'f','o','o',0,'b','a','r',0}; - char *ret; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - ret = strcpy(dest, str); - - if (ret != dest) - { - Fail("Expected strcpy to return %p, got %p!\n", dest, ret); - - } - - if (strcmp(dest, result) != 0) - { - Fail("Expected strcpy to give \"%s\", got \"%s\"!\n", result, dest); - } - - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strcpy/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strcpy/test1/test1.cpp new file mode 100644 index 0000000000..43069e59a6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strcpy/test1/test1.cpp @@ -0,0 +1,51 @@ +// 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: test1.c +** +** Purpose: +** Call the function to copy into an empty buffer. Check that the return value +** is pointing at the destination buffer. Also compare the string copied to +** the origional string, to ensure they are the same. +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char dest[80]; + char *result = "foo"; + char str[] = {'f','o','o',0,'b','a','r',0}; + char *ret; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + ret = strcpy(dest, str); + + if (ret != dest) + { + Fail("Expected strcpy to return %p, got %p!\n", dest, ret); + + } + + if (strcmp(dest, result) != 0) + { + Fail("Expected strcpy to give \"%s\", got \"%s\"!\n", result, dest); + } + + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strcspn/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strcspn/test1/CMakeLists.txt index a38761c335..717e18f0e9 100644 --- a/src/pal/tests/palsuite/c_runtime/strcspn/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strcspn/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strcspn_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strcspn/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strcspn/test1/test1.c deleted file mode 100644 index ddc5667570..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strcspn/test1/test1.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests strcspn with a character set that should give an index into -** the middle of the original string. Also tests with character sets -** that are not in the string at all, and character sets that match -** with the very first character. -** -** -**==========================================================================*/ - -#include - -struct testCase -{ - long result; - char *string1; - char *string2; -}; - -int __cdecl main(int argc, char *argv[]) -{ - int i=0; - long TheResult = 0; - - struct testCase testCases[]= - { - {4,"abcdefg12345678hijklmnopqrst","t8m1sBe"}, - {23,"This is a test, testing", "X\tylM"}, - {0,"foobar","tzkfb"}, - }; - - /* - * Initialize the PAL - */ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i + +struct testCase +{ + long result; + char *string1; + char *string2; +}; + +int __cdecl main(int argc, char *argv[]) +{ + int i=0; + long TheResult = 0; + + struct testCase testCases[]= + { + {4,"abcdefg12345678hijklmnopqrst","t8m1sBe"}, + {23,"This is a test, testing", "X\tylM"}, + {0,"foobar","tzkfb"}, + }; + + /* + * Initialize the PAL + */ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - if (strlen("foo") != 3) - Fail("ERROR: strlen(\"foo\") != 3\n"); - - if (strlen("") != 0) - Fail("ERROR: strlen(\"\") != 0\n"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strlen/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strlen/test1/test1.cpp new file mode 100644 index 0000000000..40f8e151c7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strlen/test1/test1.cpp @@ -0,0 +1,33 @@ +// 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: test1.c +** +** Purpose: +** Check the length of a string and the length of a 0 character string to +** see that this function returns the correct values for each. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + if (strlen("foo") != 3) + Fail("ERROR: strlen(\"foo\") != 3\n"); + + if (strlen("") != 0) + Fail("ERROR: strlen(\"\") != 0\n"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strncat/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strncat/test1/CMakeLists.txt index 7595f66939..f8080ecdc2 100644 --- a/src/pal/tests/palsuite/c_runtime/strncat/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strncat/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strncat_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strncat/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strncat/test1/test1.c deleted file mode 100644 index 000d1685b9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strncat/test1/test1.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Concatenate a few strings together, setting different lengths to be -** used for each one. Check to ensure the pointers which are returned are -** correct, and that the final string is what was expected. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char dest[80]; - char *test = "foo barbaz"; - char *str1 = "foo "; - char *str2 = "bar "; - char *str3 = "baz"; - char *ptr; - int i; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - dest[0] = 0; - for (i=1; i<80; i++) - { - dest[i] = 'x'; - } - - ptr = strncat(dest, str1, strlen(str1)); - if (ptr != dest) - { - Fail("ERROR: Expected strncat to return ptr to %p, got %p", dest, ptr); - } - - ptr = strncat(dest, str2, 3); - if (ptr != dest) - { - Fail("ERROR: Expected strncat to return ptr to %p, got %p", dest, ptr); - } - if (dest[7] != 0) - { - Fail("ERROR: strncat did not place a terminating NULL!"); - } - - ptr = strncat(dest, str3, 20); - if (ptr != dest) - { - Fail("ERROR: Expected strncat to return ptr to %p, got %p", dest, ptr); - } - if (strcmp(dest, test) != 0) - { - Fail("ERROR: Expected strncat to give \"%s\", got \"%s\"\n", - test, dest); - } - if (dest[strlen(test)+1] != 'x') - { - Fail("strncat went out of bounds!\n"); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strncat/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strncat/test1/test1.cpp new file mode 100644 index 0000000000..000d1685b9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strncat/test1/test1.cpp @@ -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: test1.c +** +** Purpose: +** Concatenate a few strings together, setting different lengths to be +** used for each one. Check to ensure the pointers which are returned are +** correct, and that the final string is what was expected. +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char dest[80]; + char *test = "foo barbaz"; + char *str1 = "foo "; + char *str2 = "bar "; + char *str3 = "baz"; + char *ptr; + int i; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + dest[0] = 0; + for (i=1; i<80; i++) + { + dest[i] = 'x'; + } + + ptr = strncat(dest, str1, strlen(str1)); + if (ptr != dest) + { + Fail("ERROR: Expected strncat to return ptr to %p, got %p", dest, ptr); + } + + ptr = strncat(dest, str2, 3); + if (ptr != dest) + { + Fail("ERROR: Expected strncat to return ptr to %p, got %p", dest, ptr); + } + if (dest[7] != 0) + { + Fail("ERROR: strncat did not place a terminating NULL!"); + } + + ptr = strncat(dest, str3, 20); + if (ptr != dest) + { + Fail("ERROR: Expected strncat to return ptr to %p, got %p", dest, ptr); + } + if (strcmp(dest, test) != 0) + { + Fail("ERROR: Expected strncat to give \"%s\", got \"%s\"\n", + test, dest); + } + if (dest[strlen(test)+1] != 'x') + { + Fail("strncat went out of bounds!\n"); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strncmp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strncmp/test1/CMakeLists.txt index 4a0337a3dc..34b53e294d 100644 --- a/src/pal/tests/palsuite/c_runtime/strncmp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strncmp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strncmp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strncmp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strncmp/test1/test1.c deleted file mode 100644 index 7326c3b61e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strncmp/test1/test1.c +++ /dev/null @@ -1,80 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Test to ensure all three possible return values are given under the -** appropriate circumstance. Also, uses different sizes, to only compare -** portions of strings, checking to make sure these return the correct value. -** -** -**==========================================================================*/ - -#include - -typedef struct -{ - int result; - char string1[50]; - char string2[50]; - int number; -} testCase; - -testCase testCases[]= -{ - {0,"Hello","Hello",5}, - {1,"hello","Hello",3}, - {-1,"Hello","hello",5}, - {0,"heLLo","heLLo",5}, - {1,"hello","heLlo",5}, - {-1,"heLlo","hello",5}, - {0,"0Test","0Test",5}, - {0,"***???","***???",6}, - {0,"Testing the string for string comparison","Testing the string for " - "string comparison",40}, - {-1,"Testing the string for string comparison","Testing the string for " - "string comparsioa",40}, - {1,"Testing the string for string comparison","Testing the string for " - "comparison",34}, - {0,"aaaabbbbb","aabcdefeccg",2}, - {0,"abcd","abcd",10} -}; - - -int __cdecl main(int argc, char *argv[]) -{ - int i=0; - int iresult=0; - - /* - * Initialize the PAL - */ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - for (i=0; i< sizeof(testCases)/sizeof(testCase); i++) - { - iresult = strncmp(testCases[i].string1,testCases[i].string2, - testCases[i].number); - - if( ((iresult == 0) && (testCases[i].result !=0)) || - ((iresult <0) && (testCases[i].result !=-1)) || - ((iresult >0) && (testCases[i].result !=1)) ) - - { - Fail("ERROR: strncmp returned %d instead of %d\n", - iresult, testCases[i].result); - } - - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strncmp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strncmp/test1/test1.cpp new file mode 100644 index 0000000000..7326c3b61e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strncmp/test1/test1.cpp @@ -0,0 +1,80 @@ +// 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: test1.c +** +** Purpose: +** Test to ensure all three possible return values are given under the +** appropriate circumstance. Also, uses different sizes, to only compare +** portions of strings, checking to make sure these return the correct value. +** +** +**==========================================================================*/ + +#include + +typedef struct +{ + int result; + char string1[50]; + char string2[50]; + int number; +} testCase; + +testCase testCases[]= +{ + {0,"Hello","Hello",5}, + {1,"hello","Hello",3}, + {-1,"Hello","hello",5}, + {0,"heLLo","heLLo",5}, + {1,"hello","heLlo",5}, + {-1,"heLlo","hello",5}, + {0,"0Test","0Test",5}, + {0,"***???","***???",6}, + {0,"Testing the string for string comparison","Testing the string for " + "string comparison",40}, + {-1,"Testing the string for string comparison","Testing the string for " + "string comparsioa",40}, + {1,"Testing the string for string comparison","Testing the string for " + "comparison",34}, + {0,"aaaabbbbb","aabcdefeccg",2}, + {0,"abcd","abcd",10} +}; + + +int __cdecl main(int argc, char *argv[]) +{ + int i=0; + int iresult=0; + + /* + * Initialize the PAL + */ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + for (i=0; i< sizeof(testCases)/sizeof(testCase); i++) + { + iresult = strncmp(testCases[i].string1,testCases[i].string2, + testCases[i].number); + + if( ((iresult == 0) && (testCases[i].result !=0)) || + ((iresult <0) && (testCases[i].result !=-1)) || + ((iresult >0) && (testCases[i].result !=1)) ) + + { + Fail("ERROR: strncmp returned %d instead of %d\n", + iresult, testCases[i].result); + } + + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strncpy/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strncpy/test1/CMakeLists.txt index 6e0250bce3..fb737c8c59 100644 --- a/src/pal/tests/palsuite/c_runtime/strncpy/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strncpy/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strncpy_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strncpy/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strncpy/test1/test1.c deleted file mode 100644 index 62baf61ba2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strncpy/test1/test1.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Test to see that you can copy a portion of a string into a new buffer. -** Also check that the strncpy function doesn't overflow when it is used. -** Finally check that if the number of characters given is greater than the -** amount to copy, that the destination buffer is padded with NULLs. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char dest[80]; - char *result = "foobar"; - char *str = "foobar\0baz"; - char *ret; - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - for (i=0; i<80; i++) - { - dest[i] = 'x'; - } - - ret = strncpy(dest, str, 3); - if (ret != dest) - { - Fail("Expected strncpy to return %p, got %p!\n", dest, ret); - } - - if (strncmp(dest, result, 3) != 0) - { - Fail("Expected strncpy to give \"%s\", got \"%s\"!\n", result, dest); - } - - if (dest[3] != 'x') - { - Fail("strncpy overflowed!\n"); - } - - ret = strncpy(dest, str, 40); - if (ret != dest) - { - Fail("Expected strncpy to return %p, got %p!\n", dest, ret); - } - - if (strcmp(dest, result) != 0) - { - Fail("Expected strncpy to give \"%s\", got \"%s\"!\n", result, dest); - } - - for (i=strlen(str); i<40; i++) - { - if (dest[i] != 0) - { - Fail("strncpy failed to pad the destination with NULLs!\n"); - } - } - - if (dest[40] != 'x') - { - Fail("strncpy overflowed!\n"); - } - - - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strncpy/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strncpy/test1/test1.cpp new file mode 100644 index 0000000000..62baf61ba2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strncpy/test1/test1.cpp @@ -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: test1.c +** +** Purpose: +** Test to see that you can copy a portion of a string into a new buffer. +** Also check that the strncpy function doesn't overflow when it is used. +** Finally check that if the number of characters given is greater than the +** amount to copy, that the destination buffer is padded with NULLs. +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char dest[80]; + char *result = "foobar"; + char *str = "foobar\0baz"; + char *ret; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + for (i=0; i<80; i++) + { + dest[i] = 'x'; + } + + ret = strncpy(dest, str, 3); + if (ret != dest) + { + Fail("Expected strncpy to return %p, got %p!\n", dest, ret); + } + + if (strncmp(dest, result, 3) != 0) + { + Fail("Expected strncpy to give \"%s\", got \"%s\"!\n", result, dest); + } + + if (dest[3] != 'x') + { + Fail("strncpy overflowed!\n"); + } + + ret = strncpy(dest, str, 40); + if (ret != dest) + { + Fail("Expected strncpy to return %p, got %p!\n", dest, ret); + } + + if (strcmp(dest, result) != 0) + { + Fail("Expected strncpy to give \"%s\", got \"%s\"!\n", result, dest); + } + + for (i=strlen(str); i<40; i++) + { + if (dest[i] != 0) + { + Fail("strncpy failed to pad the destination with NULLs!\n"); + } + } + + if (dest[40] != 'x') + { + Fail("strncpy overflowed!\n"); + } + + + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strpbrk/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strpbrk/test1/CMakeLists.txt index eac9ac9169..9e76436e01 100644 --- a/src/pal/tests/palsuite/c_runtime/strpbrk/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strpbrk/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strpbrk_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strpbrk/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strpbrk/test1/test1.c deleted file mode 100644 index a42b80f313..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strpbrk/test1/test1.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Search a string for characters in a given character set and ensure the -** pointer returned points to the first occurance. Check to see that the -** function returns NULL if the character is not found. -** -** -**==========================================================================*/ - -#include - -struct testCase -{ - char *result; - char *string1; - char *string2; -}; - -int __cdecl main(int argc, char *argv[]) -{ - char *ptr = NULL; - int i = 0; - - /* - * this structure includes several strings to be tested with - * strpbk function and the expected results - */ - - struct testCase testCases[] = - { - {"t cream coast","corn cup cat cream coast","sit"}, - {"eam coast","corn cup cat cream coast","like"}, - {"is is a test","This is a test","circle"}, - {"a test","This is a test","way"}, - {NULL,"This is a test","boo"}, - {NULL,"This is a test","123"}, - {" is a test of the function","This is a test of the function", - "zzz xx"} - }; - - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* A loop to go through the testcases in the structure */ - - for (i=0; i< sizeof(testCases)/sizeof(struct testCase); i++) - { - ptr = strpbrk(testCases[i].string1,testCases[i].string2); - if (ptr==NULL) - { - if (testCases[i].result != NULL) - { - Fail("Expected strpbrk() to return %s, got NULL!\n", - testCases[i].result); - } - } - else - { - if (strcmp(ptr,testCases[i].result)!=0 ) - - { - Fail("Expected strpbrk() to return %s, got %s!\n", - testCases[i].result,ptr); - } - - } - - } - - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/strpbrk/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strpbrk/test1/test1.cpp new file mode 100644 index 0000000000..a42b80f313 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strpbrk/test1/test1.cpp @@ -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: test1.c +** +** Purpose: +** Search a string for characters in a given character set and ensure the +** pointer returned points to the first occurance. Check to see that the +** function returns NULL if the character is not found. +** +** +**==========================================================================*/ + +#include + +struct testCase +{ + char *result; + char *string1; + char *string2; +}; + +int __cdecl main(int argc, char *argv[]) +{ + char *ptr = NULL; + int i = 0; + + /* + * this structure includes several strings to be tested with + * strpbk function and the expected results + */ + + struct testCase testCases[] = + { + {"t cream coast","corn cup cat cream coast","sit"}, + {"eam coast","corn cup cat cream coast","like"}, + {"is is a test","This is a test","circle"}, + {"a test","This is a test","way"}, + {NULL,"This is a test","boo"}, + {NULL,"This is a test","123"}, + {" is a test of the function","This is a test of the function", + "zzz xx"} + }; + + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* A loop to go through the testcases in the structure */ + + for (i=0; i< sizeof(testCases)/sizeof(struct testCase); i++) + { + ptr = strpbrk(testCases[i].string1,testCases[i].string2); + if (ptr==NULL) + { + if (testCases[i].result != NULL) + { + Fail("Expected strpbrk() to return %s, got NULL!\n", + testCases[i].result); + } + } + else + { + if (strcmp(ptr,testCases[i].result)!=0 ) + + { + Fail("Expected strpbrk() to return %s, got %s!\n", + testCases[i].result,ptr); + } + + } + + } + + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/strrchr/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strrchr/test1/CMakeLists.txt index 5c099b0cd2..bb6916038d 100644 --- a/src/pal/tests/palsuite/c_runtime/strrchr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strrchr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strrchr_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strrchr/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strrchr/test1/test1.c deleted file mode 100644 index a5c147eece..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strrchr/test1/test1.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test1.c -** -** Purpose: \ -** Search a string for a given character. Search for a character contained -** in the string, and ensure the pointer returned points to it. Then search -** for the null character, and ensure the pointer points to that. Finally -** search for a character which is not in the string and ensure that it -** returns NULL. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char *str = "foo bar baz"; - char *ptr; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - ptr = strrchr(str, 'b'); - if (ptr != str + 8) - { - Fail("Expected strrchr() to return %p, got %p!\n", str + 8, ptr); - } - - ptr = strrchr(str, 0); - if (ptr != str + 11) - { - Fail("Expected strrchr() to return %p, got %p!\n", str + 11, ptr); - } - - ptr = strrchr(str, 'x'); - if (ptr != NULL) - { - Fail("Expected strrchr() to return NULL, got %p!\n", ptr); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strrchr/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strrchr/test1/test1.cpp new file mode 100644 index 0000000000..a5c147eece --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strrchr/test1/test1.cpp @@ -0,0 +1,55 @@ +// 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: test1.c +** +** Purpose: \ +** Search a string for a given character. Search for a character contained +** in the string, and ensure the pointer returned points to it. Then search +** for the null character, and ensure the pointer points to that. Finally +** search for a character which is not in the string and ensure that it +** returns NULL. +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char *str = "foo bar baz"; + char *ptr; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + ptr = strrchr(str, 'b'); + if (ptr != str + 8) + { + Fail("Expected strrchr() to return %p, got %p!\n", str + 8, ptr); + } + + ptr = strrchr(str, 0); + if (ptr != str + 11) + { + Fail("Expected strrchr() to return %p, got %p!\n", str + 11, ptr); + } + + ptr = strrchr(str, 'x'); + if (ptr != NULL) + { + Fail("Expected strrchr() to return NULL, got %p!\n", ptr); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strspn/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strspn/test1/CMakeLists.txt index 45caaf1bf8..c72fd0fa9a 100644 --- a/src/pal/tests/palsuite/c_runtime/strspn/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strspn/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strspn_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strspn/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strspn/test1/test1.c deleted file mode 100644 index 78d2488438..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strspn/test1/test1.c +++ /dev/null @@ -1,60 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Check a character set against a string to see that the function returns -** the length of the substring which consists of all characters in the string. -** Also check that if the character set doesn't match the string at all, that -** the value is 0. -** -** -**==========================================================================*/ - -#include - -struct testCase -{ - long result; - char *string1; - char *string2; -}; - -int __cdecl main(int argc, char *argv[]) -{ - int i=0; - long TheResult = 0; - - struct testCase testCases[]= - { - {4,"abcdefg12345678hijklmnopqrst","a2bjk341cd"}, - {14,"This is a test, testing", "aeioTts rh"}, - {0,"foobar","kpzt"} - }; - - /* - * Initialize the PAL - */ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i + +struct testCase +{ + long result; + char *string1; + char *string2; +}; + +int __cdecl main(int argc, char *argv[]) +{ + int i=0; + long TheResult = 0; + + struct testCase testCases[]= + { + {4,"abcdefg12345678hijklmnopqrst","a2bjk341cd"}, + {14,"This is a test, testing", "aeioTts rh"}, + {0,"foobar","kpzt"} + }; + + /* + * Initialize the PAL + */ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i - - -struct testCase -{ - char *result; - char *string1; - char *string2; - -}; - -int __cdecl main(int argc, char *argv[]) -{ - int i=0; - char *ptr=NULL; - - struct testCase testCases[]= - { - {"is is a test", "This is a test","is"}, - {"fghijkl","abcdefghijkl","fgh"}, - {NULL,"aabbccddeeffgg","h"}, - {NULL,"aabb", "eeeeeee"}, - {"AAA", "BBddfdaaaaAAA","A"}, - {"fdaaaaAAA", "BBddfdaaaaAAA","f"}, - {"aadfsadfas","aadfsadfas",""}, - {NULL,"","ccc"} - }; - - /* - * Initialize the PAL - */ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i + + +struct testCase +{ + char *result; + char *string1; + char *string2; + +}; + +int __cdecl main(int argc, char *argv[]) +{ + int i=0; + char *ptr=NULL; + + struct testCase testCases[]= + { + {"is is a test", "This is a test","is"}, + {"fghijkl","abcdefghijkl","fgh"}, + {NULL,"aabbccddeeffgg","h"}, + {NULL,"aabb", "eeeeeee"}, + {"AAA", "BBddfdaaaaAAA","A"}, + {"fdaaaaAAA", "BBddfdaaaaAAA","f"}, + {"aadfsadfas","aadfsadfas",""}, + {NULL,"","ccc"} + }; + + /* + * Initialize the PAL + */ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i - - -struct testCase -{ - double CorrectResult; /* The returned double value */ - char ResultString[20]; /* The remainder string */ - char string[20]; /* The test string */ -}; - - -int __cdecl main(int argc, char **argv) -{ - - char * endptr; - double result; - int i; - - struct testCase testCases[] = - { - {1234,"","1234"}, - {-1234,"","-1234"}, - {1234.44,"","1234.44"}, - {1234e-5,"","1234e-5"}, - {1234e+5,"","1234e+5"}, - {12345E5,"","12345e5"}, - {1234.657e-8,"","1234.657e-8"}, - {1234567e-8,"foo","1234567e-8foo"}, - {999,"foo","999 foo"}, - {7,"foo"," 7foo"}, - {0,"a7","a7"}, - {-777777,"z zz","-777777z zz"} - }; - - /* - * Initialize the PAL - */ - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Loop through the structure to test each case */ - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - result = strtod(testCases[i].string,&endptr); - - /* need to check the result and the endptr result */ - if ((testCases[i].CorrectResult != result) && - (strcmp(testCases[i].ResultString,endptr)!=0)) - { - Fail("ERROR: strtod returned %f instead of %f and " - "\"%s\" instead of \"%s\" for the test of \"%s\"\n", - result, - testCases[i].CorrectResult, - endptr, - testCases[i].ResultString, - testCases[i].string); - } - - } - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/strtod/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strtod/test1/test1.cpp new file mode 100644 index 0000000000..e312d98f58 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strtod/test1/test1.cpp @@ -0,0 +1,93 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the strtod function. +** Convert a number of strings to doubles. Ensure they +** convert correctly. +** +** +**===================================================================*/ + +#include + + +struct testCase +{ + double CorrectResult; /* The returned double value */ + char ResultString[20]; /* The remainder string */ + char string[20]; /* The test string */ +}; + + +int __cdecl main(int argc, char **argv) +{ + + char * endptr; + double result; + int i; + + struct testCase testCases[] = + { + {1234,"","1234"}, + {-1234,"","-1234"}, + {1234.44,"","1234.44"}, + {1234e-5,"","1234e-5"}, + {1234e+5,"","1234e+5"}, + {12345E5,"","12345e5"}, + {1234.657e-8,"","1234.657e-8"}, + {1234567e-8,"foo","1234567e-8foo"}, + {999,"foo","999 foo"}, + {7,"foo"," 7foo"}, + {0,"a7","a7"}, + {-777777,"z zz","-777777z zz"} + }; + + /* + * Initialize the PAL + */ + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Loop through the structure to test each case */ + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + result = strtod(testCases[i].string,&endptr); + + /* need to check the result and the endptr result */ + if ((testCases[i].CorrectResult != result) && + (strcmp(testCases[i].ResultString,endptr)!=0)) + { + Fail("ERROR: strtod returned %f instead of %f and " + "\"%s\" instead of \"%s\" for the test of \"%s\"\n", + result, + testCases[i].CorrectResult, + endptr, + testCases[i].ResultString, + testCases[i].string); + } + + } + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/strtod/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strtod/test2/CMakeLists.txt index 6f407c5914..8729cc5a1c 100644 --- a/src/pal/tests/palsuite/c_runtime/strtod/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strtod/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_strtod_test2 diff --git a/src/pal/tests/palsuite/c_runtime/strtod/test2/test2.c b/src/pal/tests/palsuite/c_runtime/strtod/test2/test2.c deleted file mode 100644 index 0eaf4f53b6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strtod/test2/test2.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests strtod with overflows -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - /* Representation of positive infinty for a IEEE 64-bit double */ - INT64 PosInifity = (INT64)(0x7ff00000) << 32; - double HugeVal = *(double*) &PosInifity; - char *PosStr = "1E+10000"; - char *NegStr = "-1E+10000"; - double result; - - - if (PAL_Initialize(argc,argv)) - { - return FAIL; - } - - result = strtod(PosStr, NULL); - - if (result != HugeVal) - { - Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", - PosStr, result, HugeVal); - } - - result = strtod(NegStr, NULL); - - if (result != -HugeVal) - { - Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", - NegStr, result, -HugeVal); - } - - PAL_Terminate(); - - return PASS; -} - - - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/strtod/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/strtod/test2/test2.cpp new file mode 100644 index 0000000000..0eaf4f53b6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strtod/test2/test2.cpp @@ -0,0 +1,65 @@ +// 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: test2.c +** +** Purpose: Tests strtod with overflows +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + /* Representation of positive infinty for a IEEE 64-bit double */ + INT64 PosInifity = (INT64)(0x7ff00000) << 32; + double HugeVal = *(double*) &PosInifity; + char *PosStr = "1E+10000"; + char *NegStr = "-1E+10000"; + double result; + + + if (PAL_Initialize(argc,argv)) + { + return FAIL; + } + + result = strtod(PosStr, NULL); + + if (result != HugeVal) + { + Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", + PosStr, result, HugeVal); + } + + result = strtod(NegStr, NULL); + + if (result != -HugeVal) + { + Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", + NegStr, result, -HugeVal); + } + + PAL_Terminate(); + + return PASS; +} + + + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/strtok/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strtok/test1/CMakeLists.txt index 1d5fc04cca..422c4e96b5 100644 --- a/src/pal/tests/palsuite/c_runtime/strtok/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strtok/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strtok_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strtok/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strtok/test1/test1.c deleted file mode 100644 index f1dec70380..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strtok/test1/test1.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Search for a number of tokens within strings. Check that the return values -** are what is expect, and also that the strings match up with our expected -** results. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char str[] = "foo bar baz"; - char *result1= "foo \0ar baz"; - char *result2= "foo \0a\0 baz"; - int len = strlen(str) + 1; - char *ptr; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - ptr = strtok(str, "bz"); - if (ptr != str) - { - Fail("Expected strtok() to return %p, got %p!\n", str, ptr); - } - if (memcmp(str, result1, len) != 0) - { - Fail("strtok altered the string in an unexpeced way!\n"); - } - - ptr = strtok(NULL, "r "); - if (ptr != str + 5) - { - Fail("Expected strtok() to return %p, got %p!\n", str+5, ptr); - } - if (memcmp(str, result2, len) != 0) - { - Fail("strtok altered the string in an unexpeced way!\n"); - } - - - ptr = strtok(NULL, "X"); - if (ptr != str + 7) - { - Fail("Expected strtok() to return %p, got %p!\n", str + 7, ptr); - } - if (memcmp(str, result2, len) != 0) - { - Fail("strtok altered the string in an unexpeced way!\n"); - } - - ptr = strtok(NULL, "X"); - if (ptr != NULL) - { - Fail("Expected strtok() to return %p, got %p!\n", NULL, ptr); - } - if (memcmp(str, result2, len) != 0) - { - Fail("strtok altered the string in an unexpeced way!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/strtok/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/strtok/test1/test1.cpp new file mode 100644 index 0000000000..f1dec70380 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/strtok/test1/test1.cpp @@ -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: test1.c +** +** Purpose: +** Search for a number of tokens within strings. Check that the return values +** are what is expect, and also that the strings match up with our expected +** results. +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char str[] = "foo bar baz"; + char *result1= "foo \0ar baz"; + char *result2= "foo \0a\0 baz"; + int len = strlen(str) + 1; + char *ptr; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + ptr = strtok(str, "bz"); + if (ptr != str) + { + Fail("Expected strtok() to return %p, got %p!\n", str, ptr); + } + if (memcmp(str, result1, len) != 0) + { + Fail("strtok altered the string in an unexpeced way!\n"); + } + + ptr = strtok(NULL, "r "); + if (ptr != str + 5) + { + Fail("Expected strtok() to return %p, got %p!\n", str+5, ptr); + } + if (memcmp(str, result2, len) != 0) + { + Fail("strtok altered the string in an unexpeced way!\n"); + } + + + ptr = strtok(NULL, "X"); + if (ptr != str + 7) + { + Fail("Expected strtok() to return %p, got %p!\n", str + 7, ptr); + } + if (memcmp(str, result2, len) != 0) + { + Fail("strtok altered the string in an unexpeced way!\n"); + } + + ptr = strtok(NULL, "X"); + if (ptr != NULL) + { + Fail("Expected strtok() to return %p, got %p!\n", NULL, ptr); + } + if (memcmp(str, result2, len) != 0) + { + Fail("strtok altered the string in an unexpeced way!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/strtoul/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/strtoul/test1/CMakeLists.txt index 61dbd4f9a3..009e85fb11 100644 --- a/src/pal/tests/palsuite/c_runtime/strtoul/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/strtoul/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_strtoul_test1 diff --git a/src/pal/tests/palsuite/c_runtime/strtoul/test1/test1.c b/src/pal/tests/palsuite/c_runtime/strtoul/test1/test1.c deleted file mode 100644 index 344671b5cc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/strtoul/test1/test1.c +++ /dev/null @@ -1,73 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Tests stroul with different bases and overflows, as well as valid input. -** Makes sure that the end pointer is correct. -** -** -**==========================================================================*/ - -#include - -char teststr1[] = "12345"; -char teststr2[] = "Z"; -char teststr3[] = "4294967295"; -char teststr4[] = "4294967296"; - -typedef struct -{ - char *str; - char *end; - int base; - ULONG result; -} TestCase; - -TestCase TestCases[] = -{ - { teststr1, teststr1 + 3, 4, 27}, - { teststr1, teststr1 + 5, 10, 12345}, - { teststr2, teststr2, 10, 0}, - { teststr3, teststr3+10, 10, 4294967295ul}, - { teststr4, teststr4+10, 10, 4294967295ul} -}; - -int NumCases = sizeof(TestCases) / sizeof(TestCases[0]); - - -int __cdecl main(int argc, char *argv[]) -{ - char *end; - ULONG l; - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - for (i=0; i + +char teststr1[] = "12345"; +char teststr2[] = "Z"; +char teststr3[] = "4294967295"; +char teststr4[] = "4294967296"; + +typedef struct +{ + char *str; + char *end; + int base; + ULONG result; +} TestCase; + +TestCase TestCases[] = +{ + { teststr1, teststr1 + 3, 4, 27}, + { teststr1, teststr1 + 5, 10, 12345}, + { teststr2, teststr2, 10, 0}, + { teststr3, teststr3+10, 10, 4294967295ul}, + { teststr4, teststr4+10, 10, 4294967295ul} +}; + +int NumCases = sizeof(TestCases) / sizeof(TestCases[0]); + + +int __cdecl main(int argc, char *argv[]) +{ + char *end; + ULONG l; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + for (i=0; i -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -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; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test1/test1.cpp new file mode 100644 index 0000000000..626040d9f7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test1/test1.cpp @@ -0,0 +1,44 @@ +// 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: test1.c +** +** Purpose: General test to see if swprintf works correctly +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +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; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test10/CMakeLists.txt index 302c5e5923..222108393b 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_swprintf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/swprintf/test10/test10.c deleted file mode 100644 index 61aef593a0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test10/test10.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test10.c -** -** Purpose:Tests swprintf with octal numbers -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %o"), pos, convert("foo 52")); - DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); - DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); - DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); - DoI64Test(convert("foo %I64o"), l, "0x0000000000000042", - convert("foo 52")); - DoNumTest(convert("foo %3o"), pos, convert("foo 52")); - DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); - DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); - DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); - DoNumTest(convert("foo %03o"), pos, convert("foo 052")); - DoNumTest(convert("foo %#o"), pos, convert("foo 052")); - DoNumTest(convert("foo %+o"), pos, convert("foo 52")); - DoNumTest(convert("foo % o"), pos, convert("foo 52")); - DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); - DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test10/test10.cpp new file mode 100644 index 0000000000..61aef593a0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test10/test10.cpp @@ -0,0 +1,55 @@ +// 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: test10.c +** +** Purpose:Tests swprintf with octal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %o"), pos, convert("foo 52")); + DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); + DoI64Test(convert("foo %I64o"), l, "0x0000000000000042", + convert("foo 52")); + DoNumTest(convert("foo %3o"), pos, convert("foo 52")); + DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); + DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); + DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); + DoNumTest(convert("foo %03o"), pos, convert("foo 052")); + DoNumTest(convert("foo %#o"), pos, convert("foo 052")); + DoNumTest(convert("foo %+o"), pos, convert("foo 52")); + DoNumTest(convert("foo % o"), pos, convert("foo 52")); + DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); + DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test11/CMakeLists.txt index 484d57ef58..96222a5b2a 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_swprintf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/swprintf/test11/test11.c deleted file mode 100644 index 216f9acdbb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test11/test11.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test11.c -** -** Purpose: Tests swprintf with unsigned numbers -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %u"), pos, convert("foo 42")); - DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); - DoI64Test(convert("foo %I64u"), l, "0x0000000000000042", - convert("foo 42")); - DoNumTest(convert("foo %3u"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); - DoNumTest(convert("foo %03u"), pos, convert("foo 042")); - DoNumTest(convert("foo %#u"), pos, convert("foo 42")); - DoNumTest(convert("foo %+u"), pos, convert("foo 42")); - DoNumTest(convert("foo % u"), pos, convert("foo 42")); - DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); - DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test11/test11.cpp new file mode 100644 index 0000000000..216f9acdbb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test11/test11.cpp @@ -0,0 +1,55 @@ +// 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: test11.c +** +** Purpose: Tests swprintf with unsigned numbers +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %u"), pos, convert("foo 42")); + DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); + DoI64Test(convert("foo %I64u"), l, "0x0000000000000042", + convert("foo 42")); + DoNumTest(convert("foo %3u"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); + DoNumTest(convert("foo %03u"), pos, convert("foo 042")); + DoNumTest(convert("foo %#u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), pos, convert("foo 42")); + DoNumTest(convert("foo % u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); + DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test12/CMakeLists.txt index 6d45ee4646..1ffe620fed 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_swprintf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/swprintf/test12/test12.c deleted file mode 100644 index a41b0ddbd3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test12/test12.c +++ /dev/null @@ -1,56 +0,0 @@ -// 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: test12.c -** -** Purpose: Tests swprintf with hex numbers (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); - DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); - DoI64Test(convert("foo %I64x"), l, "0x1234567887654321", - convert("foo 1234567887654321")); - DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); - DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); - DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); - DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); - DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); - DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test12/test12.cpp new file mode 100644 index 0000000000..a41b0ddbd3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test12/test12.cpp @@ -0,0 +1,56 @@ +// 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: test12.c +** +** Purpose: Tests swprintf with hex numbers (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); + DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); + DoI64Test(convert("foo %I64x"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); + DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); + DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); + DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test13/CMakeLists.txt index 20f6f0df7b..8699589ec9 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_swprintf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/swprintf/test13/test13.c deleted file mode 100644 index b99232f7ea..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test13/test13.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test13.c -** -** Purpose: Tests swprintf with hex numbers (uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); - DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); - DoI64Test(convert("foo %I64X"), l, "0X1234567887654321", - convert("foo 1234567887654321")); - DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); - DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); - DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); - DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); - DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); - DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test13/test13.cpp new file mode 100644 index 0000000000..b99232f7ea --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test13/test13.cpp @@ -0,0 +1,55 @@ +// 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: test13.c +** +** Purpose: Tests swprintf with hex numbers (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); + DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); + DoI64Test(convert("foo %I64X"), l, "0X1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); + DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); + DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); + DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test14/CMakeLists.txt index a052f60116..2a4b84805c 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_swprintf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/swprintf/test14/test14.c deleted file mode 100644 index bcfd6a7c24..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test14/test14.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: test14.c -** -** Purpose: Tests swprintf with exponential format doubles (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), - convert("foo 2.560000e+02 ")); - DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), - convert("foo 2.6e+02")); - DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), - convert("foo 2.56000000e+02")); - DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), - convert("foo 002.560000e+02")); - DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), - convert("foo +2.560000e+02")); - DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), - convert("foo -2.560000e+02")); - DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), - convert("foo -2.560000e+02")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test14/test14.cpp new file mode 100644 index 0000000000..bcfd6a7c24 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test14/test14.cpp @@ -0,0 +1,67 @@ +// 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: test14.c +** +** Purpose: Tests swprintf with exponential format doubles (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), + convert("foo 2.560000e+02 ")); + DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), + convert("foo 2.6e+02")); + DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), + convert("foo 2.56000000e+02")); + DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), + convert("foo 002.560000e+02")); + DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), + convert("foo +2.560000e+02")); + DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test15/CMakeLists.txt index 7bc2da122f..22382bce5f 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_swprintf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/swprintf/test15/test15.c deleted file mode 100644 index 215afbe093..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test15/test15.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: test15.c -** -** Purpose:Tests swprintf with exponential format doubles (uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), - convert("foo 2.560000E+02 ")); - DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), - convert("foo 2.6E+02")); - DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), - convert("foo 2.56000000E+02")); - DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), - convert("foo 002.560000E+02")); - DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), - convert("foo +2.560000E+02")); - DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), - convert("foo -2.560000E+02")); - DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), - convert("foo -2.560000E+02")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test15/test15.cpp new file mode 100644 index 0000000000..215afbe093 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test15/test15.cpp @@ -0,0 +1,67 @@ +// 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: test15.c +** +** Purpose:Tests swprintf with exponential format doubles (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), + convert("foo 2.560000E+02 ")); + DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), + convert("foo 2.6E+02")); + DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), + convert("foo 2.56000000E+02")); + DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), + convert("foo 002.560000E+02")); + DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), + convert("foo +2.560000E+02")); + DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test16/CMakeLists.txt index e6ad3abd3f..462f0806cd 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_swprintf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/swprintf/test16/test16.c deleted file mode 100644 index 859afed8dd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test16/test16.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: test16.c -** -** Purpose:Tests swprintf with decimal point format doubles -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), - convert("foo 2560.001000 ")); - DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), - convert("foo 2560.0")); - DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), - convert("foo 2560.00100000")); - DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), - convert("foo 02560.001000")); - DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), - convert("foo +2560.001000")); - DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), - convert("foo -2560.001000")); - DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), - convert("foo -2560.001000")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test16/test16.cpp new file mode 100644 index 0000000000..859afed8dd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test16/test16.cpp @@ -0,0 +1,67 @@ +// 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: test16.c +** +** Purpose:Tests swprintf with decimal point format doubles +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), + convert("foo 2560.001000 ")); + DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), + convert("foo 2560.0")); + DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), + convert("foo 2560.00100000")); + DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), + convert("foo 02560.001000")); + DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), + convert("foo +2560.001000")); + DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test17/CMakeLists.txt index 401285b740..c5b4d44593 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_swprintf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/swprintf/test17/test17.c deleted file mode 100644 index 480f2b2fe1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test17/test17.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test17.c -** -** Purpose:Tests swprintf with compact format doubles (lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), - convert("foo 2560 ")); - DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), - convert("foo 3e+03")); - DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), - convert("foo 2.6e+03")); - DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), - convert("foo 2560.001")); - DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), - convert("foo 002560")); - DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), - convert("foo 2560.00")); - DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), - convert("foo +2560")); - DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), - convert("foo -2560")); - DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), - convert("foo -2560")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test17/test17.cpp new file mode 100644 index 0000000000..480f2b2fe1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test17/test17.cpp @@ -0,0 +1,69 @@ +// 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: test17.c +** +** Purpose:Tests swprintf with compact format doubles (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), + convert("foo 3e+03")); + DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), + convert("foo 2.6e+03")); + DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test18/CMakeLists.txt index 210ab2c7ec..6cdf576966 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test18.c + test18.cpp ) add_executable(paltest_swprintf_test18 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/swprintf/test18/test18.c deleted file mode 100644 index 1ed8cd00d8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test18/test18.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test18.c -** -** Purpose: Tests swprintf with compact format doubles (uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), - convert("foo 2560 ")); - DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), - convert("foo 3E+03")); - DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), - convert("foo 2.6E+03")); - DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), - convert("foo 2560.001")); - DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), - convert("foo 002560")); - DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), - convert("foo 2560.00")); - DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), - convert("foo +2560")); - DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), - convert("foo -2560")); - DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), - convert("foo -2560")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test18/test18.cpp new file mode 100644 index 0000000000..1ed8cd00d8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test18/test18.cpp @@ -0,0 +1,69 @@ +// 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: test18.c +** +** Purpose: Tests swprintf with compact format doubles (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), + convert("foo 3E+03")); + DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), + convert("foo 2.6E+03")); + DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test19/CMakeLists.txt index b9d44a3031..334b7b4fa1 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test19.c + test19.cpp ) add_executable(paltest_swprintf_test19 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/swprintf/test19/test19.c deleted file mode 100644 index 5199cc3cd9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test19/test19.c +++ /dev/null @@ -1,109 +0,0 @@ -// 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: test19.c -** -** Purpose: Tests swprintf with argument specified precision -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int n = -1; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoArgumentPrecTest(convert("%.*s"), 2, convert("bar"), "bar", - convert("ba"), convert("ba")); - DoArgumentPrecTest(convert("%.*S"), 2, "bar", "bar", convert("ba"), - convert("ba")); - DoArgumentPrecTest(convert("%.*n"), 3, &n, "pointer to int", convert(""), - convert("")); - if (n != 0) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - 0, n); - } - - DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", convert("a"), - convert("a")); - DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", convert("a"), - convert("a")); - DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', "a", convert("a"), - convert("a")); - DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', "a", convert("a"), - convert("a")); - DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, "42", convert("42"), - convert("42")); - DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, "42", convert("042"), - convert("042")); - DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, "42", convert("42"), - convert("42")); - DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, "42", convert("042"), - convert("042")); - DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, "42", convert("52"), - convert("52")); - DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, "42", convert("052"), - convert("052")); - DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, "42", convert("42"), - convert("42")); - DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, "42", convert("042"), - convert("042")); - DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, "0x42", convert("42"), - convert("42")); - DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, "0x42", convert("042"), - convert("042")); - DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, "0x42", convert("42"), - convert("42")); - DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, "0x42", convert("042"), - convert("042")); - - - DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000"), - convert("2.0e+000")); - DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000"), - convert("2.010e+000")); - DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000"), - convert("2.0E+000")); - DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000"), - convert("2.010E+000")); - DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0"), - convert("2.0")); - DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010"), - convert("2.010")); - DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002"), - convert("3e+002")); - DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01"), - convert("256.01")); - DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002"), - convert("3E+002")); - DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01"), - convert("256.01")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test19/test19.cpp new file mode 100644 index 0000000000..c0346036cd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test19/test19.cpp @@ -0,0 +1,109 @@ +// 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: test19.c +** +** Purpose: Tests swprintf with argument specified precision +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int n = -1; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoArgumentPrecTest(convert("%.*s"), 2, (void*)convert("bar"), "bar", + convert("ba"), convert("ba")); + DoArgumentPrecTest(convert("%.*S"), 2, (void*)"bar", "bar", convert("ba"), + convert("ba")); + DoArgumentPrecTest(convert("%.*n"), 3, (void*)&n, "pointer to int", convert(""), + convert("")); + if (n != 0) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + 0, n); + } + + DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", convert("a"), + convert("a")); + DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", convert("a"), + convert("a")); + DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', "a", convert("a"), + convert("a")); + DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', "a", convert("a"), + convert("a")); + DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, "42", convert("42"), + convert("42")); + DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, "42", convert("042"), + convert("042")); + DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, "42", convert("42"), + convert("42")); + DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, "42", convert("042"), + convert("042")); + DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, "42", convert("52"), + convert("52")); + DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, "42", convert("052"), + convert("052")); + DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, "42", convert("42"), + convert("42")); + DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, "42", convert("042"), + convert("042")); + DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, "0x42", convert("42"), + convert("42")); + DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, "0x42", convert("042"), + convert("042")); + DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, "0x42", convert("42"), + convert("42")); + DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, "0x42", convert("042"), + convert("042")); + + + DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000"), + convert("2.0e+000")); + DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000"), + convert("2.010e+000")); + DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000"), + convert("2.0E+000")); + DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000"), + convert("2.010E+000")); + DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0"), + convert("2.0")); + DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010"), + convert("2.010")); + DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002"), + convert("3e+002")); + DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01"), + convert("256.01")); + DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002"), + convert("3E+002")); + DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01"), + convert("256.01")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test2/CMakeLists.txt index 84446d5f6d..af2b13e4c7 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_swprintf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/swprintf/test2/test2.c deleted file mode 100644 index deffd3edd7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test2/test2.c +++ /dev/null @@ -1,46 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests swprintf with strings -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); - DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); - DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); - DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); - DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); - DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test2/test2.cpp new file mode 100644 index 0000000000..deffd3edd7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test2/test2.cpp @@ -0,0 +1,46 @@ +// 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: test2.c +** +** Purpose: Tests swprintf with strings +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); + DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test3/CMakeLists.txt index 6dbd8a3c36..14b81f4ac8 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_swprintf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/swprintf/test3/test3.c deleted file mode 100644 index 42875c0640..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test3/test3.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests swprintf with wide strings -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - DoStrTest(convert("foo %S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); - DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); - DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); - DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); - DoStrTest(convert("foo %5.2S"),"bar", convert("foo ba")); - DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); - DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test3/test3.cpp new file mode 100644 index 0000000000..42875c0640 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test3/test3.cpp @@ -0,0 +1,43 @@ +// 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: test3.c +** +** Purpose: Tests swprintf with wide strings +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoStrTest(convert("foo %S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); + DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %5.2S"),"bar", convert("foo ba")); + DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); + DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test4/CMakeLists.txt index a665948c47..e153e6b02f 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_swprintf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/swprintf/test4/test4.c deleted file mode 100644 index 02cc3f9005..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test4/test4.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests swprintf with pointers -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, convert("0000000000000000")); - DoPointerTest(convert("%p"), ptr, convert("0000000000123456")); - DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); - DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); - DoPointerTest(convert("%-17p"), ptr, convert("0000000000123456 ")); - DoPointerTest(convert("%+p"), ptr, convert("0000000000123456")); - DoPointerTest(convert("% p"), ptr, convert("0000000000123456")); - DoPointerTest(convert("%#p"), ptr, convert("0X0000000000123456")); - DoPointerTest(convert("%lp"), ptr, convert("00123456")); - DoPointerTest(convert("%hp"), ptr, convert("00003456")); - DoPointerTest(convert("%Lp"), ptr, convert("00123456")); - DoI64Test(convert("%I64p"), lptr, "pointer to 0X1234567887654321", - convert("1234567887654321")); -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, convert("00000000")); - DoPointerTest(convert("%p"), ptr, convert("00123456")); - DoPointerTest(convert("%9p"), ptr, convert(" 00123456")); - DoPointerTest(convert("%09p"), ptr, convert(" 00123456")); - DoPointerTest(convert("%-9p"), ptr, convert("00123456 ")); - DoPointerTest(convert("%+p"), ptr, convert("00123456")); - DoPointerTest(convert("% p"), ptr, convert("00123456")); - DoPointerTest(convert("%#p"), ptr, convert("0X00123456")); - DoPointerTest(convert("%lp"), ptr, convert("00123456")); - DoPointerTest(convert("%hp"), ptr, convert("00003456")); - DoPointerTest(convert("%Lp"), ptr, convert("00123456")); - DoI64Test(convert("%I64p"), lptr, "pointer to 0X1234567887654321", - convert("1234567887654321")); -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test4/test4.cpp new file mode 100644 index 0000000000..02cc3f9005 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test4/test4.cpp @@ -0,0 +1,71 @@ +// 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: test4.c +** +** Purpose: Tests swprintf with pointers +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("0000000000000000")); + DoPointerTest(convert("%p"), ptr, convert("0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); + DoPointerTest(convert("%-17p"), ptr, convert("0000000000123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("0000000000123456")); + DoPointerTest(convert("% p"), ptr, convert("0000000000123456")); + DoPointerTest(convert("%#p"), ptr, convert("0X0000000000123456")); + DoPointerTest(convert("%lp"), ptr, convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("00123456")); + DoI64Test(convert("%I64p"), lptr, "pointer to 0X1234567887654321", + convert("1234567887654321")); +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("00000000")); + DoPointerTest(convert("%p"), ptr, convert("00123456")); + DoPointerTest(convert("%9p"), ptr, convert(" 00123456")); + DoPointerTest(convert("%09p"), ptr, convert(" 00123456")); + DoPointerTest(convert("%-9p"), ptr, convert("00123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("00123456")); + DoPointerTest(convert("% p"), ptr, convert("00123456")); + DoPointerTest(convert("%#p"), ptr, convert("0X00123456")); + DoPointerTest(convert("%lp"), ptr, convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("00123456")); + DoI64Test(convert("%I64p"), lptr, "pointer to 0X1234567887654321", + convert("1234567887654321")); +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test5/CMakeLists.txt index 8268ec2963..967ccbb992 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_swprintf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/swprintf/test5/test5.c deleted file mode 100644 index e85adc120e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test5/test5.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: test5.c -** -** Purpose:Tests swprintf with the count specifier -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR *longStr; - WCHAR *longResult; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - longStr = - convert("really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - "%n bar"); - longResult = - convert("really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - " bar"); - - DoCountTest(convert("foo %n bar"), 4, convert("foo bar")); - DoCountTest(longStr, 257, longResult); - DoCountTest(convert("fo%n bar"), 2, convert("fo bar")); - DoCountTest(convert("%n"), 0, convert("")); - DoCountTest(convert("foo %#n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo % n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %+n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %-n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %0n bar"), 4, convert("foo bar")); - DoShortCountTest(convert("foo %hn bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %ln bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %Ln bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %I64n bar"), 4, convert("foo bar")); - DoCountTest(convert("foo %20.3n bar"), 4, convert("foo bar")); - - PAL_Terminate(); - - free(longStr); - free(longResult); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test5/test5.cpp new file mode 100644 index 0000000000..e85adc120e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test5/test5.cpp @@ -0,0 +1,67 @@ +// 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: test5.c +** +** Purpose:Tests swprintf with the count specifier +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR *longStr; + WCHAR *longResult; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + longStr = + convert("really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + "%n bar"); + longResult = + convert("really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + " bar"); + + DoCountTest(convert("foo %n bar"), 4, convert("foo bar")); + DoCountTest(longStr, 257, longResult); + DoCountTest(convert("fo%n bar"), 2, convert("fo bar")); + DoCountTest(convert("%n"), 0, convert("")); + DoCountTest(convert("foo %#n bar"), 4, convert("foo bar")); + DoCountTest(convert("foo % n bar"), 4, convert("foo bar")); + DoCountTest(convert("foo %+n bar"), 4, convert("foo bar")); + DoCountTest(convert("foo %-n bar"), 4, convert("foo bar")); + DoCountTest(convert("foo %0n bar"), 4, convert("foo bar")); + DoShortCountTest(convert("foo %hn bar"), 4, convert("foo bar")); + DoCountTest(convert("foo %ln bar"), 4, convert("foo bar")); + DoCountTest(convert("foo %Ln bar"), 4, convert("foo bar")); + DoCountTest(convert("foo %I64n bar"), 4, convert("foo bar")); + DoCountTest(convert("foo %20.3n bar"), 4, convert("foo bar")); + + PAL_Terminate(); + + free(longStr); + free(longResult); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test6/CMakeLists.txt index 6a90c0b88e..806211a992 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_swprintf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/swprintf/test6/test6.c deleted file mode 100644 index ecd6374264..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test6/test6.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test6.c -** -** Purpose: Tests swprintf with character -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoWCharTest(convert("foo %c"), wb, convert("foo b")); - DoCharTest(convert("foo %hc"), 'c', convert("foo c")); - DoWCharTest(convert("foo %lc"), wb, convert("foo b")); - DoWCharTest(convert("foo %Lc"), wb, convert("foo b")); - DoWCharTest(convert("foo %I64c"), wb, convert("foo b")); - DoWCharTest(convert("foo %5c"), wb, convert("foo b")); - DoWCharTest(convert("foo %.0c"), wb, convert("foo b")); - DoWCharTest(convert("foo %-5c"), wb, convert("foo b ")); - DoWCharTest(convert("foo %05c"), wb, convert("foo 0000b")); - DoWCharTest(convert("foo % c"), wb, convert("foo b")); - DoWCharTest(convert("foo %#c"), wb, convert("foo b")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test6/test6.cpp new file mode 100644 index 0000000000..ecd6374264 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test6/test6.cpp @@ -0,0 +1,47 @@ +// 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: test6.c +** +** Purpose: Tests swprintf with character +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoWCharTest(convert("foo %c"), wb, convert("foo b")); + DoCharTest(convert("foo %hc"), 'c', convert("foo c")); + DoWCharTest(convert("foo %lc"), wb, convert("foo b")); + DoWCharTest(convert("foo %Lc"), wb, convert("foo b")); + DoWCharTest(convert("foo %I64c"), wb, convert("foo b")); + DoWCharTest(convert("foo %5c"), wb, convert("foo b")); + DoWCharTest(convert("foo %.0c"), wb, convert("foo b")); + DoWCharTest(convert("foo %-5c"), wb, convert("foo b ")); + DoWCharTest(convert("foo %05c"), wb, convert("foo 0000b")); + DoWCharTest(convert("foo % c"), wb, convert("foo b")); + DoWCharTest(convert("foo %#c"), wb, convert("foo b")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test7/CMakeLists.txt index 2b1c30cb56..cf563799d9 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_swprintf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/swprintf/test7/test7.c deleted file mode 100644 index e231ada3d2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test7/test7.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test7.c -** -** Purpose: Tests swprintf with wide characters -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoCharTest(convert("foo %C"), 'c', convert("foo c")); - DoWCharTest(convert("foo %hc"), wb, convert("foo b")); - DoCharTest(convert("foo %lC"), 'c', convert("foo c")); - DoCharTest(convert("foo %LC"), 'c', convert("foo c")); - DoCharTest(convert("foo %I64C"), 'c', convert("foo c")); - DoCharTest(convert("foo %5C"), 'c', convert("foo c")); - DoCharTest(convert("foo %.0C"), 'c', convert("foo c")); - DoCharTest(convert("foo %-5C"), 'c', convert("foo c ")); - DoCharTest(convert("foo %05C"), 'c', convert("foo 0000c")); - DoCharTest(convert("foo % C"), 'c', convert("foo c")); - DoCharTest(convert("foo %#C"), 'c', convert("foo c")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test7/test7.cpp new file mode 100644 index 0000000000..e231ada3d2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test7/test7.cpp @@ -0,0 +1,48 @@ +// 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: test7.c +** +** Purpose: Tests swprintf with wide characters +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoCharTest(convert("foo %C"), 'c', convert("foo c")); + DoWCharTest(convert("foo %hc"), wb, convert("foo b")); + DoCharTest(convert("foo %lC"), 'c', convert("foo c")); + DoCharTest(convert("foo %LC"), 'c', convert("foo c")); + DoCharTest(convert("foo %I64C"), 'c', convert("foo c")); + DoCharTest(convert("foo %5C"), 'c', convert("foo c")); + DoCharTest(convert("foo %.0C"), 'c', convert("foo c")); + DoCharTest(convert("foo %-5C"), 'c', convert("foo c ")); + DoCharTest(convert("foo %05C"), 'c', convert("foo 0000c")); + DoCharTest(convert("foo % C"), 'c', convert("foo c")); + DoCharTest(convert("foo %#C"), 'c', convert("foo c")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test8/CMakeLists.txt index 281e6df097..e8fcf66157 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_swprintf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/swprintf/test8/test8.c deleted file mode 100644 index b4be28e78d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test8/test8.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test8.c -** -** Purpose: Tests swprintf with decimal numbers -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %d"), pos, convert("foo 42")); - DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); - DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); - DoI64Test(convert("foo %I64d"), l, "0x0000000000000042", - convert("foo 42")); - DoNumTest(convert("foo %3d"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); - DoNumTest(convert("foo %03d"), pos, convert("foo 042")); - DoNumTest(convert("foo %#d"), pos, convert("foo 42")); - DoNumTest(convert("foo %+d"), pos, convert("foo +42")); - DoNumTest(convert("foo % d"), pos, convert("foo 42")); - DoNumTest(convert("foo %+d"), neg, convert("foo -42")); - DoNumTest(convert("foo % d"), neg, convert("foo -42")); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test8/test8.cpp new file mode 100644 index 0000000000..b4be28e78d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test8/test8.cpp @@ -0,0 +1,55 @@ +// 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: test8.c +** +** Purpose: Tests swprintf with decimal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %d"), pos, convert("foo 42")); + DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); + DoI64Test(convert("foo %I64d"), l, "0x0000000000000042", + convert("foo 42")); + DoNumTest(convert("foo %3d"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); + DoNumTest(convert("foo %03d"), pos, convert("foo 042")); + DoNumTest(convert("foo %#d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), pos, convert("foo +42")); + DoNumTest(convert("foo % d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), neg, convert("foo -42")); + DoNumTest(convert("foo % d"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swprintf/test9/CMakeLists.txt index 054b40a998..c616348766 100644 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_swprintf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/swprintf/test9/test9.c deleted file mode 100644 index 2f5429e5fd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swprintf/test9/test9.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test9.c -** -** Purpose: Tests swprintf with integer numbers -** -** -**==========================================================================*/ - - - -#include -#include "../swprintf.h" - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - - DoNumTest(convert("foo %i"), pos, convert("foo 42")); - DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); - DoNumTest(convert("foo %Li"), pos, convert("foo 42")); - DoI64Test(convert("foo %I64i"), l, "0x0000000000000042", - convert("foo 42")); - DoNumTest(convert("foo %3i"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); - DoNumTest(convert("foo %03i"), pos, convert("foo 042")); - DoNumTest(convert("foo %#i"), pos, convert("foo 42")); - DoNumTest(convert("foo %+i"), pos, convert("foo +42")); - DoNumTest(convert("foo % i"), pos, convert("foo 42")); - DoNumTest(convert("foo %+i"), neg, convert("foo -42")); - DoNumTest(convert("foo % i"), neg, convert("foo -42")); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/swprintf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/swprintf/test9/test9.cpp new file mode 100644 index 0000000000..2f5429e5fd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swprintf/test9/test9.cpp @@ -0,0 +1,55 @@ +// 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: test9.c +** +** Purpose: Tests swprintf with integer numbers +** +** +**==========================================================================*/ + + + +#include +#include "../swprintf.h" + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %i"), pos, convert("foo 42")); + DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Li"), pos, convert("foo 42")); + DoI64Test(convert("foo %I64i"), l, "0x0000000000000042", + convert("foo 42")); + DoNumTest(convert("foo %3i"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); + DoNumTest(convert("foo %03i"), pos, convert("foo 042")); + DoNumTest(convert("foo %#i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), pos, convert("foo +42")); + DoNumTest(convert("foo % i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), neg, convert("foo -42")); + DoNumTest(convert("foo % i"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/swscanf.h b/src/pal/tests/palsuite/c_runtime/swscanf/swscanf.h index 1cac450cf4..6349b7dcd6 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/swscanf.h +++ b/src/pal/tests/palsuite/c_runtime/swscanf/swscanf.h @@ -14,7 +14,7 @@ #ifndef __SWSCANF_H__ #define __SWSCANF_H__ -void DoVoidTest(WCHAR *inputstr, WCHAR *formatstr) +void DoVoidTest(WCHAR *inputstr, const WCHAR *formatstr) { char buf[256] = { 0 }; int i; @@ -40,7 +40,7 @@ void DoVoidTest(WCHAR *inputstr, WCHAR *formatstr) } -void DoStrTest(WCHAR *inputstr, WCHAR *formatstr, char *checkstr) +void DoStrTest(WCHAR *inputstr, const WCHAR *formatstr, const char *checkstr) { char buf[256] = { 0 }; int ret; @@ -63,7 +63,7 @@ void DoStrTest(WCHAR *inputstr, WCHAR *formatstr, char *checkstr) } -void DoWStrTest(WCHAR *inputstr, WCHAR *formatstr, WCHAR *checkstr) +void DoWStrTest(WCHAR *inputstr, const WCHAR *formatstr, const WCHAR *checkstr) { WCHAR buf[256] = { 0 }; int ret; @@ -86,7 +86,7 @@ void DoWStrTest(WCHAR *inputstr, WCHAR *formatstr, WCHAR *checkstr) } -void DoNumTest(WCHAR *inputstr, WCHAR *formatstr, int checknum) +void DoNumTest(WCHAR *inputstr, const WCHAR *formatstr, int checknum) { int num = 0; int ret; @@ -107,7 +107,7 @@ void DoNumTest(WCHAR *inputstr, WCHAR *formatstr, int checknum) } } -void DoShortNumTest(WCHAR *inputstr, WCHAR *formatstr, short checknum) +void DoShortNumTest(WCHAR *inputstr, const WCHAR *formatstr, short checknum) { short num = 0; int ret; @@ -128,7 +128,7 @@ void DoShortNumTest(WCHAR *inputstr, WCHAR *formatstr, short checknum) } } -void DoI64NumTest(WCHAR *inputstr, WCHAR *formatstr, INT64 checknum) +void DoI64NumTest(WCHAR *inputstr, const WCHAR *formatstr, INT64 checknum) { char buf[256]; char check[256]; @@ -145,15 +145,15 @@ void DoI64NumTest(WCHAR *inputstr, WCHAR *formatstr, INT64 checknum) if (checknum != num) { - sprintf(buf, "%I64d", num); - sprintf(check, "%I64d", checknum); + sprintf_s(buf, _countof(buf), "%I64d", num); + sprintf_s(check, _countof(check), "%I64d", checknum); Fail("ERROR: scanned I64 number incorrectly from \"%s\" using \"%s\".\n" "Expected %s, got %s.\n", convertC(inputstr), convertC(formatstr), check, buf); } } -void DoCharTest(WCHAR *inputstr, WCHAR*formatstr, char* checkchars, int numchars) +void DoCharTest(WCHAR *inputstr, const WCHAR *formatstr, char* checkchars, int numchars) { char buf[256]; int ret; @@ -187,7 +187,7 @@ void DoCharTest(WCHAR *inputstr, WCHAR*formatstr, char* checkchars, int numchars } } -void DoWCharTest(WCHAR *inputstr, WCHAR *formatstr, WCHAR *checkchars, int numchars) +void DoWCharTest(WCHAR *inputstr, const WCHAR *formatstr, const WCHAR *checkchars, int numchars) { WCHAR buf[256]; int ret; @@ -223,7 +223,7 @@ void DoWCharTest(WCHAR *inputstr, WCHAR *formatstr, WCHAR *checkchars, int numch } -void DoFloatTest(WCHAR *inputstr, WCHAR *formatstr, float checkval) +void DoFloatTest(WCHAR *inputstr, const WCHAR *formatstr, float checkval) { char buf[256] = { 0 }; float val; diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test1/CMakeLists.txt index 030aaaf709..44b8939248 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_swscanf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/swscanf/test1/test1.c deleted file mode 100644 index 66136e57c5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test1/test1.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test1.c -** -** Purpose: General test of swscanf -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int num; - int ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoVoidTest(convert("foo bar"), convert("foo")); - DoVoidTest(convert("foo bar"), convert("baz")); - DoVoidTest(convert("foo bar"), convert("foo %*s")); - - DoStrTest(convert("foo % bar"), convert("foo %% %S"), "bar"); - DoStrTest(convert("foo bar baz"), convert("foo %bar %S"), "baz"); - - DoVoidTest(convert("foo bar baz"), convert("foo % bar %S")); - DoVoidTest(convert("foo bar baz"), convert("foo% bar %S")); - - - ret = swscanf(convert("foo bar baz"), convert("foo bar %n"), &num); - if (ret != 0 || num != 8) - { - Fail("ERROR: Got incorrect values in scanning \"%s\" using \"%s\".\n" - "Expected to get a value of %d with return value of %d, " - "got %d with return %d\n", "foo bar baz", "foo bar %n", 8, 0, - num, ret); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test1/test1.cpp new file mode 100644 index 0000000000..66136e57c5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test1/test1.cpp @@ -0,0 +1,53 @@ +// 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: test1.c +** +** Purpose: General test of swscanf +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int num; + int ret; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoVoidTest(convert("foo bar"), convert("foo")); + DoVoidTest(convert("foo bar"), convert("baz")); + DoVoidTest(convert("foo bar"), convert("foo %*s")); + + DoStrTest(convert("foo % bar"), convert("foo %% %S"), "bar"); + DoStrTest(convert("foo bar baz"), convert("foo %bar %S"), "baz"); + + DoVoidTest(convert("foo bar baz"), convert("foo % bar %S")); + DoVoidTest(convert("foo bar baz"), convert("foo% bar %S")); + + + ret = swscanf(convert("foo bar baz"), convert("foo bar %n"), &num); + if (ret != 0 || num != 8) + { + Fail("ERROR: Got incorrect values in scanning \"%s\" using \"%s\".\n" + "Expected to get a value of %d with return value of %d, " + "got %d with return %d\n", "foo bar baz", "foo bar %n", 8, 0, + num, ret); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test10/CMakeLists.txt index f7c8b284ff..27d42114a9 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_swscanf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/swscanf/test10/test10.c deleted file mode 100644 index a8628e0de1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test10/test10.c +++ /dev/null @@ -1,36 +0,0 @@ -// 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: test10.c -** -** Purpose:Tests swscanf with wide characters -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoCharTest(convert("1234"), convert("%C"), "1", 1); - DoCharTest(convert("abc"), convert("%2C"), "ab", 2); - DoCharTest(convert(" ab"), convert("%C"), " ", 1); - DoCharTest(convert("ab"), convert("%hC"), "a", 1); - DoWCharTest(convert("ab"), convert("%lC"), convert("a"), 1); - DoCharTest(convert("ab"), convert("%LC"), "a", 1); - DoCharTest(convert("ab"), convert("%I64C"), "a", 1); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test10/test10.cpp new file mode 100644 index 0000000000..a8628e0de1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test10/test10.cpp @@ -0,0 +1,36 @@ +// 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: test10.c +** +** Purpose:Tests swscanf with wide characters +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoCharTest(convert("1234"), convert("%C"), "1", 1); + DoCharTest(convert("abc"), convert("%2C"), "ab", 2); + DoCharTest(convert(" ab"), convert("%C"), " ", 1); + DoCharTest(convert("ab"), convert("%hC"), "a", 1); + DoWCharTest(convert("ab"), convert("%lC"), convert("a"), 1); + DoCharTest(convert("ab"), convert("%LC"), "a", 1); + DoCharTest(convert("ab"), convert("%I64C"), "a", 1); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test11/CMakeLists.txt index 17066f31b8..1ca9224ec0 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_swscanf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/swscanf/test11/test11.c deleted file mode 100644 index f7eb4af46f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test11/test11.c +++ /dev/null @@ -1,35 +0,0 @@ -// 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: test11.c -** -** Purpose: Tests swscanf with strings -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoWStrTest(convert("foo bar"), convert("foo %s"), convert("bar")); - DoWStrTest(convert("foo bar"), convert("foo %2s"), convert("ba")); - DoStrTest(convert("foo bar"), convert("foo %hs"), "bar"); - DoWStrTest(convert("foo bar"), convert("foo %ls"), convert("bar")); - DoWStrTest(convert("foo bar"), convert("foo %Ls"), convert("bar")); - DoWStrTest(convert("foo bar"), convert("foo %I64s"), convert("bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test11/test11.cpp new file mode 100644 index 0000000000..f7eb4af46f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test11/test11.cpp @@ -0,0 +1,35 @@ +// 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: test11.c +** +** Purpose: Tests swscanf with strings +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoWStrTest(convert("foo bar"), convert("foo %s"), convert("bar")); + DoWStrTest(convert("foo bar"), convert("foo %2s"), convert("ba")); + DoStrTest(convert("foo bar"), convert("foo %hs"), "bar"); + DoWStrTest(convert("foo bar"), convert("foo %ls"), convert("bar")); + DoWStrTest(convert("foo bar"), convert("foo %Ls"), convert("bar")); + DoWStrTest(convert("foo bar"), convert("foo %I64s"), convert("bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test12/CMakeLists.txt index 95f5174ecb..44d70f47ae 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_swscanf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/swscanf/test12/test12.c deleted file mode 100644 index f5f8bbdf8a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test12/test12.c +++ /dev/null @@ -1,35 +0,0 @@ -// 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: test12.c -** -** Purpose: Tests swscanf with wide strings -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoStrTest(convert("foo bar"), convert("foo %S"), "bar"); - DoStrTest(convert("foo bar"), convert("foo %2S"), "ba"); - DoStrTest(convert("foo bar"), convert("foo %hS"), "bar"); - DoWStrTest(convert("foo bar"), convert("foo %lS"), convert("bar")); - DoStrTest(convert("foo bar"), convert("foo %LS"), "bar"); - DoStrTest(convert("foo bar"), convert("foo %I64S"), "bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test12/test12.cpp new file mode 100644 index 0000000000..f5f8bbdf8a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test12/test12.cpp @@ -0,0 +1,35 @@ +// 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: test12.c +** +** Purpose: Tests swscanf with wide strings +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoStrTest(convert("foo bar"), convert("foo %S"), "bar"); + DoStrTest(convert("foo bar"), convert("foo %2S"), "ba"); + DoStrTest(convert("foo bar"), convert("foo %hS"), "bar"); + DoWStrTest(convert("foo bar"), convert("foo %lS"), convert("bar")); + DoStrTest(convert("foo bar"), convert("foo %LS"), "bar"); + DoStrTest(convert("foo bar"), convert("foo %I64S"), "bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test13/CMakeLists.txt index 47abc50313..add0cbfe18 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_swscanf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/swscanf/test13/test13.c deleted file mode 100644 index 1bb0b7b21c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test13/test13.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test13.c -** -** Purpose: Tests swscanf with floats (decimal notation) -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest(convert("123.0"), convert("%f"), 123.0f); - DoFloatTest(convert("123.0"), convert("%2f"), 12.0f); - DoFloatTest(convert("10E1"), convert("%f"), 100.0f); - DoFloatTest(convert("-12.01e-2"), convert("%f"), -0.1201f); - DoFloatTest(convert("+12.01e-2"), convert("%f"), 0.1201f); - DoFloatTest(convert("-12.01e+2"), convert("%f"), -1201.0f); - DoFloatTest(convert("+12.01e+2"), convert("%f"), 1201.0f); - DoFloatTest(convert("1234567890.0123456789f"), convert("%f"), 1234567936); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test13/test13.cpp new file mode 100644 index 0000000000..1bb0b7b21c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test13/test13.cpp @@ -0,0 +1,37 @@ +// 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: test13.c +** +** Purpose: Tests swscanf with floats (decimal notation) +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest(convert("123.0"), convert("%f"), 123.0f); + DoFloatTest(convert("123.0"), convert("%2f"), 12.0f); + DoFloatTest(convert("10E1"), convert("%f"), 100.0f); + DoFloatTest(convert("-12.01e-2"), convert("%f"), -0.1201f); + DoFloatTest(convert("+12.01e-2"), convert("%f"), 0.1201f); + DoFloatTest(convert("-12.01e+2"), convert("%f"), -1201.0f); + DoFloatTest(convert("+12.01e+2"), convert("%f"), 1201.0f); + DoFloatTest(convert("1234567890.0123456789f"), convert("%f"), 1234567936); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test14/CMakeLists.txt index a470436ce7..126e087b1c 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_swscanf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/swscanf/test14/test14.c deleted file mode 100644 index 80581b726f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test14/test14.c +++ /dev/null @@ -1,38 +0,0 @@ -// 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: test14.c -** -** Purpose: Tests swscanf with floats (exponential notation, lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest(convert("123.0"), convert("%e"), 123.0f); - DoFloatTest(convert("123.0"), convert("%2e"), 12.0f); - DoFloatTest(convert("10E1"), convert("%e"), 100.0f); - DoFloatTest(convert("-12.01e-2"), convert("%e"), -0.1201f); - DoFloatTest(convert("+12.01e-2"), convert("%e"), 0.1201f); - DoFloatTest(convert("-12.01e+2"), convert("%e"), -1201.0f); - DoFloatTest(convert("+12.01e+2"), convert("%e"), 1201.0f); - DoFloatTest(convert("1234567890.0123456789f"), convert("%e"), 1234567936); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test14/test14.cpp new file mode 100644 index 0000000000..80581b726f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test14/test14.cpp @@ -0,0 +1,38 @@ +// 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: test14.c +** +** Purpose: Tests swscanf with floats (exponential notation, lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest(convert("123.0"), convert("%e"), 123.0f); + DoFloatTest(convert("123.0"), convert("%2e"), 12.0f); + DoFloatTest(convert("10E1"), convert("%e"), 100.0f); + DoFloatTest(convert("-12.01e-2"), convert("%e"), -0.1201f); + DoFloatTest(convert("+12.01e-2"), convert("%e"), 0.1201f); + DoFloatTest(convert("-12.01e+2"), convert("%e"), -1201.0f); + DoFloatTest(convert("+12.01e+2"), convert("%e"), 1201.0f); + DoFloatTest(convert("1234567890.0123456789f"), convert("%e"), 1234567936); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test15/CMakeLists.txt index d89650b12c..7c2da2bdf8 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_swscanf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/swscanf/test15/test15.c deleted file mode 100644 index 9b7d277e17..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test15/test15.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test15.c -** -** Purpose: Tests swscanf with floats (exponential notation, uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest(convert("123.0"), convert("%E"), 123.0f); - DoFloatTest(convert("123.0"), convert("%2E"), 12.0f); - DoFloatTest(convert("10E1"), convert("%E"), 100.0f); - DoFloatTest(convert("-12.01e-2"), convert("%E"), -0.1201f); - DoFloatTest(convert("+12.01e-2"), convert("%E"), 0.1201f); - DoFloatTest(convert("-12.01e+2"), convert("%E"), -1201.0f); - DoFloatTest(convert("+12.01e+2"), convert("%E"), 1201.0f); - DoFloatTest(convert("1234567890.0123456789f"), convert("%E"), 1234567936); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test15/test15.cpp new file mode 100644 index 0000000000..9b7d277e17 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test15/test15.cpp @@ -0,0 +1,37 @@ +// 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: test15.c +** +** Purpose: Tests swscanf with floats (exponential notation, uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest(convert("123.0"), convert("%E"), 123.0f); + DoFloatTest(convert("123.0"), convert("%2E"), 12.0f); + DoFloatTest(convert("10E1"), convert("%E"), 100.0f); + DoFloatTest(convert("-12.01e-2"), convert("%E"), -0.1201f); + DoFloatTest(convert("+12.01e-2"), convert("%E"), 0.1201f); + DoFloatTest(convert("-12.01e+2"), convert("%E"), -1201.0f); + DoFloatTest(convert("+12.01e+2"), convert("%E"), 1201.0f); + DoFloatTest(convert("1234567890.0123456789f"), convert("%E"), 1234567936); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test16/CMakeLists.txt index a2a00f11b6..ba28c4dc2f 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_swscanf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/swscanf/test16/test16.c deleted file mode 100644 index c83b64468b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test16/test16.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test16.c -** -** Purpose: Tests swscanf with floats (compact notation, lowercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest(convert("123.0"), convert("%g"), 123.0f); - DoFloatTest(convert("123.0"), convert("%2g"), 12.0f); - DoFloatTest(convert("10E1"), convert("%g"), 100.0f); - DoFloatTest(convert("-12.01e-2"), convert("%g"), -0.1201f); - DoFloatTest(convert("+12.01e-2"), convert("%g"), 0.1201f); - DoFloatTest(convert("-12.01e+2"), convert("%g"), -1201.0f); - DoFloatTest(convert("+12.01e+2"), convert("%g"), 1201.0f); - DoFloatTest(convert("1234567890.0123456789f"), convert("%g"), 1234567936); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test16/test16.cpp new file mode 100644 index 0000000000..c83b64468b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test16/test16.cpp @@ -0,0 +1,37 @@ +// 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: test16.c +** +** Purpose: Tests swscanf with floats (compact notation, lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest(convert("123.0"), convert("%g"), 123.0f); + DoFloatTest(convert("123.0"), convert("%2g"), 12.0f); + DoFloatTest(convert("10E1"), convert("%g"), 100.0f); + DoFloatTest(convert("-12.01e-2"), convert("%g"), -0.1201f); + DoFloatTest(convert("+12.01e-2"), convert("%g"), 0.1201f); + DoFloatTest(convert("-12.01e+2"), convert("%g"), -1201.0f); + DoFloatTest(convert("+12.01e+2"), convert("%g"), 1201.0f); + DoFloatTest(convert("1234567890.0123456789f"), convert("%g"), 1234567936); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test17/CMakeLists.txt index c224f5d9a6..225ce868ed 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_swscanf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/swscanf/test17/test17.c deleted file mode 100644 index 9023f7020a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test17/test17.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test17.c -** -** Purpose: Tests swscanf with floats (compact notation, uppercase) -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoFloatTest(convert("123.0"), convert("%G"), 123.0f); - DoFloatTest(convert("123.0"), convert("%2G"), 12.0f); - DoFloatTest(convert("10E1"), convert("%G"), 100.0f); - DoFloatTest(convert("-12.01e-2"), convert("%G"), -0.1201f); - DoFloatTest(convert("+12.01e-2"), convert("%G"), 0.1201f); - DoFloatTest(convert("-12.01e+2"), convert("%G"), -1201.0f); - DoFloatTest(convert("+12.01e+2"), convert("%G"), 1201.0f); - DoFloatTest(convert("1234567890.0123456789f"), convert("%G"), 1234567936); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test17/test17.cpp new file mode 100644 index 0000000000..9023f7020a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test17/test17.cpp @@ -0,0 +1,37 @@ +// 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: test17.c +** +** Purpose: Tests swscanf with floats (compact notation, uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoFloatTest(convert("123.0"), convert("%G"), 123.0f); + DoFloatTest(convert("123.0"), convert("%2G"), 12.0f); + DoFloatTest(convert("10E1"), convert("%G"), 100.0f); + DoFloatTest(convert("-12.01e-2"), convert("%G"), -0.1201f); + DoFloatTest(convert("+12.01e-2"), convert("%G"), 0.1201f); + DoFloatTest(convert("-12.01e+2"), convert("%G"), -1201.0f); + DoFloatTest(convert("+12.01e+2"), convert("%G"), 1201.0f); + DoFloatTest(convert("1234567890.0123456789f"), convert("%G"), 1234567936); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test2/CMakeLists.txt index a5335ddb48..15411ecf21 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_swscanf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/swscanf/test2/test2.c deleted file mode 100644 index 8fbd3f86ba..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test2/test2.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test2.c -** -** Purpose: Test to see if swscanf handles whitespace correctly -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - -/* - * Tests out how it handles whitespace. Seems to accept anything that qualifies - * as isspace (space, tab, vertical tab, line feed, carriage return and form - * feed), even if it says it only wants spaces tabs and newlines. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoStrTest(convert("foo bar"), convert("foo %S"), "bar"); - DoStrTest(convert("foo\tbar"), convert("foo %S"), "bar"); - DoStrTest(convert("foo\nbar"), convert("foo %S"), "bar"); - DoStrTest(convert("foo\rbar"), convert("foo %S"), "bar"); - DoStrTest(convert("foo\vbar"), convert("foo %S"), "bar"); - DoStrTest(convert("foo\fbar"), convert("foo %S"), "bar"); - DoStrTest(convert("foo \t\n\r\v\fbar"), convert("foo %S"), "bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test2/test2.cpp new file mode 100644 index 0000000000..8fbd3f86ba --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test2/test2.cpp @@ -0,0 +1,43 @@ +// 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: test2.c +** +** Purpose: Test to see if swscanf handles whitespace correctly +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + +/* + * Tests out how it handles whitespace. Seems to accept anything that qualifies + * as isspace (space, tab, vertical tab, line feed, carriage return and form + * feed), even if it says it only wants spaces tabs and newlines. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoStrTest(convert("foo bar"), convert("foo %S"), "bar"); + DoStrTest(convert("foo\tbar"), convert("foo %S"), "bar"); + DoStrTest(convert("foo\nbar"), convert("foo %S"), "bar"); + DoStrTest(convert("foo\rbar"), convert("foo %S"), "bar"); + DoStrTest(convert("foo\vbar"), convert("foo %S"), "bar"); + DoStrTest(convert("foo\fbar"), convert("foo %S"), "bar"); + DoStrTest(convert("foo \t\n\r\v\fbar"), convert("foo %S"), "bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test3/CMakeLists.txt index 5c229c26d3..927026107a 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_swscanf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/swscanf/test3/test3.c deleted file mode 100644 index 8b05df20f2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test3/test3.c +++ /dev/null @@ -1,36 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests swscanf with bracketed set strings -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoWStrTest(convert("bar1"), convert("%[a-z]"), convert("bar")); - DoWStrTest(convert("bar1"), convert("%[z-a]"), convert("bar")); - DoWStrTest(convert("bar1"), convert("%[ab]"), convert("ba")); - DoWStrTest(convert("bar1"), convert("%[ar1b]"), convert("bar1")); - DoWStrTest(convert("bar1"), convert("%[^4]"), convert("bar1")); - DoWStrTest(convert("bar1"), convert("%[^4a]"), convert("b")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test3/test3.cpp new file mode 100644 index 0000000000..8b05df20f2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test3/test3.cpp @@ -0,0 +1,36 @@ +// 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: test3.c +** +** Purpose: Tests swscanf with bracketed set strings +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoWStrTest(convert("bar1"), convert("%[a-z]"), convert("bar")); + DoWStrTest(convert("bar1"), convert("%[z-a]"), convert("bar")); + DoWStrTest(convert("bar1"), convert("%[ab]"), convert("ba")); + DoWStrTest(convert("bar1"), convert("%[ar1b]"), convert("bar1")); + DoWStrTest(convert("bar1"), convert("%[^4]"), convert("bar1")); + DoWStrTest(convert("bar1"), convert("%[^4a]"), convert("b")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test4/CMakeLists.txt index 5e281aaf34..eec701645b 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_swscanf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/swscanf/test4/test4.c deleted file mode 100644 index d63d25b7d0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test4/test4.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test4.c -** -** Purpose:Tests swscanf with decimal numbers -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest(convert("1234d"), convert("%d"), 1234); - DoNumTest(convert("1234d"), convert("%2d"), 12); - DoNumTest(convert("-1"), convert("%d"), -1); - DoNumTest(convert("0x1234"), convert("%d"), 0); - DoNumTest(convert("012"), convert("%d"), 12); - DoShortNumTest(convert("-1"), convert("%hd"), n65535); - DoShortNumTest(convert("65536"), convert("%hd"), 0); - DoNumTest(convert("-1"), convert("%ld"), -1); - DoNumTest(convert("65536"), convert("%ld"), 65536); - DoNumTest(convert("-1"), convert("%Ld"), -1); - DoNumTest(convert("65536"), convert("%Ld"), 65536); - DoI64NumTest(convert("4294967296"), convert("%I64d"), I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test4/test4.cpp new file mode 100644 index 0000000000..d63d25b7d0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test4/test4.cpp @@ -0,0 +1,44 @@ +// 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: test4.c +** +** Purpose:Tests swscanf with decimal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest(convert("1234d"), convert("%d"), 1234); + DoNumTest(convert("1234d"), convert("%2d"), 12); + DoNumTest(convert("-1"), convert("%d"), -1); + DoNumTest(convert("0x1234"), convert("%d"), 0); + DoNumTest(convert("012"), convert("%d"), 12); + DoShortNumTest(convert("-1"), convert("%hd"), n65535); + DoShortNumTest(convert("65536"), convert("%hd"), 0); + DoNumTest(convert("-1"), convert("%ld"), -1); + DoNumTest(convert("65536"), convert("%ld"), 65536); + DoNumTest(convert("-1"), convert("%Ld"), -1); + DoNumTest(convert("65536"), convert("%Ld"), 65536); + DoI64NumTest(convert("4294967296"), convert("%I64d"), I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test5/CMakeLists.txt index 8b259aa78d..3f022db16c 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_swscanf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/swscanf/test5/test5.c deleted file mode 100644 index 8ae2d81da6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test5/test5.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test5.c -** -** Purpose: Tests swscanf with integer numbers -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest(convert("1234d"), convert("%i"), 1234); - DoNumTest(convert("1234d"), convert("%2i"), 12); - DoNumTest(convert("-1"), convert("%i"), -1); - DoNumTest(convert("0x1234"), convert("%i"), 0x1234); - DoNumTest(convert("012"), convert("%i"), 10); - DoShortNumTest(convert("-1"), convert("%hi"), n65535); - DoShortNumTest(convert("65536"), convert("%hi"), 0); - DoNumTest(convert("-1"), convert("%li"), -1); - DoNumTest(convert("65536"), convert("%li"), 65536); - DoNumTest(convert("-1"), convert("%Li"), -1); - DoNumTest(convert("65536"), convert("%Li"), 65536); - DoI64NumTest(convert("4294967296"), convert("%I64i"), I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test5/test5.cpp new file mode 100644 index 0000000000..8ae2d81da6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test5/test5.cpp @@ -0,0 +1,44 @@ +// 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: test5.c +** +** Purpose: Tests swscanf with integer numbers +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest(convert("1234d"), convert("%i"), 1234); + DoNumTest(convert("1234d"), convert("%2i"), 12); + DoNumTest(convert("-1"), convert("%i"), -1); + DoNumTest(convert("0x1234"), convert("%i"), 0x1234); + DoNumTest(convert("012"), convert("%i"), 10); + DoShortNumTest(convert("-1"), convert("%hi"), n65535); + DoShortNumTest(convert("65536"), convert("%hi"), 0); + DoNumTest(convert("-1"), convert("%li"), -1); + DoNumTest(convert("65536"), convert("%li"), 65536); + DoNumTest(convert("-1"), convert("%Li"), -1); + DoNumTest(convert("65536"), convert("%Li"), 65536); + DoI64NumTest(convert("4294967296"), convert("%I64i"), I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test6/CMakeLists.txt index c3fd8696ab..c55666d95c 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_swscanf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/swscanf/test6/test6.c deleted file mode 100644 index 982f799cfc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test6/test6.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test6.c -** -** Purpose:Tests swscanf with octal numbers -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest(convert("1234d"), convert("%o"), 668); - DoNumTest(convert("1234d"), convert("%2o"), 10); - DoNumTest(convert("-1"), convert("%o"), -1); - DoNumTest(convert("0x1234"), convert("%o"), 0); - DoNumTest(convert("012"), convert("%o"), 10); - DoShortNumTest(convert("-1"), convert("%ho"), n65535); - DoShortNumTest(convert("200000"), convert("%ho"), 0); - DoNumTest(convert("-1"), convert("%lo"), -1); - DoNumTest(convert("200000"), convert("%lo"), 65536); - DoNumTest(convert("-1"), convert("%Lo"), -1); - DoNumTest(convert("200000"), convert("%Lo"), 65536); - DoI64NumTest(convert("40000000000"), convert("%I64o"), I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test6/test6.cpp new file mode 100644 index 0000000000..982f799cfc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test6/test6.cpp @@ -0,0 +1,44 @@ +// 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: test6.c +** +** Purpose:Tests swscanf with octal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest(convert("1234d"), convert("%o"), 668); + DoNumTest(convert("1234d"), convert("%2o"), 10); + DoNumTest(convert("-1"), convert("%o"), -1); + DoNumTest(convert("0x1234"), convert("%o"), 0); + DoNumTest(convert("012"), convert("%o"), 10); + DoShortNumTest(convert("-1"), convert("%ho"), n65535); + DoShortNumTest(convert("200000"), convert("%ho"), 0); + DoNumTest(convert("-1"), convert("%lo"), -1); + DoNumTest(convert("200000"), convert("%lo"), 65536); + DoNumTest(convert("-1"), convert("%Lo"), -1); + DoNumTest(convert("200000"), convert("%Lo"), 65536); + DoI64NumTest(convert("40000000000"), convert("%I64o"), I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test7/CMakeLists.txt index 00541306df..adb0abe80d 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_swscanf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/swscanf/test7/test7.c deleted file mode 100644 index 45e9400549..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test7/test7.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test7.c -** -** Purpose: Test #6 for the swscanf function -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest(convert("1234d"), convert("%x"), 0x1234d); - DoNumTest(convert("1234d"), convert("%2x"), 0x12); - DoNumTest(convert("-1"), convert("%x"), -1); - DoNumTest(convert("0x1234"), convert("%x"), 0x1234); - DoNumTest(convert("012"), convert("%x"), 0x12); - DoShortNumTest(convert("-1"), convert("%hx"), n65535); - DoShortNumTest(convert("10000"), convert("%hx"), 0); - DoNumTest(convert("-1"), convert("%lx"), -1); - DoNumTest(convert("10000"), convert("%lx"), 65536); - DoNumTest(convert("-1"), convert("%Lx"), -1); - DoNumTest(convert("10000"), convert("%Lx"), 65536); - DoI64NumTest(convert("100000000"), convert("%I64x"), I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test7/test7.cpp new file mode 100644 index 0000000000..45e9400549 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test7/test7.cpp @@ -0,0 +1,44 @@ +// 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: test7.c +** +** Purpose: Test #6 for the swscanf function +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest(convert("1234d"), convert("%x"), 0x1234d); + DoNumTest(convert("1234d"), convert("%2x"), 0x12); + DoNumTest(convert("-1"), convert("%x"), -1); + DoNumTest(convert("0x1234"), convert("%x"), 0x1234); + DoNumTest(convert("012"), convert("%x"), 0x12); + DoShortNumTest(convert("-1"), convert("%hx"), n65535); + DoShortNumTest(convert("10000"), convert("%hx"), 0); + DoNumTest(convert("-1"), convert("%lx"), -1); + DoNumTest(convert("10000"), convert("%lx"), 65536); + DoNumTest(convert("-1"), convert("%Lx"), -1); + DoNumTest(convert("10000"), convert("%Lx"), 65536); + DoI64NumTest(convert("100000000"), convert("%I64x"), I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test8/CMakeLists.txt index d6aa631ab9..a69c552337 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_swscanf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/swscanf/test8/test8.c deleted file mode 100644 index a244de748f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test8/test8.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test8.c -** -** Purpose: Tests swscanf with unsigned numbers -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int n65535 = 65535; /* Walkaround compiler strictness */ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoNumTest(convert("1234d"), convert("%u"), 1234); - DoNumTest(convert("1234d"), convert("%2u"), 12); - DoNumTest(convert("-1"), convert("%u"), -1); - DoNumTest(convert("0x1234"), convert("%u"), 0); - DoNumTest(convert("012"), convert("%u"), 12); - DoShortNumTest(convert("-1"), convert("%hu"), n65535); - DoShortNumTest(convert("65536"), convert("%hu"), 0); - DoNumTest(convert("-1"), convert("%lu"), -1); - DoNumTest(convert("65536"), convert("%lu"), 65536); - DoNumTest(convert("-1"), convert("%Lu"), -1); - DoNumTest(convert("65536"), convert("%Lu"), 65536); - DoI64NumTest(convert("4294967296"), convert("%I64u"), I64(4294967296)); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test8/test8.cpp new file mode 100644 index 0000000000..a244de748f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test8/test8.cpp @@ -0,0 +1,44 @@ +// 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: test8.c +** +** Purpose: Tests swscanf with unsigned numbers +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int n65535 = 65535; /* Walkaround compiler strictness */ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoNumTest(convert("1234d"), convert("%u"), 1234); + DoNumTest(convert("1234d"), convert("%2u"), 12); + DoNumTest(convert("-1"), convert("%u"), -1); + DoNumTest(convert("0x1234"), convert("%u"), 0); + DoNumTest(convert("012"), convert("%u"), 12); + DoShortNumTest(convert("-1"), convert("%hu"), n65535); + DoShortNumTest(convert("65536"), convert("%hu"), 0); + DoNumTest(convert("-1"), convert("%lu"), -1); + DoNumTest(convert("65536"), convert("%lu"), 65536); + DoNumTest(convert("-1"), convert("%Lu"), -1); + DoNumTest(convert("65536"), convert("%Lu"), 65536); + DoI64NumTest(convert("4294967296"), convert("%I64u"), I64(4294967296)); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/swscanf/test9/CMakeLists.txt index 4f7595a205..70a9fe2064 100644 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_swscanf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/swscanf/test9/test9.c deleted file mode 100644 index e289d26f58..0000000000 --- a/src/pal/tests/palsuite/c_runtime/swscanf/test9/test9.c +++ /dev/null @@ -1,37 +0,0 @@ -// 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: test9.c -** -** Purpose: Tests swscanf with characters -** -** -**==========================================================================*/ - - - -#include -#include "../swscanf.h" - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoWCharTest(convert("1234"), convert("%c"), convert("1"), 1); - DoWCharTest(convert("1234"), convert("%c"), convert("1"), 1); - DoWCharTest(convert("abc"), convert("%2c"), convert("ab"), 2); - DoWCharTest(convert(" ab"), convert("%c"), convert(" "), 1); - DoCharTest(convert("ab"), convert("%hc"), "a", 1); - DoWCharTest(convert("ab"), convert("%lc"), convert("a"), 1); - DoWCharTest(convert("ab"), convert("%Lc"), convert("a"), 1); - DoWCharTest(convert("ab"), convert("%I64c"), convert("a"), 1); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/swscanf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/swscanf/test9/test9.cpp new file mode 100644 index 0000000000..e289d26f58 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/swscanf/test9/test9.cpp @@ -0,0 +1,37 @@ +// 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: test9.c +** +** Purpose: Tests swscanf with characters +** +** +**==========================================================================*/ + + + +#include +#include "../swscanf.h" + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoWCharTest(convert("1234"), convert("%c"), convert("1"), 1); + DoWCharTest(convert("1234"), convert("%c"), convert("1"), 1); + DoWCharTest(convert("abc"), convert("%2c"), convert("ab"), 2); + DoWCharTest(convert(" ab"), convert("%c"), convert(" "), 1); + DoCharTest(convert("ab"), convert("%hc"), "a", 1); + DoWCharTest(convert("ab"), convert("%lc"), convert("a"), 1); + DoWCharTest(convert("ab"), convert("%Lc"), convert("a"), 1); + DoWCharTest(convert("ab"), convert("%I64c"), convert("a"), 1); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/tan/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tan/test1/CMakeLists.txt index 665fc22d5e..cea661f2bb 100644 --- a/src/pal/tests/palsuite/c_runtime/tan/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/tan/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_tan_test1 diff --git a/src/pal/tests/palsuite/c_runtime/tan/test1/test1.c b/src/pal/tests/palsuite/c_runtime/tan/test1/test1.c deleted file mode 100644 index 443e5da6d6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/tan/test1/test1.c +++ /dev/null @@ -1,137 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that tan return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = tan(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("tan(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = tan(value); - - if (!_isnan(result)) - { - Fail("tan(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, 0, PAL_EPSILON }, - { 0.31830988618379067, 0.32951473309607836, PAL_EPSILON }, // value: 1 / pi - { 0.43429448190325183, 0.46382906716062964, PAL_EPSILON }, // value: log10(e) - { 0.63661977236758134, 0.73930295048660405, PAL_EPSILON }, // value: 2 / pi - { 0.69314718055994531, 0.83064087786078395, PAL_EPSILON }, // value: ln(2) - { 0.70710678118654752, 0.85451043200960189, PAL_EPSILON }, // value: 1 / sqrt(2) - { 0.78539816339744831, 1, PAL_EPSILON * 10 }, // value: pi / 4 - { 1, 1.5574077246549022, PAL_EPSILON * 10 }, - { 1.1283791670955126, 2.1108768356626451, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 6.3341191670421916, PAL_EPSILON * 10 }, // value: sqrt(2) - { 1.4426950408889634, 7.7635756709721848, PAL_EPSILON * 10 }, // value: log2(e) - // SEE BELOW -- { 1.5707963267948966, PAL_POSINF, 0 }, // value: pi / 2 - { 2.3025850929940457, -1.1134071468135374, PAL_EPSILON * 10 }, // value: ln(10) - { 2.7182818284590452, -0.45054953406980750, PAL_EPSILON }, // value: e - { 3.1415926535897932, 0, PAL_EPSILON }, // value: pi - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, -tests[i].expected, tests[i].variance); - } - - // -- SPECIAL CASE -- - // Normally, tan(pi / 2) would return PAL_POSINF (atan2(PAL_POSINF) does return (pi / 2)). - // However, it seems instead (on all supported systems), we get a different number entirely. - validate( 1.5707963267948966, 16331239353195370.0, 0); - validate(-1.5707963267948966, -16331239353195370.0, 0); - - validate_isnan(PAL_NEGINF); - validate_isnan(PAL_NAN); - validate_isnan(PAL_POSINF); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/tan/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/tan/test1/test1.cpp new file mode 100644 index 0000000000..443e5da6d6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tan/test1/test1.cpp @@ -0,0 +1,137 @@ +// 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: test1.c +** +** Purpose: Test to ensure that tan return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = tan(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("tan(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = tan(value); + + if (!_isnan(result)) + { + Fail("tan(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.31830988618379067, 0.32951473309607836, PAL_EPSILON }, // value: 1 / pi + { 0.43429448190325183, 0.46382906716062964, PAL_EPSILON }, // value: log10(e) + { 0.63661977236758134, 0.73930295048660405, PAL_EPSILON }, // value: 2 / pi + { 0.69314718055994531, 0.83064087786078395, PAL_EPSILON }, // value: ln(2) + { 0.70710678118654752, 0.85451043200960189, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.78539816339744831, 1, PAL_EPSILON * 10 }, // value: pi / 4 + { 1, 1.5574077246549022, PAL_EPSILON * 10 }, + { 1.1283791670955126, 2.1108768356626451, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 6.3341191670421916, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.4426950408889634, 7.7635756709721848, PAL_EPSILON * 10 }, // value: log2(e) + // SEE BELOW -- { 1.5707963267948966, PAL_POSINF, 0 }, // value: pi / 2 + { 2.3025850929940457, -1.1134071468135374, PAL_EPSILON * 10 }, // value: ln(10) + { 2.7182818284590452, -0.45054953406980750, PAL_EPSILON }, // value: e + { 3.1415926535897932, 0, PAL_EPSILON }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + // -- SPECIAL CASE -- + // Normally, tan(pi / 2) would return PAL_POSINF (atan2(PAL_POSINF) does return (pi / 2)). + // However, it seems instead (on all supported systems), we get a different number entirely. + validate( 1.5707963267948966, 16331239353195370.0, 0); + validate(-1.5707963267948966, -16331239353195370.0, 0); + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/tanf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/tanf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanf/test1/CMakeLists.txt new file mode 100644 index 0000000000..cd588ea23e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_tanf_test1 + ${SOURCES} +) + +add_dependencies(paltest_tanf_test1 coreclrpal) + +target_link_libraries(paltest_tanf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/tanf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/tanf/test1/test1.c new file mode 100644 index 0000000000..18d5c4e59d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanf/test1/test1.c @@ -0,0 +1,136 @@ +// 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: test1.c +** +** Purpose: Test to ensure that tanf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = tanf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("tanf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = tanf(value); + + if (!_isnanf(result)) + { + Fail("tanf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.318309886f, 0.329514733f, PAL_EPSILON }, // value: 1 / pi + { 0.434294482f, 0.463829067f, PAL_EPSILON }, // value: log10f(e) + { 0.636619772f, 0.739302950f, PAL_EPSILON }, // value: 2 / pi + { 0.693147181f, 0.830640878f, PAL_EPSILON }, // value: ln(2) + { 0.707106781f, 0.854510432f, PAL_EPSILON }, // value: 1 / sqrtf(2) + { 0.785398163f, 1, PAL_EPSILON * 10 }, // value: pi / 4 + { 1, 1.55740772f, PAL_EPSILON * 10 }, + { 1.12837917f, 2.11087684f, PAL_EPSILON * 10 }, // value: 2 / sqrtf(pi) + { 1.41421356f, 6.33411917f, PAL_EPSILON * 10 }, // value: sqrtf(2) + { 1.44269504f, 7.76357567f, PAL_EPSILON * 10 }, // value: logf2(e) + // SEE BELOW -- { 1.57079633f, PAL_POSINF, 0 }, // value: pi / 2 + { 2.30258509f, -1.11340715f, PAL_EPSILON * 10 }, // value: ln(10) + { 2.71828183f, -0.450549534f, PAL_EPSILON }, // value: e + { 3.14159265f, 0, PAL_EPSILON }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + // -- SPECIAL CASE -- + // Normally, tanf(pi / 2) would return PAL_POSINF (atan2f(PAL_POSINF) does return (pi / 2)). + // However, it seems instead (on all supported systems), we get a different number entirely. + validate( 1.57079633f, -22877332.0, PAL_EPSILON * 100000000); + validate(-1.57079633f, 22877332.0, PAL_EPSILON * 100000000); + + validate_isnan(PAL_NEGINF); + validate_isnan(PAL_NAN); + validate_isnan(PAL_POSINF); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/tanf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/tanf/test1/testinfo.dat new file mode 100644 index 0000000000..aa33232adc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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 = C Runtime +Function = tanf +Name = Positive Test for tanf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to tanf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/tanh/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanh/test1/CMakeLists.txt index f8e439dd95..9fe926d441 100644 --- a/src/pal/tests/palsuite/c_runtime/tanh/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/tanh/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_tanh_test1 diff --git a/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.c b/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.c deleted file mode 100644 index 3b8f87964a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.c +++ /dev/null @@ -1,130 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that tanh return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** -**===========================================================================*/ - -#include - -// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this -// is slightly too accurate when writing tests meant to run against libm implementations -// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. -// -// The tests themselves will take PAL_EPSILON and adjust it according to the expected result -// so that the delta used for comparison will compare the most significant digits and ignore -// any digits that are outside the double precision range (15-17 digits). - -// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use -// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx -// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will -// use PAL_EPSILON * 10. -#define PAL_EPSILON 8.8817841970012523e-16 - -#define PAL_NAN sqrt(-1.0) -#define PAL_POSINF -log(0.0) -#define PAL_NEGINF log(0.0) - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double expected; /* expected result */ - double variance; /* maximum delta between the expected and actual result */ -}; - -/** - * validate - * - * test validation function - */ -void __cdecl validate(double value, double expected, double variance) -{ - double result = tanh(value); - - /* - * The test is valid when the difference between result - * and expected is less than or equal to variance - */ - double delta = fabs(result - expected); - - if (delta > variance) - { - Fail("tanh(%g) returned %20.17g when it should have returned %20.17g", - value, result, expected); - } -} - -/** - * validate - * - * test validation function for values returning NaN - */ -void __cdecl validate_isnan(double value) -{ - double result = tanh(value); - - if (!_isnan(result)) - { - Fail("tanh(%g) returned %20.17g when it should have returned %20.17g", - value, result, PAL_NAN); - } -} - -/** - * main - * - * executable entry point - */ -int __cdecl main(int argc, char **argv) -{ - struct test tests[] = - { - /* value expected variance */ - { 0, 0, PAL_EPSILON }, - { 0.31830988618379067, 0.30797791269089433, PAL_EPSILON }, // value: 1 / pi - { 0.43429448190325183, 0.40890401183401433, PAL_EPSILON }, // value: log10(e) - { 0.63661977236758134, 0.56259360033158334, PAL_EPSILON }, // value: 2 / pi - { 0.69314718055994531, 0.6, PAL_EPSILON }, // value: ln(2) - { 0.70710678118654752, 0.60885936501391381, PAL_EPSILON }, // value: 1 / sqrt(2) - { 0.78539816339744831, 0.65579420263267244, PAL_EPSILON }, // value: pi / 4 - { 1, 0.76159415595576489, PAL_EPSILON }, - { 1.1283791670955126, 0.81046380599898809, PAL_EPSILON }, // value: 2 / sqrt(pi) - { 1.4142135623730950, 0.88838556158566054, PAL_EPSILON }, // value: sqrt(2) - { 1.4426950408889634, 0.89423894585503855, PAL_EPSILON }, // value: log2(e) - { 1.5707963267948966, 0.91715233566727435, PAL_EPSILON }, // value: pi / 2 - { 2.3025850929940457, 0.98019801980198020, PAL_EPSILON }, // value: ln(10) - { 2.7182818284590452, 0.99132891580059984, PAL_EPSILON }, // value: e - { 3.1415926535897932, 0.99627207622074994, PAL_EPSILON }, // value: pi - { PAL_POSINF, 1, PAL_EPSILON * 10 } - }; - - /* PAL initialization */ - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) - { - validate( tests[i].value, tests[i].expected, tests[i].variance); - validate(-tests[i].value, -tests[i].expected, tests[i].variance); - } - - validate_isnan(PAL_NAN); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.cpp new file mode 100644 index 0000000000..3b8f87964a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.cpp @@ -0,0 +1,130 @@ +// 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: test1.c +** +** Purpose: Test to ensure that tanh return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = tanh(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("tanh(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = tanh(value); + + if (!_isnan(result)) + { + Fail("tanh(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.31830988618379067, 0.30797791269089433, PAL_EPSILON }, // value: 1 / pi + { 0.43429448190325183, 0.40890401183401433, PAL_EPSILON }, // value: log10(e) + { 0.63661977236758134, 0.56259360033158334, PAL_EPSILON }, // value: 2 / pi + { 0.69314718055994531, 0.6, PAL_EPSILON }, // value: ln(2) + { 0.70710678118654752, 0.60885936501391381, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.65579420263267244, PAL_EPSILON }, // value: pi / 4 + { 1, 0.76159415595576489, PAL_EPSILON }, + { 1.1283791670955126, 0.81046380599898809, PAL_EPSILON }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 0.88838556158566054, PAL_EPSILON }, // value: sqrt(2) + { 1.4426950408889634, 0.89423894585503855, PAL_EPSILON }, // value: log2(e) + { 1.5707963267948966, 0.91715233566727435, PAL_EPSILON }, // value: pi / 2 + { 2.3025850929940457, 0.98019801980198020, PAL_EPSILON }, // value: ln(10) + { 2.7182818284590452, 0.99132891580059984, PAL_EPSILON }, // value: e + { 3.1415926535897932, 0.99627207622074994, PAL_EPSILON }, // value: pi + { PAL_POSINF, 1, PAL_EPSILON * 10 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/tanhf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanhf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanhf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/tanhf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanhf/test1/CMakeLists.txt new file mode 100644 index 0000000000..fd0af2a46f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanhf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_tanhf_test1 + ${SOURCES} +) + +add_dependencies(paltest_tanhf_test1 coreclrpal) + +target_link_libraries(paltest_tanhf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/tanhf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/tanhf/test1/test1.c new file mode 100644 index 0000000000..904729a2c4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanhf/test1/test1.c @@ -0,0 +1,129 @@ +// 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: test1.c +** +** Purpose: Test to ensure that tanhf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = tanhf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("tanhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = tanhf(value); + + if (!_isnanf(result)) + { + Fail("tanhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.318309886f, 0.307977913f, PAL_EPSILON }, // value: 1 / pi + { 0.434294482f, 0.408904012f, PAL_EPSILON }, // value: log10f(e) + { 0.636619772f, 0.562593600f, PAL_EPSILON }, // value: 2 / pi + { 0.693147181f, 0.6f, PAL_EPSILON }, // value: ln(2) + { 0.707106781f, 0.608859365f, PAL_EPSILON }, // value: 1 / sqrtf(2) + { 0.785398163f, 0.655794203f, PAL_EPSILON }, // value: pi / 4 + { 1, 0.761594156f, PAL_EPSILON }, + { 1.12837917f, 0.810463806f, PAL_EPSILON }, // value: 2 / sqrtf(pi) + { 1.41421356f, 0.888385562f, PAL_EPSILON }, // value: sqrtf(2) + { 1.44269504f, 0.894238946f, PAL_EPSILON }, // value: logf2(e) + { 1.57079633f, 0.917152336f, PAL_EPSILON }, // value: pi / 2 + { 2.30258509f, 0.980198020f, PAL_EPSILON }, // value: ln(10) + { 2.71828183f, 0.991328916f, PAL_EPSILON }, // value: e + { 3.14159265f, 0.996272076f, PAL_EPSILON }, // value: pi + { PAL_POSINF, 1, PAL_EPSILON * 10 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/tanhf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/tanhf/test1/testinfo.dat new file mode 100644 index 0000000000..6c7594fc5a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanhf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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 = C Runtime +Function = tanhf +Name = Positive Test for tanhf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to tanhf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/time/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/time/test1/CMakeLists.txt index d495266cef..64df144557 100644 --- a/src/pal/tests/palsuite/c_runtime/time/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/time/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_time_test1 diff --git a/src/pal/tests/palsuite/c_runtime/time/test1/test1.c b/src/pal/tests/palsuite/c_runtime/time/test1/test1.c deleted file mode 100644 index c668bf38e7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/time/test1/test1.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test1.c -** -** Purpose: Calls the time function and verifies that the time returned -** is at least a positive value. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - time_t t = 0; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - time(&t); - /*I was going to test that the time returned didn't exceed some - reasonable value, but decided not to, for fear of creating my own - little Y2K-style disaster.*/ - - if (t <= 0) - { - Fail("time() function doesn't return a time.\n"); - } - t = 0; - t = time(NULL); - if (t <= 0) - { - Fail("time() function doesn't return a time.\n"); - } - PAL_Terminate(); - return PASS; -} - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/time/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/time/test1/test1.cpp new file mode 100644 index 0000000000..c668bf38e7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/time/test1/test1.cpp @@ -0,0 +1,51 @@ +// 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: test1.c +** +** Purpose: Calls the time function and verifies that the time returned +** is at least a positive value. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + time_t t = 0; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + time(&t); + /*I was going to test that the time returned didn't exceed some + reasonable value, but decided not to, for fear of creating my own + little Y2K-style disaster.*/ + + if (t <= 0) + { + Fail("time() function doesn't return a time.\n"); + } + t = 0; + t = time(NULL); + if (t <= 0) + { + Fail("time() function doesn't return a time.\n"); + } + PAL_Terminate(); + return PASS; +} + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/tolower/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tolower/test1/CMakeLists.txt index 537f239cf8..214a509010 100644 --- a/src/pal/tests/palsuite/c_runtime/tolower/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/tolower/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_tolower_test1 diff --git a/src/pal/tests/palsuite/c_runtime/tolower/test1/test1.c b/src/pal/tests/palsuite/c_runtime/tolower/test1/test1.c deleted file mode 100644 index cab623d3f9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/tolower/test1/test1.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the tolower function. -** Check that the tolower function makes capital character -** lower case. Also check that it has no effect on lower -** case letters and special characters. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - int lower; - int start; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - struct testCase testCases[] = - { - {'a', 'A'}, /* Basic cases */ - {'z', 'Z'}, - {'b', 'b'}, /* Lower case */ - {'?', '?'}, /* Characters without case */ - {230, 230} - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through each case. Convert each character to lower case - and then compare to ensure that it is the correct value. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /*Convert to lower case*/ - result = tolower(testCases[i].start); - - if (testCases[i].lower != result) - { - Fail("ERROR: tolower lowered \"%i\" to %i instead of %i.\n", - testCases[i].start, result, testCases[i].lower); - } - - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/tolower/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/tolower/test1/test1.cpp new file mode 100644 index 0000000000..cab623d3f9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tolower/test1/test1.cpp @@ -0,0 +1,79 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the tolower function. +** Check that the tolower function makes capital character +** lower case. Also check that it has no effect on lower +** case letters and special characters. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + int lower; + int start; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + struct testCase testCases[] = + { + {'a', 'A'}, /* Basic cases */ + {'z', 'Z'}, + {'b', 'b'}, /* Lower case */ + {'?', '?'}, /* Characters without case */ + {230, 230} + }; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through each case. Convert each character to lower case + and then compare to ensure that it is the correct value. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /*Convert to lower case*/ + result = tolower(testCases[i].start); + + if (testCases[i].lower != result) + { + Fail("ERROR: tolower lowered \"%i\" to %i instead of %i.\n", + testCases[i].start, result, testCases[i].lower); + } + + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/toupper/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/toupper/test1/CMakeLists.txt index e5aa375a9b..3dd536c590 100644 --- a/src/pal/tests/palsuite/c_runtime/toupper/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/toupper/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_toupper_test1 diff --git a/src/pal/tests/palsuite/c_runtime/toupper/test1/test1.c b/src/pal/tests/palsuite/c_runtime/toupper/test1/test1.c deleted file mode 100644 index c580699e3b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/toupper/test1/test1.c +++ /dev/null @@ -1,64 +0,0 @@ -// 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: test1.c (toupper) -** -** -** Purpose: Tests the PAL implementation of the toupper function. -** Check that the toupper function makes lower case -** character a capital. Also check that it has no effect -** on upper case letters and special characters. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - int upper; - int start; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - struct testCase testCases[] = - { - {'A', 'a'}, /* Basic cases */ - {'Z', 'z'}, - {'B', 'B'}, /* Upper case */ - {'%', '%'}, /* Characters without case */ - {157, 157} - }; - - if ((PAL_Initialize(argc, argv)) != 0) - { - return FAIL; - } - - - /* Loop through each case. Convert each character to upper case - and then compare to ensure that it is the correct value. - */ - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /*Convert to upper case*/ - result = toupper(testCases[i].start); - - if (testCases[i].upper != result) - { - Fail("ERROR: toupper capitalized \"%c\" to %c instead of %c.\n", - testCases[i].start, result, testCases[i].upper); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/toupper/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/toupper/test1/test1.cpp new file mode 100644 index 0000000000..c580699e3b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/toupper/test1/test1.cpp @@ -0,0 +1,64 @@ +// 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: test1.c (toupper) +** +** +** Purpose: Tests the PAL implementation of the toupper function. +** Check that the toupper function makes lower case +** character a capital. Also check that it has no effect +** on upper case letters and special characters. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + int upper; + int start; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + struct testCase testCases[] = + { + {'A', 'a'}, /* Basic cases */ + {'Z', 'z'}, + {'B', 'B'}, /* Upper case */ + {'%', '%'}, /* Characters without case */ + {157, 157} + }; + + if ((PAL_Initialize(argc, argv)) != 0) + { + return FAIL; + } + + + /* Loop through each case. Convert each character to upper case + and then compare to ensure that it is the correct value. + */ + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /*Convert to upper case*/ + result = toupper(testCases[i].start); + + if (testCases[i].upper != result) + { + Fail("ERROR: toupper capitalized \"%c\" to %c instead of %c.\n", + testCases[i].start, result, testCases[i].upper); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/towlower/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/towlower/test1/CMakeLists.txt index 2a3e6a07ef..77a46344d4 100644 --- a/src/pal/tests/palsuite/c_runtime/towlower/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/towlower/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_towlower_test1 diff --git a/src/pal/tests/palsuite/c_runtime/towlower/test1/test1.c b/src/pal/tests/palsuite/c_runtime/towlower/test1/test1.c deleted file mode 100644 index 5f2457a5fe..0000000000 --- a/src/pal/tests/palsuite/c_runtime/towlower/test1/test1.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the towlower function. -** Check that the tolower function makes capital character -** lower case. Also check that it has no effect on lower -** case letters and special characters. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - WCHAR lower; - WCHAR start; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - struct testCase testCases[] = - { - {'a', 'A'}, /* Basic cases */ - {'z', 'Z'}, - {'b', 'b'}, /* Lower case */ - {'?', '?'}, /* Characters without case */ - {230, 230} - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Loop through each case. Convert each character to lower case - and then compare to ensure that it is the correct value. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /*Convert to lower case*/ - result = towlower(testCases[i].start); - - if (testCases[i].lower != result) - { - Fail("ERROR: towlower lowered \"%c\" to %c instead of %c.\n", - testCases[i].start, result, testCases[i].lower); - } - - } - - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/towlower/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/towlower/test1/test1.cpp new file mode 100644 index 0000000000..5f2457a5fe --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/towlower/test1/test1.cpp @@ -0,0 +1,79 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the towlower function. +** Check that the tolower function makes capital character +** lower case. Also check that it has no effect on lower +** case letters and special characters. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + WCHAR lower; + WCHAR start; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + struct testCase testCases[] = + { + {'a', 'A'}, /* Basic cases */ + {'z', 'Z'}, + {'b', 'b'}, /* Lower case */ + {'?', '?'}, /* Characters without case */ + {230, 230} + }; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Loop through each case. Convert each character to lower case + and then compare to ensure that it is the correct value. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /*Convert to lower case*/ + result = towlower(testCases[i].start); + + if (testCases[i].lower != result) + { + Fail("ERROR: towlower lowered \"%c\" to %c instead of %c.\n", + testCases[i].start, result, testCases[i].lower); + } + + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/towupper/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/towupper/test1/CMakeLists.txt index 537efbe0fa..6a2f813cc9 100644 --- a/src/pal/tests/palsuite/c_runtime/towupper/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/towupper/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_towupper_test1 diff --git a/src/pal/tests/palsuite/c_runtime/towupper/test1/test1.c b/src/pal/tests/palsuite/c_runtime/towupper/test1/test1.c deleted file mode 100644 index 63f051fa66..0000000000 --- a/src/pal/tests/palsuite/c_runtime/towupper/test1/test1.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: test1.c(towupper) -** -** -** Purpose: Tests the PAL implementation of the towupper function. -** Check that the towupper function makes lower case -** character a capital. Also check that it has no effect -** on upper case letters and special characters. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - WCHAR upper; - WCHAR start; -}; - -int __cdecl main(int argc, char **argv) -{ - - int result; - int i; - - struct testCase testCases[] = - { - {'A', 'a'}, /* Basic cases */ - {'Z', 'z'}, - {'B', 'B'}, /* Upper case */ - {'%', '%'}, /* Characters without case */ - {157, 157} - }; - - if ((PAL_Initialize(argc, argv)) != 0) - { - return FAIL; - } - - - /* Loop through each case. Convert each character to upper case - and then compare to ensure that it is the correct value. - */ - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - /*Convert to upper case*/ - result = towupper(testCases[i].start); - - if (testCases[i].upper != result) - { - Fail("ERROR: towupper capitalized \"%c\" to %c instead of %c.\n", - testCases[i].start, result, testCases[i].upper); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/towupper/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/towupper/test1/test1.cpp new file mode 100644 index 0000000000..63f051fa66 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/towupper/test1/test1.cpp @@ -0,0 +1,65 @@ +// 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: test1.c(towupper) +** +** +** Purpose: Tests the PAL implementation of the towupper function. +** Check that the towupper function makes lower case +** character a capital. Also check that it has no effect +** on upper case letters and special characters. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + WCHAR upper; + WCHAR start; +}; + +int __cdecl main(int argc, char **argv) +{ + + int result; + int i; + + struct testCase testCases[] = + { + {'A', 'a'}, /* Basic cases */ + {'Z', 'z'}, + {'B', 'B'}, /* Upper case */ + {'%', '%'}, /* Characters without case */ + {157, 157} + }; + + if ((PAL_Initialize(argc, argv)) != 0) + { + return FAIL; + } + + + /* Loop through each case. Convert each character to upper case + and then compare to ensure that it is the correct value. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + /*Convert to upper case*/ + result = towupper(testCases[i].start); + + if (testCases[i].upper != result) + { + Fail("ERROR: towupper capitalized \"%c\" to %c instead of %c.\n", + testCases[i].start, result, testCases[i].upper); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/ungetc/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ungetc/test1/CMakeLists.txt index da19397e2c..0286f99b77 100644 --- a/src/pal/tests/palsuite/c_runtime/ungetc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/ungetc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - ungetc.c + ungetc.cpp ) add_executable(paltest_ungetc_test1 diff --git a/src/pal/tests/palsuite/c_runtime/ungetc/test1/ungetc.c b/src/pal/tests/palsuite/c_runtime/ungetc/test1/ungetc.c deleted file mode 100644 index 397e42ac64..0000000000 --- a/src/pal/tests/palsuite/c_runtime/ungetc/test1/ungetc.c +++ /dev/null @@ -1,130 +0,0 @@ -// 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: ungetc.c (test 1) -** -** Purpose: Tests the PAL implementation of the ungetc function by calling -** the function on a write-only file. -** -** Dependencies: -** fopen -** fclose -** fseek -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char szFileName[] = {"test1.tmp"}; - const char text[] = - {"The quick brown fox jumped over the lazy dog's back."}; - FILE* pFile = NULL; - int nChar = 65; /* 'A' */ - int nRc = 0; - int itemsExpected; - int itemsWritten; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create the file */ - pFile = fopen(szFileName, "w"); - if (pFile == NULL) - { - Fail("ungetc: ERROR -> fopen failed to create the file \"%s\"" - " as write-only.\n", - szFileName); - } - - /* write to the file */ - itemsExpected = sizeof(text); - itemsWritten = fwrite(text, sizeof(text[0]), sizeof(text), pFile); - if (itemsWritten == 0) - { - Trace("ungetc: ERROR -> fwrite failed to write to the file \"%s\"\n", - szFileName); - - if (fclose(pFile) != 0) - { - Fail("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - - } - else if (itemsWritten != itemsExpected) - { - Trace("ungetc: ERROR -> fwrite failed to write the correct number " - "of characters to the file \"%s\"\n", - szFileName); - - if (fclose(pFile) != 0) - { - Fail("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - - /* Close the file */ - if (fclose(pFile) != 0) - { - Fail("ungetc: ERROR -> fclose failed to close the file.\n"); - } - - /* - ** open the file in write only mode and - ** attempt to push an unread character back on the stream - */ - - - /* open the file write-only */ - pFile = fopen(szFileName, "a"); - if (pFile == NULL) - { - Fail("ungetc: ERROR -> fopen failed to open the file \"%s\"" - " as write-only.\n", - szFileName); - } - - /* move the file pointer back to the beginning of the file */ - if (fseek(pFile, 1, SEEK_SET) != 0) - { - - Trace("ungetc: ERROR -> fseek failed to move the file pointer to the " - "beginning of the file.\n"); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - - /* call ungetc on a write-only file which should fail */ - if ((nRc = ungetc(nChar, pFile)) != EOF) - { - Trace("ungetc: ERROR -> ungetc returned \"%c\" when run on " - "an write-only file.\n", nChar); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - - if (fclose(pFile) != 0) - { - Fail("ungetc: ERROR -> fclose failed to close the file.\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/ungetc/test1/ungetc.cpp b/src/pal/tests/palsuite/c_runtime/ungetc/test1/ungetc.cpp new file mode 100644 index 0000000000..397e42ac64 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ungetc/test1/ungetc.cpp @@ -0,0 +1,130 @@ +// 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: ungetc.c (test 1) +** +** Purpose: Tests the PAL implementation of the ungetc function by calling +** the function on a write-only file. +** +** Dependencies: +** fopen +** fclose +** fseek +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char szFileName[] = {"test1.tmp"}; + const char text[] = + {"The quick brown fox jumped over the lazy dog's back."}; + FILE* pFile = NULL; + int nChar = 65; /* 'A' */ + int nRc = 0; + int itemsExpected; + int itemsWritten; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create the file */ + pFile = fopen(szFileName, "w"); + if (pFile == NULL) + { + Fail("ungetc: ERROR -> fopen failed to create the file \"%s\"" + " as write-only.\n", + szFileName); + } + + /* write to the file */ + itemsExpected = sizeof(text); + itemsWritten = fwrite(text, sizeof(text[0]), sizeof(text), pFile); + if (itemsWritten == 0) + { + Trace("ungetc: ERROR -> fwrite failed to write to the file \"%s\"\n", + szFileName); + + if (fclose(pFile) != 0) + { + Fail("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + + } + else if (itemsWritten != itemsExpected) + { + Trace("ungetc: ERROR -> fwrite failed to write the correct number " + "of characters to the file \"%s\"\n", + szFileName); + + if (fclose(pFile) != 0) + { + Fail("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + + /* Close the file */ + if (fclose(pFile) != 0) + { + Fail("ungetc: ERROR -> fclose failed to close the file.\n"); + } + + /* + ** open the file in write only mode and + ** attempt to push an unread character back on the stream + */ + + + /* open the file write-only */ + pFile = fopen(szFileName, "a"); + if (pFile == NULL) + { + Fail("ungetc: ERROR -> fopen failed to open the file \"%s\"" + " as write-only.\n", + szFileName); + } + + /* move the file pointer back to the beginning of the file */ + if (fseek(pFile, 1, SEEK_SET) != 0) + { + + Trace("ungetc: ERROR -> fseek failed to move the file pointer to the " + "beginning of the file.\n"); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + + /* call ungetc on a write-only file which should fail */ + if ((nRc = ungetc(nChar, pFile)) != EOF) + { + Trace("ungetc: ERROR -> ungetc returned \"%c\" when run on " + "an write-only file.\n", nChar); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + + if (fclose(pFile) != 0) + { + Fail("ungetc: ERROR -> fclose failed to close the file.\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/ungetc/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ungetc/test2/CMakeLists.txt index 7b63423628..0710074bd0 100644 --- a/src/pal/tests/palsuite/c_runtime/ungetc/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/ungetc/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - ungetc.c + ungetc.cpp ) add_executable(paltest_ungetc_test2 diff --git a/src/pal/tests/palsuite/c_runtime/ungetc/test2/ungetc.c b/src/pal/tests/palsuite/c_runtime/ungetc/test2/ungetc.c deleted file mode 100644 index cbc8102eec..0000000000 --- a/src/pal/tests/palsuite/c_runtime/ungetc/test2/ungetc.c +++ /dev/null @@ -1,188 +0,0 @@ -// 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: ungetc.c (test 2) -** -** Purpose: Tests the PAL implementation of the ungetc function -** -** Dependencies: -** fopen -** fread -** fclose -** fseek -** getc -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - const char szFileName[] = {"test2.txt"}; - const char szNewString[] = {"bar bar"}; - char szBuffer[MAX_PATH]; - FILE* pFile = NULL; - int nChar = 32; /* space */ - int i = 0; - int nRc = 0; - size_t nCount = 0; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - memset(szBuffer, 0, MAX_PATH); - - /* - ** open the file in write only mode, populate it and - ** attempt to push an unread character back on the stream - */ - - - /* open the file for read */ - pFile = fopen(szFileName, "r"); - if (pFile == NULL) - { - Fail("ungetc: ERROR -> fopen failed to open the file \"%s\"" - " as read-only.n", - szFileName); - } - - - /* - ** Call getc to get the first char and ungetc to put - ** it back. getc should read it again. - */ - - /* read a character */ - if ((nChar = getc(pFile)) == EOF) - { - Trace("ungetc: ERROR -> getc encountered an error reading.\n"); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - - /* put it back */ - if ((nRc = ungetc(nChar, pFile)) == EOF) - { - Trace("ungetc: ERROR -> ungetc failed to push '%c' back onto the" - " stream.\n"); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - - /* read it again... hopefully */ - if (((nChar = getc(pFile)) == EOF) || (nChar != nRc)) - { - Trace("ungetc: ERROR -> getc encountered an error reading.\n"); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - - /* - ** test multiple ungetcs by replacing "foo" in the stream with "bar" - */ - - /* move the file pointer back to the beginning of the file */ - if (fseek(pFile, 0, SEEK_SET) != 0) - { - Trace("ungetc: ERROR -> fseek failed to move the file pointer to the " - "beginning of the file. GetLastError returned %ld\n", - GetLastError()); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - - /* read a few characters */ - for (i = 0; i < 3; i++) - { - if (getc(pFile) == EOF) - { - Trace("ungetc: ERROR -> getc encountered an error reading. " - "GetLastError returned %ld\n", - GetLastError()); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - } - - /* we just read "foo" so push "bar" back on the stream */ - for (i = 2; i >= 0; i--) - { - if ((nRc = ungetc(szNewString[i], pFile)) == EOF) - { - Trace("ungetc: ERROR -> ungetc failed to push '%c' back onto the" - " stream.\n"); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - } - - - /* read the new and improved stream - I use szNewString because it - is correct length */ - nCount = fread(szBuffer, sizeof(char), strlen(szNewString), pFile); - - /* did we get the right number of characters?*/ - if (nCount != strlen(szNewString)) - { - Trace("ungetc: ERROR -> fread read %d characters from the stream but" - " %d characters were expected\n", - nRc, - strlen(szNewString)); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - - /* did we get the right string? */ - if (strcmp(szBuffer, szNewString) != 0) - { - Trace("ungetc: ERROR -> fread returned \"%s\" but \"%s\" was " - "expected\n", - szBuffer, - szNewString); - if (fclose(pFile) != 0) - { - Trace("ungetc: ERROR -> fclose failed to close the file.\n"); - } - Fail(""); - } - - if (fclose(pFile) != 0) - { - Fail("ungetc: ERROR -> fclose failed to close the file.\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/ungetc/test2/ungetc.cpp b/src/pal/tests/palsuite/c_runtime/ungetc/test2/ungetc.cpp new file mode 100644 index 0000000000..cbc8102eec --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ungetc/test2/ungetc.cpp @@ -0,0 +1,188 @@ +// 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: ungetc.c (test 2) +** +** Purpose: Tests the PAL implementation of the ungetc function +** +** Dependencies: +** fopen +** fread +** fclose +** fseek +** getc +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + const char szFileName[] = {"test2.txt"}; + const char szNewString[] = {"bar bar"}; + char szBuffer[MAX_PATH]; + FILE* pFile = NULL; + int nChar = 32; /* space */ + int i = 0; + int nRc = 0; + size_t nCount = 0; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + memset(szBuffer, 0, MAX_PATH); + + /* + ** open the file in write only mode, populate it and + ** attempt to push an unread character back on the stream + */ + + + /* open the file for read */ + pFile = fopen(szFileName, "r"); + if (pFile == NULL) + { + Fail("ungetc: ERROR -> fopen failed to open the file \"%s\"" + " as read-only.n", + szFileName); + } + + + /* + ** Call getc to get the first char and ungetc to put + ** it back. getc should read it again. + */ + + /* read a character */ + if ((nChar = getc(pFile)) == EOF) + { + Trace("ungetc: ERROR -> getc encountered an error reading.\n"); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + + /* put it back */ + if ((nRc = ungetc(nChar, pFile)) == EOF) + { + Trace("ungetc: ERROR -> ungetc failed to push '%c' back onto the" + " stream.\n"); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + + /* read it again... hopefully */ + if (((nChar = getc(pFile)) == EOF) || (nChar != nRc)) + { + Trace("ungetc: ERROR -> getc encountered an error reading.\n"); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + + /* + ** test multiple ungetcs by replacing "foo" in the stream with "bar" + */ + + /* move the file pointer back to the beginning of the file */ + if (fseek(pFile, 0, SEEK_SET) != 0) + { + Trace("ungetc: ERROR -> fseek failed to move the file pointer to the " + "beginning of the file. GetLastError returned %ld\n", + GetLastError()); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + + /* read a few characters */ + for (i = 0; i < 3; i++) + { + if (getc(pFile) == EOF) + { + Trace("ungetc: ERROR -> getc encountered an error reading. " + "GetLastError returned %ld\n", + GetLastError()); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + } + + /* we just read "foo" so push "bar" back on the stream */ + for (i = 2; i >= 0; i--) + { + if ((nRc = ungetc(szNewString[i], pFile)) == EOF) + { + Trace("ungetc: ERROR -> ungetc failed to push '%c' back onto the" + " stream.\n"); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + } + + + /* read the new and improved stream - I use szNewString because it + is correct length */ + nCount = fread(szBuffer, sizeof(char), strlen(szNewString), pFile); + + /* did we get the right number of characters?*/ + if (nCount != strlen(szNewString)) + { + Trace("ungetc: ERROR -> fread read %d characters from the stream but" + " %d characters were expected\n", + nRc, + strlen(szNewString)); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + + /* did we get the right string? */ + if (strcmp(szBuffer, szNewString) != 0) + { + Trace("ungetc: ERROR -> fread returned \"%s\" but \"%s\" was " + "expected\n", + szBuffer, + szNewString); + if (fclose(pFile) != 0) + { + Trace("ungetc: ERROR -> fclose failed to close the file.\n"); + } + Fail(""); + } + + if (fclose(pFile) != 0) + { + Fail("ungetc: ERROR -> fclose failed to close the file.\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test1/CMakeLists.txt index 4c967fbc5b..fcff4a2074 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_vfprintf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test1/test1.c deleted file mode 100644 index 302c914e3a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test1/test1.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the vfprintf function. A single, basic, test -** case with no formatting. -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - -int __cdecl main(int argc, char *argv[]) -{ - FILE *fp; - char testfile[] = "testfile.txt"; - char buf[256]; - char checkstr[] = "hello world"; - int ret; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - if ((fp = fopen(testfile, "w+")) == NULL) - { - Fail("ERROR: fopen failed to create \"%s\"\n", testfile); - } - - ret = DoVfprintf(fp, "hello world"); - - if (ret != strlen(checkstr)) - { - Fail("Expected vfprintf to return %d, got %d.\n", - strlen(checkstr), ret); - - } - - if ((fseek(fp, 0, SEEK_SET)) != 0) - { - Fail("ERROR: Fseek failed to set pointer to beginning of file\n" ); - } - - if ((fgets(buf, 100, fp)) == NULL) - { - Fail("ERROR: fgets failed\n"); - } - if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) - { - Fail("ERROR: expected %s, got %s\n", checkstr, buf); - } - if ((fclose(fp)) != 0) - { - Fail("ERROR: fclose failed to close \"%s\"\n", testfile); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test1/test1.cpp new file mode 100644 index 0000000000..302c914e3a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test1/test1.cpp @@ -0,0 +1,68 @@ +// 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: test1.c +** +** Purpose: Test #1 for the vfprintf function. A single, basic, test +** case with no formatting. +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + +int __cdecl main(int argc, char *argv[]) +{ + FILE *fp; + char testfile[] = "testfile.txt"; + char buf[256]; + char checkstr[] = "hello world"; + int ret; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + if ((fp = fopen(testfile, "w+")) == NULL) + { + Fail("ERROR: fopen failed to create \"%s\"\n", testfile); + } + + ret = DoVfprintf(fp, "hello world"); + + if (ret != strlen(checkstr)) + { + Fail("Expected vfprintf to return %d, got %d.\n", + strlen(checkstr), ret); + + } + + if ((fseek(fp, 0, SEEK_SET)) != 0) + { + Fail("ERROR: Fseek failed to set pointer to beginning of file\n" ); + } + + if ((fgets(buf, 100, fp)) == NULL) + { + Fail("ERROR: fgets failed\n"); + } + if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) + { + Fail("ERROR: expected %s, got %s\n", checkstr, buf); + } + if ((fclose(fp)) != 0) + { + Fail("ERROR: fclose failed to close \"%s\"\n", testfile); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test10/CMakeLists.txt index e154107e36..97c7b167ab 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_vfprintf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test10/test10.c deleted file mode 100644 index ecb4b0314a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test10/test10.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test10.c -** -** Purpose: Test #10 for the vfprintf function. Tests the octal specifier -** (%o). -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %o", pos, "foo 52"); - DoNumTest("foo %lo", 0xFFFF, "foo 177777"); - DoNumTest("foo %ho", 0xFFFF, "foo 177777"); - DoNumTest("foo %Lo", pos, "foo 52"); - DoI64Test("foo %I64o", l, "42", "foo 52"); - DoNumTest("foo %3o", pos, "foo 52"); - DoNumTest("foo %-3o", pos, "foo 52 "); - DoNumTest("foo %.1o", pos, "foo 52"); - DoNumTest("foo %.3o", pos, "foo 052"); - DoNumTest("foo %03o", pos, "foo 052"); - DoNumTest("foo %#o", pos, "foo 052"); - DoNumTest("foo %+o", pos, "foo 52"); - DoNumTest("foo % o", pos, "foo 52"); - DoNumTest("foo %+o", neg, "foo 37777777726"); - DoNumTest("foo % o", neg, "foo 37777777726"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test10/test10.cpp new file mode 100644 index 0000000000..ecb4b0314a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test10/test10.cpp @@ -0,0 +1,52 @@ +// 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: test10.c +** +** Purpose: Test #10 for the vfprintf function. Tests the octal specifier +** (%o). +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %o", pos, "foo 52"); + DoNumTest("foo %lo", 0xFFFF, "foo 177777"); + DoNumTest("foo %ho", 0xFFFF, "foo 177777"); + DoNumTest("foo %Lo", pos, "foo 52"); + DoI64Test("foo %I64o", l, "42", "foo 52"); + DoNumTest("foo %3o", pos, "foo 52"); + DoNumTest("foo %-3o", pos, "foo 52 "); + DoNumTest("foo %.1o", pos, "foo 52"); + DoNumTest("foo %.3o", pos, "foo 052"); + DoNumTest("foo %03o", pos, "foo 052"); + DoNumTest("foo %#o", pos, "foo 052"); + DoNumTest("foo %+o", pos, "foo 52"); + DoNumTest("foo % o", pos, "foo 52"); + DoNumTest("foo %+o", neg, "foo 37777777726"); + DoNumTest("foo % o", neg, "foo 37777777726"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test11/CMakeLists.txt index f51f379bcd..9250eb957d 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_vfprintf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test11/test11.c deleted file mode 100644 index 5f7bc118cc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test11/test11.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test11.c -** -** Purpose: Test #11 for the vfprintf function. Test the unsigned int -** specifier (%u). -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %u", pos, "foo 42"); - DoNumTest("foo %lu", 0xFFFF, "foo 65535"); - DoNumTest("foo %hu", 0xFFFF, "foo 65535"); - DoNumTest("foo %Lu", pos, "foo 42"); - DoI64Test("foo %I64u", l, "42", "foo 42"); - DoNumTest("foo %3u", pos, "foo 42"); - DoNumTest("foo %-3u", pos, "foo 42 "); - DoNumTest("foo %.1u", pos, "foo 42"); - DoNumTest("foo %.3u", pos, "foo 042"); - DoNumTest("foo %03u", pos, "foo 042"); - DoNumTest("foo %#u", pos, "foo 42"); - DoNumTest("foo %+u", pos, "foo 42"); - DoNumTest("foo % u", pos, "foo 42"); - DoNumTest("foo %+u", neg, "foo 4294967254"); - DoNumTest("foo % u", neg, "foo 4294967254"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test11/test11.cpp new file mode 100644 index 0000000000..5f7bc118cc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test11/test11.cpp @@ -0,0 +1,51 @@ +// 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: test11.c +** +** Purpose: Test #11 for the vfprintf function. Test the unsigned int +** specifier (%u). +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %u", pos, "foo 42"); + DoNumTest("foo %lu", 0xFFFF, "foo 65535"); + DoNumTest("foo %hu", 0xFFFF, "foo 65535"); + DoNumTest("foo %Lu", pos, "foo 42"); + DoI64Test("foo %I64u", l, "42", "foo 42"); + DoNumTest("foo %3u", pos, "foo 42"); + DoNumTest("foo %-3u", pos, "foo 42 "); + DoNumTest("foo %.1u", pos, "foo 42"); + DoNumTest("foo %.3u", pos, "foo 042"); + DoNumTest("foo %03u", pos, "foo 042"); + DoNumTest("foo %#u", pos, "foo 42"); + DoNumTest("foo %+u", pos, "foo 42"); + DoNumTest("foo % u", pos, "foo 42"); + DoNumTest("foo %+u", neg, "foo 4294967254"); + DoNumTest("foo % u", neg, "foo 4294967254"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test12/CMakeLists.txt index 3ef68cff70..53d3488b4a 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_vfprintf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test12/test12.c deleted file mode 100644 index 0bf61d3ecc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test12/test12.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test12.c -** -** Purpose: Test #12 for the vfprintf function. Tests the (lowercase) -** hexadecimal specifier (%x) -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %x", pos, "foo 1234ab"); - DoNumTest("foo %lx", pos, "foo 1234ab"); - DoNumTest("foo %hx", pos, "foo 34ab"); - DoNumTest("foo %Lx", pos, "foo 1234ab"); - DoI64Test("foo %I64x", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7x", pos, "foo 1234ab"); - DoNumTest("foo %-7x", pos, "foo 1234ab "); - DoNumTest("foo %.1x", pos, "foo 1234ab"); - DoNumTest("foo %.7x", pos, "foo 01234ab"); - DoNumTest("foo %07x", pos, "foo 01234ab"); - DoNumTest("foo %#x", pos, "foo 0x1234ab"); - DoNumTest("foo %+x", pos, "foo 1234ab"); - DoNumTest("foo % x", pos, "foo 1234ab"); - DoNumTest("foo %+x", neg, "foo ffffffd6"); - DoNumTest("foo % x", neg, "foo ffffffd6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test12/test12.cpp new file mode 100644 index 0000000000..0bf61d3ecc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test12/test12.cpp @@ -0,0 +1,53 @@ +// 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: test12.c +** +** Purpose: Test #12 for the vfprintf function. Tests the (lowercase) +** hexadecimal specifier (%x) +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %x", pos, "foo 1234ab"); + DoNumTest("foo %lx", pos, "foo 1234ab"); + DoNumTest("foo %hx", pos, "foo 34ab"); + DoNumTest("foo %Lx", pos, "foo 1234ab"); + DoI64Test("foo %I64x", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7x", pos, "foo 1234ab"); + DoNumTest("foo %-7x", pos, "foo 1234ab "); + DoNumTest("foo %.1x", pos, "foo 1234ab"); + DoNumTest("foo %.7x", pos, "foo 01234ab"); + DoNumTest("foo %07x", pos, "foo 01234ab"); + DoNumTest("foo %#x", pos, "foo 0x1234ab"); + DoNumTest("foo %+x", pos, "foo 1234ab"); + DoNumTest("foo % x", pos, "foo 1234ab"); + DoNumTest("foo %+x", neg, "foo ffffffd6"); + DoNumTest("foo % x", neg, "foo ffffffd6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test13/CMakeLists.txt index cd34f6649c..c35813b420 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_vfprintf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test13/test13.c deleted file mode 100644 index 1e42ce9e8d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test13/test13.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test13.c -** -** Purpose: Test #13 for the vfprintf function. Tests the (uppercase) -** hexadecimal specifier (%X) -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234AB; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %X", pos, "foo 1234AB"); - DoNumTest("foo %lX", pos, "foo 1234AB"); - DoNumTest("foo %hX", pos, "foo 34AB"); - DoNumTest("foo %LX", pos, "foo 1234AB"); - DoI64Test("foo %I64X", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7X", pos, "foo 1234AB"); - DoNumTest("foo %-7X", pos, "foo 1234AB "); - DoNumTest("foo %.1X", pos, "foo 1234AB"); - DoNumTest("foo %.7X", pos, "foo 01234AB"); - DoNumTest("foo %07X", pos, "foo 01234AB"); - DoNumTest("foo %#X", pos, "foo 0X1234AB"); - DoNumTest("foo %+X", pos, "foo 1234AB"); - DoNumTest("foo % X", pos, "foo 1234AB"); - DoNumTest("foo %+X", neg, "foo FFFFFFD6"); - DoNumTest("foo % X", neg, "foo FFFFFFD6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test13/test13.cpp new file mode 100644 index 0000000000..1e42ce9e8d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test13/test13.cpp @@ -0,0 +1,54 @@ +// 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: test13.c +** +** Purpose: Test #13 for the vfprintf function. Tests the (uppercase) +** hexadecimal specifier (%X) +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234AB; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %X", pos, "foo 1234AB"); + DoNumTest("foo %lX", pos, "foo 1234AB"); + DoNumTest("foo %hX", pos, "foo 34AB"); + DoNumTest("foo %LX", pos, "foo 1234AB"); + DoI64Test("foo %I64X", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7X", pos, "foo 1234AB"); + DoNumTest("foo %-7X", pos, "foo 1234AB "); + DoNumTest("foo %.1X", pos, "foo 1234AB"); + DoNumTest("foo %.7X", pos, "foo 01234AB"); + DoNumTest("foo %07X", pos, "foo 01234AB"); + DoNumTest("foo %#X", pos, "foo 0X1234AB"); + DoNumTest("foo %+X", pos, "foo 1234AB"); + DoNumTest("foo % X", pos, "foo 1234AB"); + DoNumTest("foo %+X", neg, "foo FFFFFFD6"); + DoNumTest("foo % X", neg, "foo FFFFFFD6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test14/CMakeLists.txt index 396a4631c5..bd91f509b5 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_vfprintf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test14/test14.c deleted file mode 100644 index 82f247430f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test14/test14.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test14.c -** -** Purpose: Test #14 for the vfprintf function. Tests the lowercase -** exponential notation double specifier (%e) -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", - "foo 2.560000e+02 "); - DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); - DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", - "foo 2.56000000e+02"); - DoDoubleTest("foo %014e", val, "foo 02.560000e+002", - "foo 002.560000e+02"); - DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); - DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test14/test14.cpp new file mode 100644 index 0000000000..82f247430f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test14/test14.cpp @@ -0,0 +1,54 @@ +// 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: test14.c +** +** Purpose: Test #14 for the vfprintf function. Tests the lowercase +** exponential notation double specifier (%e) +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", + "foo 2.560000e+02 "); + DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); + DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", + "foo 2.56000000e+02"); + DoDoubleTest("foo %014e", val, "foo 02.560000e+002", + "foo 002.560000e+02"); + DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); + DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test15/CMakeLists.txt index b9ddbe3b4a..30003b82f8 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_vfprintf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test15/test15.c deleted file mode 100644 index 53cc2ceb87..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test15/test15.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test15.c -** -** Purpose: Test #15 for the vfprintf function. Tests the uppercase -** exponential notation double specifier (%E) -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", - "foo 2.560000E+02 "); - DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); - DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", - "foo 2.56000000E+02"); - DoDoubleTest("foo %014E", val, "foo 02.560000E+002", - "foo 002.560000E+02"); - DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); - DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test15/test15.cpp new file mode 100644 index 0000000000..53cc2ceb87 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test15/test15.cpp @@ -0,0 +1,54 @@ +// 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: test15.c +** +** Purpose: Test #15 for the vfprintf function. Tests the uppercase +** exponential notation double specifier (%E) +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", + "foo 2.560000E+02 "); + DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); + DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", + "foo 2.56000000E+02"); + DoDoubleTest("foo %014E", val, "foo 02.560000E+002", + "foo 002.560000E+02"); + DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); + DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test16/CMakeLists.txt index 0fd4177ed8..a287f120a0 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_vfprintf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test16/test16.c deleted file mode 100644 index 2b7674bb94..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test16/test16.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test16.c -** -** Purpose: Test #16 for the vfprintf function. Tests the decimal notation -** double specifier (%f) -** -** -**==========================================================================*/ - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); - DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); - DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); - DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); - DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); - DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); - DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test16/test16.cpp new file mode 100644 index 0000000000..2b7674bb94 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test16/test16.cpp @@ -0,0 +1,50 @@ +// 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: test16.c +** +** Purpose: Test #16 for the vfprintf function. Tests the decimal notation +** double specifier (%f) +** +** +**==========================================================================*/ + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); + DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); + DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); + DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); + DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); + DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); + DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test17/CMakeLists.txt index afc0b3828d..cf1afd9d2d 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_vfprintf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test17/test17.c deleted file mode 100644 index 956be15f6f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test17/test17.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test17.c -** -** Purpose: Test #17 for the vfprintf function. Tests the lowercase -** shorthand notation double specifier (%g) -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); - DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); - DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test17/test17.cpp new file mode 100644 index 0000000000..956be15f6f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test17/test17.cpp @@ -0,0 +1,52 @@ +// 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: test17.c +** +** Purpose: Test #17 for the vfprintf function. Tests the lowercase +** shorthand notation double specifier (%g) +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); + DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); + DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test18/CMakeLists.txt index 9e373b999e..143eade9b3 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test18.c + test18.cpp ) add_executable(paltest_vfprintf_test18 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test18/test18.c deleted file mode 100644 index c61c8cbdab..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test18/test18.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the vfprintf function. Tests the uppercase -** shorthand notation double specifier (%G) -** -** -**==========================================================================*/ - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); - DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); - DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test18/test18.cpp new file mode 100644 index 0000000000..c61c8cbdab --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test18/test18.cpp @@ -0,0 +1,51 @@ +// 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: test18.c +** +** Purpose: Test #18 for the vfprintf function. Tests the uppercase +** shorthand notation double specifier (%G) +** +** +**==========================================================================*/ + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); + DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); + DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test19/CMakeLists.txt index 3120c9117f..452d929b7d 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test19.c + test19.cpp ) add_executable(paltest_vfprintf_test19 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test19/test19.c deleted file mode 100644 index e88ce23663..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test19/test19.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: test19.c -** -** Purpose: Test #19 for the vfprintf function. Tests the variable length -** precision argument. -** -** -**==========================================================================*/ - - -#include -#include "../vfprintf.h" - - - - -int __cdecl main(int argc, char *argv[]) -{ - int n = -1; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoArgumentPrecTest("%.*s", 2, "bar", "bar", "ba", "ba"); - DoArgumentPrecTest("%.*S", 2, convert("bar"), "bar", "ba", "ba"); - - DoArgumentPrecTest("%.*n ", 3, &n, "pointer to int", " ", " "); - if (n != 0) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - 0, n); - } - - DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); - DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); - DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); - DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); - - - DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); - DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); - DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); - DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); - DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); - DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); - DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); - DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); - DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); - DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test19/test19.cpp new file mode 100644 index 0000000000..d8e8f9301d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test19/test19.cpp @@ -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: test19.c +** +** Purpose: Test #19 for the vfprintf function. Tests the variable length +** precision argument. +** +** +**==========================================================================*/ + + +#include +#include "../vfprintf.h" + + + + +int __cdecl main(int argc, char *argv[]) +{ + int n = -1; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoArgumentPrecTest("%.*s", 2, (void*)"bar", "bar", "ba", "ba"); + DoArgumentPrecTest("%.*S", 2, (void*)convert("bar"), "bar", "ba", "ba"); + + DoArgumentPrecTest("%.*n ", 3, (void*)&n, "pointer to int", " ", " "); + if (n != 0) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + 0, n); + } + + DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); + DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); + DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); + DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); + + + DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); + DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); + DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); + DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); + DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); + DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); + DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); + DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); + DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); + DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test2/CMakeLists.txt index 6e700090d6..b18fb712c6 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_vfprintf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test2/test2.c deleted file mode 100644 index d01117f047..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test2/test2.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the vfprintf function. Tests the string specifier -** (%s). -** -** -**==========================================================================*/ - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoStrTest("foo %s", "bar", "foo bar"); - DoStrTest("foo %hs", "bar", "foo bar"); - DoWStrTest("foo %ls", convert("bar"), "foo bar"); - DoWStrTest("foo %ws", convert("bar"), "foo bar"); - DoStrTest("foo %Ls", "bar", "foo bar"); - DoStrTest("foo %I64s", "bar", "foo bar"); - DoStrTest("foo %5s", "bar", "foo bar"); - DoStrTest("foo %.2s", "bar", "foo ba"); - DoStrTest("foo %5.2s", "bar", "foo ba"); - DoStrTest("foo %-5s", "bar", "foo bar "); - DoStrTest("foo %05s", "bar", "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test2/test2.cpp new file mode 100644 index 0000000000..d01117f047 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test2/test2.cpp @@ -0,0 +1,45 @@ +// 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: test2.c +** +** Purpose: Test #2 for the vfprintf function. Tests the string specifier +** (%s). +** +** +**==========================================================================*/ + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoStrTest("foo %s", "bar", "foo bar"); + DoStrTest("foo %hs", "bar", "foo bar"); + DoWStrTest("foo %ls", convert("bar"), "foo bar"); + DoWStrTest("foo %ws", convert("bar"), "foo bar"); + DoStrTest("foo %Ls", "bar", "foo bar"); + DoStrTest("foo %I64s", "bar", "foo bar"); + DoStrTest("foo %5s", "bar", "foo bar"); + DoStrTest("foo %.2s", "bar", "foo ba"); + DoStrTest("foo %5.2s", "bar", "foo ba"); + DoStrTest("foo %-5s", "bar", "foo bar "); + DoStrTest("foo %05s", "bar", "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test3/CMakeLists.txt index 1a14d85603..a8f7eb1991 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_vfprintf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test3/test3.c deleted file mode 100644 index 0081daa426..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test3/test3.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the vfprintf function. Tests the wide string -** specifier (%S). -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoWStrTest("foo %S", convert("bar"), "foo bar"); - DoStrTest("foo %hS", "bar", "foo bar"); - DoWStrTest("foo %lS", convert("bar"), "foo bar"); - DoWStrTest("foo %wS", convert("bar"), "foo bar"); - DoWStrTest("foo %LS", convert("bar"), "foo bar"); - DoWStrTest("foo %I64S", convert("bar"), "foo bar"); - DoWStrTest("foo %5S", convert("bar"), "foo bar"); - DoWStrTest("foo %.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %-5S", convert("bar"), "foo bar "); - DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test3/test3.cpp new file mode 100644 index 0000000000..0081daa426 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test3/test3.cpp @@ -0,0 +1,45 @@ +// 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: test3.c +** +** Purpose: Test #3 for the vfprintf function. Tests the wide string +** specifier (%S). +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoWStrTest("foo %S", convert("bar"), "foo bar"); + DoStrTest("foo %hS", "bar", "foo bar"); + DoWStrTest("foo %lS", convert("bar"), "foo bar"); + DoWStrTest("foo %wS", convert("bar"), "foo bar"); + DoWStrTest("foo %LS", convert("bar"), "foo bar"); + DoWStrTest("foo %I64S", convert("bar"), "foo bar"); + DoWStrTest("foo %5S", convert("bar"), "foo bar"); + DoWStrTest("foo %.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %-5S", convert("bar"), "foo bar "); + DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test4/CMakeLists.txt index c1285942bc..60c31693a5 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_vfprintf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test4/test4.c deleted file mode 100644 index d24f08d6e0..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test4/test4.c +++ /dev/null @@ -1,70 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the vfprintf function. Tests the pointer -** specifier (%p). -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "0000000000000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); - -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "00000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); - -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test4/test4.cpp new file mode 100644 index 0000000000..d24f08d6e0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test4/test4.cpp @@ -0,0 +1,70 @@ +// 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: test4.c +** +** Purpose: Test #4 for the vfprintf function. Tests the pointer +** specifier (%p). +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "0000000000000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); + +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "00000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); + +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test5/CMakeLists.txt index 0cccdfd630..5f516fec6a 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_vfprintf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test5/test5.c deleted file mode 100644 index 44f21b61db..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test5/test5.c +++ /dev/null @@ -1,60 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the vfprintf function. Tests the count specifier (%n). -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - - -int __cdecl main(int argc, char *argv[]) -{ - char *longStr = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - "%n bar"; - char *longResult = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - " bar"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoCountTest("foo %n bar", 4, "foo bar"); - DoCountTest(longStr, 257, longResult); - DoCountTest("fo%n bar", 2, "fo bar"); - DoCountTest("%n ", 0, " "); - DoCountTest("foo %#n bar", 4, "foo bar"); - DoCountTest("foo % n bar", 4, "foo bar"); - DoCountTest("foo %+n bar", 4, "foo bar"); - DoCountTest("foo %-n bar", 4, "foo bar"); - DoCountTest("foo %0n bar", 4, "foo bar"); - DoShortCountTest("foo %hn bar", 4, "foo bar"); - DoCountTest("foo %ln bar", 4, "foo bar"); - DoCountTest("foo %Ln bar", 4, "foo bar"); - DoCountTest("foo %I64n bar", 4, "foo bar"); - DoCountTest("foo %20.3n bar", 4, "foo bar"); - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test5/test5.cpp new file mode 100644 index 0000000000..44f21b61db --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test5/test5.cpp @@ -0,0 +1,60 @@ +// 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: test5.c +** +** Purpose: Test #5 for the vfprintf function. Tests the count specifier (%n). +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + + +int __cdecl main(int argc, char *argv[]) +{ + char *longStr = + "really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + "%n bar"; + char *longResult = + "really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + " bar"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoCountTest("foo %n bar", 4, "foo bar"); + DoCountTest(longStr, 257, longResult); + DoCountTest("fo%n bar", 2, "fo bar"); + DoCountTest("%n ", 0, " "); + DoCountTest("foo %#n bar", 4, "foo bar"); + DoCountTest("foo % n bar", 4, "foo bar"); + DoCountTest("foo %+n bar", 4, "foo bar"); + DoCountTest("foo %-n bar", 4, "foo bar"); + DoCountTest("foo %0n bar", 4, "foo bar"); + DoShortCountTest("foo %hn bar", 4, "foo bar"); + DoCountTest("foo %ln bar", 4, "foo bar"); + DoCountTest("foo %Ln bar", 4, "foo bar"); + DoCountTest("foo %I64n bar", 4, "foo bar"); + DoCountTest("foo %20.3n bar", 4, "foo bar"); + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test6/CMakeLists.txt index 2c036a45ae..7f0cc710af 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_vfprintf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test6/test6.c deleted file mode 100644 index 36c6fe51ca..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test6/test6.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the vfprintf function. Tests the char specifier (%c). -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoCharTest("foo %c", 'b', "foo b"); - DoCharTest("foo %hc", 'b', "foo b"); - DoWCharTest("foo %lc", wc, "foo c"); - DoCharTest("foo %Lc", 'b', "foo b"); - DoCharTest("foo %I64c", 'b', "foo b"); - DoCharTest("foo %5c", 'b', "foo b"); - DoCharTest("foo %.0c", 'b', "foo b"); - DoCharTest("foo %-5c", 'b', "foo b "); - DoCharTest("foo %05c", 'b', "foo 0000b"); - DoCharTest("foo % c", 'b', "foo b"); - DoCharTest("foo %#c", 'b', "foo b"); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test6/test6.cpp new file mode 100644 index 0000000000..36c6fe51ca --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test6/test6.cpp @@ -0,0 +1,48 @@ +// 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: test6.c +** +** Purpose: Test #6 for the vfprintf function. Tests the char specifier (%c). +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoCharTest("foo %c", 'b', "foo b"); + DoCharTest("foo %hc", 'b', "foo b"); + DoWCharTest("foo %lc", wc, "foo c"); + DoCharTest("foo %Lc", 'b', "foo b"); + DoCharTest("foo %I64c", 'b', "foo b"); + DoCharTest("foo %5c", 'b', "foo b"); + DoCharTest("foo %.0c", 'b', "foo b"); + DoCharTest("foo %-5c", 'b', "foo b "); + DoCharTest("foo %05c", 'b', "foo 0000b"); + DoCharTest("foo % c", 'b', "foo b"); + DoCharTest("foo %#c", 'b', "foo b"); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test7/CMakeLists.txt index ca483af773..a2cd9a2e8f 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_vfprintf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test7/test7.c deleted file mode 100644 index a9cfe319bd..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test7/test7.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test7.c -** -** Purpose: Test #7 for the vfprintf function. Tests the wide char -** specifier (%C). -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoWCharTest("foo %C", wb, "foo b"); - DoWCharTest("foo %hC", wb, "foo b"); - DoCharTest("foo %lC", 'c', "foo c"); - DoWCharTest("foo %LC", wb, "foo b"); - DoWCharTest("foo %I64C", wb, "foo b"); - DoWCharTest("foo %5C", wb, "foo b"); - DoWCharTest("foo %.0C", wb, "foo b"); - DoWCharTest("foo %-5C", wb, "foo b "); - DoWCharTest("foo %05C", wb, "foo 0000b"); - DoWCharTest("foo % C", wb, "foo b"); - DoWCharTest("foo %#C", wb, "foo b"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test7/test7.cpp new file mode 100644 index 0000000000..a9cfe319bd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test7/test7.cpp @@ -0,0 +1,47 @@ +// 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: test7.c +** +** Purpose: Test #7 for the vfprintf function. Tests the wide char +** specifier (%C). +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoWCharTest("foo %C", wb, "foo b"); + DoWCharTest("foo %hC", wb, "foo b"); + DoCharTest("foo %lC", 'c', "foo c"); + DoWCharTest("foo %LC", wb, "foo b"); + DoWCharTest("foo %I64C", wb, "foo b"); + DoWCharTest("foo %5C", wb, "foo b"); + DoWCharTest("foo %.0C", wb, "foo b"); + DoWCharTest("foo %-5C", wb, "foo b "); + DoWCharTest("foo %05C", wb, "foo 0000b"); + DoWCharTest("foo % C", wb, "foo b"); + DoWCharTest("foo %#C", wb, "foo b"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test8/CMakeLists.txt index 89459b4e93..a7b20ee43e 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_vfprintf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test8/test8.c deleted file mode 100644 index 5cef99741a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test8/test8.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test8.c -** -** Purpose: Test #8 for the vfprintf function. Tests the decimal -** specifier (%d). -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %d", pos, "foo 42"); - DoNumTest("foo %ld", 0xFFFF, "foo 65535"); - DoNumTest("foo %hd", 0xFFFF, "foo -1"); - DoNumTest("foo %Ld", pos, "foo 42"); - DoI64Test("foo %I64d", l, "42", "foo 42"); - DoNumTest("foo %3d", pos, "foo 42"); - DoNumTest("foo %-3d", pos, "foo 42 "); - DoNumTest("foo %.1d", pos, "foo 42"); - DoNumTest("foo %.3d", pos, "foo 042"); - DoNumTest("foo %03d", pos, "foo 042"); - DoNumTest("foo %#d", pos, "foo 42"); - DoNumTest("foo %+d", pos, "foo +42"); - DoNumTest("foo % d", pos, "foo 42"); - DoNumTest("foo %+d", neg, "foo -42"); - DoNumTest("foo % d", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test8/test8.cpp new file mode 100644 index 0000000000..5cef99741a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test8/test8.cpp @@ -0,0 +1,53 @@ +// 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: test8.c +** +** Purpose: Test #8 for the vfprintf function. Tests the decimal +** specifier (%d). +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %d", pos, "foo 42"); + DoNumTest("foo %ld", 0xFFFF, "foo 65535"); + DoNumTest("foo %hd", 0xFFFF, "foo -1"); + DoNumTest("foo %Ld", pos, "foo 42"); + DoI64Test("foo %I64d", l, "42", "foo 42"); + DoNumTest("foo %3d", pos, "foo 42"); + DoNumTest("foo %-3d", pos, "foo 42 "); + DoNumTest("foo %.1d", pos, "foo 42"); + DoNumTest("foo %.3d", pos, "foo 042"); + DoNumTest("foo %03d", pos, "foo 042"); + DoNumTest("foo %#d", pos, "foo 42"); + DoNumTest("foo %+d", pos, "foo +42"); + DoNumTest("foo % d", pos, "foo 42"); + DoNumTest("foo %+d", neg, "foo -42"); + DoNumTest("foo % d", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vfprintf/test9/CMakeLists.txt index 3e3b5b99ed..242b635f93 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_vfprintf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/vfprintf/test9/test9.c deleted file mode 100644 index 45d0dc7a9e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/test9/test9.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test9.c -** -** Purpose: Test #9 for the vfprintf function. Tests the integer -** specifier (%i). -** -** -**==========================================================================*/ - - - -#include -#include "../vfprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %i", pos, "foo 42"); - DoNumTest("foo %li", 0xFFFF, "foo 65535"); - DoNumTest("foo %hi", 0xFFFF, "foo -1"); - DoNumTest("foo %Li", pos, "foo 42"); - DoI64Test("foo %I64i", l, "42", "foo 42"); - DoNumTest("foo %3i", pos, "foo 42"); - DoNumTest("foo %-3i", pos, "foo 42 "); - DoNumTest("foo %.1i", pos, "foo 42"); - DoNumTest("foo %.3i", pos, "foo 042"); - DoNumTest("foo %03i", pos, "foo 042"); - DoNumTest("foo %#i", pos, "foo 42"); - DoNumTest("foo %+i", pos, "foo +42"); - DoNumTest("foo % i", pos, "foo 42"); - DoNumTest("foo %+i", neg, "foo -42"); - DoNumTest("foo % i", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/vfprintf/test9/test9.cpp new file mode 100644 index 0000000000..45d0dc7a9e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/test9/test9.cpp @@ -0,0 +1,53 @@ +// 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: test9.c +** +** Purpose: Test #9 for the vfprintf function. Tests the integer +** specifier (%i). +** +** +**==========================================================================*/ + + + +#include +#include "../vfprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %i", pos, "foo 42"); + DoNumTest("foo %li", 0xFFFF, "foo 65535"); + DoNumTest("foo %hi", 0xFFFF, "foo -1"); + DoNumTest("foo %Li", pos, "foo 42"); + DoI64Test("foo %I64i", l, "42", "foo 42"); + DoNumTest("foo %3i", pos, "foo 42"); + DoNumTest("foo %-3i", pos, "foo 42 "); + DoNumTest("foo %.1i", pos, "foo 42"); + DoNumTest("foo %.3i", pos, "foo 042"); + DoNumTest("foo %03i", pos, "foo 042"); + DoNumTest("foo %#i", pos, "foo 42"); + DoNumTest("foo %+i", pos, "foo +42"); + DoNumTest("foo % i", pos, "foo 42"); + DoNumTest("foo %+i", neg, "foo -42"); + DoNumTest("foo % i", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vfprintf/vfprintf.h b/src/pal/tests/palsuite/c_runtime/vfprintf/vfprintf.h index f4ae7a53fa..7901b08b0d 100644 --- a/src/pal/tests/palsuite/c_runtime/vfprintf/vfprintf.h +++ b/src/pal/tests/palsuite/c_runtime/vfprintf/vfprintf.h @@ -14,7 +14,7 @@ #ifndef __vfprintf_H__ #define __vfprintf_H__ -int DoVfprintf(FILE *fp, char *format, ...) +int DoVfprintf(FILE *fp, const char *format, ...) { int retVal; va_list arglist; @@ -26,7 +26,7 @@ int DoVfprintf(FILE *fp, char *format, ...) return (retVal); } -void DoStrTest(char *formatstr, char* param, char *checkstr) +void DoStrTest(const char *formatstr, char* param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -57,7 +57,7 @@ void DoStrTest(char *formatstr, char* param, char *checkstr) fclose(fp); } -void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) +void DoWStrTest(const char *formatstr, WCHAR* param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -89,8 +89,8 @@ void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) } -void DoPointerTest(char *formatstr, void* param, char* paramstr, - char *checkstr1) +void DoPointerTest(const char *formatstr, void* param, char* paramstr, + const char *checkstr1) { FILE *fp; char buf[256] = { 0 }; @@ -130,7 +130,7 @@ void DoPointerTest(char *formatstr, void* param, char* paramstr, -void DoCountTest(char *formatstr, int param, char *checkstr) +void DoCountTest(const char *formatstr, int param, const char *checkstr) { FILE *fp; char buf[512] = { 0 }; @@ -173,7 +173,7 @@ void DoCountTest(char *formatstr, int param, char *checkstr) } } -void DoShortCountTest(char *formatstr, int param, char *checkstr) +void DoShortCountTest(const char *formatstr, int param, const char *checkstr) { FILE *fp; char buf[512] = { 0 }; @@ -217,7 +217,7 @@ void DoShortCountTest(char *formatstr, int param, char *checkstr) } -void DoCharTest(char *formatstr, char param, char *checkstr) +void DoCharTest(const char *formatstr, char param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -248,7 +248,7 @@ void DoCharTest(char *formatstr, char param, char *checkstr) fclose(fp); } -void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) +void DoWCharTest(const char *formatstr, WCHAR param, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -279,7 +279,7 @@ void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) fclose(fp); } -void DoNumTest(char *formatstr, int value, char *checkstr) +void DoNumTest(const char *formatstr, int value, const char *checkstr) { FILE *fp; char buf[256] = { 0 }; @@ -310,7 +310,7 @@ void DoNumTest(char *formatstr, int value, char *checkstr) fclose(fp); } -void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr1) +void DoI64Test(const char *formatstr, INT64 value, char *valuestr, const char *checkstr1) { FILE *fp; char buf[256] = { 0 }; @@ -341,8 +341,8 @@ void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr1) fclose(fp); } -void DoDoubleTest(char *formatstr, double value, char *checkstr1, - char *checkstr2) +void DoDoubleTest(const char *formatstr, double value, const char *checkstr1, + const char *checkstr2) { FILE *fp; char buf[256] = { 0 }; @@ -376,8 +376,8 @@ void DoDoubleTest(char *formatstr, double value, char *checkstr1, } -void DoArgumentPrecTest(char *formatstr, int precision, void *param, - char *paramstr, char *checkstr1, char *checkstr2) +void DoArgumentPrecTest(const char *formatstr, int precision, void *param, + char *paramstr, const char *checkstr1, const char *checkstr2) { FILE *fp; char buf[256]; @@ -418,8 +418,8 @@ void DoArgumentPrecTest(char *formatstr, int precision, void *param, } -void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param, - char *checkstr1, char *checkstr2) +void DoArgumentPrecDoubleTest(const char *formatstr, int precision, double param, + const char *checkstr1, const char *checkstr2) { FILE *fp; char buf[256]; diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test1/CMakeLists.txt index eabdf87393..9d866e16a2 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_vprintf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/vprintf/test1/test1.c deleted file mode 100644 index 404d7a0dc9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test1/test1.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the vprintf function. A single, basic, test -** case with no formatting. -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - -int __cdecl main(int argc, char *argv[]) -{ - char checkstr[] = "hello world"; - int ret; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - ret = vprintf("hello world", NULL); - - if (ret != strlen(checkstr)) - { - Fail("Expected vprintf to return %d, got %d.\n", - strlen(checkstr), ret); - - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test1/test1.cpp new file mode 100644 index 0000000000..404d7a0dc9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test1/test1.cpp @@ -0,0 +1,43 @@ +// 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: test1.c +** +** Purpose: Test #1 for the vprintf function. A single, basic, test +** case with no formatting. +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + +int __cdecl main(int argc, char *argv[]) +{ + char checkstr[] = "hello world"; + int ret; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + ret = vprintf("hello world", NULL); + + if (ret != strlen(checkstr)) + { + Fail("Expected vprintf to return %d, got %d.\n", + strlen(checkstr), ret); + + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test10/CMakeLists.txt index 47a21d909a..4ed04b46c6 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_vprintf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/vprintf/test10/test10.c deleted file mode 100644 index b363d7c02c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test10/test10.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test10.c -** -** Purpose: Test #10 for the vprintf function. Tests the octal specifier -** (%o). -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %o", pos, "foo 52"); - DoNumTest("foo %lo", 0xFFFF, "foo 177777"); - DoNumTest("foo %ho", 0xFFFF, "foo 177777"); - DoNumTest("foo %Lo", pos, "foo 52"); - DoI64Test("foo %I64o", l, "42", "foo 52"); - DoNumTest("foo %3o", pos, "foo 52"); - DoNumTest("foo %-3o", pos, "foo 52 "); - DoNumTest("foo %.1o", pos, "foo 52"); - DoNumTest("foo %.3o", pos, "foo 052"); - DoNumTest("foo %03o", pos, "foo 052"); - DoNumTest("foo %#o", pos, "foo 052"); - DoNumTest("foo %+o", pos, "foo 52"); - DoNumTest("foo % o", pos, "foo 52"); - DoNumTest("foo %+o", neg, "foo 37777777726"); - DoNumTest("foo % o", neg, "foo 37777777726"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test10/test10.cpp new file mode 100644 index 0000000000..b363d7c02c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test10/test10.cpp @@ -0,0 +1,52 @@ +// 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: test10.c +** +** Purpose: Test #10 for the vprintf function. Tests the octal specifier +** (%o). +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %o", pos, "foo 52"); + DoNumTest("foo %lo", 0xFFFF, "foo 177777"); + DoNumTest("foo %ho", 0xFFFF, "foo 177777"); + DoNumTest("foo %Lo", pos, "foo 52"); + DoI64Test("foo %I64o", l, "42", "foo 52"); + DoNumTest("foo %3o", pos, "foo 52"); + DoNumTest("foo %-3o", pos, "foo 52 "); + DoNumTest("foo %.1o", pos, "foo 52"); + DoNumTest("foo %.3o", pos, "foo 052"); + DoNumTest("foo %03o", pos, "foo 052"); + DoNumTest("foo %#o", pos, "foo 052"); + DoNumTest("foo %+o", pos, "foo 52"); + DoNumTest("foo % o", pos, "foo 52"); + DoNumTest("foo %+o", neg, "foo 37777777726"); + DoNumTest("foo % o", neg, "foo 37777777726"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test11/CMakeLists.txt index 4c750b72ac..5dc3c6dc69 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_vprintf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/vprintf/test11/test11.c deleted file mode 100644 index f5157ac99f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test11/test11.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test11.c -** -** Purpose: Test #11 for the vprintf function. Test the unsigned int -** specifier (%u). -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %u", pos, "foo 42"); - DoNumTest("foo %lu", 0xFFFF, "foo 65535"); - DoNumTest("foo %hu", 0xFFFF, "foo 65535"); - DoNumTest("foo %Lu", pos, "foo 42"); - DoI64Test("foo %I64u", l, "42", "foo 42"); - DoNumTest("foo %3u", pos, "foo 42"); - DoNumTest("foo %-3u", pos, "foo 42 "); - DoNumTest("foo %.1u", pos, "foo 42"); - DoNumTest("foo %.3u", pos, "foo 042"); - DoNumTest("foo %03u", pos, "foo 042"); - DoNumTest("foo %#u", pos, "foo 42"); - DoNumTest("foo %+u", pos, "foo 42"); - DoNumTest("foo % u", pos, "foo 42"); - DoNumTest("foo %+u", neg, "foo 4294967254"); - DoNumTest("foo % u", neg, "foo 4294967254"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test11/test11.cpp new file mode 100644 index 0000000000..f5157ac99f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test11/test11.cpp @@ -0,0 +1,51 @@ +// 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: test11.c +** +** Purpose: Test #11 for the vprintf function. Test the unsigned int +** specifier (%u). +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %u", pos, "foo 42"); + DoNumTest("foo %lu", 0xFFFF, "foo 65535"); + DoNumTest("foo %hu", 0xFFFF, "foo 65535"); + DoNumTest("foo %Lu", pos, "foo 42"); + DoI64Test("foo %I64u", l, "42", "foo 42"); + DoNumTest("foo %3u", pos, "foo 42"); + DoNumTest("foo %-3u", pos, "foo 42 "); + DoNumTest("foo %.1u", pos, "foo 42"); + DoNumTest("foo %.3u", pos, "foo 042"); + DoNumTest("foo %03u", pos, "foo 042"); + DoNumTest("foo %#u", pos, "foo 42"); + DoNumTest("foo %+u", pos, "foo 42"); + DoNumTest("foo % u", pos, "foo 42"); + DoNumTest("foo %+u", neg, "foo 4294967254"); + DoNumTest("foo % u", neg, "foo 4294967254"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test12/CMakeLists.txt index 1feb886fc1..a8104296c4 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_vprintf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/vprintf/test12/test12.c deleted file mode 100644 index 703a8c4fdc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test12/test12.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test12.c -** -** Purpose: Test #12 for the vprintf function. Tests the (lowercase) -** hexadecimal specifier (%x) -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %x", pos, "foo 1234ab"); - DoNumTest("foo %lx", pos, "foo 1234ab"); - DoNumTest("foo %hx", pos, "foo 34ab"); - DoNumTest("foo %Lx", pos, "foo 1234ab"); - DoI64Test("foo %I64x", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7x", pos, "foo 1234ab"); - DoNumTest("foo %-7x", pos, "foo 1234ab "); - DoNumTest("foo %.1x", pos, "foo 1234ab"); - DoNumTest("foo %.7x", pos, "foo 01234ab"); - DoNumTest("foo %07x", pos, "foo 01234ab"); - DoNumTest("foo %#x", pos, "foo 0x1234ab"); - DoNumTest("foo %+x", pos, "foo 1234ab"); - DoNumTest("foo % x", pos, "foo 1234ab"); - DoNumTest("foo %+x", neg, "foo ffffffd6"); - DoNumTest("foo % x", neg, "foo ffffffd6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test12/test12.cpp new file mode 100644 index 0000000000..703a8c4fdc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test12/test12.cpp @@ -0,0 +1,53 @@ +// 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: test12.c +** +** Purpose: Test #12 for the vprintf function. Tests the (lowercase) +** hexadecimal specifier (%x) +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %x", pos, "foo 1234ab"); + DoNumTest("foo %lx", pos, "foo 1234ab"); + DoNumTest("foo %hx", pos, "foo 34ab"); + DoNumTest("foo %Lx", pos, "foo 1234ab"); + DoI64Test("foo %I64x", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7x", pos, "foo 1234ab"); + DoNumTest("foo %-7x", pos, "foo 1234ab "); + DoNumTest("foo %.1x", pos, "foo 1234ab"); + DoNumTest("foo %.7x", pos, "foo 01234ab"); + DoNumTest("foo %07x", pos, "foo 01234ab"); + DoNumTest("foo %#x", pos, "foo 0x1234ab"); + DoNumTest("foo %+x", pos, "foo 1234ab"); + DoNumTest("foo % x", pos, "foo 1234ab"); + DoNumTest("foo %+x", neg, "foo ffffffd6"); + DoNumTest("foo % x", neg, "foo ffffffd6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test13/CMakeLists.txt index cd7535a1ad..df98081ed7 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_vprintf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/vprintf/test13/test13.c deleted file mode 100644 index ecb83ba38d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test13/test13.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test13.c -** -** Purpose: Test #13 for the vprintf function. Tests the (uppercase) -** hexadecimal specifier (%X) -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234AB; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %X", pos, "foo 1234AB"); - DoNumTest("foo %lX", pos, "foo 1234AB"); - DoNumTest("foo %hX", pos, "foo 34AB"); - DoNumTest("foo %LX", pos, "foo 1234AB"); - DoI64Test("foo %I64X", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7X", pos, "foo 1234AB"); - DoNumTest("foo %-7X", pos, "foo 1234AB "); - DoNumTest("foo %.1X", pos, "foo 1234AB"); - DoNumTest("foo %.7X", pos, "foo 01234AB"); - DoNumTest("foo %07X", pos, "foo 01234AB"); - DoNumTest("foo %#X", pos, "foo 0X1234AB"); - DoNumTest("foo %+X", pos, "foo 1234AB"); - DoNumTest("foo % X", pos, "foo 1234AB"); - DoNumTest("foo %+X", neg, "foo FFFFFFD6"); - DoNumTest("foo % X", neg, "foo FFFFFFD6"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test13/test13.cpp new file mode 100644 index 0000000000..ecb83ba38d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test13/test13.cpp @@ -0,0 +1,54 @@ +// 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: test13.c +** +** Purpose: Test #13 for the vprintf function. Tests the (uppercase) +** hexadecimal specifier (%X) +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234AB; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %X", pos, "foo 1234AB"); + DoNumTest("foo %lX", pos, "foo 1234AB"); + DoNumTest("foo %hX", pos, "foo 34AB"); + DoNumTest("foo %LX", pos, "foo 1234AB"); + DoI64Test("foo %I64X", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7X", pos, "foo 1234AB"); + DoNumTest("foo %-7X", pos, "foo 1234AB "); + DoNumTest("foo %.1X", pos, "foo 1234AB"); + DoNumTest("foo %.7X", pos, "foo 01234AB"); + DoNumTest("foo %07X", pos, "foo 01234AB"); + DoNumTest("foo %#X", pos, "foo 0X1234AB"); + DoNumTest("foo %+X", pos, "foo 1234AB"); + DoNumTest("foo % X", pos, "foo 1234AB"); + DoNumTest("foo %+X", neg, "foo FFFFFFD6"); + DoNumTest("foo % X", neg, "foo FFFFFFD6"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test14/CMakeLists.txt index 82cfd68ecf..b903d4e241 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_vprintf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/vprintf/test14/test14.c deleted file mode 100644 index 536c1950e3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test14/test14.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test14.c -** -** Purpose: Test #14 for the vprintf function. Tests the lowercase -** exponential notation double specifier (%e) -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", - "foo 2.560000e+02 "); - DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); - DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", - "foo 2.56000000e+02"); - DoDoubleTest("foo %014e", val, "foo 02.560000e+002", - "foo 002.560000e+02"); - DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); - DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test14/test14.cpp new file mode 100644 index 0000000000..536c1950e3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test14/test14.cpp @@ -0,0 +1,54 @@ +// 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: test14.c +** +** Purpose: Test #14 for the vprintf function. Tests the lowercase +** exponential notation double specifier (%e) +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", + "foo 2.560000e+02 "); + DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); + DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", + "foo 2.56000000e+02"); + DoDoubleTest("foo %014e", val, "foo 02.560000e+002", + "foo 002.560000e+02"); + DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); + DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test15/CMakeLists.txt index 29a134d48c..659ed9cb44 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_vprintf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/vprintf/test15/test15.c deleted file mode 100644 index 9aff6e457d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test15/test15.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test15.c -** -** Purpose: Test #15 for the vprintf function. Tests the uppercase -** exponential notation double specifier (%E) -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", - "foo 2.560000E+02 "); - DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); - DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", - "foo 2.56000000E+02"); - DoDoubleTest("foo %014E", val, "foo 02.560000E+002", - "foo 002.560000E+02"); - DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); - DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); - DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test15/test15.cpp new file mode 100644 index 0000000000..9aff6e457d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test15/test15.cpp @@ -0,0 +1,54 @@ +// 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: test15.c +** +** Purpose: Test #15 for the vprintf function. Tests the uppercase +** exponential notation double specifier (%E) +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %lE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %hE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %LE", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %14E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", + "foo 2.560000E+02 "); + DoDoubleTest("foo %.1E", val, "foo 2.6E+002", "foo 2.6E+02"); + DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", + "foo 2.56000000E+02"); + DoDoubleTest("foo %014E", val, "foo 02.560000E+002", + "foo 002.560000E+02"); + DoDoubleTest("foo %#E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", val, "foo +2.560000E+002", "foo +2.560000E+02"); + DoDoubleTest("foo % E", val, "foo 2.560000E+002", "foo 2.560000E+02"); + DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + DoDoubleTest("foo % E", neg, "foo -2.560000E+002", "foo -2.560000E+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test16/CMakeLists.txt index 7fbf43ac84..b2f7fe8b78 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_vprintf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/vprintf/test16/test16.c deleted file mode 100644 index 66e9afe2d7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test16/test16.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test16.c -** -** Purpose: Test #16 for the vprintf function. Tests the decimal notation -** double specifier (%f) -** -** -**==========================================================================*/ - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); - DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); - DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); - DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); - DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); - DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); - DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test16/test16.cpp new file mode 100644 index 0000000000..66e9afe2d7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test16/test16.cpp @@ -0,0 +1,50 @@ +// 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: test16.c +** +** Purpose: Test #16 for the vprintf function. Tests the decimal notation +** double specifier (%f) +** +** +**==========================================================================*/ + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); + DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); + DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); + DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); + DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); + DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); + DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test17/CMakeLists.txt index 25970cba15..76cfc9ad06 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_vprintf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/vprintf/test17/test17.c deleted file mode 100644 index d36a084903..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test17/test17.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test17.c -** -** Purpose: Test #17 for the vprintf function. Tests the lowercase -** shorthand notation double specifier (%g) -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); - DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); - DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test17/test17.cpp new file mode 100644 index 0000000000..d36a084903 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test17/test17.cpp @@ -0,0 +1,52 @@ +// 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: test17.c +** +** Purpose: Test #17 for the vprintf function. Tests the lowercase +** shorthand notation double specifier (%g) +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); + DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); + DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test18/CMakeLists.txt index 45676b93dd..633fb7ee51 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test18.c + test18.cpp ) add_executable(paltest_vprintf_test18 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/vprintf/test18/test18.c deleted file mode 100644 index 6fde79b5fb..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test18/test18.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the vprintf function. Tests the uppercase -** shorthand notation double specifier (%G) -** -** -**==========================================================================*/ - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); - DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); - DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test18/test18.cpp new file mode 100644 index 0000000000..6fde79b5fb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test18/test18.cpp @@ -0,0 +1,51 @@ +// 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: test18.c +** +** Purpose: Test #18 for the vprintf function. Tests the uppercase +** shorthand notation double specifier (%G) +** +** +**==========================================================================*/ + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); + DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); + DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test19/CMakeLists.txt index 25bc2fccd1..1a6256ad0b 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test19.c + test19.cpp ) add_executable(paltest_vprintf_test19 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/vprintf/test19/test19.c deleted file mode 100644 index d79f2e2591..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test19/test19.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: test19.c -** -** Purpose: Test #19 for the vprintf function. Tests the variable length -** precision argument. -** -** -**==========================================================================*/ - - -#include -#include "../vprintf.h" - - - - -int __cdecl main(int argc, char *argv[]) -{ - int n = -1; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoArgumentPrecTest("%.*s", 2, "bar", "bar", "ba", "ba"); - DoArgumentPrecTest("%.*S", 2, convert("bar"), "bar", "ba", "ba"); - - DoArgumentPrecTest("%.*n", 3, &n, "pointer to int", "", ""); - if (n != 0) - { - Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", - 0, n); - } - - DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); - DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); - DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); - DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); - - - DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); - DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); - DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); - DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); - DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); - DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); - DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); - DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); - DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); - DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test19/test19.cpp new file mode 100644 index 0000000000..a3e0877369 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test19/test19.cpp @@ -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: test19.c +** +** Purpose: Test #19 for the vprintf function. Tests the variable length +** precision argument. +** +** +**==========================================================================*/ + + +#include +#include "../vprintf.h" + + + + +int __cdecl main(int argc, char *argv[]) +{ + int n = -1; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoArgumentPrecTest("%.*s", 2, (void*)"bar", "bar", "ba", "ba"); + DoArgumentPrecTest("%.*S", 2, (void*)convert("bar"), "bar", "ba", "ba"); + + DoArgumentPrecTest("%.*n", 3, (void*)&n, "pointer to int", "", ""); + if (n != 0) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", + 0, n); + } + + DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); + DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); + DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); + DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); + + + DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); + DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); + DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); + DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); + DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); + DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); + DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); + DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); + DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); + DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test2/CMakeLists.txt index 6820069cb9..41e2073477 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_vprintf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/vprintf/test2/test2.c deleted file mode 100644 index 4d9c9bc6f5..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test2/test2.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the vprintf function. Tests the string specifier -** (%s). -** -** -**==========================================================================*/ - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoStrTest("foo %s", "bar", "foo bar"); - DoStrTest("foo %hs", "bar", "foo bar"); - DoWStrTest("foo %ls", convert("bar"), "foo bar"); - DoWStrTest("foo %ws", convert("bar"), "foo bar"); - DoStrTest("foo %Ls", "bar", "foo bar"); - DoStrTest("foo %I64s", "bar", "foo bar"); - DoStrTest("foo %5s", "bar", "foo bar"); - DoStrTest("foo %.2s", "bar", "foo ba"); - DoStrTest("foo %5.2s", "bar", "foo ba"); - DoStrTest("foo %-5s", "bar", "foo bar "); - DoStrTest("foo %05s", "bar", "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test2/test2.cpp new file mode 100644 index 0000000000..4d9c9bc6f5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test2/test2.cpp @@ -0,0 +1,45 @@ +// 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: test2.c +** +** Purpose: Test #2 for the vprintf function. Tests the string specifier +** (%s). +** +** +**==========================================================================*/ + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoStrTest("foo %s", "bar", "foo bar"); + DoStrTest("foo %hs", "bar", "foo bar"); + DoWStrTest("foo %ls", convert("bar"), "foo bar"); + DoWStrTest("foo %ws", convert("bar"), "foo bar"); + DoStrTest("foo %Ls", "bar", "foo bar"); + DoStrTest("foo %I64s", "bar", "foo bar"); + DoStrTest("foo %5s", "bar", "foo bar"); + DoStrTest("foo %.2s", "bar", "foo ba"); + DoStrTest("foo %5.2s", "bar", "foo ba"); + DoStrTest("foo %-5s", "bar", "foo bar "); + DoStrTest("foo %05s", "bar", "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test3/CMakeLists.txt index 676d19bf7a..8570666b11 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_vprintf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/vprintf/test3/test3.c deleted file mode 100644 index 5376c56b76..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test3/test3.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the vprintf function. Tests the wide string -** specifier (%S). -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoWStrTest("foo %S", convert("bar"), "foo bar"); - DoStrTest("foo %hS", "bar", "foo bar"); - DoWStrTest("foo %lS", convert("bar"), "foo bar"); - DoWStrTest("foo %wS", convert("bar"), "foo bar"); - DoWStrTest("foo %LS", convert("bar"), "foo bar"); - DoWStrTest("foo %I64S", convert("bar"), "foo bar"); - DoWStrTest("foo %5S", convert("bar"), "foo bar"); - DoWStrTest("foo %.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %-5S", convert("bar"), "foo bar "); - DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test3/test3.cpp new file mode 100644 index 0000000000..5376c56b76 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test3/test3.cpp @@ -0,0 +1,45 @@ +// 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: test3.c +** +** Purpose: Test #3 for the vprintf function. Tests the wide string +** specifier (%S). +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoWStrTest("foo %S", convert("bar"), "foo bar"); + DoStrTest("foo %hS", "bar", "foo bar"); + DoWStrTest("foo %lS", convert("bar"), "foo bar"); + DoWStrTest("foo %wS", convert("bar"), "foo bar"); + DoWStrTest("foo %LS", convert("bar"), "foo bar"); + DoWStrTest("foo %I64S", convert("bar"), "foo bar"); + DoWStrTest("foo %5S", convert("bar"), "foo bar"); + DoWStrTest("foo %.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %-5S", convert("bar"), "foo bar "); + DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test4/CMakeLists.txt index 9ddb087e83..06b582b5ee 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_vprintf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/vprintf/test4/test4.c deleted file mode 100644 index 3b66cde22e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test4/test4.c +++ /dev/null @@ -1,70 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the vprintf function. Tests the pointer -** specifier (%p). -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "0000000000000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); - -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "00000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); - -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test4/test4.cpp new file mode 100644 index 0000000000..3b66cde22e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test4/test4.cpp @@ -0,0 +1,70 @@ +// 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: test4.c +** +** Purpose: Test #4 for the vprintf function. Tests the pointer +** specifier (%p). +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "0000000000000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); + +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "00000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); + +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test5/CMakeLists.txt index f453bb66ee..3a1828a28c 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_vprintf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/vprintf/test5/test5.c deleted file mode 100644 index c9e2901230..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test5/test5.c +++ /dev/null @@ -1,60 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the vprintf function. Tests the count specifier (%n). -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - - -int __cdecl main(int argc, char *argv[]) -{ - char *longStr = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - "%n bar"; - char *longResult = - "really-long-string-that-just-keeps-going-on-and-on-and-on.." - "..................useless-filler.................................." - "..................useless-filler.................................." - "..................useless-filler.................................." - " bar"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoCountTest("foo %n bar", 4, "foo bar"); - DoCountTest(longStr, 257, longResult); - DoCountTest("fo%n bar", 2, "fo bar"); - DoCountTest("%n", 0, ""); - DoCountTest("foo %#n bar", 4, "foo bar"); - DoCountTest("foo % n bar", 4, "foo bar"); - DoCountTest("foo %+n bar", 4, "foo bar"); - DoCountTest("foo %-n bar", 4, "foo bar"); - DoCountTest("foo %0n bar", 4, "foo bar"); - DoShortCountTest("foo %hn bar", 4, "foo bar"); - DoCountTest("foo %ln bar", 4, "foo bar"); - DoCountTest("foo %Ln bar", 4, "foo bar"); - DoCountTest("foo %I64n bar", 4, "foo bar"); - DoCountTest("foo %20.3n bar", 4, "foo bar"); - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test5/test5.cpp new file mode 100644 index 0000000000..c9e2901230 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test5/test5.cpp @@ -0,0 +1,60 @@ +// 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: test5.c +** +** Purpose: Test #5 for the vprintf function. Tests the count specifier (%n). +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + + +int __cdecl main(int argc, char *argv[]) +{ + char *longStr = + "really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + "%n bar"; + char *longResult = + "really-long-string-that-just-keeps-going-on-and-on-and-on.." + "..................useless-filler.................................." + "..................useless-filler.................................." + "..................useless-filler.................................." + " bar"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoCountTest("foo %n bar", 4, "foo bar"); + DoCountTest(longStr, 257, longResult); + DoCountTest("fo%n bar", 2, "fo bar"); + DoCountTest("%n", 0, ""); + DoCountTest("foo %#n bar", 4, "foo bar"); + DoCountTest("foo % n bar", 4, "foo bar"); + DoCountTest("foo %+n bar", 4, "foo bar"); + DoCountTest("foo %-n bar", 4, "foo bar"); + DoCountTest("foo %0n bar", 4, "foo bar"); + DoShortCountTest("foo %hn bar", 4, "foo bar"); + DoCountTest("foo %ln bar", 4, "foo bar"); + DoCountTest("foo %Ln bar", 4, "foo bar"); + DoCountTest("foo %I64n bar", 4, "foo bar"); + DoCountTest("foo %20.3n bar", 4, "foo bar"); + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test6/CMakeLists.txt index 1ce8d5aa4c..2dac7703e6 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_vprintf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/vprintf/test6/test6.c deleted file mode 100644 index 6a83cccea6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test6/test6.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the vprintf function. Tests the char specifier (%c). -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoCharTest("foo %c", 'b', "foo b"); - DoCharTest("foo %hc", 'b', "foo b"); - DoWCharTest("foo %lc", wc, "foo c"); - DoCharTest("foo %Lc", 'b', "foo b"); - DoCharTest("foo %I64c", 'b', "foo b"); - DoCharTest("foo %5c", 'b', "foo b"); - DoCharTest("foo %.0c", 'b', "foo b"); - DoCharTest("foo %-5c", 'b', "foo b "); - DoCharTest("foo %05c", 'b', "foo 0000b"); - DoCharTest("foo % c", 'b', "foo b"); - DoCharTest("foo %#c", 'b', "foo b"); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test6/test6.cpp new file mode 100644 index 0000000000..6a83cccea6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test6/test6.cpp @@ -0,0 +1,48 @@ +// 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: test6.c +** +** Purpose: Test #6 for the vprintf function. Tests the char specifier (%c). +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoCharTest("foo %c", 'b', "foo b"); + DoCharTest("foo %hc", 'b', "foo b"); + DoWCharTest("foo %lc", wc, "foo c"); + DoCharTest("foo %Lc", 'b', "foo b"); + DoCharTest("foo %I64c", 'b', "foo b"); + DoCharTest("foo %5c", 'b', "foo b"); + DoCharTest("foo %.0c", 'b', "foo b"); + DoCharTest("foo %-5c", 'b', "foo b "); + DoCharTest("foo %05c", 'b', "foo 0000b"); + DoCharTest("foo % c", 'b', "foo b"); + DoCharTest("foo %#c", 'b', "foo b"); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test7/CMakeLists.txt index 5627fe4c1e..5a520045a9 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_vprintf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/vprintf/test7/test7.c deleted file mode 100644 index 5096ace42c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test7/test7.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test7.c -** -** Purpose: Test #7 for the vprintf function. Tests the wide char -** specifier (%C). -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoWCharTest("foo %C", wb, "foo b"); - DoWCharTest("foo %hC", wb, "foo b"); - DoCharTest("foo %lC", 'c', "foo c"); - DoWCharTest("foo %LC", wb, "foo b"); - DoWCharTest("foo %I64C", wb, "foo b"); - DoWCharTest("foo %5C", wb, "foo b"); - DoWCharTest("foo %.0C", wb, "foo b"); - DoWCharTest("foo %-5C", wb, "foo b "); - DoWCharTest("foo %05C", wb, "foo 0000b"); - DoWCharTest("foo % C", wb, "foo b"); - DoWCharTest("foo %#C", wb, "foo b"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test7/test7.cpp new file mode 100644 index 0000000000..5096ace42c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test7/test7.cpp @@ -0,0 +1,47 @@ +// 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: test7.c +** +** Purpose: Test #7 for the vprintf function. Tests the wide char +** specifier (%C). +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoWCharTest("foo %C", wb, "foo b"); + DoWCharTest("foo %hC", wb, "foo b"); + DoCharTest("foo %lC", 'c', "foo c"); + DoWCharTest("foo %LC", wb, "foo b"); + DoWCharTest("foo %I64C", wb, "foo b"); + DoWCharTest("foo %5C", wb, "foo b"); + DoWCharTest("foo %.0C", wb, "foo b"); + DoWCharTest("foo %-5C", wb, "foo b "); + DoWCharTest("foo %05C", wb, "foo 0000b"); + DoWCharTest("foo % C", wb, "foo b"); + DoWCharTest("foo %#C", wb, "foo b"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test8/CMakeLists.txt index 0131e4943e..18e4e3a0c9 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_vprintf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/vprintf/test8/test8.c deleted file mode 100644 index 2683339ece..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test8/test8.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test8.c -** -** Purpose: Test #8 for the vprintf function. Tests the decimal -** specifier (%d). -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %d", pos, "foo 42"); - DoNumTest("foo %ld", 0xFFFF, "foo 65535"); - DoNumTest("foo %hd", 0xFFFF, "foo -1"); - DoNumTest("foo %Ld", pos, "foo 42"); - DoI64Test("foo %I64d", l, "42", "foo 42"); - DoNumTest("foo %3d", pos, "foo 42"); - DoNumTest("foo %-3d", pos, "foo 42 "); - DoNumTest("foo %.1d", pos, "foo 42"); - DoNumTest("foo %.3d", pos, "foo 042"); - DoNumTest("foo %03d", pos, "foo 042"); - DoNumTest("foo %#d", pos, "foo 42"); - DoNumTest("foo %+d", pos, "foo +42"); - DoNumTest("foo % d", pos, "foo 42"); - DoNumTest("foo %+d", neg, "foo -42"); - DoNumTest("foo % d", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test8/test8.cpp new file mode 100644 index 0000000000..2683339ece --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test8/test8.cpp @@ -0,0 +1,53 @@ +// 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: test8.c +** +** Purpose: Test #8 for the vprintf function. Tests the decimal +** specifier (%d). +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %d", pos, "foo 42"); + DoNumTest("foo %ld", 0xFFFF, "foo 65535"); + DoNumTest("foo %hd", 0xFFFF, "foo -1"); + DoNumTest("foo %Ld", pos, "foo 42"); + DoI64Test("foo %I64d", l, "42", "foo 42"); + DoNumTest("foo %3d", pos, "foo 42"); + DoNumTest("foo %-3d", pos, "foo 42 "); + DoNumTest("foo %.1d", pos, "foo 42"); + DoNumTest("foo %.3d", pos, "foo 042"); + DoNumTest("foo %03d", pos, "foo 042"); + DoNumTest("foo %#d", pos, "foo 42"); + DoNumTest("foo %+d", pos, "foo +42"); + DoNumTest("foo % d", pos, "foo 42"); + DoNumTest("foo %+d", neg, "foo -42"); + DoNumTest("foo % d", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vprintf/test9/CMakeLists.txt index c70631f9dc..8bcbe81f51 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_vprintf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/vprintf/test9/test9.c deleted file mode 100644 index 8545bc760e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vprintf/test9/test9.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test9.c -** -** Purpose: Test #9 for the vprintf function. Tests the integer -** specifier (%i). -** -** -**==========================================================================*/ - - - -#include -#include "../vprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoNumTest("foo %i", pos, "foo 42"); - DoNumTest("foo %li", 0xFFFF, "foo 65535"); - DoNumTest("foo %hi", 0xFFFF, "foo -1"); - DoNumTest("foo %Li", pos, "foo 42"); - DoI64Test("foo %I64i", l, "42", "foo 42"); - DoNumTest("foo %3i", pos, "foo 42"); - DoNumTest("foo %-3i", pos, "foo 42 "); - DoNumTest("foo %.1i", pos, "foo 42"); - DoNumTest("foo %.3i", pos, "foo 042"); - DoNumTest("foo %03i", pos, "foo 042"); - DoNumTest("foo %#i", pos, "foo 42"); - DoNumTest("foo %+i", pos, "foo +42"); - DoNumTest("foo % i", pos, "foo 42"); - DoNumTest("foo %+i", neg, "foo -42"); - DoNumTest("foo % i", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/vprintf/test9/test9.cpp new file mode 100644 index 0000000000..8545bc760e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vprintf/test9/test9.cpp @@ -0,0 +1,53 @@ +// 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: test9.c +** +** Purpose: Test #9 for the vprintf function. Tests the integer +** specifier (%i). +** +** +**==========================================================================*/ + + + +#include +#include "../vprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoNumTest("foo %i", pos, "foo 42"); + DoNumTest("foo %li", 0xFFFF, "foo 65535"); + DoNumTest("foo %hi", 0xFFFF, "foo -1"); + DoNumTest("foo %Li", pos, "foo 42"); + DoI64Test("foo %I64i", l, "42", "foo 42"); + DoNumTest("foo %3i", pos, "foo 42"); + DoNumTest("foo %-3i", pos, "foo 42 "); + DoNumTest("foo %.1i", pos, "foo 42"); + DoNumTest("foo %.3i", pos, "foo 042"); + DoNumTest("foo %03i", pos, "foo 042"); + DoNumTest("foo %#i", pos, "foo 42"); + DoNumTest("foo %+i", pos, "foo +42"); + DoNumTest("foo % i", pos, "foo 42"); + DoNumTest("foo %+i", neg, "foo -42"); + DoNumTest("foo % i", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vprintf/vprintf.h b/src/pal/tests/palsuite/c_runtime/vprintf/vprintf.h index 477db32f4d..fcd8f80370 100644 --- a/src/pal/tests/palsuite/c_runtime/vprintf/vprintf.h +++ b/src/pal/tests/palsuite/c_runtime/vprintf/vprintf.h @@ -14,7 +14,7 @@ #ifndef __vprintf_H__ #define __vprintf_H__ -int DoVprintf(char *format, ...) +int DoVprintf(const char *format, ...) { int retVal; va_list arglist; @@ -26,7 +26,7 @@ int DoVprintf(char *format, ...) return (retVal); } -void DoStrTest(char *formatstr, char* param, char *checkstr) +void DoStrTest(const char *formatstr, char* param, const char *checkstr) { int ret; @@ -38,7 +38,7 @@ void DoStrTest(char *formatstr, char* param, char *checkstr) } } -void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) +void DoWStrTest(const char *formatstr, WCHAR* param, const char *checkstr) { int ret; @@ -50,8 +50,8 @@ void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) } } -void DoPointerTest(char *formatstr, void* param, char* paramstr, - char *checkstr1) +void DoPointerTest(const char *formatstr, void* param, char* paramstr, + const char *checkstr1) { int ret; @@ -63,7 +63,7 @@ void DoPointerTest(char *formatstr, void* param, char* paramstr, } } -void DoCountTest(char *formatstr, int param, char *checkstr) +void DoCountTest(const char *formatstr, int param, const char *checkstr) { int ret; int n = -1; @@ -82,7 +82,7 @@ void DoCountTest(char *formatstr, int param, char *checkstr) } } -void DoShortCountTest(char *formatstr, int param, char *checkstr) +void DoShortCountTest(const char *formatstr, int param, const char *checkstr) { int ret; short int n = -1; @@ -102,7 +102,7 @@ void DoShortCountTest(char *formatstr, int param, char *checkstr) } -void DoCharTest(char *formatstr, char param, char *checkstr) +void DoCharTest(const char *formatstr, char param, const char *checkstr) { int ret; @@ -114,7 +114,7 @@ void DoCharTest(char *formatstr, char param, char *checkstr) } } -void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) +void DoWCharTest(const char *formatstr, WCHAR param, const char *checkstr) { int ret; @@ -126,7 +126,7 @@ void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) } } -void DoNumTest(char *formatstr, int param, char *checkstr) +void DoNumTest(const char *formatstr, int param, const char *checkstr) { int ret; @@ -138,7 +138,7 @@ void DoNumTest(char *formatstr, int param, char *checkstr) } } -void DoI64Test(char *formatstr, INT64 param, char *valuestr, char *checkstr1) +void DoI64Test(const char *formatstr, INT64 param, char *valuestr, const char *checkstr1) { int ret; @@ -150,8 +150,8 @@ void DoI64Test(char *formatstr, INT64 param, char *valuestr, char *checkstr1) } } -void DoDoubleTest(char *formatstr, double param, char *checkstr1, - char *checkstr2) +void DoDoubleTest(const char *formatstr, double param, const char *checkstr1, + const char *checkstr2) { int ret; @@ -163,8 +163,8 @@ void DoDoubleTest(char *formatstr, double param, char *checkstr1, } } -void DoArgumentPrecTest(char *formatstr, int precision, void *param, - char *paramstr, char *checkstr1, char *checkstr2) +void DoArgumentPrecTest(const char *formatstr, int precision, void *param, + char *paramstr, const char *checkstr1, const char *checkstr2) { int ret; @@ -176,8 +176,8 @@ void DoArgumentPrecTest(char *formatstr, int precision, void *param, } } -void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param, - char *checkstr1, char *checkstr2) +void DoArgumentPrecDoubleTest(const char *formatstr, int precision, double param, + const char *checkstr1, const char *checkstr2) { int ret; diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test1/CMakeLists.txt index 4f0872eccc..6861157c1b 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_vsprintf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test1/test1.c deleted file mode 100644 index 2007fefc5b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test1/test1.c +++ /dev/null @@ -1,55 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - char checkstr[] = "hello world"; - char buf[256] = { 0 }; - int ret; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - testvsp(buf, "hello world"); - - if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) - { - Fail("ERROR: expected \"%s\" (up to %d chars), got \"%s\"\n", - checkstr, 256, buf); - } - - testvsp(buf, "xxxxxxxxxxxxxxxxx"); - ret = testvsp(buf, "hello world"); - - if (ret != strlen(checkstr)) - { - Fail("ERROR: expected negative return value, got %d", ret); - } - - if (memcmp(checkstr, buf, ret) != 0) - { - Fail("ERROR: expected %s, got %s\n", checkstr, buf); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test1/test1.cpp new file mode 100644 index 0000000000..2007fefc5b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test1/test1.cpp @@ -0,0 +1,55 @@ +// 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: test1.c +** +** Purpose: Test #1 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + char checkstr[] = "hello world"; + char buf[256] = { 0 }; + int ret; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + testvsp(buf, "hello world"); + + if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) + { + Fail("ERROR: expected \"%s\" (up to %d chars), got \"%s\"\n", + checkstr, 256, buf); + } + + testvsp(buf, "xxxxxxxxxxxxxxxxx"); + ret = testvsp(buf, "hello world"); + + if (ret != strlen(checkstr)) + { + Fail("ERROR: expected negative return value, got %d", ret); + } + + if (memcmp(checkstr, buf, ret) != 0) + { + Fail("ERROR: expected %s, got %s\n", checkstr, buf); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test10/CMakeLists.txt index d32de01ba1..6f535a5098 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_vsprintf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test10/test10.c deleted file mode 100644 index 791213fccc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test10/test10.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test10.c -** -** Purpose: Test #10 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %o", pos, "foo 52"); - DoNumTest("foo %lo", 0xFFFF, "foo 177777"); - DoNumTest("foo %ho", 0xFFFF, "foo 177777"); - DoNumTest("foo %Lo", pos, "foo 52"); - DoI64Test("foo %I64o", l, "42", "foo 52"); - DoNumTest("foo %3o", pos, "foo 52"); - DoNumTest("foo %-3o", pos, "foo 52 "); - DoNumTest("foo %.1o", pos, "foo 52"); - DoNumTest("foo %.3o", pos, "foo 052"); - DoNumTest("foo %03o", pos, "foo 052"); - DoNumTest("foo %#o", pos, "foo 052"); - DoNumTest("foo %+o", pos, "foo 52"); - DoNumTest("foo % o", pos, "foo 52"); - DoNumTest("foo %+o", neg, "foo 37777777726"); - DoNumTest("foo % o", neg, "foo 37777777726"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test10/test10.cpp new file mode 100644 index 0000000000..791213fccc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test10/test10.cpp @@ -0,0 +1,50 @@ +// 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: test10.c +** +** Purpose: Test #10 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %o", pos, "foo 52"); + DoNumTest("foo %lo", 0xFFFF, "foo 177777"); + DoNumTest("foo %ho", 0xFFFF, "foo 177777"); + DoNumTest("foo %Lo", pos, "foo 52"); + DoI64Test("foo %I64o", l, "42", "foo 52"); + DoNumTest("foo %3o", pos, "foo 52"); + DoNumTest("foo %-3o", pos, "foo 52 "); + DoNumTest("foo %.1o", pos, "foo 52"); + DoNumTest("foo %.3o", pos, "foo 052"); + DoNumTest("foo %03o", pos, "foo 052"); + DoNumTest("foo %#o", pos, "foo 052"); + DoNumTest("foo %+o", pos, "foo 52"); + DoNumTest("foo % o", pos, "foo 52"); + DoNumTest("foo %+o", neg, "foo 37777777726"); + DoNumTest("foo % o", neg, "foo 37777777726"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test11/CMakeLists.txt index ce67444c39..3fa628f77d 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_vsprintf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test11/test11.c deleted file mode 100644 index e0af94981b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test11/test11.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test11.c -** -** Purpose: Test #11 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %u", pos, "foo 42"); - DoNumTest("foo %lu", 0xFFFF, "foo 65535"); - DoNumTest("foo %hu", 0xFFFF, "foo 65535"); - DoNumTest("foo %Lu", pos, "foo 42"); - DoI64Test("foo %I64u", l, "42", "foo 42"); - DoNumTest("foo %3u", pos, "foo 42"); - DoNumTest("foo %-3u", pos, "foo 42 "); - DoNumTest("foo %.1u", pos, "foo 42"); - DoNumTest("foo %.3u", pos, "foo 042"); - DoNumTest("foo %03u", pos, "foo 042"); - DoNumTest("foo %#u", pos, "foo 42"); - DoNumTest("foo %+u", pos, "foo 42"); - DoNumTest("foo % u", pos, "foo 42"); - DoNumTest("foo %+u", neg, "foo 4294967254"); - DoNumTest("foo % u", neg, "foo 4294967254"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test11/test11.cpp new file mode 100644 index 0000000000..e0af94981b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test11/test11.cpp @@ -0,0 +1,50 @@ +// 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: test11.c +** +** Purpose: Test #11 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %u", pos, "foo 42"); + DoNumTest("foo %lu", 0xFFFF, "foo 65535"); + DoNumTest("foo %hu", 0xFFFF, "foo 65535"); + DoNumTest("foo %Lu", pos, "foo 42"); + DoI64Test("foo %I64u", l, "42", "foo 42"); + DoNumTest("foo %3u", pos, "foo 42"); + DoNumTest("foo %-3u", pos, "foo 42 "); + DoNumTest("foo %.1u", pos, "foo 42"); + DoNumTest("foo %.3u", pos, "foo 042"); + DoNumTest("foo %03u", pos, "foo 042"); + DoNumTest("foo %#u", pos, "foo 42"); + DoNumTest("foo %+u", pos, "foo 42"); + DoNumTest("foo % u", pos, "foo 42"); + DoNumTest("foo %+u", neg, "foo 4294967254"); + DoNumTest("foo % u", neg, "foo 4294967254"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test12/CMakeLists.txt index fe6ccb8399..f34f76abc5 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_vsprintf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test12/test12.c deleted file mode 100644 index f86ddcade8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test12/test12.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test12.c -** -** Purpose: Test #12 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return (FAIL); - } - - DoNumTest("foo %x", pos, "foo 1234ab"); - DoNumTest("foo %lx", pos, "foo 1234ab"); - DoNumTest("foo %hx", pos, "foo 34ab"); - DoNumTest("foo %Lx", pos, "foo 1234ab"); - DoI64Test("foo %I64x", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7x", pos, "foo 1234ab"); - DoNumTest("foo %-7x", pos, "foo 1234ab "); - DoNumTest("foo %.1x", pos, "foo 1234ab"); - DoNumTest("foo %.7x", pos, "foo 01234ab"); - DoNumTest("foo %07x", pos, "foo 01234ab"); - DoNumTest("foo %#x", pos, "foo 0x1234ab"); - DoNumTest("foo %+x", pos, "foo 1234ab"); - DoNumTest("foo % x", pos, "foo 1234ab"); - DoNumTest("foo %+x", neg, "foo ffffffd6"); - DoNumTest("foo % x", neg, "foo ffffffd6"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test12/test12.cpp new file mode 100644 index 0000000000..f86ddcade8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test12/test12.cpp @@ -0,0 +1,52 @@ +// 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: test12.c +** +** Purpose: Test #12 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return (FAIL); + } + + DoNumTest("foo %x", pos, "foo 1234ab"); + DoNumTest("foo %lx", pos, "foo 1234ab"); + DoNumTest("foo %hx", pos, "foo 34ab"); + DoNumTest("foo %Lx", pos, "foo 1234ab"); + DoI64Test("foo %I64x", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7x", pos, "foo 1234ab"); + DoNumTest("foo %-7x", pos, "foo 1234ab "); + DoNumTest("foo %.1x", pos, "foo 1234ab"); + DoNumTest("foo %.7x", pos, "foo 01234ab"); + DoNumTest("foo %07x", pos, "foo 01234ab"); + DoNumTest("foo %#x", pos, "foo 0x1234ab"); + DoNumTest("foo %+x", pos, "foo 1234ab"); + DoNumTest("foo % x", pos, "foo 1234ab"); + DoNumTest("foo %+x", neg, "foo ffffffd6"); + DoNumTest("foo % x", neg, "foo ffffffd6"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test13/CMakeLists.txt index 97fdf8cdd0..df23693f10 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_vsprintf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test13/test13.c deleted file mode 100644 index 36e7825531..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test13/test13.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test13.c -** -** Purpose: Test #13 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234AB; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %X", pos, "foo 1234AB"); - DoNumTest("foo %lX", pos, "foo 1234AB"); - DoNumTest("foo %hX", pos, "foo 34AB"); - DoNumTest("foo %LX", pos, "foo 1234AB"); - DoI64Test("foo %I64X", l, "0x1234567887654321", - "foo 1234567887654321"); - DoNumTest("foo %7X", pos, "foo 1234AB"); - DoNumTest("foo %-7X", pos, "foo 1234AB "); - DoNumTest("foo %.1X", pos, "foo 1234AB"); - DoNumTest("foo %.7X", pos, "foo 01234AB"); - DoNumTest("foo %07X", pos, "foo 01234AB"); - DoNumTest("foo %#X", pos, "foo 0X1234AB"); - DoNumTest("foo %+X", pos, "foo 1234AB"); - DoNumTest("foo % X", pos, "foo 1234AB"); - DoNumTest("foo %+X", neg, "foo FFFFFFD6"); - DoNumTest("foo % X", neg, "foo FFFFFFD6"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test13/test13.cpp new file mode 100644 index 0000000000..36e7825531 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test13/test13.cpp @@ -0,0 +1,52 @@ +// 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: test13.c +** +** Purpose: Test #13 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234AB; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %X", pos, "foo 1234AB"); + DoNumTest("foo %lX", pos, "foo 1234AB"); + DoNumTest("foo %hX", pos, "foo 34AB"); + DoNumTest("foo %LX", pos, "foo 1234AB"); + DoI64Test("foo %I64X", l, "0x1234567887654321", + "foo 1234567887654321"); + DoNumTest("foo %7X", pos, "foo 1234AB"); + DoNumTest("foo %-7X", pos, "foo 1234AB "); + DoNumTest("foo %.1X", pos, "foo 1234AB"); + DoNumTest("foo %.7X", pos, "foo 01234AB"); + DoNumTest("foo %07X", pos, "foo 01234AB"); + DoNumTest("foo %#X", pos, "foo 0X1234AB"); + DoNumTest("foo %+X", pos, "foo 1234AB"); + DoNumTest("foo % X", pos, "foo 1234AB"); + DoNumTest("foo %+X", neg, "foo FFFFFFD6"); + DoNumTest("foo % X", neg, "foo FFFFFFD6"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test14/CMakeLists.txt index 2851a8893e..394b5ab97c 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_vsprintf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test14/test14.c deleted file mode 100644 index 360fafc37f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test14/test14.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test14.c -** -** Purpose: Test #14 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", "foo 2.560000e+02 "); - DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); - DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", "foo 2.56000000e+02"); - DoDoubleTest("foo %014e", val, "foo 02.560000e+002", "foo 002.560000e+02"); - DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); - DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); - DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test14/test14.cpp new file mode 100644 index 0000000000..360fafc37f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test14/test14.cpp @@ -0,0 +1,50 @@ +// 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: test14.c +** +** Purpose: Test #14 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %he", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %Le", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %I64e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %14e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %-14e", val, "foo 2.560000e+002 ", "foo 2.560000e+02 "); + DoDoubleTest("foo %.1e", val, "foo 2.6e+002", "foo 2.6e+02"); + DoDoubleTest("foo %.8e", val, "foo 2.56000000e+002", "foo 2.56000000e+02"); + DoDoubleTest("foo %014e", val, "foo 02.560000e+002", "foo 002.560000e+02"); + DoDoubleTest("foo %#e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", val, "foo +2.560000e+002", "foo +2.560000e+02"); + DoDoubleTest("foo % e", val, "foo 2.560000e+002", "foo 2.560000e+02"); + DoDoubleTest("foo %+e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + DoDoubleTest("foo % e", neg, "foo -2.560000e+002", "foo -2.560000e+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test15/CMakeLists.txt index 6fb1d321b8..4793b45663 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_vsprintf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test15/test15.c deleted file mode 100644 index a5b4c94226..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test15/test15.c +++ /dev/null @@ -1,64 +0,0 @@ -// 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: test15.c -** -** Purpose: Test #15 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %E", val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest("foo %lE", val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest("foo %hE", val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest("foo %LE", val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest("foo %14E", val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", - "foo 2.560000E+02 "); - DoDoubleTest("foo %.1E", val, "foo 2.6E+002", - "foo 2.6E+02"); - DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", - "foo 2.56000000E+02"); - DoDoubleTest("foo %014E", val, "foo 02.560000E+002", - "foo 002.560000E+02"); - DoDoubleTest("foo %#E", val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest("foo %+E", val, "foo +2.560000E+002", - "foo +2.560000E+02"); - DoDoubleTest("foo % E", val, "foo 2.560000E+002", - "foo 2.560000E+02"); - DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", - "foo -2.560000E+02"); - DoDoubleTest("foo % E", neg, "foo -2.560000E+002", - "foo -2.560000E+02"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test15/test15.cpp new file mode 100644 index 0000000000..a5b4c94226 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test15/test15.cpp @@ -0,0 +1,64 @@ +// 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: test15.c +** +** Purpose: Test #15 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %E", val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest("foo %lE", val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest("foo %hE", val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest("foo %LE", val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest("foo %I64E", val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest("foo %14E", val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest("foo %-14E", val, "foo 2.560000E+002 ", + "foo 2.560000E+02 "); + DoDoubleTest("foo %.1E", val, "foo 2.6E+002", + "foo 2.6E+02"); + DoDoubleTest("foo %.8E", val, "foo 2.56000000E+002", + "foo 2.56000000E+02"); + DoDoubleTest("foo %014E", val, "foo 02.560000E+002", + "foo 002.560000E+02"); + DoDoubleTest("foo %#E", val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest("foo %+E", val, "foo +2.560000E+002", + "foo +2.560000E+02"); + DoDoubleTest("foo % E", val, "foo 2.560000E+002", + "foo 2.560000E+02"); + DoDoubleTest("foo %+E", neg, "foo -2.560000E+002", + "foo -2.560000E+02"); + DoDoubleTest("foo % E", neg, "foo -2.560000E+002", + "foo -2.560000E+02"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test16/CMakeLists.txt index ccc21378fc..6a0a52ddf7 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_vsprintf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test16/test16.c deleted file mode 100644 index a7258db9d6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test16/test16.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test16.c -** -** Purpose: Test #16 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); - DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); - DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); - DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); - DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); - DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); - DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); - DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test16/test16.cpp new file mode 100644 index 0000000000..a7258db9d6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test16/test16.cpp @@ -0,0 +1,49 @@ +// 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: test16.c +** +** Purpose: Test #16 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %hf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %Lf", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %I64f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %12f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %-12f", val, "foo 2560.001000 ", "foo 2560.001000 "); + DoDoubleTest("foo %.1f", val, "foo 2560.0", "foo 2560.0"); + DoDoubleTest("foo %.8f", val, "foo 2560.00100000", "foo 2560.00100000"); + DoDoubleTest("foo %012f", val, "foo 02560.001000", "foo 02560.001000"); + DoDoubleTest("foo %#f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", val, "foo +2560.001000", "foo +2560.001000"); + DoDoubleTest("foo % f", val, "foo 2560.001000", "foo 2560.001000"); + DoDoubleTest("foo %+f", neg, "foo -2560.001000", "foo -2560.001000"); + DoDoubleTest("foo % f", neg, "foo -2560.001000", "foo -2560.001000"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test17/CMakeLists.txt index 4c9dcd986f..4e220dab77 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_vsprintf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test17/test17.c deleted file mode 100644 index 0ad246a1ae..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test17/test17.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test17.c -** -** Purpose: Test #17 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); - DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); - DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test17/test17.cpp new file mode 100644 index 0000000000..0ad246a1ae --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test17/test17.cpp @@ -0,0 +1,50 @@ +// 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: test17.c +** +** Purpose: Test #17 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %Lg", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5g", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1g", val, "foo 3e+003", "foo 3e+03"); + DoDoubleTest("foo %.2g", val, "foo 2.6e+003", "foo 2.6e+03"); + DoDoubleTest("foo %.12g", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06g", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#g", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+g", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % g", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+g", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % g", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test18/CMakeLists.txt index 2e8610d4a5..4dd68c2987 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test18.c + test18.cpp ) add_executable(paltest_vsprintf_test18 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test18/test18.c deleted file mode 100644 index 9a45305562..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test18/test18.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); - DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); - DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); - DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); - DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); - DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); - DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); - DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); - DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); - DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test18/test18.cpp new file mode 100644 index 0000000000..9a45305562 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test18/test18.cpp @@ -0,0 +1,50 @@ +// 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: test18.c +** +** Purpose: Test #18 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest("foo %G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %lG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %hG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %LG", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %I64G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %5G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %-5G", val, "foo 2560 ", "foo 2560 "); + DoDoubleTest("foo %.1G", val, "foo 3E+003", "foo 3E+03"); + DoDoubleTest("foo %.2G", val, "foo 2.6E+003", "foo 2.6E+03"); + DoDoubleTest("foo %.12G", val, "foo 2560.001", "foo 2560.001"); + DoDoubleTest("foo %06G", val, "foo 002560", "foo 002560"); + DoDoubleTest("foo %#G", val, "foo 2560.00", "foo 2560.00"); + DoDoubleTest("foo %+G", val, "foo +2560", "foo +2560"); + DoDoubleTest("foo % G", val, "foo 2560", "foo 2560"); + DoDoubleTest("foo %+G", neg, "foo -2560", "foo -2560"); + DoDoubleTest("foo % G", neg, "foo -2560", "foo -2560"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test19/CMakeLists.txt index 92e39ab597..3156a59a15 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test19.c + test19.cpp ) add_executable(paltest_vsprintf_test19 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test19/test19.c deleted file mode 100644 index 18590ed51b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test19/test19.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: test19.c -** -** Purpose: Test #19 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - - DoArgumentPrecTest("%.*s", 2, "bar", "bar", "ba", "ba"); - DoArgumentPrecTest("%.*S", 2, convert("bar"), "bar", "ba", "ba"); - DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); - DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); - DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); - DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); - DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); - DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); - DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); - DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); - - - DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); - DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); - DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); - DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); - DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); - DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); - DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); - DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); - DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); - DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); - DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test19/test19.cpp new file mode 100644 index 0000000000..698ff36e35 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test19/test19.cpp @@ -0,0 +1,67 @@ +// 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: test19.c +** +** Purpose: Test #19 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + + DoArgumentPrecTest("%.*s", 2, (void*)"bar", "bar", "ba", "ba"); + DoArgumentPrecTest("%.*S", 2, (void*)convert("bar"), "bar", "ba", "ba"); + DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a"); + DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52"); + DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052"); + DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42"); + DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042"); + DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042"); + DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42"); + DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042"); + + + DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00"); + DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00"); + DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00"); + DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00"); + DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0"); + DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010"); + DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02"); + DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01"); + DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02"); + DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256"); + DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test2/CMakeLists.txt index 2308bc2573..210224f0f1 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_vsprintf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test2/test2.c deleted file mode 100644 index fbd4b41068..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test2/test2.c +++ /dev/null @@ -1,42 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoStrTest("foo %s", "bar", "foo bar"); - DoStrTest("foo %hs", "bar", "foo bar"); - DoWStrTest("foo %ls", convert("bar"), "foo bar"); - DoWStrTest("foo %ws", convert("bar"), "foo bar"); - DoStrTest("foo %Ls", "bar", "foo bar"); - DoStrTest("foo %I64s", "bar", "foo bar"); - DoStrTest("foo %5s", "bar", "foo bar"); - DoStrTest("foo %.2s", "bar", "foo ba"); - DoStrTest("foo %5.2s", "bar", "foo ba"); - DoStrTest("foo %-5s", "bar", "foo bar "); - DoStrTest("foo %05s", "bar", "foo 00bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test2/test2.cpp new file mode 100644 index 0000000000..fbd4b41068 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test2/test2.cpp @@ -0,0 +1,42 @@ +// 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: test2.c +** +** Purpose: Test #2 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoStrTest("foo %s", "bar", "foo bar"); + DoStrTest("foo %hs", "bar", "foo bar"); + DoWStrTest("foo %ls", convert("bar"), "foo bar"); + DoWStrTest("foo %ws", convert("bar"), "foo bar"); + DoStrTest("foo %Ls", "bar", "foo bar"); + DoStrTest("foo %I64s", "bar", "foo bar"); + DoStrTest("foo %5s", "bar", "foo bar"); + DoStrTest("foo %.2s", "bar", "foo ba"); + DoStrTest("foo %5.2s", "bar", "foo ba"); + DoStrTest("foo %-5s", "bar", "foo bar "); + DoStrTest("foo %05s", "bar", "foo 00bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test3/CMakeLists.txt index aef24171fc..5581051f9f 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_vsprintf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test3/test3.c deleted file mode 100644 index 742370ebe9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test3/test3.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoWStrTest("foo %S", convert("bar"), "foo bar"); - DoStrTest("foo %hS", "bar", "foo bar"); - DoWStrTest("foo %lS", convert("bar"), "foo bar"); - DoWStrTest("foo %wS", convert("bar"), "foo bar"); - DoWStrTest("foo %LS", convert("bar"), "foo bar"); - DoWStrTest("foo %I64S", convert("bar"), "foo bar"); - DoWStrTest("foo %5S", convert("bar"), "foo bar"); - DoWStrTest("foo %.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); - DoWStrTest("foo %-5S", convert("bar"), "foo bar "); - DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test3/test3.cpp new file mode 100644 index 0000000000..742370ebe9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test3/test3.cpp @@ -0,0 +1,43 @@ +// 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: test3.c +** +** Purpose: Test #3 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoWStrTest("foo %S", convert("bar"), "foo bar"); + DoStrTest("foo %hS", "bar", "foo bar"); + DoWStrTest("foo %lS", convert("bar"), "foo bar"); + DoWStrTest("foo %wS", convert("bar"), "foo bar"); + DoWStrTest("foo %LS", convert("bar"), "foo bar"); + DoWStrTest("foo %I64S", convert("bar"), "foo bar"); + DoWStrTest("foo %5S", convert("bar"), "foo bar"); + DoWStrTest("foo %.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %5.2S", convert("bar"), "foo ba"); + DoWStrTest("foo %-5S", convert("bar"), "foo bar "); + DoWStrTest("foo %05S", convert("bar"), "foo 00bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test4/CMakeLists.txt index 9570255475..88817fcffb 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_vsprintf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test4/test4.c deleted file mode 100644 index dc43a9e2c7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test4/test4.c +++ /dev/null @@ -1,72 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "0000000000000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); - DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64DoubleTest("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest("%p", NULL, "NULL", "00000000"); - DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); - DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); - DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); - DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); - DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); - DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); - DoI64DoubleTest("%I64p", lptr, "pointer to 0x1234567887654321", - "1234567887654321"); -#endif - - - - - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test4/test4.cpp new file mode 100644 index 0000000000..dc43a9e2c7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test4/test4.cpp @@ -0,0 +1,72 @@ +// 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: test4.c +** +** Purpose: Test #4 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "0000000000000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456"); + DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64DoubleTest("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest("%p", NULL, "NULL", "00000000"); + DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); + DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); + DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); + DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); + DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); + DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); + DoI64DoubleTest("%I64p", lptr, "pointer to 0x1234567887654321", + "1234567887654321"); +#endif + + + + + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test5/CMakeLists.txt index 34a3e6243f..6d14bf76bf 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_vsprintf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test5/test5.c deleted file mode 100644 index e630d8863b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test5/test5.c +++ /dev/null @@ -1,43 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoTest("foo %n bar", 4, "foo bar"); - DoTest("foo %#n bar", 4, "foo bar"); - DoTest("foo % n bar", 4, "foo bar"); - DoTest("foo %+n bar", 4, "foo bar"); - DoTest("foo %-n bar", 4, "foo bar"); - DoTest("foo %0n bar", 4, "foo bar"); - DoShortTest("foo %hn bar", 4, "foo bar"); - DoTest("foo %ln bar", 4, "foo bar"); - DoTest("foo %Ln bar", 4, "foo bar"); - DoTest("foo %I64n bar", 4, "foo bar"); - DoTest("foo %20.3n bar", 4, "foo bar"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test5/test5.cpp new file mode 100644 index 0000000000..e630d8863b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test5/test5.cpp @@ -0,0 +1,43 @@ +// 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: test5.c +** +** Purpose: Test #5 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoTest("foo %n bar", 4, "foo bar"); + DoTest("foo %#n bar", 4, "foo bar"); + DoTest("foo % n bar", 4, "foo bar"); + DoTest("foo %+n bar", 4, "foo bar"); + DoTest("foo %-n bar", 4, "foo bar"); + DoTest("foo %0n bar", 4, "foo bar"); + DoShortTest("foo %hn bar", 4, "foo bar"); + DoTest("foo %ln bar", 4, "foo bar"); + DoTest("foo %Ln bar", 4, "foo bar"); + DoTest("foo %I64n bar", 4, "foo bar"); + DoTest("foo %20.3n bar", 4, "foo bar"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test6/CMakeLists.txt index dccca0b2b7..606fe3b965 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_vsprintf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test6/test6.c deleted file mode 100644 index 0d38a3a114..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test6/test6.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoCharTest("foo %c", 'b', "foo b"); - DoCharTest("foo %hc", 'b', "foo b"); - DoWCharTest("foo %lc", wc, "foo c"); - DoCharTest("foo %Lc", 'b', "foo b"); - DoCharTest("foo %I64c", 'b', "foo b"); - DoCharTest("foo %5c", 'b', "foo b"); - DoCharTest("foo %.0c", 'b', "foo b"); - DoCharTest("foo %-5c", 'b', "foo b "); - DoCharTest("foo %05c", 'b', "foo 0000b"); - DoCharTest("foo % c", 'b', "foo b"); - DoCharTest("foo %#c", 'b', "foo b"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test6/test6.cpp new file mode 100644 index 0000000000..0d38a3a114 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test6/test6.cpp @@ -0,0 +1,44 @@ +// 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: test6.c +** +** Purpose: Test #6 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoCharTest("foo %c", 'b', "foo b"); + DoCharTest("foo %hc", 'b', "foo b"); + DoWCharTest("foo %lc", wc, "foo c"); + DoCharTest("foo %Lc", 'b', "foo b"); + DoCharTest("foo %I64c", 'b', "foo b"); + DoCharTest("foo %5c", 'b', "foo b"); + DoCharTest("foo %.0c", 'b', "foo b"); + DoCharTest("foo %-5c", 'b', "foo b "); + DoCharTest("foo %05c", 'b', "foo 0000b"); + DoCharTest("foo % c", 'b', "foo b"); + DoCharTest("foo %#c", 'b', "foo b"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test7/CMakeLists.txt index 7f18de056e..2dee276968 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_vsprintf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test7/test7.c deleted file mode 100644 index c9f87d4343..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test7/test7.c +++ /dev/null @@ -1,44 +0,0 @@ -// 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: test7.c -** -** Purpose: Test #7 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wb = (WCHAR) 'b'; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoWCharTest("foo %c", wb, "foo b"); - DoWCharTest("foo %hc", wb, "foo b"); - DoCharTest("foo %lc", 'c', "foo c"); - DoWCharTest("foo %Lc", wb, "foo b"); - DoWCharTest("foo %I64c", wb, "foo b"); - DoWCharTest("foo %5c", wb, "foo b"); - DoWCharTest("foo %.0c", wb, "foo b"); - DoWCharTest("foo %-5c", wb, "foo b "); - DoWCharTest("foo %05c", wb, "foo 0000b"); - DoWCharTest("foo % c", wb, "foo b"); - DoWCharTest("foo %#c", wb, "foo b"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test7/test7.cpp new file mode 100644 index 0000000000..c9f87d4343 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test7/test7.cpp @@ -0,0 +1,44 @@ +// 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: test7.c +** +** Purpose: Test #7 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wb = (WCHAR) 'b'; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoWCharTest("foo %c", wb, "foo b"); + DoWCharTest("foo %hc", wb, "foo b"); + DoCharTest("foo %lc", 'c', "foo c"); + DoWCharTest("foo %Lc", wb, "foo b"); + DoWCharTest("foo %I64c", wb, "foo b"); + DoWCharTest("foo %5c", wb, "foo b"); + DoWCharTest("foo %.0c", wb, "foo b"); + DoWCharTest("foo %-5c", wb, "foo b "); + DoWCharTest("foo %05c", wb, "foo 0000b"); + DoWCharTest("foo % c", wb, "foo b"); + DoWCharTest("foo %#c", wb, "foo b"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test8/CMakeLists.txt index 34c92e1045..8dac76fc3a 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_vsprintf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test8/test8.c deleted file mode 100644 index e741d1da8b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test8/test8.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test8.c -** -** Purpose: Test #8 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %d", pos, "foo 42"); - DoNumTest("foo %ld", 0xFFFF, "foo 65535"); - DoNumTest("foo %hd", 0xFFFF, "foo -1"); - DoNumTest("foo %Ld", pos, "foo 42"); - DoI64Test("foo %I64d", l, "42", "foo 42"); - DoNumTest("foo %3d", pos, "foo 42"); - DoNumTest("foo %-3d", pos, "foo 42 "); - DoNumTest("foo %.1d", pos, "foo 42"); - DoNumTest("foo %.3d", pos, "foo 042"); - DoNumTest("foo %03d", pos, "foo 042"); - DoNumTest("foo %#d", pos, "foo 42"); - DoNumTest("foo %+d", pos, "foo +42"); - DoNumTest("foo % d", pos, "foo 42"); - DoNumTest("foo %+d", neg, "foo -42"); - DoNumTest("foo % d", neg, "foo -42"); - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test8/test8.cpp new file mode 100644 index 0000000000..e741d1da8b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test8/test8.cpp @@ -0,0 +1,52 @@ +// 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: test8.c +** +** Purpose: Test #8 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %d", pos, "foo 42"); + DoNumTest("foo %ld", 0xFFFF, "foo 65535"); + DoNumTest("foo %hd", 0xFFFF, "foo -1"); + DoNumTest("foo %Ld", pos, "foo 42"); + DoI64Test("foo %I64d", l, "42", "foo 42"); + DoNumTest("foo %3d", pos, "foo 42"); + DoNumTest("foo %-3d", pos, "foo 42 "); + DoNumTest("foo %.1d", pos, "foo 42"); + DoNumTest("foo %.3d", pos, "foo 042"); + DoNumTest("foo %03d", pos, "foo 042"); + DoNumTest("foo %#d", pos, "foo 42"); + DoNumTest("foo %+d", pos, "foo +42"); + DoNumTest("foo % d", pos, "foo 42"); + DoNumTest("foo %+d", neg, "foo -42"); + DoNumTest("foo % d", neg, "foo -42"); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vsprintf/test9/CMakeLists.txt index 1fe177de95..95f0faad87 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_vsprintf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/vsprintf/test9/test9.c deleted file mode 100644 index e1f7c84195..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/test9/test9.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test9.c -** -** Purpose: Test #9 for the vsprintf function. -** -** -**===================================================================*/ - -#include -#include "../vsprintf.h" - -/* - * Notes: memcmp is used, as is strlen. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - { - return(FAIL); - } - - DoNumTest("foo %i", pos, "foo 42"); - DoNumTest("foo %li", 0xFFFF, "foo 65535"); - DoNumTest("foo %hi", 0xFFFF, "foo -1"); - DoNumTest("foo %Li", pos, "foo 42"); - DoI64Test("foo %I64i", l, "42", "foo 42"); - DoNumTest("foo %3i", pos, "foo 42"); - DoNumTest("foo %-3i", pos, "foo 42 "); - DoNumTest("foo %.1i", pos, "foo 42"); - DoNumTest("foo %.3i", pos, "foo 042"); - DoNumTest("foo %03i", pos, "foo 042"); - DoNumTest("foo %#i", pos, "foo 42"); - DoNumTest("foo %+i", pos, "foo +42"); - DoNumTest("foo % i", pos, "foo 42"); - DoNumTest("foo %+i", neg, "foo -42"); - DoNumTest("foo % i", neg, "foo -42"); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/vsprintf/test9/test9.cpp new file mode 100644 index 0000000000..e1f7c84195 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/test9/test9.cpp @@ -0,0 +1,51 @@ +// 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: test9.c +** +** Purpose: Test #9 for the vsprintf function. +** +** +**===================================================================*/ + +#include +#include "../vsprintf.h" + +/* + * Notes: memcmp is used, as is strlen. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest("foo %i", pos, "foo 42"); + DoNumTest("foo %li", 0xFFFF, "foo 65535"); + DoNumTest("foo %hi", 0xFFFF, "foo -1"); + DoNumTest("foo %Li", pos, "foo 42"); + DoI64Test("foo %I64i", l, "42", "foo 42"); + DoNumTest("foo %3i", pos, "foo 42"); + DoNumTest("foo %-3i", pos, "foo 42 "); + DoNumTest("foo %.1i", pos, "foo 42"); + DoNumTest("foo %.3i", pos, "foo 042"); + DoNumTest("foo %03i", pos, "foo 042"); + DoNumTest("foo %#i", pos, "foo 42"); + DoNumTest("foo %+i", pos, "foo +42"); + DoNumTest("foo % i", pos, "foo 42"); + DoNumTest("foo %+i", neg, "foo -42"); + DoNumTest("foo % i", neg, "foo -42"); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vsprintf/vsprintf.h b/src/pal/tests/palsuite/c_runtime/vsprintf/vsprintf.h index 10648d896f..7b04a777ca 100644 --- a/src/pal/tests/palsuite/c_runtime/vsprintf/vsprintf.h +++ b/src/pal/tests/palsuite/c_runtime/vsprintf/vsprintf.h @@ -26,7 +26,7 @@ int testvsp(char* buf, const char* format, ...) return (retVal); } -void DoStrTest(char *formatstr, char* param, char *checkstr) +void DoStrTest(const char *formatstr, char* param, const char *checkstr) { char buf[256] = { 0 }; @@ -39,7 +39,7 @@ void DoStrTest(char *formatstr, char* param, char *checkstr) } } -void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) +void DoWStrTest(const char *formatstr, WCHAR* param, const char *checkstr) { char buf[256] = { 0 }; @@ -53,7 +53,7 @@ void DoWStrTest(char *formatstr, WCHAR* param, char *checkstr) } -void DoCharTest(char *formatstr, char param, char *checkstr) +void DoCharTest(const char *formatstr, char param, const char *checkstr) { char buf[256] = { 0 }; @@ -66,7 +66,7 @@ void DoCharTest(char *formatstr, char param, char *checkstr) } } -void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) +void DoWCharTest(const char *formatstr, WCHAR param, const char *checkstr) { char buf[256] = { 0 }; @@ -79,7 +79,7 @@ void DoWCharTest(char *formatstr, WCHAR param, char *checkstr) } } -void DoNumTest(char *formatstr, int value, char *checkstr) +void DoNumTest(const char *formatstr, int value, const char *checkstr) { char buf[256] = { 0 }; @@ -92,7 +92,7 @@ void DoNumTest(char *formatstr, int value, char *checkstr) } } -void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr) +void DoI64Test(const char *formatstr, INT64 value, char *valuestr, const char *checkstr) { char buf[256] = { 0 }; @@ -104,7 +104,7 @@ void DoI64Test(char *formatstr, INT64 value, char *valuestr, char *checkstr) valuestr, formatstr, checkstr, buf); } } -void DoDoubleTest(char *formatstr, double value, char *checkstr1, char +void DoDoubleTest(const char *formatstr, double value, const char *checkstr1, char *checkstr2) { char buf[256] = { 0 }; @@ -119,8 +119,8 @@ void DoDoubleTest(char *formatstr, double value, char *checkstr1, char } } /*FROM TEST 9*/ -void DoArgumentPrecTest(char *formatstr, int precision, void *param, - char *paramstr, char *checkstr1, char *checkstr2) +void DoArgumentPrecTest(const char *formatstr, int precision, void *param, + char *paramstr, const char *checkstr1, const char *checkstr2) { char buf[256]; @@ -135,8 +135,8 @@ void DoArgumentPrecTest(char *formatstr, int precision, void *param, } -void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param, - char *checkstr1, char *checkstr2) +void DoArgumentPrecDoubleTest(const char *formatstr, int precision, double param, + const char *checkstr1, const char *checkstr2) { char buf[256]; @@ -150,8 +150,8 @@ void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param, } } /*FROM TEST4*/ -void DoPointerTest(char *formatstr, void* param, char* paramstr, - char *checkstr1) +void DoPointerTest(const char *formatstr, void* param, char* paramstr, + const char *checkstr1) { char buf[256] = { 0 }; @@ -164,8 +164,8 @@ void DoPointerTest(char *formatstr, void* param, char* paramstr, } } -void DoI64DoubleTest(char *formatstr, INT64 value, char *valuestr, - char *checkstr1) +void DoI64DoubleTest(const char *formatstr, INT64 value, char *valuestr, + const char *checkstr1) { char buf[256] = { 0 }; @@ -178,7 +178,7 @@ void DoI64DoubleTest(char *formatstr, INT64 value, char *valuestr, } } -void DoTest(char *formatstr, int param, char *checkstr) +void DoTest(const char *formatstr, int param, const char *checkstr) { char buf[256] = { 0 }; int n = -1; @@ -196,7 +196,7 @@ void DoTest(char *formatstr, int param, char *checkstr) } } -void DoShortTest(char *formatstr, int param, char *checkstr) +void DoShortTest(const char *formatstr, int param, const char *checkstr) { char buf[256] = { 0 }; short int n = -1; diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test1/CMakeLists.txt index 97fbeb4e28..1d6233744a 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_vswprintf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.c deleted file mode 100644 index d386ce104f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -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; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.cpp new file mode 100644 index 0000000000..d386ce104f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.cpp @@ -0,0 +1,41 @@ +// 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: test1.c +** +** Purpose: Test #1 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +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; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test10/CMakeLists.txt index 06c11f68ca..e5301427eb 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_vswprintf_test10 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.c deleted file mode 100644 index 7f316e28f6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test10.c -** -** Purpose: Test #10 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest(convert("foo %o"), pos, convert("foo 52")); - DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); - DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); - DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); - DoI64NumTest(convert("foo %I64o"), l, "42", convert("foo 52")); - DoNumTest(convert("foo %3o"), pos, convert("foo 52")); - DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); - DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); - DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); - DoNumTest(convert("foo %03o"), pos, convert("foo 052")); - DoNumTest(convert("foo %#o"), pos, convert("foo 052")); - DoNumTest(convert("foo %+o"), pos, convert("foo 52")); - DoNumTest(convert("foo % o"), pos, convert("foo 52")); - DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); - DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.cpp new file mode 100644 index 0000000000..7f316e28f6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.cpp @@ -0,0 +1,48 @@ +// 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: test10.c +** +** Purpose: Test #10 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %o"), pos, convert("foo 52")); + DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); + DoI64NumTest(convert("foo %I64o"), l, "42", convert("foo 52")); + DoNumTest(convert("foo %3o"), pos, convert("foo 52")); + DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); + DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); + DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); + DoNumTest(convert("foo %03o"), pos, convert("foo 052")); + DoNumTest(convert("foo %#o"), pos, convert("foo 052")); + DoNumTest(convert("foo %+o"), pos, convert("foo 52")); + DoNumTest(convert("foo % o"), pos, convert("foo 52")); + DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); + DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test11/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test11/CMakeLists.txt index 5237ba4e1d..1cfadb9300 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test11.c + test11.cpp ) add_executable(paltest_vswprintf_test11 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.c deleted file mode 100644 index 608069f829..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test11.c -** -** Purpose: Test #11 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest(convert("foo %u"), pos, convert("foo 42")); - DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); - DoI64NumTest(convert("foo %I64u"), l, "42", convert("foo 42")); - DoNumTest(convert("foo %3u"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); - DoNumTest(convert("foo %03u"), pos, convert("foo 042")); - DoNumTest(convert("foo %#u"), pos, convert("foo 42")); - DoNumTest(convert("foo %+u"), pos, convert("foo 42")); - DoNumTest(convert("foo % u"), pos, convert("foo 42")); - DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); - DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.cpp new file mode 100644 index 0000000000..608069f829 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.cpp @@ -0,0 +1,48 @@ +// 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: test11.c +** +** Purpose: Test #11 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %u"), pos, convert("foo 42")); + DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64u"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3u"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); + DoNumTest(convert("foo %03u"), pos, convert("foo 042")); + DoNumTest(convert("foo %#u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), pos, convert("foo 42")); + DoNumTest(convert("foo % u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); + DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test12/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test12/CMakeLists.txt index 26199c3dcc..f5a582a970 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_vswprintf_test12 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.c deleted file mode 100644 index 36b203853a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test12.c -** -** Purpose: Test #12 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); - DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); - DoI64NumTest(convert("foo %I64x"), l, "0x1234567887654321", - convert("foo 1234567887654321")); - DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); - DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); - DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); - DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); - DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); - DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); - DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.cpp new file mode 100644 index 0000000000..36b203853a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.cpp @@ -0,0 +1,48 @@ +// 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: test12.c +** +** Purpose: Test #12 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); + DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); + DoI64NumTest(convert("foo %I64x"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); + DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); + DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); + DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test13/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test13/CMakeLists.txt index d0acd98d64..5571d7336f 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test13.c + test13.cpp ) add_executable(paltest_vswprintf_test13 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.c deleted file mode 100644 index 63dc36a960..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: test13.c -** -** Purpose: Test #13 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 0x1234ab; - INT64 l = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); - DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); - DoI64NumTest(convert("foo %I64X"), l, "0x1234567887654321", - convert("foo 1234567887654321")); - DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); - DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); - DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); - DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); - DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); - DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); - DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.cpp new file mode 100644 index 0000000000..63dc36a960 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.cpp @@ -0,0 +1,48 @@ +// 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: test13.c +** +** Purpose: Test #13 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); + DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); + DoI64NumTest(convert("foo %I64X"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); + DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); + DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); + DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test14/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test14/CMakeLists.txt index 06c12674a4..234029ead4 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test14.c + test14.cpp ) add_executable(paltest_vswprintf_test14 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.c deleted file mode 100644 index bb4ab16a54..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.c +++ /dev/null @@ -1,61 +0,0 @@ -// 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: test14.c -** -** Purpose: Test #14 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), - convert("foo 2.560000e+02 ")); - DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), - convert("foo 2.6e+02")); - DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), - convert("foo 2.56000000e+02")); - DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), - convert("foo 002.560000e+02")); - DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), - convert("foo +2.560000e+02")); - DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), - convert("foo 2.560000e+02")); - DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), - convert("foo -2.560000e+02")); - DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), - convert("foo -2.560000e+02")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.cpp new file mode 100644 index 0000000000..bb4ab16a54 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.cpp @@ -0,0 +1,61 @@ +// 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: test14.c +** +** Purpose: Test #14 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), + convert("foo 2.560000e+02 ")); + DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), + convert("foo 2.6e+02")); + DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), + convert("foo 2.56000000e+02")); + DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), + convert("foo 002.560000e+02")); + DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), + convert("foo +2.560000e+02")); + DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test15/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test15/CMakeLists.txt index 05dc41b0d8..b705268bc7 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test15.c + test15.cpp ) add_executable(paltest_vswprintf_test15 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.c deleted file mode 100644 index 6296220c4e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: test15.c -** -** Purpose: Test #15 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - double val = 256.0; - double neg = -256.0; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), - convert("foo 2.560000E+02 ")); - DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), - convert("foo 2.6E+02")); - DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), - convert("foo 2.56000000E+02")); - DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), - convert("foo 002.560000E+02")); - DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), - convert("foo +2.560000E+02")); - DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), - convert("foo 2.560000E+02")); - DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), - convert("foo -2.560000E+02")); - DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), - convert("foo -2.560000E+002")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.cpp new file mode 100644 index 0000000000..6296220c4e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.cpp @@ -0,0 +1,62 @@ +// 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: test15.c +** +** Purpose: Test #15 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), + convert("foo 2.560000E+02 ")); + DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), + convert("foo 2.6E+02")); + DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), + convert("foo 2.56000000E+02")); + DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), + convert("foo 002.560000E+02")); + DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), + convert("foo +2.560000E+02")); + DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+002")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test16/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test16/CMakeLists.txt index 3c42755043..da296bcf32 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test16.c + test16.cpp ) add_executable(paltest_vswprintf_test16 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.c deleted file mode 100644 index 3a2059a491..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.c +++ /dev/null @@ -1,61 +0,0 @@ -// 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: test16.c -** -** Purpose: Test #16 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), - convert("foo 2560.001000 ")); - DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), - convert("foo 2560.0")); - DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), - convert("foo 2560.00100000")); - DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), - convert("foo 02560.001000")); - DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), - convert("foo +2560.001000")); - DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), - convert("foo 2560.001000")); - DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), - convert("foo -2560.001000")); - DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), - convert("foo -2560.001000")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.cpp new file mode 100644 index 0000000000..3a2059a491 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.cpp @@ -0,0 +1,61 @@ +// 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: test16.c +** +** Purpose: Test #16 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), + convert("foo 2560.001000 ")); + DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), + convert("foo 2560.0")); + DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), + convert("foo 2560.00100000")); + DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), + convert("foo 02560.001000")); + DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), + convert("foo +2560.001000")); + DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test17/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test17/CMakeLists.txt index b94c466d5f..02234c1672 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test17.c + test17.cpp ) add_executable(paltest_vswprintf_test17 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.c deleted file mode 100644 index 95e3bd9995..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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: test17.c -** -** Purpose: Test #17 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), - convert("foo 2560 ")); - DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), - convert("foo 3e+03")); - DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), - convert("foo 2.6e+03")); - DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), - convert("foo 2560.001")); - DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), - convert("foo 002560")); - DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), - convert("foo 2560.00")); - DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), - convert("foo +2560")); - DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), - convert("foo -2560")); - DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), - convert("foo -2560")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.cpp new file mode 100644 index 0000000000..95e3bd9995 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.cpp @@ -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: test17.c +** +** Purpose: Test #17 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), + convert("foo 3e+03")); + DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), + convert("foo 2.6e+03")); + DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test18/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test18/CMakeLists.txt index 57cc8ccb03..0c0e5b566b 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test18.c + test18.cpp ) add_executable(paltest_vswprintf_test18 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.c deleted file mode 100644 index ae7ae4c44b..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - double val = 2560.001; - double neg = -2560.001; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), - convert("foo 2560 ")); - DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), - convert("foo 3E+03")); - DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), - convert("foo 2.6E+03")); - DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), - convert("foo 2560.001")); - DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), - convert("foo 002560")); - DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), - convert("foo 2560.00")); - DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), - convert("foo +2560")); - DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), - convert("foo 2560")); - DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), - convert("foo -2560")); - DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), - convert("foo -2560")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.cpp new file mode 100644 index 0000000000..ae7ae4c44b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.cpp @@ -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: test18.c +** +** Purpose: Test #18 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), + convert("foo 3E+03")); + DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), + convert("foo 2.6E+03")); + DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test19/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test19/CMakeLists.txt index 2187b58727..066db8ab84 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test19.c + test19.cpp ) add_executable(paltest_vswprintf_test19 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.c deleted file mode 100644 index c00185be6d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.c +++ /dev/null @@ -1,137 +0,0 @@ -// 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: test18.c -** -** Purpose: Test #18 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -#define DOTEST(a,b,c,d,e) DoTest(a,b,(void*)c,d,e) - -void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, - WCHAR *paramstr, WCHAR *checkstr1, WCHAR *checkstr2) -{ - WCHAR buf[256]; - - testvswp(buf, formatstr, precision, param); - if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && - memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) - { - Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" - "Expected \"%s\" or \"%s\", got \"%s\".\n", - paramstr, - convertC(formatstr), - precision, - convertC(checkstr1), - convertC(checkstr2), - convertC(buf)); - } -} -void DoArgumentPrecDoubleTest(WCHAR *formatstr, int precision, double param, - WCHAR *checkstr1, WCHAR *checkstr2) -{ - WCHAR buf[256]; - - testvswp(buf, 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)); - } -} - -/* - * Uses memcmp & wcslen - */ - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoArgumentPrecTest(convert("%.*s"), 2, convert("bar"), convert("bar"), - convert("ba"), convert("ba")); - DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', convert("a"), - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', convert("a"), - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', convert("a"), - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', convert("a"), - convert("a"), convert("a")); - DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, convert("42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, convert("42"), - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, convert("42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, convert("42"), - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, convert("42"), - convert("52"), convert("52")); - DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, convert("42"), - convert("052"), convert("052")); - DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, convert("42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, convert("42"), - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, convert("0x42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, convert("0x42"), - convert("042"), convert("042")); - DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, convert("0x42"), - convert("42"), convert("42")); - DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, convert("0x42"), - convert("042"), convert("042")); - - - DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000"), - convert("2.0e+00")); - DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000"), - convert("2.010e+00")); - DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000"), - convert("2.0E+00")); - DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000"), - convert("2.010E+00")); - DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0"), - convert("2.0")); - DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010"), - convert("2.010")); - DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002"), - convert("3e+02")); - DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01"), - convert("256.01")); - DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002"), - convert("3E+02")); - DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256"), - convert("256")); - DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01"), - convert("256.01")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.cpp new file mode 100644 index 0000000000..1d1c5656b2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.cpp @@ -0,0 +1,137 @@ +// 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: test18.c +** +** Purpose: Test #18 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +#define DOTEST(a,b,c,d,e) DoTest(a,b,(void*)c,d,e) + +void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, + WCHAR *paramstr, WCHAR *checkstr1, WCHAR *checkstr2) +{ + WCHAR buf[256]; + + testvswp(buf, formatstr, precision, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + paramstr, + convertC(formatstr), + precision, + convertC(checkstr1), + convertC(checkstr2), + convertC(buf)); + } +} +void DoArgumentPrecDoubleTest(WCHAR *formatstr, int precision, double param, + WCHAR *checkstr1, WCHAR *checkstr2) +{ + WCHAR buf[256]; + + testvswp(buf, 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)); + } +} + +/* + * Uses memcmp & wcslen + */ + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoArgumentPrecTest(convert("%.*s"), 2, (void*)convert("bar"), convert("bar"), + convert("ba"), convert("ba")); + DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, convert("42"), + convert("52"), convert("52")); + DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, convert("42"), + convert("052"), convert("052")); + DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, convert("0x42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, convert("0x42"), + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, convert("0x42"), + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, convert("0x42"), + convert("042"), convert("042")); + + + DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000"), + convert("2.0e+00")); + DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000"), + convert("2.010e+00")); + DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000"), + convert("2.0E+00")); + DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000"), + convert("2.010E+00")); + DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0"), + convert("2.0")); + DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010"), + convert("2.010")); + DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002"), + convert("3e+02")); + DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01"), + convert("256.01")); + DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002"), + convert("3E+02")); + DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01"), + convert("256.01")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test2/CMakeLists.txt index 295448cb0c..abfceca9e2 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_vswprintf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.c deleted file mode 100644 index 491d99f0cf..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.c +++ /dev/null @@ -1,40 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); - DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); - DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); - DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); - DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); - DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.cpp new file mode 100644 index 0000000000..491d99f0cf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.cpp @@ -0,0 +1,40 @@ +// 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: test2.c +** +** Purpose: Test #2 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); + DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test3/CMakeLists.txt index 1fb6272ae7..7f4798dbc5 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_vswprintf_test3 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.c deleted file mode 100644 index 1eb0b65ebe..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.c +++ /dev/null @@ -1,40 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoStrTest(convert("foo %S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); - DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); - DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); - DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); - DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); - DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); - DoStrTest(convert("foo %5.2S"), "bar", convert("foo ba")); - DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); - DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.cpp new file mode 100644 index 0000000000..1eb0b65ebe --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.cpp @@ -0,0 +1,40 @@ +// 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: test3.c +** +** Purpose: Test #3 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoStrTest(convert("foo %S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); + DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %5.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); + DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test4/CMakeLists.txt index cae0806e03..05701ac179 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_vswprintf_test4 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.c deleted file mode 100644 index 5c9047b5a7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.c +++ /dev/null @@ -1,118 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* 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)); - } -} - -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[]) -{ - void *ptr = (void*) 0x123456; - INT64 lptr = I64(0x1234567887654321); - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - -/* -** Run only on 64 bit platforms -*/ -#if defined(BIT64) && defined(PLATFORM_UNIX) - Trace("Testing for 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("0000000000000000")); - DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), - convert("0000000000123456")); - DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), - convert(" 0000000000123456")); - DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), - convert(" 0000000000123456")); - DoPointerTest(convert("%-17p"), ptr, convert("pointer to 0x123456"), - convert("0000000000123456 ")); - DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), - convert("0000000000123456")); - DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), - convert("0X0000000000123456")); - DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), - convert("00003456")); - DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoI64DoubleTest(convert("%I64p"), lptr, - convert("pointer to 0x1234567887654321"), convert("1234567887654321")); - -#else - Trace("Testing for Non 64 Bit Platforms \n"); - DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000")); - DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoPointerTest(convert("%9p"), ptr, convert("pointer to 0x123456"), - convert(" 00123456")); - DoPointerTest(convert("%09p"), ptr, convert("pointer to 0x123456"), - convert(" 00123456")); - DoPointerTest(convert("%-9p"), ptr, convert("pointer to 0x123456"), - convert("00123456 ")); - DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), - convert("0X00123456")); - DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), - convert("00003456")); - DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), - convert("00123456")); - DoI64DoubleTest(convert("%I64p"), lptr, - convert("pointer to 0x1234567887654321"), convert("1234567887654321")); - -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.cpp new file mode 100644 index 0000000000..5c9047b5a7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.cpp @@ -0,0 +1,118 @@ +// 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: test4.c +** +** Purpose: Test #4 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* 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)); + } +} + +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[]) +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + +/* +** Run only on 64 bit platforms +*/ +#if defined(BIT64) && defined(PLATFORM_UNIX) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("0000000000000000")); + DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), + convert(" 0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), + convert(" 0000000000123456")); + DoPointerTest(convert("%-17p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456")); + DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), + convert("0X0000000000123456")); + DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), + convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoI64DoubleTest(convert("%I64p"), lptr, + convert("pointer to 0x1234567887654321"), convert("1234567887654321")); + +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000")); + DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%9p"), ptr, convert("pointer to 0x123456"), + convert(" 00123456")); + DoPointerTest(convert("%09p"), ptr, convert("pointer to 0x123456"), + convert(" 00123456")); + DoPointerTest(convert("%-9p"), ptr, convert("pointer to 0x123456"), + convert("00123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), + convert("0X00123456")); + DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), + convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoI64DoubleTest(convert("%I64p"), lptr, + convert("pointer to 0x1234567887654321"), convert("1234567887654321")); + +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test5/CMakeLists.txt index 7c480455ed..888ce27d22 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_vswprintf_test5 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test5/test5.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test5/test5.c deleted file mode 100644 index 42146c8be7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test5/test5.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -static void DoTest(WCHAR *formatstr, int param, WCHAR *checkstr) -{ - WCHAR buf[256] = { 0 }; - 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)); - } -} - -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[]) -{ - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoTest(convert("foo %n bar"), 4, convert("foo bar")); - DoTest(convert("foo %#n bar"), 4, convert("foo bar")); - DoTest(convert("foo % n bar"), 4, convert("foo bar")); - DoTest(convert("foo %+n bar"), 4, convert("foo bar")); - DoTest(convert("foo %-n bar"), 4, convert("foo bar")); - DoTest(convert("foo %0n bar"), 4, convert("foo bar")); - DoShortTest(convert("foo %hn bar"), 4, convert("foo bar")); - DoTest(convert("foo %ln bar"), 4, convert("foo bar")); - DoTest(convert("foo %Ln bar"), 4, convert("foo bar")); - DoTest(convert("foo %I64n bar"), 4, convert("foo bar")); - DoTest(convert("foo %20.3n bar"), 4, convert("foo bar")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test5/test5.cpp new file mode 100644 index 0000000000..42146c8be7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test5/test5.cpp @@ -0,0 +1,79 @@ +// 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: test5.c +** +** Purpose: Test #5 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +static void DoTest(WCHAR *formatstr, int param, WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + 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)); + } +} + +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[]) +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoTest(convert("foo %n bar"), 4, convert("foo bar")); + DoTest(convert("foo %#n bar"), 4, convert("foo bar")); + DoTest(convert("foo % n bar"), 4, convert("foo bar")); + DoTest(convert("foo %+n bar"), 4, convert("foo bar")); + DoTest(convert("foo %-n bar"), 4, convert("foo bar")); + DoTest(convert("foo %0n bar"), 4, convert("foo bar")); + DoShortTest(convert("foo %hn bar"), 4, convert("foo bar")); + DoTest(convert("foo %ln bar"), 4, convert("foo bar")); + DoTest(convert("foo %Ln bar"), 4, convert("foo bar")); + DoTest(convert("foo %I64n bar"), 4, convert("foo bar")); + DoTest(convert("foo %20.3n bar"), 4, convert("foo bar")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test6/CMakeLists.txt index d7de580853..bfbb17ccef 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_vswprintf_test6 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.c deleted file mode 100644 index 51e99267a1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoWCharTest(convert("foo %c"), wc, convert("foo c")); - DoCharTest(convert("foo %hc"), 'b', convert("foo b")); - DoWCharTest(convert("foo %lc"), wc, convert("foo c")); - DoWCharTest(convert("foo %Lc"), wc, convert("foo c")); - DoWCharTest(convert("foo %I64c"), wc, convert("foo c")); - DoWCharTest(convert("foo %5c"), wc, convert("foo c")); - DoWCharTest(convert("foo %.0c"), wc, convert("foo c")); - DoWCharTest(convert("foo %-5c"), wc, convert("foo c ")); - DoWCharTest(convert("foo %05c"), wc, convert("foo 0000c")); - DoWCharTest(convert("foo % c"), wc, convert("foo c")); - DoWCharTest(convert("foo %#c"), wc, convert("foo c")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.cpp new file mode 100644 index 0000000000..51e99267a1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.cpp @@ -0,0 +1,41 @@ +// 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: test6.c +** +** Purpose: Test #6 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoWCharTest(convert("foo %c"), wc, convert("foo c")); + DoCharTest(convert("foo %hc"), 'b', convert("foo b")); + DoWCharTest(convert("foo %lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %Lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %I64c"), wc, convert("foo c")); + DoWCharTest(convert("foo %5c"), wc, convert("foo c")); + DoWCharTest(convert("foo %.0c"), wc, convert("foo c")); + DoWCharTest(convert("foo %-5c"), wc, convert("foo c ")); + DoWCharTest(convert("foo %05c"), wc, convert("foo 0000c")); + DoWCharTest(convert("foo % c"), wc, convert("foo c")); + DoWCharTest(convert("foo %#c"), wc, convert("foo c")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test7/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test7/CMakeLists.txt index eb07ee2cae..8b980586bc 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_vswprintf_test7 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.c deleted file mode 100644 index 6037cb0fe7..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: test7.c -** -** Purpose: Test #7 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wc = (WCHAR) 'c'; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoCharTest(convert("foo %C"), 'b', convert("foo b")); - DoWCharTest(convert("foo %hC"), wc, convert("foo c")); - DoCharTest(convert("foo %lC"), 'b', convert("foo b")); - DoCharTest(convert("foo %LC"), 'b', convert("foo b")); - DoCharTest(convert("foo %I64C"), 'b', convert("foo b")); - DoCharTest(convert("foo %5C"), 'b', convert("foo b")); - DoCharTest(convert("foo %.0C"), 'b', convert("foo b")); - DoCharTest(convert("foo %-5C"), 'b', convert("foo b ")); - DoCharTest(convert("foo %05C"), 'b', convert("foo 0000b")); - DoCharTest(convert("foo % C"), 'b', convert("foo b")); - DoCharTest(convert("foo %#C"), 'b', convert("foo b")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.cpp new file mode 100644 index 0000000000..6037cb0fe7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.cpp @@ -0,0 +1,41 @@ +// 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: test7.c +** +** Purpose: Test #7 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoCharTest(convert("foo %C"), 'b', convert("foo b")); + DoWCharTest(convert("foo %hC"), wc, convert("foo c")); + DoCharTest(convert("foo %lC"), 'b', convert("foo b")); + DoCharTest(convert("foo %LC"), 'b', convert("foo b")); + DoCharTest(convert("foo %I64C"), 'b', convert("foo b")); + DoCharTest(convert("foo %5C"), 'b', convert("foo b")); + DoCharTest(convert("foo %.0C"), 'b', convert("foo b")); + DoCharTest(convert("foo %-5C"), 'b', convert("foo b ")); + DoCharTest(convert("foo %05C"), 'b', convert("foo 0000b")); + DoCharTest(convert("foo % C"), 'b', convert("foo b")); + DoCharTest(convert("foo %#C"), 'b', convert("foo b")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test8/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test8/CMakeLists.txt index ed35ea8dd0..07ba473844 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_vswprintf_test8 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.c deleted file mode 100644 index baba524650..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test8.c -** -** Purpose: Test #8 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest(convert("foo %d"), pos, convert("foo 42")); - DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); - DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); - DoI64NumTest(convert("foo %I64d"), l, "42", convert("foo 42")); - DoNumTest(convert("foo %3d"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); - DoNumTest(convert("foo %03d"), pos, convert("foo 042")); - DoNumTest(convert("foo %#d"), pos, convert("foo 42")); - DoNumTest(convert("foo %+d"), pos, convert("foo +42")); - DoNumTest(convert("foo % d"), pos, convert("foo 42")); - DoNumTest(convert("foo %+d"), neg, convert("foo -42")); - DoNumTest(convert("foo % d"), neg, convert("foo -42")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.cpp new file mode 100644 index 0000000000..baba524650 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.cpp @@ -0,0 +1,47 @@ +// 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: test8.c +** +** Purpose: Test #8 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %d"), pos, convert("foo 42")); + DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64d"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3d"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); + DoNumTest(convert("foo %03d"), pos, convert("foo 042")); + DoNumTest(convert("foo %#d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), pos, convert("foo +42")); + DoNumTest(convert("foo % d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), neg, convert("foo -42")); + DoNumTest(convert("foo % d"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test9/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/vswprintf/test9/CMakeLists.txt index 7098da31d0..11c77787e9 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_vswprintf_test9 diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.c b/src/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.c deleted file mode 100644 index 5de004f5ed..0000000000 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test9.c -** -** Purpose: Test #9 for the vswprintf function. -** -** -**===================================================================*/ - -#include -#include "../vswprintf.h" - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with wcslen */ - -int __cdecl main(int argc, char *argv[]) -{ - int neg = -42; - int pos = 42; - INT64 l = 42; - - if (PAL_Initialize(argc, argv) != 0) - return(FAIL); - - DoNumTest(convert("foo %i"), pos, convert("foo 42")); - DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); - DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); - DoNumTest(convert("foo %Li"), pos, convert("foo 42")); - DoI64NumTest(convert("foo %I64i"), l, "42", convert("foo 42")); - DoNumTest(convert("foo %3i"), pos, convert("foo 42")); - DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); - DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); - DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); - DoNumTest(convert("foo %03i"), pos, convert("foo 042")); - DoNumTest(convert("foo %#i"), pos, convert("foo 42")); - DoNumTest(convert("foo %+i"), pos, convert("foo +42")); - DoNumTest(convert("foo % i"), pos, convert("foo 42")); - DoNumTest(convert("foo %+i"), neg, convert("foo -42")); - DoNumTest(convert("foo % i"), neg, convert("foo -42")); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.cpp b/src/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.cpp new file mode 100644 index 0000000000..5de004f5ed --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.cpp @@ -0,0 +1,47 @@ +// 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: test9.c +** +** Purpose: Test #9 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +int __cdecl main(int argc, char *argv[]) +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %i"), pos, convert("foo 42")); + DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Li"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64i"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3i"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); + DoNumTest(convert("foo %03i"), pos, convert("foo 042")); + DoNumTest(convert("foo %#i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), pos, convert("foo +42")); + DoNumTest(convert("foo % i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), neg, convert("foo -42")); + DoNumTest(convert("foo % i"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/vswprintf/vswprintf.h b/src/pal/tests/palsuite/c_runtime/vswprintf/vswprintf.h index a79c9bb7a9..37a379212e 100644 --- a/src/pal/tests/palsuite/c_runtime/vswprintf/vswprintf.h +++ b/src/pal/tests/palsuite/c_runtime/vswprintf/vswprintf.h @@ -27,7 +27,7 @@ int testvswp(wchar_t* buf, const wchar_t* format, ...) return( retVal); } -void DoWStrTest(WCHAR *formatstr, WCHAR *param, WCHAR *checkstr) +void DoWStrTest(const WCHAR *formatstr, WCHAR *param, const WCHAR *checkstr) { WCHAR buf[256] = { 0 }; @@ -42,7 +42,7 @@ void DoWStrTest(WCHAR *formatstr, WCHAR *param, WCHAR *checkstr) } } -void DoStrTest(WCHAR *formatstr, char *param, WCHAR *checkstr) +void DoStrTest(const WCHAR *formatstr, char *param, const WCHAR *checkstr) { WCHAR buf[256] = { 0 }; @@ -57,7 +57,7 @@ void DoStrTest(WCHAR *formatstr, char *param, WCHAR *checkstr) } } -void DoCharTest(WCHAR *formatstr, char param, WCHAR *checkstr) +void DoCharTest(const WCHAR *formatstr, char param, const WCHAR *checkstr) { WCHAR buf[256] = { 0 }; @@ -71,7 +71,7 @@ void DoCharTest(WCHAR *formatstr, char param, WCHAR *checkstr) } } -void DoWCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) +void DoWCharTest(const WCHAR *formatstr, WCHAR param, const WCHAR *checkstr) { WCHAR buf[256] = { 0 }; @@ -85,7 +85,7 @@ void DoWCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) } } -void DoNumTest(WCHAR *formatstr, int value, WCHAR*checkstr) +void DoNumTest(const WCHAR *formatstr, int value, const WCHAR *checkstr) { WCHAR buf[256] = { 0 }; @@ -98,7 +98,7 @@ void DoNumTest(WCHAR *formatstr, int value, WCHAR*checkstr) } } -void DoI64NumTest(WCHAR *formatstr, INT64 value, char *valuestr, WCHAR*checkstr) +void DoI64NumTest(const WCHAR *formatstr, INT64 value, char *valuestr, const WCHAR *checkstr) { WCHAR buf[256] = { 0 }; @@ -110,7 +110,7 @@ void DoI64NumTest(WCHAR *formatstr, INT64 value, char *valuestr, WCHAR*checkstr) convertC(checkstr), convertC(buf)); } } -void DoDoubleTest(WCHAR *formatstr, double value, WCHAR *checkstr1, WCHAR +void DoDoubleTest(const WCHAR *formatstr, double value, const WCHAR *checkstr1, WCHAR *checkstr2) { WCHAR buf[256] = { 0 }; diff --git a/src/pal/tests/palsuite/c_runtime/wcscat/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcscat/test1/CMakeLists.txt index 34dfee01bd..815c585de4 100644 --- a/src/pal/tests/palsuite/c_runtime/wcscat/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcscat/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcscat_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcscat/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcscat/test1/test1.c deleted file mode 100644 index 789eebf5a3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcscat/test1/test1.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Test to that wcscat correctly concatanates wide strings, including placing -** null pointers. -** -** -**==========================================================================*/ - - - -#include - -/* - * Notes: uses memcmp and the (pal) sprintf - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR dest[80]; - WCHAR test[] = {'f','o','o',' ','b','a','r',' ','b','a','z',0}; - WCHAR str1[] = {'f','o','o',' ',0}; - WCHAR str2[] = {'b','a','r',' ',0}; - WCHAR str3[] = {'b','a','z',0}; - WCHAR *ptr; - char buffer[256]; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - dest[0] = 0; - - ptr = wcscat(dest, str1); - if (ptr != dest) - { - Fail("ERROR: Expected wcscat to return ptr to %p, got %p", dest, ptr); - } - - ptr = wcscat(dest, str2); - if (ptr != dest) - { - Fail("ERROR: Expected wcscat to return ptr to %p, got %p", dest, ptr); - } - - ptr = wcscat(dest, str3); - if (ptr != dest) - { - Fail("ERROR: Expected wcscat to return ptr to %p, got %p", dest, ptr); - } - - if (memcmp(dest, test, sizeof(test)) != 0) - { - sprintf(buffer, "%S", dest); - Fail("ERROR: Expected wcscat to give \"%s\", got \"%s\"\n", - "foo bar baz", buffer); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/wcscat/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcscat/test1/test1.cpp new file mode 100644 index 0000000000..e9a79d3880 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcscat/test1/test1.cpp @@ -0,0 +1,71 @@ +// 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: test1.c +** +** Purpose: +** Test to that wcscat correctly concatanates wide strings, including placing +** null pointers. +** +** +**==========================================================================*/ + + + +#include + +/* + * Notes: uses memcmp and the (pal) sprintf_s + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR dest[80]; + WCHAR test[] = {'f','o','o',' ','b','a','r',' ','b','a','z',0}; + WCHAR str1[] = {'f','o','o',' ',0}; + WCHAR str2[] = {'b','a','r',' ',0}; + WCHAR str3[] = {'b','a','z',0}; + WCHAR *ptr; + char buffer[256]; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + dest[0] = 0; + + ptr = wcscat(dest, str1); + if (ptr != dest) + { + Fail("ERROR: Expected wcscat to return ptr to %p, got %p", dest, ptr); + } + + ptr = wcscat(dest, str2); + if (ptr != dest) + { + Fail("ERROR: Expected wcscat to return ptr to %p, got %p", dest, ptr); + } + + ptr = wcscat(dest, str3); + if (ptr != dest) + { + Fail("ERROR: Expected wcscat to return ptr to %p, got %p", dest, ptr); + } + + if (memcmp(dest, test, sizeof(test)) != 0) + { + sprintf_s(buffer, _countof(buffer), "%S", dest); + Fail("ERROR: Expected wcscat to give \"%s\", got \"%s\"\n", + "foo bar baz", buffer); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/wcschr/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcschr/test1/CMakeLists.txt index 542d70b7e6..9cf0a918a0 100644 --- a/src/pal/tests/palsuite/c_runtime/wcschr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcschr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcschr_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcschr/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcschr/test1/test1.c deleted file mode 100644 index a4963672f8..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcschr/test1/test1.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Tests that wcschr correctly finds the first occurrence of a character in a -** string -** -** -**==========================================================================*/ - - - -#include - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str[] = {'f','o','o',' ','b','a','r',' ',0}; - WCHAR c = (WCHAR)' '; - WCHAR c2 = (WCHAR)'$'; - WCHAR *ptr; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - ptr = wcschr(str, c); - if (ptr != str + 3) - { - Fail("ERROR: expected wcschr to return pointer to %p, got %p\n", - str + 3, ptr); - } - - ptr = wcschr(str, c2); - if (ptr != NULL) - { - Fail("ERROR: expected wcschr to return pointer to %p, got %p\n", - NULL, ptr); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/wcschr/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcschr/test1/test1.cpp new file mode 100644 index 0000000000..a4963672f8 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcschr/test1/test1.cpp @@ -0,0 +1,51 @@ +// 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: test1.c +** +** Purpose: +** Tests that wcschr correctly finds the first occurrence of a character in a +** string +** +** +**==========================================================================*/ + + + +#include + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str[] = {'f','o','o',' ','b','a','r',' ',0}; + WCHAR c = (WCHAR)' '; + WCHAR c2 = (WCHAR)'$'; + WCHAR *ptr; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + ptr = wcschr(str, c); + if (ptr != str + 3) + { + Fail("ERROR: expected wcschr to return pointer to %p, got %p\n", + str + 3, ptr); + } + + ptr = wcschr(str, c2); + if (ptr != NULL) + { + Fail("ERROR: expected wcschr to return pointer to %p, got %p\n", + NULL, ptr); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/wcscmp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcscmp/test1/CMakeLists.txt index 009e48e1ba..98c05352f3 100644 --- a/src/pal/tests/palsuite/c_runtime/wcscmp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcscmp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcscmp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcscmp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcscmp/test1/test1.c deleted file mode 100644 index 1c38dd6d58..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcscmp/test1/test1.c +++ /dev/null @@ -1,57 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that wcscmp correctly compares two strings with -** case sensitivity. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str1[] = {'f','o','o',0}; - WCHAR str2[] = {'f','o','o','x',0}; - WCHAR str3[] = {'f','O','o',0}; - char cstr1[] = "foo"; - char cstr2[] = "foox"; - char cstr3[] = "fOo"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - - if (wcscmp(str1, str2) >= 0) - { - Fail("ERROR: wcscmp(\"%s\", \"%s\") returned >= 0\n", cstr1, cstr2); - } - - if (wcscmp(str2, str1) <= 0) - { - Fail("ERROR: wcscmp(\"%s\", \"%s\") returned <= 0\n", cstr2, cstr1); - } - - if (wcscmp(str1, str3) <= 0) - { - Fail("ERROR: wcscmp(\"%s\", \"%s\") returned >= 0\n", cstr1, cstr3); - } - - if (wcscmp(str3, str1) >= 0) - { - Fail("ERROR: wcscmp(\"%s\", \"%s\") returned >= 0\n", cstr3, cstr1); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcscmp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcscmp/test1/test1.cpp new file mode 100644 index 0000000000..1c38dd6d58 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcscmp/test1/test1.cpp @@ -0,0 +1,57 @@ +// 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: test1.c +** +** Purpose: Tests that wcscmp correctly compares two strings with +** case sensitivity. +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str1[] = {'f','o','o',0}; + WCHAR str2[] = {'f','o','o','x',0}; + WCHAR str3[] = {'f','O','o',0}; + char cstr1[] = "foo"; + char cstr2[] = "foox"; + char cstr3[] = "fOo"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + + if (wcscmp(str1, str2) >= 0) + { + Fail("ERROR: wcscmp(\"%s\", \"%s\") returned >= 0\n", cstr1, cstr2); + } + + if (wcscmp(str2, str1) <= 0) + { + Fail("ERROR: wcscmp(\"%s\", \"%s\") returned <= 0\n", cstr2, cstr1); + } + + if (wcscmp(str1, str3) <= 0) + { + Fail("ERROR: wcscmp(\"%s\", \"%s\") returned >= 0\n", cstr1, cstr3); + } + + if (wcscmp(str3, str1) >= 0) + { + Fail("ERROR: wcscmp(\"%s\", \"%s\") returned >= 0\n", cstr3, cstr1); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcscpy/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcscpy/test1/CMakeLists.txt index 5f21b829ee..872b2dec5e 100644 --- a/src/pal/tests/palsuite/c_runtime/wcscpy/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcscpy/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcscpy_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcscpy/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcscpy/test1/test1.c deleted file mode 100644 index 4e45c86516..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcscpy/test1/test1.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that wcscpy correctly copies a null-terminated wide string. -** -** -**==========================================================================*/ - - -#include - -/* - * Notes: uses memcmp and sprintf. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str[] = {'f','o','o',0,'b','a','r',0}; - WCHAR dest[80]; - WCHAR result[] = {'f','o','o',0}; - WCHAR *ret; - char buffer[256]; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - ret = wcscpy(dest, str); - - if (ret != dest || memcmp(dest, result, sizeof(result)) != 0) - { - sprintf(buffer, "%S", dest); - Fail("Expected wcscpy to give \"%s\" with a return value of %p, got \"%s\" " - "with a return value of %p.\n", "foo", dest, buffer, ret); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcscpy/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcscpy/test1/test1.cpp new file mode 100644 index 0000000000..2ecafa8307 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcscpy/test1/test1.cpp @@ -0,0 +1,47 @@ +// 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: test1.c +** +** Purpose: Tests that wcscpy correctly copies a null-terminated wide string. +** +** +**==========================================================================*/ + + +#include + +/* + * Notes: uses memcmp and sprintf_s. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str[] = {'f','o','o',0,'b','a','r',0}; + WCHAR dest[80]; + WCHAR result[] = {'f','o','o',0}; + WCHAR *ret; + char buffer[256]; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + ret = wcscpy(dest, str); + + if (ret != dest || memcmp(dest, result, sizeof(result)) != 0) + { + sprintf_s(buffer, _countof(buffer), "%S", dest); + Fail("Expected wcscpy to give \"%s\" with a return value of %p, got \"%s\" " + "with a return value of %p.\n", "foo", dest, buffer, ret); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcslen/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcslen/test1/CMakeLists.txt index de0f1c22d3..b641a830f5 100644 --- a/src/pal/tests/palsuite/c_runtime/wcslen/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcslen/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcslen_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcslen/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcslen/test1/test1.c deleted file mode 100644 index 17d0327628..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcslen/test1/test1.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Tests that wcslen correctly returns the length (in wide characters, -** not byte) of a wide string -** -** -**==========================================================================*/ - - - -#include - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str1[] = {'f','o','o',' ',0}; - WCHAR str2[] = {0}; - int ret; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - ret = wcslen(str1); - if (ret != 4) - { - Fail("ERROR: Expected wcslen of \"foo \" to be 4, got %d\n", ret); - } - - ret = wcslen(str2); - if (ret != 0) - { - Fail("ERROR: Expected wcslen of \"\" to be 0, got %d\n", ret); - } - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/wcslen/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcslen/test1/test1.cpp new file mode 100644 index 0000000000..17d0327628 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcslen/test1/test1.cpp @@ -0,0 +1,49 @@ +// 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: test1.c +** +** Purpose: +** Tests that wcslen correctly returns the length (in wide characters, +** not byte) of a wide string +** +** +**==========================================================================*/ + + + +#include + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str1[] = {'f','o','o',' ',0}; + WCHAR str2[] = {0}; + int ret; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + ret = wcslen(str1); + if (ret != 4) + { + Fail("ERROR: Expected wcslen of \"foo \" to be 4, got %d\n", ret); + } + + ret = wcslen(str2); + if (ret != 0) + { + Fail("ERROR: Expected wcslen of \"\" to be 0, got %d\n", ret); + } + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/wcsncat/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcsncat/test1/CMakeLists.txt index 12c286a43a..e90e2b7bc4 100644 --- a/src/pal/tests/palsuite/c_runtime/wcsncat/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcsncat/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcsncat_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcsncat/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcsncat/test1/test1.c deleted file mode 100644 index 0cd5c3e15a..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcsncat/test1/test1.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Tests that wcsncat correctly appends wide strings, making sure it handles -** count argument correctly (appending no more than count characters, always -** placing a null, and padding the string if necessary). -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR dest[80]; - WCHAR test[] = {'f','o','o',' ','b','a','r','b','a','z',0}; - WCHAR str1[] = {'f','o','o',' ',0}; - WCHAR str2[] = {'b','a','r',' ',0}; - WCHAR str3[] = {'b','a','z',0}; - WCHAR *ptr; - int i; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - dest[0] = 0; - for (i=1; i<80; i++) - { - dest[i] = (WCHAR)'x'; - } - - ptr = wcsncat(dest, str1, wcslen(str1)); - if (ptr != dest) - { - Fail("ERROR: Expected wcsncat to return ptr to %p, got %p", dest, ptr); - } - - ptr = wcsncat(dest, str2, 3); - if (ptr != dest) - { - Fail("ERROR: Expected wcsncat to return ptr to %p, got %p", dest, ptr); - } - if (dest[7] != 0) - { - Fail("ERROR: wcsncat did not place a terminating NULL!"); - } - - ptr = wcsncat(dest, str3, 20); - if (ptr != dest) - { - Fail("ERROR: Expected wcsncat to return ptr to %p, got %p", dest, ptr); - } - if (wcscmp(dest, test) != 0) - { - Fail("ERROR: Expected wcsncat to give \"%S\", got \"%S\"\n", - test, dest); - } - if (dest[wcslen(test)+1] != (WCHAR)'x') - { - Fail("wcsncat went out of bounds!\n"); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcsncat/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcsncat/test1/test1.cpp new file mode 100644 index 0000000000..0cd5c3e15a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcsncat/test1/test1.cpp @@ -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: test1.c +** +** Purpose: +** Tests that wcsncat correctly appends wide strings, making sure it handles +** count argument correctly (appending no more than count characters, always +** placing a null, and padding the string if necessary). +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR dest[80]; + WCHAR test[] = {'f','o','o',' ','b','a','r','b','a','z',0}; + WCHAR str1[] = {'f','o','o',' ',0}; + WCHAR str2[] = {'b','a','r',' ',0}; + WCHAR str3[] = {'b','a','z',0}; + WCHAR *ptr; + int i; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + dest[0] = 0; + for (i=1; i<80; i++) + { + dest[i] = (WCHAR)'x'; + } + + ptr = wcsncat(dest, str1, wcslen(str1)); + if (ptr != dest) + { + Fail("ERROR: Expected wcsncat to return ptr to %p, got %p", dest, ptr); + } + + ptr = wcsncat(dest, str2, 3); + if (ptr != dest) + { + Fail("ERROR: Expected wcsncat to return ptr to %p, got %p", dest, ptr); + } + if (dest[7] != 0) + { + Fail("ERROR: wcsncat did not place a terminating NULL!"); + } + + ptr = wcsncat(dest, str3, 20); + if (ptr != dest) + { + Fail("ERROR: Expected wcsncat to return ptr to %p, got %p", dest, ptr); + } + if (wcscmp(dest, test) != 0) + { + Fail("ERROR: Expected wcsncat to give \"%S\", got \"%S\"\n", + test, dest); + } + if (dest[wcslen(test)+1] != (WCHAR)'x') + { + Fail("wcsncat went out of bounds!\n"); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/CMakeLists.txt index 56c9b25806..f5511a86c6 100644 --- a/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcsncmp_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/test1.c deleted file mode 100644 index 4e4488f5a1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/test1.c +++ /dev/null @@ -1,73 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Tests that wcsncmp case-sensitively compares wide strings, making sure that -** the count argument is handled correctly. -** -** -**==========================================================================*/ - - - -#include - -/* - * Notes: uses wcslen. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str1[] = {'f','o','o',0}; - WCHAR str2[] = {'f','o','o','x',0}; - WCHAR str3[] = {'f','O','o',0}; - char cstr1[] = "foo"; - char cstr2[] = "foox"; - char cstr3[] = "fOo"; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - - if (wcsncmp(str1, str2, wcslen(str2)) >= 0) - { - Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned >= 0\n", cstr1, - cstr2, wcslen(str2)); - } - - if (wcsncmp(str2, str1, wcslen(str2)) <= 0) - { - Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned <= 0\n", cstr2, - cstr1, wcslen(str2)); - } - - if (wcsncmp(str1, str2, wcslen(str1)) != 0) - { - Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned != 0\n", cstr1, - cstr2, wcslen(str1)); - } - - if (wcsncmp(str1, str3, wcslen(str1)) <= 0) - { - Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned >= 0\n", cstr1, - cstr3, wcslen(str1)); - } - - if (wcsncmp(str3, str1, wcslen(str1)) >= 0) - { - Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned >= 0\n", cstr3, - cstr1, wcslen(str1)); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/test1.cpp new file mode 100644 index 0000000000..4e4488f5a1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcsncmp/test1/test1.cpp @@ -0,0 +1,73 @@ +// 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: test1.c +** +** Purpose: +** Tests that wcsncmp case-sensitively compares wide strings, making sure that +** the count argument is handled correctly. +** +** +**==========================================================================*/ + + + +#include + +/* + * Notes: uses wcslen. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str1[] = {'f','o','o',0}; + WCHAR str2[] = {'f','o','o','x',0}; + WCHAR str3[] = {'f','O','o',0}; + char cstr1[] = "foo"; + char cstr2[] = "foox"; + char cstr3[] = "fOo"; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + + if (wcsncmp(str1, str2, wcslen(str2)) >= 0) + { + Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned >= 0\n", cstr1, + cstr2, wcslen(str2)); + } + + if (wcsncmp(str2, str1, wcslen(str2)) <= 0) + { + Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned <= 0\n", cstr2, + cstr1, wcslen(str2)); + } + + if (wcsncmp(str1, str2, wcslen(str1)) != 0) + { + Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned != 0\n", cstr1, + cstr2, wcslen(str1)); + } + + if (wcsncmp(str1, str3, wcslen(str1)) <= 0) + { + Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned >= 0\n", cstr1, + cstr3, wcslen(str1)); + } + + if (wcsncmp(str3, str1, wcslen(str1)) >= 0) + { + Fail("ERROR: wcsncmp(\"%s\", \"%s\", %d) returned >= 0\n", cstr3, + cstr1, wcslen(str1)); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/CMakeLists.txt index 1c1d70ba04..a7254a709c 100644 --- a/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcsncpy_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/test1.c deleted file mode 100644 index 50d97b0e9c..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/test1.c +++ /dev/null @@ -1,84 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Tests to see that wcsncpy correctly copies wide strings, including handling -** the count argument correctly (copying no more that count characters, not -** automatically adding a null, and padding if necessary). -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR dest[80]; - WCHAR result[] = {'f','o','o','b','a','r',0}; - WCHAR str[] = {'f','o','o','b','a','r',0,'b','a','z',0}; - WCHAR *ret; - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - for (i=0; i<80; i++) - { - dest[i] = 'x'; - } - - ret = wcsncpy(dest, str, 3); - if (ret != dest) - { - Fail("Expected wcsncpy to return %p, got %p!\n", dest, ret); - } - - if (wcsncmp(dest, result, 3) != 0) - { - Fail("Expected wcsncpy to give \"%S\", got \"%S\"!\n", result, dest); - } - - if (dest[3] != (WCHAR)'x') - { - Fail("wcsncpy overflowed!\n"); - } - - ret = wcsncpy(dest, str, 40); - if (ret != dest) - { - Fail("Expected wcsncpy to return %p, got %p!\n", dest, ret); - } - - if (wcscmp(dest, result) != 0) - { - Fail("Expected wcsncpy to give \"%S\", got \"%S\"!\n", result, dest); - } - - for (i=wcslen(str); i<40; i++) - { - if (dest[i] != 0) - { - Fail("wcsncpy failed to pad the destination with NULLs!\n"); - } - } - - if (dest[40] != (WCHAR)'x') - { - Fail("wcsncpy overflowed!\n"); - } - - - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/test1.cpp new file mode 100644 index 0000000000..50d97b0e9c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcsncpy/test1/test1.cpp @@ -0,0 +1,84 @@ +// 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: test1.c +** +** Purpose: +** Tests to see that wcsncpy correctly copies wide strings, including handling +** the count argument correctly (copying no more that count characters, not +** automatically adding a null, and padding if necessary). +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR dest[80]; + WCHAR result[] = {'f','o','o','b','a','r',0}; + WCHAR str[] = {'f','o','o','b','a','r',0,'b','a','z',0}; + WCHAR *ret; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + for (i=0; i<80; i++) + { + dest[i] = 'x'; + } + + ret = wcsncpy(dest, str, 3); + if (ret != dest) + { + Fail("Expected wcsncpy to return %p, got %p!\n", dest, ret); + } + + if (wcsncmp(dest, result, 3) != 0) + { + Fail("Expected wcsncpy to give \"%S\", got \"%S\"!\n", result, dest); + } + + if (dest[3] != (WCHAR)'x') + { + Fail("wcsncpy overflowed!\n"); + } + + ret = wcsncpy(dest, str, 40); + if (ret != dest) + { + Fail("Expected wcsncpy to return %p, got %p!\n", dest, ret); + } + + if (wcscmp(dest, result) != 0) + { + Fail("Expected wcsncpy to give \"%S\", got \"%S\"!\n", result, dest); + } + + for (i=wcslen(str); i<40; i++) + { + if (dest[i] != 0) + { + Fail("wcsncpy failed to pad the destination with NULLs!\n"); + } + } + + if (dest[40] != (WCHAR)'x') + { + Fail("wcsncpy overflowed!\n"); + } + + + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/CMakeLists.txt index c6a3f87d75..14c1fe83a4 100644 --- a/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcspbrk_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/test1.c deleted file mode 100644 index b0432f7819..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/test1.c +++ /dev/null @@ -1,61 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Tests that wcspbrk returns a pointer to the first element in the first -** string that matches a character in the second (or NULL). -** -** -**==========================================================================*/ - -#include - -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("z "); - key2 = convert("Q"); - - result = wcspbrk(string, key1); - if (result != string + 3) - { - Fail("ERROR: Got incorrect result in scanning \"%s\" with the set \"%s\".\n" - "Expected to get pointer to %#p, got %#p\n", convertC(string), - convertC(key1), string + 3, result); - } - - result = wcspbrk(string, key2); - if (result != NULL) - { - Fail("ERROR: Got incorrect result in scanning \"%s\" with the set \"%s\".\n" - "Expected to get pointer to %#p, got %#p\n", convertC(string), - convertC(key2), NULL, result); - } - - result = wcspbrk(string, key3); - if (result != NULL) - { - Fail("ERROR: Got incorrect result in scanning \"%s\" with the set \"%s\".\n" - "Expected to get pointer to %#p, got %#p\n", convertC(string), - convertC(key3), NULL, result); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/test1.cpp new file mode 100644 index 0000000000..b0432f7819 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcspbrk/test1/test1.cpp @@ -0,0 +1,61 @@ +// 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: test1.c +** +** Purpose: +** Tests that wcspbrk returns a pointer to the first element in the first +** string that matches a character in the second (or NULL). +** +** +**==========================================================================*/ + +#include + +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("z "); + key2 = convert("Q"); + + result = wcspbrk(string, key1); + if (result != string + 3) + { + Fail("ERROR: Got incorrect result in scanning \"%s\" with the set \"%s\".\n" + "Expected to get pointer to %#p, got %#p\n", convertC(string), + convertC(key1), string + 3, result); + } + + result = wcspbrk(string, key2); + if (result != NULL) + { + Fail("ERROR: Got incorrect result in scanning \"%s\" with the set \"%s\".\n" + "Expected to get pointer to %#p, got %#p\n", convertC(string), + convertC(key2), NULL, result); + } + + result = wcspbrk(string, key3); + if (result != NULL) + { + Fail("ERROR: Got incorrect result in scanning \"%s\" with the set \"%s\".\n" + "Expected to get pointer to %#p, got %#p\n", convertC(string), + convertC(key3), NULL, result); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/CMakeLists.txt index 80513af1af..abdd6d56d2 100644 --- a/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcsrchr_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/test1.c deleted file mode 100644 index ae8765776e..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/test1.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Tests to see that wcsrchr correctly returns a pointer to the last occurence -** of a character in a a string. -** -** -**==========================================================================*/ - - - -#include - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str[] = {'f','o','o',' ','b','a','r',' ','b','a','z',0}; - WCHAR c = (WCHAR)' '; - WCHAR c2 = (WCHAR)'$'; - WCHAR *ptr; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - ptr = wcsrchr(str, c); - if (ptr != str + 7) - { - Fail("ERROR: expected wcsrchr to return pointer to %p, got %p\n", - str + 7, ptr); - } - - ptr = wcsrchr(str, c2); - if (ptr != NULL) - { - Fail("ERROR: expected wcsrchr to return pointer to %p, got %p\n", - NULL, ptr); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/test1.cpp new file mode 100644 index 0000000000..ae8765776e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcsrchr/test1/test1.cpp @@ -0,0 +1,50 @@ +// 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: test1.c +** +** Purpose: +** Tests to see that wcsrchr correctly returns a pointer to the last occurence +** of a character in a a string. +** +** +**==========================================================================*/ + + + +#include + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str[] = {'f','o','o',' ','b','a','r',' ','b','a','z',0}; + WCHAR c = (WCHAR)' '; + WCHAR c2 = (WCHAR)'$'; + WCHAR *ptr; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + ptr = wcsrchr(str, c); + if (ptr != str + 7) + { + Fail("ERROR: expected wcsrchr to return pointer to %p, got %p\n", + str + 7, ptr); + } + + ptr = wcsrchr(str, c2); + if (ptr != NULL) + { + Fail("ERROR: expected wcsrchr to return pointer to %p, got %p\n", + NULL, ptr); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/wcsstr/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcsstr/test1/CMakeLists.txt index e42619344d..0e1e0b47b0 100644 --- a/src/pal/tests/palsuite/c_runtime/wcsstr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcsstr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcsstr_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.c deleted file mode 100644 index 8296a74983..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Tests that wcsstr correctly find substrings in wide stings, including -** returning NULL when the substring can't be found. -** -** -**==========================================================================*/ - -#include - -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; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.cpp new file mode 100644 index 0000000000..8296a74983 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcsstr/test1/test1.cpp @@ -0,0 +1,62 @@ +// 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: test1.c +** +** Purpose: +** Tests that wcsstr correctly find substrings in wide stings, including +** returning NULL when the substring can't be found. +** +** +**==========================================================================*/ + +#include + +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; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstod/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstod/test1/CMakeLists.txt index cf585d051a..cca01ca964 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstod/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstod/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcstod_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcstod/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcstod/test1/test1.c deleted file mode 100644 index e41e92e961..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstod/test1/test1.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests wcstod with a number of sample strings. -** -** -**===================================================================*/ - -#include - -struct testCase -{ - double CorrectResult; - char string[20]; - int stopChar; -}; - -struct testCase testCases[] = -{ - {1234,"1234", 4}, - {-1234,"-1234", 5}, - {1234.44,"1234.44", 7}, - {1234e-5,"1234e-5", 7}, - {1234e+5,"1234e+5", 7}, - {1234E5,"1234E5", 6}, - {1234.657e-8, "1234.657e-8", 11}, - {0, "1e-800", 6}, - {0, "-1e-800", 7}, - {1234567e-8, " 1234567e-8 foo", 13}, - {0, " foo 32 bar", 0}, -}; - -int __cdecl main(int argc, char **argv) -{ - WCHAR *wideStr; - WCHAR *endptr; - double result; - int i; - - if (PAL_Initialize(argc,argv)) - { - return FAIL; - } - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - wideStr = convert(testCases[i].string); - result = wcstod(wideStr, &endptr); - - if (testCases[i].CorrectResult != result) - { - free(wideStr); - Fail("ERROR: wcstod misinterpreted \"%s\" as %g instead of " - "%g.\n", - testCases[i].string, - result, - testCases[i].CorrectResult); - } - - if (endptr != wideStr + testCases[i].stopChar) - { - free(wideStr); - Fail("ERROR: wcstod stopped scanning \"%s\" at %p, " - "instead of %p!\n", testCases[i].string, endptr, - wideStr + testCases[i].stopChar); - } - - free(wideStr); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstod/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcstod/test1/test1.cpp new file mode 100644 index 0000000000..e41e92e961 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstod/test1/test1.cpp @@ -0,0 +1,79 @@ +// 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: test1.c +** +** Purpose: Tests wcstod with a number of sample strings. +** +** +**===================================================================*/ + +#include + +struct testCase +{ + double CorrectResult; + char string[20]; + int stopChar; +}; + +struct testCase testCases[] = +{ + {1234,"1234", 4}, + {-1234,"-1234", 5}, + {1234.44,"1234.44", 7}, + {1234e-5,"1234e-5", 7}, + {1234e+5,"1234e+5", 7}, + {1234E5,"1234E5", 6}, + {1234.657e-8, "1234.657e-8", 11}, + {0, "1e-800", 6}, + {0, "-1e-800", 7}, + {1234567e-8, " 1234567e-8 foo", 13}, + {0, " foo 32 bar", 0}, +}; + +int __cdecl main(int argc, char **argv) +{ + WCHAR *wideStr; + WCHAR *endptr; + double result; + int i; + + if (PAL_Initialize(argc,argv)) + { + return FAIL; + } + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + wideStr = convert(testCases[i].string); + result = wcstod(wideStr, &endptr); + + if (testCases[i].CorrectResult != result) + { + free(wideStr); + Fail("ERROR: wcstod misinterpreted \"%s\" as %g instead of " + "%g.\n", + testCases[i].string, + result, + testCases[i].CorrectResult); + } + + if (endptr != wideStr + testCases[i].stopChar) + { + free(wideStr); + Fail("ERROR: wcstod stopped scanning \"%s\" at %p, " + "instead of %p!\n", testCases[i].string, endptr, + wideStr + testCases[i].stopChar); + } + + free(wideStr); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstod/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstod/test2/CMakeLists.txt index 43d5bf8a40..ae7450891e 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstod/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstod/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_wcstod_test2 diff --git a/src/pal/tests/palsuite/c_runtime/wcstod/test2/test2.c b/src/pal/tests/palsuite/c_runtime/wcstod/test2/test2.c deleted file mode 100644 index 8f9b5cbf58..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstod/test2/test2.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests wcstod with overflows -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - /* Representation of positive infinty for a IEEE 64-bit double */ - INT64 PosInifity = (INT64)(0x7ff00000) << 32; - double HugeVal = *(double*) &PosInifity; - char *PosStr = "1E+10000"; - char *NegStr = "-1E+10000"; - WCHAR *wideStr; - double result; - - - if (PAL_Initialize(argc,argv)) - { - return FAIL; - } - - wideStr = convert(PosStr); - result = wcstod(wideStr, NULL); - free(wideStr); - - if (result != HugeVal) - { - Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", - PosStr, result, HugeVal); - } - - - - wideStr = convert(NegStr); - result = wcstod(wideStr, NULL); - free(wideStr); - - if (result != -HugeVal) - { - Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", - NegStr, result, -HugeVal); - } - - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/wcstod/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/wcstod/test2/test2.cpp new file mode 100644 index 0000000000..8f9b5cbf58 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstod/test2/test2.cpp @@ -0,0 +1,59 @@ +// 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: test2.c +** +** Purpose: Tests wcstod with overflows +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + /* Representation of positive infinty for a IEEE 64-bit double */ + INT64 PosInifity = (INT64)(0x7ff00000) << 32; + double HugeVal = *(double*) &PosInifity; + char *PosStr = "1E+10000"; + char *NegStr = "-1E+10000"; + WCHAR *wideStr; + double result; + + + if (PAL_Initialize(argc,argv)) + { + return FAIL; + } + + wideStr = convert(PosStr); + result = wcstod(wideStr, NULL); + free(wideStr); + + if (result != HugeVal) + { + Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", + PosStr, result, HugeVal); + } + + + + wideStr = convert(NegStr); + result = wcstod(wideStr, NULL); + free(wideStr); + + if (result != -HugeVal) + { + Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", + NegStr, result, -HugeVal); + } + + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/wcstok/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstok/test1/CMakeLists.txt index 863f5d8c29..6b5bed9552 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstok/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstok/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcstok_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcstok/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcstok/test1/test1.c deleted file mode 100644 index 76d7dc02b3..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstok/test1/test1.c +++ /dev/null @@ -1,114 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Search for a number of tokens within strings. Check that the return values -** are what is expected, and also that the strings match up with our expected -** results. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - /* foo bar baz */ - WCHAR str[] = {'f','o','o',' ','b','a','r',' ','b','a','z','\0'}; - - /* foo \0ar baz */ - WCHAR result1[] = {'f','o','o',' ','\0','a','r',' ','b','a','z','\0'}; - - /* foo \0a\0 baz */ - WCHAR result2[] = {'f','o','o',' ','\0','a','\0',' ','b','a','z','\0'}; - - WCHAR* tempString; - int len = 0; - WCHAR *ptr; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - len = (wcslen(str)*sizeof(WCHAR)) + 2; - - /* Tokenize 'str'. It will hit the 'b' delimiter first. Check to see - that the ptr is pointing to the start of the string and do a compare - to ensure the tokenized string is what we expected. - */ - - tempString = convert("bz"); - ptr = wcstok(str, tempString); - free(tempString); - - if (ptr != str) - { - Fail("ERROR: Expected wcstok() to return %p, got %p!\n", str, ptr); - } - - if (memcmp(str, result1, len) != 0) - { - Fail("ERROR: wcstok altered the string in an unexpected fashion."); - } - - /* If NULL is passed as the first parameter, wcstok will continue - tokenizing the same string. Test that this works properly. - */ - tempString = convert("r "); - ptr = wcstok(NULL, tempString); - free(tempString); - - if (ptr != str + 5) - { - Fail("ERROR: Expected wcstok() to return %p, got %p!\n", str+5, ptr); - } - - if (memcmp(str, result2, len) != 0) - { - Fail("ERROR: wcstok altered the string in an unexpected fashion."); - } - - /* Continue onward, and search for 'X' now, which won't be found. The - pointer should point just after the last NULL in the string. And - the string itself shouldn't have changed. - */ - tempString = convert("X"); - ptr = wcstok(NULL, tempString); - free(tempString); - - if (ptr != str + 7) - { - Fail("ERROR: Expected wcstok() to return %p, got %p!\n", str + 7, ptr); - } - - if (memcmp(str, result2, len) != 0) - { - Fail("ERROR: wcstok altered the string in an unexpeced fashion.\n"); - } - - /* Call wcstok again. Now the ptr should point to the end of the - string at NULL. And the string itself shouldn't have changed. - */ - tempString = convert("X"); - ptr = wcstok(NULL, tempString); - free(tempString); - - if (ptr != NULL) - { - Fail("ERROR: Expected wcstok() to return %p, got %p!\n", NULL, ptr); - } - - if (memcmp(str, result2, len) != 0) - { - Fail("ERROR: wcstok altered the string in an unexpeced fashion.\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstok/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcstok/test1/test1.cpp new file mode 100644 index 0000000000..76d7dc02b3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstok/test1/test1.cpp @@ -0,0 +1,114 @@ +// 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: test1.c +** +** Purpose: +** Search for a number of tokens within strings. Check that the return values +** are what is expected, and also that the strings match up with our expected +** results. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + /* foo bar baz */ + WCHAR str[] = {'f','o','o',' ','b','a','r',' ','b','a','z','\0'}; + + /* foo \0ar baz */ + WCHAR result1[] = {'f','o','o',' ','\0','a','r',' ','b','a','z','\0'}; + + /* foo \0a\0 baz */ + WCHAR result2[] = {'f','o','o',' ','\0','a','\0',' ','b','a','z','\0'}; + + WCHAR* tempString; + int len = 0; + WCHAR *ptr; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + len = (wcslen(str)*sizeof(WCHAR)) + 2; + + /* Tokenize 'str'. It will hit the 'b' delimiter first. Check to see + that the ptr is pointing to the start of the string and do a compare + to ensure the tokenized string is what we expected. + */ + + tempString = convert("bz"); + ptr = wcstok(str, tempString); + free(tempString); + + if (ptr != str) + { + Fail("ERROR: Expected wcstok() to return %p, got %p!\n", str, ptr); + } + + if (memcmp(str, result1, len) != 0) + { + Fail("ERROR: wcstok altered the string in an unexpected fashion."); + } + + /* If NULL is passed as the first parameter, wcstok will continue + tokenizing the same string. Test that this works properly. + */ + tempString = convert("r "); + ptr = wcstok(NULL, tempString); + free(tempString); + + if (ptr != str + 5) + { + Fail("ERROR: Expected wcstok() to return %p, got %p!\n", str+5, ptr); + } + + if (memcmp(str, result2, len) != 0) + { + Fail("ERROR: wcstok altered the string in an unexpected fashion."); + } + + /* Continue onward, and search for 'X' now, which won't be found. The + pointer should point just after the last NULL in the string. And + the string itself shouldn't have changed. + */ + tempString = convert("X"); + ptr = wcstok(NULL, tempString); + free(tempString); + + if (ptr != str + 7) + { + Fail("ERROR: Expected wcstok() to return %p, got %p!\n", str + 7, ptr); + } + + if (memcmp(str, result2, len) != 0) + { + Fail("ERROR: wcstok altered the string in an unexpeced fashion.\n"); + } + + /* Call wcstok again. Now the ptr should point to the end of the + string at NULL. And the string itself shouldn't have changed. + */ + tempString = convert("X"); + ptr = wcstok(NULL, tempString); + free(tempString); + + if (ptr != NULL) + { + Fail("ERROR: Expected wcstok() to return %p, got %p!\n", NULL, ptr); + } + + if (memcmp(str, result2, len) != 0) + { + Fail("ERROR: wcstok altered the string in an unexpeced fashion.\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstol/test1/CMakeLists.txt index 25e96e7de0..f76018fca3 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcstol_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcstol/test1/test1.c deleted file mode 100644 index d84ba66adc..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test1/test1.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the wcstol function. Does a simple test with radix 4. -** -** -**==========================================================================*/ - - - -#include - - -/* - * Notes: wcstol should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR *end; - WCHAR teststr[] = {'1','2','3','4','5',0}; - LONG result = 27; - LONG l; - - if ( 0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - l = wcstol(teststr, &end, 4); - - if (l != result) - { - Fail("ERROR: Expected wcstol to return %d, got %d\n", result, l); - } - - if (end != teststr + 3) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - teststr + 3, end); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcstol/test1/test1.cpp new file mode 100644 index 0000000000..d84ba66adc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test1/test1.cpp @@ -0,0 +1,53 @@ +// 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: test1.c +** +** Purpose: Test #1 for the wcstol function. Does a simple test with radix 4. +** +** +**==========================================================================*/ + + + +#include + + +/* + * Notes: wcstol should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR *end; + WCHAR teststr[] = {'1','2','3','4','5',0}; + LONG result = 27; + LONG l; + + if ( 0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + l = wcstol(teststr, &end, 4); + + if (l != result) + { + Fail("ERROR: Expected wcstol to return %d, got %d\n", result, l); + } + + if (end != teststr + 3) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + teststr + 3, end); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstol/test2/CMakeLists.txt index ea33ec8c7e..8dc2ab6b65 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_wcstol_test2 diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test2/test2.c b/src/pal/tests/palsuite/c_runtime/wcstol/test2/test2.c deleted file mode 100644 index 58309be6b4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test2/test2.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the wcstol function. Does a simple test with radix -** 10. -** -** -**==========================================================================*/ - - - -#include - - -/* - * Notes: wcstol should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR *end; - WCHAR teststr[] = {'1','2','3','4','5',0}; - LONG result = 12345; - LONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - l = wcstol(teststr, &end, 10); - - if (l != result) - { - Fail("ERROR: Expected wcstol to return %d, got %d\n", result, l); - } - - if (end != teststr + 5) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - teststr + 5, end); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/wcstol/test2/test2.cpp new file mode 100644 index 0000000000..58309be6b4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test2/test2.cpp @@ -0,0 +1,53 @@ +// 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: test2.c +** +** Purpose: Test #2 for the wcstol function. Does a simple test with radix +** 10. +** +** +**==========================================================================*/ + + + +#include + + +/* + * Notes: wcstol should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR *end; + WCHAR teststr[] = {'1','2','3','4','5',0}; + LONG result = 12345; + LONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + l = wcstol(teststr, &end, 10); + + if (l != result) + { + Fail("ERROR: Expected wcstol to return %d, got %d\n", result, l); + } + + if (end != teststr + 5) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + teststr + 5, end); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstol/test3/CMakeLists.txt index 509feca08c..310f97d6dc 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_wcstol_test3 diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test3/test3.c b/src/pal/tests/palsuite/c_runtime/wcstol/test3/test3.c deleted file mode 100644 index 8b5ce6943d..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test3/test3.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the wcstol function. Tests an invalid string -** -** -**==========================================================================*/ - - - -#include - - -/* - * Notes: wcstol should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str[] = {'Z',0}; - WCHAR *end; - LONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - l = wcstol(str, &end, 10); - - if (l != 0) - { - Fail("ERROR: Expected wcstol to return %d, got %d\n", 0, l); - } - - if (end != str) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - str + 3, end); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/wcstol/test3/test3.cpp new file mode 100644 index 0000000000..8b5ce6943d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test3/test3.cpp @@ -0,0 +1,52 @@ +// 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: test3.c +** +** Purpose: Test #3 for the wcstol function. Tests an invalid string +** +** +**==========================================================================*/ + + + +#include + + +/* + * Notes: wcstol should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str[] = {'Z',0}; + WCHAR *end; + LONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + l = wcstol(str, &end, 10); + + if (l != 0) + { + Fail("ERROR: Expected wcstol to return %d, got %d\n", 0, l); + } + + if (end != str) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + str + 3, end); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstol/test4/CMakeLists.txt index 043c562102..23928aa704 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_wcstol_test4 diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test4/test4.c b/src/pal/tests/palsuite/c_runtime/wcstol/test4/test4.c deleted file mode 100644 index a5e65946e9..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test4/test4.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the wcstol function. Tests the limits of the -** conversions. -** -** -**==========================================================================*/ - - - -#include - - -/* - * Notes: wcstol should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR maxstr[] = {'2','1','4','7','4','8','3','6','4','7',0}; - LONG max = 2147483647; - WCHAR minstr[] = {'-','2','1','4','7','4','8','3','6','4','8',0}; - LONG min = 0x80000000; /* putting -2147483648 gives a warning */ - WCHAR *end; - LONG l; - - if ( 0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - errno = 0; - - l = wcstol(maxstr, &end, 10); - - if (l != max) - { - Fail("ERROR: Expected wcstol to return %d, got %d\n", max, l); - } - if (end != maxstr + 10) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - maxstr + 10, end); - } - if (errno != 0) - { - Fail("ERROR: wcstol set errno to non-zero (%d)\n", errno); - } - - - l = wcstol(minstr, &end, 10); - - if (l != min) - { - Fail("ERROR: Expected wcstol to return %d, got %d\n", min, l); - } - if (end != minstr + 11) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - minstr + 11, end); - } - if (errno != 0) - { - Fail("ERROR: wcstol set errno to non-zero (%d)\n", errno); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/wcstol/test4/test4.cpp new file mode 100644 index 0000000000..a5e65946e9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test4/test4.cpp @@ -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: test4.c +** +** Purpose: Test #4 for the wcstol function. Tests the limits of the +** conversions. +** +** +**==========================================================================*/ + + + +#include + + +/* + * Notes: wcstol should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR maxstr[] = {'2','1','4','7','4','8','3','6','4','7',0}; + LONG max = 2147483647; + WCHAR minstr[] = {'-','2','1','4','7','4','8','3','6','4','8',0}; + LONG min = 0x80000000; /* putting -2147483648 gives a warning */ + WCHAR *end; + LONG l; + + if ( 0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + errno = 0; + + l = wcstol(maxstr, &end, 10); + + if (l != max) + { + Fail("ERROR: Expected wcstol to return %d, got %d\n", max, l); + } + if (end != maxstr + 10) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + maxstr + 10, end); + } + if (errno != 0) + { + Fail("ERROR: wcstol set errno to non-zero (%d)\n", errno); + } + + + l = wcstol(minstr, &end, 10); + + if (l != min) + { + Fail("ERROR: Expected wcstol to return %d, got %d\n", min, l); + } + if (end != minstr + 11) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + minstr + 11, end); + } + if (errno != 0) + { + Fail("ERROR: wcstol set errno to non-zero (%d)\n", errno); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstol/test5/CMakeLists.txt index c887369880..16c709ffa0 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_wcstol_test5 diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test5/test5.c b/src/pal/tests/palsuite/c_runtime/wcstol/test5/test5.c deleted file mode 100644 index 62f0a895a6..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test5/test5.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the wcstol function. Tests over and under flowing. -** -** -**==========================================================================*/ - - - -#include - - -/* - * Notes: wcstol should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR overstr[] = {'2','1','4','7','4','8','3','6','4','8',0}; - WCHAR understr[] = {'-','2','1','4','7','4','8','3','6','4','9',0}; - WCHAR *end; - LONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - errno = 0; - - l = wcstol(overstr, &end, 10); - - if (l != LONG_MAX) - { - Fail("ERROR: Expected wcstol to return %u, got %u\n", LONG_MAX, l); - } - if (end != overstr + 10) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - overstr + 10, end); - } - if (errno != ERANGE) - { - Fail("ERROR: wcstol did not set errno to ERANGE (%d)\n", errno); - } - - - errno = 0; - l = wcstol(understr, &end, 10); - - if (l != LONG_MIN) - { - Fail("ERROR: Expected wcstol to return %u, got %u\n", LONG_MIN, l); - } - if (end != understr + 11) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - understr + 11, end); - } - if (errno != ERANGE) - { - Fail("ERROR: wcstol did not set errno to ERANGE (%d)\n", errno); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/wcstol/test5/test5.cpp new file mode 100644 index 0000000000..62f0a895a6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test5/test5.cpp @@ -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: test5.c +** +** Purpose: Test #5 for the wcstol function. Tests over and under flowing. +** +** +**==========================================================================*/ + + + +#include + + +/* + * Notes: wcstol should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR overstr[] = {'2','1','4','7','4','8','3','6','4','8',0}; + WCHAR understr[] = {'-','2','1','4','7','4','8','3','6','4','9',0}; + WCHAR *end; + LONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + errno = 0; + + l = wcstol(overstr, &end, 10); + + if (l != LONG_MAX) + { + Fail("ERROR: Expected wcstol to return %u, got %u\n", LONG_MAX, l); + } + if (end != overstr + 10) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + overstr + 10, end); + } + if (errno != ERANGE) + { + Fail("ERROR: wcstol did not set errno to ERANGE (%d)\n", errno); + } + + + errno = 0; + l = wcstol(understr, &end, 10); + + if (l != LONG_MIN) + { + Fail("ERROR: Expected wcstol to return %u, got %u\n", LONG_MIN, l); + } + if (end != understr + 11) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + understr + 11, end); + } + if (errno != ERANGE) + { + Fail("ERROR: wcstol did not set errno to ERANGE (%d)\n", errno); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstol/test6/CMakeLists.txt index d328161f39..80ccaf609b 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_wcstol_test6 diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test6/test6.c b/src/pal/tests/palsuite/c_runtime/wcstol/test6/test6.c deleted file mode 100644 index 14f6208231..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstol/test6/test6.c +++ /dev/null @@ -1,86 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the wcstol function. Tests strings with octal/hex -** number specifers -** -** -**==========================================================================*/ - - - -#include - - -/* - * Notes: wcstol should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR test1[] = {'0','x','1','2', 0}; - WCHAR test2[] = {'0','1','2',0}; - WCHAR *end; - LONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - l = wcstol(test1, &end, 16); - if (l != 0x12) - { - Fail("ERROR: Expected wcstol to return %d, got %d\n", 0x12, l); - } - if (end != test1 + 4) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - test1 + 4, end); - } - - l = wcstol(test1, &end, 10); - if (l != 0) - { - Fail("ERROR: Expected wcstol to return %d, got %d\n", 0, l); - } - if (end != test1+1) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - test1+1, end); - } - - l = wcstol(test2, &end, 8); - if (l != 10) - { - Fail("ERROR: Expected wcstol to return %d, got %d\n", 10, l); - } - if (end != test2 + 3) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - test2 + 3, end); - } - - l = wcstol(test2, &end, 10); - if (l != 12) - { - Fail("ERROR: Expected wcstol to return %d, got %d\n", 12, l); - } - - if (end != test2 + 3) - { - Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", - test2 + 3, end); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstol/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/wcstol/test6/test6.cpp new file mode 100644 index 0000000000..14f6208231 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstol/test6/test6.cpp @@ -0,0 +1,86 @@ +// 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: test6.c +** +** Purpose: Test #6 for the wcstol function. Tests strings with octal/hex +** number specifers +** +** +**==========================================================================*/ + + + +#include + + +/* + * Notes: wcstol should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR test1[] = {'0','x','1','2', 0}; + WCHAR test2[] = {'0','1','2',0}; + WCHAR *end; + LONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + l = wcstol(test1, &end, 16); + if (l != 0x12) + { + Fail("ERROR: Expected wcstol to return %d, got %d\n", 0x12, l); + } + if (end != test1 + 4) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + test1 + 4, end); + } + + l = wcstol(test1, &end, 10); + if (l != 0) + { + Fail("ERROR: Expected wcstol to return %d, got %d\n", 0, l); + } + if (end != test1+1) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + test1+1, end); + } + + l = wcstol(test2, &end, 8); + if (l != 10) + { + Fail("ERROR: Expected wcstol to return %d, got %d\n", 10, l); + } + if (end != test2 + 3) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + test2 + 3, end); + } + + l = wcstol(test2, &end, 10); + if (l != 12) + { + Fail("ERROR: Expected wcstol to return %d, got %d\n", 12, l); + } + + if (end != test2 + 3) + { + Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n", + test2 + 3, end); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstoul/test1/CMakeLists.txt index b24523e93b..58f002ab32 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wcstoul_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wcstoul/test1/test1.c deleted file mode 100644 index 5274905e30..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test1/test1.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the wcstoul function -** -** -**==========================================================================*/ -#include - -/* - * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR teststr[] = {'1','2','3','4','5',0}; - WCHAR *end; - ULONG result = 27; - ULONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - l = wcstoul(teststr, &end, 4); - - if (l != result) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", result, l); - } - - if (end != teststr + 3) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - teststr + 3, end); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wcstoul/test1/test1.cpp new file mode 100644 index 0000000000..5274905e30 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test1/test1.cpp @@ -0,0 +1,49 @@ +// 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: test1.c +** +** Purpose: Test #1 for the wcstoul function +** +** +**==========================================================================*/ +#include + +/* + * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR teststr[] = {'1','2','3','4','5',0}; + WCHAR *end; + ULONG result = 27; + ULONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + l = wcstoul(teststr, &end, 4); + + if (l != result) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", result, l); + } + + if (end != teststr + 3) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + teststr + 3, end); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstoul/test2/CMakeLists.txt index e262078e34..2c8d012310 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_wcstoul_test2 diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test2/test2.c b/src/pal/tests/palsuite/c_runtime/wcstoul/test2/test2.c deleted file mode 100644 index 2ab2dbf5d1..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test2/test2.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the wcstoul function -** -** -**==========================================================================*/ -#include - -/* - * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR teststr[] = {'1','2','3','4','5',0}; - WCHAR *end; - ULONG result = 12345; - ULONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - l = wcstoul((wchar_t*)teststr, &end, 10); - - if (l != result) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", result, l); - } - - if (end != teststr + 5) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - teststr + 5, end); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/wcstoul/test2/test2.cpp new file mode 100644 index 0000000000..2ab2dbf5d1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test2/test2.cpp @@ -0,0 +1,49 @@ +// 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: test2.c +** +** Purpose: Test #2 for the wcstoul function +** +** +**==========================================================================*/ +#include + +/* + * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR teststr[] = {'1','2','3','4','5',0}; + WCHAR *end; + ULONG result = 12345; + ULONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + l = wcstoul((wchar_t*)teststr, &end, 10); + + if (l != result) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", result, l); + } + + if (end != teststr + 5) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + teststr + 5, end); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstoul/test3/CMakeLists.txt index aae268ac59..353df07f52 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_wcstoul_test3 diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test3/test3.c b/src/pal/tests/palsuite/c_runtime/wcstoul/test3/test3.c deleted file mode 100644 index eac46615e2..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test3/test3.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: test3.c -** -** Purpose: Test #3 for the wcstoul function -** -** -**==========================================================================*/ -#include - -/* - * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str[] = {'Z',0}; - WCHAR *end; - ULONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - l = wcstoul(str, &end, 10); - - if (l != 0) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", 0, l); - } - - if (end != str) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - str, end); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/wcstoul/test3/test3.cpp new file mode 100644 index 0000000000..eac46615e2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test3/test3.cpp @@ -0,0 +1,49 @@ +// 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: test3.c +** +** Purpose: Test #3 for the wcstoul function +** +** +**==========================================================================*/ +#include + +/* + * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str[] = {'Z',0}; + WCHAR *end; + ULONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + l = wcstoul(str, &end, 10); + + if (l != 0) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", 0, l); + } + + if (end != str) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + str, end); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstoul/test4/CMakeLists.txt index bd8073023f..e1e7d55420 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_wcstoul_test4 diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test4/test4.c b/src/pal/tests/palsuite/c_runtime/wcstoul/test4/test4.c deleted file mode 100644 index 0261da4275..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test4/test4.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test4.c -** -** Purpose: Test #4 for the wcstoul function -** -** -**==========================================================================*/ -#include - -/* - * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR maxstr[] = {'4','2','9','4','9','6','7','2','9','5',0}; - ULONG max = 4294967295ul; - WCHAR *end; - ULONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - errno = 0; - - l = wcstoul(maxstr, &end, 10); - if (l != max) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", max, l); - } - if (end != maxstr + 10) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - maxstr + 10, end); - } - if (errno != 0) - { - Fail("ERROR: wcstoul set errno to non-zero (%d)\n", errno); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test4/test4.cpp b/src/pal/tests/palsuite/c_runtime/wcstoul/test4/test4.cpp new file mode 100644 index 0000000000..0261da4275 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test4/test4.cpp @@ -0,0 +1,52 @@ +// 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: test4.c +** +** Purpose: Test #4 for the wcstoul function +** +** +**==========================================================================*/ +#include + +/* + * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR maxstr[] = {'4','2','9','4','9','6','7','2','9','5',0}; + ULONG max = 4294967295ul; + WCHAR *end; + ULONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + errno = 0; + + l = wcstoul(maxstr, &end, 10); + if (l != max) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", max, l); + } + if (end != maxstr + 10) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + maxstr + 10, end); + } + if (errno != 0) + { + Fail("ERROR: wcstoul set errno to non-zero (%d)\n", errno); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test5/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstoul/test5/CMakeLists.txt index 1451e6ad57..9e83c6074c 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_wcstoul_test5 diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test5/test5.c b/src/pal/tests/palsuite/c_runtime/wcstoul/test5/test5.c deleted file mode 100644 index 00287cf7f4..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test5/test5.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test5.c -** -** Purpose: Test #5 for the wcstoul function -** -** -**==========================================================================*/ -#include - -/* - * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR overstr[] = {'4','2','9','4','9','6','7','2','9','6',0}; - WCHAR understr[] = {'-','1',0}; - WCHAR *end; - ULONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - errno = 0; - l = wcstoul(overstr, &end, 10); - - if (l != ULONG_MAX) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", ULONG_MAX, l); - } - if (end != overstr + 10) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - overstr + 10, end); - } - if (errno != ERANGE) - { - Fail("ERROR: wcstoul did not set errno to ERANGE (%d)\n", errno); - } - - errno = 0; - l = wcstoul(understr, &end, 10); - - if (l != ULONG_MAX) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", ULONG_MAX, l); - } - if (end != understr + 2) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - understr + 2, end); - } - if (errno != 0) - { - Fail("ERROR: wcstoul set errno to non-zero (%d)\n", errno); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test5/test5.cpp b/src/pal/tests/palsuite/c_runtime/wcstoul/test5/test5.cpp new file mode 100644 index 0000000000..00287cf7f4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test5/test5.cpp @@ -0,0 +1,69 @@ +// 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: test5.c +** +** Purpose: Test #5 for the wcstoul function +** +** +**==========================================================================*/ +#include + +/* + * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR overstr[] = {'4','2','9','4','9','6','7','2','9','6',0}; + WCHAR understr[] = {'-','1',0}; + WCHAR *end; + ULONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + errno = 0; + l = wcstoul(overstr, &end, 10); + + if (l != ULONG_MAX) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", ULONG_MAX, l); + } + if (end != overstr + 10) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + overstr + 10, end); + } + if (errno != ERANGE) + { + Fail("ERROR: wcstoul did not set errno to ERANGE (%d)\n", errno); + } + + errno = 0; + l = wcstoul(understr, &end, 10); + + if (l != ULONG_MAX) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", ULONG_MAX, l); + } + if (end != understr + 2) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + understr + 2, end); + } + if (errno != 0) + { + Fail("ERROR: wcstoul set errno to non-zero (%d)\n", errno); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test6/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wcstoul/test6/CMakeLists.txt index 15518bdcf8..8352d0cbbe 100644 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_wcstoul_test6 diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test6/test6.c b/src/pal/tests/palsuite/c_runtime/wcstoul/test6/test6.c deleted file mode 100644 index 28397ec73f..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wcstoul/test6/test6.c +++ /dev/null @@ -1,83 +0,0 @@ -// 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: test6.c -** -** Purpose: Test #6 for the wcstoul function. Tests strings with octal/hex -** number specifers -** -** -**==========================================================================*/ -#include - - -/* - * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, - * this is not currently tested. - */ - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR test1[] = {'0','x','1','2', 0}; - WCHAR test2[] = {'0','1','2',0}; - WCHAR *end; - ULONG l; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - l = wcstoul(test1, &end, 16); - if (l != 0x12) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", 0x12, l); - } - if (end != test1 + 4) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - test1 + 4, end); - } - - l = wcstoul(test1, &end, 10); - if (l != 0) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", 0, l); - } - if (end != test1+1) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - test1+1, end); - } - - l = wcstoul(test2, &end, 8); - if (l != 10) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", 10, l); - } - if (end != test2 + 3) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - test2 + 3, end); - } - - l = wcstoul(test2, &end, 10); - if (l != 12) - { - Fail("ERROR: Expected wcstoul to return %u, got %u\n", 12, l); - } - - if (end != test2 + 3) - { - Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", - test2 + 3, end); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/wcstoul/test6/test6.cpp b/src/pal/tests/palsuite/c_runtime/wcstoul/test6/test6.cpp new file mode 100644 index 0000000000..28397ec73f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wcstoul/test6/test6.cpp @@ -0,0 +1,83 @@ +// 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: test6.c +** +** Purpose: Test #6 for the wcstoul function. Tests strings with octal/hex +** number specifers +** +** +**==========================================================================*/ +#include + + +/* + * Notes: wcstoul should depend on the current locale's LC_NUMERIC category, + * this is not currently tested. + */ + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR test1[] = {'0','x','1','2', 0}; + WCHAR test2[] = {'0','1','2',0}; + WCHAR *end; + ULONG l; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + l = wcstoul(test1, &end, 16); + if (l != 0x12) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", 0x12, l); + } + if (end != test1 + 4) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + test1 + 4, end); + } + + l = wcstoul(test1, &end, 10); + if (l != 0) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", 0, l); + } + if (end != test1+1) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + test1+1, end); + } + + l = wcstoul(test2, &end, 8); + if (l != 10) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", 10, l); + } + if (end != test2 + 3) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + test2 + 3, end); + } + + l = wcstoul(test2, &end, 10); + if (l != 12) + { + Fail("ERROR: Expected wcstoul to return %u, got %u\n", 12, l); + } + + if (end != test2 + 3) + { + Fail("ERROR: Expected wcstoul to give an end value of %p, got %p\n", + test2 + 3, end); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wprintf/test1/CMakeLists.txt index 701bbe4160..f95fc12ea1 100644 --- a/src/pal/tests/palsuite/c_runtime/wprintf/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wprintf/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_wprintf_test1 diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.c deleted file mode 100644 index d99dc8cf93..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test1.c -** -** Purpose: Test #1 for the wprintf function. A single, basic, test -** case with no formatting. -** -** -**==========================================================================*/ - - - -#include -#include "../wprintf.h" - -int __cdecl main(int argc, char *argv[]) -{ - char checkstr[] = "hello world"; - WCHAR *wcheckstr; - int ret; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - wcheckstr = convert(checkstr); - - ret = wprintf(wcheckstr); - - if (ret != wcslen(wcheckstr)) - { - Fail("Expected wprintf to return %d, got %d.\n", - wcslen(wcheckstr), ret); - - } - - free(wcheckstr); - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.cpp new file mode 100644 index 0000000000..d99dc8cf93 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.cpp @@ -0,0 +1,47 @@ +// 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: test1.c +** +** Purpose: Test #1 for the wprintf function. A single, basic, test +** case with no formatting. +** +** +**==========================================================================*/ + + + +#include +#include "../wprintf.h" + +int __cdecl main(int argc, char *argv[]) +{ + char checkstr[] = "hello world"; + WCHAR *wcheckstr; + int ret; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + wcheckstr = convert(checkstr); + + ret = wprintf(wcheckstr); + + if (ret != wcslen(wcheckstr)) + { + Fail("Expected wprintf to return %d, got %d.\n", + wcslen(wcheckstr), ret); + + } + + free(wcheckstr); + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wprintf/test2/CMakeLists.txt index 55c3d11913..325e8046d5 100644 --- a/src/pal/tests/palsuite/c_runtime/wprintf/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/wprintf/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_wprintf_test2 diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.c deleted file mode 100644 index 254e98a394..0000000000 --- a/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.c +++ /dev/null @@ -1,45 +0,0 @@ -// 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: test2.c -** -** Purpose: Test #2 for the wprintf function. Tests the string specifier -** (%s). -** -** -**==========================================================================*/ - - -#include -#include "../wprintf.h" - - - -int __cdecl main(int argc, char *argv[]) -{ - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - DoStrTest(u"foo %s", u"bar", u"foo bar"); - DoStrTest(u"foo %ws", u"bar", u"foo bar"); - DoStrTest(u"foo %ls", u"bar", u"foo bar"); - DoStrTest(u"foo %ws", u"bar", u"foo bar"); - DoStrTest(u"foo %Ls", u"bar", u"foo bar"); - DoStrTest(u"foo %I64s", u"bar", u"foo bar"); - DoStrTest(u"foo %5s", u"bar", u"foo bar"); - DoStrTest(u"foo %.2s", u"bar", u"foo ba"); - DoStrTest(u"foo %5.2s", u"bar", u"foo ba"); - DoStrTest(u"foo %-5s", u"bar", u"foo bar "); - DoStrTest(u"foo %05s", u"bar", u"foo 00bar"); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.cpp b/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.cpp new file mode 100644 index 0000000000..254e98a394 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.cpp @@ -0,0 +1,45 @@ +// 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: test2.c +** +** Purpose: Test #2 for the wprintf function. Tests the string specifier +** (%s). +** +** +**==========================================================================*/ + + +#include +#include "../wprintf.h" + + + +int __cdecl main(int argc, char *argv[]) +{ + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + DoStrTest(u"foo %s", u"bar", u"foo bar"); + DoStrTest(u"foo %ws", u"bar", u"foo bar"); + DoStrTest(u"foo %ls", u"bar", u"foo bar"); + DoStrTest(u"foo %ws", u"bar", u"foo bar"); + DoStrTest(u"foo %Ls", u"bar", u"foo bar"); + DoStrTest(u"foo %I64s", u"bar", u"foo bar"); + DoStrTest(u"foo %5s", u"bar", u"foo bar"); + DoStrTest(u"foo %.2s", u"bar", u"foo ba"); + DoStrTest(u"foo %5.2s", u"bar", u"foo ba"); + DoStrTest(u"foo %-5s", u"bar", u"foo bar "); + DoStrTest(u"foo %05s", u"bar", u"foo 00bar"); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h b/src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h index 7d3caf1b02..3a96248c35 100644 --- a/src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h +++ b/src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h @@ -14,7 +14,7 @@ #ifndef __wprintf_H__ #define __wprintf_H__ -void DoStrTest(WCHAR *formatstr, WCHAR* param, WCHAR *checkstr) +void DoStrTest(const WCHAR *formatstr, const WCHAR *param, const WCHAR *checkstr) { int ret; @@ -27,8 +27,8 @@ void DoStrTest(WCHAR *formatstr, WCHAR* param, WCHAR *checkstr) } -void DoPointerTest(WCHAR *formatstr, void* param, WCHAR* paramstr, - WCHAR *checkstr1) +void DoPointerTest(const WCHAR *formatstr, void* param, WCHAR* paramstr, + const WCHAR *checkstr1) { int ret; @@ -40,7 +40,7 @@ void DoPointerTest(WCHAR *formatstr, void* param, WCHAR* paramstr, } } -void DoCountTest(WCHAR *formatstr, int param, WCHAR *checkstr) +void DoCountTest(const WCHAR *formatstr, int param, const WCHAR *checkstr) { int ret; int n = -1; @@ -59,7 +59,7 @@ void DoCountTest(WCHAR *formatstr, int param, WCHAR *checkstr) } } -void DoShortCountTest(WCHAR *formatstr, int param, WCHAR *checkstr) +void DoShortCountTest(const WCHAR *formatstr, int param, const WCHAR *checkstr) { int ret; short int n = -1; @@ -79,7 +79,7 @@ void DoShortCountTest(WCHAR *formatstr, int param, WCHAR *checkstr) } -void DoCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) +void DoCharTest(const WCHAR *formatstr, WCHAR param, const WCHAR *checkstr) { int ret; @@ -91,7 +91,7 @@ void DoCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) } } -void DoWCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) +void DoWCharTest(const WCHAR *formatstr, WCHAR param, const WCHAR *checkstr) { int ret; @@ -103,7 +103,7 @@ void DoWCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) } } -void DoNumTest(WCHAR *formatstr, int param, WCHAR *checkstr) +void DoNumTest(const WCHAR *formatstr, int param, const WCHAR *checkstr) { int ret; @@ -115,8 +115,8 @@ void DoNumTest(WCHAR *formatstr, int param, WCHAR *checkstr) } } -void DoI64Test(WCHAR *formatstr, INT64 param, WCHAR *valuestr, - WCHAR *checkstr1) +void DoI64Test(const WCHAR *formatstr, INT64 param, const WCHAR *valuestr, + const WCHAR *checkstr1) { int ret; @@ -128,8 +128,8 @@ void DoI64Test(WCHAR *formatstr, INT64 param, WCHAR *valuestr, } } -void DoDoubleTest(WCHAR *formatstr, double param, - WCHAR *checkstr1, WCHAR *checkstr2) +void DoDoubleTest(const WCHAR *formatstr, double param, + const WCHAR *checkstr1, const WCHAR *checkstr2) { int ret; @@ -141,8 +141,8 @@ void DoDoubleTest(WCHAR *formatstr, double param, } } -void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, - WCHAR *paramstr, WCHAR *checkstr1, WCHAR *checkstr2) +void DoArgumentPrecTest(const WCHAR *formatstr, int precision, void *param, + WCHAR *paramstr, const WCHAR *checkstr1, const WCHAR *checkstr2) { int ret; @@ -154,8 +154,8 @@ void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, } } -void DoArgumentPrecDoubleTest(WCHAR *formatstr, int precision, double param, - WCHAR *checkstr1, WCHAR *checkstr2) +void DoArgumentPrecDoubleTest(const WCHAR *formatstr, int precision, double param, + const WCHAR *checkstr1, const WCHAR *checkstr2) { int ret; diff --git a/src/pal/tests/palsuite/common/palsuite.h b/src/pal/tests/palsuite/common/palsuite.h index ef644ad8e5..b77ca2ead5 100644 --- a/src/pal/tests/palsuite/common/palsuite.h +++ b/src/pal/tests/palsuite/common/palsuite.h @@ -133,9 +133,9 @@ inline ULONG VAL32(ULONG x) #define th_htons(w) (((w) >> 8) | ((w) << 8)) #endif // BIGENDIAN +#define _countof(_array) (sizeof(_array)/sizeof(_array[0])) - -WCHAR* convert(char * aString) +WCHAR* convert(const char * aString) { int size; WCHAR* wideBuffer; @@ -150,7 +150,7 @@ WCHAR* convert(char * aString) return wideBuffer; } -char* convertC(WCHAR * wString) +char* convertC(const WCHAR * wString) { int size; char * MultiBuffer = NULL; diff --git a/src/pal/tests/palsuite/composite/object_management/event/nonshared/CMakeLists.txt b/src/pal/tests/palsuite/composite/object_management/event/nonshared/CMakeLists.txt index c6c00377e1..b336c03d37 100644 --- a/src/pal/tests/palsuite/composite/object_management/event/nonshared/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/object_management/event/nonshared/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - event.c - main.c + event.cpp + main.cpp ) add_executable(paltest_event_nonshared diff --git a/src/pal/tests/palsuite/composite/object_management/event/nonshared/event.c b/src/pal/tests/palsuite/composite/object_management/event/nonshared/event.c deleted file mode 100644 index 69ad9a30e3..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/event/nonshared/event.c +++ /dev/null @@ -1,358 +0,0 @@ -// 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 Code: main.c and event.c -** main.c creates process and waits for all processes to get over -** event.c creates a event and then calls threads which will contend for the event -** -** This test is for Object Management Test case for event where Object type is shareable. -** Algorithm -** o Main Process Creates OBJECT_TYPE Object -** o Create PROCESS_COUNT processes aware of the Shared Object -** -** Author: ShamitP -** -** -**============================================================ -*/ - -#include -#include "resultbuffer.h" -#include "resulttime.h" - -#define TIMEOUT 5000 -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; -unsigned int THREAD_COUNT = 0; -unsigned int REPEAT_COUNT = 0; -unsigned int RELATION_ID= 0; - -/* Event variables */ -//unsigned long lInitialCount = 1; /* Signaled */ -//unsigned long lMaximumCount = 1; /* Maximum value of 1 */ - -/* Capture statistics at per thread basis */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - -struct ProcessStats{ - unsigned int processId; - DWORD operationTime; - unsigned int relationId; -}; - -HANDLE StartTestsEvHandle = NULL; -HANDLE hEventHandle = NULL; - -/* Results Buffer */ -ResultBuffer *resultBuffer = NULL; - -int testStatus; - -const char sTmpEventName[MAX_PATH_FNAME] = "StartTestEvent"; - -void PALAPI Run_Thread(LPVOID lpParam); - -int GetParameters( int argc, char **argv) -{ - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management Event Test\n"); - printf("Usage:\n"); - printf("Event\n\t[USE_PROCESS_COUNT [greater than 1] \n"); - printf("\t[THREAD_COUNT [greater than 1] \n"); - printf("\t[REPEAT_COUNT [greater than 1]\n"); - printf("\t[RELATION_ID [greater than or Equal to 1]\n"); - - return -1; - } - - // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; - DWORD threadId[MAXIMUM_WAIT_OBJECTS]; - int returnCode = 0; - - DWORD dwParam = 0; - - /* Variables to capture the file name and the file pointer at thread level*/ - char fileName[MAX_LONGPATH]; - FILE *pFile = NULL; - struct statistics* buffer = NULL; - int statisticsSize = 0; - - /* Variables to capture the file name and the file pointer at process level*/ - char processFileName[MAX_LONGPATH]; - FILE *pProcessFile = NULL; - struct ProcessStats processStats; - DWORD dwStartTime; - - testStatus = PASS; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } -// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); - - /* Register the start time */ - dwStartTime = GetTickCount(); - processStats.relationId = RELATION_ID; - processStats.processId = USE_PROCESS_COUNT; - - _snprintf(processFileName, MAX_LONGPATH, "%d_process_event_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pProcessFile = fopen(processFileName, "w+"); - if(pProcessFile == NULL) - { - Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); - } - - statisticsSize = sizeof(struct statistics); - - _snprintf(fileName, MAX_LONGPATH, "%d_thread_event_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pFile = fopen(fileName, "w+"); - - if(pFile == NULL) - { - Fail("Error in opening thread File for write for process [%d]\n", USE_PROCESS_COUNT); - } - // For each thread we will log operations failed (int), passed (int), total (int) - // and number of ticks (DWORD) for the operations - resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); - - StartTestsEvHandle = CreateEvent( - NULL, /* lpEventAttributes*/ - TRUE, /* bManualReset */ - FALSE, /* bInitialState */ - NULL /* name of Event */ - ); - - if( StartTestsEvHandle == NULL ) - { - Fail("Error:%d: Unexpected failure " - "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); - - } - - /* Create StartTest Event */ - - hEventHandle = CreateEvent( - NULL, /* lpEventAttributes, inheritable to child processes*/ - TRUE, /* bAutomaticReset */ - TRUE, /* bInitialState */ - NULL - ); - - if( hEventHandle == NULL) - { - Fail("Unable to create Event handle for process id [%d], returned error [%d]\n", i, GetLastError()); - } - /* We already assume that the Event was created previously*/ - - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - } - - if (!SetEvent(StartTestsEvHandle)) - { - Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - /* Test running */ - returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); - - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testStatus = FAIL; - } - - processStats.operationTime = GetTimeDiff(dwStartTime); - - /* Write to a file*/ - if(pFile!= NULL) - { - for( i = 0; i < THREAD_COUNT; i++ ) - { - buffer = (struct statistics *)resultBuffer->getResultBuffer(i); - returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); - //Trace("Iteration %d over\n", i); - - } - } - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile\n"); - testStatus = FAIL; - } - - fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); - if(fclose(pProcessFile)) - { - Trace("Error: fclose failed for pProcessFile at Process %d\n", USE_PROCESS_COUNT); - testStatus = FAIL; - } - - /* Logging for the test case over, clean up the handles */ - -// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); - /* Clean Up */ - for( i = 0; i < THREAD_COUNT; i++ ) - { - if(!CloseHandle(hThread[i]) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); - testStatus = FAIL; - } - } - - if(!CloseHandle(StartTestsEvHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - if(!CloseHandle(hEventHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hEventHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - PAL_Terminate(); - return testStatus; - -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - unsigned int i = 0; - DWORD dwWaitResult; - - struct statistics stats; - DWORD dwStartTime; - - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - int Id=(int)lpParam; - - dwWaitResult = WaitForSingleObject( - StartTestsEvHandle, // handle to start test handle - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { - Fail("Error while waiting for StartTest Event@ thread %d, RC is %d, Error is %d\n", Id, dwWaitResult, GetLastError()); - } - - dwStartTime = GetTickCount(); - - for( i = 0; i < REPEAT_COUNT; i++ ) - { - dwWaitResult = WaitForSingleObject( - hEventHandle, // handle to Event - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { -// Trace("Error while waiting for onject @ thread %d, # iter %d, RC is %d, Error is %d\n", Id, i, dwWaitResult, GetLastError()); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - testStatus = FAIL; - continue; - } - - if (! SetEvent(hEventHandle)) - { - // Deal with error. -// Trace("Error while setting Event @ thread %d # iter %d\n", Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - // Do we need to have while true loop to attempt to set event? - testStatus = FAIL; - continue; - } - - stats.operationsTotal += 1; - stats.operationsPassed += 1; -// Trace("Successs while setting Event @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); - - } - - stats.operationTime = GetTimeDiff(dwStartTime); - if(resultBuffer->LogResult(Id, (char *)&stats)) - { - Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); - } - //Trace("Thread %d over for process %d\n", Id, USE_PROCESS_COUNT); -} diff --git a/src/pal/tests/palsuite/composite/object_management/event/nonshared/event.cpp b/src/pal/tests/palsuite/composite/object_management/event/nonshared/event.cpp new file mode 100644 index 0000000000..69ad9a30e3 --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/event/nonshared/event.cpp @@ -0,0 +1,358 @@ +// 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 Code: main.c and event.c +** main.c creates process and waits for all processes to get over +** event.c creates a event and then calls threads which will contend for the event +** +** This test is for Object Management Test case for event where Object type is shareable. +** Algorithm +** o Main Process Creates OBJECT_TYPE Object +** o Create PROCESS_COUNT processes aware of the Shared Object +** +** Author: ShamitP +** +** +**============================================================ +*/ + +#include +#include "resultbuffer.h" +#include "resulttime.h" + +#define TIMEOUT 5000 +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; +unsigned int THREAD_COUNT = 0; +unsigned int REPEAT_COUNT = 0; +unsigned int RELATION_ID= 0; + +/* Event variables */ +//unsigned long lInitialCount = 1; /* Signaled */ +//unsigned long lMaximumCount = 1; /* Maximum value of 1 */ + +/* Capture statistics at per thread basis */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + +struct ProcessStats{ + unsigned int processId; + DWORD operationTime; + unsigned int relationId; +}; + +HANDLE StartTestsEvHandle = NULL; +HANDLE hEventHandle = NULL; + +/* Results Buffer */ +ResultBuffer *resultBuffer = NULL; + +int testStatus; + +const char sTmpEventName[MAX_PATH_FNAME] = "StartTestEvent"; + +void PALAPI Run_Thread(LPVOID lpParam); + +int GetParameters( int argc, char **argv) +{ + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management Event Test\n"); + printf("Usage:\n"); + printf("Event\n\t[USE_PROCESS_COUNT [greater than 1] \n"); + printf("\t[THREAD_COUNT [greater than 1] \n"); + printf("\t[REPEAT_COUNT [greater than 1]\n"); + printf("\t[RELATION_ID [greater than or Equal to 1]\n"); + + return -1; + } + + // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; + DWORD threadId[MAXIMUM_WAIT_OBJECTS]; + int returnCode = 0; + + DWORD dwParam = 0; + + /* Variables to capture the file name and the file pointer at thread level*/ + char fileName[MAX_LONGPATH]; + FILE *pFile = NULL; + struct statistics* buffer = NULL; + int statisticsSize = 0; + + /* Variables to capture the file name and the file pointer at process level*/ + char processFileName[MAX_LONGPATH]; + FILE *pProcessFile = NULL; + struct ProcessStats processStats; + DWORD dwStartTime; + + testStatus = PASS; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } +// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); + + /* Register the start time */ + dwStartTime = GetTickCount(); + processStats.relationId = RELATION_ID; + processStats.processId = USE_PROCESS_COUNT; + + _snprintf(processFileName, MAX_LONGPATH, "%d_process_event_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pProcessFile = fopen(processFileName, "w+"); + if(pProcessFile == NULL) + { + Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); + } + + statisticsSize = sizeof(struct statistics); + + _snprintf(fileName, MAX_LONGPATH, "%d_thread_event_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pFile = fopen(fileName, "w+"); + + if(pFile == NULL) + { + Fail("Error in opening thread File for write for process [%d]\n", USE_PROCESS_COUNT); + } + // For each thread we will log operations failed (int), passed (int), total (int) + // and number of ticks (DWORD) for the operations + resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); + + StartTestsEvHandle = CreateEvent( + NULL, /* lpEventAttributes*/ + TRUE, /* bManualReset */ + FALSE, /* bInitialState */ + NULL /* name of Event */ + ); + + if( StartTestsEvHandle == NULL ) + { + Fail("Error:%d: Unexpected failure " + "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); + + } + + /* Create StartTest Event */ + + hEventHandle = CreateEvent( + NULL, /* lpEventAttributes, inheritable to child processes*/ + TRUE, /* bAutomaticReset */ + TRUE, /* bInitialState */ + NULL + ); + + if( hEventHandle == NULL) + { + Fail("Unable to create Event handle for process id [%d], returned error [%d]\n", i, GetLastError()); + } + /* We already assume that the Event was created previously*/ + + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + } + + if (!SetEvent(StartTestsEvHandle)) + { + Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + /* Test running */ + returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); + + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testStatus = FAIL; + } + + processStats.operationTime = GetTimeDiff(dwStartTime); + + /* Write to a file*/ + if(pFile!= NULL) + { + for( i = 0; i < THREAD_COUNT; i++ ) + { + buffer = (struct statistics *)resultBuffer->getResultBuffer(i); + returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); + //Trace("Iteration %d over\n", i); + + } + } + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile\n"); + testStatus = FAIL; + } + + fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); + if(fclose(pProcessFile)) + { + Trace("Error: fclose failed for pProcessFile at Process %d\n", USE_PROCESS_COUNT); + testStatus = FAIL; + } + + /* Logging for the test case over, clean up the handles */ + +// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); + /* Clean Up */ + for( i = 0; i < THREAD_COUNT; i++ ) + { + if(!CloseHandle(hThread[i]) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); + testStatus = FAIL; + } + } + + if(!CloseHandle(StartTestsEvHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + if(!CloseHandle(hEventHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hEventHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + PAL_Terminate(); + return testStatus; + +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + unsigned int i = 0; + DWORD dwWaitResult; + + struct statistics stats; + DWORD dwStartTime; + + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + int Id=(int)lpParam; + + dwWaitResult = WaitForSingleObject( + StartTestsEvHandle, // handle to start test handle + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { + Fail("Error while waiting for StartTest Event@ thread %d, RC is %d, Error is %d\n", Id, dwWaitResult, GetLastError()); + } + + dwStartTime = GetTickCount(); + + for( i = 0; i < REPEAT_COUNT; i++ ) + { + dwWaitResult = WaitForSingleObject( + hEventHandle, // handle to Event + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { +// Trace("Error while waiting for onject @ thread %d, # iter %d, RC is %d, Error is %d\n", Id, i, dwWaitResult, GetLastError()); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + testStatus = FAIL; + continue; + } + + if (! SetEvent(hEventHandle)) + { + // Deal with error. +// Trace("Error while setting Event @ thread %d # iter %d\n", Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + // Do we need to have while true loop to attempt to set event? + testStatus = FAIL; + continue; + } + + stats.operationsTotal += 1; + stats.operationsPassed += 1; +// Trace("Successs while setting Event @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); + + } + + stats.operationTime = GetTimeDiff(dwStartTime); + if(resultBuffer->LogResult(Id, (char *)&stats)) + { + Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); + } + //Trace("Thread %d over for process %d\n", Id, USE_PROCESS_COUNT); +} diff --git a/src/pal/tests/palsuite/composite/object_management/event/nonshared/main.c b/src/pal/tests/palsuite/composite/object_management/event/nonshared/main.c deleted file mode 100644 index 7b61e91737..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/event/nonshared/main.c +++ /dev/null @@ -1,228 +0,0 @@ -// 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 Code: main.c and event.c -** main.c creates process and waits for all processes to get over -** event.c creates a event and then calls threads which will contend for the event -** -** This test is for Object Management Test case for event where Object type is not shareable. -** Algorithm -** o Create PROCESS_COUNT processes. -** o Main Thread of each process creates OBJECT_TYPE Object -** -** Author: ShamitP -**============================================================ -*/ - -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int PROCESS_COUNT = 10; -unsigned int THREAD_COUNT = 20; -unsigned int REPEAT_COUNT = 20000; -unsigned int RELATION_ID = 1001; - - -struct TestStats{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - - -int GetParameters( int argc, char **argv) -{ - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management event Test\n"); - printf("Usage:\n"); - printf("main\n\t[PROCESS_COUNT [greater than 1] \n"); - printf("\t[THREAD_COUNT [greater than 1] \n"); - printf("\t[REPEAT_COUNT [greater than 1]\n"); - printf("\t[RELATION_ID [greater than or Equal to 1]\n"); - return -1; - } - - PROCESS_COUNT = atoi(argv[1]); - if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; - - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - - char lpCommandLine[MAX_LONGPATH] = ""; - const char *ObjName = "Event"; - - int returnCode = 0; - DWORD processReturnCode = 0; - int testReturnCode = PASS; - - char fileName[MAX_LONGPATH]; - FILE *pFile = NULL; - DWORD dwStartTime = 0; - struct TestStats testStats; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - testStats.relationId = RELATION_ID; - testStats.processCount = PROCESS_COUNT; - testStats.threadCount = THREAD_COUNT; - testStats.repeatCount = REPEAT_COUNT; - testStats.buildNumber = getBuildNumber(); - - - _snprintf(fileName, MAX_LONGPATH, "main_event_%d_.txt", RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening main file for write\n"); - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_LONGPATH-1, "event %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) - { - Fail ("Error: Insufficient Event name string length for %s for iteration [%d]\n", ObjName, i); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - //Create Process - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); - } - else - { - hProcess[i] = pi[i].hProcess; - //Trace("Process created for [%d]\n", i); - - } - - } - - returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); - testReturnCode = FAIL; - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - testReturnCode = FAIL; - } - } - - testStats.operationTime = GetTimeDiff(dwStartTime); - fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile\n"); - testReturnCode = FAIL; - } - - if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - } - else - { - Trace("Test Failed\n"); - } - PAL_Terminate(); - return testReturnCode; -} diff --git a/src/pal/tests/palsuite/composite/object_management/event/nonshared/main.cpp b/src/pal/tests/palsuite/composite/object_management/event/nonshared/main.cpp new file mode 100644 index 0000000000..7b61e91737 --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/event/nonshared/main.cpp @@ -0,0 +1,228 @@ +// 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 Code: main.c and event.c +** main.c creates process and waits for all processes to get over +** event.c creates a event and then calls threads which will contend for the event +** +** This test is for Object Management Test case for event where Object type is not shareable. +** Algorithm +** o Create PROCESS_COUNT processes. +** o Main Thread of each process creates OBJECT_TYPE Object +** +** Author: ShamitP +**============================================================ +*/ + +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int PROCESS_COUNT = 10; +unsigned int THREAD_COUNT = 20; +unsigned int REPEAT_COUNT = 20000; +unsigned int RELATION_ID = 1001; + + +struct TestStats{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + + +int GetParameters( int argc, char **argv) +{ + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management event Test\n"); + printf("Usage:\n"); + printf("main\n\t[PROCESS_COUNT [greater than 1] \n"); + printf("\t[THREAD_COUNT [greater than 1] \n"); + printf("\t[REPEAT_COUNT [greater than 1]\n"); + printf("\t[RELATION_ID [greater than or Equal to 1]\n"); + return -1; + } + + PROCESS_COUNT = atoi(argv[1]); + if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; + + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + + char lpCommandLine[MAX_LONGPATH] = ""; + const char *ObjName = "Event"; + + int returnCode = 0; + DWORD processReturnCode = 0; + int testReturnCode = PASS; + + char fileName[MAX_LONGPATH]; + FILE *pFile = NULL; + DWORD dwStartTime = 0; + struct TestStats testStats; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + testStats.relationId = RELATION_ID; + testStats.processCount = PROCESS_COUNT; + testStats.threadCount = THREAD_COUNT; + testStats.repeatCount = REPEAT_COUNT; + testStats.buildNumber = getBuildNumber(); + + + _snprintf(fileName, MAX_LONGPATH, "main_event_%d_.txt", RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening main file for write\n"); + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( _snprintf( lpCommandLine, MAX_LONGPATH-1, "event %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) + { + Fail ("Error: Insufficient Event name string length for %s for iteration [%d]\n", ObjName, i); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + //Create Process + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); + } + else + { + hProcess[i] = pi[i].hProcess; + //Trace("Process created for [%d]\n", i); + + } + + } + + returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); + testReturnCode = FAIL; + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + testReturnCode = FAIL; + } + } + + testStats.operationTime = GetTimeDiff(dwStartTime); + fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile\n"); + testReturnCode = FAIL; + } + + if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + } + else + { + Trace("Test Failed\n"); + } + PAL_Terminate(); + return testReturnCode; +} diff --git a/src/pal/tests/palsuite/composite/object_management/event/shared/CMakeLists.txt b/src/pal/tests/palsuite/composite/object_management/event/shared/CMakeLists.txt index d326e3a42b..86188796bd 100644 --- a/src/pal/tests/palsuite/composite/object_management/event/shared/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/object_management/event/shared/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - event.c - main.c + event.cpp + main.cpp ) add_executable(paltest_event_shared diff --git a/src/pal/tests/palsuite/composite/object_management/event/shared/event.c b/src/pal/tests/palsuite/composite/object_management/event/shared/event.c deleted file mode 100644 index 83d5fce27e..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/event/shared/event.c +++ /dev/null @@ -1,373 +0,0 @@ -// 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 Code: main.c and event.c -** main.c creates process and waits for all processes to get over -** event.c creates a event and then calls threads which will contend for the event -** -** This test is for Object Management Test case for event where Object type is shareable. -** Algorithm -** o Main Process Creates OBJECT_TYPE Object -** o Create PROCESS_COUNT processes aware of the Shared Object -** -** Author: ShamitP -** Author: ShamitP -** -** -**============================================================ -*/ - -#include -#include "resultbuffer.h" -#include "resulttime.h" - -#define TIMEOUT 5000 -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; -unsigned int THREAD_COUNT = 0; -unsigned int REPEAT_COUNT = 0; -unsigned int RELATION_ID = 0; - -/* Capture statistics at per thread basis */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - -struct ProcessStats{ - unsigned int processId; - DWORD operationTime; - unsigned int relationId; -}; - -HANDLE StartTestsEvHandle = NULL; -HANDLE hEventHandle = NULL; - -/* Results Buffer */ -ResultBuffer *resultBuffer= NULL; - -int testStatus; - -const char sTmpEventName[MAX_PATH] = "StartTestEvent"; -char objectSuffix[MAX_PATH]; - -void PALAPI Run_Thread(LPVOID lpParam); - -int GetParameters( int argc, char **argv) -{ - if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management event Test\n"); - printf("Usage:\n"); - printf("main\n\t[USE_PROCESS_COUNT (greater than 1)] \n"); - printf("\t[THREAD_COUNT (greater than 1)] \n"); - printf("\t[REPEAT_COUNT (greater than 1)]\n"); - printf("\t[RELATION_ID [greater than or equal to 1]\n"); - printf("\t[Object Name Suffix]\n"); - - return -1; - } - - // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - if(argc == 6) - { - strncpy(objectSuffix, argv[5], MAX_PATH-1); - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; - DWORD threadId[MAXIMUM_WAIT_OBJECTS]; - - WCHAR *wcObjName = NULL; - - char ObjName[MAX_PATH] = "SHARED_EVENT"; - DWORD dwParam = 0; - - int returnCode = 0; - - /* Variables to capture the file name and the file pointer at thread level*/ - char fileName[MAX_PATH]; - FILE *pFile = NULL; - struct statistics* buffer = NULL; - int statisticsSize = 0; - - /* Variables to capture the file name and the file pointer at process level*/ - char processFileName[MAX_PATH]; - FILE *pProcessFile = NULL; - struct ProcessStats processStats; - DWORD dwStartTime; - - testStatus = PASS; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - ZeroMemory( objectSuffix, MAX_PATH ); - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } -// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); - - if(argc == 5) - { - strncat(ObjName, objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - processStats.relationId = RELATION_ID; - processStats.processId = USE_PROCESS_COUNT; - - _snprintf(processFileName, MAX_PATH, "%d_process_event_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pProcessFile = fopen(processFileName, "w+"); - if(pProcessFile == NULL) - { - Fail("Error:%d: in opening Process File for write for process [%d]\n", GetLastError(), USE_PROCESS_COUNT); - } - - statisticsSize = sizeof(struct statistics); - - _snprintf(fileName, MAX_PATH, "%d_thread_event_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pFile = fopen(fileName, "w+"); - - if(pFile == NULL) - { - Fail("Error:%d: in opening thread file for write for process [%d]\n", GetLastError(), USE_PROCESS_COUNT); - } - // For each thread we will log operations failed (int), passed (int), total (int) - // and number of ticks (DWORD) for the operations - resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); - - wcObjName = convert(ObjName); - - StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ - TRUE, /* bManualReset */ - FALSE, /* bInitialState */ - NULL); /* name of Event */ - - if( StartTestsEvHandle == NULL ) - { - Fail("Error:%d: Unexpected failure " - "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); - - } - - /* Create StartTest Event */ - - hEventHandle = OpenEventW( - EVENT_ALL_ACCESS, /* lpEventAttributes, inheritable to child processes*/ - FALSE, /* bAutomaticReset */ - wcObjName - ); - - if( hEventHandle == NULL) - { - Fail("Unable to create Event handle for process id [%d], returned error [%d]\n", i, GetLastError()); - } - /* We already assume that the Event was created previously*/ - - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - } - - if (!SetEvent(StartTestsEvHandle)) - { - Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - /* Test running */ - returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); - - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testStatus = FAIL; - } - - processStats.operationTime = GetTimeDiff(dwStartTime); - - /* Write to a file*/ - if(pFile!= NULL) - { - for( i = 0; i < THREAD_COUNT; i++ ) - { - buffer = (struct statistics *)resultBuffer->getResultBuffer(i); - returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); -// Trace("Iteration %d over\n", i); - - } - } - - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile at Process %d\n", USE_PROCESS_COUNT); - testStatus = FAIL; - } - - fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); - if(fclose(pProcessFile)) - { - Trace("Error: fclose failed for pProcessFile at Process %d\n", USE_PROCESS_COUNT); - testStatus = FAIL; - } - /* Logging for the test case over, clean up the handles */ - -// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); - - for( i = 0; i < THREAD_COUNT; i++ ) - { - if(!CloseHandle(hThread[i]) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); - testStatus = FAIL; - } - } - - if(!CloseHandle(StartTestsEvHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - if(!CloseHandle(hEventHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hEventHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - free(wcObjName); - PAL_Terminate(); - return testStatus; -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - unsigned int i = 0; - DWORD dwWaitResult; - - struct statistics stats; - DWORD dwStartTime; - - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - int Id=(int)lpParam; - - dwWaitResult = WaitForSingleObject( - StartTestsEvHandle, // handle to start test handle - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { - Trace("Error:%d: while waiting for StartTest Event@ thread %d\n", GetLastError(), Id); - testStatus = FAIL; - } - - dwStartTime = GetTickCount(); - - for( i = 0; i < REPEAT_COUNT; i++ ) - { - dwWaitResult = WaitForSingleObject( - hEventHandle, // handle to Event - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { - //Trace("Error:%d: while waiting for onject @ thread %d, # iter %d\n", GetLastError(), Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - testStatus = FAIL; - continue; - } - - if (! SetEvent(hEventHandle)) - { - // Deal with error. -// Trace("Error while setting Event @ thread %d # iter %d\n", Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - // do we need to have while true loop to attempt to set event...? - testStatus = FAIL; - continue; - } - - stats.operationsTotal += 1; - stats.operationsPassed += 1; - // Trace("Successs while setting Event @ iteration %d -> thread %d -> Process %d for handle %d\n", i, Id, USE_PROCESS_COUNT, hEventHandle); - - } - - stats.operationTime = GetTimeDiff(dwStartTime); - //Trace("OPeration time is %d", stats.operationTime ); - if(resultBuffer->LogResult(Id, (char *)&stats)) - { - Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); - } - //Trace("Thread %d over for process %d\n", Id, USE_PROCESS_COUNT); -} diff --git a/src/pal/tests/palsuite/composite/object_management/event/shared/event.cpp b/src/pal/tests/palsuite/composite/object_management/event/shared/event.cpp new file mode 100644 index 0000000000..83d5fce27e --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/event/shared/event.cpp @@ -0,0 +1,373 @@ +// 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 Code: main.c and event.c +** main.c creates process and waits for all processes to get over +** event.c creates a event and then calls threads which will contend for the event +** +** This test is for Object Management Test case for event where Object type is shareable. +** Algorithm +** o Main Process Creates OBJECT_TYPE Object +** o Create PROCESS_COUNT processes aware of the Shared Object +** +** Author: ShamitP +** Author: ShamitP +** +** +**============================================================ +*/ + +#include +#include "resultbuffer.h" +#include "resulttime.h" + +#define TIMEOUT 5000 +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; +unsigned int THREAD_COUNT = 0; +unsigned int REPEAT_COUNT = 0; +unsigned int RELATION_ID = 0; + +/* Capture statistics at per thread basis */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + +struct ProcessStats{ + unsigned int processId; + DWORD operationTime; + unsigned int relationId; +}; + +HANDLE StartTestsEvHandle = NULL; +HANDLE hEventHandle = NULL; + +/* Results Buffer */ +ResultBuffer *resultBuffer= NULL; + +int testStatus; + +const char sTmpEventName[MAX_PATH] = "StartTestEvent"; +char objectSuffix[MAX_PATH]; + +void PALAPI Run_Thread(LPVOID lpParam); + +int GetParameters( int argc, char **argv) +{ + if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management event Test\n"); + printf("Usage:\n"); + printf("main\n\t[USE_PROCESS_COUNT (greater than 1)] \n"); + printf("\t[THREAD_COUNT (greater than 1)] \n"); + printf("\t[REPEAT_COUNT (greater than 1)]\n"); + printf("\t[RELATION_ID [greater than or equal to 1]\n"); + printf("\t[Object Name Suffix]\n"); + + return -1; + } + + // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + if(argc == 6) + { + strncpy(objectSuffix, argv[5], MAX_PATH-1); + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; + DWORD threadId[MAXIMUM_WAIT_OBJECTS]; + + WCHAR *wcObjName = NULL; + + char ObjName[MAX_PATH] = "SHARED_EVENT"; + DWORD dwParam = 0; + + int returnCode = 0; + + /* Variables to capture the file name and the file pointer at thread level*/ + char fileName[MAX_PATH]; + FILE *pFile = NULL; + struct statistics* buffer = NULL; + int statisticsSize = 0; + + /* Variables to capture the file name and the file pointer at process level*/ + char processFileName[MAX_PATH]; + FILE *pProcessFile = NULL; + struct ProcessStats processStats; + DWORD dwStartTime; + + testStatus = PASS; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + ZeroMemory( objectSuffix, MAX_PATH ); + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } +// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); + + if(argc == 5) + { + strncat(ObjName, objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + processStats.relationId = RELATION_ID; + processStats.processId = USE_PROCESS_COUNT; + + _snprintf(processFileName, MAX_PATH, "%d_process_event_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pProcessFile = fopen(processFileName, "w+"); + if(pProcessFile == NULL) + { + Fail("Error:%d: in opening Process File for write for process [%d]\n", GetLastError(), USE_PROCESS_COUNT); + } + + statisticsSize = sizeof(struct statistics); + + _snprintf(fileName, MAX_PATH, "%d_thread_event_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pFile = fopen(fileName, "w+"); + + if(pFile == NULL) + { + Fail("Error:%d: in opening thread file for write for process [%d]\n", GetLastError(), USE_PROCESS_COUNT); + } + // For each thread we will log operations failed (int), passed (int), total (int) + // and number of ticks (DWORD) for the operations + resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); + + wcObjName = convert(ObjName); + + StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ + TRUE, /* bManualReset */ + FALSE, /* bInitialState */ + NULL); /* name of Event */ + + if( StartTestsEvHandle == NULL ) + { + Fail("Error:%d: Unexpected failure " + "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); + + } + + /* Create StartTest Event */ + + hEventHandle = OpenEventW( + EVENT_ALL_ACCESS, /* lpEventAttributes, inheritable to child processes*/ + FALSE, /* bAutomaticReset */ + wcObjName + ); + + if( hEventHandle == NULL) + { + Fail("Unable to create Event handle for process id [%d], returned error [%d]\n", i, GetLastError()); + } + /* We already assume that the Event was created previously*/ + + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + } + + if (!SetEvent(StartTestsEvHandle)) + { + Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + /* Test running */ + returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); + + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testStatus = FAIL; + } + + processStats.operationTime = GetTimeDiff(dwStartTime); + + /* Write to a file*/ + if(pFile!= NULL) + { + for( i = 0; i < THREAD_COUNT; i++ ) + { + buffer = (struct statistics *)resultBuffer->getResultBuffer(i); + returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); +// Trace("Iteration %d over\n", i); + + } + } + + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile at Process %d\n", USE_PROCESS_COUNT); + testStatus = FAIL; + } + + fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); + if(fclose(pProcessFile)) + { + Trace("Error: fclose failed for pProcessFile at Process %d\n", USE_PROCESS_COUNT); + testStatus = FAIL; + } + /* Logging for the test case over, clean up the handles */ + +// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); + + for( i = 0; i < THREAD_COUNT; i++ ) + { + if(!CloseHandle(hThread[i]) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); + testStatus = FAIL; + } + } + + if(!CloseHandle(StartTestsEvHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + if(!CloseHandle(hEventHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hEventHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + free(wcObjName); + PAL_Terminate(); + return testStatus; +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + unsigned int i = 0; + DWORD dwWaitResult; + + struct statistics stats; + DWORD dwStartTime; + + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + int Id=(int)lpParam; + + dwWaitResult = WaitForSingleObject( + StartTestsEvHandle, // handle to start test handle + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { + Trace("Error:%d: while waiting for StartTest Event@ thread %d\n", GetLastError(), Id); + testStatus = FAIL; + } + + dwStartTime = GetTickCount(); + + for( i = 0; i < REPEAT_COUNT; i++ ) + { + dwWaitResult = WaitForSingleObject( + hEventHandle, // handle to Event + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { + //Trace("Error:%d: while waiting for onject @ thread %d, # iter %d\n", GetLastError(), Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + testStatus = FAIL; + continue; + } + + if (! SetEvent(hEventHandle)) + { + // Deal with error. +// Trace("Error while setting Event @ thread %d # iter %d\n", Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + // do we need to have while true loop to attempt to set event...? + testStatus = FAIL; + continue; + } + + stats.operationsTotal += 1; + stats.operationsPassed += 1; + // Trace("Successs while setting Event @ iteration %d -> thread %d -> Process %d for handle %d\n", i, Id, USE_PROCESS_COUNT, hEventHandle); + + } + + stats.operationTime = GetTimeDiff(dwStartTime); + //Trace("OPeration time is %d", stats.operationTime ); + if(resultBuffer->LogResult(Id, (char *)&stats)) + { + Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); + } + //Trace("Thread %d over for process %d\n", Id, USE_PROCESS_COUNT); +} diff --git a/src/pal/tests/palsuite/composite/object_management/event/shared/main.c b/src/pal/tests/palsuite/composite/object_management/event/shared/main.c deleted file mode 100644 index c4a4067b5d..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/event/shared/main.c +++ /dev/null @@ -1,265 +0,0 @@ -// 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 Code: main.c and event.c -** main.c creates process and waits for all processes to get over -** event.c creates a event and then calls threads which will contend for the event -** -** This test is for Object Management Test case for event where Object type is shareable. -** Algorithm -** o Main Process Creates OBJECT_TYPE Object -** o Create PROCESS_COUNT processes aware of the Shared Object -** -** Author: ShamitP -** -** -**============================================================ -*/ -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int PROCESS_COUNT = 2; -unsigned int THREAD_COUNT = 20; -unsigned int REPEAT_COUNT = 200; -unsigned int RELATION_ID = 1001; - - -char objectSuffix[MAX_PATH_FNAME]; - -struct TestStats{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - -int GetParameters( int argc, char **argv) -{ - if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management event Test\n"); - printf("Usage:\n"); - printf("main\n\t[PROCESS_COUNT (greater than 1)] \n"); - printf("\t[THREAD_COUNT (greater than 1)] \n"); - printf("\t[REPEAT_COUNT (greater than 1)]\n"); - printf("\t[RELATION_ID [greater than or equal to 1]\n"); - printf("\t[Object Name Suffix]\n"); - return -1; - } - - PROCESS_COUNT = atoi(argv[1]); - if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - - if(argc == 6) - { - strncpy(objectSuffix, argv[5], MAX_PATH_FNAME-1); - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; - HANDLE hEventHandle; - - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - - char lpCommandLine[MAX_LONGPATH] = ""; - char ObjName[MAX_PATH_FNAME] = "SHARED_EVENT"; - - int returnCode = 0; - DWORD processReturnCode = 0; - int testReturnCode = PASS; - - char fileName[MAX_PATH_FNAME]; - FILE *pFile = NULL; - DWORD dwStartTime; - struct TestStats testStats; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - ZeroMemory( objectSuffix, MAX_PATH_FNAME ); - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - if(argc == 5) - { - strncat(ObjName, objectSuffix, MAX_PATH_FNAME - (sizeof(ObjName) + 1) ); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - testStats.relationId = RELATION_ID; - testStats.processCount = PROCESS_COUNT; - testStats.threadCount = THREAD_COUNT; - testStats.repeatCount = REPEAT_COUNT; - testStats.buildNumber = getBuildNumber(); - - - _snprintf(fileName, MAX_PATH_FNAME, "main_event_%d_.txt", RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening main file for write\n"); - } - - hEventHandle = CreateEvent( - NULL, /* lpEventAttributes, inheritable to child processes*/ - TRUE, /* bAutomaticReset */ - TRUE, /* bInitialState */ - ObjName - ); - - if( hEventHandle == NULL) - { - Fail("Unable to create Event handle, returned error [%d]\n", GetLastError()); - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - - ZeroMemory( lpCommandLine, MAX_PATH_FNAME ); - if ( _snprintf( lpCommandLine, MAX_PATH_FNAME-1, "event %d %d %d %d %s", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID, objectSuffix) < 0 ) - { - Fail ("Error: Insufficient Event name string length for %s for iteration [%d]\n", ObjName, i); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); - } - else - { - hProcess[i] = pi[i].hProcess; -// Trace("Process created for [%d]\n", i); - - } - - //Create Process - - } - - returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); - testReturnCode = FAIL; - } - -// Trace("Test over\n"); - for( i = 0; i < PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - testReturnCode = FAIL; - } - } - - testStats.operationTime = GetTimeDiff(dwStartTime); - fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile\n"); - testReturnCode = FAIL; - } - - if(!CloseHandle(hEventHandle)) - { - Trace("Error:%d: CloseHandle failed for hEventHandle\n", GetLastError()); - testReturnCode = FAIL; - } - - if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - } - else - { - Trace("Test Failed\n"); - } - - PAL_Terminate(); - return testReturnCode; -} diff --git a/src/pal/tests/palsuite/composite/object_management/event/shared/main.cpp b/src/pal/tests/palsuite/composite/object_management/event/shared/main.cpp new file mode 100644 index 0000000000..c4a4067b5d --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/event/shared/main.cpp @@ -0,0 +1,265 @@ +// 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 Code: main.c and event.c +** main.c creates process and waits for all processes to get over +** event.c creates a event and then calls threads which will contend for the event +** +** This test is for Object Management Test case for event where Object type is shareable. +** Algorithm +** o Main Process Creates OBJECT_TYPE Object +** o Create PROCESS_COUNT processes aware of the Shared Object +** +** Author: ShamitP +** +** +**============================================================ +*/ +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int PROCESS_COUNT = 2; +unsigned int THREAD_COUNT = 20; +unsigned int REPEAT_COUNT = 200; +unsigned int RELATION_ID = 1001; + + +char objectSuffix[MAX_PATH_FNAME]; + +struct TestStats{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + +int GetParameters( int argc, char **argv) +{ + if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management event Test\n"); + printf("Usage:\n"); + printf("main\n\t[PROCESS_COUNT (greater than 1)] \n"); + printf("\t[THREAD_COUNT (greater than 1)] \n"); + printf("\t[REPEAT_COUNT (greater than 1)]\n"); + printf("\t[RELATION_ID [greater than or equal to 1]\n"); + printf("\t[Object Name Suffix]\n"); + return -1; + } + + PROCESS_COUNT = atoi(argv[1]); + if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + + if(argc == 6) + { + strncpy(objectSuffix, argv[5], MAX_PATH_FNAME-1); + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; + HANDLE hEventHandle; + + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + + char lpCommandLine[MAX_LONGPATH] = ""; + char ObjName[MAX_PATH_FNAME] = "SHARED_EVENT"; + + int returnCode = 0; + DWORD processReturnCode = 0; + int testReturnCode = PASS; + + char fileName[MAX_PATH_FNAME]; + FILE *pFile = NULL; + DWORD dwStartTime; + struct TestStats testStats; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + ZeroMemory( objectSuffix, MAX_PATH_FNAME ); + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + if(argc == 5) + { + strncat(ObjName, objectSuffix, MAX_PATH_FNAME - (sizeof(ObjName) + 1) ); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + testStats.relationId = RELATION_ID; + testStats.processCount = PROCESS_COUNT; + testStats.threadCount = THREAD_COUNT; + testStats.repeatCount = REPEAT_COUNT; + testStats.buildNumber = getBuildNumber(); + + + _snprintf(fileName, MAX_PATH_FNAME, "main_event_%d_.txt", RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening main file for write\n"); + } + + hEventHandle = CreateEvent( + NULL, /* lpEventAttributes, inheritable to child processes*/ + TRUE, /* bAutomaticReset */ + TRUE, /* bInitialState */ + ObjName + ); + + if( hEventHandle == NULL) + { + Fail("Unable to create Event handle, returned error [%d]\n", GetLastError()); + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + + ZeroMemory( lpCommandLine, MAX_PATH_FNAME ); + if ( _snprintf( lpCommandLine, MAX_PATH_FNAME-1, "event %d %d %d %d %s", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID, objectSuffix) < 0 ) + { + Fail ("Error: Insufficient Event name string length for %s for iteration [%d]\n", ObjName, i); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); + } + else + { + hProcess[i] = pi[i].hProcess; +// Trace("Process created for [%d]\n", i); + + } + + //Create Process + + } + + returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); + testReturnCode = FAIL; + } + +// Trace("Test over\n"); + for( i = 0; i < PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + testReturnCode = FAIL; + } + } + + testStats.operationTime = GetTimeDiff(dwStartTime); + fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile\n"); + testReturnCode = FAIL; + } + + if(!CloseHandle(hEventHandle)) + { + Trace("Error:%d: CloseHandle failed for hEventHandle\n", GetLastError()); + testReturnCode = FAIL; + } + + if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + } + else + { + Trace("Test Failed\n"); + } + + PAL_Terminate(); + return testReturnCode; +} diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/CMakeLists.txt b/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/CMakeLists.txt index 7859cd4653..03d5efac27 100644 --- a/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - main.c - mutex.c + main.cpp + mutex.cpp ) add_executable(paltest_mutex_nonshared diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/main.c b/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/main.c deleted file mode 100644 index 80f31aad6e..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/main.c +++ /dev/null @@ -1,230 +0,0 @@ -// 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 Code: main.c and mutex.c -** main.c creates process and waits for all processes to get over -** mutex.c creates a mutex and then calls threads which will contend for the mutex -** -** This test is for Object Management Test case for Mutex where Object type is not shareable. -** Algorithm -** o Create PROCESS_COUNT processes. -** o Main Thread of each process creates OBJECT_TYPE Object -** -** Author: ShamitP -**============================================================ -*/ - -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int PROCESS_COUNT = 2; -unsigned int THREAD_COUNT = 20; -unsigned int REPEAT_COUNT = 4000; -unsigned int RELATION_ID = 1001; - - -struct TestStats{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - -int GetParameters( int argc, char **argv) -{ - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management Mutex Test\n"); - printf("Usage:\n"); - printf("main\n\t[PROCESS_COUNT [greater than 1] \n"); - printf("\t[THREAD_COUNT [greater than 1] \n"); - printf("\t[REPEAT_COUNT [greater than 1]\n"); - printf("\t[RELATION_ID [greater than 1]\n"); - - - return -1; - } - - PROCESS_COUNT = atoi(argv[1]); - if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; - HANDLE hMutexHandle[MAXIMUM_WAIT_OBJECTS]; - - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - - const char *ObjName = "Mutex"; - char lpCommandLine[MAX_PATH] = ""; - - int returnCode = 0; - DWORD processReturnCode = 0; - int testReturnCode = PASS; - - char fileName[MAX_PATH]; - FILE *pFile = NULL; - DWORD dwStartTime; - struct TestStats testStats; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - testStats.relationId = RELATION_ID; - testStats.processCount = PROCESS_COUNT; - testStats.threadCount = THREAD_COUNT; - testStats.repeatCount = REPEAT_COUNT; - testStats.buildNumber = getBuildNumber(); - - - _snprintf(fileName, MAX_PATH, "main_mutex_%d_.txt", RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening main file for write\n"); - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_PATH-1, "mutex %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) - { - Fail("Error Insufficient mutex name string length for %s for iteration [%d]\n", ObjName, i); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); - } - else - { - hProcess[i] = pi[i].hProcess; -// Trace("Process created for [%d]\n", i); - - } - - //Create Process - - } - - returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); - testReturnCode = FAIL; - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - testReturnCode = FAIL; - } - } - - testStats.operationTime = GetTimeDiff(dwStartTime); - fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile\n"); - testReturnCode = FAIL; - } - - if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - } - else - { - Trace("Test Failed\n"); - } - - PAL_Terminate(); - return testReturnCode; -} diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/main.cpp b/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/main.cpp new file mode 100644 index 0000000000..80f31aad6e --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/main.cpp @@ -0,0 +1,230 @@ +// 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 Code: main.c and mutex.c +** main.c creates process and waits for all processes to get over +** mutex.c creates a mutex and then calls threads which will contend for the mutex +** +** This test is for Object Management Test case for Mutex where Object type is not shareable. +** Algorithm +** o Create PROCESS_COUNT processes. +** o Main Thread of each process creates OBJECT_TYPE Object +** +** Author: ShamitP +**============================================================ +*/ + +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int PROCESS_COUNT = 2; +unsigned int THREAD_COUNT = 20; +unsigned int REPEAT_COUNT = 4000; +unsigned int RELATION_ID = 1001; + + +struct TestStats{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + +int GetParameters( int argc, char **argv) +{ + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management Mutex Test\n"); + printf("Usage:\n"); + printf("main\n\t[PROCESS_COUNT [greater than 1] \n"); + printf("\t[THREAD_COUNT [greater than 1] \n"); + printf("\t[REPEAT_COUNT [greater than 1]\n"); + printf("\t[RELATION_ID [greater than 1]\n"); + + + return -1; + } + + PROCESS_COUNT = atoi(argv[1]); + if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; + HANDLE hMutexHandle[MAXIMUM_WAIT_OBJECTS]; + + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + + const char *ObjName = "Mutex"; + char lpCommandLine[MAX_PATH] = ""; + + int returnCode = 0; + DWORD processReturnCode = 0; + int testReturnCode = PASS; + + char fileName[MAX_PATH]; + FILE *pFile = NULL; + DWORD dwStartTime; + struct TestStats testStats; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + testStats.relationId = RELATION_ID; + testStats.processCount = PROCESS_COUNT; + testStats.threadCount = THREAD_COUNT; + testStats.repeatCount = REPEAT_COUNT; + testStats.buildNumber = getBuildNumber(); + + + _snprintf(fileName, MAX_PATH, "main_mutex_%d_.txt", RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening main file for write\n"); + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( _snprintf( lpCommandLine, MAX_PATH-1, "mutex %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) + { + Fail("Error Insufficient mutex name string length for %s for iteration [%d]\n", ObjName, i); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); + } + else + { + hProcess[i] = pi[i].hProcess; +// Trace("Process created for [%d]\n", i); + + } + + //Create Process + + } + + returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); + testReturnCode = FAIL; + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + testReturnCode = FAIL; + } + } + + testStats.operationTime = GetTimeDiff(dwStartTime); + fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile\n"); + testReturnCode = FAIL; + } + + if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + } + else + { + Trace("Test Failed\n"); + } + + PAL_Terminate(); + return testReturnCode; +} diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/mutex.c b/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/mutex.c deleted file mode 100644 index 7f1f659f92..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/mutex.c +++ /dev/null @@ -1,340 +0,0 @@ -// 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 Code: main.c and mutex.c -** main.c creates process and waits for all processes to get over -** mutex.c creates a mutex and then calls threads which will contend for the mutex -** -** This test is for Object Management Test case for Mutex where Object type is not shareable. -** Algorithm -** o Create PROCESS_COUNT processes. -** o Main Thread of each process creates OBJECT_TYPE Object -** -** Author: ShamitP -**============================================================ -*/ - -#include -#include "resultbuffer.h" -#include "resulttime.h" - -#define TIMEOUT 5000 -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; -unsigned int THREAD_COUNT = 0; -unsigned int REPEAT_COUNT = 0; -unsigned int RELATION_ID = 1001; - -/* Capture statistics at per thread basis */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - -struct ProcessStats{ - unsigned int processId; - DWORD operationTime; - unsigned int relationId; -}; - -HANDLE StartTestsEvHandle = NULL; -HANDLE hMutexHandle = NULL; - -/* Results Buffer */ -ResultBuffer *resultBuffer = NULL; - -int testStatus; - -void PALAPI Run_Thread(LPVOID lpParam); - -int GetParameters( int argc, char **argv) -{ - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management Mutex Test\n"); - printf("Usage:\n"); - printf("mutex\n\t[USE_PROCESS_COUNT ( greater than 1] \n"); - printf("\t[THREAD_COUNT ( greater than 1] \n"); - printf("\t[REPEAT_COUNT ( greater than 1]\n"); - printf("\t[RELATION_ID [greater than 1]\n"); - return -1; - } - - // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; - DWORD threadId[MAXIMUM_WAIT_OBJECTS]; - - const char sTmpEventName[MAX_PATH] = "StartTestEvent"; - - DWORD dwParam = 0; - - int returnCode = 0; - - /* Variables to capture the file name and the file pointer at thread level*/ - char fileName[MAX_PATH]; - FILE *pFile = NULL; - struct statistics* buffer = NULL; - int statisticsSize = 0; - - /* Variables to capture the file name and the file pointer at process level*/ - char processFileName[MAX_PATH]; - FILE *pProcessFile = NULL; - struct ProcessStats processStats; - DWORD dwStartTime; - - testStatus = PASS; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } -// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); - - /* Register the start time */ - dwStartTime = GetTickCount(); - processStats.relationId = RELATION_ID; - processStats.processId = USE_PROCESS_COUNT; - - _snprintf(processFileName, MAX_PATH, "%d_process_mutex_%d_.txt", USE_PROCESS_COUNT,RELATION_ID); - pProcessFile = fopen(processFileName, "w+"); - if(pProcessFile == NULL) - { - Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); - } - - statisticsSize = sizeof(struct statistics); - - _snprintf(fileName, MAX_PATH, "%d_thread_mutex_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); - } - // For each thread we will log operations failed (int), passed (int), total (int) - // and number of ticks (DWORD) for the operations - resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); - - StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ - TRUE, /* bManualReset */ - FALSE, /* bInitialState */ - NULL - ); /* name of Event */ - - if( StartTestsEvHandle == NULL ) - { - Fail("Error:%d: Unexpected failure " - "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); - - } - - /* Create StartTest Event */ - - hMutexHandle = CreateMutex( - NULL, - FALSE, /* bInitialOwner, owns initially */ - NULL - ); - - if( hMutexHandle == NULL) - { - Fail("Unable to create Mutex handle for process id [%d], returned error [%d]\n", i, GetLastError()); - } - /* We already assume that the mutex was created previously*/ - - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - } - - if (!SetEvent(StartTestsEvHandle)) - { - Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - /* Test running */ - returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); - - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testStatus = FAIL; - } - - processStats.operationTime = GetTimeDiff(dwStartTime); - - /* Write to a file*/ - if(pFile!= NULL) - { - for( i = 0; i < THREAD_COUNT; i++ ) - { - buffer = (struct statistics *)resultBuffer->getResultBuffer(i); - returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); -// Trace("Iteration %d over\n", i); - - } - } - fclose(pFile); - - fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); - fclose(pProcessFile); - - /* Logging for the test case over, clean up the handles */ - -// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); - - - for( i = 0; i < THREAD_COUNT; i++ ) - { - if(!CloseHandle(hThread[i]) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); - testStatus = FAIL; - } - } - - if(!CloseHandle(StartTestsEvHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - if(!CloseHandle(hMutexHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hMutexHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - PAL_Terminate(); - return testStatus; -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - unsigned int i = 0; - DWORD dwWaitResult; - - struct statistics stats; - DWORD dwStartTime; - - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - int Id=(int)lpParam; - - dwWaitResult = WaitForSingleObject( - StartTestsEvHandle, // handle to mutex - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { - Trace("Error while waiting for StartTest Event@ thread %d\n", Id); - testStatus = FAIL; - } - - dwStartTime = GetTickCount(); - - for( i = 0; i < REPEAT_COUNT; i++ ) - { - dwWaitResult = WaitForSingleObject( - hMutexHandle, // handle to mutex - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { -// Trace("Error while waiting for onject @ thread %d, # iter %d\n", Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - testStatus = FAIL; - continue; - } - if (! ReleaseMutex(hMutexHandle)) - { - // Deal with error. -// Trace("Error while releasing mutex @ thread %d # iter %d\n", Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - // Probably need to have while true loop to attempt to release mutex... - testStatus = FAIL; - continue; - } - - stats.operationsTotal += 1; - stats.operationsPassed += 1; - // Trace("Successs while releasing mutex @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); - - } - - stats.operationTime = GetTimeDiff(dwStartTime); - //Trace("OPeration time is %d", stats.operationTime ); - if(resultBuffer->LogResult(Id, (char *)&stats)) - { - Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); - } -} diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/mutex.cpp b/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/mutex.cpp new file mode 100644 index 0000000000..7f1f659f92 --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/mutex/nonshared/mutex.cpp @@ -0,0 +1,340 @@ +// 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 Code: main.c and mutex.c +** main.c creates process and waits for all processes to get over +** mutex.c creates a mutex and then calls threads which will contend for the mutex +** +** This test is for Object Management Test case for Mutex where Object type is not shareable. +** Algorithm +** o Create PROCESS_COUNT processes. +** o Main Thread of each process creates OBJECT_TYPE Object +** +** Author: ShamitP +**============================================================ +*/ + +#include +#include "resultbuffer.h" +#include "resulttime.h" + +#define TIMEOUT 5000 +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; +unsigned int THREAD_COUNT = 0; +unsigned int REPEAT_COUNT = 0; +unsigned int RELATION_ID = 1001; + +/* Capture statistics at per thread basis */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + +struct ProcessStats{ + unsigned int processId; + DWORD operationTime; + unsigned int relationId; +}; + +HANDLE StartTestsEvHandle = NULL; +HANDLE hMutexHandle = NULL; + +/* Results Buffer */ +ResultBuffer *resultBuffer = NULL; + +int testStatus; + +void PALAPI Run_Thread(LPVOID lpParam); + +int GetParameters( int argc, char **argv) +{ + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management Mutex Test\n"); + printf("Usage:\n"); + printf("mutex\n\t[USE_PROCESS_COUNT ( greater than 1] \n"); + printf("\t[THREAD_COUNT ( greater than 1] \n"); + printf("\t[REPEAT_COUNT ( greater than 1]\n"); + printf("\t[RELATION_ID [greater than 1]\n"); + return -1; + } + + // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; + DWORD threadId[MAXIMUM_WAIT_OBJECTS]; + + const char sTmpEventName[MAX_PATH] = "StartTestEvent"; + + DWORD dwParam = 0; + + int returnCode = 0; + + /* Variables to capture the file name and the file pointer at thread level*/ + char fileName[MAX_PATH]; + FILE *pFile = NULL; + struct statistics* buffer = NULL; + int statisticsSize = 0; + + /* Variables to capture the file name and the file pointer at process level*/ + char processFileName[MAX_PATH]; + FILE *pProcessFile = NULL; + struct ProcessStats processStats; + DWORD dwStartTime; + + testStatus = PASS; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } +// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); + + /* Register the start time */ + dwStartTime = GetTickCount(); + processStats.relationId = RELATION_ID; + processStats.processId = USE_PROCESS_COUNT; + + _snprintf(processFileName, MAX_PATH, "%d_process_mutex_%d_.txt", USE_PROCESS_COUNT,RELATION_ID); + pProcessFile = fopen(processFileName, "w+"); + if(pProcessFile == NULL) + { + Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); + } + + statisticsSize = sizeof(struct statistics); + + _snprintf(fileName, MAX_PATH, "%d_thread_mutex_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); + } + // For each thread we will log operations failed (int), passed (int), total (int) + // and number of ticks (DWORD) for the operations + resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); + + StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ + TRUE, /* bManualReset */ + FALSE, /* bInitialState */ + NULL + ); /* name of Event */ + + if( StartTestsEvHandle == NULL ) + { + Fail("Error:%d: Unexpected failure " + "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); + + } + + /* Create StartTest Event */ + + hMutexHandle = CreateMutex( + NULL, + FALSE, /* bInitialOwner, owns initially */ + NULL + ); + + if( hMutexHandle == NULL) + { + Fail("Unable to create Mutex handle for process id [%d], returned error [%d]\n", i, GetLastError()); + } + /* We already assume that the mutex was created previously*/ + + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + } + + if (!SetEvent(StartTestsEvHandle)) + { + Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + /* Test running */ + returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); + + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testStatus = FAIL; + } + + processStats.operationTime = GetTimeDiff(dwStartTime); + + /* Write to a file*/ + if(pFile!= NULL) + { + for( i = 0; i < THREAD_COUNT; i++ ) + { + buffer = (struct statistics *)resultBuffer->getResultBuffer(i); + returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); +// Trace("Iteration %d over\n", i); + + } + } + fclose(pFile); + + fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); + fclose(pProcessFile); + + /* Logging for the test case over, clean up the handles */ + +// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); + + + for( i = 0; i < THREAD_COUNT; i++ ) + { + if(!CloseHandle(hThread[i]) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); + testStatus = FAIL; + } + } + + if(!CloseHandle(StartTestsEvHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + if(!CloseHandle(hMutexHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hMutexHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + PAL_Terminate(); + return testStatus; +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + unsigned int i = 0; + DWORD dwWaitResult; + + struct statistics stats; + DWORD dwStartTime; + + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + int Id=(int)lpParam; + + dwWaitResult = WaitForSingleObject( + StartTestsEvHandle, // handle to mutex + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { + Trace("Error while waiting for StartTest Event@ thread %d\n", Id); + testStatus = FAIL; + } + + dwStartTime = GetTickCount(); + + for( i = 0; i < REPEAT_COUNT; i++ ) + { + dwWaitResult = WaitForSingleObject( + hMutexHandle, // handle to mutex + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { +// Trace("Error while waiting for onject @ thread %d, # iter %d\n", Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + testStatus = FAIL; + continue; + } + if (! ReleaseMutex(hMutexHandle)) + { + // Deal with error. +// Trace("Error while releasing mutex @ thread %d # iter %d\n", Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + // Probably need to have while true loop to attempt to release mutex... + testStatus = FAIL; + continue; + } + + stats.operationsTotal += 1; + stats.operationsPassed += 1; + // Trace("Successs while releasing mutex @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); + + } + + stats.operationTime = GetTimeDiff(dwStartTime); + //Trace("OPeration time is %d", stats.operationTime ); + if(resultBuffer->LogResult(Id, (char *)&stats)) + { + Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); + } +} diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/shared/CMakeLists.txt b/src/pal/tests/palsuite/composite/object_management/mutex/shared/CMakeLists.txt index cf33d0b464..d4b50cd66e 100644 --- a/src/pal/tests/palsuite/composite/object_management/mutex/shared/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/object_management/mutex/shared/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - main.c - mutex.c + main.cpp + mutex.cpp ) add_executable(paltest_mutex_shared diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/shared/main.c b/src/pal/tests/palsuite/composite/object_management/mutex/shared/main.c deleted file mode 100644 index aa98855565..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/mutex/shared/main.c +++ /dev/null @@ -1,265 +0,0 @@ -// 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. - -/*============================================================ -** -** This test is for Object Management Test case for Mutex where Object type is shareable. -** -** Source Code: main.c and mutex.c -** main.c creates a mutex, creates processes and waits for all processes to get over -** mutex.c create threads which will contend for the mutex -** -** This test is for Object Management Test case for Mutex where Object type is not shareable. -** Algorithm -** o Main Process Creates OBJECT_TYPE Object -** o Create PROCESS_COUNT processes aware of the Shared Object -** -** Author: ShamitP -** -** -**============================================================ -*/ - -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int PROCESS_COUNT = 2; -unsigned int THREAD_COUNT = 2; -unsigned int REPEAT_COUNT = 40000; -unsigned int RELATION_ID = 1001; - - -char objectSuffix[MAX_PATH]; - -struct TestStats{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - -int GetParameters( int argc, char **argv) -{ - if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management event Test\n"); - printf("Usage:\n"); - printf("main\n\t[PROCESS_COUNT (greater than 1)] \n"); - printf("\t[THREAD_COUNT (greater than 1)] \n"); - printf("\t[REPEAT_COUNT (greater than 1)]\n"); - printf("\t[RELATION_ID [greater than 1]\n"); - printf("\t[Object Name Suffix]\n"); - return -1; - } - - PROCESS_COUNT = atoi(argv[1]); - if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - if(argc == 6) - { - strncpy(objectSuffix, argv[5], MAX_PATH-1); - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; - HANDLE hMutexHandle; - - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - - char ObjName[MAX_PATH] = "SHARED_MUTEX"; - char lpCommandLine[MAX_PATH] = ""; - - int returnCode = 0; - DWORD processReturnCode = 0; - int testReturnCode = PASS; - - char fileName[MAX_PATH]; - FILE *pFile = NULL; - DWORD dwStartTime; - struct TestStats testStats; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - ZeroMemory( objectSuffix, MAX_PATH ); - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - if(argc == 5) - { - strncat(ObjName, objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - testStats.relationId = RELATION_ID; - testStats.processCount = PROCESS_COUNT; - testStats.threadCount = THREAD_COUNT; - testStats.repeatCount = REPEAT_COUNT; - testStats.buildNumber = getBuildNumber(); - - - _snprintf(fileName, MAX_PATH, "main_mutex_%d_.txt", RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening main file for write\n"); - } - - hMutexHandle = CreateMutex( - NULL, - FALSE, /* bInitialOwner, owns initially */ - ObjName - ); - - if( hMutexHandle == NULL) - { - Fail("Unable to create Mutex handle for Main thread returned error [%d]\n", GetLastError()); - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_PATH-1, "mutex %d %d %d %d %s", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID, objectSuffix) < 0 ) - { - Fail ("Error Insufficient mutex name string length for %s for iteration [%d]\n", ObjName, i); - } - - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - //Create Process - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); - } - else - { - hProcess[i] = pi[i].hProcess; -// Trace("Process created for [%d]\n", i); - - } - } - - returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); - testReturnCode = FAIL; - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - testReturnCode = FAIL; - } - } - - testStats.operationTime = GetTimeDiff(dwStartTime); - fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber ); - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile\n"); - testReturnCode = FAIL; - } - - if(!CloseHandle(hMutexHandle)) - { - Trace("Error:%d: CloseHandle failed for hMutexHandle\n", GetLastError()); - testReturnCode = FAIL; - - } - - if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - } - else - { - Trace("Test Failed\n"); - } - - PAL_Terminate(); - return testReturnCode; -} - diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/shared/main.cpp b/src/pal/tests/palsuite/composite/object_management/mutex/shared/main.cpp new file mode 100644 index 0000000000..aa98855565 --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/mutex/shared/main.cpp @@ -0,0 +1,265 @@ +// 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. + +/*============================================================ +** +** This test is for Object Management Test case for Mutex where Object type is shareable. +** +** Source Code: main.c and mutex.c +** main.c creates a mutex, creates processes and waits for all processes to get over +** mutex.c create threads which will contend for the mutex +** +** This test is for Object Management Test case for Mutex where Object type is not shareable. +** Algorithm +** o Main Process Creates OBJECT_TYPE Object +** o Create PROCESS_COUNT processes aware of the Shared Object +** +** Author: ShamitP +** +** +**============================================================ +*/ + +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int PROCESS_COUNT = 2; +unsigned int THREAD_COUNT = 2; +unsigned int REPEAT_COUNT = 40000; +unsigned int RELATION_ID = 1001; + + +char objectSuffix[MAX_PATH]; + +struct TestStats{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + +int GetParameters( int argc, char **argv) +{ + if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management event Test\n"); + printf("Usage:\n"); + printf("main\n\t[PROCESS_COUNT (greater than 1)] \n"); + printf("\t[THREAD_COUNT (greater than 1)] \n"); + printf("\t[REPEAT_COUNT (greater than 1)]\n"); + printf("\t[RELATION_ID [greater than 1]\n"); + printf("\t[Object Name Suffix]\n"); + return -1; + } + + PROCESS_COUNT = atoi(argv[1]); + if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + if(argc == 6) + { + strncpy(objectSuffix, argv[5], MAX_PATH-1); + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; + HANDLE hMutexHandle; + + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + + char ObjName[MAX_PATH] = "SHARED_MUTEX"; + char lpCommandLine[MAX_PATH] = ""; + + int returnCode = 0; + DWORD processReturnCode = 0; + int testReturnCode = PASS; + + char fileName[MAX_PATH]; + FILE *pFile = NULL; + DWORD dwStartTime; + struct TestStats testStats; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + ZeroMemory( objectSuffix, MAX_PATH ); + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + if(argc == 5) + { + strncat(ObjName, objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + testStats.relationId = RELATION_ID; + testStats.processCount = PROCESS_COUNT; + testStats.threadCount = THREAD_COUNT; + testStats.repeatCount = REPEAT_COUNT; + testStats.buildNumber = getBuildNumber(); + + + _snprintf(fileName, MAX_PATH, "main_mutex_%d_.txt", RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening main file for write\n"); + } + + hMutexHandle = CreateMutex( + NULL, + FALSE, /* bInitialOwner, owns initially */ + ObjName + ); + + if( hMutexHandle == NULL) + { + Fail("Unable to create Mutex handle for Main thread returned error [%d]\n", GetLastError()); + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( _snprintf( lpCommandLine, MAX_PATH-1, "mutex %d %d %d %d %s", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID, objectSuffix) < 0 ) + { + Fail ("Error Insufficient mutex name string length for %s for iteration [%d]\n", ObjName, i); + } + + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + //Create Process + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); + } + else + { + hProcess[i] = pi[i].hProcess; +// Trace("Process created for [%d]\n", i); + + } + } + + returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); + testReturnCode = FAIL; + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + testReturnCode = FAIL; + } + } + + testStats.operationTime = GetTimeDiff(dwStartTime); + fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber ); + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile\n"); + testReturnCode = FAIL; + } + + if(!CloseHandle(hMutexHandle)) + { + Trace("Error:%d: CloseHandle failed for hMutexHandle\n", GetLastError()); + testReturnCode = FAIL; + + } + + if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + } + else + { + Trace("Test Failed\n"); + } + + PAL_Terminate(); + return testReturnCode; +} + diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/shared/mutex.c b/src/pal/tests/palsuite/composite/object_management/mutex/shared/mutex.c deleted file mode 100644 index ec5d9b37ac..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/mutex/shared/mutex.c +++ /dev/null @@ -1,354 +0,0 @@ -// 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. - -/*============================================================ -** -** This test is for Object Management Test case for Mutex where Object type is shareable. -** -** Source Code: main.c and mutex.c -** main.c creates a mutex, creates processes and waits for all processes to get over -** mutex.c create threads which will contend for the mutex -** -** This test is for Object Management Test case for Mutex where Object type is not shareable. -** Algorithm -** o Main Process Creates OBJECT_TYPE Object -** o Create PROCESS_COUNT processes aware of the Shared Object -** -** Author: ShamitP -** -** -**============================================================ -*/ - -#include -#include "resultbuffer.h" -#include "resulttime.h" - -#define TIMEOUT 5000 -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; -unsigned int THREAD_COUNT = 0; -unsigned int REPEAT_COUNT = 0; -unsigned int RELATION_ID = 0; - - -/* Capture statistics at per thread basis */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - -struct ProcessStats{ - unsigned int processId; - DWORD operationTime; - unsigned int relationId; -}; - -HANDLE StartTestsEvHandle = NULL; -HANDLE hMutexHandle = NULL; - -/* Results Buffer */ -ResultBuffer *resultBuffer = NULL; - -int testStatus; - -const char sTmpEventName[MAX_PATH] = "StartTestEvent"; -char objectSuffix[MAX_PATH]; - -void PALAPI Run_Thread(LPVOID lpParam); - -int GetParameters( int argc, char **argv) -{ - if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management event Test\n"); - printf("Usage:\n"); - printf("main\n\t[USE_PROCESS_COUNT (greater than 1)] \n"); - printf("\t[THREAD_COUNT (greater than 1)] \n"); - printf("\t[REPEAT_COUNT (greater than 1)]\n"); - printf("\t[RELATION_ID [greater than 1]\n"); - printf("\t[Object Name Suffix]\n"); - - return -1; - } - - // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - if(argc == 6) - { - strncpy(objectSuffix, argv[5], MAX_PATH-1); - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; - DWORD threadId[MAXIMUM_WAIT_OBJECTS]; - - char ObjName[MAX_PATH] = "SHARED_MUTEX"; - DWORD dwParam = 0; - - int returnCode = 0; - - /* Variables to capture the file name and the file pointer*/ - char fileName[MAX_PATH]; - FILE *pFile = NULL; - struct statistics* buffer = NULL; - int statisticsSize = 0; - - /* Variables to capture the file name and the file pointer at process level*/ - char processFileName[MAX_PATH]; - FILE *pProcessFile = NULL; - struct ProcessStats processStats; - DWORD dwStartTime; - - testStatus = PASS; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - ZeroMemory( objectSuffix, MAX_PATH ); - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } -// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); - - if(argc == 5) - { - strncat(ObjName, objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - processStats.relationId = RELATION_ID; - processStats.processId = USE_PROCESS_COUNT; - - _snprintf(processFileName, MAX_PATH, "%d_process_mutex_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pProcessFile = fopen(processFileName, "w+"); - if(pProcessFile == NULL) - { - Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); - } statisticsSize = sizeof(struct statistics); - - _snprintf(fileName, MAX_PATH, "%d_thread_mutex_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); - } - // For each thread we will log operations failed (int), passed (int), total (int) - // and number of ticks (DWORD) for the operations - resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); - - /* Create StartTest Event */ - StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ - TRUE, /* bManualReset */ - FALSE, /* bInitialState */ - NULL); /* name of Event */ - - if( StartTestsEvHandle == NULL ) - { - Fail("Error:%d: Unexpected failure " - "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); - - } - - hMutexHandle = CreateMutex( - NULL, - FALSE, /* bInitialOwner, owns initially */ - ObjName - ); - - if( (hMutexHandle == NULL)|| (GetLastError() != ERROR_ALREADY_EXISTS)) - { - Fail("Unable to create Mutex handle for process id [%d], returned error [%d], expected ERROR_ALREADY_EXISTS\n", i, GetLastError()); - } - /* We already assume that the mutex was created previously*/ - - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - } - - if (!SetEvent(StartTestsEvHandle)) - { - Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - /* Test running */ - returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); - - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testStatus = FAIL; - } - - processStats.operationTime = GetTimeDiff(dwStartTime); - - /* Write to a file*/ - if(pFile!= NULL) - { - for( i = 0; i < THREAD_COUNT; i++ ) - { - buffer = (struct statistics *)resultBuffer->getResultBuffer(i); - returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); -// Trace("Iteration %d over\n", i); - - } - } - fclose(pFile); - - fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); - fclose(pProcessFile); - - /* Logging for the test case over, clean up the handles */ - -// Trace("Process Count %d over\n",USE_PROCESS_COUNT); - - for( i = 0; i < THREAD_COUNT; i++ ) - { - if(!CloseHandle(hThread[i]) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); - testStatus = FAIL; - } - } - - if(!CloseHandle(StartTestsEvHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - if(!CloseHandle(hMutexHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hMutexHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - PAL_Terminate(); - return testStatus; -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - unsigned int i = 0; - DWORD dwWaitResult; - - struct statistics stats; - DWORD dwStartTime; - - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - int Id=(int)lpParam; - - dwWaitResult = WaitForSingleObject( - StartTestsEvHandle, // handle to mutex - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { - Trace("Error while waiting for StartTest Event@ thread %d\n", Id); - testStatus = FAIL; - } - - dwStartTime = GetTickCount(); - - for( i = 0; i < REPEAT_COUNT; i++ ) - { - dwWaitResult = WaitForSingleObject( - hMutexHandle, // handle to mutex - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { -// Trace("Error while waiting for onject @ thread %d, # iter %d, Error Returned [%d]\n", Id, i, GetLastError()); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - testStatus = FAIL; - continue; - } - if (! ReleaseMutex(hMutexHandle)) - { - // Deal with error. -// Trace("Error while releasing mutex @ thread %d # iter %d\n", Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - // Probably need to have while true loop to attempt to release mutex... - testStatus = FAIL; - continue; - } - - stats.operationsTotal += 1; - stats.operationsPassed += 1; -// Trace("Successs while releasing mutex @ iteration %d -> thread %d -> Process count %d\n", i, Id, USE_PROCESS_COUNT); - - } - stats.operationTime = GetTimeDiff(dwStartTime); - if(resultBuffer->LogResult(Id, (char *)&stats)) - { - Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); - } -} diff --git a/src/pal/tests/palsuite/composite/object_management/mutex/shared/mutex.cpp b/src/pal/tests/palsuite/composite/object_management/mutex/shared/mutex.cpp new file mode 100644 index 0000000000..ec5d9b37ac --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/mutex/shared/mutex.cpp @@ -0,0 +1,354 @@ +// 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. + +/*============================================================ +** +** This test is for Object Management Test case for Mutex where Object type is shareable. +** +** Source Code: main.c and mutex.c +** main.c creates a mutex, creates processes and waits for all processes to get over +** mutex.c create threads which will contend for the mutex +** +** This test is for Object Management Test case for Mutex where Object type is not shareable. +** Algorithm +** o Main Process Creates OBJECT_TYPE Object +** o Create PROCESS_COUNT processes aware of the Shared Object +** +** Author: ShamitP +** +** +**============================================================ +*/ + +#include +#include "resultbuffer.h" +#include "resulttime.h" + +#define TIMEOUT 5000 +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; +unsigned int THREAD_COUNT = 0; +unsigned int REPEAT_COUNT = 0; +unsigned int RELATION_ID = 0; + + +/* Capture statistics at per thread basis */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + +struct ProcessStats{ + unsigned int processId; + DWORD operationTime; + unsigned int relationId; +}; + +HANDLE StartTestsEvHandle = NULL; +HANDLE hMutexHandle = NULL; + +/* Results Buffer */ +ResultBuffer *resultBuffer = NULL; + +int testStatus; + +const char sTmpEventName[MAX_PATH] = "StartTestEvent"; +char objectSuffix[MAX_PATH]; + +void PALAPI Run_Thread(LPVOID lpParam); + +int GetParameters( int argc, char **argv) +{ + if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management event Test\n"); + printf("Usage:\n"); + printf("main\n\t[USE_PROCESS_COUNT (greater than 1)] \n"); + printf("\t[THREAD_COUNT (greater than 1)] \n"); + printf("\t[REPEAT_COUNT (greater than 1)]\n"); + printf("\t[RELATION_ID [greater than 1]\n"); + printf("\t[Object Name Suffix]\n"); + + return -1; + } + + // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + if(argc == 6) + { + strncpy(objectSuffix, argv[5], MAX_PATH-1); + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; + DWORD threadId[MAXIMUM_WAIT_OBJECTS]; + + char ObjName[MAX_PATH] = "SHARED_MUTEX"; + DWORD dwParam = 0; + + int returnCode = 0; + + /* Variables to capture the file name and the file pointer*/ + char fileName[MAX_PATH]; + FILE *pFile = NULL; + struct statistics* buffer = NULL; + int statisticsSize = 0; + + /* Variables to capture the file name and the file pointer at process level*/ + char processFileName[MAX_PATH]; + FILE *pProcessFile = NULL; + struct ProcessStats processStats; + DWORD dwStartTime; + + testStatus = PASS; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + ZeroMemory( objectSuffix, MAX_PATH ); + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } +// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); + + if(argc == 5) + { + strncat(ObjName, objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + processStats.relationId = RELATION_ID; + processStats.processId = USE_PROCESS_COUNT; + + _snprintf(processFileName, MAX_PATH, "%d_process_mutex_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pProcessFile = fopen(processFileName, "w+"); + if(pProcessFile == NULL) + { + Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); + } statisticsSize = sizeof(struct statistics); + + _snprintf(fileName, MAX_PATH, "%d_thread_mutex_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); + } + // For each thread we will log operations failed (int), passed (int), total (int) + // and number of ticks (DWORD) for the operations + resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); + + /* Create StartTest Event */ + StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ + TRUE, /* bManualReset */ + FALSE, /* bInitialState */ + NULL); /* name of Event */ + + if( StartTestsEvHandle == NULL ) + { + Fail("Error:%d: Unexpected failure " + "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); + + } + + hMutexHandle = CreateMutex( + NULL, + FALSE, /* bInitialOwner, owns initially */ + ObjName + ); + + if( (hMutexHandle == NULL)|| (GetLastError() != ERROR_ALREADY_EXISTS)) + { + Fail("Unable to create Mutex handle for process id [%d], returned error [%d], expected ERROR_ALREADY_EXISTS\n", i, GetLastError()); + } + /* We already assume that the mutex was created previously*/ + + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + } + + if (!SetEvent(StartTestsEvHandle)) + { + Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + /* Test running */ + returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); + + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testStatus = FAIL; + } + + processStats.operationTime = GetTimeDiff(dwStartTime); + + /* Write to a file*/ + if(pFile!= NULL) + { + for( i = 0; i < THREAD_COUNT; i++ ) + { + buffer = (struct statistics *)resultBuffer->getResultBuffer(i); + returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); +// Trace("Iteration %d over\n", i); + + } + } + fclose(pFile); + + fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); + fclose(pProcessFile); + + /* Logging for the test case over, clean up the handles */ + +// Trace("Process Count %d over\n",USE_PROCESS_COUNT); + + for( i = 0; i < THREAD_COUNT; i++ ) + { + if(!CloseHandle(hThread[i]) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); + testStatus = FAIL; + } + } + + if(!CloseHandle(StartTestsEvHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + if(!CloseHandle(hMutexHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hMutexHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + PAL_Terminate(); + return testStatus; +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + unsigned int i = 0; + DWORD dwWaitResult; + + struct statistics stats; + DWORD dwStartTime; + + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + int Id=(int)lpParam; + + dwWaitResult = WaitForSingleObject( + StartTestsEvHandle, // handle to mutex + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { + Trace("Error while waiting for StartTest Event@ thread %d\n", Id); + testStatus = FAIL; + } + + dwStartTime = GetTickCount(); + + for( i = 0; i < REPEAT_COUNT; i++ ) + { + dwWaitResult = WaitForSingleObject( + hMutexHandle, // handle to mutex + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { +// Trace("Error while waiting for onject @ thread %d, # iter %d, Error Returned [%d]\n", Id, i, GetLastError()); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + testStatus = FAIL; + continue; + } + if (! ReleaseMutex(hMutexHandle)) + { + // Deal with error. +// Trace("Error while releasing mutex @ thread %d # iter %d\n", Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + // Probably need to have while true loop to attempt to release mutex... + testStatus = FAIL; + continue; + } + + stats.operationsTotal += 1; + stats.operationsPassed += 1; +// Trace("Successs while releasing mutex @ iteration %d -> thread %d -> Process count %d\n", i, Id, USE_PROCESS_COUNT); + + } + stats.operationTime = GetTimeDiff(dwStartTime); + if(resultBuffer->LogResult(Id, (char *)&stats)) + { + Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); + } +} diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/CMakeLists.txt b/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/CMakeLists.txt index 6efa228fbb..9ed4535d39 100644 --- a/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - main.c - semaphore.c + main.cpp + semaphore.cpp ) add_executable(paltest_semaphore_nonshared diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/main.c b/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/main.c deleted file mode 100644 index 854809c8f8..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/main.c +++ /dev/null @@ -1,228 +0,0 @@ -// 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 Code: main.c and semaphore.c -** main.c creates process and waits for all processes to get over -** semaphore.c creates a semaphore and then calls threads which will contend for the semaphore -** -** This test is for Object Management Test case for semaphore where Object type is not shareable. -** Algorithm -** o Create PROCESS_COUNT processes. -** o Main Thread of each process creates OBJECT_TYPE Object -** -** Author: ShamitP -** -** -**============================================================ -*/ - -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int PROCESS_COUNT = 2; -unsigned int THREAD_COUNT = 15; -unsigned int REPEAT_COUNT = 40000; -unsigned int RELATION_ID = 1001; - - - -struct TestStats{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; -}; - -int GetParameters( int argc, char **argv) -{ - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management Semaphore Test\n"); - printf("Usage:\n"); - printf("main\n\t[PROCESS_COUNT [greater than 1] \n"); - printf("\t[THREAD_COUNT [greater than 1] \n"); - printf("\t[REPEAT_COUNT [greater than 1]\n"); - printf("\t[RELATION_ID [greater than 1]\n"); - return -1; - } - - PROCESS_COUNT = atoi(argv[1]); - if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than or Equal to 1\n"); - return -1; - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; - HANDLE hSemaphoreHandle[MAXIMUM_WAIT_OBJECTS]; - - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - - const char *ObjName = "Semaphore"; - char lpCommandLine[MAX_PATH] = ""; - - int returnCode = 0; - DWORD processReturnCode = 0; - int testReturnCode = PASS; - - char fileName[MAX_PATH]; - FILE *pFile = NULL; - DWORD dwStartTime; - struct TestStats testStats; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - testStats.relationId = RELATION_ID; - testStats.processCount = PROCESS_COUNT; - testStats.threadCount = THREAD_COUNT; - testStats.repeatCount = REPEAT_COUNT; - testStats.buildNumber = getBuildNumber(); - - - _snprintf(fileName, MAX_PATH, "main_semaphore_%d_.txt", RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening main file for write\n"); - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_PATH-1, "semaphore %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) - { - Fail("Error Insufficient semaphore name string length for %s for iteration [%d]\n", ObjName, i); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - //Create Process - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); - } - else - { - hProcess[i] = pi[i].hProcess; -// Trace("Process created for [%d]\n", i); - - } - } - - returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); - testReturnCode = FAIL; - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - testReturnCode = FAIL; - } - } - - testStats.operationTime = GetTimeDiff(dwStartTime); - fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId,testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber ); - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile\n"); - testReturnCode = FAIL; - } - - if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - } - else - { - Trace("Test Failed\n"); - } - - PAL_Terminate(); - return testReturnCode; -} diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/main.cpp b/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/main.cpp new file mode 100644 index 0000000000..854809c8f8 --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/main.cpp @@ -0,0 +1,228 @@ +// 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 Code: main.c and semaphore.c +** main.c creates process and waits for all processes to get over +** semaphore.c creates a semaphore and then calls threads which will contend for the semaphore +** +** This test is for Object Management Test case for semaphore where Object type is not shareable. +** Algorithm +** o Create PROCESS_COUNT processes. +** o Main Thread of each process creates OBJECT_TYPE Object +** +** Author: ShamitP +** +** +**============================================================ +*/ + +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int PROCESS_COUNT = 2; +unsigned int THREAD_COUNT = 15; +unsigned int REPEAT_COUNT = 40000; +unsigned int RELATION_ID = 1001; + + + +struct TestStats{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; +}; + +int GetParameters( int argc, char **argv) +{ + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management Semaphore Test\n"); + printf("Usage:\n"); + printf("main\n\t[PROCESS_COUNT [greater than 1] \n"); + printf("\t[THREAD_COUNT [greater than 1] \n"); + printf("\t[REPEAT_COUNT [greater than 1]\n"); + printf("\t[RELATION_ID [greater than 1]\n"); + return -1; + } + + PROCESS_COUNT = atoi(argv[1]); + if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than or Equal to 1\n"); + return -1; + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; + HANDLE hSemaphoreHandle[MAXIMUM_WAIT_OBJECTS]; + + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + + const char *ObjName = "Semaphore"; + char lpCommandLine[MAX_PATH] = ""; + + int returnCode = 0; + DWORD processReturnCode = 0; + int testReturnCode = PASS; + + char fileName[MAX_PATH]; + FILE *pFile = NULL; + DWORD dwStartTime; + struct TestStats testStats; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + testStats.relationId = RELATION_ID; + testStats.processCount = PROCESS_COUNT; + testStats.threadCount = THREAD_COUNT; + testStats.repeatCount = REPEAT_COUNT; + testStats.buildNumber = getBuildNumber(); + + + _snprintf(fileName, MAX_PATH, "main_semaphore_%d_.txt", RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening main file for write\n"); + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( _snprintf( lpCommandLine, MAX_PATH-1, "semaphore %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) + { + Fail("Error Insufficient semaphore name string length for %s for iteration [%d]\n", ObjName, i); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + //Create Process + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); + } + else + { + hProcess[i] = pi[i].hProcess; +// Trace("Process created for [%d]\n", i); + + } + } + + returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); + testReturnCode = FAIL; + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + testReturnCode = FAIL; + } + } + + testStats.operationTime = GetTimeDiff(dwStartTime); + fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId,testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber ); + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile\n"); + testReturnCode = FAIL; + } + + if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + } + else + { + Trace("Test Failed\n"); + } + + PAL_Terminate(); + return testReturnCode; +} diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/semaphore.c b/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/semaphore.c deleted file mode 100644 index 0e487f2c17..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/semaphore.c +++ /dev/null @@ -1,342 +0,0 @@ -// 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 Code: main.c and semaphore.c -** main.c creates process and waits for all processes to get over -** semaphore.c creates a semaphore and then calls threads which will contend for the semaphore -** -** This test is for Object Management Test case for semaphore where Object type is not shareable. -** Algorithm -** o Create PROCESS_COUNT processes. -** o Main Thread of each process creates OBJECT_TYPE Object -** -** Author: ShamitP -** -** -**============================================================ -*/ - -#include -#include "resultbuffer.h" -#include "resulttime.h" - -#define TIMEOUT 5000 -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; -unsigned int THREAD_COUNT = 0; -unsigned int REPEAT_COUNT = 0; -unsigned int RELATION_ID = 0; - -/* Capture statistics at per thread basis */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - -struct ProcessStats{ - unsigned int processId; - DWORD operationTime; - unsigned int relationId; -}; - -/* Semaphore variables */ -unsigned long lInitialCount = 1; /* Signaled */ -unsigned long lMaximumCount = 1; /* Maximum value of 1 */ - -HANDLE StartTestsEvHandle = NULL; -HANDLE hSemaphoreHandle = NULL; - -/* Results Buffer */ -ResultBuffer *resultBuffer = NULL; - -int testStatus; - -const char sTmpEventName[MAX_PATH] = "StartTestEvent"; - -void PALAPI Run_Thread(LPVOID lpParam); - -int GetParameters( int argc, char **argv) -{ - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management Semaphore Test\n"); - printf("Usage:\n"); - printf("semaphore\n\t[USE_PROCESS_COUNT ( greater than 1] \n"); - printf("\t[THREAD_COUNT ( greater than 1] \n"); - printf("\t[REPEAT_COUNT ( greater than 1]\n"); - printf("\t[RELATION_ID [greater than 1]\n"); - return -1; - } - - // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than or Equal to 1\n"); - return -1; - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; - DWORD threadId[MAXIMUM_WAIT_OBJECTS]; - - const char *ObjName = "Semaphore"; - - DWORD dwParam = 0; - - int returnCode = 0; - - /* Variables to capture the file name and the file pointer at thread level*/ - char fileName[MAX_PATH]; - FILE *pFile = NULL; - struct statistics* buffer = NULL; - int statisticsSize = 0; - - /* Variables to capture the file name and the file pointer at process level*/ - char processFileName[MAX_PATH]; - FILE *pProcessFile = NULL; - struct ProcessStats processStats; - DWORD dwStartTime; - - testStatus = PASS; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - // Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); - - /* Register the start time */ - dwStartTime = GetTickCount(); - processStats.relationId = RELATION_ID; - processStats.processId = USE_PROCESS_COUNT; - - _snprintf(processFileName, MAX_PATH, "%d_process_semaphore_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pProcessFile = fopen(processFileName, "w+"); - if(pProcessFile == NULL) - { - Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); - } - - statisticsSize = sizeof(struct statistics); - - _snprintf(fileName, MAX_PATH, "%d_thread_semaphore_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); - } - // For each thread we will log operations failed (int), passed (int), total (int) - // and number of ticks (DWORD) for the operations - resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); - - StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ - TRUE, /* bManualReset */ - FALSE, /* bInitialState */ - NULL); /* name of Event */ - - if( StartTestsEvHandle == NULL ) - { - Fail("Error:%d: Unexpected failure " - "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); - - } - - /* Create StartTest Event */ - hSemaphoreHandle = CreateSemaphore( - NULL, /* lpSemaphoreAttributes */ - lInitialCount, /*lInitialCount*/ - lMaximumCount, /*lMaximumCount */ - NULL - ); - - if( hSemaphoreHandle == NULL) - { - Fail("Unable to create Semaphore handle for process id [%d], returned error [%d]\n", i, GetLastError()); - } - /* We already assume that the Semaphore was created previously*/ - - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - } - - if (!SetEvent(StartTestsEvHandle)) - { - Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - /* Test running */ - returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); - - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testStatus = FAIL; - } - - processStats.operationTime = GetTimeDiff(dwStartTime); - - /* Write to a file*/ - if(pFile!= NULL) - { - for( i = 0; i < THREAD_COUNT; i++ ) - { - buffer = (struct statistics *)resultBuffer->getResultBuffer(i); - returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); - //Trace("Iteration %d over\n", i); - - } - } - fclose(pFile); - /* Logging for the test case over, clean up the handles */ - -// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); - - for( i = 0; i < THREAD_COUNT; i++ ) - { - if(!CloseHandle(hThread[i]) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); - testStatus = FAIL; - } - } - - if(!CloseHandle(StartTestsEvHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - if(!CloseHandle(hSemaphoreHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hSemaphoreHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - PAL_Terminate(); - return PASS; -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - unsigned int i = 0; - DWORD dwWaitResult; - - int Id=(int)lpParam; - - struct statistics stats; - DWORD dwStartTime; - - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - dwWaitResult = WaitForSingleObject( - StartTestsEvHandle, // handle to start test handle - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { - Fail("Error while waiting for StartTest Event@ thread %d, RC is %d, Error is %d\n", Id, dwWaitResult, GetLastError()); - } - - dwStartTime = GetTickCount(); - - for( i = 0; i < REPEAT_COUNT; i++ ) - { - dwWaitResult = WaitForSingleObject( - hSemaphoreHandle, // handle to Semaphore - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { -// Trace("Error while waiting for onject @ thread %d, # iter %d, RC is %d, Error is %d\n", Id, i, dwWaitResult, GetLastError()); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - testStatus = FAIL; - continue; - } - if (! ReleaseSemaphore(hSemaphoreHandle, 1, NULL)) - { - // Deal with error. - // Trace("Error while releasing Semaphore @ thread %d # iter %d\n", Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - // Probably need to have while true loop to attempt to release semaphore... - testStatus = FAIL; - continue; - } - - stats.operationsTotal += 1; - stats.operationsPassed += 1; -// Trace("Successs while releasing Semaphore @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); - - } - - stats.operationTime = GetTimeDiff(dwStartTime); - if(resultBuffer->LogResult(Id, (char *)&stats)) - { - Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); - } - // Trace("Thread %d over for process %d\n", Id, USE_PROCESS_COUNT); -} diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/semaphore.cpp b/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/semaphore.cpp new file mode 100644 index 0000000000..0e487f2c17 --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/semaphore/nonshared/semaphore.cpp @@ -0,0 +1,342 @@ +// 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 Code: main.c and semaphore.c +** main.c creates process and waits for all processes to get over +** semaphore.c creates a semaphore and then calls threads which will contend for the semaphore +** +** This test is for Object Management Test case for semaphore where Object type is not shareable. +** Algorithm +** o Create PROCESS_COUNT processes. +** o Main Thread of each process creates OBJECT_TYPE Object +** +** Author: ShamitP +** +** +**============================================================ +*/ + +#include +#include "resultbuffer.h" +#include "resulttime.h" + +#define TIMEOUT 5000 +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; +unsigned int THREAD_COUNT = 0; +unsigned int REPEAT_COUNT = 0; +unsigned int RELATION_ID = 0; + +/* Capture statistics at per thread basis */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + +struct ProcessStats{ + unsigned int processId; + DWORD operationTime; + unsigned int relationId; +}; + +/* Semaphore variables */ +unsigned long lInitialCount = 1; /* Signaled */ +unsigned long lMaximumCount = 1; /* Maximum value of 1 */ + +HANDLE StartTestsEvHandle = NULL; +HANDLE hSemaphoreHandle = NULL; + +/* Results Buffer */ +ResultBuffer *resultBuffer = NULL; + +int testStatus; + +const char sTmpEventName[MAX_PATH] = "StartTestEvent"; + +void PALAPI Run_Thread(LPVOID lpParam); + +int GetParameters( int argc, char **argv) +{ + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management Semaphore Test\n"); + printf("Usage:\n"); + printf("semaphore\n\t[USE_PROCESS_COUNT ( greater than 1] \n"); + printf("\t[THREAD_COUNT ( greater than 1] \n"); + printf("\t[REPEAT_COUNT ( greater than 1]\n"); + printf("\t[RELATION_ID [greater than 1]\n"); + return -1; + } + + // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than or Equal to 1\n"); + return -1; + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; + DWORD threadId[MAXIMUM_WAIT_OBJECTS]; + + const char *ObjName = "Semaphore"; + + DWORD dwParam = 0; + + int returnCode = 0; + + /* Variables to capture the file name and the file pointer at thread level*/ + char fileName[MAX_PATH]; + FILE *pFile = NULL; + struct statistics* buffer = NULL; + int statisticsSize = 0; + + /* Variables to capture the file name and the file pointer at process level*/ + char processFileName[MAX_PATH]; + FILE *pProcessFile = NULL; + struct ProcessStats processStats; + DWORD dwStartTime; + + testStatus = PASS; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + // Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); + + /* Register the start time */ + dwStartTime = GetTickCount(); + processStats.relationId = RELATION_ID; + processStats.processId = USE_PROCESS_COUNT; + + _snprintf(processFileName, MAX_PATH, "%d_process_semaphore_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pProcessFile = fopen(processFileName, "w+"); + if(pProcessFile == NULL) + { + Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); + } + + statisticsSize = sizeof(struct statistics); + + _snprintf(fileName, MAX_PATH, "%d_thread_semaphore_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); + } + // For each thread we will log operations failed (int), passed (int), total (int) + // and number of ticks (DWORD) for the operations + resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); + + StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ + TRUE, /* bManualReset */ + FALSE, /* bInitialState */ + NULL); /* name of Event */ + + if( StartTestsEvHandle == NULL ) + { + Fail("Error:%d: Unexpected failure " + "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); + + } + + /* Create StartTest Event */ + hSemaphoreHandle = CreateSemaphore( + NULL, /* lpSemaphoreAttributes */ + lInitialCount, /*lInitialCount*/ + lMaximumCount, /*lMaximumCount */ + NULL + ); + + if( hSemaphoreHandle == NULL) + { + Fail("Unable to create Semaphore handle for process id [%d], returned error [%d]\n", i, GetLastError()); + } + /* We already assume that the Semaphore was created previously*/ + + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + } + + if (!SetEvent(StartTestsEvHandle)) + { + Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + /* Test running */ + returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); + + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testStatus = FAIL; + } + + processStats.operationTime = GetTimeDiff(dwStartTime); + + /* Write to a file*/ + if(pFile!= NULL) + { + for( i = 0; i < THREAD_COUNT; i++ ) + { + buffer = (struct statistics *)resultBuffer->getResultBuffer(i); + returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); + //Trace("Iteration %d over\n", i); + + } + } + fclose(pFile); + /* Logging for the test case over, clean up the handles */ + +// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); + + for( i = 0; i < THREAD_COUNT; i++ ) + { + if(!CloseHandle(hThread[i]) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); + testStatus = FAIL; + } + } + + if(!CloseHandle(StartTestsEvHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + if(!CloseHandle(hSemaphoreHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hSemaphoreHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + PAL_Terminate(); + return PASS; +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + unsigned int i = 0; + DWORD dwWaitResult; + + int Id=(int)lpParam; + + struct statistics stats; + DWORD dwStartTime; + + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + dwWaitResult = WaitForSingleObject( + StartTestsEvHandle, // handle to start test handle + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { + Fail("Error while waiting for StartTest Event@ thread %d, RC is %d, Error is %d\n", Id, dwWaitResult, GetLastError()); + } + + dwStartTime = GetTickCount(); + + for( i = 0; i < REPEAT_COUNT; i++ ) + { + dwWaitResult = WaitForSingleObject( + hSemaphoreHandle, // handle to Semaphore + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { +// Trace("Error while waiting for onject @ thread %d, # iter %d, RC is %d, Error is %d\n", Id, i, dwWaitResult, GetLastError()); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + testStatus = FAIL; + continue; + } + if (! ReleaseSemaphore(hSemaphoreHandle, 1, NULL)) + { + // Deal with error. + // Trace("Error while releasing Semaphore @ thread %d # iter %d\n", Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + // Probably need to have while true loop to attempt to release semaphore... + testStatus = FAIL; + continue; + } + + stats.operationsTotal += 1; + stats.operationsPassed += 1; +// Trace("Successs while releasing Semaphore @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); + + } + + stats.operationTime = GetTimeDiff(dwStartTime); + if(resultBuffer->LogResult(Id, (char *)&stats)) + { + Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); + } + // Trace("Thread %d over for process %d\n", Id, USE_PROCESS_COUNT); +} diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/shared/CMakeLists.txt b/src/pal/tests/palsuite/composite/object_management/semaphore/shared/CMakeLists.txt index 12d3ca867e..5c7f93290f 100644 --- a/src/pal/tests/palsuite/composite/object_management/semaphore/shared/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/object_management/semaphore/shared/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - main.c - semaphore.c + main.cpp + semaphore.cpp ) add_executable(paltest_semaphore_shared diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/shared/main.c b/src/pal/tests/palsuite/composite/object_management/semaphore/shared/main.c deleted file mode 100644 index deb8252b70..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/semaphore/shared/main.c +++ /dev/null @@ -1,278 +0,0 @@ -// 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 Code: main.c and semaphore.c -** main.c creates process and waits for all processes to get over -** semaphore.c creates a semaphore and then calls threads which will contend for the semaphore -** -** This test is for Object Management Test case for semaphore where Object type is shareable. -** Algorithm -** o Main Process Creates OBJECT_TYPE Object -** o Create PROCESS_COUNT processes aware of the Shared Object -** -** -** -**============================================================ -*/ - -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int PROCESS_COUNT = 1; -unsigned int THREAD_COUNT = 1; -unsigned int REPEAT_COUNT = 4; -unsigned int RELATION_ID = 1001; - - -unsigned long lInitialCount = 1; /* Signaled */ -unsigned long lMaximumCount = 1; /* Maximum value of 1 */ - -char objectSuffix[MAX_PATH]; - -struct TestStats{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - -int GetParameters( int argc, char **argv) -{ - if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management event Test\n"); - printf("Usage:\n"); - printf("main\n\t[PROCESS_COUNT (greater than 1)] \n"); - printf("\t[THREAD_COUNT (greater than 1)] \n"); - printf("\t[REPEAT_COUNT (greater than 1)]\n"); - printf("\t[RELATION_ID [greater than or equal to 1]\n"); - printf("\t[Object Name Suffix]\n"); - return -1; - } - - PROCESS_COUNT = atoi(argv[1]); - if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - - if(argc == 6) - { - strncpy(objectSuffix, argv[5], MAX_PATH-1); - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; - HANDLE hSemaphoreHandle; - - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - - char lpCommandLine[MAX_PATH] = ""; - char ObjName[MAX_PATH] = "SHARED_SEMAPHORE"; - - int returnCode = 0; - DWORD processReturnCode = 0; - int testReturnCode = PASS; - - char fileName[MAX_PATH]; - FILE *pFile = NULL; - DWORD dwStartTime; - struct TestStats testStats; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - -/* -"While the new PAL does support named semaphore it's unclear -if we should change the Windows PAL, since we share that w/ Rotor -and they are still using the old PAL. For the time being it may -make the most sense to just skip the named semaphore test on Windows -- from an object management perspective it doesn't really gain -us anything over what we already have." -*/ -#ifdef PLATFORM_UNIX - - ZeroMemory( objectSuffix, MAX_PATH ); - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - if(argc == 6) - { - strncat(ObjName, objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - testStats.relationId = RELATION_ID; - testStats.processCount = PROCESS_COUNT; - testStats.threadCount = THREAD_COUNT; - testStats.repeatCount = REPEAT_COUNT; - testStats.buildNumber = getBuildNumber(); - - _snprintf(fileName, MAX_PATH, "main_semaphore_%d_.txt", RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening main file for write\n"); - } - - hSemaphoreHandle = CreateSemaphore( - NULL, /* lpSemaphoreAttributes */ - lInitialCount, /*lInitialCount*/ - lMaximumCount, /*lMaximumCount */ - ObjName - ); - - if( hSemaphoreHandle == NULL) - { - Fail("Unable to create shared Semaphore handle @ Main returned error [%d]\n", GetLastError()); - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - - - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_PATH-1, "semaphore %d %d %d %d %s", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID, objectSuffix) < 0 ) - { - Fail("Error: Insufficient semaphore name string length for %s for iteration [%d]\n", ObjName, i); - } - - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); - } - else - { - hProcess[i] = pi[i].hProcess; -// Trace("Process created for [%d]\n", i); - - } - - } - - returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); - testReturnCode = FAIL; - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - testReturnCode = FAIL; - } - } - - testStats.operationTime = GetTimeDiff(dwStartTime); - fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile\n"); - testReturnCode = FAIL; - }; - - if(!CloseHandle(hSemaphoreHandle)) - { - Trace("Error:%d: CloseHandle failed for hSemaphoreHandle\n", GetLastError()); - testReturnCode = FAIL; - - } - - if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - } - else - { - Trace("Test Failed\n"); - } - -#endif //PLATFORM_UNIX - PAL_Terminate(); - return testReturnCode; -} diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/shared/main.cpp b/src/pal/tests/palsuite/composite/object_management/semaphore/shared/main.cpp new file mode 100644 index 0000000000..deb8252b70 --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/semaphore/shared/main.cpp @@ -0,0 +1,278 @@ +// 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 Code: main.c and semaphore.c +** main.c creates process and waits for all processes to get over +** semaphore.c creates a semaphore and then calls threads which will contend for the semaphore +** +** This test is for Object Management Test case for semaphore where Object type is shareable. +** Algorithm +** o Main Process Creates OBJECT_TYPE Object +** o Create PROCESS_COUNT processes aware of the Shared Object +** +** +** +**============================================================ +*/ + +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int PROCESS_COUNT = 1; +unsigned int THREAD_COUNT = 1; +unsigned int REPEAT_COUNT = 4; +unsigned int RELATION_ID = 1001; + + +unsigned long lInitialCount = 1; /* Signaled */ +unsigned long lMaximumCount = 1; /* Maximum value of 1 */ + +char objectSuffix[MAX_PATH]; + +struct TestStats{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + +int GetParameters( int argc, char **argv) +{ + if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management event Test\n"); + printf("Usage:\n"); + printf("main\n\t[PROCESS_COUNT (greater than 1)] \n"); + printf("\t[THREAD_COUNT (greater than 1)] \n"); + printf("\t[REPEAT_COUNT (greater than 1)]\n"); + printf("\t[RELATION_ID [greater than or equal to 1]\n"); + printf("\t[Object Name Suffix]\n"); + return -1; + } + + PROCESS_COUNT = atoi(argv[1]); + if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + + if(argc == 6) + { + strncpy(objectSuffix, argv[5], MAX_PATH-1); + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; + HANDLE hSemaphoreHandle; + + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + + char lpCommandLine[MAX_PATH] = ""; + char ObjName[MAX_PATH] = "SHARED_SEMAPHORE"; + + int returnCode = 0; + DWORD processReturnCode = 0; + int testReturnCode = PASS; + + char fileName[MAX_PATH]; + FILE *pFile = NULL; + DWORD dwStartTime; + struct TestStats testStats; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + +/* +"While the new PAL does support named semaphore it's unclear +if we should change the Windows PAL, since we share that w/ Rotor +and they are still using the old PAL. For the time being it may +make the most sense to just skip the named semaphore test on Windows +- from an object management perspective it doesn't really gain +us anything over what we already have." +*/ +#ifdef PLATFORM_UNIX + + ZeroMemory( objectSuffix, MAX_PATH ); + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + if(argc == 6) + { + strncat(ObjName, objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + testStats.relationId = RELATION_ID; + testStats.processCount = PROCESS_COUNT; + testStats.threadCount = THREAD_COUNT; + testStats.repeatCount = REPEAT_COUNT; + testStats.buildNumber = getBuildNumber(); + + _snprintf(fileName, MAX_PATH, "main_semaphore_%d_.txt", RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening main file for write\n"); + } + + hSemaphoreHandle = CreateSemaphore( + NULL, /* lpSemaphoreAttributes */ + lInitialCount, /*lInitialCount*/ + lMaximumCount, /*lMaximumCount */ + ObjName + ); + + if( hSemaphoreHandle == NULL) + { + Fail("Unable to create shared Semaphore handle @ Main returned error [%d]\n", GetLastError()); + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + + + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( _snprintf( lpCommandLine, MAX_PATH-1, "semaphore %d %d %d %d %s", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID, objectSuffix) < 0 ) + { + Fail("Error: Insufficient semaphore name string length for %s for iteration [%d]\n", ObjName, i); + } + + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); + } + else + { + hProcess[i] = pi[i].hProcess; +// Trace("Process created for [%d]\n", i); + + } + + } + + returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); + testReturnCode = FAIL; + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + testReturnCode = FAIL; + } + } + + testStats.operationTime = GetTimeDiff(dwStartTime); + fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile\n"); + testReturnCode = FAIL; + }; + + if(!CloseHandle(hSemaphoreHandle)) + { + Trace("Error:%d: CloseHandle failed for hSemaphoreHandle\n", GetLastError()); + testReturnCode = FAIL; + + } + + if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + } + else + { + Trace("Test Failed\n"); + } + +#endif //PLATFORM_UNIX + PAL_Terminate(); + return testReturnCode; +} diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/shared/semaphore.c b/src/pal/tests/palsuite/composite/object_management/semaphore/shared/semaphore.c deleted file mode 100644 index 5143c55143..0000000000 --- a/src/pal/tests/palsuite/composite/object_management/semaphore/shared/semaphore.c +++ /dev/null @@ -1,351 +0,0 @@ -// 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 Code: main.c and semaphore.c -** main.c creates process and waits for all processes to get over -** semaphore.c creates a semaphore and then calls threads which will contend for the semaphore -** -** This test is for Object Management Test case for semaphore where Object type is shareable. -** Algorithm -** o Main Process Creates OBJECT_TYPE Object -** o Create PROCESS_COUNT processes aware of the Shared Object -** -** -** -**============================================================ -*/ - -#include -#include "resultbuffer.h" -#include "resulttime.h" - -#define TIMEOUT 5000 -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; -unsigned int THREAD_COUNT = 0; -unsigned int REPEAT_COUNT = 0; -unsigned int RELATION_ID= 0; - -/* Capture statistics at per thread basis */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - -struct ProcessStats{ - unsigned int processId; - DWORD operationTime; - unsigned int relationId; -}; - -/* Semaphore variables */ -unsigned long lInitialCount = 1; /* Signaled */ -unsigned long lMaximumCount = 1; /* Maximum value of 1 */ - -HANDLE StartTestsEvHandle = NULL; -HANDLE hSemaphoreHandle = NULL; - -/* Results Buffer */ -ResultBuffer *resultBuffer = NULL; - -int testStatus; - -const char sTmpEventName[MAX_PATH] = "StartTestEvent"; -char objectSuffix[MAX_PATH]; - -void PALAPI Run_Thread(LPVOID lpParam); - -int GetParameters( int argc, char **argv) -{ - if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Object Management event Test\n"); - printf("Usage:\n"); - printf("main\n\t[PROCESS_COUNT (greater than 1)] \n"); - printf("\t[THREAD_COUNT (greater than 1)] \n"); - printf("\t[REPEAT_COUNT (greater than 1)]\n"); - printf("\t[RELATION_ID [greater than or equal to 1]\n"); - printf("\t[Object Name Suffix]\n"); - return -1; - } - - USE_PROCESS_COUNT = atoi(argv[1]); - if(USE_PROCESS_COUNT < 0) - { - printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 0 \n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - if(argc == 6) - { - strncpy(objectSuffix, argv[5], MAX_PATH-1); - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; - DWORD threadId[MAXIMUM_WAIT_OBJECTS]; - - char ObjName[MAX_PATH] = "SHARED_SEMAPHORE"; - DWORD dwParam = 0; - - int returnCode = 0; - - /* Variables to capture the file name and the file pointer at thread level*/ - char fileName[MAX_PATH]; - FILE *pFile = NULL; - struct statistics* buffer = NULL; - int statisticsSize = 0; - - /* Variables to capture the file name and the file pointer at process level*/ - char processFileName[MAX_PATH]; - FILE *pProcessFile = NULL; - struct ProcessStats processStats; - DWORD dwStartTime; - - testStatus = PASS; - - ZeroMemory( objectSuffix, MAX_PATH ); - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } -// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); - - if(argc == 6) - { - strncat(ObjName , objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - processStats.relationId = RELATION_ID; - processStats.processId = USE_PROCESS_COUNT; - - _snprintf(processFileName, MAX_PATH, "%d_process_semaphore_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pProcessFile = fopen(processFileName, "w+"); - if(pProcessFile == NULL) - { - Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); - } - - statisticsSize = sizeof(struct statistics); - - _snprintf(fileName, MAX_PATH, "%d_thread_semaphore_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); - } - // For each thread we will log operations failed (int), passed (int), total (int) - // and number of ticks (DWORD) for the operations - resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); - - /* Create Start Tests event */ - StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ - TRUE, /* bManualReset */ - FALSE, /* bInitialState */ - NULL); /* name of Event */ - - if( StartTestsEvHandle == NULL ) - { - Fail("Error:%d: Unexpected failure " - "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); - - } - - hSemaphoreHandle = CreateSemaphore( - NULL, /* lpSemaphoreAttributes */ - lInitialCount, /*lInitialCount*/ - lMaximumCount, /*lMaximumCount */ - ObjName - ); - - - if( (hSemaphoreHandle == NULL) || (GetLastError() != ERROR_ALREADY_EXISTS) ) - { - Fail("Unable to create Semaphore handle for process id [%d], returned error [%d], expected ERROR_ALREADY_EXISTS\n", i, GetLastError()); - } - - /* We already assume that the Semaphore was created previously*/ - - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - } - - if (!SetEvent(StartTestsEvHandle)) - { - Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - /* Test running */ - returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); - - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testStatus = FAIL; - } - - processStats.operationTime = GetTimeDiff(dwStartTime); - - /* Write to a file*/ - if(pFile!= NULL) - { - for( i = 0; i < THREAD_COUNT; i++ ) - { - buffer = (struct statistics *)resultBuffer->getResultBuffer(i); - returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); -// Trace("Iteration %d over\n", i); - - } - } - fclose(pFile); - /* Logging for the test case over, clean up the handles */ - -// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); - for( i = 0; i < THREAD_COUNT; i++ ) - { - if(!CloseHandle(hThread[i]) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); - testStatus = FAIL; - } - } - - if(!CloseHandle(StartTestsEvHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - if(!CloseHandle(hSemaphoreHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hSemaphoreHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - PAL_Terminate(); - return PASS; -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - unsigned int i = 0; - DWORD dwWaitResult; - - int Id=(int)lpParam; - - struct statistics stats; - DWORD dwStartTime; - - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - dwWaitResult = WaitForSingleObject( - StartTestsEvHandle, // handle to start test handle - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { - Fail("Error while waiting for StartTest Event@ thread %d, RC is %d, Error is %d\n", Id, dwWaitResult, GetLastError()); - } - - dwStartTime = GetTickCount(); - - for( i = 0; i < REPEAT_COUNT; i++ ) - { - dwWaitResult = WaitForSingleObject( - hSemaphoreHandle, // handle to Semaphore - TIMEOUT); - - if(dwWaitResult != WAIT_OBJECT_0) - { -// Trace("Error while waiting for onject @ thread %d, # iter %d, RC is %d, Error is %d\n", Id, i, dwWaitResult, GetLastError()); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - testStatus = FAIL; - continue; - } - if (! ReleaseSemaphore(hSemaphoreHandle, 1, NULL)) - { - // Deal with error. - // Trace("Error while releasing Semaphore @ thread %d # iter %d\n", Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - // Probably need to have while true loop to attempt to release semaphore.. - testStatus = FAIL; - continue; - } - - stats.operationsTotal += 1; - stats.operationsPassed += 1; -// Trace("Successs while releasing Semaphore @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); - - } - - stats.operationTime = GetTimeDiff(dwStartTime); - if(resultBuffer->LogResult(Id, (char *)&stats)) - { - Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); - } - // Trace("Thread %d over for process %d\n", Id, USE_PROCESS_COUNT); -} diff --git a/src/pal/tests/palsuite/composite/object_management/semaphore/shared/semaphore.cpp b/src/pal/tests/palsuite/composite/object_management/semaphore/shared/semaphore.cpp new file mode 100644 index 0000000000..5143c55143 --- /dev/null +++ b/src/pal/tests/palsuite/composite/object_management/semaphore/shared/semaphore.cpp @@ -0,0 +1,351 @@ +// 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 Code: main.c and semaphore.c +** main.c creates process and waits for all processes to get over +** semaphore.c creates a semaphore and then calls threads which will contend for the semaphore +** +** This test is for Object Management Test case for semaphore where Object type is shareable. +** Algorithm +** o Main Process Creates OBJECT_TYPE Object +** o Create PROCESS_COUNT processes aware of the Shared Object +** +** +** +**============================================================ +*/ + +#include +#include "resultbuffer.h" +#include "resulttime.h" + +#define TIMEOUT 5000 +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; +unsigned int THREAD_COUNT = 0; +unsigned int REPEAT_COUNT = 0; +unsigned int RELATION_ID= 0; + +/* Capture statistics at per thread basis */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + +struct ProcessStats{ + unsigned int processId; + DWORD operationTime; + unsigned int relationId; +}; + +/* Semaphore variables */ +unsigned long lInitialCount = 1; /* Signaled */ +unsigned long lMaximumCount = 1; /* Maximum value of 1 */ + +HANDLE StartTestsEvHandle = NULL; +HANDLE hSemaphoreHandle = NULL; + +/* Results Buffer */ +ResultBuffer *resultBuffer = NULL; + +int testStatus; + +const char sTmpEventName[MAX_PATH] = "StartTestEvent"; +char objectSuffix[MAX_PATH]; + +void PALAPI Run_Thread(LPVOID lpParam); + +int GetParameters( int argc, char **argv) +{ + if( (!((argc == 5) || (argc == 6) ) )|| ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Object Management event Test\n"); + printf("Usage:\n"); + printf("main\n\t[PROCESS_COUNT (greater than 1)] \n"); + printf("\t[THREAD_COUNT (greater than 1)] \n"); + printf("\t[REPEAT_COUNT (greater than 1)]\n"); + printf("\t[RELATION_ID [greater than or equal to 1]\n"); + printf("\t[Object Name Suffix]\n"); + return -1; + } + + USE_PROCESS_COUNT = atoi(argv[1]); + if(USE_PROCESS_COUNT < 0) + { + printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 0 \n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + if(argc == 6) + { + strncpy(objectSuffix, argv[5], MAX_PATH-1); + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; + DWORD threadId[MAXIMUM_WAIT_OBJECTS]; + + char ObjName[MAX_PATH] = "SHARED_SEMAPHORE"; + DWORD dwParam = 0; + + int returnCode = 0; + + /* Variables to capture the file name and the file pointer at thread level*/ + char fileName[MAX_PATH]; + FILE *pFile = NULL; + struct statistics* buffer = NULL; + int statisticsSize = 0; + + /* Variables to capture the file name and the file pointer at process level*/ + char processFileName[MAX_PATH]; + FILE *pProcessFile = NULL; + struct ProcessStats processStats; + DWORD dwStartTime; + + testStatus = PASS; + + ZeroMemory( objectSuffix, MAX_PATH ); + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } +// Trace("Process created, value of process count is [%d]\n", USE_PROCESS_COUNT); + + if(argc == 6) + { + strncat(ObjName , objectSuffix, MAX_PATH - (sizeof(ObjName) + 1) ); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + processStats.relationId = RELATION_ID; + processStats.processId = USE_PROCESS_COUNT; + + _snprintf(processFileName, MAX_PATH, "%d_process_semaphore_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pProcessFile = fopen(processFileName, "w+"); + if(pProcessFile == NULL) + { + Fail("Error in opening process File file for write for process [%d]\n", USE_PROCESS_COUNT); + } + + statisticsSize = sizeof(struct statistics); + + _snprintf(fileName, MAX_PATH, "%d_thread_semaphore_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); + } + // For each thread we will log operations failed (int), passed (int), total (int) + // and number of ticks (DWORD) for the operations + resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); + + /* Create Start Tests event */ + StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ + TRUE, /* bManualReset */ + FALSE, /* bInitialState */ + NULL); /* name of Event */ + + if( StartTestsEvHandle == NULL ) + { + Fail("Error:%d: Unexpected failure " + "to create %s Event for process count %d\n", GetLastError(), sTmpEventName, USE_PROCESS_COUNT ); + + } + + hSemaphoreHandle = CreateSemaphore( + NULL, /* lpSemaphoreAttributes */ + lInitialCount, /*lInitialCount*/ + lMaximumCount, /*lMaximumCount */ + ObjName + ); + + + if( (hSemaphoreHandle == NULL) || (GetLastError() != ERROR_ALREADY_EXISTS) ) + { + Fail("Unable to create Semaphore handle for process id [%d], returned error [%d], expected ERROR_ALREADY_EXISTS\n", i, GetLastError()); + } + + /* We already assume that the Semaphore was created previously*/ + + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + } + + if (!SetEvent(StartTestsEvHandle)) + { + Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + /* Test running */ + returnCode = WaitForMultipleObjects( THREAD_COUNT, hThread, TRUE, INFINITE); + + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testStatus = FAIL; + } + + processStats.operationTime = GetTimeDiff(dwStartTime); + + /* Write to a file*/ + if(pFile!= NULL) + { + for( i = 0; i < THREAD_COUNT; i++ ) + { + buffer = (struct statistics *)resultBuffer->getResultBuffer(i); + returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); +// Trace("Iteration %d over\n", i); + + } + } + fclose(pFile); + /* Logging for the test case over, clean up the handles */ + +// Trace("Test Thread %d done\n", USE_PROCESS_COUNT); + for( i = 0; i < THREAD_COUNT; i++ ) + { + if(!CloseHandle(hThread[i]) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); + testStatus = FAIL; + } + } + + if(!CloseHandle(StartTestsEvHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + if(!CloseHandle(hSemaphoreHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hSemaphoreHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + PAL_Terminate(); + return PASS; +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + unsigned int i = 0; + DWORD dwWaitResult; + + int Id=(int)lpParam; + + struct statistics stats; + DWORD dwStartTime; + + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + dwWaitResult = WaitForSingleObject( + StartTestsEvHandle, // handle to start test handle + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { + Fail("Error while waiting for StartTest Event@ thread %d, RC is %d, Error is %d\n", Id, dwWaitResult, GetLastError()); + } + + dwStartTime = GetTickCount(); + + for( i = 0; i < REPEAT_COUNT; i++ ) + { + dwWaitResult = WaitForSingleObject( + hSemaphoreHandle, // handle to Semaphore + TIMEOUT); + + if(dwWaitResult != WAIT_OBJECT_0) + { +// Trace("Error while waiting for onject @ thread %d, # iter %d, RC is %d, Error is %d\n", Id, i, dwWaitResult, GetLastError()); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + testStatus = FAIL; + continue; + } + if (! ReleaseSemaphore(hSemaphoreHandle, 1, NULL)) + { + // Deal with error. + // Trace("Error while releasing Semaphore @ thread %d # iter %d\n", Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + // Probably need to have while true loop to attempt to release semaphore.. + testStatus = FAIL; + continue; + } + + stats.operationsTotal += 1; + stats.operationsPassed += 1; +// Trace("Successs while releasing Semaphore @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); + + } + + stats.operationTime = GetTimeDiff(dwStartTime); + if(resultBuffer->LogResult(Id, (char *)&stats)) + { + Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); + } + // Trace("Thread %d over for process %d\n", Id, USE_PROCESS_COUNT); +} diff --git a/src/pal/tests/palsuite/composite/synchronization/criticalsection/CMakeLists.txt b/src/pal/tests/palsuite/composite/synchronization/criticalsection/CMakeLists.txt index 936c0fe82d..fc357ed258 100644 --- a/src/pal/tests/palsuite/composite/synchronization/criticalsection/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/synchronization/criticalsection/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - criticalsection.c - mainWrapper.c + criticalsection.cpp + mainWrapper.cpp ) add_executable(paltest_synchronization_criticalsection diff --git a/src/pal/tests/palsuite/composite/synchronization/criticalsection/criticalsection.c b/src/pal/tests/palsuite/composite/synchronization/criticalsection/criticalsection.c deleted file mode 100644 index 2fcd363e8a..0000000000 --- a/src/pal/tests/palsuite/composite/synchronization/criticalsection/criticalsection.c +++ /dev/null @@ -1,418 +0,0 @@ -// 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: criticalsection.c -** -** Purpose: Test Critical Section Reengineering PAL Effort -** -** PseudoCode: - Preparation: - Create PROCESS_COUNT processes. - In each process create a Critical Section - - Test: - Create THREAD_COUNT threads. - In a loop repeated REPEAT_COUNT times: - Enter Critical Section - Do Work - Leave Critical Section - The main thread waits for all of the created threads to exit (WFMO wait all on the created thread handles) and call DeleteCriticalSection - - Parameters: - PROCESS_COUNT: Number of processes - THREAD_COUNT: Number of threads in each process - REPEAT_COUNT: The number of times to execute the loop.. - - Statistics Captured: - Total elapsed time - MTBF - - Scenario: - Single Process with Multiple threads. Main thread creates critical section. - All other threads call EnterCriticalSection. When thread enters critical section - it does some work and leaves critical section. - -** Dependencies: - CreateThread -** InitializeCriticalSection -** EnterCriticalSection -** LeaveCriticalSection -** DeleteCriticalSection -** WaitForSingleObject -** -** Author: rameshg -** -** -**=========================================================*/ - -#include -#include "resultbuffer.h" - -//Global Variables -DWORD dwThreadId; -long long GLOBAL_COUNTER ; -HANDLE g_hEvent; - -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; -unsigned int THREAD_COUNT = 0; -unsigned int REPEAT_COUNT = 0; -unsigned int SLEEP_LENGTH = 0; -unsigned int RELATION_ID = 0; - - -CRITICAL_SECTION CriticalSectionM; /* Critical Section Object (used as mutex) */ - - -/* Capture statistics for each worker thread */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; //Milliseconds - unsigned int relationId; -}; - - -/*Capture Statistics at a Process level*/ -struct processStatistics{ - unsigned int processId; - DWORD operationTime; //Milliseconds - unsigned int relationId; -}; - - -ResultBuffer *resultBuffer; - -//function declarations -int GetParameters( int , char **); -void setup (void); -void cleanup(void); -void incrementCounter(void); -DWORD PALAPI enterandleavecs( LPVOID ); - - -/* -*Setup for the test case -*/ - -VOID -setup(VOID) -{ - -g_hEvent = CreateEvent(NULL,TRUE,FALSE, NULL); -if(g_hEvent == NULL) -{ - Fail("Create Event Failed\n" - "GetLastError returned %d\n", GetLastError()); -} - -GLOBAL_COUNTER=0; -/* -* Create mutual exclusion mechanisms -*/ -InitializeCriticalSection ( &CriticalSectionM ); - -} - - -/* -* Cleanup for the test case -*/ -VOID -cleanup(VOID) -{ - /* - * Clean up Critical Section object - */ - DeleteCriticalSection(&CriticalSectionM); - PAL_Terminate(); -} - - -/*function that increments a counter*/ -VOID -incrementCounter(VOID) -{ - - if (INT_MAX==GLOBAL_COUNTER) - GLOBAL_COUNTER=0; - - GLOBAL_COUNTER++; - -} - -/* - * Enter and Leave Critical Section - */ -DWORD -PALAPI -enterandleavecs( LPVOID lpParam ) -{ - - struct statistics stats; - int loopcount = REPEAT_COUNT; - int i; - DWORD dwStart =0; - - int Id=(int)lpParam; - - //initialize strucutre to hold thread level statistics - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - //Wait for main thread to signal event - if (WAIT_OBJECT_0 != WaitForSingleObject(g_hEvent,INFINITE)) - { - Fail ("readfile: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - //Collect operation start time - dwStart = GetTickCount(); - - //Operation starts loopcount times - for(i = 0; i < loopcount; i++) - { - - EnterCriticalSection(&CriticalSectionM); - /* - *Do Some Thing once you enter critical section - */ - incrementCounter(); - LeaveCriticalSection(&CriticalSectionM); - - stats.operationsPassed++; - stats.operationsTotal++; - } - //collect operation end time - stats.operationTime = GetTickCount() - dwStart; - - /*Trace("\n\n\n\nOperation Time %d\n", stats.operationTime); - Trace("Operation Passed %d\n", stats.operationsPassed); - Trace("Operation Total %d\n", stats.operationsTotal); - Trace("Operation Failed %d\n", stats.operationsFailed); */ - - if(resultBuffer->LogResult(Id, (char *)&stats)) - { - Fail("Error while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", Id, USE_PROCESS_COUNT); - } - - - return 0; -} - - -int __cdecl main (int argc, char **argv) -{ - -/* -* Parameter to the threads that will be created -*/ -DWORD dwThrdParam = 0; -HANDLE hThread[64]; -unsigned int i = 0; -DWORD dwStart; - -/* Variables to capture the file name and the file pointer*/ -char fileName[MAX_PATH_FNAME]; -char processFileName[MAX_PATH_FNAME]; -FILE *hFile,*hProcessFile; -struct processStatistics processStats; - -struct statistics* buffer; -int statisticsSize = 0; - -/* -* PAL Initialize -*/ -if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - -if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - -/*setup file for process result collection */ -_snprintf(processFileName, MAX_PATH_FNAME, "%d_process_criticalsection_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); -hProcessFile = fopen(processFileName, "w+"); -if(hProcessFile == NULL) - { - Fail("Error in opening file to write process results for process [%d]\n", USE_PROCESS_COUNT); - } - -//Initialize Process Stats Variables -processStats.operationTime = 0; -processStats.processId = USE_PROCESS_COUNT; -processStats.relationId = RELATION_ID; //Will change later - -//Start Process Time Capture -dwStart = GetTickCount(); - -//setup file for thread result collection -statisticsSize = sizeof(struct statistics); -_snprintf(fileName, MAX_PATH_FNAME, "%d_thread_criticalsection_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); -hFile = fopen(fileName, "w+"); -if(hFile == NULL) -{ - Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); -} - -// For each thread we will log operations failed (int), passed (int), total (int) -// and number of ticks (DWORD) for the operations -resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); - -/* -* Call the Setup Routine -*/ -setup(); - -//Create Thread Count Worker Threads - -while (i< THREAD_COUNT) -{ - dwThrdParam = i; - - hThread[i] = CreateThread( - NULL, - 0, - enterandleavecs, - (LPVOID)dwThrdParam, - 0, - &dwThreadId); - - if ( NULL == hThread[i] ) - { - Fail ( "CreateThread() returned NULL. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - i++; -} - -/* -* Set Event to signal all threads to start using the CS -*/ - -if (0==SetEvent(g_hEvent)) -{ - Fail ( "SetEvent returned Zero. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); -} - -/* - * Wait for worker threads to complete - * - */ -if ( WAIT_OBJECT_0 != WaitForMultipleObjects (THREAD_COUNT,hThread,TRUE, INFINITE)) -{ - Fail ( "WaitForMultipleObject Failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); -} - - -//Get the end time of the process -processStats.operationTime = GetTickCount() - dwStart; - -//Write Process Result Contents to File -if(hProcessFile!= NULL) - { - fprintf(hProcessFile, "%d,%lu,%d\n", processStats.processId, processStats.operationTime, processStats.relationId ); - } - -if (0!=fclose(hProcessFile)) -{ - Fail("Unable to write process results to file" - "GetLastError returned %d\n", GetLastError()); -} - - -/*Write Threads Results to a file*/ -if(hFile!= NULL) -{ - for( i = 0; i < THREAD_COUNT; i++ ) - { - buffer = (struct statistics *)resultBuffer->getResultBuffer(i); - fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); - //Trace("Iteration %d over\n", i); - } -} - -if (0!=fclose(hFile)) -{ - Fail("Unable to write thread results to file" - "GetLastError returned %d\n", GetLastError()); -} - - /* Logging for the test case over, clean up the handles */ - //Trace("Contents of the buffer are [%s]\n", resultBuffer->getResultBuffer()); - - -//Call Cleanup for Test Case -cleanup(); - -//Trace("Value of GLOBAL COUNTER %d \n", GLOBAL_COUNTER); -return (PASS); - -} - - -int GetParameters( int argc, char **argv) -{ - - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Critical Section Test\n"); - printf("Usage:\n"); - printf("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); - printf("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to 64 \n"); - printf("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); - printf("\t[RELATION_ID [Greater than or Equal to 1]\n"); - return -1; - } - -// Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nPROCESS_COUNT to greater than or equal to 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( THREAD_COUNT < 1 || THREAD_COUNT > 64) - { - printf("\nTHREAD_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nREPEAT_COUNT to greater than or equal to 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - return 0; -} - diff --git a/src/pal/tests/palsuite/composite/synchronization/criticalsection/criticalsection.cpp b/src/pal/tests/palsuite/composite/synchronization/criticalsection/criticalsection.cpp new file mode 100644 index 0000000000..2fcd363e8a --- /dev/null +++ b/src/pal/tests/palsuite/composite/synchronization/criticalsection/criticalsection.cpp @@ -0,0 +1,418 @@ +// 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: criticalsection.c +** +** Purpose: Test Critical Section Reengineering PAL Effort +** +** PseudoCode: + Preparation: + Create PROCESS_COUNT processes. + In each process create a Critical Section + + Test: + Create THREAD_COUNT threads. + In a loop repeated REPEAT_COUNT times: + Enter Critical Section + Do Work + Leave Critical Section + The main thread waits for all of the created threads to exit (WFMO wait all on the created thread handles) and call DeleteCriticalSection + + Parameters: + PROCESS_COUNT: Number of processes + THREAD_COUNT: Number of threads in each process + REPEAT_COUNT: The number of times to execute the loop.. + + Statistics Captured: + Total elapsed time + MTBF + + Scenario: + Single Process with Multiple threads. Main thread creates critical section. + All other threads call EnterCriticalSection. When thread enters critical section + it does some work and leaves critical section. + +** Dependencies: + CreateThread +** InitializeCriticalSection +** EnterCriticalSection +** LeaveCriticalSection +** DeleteCriticalSection +** WaitForSingleObject +** +** Author: rameshg +** +** +**=========================================================*/ + +#include +#include "resultbuffer.h" + +//Global Variables +DWORD dwThreadId; +long long GLOBAL_COUNTER ; +HANDLE g_hEvent; + +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; +unsigned int THREAD_COUNT = 0; +unsigned int REPEAT_COUNT = 0; +unsigned int SLEEP_LENGTH = 0; +unsigned int RELATION_ID = 0; + + +CRITICAL_SECTION CriticalSectionM; /* Critical Section Object (used as mutex) */ + + +/* Capture statistics for each worker thread */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; //Milliseconds + unsigned int relationId; +}; + + +/*Capture Statistics at a Process level*/ +struct processStatistics{ + unsigned int processId; + DWORD operationTime; //Milliseconds + unsigned int relationId; +}; + + +ResultBuffer *resultBuffer; + +//function declarations +int GetParameters( int , char **); +void setup (void); +void cleanup(void); +void incrementCounter(void); +DWORD PALAPI enterandleavecs( LPVOID ); + + +/* +*Setup for the test case +*/ + +VOID +setup(VOID) +{ + +g_hEvent = CreateEvent(NULL,TRUE,FALSE, NULL); +if(g_hEvent == NULL) +{ + Fail("Create Event Failed\n" + "GetLastError returned %d\n", GetLastError()); +} + +GLOBAL_COUNTER=0; +/* +* Create mutual exclusion mechanisms +*/ +InitializeCriticalSection ( &CriticalSectionM ); + +} + + +/* +* Cleanup for the test case +*/ +VOID +cleanup(VOID) +{ + /* + * Clean up Critical Section object + */ + DeleteCriticalSection(&CriticalSectionM); + PAL_Terminate(); +} + + +/*function that increments a counter*/ +VOID +incrementCounter(VOID) +{ + + if (INT_MAX==GLOBAL_COUNTER) + GLOBAL_COUNTER=0; + + GLOBAL_COUNTER++; + +} + +/* + * Enter and Leave Critical Section + */ +DWORD +PALAPI +enterandleavecs( LPVOID lpParam ) +{ + + struct statistics stats; + int loopcount = REPEAT_COUNT; + int i; + DWORD dwStart =0; + + int Id=(int)lpParam; + + //initialize strucutre to hold thread level statistics + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + //Wait for main thread to signal event + if (WAIT_OBJECT_0 != WaitForSingleObject(g_hEvent,INFINITE)) + { + Fail ("readfile: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + //Collect operation start time + dwStart = GetTickCount(); + + //Operation starts loopcount times + for(i = 0; i < loopcount; i++) + { + + EnterCriticalSection(&CriticalSectionM); + /* + *Do Some Thing once you enter critical section + */ + incrementCounter(); + LeaveCriticalSection(&CriticalSectionM); + + stats.operationsPassed++; + stats.operationsTotal++; + } + //collect operation end time + stats.operationTime = GetTickCount() - dwStart; + + /*Trace("\n\n\n\nOperation Time %d\n", stats.operationTime); + Trace("Operation Passed %d\n", stats.operationsPassed); + Trace("Operation Total %d\n", stats.operationsTotal); + Trace("Operation Failed %d\n", stats.operationsFailed); */ + + if(resultBuffer->LogResult(Id, (char *)&stats)) + { + Fail("Error while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", Id, USE_PROCESS_COUNT); + } + + + return 0; +} + + +int __cdecl main (int argc, char **argv) +{ + +/* +* Parameter to the threads that will be created +*/ +DWORD dwThrdParam = 0; +HANDLE hThread[64]; +unsigned int i = 0; +DWORD dwStart; + +/* Variables to capture the file name and the file pointer*/ +char fileName[MAX_PATH_FNAME]; +char processFileName[MAX_PATH_FNAME]; +FILE *hFile,*hProcessFile; +struct processStatistics processStats; + +struct statistics* buffer; +int statisticsSize = 0; + +/* +* PAL Initialize +*/ +if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + +if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + +/*setup file for process result collection */ +_snprintf(processFileName, MAX_PATH_FNAME, "%d_process_criticalsection_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); +hProcessFile = fopen(processFileName, "w+"); +if(hProcessFile == NULL) + { + Fail("Error in opening file to write process results for process [%d]\n", USE_PROCESS_COUNT); + } + +//Initialize Process Stats Variables +processStats.operationTime = 0; +processStats.processId = USE_PROCESS_COUNT; +processStats.relationId = RELATION_ID; //Will change later + +//Start Process Time Capture +dwStart = GetTickCount(); + +//setup file for thread result collection +statisticsSize = sizeof(struct statistics); +_snprintf(fileName, MAX_PATH_FNAME, "%d_thread_criticalsection_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); +hFile = fopen(fileName, "w+"); +if(hFile == NULL) +{ + Fail("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT); +} + +// For each thread we will log operations failed (int), passed (int), total (int) +// and number of ticks (DWORD) for the operations +resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); + +/* +* Call the Setup Routine +*/ +setup(); + +//Create Thread Count Worker Threads + +while (i< THREAD_COUNT) +{ + dwThrdParam = i; + + hThread[i] = CreateThread( + NULL, + 0, + enterandleavecs, + (LPVOID)dwThrdParam, + 0, + &dwThreadId); + + if ( NULL == hThread[i] ) + { + Fail ( "CreateThread() returned NULL. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + i++; +} + +/* +* Set Event to signal all threads to start using the CS +*/ + +if (0==SetEvent(g_hEvent)) +{ + Fail ( "SetEvent returned Zero. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); +} + +/* + * Wait for worker threads to complete + * + */ +if ( WAIT_OBJECT_0 != WaitForMultipleObjects (THREAD_COUNT,hThread,TRUE, INFINITE)) +{ + Fail ( "WaitForMultipleObject Failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); +} + + +//Get the end time of the process +processStats.operationTime = GetTickCount() - dwStart; + +//Write Process Result Contents to File +if(hProcessFile!= NULL) + { + fprintf(hProcessFile, "%d,%lu,%d\n", processStats.processId, processStats.operationTime, processStats.relationId ); + } + +if (0!=fclose(hProcessFile)) +{ + Fail("Unable to write process results to file" + "GetLastError returned %d\n", GetLastError()); +} + + +/*Write Threads Results to a file*/ +if(hFile!= NULL) +{ + for( i = 0; i < THREAD_COUNT; i++ ) + { + buffer = (struct statistics *)resultBuffer->getResultBuffer(i); + fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); + //Trace("Iteration %d over\n", i); + } +} + +if (0!=fclose(hFile)) +{ + Fail("Unable to write thread results to file" + "GetLastError returned %d\n", GetLastError()); +} + + /* Logging for the test case over, clean up the handles */ + //Trace("Contents of the buffer are [%s]\n", resultBuffer->getResultBuffer()); + + +//Call Cleanup for Test Case +cleanup(); + +//Trace("Value of GLOBAL COUNTER %d \n", GLOBAL_COUNTER); +return (PASS); + +} + + +int GetParameters( int argc, char **argv) +{ + + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Critical Section Test\n"); + printf("Usage:\n"); + printf("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); + printf("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to 64 \n"); + printf("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); + printf("\t[RELATION_ID [Greater than or Equal to 1]\n"); + return -1; + } + +// Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nPROCESS_COUNT to greater than or equal to 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( THREAD_COUNT < 1 || THREAD_COUNT > 64) + { + printf("\nTHREAD_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nREPEAT_COUNT to greater than or equal to 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + return 0; +} + diff --git a/src/pal/tests/palsuite/composite/synchronization/criticalsection/mainWrapper.c b/src/pal/tests/palsuite/composite/synchronization/criticalsection/mainWrapper.c deleted file mode 100644 index 4bc2f3d834..0000000000 --- a/src/pal/tests/palsuite/composite/synchronization/criticalsection/mainWrapper.c +++ /dev/null @@ -1,255 +0,0 @@ -// 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 Code: mainWrapper.c - -mainWrapper.c creates Composite Test Case Processes and waits for all processes to get over - -Algorithm -o Create PROCESS_COUNT processes. - -Author: RameshG -*/ - -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; //default -unsigned int THREAD_COUNT = 0; //default -unsigned int REPEAT_COUNT = 0; //default -unsigned int SLEEP_LENGTH = 0; //default -unsigned int RELATION_ID = 1001; - - -//Strucuture to capture application wide statistics -struct applicationStatistics{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - - -//Get parameters from the commandline -int GetParameters( int argc, char **argv) -{ - - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("Main Wrapper PAL -Composite Critical Section Test\n"); - printf("Usage:\n"); - printf("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); - printf("\t[THREAD_COUNT] Greater than or Equal to 1 and Less than or Equal to 64 \n"); - printf("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); - printf("\t[RELATION_ID [Greater than or Equal to 1]\n"); - - return -1; - } - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nPROCESS_COUNT to greater than or equal to 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( THREAD_COUNT < 1 || THREAD_COUNT > 64) - { - printf("\nTHREAD_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nREPEAT_COUNT to greater than or equal to 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - - - - return 0; -} - -//Main entry point for the application - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; //Array to hold Process handles - DWORD processReturnCode = 0; - int testReturnCode = PASS; - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - FILE *hFile; //handle to application results file - char fileName[MAX_PATH]; //file name of the application results file - struct applicationStatistics appStats; - DWORD dwStart=0; //to store the tick count - char lpCommandLine[MAX_PATH] = ""; - int returnCode = 0; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - - - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - //Initialize Application Statistics Strucuture - appStats.operationTime=0; - appStats.relationId = RELATION_ID; - appStats.processCount = USE_PROCESS_COUNT; - appStats.threadCount = THREAD_COUNT; - appStats.repeatCount = REPEAT_COUNT; - appStats.buildNumber = getBuildNumber(); - - -_snprintf(fileName, MAX_PATH, "main_criticalsection_%d_.txt", RELATION_ID); - -hFile = fopen(fileName, "w+"); - -if(hFile == NULL) - { - Fail("Error in opening file to write application results for Critical Section Test, and error code is %d\n", GetLastError()); - } - -//Start Process Time Capture -dwStart = GetTickCount(); - -for( i = 0; i < USE_PROCESS_COUNT; i++ ) - { - - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_PATH-1, "criticalsection %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) - { - Trace ("Error: Insufficient commandline string length for for iteration [%d]\n", i); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - //Printing the Command Line - //Trace("Command Line \t %s \n", lpCommandLine); - - //Create Process - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d] and failed with error code %d\n", i, GetLastError()); - } - else - { - hProcess[i] = pi[i].hProcess; - //Trace("Process created for [%d]\n", i); - } - - } - - returnCode = WaitForMultipleObjects( USE_PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testReturnCode = FAIL; - } - - for( i = 0; i < USE_PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - testReturnCode = FAIL; - } - } - -//Get the end time of the process -appStats.operationTime = GetTickCount() - dwStart; - -if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - - } - else - { - Fail("Test Failed\n"); - - } - -//Write Process Result Contents to File -if(hFile!= NULL) - { - fprintf(hFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId,appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); - } - -if (0!=fclose(hFile)) -{ - Trace("Error:%d: fclose failed for file %s\n", GetLastError(), fileName); -} - - PAL_Terminate(); - -if( testReturnCode == PASS) -{ - return PASS; -} -else -{ - return FAIL; -} - -} diff --git a/src/pal/tests/palsuite/composite/synchronization/criticalsection/mainWrapper.cpp b/src/pal/tests/palsuite/composite/synchronization/criticalsection/mainWrapper.cpp new file mode 100644 index 0000000000..4bc2f3d834 --- /dev/null +++ b/src/pal/tests/palsuite/composite/synchronization/criticalsection/mainWrapper.cpp @@ -0,0 +1,255 @@ +// 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 Code: mainWrapper.c + +mainWrapper.c creates Composite Test Case Processes and waits for all processes to get over + +Algorithm +o Create PROCESS_COUNT processes. + +Author: RameshG +*/ + +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; //default +unsigned int THREAD_COUNT = 0; //default +unsigned int REPEAT_COUNT = 0; //default +unsigned int SLEEP_LENGTH = 0; //default +unsigned int RELATION_ID = 1001; + + +//Strucuture to capture application wide statistics +struct applicationStatistics{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + + +//Get parameters from the commandline +int GetParameters( int argc, char **argv) +{ + + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("Main Wrapper PAL -Composite Critical Section Test\n"); + printf("Usage:\n"); + printf("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); + printf("\t[THREAD_COUNT] Greater than or Equal to 1 and Less than or Equal to 64 \n"); + printf("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); + printf("\t[RELATION_ID [Greater than or Equal to 1]\n"); + + return -1; + } + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nPROCESS_COUNT to greater than or equal to 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( THREAD_COUNT < 1 || THREAD_COUNT > 64) + { + printf("\nTHREAD_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nREPEAT_COUNT to greater than or equal to 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + + + + return 0; +} + +//Main entry point for the application + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; //Array to hold Process handles + DWORD processReturnCode = 0; + int testReturnCode = PASS; + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + FILE *hFile; //handle to application results file + char fileName[MAX_PATH]; //file name of the application results file + struct applicationStatistics appStats; + DWORD dwStart=0; //to store the tick count + char lpCommandLine[MAX_PATH] = ""; + int returnCode = 0; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + + + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + //Initialize Application Statistics Strucuture + appStats.operationTime=0; + appStats.relationId = RELATION_ID; + appStats.processCount = USE_PROCESS_COUNT; + appStats.threadCount = THREAD_COUNT; + appStats.repeatCount = REPEAT_COUNT; + appStats.buildNumber = getBuildNumber(); + + +_snprintf(fileName, MAX_PATH, "main_criticalsection_%d_.txt", RELATION_ID); + +hFile = fopen(fileName, "w+"); + +if(hFile == NULL) + { + Fail("Error in opening file to write application results for Critical Section Test, and error code is %d\n", GetLastError()); + } + +//Start Process Time Capture +dwStart = GetTickCount(); + +for( i = 0; i < USE_PROCESS_COUNT; i++ ) + { + + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( _snprintf( lpCommandLine, MAX_PATH-1, "criticalsection %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) + { + Trace ("Error: Insufficient commandline string length for for iteration [%d]\n", i); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + //Printing the Command Line + //Trace("Command Line \t %s \n", lpCommandLine); + + //Create Process + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d] and failed with error code %d\n", i, GetLastError()); + } + else + { + hProcess[i] = pi[i].hProcess; + //Trace("Process created for [%d]\n", i); + } + + } + + returnCode = WaitForMultipleObjects( USE_PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testReturnCode = FAIL; + } + + for( i = 0; i < USE_PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + testReturnCode = FAIL; + } + } + +//Get the end time of the process +appStats.operationTime = GetTickCount() - dwStart; + +if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + + } + else + { + Fail("Test Failed\n"); + + } + +//Write Process Result Contents to File +if(hFile!= NULL) + { + fprintf(hFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId,appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); + } + +if (0!=fclose(hFile)) +{ + Trace("Error:%d: fclose failed for file %s\n", GetLastError(), fileName); +} + + PAL_Terminate(); + +if( testReturnCode == PASS) +{ + return PASS; +} +else +{ + return FAIL; +} + +} diff --git a/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/CMakeLists.txt b/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/CMakeLists.txt index d01b1064f6..9a02993916 100644 --- a/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES mtx_critsect.cpp - pal_composite_native_cs.c + pal_composite_native_cs.cpp resultbuffer.cpp ) diff --git a/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/pal_composite_native_cs.c b/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/pal_composite_native_cs.c deleted file mode 100644 index 40efacd7c9..0000000000 --- a/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/pal_composite_native_cs.c +++ /dev/null @@ -1,471 +0,0 @@ -// 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. - -#include -#include -#include -#include -#include -//#include -#include "mtx_critsect.cpp" -//#include "mtx_critsect.h" -#include "resultbuffer.h" - - - -#define LONGLONG long long -#define ULONGLONG unsigned LONGLONG -/*Defining Global Variables*/ - -int THREAD_COUNT=0; -int REPEAT_COUNT=0; -int GLOBAL_COUNTER=0; -int USE_PROCESS_COUNT = 0; -int RELATION_ID =0; -int g_counter = 0; -int MAX_PATH = 256; -LONGLONG callibrationValue = 0; - -pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t g_cv = PTHREAD_COND_INITIALIZER; -pthread_cond_t g_cv2 = PTHREAD_COND_INITIALIZER; -CRITICAL_SECTION g_cs; - -/* Capture statistics for each worker thread */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - - -struct applicationStatistics{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - -ResultBuffer *resultBuffer; - - -void* waitforworkerthreads(void*); -void starttests(int); -int setuptest(void); -int cleanuptest(void); -int GetParameters( int , char **); -void incrementCounter(void); -ULONGLONG GetTicks(void); -ULONGLONG getPerfCallibrationValue(void); - - - -extern int main(int argc, char **argv) - { - //Variable Declaration - pthread_t pthreads[640]; - int threadID[640]; - int i=0; - int j=0; - int rtn=0; - ULONGLONG startTicks = 0; - - /* Variables to capture the file name and the file pointer*/ - char fileName[MAX_PATH]; - FILE *hFile; - struct statistics* buffer; - int statisticsSize = 0; - - /*Variable to Captutre Information at the Application Level*/ - struct applicationStatistics appStats; - char mainFileName[MAX_PATH]; - FILE *hMainFile; - - //Get perfCallibrationValue - - callibrationValue = getPerfCallibrationValue(); - printf("Callibration Value for this Platform %llu \n", callibrationValue); - - - //Get Parameters - if(GetParameters(argc, argv)) - { - printf("Error in obtaining the parameters\n"); - exit(-1); - } - - //Assign Values to Application Statistics Members - appStats.relationId=RELATION_ID; - appStats.operationTime=0; - appStats.buildNumber = "999.99"; - appStats.processCount = USE_PROCESS_COUNT; - appStats.threadCount = THREAD_COUNT; - appStats.repeatCount = REPEAT_COUNT; - - printf("RELATION ID : %d\n", appStats.relationId); - printf("Process Count : %d\n", appStats.processCount); - printf("Thread Count : %d\n", appStats.threadCount); - printf("Repeat Count : %d\n", appStats.repeatCount); - - - //Open file for Application Statistics Collection - snprintf(mainFileName, MAX_PATH, "main_nativecriticalsection_%d_.txt",appStats.relationId); - hMainFile = fopen(mainFileName, "w+"); - - if(hMainFile == NULL) - { - printf("Error in opening main file for write\n"); - } - - - for (i=0;igetResultBuffer(i); - fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); - //printf("Iteration %d over\n", i); - } - } - fclose(hFile); - - - - //Call Test Case Cleanup Routine - if (0!=cleanuptest()) - { - //Error Condition - printf("Error Cleaning up Test Case"); - exit(-1); - } - - - if(hMainFile!= NULL) - { - printf("Writing to Main File \n"); - fprintf(hMainFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId, appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); - - } - fclose(hMainFile); - return 0; - } - -void * waitforworkerthreads(void * threadId) -{ - - int *threadParam = (int*) threadId; - -// printf("Thread ID : %d \n", *threadParam); - - //Accquire Lock - if (0!=pthread_mutex_lock(&g_mutex)) - { - //Error Condition - printf("Error Accquiring Mutex Lock in Wait for Worker Thread\n"); - exit(-1); - } - - //Increment Global Counter - GLOBAL_COUNTER++; - - - //If global counter is equal to thread count then signal main thread - if (GLOBAL_COUNTER == THREAD_COUNT) - { - if (0!=pthread_cond_signal(&g_cv2)) - { - //Error Condition - printf("Error in setting conditional variable\n"); - exit(-1); - } - } - - //Wait for main thread to signal - if (0!=pthread_cond_wait(&g_cv,&g_mutex)) - { - //Error Condition - printf("Error waiting on conditional variable in Worker Thread\n"); - exit(-1); - } - - //Release the mutex lock - if (0!=pthread_mutex_unlock(&g_mutex)) - { - //Error Condition - printf("Error Releasing Mutex Lock in Worker Thread\n"); - exit(-1); - } - - //Start the test - starttests(*threadParam); - -} - -void starttests(int threadID) -{ - /*All threads beign executing tests cases*/ - int i = 0; - int Id = threadID; - struct statistics stats; - ULONGLONG startTime = 0; - ULONGLONG endTime = 0; - - - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - //Enter and Leave Critical Section in a loop REPEAT_COUNT Times - - startTime = GetTicks(); - - for (i=0;iLogResult(Id, (char *)&stats)) - { - printf("Error while writing to shared memory, Thread Id is[??] and Process id is [%d]\n", USE_PROCESS_COUNT); - } - -} - -int setuptest(void) -{ - - //Initalize Critical Section - if (0!=MTXInitializeCriticalSection( &g_cs)) - { - return -1; - } - return 0; -} - -int cleanuptest(void) -{ - - //Delete Critical Section - if (0!=MTXDeleteCriticalSection(&g_cs)) - { - return -1; - } - return 0; -} - -int GetParameters( int argc, char **argv) -{ - - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Native Critical Section Test\n"); - printf("Usage:\n"); - printf("\t[PROCESS_ID ( greater than 1] \n"); - printf("\t[THREAD_COUNT ( greater than 1] \n"); - printf("\t[REPEAT_COUNT ( greater than 1]\n"); - printf("\t[RELATION_ID [greater than or Equal to 1]\n"); - return -1; - } - - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( THREAD_COUNT < 1) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1\n"); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nInvalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - - return 0; -} - -void incrementCounter(void) -{ - g_counter ++; -} - - -//Implementation borrowed from pertrace.c -ULONGLONG GetTicks(void) -{ -#ifdef i386 - unsigned long a, d; - asm volatile("rdtsc":"=a" (a), "=d" (d)); - return ((ULONGLONG)((unsigned int)(d)) << 32) | (unsigned int)(a); -#else -#if defined(__sparc__) || (defined (_HPUX_) && defined(__ia64__)) - return (ULONGLONG)gethrtime(); -#else - // #error Don''t know how to get ticks on this platform - return (ULONGLONG)gethrtime(); -#endif // __sparc__ -#endif // _X86_ -} - - -/**/ -ULONGLONG getPerfCallibrationValue(void) -{ - ULONGLONG startTicks; - ULONGLONG endTicks; - - startTicks = GetTicks(); - sleep(1); - endTicks = GetTicks(); - - return ((endTicks-startTicks)/1000); //Return number of Ticks in One Milliseconds - -} - diff --git a/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/pal_composite_native_cs.cpp b/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/pal_composite_native_cs.cpp new file mode 100644 index 0000000000..40efacd7c9 --- /dev/null +++ b/src/pal/tests/palsuite/composite/synchronization/nativecriticalsection/pal_composite_native_cs.cpp @@ -0,0 +1,471 @@ +// 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. + +#include +#include +#include +#include +#include +//#include +#include "mtx_critsect.cpp" +//#include "mtx_critsect.h" +#include "resultbuffer.h" + + + +#define LONGLONG long long +#define ULONGLONG unsigned LONGLONG +/*Defining Global Variables*/ + +int THREAD_COUNT=0; +int REPEAT_COUNT=0; +int GLOBAL_COUNTER=0; +int USE_PROCESS_COUNT = 0; +int RELATION_ID =0; +int g_counter = 0; +int MAX_PATH = 256; +LONGLONG callibrationValue = 0; + +pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t g_cv = PTHREAD_COND_INITIALIZER; +pthread_cond_t g_cv2 = PTHREAD_COND_INITIALIZER; +CRITICAL_SECTION g_cs; + +/* Capture statistics for each worker thread */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + + +struct applicationStatistics{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + +ResultBuffer *resultBuffer; + + +void* waitforworkerthreads(void*); +void starttests(int); +int setuptest(void); +int cleanuptest(void); +int GetParameters( int , char **); +void incrementCounter(void); +ULONGLONG GetTicks(void); +ULONGLONG getPerfCallibrationValue(void); + + + +extern int main(int argc, char **argv) + { + //Variable Declaration + pthread_t pthreads[640]; + int threadID[640]; + int i=0; + int j=0; + int rtn=0; + ULONGLONG startTicks = 0; + + /* Variables to capture the file name and the file pointer*/ + char fileName[MAX_PATH]; + FILE *hFile; + struct statistics* buffer; + int statisticsSize = 0; + + /*Variable to Captutre Information at the Application Level*/ + struct applicationStatistics appStats; + char mainFileName[MAX_PATH]; + FILE *hMainFile; + + //Get perfCallibrationValue + + callibrationValue = getPerfCallibrationValue(); + printf("Callibration Value for this Platform %llu \n", callibrationValue); + + + //Get Parameters + if(GetParameters(argc, argv)) + { + printf("Error in obtaining the parameters\n"); + exit(-1); + } + + //Assign Values to Application Statistics Members + appStats.relationId=RELATION_ID; + appStats.operationTime=0; + appStats.buildNumber = "999.99"; + appStats.processCount = USE_PROCESS_COUNT; + appStats.threadCount = THREAD_COUNT; + appStats.repeatCount = REPEAT_COUNT; + + printf("RELATION ID : %d\n", appStats.relationId); + printf("Process Count : %d\n", appStats.processCount); + printf("Thread Count : %d\n", appStats.threadCount); + printf("Repeat Count : %d\n", appStats.repeatCount); + + + //Open file for Application Statistics Collection + snprintf(mainFileName, MAX_PATH, "main_nativecriticalsection_%d_.txt",appStats.relationId); + hMainFile = fopen(mainFileName, "w+"); + + if(hMainFile == NULL) + { + printf("Error in opening main file for write\n"); + } + + + for (i=0;igetResultBuffer(i); + fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); + //printf("Iteration %d over\n", i); + } + } + fclose(hFile); + + + + //Call Test Case Cleanup Routine + if (0!=cleanuptest()) + { + //Error Condition + printf("Error Cleaning up Test Case"); + exit(-1); + } + + + if(hMainFile!= NULL) + { + printf("Writing to Main File \n"); + fprintf(hMainFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId, appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); + + } + fclose(hMainFile); + return 0; + } + +void * waitforworkerthreads(void * threadId) +{ + + int *threadParam = (int*) threadId; + +// printf("Thread ID : %d \n", *threadParam); + + //Accquire Lock + if (0!=pthread_mutex_lock(&g_mutex)) + { + //Error Condition + printf("Error Accquiring Mutex Lock in Wait for Worker Thread\n"); + exit(-1); + } + + //Increment Global Counter + GLOBAL_COUNTER++; + + + //If global counter is equal to thread count then signal main thread + if (GLOBAL_COUNTER == THREAD_COUNT) + { + if (0!=pthread_cond_signal(&g_cv2)) + { + //Error Condition + printf("Error in setting conditional variable\n"); + exit(-1); + } + } + + //Wait for main thread to signal + if (0!=pthread_cond_wait(&g_cv,&g_mutex)) + { + //Error Condition + printf("Error waiting on conditional variable in Worker Thread\n"); + exit(-1); + } + + //Release the mutex lock + if (0!=pthread_mutex_unlock(&g_mutex)) + { + //Error Condition + printf("Error Releasing Mutex Lock in Worker Thread\n"); + exit(-1); + } + + //Start the test + starttests(*threadParam); + +} + +void starttests(int threadID) +{ + /*All threads beign executing tests cases*/ + int i = 0; + int Id = threadID; + struct statistics stats; + ULONGLONG startTime = 0; + ULONGLONG endTime = 0; + + + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + //Enter and Leave Critical Section in a loop REPEAT_COUNT Times + + startTime = GetTicks(); + + for (i=0;iLogResult(Id, (char *)&stats)) + { + printf("Error while writing to shared memory, Thread Id is[??] and Process id is [%d]\n", USE_PROCESS_COUNT); + } + +} + +int setuptest(void) +{ + + //Initalize Critical Section + if (0!=MTXInitializeCriticalSection( &g_cs)) + { + return -1; + } + return 0; +} + +int cleanuptest(void) +{ + + //Delete Critical Section + if (0!=MTXDeleteCriticalSection(&g_cs)) + { + return -1; + } + return 0; +} + +int GetParameters( int argc, char **argv) +{ + + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Native Critical Section Test\n"); + printf("Usage:\n"); + printf("\t[PROCESS_ID ( greater than 1] \n"); + printf("\t[THREAD_COUNT ( greater than 1] \n"); + printf("\t[REPEAT_COUNT ( greater than 1]\n"); + printf("\t[RELATION_ID [greater than or Equal to 1]\n"); + return -1; + } + + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( THREAD_COUNT < 1) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1\n"); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nInvalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + + return 0; +} + +void incrementCounter(void) +{ + g_counter ++; +} + + +//Implementation borrowed from pertrace.c +ULONGLONG GetTicks(void) +{ +#ifdef i386 + unsigned long a, d; + asm volatile("rdtsc":"=a" (a), "=d" (d)); + return ((ULONGLONG)((unsigned int)(d)) << 32) | (unsigned int)(a); +#else +#if defined(__sparc__) || (defined (_HPUX_) && defined(__ia64__)) + return (ULONGLONG)gethrtime(); +#else + // #error Don''t know how to get ticks on this platform + return (ULONGLONG)gethrtime(); +#endif // __sparc__ +#endif // _X86_ +} + + +/**/ +ULONGLONG getPerfCallibrationValue(void) +{ + ULONGLONG startTicks; + ULONGLONG endTicks; + + startTicks = GetTicks(); + sleep(1); + endTicks = GetTicks(); + + return ((endTicks-startTicks)/1000); //Return number of Ticks in One Milliseconds + +} + diff --git a/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/CMakeLists.txt b/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/CMakeLists.txt index c4567f638c..717bdd6b20 100644 --- a/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/CMakeLists.txt @@ -5,7 +5,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES interlocked.cpp mtx_critsect.cpp - pal_composite_native_cs.c + pal_composite_native_cs.cpp resultbuffer.cpp ) diff --git a/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/pal_composite_native_cs.c b/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/pal_composite_native_cs.c deleted file mode 100644 index 4c19d3b0de..0000000000 --- a/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/pal_composite_native_cs.c +++ /dev/null @@ -1,475 +0,0 @@ -// 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. - -#include -#include -#include -#include -#include -//#include -//#include "mtx_critsect.cpp" -#include "mtx_critsect.h" -#include "resultbuffer.h" - - - -#define LONGLONG long long -#define ULONGLONG unsigned LONGLONG -/*Defining Global Variables*/ - -int THREAD_COUNT=0; -int REPEAT_COUNT=0; -int GLOBAL_COUNTER=0; -int USE_PROCESS_COUNT = 0; -int RELATION_ID =0; -int g_counter = 0; -int MAX_PATH = 256; -LONGLONG callibrationValue = 0; - -pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t g_cv = PTHREAD_COND_INITIALIZER; -pthread_cond_t g_cv2 = PTHREAD_COND_INITIALIZER; -CRITICAL_SECTION g_cs; - -/* Capture statistics for each worker thread */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - - -struct applicationStatistics{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - -ResultBuffer *resultBuffer; - - -void* waitforworkerthreads(void*); -void starttests(int); -int setuptest(void); -int cleanuptest(void); -int GetParameters( int , char **); -void incrementCounter(void); -ULONGLONG GetTicks(void); -ULONGLONG getPerfCallibrationValue(void); - - - -extern int main(int argc, char **argv) - { - //Variable Declaration - pthread_t pthreads[640]; - int threadID[640]; - int i=0; - int j=0; - int rtn=0; - ULONGLONG startTicks = 0; - - /* Variables to capture the file name and the file pointer*/ - char fileName[MAX_PATH]; - FILE *hFile; - struct statistics* buffer; - int statisticsSize = 0; - - /*Variable to Captutre Information at the Application Level*/ - struct applicationStatistics appStats; - char mainFileName[MAX_PATH]; - FILE *hMainFile; - - //Get perfCallibrationValue - - callibrationValue = getPerfCallibrationValue(); - printf("Callibration Value for this Platform %llu \n", callibrationValue); - - - //Get Parameters - if(GetParameters(argc, argv)) - { - printf("Error in obtaining the parameters\n"); - exit(-1); - } - - //Assign Values to Application Statistics Members - appStats.relationId=RELATION_ID; - appStats.operationTime=0; - appStats.buildNumber = "999.99"; - appStats.processCount = USE_PROCESS_COUNT; - appStats.threadCount = THREAD_COUNT; - appStats.repeatCount = REPEAT_COUNT; - - printf("RELATION ID : %d\n", appStats.relationId); - printf("Process Count : %d\n", appStats.processCount); - printf("Thread Count : %d\n", appStats.threadCount); - printf("Repeat Count : %d\n", appStats.repeatCount); - - - //Open file for Application Statistics Collection - snprintf(mainFileName, MAX_PATH, "main_nativecriticalsection_%d_.txt",appStats.relationId); - hMainFile = fopen(mainFileName, "w+"); - - if(hMainFile == NULL) - { - printf("Error in opening main file for write\n"); - } - - - for (i=0;igetResultBuffer(i); - fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); - //printf("Iteration %d over\n", i); - } - } - fclose(hFile); - - - - //Call Test Case Cleanup Routine - if (0!=cleanuptest()) - { - //Error Condition - printf("Error Cleaning up Test Case"); - exit(-1); - } - - - if(hMainFile!= NULL) - { - printf("Writing to Main File \n"); - fprintf(hMainFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId, appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); - - } - fclose(hMainFile); - return 0; - } - -void * waitforworkerthreads(void * threadId) -{ - - int *threadParam = (int*) threadId; - -// printf("Thread ID : %d \n", *threadParam); - - //Accquire Lock - if (0!=pthread_mutex_lock(&g_mutex)) - { - //Error Condition - printf("Error Accquiring Mutex Lock in Wait for Worker Thread\n"); - exit(-1); - } - - //Increment Global Counter - GLOBAL_COUNTER++; - - - //If global counter is equal to thread count then signal main thread - if (GLOBAL_COUNTER == THREAD_COUNT) - { - if (0!=pthread_cond_signal(&g_cv2)) - { - //Error Condition - printf("Error in setting conditional variable\n"); - exit(-1); - } - } - - //Wait for main thread to signal - if (0!=pthread_cond_wait(&g_cv,&g_mutex)) - { - //Error Condition - printf("Error waiting on conditional variable in Worker Thread\n"); - exit(-1); - } - - //Release the mutex lock - if (0!=pthread_mutex_unlock(&g_mutex)) - { - //Error Condition - printf("Error Releasing Mutex Lock in Worker Thread\n"); - exit(-1); - } - - //Start the test - starttests(*threadParam); - -} - -void starttests(int threadID) -{ - /*All threads beign executing tests cases*/ - int i = 0; - int Id = threadID; - struct statistics stats; - ULONGLONG startTime = 0; - ULONGLONG endTime = 0; - - LONG volatile Destination; - LONG Exchange; - LONG Comperand; - LONG result; - - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - //Enter and Leave Critical Section in a loop REPEAT_COUNT Times - - - startTime = GetTicks(); - - for (i=0;iLogResult(Id, (char *)&stats)) - { - printf("Error while writing to shared memory, Thread Id is[??] and Process id is [%d]\n", USE_PROCESS_COUNT); - } - -} - -int setuptest(void) -{ - - //Initalize Critical Section - /* - if (0!=MTXInitializeCriticalSection( &g_cs)) - { - return -1; - } - */ - return 0; -} - -int cleanuptest(void) -{ - - //Delete Critical Section - /* - if (0!=MTXDeleteCriticalSection(&g_cs)) - { - return -1; - } - */ - return 0; -} - -int GetParameters( int argc, char **argv) -{ - - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Native Critical Section Test\n"); - printf("Usage:\n"); - printf("\t[PROCESS_ID ( greater than 1] \n"); - printf("\t[THREAD_COUNT ( greater than 1] \n"); - printf("\t[REPEAT_COUNT ( greater than 1]\n"); - printf("\t[RELATION_ID [greater than or Equal to 1]\n"); - return -1; - } - - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( THREAD_COUNT < 1) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1\n"); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nInvalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - - return 0; -} - -void incrementCounter(void) -{ - g_counter ++; -} - - -//Implementation borrowed from pertrace.c -ULONGLONG GetTicks(void) -{ -#ifdef i386 - unsigned long a, d; - asm volatile("rdtsc":"=a" (a), "=d" (d)); - return ((ULONGLONG)((unsigned int)(d)) << 32) | (unsigned int)(a); -#else -#if defined(__sparc__) || (defined (_HPUX_) && defined(__ia64__)) - return (ULONGLONG)gethrtime(); -#else - // #error Don''t know how to get ticks on this platform - return (ULONGLONG)gethrtime(); -#endif // __sparc__ -#endif // _X86_ -} - - -/**/ -ULONGLONG getPerfCallibrationValue(void) -{ - ULONGLONG startTicks; - ULONGLONG endTicks; - - startTicks = GetTicks(); - sleep(1); - endTicks = GetTicks(); - - return ((endTicks-startTicks)/1000); //Return number of Ticks in One Milliseconds - -} - diff --git a/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/pal_composite_native_cs.cpp b/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/pal_composite_native_cs.cpp new file mode 100644 index 0000000000..4c19d3b0de --- /dev/null +++ b/src/pal/tests/palsuite/composite/synchronization/nativecs_interlocked/pal_composite_native_cs.cpp @@ -0,0 +1,475 @@ +// 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. + +#include +#include +#include +#include +#include +//#include +//#include "mtx_critsect.cpp" +#include "mtx_critsect.h" +#include "resultbuffer.h" + + + +#define LONGLONG long long +#define ULONGLONG unsigned LONGLONG +/*Defining Global Variables*/ + +int THREAD_COUNT=0; +int REPEAT_COUNT=0; +int GLOBAL_COUNTER=0; +int USE_PROCESS_COUNT = 0; +int RELATION_ID =0; +int g_counter = 0; +int MAX_PATH = 256; +LONGLONG callibrationValue = 0; + +pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t g_cv = PTHREAD_COND_INITIALIZER; +pthread_cond_t g_cv2 = PTHREAD_COND_INITIALIZER; +CRITICAL_SECTION g_cs; + +/* Capture statistics for each worker thread */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + + +struct applicationStatistics{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + +ResultBuffer *resultBuffer; + + +void* waitforworkerthreads(void*); +void starttests(int); +int setuptest(void); +int cleanuptest(void); +int GetParameters( int , char **); +void incrementCounter(void); +ULONGLONG GetTicks(void); +ULONGLONG getPerfCallibrationValue(void); + + + +extern int main(int argc, char **argv) + { + //Variable Declaration + pthread_t pthreads[640]; + int threadID[640]; + int i=0; + int j=0; + int rtn=0; + ULONGLONG startTicks = 0; + + /* Variables to capture the file name and the file pointer*/ + char fileName[MAX_PATH]; + FILE *hFile; + struct statistics* buffer; + int statisticsSize = 0; + + /*Variable to Captutre Information at the Application Level*/ + struct applicationStatistics appStats; + char mainFileName[MAX_PATH]; + FILE *hMainFile; + + //Get perfCallibrationValue + + callibrationValue = getPerfCallibrationValue(); + printf("Callibration Value for this Platform %llu \n", callibrationValue); + + + //Get Parameters + if(GetParameters(argc, argv)) + { + printf("Error in obtaining the parameters\n"); + exit(-1); + } + + //Assign Values to Application Statistics Members + appStats.relationId=RELATION_ID; + appStats.operationTime=0; + appStats.buildNumber = "999.99"; + appStats.processCount = USE_PROCESS_COUNT; + appStats.threadCount = THREAD_COUNT; + appStats.repeatCount = REPEAT_COUNT; + + printf("RELATION ID : %d\n", appStats.relationId); + printf("Process Count : %d\n", appStats.processCount); + printf("Thread Count : %d\n", appStats.threadCount); + printf("Repeat Count : %d\n", appStats.repeatCount); + + + //Open file for Application Statistics Collection + snprintf(mainFileName, MAX_PATH, "main_nativecriticalsection_%d_.txt",appStats.relationId); + hMainFile = fopen(mainFileName, "w+"); + + if(hMainFile == NULL) + { + printf("Error in opening main file for write\n"); + } + + + for (i=0;igetResultBuffer(i); + fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); + //printf("Iteration %d over\n", i); + } + } + fclose(hFile); + + + + //Call Test Case Cleanup Routine + if (0!=cleanuptest()) + { + //Error Condition + printf("Error Cleaning up Test Case"); + exit(-1); + } + + + if(hMainFile!= NULL) + { + printf("Writing to Main File \n"); + fprintf(hMainFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId, appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); + + } + fclose(hMainFile); + return 0; + } + +void * waitforworkerthreads(void * threadId) +{ + + int *threadParam = (int*) threadId; + +// printf("Thread ID : %d \n", *threadParam); + + //Accquire Lock + if (0!=pthread_mutex_lock(&g_mutex)) + { + //Error Condition + printf("Error Accquiring Mutex Lock in Wait for Worker Thread\n"); + exit(-1); + } + + //Increment Global Counter + GLOBAL_COUNTER++; + + + //If global counter is equal to thread count then signal main thread + if (GLOBAL_COUNTER == THREAD_COUNT) + { + if (0!=pthread_cond_signal(&g_cv2)) + { + //Error Condition + printf("Error in setting conditional variable\n"); + exit(-1); + } + } + + //Wait for main thread to signal + if (0!=pthread_cond_wait(&g_cv,&g_mutex)) + { + //Error Condition + printf("Error waiting on conditional variable in Worker Thread\n"); + exit(-1); + } + + //Release the mutex lock + if (0!=pthread_mutex_unlock(&g_mutex)) + { + //Error Condition + printf("Error Releasing Mutex Lock in Worker Thread\n"); + exit(-1); + } + + //Start the test + starttests(*threadParam); + +} + +void starttests(int threadID) +{ + /*All threads beign executing tests cases*/ + int i = 0; + int Id = threadID; + struct statistics stats; + ULONGLONG startTime = 0; + ULONGLONG endTime = 0; + + LONG volatile Destination; + LONG Exchange; + LONG Comperand; + LONG result; + + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + //Enter and Leave Critical Section in a loop REPEAT_COUNT Times + + + startTime = GetTicks(); + + for (i=0;iLogResult(Id, (char *)&stats)) + { + printf("Error while writing to shared memory, Thread Id is[??] and Process id is [%d]\n", USE_PROCESS_COUNT); + } + +} + +int setuptest(void) +{ + + //Initalize Critical Section + /* + if (0!=MTXInitializeCriticalSection( &g_cs)) + { + return -1; + } + */ + return 0; +} + +int cleanuptest(void) +{ + + //Delete Critical Section + /* + if (0!=MTXDeleteCriticalSection(&g_cs)) + { + return -1; + } + */ + return 0; +} + +int GetParameters( int argc, char **argv) +{ + + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Native Critical Section Test\n"); + printf("Usage:\n"); + printf("\t[PROCESS_ID ( greater than 1] \n"); + printf("\t[THREAD_COUNT ( greater than 1] \n"); + printf("\t[REPEAT_COUNT ( greater than 1]\n"); + printf("\t[RELATION_ID [greater than or Equal to 1]\n"); + return -1; + } + + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( THREAD_COUNT < 1) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1\n"); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nInvalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + + return 0; +} + +void incrementCounter(void) +{ + g_counter ++; +} + + +//Implementation borrowed from pertrace.c +ULONGLONG GetTicks(void) +{ +#ifdef i386 + unsigned long a, d; + asm volatile("rdtsc":"=a" (a), "=d" (d)); + return ((ULONGLONG)((unsigned int)(d)) << 32) | (unsigned int)(a); +#else +#if defined(__sparc__) || (defined (_HPUX_) && defined(__ia64__)) + return (ULONGLONG)gethrtime(); +#else + // #error Don''t know how to get ticks on this platform + return (ULONGLONG)gethrtime(); +#endif // __sparc__ +#endif // _X86_ +} + + +/**/ +ULONGLONG getPerfCallibrationValue(void) +{ + ULONGLONG startTicks; + ULONGLONG endTicks; + + startTicks = GetTicks(); + sleep(1); + endTicks = GetTicks(); + + return ((endTicks-startTicks)/1000); //Return number of Ticks in One Milliseconds + +} + diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension/CMakeLists.txt b/src/pal/tests/palsuite/composite/threading/threadsuspension/CMakeLists.txt index 134cce0809..d396d2fc49 100644 --- a/src/pal/tests/palsuite/composite/threading/threadsuspension/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/threading/threadsuspension/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - mainWrapper.c - threadsuspension.c + mainWrapper.cpp + threadsuspension.cpp ) add_executable(paltest_threading_threadsuspension diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension/mainWrapper.c b/src/pal/tests/palsuite/composite/threading/threadsuspension/mainWrapper.c deleted file mode 100644 index 05a71191cf..0000000000 --- a/src/pal/tests/palsuite/composite/threading/threadsuspension/mainWrapper.c +++ /dev/null @@ -1,274 +0,0 @@ -// 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 Code: mainWrapper.c - -mainWrapper.c creates Composite Test Case Processes and waits for all processes to get over - -Algorithm -o Create PROCESS_COUNT processes. - -Author: RameshG -*/ - -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; //default -unsigned int WORKER_THREAD_MULTIPLIER_COUNT = 0; //default -unsigned int REPEAT_COUNT = 0; //default -unsigned int SLEEP_LENGTH = 0; //default -unsigned int RELATION_ID = 0;//default -unsigned int THREAD_COUNT = 1; //There is only one suspender and resume thread for this test case - -char *testCaseName; - - -struct applicationStatistics{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - - -int GetParameters( int argc, char **argv) -{ - - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Thread Suspension Test\n"); - printf("Usage:\n"); - printf("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); - printf("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to %d \n", MAXIMUM_WAIT_OBJECTS); - printf("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); - printf("\t[RELATION_ID [greater than or Equal to 1]\n"); - return -1; - } - - // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nPROCESS_COUNT to greater than or equal to 1\n"); - return -1; - } - - WORKER_THREAD_MULTIPLIER_COUNT = atoi(argv[2]); - if( WORKER_THREAD_MULTIPLIER_COUNT < 1 || WORKER_THREAD_MULTIPLIER_COUNT > 64) - { - printf("\nWORKER_THREAD_MULTIPLIER_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nREPEAT_COUNT to greater than or equal to 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nRELATION_ID to be greater than or equal to 1\n"); - return -1; - } - - - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; - DWORD processReturnCode = 0; - int testReturnCode = PASS; - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - - FILE *hFile; - char fileName[MAX_PATH]; - struct applicationStatistics appStats; - - DWORD dwStart=0; - - char lpCommandLine[MAX_PATH] = ""; - - char build[] ="0000.00"; - int returnCode = 0; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - //Initialize Application Statistics Strucuture - appStats.relationId=RELATION_ID; - appStats.operationTime=0; - appStats.buildNumber = getBuildNumber(); - //appStats.buildNumber = build; - appStats.processCount = 0; - appStats.threadCount = 0; - appStats.repeatCount = 0; - - - - - -//Start Process Time Capture -dwStart = GetTickCount(); - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - -//Assign Correct Values to the Application Stats Structure - appStats.relationId=RELATION_ID; - appStats.processCount = USE_PROCESS_COUNT; - appStats.threadCount = THREAD_COUNT ; - appStats.repeatCount = REPEAT_COUNT; - - Trace("Relation ID: %d \n", RELATION_ID); - Trace("USE_PROCESS_COUNT: %d \n", USE_PROCESS_COUNT); - Trace("WORKER_THREAD_MULTIPLIER_COUNT: %d \n", WORKER_THREAD_MULTIPLIER_COUNT); - Trace("REPEAT_COUNT: %d \n", REPEAT_COUNT); - - -_snprintf(fileName, MAX_PATH, "main_threadsuspension_%d_.txt",appStats.relationId); - - hFile = fopen(fileName, "w+"); -if(hFile == NULL) - { - Fail("Error in opening file to write application results for Thread Suspension Test with error code %d \n", GetLastError() ); - } - - - - for( i = 0; i < USE_PROCESS_COUNT; i++ ) - { - - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_PATH-1, "threadsuspension %d %d %d %d", i, WORKER_THREAD_MULTIPLIER_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) - { - Trace ("Error: Insufficient commandline string length for for iteration [%d]\n", i); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - //Printing the Command Line - //Trace("Command Line \t %s \n", lpCommandLine); - - //Create Process - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d] and GetLastError value is %d\n", i, GetLastError()); - - } - else - { - hProcess[i] = pi[i].hProcess; - //Trace("Process created for [%d]\n", i); - } - - } - - returnCode = WaitForMultipleObjects( USE_PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testReturnCode = FAIL; - } - - for( i = 0; i < USE_PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - testReturnCode = FAIL; - } - } - -//Get the end time of the process -appStats.operationTime = GetTickCount() - dwStart; - -if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - } - else - { - Trace("Test Failed\n"); - } - -//Write Process Result Contents to File -if(hFile!= NULL) - { - fprintf(hFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId, appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); - } - -if (0!=fclose(hFile)) -{ - Trace("Error:%d: fclose failed for file %s\n", GetLastError(), fileName); -} - PAL_Terminate(); - - -if( testReturnCode == PASS) - { - return PASS; - } - else - { - return FAIL; - - } - -} diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension/mainWrapper.cpp b/src/pal/tests/palsuite/composite/threading/threadsuspension/mainWrapper.cpp new file mode 100644 index 0000000000..05a71191cf --- /dev/null +++ b/src/pal/tests/palsuite/composite/threading/threadsuspension/mainWrapper.cpp @@ -0,0 +1,274 @@ +// 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 Code: mainWrapper.c + +mainWrapper.c creates Composite Test Case Processes and waits for all processes to get over + +Algorithm +o Create PROCESS_COUNT processes. + +Author: RameshG +*/ + +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; //default +unsigned int WORKER_THREAD_MULTIPLIER_COUNT = 0; //default +unsigned int REPEAT_COUNT = 0; //default +unsigned int SLEEP_LENGTH = 0; //default +unsigned int RELATION_ID = 0;//default +unsigned int THREAD_COUNT = 1; //There is only one suspender and resume thread for this test case + +char *testCaseName; + + +struct applicationStatistics{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + + +int GetParameters( int argc, char **argv) +{ + + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Thread Suspension Test\n"); + printf("Usage:\n"); + printf("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); + printf("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to %d \n", MAXIMUM_WAIT_OBJECTS); + printf("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); + printf("\t[RELATION_ID [greater than or Equal to 1]\n"); + return -1; + } + + // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nPROCESS_COUNT to greater than or equal to 1\n"); + return -1; + } + + WORKER_THREAD_MULTIPLIER_COUNT = atoi(argv[2]); + if( WORKER_THREAD_MULTIPLIER_COUNT < 1 || WORKER_THREAD_MULTIPLIER_COUNT > 64) + { + printf("\nWORKER_THREAD_MULTIPLIER_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nREPEAT_COUNT to greater than or equal to 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nRELATION_ID to be greater than or equal to 1\n"); + return -1; + } + + + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; + DWORD processReturnCode = 0; + int testReturnCode = PASS; + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + + FILE *hFile; + char fileName[MAX_PATH]; + struct applicationStatistics appStats; + + DWORD dwStart=0; + + char lpCommandLine[MAX_PATH] = ""; + + char build[] ="0000.00"; + int returnCode = 0; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + //Initialize Application Statistics Strucuture + appStats.relationId=RELATION_ID; + appStats.operationTime=0; + appStats.buildNumber = getBuildNumber(); + //appStats.buildNumber = build; + appStats.processCount = 0; + appStats.threadCount = 0; + appStats.repeatCount = 0; + + + + + +//Start Process Time Capture +dwStart = GetTickCount(); + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + +//Assign Correct Values to the Application Stats Structure + appStats.relationId=RELATION_ID; + appStats.processCount = USE_PROCESS_COUNT; + appStats.threadCount = THREAD_COUNT ; + appStats.repeatCount = REPEAT_COUNT; + + Trace("Relation ID: %d \n", RELATION_ID); + Trace("USE_PROCESS_COUNT: %d \n", USE_PROCESS_COUNT); + Trace("WORKER_THREAD_MULTIPLIER_COUNT: %d \n", WORKER_THREAD_MULTIPLIER_COUNT); + Trace("REPEAT_COUNT: %d \n", REPEAT_COUNT); + + +_snprintf(fileName, MAX_PATH, "main_threadsuspension_%d_.txt",appStats.relationId); + + hFile = fopen(fileName, "w+"); +if(hFile == NULL) + { + Fail("Error in opening file to write application results for Thread Suspension Test with error code %d \n", GetLastError() ); + } + + + + for( i = 0; i < USE_PROCESS_COUNT; i++ ) + { + + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( _snprintf( lpCommandLine, MAX_PATH-1, "threadsuspension %d %d %d %d", i, WORKER_THREAD_MULTIPLIER_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) + { + Trace ("Error: Insufficient commandline string length for for iteration [%d]\n", i); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + //Printing the Command Line + //Trace("Command Line \t %s \n", lpCommandLine); + + //Create Process + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d] and GetLastError value is %d\n", i, GetLastError()); + + } + else + { + hProcess[i] = pi[i].hProcess; + //Trace("Process created for [%d]\n", i); + } + + } + + returnCode = WaitForMultipleObjects( USE_PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testReturnCode = FAIL; + } + + for( i = 0; i < USE_PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + testReturnCode = FAIL; + } + } + +//Get the end time of the process +appStats.operationTime = GetTickCount() - dwStart; + +if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + } + else + { + Trace("Test Failed\n"); + } + +//Write Process Result Contents to File +if(hFile!= NULL) + { + fprintf(hFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId, appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); + } + +if (0!=fclose(hFile)) +{ + Trace("Error:%d: fclose failed for file %s\n", GetLastError(), fileName); +} + PAL_Terminate(); + + +if( testReturnCode == PASS) + { + return PASS; + } + else + { + return FAIL; + + } + +} diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension/threadsuspension.c b/src/pal/tests/palsuite/composite/threading/threadsuspension/threadsuspension.c deleted file mode 100644 index 86ee4e2fc0..0000000000 --- a/src/pal/tests/palsuite/composite/threading/threadsuspension/threadsuspension.c +++ /dev/null @@ -1,907 +0,0 @@ -// 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: \composite\threading\threadsuspension\threadsuspension.c -** -** Purpose: To verify Thread Suspension Reegneering effort for this milestone - - PsedoCode: - - Preparation: - Create PROCESS_COUNT processes. - Test: - Create Worker Thread - Start Reading and writing to a File - - Create Worker Thread - In an infinite loop do the following - Enter Critical Section - Increment Counter - Leave Critical Section - - Create Worker Thread - Allocate Memory and Free Memory - - Create Worker Thread - In a tight loop add numbers - - In a loop repeated REPEAT_COUNT times - - Create Thread - - Suspend all worker threads - Resume all worker threads - - At the end of the loop call PAL_Shutdown - - Parameters: - PROCESS_COUNT: Number of processes - WORKER_THREAD_MULTIPLIER_COUNT: Number of instances of worker threads in each process - REPEAT_COUNT: The number of times to execute the loop. - - Statistics Captured: - Total elapsed time - MTBF - - - Scenario: -** - One thread suspends all remaining threads which are in the middle of doing some work and resume all threads - Thread 1: Reading and Writing File - Thread 2: Enter and Leave Critical Section - Thread 3: Allocating chunks of memory - Thread 4: Perform Unsafe Operation (printf, malloc) - Thread 5: Suspends Thread 1 to Thread 4 and resumes them - -** -** -** -** Dependencies: -** -** - -** -**=========================================================*/ - -#include -#include "resultbuffer.h" - -#define BUFSIZE 4096 -#define NUMBER_OF_WORKER_THREAD_TYPES 4 -#define THREAD_MAX 64 - -#define TEST_FAIL 1 -#define TEST_PASS 0 - - -DWORD GLOBAL_COUNTER ; -DWORD UNIQUE_FILE_NUMBER=0; -HANDLE g_hEvent; - -bool failFlag = false; //To Track failure at the Operation Level - -// 2 dimensional array to hold thread handles for each worker thread -HANDLE hThread[NUMBER_OF_WORKER_THREAD_TYPES][THREAD_MAX]; - -/*unsigned int g_readfileoperation; -unsigned int g_enterleavecsoperation; -unsigned int g_allocatefreeoperation; -unsigned int g_doworintightloop; -*/ - -int TYPES_OF_WORKER_THREAD = NUMBER_OF_WORKER_THREAD_TYPES; - -int testStatus=TEST_PASS; //Indicates test failure - - -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - -struct processStatistics{ - unsigned int processId; - DWORD operationTime; - unsigned int relationId; -}; - -/* Results Buffer */ -ResultBuffer *resultBuffer; - - -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; //Identifies the Process number. There could potentially -unsigned int WORKER_THREAD_MULTIPLIER_COUNT = 0; //In this test case this represents the number of worker thread instances -unsigned int REPEAT_COUNT = 0; //Number of Suspend Resume operation of worker threads -unsigned int RELATION_ID = 0; - - - -CRITICAL_SECTION CriticalSectionM; /* Critical Section Object (used as mutex) */ -CRITICAL_SECTION g_csUniqueFileName; - -void PALAPI setup(void); -void PALAPI cleanup(void); -void PALAPI incrementCounter(void); -DWORD PALAPI readfile( LPVOID); -DWORD PALAPI enterandleave_cs( LPVOID); -DWORD PALAPI allocateandfree_memory( LPVOID); -DWORD PALAPI doworkintightloop_cs( LPVOID); -DWORD PALAPI suspendandresumethreads( LPVOID); -int GetParameters(int, char * *); - - -//Main Entry for the Thread Suspension Test Case -int __cdecl main (int argc, char **argv) -{ - -/* -* Parameter to the threads that will be created -*/ - - -DWORD dwThrdParam = 0; -DWORD dwStart; - -/* Variables to capture the file name and the file pointer*/ -char fileName[MAX_PATH]; -char processFileName[MAX_PATH]; - -FILE *hFile, *hProcessFile; -struct statistics* buffer; -struct processStatistics *processBuffer; - -struct processStatistics processStats; - -struct statistics* tmpBuf = NULL; -int statisticsSize = 0; - -DWORD dwThreadId=0; -HANDLE hMainThread; -unsigned int i = 0; -int j = 0; - - -/* -* PAL Initialize -*/ - -if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - -//Get Parameters -if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - -//Setup for Process Result Collection -statisticsSize = sizeof(struct statistics); -_snprintf(processFileName, MAX_PATH, "%d_process_threadsuspension_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); -hProcessFile = fopen(processFileName, "w+"); - -if(hProcessFile == NULL) - { - Fail("Error in opening file to write process results for process [%d]\n", USE_PROCESS_COUNT); - } - -//Initialize Process Stats Variables -processStats.operationTime = 0; -processStats.processId = USE_PROCESS_COUNT; -processStats.relationId = RELATION_ID; - -//Start Process Time Capture -dwStart = GetTickCount(); - -//Setup for Thread Result Collection -statisticsSize = sizeof(struct statistics); -_snprintf(fileName, MAX_PATH, "%d_thread_threadsuspension_%d_.txt", USE_PROCESS_COUNT,RELATION_ID); -hFile = fopen(fileName, "w+"); - -if(hFile == NULL) - { - Fail("Error in opening file to write thread results for process [%d]\n", USE_PROCESS_COUNT); - } - -// For each thread we will log relationid (int), processid (int), operations failed (int), passed (int), total (int) -// and number of ticks (DWORD) for the operations -resultBuffer = new ResultBuffer( 1, statisticsSize); - -/* -* Call the Setup Routine -*/ -setup(); - -Trace("WORKER_THREAD_MULTIPLIER_COUNT: %d \n", WORKER_THREAD_MULTIPLIER_COUNT); - -//Create WORKER_THREAD_MULTIPLIER_COUNT Instances of each type of worker thread -for (i=0;igetResultBuffer(i); - fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); - } - } - -if (0!=fclose(hFile)) -{ - Fail("Unable to write thread results to file" - "GetLastError returned %d\n", GetLastError()); -} - -cleanup(); - -if (failFlag == TRUE) -{ - return FAIL; -} -else -{ - return PASS; -} -} - - -/* -* Setup for the test case -*/ - -VOID -setup(VOID) -{ - /*Delete All Temporary Files Created by the previous execution of the test case*/ - HANDLE hSearch; - BOOL fFinished = FALSE; - WIN32_FIND_DATA FileData; - - //Start searching for .tmp files in the current directory. - hSearch = FindFirstFile("*.tmp*", &FileData); - if (hSearch == INVALID_HANDLE_VALUE) - { - //No Files That Matched Criteria - fFinished = TRUE; - } - - //Delete all files that match the pattern - while (!fFinished) - { - if (!DeleteFile(FileData.cFileName)) - { - Trace("Setup: Could not delete temporary file %s\n",FileData.cFileName ); - Fail ("GetLastError returned %d\n", GetLastError()); - } - if (!FindNextFile(hSearch, &FileData)) - { - if (GetLastError() == ERROR_NO_MORE_FILES) - { - fFinished = TRUE; - } - else - { - Fail("Unable to Delete Temporary Files, GetLastError is %d \n", GetLastError()); - } - } - } - - // Close the search handle, only if HANDLE is Valid - if (hSearch != INVALID_HANDLE_VALUE) - { - if (!FindClose(hSearch)) - { - Trace("Setup: Could not close search handle \n"); - Fail ("GetLastError returned %d\n", GetLastError()); - } - } - - g_hEvent = CreateEvent(NULL,TRUE,FALSE, NULL); - if(g_hEvent == NULL) - { - Fail("Create Event Failed\n" - "GetLastError returned %d\n", GetLastError()); - } - - InitializeCriticalSection ( &g_csUniqueFileName); -} - -/* -* Cleanup for the test case -*/ - -VOID -cleanup(VOID) -{ - //DeleteCriticalSection(&g_csUniqueFileName); - PAL_Terminate(); -} - - -VOID -incrementCounter(VOID) -{ - - if (INT_MAX == GLOBAL_COUNTER) - { - GLOBAL_COUNTER = 0; - } - - GLOBAL_COUNTER++; -} - -/* - * Worker Thread - * Read File: Read from a file and write to a temporary file and then delete the temp file - */ -DWORD -PALAPI -readfile( LPVOID lpParam ) -{ - - // Declaring Local Variables - HANDLE hFile,hTempfile; - char buffer[BUFSIZE]; - DWORD dwBytesRead, dwBytesWritten, dwBufSize=BUFSIZE; - DWORD dwWaitResult=0; - char filename[MAX_PATH]; - - //Wait for event to signal to start test - dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("readfile: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - - /*Start Operation*/ - - // Open the existing file. - while(TRUE) - { - - hFile = CreateFile("samplefile.dat", // file name - GENERIC_READ, // open for reading - FILE_SHARE_READ, // Share the file for read - NULL, // default security - OPEN_EXISTING, // existing file only - FILE_ATTRIBUTE_NORMAL, // normal file - NULL); // no template - - if (hFile == INVALID_HANDLE_VALUE) - { - Trace("Could not open file \n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - - //Generate Unique File Name to Write - //Enter CS - EnterCriticalSection(&g_csUniqueFileName); - - //Increment Number and assign to local variable - UNIQUE_FILE_NUMBER++; - _snprintf(filename, MAX_PATH, "%d_%d_tempfile.tmp", USE_PROCESS_COUNT,UNIQUE_FILE_NUMBER); - //filename = itoa(UNIQUE_FILE_NUMBER); - //Leave CS - LeaveCriticalSection(&g_csUniqueFileName); - - - // Create a temporary file with name generate above - hTempfile = CreateFile(filename, // file name - GENERIC_WRITE, // open for read/write - 0, // do not share - NULL, // default security - CREATE_ALWAYS, // overwrite existing file - FILE_ATTRIBUTE_NORMAL, // normal file - NULL); // no template - - - if (hTempfile == INVALID_HANDLE_VALUE) - { - Trace("Could not create temporary file\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - - // Read 4K blocks to the buffer. - // Change all characters in the buffer to upper case. - // Write the buffer to the temporary file. - - do - { - if (ReadFile(hFile, buffer, 4096, - &dwBytesRead, NULL)) - { - - WriteFile(hTempfile, buffer, dwBytesRead, - &dwBytesWritten, NULL); - } - } while (dwBytesRead == BUFSIZE); - - - - // Close both files. - if (0==CloseHandle(hFile)) - { - Trace("Could not handle hFile\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - - if (0==CloseHandle(hTempfile)) - { - Trace("Could not handle hTempFile\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - - //Delete the file that was created - if (!DeleteFile(filename)) - { - Trace("Could not delete temporary file %s\n", filename); - Fail ( "GetLastError returned %d\n", GetLastError()); - - } - - //g_readfileoperation++; - } - -/*End Operation*/ - - return 0; -} - - -/* Worker Thread - * Enter and Leave Nested Critical Sections - */ -DWORD -PALAPI -enterandleave_cs( LPVOID lpParam ) -{ - - //Declare Local Variables - - CRITICAL_SECTION lcs; - CRITICAL_SECTION lcsNested; - - DWORD dwWaitResult; - - //Intialize Critical Section Structures - InitializeCriticalSection ( &lcs); - InitializeCriticalSection ( &lcsNested); - - - //Wait for event to signal to start test - dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("enterandleave_cs: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - //Trace("Critical Section Started\n"); - - while(TRUE) - { - EnterCriticalSection(&lcs); - - EnterCriticalSection(&lcsNested); - - incrementCounter(); - - LeaveCriticalSection(&lcsNested); - - LeaveCriticalSection(&lcs); - //g_enterleavecsoperation++; - } - - //Delete Critical Section Structures - - DeleteCriticalSection(&lcs); - DeleteCriticalSection(&lcsNested); - - - return 0; -} - - -/* - * Allocate and Free Memory - */ -DWORD -PALAPI -allocateandfree_memory( LPVOID lpParam ) -{ - - - int i; - char *textArrPtr[64]; - DWORD dwWaitResult; - - //Wait for event to signal to start test - dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("allocateandfree_memory: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - - while(TRUE) - { - - //do allocate and free operation - - for (i=0;i<64;i++) - { - textArrPtr[i] = (char*) malloc(BUFSIZE); - if (textArrPtr[i] == NULL) - { - Fail("Insufficient Memory Available, GetLastError is %d \n", GetLastError()); - testStatus = TEST_FAIL; - } - } - - for (i=0;i<64;i++) - { - free(textArrPtr[i]); - } - //g_allocatefreeoperation++; - } - - - - - return 0; -} - -/* - * Do work in a tight loop - */ -DWORD -PALAPI -doworkintightloop_cs( LPVOID lpParam ) -{ - - unsigned int i; - DWORD dwWaitResult; - - //Wait for event to signal to start test - dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("doworkintightloop_cs: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - i= 0; - while (TRUE) - { - - if (INT_MAX == i) - i =0; - i++; - //g_doworintightloop++; - } - - return 0; -} - - -/* - * Main Test Case worker thread which will suspend and resume all other worker threads - */ -DWORD -PALAPI -suspendandresumethreads( LPVOID lpParam ) -{ - - unsigned int loopcount = REPEAT_COUNT; - int Id=(int)lpParam; - unsigned int i,j,k; - DWORD dwStart; - DWORD dwWaitResult=0; - DWORD dwLastError = 0; - struct statistics stats; - struct statistics* buffer; - - - - //Initialize the Statistics Structure - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - - - //Wait for event to signal to start test - WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("suspendandresumethreads: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - - //Capture Start Import - dwStart = GetTickCount(); - - for(i = 0; i < loopcount; i++) - { - - failFlag = false; - - //Suspend Worker Threads - for (k=0;kLogResult(Id, (char *)&stats)) - { - Fail("Error while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", Id, USE_PROCESS_COUNT); - } - - buffer = (struct statistics *)resultBuffer->getResultBuffer(Id); - //Trace("\n%d,%d,%d,%lu\n", buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime ); - - - return 0; -} - - - -int GetParameters( int argc, char **argv) -{ - - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - Trace("PAL -Composite Thread Suspension Test\n"); - Trace("Usage:\n"); - Trace("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); - Trace("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to 64 \n"); - Trace("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); - Trace("\t[RELATION_ID [greater than or Equal to 1]\n"); - return -1; - } - -// Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - Trace("\nPROCESS_COUNT to greater than or equal to 1\n"); - return -1; - } - - WORKER_THREAD_MULTIPLIER_COUNT = atoi(argv[2]); - if( WORKER_THREAD_MULTIPLIER_COUNT < 1 || WORKER_THREAD_MULTIPLIER_COUNT > 64) - { - Trace("\nWORKER_THREAD_MULTIPLIER_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - Trace("\nREPEAT_COUNT to greater than or equal to 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - Trace("\nRELATION_ID to be greater than or equal to 1\n"); - return -1; - } - return 0; -} diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension/threadsuspension.cpp b/src/pal/tests/palsuite/composite/threading/threadsuspension/threadsuspension.cpp new file mode 100644 index 0000000000..86ee4e2fc0 --- /dev/null +++ b/src/pal/tests/palsuite/composite/threading/threadsuspension/threadsuspension.cpp @@ -0,0 +1,907 @@ +// 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: \composite\threading\threadsuspension\threadsuspension.c +** +** Purpose: To verify Thread Suspension Reegneering effort for this milestone + + PsedoCode: + + Preparation: + Create PROCESS_COUNT processes. + Test: + Create Worker Thread + Start Reading and writing to a File + + Create Worker Thread + In an infinite loop do the following + Enter Critical Section + Increment Counter + Leave Critical Section + + Create Worker Thread + Allocate Memory and Free Memory + + Create Worker Thread + In a tight loop add numbers + + In a loop repeated REPEAT_COUNT times + + Create Thread + + Suspend all worker threads + Resume all worker threads + + At the end of the loop call PAL_Shutdown + + Parameters: + PROCESS_COUNT: Number of processes + WORKER_THREAD_MULTIPLIER_COUNT: Number of instances of worker threads in each process + REPEAT_COUNT: The number of times to execute the loop. + + Statistics Captured: + Total elapsed time + MTBF + + + Scenario: +** + One thread suspends all remaining threads which are in the middle of doing some work and resume all threads + Thread 1: Reading and Writing File + Thread 2: Enter and Leave Critical Section + Thread 3: Allocating chunks of memory + Thread 4: Perform Unsafe Operation (printf, malloc) + Thread 5: Suspends Thread 1 to Thread 4 and resumes them + +** +** +** +** Dependencies: +** +** + +** +**=========================================================*/ + +#include +#include "resultbuffer.h" + +#define BUFSIZE 4096 +#define NUMBER_OF_WORKER_THREAD_TYPES 4 +#define THREAD_MAX 64 + +#define TEST_FAIL 1 +#define TEST_PASS 0 + + +DWORD GLOBAL_COUNTER ; +DWORD UNIQUE_FILE_NUMBER=0; +HANDLE g_hEvent; + +bool failFlag = false; //To Track failure at the Operation Level + +// 2 dimensional array to hold thread handles for each worker thread +HANDLE hThread[NUMBER_OF_WORKER_THREAD_TYPES][THREAD_MAX]; + +/*unsigned int g_readfileoperation; +unsigned int g_enterleavecsoperation; +unsigned int g_allocatefreeoperation; +unsigned int g_doworintightloop; +*/ + +int TYPES_OF_WORKER_THREAD = NUMBER_OF_WORKER_THREAD_TYPES; + +int testStatus=TEST_PASS; //Indicates test failure + + +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + +struct processStatistics{ + unsigned int processId; + DWORD operationTime; + unsigned int relationId; +}; + +/* Results Buffer */ +ResultBuffer *resultBuffer; + + +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; //Identifies the Process number. There could potentially +unsigned int WORKER_THREAD_MULTIPLIER_COUNT = 0; //In this test case this represents the number of worker thread instances +unsigned int REPEAT_COUNT = 0; //Number of Suspend Resume operation of worker threads +unsigned int RELATION_ID = 0; + + + +CRITICAL_SECTION CriticalSectionM; /* Critical Section Object (used as mutex) */ +CRITICAL_SECTION g_csUniqueFileName; + +void PALAPI setup(void); +void PALAPI cleanup(void); +void PALAPI incrementCounter(void); +DWORD PALAPI readfile( LPVOID); +DWORD PALAPI enterandleave_cs( LPVOID); +DWORD PALAPI allocateandfree_memory( LPVOID); +DWORD PALAPI doworkintightloop_cs( LPVOID); +DWORD PALAPI suspendandresumethreads( LPVOID); +int GetParameters(int, char * *); + + +//Main Entry for the Thread Suspension Test Case +int __cdecl main (int argc, char **argv) +{ + +/* +* Parameter to the threads that will be created +*/ + + +DWORD dwThrdParam = 0; +DWORD dwStart; + +/* Variables to capture the file name and the file pointer*/ +char fileName[MAX_PATH]; +char processFileName[MAX_PATH]; + +FILE *hFile, *hProcessFile; +struct statistics* buffer; +struct processStatistics *processBuffer; + +struct processStatistics processStats; + +struct statistics* tmpBuf = NULL; +int statisticsSize = 0; + +DWORD dwThreadId=0; +HANDLE hMainThread; +unsigned int i = 0; +int j = 0; + + +/* +* PAL Initialize +*/ + +if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + +//Get Parameters +if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + +//Setup for Process Result Collection +statisticsSize = sizeof(struct statistics); +_snprintf(processFileName, MAX_PATH, "%d_process_threadsuspension_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); +hProcessFile = fopen(processFileName, "w+"); + +if(hProcessFile == NULL) + { + Fail("Error in opening file to write process results for process [%d]\n", USE_PROCESS_COUNT); + } + +//Initialize Process Stats Variables +processStats.operationTime = 0; +processStats.processId = USE_PROCESS_COUNT; +processStats.relationId = RELATION_ID; + +//Start Process Time Capture +dwStart = GetTickCount(); + +//Setup for Thread Result Collection +statisticsSize = sizeof(struct statistics); +_snprintf(fileName, MAX_PATH, "%d_thread_threadsuspension_%d_.txt", USE_PROCESS_COUNT,RELATION_ID); +hFile = fopen(fileName, "w+"); + +if(hFile == NULL) + { + Fail("Error in opening file to write thread results for process [%d]\n", USE_PROCESS_COUNT); + } + +// For each thread we will log relationid (int), processid (int), operations failed (int), passed (int), total (int) +// and number of ticks (DWORD) for the operations +resultBuffer = new ResultBuffer( 1, statisticsSize); + +/* +* Call the Setup Routine +*/ +setup(); + +Trace("WORKER_THREAD_MULTIPLIER_COUNT: %d \n", WORKER_THREAD_MULTIPLIER_COUNT); + +//Create WORKER_THREAD_MULTIPLIER_COUNT Instances of each type of worker thread +for (i=0;igetResultBuffer(i); + fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); + } + } + +if (0!=fclose(hFile)) +{ + Fail("Unable to write thread results to file" + "GetLastError returned %d\n", GetLastError()); +} + +cleanup(); + +if (failFlag == TRUE) +{ + return FAIL; +} +else +{ + return PASS; +} +} + + +/* +* Setup for the test case +*/ + +VOID +setup(VOID) +{ + /*Delete All Temporary Files Created by the previous execution of the test case*/ + HANDLE hSearch; + BOOL fFinished = FALSE; + WIN32_FIND_DATA FileData; + + //Start searching for .tmp files in the current directory. + hSearch = FindFirstFile("*.tmp*", &FileData); + if (hSearch == INVALID_HANDLE_VALUE) + { + //No Files That Matched Criteria + fFinished = TRUE; + } + + //Delete all files that match the pattern + while (!fFinished) + { + if (!DeleteFile(FileData.cFileName)) + { + Trace("Setup: Could not delete temporary file %s\n",FileData.cFileName ); + Fail ("GetLastError returned %d\n", GetLastError()); + } + if (!FindNextFile(hSearch, &FileData)) + { + if (GetLastError() == ERROR_NO_MORE_FILES) + { + fFinished = TRUE; + } + else + { + Fail("Unable to Delete Temporary Files, GetLastError is %d \n", GetLastError()); + } + } + } + + // Close the search handle, only if HANDLE is Valid + if (hSearch != INVALID_HANDLE_VALUE) + { + if (!FindClose(hSearch)) + { + Trace("Setup: Could not close search handle \n"); + Fail ("GetLastError returned %d\n", GetLastError()); + } + } + + g_hEvent = CreateEvent(NULL,TRUE,FALSE, NULL); + if(g_hEvent == NULL) + { + Fail("Create Event Failed\n" + "GetLastError returned %d\n", GetLastError()); + } + + InitializeCriticalSection ( &g_csUniqueFileName); +} + +/* +* Cleanup for the test case +*/ + +VOID +cleanup(VOID) +{ + //DeleteCriticalSection(&g_csUniqueFileName); + PAL_Terminate(); +} + + +VOID +incrementCounter(VOID) +{ + + if (INT_MAX == GLOBAL_COUNTER) + { + GLOBAL_COUNTER = 0; + } + + GLOBAL_COUNTER++; +} + +/* + * Worker Thread + * Read File: Read from a file and write to a temporary file and then delete the temp file + */ +DWORD +PALAPI +readfile( LPVOID lpParam ) +{ + + // Declaring Local Variables + HANDLE hFile,hTempfile; + char buffer[BUFSIZE]; + DWORD dwBytesRead, dwBytesWritten, dwBufSize=BUFSIZE; + DWORD dwWaitResult=0; + char filename[MAX_PATH]; + + //Wait for event to signal to start test + dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("readfile: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + + /*Start Operation*/ + + // Open the existing file. + while(TRUE) + { + + hFile = CreateFile("samplefile.dat", // file name + GENERIC_READ, // open for reading + FILE_SHARE_READ, // Share the file for read + NULL, // default security + OPEN_EXISTING, // existing file only + FILE_ATTRIBUTE_NORMAL, // normal file + NULL); // no template + + if (hFile == INVALID_HANDLE_VALUE) + { + Trace("Could not open file \n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + + //Generate Unique File Name to Write + //Enter CS + EnterCriticalSection(&g_csUniqueFileName); + + //Increment Number and assign to local variable + UNIQUE_FILE_NUMBER++; + _snprintf(filename, MAX_PATH, "%d_%d_tempfile.tmp", USE_PROCESS_COUNT,UNIQUE_FILE_NUMBER); + //filename = itoa(UNIQUE_FILE_NUMBER); + //Leave CS + LeaveCriticalSection(&g_csUniqueFileName); + + + // Create a temporary file with name generate above + hTempfile = CreateFile(filename, // file name + GENERIC_WRITE, // open for read/write + 0, // do not share + NULL, // default security + CREATE_ALWAYS, // overwrite existing file + FILE_ATTRIBUTE_NORMAL, // normal file + NULL); // no template + + + if (hTempfile == INVALID_HANDLE_VALUE) + { + Trace("Could not create temporary file\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + + // Read 4K blocks to the buffer. + // Change all characters in the buffer to upper case. + // Write the buffer to the temporary file. + + do + { + if (ReadFile(hFile, buffer, 4096, + &dwBytesRead, NULL)) + { + + WriteFile(hTempfile, buffer, dwBytesRead, + &dwBytesWritten, NULL); + } + } while (dwBytesRead == BUFSIZE); + + + + // Close both files. + if (0==CloseHandle(hFile)) + { + Trace("Could not handle hFile\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + + if (0==CloseHandle(hTempfile)) + { + Trace("Could not handle hTempFile\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + + //Delete the file that was created + if (!DeleteFile(filename)) + { + Trace("Could not delete temporary file %s\n", filename); + Fail ( "GetLastError returned %d\n", GetLastError()); + + } + + //g_readfileoperation++; + } + +/*End Operation*/ + + return 0; +} + + +/* Worker Thread + * Enter and Leave Nested Critical Sections + */ +DWORD +PALAPI +enterandleave_cs( LPVOID lpParam ) +{ + + //Declare Local Variables + + CRITICAL_SECTION lcs; + CRITICAL_SECTION lcsNested; + + DWORD dwWaitResult; + + //Intialize Critical Section Structures + InitializeCriticalSection ( &lcs); + InitializeCriticalSection ( &lcsNested); + + + //Wait for event to signal to start test + dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("enterandleave_cs: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + //Trace("Critical Section Started\n"); + + while(TRUE) + { + EnterCriticalSection(&lcs); + + EnterCriticalSection(&lcsNested); + + incrementCounter(); + + LeaveCriticalSection(&lcsNested); + + LeaveCriticalSection(&lcs); + //g_enterleavecsoperation++; + } + + //Delete Critical Section Structures + + DeleteCriticalSection(&lcs); + DeleteCriticalSection(&lcsNested); + + + return 0; +} + + +/* + * Allocate and Free Memory + */ +DWORD +PALAPI +allocateandfree_memory( LPVOID lpParam ) +{ + + + int i; + char *textArrPtr[64]; + DWORD dwWaitResult; + + //Wait for event to signal to start test + dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("allocateandfree_memory: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + + while(TRUE) + { + + //do allocate and free operation + + for (i=0;i<64;i++) + { + textArrPtr[i] = (char*) malloc(BUFSIZE); + if (textArrPtr[i] == NULL) + { + Fail("Insufficient Memory Available, GetLastError is %d \n", GetLastError()); + testStatus = TEST_FAIL; + } + } + + for (i=0;i<64;i++) + { + free(textArrPtr[i]); + } + //g_allocatefreeoperation++; + } + + + + + return 0; +} + +/* + * Do work in a tight loop + */ +DWORD +PALAPI +doworkintightloop_cs( LPVOID lpParam ) +{ + + unsigned int i; + DWORD dwWaitResult; + + //Wait for event to signal to start test + dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("doworkintightloop_cs: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + i= 0; + while (TRUE) + { + + if (INT_MAX == i) + i =0; + i++; + //g_doworintightloop++; + } + + return 0; +} + + +/* + * Main Test Case worker thread which will suspend and resume all other worker threads + */ +DWORD +PALAPI +suspendandresumethreads( LPVOID lpParam ) +{ + + unsigned int loopcount = REPEAT_COUNT; + int Id=(int)lpParam; + unsigned int i,j,k; + DWORD dwStart; + DWORD dwWaitResult=0; + DWORD dwLastError = 0; + struct statistics stats; + struct statistics* buffer; + + + + //Initialize the Statistics Structure + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + + + //Wait for event to signal to start test + WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("suspendandresumethreads: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + + //Capture Start Import + dwStart = GetTickCount(); + + for(i = 0; i < loopcount; i++) + { + + failFlag = false; + + //Suspend Worker Threads + for (k=0;kLogResult(Id, (char *)&stats)) + { + Fail("Error while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", Id, USE_PROCESS_COUNT); + } + + buffer = (struct statistics *)resultBuffer->getResultBuffer(Id); + //Trace("\n%d,%d,%d,%lu\n", buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime ); + + + return 0; +} + + + +int GetParameters( int argc, char **argv) +{ + + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + Trace("PAL -Composite Thread Suspension Test\n"); + Trace("Usage:\n"); + Trace("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); + Trace("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to 64 \n"); + Trace("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); + Trace("\t[RELATION_ID [greater than or Equal to 1]\n"); + return -1; + } + +// Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + Trace("\nPROCESS_COUNT to greater than or equal to 1\n"); + return -1; + } + + WORKER_THREAD_MULTIPLIER_COUNT = atoi(argv[2]); + if( WORKER_THREAD_MULTIPLIER_COUNT < 1 || WORKER_THREAD_MULTIPLIER_COUNT > 64) + { + Trace("\nWORKER_THREAD_MULTIPLIER_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + Trace("\nREPEAT_COUNT to greater than or equal to 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + Trace("\nRELATION_ID to be greater than or equal to 1\n"); + return -1; + } + return 0; +} diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/CMakeLists.txt b/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/CMakeLists.txt index 5361a1cf0d..2c880921fe 100644 --- a/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - mainWrapper.c - threadsuspension.c + mainWrapper.cpp + threadsuspension.cpp ) add_executable(paltest_threading_threadsuspension_switchthread diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/mainWrapper.c b/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/mainWrapper.c deleted file mode 100644 index 05a71191cf..0000000000 --- a/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/mainWrapper.c +++ /dev/null @@ -1,274 +0,0 @@ -// 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 Code: mainWrapper.c - -mainWrapper.c creates Composite Test Case Processes and waits for all processes to get over - -Algorithm -o Create PROCESS_COUNT processes. - -Author: RameshG -*/ - -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; //default -unsigned int WORKER_THREAD_MULTIPLIER_COUNT = 0; //default -unsigned int REPEAT_COUNT = 0; //default -unsigned int SLEEP_LENGTH = 0; //default -unsigned int RELATION_ID = 0;//default -unsigned int THREAD_COUNT = 1; //There is only one suspender and resume thread for this test case - -char *testCaseName; - - -struct applicationStatistics{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - - -int GetParameters( int argc, char **argv) -{ - - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite Thread Suspension Test\n"); - printf("Usage:\n"); - printf("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); - printf("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to %d \n", MAXIMUM_WAIT_OBJECTS); - printf("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); - printf("\t[RELATION_ID [greater than or Equal to 1]\n"); - return -1; - } - - // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nPROCESS_COUNT to greater than or equal to 1\n"); - return -1; - } - - WORKER_THREAD_MULTIPLIER_COUNT = atoi(argv[2]); - if( WORKER_THREAD_MULTIPLIER_COUNT < 1 || WORKER_THREAD_MULTIPLIER_COUNT > 64) - { - printf("\nWORKER_THREAD_MULTIPLIER_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nREPEAT_COUNT to greater than or equal to 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - printf("\nRELATION_ID to be greater than or equal to 1\n"); - return -1; - } - - - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; - DWORD processReturnCode = 0; - int testReturnCode = PASS; - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - - FILE *hFile; - char fileName[MAX_PATH]; - struct applicationStatistics appStats; - - DWORD dwStart=0; - - char lpCommandLine[MAX_PATH] = ""; - - char build[] ="0000.00"; - int returnCode = 0; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - //Initialize Application Statistics Strucuture - appStats.relationId=RELATION_ID; - appStats.operationTime=0; - appStats.buildNumber = getBuildNumber(); - //appStats.buildNumber = build; - appStats.processCount = 0; - appStats.threadCount = 0; - appStats.repeatCount = 0; - - - - - -//Start Process Time Capture -dwStart = GetTickCount(); - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - -//Assign Correct Values to the Application Stats Structure - appStats.relationId=RELATION_ID; - appStats.processCount = USE_PROCESS_COUNT; - appStats.threadCount = THREAD_COUNT ; - appStats.repeatCount = REPEAT_COUNT; - - Trace("Relation ID: %d \n", RELATION_ID); - Trace("USE_PROCESS_COUNT: %d \n", USE_PROCESS_COUNT); - Trace("WORKER_THREAD_MULTIPLIER_COUNT: %d \n", WORKER_THREAD_MULTIPLIER_COUNT); - Trace("REPEAT_COUNT: %d \n", REPEAT_COUNT); - - -_snprintf(fileName, MAX_PATH, "main_threadsuspension_%d_.txt",appStats.relationId); - - hFile = fopen(fileName, "w+"); -if(hFile == NULL) - { - Fail("Error in opening file to write application results for Thread Suspension Test with error code %d \n", GetLastError() ); - } - - - - for( i = 0; i < USE_PROCESS_COUNT; i++ ) - { - - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_PATH-1, "threadsuspension %d %d %d %d", i, WORKER_THREAD_MULTIPLIER_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) - { - Trace ("Error: Insufficient commandline string length for for iteration [%d]\n", i); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - //Printing the Command Line - //Trace("Command Line \t %s \n", lpCommandLine); - - //Create Process - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d] and GetLastError value is %d\n", i, GetLastError()); - - } - else - { - hProcess[i] = pi[i].hProcess; - //Trace("Process created for [%d]\n", i); - } - - } - - returnCode = WaitForMultipleObjects( USE_PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testReturnCode = FAIL; - } - - for( i = 0; i < USE_PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - testReturnCode = FAIL; - } - } - -//Get the end time of the process -appStats.operationTime = GetTickCount() - dwStart; - -if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - } - else - { - Trace("Test Failed\n"); - } - -//Write Process Result Contents to File -if(hFile!= NULL) - { - fprintf(hFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId, appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); - } - -if (0!=fclose(hFile)) -{ - Trace("Error:%d: fclose failed for file %s\n", GetLastError(), fileName); -} - PAL_Terminate(); - - -if( testReturnCode == PASS) - { - return PASS; - } - else - { - return FAIL; - - } - -} diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/mainWrapper.cpp b/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/mainWrapper.cpp new file mode 100644 index 0000000000..05a71191cf --- /dev/null +++ b/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/mainWrapper.cpp @@ -0,0 +1,274 @@ +// 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 Code: mainWrapper.c + +mainWrapper.c creates Composite Test Case Processes and waits for all processes to get over + +Algorithm +o Create PROCESS_COUNT processes. + +Author: RameshG +*/ + +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; //default +unsigned int WORKER_THREAD_MULTIPLIER_COUNT = 0; //default +unsigned int REPEAT_COUNT = 0; //default +unsigned int SLEEP_LENGTH = 0; //default +unsigned int RELATION_ID = 0;//default +unsigned int THREAD_COUNT = 1; //There is only one suspender and resume thread for this test case + +char *testCaseName; + + +struct applicationStatistics{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + + +int GetParameters( int argc, char **argv) +{ + + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite Thread Suspension Test\n"); + printf("Usage:\n"); + printf("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); + printf("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to %d \n", MAXIMUM_WAIT_OBJECTS); + printf("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); + printf("\t[RELATION_ID [greater than or Equal to 1]\n"); + return -1; + } + + // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nPROCESS_COUNT to greater than or equal to 1\n"); + return -1; + } + + WORKER_THREAD_MULTIPLIER_COUNT = atoi(argv[2]); + if( WORKER_THREAD_MULTIPLIER_COUNT < 1 || WORKER_THREAD_MULTIPLIER_COUNT > 64) + { + printf("\nWORKER_THREAD_MULTIPLIER_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nREPEAT_COUNT to greater than or equal to 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + printf("\nRELATION_ID to be greater than or equal to 1\n"); + return -1; + } + + + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; + DWORD processReturnCode = 0; + int testReturnCode = PASS; + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + + FILE *hFile; + char fileName[MAX_PATH]; + struct applicationStatistics appStats; + + DWORD dwStart=0; + + char lpCommandLine[MAX_PATH] = ""; + + char build[] ="0000.00"; + int returnCode = 0; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + //Initialize Application Statistics Strucuture + appStats.relationId=RELATION_ID; + appStats.operationTime=0; + appStats.buildNumber = getBuildNumber(); + //appStats.buildNumber = build; + appStats.processCount = 0; + appStats.threadCount = 0; + appStats.repeatCount = 0; + + + + + +//Start Process Time Capture +dwStart = GetTickCount(); + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + +//Assign Correct Values to the Application Stats Structure + appStats.relationId=RELATION_ID; + appStats.processCount = USE_PROCESS_COUNT; + appStats.threadCount = THREAD_COUNT ; + appStats.repeatCount = REPEAT_COUNT; + + Trace("Relation ID: %d \n", RELATION_ID); + Trace("USE_PROCESS_COUNT: %d \n", USE_PROCESS_COUNT); + Trace("WORKER_THREAD_MULTIPLIER_COUNT: %d \n", WORKER_THREAD_MULTIPLIER_COUNT); + Trace("REPEAT_COUNT: %d \n", REPEAT_COUNT); + + +_snprintf(fileName, MAX_PATH, "main_threadsuspension_%d_.txt",appStats.relationId); + + hFile = fopen(fileName, "w+"); +if(hFile == NULL) + { + Fail("Error in opening file to write application results for Thread Suspension Test with error code %d \n", GetLastError() ); + } + + + + for( i = 0; i < USE_PROCESS_COUNT; i++ ) + { + + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( _snprintf( lpCommandLine, MAX_PATH-1, "threadsuspension %d %d %d %d", i, WORKER_THREAD_MULTIPLIER_COUNT, REPEAT_COUNT, RELATION_ID) < 0 ) + { + Trace ("Error: Insufficient commandline string length for for iteration [%d]\n", i); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + //Printing the Command Line + //Trace("Command Line \t %s \n", lpCommandLine); + + //Create Process + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d] and GetLastError value is %d\n", i, GetLastError()); + + } + else + { + hProcess[i] = pi[i].hProcess; + //Trace("Process created for [%d]\n", i); + } + + } + + returnCode = WaitForMultipleObjects( USE_PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testReturnCode = FAIL; + } + + for( i = 0; i < USE_PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + testReturnCode = FAIL; + } + } + +//Get the end time of the process +appStats.operationTime = GetTickCount() - dwStart; + +if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + } + else + { + Trace("Test Failed\n"); + } + +//Write Process Result Contents to File +if(hFile!= NULL) + { + fprintf(hFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId, appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber); + } + +if (0!=fclose(hFile)) +{ + Trace("Error:%d: fclose failed for file %s\n", GetLastError(), fileName); +} + PAL_Terminate(); + + +if( testReturnCode == PASS) + { + return PASS; + } + else + { + return FAIL; + + } + +} diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/threadsuspension.c b/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/threadsuspension.c deleted file mode 100644 index a117b86174..0000000000 --- a/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/threadsuspension.c +++ /dev/null @@ -1,914 +0,0 @@ -// 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: \composite\threading\threadsuspension\threadsuspension.c -** -** Purpose: To verify Thread Suspension Reegneering effort for this milestone - - PsedoCode: - - Preparation: - Create PROCESS_COUNT processes. - Test: - Create Worker Thread - Start Reading and writing to a File - - Create Worker Thread - In an infinite loop do the following - Enter Critical Section - Increment Counter - Leave Critical Section - - Create Worker Thread - Allocate Memory and Free Memory - - Create Worker Thread - In a tight loop add numbers - - In a loop repeated REPEAT_COUNT times - - Create Thread - - Suspend all worker threads - Resume all worker threads - - At the end of the loop call PAL_Shutdown - - Parameters: - PROCESS_COUNT: Number of processes - WORKER_THREAD_MULTIPLIER_COUNT: Number of instances of worker threads in each process - REPEAT_COUNT: The number of times to execute the loop. - - Statistics Captured: - Total elapsed time - MTBF - - - Scenario: -** - One thread suspends all remaining threads which are in the middle of doing some work and resume all threads - Thread 1: Reading and Writing File - Thread 2: Enter and Leave Critical Section - Thread 3: Allocating chunks of memory - Thread 4: Perform Unsafe Operation (printf, malloc) - Thread 5: Suspends Thread 1 to Thread 4 and resumes them - -** -** -** -** Dependencies: -** -** - -** -**=========================================================*/ - -#include -#include "resultbuffer.h" - -#define BUFSIZE 4096 -#define NUMBER_OF_WORKER_THREAD_TYPES 4 -#define THREAD_MAX 64 - -#define TEST_FAIL 1 -#define TEST_PASS 0 - - -DWORD GLOBAL_COUNTER ; -DWORD UNIQUE_FILE_NUMBER=0; -HANDLE g_hEvent; - -bool failFlag = false; //To Track failure at the Operation Level - -// 2 dimensional array to hold thread handles for each worker thread -HANDLE hThread[NUMBER_OF_WORKER_THREAD_TYPES][THREAD_MAX]; - -/*unsigned int g_readfileoperation; -unsigned int g_enterleavecsoperation; -unsigned int g_allocatefreeoperation; -unsigned int g_doworintightloop; -*/ - -int TYPES_OF_WORKER_THREAD = NUMBER_OF_WORKER_THREAD_TYPES; - -int testStatus=TEST_PASS; //Indicates test failure - - -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; -}; - -struct processStatistics{ - unsigned int processId; - DWORD operationTime; - unsigned int relationId; -}; - -/* Results Buffer */ -ResultBuffer *resultBuffer; - - -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; //Identifies the Process number. There could potentially -unsigned int WORKER_THREAD_MULTIPLIER_COUNT = 0; //In this test case this represents the number of worker thread instances -unsigned int REPEAT_COUNT = 0; //Number of Suspend Resume operation of worker threads -unsigned int RELATION_ID = 0; - - - -CRITICAL_SECTION CriticalSectionM; /* Critical Section Object (used as mutex) */ -CRITICAL_SECTION g_csUniqueFileName; - -void PALAPI setup(void); -void PALAPI cleanup(void); -void PALAPI incrementCounter(void); -DWORD PALAPI readfile( LPVOID); -DWORD PALAPI enterandleave_cs( LPVOID); -DWORD PALAPI allocateandfree_memory( LPVOID); -DWORD PALAPI doworkintightloop_cs( LPVOID); -DWORD PALAPI suspendandresumethreads( LPVOID); -int GetParameters(int, char * *); - - -//Main Entry for the Thread Suspension Test Case -int __cdecl main (int argc, char **argv) -{ - -/* -* Parameter to the threads that will be created -*/ - - -DWORD dwThrdParam = 0; -DWORD dwStart; - -/* Variables to capture the file name and the file pointer*/ -char fileName[MAX_PATH]; -char processFileName[MAX_PATH]; - -FILE *hFile, *hProcessFile; -struct statistics* buffer; -struct processStatistics *processBuffer; - -struct processStatistics processStats; - -struct statistics* tmpBuf = NULL; -int statisticsSize = 0; - -DWORD dwThreadId=0; -HANDLE hMainThread; -unsigned int i = 0; -int j = 0; - - -/* -* PAL Initialize -*/ - -if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - -//Get Parameters -if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - -//Setup for Process Result Collection -statisticsSize = sizeof(struct statistics); -_snprintf(processFileName, MAX_PATH, "%d_process_threadsuspension_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); -hProcessFile = fopen(processFileName, "w+"); - -if(hProcessFile == NULL) - { - Fail("Error in opening file to write process results for process [%d]\n", USE_PROCESS_COUNT); - } - -//Initialize Process Stats Variables -processStats.operationTime = 0; -processStats.processId = USE_PROCESS_COUNT; -processStats.relationId = RELATION_ID; - -//Start Process Time Capture -dwStart = GetTickCount(); - -//Setup for Thread Result Collection -statisticsSize = sizeof(struct statistics); -_snprintf(fileName, MAX_PATH, "%d_thread_threadsuspension_%d_.txt", USE_PROCESS_COUNT,RELATION_ID); -hFile = fopen(fileName, "w+"); - -if(hFile == NULL) - { - Fail("Error in opening file to write thread results for process [%d]\n", USE_PROCESS_COUNT); - } - -// For each thread we will log relationid (int), processid (int), operations failed (int), passed (int), total (int) -// and number of ticks (DWORD) for the operations -resultBuffer = new ResultBuffer( 1, statisticsSize); - -/* -* Call the Setup Routine -*/ -setup(); - -Trace("WORKER_THREAD_MULTIPLIER_COUNT: %d \n", WORKER_THREAD_MULTIPLIER_COUNT); - -//Create WORKER_THREAD_MULTIPLIER_COUNT Instances of each type of worker thread -for (i=0;igetResultBuffer(i); - fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); - } - } - -if (0!=fclose(hFile)) -{ - Fail("Unable to write thread results to file" - "GetLastError returned %d\n", GetLastError()); -} - -cleanup(); - -if (failFlag == TRUE) -{ - return FAIL; -} -else -{ - return PASS; -} -} - - -/* -* Setup for the test case -*/ - -VOID -setup(VOID) -{ - /*Delete All Temporary Files Created by the previous execution of the test case*/ - HANDLE hSearch; - BOOL fFinished = FALSE; - WIN32_FIND_DATA FileData; - - //Start searching for .tmp files in the current directory. - hSearch = FindFirstFile("*.tmp*", &FileData); - if (hSearch == INVALID_HANDLE_VALUE) - { - //No Files That Matched Criteria - fFinished = TRUE; - } - - //Delete all files that match the pattern - while (!fFinished) - { - if (!DeleteFile(FileData.cFileName)) - { - Trace("Setup: Could not delete temporary file %s\n",FileData.cFileName ); - Fail ("GetLastError returned %d\n", GetLastError()); - } - if (!FindNextFile(hSearch, &FileData)) - { - if (GetLastError() == ERROR_NO_MORE_FILES) - { - fFinished = TRUE; - } - else - { - Fail("Unable to Delete Temporary Files, GetLastError is %d \n", GetLastError()); - } - } - } - - // Close the search handle, only if HANDLE is Valid - if (hSearch != INVALID_HANDLE_VALUE) - { - if (!FindClose(hSearch)) - { - Trace("Setup: Could not close search handle \n"); - Fail ("GetLastError returned %d\n", GetLastError()); - } - } - - g_hEvent = CreateEvent(NULL,TRUE,FALSE, NULL); - if(g_hEvent == NULL) - { - Fail("Create Event Failed\n" - "GetLastError returned %d\n", GetLastError()); - } - - InitializeCriticalSection ( &g_csUniqueFileName); -} - -/* -* Cleanup for the test case -*/ - -VOID -cleanup(VOID) -{ - //DeleteCriticalSection(&g_csUniqueFileName); - PAL_Terminate(); -} - - -VOID -incrementCounter(VOID) -{ - - if (INT_MAX == GLOBAL_COUNTER) - { - GLOBAL_COUNTER = 0; - } - - GLOBAL_COUNTER++; -} - -/* - * Worker Thread - * Read File: Read from a file and write to a temporary file and then delete the temp file - */ -DWORD -PALAPI -readfile( LPVOID lpParam ) -{ - - // Declaring Local Variables - HANDLE hFile,hTempfile; - char buffer[BUFSIZE]; - DWORD dwBytesRead, dwBytesWritten, dwBufSize=BUFSIZE; - DWORD dwWaitResult=0; - char filename[MAX_PATH]; - - //Wait for event to signal to start test - dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("readfile: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - - /*Start Operation*/ - - // Open the existing file. - while(TRUE) - { - - hFile = CreateFile("samplefile.dat", // file name - GENERIC_READ, // open for reading - FILE_SHARE_READ, // Share the file for read - NULL, // default security - OPEN_EXISTING, // existing file only - FILE_ATTRIBUTE_NORMAL, // normal file - NULL); // no template - - if (hFile == INVALID_HANDLE_VALUE) - { - Trace("Could not open file \n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - - //Generate Unique File Name to Write - //Enter CS - EnterCriticalSection(&g_csUniqueFileName); - - //Increment Number and assign to local variable - UNIQUE_FILE_NUMBER++; - _snprintf(filename, MAX_PATH, "%d_%d_tempfile.tmp", USE_PROCESS_COUNT,UNIQUE_FILE_NUMBER); - //filename = itoa(UNIQUE_FILE_NUMBER); - //Leave CS - LeaveCriticalSection(&g_csUniqueFileName); - - - // Create a temporary file with name generate above - hTempfile = CreateFile(filename, // file name - GENERIC_WRITE, // open for read/write - 0, // do not share - NULL, // default security - CREATE_ALWAYS, // overwrite existing file - FILE_ATTRIBUTE_NORMAL, // normal file - NULL); // no template - - - if (hTempfile == INVALID_HANDLE_VALUE) - { - Trace("Could not create temporary file\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - - // Read 4K blocks to the buffer. - // Change all characters in the buffer to upper case. - // Write the buffer to the temporary file. - - do - { - if (ReadFile(hFile, buffer, 4096, - &dwBytesRead, NULL)) - { - - WriteFile(hTempfile, buffer, dwBytesRead, - &dwBytesWritten, NULL); - } - } while (dwBytesRead == BUFSIZE); - - - - // Close both files. - if (0==CloseHandle(hFile)) - { - Trace("Could not handle hFile\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - - if (0==CloseHandle(hTempfile)) - { - Trace("Could not handle hTempFile\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - - //Delete the file that was created - if (!DeleteFile(filename)) - { - Trace("Could not delete temporary file %s\n", filename); - Fail ( "GetLastError returned %d\n", GetLastError()); - - } - - SwitchToThread(); - //g_readfileoperation++; - } - -/*End Operation*/ - - return 0; -} - - -/* Worker Thread - * Enter and Leave Nested Critical Sections - */ -DWORD -PALAPI -enterandleave_cs( LPVOID lpParam ) -{ - - //Declare Local Variables - - CRITICAL_SECTION lcs; - CRITICAL_SECTION lcsNested; - - DWORD dwWaitResult; - - //Intialize Critical Section Structures - InitializeCriticalSection ( &lcs); - InitializeCriticalSection ( &lcsNested); - - - //Wait for event to signal to start test - dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("enterandleave_cs: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - //Trace("Critical Section Started\n"); - - while(TRUE) - { - EnterCriticalSection(&lcs); - - EnterCriticalSection(&lcsNested); - - incrementCounter(); - - LeaveCriticalSection(&lcsNested); - - LeaveCriticalSection(&lcs); - - SwitchToThread(); - //g_enterleavecsoperation++; - } - - //Delete Critical Section Structures - - DeleteCriticalSection(&lcs); - DeleteCriticalSection(&lcsNested); - - - return 0; -} - - -/* - * Allocate and Free Memory - */ -DWORD -PALAPI -allocateandfree_memory( LPVOID lpParam ) -{ - - - int i; - char *textArrPtr[64]; - DWORD dwWaitResult; - - //Wait for event to signal to start test - dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("allocateandfree_memory: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - - while(TRUE) - { - - //do allocate and free operation - - for (i=0;i<64;i++) - { - textArrPtr[i] = (char*) malloc(BUFSIZE); - if (textArrPtr[i] == NULL) - { - Fail("Insufficient Memory Available, GetLastError is %d \n", GetLastError()); - testStatus = TEST_FAIL; - } - } - - for (i=0;i<64;i++) - { - free(textArrPtr[i]); - } - - SwitchToThread(); - //g_allocatefreeoperation++; - } - - - - - return 0; -} - -/* - * Do work in a tight loop - */ -DWORD -PALAPI -doworkintightloop_cs( LPVOID lpParam ) -{ - - unsigned int i; - DWORD dwWaitResult; - - //Wait for event to signal to start test - dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("doworkintightloop_cs: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - i= 0; - while (TRUE) - { - - if (INT_MAX == i) - i =0; - i++; - //g_doworintightloop++; - - SwitchToThread(); - } - - return 0; -} - - -/* - * Main Test Case worker thread which will suspend and resume all other worker threads - */ -DWORD -PALAPI -suspendandresumethreads( LPVOID lpParam ) -{ - - unsigned int loopcount = REPEAT_COUNT; - int Id=(int)lpParam; - unsigned int i,j,k; - DWORD dwStart; - DWORD dwWaitResult=0; - DWORD dwLastError = 0; - struct statistics stats; - struct statistics* buffer; - - - - //Initialize the Statistics Structure - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - - - //Wait for event to signal to start test - WaitForSingleObject(g_hEvent,INFINITE); - if (WAIT_OBJECT_0 != dwWaitResult) - { - Fail ("suspendandresumethreads: Wait for Single Object (g_hEvent) failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - - //Capture Start Import - dwStart = GetTickCount(); - - for(i = 0; i < loopcount; i++) - { - - failFlag = false; - - //Suspend Worker Threads - for (k=0;kLogResult(Id, (char *)&stats)) - { - Fail("Error while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", Id, USE_PROCESS_COUNT); - } - - buffer = (struct statistics *)resultBuffer->getResultBuffer(Id); - //Trace("\n%d,%d,%d,%lu\n", buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime ); - - - return 0; -} - - - -int GetParameters( int argc, char **argv) -{ - - if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - Trace("PAL -Composite Thread Suspension Test\n"); - Trace("Usage:\n"); - Trace("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); - Trace("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to 64 \n"); - Trace("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); - Trace("\t[RELATION_ID [greater than or Equal to 1]\n"); - return -1; - } - -// Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - Trace("\nPROCESS_COUNT to greater than or equal to 1\n"); - return -1; - } - - WORKER_THREAD_MULTIPLIER_COUNT = atoi(argv[2]); - if( WORKER_THREAD_MULTIPLIER_COUNT < 1 || WORKER_THREAD_MULTIPLIER_COUNT > 64) - { - Trace("\nWORKER_THREAD_MULTIPLIER_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - Trace("\nREPEAT_COUNT to greater than or equal to 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[4]); - if( RELATION_ID < 1) - { - Trace("\nRELATION_ID to be greater than or equal to 1\n"); - return -1; - } - return 0; -} diff --git a/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/threadsuspension.cpp b/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/threadsuspension.cpp new file mode 100644 index 0000000000..a117b86174 --- /dev/null +++ b/src/pal/tests/palsuite/composite/threading/threadsuspension_switchthread/threadsuspension.cpp @@ -0,0 +1,914 @@ +// 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: \composite\threading\threadsuspension\threadsuspension.c +** +** Purpose: To verify Thread Suspension Reegneering effort for this milestone + + PsedoCode: + + Preparation: + Create PROCESS_COUNT processes. + Test: + Create Worker Thread + Start Reading and writing to a File + + Create Worker Thread + In an infinite loop do the following + Enter Critical Section + Increment Counter + Leave Critical Section + + Create Worker Thread + Allocate Memory and Free Memory + + Create Worker Thread + In a tight loop add numbers + + In a loop repeated REPEAT_COUNT times + + Create Thread + + Suspend all worker threads + Resume all worker threads + + At the end of the loop call PAL_Shutdown + + Parameters: + PROCESS_COUNT: Number of processes + WORKER_THREAD_MULTIPLIER_COUNT: Number of instances of worker threads in each process + REPEAT_COUNT: The number of times to execute the loop. + + Statistics Captured: + Total elapsed time + MTBF + + + Scenario: +** + One thread suspends all remaining threads which are in the middle of doing some work and resume all threads + Thread 1: Reading and Writing File + Thread 2: Enter and Leave Critical Section + Thread 3: Allocating chunks of memory + Thread 4: Perform Unsafe Operation (printf, malloc) + Thread 5: Suspends Thread 1 to Thread 4 and resumes them + +** +** +** +** Dependencies: +** +** + +** +**=========================================================*/ + +#include +#include "resultbuffer.h" + +#define BUFSIZE 4096 +#define NUMBER_OF_WORKER_THREAD_TYPES 4 +#define THREAD_MAX 64 + +#define TEST_FAIL 1 +#define TEST_PASS 0 + + +DWORD GLOBAL_COUNTER ; +DWORD UNIQUE_FILE_NUMBER=0; +HANDLE g_hEvent; + +bool failFlag = false; //To Track failure at the Operation Level + +// 2 dimensional array to hold thread handles for each worker thread +HANDLE hThread[NUMBER_OF_WORKER_THREAD_TYPES][THREAD_MAX]; + +/*unsigned int g_readfileoperation; +unsigned int g_enterleavecsoperation; +unsigned int g_allocatefreeoperation; +unsigned int g_doworintightloop; +*/ + +int TYPES_OF_WORKER_THREAD = NUMBER_OF_WORKER_THREAD_TYPES; + +int testStatus=TEST_PASS; //Indicates test failure + + +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; +}; + +struct processStatistics{ + unsigned int processId; + DWORD operationTime; + unsigned int relationId; +}; + +/* Results Buffer */ +ResultBuffer *resultBuffer; + + +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; //Identifies the Process number. There could potentially +unsigned int WORKER_THREAD_MULTIPLIER_COUNT = 0; //In this test case this represents the number of worker thread instances +unsigned int REPEAT_COUNT = 0; //Number of Suspend Resume operation of worker threads +unsigned int RELATION_ID = 0; + + + +CRITICAL_SECTION CriticalSectionM; /* Critical Section Object (used as mutex) */ +CRITICAL_SECTION g_csUniqueFileName; + +void PALAPI setup(void); +void PALAPI cleanup(void); +void PALAPI incrementCounter(void); +DWORD PALAPI readfile( LPVOID); +DWORD PALAPI enterandleave_cs( LPVOID); +DWORD PALAPI allocateandfree_memory( LPVOID); +DWORD PALAPI doworkintightloop_cs( LPVOID); +DWORD PALAPI suspendandresumethreads( LPVOID); +int GetParameters(int, char * *); + + +//Main Entry for the Thread Suspension Test Case +int __cdecl main (int argc, char **argv) +{ + +/* +* Parameter to the threads that will be created +*/ + + +DWORD dwThrdParam = 0; +DWORD dwStart; + +/* Variables to capture the file name and the file pointer*/ +char fileName[MAX_PATH]; +char processFileName[MAX_PATH]; + +FILE *hFile, *hProcessFile; +struct statistics* buffer; +struct processStatistics *processBuffer; + +struct processStatistics processStats; + +struct statistics* tmpBuf = NULL; +int statisticsSize = 0; + +DWORD dwThreadId=0; +HANDLE hMainThread; +unsigned int i = 0; +int j = 0; + + +/* +* PAL Initialize +*/ + +if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + +//Get Parameters +if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + +//Setup for Process Result Collection +statisticsSize = sizeof(struct statistics); +_snprintf(processFileName, MAX_PATH, "%d_process_threadsuspension_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); +hProcessFile = fopen(processFileName, "w+"); + +if(hProcessFile == NULL) + { + Fail("Error in opening file to write process results for process [%d]\n", USE_PROCESS_COUNT); + } + +//Initialize Process Stats Variables +processStats.operationTime = 0; +processStats.processId = USE_PROCESS_COUNT; +processStats.relationId = RELATION_ID; + +//Start Process Time Capture +dwStart = GetTickCount(); + +//Setup for Thread Result Collection +statisticsSize = sizeof(struct statistics); +_snprintf(fileName, MAX_PATH, "%d_thread_threadsuspension_%d_.txt", USE_PROCESS_COUNT,RELATION_ID); +hFile = fopen(fileName, "w+"); + +if(hFile == NULL) + { + Fail("Error in opening file to write thread results for process [%d]\n", USE_PROCESS_COUNT); + } + +// For each thread we will log relationid (int), processid (int), operations failed (int), passed (int), total (int) +// and number of ticks (DWORD) for the operations +resultBuffer = new ResultBuffer( 1, statisticsSize); + +/* +* Call the Setup Routine +*/ +setup(); + +Trace("WORKER_THREAD_MULTIPLIER_COUNT: %d \n", WORKER_THREAD_MULTIPLIER_COUNT); + +//Create WORKER_THREAD_MULTIPLIER_COUNT Instances of each type of worker thread +for (i=0;igetResultBuffer(i); + fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); + } + } + +if (0!=fclose(hFile)) +{ + Fail("Unable to write thread results to file" + "GetLastError returned %d\n", GetLastError()); +} + +cleanup(); + +if (failFlag == TRUE) +{ + return FAIL; +} +else +{ + return PASS; +} +} + + +/* +* Setup for the test case +*/ + +VOID +setup(VOID) +{ + /*Delete All Temporary Files Created by the previous execution of the test case*/ + HANDLE hSearch; + BOOL fFinished = FALSE; + WIN32_FIND_DATA FileData; + + //Start searching for .tmp files in the current directory. + hSearch = FindFirstFile("*.tmp*", &FileData); + if (hSearch == INVALID_HANDLE_VALUE) + { + //No Files That Matched Criteria + fFinished = TRUE; + } + + //Delete all files that match the pattern + while (!fFinished) + { + if (!DeleteFile(FileData.cFileName)) + { + Trace("Setup: Could not delete temporary file %s\n",FileData.cFileName ); + Fail ("GetLastError returned %d\n", GetLastError()); + } + if (!FindNextFile(hSearch, &FileData)) + { + if (GetLastError() == ERROR_NO_MORE_FILES) + { + fFinished = TRUE; + } + else + { + Fail("Unable to Delete Temporary Files, GetLastError is %d \n", GetLastError()); + } + } + } + + // Close the search handle, only if HANDLE is Valid + if (hSearch != INVALID_HANDLE_VALUE) + { + if (!FindClose(hSearch)) + { + Trace("Setup: Could not close search handle \n"); + Fail ("GetLastError returned %d\n", GetLastError()); + } + } + + g_hEvent = CreateEvent(NULL,TRUE,FALSE, NULL); + if(g_hEvent == NULL) + { + Fail("Create Event Failed\n" + "GetLastError returned %d\n", GetLastError()); + } + + InitializeCriticalSection ( &g_csUniqueFileName); +} + +/* +* Cleanup for the test case +*/ + +VOID +cleanup(VOID) +{ + //DeleteCriticalSection(&g_csUniqueFileName); + PAL_Terminate(); +} + + +VOID +incrementCounter(VOID) +{ + + if (INT_MAX == GLOBAL_COUNTER) + { + GLOBAL_COUNTER = 0; + } + + GLOBAL_COUNTER++; +} + +/* + * Worker Thread + * Read File: Read from a file and write to a temporary file and then delete the temp file + */ +DWORD +PALAPI +readfile( LPVOID lpParam ) +{ + + // Declaring Local Variables + HANDLE hFile,hTempfile; + char buffer[BUFSIZE]; + DWORD dwBytesRead, dwBytesWritten, dwBufSize=BUFSIZE; + DWORD dwWaitResult=0; + char filename[MAX_PATH]; + + //Wait for event to signal to start test + dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("readfile: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + + /*Start Operation*/ + + // Open the existing file. + while(TRUE) + { + + hFile = CreateFile("samplefile.dat", // file name + GENERIC_READ, // open for reading + FILE_SHARE_READ, // Share the file for read + NULL, // default security + OPEN_EXISTING, // existing file only + FILE_ATTRIBUTE_NORMAL, // normal file + NULL); // no template + + if (hFile == INVALID_HANDLE_VALUE) + { + Trace("Could not open file \n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + + //Generate Unique File Name to Write + //Enter CS + EnterCriticalSection(&g_csUniqueFileName); + + //Increment Number and assign to local variable + UNIQUE_FILE_NUMBER++; + _snprintf(filename, MAX_PATH, "%d_%d_tempfile.tmp", USE_PROCESS_COUNT,UNIQUE_FILE_NUMBER); + //filename = itoa(UNIQUE_FILE_NUMBER); + //Leave CS + LeaveCriticalSection(&g_csUniqueFileName); + + + // Create a temporary file with name generate above + hTempfile = CreateFile(filename, // file name + GENERIC_WRITE, // open for read/write + 0, // do not share + NULL, // default security + CREATE_ALWAYS, // overwrite existing file + FILE_ATTRIBUTE_NORMAL, // normal file + NULL); // no template + + + if (hTempfile == INVALID_HANDLE_VALUE) + { + Trace("Could not create temporary file\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + + // Read 4K blocks to the buffer. + // Change all characters in the buffer to upper case. + // Write the buffer to the temporary file. + + do + { + if (ReadFile(hFile, buffer, 4096, + &dwBytesRead, NULL)) + { + + WriteFile(hTempfile, buffer, dwBytesRead, + &dwBytesWritten, NULL); + } + } while (dwBytesRead == BUFSIZE); + + + + // Close both files. + if (0==CloseHandle(hFile)) + { + Trace("Could not handle hFile\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + + if (0==CloseHandle(hTempfile)) + { + Trace("Could not handle hTempFile\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + + //Delete the file that was created + if (!DeleteFile(filename)) + { + Trace("Could not delete temporary file %s\n", filename); + Fail ( "GetLastError returned %d\n", GetLastError()); + + } + + SwitchToThread(); + //g_readfileoperation++; + } + +/*End Operation*/ + + return 0; +} + + +/* Worker Thread + * Enter and Leave Nested Critical Sections + */ +DWORD +PALAPI +enterandleave_cs( LPVOID lpParam ) +{ + + //Declare Local Variables + + CRITICAL_SECTION lcs; + CRITICAL_SECTION lcsNested; + + DWORD dwWaitResult; + + //Intialize Critical Section Structures + InitializeCriticalSection ( &lcs); + InitializeCriticalSection ( &lcsNested); + + + //Wait for event to signal to start test + dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("enterandleave_cs: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + //Trace("Critical Section Started\n"); + + while(TRUE) + { + EnterCriticalSection(&lcs); + + EnterCriticalSection(&lcsNested); + + incrementCounter(); + + LeaveCriticalSection(&lcsNested); + + LeaveCriticalSection(&lcs); + + SwitchToThread(); + //g_enterleavecsoperation++; + } + + //Delete Critical Section Structures + + DeleteCriticalSection(&lcs); + DeleteCriticalSection(&lcsNested); + + + return 0; +} + + +/* + * Allocate and Free Memory + */ +DWORD +PALAPI +allocateandfree_memory( LPVOID lpParam ) +{ + + + int i; + char *textArrPtr[64]; + DWORD dwWaitResult; + + //Wait for event to signal to start test + dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("allocateandfree_memory: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + + while(TRUE) + { + + //do allocate and free operation + + for (i=0;i<64;i++) + { + textArrPtr[i] = (char*) malloc(BUFSIZE); + if (textArrPtr[i] == NULL) + { + Fail("Insufficient Memory Available, GetLastError is %d \n", GetLastError()); + testStatus = TEST_FAIL; + } + } + + for (i=0;i<64;i++) + { + free(textArrPtr[i]); + } + + SwitchToThread(); + //g_allocatefreeoperation++; + } + + + + + return 0; +} + +/* + * Do work in a tight loop + */ +DWORD +PALAPI +doworkintightloop_cs( LPVOID lpParam ) +{ + + unsigned int i; + DWORD dwWaitResult; + + //Wait for event to signal to start test + dwWaitResult = WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("doworkintightloop_cs: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + i= 0; + while (TRUE) + { + + if (INT_MAX == i) + i =0; + i++; + //g_doworintightloop++; + + SwitchToThread(); + } + + return 0; +} + + +/* + * Main Test Case worker thread which will suspend and resume all other worker threads + */ +DWORD +PALAPI +suspendandresumethreads( LPVOID lpParam ) +{ + + unsigned int loopcount = REPEAT_COUNT; + int Id=(int)lpParam; + unsigned int i,j,k; + DWORD dwStart; + DWORD dwWaitResult=0; + DWORD dwLastError = 0; + struct statistics stats; + struct statistics* buffer; + + + + //Initialize the Statistics Structure + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + + + //Wait for event to signal to start test + WaitForSingleObject(g_hEvent,INFINITE); + if (WAIT_OBJECT_0 != dwWaitResult) + { + Fail ("suspendandresumethreads: Wait for Single Object (g_hEvent) failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + + //Capture Start Import + dwStart = GetTickCount(); + + for(i = 0; i < loopcount; i++) + { + + failFlag = false; + + //Suspend Worker Threads + for (k=0;kLogResult(Id, (char *)&stats)) + { + Fail("Error while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", Id, USE_PROCESS_COUNT); + } + + buffer = (struct statistics *)resultBuffer->getResultBuffer(Id); + //Trace("\n%d,%d,%d,%lu\n", buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime ); + + + return 0; +} + + + +int GetParameters( int argc, char **argv) +{ + + if( (argc != 5) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + Trace("PAL -Composite Thread Suspension Test\n"); + Trace("Usage:\n"); + Trace("\t[PROCESS_COUNT] Greater than or Equal to 1 \n"); + Trace("\t[WORKER_THREAD_MULTIPLIER_COUNT] Greater than or Equal to 1 and Less than or Equal to 64 \n"); + Trace("\t[REPEAT_COUNT] Greater than or Equal to 1\n"); + Trace("\t[RELATION_ID [greater than or Equal to 1]\n"); + return -1; + } + +// Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + Trace("\nPROCESS_COUNT to greater than or equal to 1\n"); + return -1; + } + + WORKER_THREAD_MULTIPLIER_COUNT = atoi(argv[2]); + if( WORKER_THREAD_MULTIPLIER_COUNT < 1 || WORKER_THREAD_MULTIPLIER_COUNT > 64) + { + Trace("\nWORKER_THREAD_MULTIPLIER_COUNT to be greater than or equal to 1 or less than or equal to 64\n"); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + Trace("\nREPEAT_COUNT to greater than or equal to 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[4]); + if( RELATION_ID < 1) + { + Trace("\nRELATION_ID to be greater than or equal to 1\n"); + return -1; + } + return 0; +} diff --git a/src/pal/tests/palsuite/composite/wfmo/CMakeLists.txt b/src/pal/tests/palsuite/composite/wfmo/CMakeLists.txt index 7dbddbc989..5e103102af 100644 --- a/src/pal/tests/palsuite/composite/wfmo/CMakeLists.txt +++ b/src/pal/tests/palsuite/composite/wfmo/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - main.c - mutex.c + main.cpp + mutex.cpp ) add_executable(paltest_composite_wfmo diff --git a/src/pal/tests/palsuite/composite/wfmo/main.c b/src/pal/tests/palsuite/composite/wfmo/main.c deleted file mode 100644 index d186aa7b8b..0000000000 --- a/src/pal/tests/palsuite/composite/wfmo/main.c +++ /dev/null @@ -1,239 +0,0 @@ -// 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 Code: main.c and mutex.c -** main.c creates process and waits for all processes to get over -** mutex.c creates a mutex and then calls threads which will contend for the mutex -** -** This test is for WFMO Test case for Mutex -** Algorithm -** o Create PROCESS_COUNT processes. -** o Main Thread of each process creates OBJECT_TYPE Object -** -** Author: ShamitP -** -** -**============================================================ -*/ - -#include -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int PROCESS_COUNT = 3; -unsigned int THREAD_COUNT = 30; -unsigned int REPEAT_COUNT = 40; -unsigned int SLEEP_LENGTH = 4; -unsigned int RELATION_ID = 1001; - - - -struct TestStats{ - DWORD operationTime; - unsigned int relationId; - unsigned int processCount; - unsigned int threadCount; - unsigned int repeatCount; - char* buildNumber; - -}; - -int GetParameters( int argc, char **argv) -{ - if( (argc != 6) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite WFMO Test\n"); - printf("Usage:\n"); - printf("main\n\t[PROCESS_COUNT [greater than 0] \n"); - printf("\t[THREAD_COUNT [greater than 0] \n"); - printf("\t[REPEAT_COUNT [greater than 0]\n"); - printf("\t[SLEEP_LENGTH [greater than 0]\n"); - printf("\t[RELATION_ID [greater than 0]\n"); - - - - return -1; - } - - PROCESS_COUNT = atoi(argv[1]); - if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - SLEEP_LENGTH = atoi(argv[4]); - if( SLEEP_LENGTH < 1) - { - printf("\nMain Process:Invalid SLEEP_LENGTH number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[5]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; - - STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; - PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; - - char lpCommandLine[MAX_PATH] = ""; - - int returnCode = 0; - DWORD processReturnCode = 0; - int testReturnCode = PASS; - - char fileName[MAX_PATH]; - FILE *pFile = NULL; - DWORD dwStartTime; - struct TestStats testStats; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - testStats.relationId = 0; - testStats.relationId = RELATION_ID; - testStats.processCount = PROCESS_COUNT; - testStats.threadCount = THREAD_COUNT; - testStats.repeatCount = REPEAT_COUNT; - testStats.buildNumber = getBuildNumber(); - - - - _snprintf(fileName, MAX_PATH, "main_wfmo_%d_.txt",testStats.relationId); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening main file for write\n"); - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_PATH-1, "mutex %d %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, SLEEP_LENGTH, RELATION_ID) < 0 ) - { - Trace ("Error: Insufficient commandline string length for for iteration [%d]\n", i); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi[i], sizeof(pi[i]) ); - ZeroMemory ( &si[i], sizeof(si[i]) ); - - /* Set the process flags and standard io handles */ - si[i].cb = sizeof(si[i]); - - //Create Process - if(!CreateProcess( NULL, /* lpApplicationName*/ - lpCommandLine, /* lpCommandLine */ - NULL, /* lpProcessAttributes */ - NULL, /* lpThreadAttributes */ - TRUE, /* bInheritHandles */ - 0, /* dwCreationFlags, */ - NULL, /* lpEnvironment */ - NULL, /* pCurrentDirectory */ - &si[i], /* lpStartupInfo */ - &pi[i] /* lpProcessInformation */ - )) - { - Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); - } - else - { - hProcess[i] = pi[i].hProcess; - // Trace("Process created for [%d]\n", i); - } - - } - - returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); - } - - for( i = 0; i < PROCESS_COUNT; i++ ) - { - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) - { - Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", - i, GetLastError() ); - - testReturnCode = FAIL; - } - - if(processReturnCode == FAIL) - { - Trace( "Process [%d] failed and returned FAIL\n", i); - testReturnCode = FAIL; - } - - if(!CloseHandle(pi[i].hThread)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); - } - - if(!CloseHandle(pi[i].hProcess) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); - } - } - - testStats.operationTime = GetTimeDiff(dwStartTime); - fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile\n"); - testReturnCode = FAIL; - } - - if( testReturnCode == PASS) - { - Trace("Test Passed\n"); - } - else - { - Trace("Test Failed\n"); - } - PAL_Terminate(); - return testReturnCode; -} diff --git a/src/pal/tests/palsuite/composite/wfmo/main.cpp b/src/pal/tests/palsuite/composite/wfmo/main.cpp new file mode 100644 index 0000000000..d186aa7b8b --- /dev/null +++ b/src/pal/tests/palsuite/composite/wfmo/main.cpp @@ -0,0 +1,239 @@ +// 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 Code: main.c and mutex.c +** main.c creates process and waits for all processes to get over +** mutex.c creates a mutex and then calls threads which will contend for the mutex +** +** This test is for WFMO Test case for Mutex +** Algorithm +** o Create PROCESS_COUNT processes. +** o Main Thread of each process creates OBJECT_TYPE Object +** +** Author: ShamitP +** +** +**============================================================ +*/ + +#include +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int PROCESS_COUNT = 3; +unsigned int THREAD_COUNT = 30; +unsigned int REPEAT_COUNT = 40; +unsigned int SLEEP_LENGTH = 4; +unsigned int RELATION_ID = 1001; + + + +struct TestStats{ + DWORD operationTime; + unsigned int relationId; + unsigned int processCount; + unsigned int threadCount; + unsigned int repeatCount; + char* buildNumber; + +}; + +int GetParameters( int argc, char **argv) +{ + if( (argc != 6) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite WFMO Test\n"); + printf("Usage:\n"); + printf("main\n\t[PROCESS_COUNT [greater than 0] \n"); + printf("\t[THREAD_COUNT [greater than 0] \n"); + printf("\t[REPEAT_COUNT [greater than 0]\n"); + printf("\t[SLEEP_LENGTH [greater than 0]\n"); + printf("\t[RELATION_ID [greater than 0]\n"); + + + + return -1; + } + + PROCESS_COUNT = atoi(argv[1]); + if( (PROCESS_COUNT < 1) || (PROCESS_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nMain Process:Invalid PROCESS_COUNT number, Pass greater than 1 and less than PROCESS_COUNT %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nMain Process:Invalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + SLEEP_LENGTH = atoi(argv[4]); + if( SLEEP_LENGTH < 1) + { + printf("\nMain Process:Invalid SLEEP_LENGTH number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[5]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hProcess[MAXIMUM_WAIT_OBJECTS]; + + STARTUPINFO si[MAXIMUM_WAIT_OBJECTS]; + PROCESS_INFORMATION pi[MAXIMUM_WAIT_OBJECTS]; + + char lpCommandLine[MAX_PATH] = ""; + + int returnCode = 0; + DWORD processReturnCode = 0; + int testReturnCode = PASS; + + char fileName[MAX_PATH]; + FILE *pFile = NULL; + DWORD dwStartTime; + struct TestStats testStats; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + testStats.relationId = 0; + testStats.relationId = RELATION_ID; + testStats.processCount = PROCESS_COUNT; + testStats.threadCount = THREAD_COUNT; + testStats.repeatCount = REPEAT_COUNT; + testStats.buildNumber = getBuildNumber(); + + + + _snprintf(fileName, MAX_PATH, "main_wfmo_%d_.txt",testStats.relationId); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening main file for write\n"); + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( _snprintf( lpCommandLine, MAX_PATH-1, "mutex %d %d %d %d %d", i, THREAD_COUNT, REPEAT_COUNT, SLEEP_LENGTH, RELATION_ID) < 0 ) + { + Trace ("Error: Insufficient commandline string length for for iteration [%d]\n", i); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi[i], sizeof(pi[i]) ); + ZeroMemory ( &si[i], sizeof(si[i]) ); + + /* Set the process flags and standard io handles */ + si[i].cb = sizeof(si[i]); + + //Create Process + if(!CreateProcess( NULL, /* lpApplicationName*/ + lpCommandLine, /* lpCommandLine */ + NULL, /* lpProcessAttributes */ + NULL, /* lpThreadAttributes */ + TRUE, /* bInheritHandles */ + 0, /* dwCreationFlags, */ + NULL, /* lpEnvironment */ + NULL, /* pCurrentDirectory */ + &si[i], /* lpStartupInfo */ + &pi[i] /* lpProcessInformation */ + )) + { + Fail("Process Not created for [%d], the error code is [%d]\n", i, GetLastError()); + } + else + { + hProcess[i] = pi[i].hProcess; + // Trace("Process created for [%d]\n", i); + } + + } + + returnCode = WaitForMultipleObjects( PROCESS_COUNT, hProcess, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) @ Main thread for %d processes returned %d, and GetLastError value is %d\n", PROCESS_COUNT, returnCode, GetLastError()); + } + + for( i = 0; i < PROCESS_COUNT; i++ ) + { + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi[i].hProcess, &processReturnCode ) ) + { + Trace( "GetExitCodeProcess call failed for iteration %d with error code %u\n", + i, GetLastError() ); + + testReturnCode = FAIL; + } + + if(processReturnCode == FAIL) + { + Trace( "Process [%d] failed and returned FAIL\n", i); + testReturnCode = FAIL; + } + + if(!CloseHandle(pi[i].hThread)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread\n", GetLastError(), i); + } + + if(!CloseHandle(pi[i].hProcess) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hProcess\n", GetLastError(), i); + } + } + + testStats.operationTime = GetTimeDiff(dwStartTime); + fprintf(pFile, "%d,%d,%d,%d,%d,%s\n", testStats.operationTime, testStats.relationId, testStats.processCount, testStats.threadCount, testStats.repeatCount, testStats.buildNumber); + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile\n"); + testReturnCode = FAIL; + } + + if( testReturnCode == PASS) + { + Trace("Test Passed\n"); + } + else + { + Trace("Test Failed\n"); + } + PAL_Terminate(); + return testReturnCode; +} diff --git a/src/pal/tests/palsuite/composite/wfmo/mutex.c b/src/pal/tests/palsuite/composite/wfmo/mutex.c deleted file mode 100644 index c8ed01426c..0000000000 --- a/src/pal/tests/palsuite/composite/wfmo/mutex.c +++ /dev/null @@ -1,365 +0,0 @@ -// 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 Code: main.c and mutex.c -** main.c creates process and waits for all processes to get over -** mutex.c creates a mutex and then calls threads which will -** contend for the mutex -** -** This test is for WFMO Test case for Mutex -** Algorithm -** o Create PROCESS_COUNT processes. -** o Main Thread of each process creates OBJECT_TYPE Object -** -** Author: ShamitP -** -** -**============================================================ -*/ - -#include -#include "resultbuffer.h" -#include "resulttime.h" - -/* Test Input Variables */ -unsigned int USE_PROCESS_COUNT = 0; -unsigned int THREAD_COUNT = 0; -unsigned int REPEAT_COUNT = 0; -unsigned int SLEEP_LENGTH = 0; -unsigned int RELATION_ID = 1001; - - -/* Capture statistics at per thread basis */ -struct statistics{ - unsigned int processId; - unsigned int operationsFailed; - unsigned int operationsPassed; - unsigned int operationsTotal; - DWORD operationTime; - unsigned int relationId; - -}; - -struct ProcessStats{ - unsigned int processId; - DWORD operationTime; - unsigned int relationId; -}; - -/* Handle to signal threads to start the tests */ -HANDLE StartTestsEvHandle = NULL; -/* Handle to mutex which will be contended by threads */ -HANDLE hMutexHandle = NULL; -/* Results Buffer */ -ResultBuffer *resultBuffer = NULL; - -int testStatus; - -void PALAPI Run_Thread(LPVOID lpParam); - -int GetParameters( int argc, char **argv) -{ - if( (argc != 6) || ((argc == 1) && !strcmp(argv[1],"/?")) - || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) - { - printf("PAL -Composite WFMO Test\n"); - printf("Usage:\n"); - printf("mutex\n\t[USE_PROCESS_COUNT [greater than 0] \n"); - printf("\t[THREAD_COUNT [greater than 0] \n"); - printf("\t[REPEAT_COUNT [greater than 0]\n"); - printf("\t[SLEEP_LENGTH [greater than 0]\n"); - printf("\t[RELATION_ID [greater than 0]\n"); - - - return -1; - } - - // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); - - USE_PROCESS_COUNT = atoi(argv[1]); - if( USE_PROCESS_COUNT < 0) - { - printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); - return -1; - } - - THREAD_COUNT = atoi(argv[2]); - if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) - { - printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); - return -1; - } - - REPEAT_COUNT = atoi(argv[3]); - if( REPEAT_COUNT < 1) - { - printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); - return -1; - } - - SLEEP_LENGTH = atoi(argv[4]); - if( SLEEP_LENGTH < 1) - { - printf("\nMain Process:Invalid SLEEP_LENGTH number, Pass greater than 1\n"); - return -1; - } - - RELATION_ID = atoi(argv[5]); - if( RELATION_ID < 1) - { - printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); - return -1; - } - - return 0; -} - - int __cdecl main(INT argc, CHAR **argv) -{ - unsigned int i = 0; - HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; - DWORD threadId[MAXIMUM_WAIT_OBJECTS]; - int returnCode = 0; - - DWORD dwParam = 0; - - /* Variables to capture the file name and the file pointer at thread level*/ - char fileName[MAX_PATH]; - FILE *pFile = NULL; - struct statistics* buffer = NULL; - int statisticsSize = 0; - - /* Variables to capture the file name and the file pointer at process level*/ - char processFileName[MAX_PATH]; - FILE *pProcessFile = NULL; - struct ProcessStats processStats; - DWORD dwStartTime; - - testStatus = PASS; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(GetParameters(argc, argv)) - { - Fail("Error in obtaining the parameters\n"); - } -// Trace("Process created, value of process count is [%d] and no. of threads is [%d]\n", USE_PROCESS_COUNT, THREAD_COUNT); - - /* Register the start time */ - dwStartTime = GetTickCount(); - processStats.relationId = RELATION_ID; - processStats.processId = USE_PROCESS_COUNT; - - _snprintf(processFileName, MAX_PATH, "%d_process_wfmo_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pProcessFile = fopen(processFileName, "w+"); - if(pProcessFile == NULL) - { - Fail("Error:%d: in opening Process File for write for process [%d]\n", GetLastError(), USE_PROCESS_COUNT); - } - - statisticsSize = sizeof(struct statistics); - - _snprintf(fileName, MAX_PATH, "%d_thread_wfmo_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); - pFile = fopen(fileName, "w+"); - if(pFile == NULL) - { - Fail("Error in opening file for write for process [%d], error [%d]\n", USE_PROCESS_COUNT, GetLastError()); - } - // For each thread we will log operations failed (int), passed (int), total (int) - // and number of ticks (DWORD) for the operations - resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); - - StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ - TRUE, /* bManualReset */ - FALSE, /* bInitialState */ - NULL); /* name of Event */ - - if( StartTestsEvHandle == NULL ) - { - Fail("Error:%d: Unexpected failure " - "to create start tests Event for process count %d\n", GetLastError(), USE_PROCESS_COUNT ); - - } - - /* Create StartTest Event */ - hMutexHandle = CreateMutex( - NULL, - FALSE, /* bInitialOwner, owns initially */ - NULL - ); - - if( hMutexHandle == NULL) - { - Fail("Unable to create Mutex handle for process id [%d], returned error [%d]\n", i, GetLastError()); - } - - /* We already assume that the mutex was created previously*/ - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - - } - - if (!SetEvent(StartTestsEvHandle)) - { - Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); - } - /* Test running */ - - if( THREAD_COUNT != 1 ) - { - returnCode = WaitForMultipleObjects(THREAD_COUNT, hThread, TRUE, INFINITE); - } - else - { - returnCode = WaitForSingleObject(hThread[0], INFINITE); - } - - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); - testStatus = FAIL; - } - - processStats.operationTime = GetTimeDiff(dwStartTime); - - /* Write to a file*/ - if(pFile!= NULL) - { - for( i = 0; i < THREAD_COUNT; i++ ) - { - buffer = (struct statistics *)resultBuffer->getResultBuffer(i); - returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); - //Trace("Iteration %d over\n", i); - - } - } - if(fclose(pFile)) - { - Trace("Error: fclose failed for pFile at Process %d\n", USE_PROCESS_COUNT); - testStatus = FAIL; - } - - fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); - if(fclose(pProcessFile)) - { - Trace("Error: fclose failed for pProcessFile at Process %d\n", USE_PROCESS_COUNT); - testStatus = FAIL; - } - - /* Logging for the test case over, clean up the handles */ - // Trace("Test Process %d done\n", USE_PROCESS_COUNT); - //Trace("Contents of the buffer are [%s]\n", resultBuffer->getResultBuffer()); - for( i = 0; i < THREAD_COUNT; i++ ) - { - if(!CloseHandle(hThread[i]) ) - { - Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); - testStatus = FAIL; - } - } - - if(!CloseHandle(StartTestsEvHandle)) - { - Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); - testStatus = FAIL; - } - - PAL_Terminate(); - return testStatus; -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - unsigned int i = 0; - struct statistics stats; - - DWORD dwWaitResult; - DWORD dwStartTime; - - stats.relationId = RELATION_ID; - stats.processId = USE_PROCESS_COUNT; - stats.operationsFailed = 0; - stats.operationsPassed = 0; - stats.operationsTotal = 0; - stats.operationTime = 0; - - int Id=(int)lpParam; - - dwWaitResult = WaitForSingleObject( - StartTestsEvHandle, // handle to mutex - INFINITE); - - if(dwWaitResult != WAIT_OBJECT_0) - { - Trace("Error:%d: while waiting for StartTest Event@ thread %d\n", GetLastError(), Id); - testStatus = FAIL; - } - - /* Register the start time */ - dwStartTime = GetTickCount(); - - /* Run the tests repeat count times */ - for( i = 0; i < REPEAT_COUNT; i++ ) - { - dwWaitResult = WaitForSingleObject( - hMutexHandle, // handle to mutex - INFINITE); - - if(dwWaitResult != WAIT_OBJECT_0) - { - Trace("Error:%d: while waiting for onject @ thread %d, # iter %d\n", GetLastError(), Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - testStatus = FAIL; - continue; - } - - Sleep(SLEEP_LENGTH); - - if (!ReleaseMutex(hMutexHandle)) - { - // Deal with error. - Trace("Error:%d: while releasing mutex @ thread %d # iter %d\n", GetLastError(), Id, i); - stats.operationsFailed += 1; - stats.operationsTotal += 1; - // do we need to have while true loop to attempt to release mutex...? - testStatus = FAIL; - continue; - } - - stats.operationsTotal += 1; - stats.operationsPassed += 1; - -// Trace("Successs while releasing mutex @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); - - } - - stats.operationTime = GetTimeDiff(dwStartTime); - // Trace("Operation Time %lu, Process Count [%d], ThreadCount[%d]\n", stats.operationTime, USE_PROCESS_COUNT, Id); - - if(resultBuffer->LogResult(Id, (char *)&stats)) - { - Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); - } - // Trace("Contents of the buffer are after thread [%d]\n", Id); -} diff --git a/src/pal/tests/palsuite/composite/wfmo/mutex.cpp b/src/pal/tests/palsuite/composite/wfmo/mutex.cpp new file mode 100644 index 0000000000..c8ed01426c --- /dev/null +++ b/src/pal/tests/palsuite/composite/wfmo/mutex.cpp @@ -0,0 +1,365 @@ +// 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 Code: main.c and mutex.c +** main.c creates process and waits for all processes to get over +** mutex.c creates a mutex and then calls threads which will +** contend for the mutex +** +** This test is for WFMO Test case for Mutex +** Algorithm +** o Create PROCESS_COUNT processes. +** o Main Thread of each process creates OBJECT_TYPE Object +** +** Author: ShamitP +** +** +**============================================================ +*/ + +#include +#include "resultbuffer.h" +#include "resulttime.h" + +/* Test Input Variables */ +unsigned int USE_PROCESS_COUNT = 0; +unsigned int THREAD_COUNT = 0; +unsigned int REPEAT_COUNT = 0; +unsigned int SLEEP_LENGTH = 0; +unsigned int RELATION_ID = 1001; + + +/* Capture statistics at per thread basis */ +struct statistics{ + unsigned int processId; + unsigned int operationsFailed; + unsigned int operationsPassed; + unsigned int operationsTotal; + DWORD operationTime; + unsigned int relationId; + +}; + +struct ProcessStats{ + unsigned int processId; + DWORD operationTime; + unsigned int relationId; +}; + +/* Handle to signal threads to start the tests */ +HANDLE StartTestsEvHandle = NULL; +/* Handle to mutex which will be contended by threads */ +HANDLE hMutexHandle = NULL; +/* Results Buffer */ +ResultBuffer *resultBuffer = NULL; + +int testStatus; + +void PALAPI Run_Thread(LPVOID lpParam); + +int GetParameters( int argc, char **argv) +{ + if( (argc != 6) || ((argc == 1) && !strcmp(argv[1],"/?")) + || !strcmp(argv[1],"/h") || !strcmp(argv[1],"/H")) + { + printf("PAL -Composite WFMO Test\n"); + printf("Usage:\n"); + printf("mutex\n\t[USE_PROCESS_COUNT [greater than 0] \n"); + printf("\t[THREAD_COUNT [greater than 0] \n"); + printf("\t[REPEAT_COUNT [greater than 0]\n"); + printf("\t[SLEEP_LENGTH [greater than 0]\n"); + printf("\t[RELATION_ID [greater than 0]\n"); + + + return -1; + } + + // Trace("Args 1 is [%s], Arg 2 is [%s], Arg 3 is [%s]\n", argv[1], argv[2], argv[3]); + + USE_PROCESS_COUNT = atoi(argv[1]); + if( USE_PROCESS_COUNT < 0) + { + printf("\nInvalid USE_PROCESS_COUNT number, Pass greater than 1\n"); + return -1; + } + + THREAD_COUNT = atoi(argv[2]); + if( (THREAD_COUNT < 1) || (THREAD_COUNT > MAXIMUM_WAIT_OBJECTS) ) + { + printf("\nInvalid THREAD_COUNT number, Pass greater than 1 and less than %d\n", MAXIMUM_WAIT_OBJECTS); + return -1; + } + + REPEAT_COUNT = atoi(argv[3]); + if( REPEAT_COUNT < 1) + { + printf("\nInvalid REPEAT_COUNT number, Pass greater than 1\n"); + return -1; + } + + SLEEP_LENGTH = atoi(argv[4]); + if( SLEEP_LENGTH < 1) + { + printf("\nMain Process:Invalid SLEEP_LENGTH number, Pass greater than 1\n"); + return -1; + } + + RELATION_ID = atoi(argv[5]); + if( RELATION_ID < 1) + { + printf("\nMain Process:Invalid RELATION_ID number, Pass greater than 1\n"); + return -1; + } + + return 0; +} + + int __cdecl main(INT argc, CHAR **argv) +{ + unsigned int i = 0; + HANDLE hThread[MAXIMUM_WAIT_OBJECTS]; + DWORD threadId[MAXIMUM_WAIT_OBJECTS]; + int returnCode = 0; + + DWORD dwParam = 0; + + /* Variables to capture the file name and the file pointer at thread level*/ + char fileName[MAX_PATH]; + FILE *pFile = NULL; + struct statistics* buffer = NULL; + int statisticsSize = 0; + + /* Variables to capture the file name and the file pointer at process level*/ + char processFileName[MAX_PATH]; + FILE *pProcessFile = NULL; + struct ProcessStats processStats; + DWORD dwStartTime; + + testStatus = PASS; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(GetParameters(argc, argv)) + { + Fail("Error in obtaining the parameters\n"); + } +// Trace("Process created, value of process count is [%d] and no. of threads is [%d]\n", USE_PROCESS_COUNT, THREAD_COUNT); + + /* Register the start time */ + dwStartTime = GetTickCount(); + processStats.relationId = RELATION_ID; + processStats.processId = USE_PROCESS_COUNT; + + _snprintf(processFileName, MAX_PATH, "%d_process_wfmo_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pProcessFile = fopen(processFileName, "w+"); + if(pProcessFile == NULL) + { + Fail("Error:%d: in opening Process File for write for process [%d]\n", GetLastError(), USE_PROCESS_COUNT); + } + + statisticsSize = sizeof(struct statistics); + + _snprintf(fileName, MAX_PATH, "%d_thread_wfmo_%d_.txt", USE_PROCESS_COUNT, RELATION_ID); + pFile = fopen(fileName, "w+"); + if(pFile == NULL) + { + Fail("Error in opening file for write for process [%d], error [%d]\n", USE_PROCESS_COUNT, GetLastError()); + } + // For each thread we will log operations failed (int), passed (int), total (int) + // and number of ticks (DWORD) for the operations + resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize); + + StartTestsEvHandle = CreateEvent( NULL, /* lpEventAttributes*/ + TRUE, /* bManualReset */ + FALSE, /* bInitialState */ + NULL); /* name of Event */ + + if( StartTestsEvHandle == NULL ) + { + Fail("Error:%d: Unexpected failure " + "to create start tests Event for process count %d\n", GetLastError(), USE_PROCESS_COUNT ); + + } + + /* Create StartTest Event */ + hMutexHandle = CreateMutex( + NULL, + FALSE, /* bInitialOwner, owns initially */ + NULL + ); + + if( hMutexHandle == NULL) + { + Fail("Unable to create Mutex handle for process id [%d], returned error [%d]\n", i, GetLastError()); + } + + /* We already assume that the mutex was created previously*/ + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + + } + + if (!SetEvent(StartTestsEvHandle)) + { + Fail("Set Event for Start Tests failed for %d process, and GetLastError value is %d\n", USE_PROCESS_COUNT, GetLastError()); + } + /* Test running */ + + if( THREAD_COUNT != 1 ) + { + returnCode = WaitForMultipleObjects(THREAD_COUNT, hThread, TRUE, INFINITE); + } + else + { + returnCode = WaitForSingleObject(hThread[0], INFINITE); + } + + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) for %d process returned %d, and GetLastError value is %d\n", USE_PROCESS_COUNT, returnCode, GetLastError()); + testStatus = FAIL; + } + + processStats.operationTime = GetTimeDiff(dwStartTime); + + /* Write to a file*/ + if(pFile!= NULL) + { + for( i = 0; i < THREAD_COUNT; i++ ) + { + buffer = (struct statistics *)resultBuffer->getResultBuffer(i); + returnCode = fprintf(pFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId ); + //Trace("Iteration %d over\n", i); + + } + } + if(fclose(pFile)) + { + Trace("Error: fclose failed for pFile at Process %d\n", USE_PROCESS_COUNT); + testStatus = FAIL; + } + + fprintf(pProcessFile, "%d,%d,%d\n", USE_PROCESS_COUNT, processStats.operationTime, processStats.relationId ); + if(fclose(pProcessFile)) + { + Trace("Error: fclose failed for pProcessFile at Process %d\n", USE_PROCESS_COUNT); + testStatus = FAIL; + } + + /* Logging for the test case over, clean up the handles */ + // Trace("Test Process %d done\n", USE_PROCESS_COUNT); + //Trace("Contents of the buffer are [%s]\n", resultBuffer->getResultBuffer()); + for( i = 0; i < THREAD_COUNT; i++ ) + { + if(!CloseHandle(hThread[i]) ) + { + Trace("Error:%d: CloseHandle failed for Process [%d] hThread[%d]\n", GetLastError(), USE_PROCESS_COUNT, i); + testStatus = FAIL; + } + } + + if(!CloseHandle(StartTestsEvHandle)) + { + Trace("Error:%d: CloseHandle failed for Process [%d] StartTestsEvHandle\n", GetLastError(), USE_PROCESS_COUNT); + testStatus = FAIL; + } + + PAL_Terminate(); + return testStatus; +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + unsigned int i = 0; + struct statistics stats; + + DWORD dwWaitResult; + DWORD dwStartTime; + + stats.relationId = RELATION_ID; + stats.processId = USE_PROCESS_COUNT; + stats.operationsFailed = 0; + stats.operationsPassed = 0; + stats.operationsTotal = 0; + stats.operationTime = 0; + + int Id=(int)lpParam; + + dwWaitResult = WaitForSingleObject( + StartTestsEvHandle, // handle to mutex + INFINITE); + + if(dwWaitResult != WAIT_OBJECT_0) + { + Trace("Error:%d: while waiting for StartTest Event@ thread %d\n", GetLastError(), Id); + testStatus = FAIL; + } + + /* Register the start time */ + dwStartTime = GetTickCount(); + + /* Run the tests repeat count times */ + for( i = 0; i < REPEAT_COUNT; i++ ) + { + dwWaitResult = WaitForSingleObject( + hMutexHandle, // handle to mutex + INFINITE); + + if(dwWaitResult != WAIT_OBJECT_0) + { + Trace("Error:%d: while waiting for onject @ thread %d, # iter %d\n", GetLastError(), Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + testStatus = FAIL; + continue; + } + + Sleep(SLEEP_LENGTH); + + if (!ReleaseMutex(hMutexHandle)) + { + // Deal with error. + Trace("Error:%d: while releasing mutex @ thread %d # iter %d\n", GetLastError(), Id, i); + stats.operationsFailed += 1; + stats.operationsTotal += 1; + // do we need to have while true loop to attempt to release mutex...? + testStatus = FAIL; + continue; + } + + stats.operationsTotal += 1; + stats.operationsPassed += 1; + +// Trace("Successs while releasing mutex @ iteration %d -> thread %d -> Process %d\n", i, Id, USE_PROCESS_COUNT); + + } + + stats.operationTime = GetTimeDiff(dwStartTime); + // Trace("Operation Time %lu, Process Count [%d], ThreadCount[%d]\n", stats.operationTime, USE_PROCESS_COUNT, Id); + + if(resultBuffer->LogResult(Id, (char *)&stats)) + { + Fail("Error:%d: while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", GetLastError(), Id, USE_PROCESS_COUNT); + } + // Trace("Contents of the buffer are after thread [%d]\n", Id); +} diff --git a/src/pal/tests/palsuite/debug_api/DebugBreak/test1/CMakeLists.txt b/src/pal/tests/palsuite/debug_api/DebugBreak/test1/CMakeLists.txt index db66cbe1d0..1b2ae538cc 100644 --- a/src/pal/tests/palsuite/debug_api/DebugBreak/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/debug_api/DebugBreak/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_debugbreak_test1 diff --git a/src/pal/tests/palsuite/debug_api/DebugBreak/test1/test1.c b/src/pal/tests/palsuite/debug_api/DebugBreak/test1/test1.c deleted file mode 100644 index 2b10b9ad9d..0000000000 --- a/src/pal/tests/palsuite/debug_api/DebugBreak/test1/test1.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that DebugBreak works in the grossest fashion. -** -** -**============================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bTry = FALSE; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - PAL_TRY - { - DebugBreak(); - if (!bTry) - { - Fail("DebugBreak: Continued in Try block.\n"); - } - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - bTry = TRUE; - } - PAL_ENDTRY; - - if (!bTry) - { - Fail("DebugBreak: Did not reach the exception block.\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/debug_api/DebugBreak/test1/test1.cpp b/src/pal/tests/palsuite/debug_api/DebugBreak/test1/test1.cpp new file mode 100644 index 0000000000..2b10b9ad9d --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/DebugBreak/test1/test1.cpp @@ -0,0 +1,47 @@ +// 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: test1.c +** +** Purpose: Tests that DebugBreak works in the grossest fashion. +** +** +**============================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bTry = FALSE; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + PAL_TRY + { + DebugBreak(); + if (!bTry) + { + Fail("DebugBreak: Continued in Try block.\n"); + } + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + bTry = TRUE; + } + PAL_ENDTRY; + + if (!bTry) + { + Fail("DebugBreak: Did not reach the exception block.\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/CMakeLists.txt b/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/CMakeLists.txt index 5bc7fdb6e9..3000734afe 100644 --- a/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test1.c + test1.cpp ) add_executable(paltest_outputdebugstringa_test1 @@ -20,7 +20,7 @@ target_link_libraries(paltest_outputdebugstringa_test1 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_outputdebugstringa_test1_helper diff --git a/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/helper.c b/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/helper.c deleted file mode 100644 index 90073dfedd..0000000000 --- a/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/helper.c +++ /dev/null @@ -1,35 +0,0 @@ -// 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: helper.c -** -** Purpose: Intended to be the child process of a debugger. Calls -** OutputDebugStringA once with a normal string, once with an empty -** string -** -** -**============================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - OutputDebugStringA("Foo!\n"); - - OutputDebugStringA(""); - - /* give a chance to the debugger process to read the debug string before - exiting */ - Sleep(1000); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/helper.cpp b/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/helper.cpp new file mode 100644 index 0000000000..90073dfedd --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/helper.cpp @@ -0,0 +1,35 @@ +// 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: helper.c +** +** Purpose: Intended to be the child process of a debugger. Calls +** OutputDebugStringA once with a normal string, once with an empty +** string +** +** +**============================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + OutputDebugStringA("Foo!\n"); + + OutputDebugStringA(""); + + /* give a chance to the debugger process to read the debug string before + exiting */ + Sleep(1000); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/test1.c b/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/test1.c deleted file mode 100644 index 080c6ac53e..0000000000 --- a/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/test1.c +++ /dev/null @@ -1,94 +0,0 @@ -// 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: test1.c -** -** Purpose: Debugs the helper application. Checks that certain events, in -** particular the OUTPUT_DEBUG_STRING_EVENT, is generated correctly -** and gives the correct values. -** -** -**============================================================*/ - -#include - -const int DELAY_MS = 2000; - -struct OutputCheck -{ - DWORD ExpectedEventCode; - DWORD ExpectedUnicode; - char *ExpectedStr; -}; - -int __cdecl main(int argc, char *argv[]) -{ - - PROCESS_INFORMATION pi; - STARTUPINFO si; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - /* Create a new process. This is the process to be Debugged */ - if(!CreateProcess( NULL, "helper", NULL, NULL, - FALSE, 0, NULL, NULL, &si, &pi)) - { - Fail("ERROR: CreateProcess failed to load executable 'helper'. " - "GetLastError() returned %d.\n",GetLastError()); - } - - /* This is the main loop. It exits when the process which is being - debugged is finished executing. - */ - - while(1) - { - DWORD dwRet = 0; - dwRet = WaitForSingleObject(pi.hProcess, - DELAY_MS /* Wait for 2 seconds max*/ - ); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("WaitForSingleObjectTest:WaitForSingleObject " - "failed (%x) after waiting %d seconds for the helper\n", - GetLastError(), DELAY_MS / 1000); - } - else - { - DWORD dwExitCode; - - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) - { - DWORD dwError; - - dwError = GetLastError(); - CloseHandle ( pi.hProcess ); - CloseHandle ( pi.hThread ); - Fail( "GetExitCodeProcess call failed with error code %d\n", - dwError ); - } - - if(dwExitCode != STILL_ACTIVE) { - CloseHandle(pi.hThread); - CloseHandle(pi.hProcess); - break; - } - Trace("still executing %d..\n", dwExitCode); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/test1.cpp b/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/test1.cpp new file mode 100644 index 0000000000..080c6ac53e --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/OutputDebugStringA/test1/test1.cpp @@ -0,0 +1,94 @@ +// 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: test1.c +** +** Purpose: Debugs the helper application. Checks that certain events, in +** particular the OUTPUT_DEBUG_STRING_EVENT, is generated correctly +** and gives the correct values. +** +** +**============================================================*/ + +#include + +const int DELAY_MS = 2000; + +struct OutputCheck +{ + DWORD ExpectedEventCode; + DWORD ExpectedUnicode; + char *ExpectedStr; +}; + +int __cdecl main(int argc, char *argv[]) +{ + + PROCESS_INFORMATION pi; + STARTUPINFO si; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + /* Create a new process. This is the process to be Debugged */ + if(!CreateProcess( NULL, "helper", NULL, NULL, + FALSE, 0, NULL, NULL, &si, &pi)) + { + Fail("ERROR: CreateProcess failed to load executable 'helper'. " + "GetLastError() returned %d.\n",GetLastError()); + } + + /* This is the main loop. It exits when the process which is being + debugged is finished executing. + */ + + while(1) + { + DWORD dwRet = 0; + dwRet = WaitForSingleObject(pi.hProcess, + DELAY_MS /* Wait for 2 seconds max*/ + ); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("WaitForSingleObjectTest:WaitForSingleObject " + "failed (%x) after waiting %d seconds for the helper\n", + GetLastError(), DELAY_MS / 1000); + } + else + { + DWORD dwExitCode; + + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) + { + DWORD dwError; + + dwError = GetLastError(); + CloseHandle ( pi.hProcess ); + CloseHandle ( pi.hThread ); + Fail( "GetExitCodeProcess call failed with error code %d\n", + dwError ); + } + + if(dwExitCode != STILL_ACTIVE) { + CloseHandle(pi.hThread); + CloseHandle(pi.hProcess); + break; + } + Trace("still executing %d..\n", dwExitCode); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/CMakeLists.txt b/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/CMakeLists.txt index 9202baeaef..4a93f0e394 100644 --- a/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_outputdebugstringw_test1 diff --git a/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/test1.c b/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/test1.c deleted file mode 100644 index 88b55427bc..0000000000 --- a/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/test1.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: test1.c -** -** Purpose: Intended to be the child process of a debugger. Calls -** OutputDebugStringW once with a normal string, once with an empty -** string -** -** -**============================================================*/ - -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR *str1; - WCHAR *str2; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - str1 = convert("Foo!"); - str2 = convert(""); - - OutputDebugStringW(str1); - - OutputDebugStringW(str2); - - free(str1); - free(str2); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/test1.cpp b/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/test1.cpp new file mode 100644 index 0000000000..88b55427bc --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/OutputDebugStringW/test1/test1.cpp @@ -0,0 +1,41 @@ +// 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: test1.c +** +** Purpose: Intended to be the child process of a debugger. Calls +** OutputDebugStringW once with a normal string, once with an empty +** string +** +** +**============================================================*/ + +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR *str1; + WCHAR *str2; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + str1 = convert("Foo!"); + str2 = convert(""); + + OutputDebugStringW(str1); + + OutputDebugStringW(str2); + + free(str1); + free(str2); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/CMakeLists.txt b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/CMakeLists.txt index 39130aac1c..afd581fb92 100644 --- a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test1.c + test1.cpp ) add_executable(paltest_writeprocessmemory_test1 @@ -20,7 +20,7 @@ target_link_libraries(paltest_writeprocessmemory_test1 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_writeprocessmemory_test1_helper diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/helper.c b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/helper.c deleted file mode 100644 index 1a7318969c..0000000000 --- a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/helper.c +++ /dev/null @@ -1,243 +0,0 @@ -// 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: helper.c -** -** Purpose: This helper process sets up a several blocks of memory, -** then uses a file to tell its parent process where that memory is -** So it can do a WriteProcessMemory on it. When the parent process is done -** we check here that it was written properly. -** -** -**============================================================*/ - -#include "commonconsts.h" - -#include - -struct allhandles_t -{ - HANDLE hEvToHelper; - HANDLE hEvFromHelper; - char *valuesFileName; -}; - - -/* function: wpmDoIt - * - * This is a general WriteProcessMemory testing function that sets up - * the RAM pointed to and tells the companion process on the other end - * of the handles in 'Comms' to attempt to alter 'lenDest' bytes at - * '*pDest'. - * - * '*pBuffer'[0..'lenBuffer'] is expected to be a guard region - * surrounding the '*pDest'[0..'lenDest'] region so that this function - * can verify that only the proper bytes were altered. - */ - -int wpmDoIt(struct allhandles_t Comms, - char * pBuffer, unsigned int lenBuffer, - char * pDest, unsigned int lenDest, - const char* storageDescription) -{ - char *pCurr; - FILE *commsFile; - DWORD dwRet; - - if (pBuffer > pDest || lenDest > lenBuffer) - { - Trace("WriteProcessMemory::DoIt() test implementation: " - "(pBuffer > pDest || lenDest > lenBuffer)\n"); - return FALSE; - } - - /* set up the storage */ - memset(pBuffer, guardValue, lenBuffer); - memset(pDest, initialValue, lenDest); - - /* tell the parent what RAM to adjust */ - if(!(commsFile = fopen(Comms.valuesFileName, "w"))) - { - Trace("WriteProcessMemory: fopen of '%S' failed (%u). \n", - Comms.valuesFileName, GetLastError()); - return FALSE; - } - if (!fprintf(commsFile, "%u %u '%s'\n", - pDest, lenDest, storageDescription)) - { - Trace("WriteProcessMemory: fprintf to '%S' failed (%u). \n", - Comms.valuesFileName, GetLastError()); - return FALSE; - } - PEDANTIC1(fclose, (commsFile)); - - /* Tell the parent the data is ready for it to adjust */ - PEDANTIC(ResetEvent, (Comms.hEvToHelper)); - PEDANTIC(SetEvent, (Comms.hEvFromHelper)); - - dwRet = WaitForSingleObject(Comms.hEvToHelper, TIMEOUT); /* parent is done */ - if (dwRet != WAIT_OBJECT_0) - { - Trace("helper WaitForSingleObjectTest: WaitForSingleObject " - "failed (%u)\n", GetLastError()); - return FALSE; - } - - /* check the stuff that SHOULD have changed */ - for (pCurr = pDest; pCurr < (pDest + lenDest); pCurr++) - { - if ( *pCurr != nextValue) - { - Trace("When testing '%s': alteration test failed " - "at %u offset %u. Found '%c' instead of '%c'\n.", - storageDescription, pDest, pCurr - pDest, *pCurr, nextValue); - Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer); - return FALSE; - } - } - /* check the stuff that should NOT have changed */ - for (pCurr = pBuffer; pCurr < pDest; pCurr++ ) - { - if ( *pCurr != guardValue) - { - Trace("When testing '%s': leading guard zone test failed " - "at %u offset %u. Found '%c' instead of '%c'\n.", - storageDescription, pDest, pCurr - pBuffer, *pCurr, guardValue); - Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer); - return FALSE; - } - } - for (pCurr = pDest + lenDest; pCurr < (pBuffer + lenBuffer); pCurr++ ) - { - if ( *pCurr != guardValue) - { - Trace("When testing '%s': trailing guard zone test failed " - "at %u offset %u. Found '%c' instead of '%c'\n.", - storageDescription, pDest + lenDest, pCurr - pBuffer, *pCurr, guardValue); - Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer); - return FALSE; - } - } - - return TRUE; -} - -int __cdecl main(int argc, char *argv[]) -{ - - BOOL success = TRUE; /* assume success */ - struct allhandles_t Comms = {0,0,0} ; - - /* variables to track storage to alter */ - char *pTarget = NULL; - unsigned int sizeTarget; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* hook up with the events created by the parent */ - Comms.hEvToHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcToHelperEvName); - if (!Comms.hEvToHelper) - { - Fail("WriteProcessMemory: OpenEvent of '%S' failed (%u). " - "(the event should already exist!)\n", - szcToHelperEvName, GetLastError()); - } - Comms.hEvFromHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcFromHelperEvName); - if (!Comms.hEvToHelper) - { - Trace("WriteProcessMemory: OpenEvent of '%S' failed (%u). " - "(the event should already exist!)\n", - szcFromHelperEvName, GetLastError()); - success = FALSE; - goto EXIT; - } - Comms.valuesFileName = argv[1]; - - { - char autoAllocatedOnStack[51]; - - /* Get the parent process to write to the local stack */ - success &= wpmDoIt(Comms, autoAllocatedOnStack, - sizeof(autoAllocatedOnStack), - autoAllocatedOnStack + sizeof(int), - sizeof(autoAllocatedOnStack) - 2 * sizeof(int), - "const size array on stack with int sized guards"); - } - - /* Get the parent process to write to stuff on the heap */ - sizeTarget = 2 * sizeof(int) + 23 ; /* 23 is just a random prime > 16 */ - if (!(pTarget = malloc(sizeTarget))) - { - Trace("WriteProcessMemory helper: unable to allocate '%s'->%d bytes of memory" - "(%u).\n", - argv[3], sizeTarget, GetLastError()); - success = FALSE; - goto EXIT; - - } - success &= wpmDoIt(Comms, pTarget, sizeTarget, - pTarget + sizeof(int), - sizeTarget - 2 * sizeof(int), - "array on heap with int sized guards"); - - /* just to be nice try something 16 - 2 * sizeof(int) bytes long */ - { - char autoAllocatedOnStack[16]; - - /* Get the parent process to write to the local stack */ - success &= wpmDoIt(Comms, autoAllocatedOnStack, - sizeof(autoAllocatedOnStack), - autoAllocatedOnStack + sizeof(int), - sizeof(autoAllocatedOnStack) - 2 * sizeof(int), - "another 16 byte array on stack with int sized guards inside"); - } - - /* NOTE: Don't try 0 bytes long. Win32 WriteProcessMemory claims - * it writes 8 bytes in that case! */ - - /* and 1 byte long... */ - { - char autoAllocatedOnStack[1+ 2 * sizeof(int)]; - - /* Get the parent process to write to the local stack */ - success &= wpmDoIt(Comms, autoAllocatedOnStack, - sizeof(autoAllocatedOnStack), - autoAllocatedOnStack + sizeof(int), - 1, - "no bytes with int sized guards outside on stack"); - } - - -EXIT: - /* Tell the parent that we are done */ - if (!DeleteFile(Comms.valuesFileName)) - { - Trace("helper: DeleteFile failed so parent (test1) is unlikely " - "to exit cleanly\n"); - } - PEDANTIC(ResetEvent, (Comms.hEvToHelper)); - if (!SetEvent(Comms.hEvFromHelper)) - { - Trace("helper: SetEvent failed so parent (test1) is unlikely " - "to exit cleanly\n"); - } - - free(pTarget); - PEDANTIC(CloseHandle, (Comms.hEvToHelper)); - PEDANTIC(CloseHandle, (Comms.hEvFromHelper)); - - if (!success) - { - Fail(""); - } - - PAL_Terminate(); - - return success ? PASS : FAIL; -} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/helper.cpp b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/helper.cpp new file mode 100644 index 0000000000..d965ca7a51 --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/helper.cpp @@ -0,0 +1,243 @@ +// 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: helper.c +** +** Purpose: This helper process sets up a several blocks of memory, +** then uses a file to tell its parent process where that memory is +** So it can do a WriteProcessMemory on it. When the parent process is done +** we check here that it was written properly. +** +** +**============================================================*/ + +#include "commonconsts.h" + +#include + +struct allhandles_t +{ + HANDLE hEvToHelper; + HANDLE hEvFromHelper; + char *valuesFileName; +}; + + +/* function: wpmDoIt + * + * This is a general WriteProcessMemory testing function that sets up + * the RAM pointed to and tells the companion process on the other end + * of the handles in 'Comms' to attempt to alter 'lenDest' bytes at + * '*pDest'. + * + * '*pBuffer'[0..'lenBuffer'] is expected to be a guard region + * surrounding the '*pDest'[0..'lenDest'] region so that this function + * can verify that only the proper bytes were altered. + */ + +int wpmDoIt(struct allhandles_t Comms, + char * pBuffer, unsigned int lenBuffer, + char * pDest, unsigned int lenDest, + const char* storageDescription) +{ + char *pCurr; + FILE *commsFile; + DWORD dwRet; + + if (pBuffer > pDest || lenDest > lenBuffer) + { + Trace("WriteProcessMemory::DoIt() test implementation: " + "(pBuffer > pDest || lenDest > lenBuffer)\n"); + return FALSE; + } + + /* set up the storage */ + memset(pBuffer, guardValue, lenBuffer); + memset(pDest, initialValue, lenDest); + + /* tell the parent what RAM to adjust */ + if(!(commsFile = fopen(Comms.valuesFileName, "w"))) + { + Trace("WriteProcessMemory: fopen of '%S' failed (%u). \n", + Comms.valuesFileName, GetLastError()); + return FALSE; + } + if (!fprintf(commsFile, "%u %u '%s'\n", + pDest, lenDest, storageDescription)) + { + Trace("WriteProcessMemory: fprintf to '%S' failed (%u). \n", + Comms.valuesFileName, GetLastError()); + return FALSE; + } + PEDANTIC1(fclose, (commsFile)); + + /* Tell the parent the data is ready for it to adjust */ + PEDANTIC(ResetEvent, (Comms.hEvToHelper)); + PEDANTIC(SetEvent, (Comms.hEvFromHelper)); + + dwRet = WaitForSingleObject(Comms.hEvToHelper, TIMEOUT); /* parent is done */ + if (dwRet != WAIT_OBJECT_0) + { + Trace("helper WaitForSingleObjectTest: WaitForSingleObject " + "failed (%u)\n", GetLastError()); + return FALSE; + } + + /* check the stuff that SHOULD have changed */ + for (pCurr = pDest; pCurr < (pDest + lenDest); pCurr++) + { + if ( *pCurr != nextValue) + { + Trace("When testing '%s': alteration test failed " + "at %u offset %u. Found '%c' instead of '%c'\n.", + storageDescription, pDest, pCurr - pDest, *pCurr, nextValue); + Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer); + return FALSE; + } + } + /* check the stuff that should NOT have changed */ + for (pCurr = pBuffer; pCurr < pDest; pCurr++ ) + { + if ( *pCurr != guardValue) + { + Trace("When testing '%s': leading guard zone test failed " + "at %u offset %u. Found '%c' instead of '%c'\n.", + storageDescription, pDest, pCurr - pBuffer, *pCurr, guardValue); + Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer); + return FALSE; + } + } + for (pCurr = pDest + lenDest; pCurr < (pBuffer + lenBuffer); pCurr++ ) + { + if ( *pCurr != guardValue) + { + Trace("When testing '%s': trailing guard zone test failed " + "at %u offset %u. Found '%c' instead of '%c'\n.", + storageDescription, pDest + lenDest, pCurr - pBuffer, *pCurr, guardValue); + Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer); + return FALSE; + } + } + + return TRUE; +} + +int __cdecl main(int argc, char *argv[]) +{ + + BOOL success = TRUE; /* assume success */ + struct allhandles_t Comms = {0,0,0} ; + + /* variables to track storage to alter */ + char *pTarget = NULL; + unsigned int sizeTarget; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* hook up with the events created by the parent */ + Comms.hEvToHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcToHelperEvName); + if (!Comms.hEvToHelper) + { + Fail("WriteProcessMemory: OpenEvent of '%S' failed (%u). " + "(the event should already exist!)\n", + szcToHelperEvName, GetLastError()); + } + Comms.hEvFromHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcFromHelperEvName); + if (!Comms.hEvToHelper) + { + Trace("WriteProcessMemory: OpenEvent of '%S' failed (%u). " + "(the event should already exist!)\n", + szcFromHelperEvName, GetLastError()); + success = FALSE; + goto EXIT; + } + Comms.valuesFileName = argv[1]; + + { + char autoAllocatedOnStack[51]; + + /* Get the parent process to write to the local stack */ + success &= wpmDoIt(Comms, autoAllocatedOnStack, + sizeof(autoAllocatedOnStack), + autoAllocatedOnStack + sizeof(int), + sizeof(autoAllocatedOnStack) - 2 * sizeof(int), + "const size array on stack with int sized guards"); + } + + /* Get the parent process to write to stuff on the heap */ + sizeTarget = 2 * sizeof(int) + 23 ; /* 23 is just a random prime > 16 */ + if (!(pTarget = (char*)malloc(sizeTarget))) + { + Trace("WriteProcessMemory helper: unable to allocate '%s'->%d bytes of memory" + "(%u).\n", + argv[3], sizeTarget, GetLastError()); + success = FALSE; + goto EXIT; + + } + success &= wpmDoIt(Comms, pTarget, sizeTarget, + pTarget + sizeof(int), + sizeTarget - 2 * sizeof(int), + "array on heap with int sized guards"); + + /* just to be nice try something 16 - 2 * sizeof(int) bytes long */ + { + char autoAllocatedOnStack[16]; + + /* Get the parent process to write to the local stack */ + success &= wpmDoIt(Comms, autoAllocatedOnStack, + sizeof(autoAllocatedOnStack), + autoAllocatedOnStack + sizeof(int), + sizeof(autoAllocatedOnStack) - 2 * sizeof(int), + "another 16 byte array on stack with int sized guards inside"); + } + + /* NOTE: Don't try 0 bytes long. Win32 WriteProcessMemory claims + * it writes 8 bytes in that case! */ + + /* and 1 byte long... */ + { + char autoAllocatedOnStack[1+ 2 * sizeof(int)]; + + /* Get the parent process to write to the local stack */ + success &= wpmDoIt(Comms, autoAllocatedOnStack, + sizeof(autoAllocatedOnStack), + autoAllocatedOnStack + sizeof(int), + 1, + "no bytes with int sized guards outside on stack"); + } + + +EXIT: + /* Tell the parent that we are done */ + if (!DeleteFile(Comms.valuesFileName)) + { + Trace("helper: DeleteFile failed so parent (test1) is unlikely " + "to exit cleanly\n"); + } + PEDANTIC(ResetEvent, (Comms.hEvToHelper)); + if (!SetEvent(Comms.hEvFromHelper)) + { + Trace("helper: SetEvent failed so parent (test1) is unlikely " + "to exit cleanly\n"); + } + + free(pTarget); + PEDANTIC(CloseHandle, (Comms.hEvToHelper)); + PEDANTIC(CloseHandle, (Comms.hEvFromHelper)); + + if (!success) + { + Fail(""); + } + + PAL_Terminate(); + + return success ? PASS : FAIL; +} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/test1.c b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/test1.c deleted file mode 100644 index 8de029d973..0000000000 --- a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/test1.c +++ /dev/null @@ -1,189 +0,0 @@ -// 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: test1.c -** -** Purpose: Create a child process and some events for communications with it. -** When the child gets back to us with a memory location and a length, -** Call WriteProcessMemory on this location and check to see that it -** writes successfully. -** -** -**============================================================*/ - -#define UNICODE - -#include "commonconsts.h" - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - PROCESS_INFORMATION pi; - STARTUPINFO si; - HANDLE hEvToHelper; - HANDLE hEvFromHelper; - DWORD dwExitCode; - - - DWORD dwRet; - char cmdComposeBuf[MAX_PATH]; - PWCHAR uniString; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Create the signals we need for cross process communication */ - hEvToHelper = CreateEvent(NULL, TRUE, FALSE, szcToHelperEvName); - if (!hEvToHelper) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "GetLastError() returned %d.\n", szcToHelperEvName, - GetLastError()); - } - if (GetLastError() == ERROR_ALREADY_EXISTS) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "(already exists!)\n", szcToHelperEvName); - } - hEvFromHelper = CreateEvent(NULL, TRUE, FALSE, szcFromHelperEvName); - if (!hEvToHelper) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "GetLastError() returned %d.\n", szcFromHelperEvName, - GetLastError()); - } - if (GetLastError() == ERROR_ALREADY_EXISTS) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "(already exists!)\n", szcFromHelperEvName); - } - ResetEvent(hEvFromHelper); - ResetEvent(hEvToHelper); - - if (!sprintf(cmdComposeBuf, "helper %s", commsFileName)) - { - Fail("Could not convert command line\n"); - } - uniString = convert(cmdComposeBuf); - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - /* Create a new process. This is the process that will ask for - * memory munging */ - if(!CreateProcess( NULL, uniString, NULL, NULL, - FALSE, 0, NULL, NULL, &si, &pi)) - { - Trace("ERROR: CreateProcess failed to load executable '%S'. " - "GetLastError() returned %u.\n", - uniString, GetLastError()); - free(uniString); - Fail(""); - } - free(uniString); - - while(1) - { - FILE *commsFile; - char* pSrcMemory; - char* pDestMemory; - int Count; - SIZE_T wpmCount; - char incomingCMDBuffer[MAX_PATH + 1]; - - /* wait until the helper tells us that it has given us - * something to do */ - dwRet = WaitForSingleObject(hEvFromHelper, TIMEOUT); - if (dwRet != WAIT_OBJECT_0) - { - Trace("test1 WaitForSingleObjectTest: WaitForSingleObject " - "failed (%u)\n", GetLastError()); - break; /* no more work incoming */ - } - - /* get the parameters to test WriteProcessMemory with */ - if (!(commsFile = fopen(commsFileName, "r"))) - { - /* no file means there is no more work */ - break; - } - if ( NULL == fgets(incomingCMDBuffer, MAX_PATH, commsFile)) - { - Fail ("unable to read from communication file %s " - "for reasons %u & %u\n", - errno, GetLastError()); - } - PEDANTIC1(fclose,(commsFile)); - sscanf(incomingCMDBuffer, "%u %u", &pDestMemory, &Count); - if (argc > 1) - { - Trace("Preparing to write to %u bytes @ %u ('%s')\n", - Count, pDestMemory, incomingCMDBuffer); - } - - /* compose some data to write to the client process */ - if (!(pSrcMemory = malloc(Count))) - { - Trace("could not dynamically allocate memory to copy from " - "for reasons %u & %u\n", - errno, GetLastError()); - goto doneIteration; - } - memset(pSrcMemory, nextValue, Count); - - /* do the work */ - dwRet = WriteProcessMemory(pi.hProcess, - pDestMemory, - pSrcMemory, - Count, - &wpmCount); - if (!dwRet) - { - Trace("%s: Problem: on a write to %u bytes @ %u ('%s')\n", - argv[0], Count, pDestMemory, incomingCMDBuffer); - Trace("test1 WriteProcessMemory returned a%u(!=0) (GLE=%u)\n", - GetLastError()); - } - if(Count != wpmCount) - { - Trace("%s: Problem: on a write to %u bytes @ %u ('%s')\n", - argv[0], Count, pDestMemory, incomingCMDBuffer); - Trace("The number of bytes written should have been " - "%u, but was reported as %u.\n", Count, wpmCount); - } - free(pSrcMemory); - - doneIteration: - PEDANTIC(ResetEvent, (hEvFromHelper)); - PEDANTIC(SetEvent, (hEvToHelper)); - } - - /* wait for the child process to complete */ - WaitForSingleObject ( pi.hProcess, TIMEOUT ); - /* this may return a failure code on a success path */ - - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) - { - Trace( "GetExitCodeProcess call failed with error code %u\n", - GetLastError() ); - dwExitCode = FAIL; - } - - - PEDANTIC(CloseHandle, (hEvToHelper)); - PEDANTIC(CloseHandle, (hEvFromHelper)); - PEDANTIC(CloseHandle, (pi.hThread)); - PEDANTIC(CloseHandle, (pi.hProcess)); - - PAL_TerminateEx(dwExitCode); - return dwExitCode; -} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/test1.cpp b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/test1.cpp new file mode 100644 index 0000000000..f390c10c72 --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test1/test1.cpp @@ -0,0 +1,189 @@ +// 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: test1.c +** +** Purpose: Create a child process and some events for communications with it. +** When the child gets back to us with a memory location and a length, +** Call WriteProcessMemory on this location and check to see that it +** writes successfully. +** +** +**============================================================*/ + +#define UNICODE + +#include "commonconsts.h" + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + PROCESS_INFORMATION pi; + STARTUPINFO si; + HANDLE hEvToHelper; + HANDLE hEvFromHelper; + DWORD dwExitCode; + + + DWORD dwRet; + char cmdComposeBuf[MAX_PATH]; + PWCHAR uniString; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Create the signals we need for cross process communication */ + hEvToHelper = CreateEvent(NULL, TRUE, FALSE, szcToHelperEvName); + if (!hEvToHelper) + { + Fail("WriteProcessMemory: CreateEvent of '%S' failed. " + "GetLastError() returned %d.\n", szcToHelperEvName, + GetLastError()); + } + if (GetLastError() == ERROR_ALREADY_EXISTS) + { + Fail("WriteProcessMemory: CreateEvent of '%S' failed. " + "(already exists!)\n", szcToHelperEvName); + } + hEvFromHelper = CreateEvent(NULL, TRUE, FALSE, szcFromHelperEvName); + if (!hEvToHelper) + { + Fail("WriteProcessMemory: CreateEvent of '%S' failed. " + "GetLastError() returned %d.\n", szcFromHelperEvName, + GetLastError()); + } + if (GetLastError() == ERROR_ALREADY_EXISTS) + { + Fail("WriteProcessMemory: CreateEvent of '%S' failed. " + "(already exists!)\n", szcFromHelperEvName); + } + ResetEvent(hEvFromHelper); + ResetEvent(hEvToHelper); + + if (!sprintf_s(cmdComposeBuf, _countof(cmdComposeBuf), "helper %s", commsFileName)) + { + Fail("Could not convert command line\n"); + } + uniString = convert(cmdComposeBuf); + + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + /* Create a new process. This is the process that will ask for + * memory munging */ + if(!CreateProcess( NULL, uniString, NULL, NULL, + FALSE, 0, NULL, NULL, &si, &pi)) + { + Trace("ERROR: CreateProcess failed to load executable '%S'. " + "GetLastError() returned %u.\n", + uniString, GetLastError()); + free(uniString); + Fail(""); + } + free(uniString); + + while(1) + { + FILE *commsFile; + char* pSrcMemory; + char* pDestMemory; + int Count; + SIZE_T wpmCount; + char incomingCMDBuffer[MAX_PATH + 1]; + + /* wait until the helper tells us that it has given us + * something to do */ + dwRet = WaitForSingleObject(hEvFromHelper, TIMEOUT); + if (dwRet != WAIT_OBJECT_0) + { + Trace("test1 WaitForSingleObjectTest: WaitForSingleObject " + "failed (%u)\n", GetLastError()); + break; /* no more work incoming */ + } + + /* get the parameters to test WriteProcessMemory with */ + if (!(commsFile = fopen(commsFileName, "r"))) + { + /* no file means there is no more work */ + break; + } + if ( NULL == fgets(incomingCMDBuffer, MAX_PATH, commsFile)) + { + Fail ("unable to read from communication file %s " + "for reasons %u & %u\n", + errno, GetLastError()); + } + PEDANTIC1(fclose,(commsFile)); + sscanf(incomingCMDBuffer, "%u %u", &pDestMemory, &Count); + if (argc > 1) + { + Trace("Preparing to write to %u bytes @ %u ('%s')\n", + Count, pDestMemory, incomingCMDBuffer); + } + + /* compose some data to write to the client process */ + if (!(pSrcMemory = (char*)malloc(Count))) + { + Trace("could not dynamically allocate memory to copy from " + "for reasons %u & %u\n", + errno, GetLastError()); + goto doneIteration; + } + memset(pSrcMemory, nextValue, Count); + + /* do the work */ + dwRet = WriteProcessMemory(pi.hProcess, + pDestMemory, + pSrcMemory, + Count, + &wpmCount); + if (!dwRet) + { + Trace("%s: Problem: on a write to %u bytes @ %u ('%s')\n", + argv[0], Count, pDestMemory, incomingCMDBuffer); + Trace("test1 WriteProcessMemory returned a%u(!=0) (GLE=%u)\n", + GetLastError()); + } + if(Count != wpmCount) + { + Trace("%s: Problem: on a write to %u bytes @ %u ('%s')\n", + argv[0], Count, pDestMemory, incomingCMDBuffer); + Trace("The number of bytes written should have been " + "%u, but was reported as %u.\n", Count, wpmCount); + } + free(pSrcMemory); + + doneIteration: + PEDANTIC(ResetEvent, (hEvFromHelper)); + PEDANTIC(SetEvent, (hEvToHelper)); + } + + /* wait for the child process to complete */ + WaitForSingleObject ( pi.hProcess, TIMEOUT ); + /* this may return a failure code on a success path */ + + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) + { + Trace( "GetExitCodeProcess call failed with error code %u\n", + GetLastError() ); + dwExitCode = FAIL; + } + + + PEDANTIC(CloseHandle, (hEvToHelper)); + PEDANTIC(CloseHandle, (hEvFromHelper)); + PEDANTIC(CloseHandle, (pi.hThread)); + PEDANTIC(CloseHandle, (pi.hProcess)); + + PAL_TerminateEx(dwExitCode); + return dwExitCode; +} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/CMakeLists.txt b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/CMakeLists.txt index ecc0e06dac..3a5067c926 100644 --- a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test3.c + test3.cpp ) add_executable(paltest_writeprocessmemory_test3 @@ -20,7 +20,7 @@ target_link_libraries(paltest_writeprocessmemory_test3 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_writeprocessmemory_test3_helper diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/helper.c b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/helper.c deleted file mode 100644 index 170e2064cb..0000000000 --- a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/helper.c +++ /dev/null @@ -1,256 +0,0 @@ -// 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: helper.c - -** -==============================================================*/ - - -/* -** -** Purpose: This helper process sets up a several blocks of memory -** that should be unwritable from the parent process, then uses a file -** to tell its parent process where that memory is so it can attempt a -** WriteProcessMemory on it. When the parent process is done we check -** here that it was (properly) unable to change the contents of the -** memory. -*/ - -#include "commonconsts.h" - -#include - -struct allhandles_t -{ - HANDLE hEvToHelper; - HANDLE hEvFromHelper; - char *valuesFileName; -}; - - -/* function: wpmVerifyCant - * - * This is a general WriteProcessMemory testing function that sets up - * the RAM pointed to and tells the companion process on the other end - * of the handles in 'Comms' to attempt to alter 'lenDest' bytes at - * '*pDest'. - * - * However, the memory at pDest[0..lenDest] is expected to be unwritable by - * the companion process. The companion is expects this. This function - * verifies that no bytes were affected - */ - -int wpmVerifyCant(struct allhandles_t Comms, - char * pDest, unsigned int lenDest, - unsigned int lenLegitDest, - DWORD dwExpectedErrorCode, - const char* storageDescription) -{ - char *pCurr; - FILE *commsFile; - DWORD dwRet; - - unsigned int lenSafe = min(lenDest, lenLegitDest); - - PAL_TRY - { - memset(pDest, initialValue, lenSafe); - } - PAL_EXCEPT_EX (setup, EXCEPTION_EXECUTE_HANDLER) - { - Trace("WriteProcessMemory: bug in test values for '%s' (%p, %u, %u), " - "the initial memset threw an exception.\n", - storageDescription, pDest, lenDest, lenSafe); - } - PAL_ENDTRY; - - /* tell the parent what RAM to attempt to adjust */ - if(!(commsFile = fopen(Comms.valuesFileName, "w"))) - { - Trace("WriteProcessMemory: fopen of '%S' failed (%u). \n", - Comms.valuesFileName, GetLastError()); - return FALSE; - } - if (!fprintf(commsFile, "%u %u %u '%s'\n", - pDest, lenDest, dwExpectedErrorCode, storageDescription)) - { - Trace("WriteProcessMemory: fprintf to '%S' failed (%u). \n", - Comms.valuesFileName, GetLastError()); - return FALSE; - } - PEDANTIC1(fclose, (commsFile)); - - /* Tell the parent the data is ready for it to adjust */ - PEDANTIC(ResetEvent, (Comms.hEvToHelper)); - PEDANTIC(SetEvent, (Comms.hEvFromHelper)); - - dwRet = WaitForSingleObject(Comms.hEvToHelper, TIMEOUT); - if (dwRet != WAIT_OBJECT_0) - { - Trace("helper WaitForSingleObjectTest: WaitForSingleObject " - "failed (%u)\n", GetLastError()); - return FALSE; - } - - PAL_TRY - { - /* check the stuff (as much as we can) that should NOT have changed */ - for (pCurr = pDest; pCurr < (pDest + lenSafe); pCurr++ ) - { - if ( *pCurr != initialValue) - { - Trace("When testing '%s': real memory values preservation failed " - "at %u offset %u. Found '%c' instead of '%c'\n.", - storageDescription, pDest, pCurr - pDest, - *pCurr, initialValue); - return FALSE; - } - } - } - PAL_EXCEPT_EX (testing, EXCEPTION_EXECUTE_HANDLER) - { - Trace("WriteProcessMemory: bug in test values for '%s' (%p, %u, %u), " - "the verification pass threw an exception.\n", - storageDescription, pDest, lenDest, lenSafe); - } - PAL_ENDTRY; - - return TRUE; -} - -int __cdecl main(int argc, char *argv[]) -{ - BOOL success = TRUE; /* assume success */ - struct allhandles_t Comms = {0,0,0} ; - - SYSTEM_INFO sysinfo; - - char* Memory; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* hook up with the events created by the parent */ - Comms.hEvToHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcToHelperEvName); - if (!Comms.hEvToHelper) - { - Fail("WriteProcessMemory: OpenEvent of '%S' failed (%u). " - "(the event should already exist!)\n", - szcToHelperEvName, GetLastError()); - success = FALSE; - goto EXIT; - } - Comms.hEvFromHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcFromHelperEvName); - if (!Comms.hEvToHelper) - { - Trace("WriteProcessMemory: OpenEvent of '%S' failed (%u). " - "(the event should already exist!)\n", - szcFromHelperEvName, GetLastError()); - success = FALSE; - goto EXIT; - } - Comms.valuesFileName = argv[1]; - - /* test setup */ - GetSystemInfo(&sysinfo); - - { - unsigned int allocSize = sysinfo.dwPageSize * 2; - unsigned int writeLen = allocSize * 2; - - /* First test: overrun the allocated memory */ - Memory = (char*)VirtualAlloc(NULL, allocSize, - MEM_COMMIT, PAGE_READWRITE); - - if(Memory == NULL) - { - Fail("ERROR: Attempted to commit two pages, but the " - " VirtualAlloc call failed. " - "GetLastError() returned %u.\n",GetLastError()); - } - success &= wpmVerifyCant(Comms, Memory, writeLen, allocSize, - ERROR_INVALID_ADDRESS, - "should not write beyond committed allocation"); - - PEDANTIC1(VirtualFree, (Memory, allocSize, - MEM_DECOMMIT | MEM_RELEASE)); - } - - { - /* Allocate the memory as readonly */ - unsigned int allocSize = sysinfo.dwPageSize * 2; - unsigned int writeLen = allocSize; - - Memory = (char*)VirtualAlloc(NULL, allocSize, - MEM_COMMIT, PAGE_READONLY); - - if(Memory == NULL) - { - Fail("ERROR: Attempted to commit two pages readonly, but the " - " VirtualAlloc call failed. " - "GetLastError() returned %u.\n",GetLastError()); - } - success &= wpmVerifyCant(Comms, Memory, writeLen, 0, - ERROR_NOACCESS, - "should not write in READONLY allocation"); - - PEDANTIC1(VirtualFree, (Memory, allocSize, - MEM_DECOMMIT | MEM_RELEASE)); - } - - - { - /* attempt to write to memory that is not committed yet */ - unsigned int allocSize = sysinfo.dwPageSize * 2; - unsigned int writeLen = allocSize; - - Memory = (char*)VirtualAlloc(NULL, allocSize, - MEM_RESERVE, PAGE_NOACCESS); - - if(Memory == NULL) - { - Fail("ERROR: Attempted to reserve two pages, but the " - " VirtualAlloc call failed. " - "GetLastError() returned %u.\n",GetLastError()); - } - success &= wpmVerifyCant(Comms, Memory, writeLen, 0, - ERROR_INVALID_ADDRESS, - "should not write in memory that is" - " RESERVED but not COMMITTED"); - - PEDANTIC1(VirtualFree, (Memory, allocSize, MEM_RELEASE)); - } - - -EXIT: - /* Tell the parent that we are done */ - if (!DeleteFile(Comms.valuesFileName)) - { - Trace("helper: DeleteFile failed so parent (test1) is unlikely " - "to exit cleanly\n"); - } - PEDANTIC(ResetEvent, (Comms.hEvToHelper)); - if (!SetEvent(Comms.hEvFromHelper)) - { - Trace("helper: SetEvent failed so parent (test1) is unlikely " - "to exit cleanly\n"); - } - - PEDANTIC(CloseHandle, (Comms.hEvToHelper)); - PEDANTIC(CloseHandle, (Comms.hEvFromHelper)); - - if (!success) - { - Fail(""); - } - - PAL_Terminate(); - - return success ? PASS : FAIL; -} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/helper.cpp b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/helper.cpp new file mode 100644 index 0000000000..170e2064cb --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/helper.cpp @@ -0,0 +1,256 @@ +// 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: helper.c + +** +==============================================================*/ + + +/* +** +** Purpose: This helper process sets up a several blocks of memory +** that should be unwritable from the parent process, then uses a file +** to tell its parent process where that memory is so it can attempt a +** WriteProcessMemory on it. When the parent process is done we check +** here that it was (properly) unable to change the contents of the +** memory. +*/ + +#include "commonconsts.h" + +#include + +struct allhandles_t +{ + HANDLE hEvToHelper; + HANDLE hEvFromHelper; + char *valuesFileName; +}; + + +/* function: wpmVerifyCant + * + * This is a general WriteProcessMemory testing function that sets up + * the RAM pointed to and tells the companion process on the other end + * of the handles in 'Comms' to attempt to alter 'lenDest' bytes at + * '*pDest'. + * + * However, the memory at pDest[0..lenDest] is expected to be unwritable by + * the companion process. The companion is expects this. This function + * verifies that no bytes were affected + */ + +int wpmVerifyCant(struct allhandles_t Comms, + char * pDest, unsigned int lenDest, + unsigned int lenLegitDest, + DWORD dwExpectedErrorCode, + const char* storageDescription) +{ + char *pCurr; + FILE *commsFile; + DWORD dwRet; + + unsigned int lenSafe = min(lenDest, lenLegitDest); + + PAL_TRY + { + memset(pDest, initialValue, lenSafe); + } + PAL_EXCEPT_EX (setup, EXCEPTION_EXECUTE_HANDLER) + { + Trace("WriteProcessMemory: bug in test values for '%s' (%p, %u, %u), " + "the initial memset threw an exception.\n", + storageDescription, pDest, lenDest, lenSafe); + } + PAL_ENDTRY; + + /* tell the parent what RAM to attempt to adjust */ + if(!(commsFile = fopen(Comms.valuesFileName, "w"))) + { + Trace("WriteProcessMemory: fopen of '%S' failed (%u). \n", + Comms.valuesFileName, GetLastError()); + return FALSE; + } + if (!fprintf(commsFile, "%u %u %u '%s'\n", + pDest, lenDest, dwExpectedErrorCode, storageDescription)) + { + Trace("WriteProcessMemory: fprintf to '%S' failed (%u). \n", + Comms.valuesFileName, GetLastError()); + return FALSE; + } + PEDANTIC1(fclose, (commsFile)); + + /* Tell the parent the data is ready for it to adjust */ + PEDANTIC(ResetEvent, (Comms.hEvToHelper)); + PEDANTIC(SetEvent, (Comms.hEvFromHelper)); + + dwRet = WaitForSingleObject(Comms.hEvToHelper, TIMEOUT); + if (dwRet != WAIT_OBJECT_0) + { + Trace("helper WaitForSingleObjectTest: WaitForSingleObject " + "failed (%u)\n", GetLastError()); + return FALSE; + } + + PAL_TRY + { + /* check the stuff (as much as we can) that should NOT have changed */ + for (pCurr = pDest; pCurr < (pDest + lenSafe); pCurr++ ) + { + if ( *pCurr != initialValue) + { + Trace("When testing '%s': real memory values preservation failed " + "at %u offset %u. Found '%c' instead of '%c'\n.", + storageDescription, pDest, pCurr - pDest, + *pCurr, initialValue); + return FALSE; + } + } + } + PAL_EXCEPT_EX (testing, EXCEPTION_EXECUTE_HANDLER) + { + Trace("WriteProcessMemory: bug in test values for '%s' (%p, %u, %u), " + "the verification pass threw an exception.\n", + storageDescription, pDest, lenDest, lenSafe); + } + PAL_ENDTRY; + + return TRUE; +} + +int __cdecl main(int argc, char *argv[]) +{ + BOOL success = TRUE; /* assume success */ + struct allhandles_t Comms = {0,0,0} ; + + SYSTEM_INFO sysinfo; + + char* Memory; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* hook up with the events created by the parent */ + Comms.hEvToHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcToHelperEvName); + if (!Comms.hEvToHelper) + { + Fail("WriteProcessMemory: OpenEvent of '%S' failed (%u). " + "(the event should already exist!)\n", + szcToHelperEvName, GetLastError()); + success = FALSE; + goto EXIT; + } + Comms.hEvFromHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcFromHelperEvName); + if (!Comms.hEvToHelper) + { + Trace("WriteProcessMemory: OpenEvent of '%S' failed (%u). " + "(the event should already exist!)\n", + szcFromHelperEvName, GetLastError()); + success = FALSE; + goto EXIT; + } + Comms.valuesFileName = argv[1]; + + /* test setup */ + GetSystemInfo(&sysinfo); + + { + unsigned int allocSize = sysinfo.dwPageSize * 2; + unsigned int writeLen = allocSize * 2; + + /* First test: overrun the allocated memory */ + Memory = (char*)VirtualAlloc(NULL, allocSize, + MEM_COMMIT, PAGE_READWRITE); + + if(Memory == NULL) + { + Fail("ERROR: Attempted to commit two pages, but the " + " VirtualAlloc call failed. " + "GetLastError() returned %u.\n",GetLastError()); + } + success &= wpmVerifyCant(Comms, Memory, writeLen, allocSize, + ERROR_INVALID_ADDRESS, + "should not write beyond committed allocation"); + + PEDANTIC1(VirtualFree, (Memory, allocSize, + MEM_DECOMMIT | MEM_RELEASE)); + } + + { + /* Allocate the memory as readonly */ + unsigned int allocSize = sysinfo.dwPageSize * 2; + unsigned int writeLen = allocSize; + + Memory = (char*)VirtualAlloc(NULL, allocSize, + MEM_COMMIT, PAGE_READONLY); + + if(Memory == NULL) + { + Fail("ERROR: Attempted to commit two pages readonly, but the " + " VirtualAlloc call failed. " + "GetLastError() returned %u.\n",GetLastError()); + } + success &= wpmVerifyCant(Comms, Memory, writeLen, 0, + ERROR_NOACCESS, + "should not write in READONLY allocation"); + + PEDANTIC1(VirtualFree, (Memory, allocSize, + MEM_DECOMMIT | MEM_RELEASE)); + } + + + { + /* attempt to write to memory that is not committed yet */ + unsigned int allocSize = sysinfo.dwPageSize * 2; + unsigned int writeLen = allocSize; + + Memory = (char*)VirtualAlloc(NULL, allocSize, + MEM_RESERVE, PAGE_NOACCESS); + + if(Memory == NULL) + { + Fail("ERROR: Attempted to reserve two pages, but the " + " VirtualAlloc call failed. " + "GetLastError() returned %u.\n",GetLastError()); + } + success &= wpmVerifyCant(Comms, Memory, writeLen, 0, + ERROR_INVALID_ADDRESS, + "should not write in memory that is" + " RESERVED but not COMMITTED"); + + PEDANTIC1(VirtualFree, (Memory, allocSize, MEM_RELEASE)); + } + + +EXIT: + /* Tell the parent that we are done */ + if (!DeleteFile(Comms.valuesFileName)) + { + Trace("helper: DeleteFile failed so parent (test1) is unlikely " + "to exit cleanly\n"); + } + PEDANTIC(ResetEvent, (Comms.hEvToHelper)); + if (!SetEvent(Comms.hEvFromHelper)) + { + Trace("helper: SetEvent failed so parent (test1) is unlikely " + "to exit cleanly\n"); + } + + PEDANTIC(CloseHandle, (Comms.hEvToHelper)); + PEDANTIC(CloseHandle, (Comms.hEvFromHelper)); + + if (!success) + { + Fail(""); + } + + PAL_Terminate(); + + return success ? PASS : FAIL; +} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/test3.c b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/test3.c deleted file mode 100644 index 063cb4cbec..0000000000 --- a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/test3.c +++ /dev/null @@ -1,205 +0,0 @@ -// 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: test3.c -** -** Purpose: Create a child process and debug it. When the child -** raises an exception, it sends back a memory location. Call -** WriteProcessMemory on the memory location, but attempt to write -** more than the memory allows. This should cause an error and the -** data should be unchanged. -** -** -==============================================================*/ - -#define UNICODE - -#include "commonconsts.h" - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - PROCESS_INFORMATION pi; - STARTUPINFO si; - HANDLE hEvToHelper; - HANDLE hEvFromHelper; - DWORD dwExitCode; - - - DWORD dwRet; - BOOL success = TRUE; /* assume success */ - char cmdComposeBuf[MAX_PATH]; - PWCHAR uniString; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Create the signals we need for cross process communication */ - hEvToHelper = CreateEvent(NULL, TRUE, FALSE, szcToHelperEvName); - if (!hEvToHelper) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "GetLastError() returned %u.\n", szcToHelperEvName, - GetLastError()); - } - if (GetLastError() == ERROR_ALREADY_EXISTS) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "(already exists!)\n", szcToHelperEvName); - } - hEvFromHelper = CreateEvent(NULL, TRUE, FALSE, szcFromHelperEvName); - if (!hEvToHelper) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "GetLastError() returned %u.\n", szcFromHelperEvName, - GetLastError()); - } - if (GetLastError() == ERROR_ALREADY_EXISTS) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "(already exists!)\n", szcFromHelperEvName); - } - - if (!sprintf(cmdComposeBuf, "helper %s", commsFileName)) - { - Fail("Could not convert command line\n"); - } - uniString = convert(cmdComposeBuf); - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - /* Create a new process. This is the process that will ask for - * memory munging */ - if(!CreateProcess( NULL, uniString, NULL, NULL, - FALSE, 0, NULL, NULL, &si, &pi)) - { - Trace("ERROR: CreateProcess failed to load executable '%S'. " - "GetLastError() returned %u.\n", - uniString, GetLastError()); - free(uniString); - Fail(""); - } - free(uniString); - - while(1) - { - FILE *commsFile; - char* pSrcMemory; - char* pDestMemory; - int Count; - SIZE_T wpmCount; - DWORD dwExpectedErrorCode; - - char incomingCMDBuffer[MAX_PATH + 1]; - - /* wait until the helper tells us that it has given us - * something to do */ - dwRet = WaitForSingleObject(hEvFromHelper, TIMEOUT); - if (dwRet != WAIT_OBJECT_0) - { - Trace("test1 WaitForSingleObjectTest: WaitForSingleObject " - "failed (%u)\n", GetLastError()); - break; /* no more work incoming */ - } - - /* get the parameters to test WriteProcessMemory with */ - if (!(commsFile = fopen(commsFileName, "r"))) - { - /* no file means there is no more work */ - break; - } - if ( NULL == fgets(incomingCMDBuffer, MAX_PATH, commsFile)) - { - Trace ("unable to read from communication file %s " - "for reasons %u & %u\n", - errno, GetLastError()); - success = FALSE; - PEDANTIC1(fclose,(commsFile)); - /* it's not worth continuing this trial */ - goto doneIteration; - } - PEDANTIC1(fclose,(commsFile)); - sscanf(incomingCMDBuffer, "%u %u %u", - &pDestMemory, &Count, &dwExpectedErrorCode); - if (argc > 1) - { - Trace("Preparing to write to %u bytes @ %u ('%s')\n", - Count, pDestMemory, incomingCMDBuffer); - } - - /* compose some data to write to the client process */ - if (!(pSrcMemory = malloc(Count))) - { - Trace("could not dynamically allocate memory to copy from " - "for reasons %u & %u\n", - errno, GetLastError()); - success = FALSE; - goto doneIteration; - } - memset(pSrcMemory, nextValue, Count); - - /* do the work */ - dwRet = WriteProcessMemory(pi.hProcess, - pDestMemory, - pSrcMemory, - Count, - &wpmCount); - - if(dwRet != 0) - { - Trace("ERROR: Situation: '%s', return code: %u, bytes 'written': %u\n", - incomingCMDBuffer, dwRet, wpmCount); - Trace("ERROR: WriteProcessMemory did not fail as it should, as " - "it attempted to write to a range of memory which was " - "not completely accessible.\n"); - success = FALSE; - } - - if(GetLastError() != dwExpectedErrorCode) - { - Trace("ERROR: GetLastError() should have returned " - "%u , but instead it returned %u.\n", - dwExpectedErrorCode, GetLastError()); - success = FALSE; - } - free(pSrcMemory); - - doneIteration: - PEDANTIC(ResetEvent, (hEvFromHelper)); - PEDANTIC(SetEvent, (hEvToHelper)); - } - - - /* wait for the child process to complete */ - WaitForSingleObject ( pi.hProcess, TIMEOUT ); - /* this may return a failure code on a success path */ - - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) - { - Trace( "GetExitCodeProcess call failed with error code %u\n", - GetLastError() ); - dwExitCode = FAIL; - } - if(!success) - { - dwExitCode = FAIL; - } - - PEDANTIC(CloseHandle, (hEvToHelper)); - PEDANTIC(CloseHandle, (hEvFromHelper)); - PEDANTIC(CloseHandle, (pi.hThread)); - PEDANTIC(CloseHandle, (pi.hProcess)); - - PAL_Terminate(dwExitCode); - return dwExitCode; -} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/test3.cpp b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/test3.cpp new file mode 100644 index 0000000000..15b4b3f79d --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test3/test3.cpp @@ -0,0 +1,205 @@ +// 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: test3.c +** +** Purpose: Create a child process and debug it. When the child +** raises an exception, it sends back a memory location. Call +** WriteProcessMemory on the memory location, but attempt to write +** more than the memory allows. This should cause an error and the +** data should be unchanged. +** +** +==============================================================*/ + +#define UNICODE + +#include "commonconsts.h" + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + PROCESS_INFORMATION pi; + STARTUPINFO si; + HANDLE hEvToHelper; + HANDLE hEvFromHelper; + DWORD dwExitCode; + + + DWORD dwRet; + BOOL success = TRUE; /* assume success */ + char cmdComposeBuf[MAX_PATH]; + PWCHAR uniString; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Create the signals we need for cross process communication */ + hEvToHelper = CreateEvent(NULL, TRUE, FALSE, szcToHelperEvName); + if (!hEvToHelper) + { + Fail("WriteProcessMemory: CreateEvent of '%S' failed. " + "GetLastError() returned %u.\n", szcToHelperEvName, + GetLastError()); + } + if (GetLastError() == ERROR_ALREADY_EXISTS) + { + Fail("WriteProcessMemory: CreateEvent of '%S' failed. " + "(already exists!)\n", szcToHelperEvName); + } + hEvFromHelper = CreateEvent(NULL, TRUE, FALSE, szcFromHelperEvName); + if (!hEvToHelper) + { + Fail("WriteProcessMemory: CreateEvent of '%S' failed. " + "GetLastError() returned %u.\n", szcFromHelperEvName, + GetLastError()); + } + if (GetLastError() == ERROR_ALREADY_EXISTS) + { + Fail("WriteProcessMemory: CreateEvent of '%S' failed. " + "(already exists!)\n", szcFromHelperEvName); + } + + if (!sprintf_s(cmdComposeBuf, _countof(cmdComposeBuf), "helper %s", commsFileName)) + { + Fail("Could not convert command line\n"); + } + uniString = convert(cmdComposeBuf); + + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + /* Create a new process. This is the process that will ask for + * memory munging */ + if(!CreateProcess( NULL, uniString, NULL, NULL, + FALSE, 0, NULL, NULL, &si, &pi)) + { + Trace("ERROR: CreateProcess failed to load executable '%S'. " + "GetLastError() returned %u.\n", + uniString, GetLastError()); + free(uniString); + Fail(""); + } + free(uniString); + + while(1) + { + FILE *commsFile; + char* pSrcMemory; + char* pDestMemory; + int Count; + SIZE_T wpmCount; + DWORD dwExpectedErrorCode; + + char incomingCMDBuffer[MAX_PATH + 1]; + + /* wait until the helper tells us that it has given us + * something to do */ + dwRet = WaitForSingleObject(hEvFromHelper, TIMEOUT); + if (dwRet != WAIT_OBJECT_0) + { + Trace("test1 WaitForSingleObjectTest: WaitForSingleObject " + "failed (%u)\n", GetLastError()); + break; /* no more work incoming */ + } + + /* get the parameters to test WriteProcessMemory with */ + if (!(commsFile = fopen(commsFileName, "r"))) + { + /* no file means there is no more work */ + break; + } + if ( NULL == fgets(incomingCMDBuffer, MAX_PATH, commsFile)) + { + Trace ("unable to read from communication file %s " + "for reasons %u & %u\n", + errno, GetLastError()); + success = FALSE; + PEDANTIC1(fclose,(commsFile)); + /* it's not worth continuing this trial */ + goto doneIteration; + } + PEDANTIC1(fclose,(commsFile)); + sscanf(incomingCMDBuffer, "%u %u %u", + &pDestMemory, &Count, &dwExpectedErrorCode); + if (argc > 1) + { + Trace("Preparing to write to %u bytes @ %u ('%s')\n", + Count, pDestMemory, incomingCMDBuffer); + } + + /* compose some data to write to the client process */ + if (!(pSrcMemory = (char*)malloc(Count))) + { + Trace("could not dynamically allocate memory to copy from " + "for reasons %u & %u\n", + errno, GetLastError()); + success = FALSE; + goto doneIteration; + } + memset(pSrcMemory, nextValue, Count); + + /* do the work */ + dwRet = WriteProcessMemory(pi.hProcess, + pDestMemory, + pSrcMemory, + Count, + &wpmCount); + + if(dwRet != 0) + { + Trace("ERROR: Situation: '%s', return code: %u, bytes 'written': %u\n", + incomingCMDBuffer, dwRet, wpmCount); + Trace("ERROR: WriteProcessMemory did not fail as it should, as " + "it attempted to write to a range of memory which was " + "not completely accessible.\n"); + success = FALSE; + } + + if(GetLastError() != dwExpectedErrorCode) + { + Trace("ERROR: GetLastError() should have returned " + "%u , but instead it returned %u.\n", + dwExpectedErrorCode, GetLastError()); + success = FALSE; + } + free(pSrcMemory); + + doneIteration: + PEDANTIC(ResetEvent, (hEvFromHelper)); + PEDANTIC(SetEvent, (hEvToHelper)); + } + + + /* wait for the child process to complete */ + WaitForSingleObject ( pi.hProcess, TIMEOUT ); + /* this may return a failure code on a success path */ + + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) + { + Trace( "GetExitCodeProcess call failed with error code %u\n", + GetLastError() ); + dwExitCode = FAIL; + } + if(!success) + { + dwExitCode = FAIL; + } + + PEDANTIC(CloseHandle, (hEvToHelper)); + PEDANTIC(CloseHandle, (hEvFromHelper)); + PEDANTIC(CloseHandle, (pi.hThread)); + PEDANTIC(CloseHandle, (pi.hProcess)); + + PAL_Terminate(dwExitCode); + return dwExitCode; +} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/CMakeLists.txt b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/CMakeLists.txt index cf1ce13862..7cba09038a 100644 --- a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test4.c + test4.cpp ) add_executable(paltest_writeprocessmemory_test4 @@ -20,7 +20,7 @@ target_link_libraries(paltest_writeprocessmemory_test4 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_writeprocessmemory_test4_helper diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/helper.c b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/helper.c deleted file mode 100644 index b653ea5057..0000000000 --- a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/helper.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: helper.c -** -** Purpose: This helper process sets up a block of memory, then -** raises an exception to pass that memory location back to the -** parent process. When the parent process is done calling WriteProcessMemory -** we check here that it was written properly. -** -** -**============================================================*/ - -#include -const int MY_EXCEPTION=999; - -int __cdecl main(int argc, char *argv[]) -{ - - char* Memory; - char* TheArray[1]; - int i; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - Memory = (char*)VirtualAlloc(NULL, 4096, MEM_COMMIT, PAGE_READONLY); - - if(Memory == NULL) - { - Fail("ERROR: Attempted to allocate two pages, but the VirtualAlloc " - "call failed. GetLastError() returned %d.\n",GetLastError()); - } - - - TheArray[0] = Memory; - - - /* Need to sleep for a couple seconds. Otherwise this process - won't be being debugged when the first exception is raised. - */ - Sleep(4000); - - RaiseException(MY_EXCEPTION, 0, 1, (ULONG_PTR*)TheArray); - - for(i=0; i<4096; ++i) - { - if(Memory[i] != '\0') - { - Fail("ERROR: The memory should be unchanged after the " - "invalid call to WriteProcessMemory, but the char " - "at index %d has changed.\n",i); - } - } - - - - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/helper.cpp b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/helper.cpp new file mode 100644 index 0000000000..b653ea5057 --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/helper.cpp @@ -0,0 +1,67 @@ +// 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: helper.c +** +** Purpose: This helper process sets up a block of memory, then +** raises an exception to pass that memory location back to the +** parent process. When the parent process is done calling WriteProcessMemory +** we check here that it was written properly. +** +** +**============================================================*/ + +#include +const int MY_EXCEPTION=999; + +int __cdecl main(int argc, char *argv[]) +{ + + char* Memory; + char* TheArray[1]; + int i; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + Memory = (char*)VirtualAlloc(NULL, 4096, MEM_COMMIT, PAGE_READONLY); + + if(Memory == NULL) + { + Fail("ERROR: Attempted to allocate two pages, but the VirtualAlloc " + "call failed. GetLastError() returned %d.\n",GetLastError()); + } + + + TheArray[0] = Memory; + + + /* Need to sleep for a couple seconds. Otherwise this process + won't be being debugged when the first exception is raised. + */ + Sleep(4000); + + RaiseException(MY_EXCEPTION, 0, 1, (ULONG_PTR*)TheArray); + + for(i=0; i<4096; ++i) + { + if(Memory[i] != '\0') + { + Fail("ERROR: The memory should be unchanged after the " + "invalid call to WriteProcessMemory, but the char " + "at index %d has changed.\n",i); + } + } + + + + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/test4.c b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/test4.c deleted file mode 100644 index 51db23499b..0000000000 --- a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/test4.c +++ /dev/null @@ -1,124 +0,0 @@ -// 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: test4.c -** -** Purpose: Create a child process and debug it. When the child -** raises an exception, it sends back a memory location. Call -** WriteProcessMemory on a restricted memory location and ensure that -** it fails. -** -** -**============================================================*/ - -#include -const int MY_EXCEPTION=999; - -int __cdecl main(int argc, char *argv[]) -{ - - PROCESS_INFORMATION pi; - STARTUPINFO si; - DEBUG_EVENT DebugEv; - DWORD dwContinueStatus = DBG_CONTINUE; - int Count, ret; - char* DataBuffer[4096]; - char* Memory; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - memset(DataBuffer, 'z', 4096); - - /* Create a new process. This is the process to be Debugged */ - if(!CreateProcess( NULL, "helper", NULL, NULL, - FALSE, 0, NULL, NULL, &si, &pi)) - { - Fail("ERROR: CreateProcess failed to load executable 'helper'. " - "GetLastError() returned %d.\n",GetLastError()); - } - - /* Call DebugActiveProcess, because the process wasn't created as a - debug process. - */ - if(DebugActiveProcess(pi.dwProcessId) == 0) - { - Fail("ERROR: Failed calling DebugActiveProcess on the process " - "which was created to debug. GetLastError() returned %d.\n", - GetLastError()); - } - - - /* Call WaitForDebugEvent, which will wait until the helper process - raises an exception. - */ - - while(1) - { - if(WaitForDebugEvent(&DebugEv, INFINITE) == 0) - { - Fail("ERROR: WaitForDebugEvent returned 0, indicating failure. " - "GetLastError() returned %d.\n",GetLastError()); - } - - /* We're waiting for the helper process to send this exception. - When it does, we call WriteProcess. If it gets called more than - once, it is ignored. - */ - - if(DebugEv.u.Exception.ExceptionRecord.ExceptionCode == MY_EXCEPTION) - { - - Memory = (LPVOID) - DebugEv.u.Exception.ExceptionRecord.ExceptionInformation[0]; - - /* Write to this memory which we have no access to. */ - - ret = WriteProcessMemory(pi.hProcess, - Memory, - DataBuffer, - 4096, - &Count); - - if(ret != 0) - { - Fail("ERROR: WriteProcessMemory should have failed, as " - "it attempted to write to a range of memory which was " - "not accessible.\n"); - } - - if(GetLastError() != ERROR_NOACCESS) - { - Fail("ERROR: GetLastError() should have returned " - "ERROR_NOACCESS , but intead it returned " - "%d.\n",GetLastError()); - } - } - - if(DebugEv.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) - { - break; - } - - if(ContinueDebugEvent(DebugEv.dwProcessId, - DebugEv.dwThreadId, dwContinueStatus) == 0) - { - Fail("ERROR: ContinueDebugEvent failed to continue the thread " - "which had a debug event. GetLastError() returned %d.\n", - GetLastError()); - } - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/test4.cpp b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/test4.cpp new file mode 100644 index 0000000000..51db23499b --- /dev/null +++ b/src/pal/tests/palsuite/debug_api/WriteProcessMemory/test4/test4.cpp @@ -0,0 +1,124 @@ +// 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: test4.c +** +** Purpose: Create a child process and debug it. When the child +** raises an exception, it sends back a memory location. Call +** WriteProcessMemory on a restricted memory location and ensure that +** it fails. +** +** +**============================================================*/ + +#include +const int MY_EXCEPTION=999; + +int __cdecl main(int argc, char *argv[]) +{ + + PROCESS_INFORMATION pi; + STARTUPINFO si; + DEBUG_EVENT DebugEv; + DWORD dwContinueStatus = DBG_CONTINUE; + int Count, ret; + char* DataBuffer[4096]; + char* Memory; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + memset(DataBuffer, 'z', 4096); + + /* Create a new process. This is the process to be Debugged */ + if(!CreateProcess( NULL, "helper", NULL, NULL, + FALSE, 0, NULL, NULL, &si, &pi)) + { + Fail("ERROR: CreateProcess failed to load executable 'helper'. " + "GetLastError() returned %d.\n",GetLastError()); + } + + /* Call DebugActiveProcess, because the process wasn't created as a + debug process. + */ + if(DebugActiveProcess(pi.dwProcessId) == 0) + { + Fail("ERROR: Failed calling DebugActiveProcess on the process " + "which was created to debug. GetLastError() returned %d.\n", + GetLastError()); + } + + + /* Call WaitForDebugEvent, which will wait until the helper process + raises an exception. + */ + + while(1) + { + if(WaitForDebugEvent(&DebugEv, INFINITE) == 0) + { + Fail("ERROR: WaitForDebugEvent returned 0, indicating failure. " + "GetLastError() returned %d.\n",GetLastError()); + } + + /* We're waiting for the helper process to send this exception. + When it does, we call WriteProcess. If it gets called more than + once, it is ignored. + */ + + if(DebugEv.u.Exception.ExceptionRecord.ExceptionCode == MY_EXCEPTION) + { + + Memory = (LPVOID) + DebugEv.u.Exception.ExceptionRecord.ExceptionInformation[0]; + + /* Write to this memory which we have no access to. */ + + ret = WriteProcessMemory(pi.hProcess, + Memory, + DataBuffer, + 4096, + &Count); + + if(ret != 0) + { + Fail("ERROR: WriteProcessMemory should have failed, as " + "it attempted to write to a range of memory which was " + "not accessible.\n"); + } + + if(GetLastError() != ERROR_NOACCESS) + { + Fail("ERROR: GetLastError() should have returned " + "ERROR_NOACCESS , but intead it returned " + "%d.\n",GetLastError()); + } + } + + if(DebugEv.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) + { + break; + } + + if(ContinueDebugEvent(DebugEv.dwProcessId, + DebugEv.dwThreadId, dwContinueStatus) == 0) + { + Fail("ERROR: ContinueDebugEvent failed to continue the thread " + "which had a debug event. GetLastError() returned %d.\n", + GetLastError()); + } + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/CMakeLists.txt index adbc8ae86a..4e30869d85 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_EXCEPT_FILTER.c + PAL_EXCEPT_FILTER.cpp ) add_executable(paltest_pal_except_filter_test1 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.c b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.c deleted file mode 100644 index ee65f43d2c..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.c +++ /dev/null @@ -1,118 +0,0 @@ -// 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: pal_except_filter.c (test 1) -** -** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER. An -** exception is forced and a known value is passed to the filter -** fuction. The known value as well as booleans are tested to -** ensure proper functioning. -** -** -**===================================================================*/ - - - -#include - -BOOL bFilter = FALSE; -BOOL bTry = FALSE; -const int nValidator = 12321; - -LONG ExitFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) -{ - int nTestInt = *(int *)pnTestInt; - - /* let the main know we've hit the filter function */ - bFilter = TRUE; - - if (!bTry) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The filter was hit without PAL_TRY being hit.\n"); - } - - /* was the correct value passed? */ - if (nValidator != nTestInt) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Parameter passed to filter function" - " should have been \"%d\" but was \"%d\".\n", - nValidator, - nTestInt); - } - return EXCEPTION_EXECUTE_HANDLER; -} - - -int __cdecl main(int argc, char *argv[]) -{ - int* p = 0x00000000; /* pointer to NULL */ - BOOL bExcept = FALSE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the exception block - */ - - PAL_TRY - { - if (bExcept) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - - Fail("PAL_EXCEPT_FILTER: ERROR -> code was executed after the " - "access violation.\n"); - } - PAL_EXCEPT_FILTER(ExitFilter, (LPVOID)&nValidator) - { - if (!bTry) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER was hit without PAL_TRY being hit.\n"); - } - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the PAL_TRY" - " block was not executed.\n"); - } - - if (!bExcept) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "PAL_EXCEPT_FILTER block was not executed.\n"); - } - - if (!bFilter) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the filter" - " function was not executed.\n"); - } - - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept || !bFilter) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.cpp b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.cpp new file mode 100644 index 0000000000..ee65f43d2c --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test1/PAL_EXCEPT_FILTER.cpp @@ -0,0 +1,118 @@ +// 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: pal_except_filter.c (test 1) +** +** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER. An +** exception is forced and a known value is passed to the filter +** fuction. The known value as well as booleans are tested to +** ensure proper functioning. +** +** +**===================================================================*/ + + + +#include + +BOOL bFilter = FALSE; +BOOL bTry = FALSE; +const int nValidator = 12321; + +LONG ExitFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) +{ + int nTestInt = *(int *)pnTestInt; + + /* let the main know we've hit the filter function */ + bFilter = TRUE; + + if (!bTry) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The filter was hit without PAL_TRY being hit.\n"); + } + + /* was the correct value passed? */ + if (nValidator != nTestInt) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Parameter passed to filter function" + " should have been \"%d\" but was \"%d\".\n", + nValidator, + nTestInt); + } + return EXCEPTION_EXECUTE_HANDLER; +} + + +int __cdecl main(int argc, char *argv[]) +{ + int* p = 0x00000000; /* pointer to NULL */ + BOOL bExcept = FALSE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the exception block + */ + + PAL_TRY + { + if (bExcept) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + + Fail("PAL_EXCEPT_FILTER: ERROR -> code was executed after the " + "access violation.\n"); + } + PAL_EXCEPT_FILTER(ExitFilter, (LPVOID)&nValidator) + { + if (!bTry) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER was hit without PAL_TRY being hit.\n"); + } + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the PAL_TRY" + " block was not executed.\n"); + } + + if (!bExcept) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "PAL_EXCEPT_FILTER block was not executed.\n"); + } + + if (!bFilter) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the filter" + " function was not executed.\n"); + } + + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept || !bFilter) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/CMakeLists.txt index 62cda706d5..3f979c08db 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - pal_except_filter.c + pal_except_filter.cpp ) add_executable(paltest_pal_except_filter_test2 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/pal_except_filter.c b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/pal_except_filter.c deleted file mode 100644 index ccf53fb0ba..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/pal_except_filter.c +++ /dev/null @@ -1,154 +0,0 @@ -// 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: pal_except_filter.c (test 2) -** -** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER. An -** exception is forced and the filter returns -** EXCEPTION_CONTINUE_EXECUTION to allow execution to continue. -** -** -**===================================================================*/ - - -#include - -char* p; /* pointer to be abused */ - -BOOL bFilter = FALSE; -BOOL bTry = FALSE; -BOOL bTry2 = FALSE; -BOOL bContinued = FALSE; -const int nValidator = 12321; - -LONG ExitFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) -{ - int nTestInt = *(int *)pnTestInt; - void *Temp; - - /* let the main know we've hit the filter function */ - bFilter = TRUE; - - if (!bTry) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The filter was hit without PAL_TRY being hit.\n"); - } - - /* was the correct value passed? */ - if (nValidator != nTestInt) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Parameter passed to filter function" - " should have been \"%d\" but was \"%d\".\n", - nValidator, - nTestInt); - } - - /* Are we dealing with the exception we expected? */ - if (EXCEPTION_ACCESS_VIOLATION != ep->ExceptionRecord->ExceptionCode) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Unexpected Exception" - " should have been \"%x\" but was \"%x\".\n", - EXCEPTION_ACCESS_VIOLATION, - ep->ExceptionRecord->ExceptionCode); - } - - /* attempt to correct the problem by commiting the page at address 'p' */ - Temp= VirtualAlloc(p, 1, MEM_COMMIT, PAGE_READWRITE); - if (!Temp) - { - Fail("EXCEPTION_CONTINUE_EXECUTION: last error = %u - probably " - "out of memory. Unable to continue, not proof of exception " - "failure\n", - GetLastError()); - } - /* The memory that 'p' points to is now valid */ - - return EXCEPTION_CONTINUE_EXECUTION; -} - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bExcept = FALSE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the exception block - */ - - PAL_TRY - { - if (bExcept) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - - /* reserve an address chunk for p to point to */ - p = (char*) VirtualAlloc(0, 1, MEM_RESERVE, PAGE_READONLY); - if (!p) - { - Fail("EXCEPTION_CONTINUE_EXECUTION: test setup via " - "VirtualAlloc failed.\n"); - } - - *p = 13; /* causes an access violation exception */ - - bTry2 = TRUE; - - - } - PAL_EXCEPT_FILTER(ExitFilter, (LPVOID)&nValidator) - { - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER block */ - Fail("PAL_EXCEPT_FILTER: ERROR -> in handler despite filter's " - "continue choice\n"); - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the PAL_TRY" - " block was not executed.\n"); - } - - if (bExcept) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "PAL_EXCEPT_FILTER block was executed.\n"); - } - - if (!bFilter) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the filter" - " function was not executed.\n"); - } - - - if (!bTry2) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the PAL_TRY" - " block after the exception causing statements was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || bExcept || !bFilter) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/pal_except_filter.cpp b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/pal_except_filter.cpp new file mode 100644 index 0000000000..ccf53fb0ba --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test2/pal_except_filter.cpp @@ -0,0 +1,154 @@ +// 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: pal_except_filter.c (test 2) +** +** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER. An +** exception is forced and the filter returns +** EXCEPTION_CONTINUE_EXECUTION to allow execution to continue. +** +** +**===================================================================*/ + + +#include + +char* p; /* pointer to be abused */ + +BOOL bFilter = FALSE; +BOOL bTry = FALSE; +BOOL bTry2 = FALSE; +BOOL bContinued = FALSE; +const int nValidator = 12321; + +LONG ExitFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) +{ + int nTestInt = *(int *)pnTestInt; + void *Temp; + + /* let the main know we've hit the filter function */ + bFilter = TRUE; + + if (!bTry) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The filter was hit without PAL_TRY being hit.\n"); + } + + /* was the correct value passed? */ + if (nValidator != nTestInt) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Parameter passed to filter function" + " should have been \"%d\" but was \"%d\".\n", + nValidator, + nTestInt); + } + + /* Are we dealing with the exception we expected? */ + if (EXCEPTION_ACCESS_VIOLATION != ep->ExceptionRecord->ExceptionCode) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Unexpected Exception" + " should have been \"%x\" but was \"%x\".\n", + EXCEPTION_ACCESS_VIOLATION, + ep->ExceptionRecord->ExceptionCode); + } + + /* attempt to correct the problem by commiting the page at address 'p' */ + Temp= VirtualAlloc(p, 1, MEM_COMMIT, PAGE_READWRITE); + if (!Temp) + { + Fail("EXCEPTION_CONTINUE_EXECUTION: last error = %u - probably " + "out of memory. Unable to continue, not proof of exception " + "failure\n", + GetLastError()); + } + /* The memory that 'p' points to is now valid */ + + return EXCEPTION_CONTINUE_EXECUTION; +} + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bExcept = FALSE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the exception block + */ + + PAL_TRY + { + if (bExcept) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + + /* reserve an address chunk for p to point to */ + p = (char*) VirtualAlloc(0, 1, MEM_RESERVE, PAGE_READONLY); + if (!p) + { + Fail("EXCEPTION_CONTINUE_EXECUTION: test setup via " + "VirtualAlloc failed.\n"); + } + + *p = 13; /* causes an access violation exception */ + + bTry2 = TRUE; + + + } + PAL_EXCEPT_FILTER(ExitFilter, (LPVOID)&nValidator) + { + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER block */ + Fail("PAL_EXCEPT_FILTER: ERROR -> in handler despite filter's " + "continue choice\n"); + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the PAL_TRY" + " block was not executed.\n"); + } + + if (bExcept) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "PAL_EXCEPT_FILTER block was executed.\n"); + } + + if (!bFilter) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the filter" + " function was not executed.\n"); + } + + + if (!bTry2) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the PAL_TRY" + " block after the exception causing statements was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || bExcept || !bFilter) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/CMakeLists.txt index cc68fb031c..2bdf44e058 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - pal_except_filter.c + pal_except_filter.cpp ) add_executable(paltest_pal_except_filter_test3 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/pal_except_filter.c b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/pal_except_filter.c deleted file mode 100644 index 20c36840b1..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/pal_except_filter.c +++ /dev/null @@ -1,206 +0,0 @@ -// 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: pal_except_filter.c (test 3) -** -** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER in the -** presence of a call stack. An -** exception is forced and passed to two nested exception filters for -** consideration. The first filter returns EXCEPTION_CONTINUE_SEARCH -** so the second can run and return EXCEPTION_EXECUTE_HANDLER. The -** initial exception handler should be skipped, and the second -** executed -** -** -**===================================================================*/ - - - -#include - -BOOL bFilterCS = FALSE; -BOOL bFilterEE = FALSE; -BOOL bTry1 = FALSE; -BOOL bTry2 = FALSE; -BOOL bExcept1 = FALSE; -BOOL bExcept2 = FALSE; -BOOL bContinued = FALSE; -const int nValidator = 12321; - -LONG ContSearchFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) -{ - - /* let the main know we've hit the filter function */ - bFilterCS = TRUE; - - if (!bTry1 || !bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ContSearch filter was hit without PAL_TRY being hit.\n"); - } - - if (bFilterEE) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ContSearch filter was hit after the ExecuteException " - "filter.\n"); - } - - return EXCEPTION_CONTINUE_SEARCH; -} - -LONG ExecExeptionFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) -{ - /* let the main know we've hit the filter function */ - bFilterEE = TRUE; - - if (!bTry1 || !bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ContSearch filter was hit without PAL_TRY being hit.\n"); - } - - if (!bFilterCS) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ExecExeption filter was hit before the ContSearch " - "filter.\n"); - } - return EXCEPTION_EXECUTE_HANDLER; -} - -void NestedFunc1 (void) -{ - int* p = 0x00000000; /* pointer to NULL */ - - PAL_TRY - { - if (bExcept1 || bExcept2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); - } - bTry2 = TRUE; /* indicate we hit the inner PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " We executed beyond the trapping code.\n"); - } - PAL_EXCEPT_FILTER(ContSearchFilter, (LPVOID)&nValidator) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The dummy handler was " - "being hit.\n"); - bExcept2 = TRUE; /* indicate we hit the inner block */ - } - PAL_ENDTRY; - -} - -void NestedFunc2 (void) -{ - NestedFunc1(); -} - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the second exception block only based - ** on the return codes of the filters - */ - - PAL_TRY - { - if (bExcept1 || bExcept2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); - } - bTry1 = TRUE; /* indicate we hit the outer PAL_TRY block */ - - NestedFunc2(); - - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " We executed beyond the trapping code.\n"); - } - PAL_EXCEPT_FILTER(ExecExeptionFilter, (LPVOID)&nValidator) - { - if (!bTry1) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without PAL_TRY's code " - "being hit.\n"); - } - if (!bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without PAL_TRY's code " - "being hit.\n"); - } - if (!bFilterCS) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without the inner filter " - "being hit.\n"); - } - if (!bFilterEE) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without the outer filter " - "being hit.\n"); - } - bExcept1 = TRUE; /* indicate we hit the outer block */ - } - PAL_ENDTRY; - - if (!bTry1) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the outer" - " PAL_TRY block was not executed.\n"); - } - - if (bExcept2) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "inner PAL_EXCEPT_FILTER block was executed.\n"); - } - if (!bExcept1) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "outer PAL_EXCEPT_FILTER block was not executed.\n"); - } - - if (!bFilterCS) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "search continuing filter" - " function was not executed.\n"); - } - if (!bFilterEE) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "execute handler filter" - " function was not executed.\n"); - } - - - /* did we hit all the code blocks? */ - if(!bTry1 || !bTry2 || !bExcept1 || bExcept2 || !bFilterEE || !bFilterCS ) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/pal_except_filter.cpp b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/pal_except_filter.cpp new file mode 100644 index 0000000000..20c36840b1 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER/test3/pal_except_filter.cpp @@ -0,0 +1,206 @@ +// 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: pal_except_filter.c (test 3) +** +** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER in the +** presence of a call stack. An +** exception is forced and passed to two nested exception filters for +** consideration. The first filter returns EXCEPTION_CONTINUE_SEARCH +** so the second can run and return EXCEPTION_EXECUTE_HANDLER. The +** initial exception handler should be skipped, and the second +** executed +** +** +**===================================================================*/ + + + +#include + +BOOL bFilterCS = FALSE; +BOOL bFilterEE = FALSE; +BOOL bTry1 = FALSE; +BOOL bTry2 = FALSE; +BOOL bExcept1 = FALSE; +BOOL bExcept2 = FALSE; +BOOL bContinued = FALSE; +const int nValidator = 12321; + +LONG ContSearchFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) +{ + + /* let the main know we've hit the filter function */ + bFilterCS = TRUE; + + if (!bTry1 || !bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ContSearch filter was hit without PAL_TRY being hit.\n"); + } + + if (bFilterEE) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ContSearch filter was hit after the ExecuteException " + "filter.\n"); + } + + return EXCEPTION_CONTINUE_SEARCH; +} + +LONG ExecExeptionFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) +{ + /* let the main know we've hit the filter function */ + bFilterEE = TRUE; + + if (!bTry1 || !bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ContSearch filter was hit without PAL_TRY being hit.\n"); + } + + if (!bFilterCS) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ExecExeption filter was hit before the ContSearch " + "filter.\n"); + } + return EXCEPTION_EXECUTE_HANDLER; +} + +void NestedFunc1 (void) +{ + int* p = 0x00000000; /* pointer to NULL */ + + PAL_TRY + { + if (bExcept1 || bExcept2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); + } + bTry2 = TRUE; /* indicate we hit the inner PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " We executed beyond the trapping code.\n"); + } + PAL_EXCEPT_FILTER(ContSearchFilter, (LPVOID)&nValidator) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The dummy handler was " + "being hit.\n"); + bExcept2 = TRUE; /* indicate we hit the inner block */ + } + PAL_ENDTRY; + +} + +void NestedFunc2 (void) +{ + NestedFunc1(); +} + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the second exception block only based + ** on the return codes of the filters + */ + + PAL_TRY + { + if (bExcept1 || bExcept2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); + } + bTry1 = TRUE; /* indicate we hit the outer PAL_TRY block */ + + NestedFunc2(); + + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " We executed beyond the trapping code.\n"); + } + PAL_EXCEPT_FILTER(ExecExeptionFilter, (LPVOID)&nValidator) + { + if (!bTry1) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without PAL_TRY's code " + "being hit.\n"); + } + if (!bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without PAL_TRY's code " + "being hit.\n"); + } + if (!bFilterCS) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without the inner filter " + "being hit.\n"); + } + if (!bFilterEE) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without the outer filter " + "being hit.\n"); + } + bExcept1 = TRUE; /* indicate we hit the outer block */ + } + PAL_ENDTRY; + + if (!bTry1) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the outer" + " PAL_TRY block was not executed.\n"); + } + + if (bExcept2) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "inner PAL_EXCEPT_FILTER block was executed.\n"); + } + if (!bExcept1) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "outer PAL_EXCEPT_FILTER block was not executed.\n"); + } + + if (!bFilterCS) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "search continuing filter" + " function was not executed.\n"); + } + if (!bFilterEE) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "execute handler filter" + " function was not executed.\n"); + } + + + /* did we hit all the code blocks? */ + if(!bTry1 || !bTry2 || !bExcept1 || bExcept2 || !bFilterEE || !bFilterCS ) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/CMakeLists.txt index 21c3b5d33c..cf0a5e7c6d 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_EXCEPT_FILTER_EX.c + PAL_EXCEPT_FILTER_EX.cpp ) add_executable(paltest_pal_except_filter_ex_test1 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/PAL_EXCEPT_FILTER_EX.c b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/PAL_EXCEPT_FILTER_EX.c deleted file mode 100644 index 91f392d8d7..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/PAL_EXCEPT_FILTER_EX.c +++ /dev/null @@ -1,197 +0,0 @@ -// 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: PAL_EXCEPT_FILTER_EX.c (test 1) -** -** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER_EX. -** There are two try blocks in this test. The first forces an -** exception error to force hitting the first filter. The second -** doesn't to make sure we don't hit the filter. A value is also -** passed into the filter program and it is validated to make sure -** it was passed correctly. -** -** -**===================================================================*/ - -#include - -BOOL bFilter = FALSE; -BOOL bTry = FALSE; -const int nValidator = 12321; - - -/** -** -** Filter function for the first try block -** -**/ - -LONG Filter_01(EXCEPTION_POINTERS* ep, VOID *pnTestInt) -{ - int nTestInt = *(int *)pnTestInt; - - /* let the main know we've hit the filter function */ - bFilter = TRUE; - - if (!bTry) - { - Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." - " The filter was hit without PAL_TRY being hit.\n"); - } - - /* was the correct value passed? */ - if (nValidator != nTestInt) - { - Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Parameter passed to filter" - " function should have been \"%d\" but was \"%d\".\n", - nValidator, - nTestInt); - } - - return EXCEPTION_EXECUTE_HANDLER; -} - - -/** -** -** Filter function for the second try block. We shouldn't -** hit this function. -** -**/ - -LONG Filter_02(EXCEPTION_POINTERS* ep, VOID *pnTestInt) -{ - /* let the main know we've hit the filter function */ - bFilter = TRUE; - - return EXCEPTION_EXECUTE_HANDLER; -} - - -int __cdecl main(int argc, char *argv[]) -{ - int* p = 0x00000000; - BOOL bExcept = FALSE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the exception block - */ - - PAL_TRY - { - if (bExcept) - { - Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." - " The first PAL_EXCEPT_FILTER_EX was hit before PAL_TRY.\n"); - } - - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - - Fail("PAL_EXCEPT_FILTER_EX: ERROR -> code was executed after the " - "access violation.\n"); - } - PAL_EXCEPT_FILTER(Filter_01, (LPVOID)&nValidator) - { - if (!bTry) - { - Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER_EX was hit without PAL_TRY being hit.\n"); - } - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER_EX block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the " - "first PAL_TRY block was not executed.\n"); - } - - if (!bExcept) - { - Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the " - "first PAL_EXCEPT_FILTER_EX block was not executed.\n"); - } - - if (!bFilter) - { - Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the first" - " filter function was not executed.\n"); - } - - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept || !bFilter) - { - Fail(""); - } - - bTry = bExcept = bFilter = FALSE; - - - /* - ** test to make sure we skip the exception block - */ - - PAL_TRY - { - if (bExcept) - { - Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." - " Second PAL_EXCEPT_FILTER_EX was hit before PAL_TRY.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - } - PAL_EXCEPT_FILTER(Filter_02, (LPVOID)&nValidator) - { - if (!bTry) - { - Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER_EX was hit without PAL_TRY being hit.\n"); - } - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER_EX block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the " - "second PAL_TRY block was not executed.\n"); - } - - if (bExcept) - { - Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the " - "second PAL_EXCEPT_FILTER_EX block was executed even though an" - " exception was not triggered.\n"); - } - - if (bFilter) - { - Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the second" - " filter function was executed even though an exception was" - " not triggered.\n"); - } - - - /* did we hit all the correct code blocks? */ - if(!bTry || bExcept || bFilter) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/PAL_EXCEPT_FILTER_EX.cpp b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/PAL_EXCEPT_FILTER_EX.cpp new file mode 100644 index 0000000000..91f392d8d7 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test1/PAL_EXCEPT_FILTER_EX.cpp @@ -0,0 +1,197 @@ +// 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: PAL_EXCEPT_FILTER_EX.c (test 1) +** +** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER_EX. +** There are two try blocks in this test. The first forces an +** exception error to force hitting the first filter. The second +** doesn't to make sure we don't hit the filter. A value is also +** passed into the filter program and it is validated to make sure +** it was passed correctly. +** +** +**===================================================================*/ + +#include + +BOOL bFilter = FALSE; +BOOL bTry = FALSE; +const int nValidator = 12321; + + +/** +** +** Filter function for the first try block +** +**/ + +LONG Filter_01(EXCEPTION_POINTERS* ep, VOID *pnTestInt) +{ + int nTestInt = *(int *)pnTestInt; + + /* let the main know we've hit the filter function */ + bFilter = TRUE; + + if (!bTry) + { + Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." + " The filter was hit without PAL_TRY being hit.\n"); + } + + /* was the correct value passed? */ + if (nValidator != nTestInt) + { + Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Parameter passed to filter" + " function should have been \"%d\" but was \"%d\".\n", + nValidator, + nTestInt); + } + + return EXCEPTION_EXECUTE_HANDLER; +} + + +/** +** +** Filter function for the second try block. We shouldn't +** hit this function. +** +**/ + +LONG Filter_02(EXCEPTION_POINTERS* ep, VOID *pnTestInt) +{ + /* let the main know we've hit the filter function */ + bFilter = TRUE; + + return EXCEPTION_EXECUTE_HANDLER; +} + + +int __cdecl main(int argc, char *argv[]) +{ + int* p = 0x00000000; + BOOL bExcept = FALSE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the exception block + */ + + PAL_TRY + { + if (bExcept) + { + Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." + " The first PAL_EXCEPT_FILTER_EX was hit before PAL_TRY.\n"); + } + + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + + Fail("PAL_EXCEPT_FILTER_EX: ERROR -> code was executed after the " + "access violation.\n"); + } + PAL_EXCEPT_FILTER(Filter_01, (LPVOID)&nValidator) + { + if (!bTry) + { + Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER_EX was hit without PAL_TRY being hit.\n"); + } + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER_EX block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the " + "first PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the " + "first PAL_EXCEPT_FILTER_EX block was not executed.\n"); + } + + if (!bFilter) + { + Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the first" + " filter function was not executed.\n"); + } + + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept || !bFilter) + { + Fail(""); + } + + bTry = bExcept = bFilter = FALSE; + + + /* + ** test to make sure we skip the exception block + */ + + PAL_TRY + { + if (bExcept) + { + Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." + " Second PAL_EXCEPT_FILTER_EX was hit before PAL_TRY.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + } + PAL_EXCEPT_FILTER(Filter_02, (LPVOID)&nValidator) + { + if (!bTry) + { + Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER_EX was hit without PAL_TRY being hit.\n"); + } + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER_EX block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the " + "second PAL_TRY block was not executed.\n"); + } + + if (bExcept) + { + Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the " + "second PAL_EXCEPT_FILTER_EX block was executed even though an" + " exception was not triggered.\n"); + } + + if (bFilter) + { + Trace("PAL_EXCEPT_FILTER_EX: ERROR -> It appears the code in the second" + " filter function was executed even though an exception was" + " not triggered.\n"); + } + + + /* did we hit all the correct code blocks? */ + if(!bTry || bExcept || bFilter) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/CMakeLists.txt index 350acff036..a3f82c26b9 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - pal_except_filter_ex.c + pal_except_filter_ex.cpp ) add_executable(paltest_pal_except_filter_ex_test2 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/pal_except_filter_ex.c b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/pal_except_filter_ex.c deleted file mode 100644 index ab25c49733..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/pal_except_filter_ex.c +++ /dev/null @@ -1,142 +0,0 @@ -// 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: PAL_EXCEPT_FILTER_EX.c (test 2) -** -** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER_EX. -** There is a nested try blocks in this test. The nested -** PAL_TRY creates an exception and the FILTER creates another. -** This test makes sure that this case does not end in a -** infinite loop. -** -** -**===================================================================*/ - -#include - -BOOL bFilter = FALSE; -BOOL bTry = FALSE; -BOOL bTry2 = FALSE; -const int nValidator = 12321; - -/* Filter function for the first try block. - */ -LONG Filter_01(EXCEPTION_POINTERS* ep, VOID *pnTestInt) -{ - int nTestInt = *(int *)pnTestInt; - - /* Signal main() that filter has been executed. */ - bFilter = TRUE; - - if (!bTry) - { - Fail("ERROR: The filter was executed without " - "entering the first PAL_TRY.\n"); - } - - if (!bTry2) - { - Fail("ERROR: The filter was executed without " - "entering the second PAL_TRY.\n"); - } - - /* Was the correct value passed? */ - if (nValidator != nTestInt) - { - Fail("ERROR: Parameter passed to filter function " - "should have been \"%d\" but was \"%d\".\n", - nValidator, - nTestInt); - } - - return EXCEPTION_EXECUTE_HANDLER; -} - -int __cdecl main(int argc, char *argv[]) -{ - int* p = 0x00000000; - BOOL bExcept = FALSE; - BOOL bExcept2 = FALSE; - - /* Initalize the PAL. - */ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Test a nested PAL_Try block. - */ - PAL_TRY - { - /* Signal entry into first PAL_TRY block.*/ - bTry = TRUE; - - PAL_TRY - { - /* Signal entry into second PAL_TRY block.*/ - bTry2 = TRUE; - /* Cause an exception.*/ - *p = 13; - } - PAL_EXCEPT_FILTER(Filter_01, (LPVOID)&nValidator) - { - /* Signal entry into second PAL_EXCEPT filter.*/ - bExcept = TRUE; - /* Cause another exception.*/ - *p = 13; - } - PAL_ENDTRY - - } - PAL_EXCEPT_FILTER(Filter_01, (LPVOID)&nValidator) - { - /* Signal entry into second PAL_EXCEPT filter.*/ - bExcept2 = TRUE; - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("ERROR: The code in the first " - "PAL_TRY block was not executed.\n"); - } - - if (!bTry2) - { - Trace("ERROR: The code in the nested " - "PAL_TRY block was not executed.\n"); - } - - if (!bExcept) - { - Trace("ERROR: The code in the first " - "PAL_EXCEPT_FILTER_EX block was not executed.\n"); - } - - if (!bExcept2) - { - Trace("ERROR: The code in the second " - "PAL_EXCEPT_FILTER_EX block was not executed.\n"); - } - - if (!bFilter) - { - Trace("ERROR: The code in the first " - "filter function was not executed.\n"); - } - - if(!bTry || !bTry2 || !bExcept || !bExcept2 || !bFilter ) - { - Fail(""); - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/pal_except_filter_ex.cpp b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/pal_except_filter_ex.cpp new file mode 100644 index 0000000000..ab25c49733 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test2/pal_except_filter_ex.cpp @@ -0,0 +1,142 @@ +// 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: PAL_EXCEPT_FILTER_EX.c (test 2) +** +** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER_EX. +** There is a nested try blocks in this test. The nested +** PAL_TRY creates an exception and the FILTER creates another. +** This test makes sure that this case does not end in a +** infinite loop. +** +** +**===================================================================*/ + +#include + +BOOL bFilter = FALSE; +BOOL bTry = FALSE; +BOOL bTry2 = FALSE; +const int nValidator = 12321; + +/* Filter function for the first try block. + */ +LONG Filter_01(EXCEPTION_POINTERS* ep, VOID *pnTestInt) +{ + int nTestInt = *(int *)pnTestInt; + + /* Signal main() that filter has been executed. */ + bFilter = TRUE; + + if (!bTry) + { + Fail("ERROR: The filter was executed without " + "entering the first PAL_TRY.\n"); + } + + if (!bTry2) + { + Fail("ERROR: The filter was executed without " + "entering the second PAL_TRY.\n"); + } + + /* Was the correct value passed? */ + if (nValidator != nTestInt) + { + Fail("ERROR: Parameter passed to filter function " + "should have been \"%d\" but was \"%d\".\n", + nValidator, + nTestInt); + } + + return EXCEPTION_EXECUTE_HANDLER; +} + +int __cdecl main(int argc, char *argv[]) +{ + int* p = 0x00000000; + BOOL bExcept = FALSE; + BOOL bExcept2 = FALSE; + + /* Initalize the PAL. + */ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Test a nested PAL_Try block. + */ + PAL_TRY + { + /* Signal entry into first PAL_TRY block.*/ + bTry = TRUE; + + PAL_TRY + { + /* Signal entry into second PAL_TRY block.*/ + bTry2 = TRUE; + /* Cause an exception.*/ + *p = 13; + } + PAL_EXCEPT_FILTER(Filter_01, (LPVOID)&nValidator) + { + /* Signal entry into second PAL_EXCEPT filter.*/ + bExcept = TRUE; + /* Cause another exception.*/ + *p = 13; + } + PAL_ENDTRY + + } + PAL_EXCEPT_FILTER(Filter_01, (LPVOID)&nValidator) + { + /* Signal entry into second PAL_EXCEPT filter.*/ + bExcept2 = TRUE; + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("ERROR: The code in the first " + "PAL_TRY block was not executed.\n"); + } + + if (!bTry2) + { + Trace("ERROR: The code in the nested " + "PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("ERROR: The code in the first " + "PAL_EXCEPT_FILTER_EX block was not executed.\n"); + } + + if (!bExcept2) + { + Trace("ERROR: The code in the second " + "PAL_EXCEPT_FILTER_EX block was not executed.\n"); + } + + if (!bFilter) + { + Trace("ERROR: The code in the first " + "filter function was not executed.\n"); + } + + if(!bTry || !bTry2 || !bExcept || !bExcept2 || !bFilter ) + { + Fail(""); + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/CMakeLists.txt index 7f485c8ca4..532b29a9a1 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - pal_except_filter.c + pal_except_filter.cpp ) add_executable(paltest_pal_except_filter_ex_test3 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/pal_except_filter.c b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/pal_except_filter.c deleted file mode 100644 index a17cb4f6b3..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/pal_except_filter.c +++ /dev/null @@ -1,208 +0,0 @@ -// 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: pal_except_filter_ex.c (test 3) -** -** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER_EX. An -** exception is forced and passed to two nested exception filters for -** consideration. The first filter returns EXCEPTION_CONTINUE_SEARCH -** so the second can run and return EXCEPTION_EXECUTE_HANDLER. The -** initial exception handler should be skipped, and the second -** executed -** -** -**===================================================================*/ - - - -#include - -BOOL bFilterCS = FALSE; -BOOL bFilterEE = FALSE; -BOOL bTry1 = FALSE; -BOOL bTry2 = FALSE; -BOOL bContinued = FALSE; -const int nValidator = 12321; - -LONG ContSearchFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) -{ - - /* let the main know we've hit the filter function */ - bFilterCS = TRUE; - - if (!bTry1 || !bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ContSearch filter was hit without PAL_TRY being hit.\n"); - } - - if (bFilterEE) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ContSearch filter was hit after the ExecuteException " - "filter.\n"); - } - - return EXCEPTION_CONTINUE_SEARCH; -} - -LONG ExecExeptionFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) -{ - /* let the main know we've hit the filter function */ - bFilterEE = TRUE; - - if (!bTry1 || !bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ContSearch filter was hit without PAL_TRY being hit.\n"); - } - - if (!bFilterCS) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ExecExeption filter was hit before the ContSearch " - "filter.\n"); - } - return EXCEPTION_EXECUTE_HANDLER; -} - -int __cdecl main(int argc, char *argv[]) -{ - int* p = 0x00000000; /* pointer to NULL */ - BOOL bExcept1 = FALSE; - BOOL bExcept2 = FALSE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the second exception block only based - ** on the return codes of the filters - */ - - PAL_TRY - { - if (bExcept1 || bExcept2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); - } - bTry1 = TRUE; /* indicate we hit the outer PAL_TRY block */ - - PAL_TRY - { - if (bExcept1 || bExcept2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); - } - bTry2 = TRUE; /* indicate we hit the inner PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " We executed beyond the trapping code.\n"); - } - - PAL_EXCEPT_FILTER(ContSearchFilter, (LPVOID)&nValidator) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The dummy handler was " - "being hit.\n"); - } - PAL_ENDTRY; - - bExcept2 = TRUE; /* indicate we hit the inner block */ - } - PAL_EXCEPT_FILTER(ExecExeptionFilter, (LPVOID)&nValidator) - { - if (!bTry1) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without PAL_TRY's code " - "being hit.\n"); - } - if (!bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without PAL_TRY's code " - "being hit.\n"); - } - if (!bFilterCS) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on. " - "PAL_EXCEPT_FILTER's handler was hit without " - "the inner filter being hit.\n"); - } - if (!bFilterEE) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on. " - "PAL_EXCEPT_FILTER's handler was hit without " - "the outer filter being hit.\n"); - } - bExcept1 = TRUE; /* indicate we hit the outer block */ - } - PAL_ENDTRY; - - if (!bTry1) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the outer" - " PAL_TRY block was not executed.\n"); - } - - if (!bTry2) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the inner" - " PAL_TRY block was not executed.\n"); - } - - if (bExcept2) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "inner PAL_EXCEPT_FILTER block was executed.\n"); - } - if (!bExcept1) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "outer PAL_EXCEPT_FILTER block was not executed.\n"); - } - - if (!bFilterCS) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "search continuing filter" - " function was not executed.\n"); - } - if (!bFilterEE) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "execute handler filter" - " function was not executed.\n"); - } - - - if (!bTry2) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the PAL_TRY " - "block after the exception causing statements " - "was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry1 || !bTry2 || !bExcept1 || bExcept2 || !bFilterEE || !bFilterCS ) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/pal_except_filter.cpp b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/pal_except_filter.cpp new file mode 100644 index 0000000000..a17cb4f6b3 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_EXCEPT_FILTER_EX/test3/pal_except_filter.cpp @@ -0,0 +1,208 @@ +// 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: pal_except_filter_ex.c (test 3) +** +** Purpose: Tests the PAL implementation of the PAL_EXCEPT_FILTER_EX. An +** exception is forced and passed to two nested exception filters for +** consideration. The first filter returns EXCEPTION_CONTINUE_SEARCH +** so the second can run and return EXCEPTION_EXECUTE_HANDLER. The +** initial exception handler should be skipped, and the second +** executed +** +** +**===================================================================*/ + + + +#include + +BOOL bFilterCS = FALSE; +BOOL bFilterEE = FALSE; +BOOL bTry1 = FALSE; +BOOL bTry2 = FALSE; +BOOL bContinued = FALSE; +const int nValidator = 12321; + +LONG ContSearchFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) +{ + + /* let the main know we've hit the filter function */ + bFilterCS = TRUE; + + if (!bTry1 || !bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ContSearch filter was hit without PAL_TRY being hit.\n"); + } + + if (bFilterEE) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ContSearch filter was hit after the ExecuteException " + "filter.\n"); + } + + return EXCEPTION_CONTINUE_SEARCH; +} + +LONG ExecExeptionFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) +{ + /* let the main know we've hit the filter function */ + bFilterEE = TRUE; + + if (!bTry1 || !bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ContSearch filter was hit without PAL_TRY being hit.\n"); + } + + if (!bFilterCS) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ExecExeption filter was hit before the ContSearch " + "filter.\n"); + } + return EXCEPTION_EXECUTE_HANDLER; +} + +int __cdecl main(int argc, char *argv[]) +{ + int* p = 0x00000000; /* pointer to NULL */ + BOOL bExcept1 = FALSE; + BOOL bExcept2 = FALSE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the second exception block only based + ** on the return codes of the filters + */ + + PAL_TRY + { + if (bExcept1 || bExcept2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); + } + bTry1 = TRUE; /* indicate we hit the outer PAL_TRY block */ + + PAL_TRY + { + if (bExcept1 || bExcept2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); + } + bTry2 = TRUE; /* indicate we hit the inner PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " We executed beyond the trapping code.\n"); + } + + PAL_EXCEPT_FILTER(ContSearchFilter, (LPVOID)&nValidator) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The dummy handler was " + "being hit.\n"); + } + PAL_ENDTRY; + + bExcept2 = TRUE; /* indicate we hit the inner block */ + } + PAL_EXCEPT_FILTER(ExecExeptionFilter, (LPVOID)&nValidator) + { + if (!bTry1) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without PAL_TRY's code " + "being hit.\n"); + } + if (!bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without PAL_TRY's code " + "being hit.\n"); + } + if (!bFilterCS) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on. " + "PAL_EXCEPT_FILTER's handler was hit without " + "the inner filter being hit.\n"); + } + if (!bFilterEE) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on. " + "PAL_EXCEPT_FILTER's handler was hit without " + "the outer filter being hit.\n"); + } + bExcept1 = TRUE; /* indicate we hit the outer block */ + } + PAL_ENDTRY; + + if (!bTry1) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the outer" + " PAL_TRY block was not executed.\n"); + } + + if (!bTry2) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the inner" + " PAL_TRY block was not executed.\n"); + } + + if (bExcept2) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "inner PAL_EXCEPT_FILTER block was executed.\n"); + } + if (!bExcept1) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "outer PAL_EXCEPT_FILTER block was not executed.\n"); + } + + if (!bFilterCS) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "search continuing filter" + " function was not executed.\n"); + } + if (!bFilterEE) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "execute handler filter" + " function was not executed.\n"); + } + + + if (!bTry2) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the PAL_TRY " + "block after the exception causing statements " + "was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry1 || !bTry2 || !bExcept1 || bExcept2 || !bFilterEE || !bFilterCS ) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} + + diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/CMakeLists.txt index 8a1a832361..b478de63e4 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_TRY_EXCEPT.c + PAL_TRY_EXCEPT.cpp ) add_executable(paltest_pal_try_except_test1 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.c b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.c deleted file mode 100644 index 4fb09bd276..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.c +++ /dev/null @@ -1,82 +0,0 @@ -// 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: PAL_TRY_EXCEPT.c (test 1) -** -** Purpose: Tests the PAL implementation of the PAL_TRY and -** PAL_EXCEPT functions. An exception is forced to ensure -** the exception block is hit. -** -** -**===================================================================*/ - - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - int* p = 0x00000000; /* NULL pointer */ - BOOL bTry = FALSE; - BOOL bExcept = FALSE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the exception block - */ - - PAL_TRY - { - if (bExcept) - { - Fail("PAL_TRY_EXCEPT: ERROR -> Something weird is going on." - " PAL_EXCEPT was hit before PAL_TRY.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - Fail("PAL_TRY_EXCEPT: ERROR -> code was executed after the " - "access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("PAL_TRY_EXCEPT: ERROR -> Something weird is going on." - " PAL_EXCEPT was hit without PAL_TRY being hit.\n"); - } - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" - " block was not executed.\n"); - } - - if (!bExcept) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_EXCEPT" - " block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.cpp b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.cpp new file mode 100644 index 0000000000..4fb09bd276 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test1/PAL_TRY_EXCEPT.cpp @@ -0,0 +1,82 @@ +// 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: PAL_TRY_EXCEPT.c (test 1) +** +** Purpose: Tests the PAL implementation of the PAL_TRY and +** PAL_EXCEPT functions. An exception is forced to ensure +** the exception block is hit. +** +** +**===================================================================*/ + + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + int* p = 0x00000000; /* NULL pointer */ + BOOL bTry = FALSE; + BOOL bExcept = FALSE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the exception block + */ + + PAL_TRY + { + if (bExcept) + { + Fail("PAL_TRY_EXCEPT: ERROR -> Something weird is going on." + " PAL_EXCEPT was hit before PAL_TRY.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + Fail("PAL_TRY_EXCEPT: ERROR -> code was executed after the " + "access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("PAL_TRY_EXCEPT: ERROR -> Something weird is going on." + " PAL_EXCEPT was hit without PAL_TRY being hit.\n"); + } + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" + " block was not executed.\n"); + } + + if (!bExcept) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_EXCEPT" + " block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/CMakeLists.txt index cdf371926c..0e344a9320 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_TRY_EXCEPT.c + PAL_TRY_EXCEPT.cpp ) add_executable(paltest_pal_try_except_test2 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.c b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.c deleted file mode 100644 index eb7b9d1257..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: PAL_TRY_EXCEPT.c (test 2) -** -** Purpose: Tests the PAL implementation of the PAL_TRY and -** PAL_EXCEPT functions. Tests that the EXCEPTION block -** is missed if no exceptions happen -** -** -**===================================================================*/ - - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bTry = FALSE; - BOOL bExcept = FALSE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** Test to make sure we skip the exception block. - */ - - PAL_TRY - { - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" - " block was not executed.\n"); - } - - if (bExcept) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_EXCEPT" - " block was executed even though no exception was supposed to" - " happen.\n"); - } - - /* did we hit the correct code blocks? */ - if(!bTry || bExcept) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.cpp b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.cpp new file mode 100644 index 0000000000..eb7b9d1257 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT/test2/PAL_TRY_EXCEPT.cpp @@ -0,0 +1,68 @@ +// 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: PAL_TRY_EXCEPT.c (test 2) +** +** Purpose: Tests the PAL implementation of the PAL_TRY and +** PAL_EXCEPT functions. Tests that the EXCEPTION block +** is missed if no exceptions happen +** +** +**===================================================================*/ + + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bTry = FALSE; + BOOL bExcept = FALSE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** Test to make sure we skip the exception block. + */ + + PAL_TRY + { + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" + " block was not executed.\n"); + } + + if (bExcept) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_EXCEPT" + " block was executed even though no exception was supposed to" + " happen.\n"); + } + + /* did we hit the correct code blocks? */ + if(!bTry || bExcept) + { + Fail(""); + } + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/CMakeLists.txt index c30877f65e..cced8a11be 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_TRY_EXCEPT_EX.c + PAL_TRY_EXCEPT_EX.cpp ) add_executable(paltest_pal_try_except_ex_test1 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.c b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.c deleted file mode 100644 index 8b4dd7b430..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.c +++ /dev/null @@ -1,133 +0,0 @@ -// 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: PAL_TRY_EXCEPT.c (test 1) -** -** Purpose: Tests the PAL implementation of the PAL_TRY and -** PAL_EXCEPT functions. Exceptions are forced to ensure -** the exception blocks are hit. -** -** -**===================================================================*/ - - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - int* p = 0x00000000; /* NULL pointer */ - BOOL bTry = FALSE; - BOOL bExcept = FALSE; - BOOL bTestA = TRUE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the exception block - */ - - PAL_TRY - { - if (!bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR ->" - " It appears the first try block was hit a second time.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - Fail("PAL_TRY_EXCEPT: ERROR -> code was executed after the " - "access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR ->" - " It appears the first except block was hit a second time.\n"); - } - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" - " block was not executed.\n"); - } - - if (!bExcept) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the first" - " PAL_EXCEPT block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept) - { - Fail(""); - } - - - /* - ** test to make sure we get into the second exception block - */ - - bTry = FALSE; - bExcept = FALSE; - bTestA = FALSE; /* we are now going into the second block test */ - - - PAL_TRY - { - if (bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR -> It appears" - " the second try block was hit too early.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - Fail("PAL_TRY_EXCEPT: ERROR -> code was executed after the " - "access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR -> It appears" - " the second except block was hit too early.\n"); - } - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second" - " PAL_TRY block was not executed."); - } - - if (!bExcept) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_EXCEPT" - " block was not executed."); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept) - { - Fail("\n"); - } - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.cpp b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.cpp new file mode 100644 index 0000000000..8b4dd7b430 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test1/PAL_TRY_EXCEPT_EX.cpp @@ -0,0 +1,133 @@ +// 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: PAL_TRY_EXCEPT.c (test 1) +** +** Purpose: Tests the PAL implementation of the PAL_TRY and +** PAL_EXCEPT functions. Exceptions are forced to ensure +** the exception blocks are hit. +** +** +**===================================================================*/ + + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + int* p = 0x00000000; /* NULL pointer */ + BOOL bTry = FALSE; + BOOL bExcept = FALSE; + BOOL bTestA = TRUE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the exception block + */ + + PAL_TRY + { + if (!bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR ->" + " It appears the first try block was hit a second time.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + Fail("PAL_TRY_EXCEPT: ERROR -> code was executed after the " + "access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR ->" + " It appears the first except block was hit a second time.\n"); + } + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" + " block was not executed.\n"); + } + + if (!bExcept) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the first" + " PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept) + { + Fail(""); + } + + + /* + ** test to make sure we get into the second exception block + */ + + bTry = FALSE; + bExcept = FALSE; + bTestA = FALSE; /* we are now going into the second block test */ + + + PAL_TRY + { + if (bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR -> It appears" + " the second try block was hit too early.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + Fail("PAL_TRY_EXCEPT: ERROR -> code was executed after the " + "access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR -> It appears" + " the second except block was hit too early.\n"); + } + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second" + " PAL_TRY block was not executed."); + } + + if (!bExcept) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_EXCEPT" + " block was not executed."); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept) + { + Fail("\n"); + } + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/CMakeLists.txt index 0d4c4db240..c3549b5d87 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_TRY_EXCEPT_EX.c + PAL_TRY_EXCEPT_EX.cpp ) add_executable(paltest_pal_try_except_ex_test2 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.c b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.c deleted file mode 100644 index 5ab4a95ce9..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.c +++ /dev/null @@ -1,123 +0,0 @@ -// 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: PAL_TRY_EXCEPT.c (test 2) -** -** Purpose: Tests the PAL implementation of the PAL_TRY and -** PAL_EXCEPT functions. Exceptions are not forced to ensure -** the proper blocks are hit. -** -** -**===================================================================*/ - - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bTry = FALSE; - BOOL bExcept = FALSE; - BOOL bTestA = TRUE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the exception block - */ - - PAL_TRY - { - if (!bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR ->" - " It appears the first try block was hit a second time.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" - " block was not executed.\n"); - } - - if (bExcept) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the first" - " PAL_EXCEPT block was executed even though no exceptions were " - "encountered.\n"); - } - - /* did we hit all the proper code blocks? */ - if(!bTry || bExcept) - { - Fail(""); - } - - - /* - ** test to make sure we skip the second exception block - */ - - bTry = FALSE; - bExcept = FALSE; - bTestA = FALSE; /* we are now going into the second block test */ - - - PAL_TRY - { - if (bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR -> It appears" - " the second try block was hit too early.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR -> It appears" - " the second except block was hit too early.\n"); - } - bExcept = TRUE; /* indicate we hit the PAL_TRY block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second" - " PAL_TRY block was not executed.\n"); - } - - if (bExcept) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second" - " PAL_EXCEPT block was executed even though no exceptions were " - "encountered.\n"); - } - - /* did we hit all the proper code blocks? */ - if(!bTry || bExcept) - { - Fail("\n"); - } - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.cpp b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.cpp new file mode 100644 index 0000000000..5ab4a95ce9 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test2/PAL_TRY_EXCEPT_EX.cpp @@ -0,0 +1,123 @@ +// 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: PAL_TRY_EXCEPT.c (test 2) +** +** Purpose: Tests the PAL implementation of the PAL_TRY and +** PAL_EXCEPT functions. Exceptions are not forced to ensure +** the proper blocks are hit. +** +** +**===================================================================*/ + + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bTry = FALSE; + BOOL bExcept = FALSE; + BOOL bTestA = TRUE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the exception block + */ + + PAL_TRY + { + if (!bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR ->" + " It appears the first try block was hit a second time.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" + " block was not executed.\n"); + } + + if (bExcept) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the first" + " PAL_EXCEPT block was executed even though no exceptions were " + "encountered.\n"); + } + + /* did we hit all the proper code blocks? */ + if(!bTry || bExcept) + { + Fail(""); + } + + + /* + ** test to make sure we skip the second exception block + */ + + bTry = FALSE; + bExcept = FALSE; + bTestA = FALSE; /* we are now going into the second block test */ + + + PAL_TRY + { + if (bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR -> It appears" + " the second try block was hit too early.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR -> It appears" + " the second except block was hit too early.\n"); + } + bExcept = TRUE; /* indicate we hit the PAL_TRY block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second" + " PAL_TRY block was not executed.\n"); + } + + if (bExcept) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second" + " PAL_EXCEPT block was executed even though no exceptions were " + "encountered.\n"); + } + + /* did we hit all the proper code blocks? */ + if(!bTry || bExcept) + { + Fail("\n"); + } + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/CMakeLists.txt index dc797f2f09..34790da3d3 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_TRY_EXCEPT_EX.c + PAL_TRY_EXCEPT_EX.cpp ) add_executable(paltest_pal_try_except_ex_test3 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.c b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.c deleted file mode 100644 index d6a948926b..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.c +++ /dev/null @@ -1,130 +0,0 @@ -// 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: PAL_TRY_EXCEPT.c (test 3) -** -** Purpose: Tests the PAL implementation of the PAL_TRY and -** PAL_EXCEPT functions. Force an exception in only one block -** to ensure the proper exception block is hit. -** -** -**===================================================================*/ - - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - int* p = 0x00000000; /* NULL pointer */ - BOOL bTry = FALSE; - BOOL bExcept = FALSE; - BOOL bTestA = TRUE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the exception block - */ - - PAL_TRY - { - if (!bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR ->" - " It appears the first try block was hit a second time.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - Fail("PAL_TRY_EXCEPT: ERROR -> code was executed after the " - "access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR ->" - " It appears the first except block was hit a second time.\n"); - } - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" - " block was not executed.\n"); - } - - if (!bExcept) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the first" - " PAL_EXCEPT block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept) - { - Fail("\n"); - } - - - /* - ** test to make sure we get into the second exception block - */ - - bTry = FALSE; - bExcept = FALSE; - bTestA = FALSE; /* we are now going into the second block test */ - - - PAL_TRY - { - if (bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR -> It appears" - " the second try block was hit too early.\n"); - } - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (bTestA) - { - Fail("PAL_TRY_EXCEPT: ERROR -> It appears" - " the second except block was hit too early.\n"); - } - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second" - " PAL_TRY block was not executed.\n"); - } - - if (bExcept) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second " - " PAL_EXCEPT block was executed for some reason.\n"); - } - - /* did we hit all the correct code blocks? */ - if(!bTry || bExcept) - { - Fail("\n"); - } - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.cpp b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.cpp new file mode 100644 index 0000000000..d6a948926b --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_EXCEPT_EX/test3/PAL_TRY_EXCEPT_EX.cpp @@ -0,0 +1,130 @@ +// 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: PAL_TRY_EXCEPT.c (test 3) +** +** Purpose: Tests the PAL implementation of the PAL_TRY and +** PAL_EXCEPT functions. Force an exception in only one block +** to ensure the proper exception block is hit. +** +** +**===================================================================*/ + + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + int* p = 0x00000000; /* NULL pointer */ + BOOL bTry = FALSE; + BOOL bExcept = FALSE; + BOOL bTestA = TRUE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the exception block + */ + + PAL_TRY + { + if (!bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR ->" + " It appears the first try block was hit a second time.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + Fail("PAL_TRY_EXCEPT: ERROR -> code was executed after the " + "access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR ->" + " It appears the first except block was hit a second time.\n"); + } + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" + " block was not executed.\n"); + } + + if (!bExcept) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the first" + " PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept) + { + Fail("\n"); + } + + + /* + ** test to make sure we get into the second exception block + */ + + bTry = FALSE; + bExcept = FALSE; + bTestA = FALSE; /* we are now going into the second block test */ + + + PAL_TRY + { + if (bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR -> It appears" + " the second try block was hit too early.\n"); + } + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (bTestA) + { + Fail("PAL_TRY_EXCEPT: ERROR -> It appears" + " the second except block was hit too early.\n"); + } + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second" + " PAL_TRY block was not executed.\n"); + } + + if (bExcept) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the second " + " PAL_EXCEPT block was executed for some reason.\n"); + } + + /* did we hit all the correct code blocks? */ + if(!bTry || bExcept) + { + Fail("\n"); + } + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/CMakeLists.txt index a5fdd26924..f004db1658 100644 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_TRY_LEAVE_FINALLY.c + PAL_TRY_LEAVE_FINALLY.cpp ) add_executable(paltest_pal_try_leave_finally_test1 diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/PAL_TRY_LEAVE_FINALLY.c b/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/PAL_TRY_LEAVE_FINALLY.c deleted file mode 100644 index 675c2a5947..0000000000 --- a/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/PAL_TRY_LEAVE_FINALLY.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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: pal_try_leave_finally.c -** -** Purpose: Tests the PAL implementation of the PAL_TRY, PAL_LEAVE -** and PAL_FINALLY functions. -** -** -**===================================================================*/ - - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bTry = FALSE; - BOOL bFinally = FALSE; - BOOL bLeave = TRUE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - PAL_TRY - { - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - - goto Done; - - bLeave = FALSE; /* indicate we stuck around */ - Done: ; - } - PAL_FINALLY - { - bFinally = TRUE; /* indicate we hit the PAL_FINALLY block */ - } - PAL_ENDTRY; - - /* did we go where we were meant to go */ - if (!bTry) - { - Trace("PAL_TRY_FINALLY: ERROR -> It appears the code in the PAL_TRY" - " block was not executed.\n"); - } - - if (!bLeave) - { - Trace("PAL_TRY_FINALLY: ERROR -> It appears code was executed after " - "PAL_LEAVE was called. It should have jumped directly to the " - "PAL_FINALLY block.\n"); - } - - if (!bFinally) - { - Trace("PAL_TRY_FINALLY: ERROR -> It appears the code in the PAL_FINALLY" - " block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bLeave || !bFinally) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/PAL_TRY_LEAVE_FINALLY.cpp b/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/PAL_TRY_LEAVE_FINALLY.cpp new file mode 100644 index 0000000000..675c2a5947 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/PAL_TRY_LEAVE_FINALLY/test1/PAL_TRY_LEAVE_FINALLY.cpp @@ -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: pal_try_leave_finally.c +** +** Purpose: Tests the PAL implementation of the PAL_TRY, PAL_LEAVE +** and PAL_FINALLY functions. +** +** +**===================================================================*/ + + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bTry = FALSE; + BOOL bFinally = FALSE; + BOOL bLeave = TRUE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + PAL_TRY + { + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + + goto Done; + + bLeave = FALSE; /* indicate we stuck around */ + Done: ; + } + PAL_FINALLY + { + bFinally = TRUE; /* indicate we hit the PAL_FINALLY block */ + } + PAL_ENDTRY; + + /* did we go where we were meant to go */ + if (!bTry) + { + Trace("PAL_TRY_FINALLY: ERROR -> It appears the code in the PAL_TRY" + " block was not executed.\n"); + } + + if (!bLeave) + { + Trace("PAL_TRY_FINALLY: ERROR -> It appears code was executed after " + "PAL_LEAVE was called. It should have jumped directly to the " + "PAL_FINALLY block.\n"); + } + + if (!bFinally) + { + Trace("PAL_TRY_FINALLY: ERROR -> It appears the code in the PAL_FINALLY" + " block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bLeave || !bFinally) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/CMakeLists.txt index e526029bee..068427303f 100644 --- a/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_setunhandledexceptionfilter_test1 diff --git a/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/test1.c b/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/test1.c deleted file mode 100644 index 5a067f9354..0000000000 --- a/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/test1.c +++ /dev/null @@ -1,82 +0,0 @@ -// 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: test1.c -** -** Purpose: Sets up a new unhandled exception filter, and makes sure it -** returns the previous filter. Raises an unhandled exception and -** makes sure this reaches the filter. -** -** -**============================================================*/ - - -#include - -/* This isn't defined in the pal, so copied from win32 */ -#define EXCEPTION_EXECUTE_HANDLER 1 -#define EXCEPTION_CONTINUE_EXECUTION -1 - - -int InFilter = FALSE; - -LONG PALAPI FirstFilter(LPEXCEPTION_POINTERS p) -{ - return EXCEPTION_EXECUTE_HANDLER; -} - -LONG PALAPI ContinueFilter(LPEXCEPTION_POINTERS p) -{ - InFilter = TRUE; - - Trace("This test has succeeded as far at the automated checks can " - "tell. Manual verification is now required to be completely sure.\n"); - Trace("Now the PAL's handling of application errors will be tested " - "with an exception code of %u.\n", - p->ExceptionRecord->ExceptionCode); - Trace("Please verify that the actions that the PAL now takes are " - "as specified for it.\n"); - - return EXCEPTION_CONTINUE_SEARCH; -} - -int __cdecl main(int argc, char *argv[]) -{ - LPTOP_LEVEL_EXCEPTION_FILTER OldFilter; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - - SetUnhandledExceptionFilter(FirstFilter); - - OldFilter = SetUnhandledExceptionFilter(ContinueFilter); - if (OldFilter != FirstFilter) - { - Fail("SetUnhandledExceptionFilter did not return a pointer to the " - "previous filter!\n"); - } - - /* - * Raise an unhandled exception. This should cause our filter to be - * excecuted and the program to exit with a code the same as the - * exception code. - */ - RaiseException(3,0,0,0); - - - /* - * This code should not be executed because the toplevelhandler is - * expected to "just" set the exit code and abend the program - */ - Fail("An unhandled exception did not cause the program to abend with" - "the exit code == the ExceptionCode!\n"); - - PAL_Terminate(); - return FAIL; -} diff --git a/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/test1.cpp b/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/test1.cpp new file mode 100644 index 0000000000..5a067f9354 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/SetUnhandledExceptionFilter/test1/test1.cpp @@ -0,0 +1,82 @@ +// 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: test1.c +** +** Purpose: Sets up a new unhandled exception filter, and makes sure it +** returns the previous filter. Raises an unhandled exception and +** makes sure this reaches the filter. +** +** +**============================================================*/ + + +#include + +/* This isn't defined in the pal, so copied from win32 */ +#define EXCEPTION_EXECUTE_HANDLER 1 +#define EXCEPTION_CONTINUE_EXECUTION -1 + + +int InFilter = FALSE; + +LONG PALAPI FirstFilter(LPEXCEPTION_POINTERS p) +{ + return EXCEPTION_EXECUTE_HANDLER; +} + +LONG PALAPI ContinueFilter(LPEXCEPTION_POINTERS p) +{ + InFilter = TRUE; + + Trace("This test has succeeded as far at the automated checks can " + "tell. Manual verification is now required to be completely sure.\n"); + Trace("Now the PAL's handling of application errors will be tested " + "with an exception code of %u.\n", + p->ExceptionRecord->ExceptionCode); + Trace("Please verify that the actions that the PAL now takes are " + "as specified for it.\n"); + + return EXCEPTION_CONTINUE_SEARCH; +} + +int __cdecl main(int argc, char *argv[]) +{ + LPTOP_LEVEL_EXCEPTION_FILTER OldFilter; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + + SetUnhandledExceptionFilter(FirstFilter); + + OldFilter = SetUnhandledExceptionFilter(ContinueFilter); + if (OldFilter != FirstFilter) + { + Fail("SetUnhandledExceptionFilter did not return a pointer to the " + "previous filter!\n"); + } + + /* + * Raise an unhandled exception. This should cause our filter to be + * excecuted and the program to exit with a code the same as the + * exception code. + */ + RaiseException(3,0,0,0); + + + /* + * This code should not be executed because the toplevelhandler is + * expected to "just" set the exit code and abend the program + */ + Fail("An unhandled exception did not cause the program to abend with" + "the exit code == the ExceptionCode!\n"); + + PAL_Terminate(); + return FAIL; +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test1/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_except/test1/CMakeLists.txt index 635e35d635..b219238ef4 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_pal_except_test1 diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test1/test1.c b/src/pal/tests/palsuite/exception_handling/pal_except/test1/test1.c deleted file mode 100644 index 0fe48e7fc3..0000000000 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test1/test1.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: test1.c (exception_handling\pal_except\test1) -** -** Purpose: Test to make sure the PAL_EXCEPT block is executed -** after an exception occurs in the PAL_TRY block -** -** -**===================================================================*/ -#include - -/* Execution flags */ -BOOL bTry = FALSE; -BOOL bExcept = FALSE; - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - PAL_TRY - { - int* p = 0x00000000; /* NULL pointer */ - - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); - } - - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); - } - - if (!bExcept) - { - Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test1/test1.cpp b/src/pal/tests/palsuite/exception_handling/pal_except/test1/test1.cpp new file mode 100644 index 0000000000..0fe48e7fc3 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test1/test1.cpp @@ -0,0 +1,67 @@ +// 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: test1.c (exception_handling\pal_except\test1) +** +** Purpose: Test to make sure the PAL_EXCEPT block is executed +** after an exception occurs in the PAL_TRY block +** +** +**===================================================================*/ +#include + +/* Execution flags */ +BOOL bTry = FALSE; +BOOL bExcept = FALSE; + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + PAL_TRY + { + int* p = 0x00000000; /* NULL pointer */ + + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); + } + + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test2/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_except/test2/CMakeLists.txt index 813b0e66a1..27a725353b 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_pal_except_test2 diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test2/test2.c b/src/pal/tests/palsuite/exception_handling/pal_except/test2/test2.c deleted file mode 100644 index bc0d4e300a..0000000000 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test2/test2.c +++ /dev/null @@ -1,111 +0,0 @@ -// 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: test2.c (exception_handling\pal_except\test2) -** -** Purpose: Test to make sure the PAL_EXCEPT block is executed -** after an exception occurs in the PAL_TRY block -** that contains another PAL_TRY-PAL_EXCEPT block -** -** -**===================================================================*/ -#include - -/* Execution flags */ -BOOL bTry = FALSE; -BOOL bExcept = FALSE; -BOOL bTry_nested = FALSE; -BOOL bExcept_nested = FALSE; - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - PAL_TRY - { - int* p = 0x00000000; /* NULL pointer */ - - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - - - /* Nested PAL_TRY */ - PAL_TRY - { - bTry_nested = TRUE; - - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the nested access violation.\n"); - - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("ERROR: Nested PAL_EXCEPT was hit without " - "nested PAL_TRY being hit.\n"); - } - bExcept_nested = TRUE; - } - PAL_ENDTRY; - - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); - } - if (!bExcept_nested) - { - Fail("ERROR: PAL_EXCEPT was hit without " - "nested PAL_EXCEPT being hit.\n"); - } - - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); - } - - if (!bExcept) - { - Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); - } - - if (!bTry_nested) - { - Trace("ERROR: the code in the " - "nested PAL_TRY block was not executed.\n"); - } - - if (!bExcept_nested) - { - Trace("ERROR: the code in the " - "nested PAL_EXCEPT block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept || - !bTry_nested || !bExcept_nested) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test2/test2.cpp b/src/pal/tests/palsuite/exception_handling/pal_except/test2/test2.cpp new file mode 100644 index 0000000000..bc0d4e300a --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test2/test2.cpp @@ -0,0 +1,111 @@ +// 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: test2.c (exception_handling\pal_except\test2) +** +** Purpose: Test to make sure the PAL_EXCEPT block is executed +** after an exception occurs in the PAL_TRY block +** that contains another PAL_TRY-PAL_EXCEPT block +** +** +**===================================================================*/ +#include + +/* Execution flags */ +BOOL bTry = FALSE; +BOOL bExcept = FALSE; +BOOL bTry_nested = FALSE; +BOOL bExcept_nested = FALSE; + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + PAL_TRY + { + int* p = 0x00000000; /* NULL pointer */ + + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + + + /* Nested PAL_TRY */ + PAL_TRY + { + bTry_nested = TRUE; + + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the nested access violation.\n"); + + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: Nested PAL_EXCEPT was hit without " + "nested PAL_TRY being hit.\n"); + } + bExcept_nested = TRUE; + } + PAL_ENDTRY; + + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); + } + if (!bExcept_nested) + { + Fail("ERROR: PAL_EXCEPT was hit without " + "nested PAL_EXCEPT being hit.\n"); + } + + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); + } + + if (!bTry_nested) + { + Trace("ERROR: the code in the " + "nested PAL_TRY block was not executed.\n"); + } + + if (!bExcept_nested) + { + Trace("ERROR: the code in the " + "nested PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept || + !bTry_nested || !bExcept_nested) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test3/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_except/test3/CMakeLists.txt index 5fc3b096af..680341a782 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_pal_except_test3 diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test3/test3.c b/src/pal/tests/palsuite/exception_handling/pal_except/test3/test3.c deleted file mode 100644 index 0137697774..0000000000 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test3/test3.c +++ /dev/null @@ -1,120 +0,0 @@ -// 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: test3.c (exception_handling\pal_except\test3) -** -** Purpose: Test to make sure the PAL_EXCEPT block is executed -** after an exception occurs in the PAL_TRY block -** that calls a function that contains -** another PAL_TRY-PAL_EXCEPT block -** -** -**===================================================================*/ -#include - -/* Execution flags */ -BOOL bTry = FALSE; -BOOL bExcept = FALSE; -BOOL bTry_function = FALSE; -BOOL bExcept_function = FALSE; - -/* - * Helper function that contains a PAL_TRY-PAL_EXCEPT block - */ -void Helper() -{ - /* Nested PAL_TRY */ - PAL_TRY - { - int *lp = 0x00000000; - - bTry_function = TRUE; - - *lp = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the function's access violation.\n"); - - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("ERROR: Nested PAL_EXCEPT was hit without " - "the function's PAL_TRY being hit.\n"); - } - bExcept_function = TRUE; - } - PAL_ENDTRY; -} - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - PAL_TRY - { - int* p = 0x00000000; /* NULL pointer */ - - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - - Helper(); - - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); - } - if (!bExcept_function) - { - Fail("ERROR: PAL_EXCEPT was hit without " - "function's PAL_EXCEPT being hit.\n"); - } - - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); - } - - if (!bExcept) - { - Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); - } - - if (!bTry_function) - { - Trace("ERROR: the code in the " - "function's PAL_TRY block was not executed.\n"); - } - - if (!bExcept_function) - { - Trace("ERROR: the code in the " - "function's PAL_EXCEPT block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept || - !bTry_function || !bExcept_function) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test3/test3.cpp b/src/pal/tests/palsuite/exception_handling/pal_except/test3/test3.cpp new file mode 100644 index 0000000000..0137697774 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test3/test3.cpp @@ -0,0 +1,120 @@ +// 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: test3.c (exception_handling\pal_except\test3) +** +** Purpose: Test to make sure the PAL_EXCEPT block is executed +** after an exception occurs in the PAL_TRY block +** that calls a function that contains +** another PAL_TRY-PAL_EXCEPT block +** +** +**===================================================================*/ +#include + +/* Execution flags */ +BOOL bTry = FALSE; +BOOL bExcept = FALSE; +BOOL bTry_function = FALSE; +BOOL bExcept_function = FALSE; + +/* + * Helper function that contains a PAL_TRY-PAL_EXCEPT block + */ +void Helper() +{ + /* Nested PAL_TRY */ + PAL_TRY + { + int *lp = 0x00000000; + + bTry_function = TRUE; + + *lp = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the function's access violation.\n"); + + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: Nested PAL_EXCEPT was hit without " + "the function's PAL_TRY being hit.\n"); + } + bExcept_function = TRUE; + } + PAL_ENDTRY; +} + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + PAL_TRY + { + int* p = 0x00000000; /* NULL pointer */ + + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + + Helper(); + + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); + } + if (!bExcept_function) + { + Fail("ERROR: PAL_EXCEPT was hit without " + "function's PAL_EXCEPT being hit.\n"); + } + + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); + } + + if (!bTry_function) + { + Trace("ERROR: the code in the " + "function's PAL_TRY block was not executed.\n"); + } + + if (!bExcept_function) + { + Trace("ERROR: the code in the " + "function's PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept || + !bTry_function || !bExcept_function) + { + Fail(""); + } + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test4/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_except/test4/CMakeLists.txt index cc054d15dd..98eb7bfb23 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_pal_except_test4 diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test4/test4.c b/src/pal/tests/palsuite/exception_handling/pal_except/test4/test4.c deleted file mode 100644 index 87844973b0..0000000000 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test4/test4.c +++ /dev/null @@ -1,105 +0,0 @@ -// 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: test4.c (exception_handling\pal_except\test4) -** -** Purpose: Test to make sure the PAL_EXCEPT block is executed -** after an exception occurs in the PAL_TRY block -** if the PAL_EXCEPT block contains a nested -** PAL_TRY-PAL_EXCEPT block -** -** -**===================================================================*/ -#include - -/* Execution flags */ -BOOL bTry = FALSE; -BOOL bExcept = FALSE; -BOOL bTry_nested = FALSE; -BOOL bExcept_nested = FALSE; - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - PAL_TRY - { - int* p = 0x00000000; /* NULL pointer */ - - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); - } - - PAL_TRY - { - int *lp = 0x00000000; - - bTry_nested = TRUE; - *lp = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the " - "nested access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry_nested) - { - Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit " - "in the nested block.\n"); - } - bExcept_nested = TRUE; - } - PAL_ENDTRY; - - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); - } - - if (!bExcept) - { - Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); - } - - if (!bTry_nested) - { - Trace("ERROR: the code in the nested " - "PAL_TRY block was not executed.\n"); - } - - if (!bExcept_nested) - { - Trace("ERROR: the code in the nested " - "PAL_EXCEPT block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept || - !bTry_nested || !bExcept_nested) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test4/test4.cpp b/src/pal/tests/palsuite/exception_handling/pal_except/test4/test4.cpp new file mode 100644 index 0000000000..87844973b0 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test4/test4.cpp @@ -0,0 +1,105 @@ +// 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: test4.c (exception_handling\pal_except\test4) +** +** Purpose: Test to make sure the PAL_EXCEPT block is executed +** after an exception occurs in the PAL_TRY block +** if the PAL_EXCEPT block contains a nested +** PAL_TRY-PAL_EXCEPT block +** +** +**===================================================================*/ +#include + +/* Execution flags */ +BOOL bTry = FALSE; +BOOL bExcept = FALSE; +BOOL bTry_nested = FALSE; +BOOL bExcept_nested = FALSE; + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + PAL_TRY + { + int* p = 0x00000000; /* NULL pointer */ + + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); + } + + PAL_TRY + { + int *lp = 0x00000000; + + bTry_nested = TRUE; + *lp = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the " + "nested access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry_nested) + { + Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit " + "in the nested block.\n"); + } + bExcept_nested = TRUE; + } + PAL_ENDTRY; + + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); + } + + if (!bTry_nested) + { + Trace("ERROR: the code in the nested " + "PAL_TRY block was not executed.\n"); + } + + if (!bExcept_nested) + { + Trace("ERROR: the code in the nested " + "PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept || + !bTry_nested || !bExcept_nested) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test5/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_except/test5/CMakeLists.txt index 7b8f1d0361..9a39e32cce 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_pal_except_test5 diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test5/test5.c b/src/pal/tests/palsuite/exception_handling/pal_except/test5/test5.c deleted file mode 100644 index f9faf4440e..0000000000 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test5/test5.c +++ /dev/null @@ -1,112 +0,0 @@ -// 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: test5.c (exception_handling\pal_except\test5) -** -** Purpose: Test to make sure the PAL_EXCEPT block is executed -** after an exception occurs in the PAL_TRY block -** if the PAL_EXCEPT block calls a function that contains -** another PAL_TRY-PAL_EXCEPT block -** -** -**===================================================================*/ -#include - -/* Execution flags */ -BOOL bTry = FALSE; -BOOL bExcept = FALSE; -BOOL bTry_nested = FALSE; -BOOL bExcept_nested = FALSE; - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - PAL_TRY - { - int* p = 0x00000000; /* NULL pointer */ - - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - - - /* Nested PAL_TRY */ - PAL_TRY - { - bTry_nested = TRUE; - - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the nested access violation.\n"); - - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("ERROR: Nested PAL_EXCEPT was hit without " - "nested PAL_TRY being hit.\n"); - } - bExcept_nested = TRUE; - } - PAL_ENDTRY; - - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); - } - if (!bExcept_nested) - { - Fail("ERROR: PAL_EXCEPT was hit without " - "nested PAL_EXCEPT being hit.\n"); - } - - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); - } - - if (!bExcept) - { - Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); - } - - if (!bTry_nested) - { - Trace("ERROR: the code in the " - "nested PAL_TRY block was not executed.\n"); - } - - if (!bExcept_nested) - { - Trace("ERROR: the code in the " - "nested PAL_EXCEPT block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept || - !bTry_nested || !bExcept_nested) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test5/test5.cpp b/src/pal/tests/palsuite/exception_handling/pal_except/test5/test5.cpp new file mode 100644 index 0000000000..f9faf4440e --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test5/test5.cpp @@ -0,0 +1,112 @@ +// 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: test5.c (exception_handling\pal_except\test5) +** +** Purpose: Test to make sure the PAL_EXCEPT block is executed +** after an exception occurs in the PAL_TRY block +** if the PAL_EXCEPT block calls a function that contains +** another PAL_TRY-PAL_EXCEPT block +** +** +**===================================================================*/ +#include + +/* Execution flags */ +BOOL bTry = FALSE; +BOOL bExcept = FALSE; +BOOL bTry_nested = FALSE; +BOOL bExcept_nested = FALSE; + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + PAL_TRY + { + int* p = 0x00000000; /* NULL pointer */ + + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + + + /* Nested PAL_TRY */ + PAL_TRY + { + bTry_nested = TRUE; + + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the nested access violation.\n"); + + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: Nested PAL_EXCEPT was hit without " + "nested PAL_TRY being hit.\n"); + } + bExcept_nested = TRUE; + } + PAL_ENDTRY; + + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); + } + if (!bExcept_nested) + { + Fail("ERROR: PAL_EXCEPT was hit without " + "nested PAL_EXCEPT being hit.\n"); + } + + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); + } + + if (!bTry_nested) + { + Trace("ERROR: the code in the " + "nested PAL_TRY block was not executed.\n"); + } + + if (!bExcept_nested) + { + Trace("ERROR: the code in the " + "nested PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept || + !bTry_nested || !bExcept_nested) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test6/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_except/test6/CMakeLists.txt index 7f943bf126..d009128871 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_pal_except_test6 diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test6/test6.c b/src/pal/tests/palsuite/exception_handling/pal_except/test6/test6.c deleted file mode 100644 index 44b0ba1bc9..0000000000 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test6/test6.c +++ /dev/null @@ -1,160 +0,0 @@ -// 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: test6.c (exception_handling\pal_except\test6) -** -** Purpose: Test to make sure the PAL_EXCEPT block is executed -** after an exception occurs in the PAL_TRY block -** that contains multiple PAL_TRY-PAL_EXCEPT blocks -** -** -**===================================================================*/ -#include - -/* Execution flags */ -BOOL bTry = FALSE; -BOOL bExcept = FALSE; -BOOL bTry_nested = FALSE; -BOOL bExcept_nested = FALSE; -BOOL bTry_nested2 = FALSE; -BOOL bExcept_nested2 = FALSE; - - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* First block */ - PAL_TRY - { - int* p = 0x00000000; /* NULL pointer */ - - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - - /* Second PAL_TRY block */ - PAL_TRY - { - bTry_nested = TRUE; - - /* Third PAL_TRY block*/ - PAL_TRY - { - bTry_nested2 = TRUE; - - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the nested access violation.\n"); - - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry_nested2) - { - Fail("ERROR: Third PAL_EXCEPT was hit without " - "third PAL_TRY being hit.\n"); - } - bExcept_nested2 = TRUE; - } - PAL_ENDTRY; - - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the nested access violation.\n"); - - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry_nested) - { - Fail("ERROR: Second PAL_EXCEPT was hit without " - "second PAL_TRY being hit.\n"); - } - if (!bExcept_nested2) - { - Fail("ERROR: second PAL_EXCEPT was hit without " - "third PAL_EXCEPT being hit.\n"); - } - bExcept_nested = TRUE; - } - PAL_ENDTRY; - - *p = 13; /* causes an access violation exception */ - - Fail("ERROR: code was executed after the access violation.\n"); - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - if (!bTry) - { - Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); - } - if (!bExcept_nested) - { - Fail("ERROR: first PAL_EXCEPT was hit without " - "second PAL_EXCEPT being hit.\n"); - } - if (!bExcept_nested2) - { - Fail("ERROR: first PAL_EXCEPT was hit without " - "third PAL_EXCEPT being hit.\n"); - } - - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("ERROR: the code in the " - "first PAL_TRY block was not executed.\n"); - } - - if (!bExcept) - { - Trace("ERROR: the code in the " - "first PAL_EXCEPT block was not executed.\n"); - } - - if (!bTry_nested) - { - Trace("ERROR: the code in the " - "second PAL_TRY block was not executed.\n"); - } - - if (!bExcept_nested) - { - Trace("ERROR: the code in the " - "second PAL_EXCEPT block was not executed.\n"); - } - - if (!bTry_nested2) - { - Trace("ERROR: the code in the " - "third PAL_TRY block was not executed.\n"); - } - - if (!bExcept_nested2) - { - Trace("ERROR: the code in the " - "third PAL_EXCEPT block was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if(!bTry || !bExcept || - !bTry_nested || !bExcept_nested || - !bTry_nested2 || !bExcept_nested2) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test6/test6.cpp b/src/pal/tests/palsuite/exception_handling/pal_except/test6/test6.cpp new file mode 100644 index 0000000000..44b0ba1bc9 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test6/test6.cpp @@ -0,0 +1,160 @@ +// 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: test6.c (exception_handling\pal_except\test6) +** +** Purpose: Test to make sure the PAL_EXCEPT block is executed +** after an exception occurs in the PAL_TRY block +** that contains multiple PAL_TRY-PAL_EXCEPT blocks +** +** +**===================================================================*/ +#include + +/* Execution flags */ +BOOL bTry = FALSE; +BOOL bExcept = FALSE; +BOOL bTry_nested = FALSE; +BOOL bExcept_nested = FALSE; +BOOL bTry_nested2 = FALSE; +BOOL bExcept_nested2 = FALSE; + + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* First block */ + PAL_TRY + { + int* p = 0x00000000; /* NULL pointer */ + + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + + /* Second PAL_TRY block */ + PAL_TRY + { + bTry_nested = TRUE; + + /* Third PAL_TRY block*/ + PAL_TRY + { + bTry_nested2 = TRUE; + + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the nested access violation.\n"); + + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry_nested2) + { + Fail("ERROR: Third PAL_EXCEPT was hit without " + "third PAL_TRY being hit.\n"); + } + bExcept_nested2 = TRUE; + } + PAL_ENDTRY; + + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the nested access violation.\n"); + + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry_nested) + { + Fail("ERROR: Second PAL_EXCEPT was hit without " + "second PAL_TRY being hit.\n"); + } + if (!bExcept_nested2) + { + Fail("ERROR: second PAL_EXCEPT was hit without " + "third PAL_EXCEPT being hit.\n"); + } + bExcept_nested = TRUE; + } + PAL_ENDTRY; + + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); + } + if (!bExcept_nested) + { + Fail("ERROR: first PAL_EXCEPT was hit without " + "second PAL_EXCEPT being hit.\n"); + } + if (!bExcept_nested2) + { + Fail("ERROR: first PAL_EXCEPT was hit without " + "third PAL_EXCEPT being hit.\n"); + } + + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("ERROR: the code in the " + "first PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("ERROR: the code in the " + "first PAL_EXCEPT block was not executed.\n"); + } + + if (!bTry_nested) + { + Trace("ERROR: the code in the " + "second PAL_TRY block was not executed.\n"); + } + + if (!bExcept_nested) + { + Trace("ERROR: the code in the " + "second PAL_EXCEPT block was not executed.\n"); + } + + if (!bTry_nested2) + { + Trace("ERROR: the code in the " + "third PAL_TRY block was not executed.\n"); + } + + if (!bExcept_nested2) + { + Trace("ERROR: the code in the " + "third PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept || + !bTry_nested || !bExcept_nested || + !bTry_nested2 || !bExcept_nested2) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test7/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_except/test7/CMakeLists.txt index 09399c8f6b..33fee62cc2 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_pal_except_test7 diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test7/test7.c b/src/pal/tests/palsuite/exception_handling/pal_except/test7/test7.c deleted file mode 100644 index a8dc8331c2..0000000000 --- a/src/pal/tests/palsuite/exception_handling/pal_except/test7/test7.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: test7.c (exception_handling\pal_except\test7) -** -** Purpose: Tests the PAL implementation of the PAL_TRY and -** PAL_EXCEPT functions. Tests that the EXCEPTION block -** is missed if no exceptions happen -** -** -**===================================================================*/ - - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bTry = FALSE; - BOOL bExcept = FALSE; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* - ** Test to make sure we skip the exception block. - */ - - PAL_TRY - { - bTry = TRUE; /* indicate we hit the PAL_TRY block */ - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ - } - PAL_ENDTRY; - - if (!bTry) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" - " block was not executed.\n"); - } - - if (bExcept) - { - Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_EXCEPT" - " block was executed even though no exception was supposed to" - " happen.\n"); - } - - /* did we hit the correct code blocks? */ - if(!bTry || bExcept) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/exception_handling/pal_except/test7/test7.cpp b/src/pal/tests/palsuite/exception_handling/pal_except/test7/test7.cpp new file mode 100644 index 0000000000..a8dc8331c2 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_except/test7/test7.cpp @@ -0,0 +1,67 @@ +// 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: test7.c (exception_handling\pal_except\test7) +** +** Purpose: Tests the PAL implementation of the PAL_TRY and +** PAL_EXCEPT functions. Tests that the EXCEPTION block +** is missed if no exceptions happen +** +** +**===================================================================*/ + + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bTry = FALSE; + BOOL bExcept = FALSE; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* + ** Test to make sure we skip the exception block. + */ + + PAL_TRY + { + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_TRY" + " block was not executed.\n"); + } + + if (bExcept) + { + Trace("PAL_TRY_EXCEPT: ERROR -> It appears the code in the PAL_EXCEPT" + " block was executed even though no exception was supposed to" + " happen.\n"); + } + + /* did we hit the correct code blocks? */ + if(!bTry || bExcept) + { + Fail(""); + } + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_finally/test1/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_finally/test1/CMakeLists.txt index 5d947ad7db..67cc6c0b92 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_finally/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/pal_finally/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - pal_finally.c + pal_finally.cpp ) add_executable(paltest_pal_finally_test1 diff --git a/src/pal/tests/palsuite/exception_handling/pal_finally/test1/pal_finally.c b/src/pal/tests/palsuite/exception_handling/pal_finally/test1/pal_finally.c deleted file mode 100644 index f278f98956..0000000000 --- a/src/pal/tests/palsuite/exception_handling/pal_finally/test1/pal_finally.c +++ /dev/null @@ -1,302 +0,0 @@ -// 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: pal_finally.c (test 3) -** -** Purpose: Tests the PAL implementation of the PAL_FINALLY in the -** presence of a call stack. An exception is forced and -** passed to two nested exception filters for consideration. -** The first filter returns EXCEPTION_CONTINUE_SEARCH so the -** second can run and return EXCEPTION_EXECUTE_HANDLER. The -** initial exception handler should be skipped, and the -** second executed, and all the PAL_FINALLY blocks handled -** -** -**===================================================================*/ -#include - -BOOL bFilterCS = FALSE; -BOOL bFilterEE = FALSE; -BOOL bFinally1 = FALSE; -BOOL bFinally2 = FALSE; -BOOL bFinally3 = FALSE; -BOOL bFinally4 = FALSE; -BOOL bTry1 = FALSE; -BOOL bTry2 = FALSE; -BOOL bExcept1 = FALSE; -BOOL bExcept2 = FALSE; -BOOL bContinued = FALSE; -const int nValidator = 12321; - -LONG ContSearchFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) -{ - - /* let the main know we've hit the filter function */ - bFilterCS = TRUE; - - if (!bTry1 || !bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ContSearch filter was hit without PAL_TRY being hit.\n"); - } - - if (bFilterEE) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ContSearch filter was hit after the ExecuteException " - "filter.\n"); - } - - return EXCEPTION_CONTINUE_SEARCH; -} - -LONG ExecExeptionFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) -{ - /* let the main know we've hit the filter function */ - bFilterEE = TRUE; - - if (!bTry1 || !bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ContSearch filter was hit without PAL_TRY being hit.\n"); - } - - if (!bFilterCS) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The ExecExeption filter was hit before the ContSearch " - "filter.\n"); - } - return EXCEPTION_EXECUTE_HANDLER; -} - -void NestedFunc1 (void) -{ - int* p = 0x00000000; /* pointer to NULL */ - - PAL_TRY - { - PAL_TRY - { - - if (bExcept1 || bExcept2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); - } - bTry2 = TRUE; /* indicate we hit the inner PAL_TRY block */ - *p = 13; /* causes an access violation exception */ - - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " We executed beyond the trapping code.\n"); - } - PAL_FINALLY - { - if (!bTry1) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The first finally handler was hit without the outer " - "PAL_TRY's code being hit.\n"); - } - if (!bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The first finally handler was hit without the inner " - "PAL_TRY's code being hit.\n"); - } - if (!bFilterCS) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The first finally handler was hit without the inner " - "filter being hit.\n"); - } - if (!bFilterEE) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The first finally handler handler was hit without the " - "outer filter being hit.\n"); - } - bFinally1 = TRUE; /* indicate we hit the first finally block */ - } - PAL_ENDTRY; - } - PAL_EXCEPT_FILTER(ContSearchFilter, (LPVOID)&nValidator) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The dummy handler was " - "being hit.\n"); - bExcept2 = TRUE; /* indicate we hit the inner block */ - } - PAL_ENDTRY; - -} - -void NestedFunc2 (void) -{ - PAL_TRY - { - NestedFunc1(); - } - PAL_FINALLY - { - if (!bFinally1) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " The second finally handler handler was hit without the " - " top level one being hit.\n"); - } - bFinally2 = TRUE; - } - PAL_ENDTRY ; -} - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - ** test to make sure we get into the second exception block only based - ** on the return codes of the filters - */ - - PAL_TRY - { - PAL_TRY - { - PAL_TRY - { - if (bExcept1 || bExcept2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going" - " on. PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); - } - bTry1 = TRUE; /* indicate we hit the outer PAL_TRY block */ - - NestedFunc2(); - - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " We executed beyond the trapping code.\n"); - } - PAL_FINALLY - { - if (!bFinally2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going" - " on. Finally handlers hit out of order (2->3)\n"); - } - bFinally3 = TRUE; - } - PAL_ENDTRY; - } - PAL_EXCEPT_FILTER(ExecExeptionFilter, (LPVOID)&nValidator) - { - if (!bTry1) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without the outer " - "PAL_TRY's code being hit.\n"); - } - if (!bTry2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without the inner " - "PAL_TRY's code being hit.\n"); - } - if (!bFilterCS) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without the inner " - "filter being hit.\n"); - } - if (!bFilterEE) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " PAL_EXCEPT_FILTER's handler was hit without the outer " - "filter being hit.\n"); - } - bExcept1 = TRUE; /* indicate we hit the outer block */ - } - PAL_ENDTRY; - - if (bFinally4) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " Finally handler # 4 executed before it should be \n"); - } - } - PAL_FINALLY - { - if (!bExcept1 || bExcept2) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " Exceptions handlers hit in wierd ways\n"); - } - if (!bFinally3) - { - Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." - " Finally handlers hit out of order 3->4)\n"); - } - - bFinally4 = TRUE; - } - PAL_ENDTRY; - - if (!bTry1) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the outer" - " PAL_TRY block was not executed.\n"); - } - - if (!bTry2) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the inner" - " PAL_TRY block was not executed.\n"); - } - - if (bExcept2) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "inner PAL_EXCEPT_FILTER block was executed.\n"); - } - if (!bExcept1) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "outer PAL_EXCEPT_FILTER block was not executed.\n"); - } - - if (!bFilterCS) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "search continuing filter" - " function was not executed.\n"); - } - if (!bFilterEE) - { - Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " - "execute handler filter" - " function was not executed.\n"); - } - - /* did we hit all the code blocks? */ - if (!bFinally1 || !bFinally2 || !bFinally3 || !bFinally4) - { - Fail(""); - } - if(!bTry1 || !bTry2 || !bExcept1 || bExcept2 || !bFilterEE || !bFilterCS ) - { - Fail(""); - } - - - PAL_Terminate(); - return PASS; - -} - diff --git a/src/pal/tests/palsuite/exception_handling/pal_finally/test1/pal_finally.cpp b/src/pal/tests/palsuite/exception_handling/pal_finally/test1/pal_finally.cpp new file mode 100644 index 0000000000..f278f98956 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_finally/test1/pal_finally.cpp @@ -0,0 +1,302 @@ +// 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: pal_finally.c (test 3) +** +** Purpose: Tests the PAL implementation of the PAL_FINALLY in the +** presence of a call stack. An exception is forced and +** passed to two nested exception filters for consideration. +** The first filter returns EXCEPTION_CONTINUE_SEARCH so the +** second can run and return EXCEPTION_EXECUTE_HANDLER. The +** initial exception handler should be skipped, and the +** second executed, and all the PAL_FINALLY blocks handled +** +** +**===================================================================*/ +#include + +BOOL bFilterCS = FALSE; +BOOL bFilterEE = FALSE; +BOOL bFinally1 = FALSE; +BOOL bFinally2 = FALSE; +BOOL bFinally3 = FALSE; +BOOL bFinally4 = FALSE; +BOOL bTry1 = FALSE; +BOOL bTry2 = FALSE; +BOOL bExcept1 = FALSE; +BOOL bExcept2 = FALSE; +BOOL bContinued = FALSE; +const int nValidator = 12321; + +LONG ContSearchFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) +{ + + /* let the main know we've hit the filter function */ + bFilterCS = TRUE; + + if (!bTry1 || !bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ContSearch filter was hit without PAL_TRY being hit.\n"); + } + + if (bFilterEE) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ContSearch filter was hit after the ExecuteException " + "filter.\n"); + } + + return EXCEPTION_CONTINUE_SEARCH; +} + +LONG ExecExeptionFilter(EXCEPTION_POINTERS* ep, LPVOID pnTestInt) +{ + /* let the main know we've hit the filter function */ + bFilterEE = TRUE; + + if (!bTry1 || !bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ContSearch filter was hit without PAL_TRY being hit.\n"); + } + + if (!bFilterCS) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The ExecExeption filter was hit before the ContSearch " + "filter.\n"); + } + return EXCEPTION_EXECUTE_HANDLER; +} + +void NestedFunc1 (void) +{ + int* p = 0x00000000; /* pointer to NULL */ + + PAL_TRY + { + PAL_TRY + { + + if (bExcept1 || bExcept2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); + } + bTry2 = TRUE; /* indicate we hit the inner PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " We executed beyond the trapping code.\n"); + } + PAL_FINALLY + { + if (!bTry1) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The first finally handler was hit without the outer " + "PAL_TRY's code being hit.\n"); + } + if (!bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The first finally handler was hit without the inner " + "PAL_TRY's code being hit.\n"); + } + if (!bFilterCS) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The first finally handler was hit without the inner " + "filter being hit.\n"); + } + if (!bFilterEE) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The first finally handler handler was hit without the " + "outer filter being hit.\n"); + } + bFinally1 = TRUE; /* indicate we hit the first finally block */ + } + PAL_ENDTRY; + } + PAL_EXCEPT_FILTER(ContSearchFilter, (LPVOID)&nValidator) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The dummy handler was " + "being hit.\n"); + bExcept2 = TRUE; /* indicate we hit the inner block */ + } + PAL_ENDTRY; + +} + +void NestedFunc2 (void) +{ + PAL_TRY + { + NestedFunc1(); + } + PAL_FINALLY + { + if (!bFinally1) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " The second finally handler handler was hit without the " + " top level one being hit.\n"); + } + bFinally2 = TRUE; + } + PAL_ENDTRY ; +} + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + ** test to make sure we get into the second exception block only based + ** on the return codes of the filters + */ + + PAL_TRY + { + PAL_TRY + { + PAL_TRY + { + if (bExcept1 || bExcept2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going" + " on. PAL_EXCEPT_FILTER was hit before PAL_TRY.\n"); + } + bTry1 = TRUE; /* indicate we hit the outer PAL_TRY block */ + + NestedFunc2(); + + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " We executed beyond the trapping code.\n"); + } + PAL_FINALLY + { + if (!bFinally2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going" + " on. Finally handlers hit out of order (2->3)\n"); + } + bFinally3 = TRUE; + } + PAL_ENDTRY; + } + PAL_EXCEPT_FILTER(ExecExeptionFilter, (LPVOID)&nValidator) + { + if (!bTry1) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without the outer " + "PAL_TRY's code being hit.\n"); + } + if (!bTry2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without the inner " + "PAL_TRY's code being hit.\n"); + } + if (!bFilterCS) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without the inner " + "filter being hit.\n"); + } + if (!bFilterEE) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " PAL_EXCEPT_FILTER's handler was hit without the outer " + "filter being hit.\n"); + } + bExcept1 = TRUE; /* indicate we hit the outer block */ + } + PAL_ENDTRY; + + if (bFinally4) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " Finally handler # 4 executed before it should be \n"); + } + } + PAL_FINALLY + { + if (!bExcept1 || bExcept2) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " Exceptions handlers hit in wierd ways\n"); + } + if (!bFinally3) + { + Fail("PAL_EXCEPT_FILTER: ERROR -> Something weird is going on." + " Finally handlers hit out of order 3->4)\n"); + } + + bFinally4 = TRUE; + } + PAL_ENDTRY; + + if (!bTry1) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the outer" + " PAL_TRY block was not executed.\n"); + } + + if (!bTry2) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the inner" + " PAL_TRY block was not executed.\n"); + } + + if (bExcept2) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "inner PAL_EXCEPT_FILTER block was executed.\n"); + } + if (!bExcept1) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "outer PAL_EXCEPT_FILTER block was not executed.\n"); + } + + if (!bFilterCS) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "search continuing filter" + " function was not executed.\n"); + } + if (!bFilterEE) + { + Trace("PAL_EXCEPT_FILTER: ERROR -> It appears the code in the " + "execute handler filter" + " function was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if (!bFinally1 || !bFinally2 || !bFinally3 || !bFinally4) + { + Fail(""); + } + if(!bTry1 || !bTry2 || !bExcept1 || bExcept2 || !bFilterEE || !bFilterCS ) + { + Fail(""); + } + + + PAL_Terminate(); + return PASS; + +} + diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.cpp b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.cpp index 614690897a..000ed6271c 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.cpp +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.cpp @@ -20,6 +20,17 @@ int InitializeDllTest1() return PAL_InitializeDLL(); } +__attribute__((noinline,optnone)) +static void FailingFunction(volatile int *p) +{ + if (p == NULL) + { + throw PAL_SEHException(); + } + + *p = 1; // Causes an access violation exception +} + BOOL bTry = FALSE; BOOL bExcept = FALSE; @@ -33,7 +44,8 @@ int DllTest1() volatile int* p = (volatile int *)0x11; // Invalid pointer bTry = TRUE; // Indicate we hit the PAL_TRY block - *p = 1; // Causes an access violation exception + FailingFunction(p); // Throw in function to fool C++ runtime into handling + // h/w exception Fail("ERROR: code was executed after the access violation.\n"); } diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.cpp b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.cpp index 1e85821422..27fc213e4f 100644 --- a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.cpp +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.cpp @@ -20,6 +20,17 @@ int InitializeDllTest2() return PAL_InitializeDLL(); } +__attribute__((noinline,optnone)) +static void FailingFunction(volatile int *p) +{ + if (p == NULL) + { + throw PAL_SEHException(); + } + + *p = 1; // Causes an access violation exception +} + BOOL bTry = FALSE; BOOL bExcept = FALSE; @@ -33,7 +44,8 @@ int DllTest2() volatile int* p = (volatile int *)0x22; // Invalid pointer bTry = TRUE; // Indicate we hit the PAL_TRY block - *p = 2; // Causes an access violation exception + FailingFunction(p); // Throw in function to fool C++ runtime into handling + // h/w exception Fail("ERROR: code was executed after the access violation.\n"); } diff --git a/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/AreFileApisANSI.c b/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/AreFileApisANSI.c deleted file mode 100644 index ec61f0cb7d..0000000000 --- a/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/AreFileApisANSI.c +++ /dev/null @@ -1,40 +0,0 @@ -// 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: AreFileApisANSI.c -** -** Purpose: Tests the PAL implementation of the AreFileApisANSI function. -** The only possible return is TRUE. -** -** -**===================================================================*/ - - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bRc = FALSE; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - bRc = AreFileApisANSI(); - - - if (bRc == FALSE) - { - Fail("AreFileApisANSI: ERROR: Function returned FALSE whereas only TRUE " - "is acceptable.\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/AreFileApisANSI.cpp b/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/AreFileApisANSI.cpp new file mode 100644 index 0000000000..ec61f0cb7d --- /dev/null +++ b/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/AreFileApisANSI.cpp @@ -0,0 +1,40 @@ +// 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: AreFileApisANSI.c +** +** Purpose: Tests the PAL implementation of the AreFileApisANSI function. +** The only possible return is TRUE. +** +** +**===================================================================*/ + + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bRc = FALSE; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + bRc = AreFileApisANSI(); + + + if (bRc == FALSE) + { + Fail("AreFileApisANSI: ERROR: Function returned FALSE whereas only TRUE " + "is acceptable.\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/CMakeLists.txt index 4f50127cb9..e624bef462 100644 --- a/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/AreFileApisANSI/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - AreFileApisANSI.c + AreFileApisANSI.cpp ) add_executable(paltest_arefileapisansi_test1 diff --git a/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CMakeLists.txt index fdcb6559b3..fa96a44cdd 100644 --- a/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CompareFileTime.c + CompareFileTime.cpp ) add_executable(paltest_comparefiletime_test1 diff --git a/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CompareFileTime.c b/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CompareFileTime.c deleted file mode 100644 index 3758f7e4eb..0000000000 --- a/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CompareFileTime.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: CompareFileTime.c -** -** Purpose: Tests the PAL implementation of the CompareFileTime function. -** Defines a large and small file time, and compares them in all fashions -** to ensure proper return values. -** -** -**===================================================================*/ - -#include - - - -int __cdecl main(int argc, char **argv) -{ - - FILETIME SmallTime, BigTime; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Set a Big and Small time. These were generated using - GetFileTime on a file, with a recent creation time and an old - modify time, to get a bigger and smaller value. - */ - - BigTime.dwLowDateTime = -755748832; - BigTime.dwHighDateTime = 29436941; - - SmallTime.dwLowDateTime = -459754240; - SmallTime.dwHighDateTime = 29436314; - - /* Check to see that SmallTime is less than Big Time */ - - if(CompareFileTime(&SmallTime,&BigTime) != -1) - { - Fail("ERROR: The first time is less than the second time, so " - "-1 should have been returned to indicate this."); - } - - /* Check that BigTime is greater than SmallTime */ - - if(CompareFileTime(&BigTime,&SmallTime) != 1) - { - Fail("ERROR: The first time is greater than the second time, so " - "1 should have been returned to indicate this."); - } - - /* Check that BigTime is equal to BigTime */ - - if(CompareFileTime(&BigTime,&BigTime) != 0) - { - Fail("ERROR: The first time is equal to the second time, so " - "0 should have been returned to indicate this."); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CompareFileTime.cpp b/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CompareFileTime.cpp new file mode 100644 index 0000000000..3758f7e4eb --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CompareFileTime/test1/CompareFileTime.cpp @@ -0,0 +1,68 @@ +// 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: CompareFileTime.c +** +** Purpose: Tests the PAL implementation of the CompareFileTime function. +** Defines a large and small file time, and compares them in all fashions +** to ensure proper return values. +** +** +**===================================================================*/ + +#include + + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME SmallTime, BigTime; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Set a Big and Small time. These were generated using + GetFileTime on a file, with a recent creation time and an old + modify time, to get a bigger and smaller value. + */ + + BigTime.dwLowDateTime = -755748832; + BigTime.dwHighDateTime = 29436941; + + SmallTime.dwLowDateTime = -459754240; + SmallTime.dwHighDateTime = 29436314; + + /* Check to see that SmallTime is less than Big Time */ + + if(CompareFileTime(&SmallTime,&BigTime) != -1) + { + Fail("ERROR: The first time is less than the second time, so " + "-1 should have been returned to indicate this."); + } + + /* Check that BigTime is greater than SmallTime */ + + if(CompareFileTime(&BigTime,&SmallTime) != 1) + { + Fail("ERROR: The first time is greater than the second time, so " + "1 should have been returned to indicate this."); + } + + /* Check that BigTime is equal to BigTime */ + + if(CompareFileTime(&BigTime,&BigTime) != 0) + { + Fail("ERROR: The first time is equal to the second time, so " + "0 should have been returned to indicate this."); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CopyFileA/test1/CMakeLists.txt index b52e5076fa..13abbc0979 100644 --- a/src/pal/tests/palsuite/file_io/CopyFileA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CopyFileA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CopyFileA.c + CopyFileA.cpp ) add_executable(paltest_copyfilea_test1 diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.c b/src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.c deleted file mode 100644 index bfea85b7cb..0000000000 --- a/src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.c +++ /dev/null @@ -1,159 +0,0 @@ -// 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: CopyFileA.c -** -** Purpose: Tests the PAL implementation of the CopyFileA function -** -** -**===================================================================*/ - -/* - 1. copy an existing file to existing with overwrite true - 2. copy an existing file to existing with overwrite false - 3. copy an existing file to non-existant with overwrite true - 4. copy an existing file to non-existant with overwrite false - 5. copy non-existant file to existing with overwrite true - 6. copy non-existant file to existing with overwrite false - 7. copy non-existant file to non-existant with overwrite true - 8. copy non-existant file to non-existant with overwrite false -*/ - -#include - -struct TESTS{ - char* lpSource; - char* lpDestination; - BOOL bFailIfExists; - int nResult; - }; - - -int __cdecl main(int argc, char *argv[]) -{ - char szSrcExisting[] = {"src_existing.tmp"}; - char szSrcNonExistant[] = {"src_non-existant.tmp"}; - char szDstExisting[] = {"dst_existing.tmp"}; - char szDstNonExistant[] = {"dst_non-existant.tmp"}; - BOOL bRc = TRUE; - BOOL bSuccess = TRUE; - FILE* tempFile = NULL; - int i; - struct TESTS testCase[] = - { - {szSrcExisting, szDstExisting, FALSE, 1}, - {szSrcExisting, szDstExisting, TRUE, 0}, - {szSrcExisting, szDstNonExistant, FALSE, 1}, - {szSrcExisting, szDstNonExistant, TRUE, 1}, - {szSrcNonExistant, szDstExisting, FALSE, 0}, - {szSrcNonExistant, szDstExisting, TRUE, 0}, - {szSrcNonExistant, szDstNonExistant, FALSE, 0}, - {szSrcNonExistant, szDstNonExistant, TRUE, 0} - }; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create the src_existing file */ - tempFile = fopen(szSrcExisting, "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "CopyFileA test file: src_existing.tmp\n"); - fclose(tempFile); - } - else - { - Fail("CopyFileA: ERROR-> Couldn't create \"src_existing.tmp\" with " - "error %ld\n", - GetLastError()); - } - - /* create the dst_existing file */ - tempFile = fopen(szDstExisting, "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "CopyFileA test file: dst_existing.tmp\n"); - fclose(tempFile); - } - else - { - Fail("CopyFileA: ERROR-> Couldn't create \"dst_existing.tmp\" with " - "error %ld\n", - GetLastError()); - } - - - - for (i = 0; i < (sizeof(testCase) / sizeof(struct TESTS)); i++) - { - bRc = CopyFileA(testCase[i].lpSource, - testCase[i].lpDestination, - testCase[i].bFailIfExists); - if (!bRc) - { - if (testCase[i].nResult == 1) - { - Trace("CopyFileA: FAILED: %s -> %s with bFailIfExists = %d " - "with error %ld\n", - testCase[i].lpSource, - testCase[i].lpDestination, - testCase[i].bFailIfExists, - GetLastError()); - bSuccess = FALSE; - } - } - else - { - if (testCase[i].nResult == 0) - { - Trace("CopyFileA: FAILED: %s -> %s with bFailIfExists = %d\n", - testCase[i].lpSource, - testCase[i].lpDestination, - testCase[i].bFailIfExists); - bSuccess = FALSE; - } - else - { - /* verify the file was moved */ - if (GetFileAttributesA(testCase[i].lpDestination) == -1) - { - Trace("CopyFileA: GetFileAttributes of destination file " - "failed with error code %ld. \n", - GetLastError()); - bSuccess = FALSE; - } - else if (GetFileAttributesA(testCase[i].lpSource) == -1) - { - Trace("CopyFileA: GetFileAttributes of source file " - "failed with error code %ld. \n", - GetLastError()); - bSuccess = FALSE; - } - else - { - /* verify attributes of destination file to source file*/ - if(GetFileAttributes(testCase[i].lpSource) != - GetFileAttributes(testCase[i].lpDestination)) - { - Trace("CopyFileA : The file attributes of the " - "destination file do not match the file " - "attributes of the source file.\n"); - bSuccess = FALSE; - } - } - } - } - /* delete file file but don't worry if it fails */ - DeleteFileA(szDstNonExistant); - } - - int exitCode = bSuccess ? PASS : FAIL; - PAL_TerminateEx(exitCode); - return exitCode; -} diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.cpp b/src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.cpp new file mode 100644 index 0000000000..bfea85b7cb --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CopyFileA/test1/CopyFileA.cpp @@ -0,0 +1,159 @@ +// 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: CopyFileA.c +** +** Purpose: Tests the PAL implementation of the CopyFileA function +** +** +**===================================================================*/ + +/* + 1. copy an existing file to existing with overwrite true + 2. copy an existing file to existing with overwrite false + 3. copy an existing file to non-existant with overwrite true + 4. copy an existing file to non-existant with overwrite false + 5. copy non-existant file to existing with overwrite true + 6. copy non-existant file to existing with overwrite false + 7. copy non-existant file to non-existant with overwrite true + 8. copy non-existant file to non-existant with overwrite false +*/ + +#include + +struct TESTS{ + char* lpSource; + char* lpDestination; + BOOL bFailIfExists; + int nResult; + }; + + +int __cdecl main(int argc, char *argv[]) +{ + char szSrcExisting[] = {"src_existing.tmp"}; + char szSrcNonExistant[] = {"src_non-existant.tmp"}; + char szDstExisting[] = {"dst_existing.tmp"}; + char szDstNonExistant[] = {"dst_non-existant.tmp"}; + BOOL bRc = TRUE; + BOOL bSuccess = TRUE; + FILE* tempFile = NULL; + int i; + struct TESTS testCase[] = + { + {szSrcExisting, szDstExisting, FALSE, 1}, + {szSrcExisting, szDstExisting, TRUE, 0}, + {szSrcExisting, szDstNonExistant, FALSE, 1}, + {szSrcExisting, szDstNonExistant, TRUE, 1}, + {szSrcNonExistant, szDstExisting, FALSE, 0}, + {szSrcNonExistant, szDstExisting, TRUE, 0}, + {szSrcNonExistant, szDstNonExistant, FALSE, 0}, + {szSrcNonExistant, szDstNonExistant, TRUE, 0} + }; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create the src_existing file */ + tempFile = fopen(szSrcExisting, "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "CopyFileA test file: src_existing.tmp\n"); + fclose(tempFile); + } + else + { + Fail("CopyFileA: ERROR-> Couldn't create \"src_existing.tmp\" with " + "error %ld\n", + GetLastError()); + } + + /* create the dst_existing file */ + tempFile = fopen(szDstExisting, "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "CopyFileA test file: dst_existing.tmp\n"); + fclose(tempFile); + } + else + { + Fail("CopyFileA: ERROR-> Couldn't create \"dst_existing.tmp\" with " + "error %ld\n", + GetLastError()); + } + + + + for (i = 0; i < (sizeof(testCase) / sizeof(struct TESTS)); i++) + { + bRc = CopyFileA(testCase[i].lpSource, + testCase[i].lpDestination, + testCase[i].bFailIfExists); + if (!bRc) + { + if (testCase[i].nResult == 1) + { + Trace("CopyFileA: FAILED: %s -> %s with bFailIfExists = %d " + "with error %ld\n", + testCase[i].lpSource, + testCase[i].lpDestination, + testCase[i].bFailIfExists, + GetLastError()); + bSuccess = FALSE; + } + } + else + { + if (testCase[i].nResult == 0) + { + Trace("CopyFileA: FAILED: %s -> %s with bFailIfExists = %d\n", + testCase[i].lpSource, + testCase[i].lpDestination, + testCase[i].bFailIfExists); + bSuccess = FALSE; + } + else + { + /* verify the file was moved */ + if (GetFileAttributesA(testCase[i].lpDestination) == -1) + { + Trace("CopyFileA: GetFileAttributes of destination file " + "failed with error code %ld. \n", + GetLastError()); + bSuccess = FALSE; + } + else if (GetFileAttributesA(testCase[i].lpSource) == -1) + { + Trace("CopyFileA: GetFileAttributes of source file " + "failed with error code %ld. \n", + GetLastError()); + bSuccess = FALSE; + } + else + { + /* verify attributes of destination file to source file*/ + if(GetFileAttributes(testCase[i].lpSource) != + GetFileAttributes(testCase[i].lpDestination)) + { + Trace("CopyFileA : The file attributes of the " + "destination file do not match the file " + "attributes of the source file.\n"); + bSuccess = FALSE; + } + } + } + } + /* delete file file but don't worry if it fails */ + DeleteFileA(szDstNonExistant); + } + + int exitCode = bSuccess ? PASS : FAIL; + PAL_TerminateEx(exitCode); + return exitCode; +} diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CopyFileA/test2/CMakeLists.txt index 7454f32f51..cd0d8bc6cf 100644 --- a/src/pal/tests/palsuite/file_io/CopyFileA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CopyFileA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_copyfilea_test2 diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test2/test2.c b/src/pal/tests/palsuite/file_io/CopyFileA/test2/test2.c deleted file mode 100644 index 56618d0a58..0000000000 --- a/src/pal/tests/palsuite/file_io/CopyFileA/test2/test2.c +++ /dev/null @@ -1,120 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests the PAL implementation of the CopyFileA function -** to see if a file can be copied to itself -** -** -**===================================================================*/ - - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - BOOL bRc = TRUE; - char* szSrcExisting = "src_existing.tmp"; - FILE* tempFile = NULL; - DWORD temp; - int retCode; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create the src_existing file */ - tempFile = fopen(szSrcExisting, "w"); - if (tempFile != NULL) - { - retCode = fputs("CopyFileA test file: src_existing.tmp ", tempFile); - if(retCode < 0) - { - Fail("CopyFileA: ERROR-> Couldn't write to %s with error " - "%u.\n", szSrcExisting, GetLastError()); - } - retCode = fclose(tempFile); - if(retCode != 0) - { - Fail("CopyFileA: ERROR-> Couldn't close file: %s with error " - "%u.\n", szSrcExisting, GetLastError()); - } - - } - else - { - Fail("CopyFileA: ERROR-> Couldn't create %s with " - "error %ld\n",szSrcExisting,GetLastError()); - } - - /* Get file attributes of source */ - temp = GetFileAttributes(szSrcExisting); - if (temp == -1) - { - Fail("CopyFileA: GetFileAttributes of source file " - "failed with error code %ld. \n", - GetLastError()); - } - - /* make sure a file can't copy to itself - first testing with IfFileExists flag set to true */ - bRc = CopyFileA(szSrcExisting,szSrcExisting,TRUE); - if(bRc) - { - Fail("ERROR: Cannot copy a file to itself, %u",GetLastError()); - } - - /* try to get file attributes of desitnation */ - if (GetFileAttributesA(szSrcExisting) == -1) - { - Fail("CopyFileA: GetFileAttributes of destination file " - "failed with error code %ld. \n", - GetLastError()); - } - else - { - /* verify attributes of destination file to source file*/ - - if(temp != GetFileAttributes(szSrcExisting)) - { - Fail("CopyFileA : The file attributes of the " - "destination file do not match the file " - "attributes of the source file.\n"); - } - } - - /* testing with IfFileExists flags set to false - should fail in Windows and pass in UNIX */ - bRc = CopyFileA(szSrcExisting,szSrcExisting,FALSE); - if(bRc && (GetLastError() != ERROR_ALREADY_EXISTS)) - { - Fail("ERROR: Cannot copy a file to itself, %u",GetLastError()); - } - - if (GetFileAttributesA(szSrcExisting) == -1) - { - Fail("CopyFileA: GetFileAttributes of destination file " - "failed with error code %ld. \n", - GetLastError()); - } - else - { - /* verify attributes of destination file to source file*/ - - if(temp != GetFileAttributes(szSrcExisting)) - { - Fail("CopyFileA : The file attributes of the " - "destination file do not match the file " - "attributes of the source file.\n"); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test2/test2.cpp b/src/pal/tests/palsuite/file_io/CopyFileA/test2/test2.cpp new file mode 100644 index 0000000000..56618d0a58 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CopyFileA/test2/test2.cpp @@ -0,0 +1,120 @@ +// 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: test2.c +** +** Purpose: Tests the PAL implementation of the CopyFileA function +** to see if a file can be copied to itself +** +** +**===================================================================*/ + + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + BOOL bRc = TRUE; + char* szSrcExisting = "src_existing.tmp"; + FILE* tempFile = NULL; + DWORD temp; + int retCode; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create the src_existing file */ + tempFile = fopen(szSrcExisting, "w"); + if (tempFile != NULL) + { + retCode = fputs("CopyFileA test file: src_existing.tmp ", tempFile); + if(retCode < 0) + { + Fail("CopyFileA: ERROR-> Couldn't write to %s with error " + "%u.\n", szSrcExisting, GetLastError()); + } + retCode = fclose(tempFile); + if(retCode != 0) + { + Fail("CopyFileA: ERROR-> Couldn't close file: %s with error " + "%u.\n", szSrcExisting, GetLastError()); + } + + } + else + { + Fail("CopyFileA: ERROR-> Couldn't create %s with " + "error %ld\n",szSrcExisting,GetLastError()); + } + + /* Get file attributes of source */ + temp = GetFileAttributes(szSrcExisting); + if (temp == -1) + { + Fail("CopyFileA: GetFileAttributes of source file " + "failed with error code %ld. \n", + GetLastError()); + } + + /* make sure a file can't copy to itself + first testing with IfFileExists flag set to true */ + bRc = CopyFileA(szSrcExisting,szSrcExisting,TRUE); + if(bRc) + { + Fail("ERROR: Cannot copy a file to itself, %u",GetLastError()); + } + + /* try to get file attributes of desitnation */ + if (GetFileAttributesA(szSrcExisting) == -1) + { + Fail("CopyFileA: GetFileAttributes of destination file " + "failed with error code %ld. \n", + GetLastError()); + } + else + { + /* verify attributes of destination file to source file*/ + + if(temp != GetFileAttributes(szSrcExisting)) + { + Fail("CopyFileA : The file attributes of the " + "destination file do not match the file " + "attributes of the source file.\n"); + } + } + + /* testing with IfFileExists flags set to false + should fail in Windows and pass in UNIX */ + bRc = CopyFileA(szSrcExisting,szSrcExisting,FALSE); + if(bRc && (GetLastError() != ERROR_ALREADY_EXISTS)) + { + Fail("ERROR: Cannot copy a file to itself, %u",GetLastError()); + } + + if (GetFileAttributesA(szSrcExisting) == -1) + { + Fail("CopyFileA: GetFileAttributes of destination file " + "failed with error code %ld. \n", + GetLastError()); + } + else + { + /* verify attributes of destination file to source file*/ + + if(temp != GetFileAttributes(szSrcExisting)) + { + Fail("CopyFileA : The file attributes of the " + "destination file do not match the file " + "attributes of the source file.\n"); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CopyFileA/test3/CMakeLists.txt index 986be9fd22..0bb41b8d8f 100644 --- a/src/pal/tests/palsuite/file_io/CopyFileA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CopyFileA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_copyfilea_test3 diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test3/test3.c b/src/pal/tests/palsuite/file_io/CopyFileA/test3/test3.c deleted file mode 100644 index 18c8ce80dc..0000000000 --- a/src/pal/tests/palsuite/file_io/CopyFileA/test3/test3.c +++ /dev/null @@ -1,141 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests the PAL implementation of the CopyFileA function -** to see if a file can be copied to itself -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - BOOL bRc = TRUE; - char* szSrcExisting = "src_existing.tmp"; - char* szDest = "src_dest.tmp"; - FILE* tempFile = NULL; - int retCode; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create the src_existing file */ - tempFile = fopen(szSrcExisting, "w"); - if (tempFile != NULL) - { - retCode = fputs("CopyFileA test file: src_existing.tmp ", tempFile); - if(retCode < 0) - { - retCode = fclose(tempFile); - if(retCode != 0) - { - Trace("CopyFileA: ERROR-> Couldn't close file: %s with error " - "%u.\n", szSrcExisting, GetLastError()); - } - - Fail("CopyFileA: ERROR-> Couldn't write to %s with error " - "%u.\n", szSrcExisting, GetLastError()); - } - retCode = fclose(tempFile); - if(retCode != 0) - { - Fail("CopyFileA: ERROR-> Couldn't close file: %s with error " - "%u.\n", szSrcExisting, GetLastError()); - } - - } - else - { - Fail("CopyFileA: ERROR-> Couldn't create %s with " - "error %ld\n",szSrcExisting,GetLastError()); - } - - /* set the file attributes of the source file to readonly */ - bRc = SetFileAttributes(szSrcExisting, FILE_ATTRIBUTE_READONLY); - if(!bRc) - { - Fail("CopyFileA: ERROR-> Couldn't set file attributes for " - "file %s with error %u\n", szSrcExisting, GetLastError()); - } - - // Check the file attributes to make sure SetFileAttributes() above actually succeeded - DWORD fileAttributes = GetFileAttributesA(szSrcExisting); - if (fileAttributes == INVALID_FILE_ATTRIBUTES) - { - Fail("CopyFileA: Failed to get file attributes for source file, %u\n", GetLastError()); - } - if ((fileAttributes & FILE_ATTRIBUTE_READONLY) == 0) - { - Fail("CopyFileA: SetFileAttributes(read-only) on source file returned success but did not make it read-only.\n"); - } - - /* copy the file */ - bRc = CopyFileA(szSrcExisting,szDest,TRUE); - if(!bRc) - { - Fail("CopyFileA: Cannot copy a file with error, %u",GetLastError()); - } - - - /* try to get file attributes of destination file */ - fileAttributes = GetFileAttributesA(szDest); - if (fileAttributes == INVALID_FILE_ATTRIBUTES) - { - Fail("CopyFileA: GetFileAttributes of destination file " - "failed with error code %ld. \n", - GetLastError()); - } - - /* verify attributes of destination file to source file*/ - if((fileAttributes & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) - { - Fail("CopyFileA : The file attributes of the " - "destination file do not match the file " - "attributes of the source file.\n"); - } - - /* set the attributes of the destination file to normal again */ - bRc = SetFileAttributesA(szDest, FILE_ATTRIBUTE_NORMAL); - if(!bRc) - { - Fail("CopyFileA: ERROR-> Couldn't set file attributes for " - "file %s with error %u\n", szDest, GetLastError()); - } - - /* delete the newly copied file */ - bRc = DeleteFile(szDest); - if(!bRc) - { - Fail("CopyFileA: DeleteFile failed to delete the" - "file correctly with error,%u.\n",GetLastError()); - } - - /* set the attributes of the source file to normal again */ - bRc = SetFileAttributesA(szSrcExisting, FILE_ATTRIBUTE_NORMAL); - if(!bRc) - { - Fail("CopyFileA: ERROR-> Couldn't set file attributes for " - "file %s with error %u\n", szSrcExisting, GetLastError()); - } - - /* delete the original file */ - bRc = DeleteFile(szSrcExisting); - if(!bRc) - { - Fail("CopyFileA: DeleteFile failed to delete the" - "file correctly with error,%u.\n",GetLastError()); - } - - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test3/test3.cpp b/src/pal/tests/palsuite/file_io/CopyFileA/test3/test3.cpp new file mode 100644 index 0000000000..18c8ce80dc --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CopyFileA/test3/test3.cpp @@ -0,0 +1,141 @@ +// 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: test3.c +** +** Purpose: Tests the PAL implementation of the CopyFileA function +** to see if a file can be copied to itself +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + BOOL bRc = TRUE; + char* szSrcExisting = "src_existing.tmp"; + char* szDest = "src_dest.tmp"; + FILE* tempFile = NULL; + int retCode; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create the src_existing file */ + tempFile = fopen(szSrcExisting, "w"); + if (tempFile != NULL) + { + retCode = fputs("CopyFileA test file: src_existing.tmp ", tempFile); + if(retCode < 0) + { + retCode = fclose(tempFile); + if(retCode != 0) + { + Trace("CopyFileA: ERROR-> Couldn't close file: %s with error " + "%u.\n", szSrcExisting, GetLastError()); + } + + Fail("CopyFileA: ERROR-> Couldn't write to %s with error " + "%u.\n", szSrcExisting, GetLastError()); + } + retCode = fclose(tempFile); + if(retCode != 0) + { + Fail("CopyFileA: ERROR-> Couldn't close file: %s with error " + "%u.\n", szSrcExisting, GetLastError()); + } + + } + else + { + Fail("CopyFileA: ERROR-> Couldn't create %s with " + "error %ld\n",szSrcExisting,GetLastError()); + } + + /* set the file attributes of the source file to readonly */ + bRc = SetFileAttributes(szSrcExisting, FILE_ATTRIBUTE_READONLY); + if(!bRc) + { + Fail("CopyFileA: ERROR-> Couldn't set file attributes for " + "file %s with error %u\n", szSrcExisting, GetLastError()); + } + + // Check the file attributes to make sure SetFileAttributes() above actually succeeded + DWORD fileAttributes = GetFileAttributesA(szSrcExisting); + if (fileAttributes == INVALID_FILE_ATTRIBUTES) + { + Fail("CopyFileA: Failed to get file attributes for source file, %u\n", GetLastError()); + } + if ((fileAttributes & FILE_ATTRIBUTE_READONLY) == 0) + { + Fail("CopyFileA: SetFileAttributes(read-only) on source file returned success but did not make it read-only.\n"); + } + + /* copy the file */ + bRc = CopyFileA(szSrcExisting,szDest,TRUE); + if(!bRc) + { + Fail("CopyFileA: Cannot copy a file with error, %u",GetLastError()); + } + + + /* try to get file attributes of destination file */ + fileAttributes = GetFileAttributesA(szDest); + if (fileAttributes == INVALID_FILE_ATTRIBUTES) + { + Fail("CopyFileA: GetFileAttributes of destination file " + "failed with error code %ld. \n", + GetLastError()); + } + + /* verify attributes of destination file to source file*/ + if((fileAttributes & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) + { + Fail("CopyFileA : The file attributes of the " + "destination file do not match the file " + "attributes of the source file.\n"); + } + + /* set the attributes of the destination file to normal again */ + bRc = SetFileAttributesA(szDest, FILE_ATTRIBUTE_NORMAL); + if(!bRc) + { + Fail("CopyFileA: ERROR-> Couldn't set file attributes for " + "file %s with error %u\n", szDest, GetLastError()); + } + + /* delete the newly copied file */ + bRc = DeleteFile(szDest); + if(!bRc) + { + Fail("CopyFileA: DeleteFile failed to delete the" + "file correctly with error,%u.\n",GetLastError()); + } + + /* set the attributes of the source file to normal again */ + bRc = SetFileAttributesA(szSrcExisting, FILE_ATTRIBUTE_NORMAL); + if(!bRc) + { + Fail("CopyFileA: ERROR-> Couldn't set file attributes for " + "file %s with error %u\n", szSrcExisting, GetLastError()); + } + + /* delete the original file */ + bRc = DeleteFile(szSrcExisting); + if(!bRc) + { + Fail("CopyFileA: DeleteFile failed to delete the" + "file correctly with error,%u.\n",GetLastError()); + } + + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CopyFileA/test4/CMakeLists.txt index fb48c83741..12f85d1747 100644 --- a/src/pal/tests/palsuite/file_io/CopyFileA/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CopyFileA/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_copyfilea_test4 diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test4/test4.c b/src/pal/tests/palsuite/file_io/CopyFileA/test4/test4.c deleted file mode 100644 index 1ae69f5e1f..0000000000 --- a/src/pal/tests/palsuite/file_io/CopyFileA/test4/test4.c +++ /dev/null @@ -1,180 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests the PAL implementation of the CopyFileA function -** to see if a file can through different users belonging to -** different groups. -** - -=====================================================================*/ - -/* USECASE - Copy a file from a different user, belonging to a different group to - the the current user, who is a member of the current group. Then check - to see that the current user has the basic access rights to the copied - file. - - Thie original file used is the passwd file in the etc directory of a - BSD machine. This file should exist on all machines. -*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - return PASS; - -#else - - BOOL bRc = TRUE; - char* szSrcExisting = "/etc/passwd"; - char* szDest = "temp.tmp"; - char* szStringTest = "Marry had a little lamb"; - char szStringRead[30]; /* large enough for string szStringTest */ - - HANDLE hFile = NULL; - DWORD dwBytesWritten=0; - DWORD dwBytesRead=0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* copy the file */ - bRc = CopyFileA(szSrcExisting,szDest,TRUE); - if(!bRc) - { - Fail("CopyFileA: Cannot copy a file with error, %u",GetLastError()); - } - - /* try to get file attributes of destination file */ - if (GetFileAttributesA(szDest) == -1) - { - Fail("CopyFileA: GetFileAttributes of destination file " - "failed with error code %u. \n", - GetLastError()); - } - - /* set the attributes of the destination file to normal again */ - bRc = SetFileAttributes(szDest, FILE_ATTRIBUTE_NORMAL); - if(!bRc) - { - Fail("CopyFileA: ERROR-> Couldn't set file attributes for " - "file %s with error %u\n", szDest, GetLastError()); - } - - /* open the file for write purposes */ - hFile = CreateFile(szDest, - GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("CopyFileA: ERROR -> Unable to create file \"%s\".\n", - szDest); - } - - /* Attempt to write to the file */ - bRc = WriteFile(hFile, szStringTest, strlen(szStringTest), &dwBytesWritten, NULL); - if (!bRc) - { - Trace("CopyFileA: ERROR -> Unable to write to copied file with error " - "%u.\n", GetLastError()); - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with " - "error %u.\n",szDest, GetLastError()); - } - Fail(""); - - } - - /* Close the file handle */ - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with error %u " - ".\n",szDest,GetLastError()); - } - - - /* open the file for read purposes */ - hFile = CreateFile(szDest, - GENERIC_READ, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("CopyFileA: ERROR -> Unable to create file \"%s\".\n", - szDest); - } - - /* Attempt to read from the file */ - bRc = ReadFile(hFile, szStringRead, strlen(szStringTest), &dwBytesRead, NULL); - if (!bRc) - { - Trace("CopyFileA: ERROR -> Unable to read from copied file with " - "error %u.\n",GetLastError()); - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with " - "error %u.\n",szDest, GetLastError()); - } - Fail(""); - - } - - if(strncmp(szStringTest,szStringRead, strlen(szStringTest)) != 0) - { - Trace("CopyFileA: ERROR -> The string which was written '%s' does not " - "match the string '%s' which was read from the copied file.\n", - szStringTest,szStringRead); - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with " - "error %u.\n",szDest, GetLastError()); - } - Fail(""); - } - - /* Close the file handle */ - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with error %u " - ".\n",szDest,GetLastError()); - } - - /* Remove the temporary file */ - bRc = DeleteFile(szDest); - if(!bRc) - { - Fail("CopyFileA: Could not remove copied file with error %u\n", - GetLastError()); - } - - PAL_Terminate(); - return PASS; - -#endif - -} diff --git a/src/pal/tests/palsuite/file_io/CopyFileA/test4/test4.cpp b/src/pal/tests/palsuite/file_io/CopyFileA/test4/test4.cpp new file mode 100644 index 0000000000..1ae69f5e1f --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CopyFileA/test4/test4.cpp @@ -0,0 +1,180 @@ +// 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: test4.c +** +** Purpose: Tests the PAL implementation of the CopyFileA function +** to see if a file can through different users belonging to +** different groups. +** + +=====================================================================*/ + +/* USECASE + Copy a file from a different user, belonging to a different group to + the the current user, who is a member of the current group. Then check + to see that the current user has the basic access rights to the copied + file. + + Thie original file used is the passwd file in the etc directory of a + BSD machine. This file should exist on all machines. +*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + return PASS; + +#else + + BOOL bRc = TRUE; + char* szSrcExisting = "/etc/passwd"; + char* szDest = "temp.tmp"; + char* szStringTest = "Marry had a little lamb"; + char szStringRead[30]; /* large enough for string szStringTest */ + + HANDLE hFile = NULL; + DWORD dwBytesWritten=0; + DWORD dwBytesRead=0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* copy the file */ + bRc = CopyFileA(szSrcExisting,szDest,TRUE); + if(!bRc) + { + Fail("CopyFileA: Cannot copy a file with error, %u",GetLastError()); + } + + /* try to get file attributes of destination file */ + if (GetFileAttributesA(szDest) == -1) + { + Fail("CopyFileA: GetFileAttributes of destination file " + "failed with error code %u. \n", + GetLastError()); + } + + /* set the attributes of the destination file to normal again */ + bRc = SetFileAttributes(szDest, FILE_ATTRIBUTE_NORMAL); + if(!bRc) + { + Fail("CopyFileA: ERROR-> Couldn't set file attributes for " + "file %s with error %u\n", szDest, GetLastError()); + } + + /* open the file for write purposes */ + hFile = CreateFile(szDest, + GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("CopyFileA: ERROR -> Unable to create file \"%s\".\n", + szDest); + } + + /* Attempt to write to the file */ + bRc = WriteFile(hFile, szStringTest, strlen(szStringTest), &dwBytesWritten, NULL); + if (!bRc) + { + Trace("CopyFileA: ERROR -> Unable to write to copied file with error " + "%u.\n", GetLastError()); + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with " + "error %u.\n",szDest, GetLastError()); + } + Fail(""); + + } + + /* Close the file handle */ + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with error %u " + ".\n",szDest,GetLastError()); + } + + + /* open the file for read purposes */ + hFile = CreateFile(szDest, + GENERIC_READ, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("CopyFileA: ERROR -> Unable to create file \"%s\".\n", + szDest); + } + + /* Attempt to read from the file */ + bRc = ReadFile(hFile, szStringRead, strlen(szStringTest), &dwBytesRead, NULL); + if (!bRc) + { + Trace("CopyFileA: ERROR -> Unable to read from copied file with " + "error %u.\n",GetLastError()); + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with " + "error %u.\n",szDest, GetLastError()); + } + Fail(""); + + } + + if(strncmp(szStringTest,szStringRead, strlen(szStringTest)) != 0) + { + Trace("CopyFileA: ERROR -> The string which was written '%s' does not " + "match the string '%s' which was read from the copied file.\n", + szStringTest,szStringRead); + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with " + "error %u.\n",szDest, GetLastError()); + } + Fail(""); + } + + /* Close the file handle */ + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileA: ERROR -> Unable to close file \"%s\" with error %u " + ".\n",szDest,GetLastError()); + } + + /* Remove the temporary file */ + bRc = DeleteFile(szDest); + if(!bRc) + { + Fail("CopyFileA: Could not remove copied file with error %u\n", + GetLastError()); + } + + PAL_Terminate(); + return PASS; + +#endif + +} diff --git a/src/pal/tests/palsuite/file_io/CopyFileW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CopyFileW/test1/CMakeLists.txt index 766b120035..20c8141d90 100644 --- a/src/pal/tests/palsuite/file_io/CopyFileW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CopyFileW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CopyFileW.c + CopyFileW.cpp ) add_executable(paltest_copyfilew_test1 diff --git a/src/pal/tests/palsuite/file_io/CopyFileW/test1/CopyFileW.c b/src/pal/tests/palsuite/file_io/CopyFileW/test1/CopyFileW.c deleted file mode 100644 index 6127cc21bd..0000000000 --- a/src/pal/tests/palsuite/file_io/CopyFileW/test1/CopyFileW.c +++ /dev/null @@ -1,155 +0,0 @@ -// 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: CopyFileW.c -** -** Purpose: Tests the PAL implementation of the CopyFileW function -** -** -**===================================================================*/ - -/* -1. copy an existing file to non-existant with overwrite true -2. copy an existing file to non-existant with overwrite false -3. copy an existing file to existing with overwrite true -4. copy an existing file to existing with overwrite false -5. copy non-existant file to non-existant with overwrite true -6. copy non-existant file to non-existant with overwrite false -7. copy non-existant file to existing with overwrite true -8. copy non-existant file to existing with overwrite false -*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - LPSTR lpSource[2] = {"src_existing.tmp", "src_non-existant.tmp"}; - LPSTR lpDestination[2] = {"dst_existing.tmp", "dst_non-existant.tmp"}; - WCHAR* wcSource; - WCHAR* wcDest; - BOOL bFailIfExists[3] = {FALSE, TRUE}; - BOOL bRc = TRUE; - BOOL bSuccess = TRUE; - char results[20]; - FILE* resultsFile = NULL; - FILE* tempFile = NULL; - int nCounter = 0; - int i, j, k; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* load the expected results */ - resultsFile = fopen("expectedresults.txt", "r"); - memset (results, 0, 20); - fgets(results, 20, resultsFile); - fclose(resultsFile); - - nCounter = 0; - - /* create the src_existing file */ - tempFile = fopen(lpSource[0], "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "CopyFileW test file: src_existing.tmp\n"); - fclose(tempFile); - } - else - { - Fail("CopyFileW: ERROR-> Couldn't create \"src_existing.tmp\"\n"); - } - - /* create the dst_existing file */ - tempFile = fopen(lpDestination[0], "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "CopyFileW test file: dst_existing.tmp\n"); - fclose(tempFile); - } - else - { - Fail("CopyFileW: ERROR-> Couldn't create \"dst_existing.tmp\"\n"); - } - - - /* lpSource loop */ - for (i = 0; i < 2; i++) - { - /* lpDestination loop */ - for (j = 0; j < 2; j++) - { - /* bFailIfExists loop */ - for (k = 0; k < 2; k++) - { - wcSource = convert(lpSource[i]); - wcDest = convert(lpDestination[j]); - bRc = CopyFileW(wcSource, - wcDest, - bFailIfExists[k]); - free(wcSource); - free(wcDest); - if (!bRc) - { - if (results[nCounter] == '1') - { - Trace("CopyFileW: FAILED: test[%d][%d][%d]\n", i, j, k); - bSuccess = FALSE; - } - } - else - { - if (results[nCounter] == '0') - { - Trace("CopyFileW: FAILED: test[%d][%d][%d]\n", i, j, k); - bSuccess = FALSE; - } - else - { - /* verify the file was moved */ - if (GetFileAttributesA(lpDestination[j]) == -1) - { - Trace("CopyFileW: GetFileAttributes of destination" - "file failed on test[%d][%d][%d] with error " - "code %ld. \n",i,j,k,GetLastError()); - bSuccess = FALSE; - } - else if (GetFileAttributesA(lpSource[i]) == -1) - { - Trace("CopyFileW: GetFileAttributes of source file " - "file failed on test[%d][%d][%d] with error " - "code %ld. \n",i,j,k,GetLastError()); - bSuccess = FALSE; - } - else - { - /* verify attributes of destination file to - source file*/ - if(GetFileAttributes(lpSource[i]) != - GetFileAttributes(lpDestination[j])) - { - Trace("CopyFileW : The file attributes of the " - "destination file do not match the file " - "attributes of the source file on test " - "[%d][%d][%d].\n",i,j,k); - bSuccess = FALSE; - } - } - } - - } - nCounter++; - /* delete file file but don't worry if it fails */ - DeleteFileA(lpDestination[1]); - } - } - } - - int exitCode = bSuccess ? PASS : FAIL; - PAL_TerminateEx(exitCode); - return exitCode; -} diff --git a/src/pal/tests/palsuite/file_io/CopyFileW/test1/CopyFileW.cpp b/src/pal/tests/palsuite/file_io/CopyFileW/test1/CopyFileW.cpp new file mode 100644 index 0000000000..6127cc21bd --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CopyFileW/test1/CopyFileW.cpp @@ -0,0 +1,155 @@ +// 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: CopyFileW.c +** +** Purpose: Tests the PAL implementation of the CopyFileW function +** +** +**===================================================================*/ + +/* +1. copy an existing file to non-existant with overwrite true +2. copy an existing file to non-existant with overwrite false +3. copy an existing file to existing with overwrite true +4. copy an existing file to existing with overwrite false +5. copy non-existant file to non-existant with overwrite true +6. copy non-existant file to non-existant with overwrite false +7. copy non-existant file to existing with overwrite true +8. copy non-existant file to existing with overwrite false +*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + LPSTR lpSource[2] = {"src_existing.tmp", "src_non-existant.tmp"}; + LPSTR lpDestination[2] = {"dst_existing.tmp", "dst_non-existant.tmp"}; + WCHAR* wcSource; + WCHAR* wcDest; + BOOL bFailIfExists[3] = {FALSE, TRUE}; + BOOL bRc = TRUE; + BOOL bSuccess = TRUE; + char results[20]; + FILE* resultsFile = NULL; + FILE* tempFile = NULL; + int nCounter = 0; + int i, j, k; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* load the expected results */ + resultsFile = fopen("expectedresults.txt", "r"); + memset (results, 0, 20); + fgets(results, 20, resultsFile); + fclose(resultsFile); + + nCounter = 0; + + /* create the src_existing file */ + tempFile = fopen(lpSource[0], "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "CopyFileW test file: src_existing.tmp\n"); + fclose(tempFile); + } + else + { + Fail("CopyFileW: ERROR-> Couldn't create \"src_existing.tmp\"\n"); + } + + /* create the dst_existing file */ + tempFile = fopen(lpDestination[0], "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "CopyFileW test file: dst_existing.tmp\n"); + fclose(tempFile); + } + else + { + Fail("CopyFileW: ERROR-> Couldn't create \"dst_existing.tmp\"\n"); + } + + + /* lpSource loop */ + for (i = 0; i < 2; i++) + { + /* lpDestination loop */ + for (j = 0; j < 2; j++) + { + /* bFailIfExists loop */ + for (k = 0; k < 2; k++) + { + wcSource = convert(lpSource[i]); + wcDest = convert(lpDestination[j]); + bRc = CopyFileW(wcSource, + wcDest, + bFailIfExists[k]); + free(wcSource); + free(wcDest); + if (!bRc) + { + if (results[nCounter] == '1') + { + Trace("CopyFileW: FAILED: test[%d][%d][%d]\n", i, j, k); + bSuccess = FALSE; + } + } + else + { + if (results[nCounter] == '0') + { + Trace("CopyFileW: FAILED: test[%d][%d][%d]\n", i, j, k); + bSuccess = FALSE; + } + else + { + /* verify the file was moved */ + if (GetFileAttributesA(lpDestination[j]) == -1) + { + Trace("CopyFileW: GetFileAttributes of destination" + "file failed on test[%d][%d][%d] with error " + "code %ld. \n",i,j,k,GetLastError()); + bSuccess = FALSE; + } + else if (GetFileAttributesA(lpSource[i]) == -1) + { + Trace("CopyFileW: GetFileAttributes of source file " + "file failed on test[%d][%d][%d] with error " + "code %ld. \n",i,j,k,GetLastError()); + bSuccess = FALSE; + } + else + { + /* verify attributes of destination file to + source file*/ + if(GetFileAttributes(lpSource[i]) != + GetFileAttributes(lpDestination[j])) + { + Trace("CopyFileW : The file attributes of the " + "destination file do not match the file " + "attributes of the source file on test " + "[%d][%d][%d].\n",i,j,k); + bSuccess = FALSE; + } + } + } + + } + nCounter++; + /* delete file file but don't worry if it fails */ + DeleteFileA(lpDestination[1]); + } + } + } + + int exitCode = bSuccess ? PASS : FAIL; + PAL_TerminateEx(exitCode); + return exitCode; +} diff --git a/src/pal/tests/palsuite/file_io/CopyFileW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CopyFileW/test2/CMakeLists.txt index 5c0030bc8d..4201bdca88 100644 --- a/src/pal/tests/palsuite/file_io/CopyFileW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CopyFileW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_copyfilew_test2 diff --git a/src/pal/tests/palsuite/file_io/CopyFileW/test2/test2.c b/src/pal/tests/palsuite/file_io/CopyFileW/test2/test2.c deleted file mode 100644 index 5380a181ca..0000000000 --- a/src/pal/tests/palsuite/file_io/CopyFileW/test2/test2.c +++ /dev/null @@ -1,124 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests the PAL implementation of the CopyFileW function -** Attempt to copy a file to itself -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - LPSTR szSrcExisting = "src_existing.tmp"; - WCHAR* wcSource; - BOOL bRc = TRUE; - FILE* tempFile = NULL; - DWORD temp; - int retCode; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create the src_existing file */ - tempFile = fopen(szSrcExisting, "w"); - if (tempFile != NULL) - { - retCode = fputs("CopyFileA test file: src_existing.tmp ", tempFile); - if(retCode < 0) - { - Fail("CopyFileW: ERROR-> Couldn't write to %s with error " - "%u.\n", szSrcExisting, GetLastError()); - } - retCode = fclose(tempFile); - if(retCode != 0) - { - Fail("CopyFileW: ERROR-> Couldn't close file: %s with error " - "%u.\n", szSrcExisting, GetLastError()); - } - } - else - { - Fail("CopyFileW: ERROR-> Couldn't create %s.\n", szSrcExisting); - } - - /* convert source string to wide character */ - wcSource = convert(szSrcExisting); - - /* Get file attributes of source */ - temp = GetFileAttributes(szSrcExisting); - if (temp == -1) - { - free(wcSource); - Fail("CopyFileW: GetFileAttributes of source file " - "failed with error code %ld. \n", - GetLastError()); - } - - /* make sure a file can't copy to itself - first testing with IfFileExists flag set to true */ - bRc = CopyFileW(wcSource,wcSource,TRUE); - if(bRc) - { - free(wcSource); - Fail("ERROR: Cannot copy a file to itself, %u",GetLastError()); - } - - /* try to get file attributes of desitnation */ - if (GetFileAttributesA(szSrcExisting) == -1) - { - free(wcSource); - Fail("CopyFileW: GetFileAttributes of destination file " - "failed with error code %ld. \n", - GetLastError()); - } - else - { - /* verify attributes of destination file to source file*/ - if(temp != GetFileAttributes(szSrcExisting)) - { - free(wcSource); - Fail("CopyFileW : The file attributes of the " - "destination file do not match the file " - "attributes of the source file.\n"); - } - } - - /* testing with IfFileExists flags set to false - should fail in Windows and pass in UNIX */ - bRc = CopyFileW(wcSource,wcSource,FALSE); - free(wcSource); - if(bRc && (GetLastError() != ERROR_ALREADY_EXISTS)) - { - Fail("ERROR: Cannot copy a file to itself, %u",GetLastError()); - } - - if (GetFileAttributesA(szSrcExisting) == -1) - { - Fail("CopyFileW: GetFileAttributes of destination file " - "failed with error code %ld. \n", - GetLastError()); - } - else - { - /* verify attributes of destination file to source file*/ - - if(temp != GetFileAttributes(szSrcExisting)) - { - Fail("CopyFileW : The file attributes of the " - "destination file do not match the file " - "attributes of the source file.\n"); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/CopyFileW/test2/test2.cpp b/src/pal/tests/palsuite/file_io/CopyFileW/test2/test2.cpp new file mode 100644 index 0000000000..5380a181ca --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CopyFileW/test2/test2.cpp @@ -0,0 +1,124 @@ +// 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: test2.c +** +** Purpose: Tests the PAL implementation of the CopyFileW function +** Attempt to copy a file to itself +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + LPSTR szSrcExisting = "src_existing.tmp"; + WCHAR* wcSource; + BOOL bRc = TRUE; + FILE* tempFile = NULL; + DWORD temp; + int retCode; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create the src_existing file */ + tempFile = fopen(szSrcExisting, "w"); + if (tempFile != NULL) + { + retCode = fputs("CopyFileA test file: src_existing.tmp ", tempFile); + if(retCode < 0) + { + Fail("CopyFileW: ERROR-> Couldn't write to %s with error " + "%u.\n", szSrcExisting, GetLastError()); + } + retCode = fclose(tempFile); + if(retCode != 0) + { + Fail("CopyFileW: ERROR-> Couldn't close file: %s with error " + "%u.\n", szSrcExisting, GetLastError()); + } + } + else + { + Fail("CopyFileW: ERROR-> Couldn't create %s.\n", szSrcExisting); + } + + /* convert source string to wide character */ + wcSource = convert(szSrcExisting); + + /* Get file attributes of source */ + temp = GetFileAttributes(szSrcExisting); + if (temp == -1) + { + free(wcSource); + Fail("CopyFileW: GetFileAttributes of source file " + "failed with error code %ld. \n", + GetLastError()); + } + + /* make sure a file can't copy to itself + first testing with IfFileExists flag set to true */ + bRc = CopyFileW(wcSource,wcSource,TRUE); + if(bRc) + { + free(wcSource); + Fail("ERROR: Cannot copy a file to itself, %u",GetLastError()); + } + + /* try to get file attributes of desitnation */ + if (GetFileAttributesA(szSrcExisting) == -1) + { + free(wcSource); + Fail("CopyFileW: GetFileAttributes of destination file " + "failed with error code %ld. \n", + GetLastError()); + } + else + { + /* verify attributes of destination file to source file*/ + if(temp != GetFileAttributes(szSrcExisting)) + { + free(wcSource); + Fail("CopyFileW : The file attributes of the " + "destination file do not match the file " + "attributes of the source file.\n"); + } + } + + /* testing with IfFileExists flags set to false + should fail in Windows and pass in UNIX */ + bRc = CopyFileW(wcSource,wcSource,FALSE); + free(wcSource); + if(bRc && (GetLastError() != ERROR_ALREADY_EXISTS)) + { + Fail("ERROR: Cannot copy a file to itself, %u",GetLastError()); + } + + if (GetFileAttributesA(szSrcExisting) == -1) + { + Fail("CopyFileW: GetFileAttributes of destination file " + "failed with error code %ld. \n", + GetLastError()); + } + else + { + /* verify attributes of destination file to source file*/ + + if(temp != GetFileAttributes(szSrcExisting)) + { + Fail("CopyFileW : The file attributes of the " + "destination file do not match the file " + "attributes of the source file.\n"); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/CopyFileW/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CopyFileW/test3/CMakeLists.txt index 52d9aad1c0..d0fd94c990 100644 --- a/src/pal/tests/palsuite/file_io/CopyFileW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CopyFileW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_copyfilew_test3 diff --git a/src/pal/tests/palsuite/file_io/CopyFileW/test3/test3.c b/src/pal/tests/palsuite/file_io/CopyFileW/test3/test3.c deleted file mode 100644 index a2eb04c443..0000000000 --- a/src/pal/tests/palsuite/file_io/CopyFileW/test3/test3.c +++ /dev/null @@ -1,196 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests the PAL implementation of the CopyFileW function -** to see if a file can through different users belonging to -** different groups. -** - -=====================================================================*/ - -/* USECASE - Copy a file from a different user, belonging to a different group to - the the current user, who is a member of the current group. Then check - to see that the current user has the basic access rights to the copied - file. - - Thie original file used is the passwd file in the etc directory of a - BSD machine. This file should exist on all machines. -*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - return PASS; - -#else - - BOOL bRc = TRUE; - WCHAR szSrcExisting[] = {'/','e','t','c','/','p','a','s','s','w','d','\0'}; - WCHAR szDest[] = {'t','e','m','p','.','t','m','p','\0'}; - WCHAR szStringTest[] = {'M','a','r','r','y',' ','h','a','d',' ','a',' ', - 'l','i','t','t','l','e',' ','l','a','m','b','\0'}; - WCHAR szStringRead[30]; /* large enough for string szStringTest */ - - HANDLE hFile = NULL; - DWORD dwBytesWritten=0; - DWORD dwBytesRead=0; - int size=0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* copy the file */ - bRc = CopyFileW(szSrcExisting,szDest,TRUE); - if(!bRc) - { - Fail("CopyFileW: Cannot copy a file with error, %u",GetLastError()); - } - - /* try to get file attributes of destination file */ - if (GetFileAttributesW(szDest) == -1) - { - Fail("CopyFileW: GetFileAttributes of destination file " - "failed with error code %u. \n", - GetLastError()); - } - - /* set the attributes of the destination file to normal again */ - bRc = SetFileAttributesW(szDest, FILE_ATTRIBUTE_NORMAL); - if(!bRc) - { - Fail("CopyFileW: ERROR-> Couldn't set file attributes for " - "file %S with error %u\n", szDest, GetLastError()); - } - - /* open the file for write purposes */ - hFile = CreateFileW((WCHAR *)szDest, - GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("CopyFileW: ERROR -> Unable to create file \"%S\".\n", - szDest); - } - - /* To account for the size of a WCHAR is twice that of a char */ - size = wcslen(szStringTest); - size = size*sizeof(WCHAR); - - /* Attempt to write to the file */ - bRc = WriteFile(hFile, - szStringTest, - size, - &dwBytesWritten, - NULL); - - if (!bRc) - { - Trace("CopyFileW: ERROR -> Unable to write to copied file with error " - "%u.\n", GetLastError()); - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with " - "error %u.\n",szDest, GetLastError()); - } - Fail(""); - - } - - /* Close the file handle */ - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with error %u " - ".\n",szDest,GetLastError()); - } - - - /* open the file for read purposes */ - hFile = CreateFileW((WCHAR *)szDest, - GENERIC_READ, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("CopyFileW: ERROR -> Unable to create file \"%S\".\n", - szDest); - } - - /* Attempt to read from the file */ - bRc = ReadFile(hFile, - szStringRead, - size, - &dwBytesRead, - NULL); - - if (!bRc) - { - Trace("CopyFileW: ERROR -> Unable to read from copied file with " - "error %u.\n",GetLastError()); - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with " - "error %u.\n",szDest, GetLastError()); - } - Fail(""); - - } - - if(wcsncmp(szStringTest,szStringRead, wcslen(szStringTest)) != 0) - { - Trace("CopyFileW: ERROR -> The string which was written '%S' does not " - "match the string '%S' which was read from the copied file.\n", - szStringTest,szStringRead); - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with " - "error %u.\n",szDest, GetLastError()); - } - Fail(""); - } - - /* Close the file handle */ - bRc = CloseHandle(hFile); - if (!bRc) - { - Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with error %u " - ".\n",szDest,GetLastError()); - } - - /* Remove the temporary file */ - bRc = DeleteFileW(szDest); - if(!bRc) - { - Fail("CopyFileW: Could not remove copied file with error %u.\n", - GetLastError()); - } - - PAL_Terminate(); - return PASS; - -#endif - -} diff --git a/src/pal/tests/palsuite/file_io/CopyFileW/test3/test3.cpp b/src/pal/tests/palsuite/file_io/CopyFileW/test3/test3.cpp new file mode 100644 index 0000000000..a2eb04c443 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CopyFileW/test3/test3.cpp @@ -0,0 +1,196 @@ +// 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: test4.c +** +** Purpose: Tests the PAL implementation of the CopyFileW function +** to see if a file can through different users belonging to +** different groups. +** + +=====================================================================*/ + +/* USECASE + Copy a file from a different user, belonging to a different group to + the the current user, who is a member of the current group. Then check + to see that the current user has the basic access rights to the copied + file. + + Thie original file used is the passwd file in the etc directory of a + BSD machine. This file should exist on all machines. +*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + return PASS; + +#else + + BOOL bRc = TRUE; + WCHAR szSrcExisting[] = {'/','e','t','c','/','p','a','s','s','w','d','\0'}; + WCHAR szDest[] = {'t','e','m','p','.','t','m','p','\0'}; + WCHAR szStringTest[] = {'M','a','r','r','y',' ','h','a','d',' ','a',' ', + 'l','i','t','t','l','e',' ','l','a','m','b','\0'}; + WCHAR szStringRead[30]; /* large enough for string szStringTest */ + + HANDLE hFile = NULL; + DWORD dwBytesWritten=0; + DWORD dwBytesRead=0; + int size=0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* copy the file */ + bRc = CopyFileW(szSrcExisting,szDest,TRUE); + if(!bRc) + { + Fail("CopyFileW: Cannot copy a file with error, %u",GetLastError()); + } + + /* try to get file attributes of destination file */ + if (GetFileAttributesW(szDest) == -1) + { + Fail("CopyFileW: GetFileAttributes of destination file " + "failed with error code %u. \n", + GetLastError()); + } + + /* set the attributes of the destination file to normal again */ + bRc = SetFileAttributesW(szDest, FILE_ATTRIBUTE_NORMAL); + if(!bRc) + { + Fail("CopyFileW: ERROR-> Couldn't set file attributes for " + "file %S with error %u\n", szDest, GetLastError()); + } + + /* open the file for write purposes */ + hFile = CreateFileW((WCHAR *)szDest, + GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("CopyFileW: ERROR -> Unable to create file \"%S\".\n", + szDest); + } + + /* To account for the size of a WCHAR is twice that of a char */ + size = wcslen(szStringTest); + size = size*sizeof(WCHAR); + + /* Attempt to write to the file */ + bRc = WriteFile(hFile, + szStringTest, + size, + &dwBytesWritten, + NULL); + + if (!bRc) + { + Trace("CopyFileW: ERROR -> Unable to write to copied file with error " + "%u.\n", GetLastError()); + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with " + "error %u.\n",szDest, GetLastError()); + } + Fail(""); + + } + + /* Close the file handle */ + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with error %u " + ".\n",szDest,GetLastError()); + } + + + /* open the file for read purposes */ + hFile = CreateFileW((WCHAR *)szDest, + GENERIC_READ, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("CopyFileW: ERROR -> Unable to create file \"%S\".\n", + szDest); + } + + /* Attempt to read from the file */ + bRc = ReadFile(hFile, + szStringRead, + size, + &dwBytesRead, + NULL); + + if (!bRc) + { + Trace("CopyFileW: ERROR -> Unable to read from copied file with " + "error %u.\n",GetLastError()); + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with " + "error %u.\n",szDest, GetLastError()); + } + Fail(""); + + } + + if(wcsncmp(szStringTest,szStringRead, wcslen(szStringTest)) != 0) + { + Trace("CopyFileW: ERROR -> The string which was written '%S' does not " + "match the string '%S' which was read from the copied file.\n", + szStringTest,szStringRead); + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with " + "error %u.\n",szDest, GetLastError()); + } + Fail(""); + } + + /* Close the file handle */ + bRc = CloseHandle(hFile); + if (!bRc) + { + Fail("CopyFileW: ERROR -> Unable to close file \"%S\" with error %u " + ".\n",szDest,GetLastError()); + } + + /* Remove the temporary file */ + bRc = DeleteFileW(szDest); + if(!bRc) + { + Fail("CopyFileW: Could not remove copied file with error %u.\n", + GetLastError()); + } + + PAL_Terminate(); + return PASS; + +#endif + +} diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CMakeLists.txt index f8cdf19933..1dc87fa34b 100644 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateDirectoryA.c + CreateDirectoryA.cpp ) add_executable(paltest_createdirectorya_test1 diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c deleted file mode 100644 index 2bb441e732..0000000000 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.c +++ /dev/null @@ -1,296 +0,0 @@ -// 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: CreateDirectoryA.c -** -** Purpose: Tests the PAL implementation of the CreateDirectoryA function. -** -** Depends on: -** RemoveDirectoryW (since RemoveDirectoryA is unavailable) -** GetCurrentDirectoryA -** -** -**===================================================================*/ - -#include - - -/* apparently, under WIN32 the max path size is 248 but under - BSD it is _MAX_PATH */ -#if WIN32 -#define CREATE_MAX_PATH_SIZE 248 -#else -#define CREATE_MAX_PATH_SIZE _MAX_PATH -#endif - - -int __cdecl main(int argc, char *argv[]) -{ - const char* szTestDir = {"test_directory"}; - const char* szDotDir = {".dotDirectory"}; - BOOL bRc = FALSE; - BOOL bSuccess = FALSE; - const int buf_size = CREATE_MAX_PATH_SIZE + 10; - char szDirName[CREATE_MAX_PATH_SIZE + 10]; - char buffer[CREATE_MAX_PATH_SIZE + 10]; - WCHAR* pTemp = NULL; - DWORD curDirLen; - DWORD curDirectory = 1024; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - /* directory does not exist */ - bRc = CreateDirectoryA(szTestDir, NULL); - if (bRc == FALSE) - { - Fail("CreateDirectoryA: Failed to create \"%s\" with error code %ld\n", - szTestDir, - GetLastError()); - } - - - /* directory exists should fail */ - bRc = CreateDirectoryA(szTestDir, NULL); - if (bRc == TRUE) - { - pTemp = convert((LPSTR)szTestDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - Fail("CreateDirectoryA: Succeeded creating the directory" - "\"%s\" when it exists already.\n", - szTestDir); - } - else - { - pTemp = convert((LPSTR)szTestDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - } - - - /* long directory names (CREATE_MAX_PATH_SIZE - 1, CREATE_MAX_PATH_SIZE - and CREATE_MAX_PATH_SIZE + 1 characters - including terminating null char) */ - - curDirLen = GetCurrentDirectoryA(0, NULL); - - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 2 - curDirLen); - bRc = CreateDirectoryA(szDirName, NULL); - if (bRc == FALSE) - { - Fail("CreateDirectoryA: Failed to create a directory" - " name %d chars long with the error code %ld\n", - strlen(szDirName), - GetLastError()); - } - else - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - } - - /* Set directory back to initial directory */ - SetCurrentDirectoryA(buffer); - - pTemp = convert((LPSTR)szDirName); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szDirName, - GetLastError()); - } - } - - - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 1 - curDirLen); - bRc = CreateDirectoryA(szDirName, NULL); - if (bRc == FALSE) - { - Fail("CreateDirectoryA: Failed to create a directory" - " name %d chars long with error code %ld\n", - strlen(szDirName), - GetLastError()); - } - else - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - } - - /* Set Directroy back to initial directory */ - SetCurrentDirectoryA(buffer); - - pTemp = convert(szDirName); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szDirName, - GetLastError()); - } - } - - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - curDirLen); - bRc = CreateDirectoryA(szDirName, NULL); - if (bRc != FALSE) - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - } - - /* set directory back to initial directory */ - SetCurrentDirectoryA(buffer); - - pTemp = convert(szDirName); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szDirName, - GetLastError()); - } - if (strlen(szDirName) > CREATE_MAX_PATH_SIZE) - { - Fail("CreateDirectoryA: Failed because it created a directory" - " name 1 character longer (%d chars) than the max dir size " - "allowed\n", - strlen(szDirName)); - } - } - - - /* long directory name CREATE_MAX_PATH_SIZE + 3 chars including "..\" - (real path length <= CREATE_MAX_PATH_SIZE) */ - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE + 3 - 1 - curDirLen); - szDirName[0] = '.'; - szDirName[1] = '.'; - szDirName[2] = '\\'; - bRc = CreateDirectoryA(szDirName, NULL); - if (bRc == FALSE) - { - Fail("CreateDirectoryA: Failed to create a directory name more " - "than %d chars long and its real path name is less " - "than %d chars, error %u\n", - CREATE_MAX_PATH_SIZE, - CREATE_MAX_PATH_SIZE, GetLastError()); - } - else - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - } - - /* set directory back to initial directory */ - SetCurrentDirectoryA(buffer); - - pTemp = convert(szDirName); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " - " \"%s\" with the error code %ld.\n", - szDirName, - GetLastError()); - } - } - - - /* directories with dots */ - memset(szDirName, 0, buf_size); - sprintf(szDirName, szDotDir); - bRc = CreateDirectoryA(szDirName, NULL); - if (bRc == FALSE) - { - Fail("CreateDirectoryA: Failed to create \"%s\" with error code %ld\n", - szDotDir, - GetLastError()); - } - else - { - - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - } - - /* set directory back to initial directory */ - SetCurrentDirectoryA(buffer); - - pTemp = convert((LPSTR)szDotDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " - " \"%s\" with the error code %ld.\n", - szDotDir, - GetLastError()); - } - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.cpp b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.cpp new file mode 100644 index 0000000000..4082d38b36 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test1/CreateDirectoryA.cpp @@ -0,0 +1,296 @@ +// 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: CreateDirectoryA.c +** +** Purpose: Tests the PAL implementation of the CreateDirectoryA function. +** +** Depends on: +** RemoveDirectoryW (since RemoveDirectoryA is unavailable) +** GetCurrentDirectoryA +** +** +**===================================================================*/ + +#include + + +/* apparently, under WIN32 the max path size is 248 but under + BSD it is _MAX_PATH */ +#if WIN32 +#define CREATE_MAX_PATH_SIZE 248 +#else +#define CREATE_MAX_PATH_SIZE _MAX_PATH +#endif + + +int __cdecl main(int argc, char *argv[]) +{ + const char* szTestDir = {"test_directory"}; + const char* szDotDir = {".dotDirectory"}; + BOOL bRc = FALSE; + BOOL bSuccess = FALSE; + const int buf_size = CREATE_MAX_PATH_SIZE + 10; + char szDirName[CREATE_MAX_PATH_SIZE + 10]; + char buffer[CREATE_MAX_PATH_SIZE + 10]; + WCHAR* pTemp = NULL; + DWORD curDirLen; + DWORD curDirectory = 1024; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + /* directory does not exist */ + bRc = CreateDirectoryA(szTestDir, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: Failed to create \"%s\" with error code %ld\n", + szTestDir, + GetLastError()); + } + + + /* directory exists should fail */ + bRc = CreateDirectoryA(szTestDir, NULL); + if (bRc == TRUE) + { + pTemp = convert((LPSTR)szTestDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + Fail("CreateDirectoryA: Succeeded creating the directory" + "\"%s\" when it exists already.\n", + szTestDir); + } + else + { + pTemp = convert((LPSTR)szTestDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + } + + + /* long directory names (CREATE_MAX_PATH_SIZE - 1, CREATE_MAX_PATH_SIZE + and CREATE_MAX_PATH_SIZE + 1 characters + including terminating null char) */ + + curDirLen = GetCurrentDirectoryA(0, NULL); + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 2 - curDirLen); + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: Failed to create a directory" + " name %d chars long with the error code %ld\n", + strlen(szDirName), + GetLastError()); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* Set directory back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert((LPSTR)szDirName); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szDirName, + GetLastError()); + } + } + + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 1 - curDirLen); + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: Failed to create a directory" + " name %d chars long with error code %ld\n", + strlen(szDirName), + GetLastError()); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* Set Directroy back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert(szDirName); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szDirName, + GetLastError()); + } + } + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - curDirLen); + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc != FALSE) + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* set directory back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert(szDirName); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szDirName, + GetLastError()); + } + if (strlen(szDirName) > CREATE_MAX_PATH_SIZE) + { + Fail("CreateDirectoryA: Failed because it created a directory" + " name 1 character longer (%d chars) than the max dir size " + "allowed\n", + strlen(szDirName)); + } + } + + + /* long directory name CREATE_MAX_PATH_SIZE + 3 chars including "..\" + (real path length <= CREATE_MAX_PATH_SIZE) */ + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE + 3 - 1 - curDirLen); + szDirName[0] = '.'; + szDirName[1] = '.'; + szDirName[2] = '\\'; + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: Failed to create a directory name more " + "than %d chars long and its real path name is less " + "than %d chars, error %u\n", + CREATE_MAX_PATH_SIZE, + CREATE_MAX_PATH_SIZE, GetLastError()); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* set directory back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert(szDirName); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + " \"%s\" with the error code %ld.\n", + szDirName, + GetLastError()); + } + } + + + /* directories with dots */ + memset(szDirName, 0, buf_size); + sprintf_s(szDirName, _countof(szDirName), szDotDir); + bRc = CreateDirectoryA(szDirName, NULL); + if (bRc == FALSE) + { + Fail("CreateDirectoryA: Failed to create \"%s\" with error code %ld\n", + szDotDir, + GetLastError()); + } + else + { + + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Fail("CreateDirectoryA: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + } + + /* set directory back to initial directory */ + SetCurrentDirectoryA(buffer); + + pTemp = convert((LPSTR)szDotDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Fail("CreateDirectoryA: RemoveDirectoryW failed to remove " + " \"%s\" with the error code %ld.\n", + szDotDir, + GetLastError()); + } + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/CMakeLists.txt index a50a986d1a..3ee8abbcc2 100644 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createdirectorya.c + createdirectorya.cpp ) add_executable(paltest_createdirectorya_test2 diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/createdirectorya.c b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/createdirectorya.c deleted file mode 100644 index fc1bc967b7..0000000000 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/createdirectorya.c +++ /dev/null @@ -1,335 +0,0 @@ -// 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: createdirectorya.c -** -** Purpose: Tests the PAL implementation of the CreateDirectoryA function. -** Test creating a directory in a directory path that does not exist. -** Test creating directory with trailing slashes. -** -** Depends on: -** RemoveDirectoryW (since RemoveDirectoryA is unavailable) -** -** -**==========================================================================*/ - - - -#include - -int main(int argc, char *argv[]) -{ - -#if WIN32 - const char* szTestRootDir = {"/at_root_directory_PALTEST"}; -#endif - - const char* szTestDir = {"test_ directory"}; - const char* szTestSubDir = - {".\\./././../test2/./../../////////createdirectorya" - "\\\\/test2/test_ directory\\sub"}; - const char* szTest2SubDir = {"test_ directory/sub\\sub_sub"}; - const char* szTest2SubDirWinSlash = - {"test_ directory/sub\\sub_sub\\"}; - const char* szTest2SubDirUnixSlash = - {"test_ directory/sub\\sub_sub/////"}; - BOOL bRc = FALSE; - BOOL clean = TRUE; - WCHAR* pTemp = NULL; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* platform dependent cases */ - /* test for WIN32, create directory at the root." - * using '/directory_name ' format */ -#if WIN32 - - bRc = CreateDirectoryA(szTestRootDir, NULL); - - if (bRc != TRUE) - { - Fail("CreateDirectoryA: Failed creating the directory " - "\"%s\" with the error code %ld.\n", - szTestRootDir,GetLastError()); - } - - /* clean szTestRootDir */ - pTemp = convert((LPSTR) szTestRootDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - - if (! bRc) - { - clean=bRc; - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestRootDir, - GetLastError()); - } - -#endif - - - /* - * create subdirectory "test_directory//sub//sub_sub" - * while parent directory does not exist. - */ - bRc = CreateDirectoryA(szTest2SubDir, NULL); - if (bRc == TRUE) - { - pTemp = convert((LPSTR)szTest2SubDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTest2SubDir, - GetLastError()); - } - Fail("CreateDirectoryA: Succeeded creating the directory\"%s\" while" - " its parent directory does not exists. It should fail.\n", - szTest2SubDir); - - } - - - /* create directory tree one by one - * first create "test_dir" - */ - bRc = CreateDirectoryA(szTestDir, NULL); - - if (bRc != TRUE)/*failed creating the path*/ - { - Fail("CreateDirectoryA: Failed creating the directory " - "\"%s\" with the error code %ld.\n", szTestDir,GetLastError()); - } - - /* create the sub directory test_directory//sub */ - bRc = CreateDirectoryA(szTestSubDir, NULL); - - if (bRc != TRUE)/*failed creating the path*/ - { - Trace("CreateDirectoryA: Failed creating the directory " - "\"%s\" with the error code %ld.\n", - szTestSubDir , GetLastError()); - - /* cleaning... remove parent directory */ - pTemp = convert((LPSTR)szTestDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with an error code %ld.\n", - szTestDir, - GetLastError()); - } - Fail(""); - } - - /* - * the director structure is test_directory//sub - * test creating directory " test_directory//sub//sub_sub" - */ - bRc = CreateDirectoryA(szTest2SubDir, NULL); - if (bRc != TRUE) - { - Trace("CreateDirectoryA: Failed creating the directory " - "\"%s\" with the error code %ld.\n", - szTest2SubDir , GetLastError()); - - /* remove parent directory test_directory//sub */ - pTemp = convert((LPSTR)szTestSubDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (!bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /* remove parent directory test_directory */ - pTemp = convert((LPSTR)szTestDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (! bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - Fail(""); - - } - - /* RemoveDirectiryW szTest2SubDir */ - pTemp = convert((LPSTR)szTest2SubDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - - if (! bRc) - { - clean=bRc; - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTest2SubDir, - GetLastError()); - } - - - /* - * the director structure is test_directory//sub - * test creating directory " test_directory//sub//sub_sub\\" - */ - bRc = CreateDirectoryA(szTest2SubDirWinSlash, NULL); - if (bRc != TRUE) - { - Trace("CreateDirectoryA: Failed creating the directory " - "\"%s\" with the error code %ld.\n", - szTest2SubDirWinSlash , GetLastError()); - - /* remove parent directory test_directory//sub */ - pTemp = convert((LPSTR)szTestSubDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (! bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /* remove parent directory test_directory */ - pTemp = convert((LPSTR)szTestDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (! bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - Fail(""); - - } - - /* RemoveDirectiryW szTest2SubDirWinSlash */ - pTemp = convert((LPSTR)szTest2SubDirWinSlash); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - - if (! bRc) - { - clean=bRc; - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTest2SubDirWinSlash, - GetLastError()); - } - - /* - * the director structure is test_directory//sub - * test creating directory " test_directory//sub//sub_sub/////" - */ - bRc = CreateDirectoryA(szTest2SubDirUnixSlash, NULL); - if (bRc != TRUE) - { - Trace("CreateDirectoryA: Failed creating the directory " - "\"%s\" with the error code %ld.\n", - szTest2SubDirUnixSlash , GetLastError()); - - /* remove parent directory test_directory//sub */ - pTemp = convert((LPSTR)szTestSubDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (! bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /* remove parent directory test_directory */ - pTemp = convert((LPSTR)szTestDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - if (! bRc) - { - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - Fail(""); - - } - - /* RemoveDirectiryW will return false if directory does not exist. - * if it returns true then test is completed and the directory path - * is clean for running the test again. - */ - pTemp = convert((LPSTR)szTest2SubDirUnixSlash); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - - if (! bRc) - { - clean=bRc; - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTest2SubDirUnixSlash, - GetLastError()); - } - - - - - /*clean parent szTestSubDir */ - pTemp = convert((LPSTR)szTestSubDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /*clean parent szTestDir */ - pTemp = convert((LPSTR)szTestDir); - bRc = RemoveDirectoryW(pTemp); - free(pTemp); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " - "\"%s\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - - if(! clean) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/createdirectorya.cpp b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/createdirectorya.cpp new file mode 100644 index 0000000000..fc1bc967b7 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryA/test2/createdirectorya.cpp @@ -0,0 +1,335 @@ +// 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: createdirectorya.c +** +** Purpose: Tests the PAL implementation of the CreateDirectoryA function. +** Test creating a directory in a directory path that does not exist. +** Test creating directory with trailing slashes. +** +** Depends on: +** RemoveDirectoryW (since RemoveDirectoryA is unavailable) +** +** +**==========================================================================*/ + + + +#include + +int main(int argc, char *argv[]) +{ + +#if WIN32 + const char* szTestRootDir = {"/at_root_directory_PALTEST"}; +#endif + + const char* szTestDir = {"test_ directory"}; + const char* szTestSubDir = + {".\\./././../test2/./../../////////createdirectorya" + "\\\\/test2/test_ directory\\sub"}; + const char* szTest2SubDir = {"test_ directory/sub\\sub_sub"}; + const char* szTest2SubDirWinSlash = + {"test_ directory/sub\\sub_sub\\"}; + const char* szTest2SubDirUnixSlash = + {"test_ directory/sub\\sub_sub/////"}; + BOOL bRc = FALSE; + BOOL clean = TRUE; + WCHAR* pTemp = NULL; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* platform dependent cases */ + /* test for WIN32, create directory at the root." + * using '/directory_name ' format */ +#if WIN32 + + bRc = CreateDirectoryA(szTestRootDir, NULL); + + if (bRc != TRUE) + { + Fail("CreateDirectoryA: Failed creating the directory " + "\"%s\" with the error code %ld.\n", + szTestRootDir,GetLastError()); + } + + /* clean szTestRootDir */ + pTemp = convert((LPSTR) szTestRootDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + + if (! bRc) + { + clean=bRc; + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestRootDir, + GetLastError()); + } + +#endif + + + /* + * create subdirectory "test_directory//sub//sub_sub" + * while parent directory does not exist. + */ + bRc = CreateDirectoryA(szTest2SubDir, NULL); + if (bRc == TRUE) + { + pTemp = convert((LPSTR)szTest2SubDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTest2SubDir, + GetLastError()); + } + Fail("CreateDirectoryA: Succeeded creating the directory\"%s\" while" + " its parent directory does not exists. It should fail.\n", + szTest2SubDir); + + } + + + /* create directory tree one by one + * first create "test_dir" + */ + bRc = CreateDirectoryA(szTestDir, NULL); + + if (bRc != TRUE)/*failed creating the path*/ + { + Fail("CreateDirectoryA: Failed creating the directory " + "\"%s\" with the error code %ld.\n", szTestDir,GetLastError()); + } + + /* create the sub directory test_directory//sub */ + bRc = CreateDirectoryA(szTestSubDir, NULL); + + if (bRc != TRUE)/*failed creating the path*/ + { + Trace("CreateDirectoryA: Failed creating the directory " + "\"%s\" with the error code %ld.\n", + szTestSubDir , GetLastError()); + + /* cleaning... remove parent directory */ + pTemp = convert((LPSTR)szTestDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with an error code %ld.\n", + szTestDir, + GetLastError()); + } + Fail(""); + } + + /* + * the director structure is test_directory//sub + * test creating directory " test_directory//sub//sub_sub" + */ + bRc = CreateDirectoryA(szTest2SubDir, NULL); + if (bRc != TRUE) + { + Trace("CreateDirectoryA: Failed creating the directory " + "\"%s\" with the error code %ld.\n", + szTest2SubDir , GetLastError()); + + /* remove parent directory test_directory//sub */ + pTemp = convert((LPSTR)szTestSubDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (!bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /* remove parent directory test_directory */ + pTemp = convert((LPSTR)szTestDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (! bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + Fail(""); + + } + + /* RemoveDirectiryW szTest2SubDir */ + pTemp = convert((LPSTR)szTest2SubDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + + if (! bRc) + { + clean=bRc; + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTest2SubDir, + GetLastError()); + } + + + /* + * the director structure is test_directory//sub + * test creating directory " test_directory//sub//sub_sub\\" + */ + bRc = CreateDirectoryA(szTest2SubDirWinSlash, NULL); + if (bRc != TRUE) + { + Trace("CreateDirectoryA: Failed creating the directory " + "\"%s\" with the error code %ld.\n", + szTest2SubDirWinSlash , GetLastError()); + + /* remove parent directory test_directory//sub */ + pTemp = convert((LPSTR)szTestSubDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (! bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /* remove parent directory test_directory */ + pTemp = convert((LPSTR)szTestDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (! bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + Fail(""); + + } + + /* RemoveDirectiryW szTest2SubDirWinSlash */ + pTemp = convert((LPSTR)szTest2SubDirWinSlash); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + + if (! bRc) + { + clean=bRc; + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTest2SubDirWinSlash, + GetLastError()); + } + + /* + * the director structure is test_directory//sub + * test creating directory " test_directory//sub//sub_sub/////" + */ + bRc = CreateDirectoryA(szTest2SubDirUnixSlash, NULL); + if (bRc != TRUE) + { + Trace("CreateDirectoryA: Failed creating the directory " + "\"%s\" with the error code %ld.\n", + szTest2SubDirUnixSlash , GetLastError()); + + /* remove parent directory test_directory//sub */ + pTemp = convert((LPSTR)szTestSubDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (! bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /* remove parent directory test_directory */ + pTemp = convert((LPSTR)szTestDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + if (! bRc) + { + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + Fail(""); + + } + + /* RemoveDirectiryW will return false if directory does not exist. + * if it returns true then test is completed and the directory path + * is clean for running the test again. + */ + pTemp = convert((LPSTR)szTest2SubDirUnixSlash); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + + if (! bRc) + { + clean=bRc; + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTest2SubDirUnixSlash, + GetLastError()); + } + + + + + /*clean parent szTestSubDir */ + pTemp = convert((LPSTR)szTestSubDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /*clean parent szTestDir */ + pTemp = convert((LPSTR)szTestDir); + bRc = RemoveDirectoryW(pTemp); + free(pTemp); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryA: RemoveDirectoryW failed to remove " + "\"%s\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + + if(! clean) + { + Fail(""); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CMakeLists.txt index 1981e37082..f8cb584cc6 100644 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateDirectoryW.c + CreateDirectoryW.cpp ) add_executable(paltest_createdirectoryw_test1 diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.c b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.c deleted file mode 100644 index 9b020cc19c..0000000000 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.c +++ /dev/null @@ -1,347 +0,0 @@ -// 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: CreateDirectoryW.c -** -** Purpose: Tests the PAL implementation of the CreateDirectoryW function. -** -** -**===================================================================*/ - -#include - - -/* apparently, under WIN32 the max path size is 248 but under - BSD it is _MAX_PATH */ -#if WIN32 -#define CREATE_MAX_PATH_SIZE 248 -#else -#define CREATE_MAX_PATH_SIZE _MAX_PATH -#endif - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bRc = FALSE; - BOOL bSuccess = FALSE; - const int buf_size = CREATE_MAX_PATH_SIZE + 10; - char szDirName[CREATE_MAX_PATH_SIZE + 10]; - char buffer[CREATE_MAX_PATH_SIZE + 10]; - WCHAR* pTemp = NULL; - DWORD curDirLen; - DWORD curDirectory = 1024; - - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* directory does not exist */ - pTemp = convert("test_directory"); - bRc = CreateDirectoryW(pTemp, NULL); - free(pTemp); - if (bRc == FALSE) - { - Fail("CreateDirectoryW: Failed to create \"test_directory\"\n"); - } - - /* directory exists */ - pTemp = convert("test_directory"); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == TRUE) - { - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail("CreateDirectoryW: Succeeded creating the directory" - " \"test_directory\" when it exists already.\n"); - } - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - - /* long directory names (CREATE_MAX_PATH_SIZE - 1, CREATE_MAX_PATH_SIZE - and CREATE_MAX_PATH_SIZE + 1 characters - including terminating null char) */ - - curDirLen = GetCurrentDirectoryA(0, NULL); - - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 2 - curDirLen); - pTemp = convert((LPSTR)szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == FALSE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed to create a directory" - " name (%d) chars long with the error code %ld\n", - CREATE_MAX_PATH_SIZE - 1, - GetLastError()); - } - else - { - - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail(""); - - } - - /* Set directory back to initial directory */ - bRc = SetCurrentDirectoryA(buffer); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " - "change the directory with error %u.\n", - GetLastError()); - } - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - } - - - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 1 - curDirLen); - pTemp = convert(szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == FALSE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed to create a directory" - " name %d chars long with error code %ld\n", - strlen(szDirName), - GetLastError()); - } - else - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail(""); - } - - /* Set directory back to initial directory */ - bRc = SetCurrentDirectoryA(buffer); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " - "change the directory with error %u.\n", - GetLastError()); - } - - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - } - - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - curDirLen); - pTemp = convert(szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - - if (bRc != FALSE) - { - RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - if (strlen(szDirName) > CREATE_MAX_PATH_SIZE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed because it created a directory" - " name 1 character longer (%d chars) than the max dir size" - " allowed\n", - strlen(szDirName)); - } - } - - free(pTemp); - - /* long directory name CREATE_MAX_PATH_SIZE + 3 chars including "..\" - (real path length <= CREATE_MAX_PATH_SIZE) */ - memset(szDirName, 0, buf_size); - memset(szDirName, 'a', CREATE_MAX_PATH_SIZE + 3 - 1 - curDirLen); - szDirName[0] = '.'; - szDirName[1] = '.'; - szDirName[2] = '\\'; - pTemp = convert(szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == FALSE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed to create a directory name more " - "than %d chars long and its real path name is less " - "than %d chars\n", - CREATE_MAX_PATH_SIZE, - CREATE_MAX_PATH_SIZE); - } - else - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail(""); - } - - /* Set directory back to initial directory */ - bRc = SetCurrentDirectoryA(buffer); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " - "change the directory with error %u.\n", - GetLastError()); - } - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - } - - /* directories with dots */ - memset(szDirName, 0, 252); - sprintf(szDirName, ".dotDirectory"); - pTemp = convert(szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == FALSE) - { - free(pTemp); - Fail("CreateDirectoryW: Failed to create a dot directory\n"); - } - else - { - /* Check to see if it's possible to navigate to directory */ - GetCurrentDirectoryA(curDirectory, buffer); - bSuccess = SetCurrentDirectoryA(szDirName); - if(!bSuccess) - { - Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " - "navigate to the newly created directory with error " - "code %u.\n", GetLastError()); - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - Fail(""); - } - - /* Set directory back to initial directory */ - bRc = SetCurrentDirectoryA(buffer); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " - "change the directory with error %u.\n", - GetLastError()); - } - - bRc = RemoveDirectoryW(pTemp); - if(!bRc) - { - free(pTemp); - Fail("CreateDirectoryW: RemoveDirectoryW failed to " - "delete the directory with error %u.\n", - GetLastError()); - } - free(pTemp); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.cpp b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.cpp new file mode 100644 index 0000000000..bbaedda745 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test1/CreateDirectoryW.cpp @@ -0,0 +1,347 @@ +// 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: CreateDirectoryW.c +** +** Purpose: Tests the PAL implementation of the CreateDirectoryW function. +** +** +**===================================================================*/ + +#include + + +/* apparently, under WIN32 the max path size is 248 but under + BSD it is _MAX_PATH */ +#if WIN32 +#define CREATE_MAX_PATH_SIZE 248 +#else +#define CREATE_MAX_PATH_SIZE _MAX_PATH +#endif + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bRc = FALSE; + BOOL bSuccess = FALSE; + const int buf_size = CREATE_MAX_PATH_SIZE + 10; + char szDirName[CREATE_MAX_PATH_SIZE + 10]; + char buffer[CREATE_MAX_PATH_SIZE + 10]; + WCHAR* pTemp = NULL; + DWORD curDirLen; + DWORD curDirectory = 1024; + + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* directory does not exist */ + pTemp = convert("test_directory"); + bRc = CreateDirectoryW(pTemp, NULL); + free(pTemp); + if (bRc == FALSE) + { + Fail("CreateDirectoryW: Failed to create \"test_directory\"\n"); + } + + /* directory exists */ + pTemp = convert("test_directory"); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == TRUE) + { + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail("CreateDirectoryW: Succeeded creating the directory" + " \"test_directory\" when it exists already.\n"); + } + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + + /* long directory names (CREATE_MAX_PATH_SIZE - 1, CREATE_MAX_PATH_SIZE + and CREATE_MAX_PATH_SIZE + 1 characters + including terminating null char) */ + + curDirLen = GetCurrentDirectoryA(0, NULL); + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 2 - curDirLen); + pTemp = convert((LPSTR)szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == FALSE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed to create a directory" + " name (%d) chars long with the error code %ld\n", + CREATE_MAX_PATH_SIZE - 1, + GetLastError()); + } + else + { + + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail(""); + + } + + /* Set directory back to initial directory */ + bRc = SetCurrentDirectoryA(buffer); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " + "change the directory with error %u.\n", + GetLastError()); + } + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + } + + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - 1 - curDirLen); + pTemp = convert(szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == FALSE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed to create a directory" + " name %d chars long with error code %ld\n", + strlen(szDirName), + GetLastError()); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail(""); + } + + /* Set directory back to initial directory */ + bRc = SetCurrentDirectoryA(buffer); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " + "change the directory with error %u.\n", + GetLastError()); + } + + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + } + + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE - curDirLen); + pTemp = convert(szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + + if (bRc != FALSE) + { + RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + if (strlen(szDirName) > CREATE_MAX_PATH_SIZE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed because it created a directory" + " name 1 character longer (%d chars) than the max dir size" + " allowed\n", + strlen(szDirName)); + } + } + + free(pTemp); + + /* long directory name CREATE_MAX_PATH_SIZE + 3 chars including "..\" + (real path length <= CREATE_MAX_PATH_SIZE) */ + memset(szDirName, 0, buf_size); + memset(szDirName, 'a', CREATE_MAX_PATH_SIZE + 3 - 1 - curDirLen); + szDirName[0] = '.'; + szDirName[1] = '.'; + szDirName[2] = '\\'; + pTemp = convert(szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == FALSE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed to create a directory name more " + "than %d chars long and its real path name is less " + "than %d chars\n", + CREATE_MAX_PATH_SIZE, + CREATE_MAX_PATH_SIZE); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail(""); + } + + /* Set directory back to initial directory */ + bRc = SetCurrentDirectoryA(buffer); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " + "change the directory with error %u.\n", + GetLastError()); + } + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + } + + /* directories with dots */ + memset(szDirName, 0, 252); + sprintf_s(szDirName, _countof(szDirName), ".dotDirectory"); + pTemp = convert(szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == FALSE) + { + free(pTemp); + Fail("CreateDirectoryW: Failed to create a dot directory\n"); + } + else + { + /* Check to see if it's possible to navigate to directory */ + GetCurrentDirectoryA(curDirectory, buffer); + bSuccess = SetCurrentDirectoryA(szDirName); + if(!bSuccess) + { + Trace("CreateDirectoryW: SetCurrentDirectoryA failed to " + "navigate to the newly created directory with error " + "code %u.\n", GetLastError()); + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + Fail(""); + } + + /* Set directory back to initial directory */ + bRc = SetCurrentDirectoryA(buffer); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: SetCurrentDirectoryA failed to " + "change the directory with error %u.\n", + GetLastError()); + } + + bRc = RemoveDirectoryW(pTemp); + if(!bRc) + { + free(pTemp); + Fail("CreateDirectoryW: RemoveDirectoryW failed to " + "delete the directory with error %u.\n", + GetLastError()); + } + free(pTemp); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/CMakeLists.txt index aae4e7dc54..f8614ca5a6 100644 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createdirectoryw.c + createdirectoryw.cpp ) add_executable(paltest_createdirectoryw_test2 diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.c b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.c deleted file mode 100644 index 20fac5a879..0000000000 --- a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.c +++ /dev/null @@ -1,345 +0,0 @@ -// 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: createdirectoryw.c -** -** Purpose: Tests the PAL implementation of the CreateDirectoryW function. -** Test creating a directory in a directory path that does not exist. -** Test creating directory with trailing slashes. -** -** Depends on: -** RemoveDirectoryW. -** -** -**==========================================================================*/ - -#include - -#if WIN32 -WCHAR* szTestRootDir = NULL; -#endif - -WCHAR* szTestDir = NULL; -WCHAR* szTestSubDir = NULL; -WCHAR* szTest2SubDir = NULL; -WCHAR* szTest2SubDirWinSlash = NULL; -WCHAR* szTest2SubDirUnixSlash = NULL; - - -/* Free the memory allocated by convert(...) function*/ -static void CleanMemory(){ - -#if WIN32 - free(szTestRootDir); -#endif - - free( szTestDir); - free( szTestSubDir); - free( szTest2SubDir); - free( szTest2SubDirWinSlash); - free( szTest2SubDirUnixSlash); - -} - - -int main(int argc, char *argv[]) -{ - BOOL bRc = FALSE; - BOOL clean = TRUE; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* initialize strings */ - -#if WIN32 - szTestRootDir = convert("/at_root_directory_PALTEST"); -#endif - - szTestDir = convert("test_ directory"); - szTestSubDir = convert( - ".\\./././../test2/./../../////////createdirectoryw" - "\\\\/test2/test_ directory\\sub"); - szTest2SubDir = convert("test_ directory/sub\\sub_sub"); - szTest2SubDirWinSlash = convert("test_ directory/sub\\sub_sub\\\\"); - szTest2SubDirUnixSlash = convert("test_ directory/sub\\sub_sub///"); - - - /* Platform dependent cases:- - * test for WIN32, create directory at the root. - * using /directory_name format - */ -#if WIN32 - - bRc = CreateDirectoryW(szTestRootDir, NULL); - - if (bRc != TRUE) - { - - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTestRootDir,GetLastError()); - CleanMemory(); - Fail(""); - } - - /*clean szTestRootDir */ - bRc = RemoveDirectoryW(szTestRootDir); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestRootDir, - GetLastError()); - } - -#endif - - - /* - * create subdirectory "test_directory//sub//sub_sub" - * while parent directory does not exist. - */ - bRc = CreateDirectoryW(szTest2SubDir, NULL); - if (bRc == TRUE) - { - bRc = RemoveDirectoryW(szTest2SubDir); - - if (! bRc ) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTest2SubDir, - GetLastError()); - } - - Trace("CreateDirectoryW: Succeeded creating the directory\"%S\" while" - " its parent directory does not exists. It should fail.\n", - szTest2SubDir); - CleanMemory(); - Fail(""); - - } - - - /* create directory tree one by one - * first create "test_dir" - */ - bRc = CreateDirectoryW(szTestDir, NULL); - - - if (bRc != TRUE)/*failed creating the path*/ - { - - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", szTestDir,GetLastError()); - CleanMemory(); - Fail(""); - } - - /* create the sub directory test_directory//sub */ - bRc = CreateDirectoryW(szTestSubDir, NULL); - - if (bRc != TRUE)/*failed creating the path*/ - { - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTestSubDir , GetLastError()); - - /* cleaning... remove parent directory */ - bRc = RemoveDirectoryW(szTestDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with an error code %ld.\n", - szTestDir, - GetLastError()); - } - CleanMemory(); - Fail(""); - } - - /* - * the director structure is test_directory//sub - * test creating directory " test_directory//sub//sub_sub" - */ - bRc = CreateDirectoryW(szTest2SubDir, NULL); - if (bRc != TRUE) - { - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTest2SubDir , GetLastError()); - - /* remove parent directory test_directory//sub */ - bRc = RemoveDirectoryW(szTestSubDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /* remove parent directory test_directory */ - bRc = RemoveDirectoryW(szTestDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - CleanMemory(); - Fail(""); - - } - - /* Remove Directiry szTest2SubDir*/ - bRc = RemoveDirectoryW(szTest2SubDir); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTest2SubDir, - GetLastError()); - } - - /* - * the director structure is test_directory//sub - * test creating directory " test_directory//sub//sub_sub\\\\" - */ - bRc = CreateDirectoryW(szTest2SubDirWinSlash, NULL); - if (bRc != TRUE) - { - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTest2SubDirWinSlash , GetLastError()); - - /* remove parent directory test_directory//sub */ - bRc = RemoveDirectoryW(szTestSubDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /* remove parent directory test_directory */ - bRc = RemoveDirectoryW(szTestDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - CleanMemory(); - Fail(""); - - } - - /* Remove Directiry szTest2SubDirWinSlash */ - bRc = RemoveDirectoryW(szTest2SubDirWinSlash); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTest2SubDirWinSlash, - GetLastError()); - } - - /* - * the director structure is test_directory//sub - * test creating directory " test_directory//sub//sub_sub///" - */ - bRc = CreateDirectoryW(szTest2SubDirUnixSlash, NULL); - if (bRc != TRUE) - { - Trace("CreateDirectoryW: Failed creating the directory " - "\"%S\" with the error code %ld.\n", - szTest2SubDirUnixSlash , GetLastError()); - - /* remove parent directory test_directory//sub */ - bRc = RemoveDirectoryW(szTestSubDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /* remove parent directory test_directory */ - bRc = RemoveDirectoryW(szTestDir); - if (! bRc) - { - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - CleanMemory(); - Fail(""); - - } - - /* Remove Directiry szTest2SubDirUnixSlash.*/ - bRc = RemoveDirectoryW(szTest2SubDirUnixSlash); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTest2SubDirUnixSlash, - GetLastError()); - } - - /*clean parent szTestSubDir */ - bRc = RemoveDirectoryW(szTestSubDir); - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestSubDir, - GetLastError()); - } - - /*clean parent szTestDir */ - bRc = RemoveDirectoryW(szTestDir); - - - if (! bRc) - { - clean = bRc; - Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " - "\"%S\" with the error code %ld.\n", - szTestDir, - GetLastError()); - } - - if(! clean) - { - CleanMemory(); - Fail(""); - } - - CleanMemory(); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.cpp b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.cpp new file mode 100644 index 0000000000..20fac5a879 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateDirectoryW/test2/createdirectoryw.cpp @@ -0,0 +1,345 @@ +// 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: createdirectoryw.c +** +** Purpose: Tests the PAL implementation of the CreateDirectoryW function. +** Test creating a directory in a directory path that does not exist. +** Test creating directory with trailing slashes. +** +** Depends on: +** RemoveDirectoryW. +** +** +**==========================================================================*/ + +#include + +#if WIN32 +WCHAR* szTestRootDir = NULL; +#endif + +WCHAR* szTestDir = NULL; +WCHAR* szTestSubDir = NULL; +WCHAR* szTest2SubDir = NULL; +WCHAR* szTest2SubDirWinSlash = NULL; +WCHAR* szTest2SubDirUnixSlash = NULL; + + +/* Free the memory allocated by convert(...) function*/ +static void CleanMemory(){ + +#if WIN32 + free(szTestRootDir); +#endif + + free( szTestDir); + free( szTestSubDir); + free( szTest2SubDir); + free( szTest2SubDirWinSlash); + free( szTest2SubDirUnixSlash); + +} + + +int main(int argc, char *argv[]) +{ + BOOL bRc = FALSE; + BOOL clean = TRUE; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* initialize strings */ + +#if WIN32 + szTestRootDir = convert("/at_root_directory_PALTEST"); +#endif + + szTestDir = convert("test_ directory"); + szTestSubDir = convert( + ".\\./././../test2/./../../////////createdirectoryw" + "\\\\/test2/test_ directory\\sub"); + szTest2SubDir = convert("test_ directory/sub\\sub_sub"); + szTest2SubDirWinSlash = convert("test_ directory/sub\\sub_sub\\\\"); + szTest2SubDirUnixSlash = convert("test_ directory/sub\\sub_sub///"); + + + /* Platform dependent cases:- + * test for WIN32, create directory at the root. + * using /directory_name format + */ +#if WIN32 + + bRc = CreateDirectoryW(szTestRootDir, NULL); + + if (bRc != TRUE) + { + + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTestRootDir,GetLastError()); + CleanMemory(); + Fail(""); + } + + /*clean szTestRootDir */ + bRc = RemoveDirectoryW(szTestRootDir); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestRootDir, + GetLastError()); + } + +#endif + + + /* + * create subdirectory "test_directory//sub//sub_sub" + * while parent directory does not exist. + */ + bRc = CreateDirectoryW(szTest2SubDir, NULL); + if (bRc == TRUE) + { + bRc = RemoveDirectoryW(szTest2SubDir); + + if (! bRc ) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTest2SubDir, + GetLastError()); + } + + Trace("CreateDirectoryW: Succeeded creating the directory\"%S\" while" + " its parent directory does not exists. It should fail.\n", + szTest2SubDir); + CleanMemory(); + Fail(""); + + } + + + /* create directory tree one by one + * first create "test_dir" + */ + bRc = CreateDirectoryW(szTestDir, NULL); + + + if (bRc != TRUE)/*failed creating the path*/ + { + + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", szTestDir,GetLastError()); + CleanMemory(); + Fail(""); + } + + /* create the sub directory test_directory//sub */ + bRc = CreateDirectoryW(szTestSubDir, NULL); + + if (bRc != TRUE)/*failed creating the path*/ + { + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTestSubDir , GetLastError()); + + /* cleaning... remove parent directory */ + bRc = RemoveDirectoryW(szTestDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with an error code %ld.\n", + szTestDir, + GetLastError()); + } + CleanMemory(); + Fail(""); + } + + /* + * the director structure is test_directory//sub + * test creating directory " test_directory//sub//sub_sub" + */ + bRc = CreateDirectoryW(szTest2SubDir, NULL); + if (bRc != TRUE) + { + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTest2SubDir , GetLastError()); + + /* remove parent directory test_directory//sub */ + bRc = RemoveDirectoryW(szTestSubDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /* remove parent directory test_directory */ + bRc = RemoveDirectoryW(szTestDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + CleanMemory(); + Fail(""); + + } + + /* Remove Directiry szTest2SubDir*/ + bRc = RemoveDirectoryW(szTest2SubDir); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTest2SubDir, + GetLastError()); + } + + /* + * the director structure is test_directory//sub + * test creating directory " test_directory//sub//sub_sub\\\\" + */ + bRc = CreateDirectoryW(szTest2SubDirWinSlash, NULL); + if (bRc != TRUE) + { + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTest2SubDirWinSlash , GetLastError()); + + /* remove parent directory test_directory//sub */ + bRc = RemoveDirectoryW(szTestSubDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /* remove parent directory test_directory */ + bRc = RemoveDirectoryW(szTestDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + CleanMemory(); + Fail(""); + + } + + /* Remove Directiry szTest2SubDirWinSlash */ + bRc = RemoveDirectoryW(szTest2SubDirWinSlash); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTest2SubDirWinSlash, + GetLastError()); + } + + /* + * the director structure is test_directory//sub + * test creating directory " test_directory//sub//sub_sub///" + */ + bRc = CreateDirectoryW(szTest2SubDirUnixSlash, NULL); + if (bRc != TRUE) + { + Trace("CreateDirectoryW: Failed creating the directory " + "\"%S\" with the error code %ld.\n", + szTest2SubDirUnixSlash , GetLastError()); + + /* remove parent directory test_directory//sub */ + bRc = RemoveDirectoryW(szTestSubDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /* remove parent directory test_directory */ + bRc = RemoveDirectoryW(szTestDir); + if (! bRc) + { + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + CleanMemory(); + Fail(""); + + } + + /* Remove Directiry szTest2SubDirUnixSlash.*/ + bRc = RemoveDirectoryW(szTest2SubDirUnixSlash); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTest2SubDirUnixSlash, + GetLastError()); + } + + /*clean parent szTestSubDir */ + bRc = RemoveDirectoryW(szTestSubDir); + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestSubDir, + GetLastError()); + } + + /*clean parent szTestDir */ + bRc = RemoveDirectoryW(szTestDir); + + + if (! bRc) + { + clean = bRc; + Trace("CreateDirectoryW: RemoveDirectoryW failed to remove " + "\"%S\" with the error code %ld.\n", + szTestDir, + GetLastError()); + } + + if(! clean) + { + CleanMemory(); + Fail(""); + } + + CleanMemory(); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/CreateFileA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CreateFileA/test1/CMakeLists.txt index 8814b2281b..edacdbd621 100644 --- a/src/pal/tests/palsuite/file_io/CreateFileA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CreateFileA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileA.c + CreateFileA.cpp ) add_executable(paltest_createfilea_test1 diff --git a/src/pal/tests/palsuite/file_io/CreateFileA/test1/CreateFileA.c b/src/pal/tests/palsuite/file_io/CreateFileA/test1/CreateFileA.c deleted file mode 100644 index a70867a5c8..0000000000 --- a/src/pal/tests/palsuite/file_io/CreateFileA/test1/CreateFileA.c +++ /dev/null @@ -1,145 +0,0 @@ -// 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: CreateFileA.c -** -** Purpose: Test the PAL implementation of the CreateFileA function -** -** -**===================================================================*/ - -#include - -BOOL Cleanup(void) -{ - char FileName[20]; - int i; - BOOL bRet = TRUE; // assume success - - // loop through all accesses, modes, dispositions and flags - for (i=0; i<4*8*4*5; ++i) { - sprintf(FileName, "test%03d.txt", i); - if (DeleteFileA(FileName) == FALSE) { - if (GetLastError() != ERROR_FILE_NOT_FOUND) { - bRet = FALSE; - } - } - } - return bRet; -} - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bSuccess = TRUE; - int nCounter = 0; - HANDLE hFile; - char lpFileName[20]; - 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); - nCounter = (int)strlen(results); - 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(lpFileName, "test%03d.txt", nCounter); - hFile = CreateFile(lpFileName, - dwDesiredAccess[i], - dwShareMode[j], - lpAttr, - dwCreationDisp[k], - dwFlagsAttrib[l], - hTemplate); - if (hFile == INVALID_HANDLE_VALUE) - { - if (results[nCounter] == '1') - { - Trace("CreateFile: ERROR: Failed when expected " - "to pass %s [%d][%d][%d][%d]\n", - lpFileName, i, j, k, l); - bSuccess = FALSE; - } - } - else - { - CloseHandle(hFile); - if (results[nCounter] == '0') - { - Trace("CreateFile: ERROR: Passed when expected " - "to fail %s [%d][%d][%d][%d]\n", - lpFileName, i, j, k, l); - bSuccess = FALSE; - } - } - nCounter ++; - } - } - } - } - - if (!Cleanup()) - { - Trace("Post-test Cleanup() failed. LastError=%d\n", GetLastError()); - return FAIL; - } - - int exitCode = bSuccess ? PASS : FAIL; - PAL_TerminateEx(exitCode); - return exitCode; -} diff --git a/src/pal/tests/palsuite/file_io/CreateFileA/test1/CreateFileA.cpp b/src/pal/tests/palsuite/file_io/CreateFileA/test1/CreateFileA.cpp new file mode 100644 index 0000000000..f98fc5b9c5 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateFileA/test1/CreateFileA.cpp @@ -0,0 +1,145 @@ +// 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: CreateFileA.c +** +** Purpose: Test the PAL implementation of the CreateFileA function +** +** +**===================================================================*/ + +#include + +BOOL Cleanup(void) +{ + char FileName[20]; + int i; + BOOL bRet = TRUE; // assume success + + // loop through all accesses, modes, dispositions and flags + for (i=0; i<4*8*4*5; ++i) { + sprintf_s(FileName, _countof(FileName), "test%03d.txt", i); + if (DeleteFileA(FileName) == FALSE) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) { + bRet = FALSE; + } + } + } + return bRet; +} + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bSuccess = TRUE; + int nCounter = 0; + HANDLE hFile; + char lpFileName[20]; + 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); + nCounter = (int)strlen(results); + 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_s(lpFileName, _countof(lpFileName), "test%03d.txt", nCounter); + hFile = CreateFile(lpFileName, + dwDesiredAccess[i], + dwShareMode[j], + lpAttr, + dwCreationDisp[k], + dwFlagsAttrib[l], + hTemplate); + if (hFile == INVALID_HANDLE_VALUE) + { + if (results[nCounter] == '1') + { + Trace("CreateFile: ERROR: Failed when expected " + "to pass %s [%d][%d][%d][%d]\n", + lpFileName, i, j, k, l); + bSuccess = FALSE; + } + } + else + { + CloseHandle(hFile); + if (results[nCounter] == '0') + { + Trace("CreateFile: ERROR: Passed when expected " + "to fail %s [%d][%d][%d][%d]\n", + lpFileName, i, j, k, l); + bSuccess = FALSE; + } + } + nCounter ++; + } + } + } + } + + if (!Cleanup()) + { + Trace("Post-test Cleanup() failed. LastError=%d\n", GetLastError()); + return FAIL; + } + + int exitCode = bSuccess ? PASS : FAIL; + PAL_TerminateEx(exitCode); + return exitCode; +} diff --git a/src/pal/tests/palsuite/file_io/CreateFileW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CreateFileW/test1/CMakeLists.txt index 1ff0b8062f..820e169a37 100644 --- a/src/pal/tests/palsuite/file_io/CreateFileW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/CreateFileW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileW.c + CreateFileW.cpp ) add_executable(paltest_createfilew_test1 diff --git a/src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.c b/src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.c deleted file mode 100644 index 4d7d20af29..0000000000 --- a/src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.c +++ /dev/null @@ -1,152 +0,0 @@ -// 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: CreateFileW.c -** -** Purpose: Test the PAL implementation of the CreateFileW function -** -** -**===================================================================*/ - -#include - -BOOL Cleanup(void) -{ - char FileName[20]; - int i; - BOOL bRet = TRUE; // assume success - - // loop through all accesses, modes, dispositions and flags - for (i=0; i<4*8*4*5; ++i) { - sprintf(FileName, "test%03d.txt", i); - if (DeleteFileA(FileName) == FALSE) { - if (GetLastError() != ERROR_FILE_NOT_FOUND) { - bRet = FALSE; - } - } - } - return bRet; -} - - -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; - } - - int exitCode = bSuccess ? PASS : FAIL; - PAL_TerminateEx(exitCode); - return exitCode; -} diff --git a/src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.cpp b/src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.cpp new file mode 100644 index 0000000000..0619f5b4aa --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.cpp @@ -0,0 +1,152 @@ +// 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: CreateFileW.c +** +** Purpose: Test the PAL implementation of the CreateFileW function +** +** +**===================================================================*/ + +#include + +BOOL Cleanup(void) +{ + char FileName[20]; + int i; + BOOL bRet = TRUE; // assume success + + // loop through all accesses, modes, dispositions and flags + for (i=0; i<4*8*4*5; ++i) { + sprintf_s(FileName, _countof(FileName), "test%03d.txt", i); + if (DeleteFileA(FileName) == FALSE) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) { + bRet = FALSE; + } + } + } + return bRet; +} + + +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_s(string, _countof(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; + } + + int exitCode = bSuccess ? PASS : FAIL; + PAL_TerminateEx(exitCode); + return exitCode; +} diff --git a/src/pal/tests/palsuite/file_io/DeleteFileW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/DeleteFileW/test1/CMakeLists.txt index 046fd35148..eada6145b9 100644 --- a/src/pal/tests/palsuite/file_io/DeleteFileW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/DeleteFileW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - DeleteFileW.c + DeleteFileW.cpp ) add_executable(paltest_deletefilew_test1 diff --git a/src/pal/tests/palsuite/file_io/DeleteFileW/test1/DeleteFileW.c b/src/pal/tests/palsuite/file_io/DeleteFileW/test1/DeleteFileW.c deleted file mode 100644 index fca96d1e00..0000000000 --- a/src/pal/tests/palsuite/file_io/DeleteFileW/test1/DeleteFileW.c +++ /dev/null @@ -1,164 +0,0 @@ -// 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: DeleteFileW.c -** -** Purpose: Tests the PAL implementation of the DeleteFileW function. -** -** -**===================================================================*/ - -// delete an existing file -// delete a non-existant file -// delete an open file -// delete files using wild cards -// delete a hidden file -// delete a file without proper permissions -// - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - FILE *tempFile = NULL; - BOOL bRc = FALSE; - WCHAR* pTemp = NULL; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // - // deleting an existing file - // - tempFile = fopen("testFile01.tmp", "w"); - if (tempFile == NULL) - { - Fail ("DeleteFileW: ERROR: Couldn't create \"DeleteFileW's" - " testFile01.tmp\"\n"); - } - - fprintf(tempFile, "DeleteFileW test file.\n"); - if (fclose(tempFile) != 0) - { - Fail ("DeleteFileA: ERROR: Couldn't close \"DeleteFileW's" - " testFile01.tmp\"\n"); - } - - pTemp = convert("testFile01.tmp"); - bRc = DeleteFileW(pTemp); - free(pTemp); - if (bRc != TRUE) - { - Fail ("DeleteFileW: ERROR: Couldn't delete DeleteFileW's" - " \"testFile01.tmp\"\n" - " Error is %d\n", GetLastError()); - } - - - // - // deleting a non-existant file : should fail - // - - pTemp = convert("testFile02.tmp"); - bRc = DeleteFileW(pTemp); - free(pTemp); - if (bRc != FALSE) - { - Fail ("DeleteFileW: ERROR: Was able to delete the non-existant" - " file \"testFile02.tmp\"\n"); - } - - - - - // - // deleting an open file - // - tempFile = fopen("testFile03.tmp", "w"); - if (tempFile == NULL) - { - Fail("DeleteFileW: ERROR: Couldn't create \"DeleteFileW's" - " testFile03.tmp\"\n"); - } - - fprintf(tempFile, "DeleteFileW test file.\n"); - if (fclose(tempFile) != 0) - { - Fail ("DeleteFileA: ERROR: Couldn't close \"DeleteFileW's" - " testFile03.tmp\"\n"); - } - - pTemp = convert("testFile03.tmp"); - bRc = DeleteFileW(pTemp); - if (bRc != TRUE) - { - Fail("DeleteFileW: ERROR: Couldn't delete DeleteFileW's" - " \"testFile03.tmp\"\n" - " Error is %d\n", GetLastError()); - free(pTemp); - } - bRc = DeleteFileW(pTemp); - free(pTemp); - - - - - // - // delete using wild cards - // - - // create the test file - tempFile = fopen("testFile04.tmp", "w"); - if (tempFile == NULL) - { - Fail("DeleteFileW: ERROR: Couldn't create DeleteFileW's" - " \"testFile04.tmp\"\n"); - } - fprintf(tempFile, "DeleteFileW test file.\n"); - if (fclose(tempFile) != 0) - { - Fail ("DeleteFileA: ERROR: Couldn't close \"DeleteFileW's" - " testFile04.tmp\"\n"); - } - - // delete using '?' - pTemp = convert("testFile0?.tmp"); - bRc = DeleteFileW(pTemp); - free(pTemp); - if (bRc == TRUE) - { - Fail("DeleteFileW: ERROR: Was able to delete using the" - " \'?\' wildcard\n"); - } - - // delete using '*' - pTemp = convert("testFile*.tmp"); - bRc = DeleteFileW(pTemp); - free(pTemp); - if (bRc == TRUE) - { - Fail("DeleteFileW: ERROR: Was able to delete using the" - " \'*\' wildcard\n"); - } - - pTemp = convert("testFile04.tmp"); - bRc = DeleteFileW(pTemp); - free(pTemp); - if (bRc != TRUE) - { - Fail ("DeleteFileW: ERROR: Couldn't delete DeleteFileW's" - " \"testFile04.tmp\"\n" - " Error is %d\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/DeleteFileW/test1/DeleteFileW.cpp b/src/pal/tests/palsuite/file_io/DeleteFileW/test1/DeleteFileW.cpp new file mode 100644 index 0000000000..fca96d1e00 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/DeleteFileW/test1/DeleteFileW.cpp @@ -0,0 +1,164 @@ +// 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: DeleteFileW.c +** +** Purpose: Tests the PAL implementation of the DeleteFileW function. +** +** +**===================================================================*/ + +// delete an existing file +// delete a non-existant file +// delete an open file +// delete files using wild cards +// delete a hidden file +// delete a file without proper permissions +// + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + FILE *tempFile = NULL; + BOOL bRc = FALSE; + WCHAR* pTemp = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // + // deleting an existing file + // + tempFile = fopen("testFile01.tmp", "w"); + if (tempFile == NULL) + { + Fail ("DeleteFileW: ERROR: Couldn't create \"DeleteFileW's" + " testFile01.tmp\"\n"); + } + + fprintf(tempFile, "DeleteFileW test file.\n"); + if (fclose(tempFile) != 0) + { + Fail ("DeleteFileA: ERROR: Couldn't close \"DeleteFileW's" + " testFile01.tmp\"\n"); + } + + pTemp = convert("testFile01.tmp"); + bRc = DeleteFileW(pTemp); + free(pTemp); + if (bRc != TRUE) + { + Fail ("DeleteFileW: ERROR: Couldn't delete DeleteFileW's" + " \"testFile01.tmp\"\n" + " Error is %d\n", GetLastError()); + } + + + // + // deleting a non-existant file : should fail + // + + pTemp = convert("testFile02.tmp"); + bRc = DeleteFileW(pTemp); + free(pTemp); + if (bRc != FALSE) + { + Fail ("DeleteFileW: ERROR: Was able to delete the non-existant" + " file \"testFile02.tmp\"\n"); + } + + + + + // + // deleting an open file + // + tempFile = fopen("testFile03.tmp", "w"); + if (tempFile == NULL) + { + Fail("DeleteFileW: ERROR: Couldn't create \"DeleteFileW's" + " testFile03.tmp\"\n"); + } + + fprintf(tempFile, "DeleteFileW test file.\n"); + if (fclose(tempFile) != 0) + { + Fail ("DeleteFileA: ERROR: Couldn't close \"DeleteFileW's" + " testFile03.tmp\"\n"); + } + + pTemp = convert("testFile03.tmp"); + bRc = DeleteFileW(pTemp); + if (bRc != TRUE) + { + Fail("DeleteFileW: ERROR: Couldn't delete DeleteFileW's" + " \"testFile03.tmp\"\n" + " Error is %d\n", GetLastError()); + free(pTemp); + } + bRc = DeleteFileW(pTemp); + free(pTemp); + + + + + // + // delete using wild cards + // + + // create the test file + tempFile = fopen("testFile04.tmp", "w"); + if (tempFile == NULL) + { + Fail("DeleteFileW: ERROR: Couldn't create DeleteFileW's" + " \"testFile04.tmp\"\n"); + } + fprintf(tempFile, "DeleteFileW test file.\n"); + if (fclose(tempFile) != 0) + { + Fail ("DeleteFileA: ERROR: Couldn't close \"DeleteFileW's" + " testFile04.tmp\"\n"); + } + + // delete using '?' + pTemp = convert("testFile0?.tmp"); + bRc = DeleteFileW(pTemp); + free(pTemp); + if (bRc == TRUE) + { + Fail("DeleteFileW: ERROR: Was able to delete using the" + " \'?\' wildcard\n"); + } + + // delete using '*' + pTemp = convert("testFile*.tmp"); + bRc = DeleteFileW(pTemp); + free(pTemp); + if (bRc == TRUE) + { + Fail("DeleteFileW: ERROR: Was able to delete using the" + " \'*\' wildcard\n"); + } + + pTemp = convert("testFile04.tmp"); + bRc = DeleteFileW(pTemp); + free(pTemp); + if (bRc != TRUE) + { + Fail ("DeleteFileW: ERROR: Couldn't delete DeleteFileW's" + " \"testFile04.tmp\"\n" + " Error is %d\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/FILECanonicalizePath/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FILECanonicalizePath/CMakeLists.txt index 0c02c98f15..7045983629 100644 --- a/src/pal/tests/palsuite/file_io/FILECanonicalizePath/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/FILECanonicalizePath/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - FILECanonicalizePath.c + FILECanonicalizePath.cpp ) add_executable(paltest_filecanonicalizepath_test1 diff --git a/src/pal/tests/palsuite/file_io/FILECanonicalizePath/FILECanonicalizePath.c b/src/pal/tests/palsuite/file_io/FILECanonicalizePath/FILECanonicalizePath.c deleted file mode 100644 index 91bac1f3cb..0000000000 --- a/src/pal/tests/palsuite/file_io/FILECanonicalizePath/FILECanonicalizePath.c +++ /dev/null @@ -1,83 +0,0 @@ -// 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: FILECanonicalizePath.c (test 1) -** -** Purpose: Tests the PAL implementation of the FILECanonicalizePath function. -** -** -**===================================================================*/ - -#include - -extern void FILECanonicalizePath(LPSTR lpUnixPath); - -void TestCase(LPSTR input, LPSTR expectedOutput); - -int __cdecl main(int argc, char *argv[]) -{ - if (PAL_Initialize(argc,argv) != 0) - { - return FAIL; - } - - // Case 01: / should not change - TestCase("/Test", "/Test"); - - // Case 02: // should not change - TestCase("/Test/Foo", "/Test/Foo"); - - // Case 03: // transforms to / - TestCase("//", "/"); - - // Case 04: /./ transforms to / - TestCase("/./", "/"); - - // Case 05: //../ transforms to / - TestCase("/Test/../", "/"); - - // Case 06: /Test/Foo/.. transforms to /Test - TestCase("/Test/Foo/..", "/Test"); - - // Case 07: /Test/.. transforms to / - TestCase("/Test/..", "/"); - - // Case 08: /. transforms to / - TestCase("/.", "/"); - - // Case 09: / - TestCase("/Test/.", "/Test"); - - // Case 10: //../. transforms to / - TestCase("/Test/../.", "/"); - - // Case 11: /.. transforms to / - TestCase("/..", "/"); - - PAL_Terminate(); - return PASS; -} - -void TestCase(LPSTR input, LPSTR expectedOutput) -{ - // Save the input for debug logging since the input is edited in-place - char* pOriginalInput = (char*)malloc(strlen(input) * sizeof(char) + 1); - strcpy(pOriginalInput, input); - - char* pInput = (char*)malloc(strlen(input) * sizeof(char) + 1); - strcpy(pInput, pOriginalInput); - - FILECanonicalizePath(pInput); - if (strcmp(pInput, expectedOutput) != 0) - { - free(pOriginalInput); - free(pInput); - Fail("FILECanonicalizePath error: input %s did not match expected output %s; got %s instead", pOriginalInput, expectedOutput, pInput); - } - - free(pOriginalInput); - free(pInput); -} diff --git a/src/pal/tests/palsuite/file_io/FILECanonicalizePath/FILECanonicalizePath.cpp b/src/pal/tests/palsuite/file_io/FILECanonicalizePath/FILECanonicalizePath.cpp new file mode 100644 index 0000000000..3a1758aa3b --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FILECanonicalizePath/FILECanonicalizePath.cpp @@ -0,0 +1,83 @@ +// 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: FILECanonicalizePath.c (test 1) +** +** Purpose: Tests the PAL implementation of the FILECanonicalizePath function. +** +** +**===================================================================*/ + +#include + +extern "C" void FILECanonicalizePath(LPSTR lpUnixPath); + +void TestCase(LPSTR input, LPSTR expectedOutput); + +int __cdecl main(int argc, char *argv[]) +{ + if (PAL_Initialize(argc,argv) != 0) + { + return FAIL; + } + + // Case 01: / should not change + TestCase("/Test", "/Test"); + + // Case 02: // should not change + TestCase("/Test/Foo", "/Test/Foo"); + + // Case 03: // transforms to / + TestCase("//", "/"); + + // Case 04: /./ transforms to / + TestCase("/./", "/"); + + // Case 05: //../ transforms to / + TestCase("/Test/../", "/"); + + // Case 06: /Test/Foo/.. transforms to /Test + TestCase("/Test/Foo/..", "/Test"); + + // Case 07: /Test/.. transforms to / + TestCase("/Test/..", "/"); + + // Case 08: /. transforms to / + TestCase("/.", "/"); + + // Case 09: / + TestCase("/Test/.", "/Test"); + + // Case 10: //../. transforms to / + TestCase("/Test/../.", "/"); + + // Case 11: /.. transforms to / + TestCase("/..", "/"); + + PAL_Terminate(); + return PASS; +} + +void TestCase(LPSTR input, LPSTR expectedOutput) +{ + // Save the input for debug logging since the input is edited in-place + char* pOriginalInput = (char*)malloc(strlen(input) * sizeof(char) + 1); + strcpy(pOriginalInput, input); + + char* pInput = (char*)malloc(strlen(input) * sizeof(char) + 1); + strcpy(pInput, pOriginalInput); + + FILECanonicalizePath(pInput); + if (strcmp(pInput, expectedOutput) != 0) + { + free(pOriginalInput); + free(pInput); + Fail("FILECanonicalizePath error: input %s did not match expected output %s; got %s instead", pOriginalInput, expectedOutput, pInput); + } + + free(pOriginalInput); + free(pInput); +} diff --git a/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/CMakeLists.txt index 131054266b..6ec6a98b3f 100644 --- a/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_filetimetodosdatetime_test1 diff --git a/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/test1.c b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/test1.c deleted file mode 100644 index 5f2c81ff98..0000000000 --- a/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/test1.c +++ /dev/null @@ -1,116 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that FileTimeToDosDateTime successfully converts values. -** Makes sure values are rounded up, and the limits of the function -** pass. Also tests that values outside the valid range fail. -** -** -**===================================================================*/ - -#include - -typedef struct -{ - DWORD FileTimeLow; - DWORD FileTimeHigh; - WORD FatDate; - WORD FatTime; -} testCase; - -int __cdecl main(int argc, char **argv) -{ - FILETIME FileTime; - WORD ResultDate; - WORD ResultTime; - BOOL ret; - int i; - - testCase testCases[] = - { - /* Test a normal time */ - {0x9BE00100, 0x1B4A02C, 0x14CF, 0x55AF}, /* 12/15/2000, 10:45:30 AM*/ - /* Test that 12/15/2000, 10:45:29 Gets rounded up */ - {0x9B476A80, 0x1B4A02C, 0x14CF, 0x55AF}, /* 12/15/2000, 10:45:30 AM*/ - /* Test that 12/15/2000, 10:45:31 Gets rounded up */ - {0x9C789780, 0x1B4A02C, 0x14CF, 0x55B0}, /* 12/15/2000, 10:45:32 AM*/ - - /* Test the upper and lower limits of the function */ - {0xE1D58000, 0x1A8E79F, 0x0021, 0x0000}, /* 1/1/1980, 12:00:00 AM*/ - {0xb9de1300, 0x1e9eede, 0x739f, 0xbf7d}, /* 12/31/2037, 11:59:58 PM*/ - - /* Tests that should fail */ - {0, 0, 0, 0}, - {0xE0A45300, 0x1A8E79F, 0, 0}, - {0x66D29301, 0x23868B8, 0, 0} - - /* All this accomplishes is for the date to overflow. - Likely the only reason it fails in Windows is bacause the - resulting date falls outside of the legal range. Under BSD, - it falls into a legal range. This being that BSD calculates time - from 1900 to 2037, not 1980 to 2107. - {0xFFFFFFFF, 0xFFFFFFF, 0, 0} - */ - }; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - for (i=0; i + +typedef struct +{ + DWORD FileTimeLow; + DWORD FileTimeHigh; + WORD FatDate; + WORD FatTime; +} testCase; + +int __cdecl main(int argc, char **argv) +{ + FILETIME FileTime; + WORD ResultDate; + WORD ResultTime; + BOOL ret; + int i; + + testCase testCases[] = + { + /* Test a normal time */ + {0x9BE00100, 0x1B4A02C, 0x14CF, 0x55AF}, /* 12/15/2000, 10:45:30 AM*/ + /* Test that 12/15/2000, 10:45:29 Gets rounded up */ + {0x9B476A80, 0x1B4A02C, 0x14CF, 0x55AF}, /* 12/15/2000, 10:45:30 AM*/ + /* Test that 12/15/2000, 10:45:31 Gets rounded up */ + {0x9C789780, 0x1B4A02C, 0x14CF, 0x55B0}, /* 12/15/2000, 10:45:32 AM*/ + + /* Test the upper and lower limits of the function */ + {0xE1D58000, 0x1A8E79F, 0x0021, 0x0000}, /* 1/1/1980, 12:00:00 AM*/ + {0xb9de1300, 0x1e9eede, 0x739f, 0xbf7d}, /* 12/31/2037, 11:59:58 PM*/ + + /* Tests that should fail */ + {0, 0, 0, 0}, + {0xE0A45300, 0x1A8E79F, 0, 0}, + {0x66D29301, 0x23868B8, 0, 0} + + /* All this accomplishes is for the date to overflow. + Likely the only reason it fails in Windows is bacause the + resulting date falls outside of the legal range. Under BSD, + it falls into a legal range. This being that BSD calculates time + from 1900 to 2037, not 1980 to 2107. + {0xFFFFFFFF, 0xFFFFFFF, 0, 0} + */ + }; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + for (i=0; i - - - -const WCHAR szFindName[] = {'t','e', 's', 't', '0', '1', '.', 't', 'x', 't', '\0'}; -const WCHAR szFindName_02[] = {'t','e', 's', 't', '0', '2', '.', 't', 'x', 't', '\0'}; -const WCHAR szFindName_03[] = {'t','e', 's', 't', '0', '3', '.', 't', 'x', 't', '\0'}; -const WCHAR szFindNameWldCard_01[] = {'t','e', 's', 't', '0', '?', '.', 't', 'x', 't', '\0'}; -const WCHAR szFindNameWldCard_02[] = {'*', '.', 't', 'x', 't', '\0'}; -const WCHAR szDirName[] = {'t','e', 's', 't', '_', 'd', 'i', 'r', '\0'}; -const WCHAR szDirName_02[] = {'t','e', 's', 't', '_', 'd', 'i', 'r', '0', '2', '\0'}; -const WCHAR szDirNameWldCard[] = {'t','e', 's', 't', '_', '*', '\0'}; - - - -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; -} - - -void removeAll() -{ - RemoveDirectoryW(szDirName); - RemoveDirectoryW(szDirName_02); - - DeleteFileW(szFindName); - DeleteFileW(szFindName_02); - DeleteFileW(szFindName_03); -} - - -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; -} - diff --git a/src/pal/tests/palsuite/file_io/FindClose/test1/FindClose.cpp b/src/pal/tests/palsuite/file_io/FindClose/test1/FindClose.cpp new file mode 100644 index 0000000000..3d53806e48 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindClose/test1/FindClose.cpp @@ -0,0 +1,275 @@ +// 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: FindClose.c +** +** Purpose: Tests the PAL implementation of the FindClose function. +** +** +**===================================================================*/ + + +#include + + + +const WCHAR szFindName[] = {'t','e', 's', 't', '0', '1', '.', 't', 'x', 't', '\0'}; +const WCHAR szFindName_02[] = {'t','e', 's', 't', '0', '2', '.', 't', 'x', 't', '\0'}; +const WCHAR szFindName_03[] = {'t','e', 's', 't', '0', '3', '.', 't', 'x', 't', '\0'}; +const WCHAR szFindNameWldCard_01[] = {'t','e', 's', 't', '0', '?', '.', 't', 'x', 't', '\0'}; +const WCHAR szFindNameWldCard_02[] = {'*', '.', 't', 'x', 't', '\0'}; +const WCHAR szDirName[] = {'t','e', 's', 't', '_', 'd', 'i', 'r', '\0'}; +const WCHAR szDirName_02[] = {'t','e', 's', 't', '_', 'd', 'i', 'r', '0', '2', '\0'}; +const WCHAR szDirNameWldCard[] = {'t','e', 's', 't', '_', '*', '\0'}; + + + +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; +} + + +void removeAll() +{ + RemoveDirectoryW(szDirName); + RemoveDirectoryW(szDirName_02); + + DeleteFileW(szFindName); + DeleteFileW(szFindName_02); + DeleteFileW(szFindName_03); +} + + +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; +} + diff --git a/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/CMakeLists.txt index 6613c4d444..aeac94d42f 100644 --- a/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - FindFirstFileA.c + FindFirstFileA.cpp ) add_executable(paltest_findfirstfilea_test1 diff --git a/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/FindFirstFileA.c b/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/FindFirstFileA.c deleted file mode 100644 index 6ceb6a9747..0000000000 --- a/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/FindFirstFileA.c +++ /dev/null @@ -1,206 +0,0 @@ -// 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: FindFirstFileA.c -** -** Purpose: Tests the PAL implementation of the FindFirstFileA function. -** -** -**===================================================================*/ - - -#include - - -const char* szNoFileName = "333asdf.x77t"; -const char* szFindName = "test01.txt"; -const char* szFindNameWldCard_01 = "test0?.txt"; -const char* szFindNameWldCard_02 = "*.txt"; -const char* szDirName = "test_dir"; -const char* szDirNameSlash = "test_dir\\"; -const char* szDirNameWldCard_01 = "?est_dir"; -const char* szDirNameWldCard_02 = "test_*"; -/* Longer than MAX_LONGPATH characters */ -char szLongFindName[MAX_LONGPATH+1]; - -BOOL CleanUp() -{ - DWORD dwAtt; - BOOL result = TRUE; - - dwAtt = GetFileAttributesA(szFindName); - if( dwAtt != INVALID_FILE_ATTRIBUTES ) - { - if(!SetFileAttributesA (szFindName, FILE_ATTRIBUTE_NORMAL)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL); - } - if(!DeleteFileA (szFindName)) - { - result = FALSE; - Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt); - } - } - - dwAtt = GetFileAttributesA(szDirName); - if( dwAtt != INVALID_FILE_ATTRIBUTES ) - { - if(!RemoveDirectoryA (szDirName)) - { - result = FALSE; - Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt); - } - } - - return result; -} - -int __cdecl main(int argc, char *argv[]) -{ - WIN32_FIND_DATA findFileData; - HANDLE hFind = NULL; - FILE *pFile = NULL; - BOOL bRc = FALSE; - WCHAR* szwTemp = NULL; - - memset(szLongFindName, 'a', MAX_LONGPATH+1); - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - if(!CleanUp()) - { - Fail("FindFirstFileW: ERROR : Initial Clean Up failed\n"); - } - - // - // find a file with a NULL pointer - // - hFind = FindFirstFileA(NULL, &findFileData); - if (hFind != INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileA: ERROR -> Found invalid NULL file"); - } - - - // - // find a file that doesn't exist - // - hFind = FindFirstFileA(szNoFileName, &findFileData); - if (hFind != INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileA: ERROR -> Found invalid NULL file"); - } - - - // - // find a file that exists - // - pFile = fopen(szFindName, "w"); - if (pFile == NULL) - { - Fail("FindFirstFileA: ERROR -> Unable to create a test file\n"); - } - else - { - fclose(pFile); - } - hFind = FindFirstFileA(szFindName, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szFindName); - } - else - { - // validate we found the correct file - if (strcmp(szFindName, findFileData.cFileName) != 0) - { - Fail ("FindFirstFileA: ERROR -> Found the wrong file\n"); - } - } - - - // - // find a directory that exists - // - szwTemp = convert((LPSTR)szDirName); - bRc = CreateDirectoryW(szwTemp, NULL); - free(szwTemp); - if (bRc == FALSE) - { - Fail("FindFirstFileA: ERROR -> Failed to create the directory " - "\"%s\"\n", - szDirName); - } - - hFind = FindFirstFileA(szDirName, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileA: ERROR. Unable to find \"%s\"\n", szDirName); - } - else - { - // validate we found the correct directory - if (strcmp(szDirName, findFileData.cFileName) != 0) - { - Fail ("FindFirstFileA: ERROR -> Found the wrong directory\n"); - } - } - - - // - // find a directory using a trailing '\' on the directory name: should fail - // - hFind = FindFirstFileA(szDirNameSlash, &findFileData); - if (hFind != INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileA: ERROR -> Able to find \"%s\": trailing " - "slash should have failed.\n", - szDirNameSlash); - } - - // find a file using wild cards - hFind = FindFirstFileA(szFindNameWldCard_01, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", - szFindNameWldCard_01); - } - - hFind = FindFirstFileA(szFindNameWldCard_02, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szFindNameWldCard_02); - } - - - // - // find a directory using wild cards - // - hFind = FindFirstFileA(szDirNameWldCard_01, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szDirNameWldCard_01); - } - - hFind = FindFirstFileA(szDirNameWldCard_02, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szDirNameWldCard_02); - } - - if(!CleanUp()) - { - Fail("FindFirstFileW: ERROR : Final Clean Up failed\n"); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/FindFirstFileA.cpp b/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/FindFirstFileA.cpp new file mode 100644 index 0000000000..6ceb6a9747 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindFirstFileA/test1/FindFirstFileA.cpp @@ -0,0 +1,206 @@ +// 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: FindFirstFileA.c +** +** Purpose: Tests the PAL implementation of the FindFirstFileA function. +** +** +**===================================================================*/ + + +#include + + +const char* szNoFileName = "333asdf.x77t"; +const char* szFindName = "test01.txt"; +const char* szFindNameWldCard_01 = "test0?.txt"; +const char* szFindNameWldCard_02 = "*.txt"; +const char* szDirName = "test_dir"; +const char* szDirNameSlash = "test_dir\\"; +const char* szDirNameWldCard_01 = "?est_dir"; +const char* szDirNameWldCard_02 = "test_*"; +/* Longer than MAX_LONGPATH characters */ +char szLongFindName[MAX_LONGPATH+1]; + +BOOL CleanUp() +{ + DWORD dwAtt; + BOOL result = TRUE; + + dwAtt = GetFileAttributesA(szFindName); + if( dwAtt != INVALID_FILE_ATTRIBUTES ) + { + if(!SetFileAttributesA (szFindName, FILE_ATTRIBUTE_NORMAL)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL); + } + if(!DeleteFileA (szFindName)) + { + result = FALSE; + Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt); + } + } + + dwAtt = GetFileAttributesA(szDirName); + if( dwAtt != INVALID_FILE_ATTRIBUTES ) + { + if(!RemoveDirectoryA (szDirName)) + { + result = FALSE; + Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt); + } + } + + return result; +} + +int __cdecl main(int argc, char *argv[]) +{ + WIN32_FIND_DATA findFileData; + HANDLE hFind = NULL; + FILE *pFile = NULL; + BOOL bRc = FALSE; + WCHAR* szwTemp = NULL; + + memset(szLongFindName, 'a', MAX_LONGPATH+1); + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + if(!CleanUp()) + { + Fail("FindFirstFileW: ERROR : Initial Clean Up failed\n"); + } + + // + // find a file with a NULL pointer + // + hFind = FindFirstFileA(NULL, &findFileData); + if (hFind != INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileA: ERROR -> Found invalid NULL file"); + } + + + // + // find a file that doesn't exist + // + hFind = FindFirstFileA(szNoFileName, &findFileData); + if (hFind != INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileA: ERROR -> Found invalid NULL file"); + } + + + // + // find a file that exists + // + pFile = fopen(szFindName, "w"); + if (pFile == NULL) + { + Fail("FindFirstFileA: ERROR -> Unable to create a test file\n"); + } + else + { + fclose(pFile); + } + hFind = FindFirstFileA(szFindName, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szFindName); + } + else + { + // validate we found the correct file + if (strcmp(szFindName, findFileData.cFileName) != 0) + { + Fail ("FindFirstFileA: ERROR -> Found the wrong file\n"); + } + } + + + // + // find a directory that exists + // + szwTemp = convert((LPSTR)szDirName); + bRc = CreateDirectoryW(szwTemp, NULL); + free(szwTemp); + if (bRc == FALSE) + { + Fail("FindFirstFileA: ERROR -> Failed to create the directory " + "\"%s\"\n", + szDirName); + } + + hFind = FindFirstFileA(szDirName, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileA: ERROR. Unable to find \"%s\"\n", szDirName); + } + else + { + // validate we found the correct directory + if (strcmp(szDirName, findFileData.cFileName) != 0) + { + Fail ("FindFirstFileA: ERROR -> Found the wrong directory\n"); + } + } + + + // + // find a directory using a trailing '\' on the directory name: should fail + // + hFind = FindFirstFileA(szDirNameSlash, &findFileData); + if (hFind != INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileA: ERROR -> Able to find \"%s\": trailing " + "slash should have failed.\n", + szDirNameSlash); + } + + // find a file using wild cards + hFind = FindFirstFileA(szFindNameWldCard_01, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", + szFindNameWldCard_01); + } + + hFind = FindFirstFileA(szFindNameWldCard_02, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szFindNameWldCard_02); + } + + + // + // find a directory using wild cards + // + hFind = FindFirstFileA(szDirNameWldCard_01, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szDirNameWldCard_01); + } + + hFind = FindFirstFileA(szDirNameWldCard_02, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileA: ERROR -> Unable to find \"%s\"\n", szDirNameWldCard_02); + } + + if(!CleanUp()) + { + Fail("FindFirstFileW: ERROR : Final Clean Up failed\n"); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/CMakeLists.txt index 23e95c7dad..2a6ea2b7a4 100644 --- a/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - FindFirstFileW.c + FindFirstFileW.cpp ) add_executable(paltest_findfirstfilew_test1 diff --git a/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/FindFirstFileW.c b/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/FindFirstFileW.c deleted file mode 100644 index f69a625976..0000000000 --- a/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/FindFirstFileW.c +++ /dev/null @@ -1,212 +0,0 @@ -// 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: FindFirstFileW.c -** -** Purpose: Tests the PAL implementation of the FindFirstFileW function. -** -** -**===================================================================*/ - - -#include - - -const char* szNoFileName = "333asdf.x77t"; -const char* szFindName = "test01.txt"; -const char* szFindNameWldCard_01 = "test0?.txt"; -const char* szFindNameWldCard_02 = "*.txt"; -const char* szDirName = "test_dir"; -const char* szDirNameSlash = "test_dir\\"; -const char* szDirNameWldCard_01 = "?est_dir"; -const char* szDirNameWldCard_02 = "test_*"; - - -BOOL CleanUp() -{ - DWORD dwAtt; - BOOL result = TRUE; - - dwAtt = GetFileAttributesA(szFindName); - if( dwAtt != INVALID_FILE_ATTRIBUTES ) - { - if(!SetFileAttributesA (szFindName, FILE_ATTRIBUTE_NORMAL)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL); - } - if(!DeleteFileA (szFindName)) - { - result = FALSE; - Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt); - } - } - - dwAtt = GetFileAttributesA(szDirName); - if( dwAtt != INVALID_FILE_ATTRIBUTES ) - { - if(!RemoveDirectoryA (szDirName)) - { - result = FALSE; - Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt); - } - } - - return result; -} - -int __cdecl main(int argc, char *argv[]) -{ - WIN32_FIND_DATAW findFileData; - HANDLE hFind = NULL; - FILE *pFile = NULL; - BOOL bRc = FALSE; - WCHAR* pTemp = NULL; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - if(!CleanUp()) - { - Fail("FindFirstFileW: ERROR : Initial Clean Up failed\n"); - } - - // - // find a file that doesn't exist - // - pTemp = convert((LPSTR)szNoFileName); - hFind = FindFirstFileW(pTemp, &findFileData); - free(pTemp); - if (hFind != INVALID_HANDLE_VALUE) - { - Fail ("FindFirstFileW: ERROR -> Found invalid NULL file\n"); - } - - - // - // find a file that exists - // - pFile = fopen(szFindName, "w"); - if (pFile == NULL) - { - Fail("FindFirstFileW: ERROR -> Unable to create a test file\n"); - } - else - { - fclose(pFile); - } - pTemp = convert((LPSTR)szFindName); - hFind = FindFirstFileW(pTemp, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - free(pTemp); - Fail ("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", szFindName); - } - else - { - // validate we found the correct file - if (wcscmp(pTemp, findFileData.cFileName) != 0) - { - free(pTemp); - Fail ("FindFirstFileW: ERROR -> Found the wrong file\n"); - } - } - free(pTemp); - - // - // find a directory that exists - // - pTemp = convert((LPSTR)szDirName); - bRc = CreateDirectoryW(pTemp, NULL); - if (bRc == FALSE) - { - Fail("FindFirstFileW: ERROR[%u] -> Failed to create the directory \"%s\"\n", - GetLastError(), szDirName); - } - - hFind = FindFirstFileW(pTemp, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - free(pTemp); - Fail("FindFirstFileW: ERROR. Unable to find \"%s\"\n", szDirName); - } - else - { - // validate we found the correct directory - if (wcscmp(pTemp, findFileData.cFileName) != 0) - { - free(pTemp); - Fail("FindFirstFileW: ERROR -> Found the wrong directory\n"); - } - } - free(pTemp); - - // - // find a directory using a trailing '\' on the directory name: should fail - // - pTemp = convert((LPSTR)szDirNameSlash); - hFind = FindFirstFileW(pTemp, &findFileData); - free(pTemp); - if (hFind != INVALID_HANDLE_VALUE) - { - Fail("FindFirstFileW: ERROR -> Able to find \"%s\": trailing " - "slash should have failed.\n", - szDirNameSlash); - } - - // find a file using wild cards - pTemp = convert((LPSTR)szFindNameWldCard_01); - hFind = FindFirstFileW(pTemp, &findFileData); - free(pTemp); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", - szFindNameWldCard_01); - } - - pTemp = convert((LPSTR)szFindNameWldCard_02); - hFind = FindFirstFileW(pTemp, &findFileData); - free(pTemp); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", - szFindNameWldCard_02); - } - - - // - // find a directory using wild cards - // - - pTemp = convert((LPSTR)szDirNameWldCard_01); - hFind = FindFirstFileW(pTemp, &findFileData); - free(pTemp); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", - szDirNameWldCard_01); - } - - pTemp = convert((LPSTR)szDirNameWldCard_02); - hFind = FindFirstFileW(pTemp, &findFileData); - free(pTemp); - if (hFind == INVALID_HANDLE_VALUE) - { - Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", - szDirNameWldCard_02); - } - - if(!CleanUp()) - { - Fail("FindFirstFileW: ERROR : Final Clean Up failed\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/FindFirstFileW.cpp b/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/FindFirstFileW.cpp new file mode 100644 index 0000000000..f69a625976 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindFirstFileW/test1/FindFirstFileW.cpp @@ -0,0 +1,212 @@ +// 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: FindFirstFileW.c +** +** Purpose: Tests the PAL implementation of the FindFirstFileW function. +** +** +**===================================================================*/ + + +#include + + +const char* szNoFileName = "333asdf.x77t"; +const char* szFindName = "test01.txt"; +const char* szFindNameWldCard_01 = "test0?.txt"; +const char* szFindNameWldCard_02 = "*.txt"; +const char* szDirName = "test_dir"; +const char* szDirNameSlash = "test_dir\\"; +const char* szDirNameWldCard_01 = "?est_dir"; +const char* szDirNameWldCard_02 = "test_*"; + + +BOOL CleanUp() +{ + DWORD dwAtt; + BOOL result = TRUE; + + dwAtt = GetFileAttributesA(szFindName); + if( dwAtt != INVALID_FILE_ATTRIBUTES ) + { + if(!SetFileAttributesA (szFindName, FILE_ATTRIBUTE_NORMAL)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL); + } + if(!DeleteFileA (szFindName)) + { + result = FALSE; + Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt); + } + } + + dwAtt = GetFileAttributesA(szDirName); + if( dwAtt != INVALID_FILE_ATTRIBUTES ) + { + if(!RemoveDirectoryA (szDirName)) + { + result = FALSE; + Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt); + } + } + + return result; +} + +int __cdecl main(int argc, char *argv[]) +{ + WIN32_FIND_DATAW findFileData; + HANDLE hFind = NULL; + FILE *pFile = NULL; + BOOL bRc = FALSE; + WCHAR* pTemp = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + if(!CleanUp()) + { + Fail("FindFirstFileW: ERROR : Initial Clean Up failed\n"); + } + + // + // find a file that doesn't exist + // + pTemp = convert((LPSTR)szNoFileName); + hFind = FindFirstFileW(pTemp, &findFileData); + free(pTemp); + if (hFind != INVALID_HANDLE_VALUE) + { + Fail ("FindFirstFileW: ERROR -> Found invalid NULL file\n"); + } + + + // + // find a file that exists + // + pFile = fopen(szFindName, "w"); + if (pFile == NULL) + { + Fail("FindFirstFileW: ERROR -> Unable to create a test file\n"); + } + else + { + fclose(pFile); + } + pTemp = convert((LPSTR)szFindName); + hFind = FindFirstFileW(pTemp, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + free(pTemp); + Fail ("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", szFindName); + } + else + { + // validate we found the correct file + if (wcscmp(pTemp, findFileData.cFileName) != 0) + { + free(pTemp); + Fail ("FindFirstFileW: ERROR -> Found the wrong file\n"); + } + } + free(pTemp); + + // + // find a directory that exists + // + pTemp = convert((LPSTR)szDirName); + bRc = CreateDirectoryW(pTemp, NULL); + if (bRc == FALSE) + { + Fail("FindFirstFileW: ERROR[%u] -> Failed to create the directory \"%s\"\n", + GetLastError(), szDirName); + } + + hFind = FindFirstFileW(pTemp, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + free(pTemp); + Fail("FindFirstFileW: ERROR. Unable to find \"%s\"\n", szDirName); + } + else + { + // validate we found the correct directory + if (wcscmp(pTemp, findFileData.cFileName) != 0) + { + free(pTemp); + Fail("FindFirstFileW: ERROR -> Found the wrong directory\n"); + } + } + free(pTemp); + + // + // find a directory using a trailing '\' on the directory name: should fail + // + pTemp = convert((LPSTR)szDirNameSlash); + hFind = FindFirstFileW(pTemp, &findFileData); + free(pTemp); + if (hFind != INVALID_HANDLE_VALUE) + { + Fail("FindFirstFileW: ERROR -> Able to find \"%s\": trailing " + "slash should have failed.\n", + szDirNameSlash); + } + + // find a file using wild cards + pTemp = convert((LPSTR)szFindNameWldCard_01); + hFind = FindFirstFileW(pTemp, &findFileData); + free(pTemp); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", + szFindNameWldCard_01); + } + + pTemp = convert((LPSTR)szFindNameWldCard_02); + hFind = FindFirstFileW(pTemp, &findFileData); + free(pTemp); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", + szFindNameWldCard_02); + } + + + // + // find a directory using wild cards + // + + pTemp = convert((LPSTR)szDirNameWldCard_01); + hFind = FindFirstFileW(pTemp, &findFileData); + free(pTemp); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", + szDirNameWldCard_01); + } + + pTemp = convert((LPSTR)szDirNameWldCard_02); + hFind = FindFirstFileW(pTemp, &findFileData); + free(pTemp); + if (hFind == INVALID_HANDLE_VALUE) + { + Fail("FindFirstFileW: ERROR -> Unable to find \"%s\"\n", + szDirNameWldCard_02); + } + + if(!CleanUp()) + { + Fail("FindFirstFileW: ERROR : Final Clean Up failed\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FindNextFileA/test1/CMakeLists.txt index efb1655d95..6e97b7aaad 100644 --- a/src/pal/tests/palsuite/file_io/FindNextFileA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/FindNextFileA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - FindNextFileA.c + FindNextFileA.cpp ) add_executable(paltest_findnextfilea_test1 diff --git a/src/pal/tests/palsuite/file_io/FindNextFileA/test1/FindNextFileA.c b/src/pal/tests/palsuite/file_io/FindNextFileA/test1/FindNextFileA.c deleted file mode 100644 index 578fa00542..0000000000 --- a/src/pal/tests/palsuite/file_io/FindNextFileA/test1/FindNextFileA.c +++ /dev/null @@ -1,243 +0,0 @@ -// 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: FindNextFileA.c -** -** Purpose: Tests the PAL implementation of the FindNextFileA function. -** -** -**===================================================================*/ - -#include - - -const char* szFindName = "test01.txt"; -const char* szFindName_02 = "test02.txt"; -const char* szFindNameWldCard_01 = "test0?.txt"; -const char* szFindNameWldCard_02 = "*.txt"; -const char* szDirName = "test_dir"; -const char* szDirName_02 = "test_dir_02"; -const char* szDirNameWldCard = "test_*"; - - - -void removeAll() -{ - WCHAR* wTempPtr = NULL; - - wTempPtr = convert((LPSTR)szDirName); - RemoveDirectoryW(wTempPtr); - free (wTempPtr); - wTempPtr = convert((LPSTR)szDirName_02); - RemoveDirectoryW(wTempPtr); - free (wTempPtr); - DeleteFile(szFindName); - DeleteFile(szFindName_02); -} - - - -BOOL createTestFile(const char* szName) -{ - FILE *pFile = NULL; - - pFile = fopen(szName, "w"); - if (pFile == NULL) - { - Trace("FindNextFile: ERROR -> Unable to create file \"%s\".\n", - szName); - removeAll(); - return FALSE; - } - else - { - fprintf(pFile, "FindNextFile test file, \"%s\".\n", szFindName); - fclose(pFile); - } - return TRUE; -} - - - -int __cdecl main(int argc, char *argv[]) -{ - WIN32_FIND_DATA findFileData; - WIN32_FIND_DATA findFileData_02; - HANDLE hFind = NULL; - BOOL bRc = FALSE; - DWORD dwBytesWritten; - WCHAR* wTempPtr = NULL; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - removeAll(); - - - // - // find a file with a NULL pointer - // - hFind = FindFirstFileA(NULL, &findFileData); - if (hFind != INVALID_HANDLE_VALUE) - { - Fail("FindNextFile: ERROR -> Found invalid NULL file"); - } - - bRc = FindNextFile(hFind, &findFileData); - if (bRc == TRUE) - { - Fail("FindNextFile: ERROR -> Found a file based on an invalid handle"); - } - - - // - // find a file that exists - // - if(createTestFile(szFindName) == FALSE) - { - PAL_TerminateEx(FAIL); - return FAIL; - } - if(createTestFile(szFindName_02) == FALSE) - { - PAL_TerminateEx(FAIL); - return FAIL; - } - - hFind = FindFirstFileA(szFindName, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - removeAll(); - Fail("FindNextFile: ERROR -> Unable to find \"%s\"\n", szFindName); - } - else - { - bRc = FindNextFile(hFind, &findFileData); - if (bRc != FALSE) - { - removeAll(); - Fail("FindNextFile: ERROR -> Found a file that doesn't exist.\n"); - } - } - - - // - // find a directory that exists - // - wTempPtr = convert((LPSTR)szDirName); - bRc = CreateDirectoryW(wTempPtr, NULL); - free (wTempPtr); - if (bRc == FALSE) - { - removeAll(); - Fail("FindNextFile: ERROR -> Failed to create the directory \"%s\"\n", - szDirName); - } - wTempPtr = convert((LPSTR)szDirName_02); - bRc = CreateDirectoryW(wTempPtr, NULL); - free (wTempPtr); - if (bRc == FALSE) - { - removeAll(); - Fail("FindNextFile: ERROR -> Failed to create the directory \"%s\"\n", - szDirName_02); - } - - hFind = FindFirstFileA(szDirName, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - removeAll(); - Fail("FindNextFile: ERROR. FindFirstFileA was unable to find \"%s\"\n", - szDirName); - } - else - { - bRc = FindNextFile(hFind, &findFileData); - if (bRc != FALSE) - { - removeAll(); - Fail("FindNextFile: ERROR -> Found a directory that doesn't exist.\n"); - } - } - - - // - // find a file using wild cards - // - hFind = FindFirstFileA(szFindNameWldCard_01, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - removeAll(); - Fail("FindNextFile: ERROR -> FindFirstFileA was unable to find \"%s\"\n", - szFindNameWldCard_01); - } - else - { - bRc = FindNextFile(hFind, &findFileData_02); - if (bRc == FALSE) - { - removeAll(); - Fail("FindNextFile: ERROR -> Unable to find another file.\n"); - } - else - { - // validate we found the correct file - if (strcmp(findFileData_02.cFileName, findFileData.cFileName) == 0) - { - removeAll(); - Fail("FindNextFile: ERROR -> Found the same file \"%s\".\n", - findFileData.cFileName); - } - } - } - - - // - // find a directory using wild cards - // - hFind = FindFirstFileA(szDirNameWldCard, &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - removeAll(); - Fail("FindNextFile: ERROR -> Unable to find \"%s\"\n", - szDirNameWldCard); - } - else - { - bRc = FindNextFile(hFind, &findFileData_02); - if (bRc == FALSE) - { - removeAll(); - Fail("FindNextFile: ERROR -> Unable to find another directory.\n"); - } - else - { - // validate we found the correct directory - if (strcmp(findFileData_02.cFileName, findFileData.cFileName) == 0) - { - removeAll(); - Fail("FindNextFile: ERROR -> Found the same directory \"%s\".\n", - findFileData.cFileName); - } - } - } - - // - // attempt to write to the hFind handle (which should fail) - // - bRc = WriteFile(hFind, "this is a test", 10, &dwBytesWritten, NULL); - removeAll(); - if (bRc == TRUE) - { - Fail("FindNextFile: ERROR -> Able to write to a FindNextFile handle.\n"); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileA/test1/FindNextFileA.cpp b/src/pal/tests/palsuite/file_io/FindNextFileA/test1/FindNextFileA.cpp new file mode 100644 index 0000000000..578fa00542 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileA/test1/FindNextFileA.cpp @@ -0,0 +1,243 @@ +// 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: FindNextFileA.c +** +** Purpose: Tests the PAL implementation of the FindNextFileA function. +** +** +**===================================================================*/ + +#include + + +const char* szFindName = "test01.txt"; +const char* szFindName_02 = "test02.txt"; +const char* szFindNameWldCard_01 = "test0?.txt"; +const char* szFindNameWldCard_02 = "*.txt"; +const char* szDirName = "test_dir"; +const char* szDirName_02 = "test_dir_02"; +const char* szDirNameWldCard = "test_*"; + + + +void removeAll() +{ + WCHAR* wTempPtr = NULL; + + wTempPtr = convert((LPSTR)szDirName); + RemoveDirectoryW(wTempPtr); + free (wTempPtr); + wTempPtr = convert((LPSTR)szDirName_02); + RemoveDirectoryW(wTempPtr); + free (wTempPtr); + DeleteFile(szFindName); + DeleteFile(szFindName_02); +} + + + +BOOL createTestFile(const char* szName) +{ + FILE *pFile = NULL; + + pFile = fopen(szName, "w"); + if (pFile == NULL) + { + Trace("FindNextFile: ERROR -> Unable to create file \"%s\".\n", + szName); + removeAll(); + return FALSE; + } + else + { + fprintf(pFile, "FindNextFile test file, \"%s\".\n", szFindName); + fclose(pFile); + } + return TRUE; +} + + + +int __cdecl main(int argc, char *argv[]) +{ + WIN32_FIND_DATA findFileData; + WIN32_FIND_DATA findFileData_02; + HANDLE hFind = NULL; + BOOL bRc = FALSE; + DWORD dwBytesWritten; + WCHAR* wTempPtr = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + removeAll(); + + + // + // find a file with a NULL pointer + // + hFind = FindFirstFileA(NULL, &findFileData); + if (hFind != INVALID_HANDLE_VALUE) + { + Fail("FindNextFile: ERROR -> Found invalid NULL file"); + } + + bRc = FindNextFile(hFind, &findFileData); + if (bRc == TRUE) + { + Fail("FindNextFile: ERROR -> Found a file based on an invalid handle"); + } + + + // + // find a file that exists + // + if(createTestFile(szFindName) == FALSE) + { + PAL_TerminateEx(FAIL); + return FAIL; + } + if(createTestFile(szFindName_02) == FALSE) + { + PAL_TerminateEx(FAIL); + return FAIL; + } + + hFind = FindFirstFileA(szFindName, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFile: ERROR -> Unable to find \"%s\"\n", szFindName); + } + else + { + bRc = FindNextFile(hFind, &findFileData); + if (bRc != FALSE) + { + removeAll(); + Fail("FindNextFile: ERROR -> Found a file that doesn't exist.\n"); + } + } + + + // + // find a directory that exists + // + wTempPtr = convert((LPSTR)szDirName); + bRc = CreateDirectoryW(wTempPtr, NULL); + free (wTempPtr); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFile: ERROR -> Failed to create the directory \"%s\"\n", + szDirName); + } + wTempPtr = convert((LPSTR)szDirName_02); + bRc = CreateDirectoryW(wTempPtr, NULL); + free (wTempPtr); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFile: ERROR -> Failed to create the directory \"%s\"\n", + szDirName_02); + } + + hFind = FindFirstFileA(szDirName, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFile: ERROR. FindFirstFileA was unable to find \"%s\"\n", + szDirName); + } + else + { + bRc = FindNextFile(hFind, &findFileData); + if (bRc != FALSE) + { + removeAll(); + Fail("FindNextFile: ERROR -> Found a directory that doesn't exist.\n"); + } + } + + + // + // find a file using wild cards + // + hFind = FindFirstFileA(szFindNameWldCard_01, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFile: ERROR -> FindFirstFileA was unable to find \"%s\"\n", + szFindNameWldCard_01); + } + else + { + bRc = FindNextFile(hFind, &findFileData_02); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFile: ERROR -> Unable to find another file.\n"); + } + else + { + // validate we found the correct file + if (strcmp(findFileData_02.cFileName, findFileData.cFileName) == 0) + { + removeAll(); + Fail("FindNextFile: ERROR -> Found the same file \"%s\".\n", + findFileData.cFileName); + } + } + } + + + // + // find a directory using wild cards + // + hFind = FindFirstFileA(szDirNameWldCard, &findFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFile: ERROR -> Unable to find \"%s\"\n", + szDirNameWldCard); + } + else + { + bRc = FindNextFile(hFind, &findFileData_02); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFile: ERROR -> Unable to find another directory.\n"); + } + else + { + // validate we found the correct directory + if (strcmp(findFileData_02.cFileName, findFileData.cFileName) == 0) + { + removeAll(); + Fail("FindNextFile: ERROR -> Found the same directory \"%s\".\n", + findFileData.cFileName); + } + } + } + + // + // attempt to write to the hFind handle (which should fail) + // + bRc = WriteFile(hFind, "this is a test", 10, &dwBytesWritten, NULL); + removeAll(); + if (bRc == TRUE) + { + Fail("FindNextFile: ERROR -> Able to write to a FindNextFile handle.\n"); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileA/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FindNextFileA/test2/CMakeLists.txt index 96821bdaaa..e037bd3aa0 100644 --- a/src/pal/tests/palsuite/file_io/FindNextFileA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/FindNextFileA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - findnextfilea.c + findnextfilea.cpp ) add_executable(paltest_findnextfilea_test2 diff --git a/src/pal/tests/palsuite/file_io/FindNextFileA/test2/findnextfilea.c b/src/pal/tests/palsuite/file_io/FindNextFileA/test2/findnextfilea.c deleted file mode 100644 index c841a4d498..0000000000 --- a/src/pal/tests/palsuite/file_io/FindNextFileA/test2/findnextfilea.c +++ /dev/null @@ -1,107 +0,0 @@ -// 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: findnextfilea.c -** -** Purpose: Tests the PAL implementation of the FindNextFileA function. -** Tests '*' and '*.*' to ensure that '.' and '..' are -** returned in the expected order -** -** -**===================================================================*/ - -#include - - -const char* szDot = "."; -const char* szDotDot = ".."; -const char* szStar = "*"; -const char* szStarDotStar = "*.*"; - - -static void DoTest(const char* szDir, - const char* szResult1, - const char* szResult2) -{ - HANDLE hFind; - WIN32_FIND_DATA findFileData; - - /* - ** find the first - */ - if ((hFind = FindFirstFileA(szDir, &findFileData)) == INVALID_HANDLE_VALUE) - { - Fail("FindNextFileA: ERROR -> FindFirstFileA(\"%s\") failed. " - "GetLastError returned %u.\n", - szStar, - GetLastError()); - } - - /* did we find the expected */ - if (strcmp(szResult1, findFileData.cFileName) != 0) - { - if (!FindClose(hFind)) - { - Trace("FindNextFileA: ERROR -> Failed to close the find handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("FindNextFileA: ERROR -> FindFirstFile(\"%s\") didn't find" - " the expected \"%s\" but found \"%s\" instead.\n", - szDir, - szResult1, - findFileData.cFileName); - } - - /* we found the first expected, let's see if we find the next expected*/ - if (!FindNextFileA(hFind, &findFileData)) - { - Trace("FindNextFileA: ERROR -> FindNextFileA should have found \"%s\"" - " but failed. GetLastError returned %u.\n", - szResult2, - GetLastError()); - if (!FindClose(hFind)) - { - Trace("FindNextFileA: ERROR -> Failed to close the find handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* we found something, but was it '.' */ - if (strcmp(szResult2, findFileData.cFileName) != 0) - { - if (!FindClose(hFind)) - { - Trace("FindNextFileA: ERROR -> Failed to close the find handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("FindNextFileA: ERROR -> FindNextFileA based on \"%s\" didn't find" - " the expected \"%s\" but found \"%s\" instead.\n", - szDir, - szResult2, - findFileData.cFileName); - } -} - -int __cdecl main(int argc, char *argv[]) -{ - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - DoTest(szStar, szDot, szDotDot); - DoTest(szStarDotStar, szDot, szDotDot); - - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileA/test2/findnextfilea.cpp b/src/pal/tests/palsuite/file_io/FindNextFileA/test2/findnextfilea.cpp new file mode 100644 index 0000000000..c841a4d498 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileA/test2/findnextfilea.cpp @@ -0,0 +1,107 @@ +// 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: findnextfilea.c +** +** Purpose: Tests the PAL implementation of the FindNextFileA function. +** Tests '*' and '*.*' to ensure that '.' and '..' are +** returned in the expected order +** +** +**===================================================================*/ + +#include + + +const char* szDot = "."; +const char* szDotDot = ".."; +const char* szStar = "*"; +const char* szStarDotStar = "*.*"; + + +static void DoTest(const char* szDir, + const char* szResult1, + const char* szResult2) +{ + HANDLE hFind; + WIN32_FIND_DATA findFileData; + + /* + ** find the first + */ + if ((hFind = FindFirstFileA(szDir, &findFileData)) == INVALID_HANDLE_VALUE) + { + Fail("FindNextFileA: ERROR -> FindFirstFileA(\"%s\") failed. " + "GetLastError returned %u.\n", + szStar, + GetLastError()); + } + + /* did we find the expected */ + if (strcmp(szResult1, findFileData.cFileName) != 0) + { + if (!FindClose(hFind)) + { + Trace("FindNextFileA: ERROR -> Failed to close the find handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("FindNextFileA: ERROR -> FindFirstFile(\"%s\") didn't find" + " the expected \"%s\" but found \"%s\" instead.\n", + szDir, + szResult1, + findFileData.cFileName); + } + + /* we found the first expected, let's see if we find the next expected*/ + if (!FindNextFileA(hFind, &findFileData)) + { + Trace("FindNextFileA: ERROR -> FindNextFileA should have found \"%s\"" + " but failed. GetLastError returned %u.\n", + szResult2, + GetLastError()); + if (!FindClose(hFind)) + { + Trace("FindNextFileA: ERROR -> Failed to close the find handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* we found something, but was it '.' */ + if (strcmp(szResult2, findFileData.cFileName) != 0) + { + if (!FindClose(hFind)) + { + Trace("FindNextFileA: ERROR -> Failed to close the find handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("FindNextFileA: ERROR -> FindNextFileA based on \"%s\" didn't find" + " the expected \"%s\" but found \"%s\" instead.\n", + szDir, + szResult2, + findFileData.cFileName); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + DoTest(szStar, szDot, szDotDot); + DoTest(szStarDotStar, szDot, szDotDot); + + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/CMakeLists.txt index 4a283dd3a5..a7c3e7ea02 100644 --- a/src/pal/tests/palsuite/file_io/FindNextFileW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - FindNextFileW.c + FindNextFileW.cpp ) add_executable(paltest_findnextfilew_test1 diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.c b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.c deleted file mode 100644 index 42e2e55805..0000000000 --- a/src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.c +++ /dev/null @@ -1,249 +0,0 @@ -// 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: FindNextFileW.c -** -** Purpose: Tests the PAL implementation of the FindNextFileW function. -** -** -**===================================================================*/ - -#include - - -const char* szFindName = "test01.txt"; -const char* szFindName_02 = "test02.txt"; -const char* szFindNameWldCard_01 = "test0?.txt"; -const char* szFindNameWldCard_02 = "*.txt"; -const char* szDirName = "test_dir"; -const char* szDirName_02 = "test_dir_02"; -const char* szDirNameWldCard = "test_*"; - - - -void removeAll() -{ - WCHAR* wTempPtr = NULL; - - wTempPtr = convert((LPSTR)szDirName); - RemoveDirectoryW(wTempPtr); - free(wTempPtr); - - wTempPtr = convert((LPSTR)szDirName_02); - RemoveDirectoryW(wTempPtr); - free(wTempPtr); - - wTempPtr = convert((LPSTR)szFindName); - DeleteFileW(wTempPtr); - free(wTempPtr); - - wTempPtr = convert((LPSTR)szFindName_02); - DeleteFileW(wTempPtr); - free(wTempPtr); -} - - - -BOOL createTestFile(const char* szName) -{ - FILE *pFile = NULL; - - pFile = fopen(szName, "w"); - if (pFile == NULL) - { - Trace("FindNextFileW: ERROR -> Unable to create file \"%s\".\n", szName); - removeAll(); - return FALSE; - } - else - { - fprintf(pFile, "FindNextFileW test file, \"%s\".\n", szFindName); - fclose(pFile); - } - - return TRUE; -} - - - -int __cdecl main(int argc, char *argv[]) -{ - WIN32_FIND_DATAW findFileData; - WIN32_FIND_DATAW findFileData_02; - HANDLE hFind = NULL; - BOOL bRc = FALSE; - DWORD dwBytesWritten; - WCHAR* wTempPtr = NULL; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - removeAll(); - - - // - // find a file that exists - // - if(createTestFile(szFindName) == FALSE) - { - PAL_TerminateEx(FAIL); - return FAIL; - } - if(createTestFile(szFindName_02) == FALSE) - { - PAL_TerminateEx(FAIL); - return FAIL; - } - - wTempPtr = convert((LPSTR)szFindName); - hFind = FindFirstFileW(wTempPtr, &findFileData); - free(wTempPtr); - if (hFind == INVALID_HANDLE_VALUE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Unable to find \"%s\"\n", szFindName); - } - else - { - bRc = FindNextFileW(hFind, &findFileData); - if (bRc != FALSE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Found a file that doesn't exist.\n"); - } - } - - - // - // find a directory that exists - // - wTempPtr = convert((LPSTR)szDirName); - bRc = CreateDirectoryW(wTempPtr, NULL); - free (wTempPtr); - if (bRc == FALSE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Failed to create the directory \"%s\"\n", - szDirName); - } - wTempPtr = convert((LPSTR)szDirName_02); - bRc = CreateDirectoryW(wTempPtr, NULL); - free (wTempPtr); - if (bRc == FALSE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Failed to create the directory " - "\"%s\"\n", - szDirName_02); - } - - wTempPtr = convert((LPSTR)szDirName); - hFind = FindFirstFileW(wTempPtr, &findFileData); - free (wTempPtr); - if (hFind == INVALID_HANDLE_VALUE) - { - removeAll(); - Fail("FindNextFileW: ERROR. FindFirstFileW was unable " - "to find \"%s\"\n", - szDirName); - } - else - { - bRc = FindNextFileW(hFind, &findFileData); - if (bRc != FALSE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Found a directory that " - "doesn't exist.\n"); - } - } - - - // - // find a file using wild cards - // - wTempPtr = convert((LPSTR)szFindNameWldCard_01); - hFind = FindFirstFileW(wTempPtr, &findFileData); - free(wTempPtr); - if (hFind == INVALID_HANDLE_VALUE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> FindFirstFileW was unable to " - "find \"%s\"\n", - szFindNameWldCard_01); - } - else - { - bRc = FindNextFileW(hFind, &findFileData_02); - if (bRc == FALSE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Unable to find another file.\n"); - } - else - { - // validate we found the correct file - if (wcscmp(findFileData_02.cFileName, findFileData.cFileName) == 0) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Found the same file \"%S\".\n", - findFileData.cFileName); - } - } - } - - - // - // find a directory using wild cards - // - wTempPtr = convert((LPSTR)szDirNameWldCard); - hFind = FindFirstFileW(wTempPtr, &findFileData); - free(wTempPtr); - if (hFind == INVALID_HANDLE_VALUE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Unable to find \"%s\"\n", - szDirNameWldCard); - } - else - { - bRc = FindNextFileW(hFind, &findFileData_02); - if (bRc == FALSE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Unable to find another directory.\n"); - } - else - { - // validate we found the correct directory - if (wcscmp(findFileData_02.cFileName, findFileData.cFileName) == 0) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Found the same directory " - "\"%S\".\n", - findFileData.cFileName); - } - } - } - - // - // attempt to write to the hFind handle (which should fail) - // - bRc = WriteFile(hFind, "this is a test", 10, &dwBytesWritten, NULL); - if (bRc == TRUE) - { - removeAll(); - Fail("FindNextFileW: ERROR -> Able to write to a FindNextFileW " - "handle.\n"); - } - - removeAll(); - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.cpp b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.cpp new file mode 100644 index 0000000000..42e2e55805 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.cpp @@ -0,0 +1,249 @@ +// 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: FindNextFileW.c +** +** Purpose: Tests the PAL implementation of the FindNextFileW function. +** +** +**===================================================================*/ + +#include + + +const char* szFindName = "test01.txt"; +const char* szFindName_02 = "test02.txt"; +const char* szFindNameWldCard_01 = "test0?.txt"; +const char* szFindNameWldCard_02 = "*.txt"; +const char* szDirName = "test_dir"; +const char* szDirName_02 = "test_dir_02"; +const char* szDirNameWldCard = "test_*"; + + + +void removeAll() +{ + WCHAR* wTempPtr = NULL; + + wTempPtr = convert((LPSTR)szDirName); + RemoveDirectoryW(wTempPtr); + free(wTempPtr); + + wTempPtr = convert((LPSTR)szDirName_02); + RemoveDirectoryW(wTempPtr); + free(wTempPtr); + + wTempPtr = convert((LPSTR)szFindName); + DeleteFileW(wTempPtr); + free(wTempPtr); + + wTempPtr = convert((LPSTR)szFindName_02); + DeleteFileW(wTempPtr); + free(wTempPtr); +} + + + +BOOL createTestFile(const char* szName) +{ + FILE *pFile = NULL; + + pFile = fopen(szName, "w"); + if (pFile == NULL) + { + Trace("FindNextFileW: ERROR -> Unable to create file \"%s\".\n", szName); + removeAll(); + return FALSE; + } + else + { + fprintf(pFile, "FindNextFileW test file, \"%s\".\n", szFindName); + fclose(pFile); + } + + return TRUE; +} + + + +int __cdecl main(int argc, char *argv[]) +{ + WIN32_FIND_DATAW findFileData; + WIN32_FIND_DATAW findFileData_02; + HANDLE hFind = NULL; + BOOL bRc = FALSE; + DWORD dwBytesWritten; + WCHAR* wTempPtr = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + removeAll(); + + + // + // find a file that exists + // + if(createTestFile(szFindName) == FALSE) + { + PAL_TerminateEx(FAIL); + return FAIL; + } + if(createTestFile(szFindName_02) == FALSE) + { + PAL_TerminateEx(FAIL); + return FAIL; + } + + wTempPtr = convert((LPSTR)szFindName); + hFind = FindFirstFileW(wTempPtr, &findFileData); + free(wTempPtr); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Unable to find \"%s\"\n", szFindName); + } + else + { + bRc = FindNextFileW(hFind, &findFileData); + if (bRc != FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Found a file that doesn't exist.\n"); + } + } + + + // + // find a directory that exists + // + wTempPtr = convert((LPSTR)szDirName); + bRc = CreateDirectoryW(wTempPtr, NULL); + free (wTempPtr); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Failed to create the directory \"%s\"\n", + szDirName); + } + wTempPtr = convert((LPSTR)szDirName_02); + bRc = CreateDirectoryW(wTempPtr, NULL); + free (wTempPtr); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Failed to create the directory " + "\"%s\"\n", + szDirName_02); + } + + wTempPtr = convert((LPSTR)szDirName); + hFind = FindFirstFileW(wTempPtr, &findFileData); + free (wTempPtr); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFileW: ERROR. FindFirstFileW was unable " + "to find \"%s\"\n", + szDirName); + } + else + { + bRc = FindNextFileW(hFind, &findFileData); + if (bRc != FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Found a directory that " + "doesn't exist.\n"); + } + } + + + // + // find a file using wild cards + // + wTempPtr = convert((LPSTR)szFindNameWldCard_01); + hFind = FindFirstFileW(wTempPtr, &findFileData); + free(wTempPtr); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> FindFirstFileW was unable to " + "find \"%s\"\n", + szFindNameWldCard_01); + } + else + { + bRc = FindNextFileW(hFind, &findFileData_02); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Unable to find another file.\n"); + } + else + { + // validate we found the correct file + if (wcscmp(findFileData_02.cFileName, findFileData.cFileName) == 0) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Found the same file \"%S\".\n", + findFileData.cFileName); + } + } + } + + + // + // find a directory using wild cards + // + wTempPtr = convert((LPSTR)szDirNameWldCard); + hFind = FindFirstFileW(wTempPtr, &findFileData); + free(wTempPtr); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Unable to find \"%s\"\n", + szDirNameWldCard); + } + else + { + bRc = FindNextFileW(hFind, &findFileData_02); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Unable to find another directory.\n"); + } + else + { + // validate we found the correct directory + if (wcscmp(findFileData_02.cFileName, findFileData.cFileName) == 0) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Found the same directory " + "\"%S\".\n", + findFileData.cFileName); + } + } + } + + // + // attempt to write to the hFind handle (which should fail) + // + bRc = WriteFile(hFind, "this is a test", 10, &dwBytesWritten, NULL); + if (bRc == TRUE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Able to write to a FindNextFileW " + "handle.\n"); + } + + removeAll(); + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/CMakeLists.txt index 2938afb888..7b4c3c9597 100644 --- a/src/pal/tests/palsuite/file_io/FindNextFileW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - findnextfilew.c + findnextfilew.cpp ) add_executable(paltest_findnextfilew_test2 diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.c b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.c deleted file mode 100644 index 3e806c2576..0000000000 --- a/src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.c +++ /dev/null @@ -1,107 +0,0 @@ -// 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: FindNextFileW.c -** -** Purpose: Tests the PAL implementation of the FindNextFileW function. -** Tests '*' and '*.*' to ensure that '.' and '..' are -** returned in the expected order -** -** -**===================================================================*/ - -#include - - -const WCHAR szwDot[] = {'.','\0'}; -const WCHAR szwDotDot[] = {'.','.','\0'}; -const WCHAR szwStar[] = {'*','\0'}; -const WCHAR szwStarDotStar[] = {'*','.','*','\0'}; - - -static void DoTest(const WCHAR* szwDir, - const WCHAR* szwResult1, - const WCHAR* szwResult2) -{ - HANDLE hFind; - WIN32_FIND_DATAW findFileData; - - /* - ** find the first - */ - if ((hFind = FindFirstFileW(szwDir, &findFileData)) == INVALID_HANDLE_VALUE) - { - Fail("FindNextFileW: ERROR -> FindFirstFileW(\"%S\") failed. " - "GetLastError returned %u.\n", - szwStar, - GetLastError()); - } - - /* did we find the expected */ - if (wcscmp(szwResult1, findFileData.cFileName) != 0) - { - if (!FindClose(hFind)) - { - Trace("FindNextFileW: ERROR -> Failed to close the find handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("FindNextFileW: ERROR -> FindFirstFile(\"%S\") didn't find" - " the expected \"%S\" but found \"%S\" instead.\n", - szwDir, - szwResult1, - findFileData.cFileName); - } - - /* we found the first expected, let's see if we find the next expected*/ - if (!FindNextFileW(hFind, &findFileData)) - { - Trace("FindNextFileW: ERROR -> FindNextFileW should have found \"%S\"" - " but failed. GetLastError returned %u.\n", - szwResult2, - GetLastError()); - if (!FindClose(hFind)) - { - Trace("FindNextFileW: ERROR -> Failed to close the find handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* we found something, but was it '.' */ - if (wcscmp(szwResult2, findFileData.cFileName) != 0) - { - if (!FindClose(hFind)) - { - Trace("FindNextFileW: ERROR -> Failed to close the find handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("FindNextFileW: ERROR -> FindNextFileW based on \"%S\" didn't find" - " the expected \"%S\" but found \"%S\" instead.\n", - szwDir, - szwResult2, - findFileData.cFileName); - } -} - -int __cdecl main(int argc, char *argv[]) -{ - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - DoTest(szwStar, szwDot, szwDotDot); - DoTest(szwStarDotStar, szwDot, szwDotDot); - - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.cpp b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.cpp new file mode 100644 index 0000000000..3e806c2576 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.cpp @@ -0,0 +1,107 @@ +// 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: FindNextFileW.c +** +** Purpose: Tests the PAL implementation of the FindNextFileW function. +** Tests '*' and '*.*' to ensure that '.' and '..' are +** returned in the expected order +** +** +**===================================================================*/ + +#include + + +const WCHAR szwDot[] = {'.','\0'}; +const WCHAR szwDotDot[] = {'.','.','\0'}; +const WCHAR szwStar[] = {'*','\0'}; +const WCHAR szwStarDotStar[] = {'*','.','*','\0'}; + + +static void DoTest(const WCHAR* szwDir, + const WCHAR* szwResult1, + const WCHAR* szwResult2) +{ + HANDLE hFind; + WIN32_FIND_DATAW findFileData; + + /* + ** find the first + */ + if ((hFind = FindFirstFileW(szwDir, &findFileData)) == INVALID_HANDLE_VALUE) + { + Fail("FindNextFileW: ERROR -> FindFirstFileW(\"%S\") failed. " + "GetLastError returned %u.\n", + szwStar, + GetLastError()); + } + + /* did we find the expected */ + if (wcscmp(szwResult1, findFileData.cFileName) != 0) + { + if (!FindClose(hFind)) + { + Trace("FindNextFileW: ERROR -> Failed to close the find handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("FindNextFileW: ERROR -> FindFirstFile(\"%S\") didn't find" + " the expected \"%S\" but found \"%S\" instead.\n", + szwDir, + szwResult1, + findFileData.cFileName); + } + + /* we found the first expected, let's see if we find the next expected*/ + if (!FindNextFileW(hFind, &findFileData)) + { + Trace("FindNextFileW: ERROR -> FindNextFileW should have found \"%S\"" + " but failed. GetLastError returned %u.\n", + szwResult2, + GetLastError()); + if (!FindClose(hFind)) + { + Trace("FindNextFileW: ERROR -> Failed to close the find handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* we found something, but was it '.' */ + if (wcscmp(szwResult2, findFileData.cFileName) != 0) + { + if (!FindClose(hFind)) + { + Trace("FindNextFileW: ERROR -> Failed to close the find handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("FindNextFileW: ERROR -> FindNextFileW based on \"%S\" didn't find" + " the expected \"%S\" but found \"%S\" instead.\n", + szwDir, + szwResult2, + findFileData.cFileName); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + DoTest(szwStar, szwDot, szwDotDot); + DoTest(szwStarDotStar, szwDot, szwDotDot); + + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/CMakeLists.txt index e3fbccd2ae..6c24ac76d1 100644 --- a/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - FlushFileBuffers.c + FlushFileBuffers.cpp ) add_executable(paltest_flushfilebuffers_test1 diff --git a/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/FlushFileBuffers.c b/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/FlushFileBuffers.c deleted file mode 100644 index 246be64847..0000000000 --- a/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/FlushFileBuffers.c +++ /dev/null @@ -1,130 +0,0 @@ -// 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: FlushFileBuffers.c -** -** Purpose: Tests the PAL implementation of the FlushFileBuffers function -** This tests checks the return values of FlushFileBuffers -- once on an -** open handle and once on a closed handle. -** -** Depends: -** CreateFile -** WriteFile -** CloseHandle -** DeleteFileA -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char **argv) -{ - - int TheReturn; - HANDLE TheFileHandle; - DWORD temp; - DWORD originalSize=10000; - DWORD finalSize=10000; - const char* fileName="the_file"; - - /* 1 2 3 4*/ - char * SomeText = "1234567890123456789012345678901234567890"; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - /* Open the file to get a HANDLE */ - TheFileHandle = - CreateFile( - fileName, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: CreateFile failed. Test depends on this function."); - } - - /* get the file size */ - originalSize = GetFileSize (TheFileHandle, NULL) ; - if(originalSize == INVALID_FILE_SIZE) - { - Fail("ERROR: call to GetFileSize faild with error " - "The GetLastError is %d.",GetLastError()); - } - - /* Write something too the HANDLE. Should be buffered */ - TheReturn = WriteFile(TheFileHandle, - SomeText, - strlen(SomeText), - &temp, - NULL); - - if(TheReturn == 0) - { - Fail("ERROR: WriteFile failed. Test depends on this function."); - } - - /* Test to see that FlushFileBuffers returns a success value */ - TheReturn = FlushFileBuffers(TheFileHandle); - if(TheReturn == 0) - { - Fail("ERROR: The FlushFileBuffers function returned 0, which " - "indicates failure, when trying to flush a valid HANDLE. " - "The GetLastError is %d.",GetLastError()); - } - - /* test if flush modified the file */ - finalSize = GetFileSize (TheFileHandle, NULL) ; - if(finalSize==INVALID_FILE_SIZE) - { - Fail("ERROR: call to GetFileSize faild with error " - "The GetLastError is %d.",GetLastError()); - } - if(finalSize!=(originalSize+strlen(SomeText))) - { - Fail("ERROR: FlushFileBuffers failed. data was not written to the file"); - } - - - /* Close the Handle */ - TheReturn = CloseHandle(TheFileHandle); - if(TheReturn == 0) - { - Fail("ERROR: CloseHandle failed. This function depends " - "upon it."); - } - - - /* Test to see that FlushFileBuffers returns a failure value */ - TheReturn = FlushFileBuffers(TheFileHandle); - if(TheReturn != 0) - { - Fail("ERROR: The FlushFileBuffers function returned non-zero, " - "which indicates success, when trying to flush an invalid " - "HANDLE."); - } - - /* make sure file does not exist */ - if(DeleteFileA(fileName)== 0 ) - { - Fail("ERROR: call to DeleteFileA faild with error " - "The GetLastError is %d.",GetLastError()); - } - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/FlushFileBuffers.cpp b/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/FlushFileBuffers.cpp new file mode 100644 index 0000000000..246be64847 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FlushFileBuffers/test1/FlushFileBuffers.cpp @@ -0,0 +1,130 @@ +// 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: FlushFileBuffers.c +** +** Purpose: Tests the PAL implementation of the FlushFileBuffers function +** This tests checks the return values of FlushFileBuffers -- once on an +** open handle and once on a closed handle. +** +** Depends: +** CreateFile +** WriteFile +** CloseHandle +** DeleteFileA +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char **argv) +{ + + int TheReturn; + HANDLE TheFileHandle; + DWORD temp; + DWORD originalSize=10000; + DWORD finalSize=10000; + const char* fileName="the_file"; + + /* 1 2 3 4*/ + char * SomeText = "1234567890123456789012345678901234567890"; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + /* Open the file to get a HANDLE */ + TheFileHandle = + CreateFile( + fileName, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: CreateFile failed. Test depends on this function."); + } + + /* get the file size */ + originalSize = GetFileSize (TheFileHandle, NULL) ; + if(originalSize == INVALID_FILE_SIZE) + { + Fail("ERROR: call to GetFileSize faild with error " + "The GetLastError is %d.",GetLastError()); + } + + /* Write something too the HANDLE. Should be buffered */ + TheReturn = WriteFile(TheFileHandle, + SomeText, + strlen(SomeText), + &temp, + NULL); + + if(TheReturn == 0) + { + Fail("ERROR: WriteFile failed. Test depends on this function."); + } + + /* Test to see that FlushFileBuffers returns a success value */ + TheReturn = FlushFileBuffers(TheFileHandle); + if(TheReturn == 0) + { + Fail("ERROR: The FlushFileBuffers function returned 0, which " + "indicates failure, when trying to flush a valid HANDLE. " + "The GetLastError is %d.",GetLastError()); + } + + /* test if flush modified the file */ + finalSize = GetFileSize (TheFileHandle, NULL) ; + if(finalSize==INVALID_FILE_SIZE) + { + Fail("ERROR: call to GetFileSize faild with error " + "The GetLastError is %d.",GetLastError()); + } + if(finalSize!=(originalSize+strlen(SomeText))) + { + Fail("ERROR: FlushFileBuffers failed. data was not written to the file"); + } + + + /* Close the Handle */ + TheReturn = CloseHandle(TheFileHandle); + if(TheReturn == 0) + { + Fail("ERROR: CloseHandle failed. This function depends " + "upon it."); + } + + + /* Test to see that FlushFileBuffers returns a failure value */ + TheReturn = FlushFileBuffers(TheFileHandle); + if(TheReturn != 0) + { + Fail("ERROR: The FlushFileBuffers function returned non-zero, " + "which indicates success, when trying to flush an invalid " + "HANDLE."); + } + + /* make sure file does not exist */ + if(DeleteFileA(fileName)== 0 ) + { + Fail("ERROR: call to DeleteFileA faild with error " + "The GetLastError is %d.",GetLastError()); + } + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/CMakeLists.txt index 131f4a5fb7..64ab6ea945 100644 --- a/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetConsoleCP.c + GetConsoleCP.cpp ) add_executable(paltest_getconsolecp_test1 diff --git a/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/GetConsoleCP.c b/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/GetConsoleCP.c deleted file mode 100644 index ba17d6c64d..0000000000 --- a/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/GetConsoleCP.c +++ /dev/null @@ -1,35 +0,0 @@ -// 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: GetConsoleCP.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetConsoleCP function. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - UINT uiCP = 0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - uiCP = GetConsoleCP(); - if ((uiCP != CP_ACP) && (uiCP != GetACP()) && (uiCP != 437)) /*437 for MSDOS*/ - { - Fail("GetConsoleCP: ERROR -> The invalid code page %d was returned.\n", - uiCP); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/GetConsoleCP.cpp b/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/GetConsoleCP.cpp new file mode 100644 index 0000000000..ba17d6c64d --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetConsoleCP/test1/GetConsoleCP.cpp @@ -0,0 +1,35 @@ +// 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: GetConsoleCP.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetConsoleCP function. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + UINT uiCP = 0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + uiCP = GetConsoleCP(); + if ((uiCP != CP_ACP) && (uiCP != GetACP()) && (uiCP != 437)) /*437 for MSDOS*/ + { + Fail("GetConsoleCP: ERROR -> The invalid code page %d was returned.\n", + uiCP); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/CMakeLists.txt index d19ab95a37..756f87b382 100644 --- a/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetConsoleOutputCP.c + GetConsoleOutputCP.cpp ) add_executable(paltest_getconsoleoutputcp_test1 diff --git a/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/GetConsoleOutputCP.c b/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/GetConsoleOutputCP.c deleted file mode 100644 index 3deaebf68f..0000000000 --- a/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/GetConsoleOutputCP.c +++ /dev/null @@ -1,35 +0,0 @@ -// 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: GetConsoleOutputCP.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetConsoleOutputCP function. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - UINT uiCP = 0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - uiCP = GetConsoleOutputCP(); - if ((uiCP != CP_ACP) && (uiCP != GetACP()) && (uiCP != 437)) /*437 for MSDOS*/ - { - Fail("GetConsoleOutputCP: ERROR -> The invalid code page %d was returned.\n", - uiCP); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/GetConsoleOutputCP.cpp b/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/GetConsoleOutputCP.cpp new file mode 100644 index 0000000000..3deaebf68f --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetConsoleOutputCP/test1/GetConsoleOutputCP.cpp @@ -0,0 +1,35 @@ +// 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: GetConsoleOutputCP.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetConsoleOutputCP function. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + UINT uiCP = 0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + uiCP = GetConsoleOutputCP(); + if ((uiCP != CP_ACP) && (uiCP != GetACP()) && (uiCP != 437)) /*437 for MSDOS*/ + { + Fail("GetConsoleOutputCP: ERROR -> The invalid code page %d was returned.\n", + uiCP); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/CMakeLists.txt index f7382b047d..28efc6897f 100644 --- a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetCurrentDirectoryA.c + GetCurrentDirectoryA.cpp ) add_executable(paltest_getcurrentdirectorya_test1 diff --git a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/GetCurrentDirectoryA.c b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/GetCurrentDirectoryA.c deleted file mode 100644 index b09e8a104d..0000000000 --- a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/GetCurrentDirectoryA.c +++ /dev/null @@ -1,97 +0,0 @@ -// 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: GetCurrentDirectoryA.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetCurrentDirectoryA function. -** -** -**===================================================================*/ - -#include - -const char* szFileName = "blah"; - - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwRc = 0; - DWORD dwRc2 = 0; - char szReturnedPath[_MAX_PATH+1]; - char szCurrentDir[_MAX_PATH+1]; - LPSTR pPathPtr; - size_t nCount = 0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // use GetFullPathName to to get the current path by stripping - // the file name off the end - memset(szReturnedPath, 0, sizeof(char)*(_MAX_PATH+1)); - dwRc = GetFullPathNameA(szFileName, _MAX_PATH, szReturnedPath, &pPathPtr); - if (dwRc == 0) - { - // GetFullPathName failed - Fail("GetCurrentDirectoryA: ERROR -> GetFullPathNameA failed " - "with error code: %ld.\n", GetLastError()); - } - else if(dwRc > _MAX_PATH) - { - Fail("GetCurrentDirectoryA: ERROR -> The path name GetFullPathNameA " - "returned is longer than _MAX_PATH characters.\n"); - } - - - // strip the file name from the full path to get the current path - nCount = strlen(szReturnedPath) - strlen(szFileName) - 1; - memset(szCurrentDir, 0, sizeof(char)*(_MAX_PATH+1)); - strncpy(szCurrentDir, szReturnedPath, nCount); - - // compare the results of GetCurrentDirectoryA with the above - memset(szReturnedPath, 0, sizeof(char)*(_MAX_PATH+1)); - dwRc = GetCurrentDirectoryA((sizeof(char)*(_MAX_PATH+1)), szReturnedPath); - if (dwRc == 0) - { - Fail("GetCurrentDirectoryA: ERROR -> GetCurrentDirectoryA failed " - "with error code: %ld.\n", GetLastError()); - } - else if(dwRc > _MAX_PATH) - { - Fail("GetCurrentDirectoryA: ERROR -> The path name " - "returned is longer than _MAX_PATH characters.\n"); - } - - - /* test case the passed buffer size is not big enough - * function should return the size required + 1 a terminating null character - */ - - /* good buffer size */ - dwRc = GetCurrentDirectoryA((sizeof(CHAR)*(_MAX_PATH+1)), szReturnedPath); - - /* small buffer (0 size)*/ - dwRc2 = GetCurrentDirectoryA(0, szReturnedPath); - if (dwRc2 != (dwRc+1) ) - { - Fail("GetCurrentDirectoryA: ERROR -> failed to give the correct " - "return value when passed a buffer not big enough. " - "Expected %u while result is %u \n",(dwRc+1),dwRc2); - - } - - if (strcmp(szReturnedPath, szCurrentDir) != 0) - { - Fail("GetCurrentDirectoryA: ERROR -> The computed and returned " - "directories do not compare.\n"); - } - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/GetCurrentDirectoryA.cpp b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/GetCurrentDirectoryA.cpp new file mode 100644 index 0000000000..b09e8a104d --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryA/test1/GetCurrentDirectoryA.cpp @@ -0,0 +1,97 @@ +// 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: GetCurrentDirectoryA.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetCurrentDirectoryA function. +** +** +**===================================================================*/ + +#include + +const char* szFileName = "blah"; + + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + DWORD dwRc2 = 0; + char szReturnedPath[_MAX_PATH+1]; + char szCurrentDir[_MAX_PATH+1]; + LPSTR pPathPtr; + size_t nCount = 0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // use GetFullPathName to to get the current path by stripping + // the file name off the end + memset(szReturnedPath, 0, sizeof(char)*(_MAX_PATH+1)); + dwRc = GetFullPathNameA(szFileName, _MAX_PATH, szReturnedPath, &pPathPtr); + if (dwRc == 0) + { + // GetFullPathName failed + Fail("GetCurrentDirectoryA: ERROR -> GetFullPathNameA failed " + "with error code: %ld.\n", GetLastError()); + } + else if(dwRc > _MAX_PATH) + { + Fail("GetCurrentDirectoryA: ERROR -> The path name GetFullPathNameA " + "returned is longer than _MAX_PATH characters.\n"); + } + + + // strip the file name from the full path to get the current path + nCount = strlen(szReturnedPath) - strlen(szFileName) - 1; + memset(szCurrentDir, 0, sizeof(char)*(_MAX_PATH+1)); + strncpy(szCurrentDir, szReturnedPath, nCount); + + // compare the results of GetCurrentDirectoryA with the above + memset(szReturnedPath, 0, sizeof(char)*(_MAX_PATH+1)); + dwRc = GetCurrentDirectoryA((sizeof(char)*(_MAX_PATH+1)), szReturnedPath); + if (dwRc == 0) + { + Fail("GetCurrentDirectoryA: ERROR -> GetCurrentDirectoryA failed " + "with error code: %ld.\n", GetLastError()); + } + else if(dwRc > _MAX_PATH) + { + Fail("GetCurrentDirectoryA: ERROR -> The path name " + "returned is longer than _MAX_PATH characters.\n"); + } + + + /* test case the passed buffer size is not big enough + * function should return the size required + 1 a terminating null character + */ + + /* good buffer size */ + dwRc = GetCurrentDirectoryA((sizeof(CHAR)*(_MAX_PATH+1)), szReturnedPath); + + /* small buffer (0 size)*/ + dwRc2 = GetCurrentDirectoryA(0, szReturnedPath); + if (dwRc2 != (dwRc+1) ) + { + Fail("GetCurrentDirectoryA: ERROR -> failed to give the correct " + "return value when passed a buffer not big enough. " + "Expected %u while result is %u \n",(dwRc+1),dwRc2); + + } + + if (strcmp(szReturnedPath, szCurrentDir) != 0) + { + Fail("GetCurrentDirectoryA: ERROR -> The computed and returned " + "directories do not compare.\n"); + } + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/CMakeLists.txt index ed8419926c..ee07f5e0d1 100644 --- a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetCurrentDirectoryW.c + GetCurrentDirectoryW.cpp ) add_executable(paltest_getcurrentdirectoryw_test1 diff --git a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/GetCurrentDirectoryW.c b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/GetCurrentDirectoryW.c deleted file mode 100644 index 4f4697b0a2..0000000000 --- a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/GetCurrentDirectoryW.c +++ /dev/null @@ -1,106 +0,0 @@ -// 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: GetCurrentDirectoryW.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetCurrentDirectoryW function. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwRc = 0; - DWORD dwRc2 = 0; - WCHAR szwReturnedPath[_MAX_PATH+1]; - WCHAR szwCurrentDir[_MAX_PATH+1]; - WCHAR szwFileName[_MAX_PATH] = {'b','l','a','h','\0'}; - LPWSTR pPathPtr; - size_t nCount = 0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* use GetFullPathName to to get the current path by stripping - * the file name off the end */ - memset(szwReturnedPath, 0, sizeof(WCHAR)*(_MAX_PATH+1)); - dwRc = GetFullPathNameW(szwFileName, _MAX_PATH, szwReturnedPath, &pPathPtr); - if (dwRc == 0) - { - /* GetFullPathName failed */ - Fail("GetCurrentDirectoryW: ERROR -> GetFullPathNameW failed " - "with error code: %ld.\n", GetLastError()); - } - else if(dwRc >_MAX_PATH) - { - Fail("GetCurrentDirectoryW: ERROR -> The path name GetFullPathNameW " - "returned is longer than _MAX_PATH characters.\n"); - } - - /* strip the file name from the full path to get the current path */ - nCount = wcslen(szwReturnedPath) - wcslen(szwFileName) - 1; - memset(szwCurrentDir, 0, sizeof(WCHAR)*(_MAX_PATH+1)); - memcpy(szwCurrentDir, szwReturnedPath, nCount*sizeof(WCHAR)); - - /* compare the results of GetCurrentDirectoryW with the above */ - memset(szwReturnedPath, 0, sizeof(WCHAR)*(_MAX_PATH+1)); - dwRc = GetCurrentDirectoryW((sizeof(WCHAR)*(_MAX_PATH+1)), szwReturnedPath); - if (dwRc == 0) - { - Fail("GetCurrentDirectoryW: ERROR -> GetCurrentDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - else if(dwRc >_MAX_PATH) - { - Fail("GetCurrentDirectoryW: ERROR -> The path name " - "returned is longer than _MAX_PATH characters.\n"); - } - - /* check to see whether the length of the returned string is equal to - * the DWORD returned by GetCurrentDirectoryW. - */ - if(wcslen(szwReturnedPath) != dwRc) - { - Fail("GetCurrentDirectoryW: ERROR -> The Length of the path name " - "returned \"%u\" is not equal to the return value of the " - "function \"%u\".\n" , wcslen(szwReturnedPath), dwRc); - } - - - - /* test case the passed buffer size is not big enough - * function should return the size required + 1 for a terminating null character - */ - - /* good buffer size */ - dwRc = GetCurrentDirectoryW((sizeof(WCHAR)*(_MAX_PATH+1)), szwReturnedPath); - - /* small buffer (0 size)*/ - dwRc2 = GetCurrentDirectoryW(0, szwReturnedPath); - if (dwRc2 != (dwRc+1) ) - { - Fail("GetCurrentDirectoryW: ERROR -> failed to give the correct " - "return value when passed a buffer not big enough. " - "Expected %u while result is %u ",(dwRc+1),dwRc2); - - } - - if (wcsncmp(szwReturnedPath, szwCurrentDir, wcslen(szwReturnedPath)) != 0) - { - Fail("GetCurrentDirectoryW: ERROR -> The computed and returned " - "directories do not compare.\n"); - } - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/GetCurrentDirectoryW.cpp b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/GetCurrentDirectoryW.cpp new file mode 100644 index 0000000000..4f4697b0a2 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetCurrentDirectoryW/test1/GetCurrentDirectoryW.cpp @@ -0,0 +1,106 @@ +// 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: GetCurrentDirectoryW.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetCurrentDirectoryW function. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + DWORD dwRc2 = 0; + WCHAR szwReturnedPath[_MAX_PATH+1]; + WCHAR szwCurrentDir[_MAX_PATH+1]; + WCHAR szwFileName[_MAX_PATH] = {'b','l','a','h','\0'}; + LPWSTR pPathPtr; + size_t nCount = 0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* use GetFullPathName to to get the current path by stripping + * the file name off the end */ + memset(szwReturnedPath, 0, sizeof(WCHAR)*(_MAX_PATH+1)); + dwRc = GetFullPathNameW(szwFileName, _MAX_PATH, szwReturnedPath, &pPathPtr); + if (dwRc == 0) + { + /* GetFullPathName failed */ + Fail("GetCurrentDirectoryW: ERROR -> GetFullPathNameW failed " + "with error code: %ld.\n", GetLastError()); + } + else if(dwRc >_MAX_PATH) + { + Fail("GetCurrentDirectoryW: ERROR -> The path name GetFullPathNameW " + "returned is longer than _MAX_PATH characters.\n"); + } + + /* strip the file name from the full path to get the current path */ + nCount = wcslen(szwReturnedPath) - wcslen(szwFileName) - 1; + memset(szwCurrentDir, 0, sizeof(WCHAR)*(_MAX_PATH+1)); + memcpy(szwCurrentDir, szwReturnedPath, nCount*sizeof(WCHAR)); + + /* compare the results of GetCurrentDirectoryW with the above */ + memset(szwReturnedPath, 0, sizeof(WCHAR)*(_MAX_PATH+1)); + dwRc = GetCurrentDirectoryW((sizeof(WCHAR)*(_MAX_PATH+1)), szwReturnedPath); + if (dwRc == 0) + { + Fail("GetCurrentDirectoryW: ERROR -> GetCurrentDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + else if(dwRc >_MAX_PATH) + { + Fail("GetCurrentDirectoryW: ERROR -> The path name " + "returned is longer than _MAX_PATH characters.\n"); + } + + /* check to see whether the length of the returned string is equal to + * the DWORD returned by GetCurrentDirectoryW. + */ + if(wcslen(szwReturnedPath) != dwRc) + { + Fail("GetCurrentDirectoryW: ERROR -> The Length of the path name " + "returned \"%u\" is not equal to the return value of the " + "function \"%u\".\n" , wcslen(szwReturnedPath), dwRc); + } + + + + /* test case the passed buffer size is not big enough + * function should return the size required + 1 for a terminating null character + */ + + /* good buffer size */ + dwRc = GetCurrentDirectoryW((sizeof(WCHAR)*(_MAX_PATH+1)), szwReturnedPath); + + /* small buffer (0 size)*/ + dwRc2 = GetCurrentDirectoryW(0, szwReturnedPath); + if (dwRc2 != (dwRc+1) ) + { + Fail("GetCurrentDirectoryW: ERROR -> failed to give the correct " + "return value when passed a buffer not big enough. " + "Expected %u while result is %u ",(dwRc+1),dwRc2); + + } + + if (wcsncmp(szwReturnedPath, szwCurrentDir, wcslen(szwReturnedPath)) != 0) + { + Fail("GetCurrentDirectoryW: ERROR -> The computed and returned " + "directories do not compare.\n"); + } + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/CMakeLists.txt index 6b06376233..7de0b275f6 100644 --- a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetDiskFreeSpaceW.c + GetDiskFreeSpaceW.cpp ) add_executable(paltest_getdiskfreespacew_test1 diff --git a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.c b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.c deleted file mode 100644 index c1445f654f..0000000000 --- a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.c +++ /dev/null @@ -1,94 +0,0 @@ -// 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: GetDiskFreeSpaceW.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetDiskFreeSpaceW function. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwSectorsPerCluster; /* sectors per cluster */ - DWORD dwBytesPerSector; /* bytes per sector */ - DWORD dwSectorsPerCluster_02; /* sectors per cluster */ - DWORD dwBytesPerSector_02; /* bytes per sector */ - DWORD dwNumberOfFreeClusters; /* free clusters */ - DWORD dwTotalNumberOfClusters; /* total clusters */ - BOOL bRc = FALSE; - WCHAR szwRootPath[10] = {'/','\0'}; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* test the NULL option which translates to the current drive */ - bRc = GetDiskFreeSpaceW(NULL, - &dwSectorsPerCluster, - &dwBytesPerSector, - &dwNumberOfFreeClusters, - &dwTotalNumberOfClusters); - if (bRc != TRUE) - { - Fail("GetDiskFreeSpaceW: ERROR -> Failed with error code: %ld\n", - GetLastError()); - } - else if (dwSectorsPerCluster == 0) - { - Fail("GetDiskFreeSpaceW: ERROR -> dwSectorsPerCluster returned 0\n"); - } - else if (dwBytesPerSector == 0) - { - Fail("GetDiskFreeSpaceW: ERROR -> dwBytesPerSector returned 0\n"); - } - - /* test the root directory to the current drive */ - bRc = GetDiskFreeSpaceW(szwRootPath, - &dwSectorsPerCluster_02, - &dwBytesPerSector_02, - &dwNumberOfFreeClusters, - &dwTotalNumberOfClusters); - if (bRc != TRUE) - { - Fail("GetDiskFreeSpaceW: ERROR -> Failed with error code: %ld\n", - GetLastError()); - } - else if (dwSectorsPerCluster == 0) - { - Fail("GetDiskFreeSpaceW: ERROR -> dwSectorsPerCluster returned 0\n"); - } - else if (dwBytesPerSector == 0) - { - Fail("GetDiskFreeSpaceW: ERROR -> dwBytesPerSector returned 0\n"); - } - /* - ** make sure the values returned for NULL path and root path - ** are the same - */ - else if (dwSectorsPerCluster_02 != dwSectorsPerCluster) - { - Fail("GetDiskFreeSpaceW: ERROR -> dwSectorsPerCluster for NULL path " - "(%u) should have been the same as the root path (%u).\n", - dwSectorsPerCluster, - dwSectorsPerCluster_02); - } - else if (dwBytesPerSector_02 != dwBytesPerSector) - { - Fail("GetDiskFreeSpaceW: ERROR -> dwBytesPerSector for NULL path " - "(%u) should have been the same as the root path (%u).\n", - dwBytesPerSector, - dwBytesPerSector_02); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.cpp b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.cpp new file mode 100644 index 0000000000..c1445f654f --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test1/GetDiskFreeSpaceW.cpp @@ -0,0 +1,94 @@ +// 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: GetDiskFreeSpaceW.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetDiskFreeSpaceW function. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwSectorsPerCluster; /* sectors per cluster */ + DWORD dwBytesPerSector; /* bytes per sector */ + DWORD dwSectorsPerCluster_02; /* sectors per cluster */ + DWORD dwBytesPerSector_02; /* bytes per sector */ + DWORD dwNumberOfFreeClusters; /* free clusters */ + DWORD dwTotalNumberOfClusters; /* total clusters */ + BOOL bRc = FALSE; + WCHAR szwRootPath[10] = {'/','\0'}; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* test the NULL option which translates to the current drive */ + bRc = GetDiskFreeSpaceW(NULL, + &dwSectorsPerCluster, + &dwBytesPerSector, + &dwNumberOfFreeClusters, + &dwTotalNumberOfClusters); + if (bRc != TRUE) + { + Fail("GetDiskFreeSpaceW: ERROR -> Failed with error code: %ld\n", + GetLastError()); + } + else if (dwSectorsPerCluster == 0) + { + Fail("GetDiskFreeSpaceW: ERROR -> dwSectorsPerCluster returned 0\n"); + } + else if (dwBytesPerSector == 0) + { + Fail("GetDiskFreeSpaceW: ERROR -> dwBytesPerSector returned 0\n"); + } + + /* test the root directory to the current drive */ + bRc = GetDiskFreeSpaceW(szwRootPath, + &dwSectorsPerCluster_02, + &dwBytesPerSector_02, + &dwNumberOfFreeClusters, + &dwTotalNumberOfClusters); + if (bRc != TRUE) + { + Fail("GetDiskFreeSpaceW: ERROR -> Failed with error code: %ld\n", + GetLastError()); + } + else if (dwSectorsPerCluster == 0) + { + Fail("GetDiskFreeSpaceW: ERROR -> dwSectorsPerCluster returned 0\n"); + } + else if (dwBytesPerSector == 0) + { + Fail("GetDiskFreeSpaceW: ERROR -> dwBytesPerSector returned 0\n"); + } + /* + ** make sure the values returned for NULL path and root path + ** are the same + */ + else if (dwSectorsPerCluster_02 != dwSectorsPerCluster) + { + Fail("GetDiskFreeSpaceW: ERROR -> dwSectorsPerCluster for NULL path " + "(%u) should have been the same as the root path (%u).\n", + dwSectorsPerCluster, + dwSectorsPerCluster_02); + } + else if (dwBytesPerSector_02 != dwBytesPerSector) + { + Fail("GetDiskFreeSpaceW: ERROR -> dwBytesPerSector for NULL path " + "(%u) should have been the same as the root path (%u).\n", + dwBytesPerSector, + dwBytesPerSector_02); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/CMakeLists.txt index 5660b39e1a..7bcbf55c42 100644 --- a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - getdiskfreespacew.c + getdiskfreespacew.cpp ) add_executable(paltest_getdiskfreespacew_test2 diff --git a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/getdiskfreespacew.c b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/getdiskfreespacew.c deleted file mode 100644 index 83dcb54b51..0000000000 --- a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/getdiskfreespacew.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: GetDiskFreeSpaceW.c (test 2) -** -** Purpose: Tests the PAL implementation of the GetDiskFreeSpaceW -** function on valid non-root paths. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwSectorsPerCluster; /* sectors per cluster */ - DWORD dwBytesPerSector; /* bytes per sector */ - DWORD dwNumberOfFreeClusters; /* free clusters */ - DWORD dwTotalNumberOfClusters; /* total clusters */ - BOOL bRc = FALSE; - WCHAR szwCurrentPath[MAX_LONGPATH]; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* get the current directory so we are sure to have a valid path */ - if (!GetCurrentDirectoryW(MAX_LONGPATH, szwCurrentPath)) - { - Fail("GetDiskFreeSpaceW: ERROR -> GetCurrentDirectoryW failed with " - "error code: %u.\n", - GetLastError()); - } - - /* test the current path*/ - bRc = GetDiskFreeSpaceW(szwCurrentPath, - &dwSectorsPerCluster, - &dwBytesPerSector, - &dwNumberOfFreeClusters, - &dwTotalNumberOfClusters); - if (bRc != TRUE) - { - Fail("GetDiskFreeSpaceW: ERROR -> Failed with error code: %u for " - "the path \"%S\".\n", - GetLastError(), - szwCurrentPath); - } - else if (dwSectorsPerCluster == 0) - { - Fail("GetDiskFreeSpaceW: ERROR -> dwSectorsPerCluster returned 0\n"); - } - else if (dwBytesPerSector == 0) - { - Fail("GetDiskFreeSpaceW: ERROR -> dwBytesPerSector returned 0\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/getdiskfreespacew.cpp b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/getdiskfreespacew.cpp new file mode 100644 index 0000000000..83dcb54b51 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetDiskFreeSpaceW/test2/getdiskfreespacew.cpp @@ -0,0 +1,65 @@ +// 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: GetDiskFreeSpaceW.c (test 2) +** +** Purpose: Tests the PAL implementation of the GetDiskFreeSpaceW +** function on valid non-root paths. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwSectorsPerCluster; /* sectors per cluster */ + DWORD dwBytesPerSector; /* bytes per sector */ + DWORD dwNumberOfFreeClusters; /* free clusters */ + DWORD dwTotalNumberOfClusters; /* total clusters */ + BOOL bRc = FALSE; + WCHAR szwCurrentPath[MAX_LONGPATH]; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* get the current directory so we are sure to have a valid path */ + if (!GetCurrentDirectoryW(MAX_LONGPATH, szwCurrentPath)) + { + Fail("GetDiskFreeSpaceW: ERROR -> GetCurrentDirectoryW failed with " + "error code: %u.\n", + GetLastError()); + } + + /* test the current path*/ + bRc = GetDiskFreeSpaceW(szwCurrentPath, + &dwSectorsPerCluster, + &dwBytesPerSector, + &dwNumberOfFreeClusters, + &dwTotalNumberOfClusters); + if (bRc != TRUE) + { + Fail("GetDiskFreeSpaceW: ERROR -> Failed with error code: %u for " + "the path \"%S\".\n", + GetLastError(), + szwCurrentPath); + } + else if (dwSectorsPerCluster == 0) + { + Fail("GetDiskFreeSpaceW: ERROR -> dwSectorsPerCluster returned 0\n"); + } + else if (dwBytesPerSector == 0) + { + Fail("GetDiskFreeSpaceW: ERROR -> dwBytesPerSector returned 0\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/CMakeLists.txt index 6bf9818e86..414df7f6b5 100644 --- a/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFileAttributesA.c + GetFileAttributesA.cpp ) add_executable(paltest_getfileattributesa_test1 diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/GetFileAttributesA.c b/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/GetFileAttributesA.c deleted file mode 100644 index ff6bd0b8e0..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/GetFileAttributesA.c +++ /dev/null @@ -1,340 +0,0 @@ -// 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: GetFileAttributesA.c -** -** Purpose: Tests the PAL implementation of the GetFileAttributesA function by -** checking the attributes of: -** - a normal directory and file -** - a read only directory and file -** - a read write directory and file -** - a hidden directory and file -** - a read only hidden directory and file -** - a directory and a file with no attributes -** - an invalid file name -** -** -**===========================================================================*/ -#include - -const int TYPE_DIR = 0; -const int TYPE_FILE = 1; -/* Structure defining a test case */ -typedef struct -{ - char *name; /* name of the file/directory */ - DWORD expectedAttribs; /* expected attributes */ - HANDLE hFile; /* Handle to the file */ - int isFile; /* is file (1) or dir (0) */ -}TestCaseFile; - -typedef struct -{ - char *name; /* name of the file/directory */ - DWORD expectedAttribs; /* expected attributes */ - HANDLE hFile; /* Handle to the file */ - int isFile; /* is file (1) or dir (0) */ -}TestCaseDir; - -DWORD desiredAccessFile = GENERIC_READ | GENERIC_WRITE; -DWORD shareModeFile = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE; -LPSECURITY_ATTRIBUTES lpAttrFile = NULL; -DWORD dwCreationDispFile = CREATE_NEW; -DWORD dwFlagsAttribFile = FILE_ATTRIBUTE_NORMAL; -HANDLE hTemplateFile = NULL; - -int numFileTests = 6; -TestCaseFile gfaTestsFile[6]; /* GetFileAttributes tests list */ - -int numDirTests = 6; -TestCaseDir gfaTestsDir[6]; /* GetFileAttributes tests list */ - -BOOL CleanUpFiles() -{ - DWORD dwAtt; - int i; - BOOL result = TRUE; - for (i = 0; i < numFileTests -1 ; i++ ) - { - dwAtt = GetFileAttributesA(gfaTestsFile[i].name); - - if( dwAtt != INVALID_FILE_ATTRIBUTES ) - { - //Trace("Files iteration %d\n", i); - if(!SetFileAttributesA (gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL); - } - - if(!DeleteFileA (gfaTestsFile[i].name)) - { - result = FALSE; - Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, dwAtt); - } - - } - } -// Trace("Value of result is %d\n", result); - return result; -} -BOOL SetUpFiles() -{ - int i = 0; - BOOL result = TRUE; - for (i = 0; i < numFileTests -1; i++ ) - { - gfaTestsFile[i].hFile = CreateFile(gfaTestsFile[i].name, - desiredAccessFile, - shareModeFile, - lpAttrFile, - dwCreationDispFile, - dwFlagsAttribFile, - hTemplateFile); - - if( gfaTestsFile[i].hFile == NULL ) - { - Fail("Error while creating files for iteration %d\n", i); - } - - if(!SetFileAttributesA (gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs); - } - } - - return result; -} - -BOOL CleanUpDirs() -{ - DWORD dwAtt; - int i; - BOOL result = TRUE; - for (i = 0; i < numDirTests -1 ; i++ ) - { - dwAtt = GetFileAttributesA(gfaTestsDir[i].name); - - if( dwAtt != INVALID_FILE_ATTRIBUTES ) - { - - if(!SetFileAttributesA (gfaTestsDir[i].name, FILE_ATTRIBUTE_DIRECTORY)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY)); - } - - if(!RemoveDirectoryA (gfaTestsDir[i].name)) - { - result = FALSE; - Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt); - } - - } - } - - return result; -} - -BOOL SetUpDirs() -{ - int i = 0; - BOOL result = TRUE; - DWORD ret = 0; - for (i = 0; i < numDirTests - 1 ; i++ ) - { - result = CreateDirectory(gfaTestsDir[i].name, - NULL); - - if(!result ) - { - result = FALSE; - Fail("Error while creating directory for iteration %d\n", i); - } - - if(!SetFileAttributesA (gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); - } - - ret = GetFileAttributesA (gfaTestsDir[i].name); - if(ret != gfaTestsDir[i].expectedAttribs) - { - result = FALSE; - Trace("ERROR: Error setting attributes [%s][%d]\n", gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); - } - //Trace("Setup Dir setting attr [%d], returned [%d]\n", gfaTestsDir[i].expectedAttribs, ret); - - } - //Trace("Setup dirs returning %d\n", result); - return result; -} -int __cdecl main(int argc, char **argv) -{ - int i; - BOOL bFailed = FALSE; - DWORD result; - - char * NormalDirectoryName = "normal_test_directory"; - char * ReadOnlyDirectoryName = "ro_test_directory"; - char * ReadWriteDirectoryName = "rw_directory"; - char * HiddenDirectoryName = ".hidden_directory"; - char * HiddenReadOnlyDirectoryName = ".hidden_ro_directory"; - char * NoDirectoryName = "no_directory"; - - char * NormalFileName = "normal_test_file"; - char * ReadOnlyFileName = "ro_test_file"; - char * ReadWriteFileName = "rw_file"; - char * HiddenFileName = ".hidden_file"; - char * HiddenReadOnlyFileName = ".hidden_ro_file"; - char * NotReallyAFileName = "not_really_a_file"; - - /* Tests on directory */ - gfaTestsDir[0].name = NormalDirectoryName; - gfaTestsDir[0].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; - gfaTestsDir[0].isFile = TYPE_DIR; - - gfaTestsDir[1].name = ReadOnlyDirectoryName; - gfaTestsDir[1].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | - FILE_ATTRIBUTE_READONLY; - gfaTestsDir[1].isFile = TYPE_DIR; - - gfaTestsDir[2].name = ReadWriteDirectoryName; - gfaTestsDir[2].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; - gfaTestsDir[2].isFile = TYPE_DIR; - - gfaTestsDir[3].name = HiddenDirectoryName; - gfaTestsDir[3].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; //| - //FILE_ATTRIBUTE_HIDDEN; - gfaTestsDir[3].isFile = TYPE_DIR; - - gfaTestsDir[4].name = HiddenReadOnlyDirectoryName; - gfaTestsDir[4].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | - FILE_ATTRIBUTE_READONLY; //| - //FILE_ATTRIBUTE_HIDDEN; - gfaTestsDir[4].isFile = TYPE_DIR; - - gfaTestsDir[5].name = NoDirectoryName; - gfaTestsDir[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; - gfaTestsDir[5].isFile = TYPE_DIR; - - /* Tests on file */ - gfaTestsFile[0].name = NormalFileName; - gfaTestsFile[0].expectedAttribs = FILE_ATTRIBUTE_NORMAL; - gfaTestsFile[0].isFile = TYPE_FILE; - - - gfaTestsFile[1].name = ReadOnlyFileName; - gfaTestsFile[1].expectedAttribs = FILE_ATTRIBUTE_READONLY; - gfaTestsFile[1].isFile = TYPE_FILE; - - gfaTestsFile[2].name = ReadWriteFileName; - gfaTestsFile[2].expectedAttribs = FILE_ATTRIBUTE_NORMAL; - gfaTestsFile[2].isFile = TYPE_FILE; - - gfaTestsFile[3].name = HiddenFileName; - gfaTestsFile[3].expectedAttribs = FILE_ATTRIBUTE_NORMAL; //FILE_ATTRIBUTE_HIDDEN; - gfaTestsFile[3].isFile = TYPE_FILE; - - gfaTestsFile[4].name = HiddenReadOnlyFileName; - gfaTestsFile[4].expectedAttribs = FILE_ATTRIBUTE_READONLY; //| - //FILE_ATTRIBUTE_HIDDEN; - gfaTestsFile[4].isFile = TYPE_FILE; - - - gfaTestsFile[5].name = NotReallyAFileName; - gfaTestsFile[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; - gfaTestsFile[5].isFile = TYPE_FILE; - - /* Initialize PAL environment */ - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - if(!CleanUpFiles()) - { - Fail("GetFileAttributesA: Pre-Clean Up Files Failed\n"); - } - - if(0 == SetUpFiles()) - { - Fail("GetFileAttributesA: SetUp Files Failed\n"); - } - - if(!CleanUpDirs()) - { - Fail("GetFileAttributesA: Pre-Clean Up Directories Failed\n"); - } - - if(!SetUpDirs()) - { - Fail("GetFileAttributesA: SetUp Directories Failed\n"); - } - - /* - * Go through all the test cases above, - * call GetFileAttributesA on the name and - * make sure the return value is the one expected - */ - for( i = 0; i < numFileTests; i++ ) - { - result = GetFileAttributesA(gfaTestsFile[i].name); - - if( result != gfaTestsFile[i].expectedAttribs ) - { - bFailed = TRUE; - - Trace("ERROR: GetFileAttributesA Test#%u on %s " - "returned %u instead of %u. \n", - i, - gfaTestsFile[i].name, - result, - gfaTestsFile[i].expectedAttribs); - - } - } - - - for( i = 0; i < numDirTests; i++ ) - { - result = GetFileAttributesA(gfaTestsDir[i].name); - - if( result != gfaTestsDir[i].expectedAttribs ) - { - bFailed = TRUE; - - Trace("ERROR: GetFileAttributesA on Directories Test#%u on %s " - "returned %u instead of %u. \n", - i, - gfaTestsDir[i].name, - result, - gfaTestsDir[i].expectedAttribs); - - } - } - - if(!CleanUpFiles()) - { - Fail("GetFileAttributesA: Post-Clean Up Files Failed\n"); - } - - if(!CleanUpDirs()) - { - Fail("GetFileAttributesA: Post-Clean Up Directories Failed\n"); - } - - /* If any errors, just call Fail() */ - if( bFailed ) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/GetFileAttributesA.cpp b/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/GetFileAttributesA.cpp new file mode 100644 index 0000000000..ff6bd0b8e0 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileAttributesA/test1/GetFileAttributesA.cpp @@ -0,0 +1,340 @@ +// 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: GetFileAttributesA.c +** +** Purpose: Tests the PAL implementation of the GetFileAttributesA function by +** checking the attributes of: +** - a normal directory and file +** - a read only directory and file +** - a read write directory and file +** - a hidden directory and file +** - a read only hidden directory and file +** - a directory and a file with no attributes +** - an invalid file name +** +** +**===========================================================================*/ +#include + +const int TYPE_DIR = 0; +const int TYPE_FILE = 1; +/* Structure defining a test case */ +typedef struct +{ + char *name; /* name of the file/directory */ + DWORD expectedAttribs; /* expected attributes */ + HANDLE hFile; /* Handle to the file */ + int isFile; /* is file (1) or dir (0) */ +}TestCaseFile; + +typedef struct +{ + char *name; /* name of the file/directory */ + DWORD expectedAttribs; /* expected attributes */ + HANDLE hFile; /* Handle to the file */ + int isFile; /* is file (1) or dir (0) */ +}TestCaseDir; + +DWORD desiredAccessFile = GENERIC_READ | GENERIC_WRITE; +DWORD shareModeFile = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE; +LPSECURITY_ATTRIBUTES lpAttrFile = NULL; +DWORD dwCreationDispFile = CREATE_NEW; +DWORD dwFlagsAttribFile = FILE_ATTRIBUTE_NORMAL; +HANDLE hTemplateFile = NULL; + +int numFileTests = 6; +TestCaseFile gfaTestsFile[6]; /* GetFileAttributes tests list */ + +int numDirTests = 6; +TestCaseDir gfaTestsDir[6]; /* GetFileAttributes tests list */ + +BOOL CleanUpFiles() +{ + DWORD dwAtt; + int i; + BOOL result = TRUE; + for (i = 0; i < numFileTests -1 ; i++ ) + { + dwAtt = GetFileAttributesA(gfaTestsFile[i].name); + + if( dwAtt != INVALID_FILE_ATTRIBUTES ) + { + //Trace("Files iteration %d\n", i); + if(!SetFileAttributesA (gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL); + } + + if(!DeleteFileA (gfaTestsFile[i].name)) + { + result = FALSE; + Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, dwAtt); + } + + } + } +// Trace("Value of result is %d\n", result); + return result; +} +BOOL SetUpFiles() +{ + int i = 0; + BOOL result = TRUE; + for (i = 0; i < numFileTests -1; i++ ) + { + gfaTestsFile[i].hFile = CreateFile(gfaTestsFile[i].name, + desiredAccessFile, + shareModeFile, + lpAttrFile, + dwCreationDispFile, + dwFlagsAttribFile, + hTemplateFile); + + if( gfaTestsFile[i].hFile == NULL ) + { + Fail("Error while creating files for iteration %d\n", i); + } + + if(!SetFileAttributesA (gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs); + } + } + + return result; +} + +BOOL CleanUpDirs() +{ + DWORD dwAtt; + int i; + BOOL result = TRUE; + for (i = 0; i < numDirTests -1 ; i++ ) + { + dwAtt = GetFileAttributesA(gfaTestsDir[i].name); + + if( dwAtt != INVALID_FILE_ATTRIBUTES ) + { + + if(!SetFileAttributesA (gfaTestsDir[i].name, FILE_ATTRIBUTE_DIRECTORY)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY)); + } + + if(!RemoveDirectoryA (gfaTestsDir[i].name)) + { + result = FALSE; + Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt); + } + + } + } + + return result; +} + +BOOL SetUpDirs() +{ + int i = 0; + BOOL result = TRUE; + DWORD ret = 0; + for (i = 0; i < numDirTests - 1 ; i++ ) + { + result = CreateDirectory(gfaTestsDir[i].name, + NULL); + + if(!result ) + { + result = FALSE; + Fail("Error while creating directory for iteration %d\n", i); + } + + if(!SetFileAttributesA (gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); + } + + ret = GetFileAttributesA (gfaTestsDir[i].name); + if(ret != gfaTestsDir[i].expectedAttribs) + { + result = FALSE; + Trace("ERROR: Error setting attributes [%s][%d]\n", gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); + } + //Trace("Setup Dir setting attr [%d], returned [%d]\n", gfaTestsDir[i].expectedAttribs, ret); + + } + //Trace("Setup dirs returning %d\n", result); + return result; +} +int __cdecl main(int argc, char **argv) +{ + int i; + BOOL bFailed = FALSE; + DWORD result; + + char * NormalDirectoryName = "normal_test_directory"; + char * ReadOnlyDirectoryName = "ro_test_directory"; + char * ReadWriteDirectoryName = "rw_directory"; + char * HiddenDirectoryName = ".hidden_directory"; + char * HiddenReadOnlyDirectoryName = ".hidden_ro_directory"; + char * NoDirectoryName = "no_directory"; + + char * NormalFileName = "normal_test_file"; + char * ReadOnlyFileName = "ro_test_file"; + char * ReadWriteFileName = "rw_file"; + char * HiddenFileName = ".hidden_file"; + char * HiddenReadOnlyFileName = ".hidden_ro_file"; + char * NotReallyAFileName = "not_really_a_file"; + + /* Tests on directory */ + gfaTestsDir[0].name = NormalDirectoryName; + gfaTestsDir[0].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; + gfaTestsDir[0].isFile = TYPE_DIR; + + gfaTestsDir[1].name = ReadOnlyDirectoryName; + gfaTestsDir[1].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | + FILE_ATTRIBUTE_READONLY; + gfaTestsDir[1].isFile = TYPE_DIR; + + gfaTestsDir[2].name = ReadWriteDirectoryName; + gfaTestsDir[2].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; + gfaTestsDir[2].isFile = TYPE_DIR; + + gfaTestsDir[3].name = HiddenDirectoryName; + gfaTestsDir[3].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; //| + //FILE_ATTRIBUTE_HIDDEN; + gfaTestsDir[3].isFile = TYPE_DIR; + + gfaTestsDir[4].name = HiddenReadOnlyDirectoryName; + gfaTestsDir[4].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | + FILE_ATTRIBUTE_READONLY; //| + //FILE_ATTRIBUTE_HIDDEN; + gfaTestsDir[4].isFile = TYPE_DIR; + + gfaTestsDir[5].name = NoDirectoryName; + gfaTestsDir[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; + gfaTestsDir[5].isFile = TYPE_DIR; + + /* Tests on file */ + gfaTestsFile[0].name = NormalFileName; + gfaTestsFile[0].expectedAttribs = FILE_ATTRIBUTE_NORMAL; + gfaTestsFile[0].isFile = TYPE_FILE; + + + gfaTestsFile[1].name = ReadOnlyFileName; + gfaTestsFile[1].expectedAttribs = FILE_ATTRIBUTE_READONLY; + gfaTestsFile[1].isFile = TYPE_FILE; + + gfaTestsFile[2].name = ReadWriteFileName; + gfaTestsFile[2].expectedAttribs = FILE_ATTRIBUTE_NORMAL; + gfaTestsFile[2].isFile = TYPE_FILE; + + gfaTestsFile[3].name = HiddenFileName; + gfaTestsFile[3].expectedAttribs = FILE_ATTRIBUTE_NORMAL; //FILE_ATTRIBUTE_HIDDEN; + gfaTestsFile[3].isFile = TYPE_FILE; + + gfaTestsFile[4].name = HiddenReadOnlyFileName; + gfaTestsFile[4].expectedAttribs = FILE_ATTRIBUTE_READONLY; //| + //FILE_ATTRIBUTE_HIDDEN; + gfaTestsFile[4].isFile = TYPE_FILE; + + + gfaTestsFile[5].name = NotReallyAFileName; + gfaTestsFile[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; + gfaTestsFile[5].isFile = TYPE_FILE; + + /* Initialize PAL environment */ + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + if(!CleanUpFiles()) + { + Fail("GetFileAttributesA: Pre-Clean Up Files Failed\n"); + } + + if(0 == SetUpFiles()) + { + Fail("GetFileAttributesA: SetUp Files Failed\n"); + } + + if(!CleanUpDirs()) + { + Fail("GetFileAttributesA: Pre-Clean Up Directories Failed\n"); + } + + if(!SetUpDirs()) + { + Fail("GetFileAttributesA: SetUp Directories Failed\n"); + } + + /* + * Go through all the test cases above, + * call GetFileAttributesA on the name and + * make sure the return value is the one expected + */ + for( i = 0; i < numFileTests; i++ ) + { + result = GetFileAttributesA(gfaTestsFile[i].name); + + if( result != gfaTestsFile[i].expectedAttribs ) + { + bFailed = TRUE; + + Trace("ERROR: GetFileAttributesA Test#%u on %s " + "returned %u instead of %u. \n", + i, + gfaTestsFile[i].name, + result, + gfaTestsFile[i].expectedAttribs); + + } + } + + + for( i = 0; i < numDirTests; i++ ) + { + result = GetFileAttributesA(gfaTestsDir[i].name); + + if( result != gfaTestsDir[i].expectedAttribs ) + { + bFailed = TRUE; + + Trace("ERROR: GetFileAttributesA on Directories Test#%u on %s " + "returned %u instead of %u. \n", + i, + gfaTestsDir[i].name, + result, + gfaTestsDir[i].expectedAttribs); + + } + } + + if(!CleanUpFiles()) + { + Fail("GetFileAttributesA: Post-Clean Up Files Failed\n"); + } + + if(!CleanUpDirs()) + { + Fail("GetFileAttributesA: Post-Clean Up Directories Failed\n"); + } + + /* If any errors, just call Fail() */ + if( bFailed ) + { + Fail(""); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/CMakeLists.txt index 2d299d82e5..6ea24d9d32 100644 --- a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getfileattributesexw_test1 diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/test1.c b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/test1.c deleted file mode 100644 index 7a622b628c..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/test1.c +++ /dev/null @@ -1,227 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests the PAL implementation of the GetFileAttributesExW function. -** Call the function on a normal directory and file and a read-only directory -** and file and a hidden file and directory. -** Ensure that the attributes returned are correct, and the -** file times and file sizes. -** -** -**===================================================================*/ - -#define UNICODE -#include - -typedef enum Item -{ - IS_DIR, - IS_FILE -}ItemType; - -/* - This is a helper function which takes two FILETIME structures and - checks to see if they contain the exact same time. -*/ -int IsEqualFileTime(FILETIME FirstTime, FILETIME SecondTime) -{ - - ULONG64 TimeOne, TimeTwo; - - TimeOne = ((((ULONG64)FirstTime.dwHighDateTime)<<32) | - ((ULONG64)FirstTime.dwLowDateTime)); - - TimeTwo = ((((ULONG64)SecondTime.dwHighDateTime)<<32) | - ((ULONG64)SecondTime.dwLowDateTime)); - - return(TimeOne == TimeTwo); -} - -/* This function takes a structure and checks that the information - within the structure is correct. The 'Attribs' are the expected - file attributes, 'TheType' is IS_DIR or IS_FILE and the 'Name' is the - name of the file/directory in question. -*/ -void VerifyInfo(WIN32_FILE_ATTRIBUTE_DATA InfoStruct, - DWORD Attribs, ItemType TheType, WCHAR* Name) -{ - HANDLE hFile; - FILETIME CorrectCreation, CorrectAccess, CorrectModify; - WCHAR CopyName[64]; - - wcscpy(CopyName,Name); - free(Name); - - /* Check to see that the file attributes were recorded */ - if(InfoStruct.dwFileAttributes != Attribs) - { - Fail("ERROR: The file attributes on the file/directory were " - "recorded as being %d instead of %d.\n", - InfoStruct.dwFileAttributes, - Attribs); - } - - /* Note: We can't open a handle to a directory in windows. This - block of tests will only be run on files. - */ - if(TheType == IS_FILE) - { - - /* Get a handle to the file */ - hFile = CreateFile(CopyName, - 0, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open a handle to the file " - "'%S'. GetLastError() returned %d.",CopyName, - GetLastError()); - } - - - - /* Get the FileTime of the file in question */ - if(GetFileTime(hFile, &CorrectCreation, - &CorrectAccess, &CorrectModify) == 0) - { - Fail("ERROR: GetFileTime failed to get the filetime of the " - "file. GetLastError() returned %d.", - GetLastError()); - } - - /* Check that the Creation, Access and Last Modified times are all - the same in the structure as what GetFileTime just returned. - */ - if(!IsEqualFileTime(CorrectCreation, InfoStruct.ftCreationTime)) - { - Fail("ERROR: The creation time of the file " - "does not match the creation time given from " - "GetFileTime.\n"); - } - if(!IsEqualFileTime(CorrectAccess, InfoStruct.ftLastAccessTime)) - { - Fail("ERROR: The access time of the file " - "does not match the access time given from " - "GetFileTime.\n"); - } - if(!IsEqualFileTime(CorrectModify, InfoStruct.ftLastWriteTime)) - { - Fail("ERROR: The write time of the file " - "does not match the last write time given from " - "GetFileTime.\n"); - } - - if(InfoStruct.nFileSizeLow != GetFileSize(hFile,NULL)) - { - Fail("ERROR: The file size reported by GetFileAttributesEx " - "did not match the file size given by GetFileSize.\n"); - } - - if(CloseHandle(hFile) == 0) - { - Fail("ERROR: Failed to properly close the handle to the " - "file we're testing. GetLastError() returned %d.\n", - GetLastError()); - - } - - } - - -} - -/* Given a file/directory name, the expected attribs and whether or not it - is a file or directory, call GetFileAttributesEx and verify the - results are correct. -*/ - -void RunTest(char* Name, DWORD Attribs, ItemType TheType ) -{ - WCHAR* TheName; - WIN32_FILE_ATTRIBUTE_DATA InfoStruct; - DWORD TheResult; - - TheName = convert(Name); - - TheResult = GetFileAttributesEx(TheName, - GetFileExInfoStandard, - &InfoStruct); - if(TheResult == 0) - { - free(TheName); - Fail("ERROR: GetFileAttributesEx returned 0, indicating failure. " - "GetLastError returned %d.\n",GetLastError()); - } - - VerifyInfo(InfoStruct, Attribs, TheType, TheName); - -} - -int __cdecl main(int argc, char **argv) -{ - DWORD TheResult; - WCHAR* FileName; - WIN32_FILE_ATTRIBUTE_DATA InfoStruct; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Test a Directroy */ - RunTest("normal_test_directory", FILE_ATTRIBUTE_DIRECTORY, IS_DIR); - - - /* Test a Normal File */ - - RunTest("normal_test_file", FILE_ATTRIBUTE_NORMAL, IS_FILE); - - /* Test a Read-Only Directroy */ - - RunTest("ro_test_directory", - FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_DIRECTORY, IS_DIR); - - /* Test a Read-Only File */ - - RunTest("ro_test_file", FILE_ATTRIBUTE_READONLY, IS_FILE); - - /* Test a Hidden File */ - - RunTest(".hidden_file", FILE_ATTRIBUTE_HIDDEN, IS_FILE); - - /* Test a Hidden Directroy */ - - RunTest(".hidden_directory", - FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_DIRECTORY, IS_DIR); - - /* Test a Non-Existant File */ - - FileName = convert("nonexistent_test_file"); - - TheResult = GetFileAttributesEx(FileName, - GetFileExInfoStandard, - &InfoStruct); - - if(TheResult != 0) - { - free(FileName); - Fail("ERROR: GetFileAttributesEx returned non-zero, indicating " - "success when it should have failed. It was called on a " - "non-existent file."); - } - - free(FileName); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/test1.cpp b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/test1.cpp new file mode 100644 index 0000000000..7a622b628c --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test1/test1.cpp @@ -0,0 +1,227 @@ +// 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: test1.c +** +** Purpose: Tests the PAL implementation of the GetFileAttributesExW function. +** Call the function on a normal directory and file and a read-only directory +** and file and a hidden file and directory. +** Ensure that the attributes returned are correct, and the +** file times and file sizes. +** +** +**===================================================================*/ + +#define UNICODE +#include + +typedef enum Item +{ + IS_DIR, + IS_FILE +}ItemType; + +/* + This is a helper function which takes two FILETIME structures and + checks to see if they contain the exact same time. +*/ +int IsEqualFileTime(FILETIME FirstTime, FILETIME SecondTime) +{ + + ULONG64 TimeOne, TimeTwo; + + TimeOne = ((((ULONG64)FirstTime.dwHighDateTime)<<32) | + ((ULONG64)FirstTime.dwLowDateTime)); + + TimeTwo = ((((ULONG64)SecondTime.dwHighDateTime)<<32) | + ((ULONG64)SecondTime.dwLowDateTime)); + + return(TimeOne == TimeTwo); +} + +/* This function takes a structure and checks that the information + within the structure is correct. The 'Attribs' are the expected + file attributes, 'TheType' is IS_DIR or IS_FILE and the 'Name' is the + name of the file/directory in question. +*/ +void VerifyInfo(WIN32_FILE_ATTRIBUTE_DATA InfoStruct, + DWORD Attribs, ItemType TheType, WCHAR* Name) +{ + HANDLE hFile; + FILETIME CorrectCreation, CorrectAccess, CorrectModify; + WCHAR CopyName[64]; + + wcscpy(CopyName,Name); + free(Name); + + /* Check to see that the file attributes were recorded */ + if(InfoStruct.dwFileAttributes != Attribs) + { + Fail("ERROR: The file attributes on the file/directory were " + "recorded as being %d instead of %d.\n", + InfoStruct.dwFileAttributes, + Attribs); + } + + /* Note: We can't open a handle to a directory in windows. This + block of tests will only be run on files. + */ + if(TheType == IS_FILE) + { + + /* Get a handle to the file */ + hFile = CreateFile(CopyName, + 0, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open a handle to the file " + "'%S'. GetLastError() returned %d.",CopyName, + GetLastError()); + } + + + + /* Get the FileTime of the file in question */ + if(GetFileTime(hFile, &CorrectCreation, + &CorrectAccess, &CorrectModify) == 0) + { + Fail("ERROR: GetFileTime failed to get the filetime of the " + "file. GetLastError() returned %d.", + GetLastError()); + } + + /* Check that the Creation, Access and Last Modified times are all + the same in the structure as what GetFileTime just returned. + */ + if(!IsEqualFileTime(CorrectCreation, InfoStruct.ftCreationTime)) + { + Fail("ERROR: The creation time of the file " + "does not match the creation time given from " + "GetFileTime.\n"); + } + if(!IsEqualFileTime(CorrectAccess, InfoStruct.ftLastAccessTime)) + { + Fail("ERROR: The access time of the file " + "does not match the access time given from " + "GetFileTime.\n"); + } + if(!IsEqualFileTime(CorrectModify, InfoStruct.ftLastWriteTime)) + { + Fail("ERROR: The write time of the file " + "does not match the last write time given from " + "GetFileTime.\n"); + } + + if(InfoStruct.nFileSizeLow != GetFileSize(hFile,NULL)) + { + Fail("ERROR: The file size reported by GetFileAttributesEx " + "did not match the file size given by GetFileSize.\n"); + } + + if(CloseHandle(hFile) == 0) + { + Fail("ERROR: Failed to properly close the handle to the " + "file we're testing. GetLastError() returned %d.\n", + GetLastError()); + + } + + } + + +} + +/* Given a file/directory name, the expected attribs and whether or not it + is a file or directory, call GetFileAttributesEx and verify the + results are correct. +*/ + +void RunTest(char* Name, DWORD Attribs, ItemType TheType ) +{ + WCHAR* TheName; + WIN32_FILE_ATTRIBUTE_DATA InfoStruct; + DWORD TheResult; + + TheName = convert(Name); + + TheResult = GetFileAttributesEx(TheName, + GetFileExInfoStandard, + &InfoStruct); + if(TheResult == 0) + { + free(TheName); + Fail("ERROR: GetFileAttributesEx returned 0, indicating failure. " + "GetLastError returned %d.\n",GetLastError()); + } + + VerifyInfo(InfoStruct, Attribs, TheType, TheName); + +} + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + WCHAR* FileName; + WIN32_FILE_ATTRIBUTE_DATA InfoStruct; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Test a Directroy */ + RunTest("normal_test_directory", FILE_ATTRIBUTE_DIRECTORY, IS_DIR); + + + /* Test a Normal File */ + + RunTest("normal_test_file", FILE_ATTRIBUTE_NORMAL, IS_FILE); + + /* Test a Read-Only Directroy */ + + RunTest("ro_test_directory", + FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_DIRECTORY, IS_DIR); + + /* Test a Read-Only File */ + + RunTest("ro_test_file", FILE_ATTRIBUTE_READONLY, IS_FILE); + + /* Test a Hidden File */ + + RunTest(".hidden_file", FILE_ATTRIBUTE_HIDDEN, IS_FILE); + + /* Test a Hidden Directroy */ + + RunTest(".hidden_directory", + FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_DIRECTORY, IS_DIR); + + /* Test a Non-Existant File */ + + FileName = convert("nonexistent_test_file"); + + TheResult = GetFileAttributesEx(FileName, + GetFileExInfoStandard, + &InfoStruct); + + if(TheResult != 0) + { + free(FileName); + Fail("ERROR: GetFileAttributesEx returned non-zero, indicating " + "success when it should have failed. It was called on a " + "non-existent file."); + } + + free(FileName); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/CMakeLists.txt index 70caac2c69..0faa3bd11e 100644 --- a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_getfileattributesexw_test2 diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/test2.c b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/test2.c deleted file mode 100644 index f244a3bf6a..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/test2.c +++ /dev/null @@ -1,170 +0,0 @@ -// 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: getfileattributesexw.c (getfileattributesexw\test2) -** -** Purpose: Tests the PAL implementation of GetFileAttributesExW. -** First get a file's attributes, modify the file, -** re-get its attributes -** and compare the two sets of attributes. -** -** -**===================================================================*/ -#include - -/** - * This is a helper function which takes two FILETIME structures and - * checks that the second time isn't before the first. - */ -static int IsFileTimeOk(FILETIME FirstTime, FILETIME SecondTime) -{ - - ULONG64 TimeOne, TimeTwo; - - TimeOne = ((((ULONG64)FirstTime.dwHighDateTime)<<32) | - ((ULONG64)FirstTime.dwLowDateTime)); - - TimeTwo = ((((ULONG64)SecondTime.dwHighDateTime)<<32) | - ((ULONG64)SecondTime.dwLowDateTime)); - - return(TimeOne <= TimeTwo); -} - -int __cdecl main(int argc, char **argv) -{ - DWORD res; - char fileName[MAX_PATH] = "test_file"; - WCHAR *wFileName; - WIN32_FILE_ATTRIBUTE_DATA beforeAttribs; - WIN32_FILE_ATTRIBUTE_DATA afterAttribs; - FILE *testFile; - ULONG64 beforeFileSize; - ULONG64 afterFileSize; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Create the file */ - testFile = fopen(fileName, "w+"); - if( NULL == testFile ) - { - Fail("Unexpected error: Unable to open file %S " - "with fopen. \n", - fileName); - } - - if( EOF == fputs( "testing", testFile ) ) - { - Fail("Unexpected error: Unable to write to file %S " - "with fputs. \n", - fileName); - } - - if( 0 != fclose(testFile) ) - { - Fail("Unexpected error: Unable to close file %S " - "with fclose. \n", - fileName); - } - - /* Test the Values returned by GetFileAttributesExW - * before and after manipulating a file shouldn't be the same. - */ - - wFileName = convert(fileName); - - res = GetFileAttributesExW(wFileName, - GetFileExInfoStandard, - &beforeAttribs); - - if(res == 0) - { - Fail("ERROR: unable to get initial file attributes with " - "GetFileAttributesEx that returned 0 with error %d.\n", - GetLastError()); - } - - /* Make sure the time are different */ - Sleep(500); - - testFile = fopen(fileName, "w+"); - if( NULL == testFile ) - { - Fail("Unexpected error: Unable to open file %S " - "with fopen. \n", - fileName); - } - - if( EOF == fputs( "testing GetFileAttributesExW", testFile ) ) - { - Fail("Unexpected error: Unable to write to file %S " - "with fputs. \n", - fileName); - } - - if( 0 != fclose(testFile) ) - { - Fail("Unexpected error: Unable to close file %S " - "with fclose. \n", - fileName); - } - - res = GetFileAttributesExW(wFileName, - GetFileExInfoStandard, - &afterAttribs); - - if(res == 0) - { - Fail("ERROR: unable to get file attributes after operations with " - "GetFileAttributesEx that returned 0 with error %d.\n", - GetLastError()); - } - - /* Check the creation time */ - if(!IsFileTimeOk(beforeAttribs.ftCreationTime, - afterAttribs.ftCreationTime)) - { - Fail("ERROR: Creation time after the fputs operation " - "is earlier than the creation time before the fputs.\n"); - } - - /* Check the last access time */ - if(!IsFileTimeOk(beforeAttribs.ftLastAccessTime, - afterAttribs.ftLastAccessTime)) - { - Fail("ERROR: Last access time after the fputs operation " - "is earlier than the last access time before the fputs.\n"); - } - - /* Check the last write time */ - if(!IsFileTimeOk(beforeAttribs.ftLastWriteTime, - afterAttribs.ftLastWriteTime)) - { - Fail("ERROR: Last write time after the fputs operation " - "is earlier than the last write time before the fputs.\n"); - } - - beforeFileSize = ((ULONG64)beforeAttribs.nFileSizeHigh)<< 32 | - ((ULONG64)beforeAttribs.nFileSizeLow); - - afterFileSize = ((ULONG64)afterAttribs.nFileSizeHigh)<< 32 | - ((ULONG64)afterAttribs.nFileSizeLow); - - /* Check the file size */ - if( afterFileSize <= beforeFileSize ) - { - Fail("ERROR: the file should have had a bigger size " - "after(%d) the operations than before(%d)\n", - afterAttribs.nFileSizeLow, - beforeAttribs.nFileSizeLow); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/test2.cpp b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/test2.cpp new file mode 100644 index 0000000000..f244a3bf6a --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileAttributesExW/test2/test2.cpp @@ -0,0 +1,170 @@ +// 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: getfileattributesexw.c (getfileattributesexw\test2) +** +** Purpose: Tests the PAL implementation of GetFileAttributesExW. +** First get a file's attributes, modify the file, +** re-get its attributes +** and compare the two sets of attributes. +** +** +**===================================================================*/ +#include + +/** + * This is a helper function which takes two FILETIME structures and + * checks that the second time isn't before the first. + */ +static int IsFileTimeOk(FILETIME FirstTime, FILETIME SecondTime) +{ + + ULONG64 TimeOne, TimeTwo; + + TimeOne = ((((ULONG64)FirstTime.dwHighDateTime)<<32) | + ((ULONG64)FirstTime.dwLowDateTime)); + + TimeTwo = ((((ULONG64)SecondTime.dwHighDateTime)<<32) | + ((ULONG64)SecondTime.dwLowDateTime)); + + return(TimeOne <= TimeTwo); +} + +int __cdecl main(int argc, char **argv) +{ + DWORD res; + char fileName[MAX_PATH] = "test_file"; + WCHAR *wFileName; + WIN32_FILE_ATTRIBUTE_DATA beforeAttribs; + WIN32_FILE_ATTRIBUTE_DATA afterAttribs; + FILE *testFile; + ULONG64 beforeFileSize; + ULONG64 afterFileSize; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Create the file */ + testFile = fopen(fileName, "w+"); + if( NULL == testFile ) + { + Fail("Unexpected error: Unable to open file %S " + "with fopen. \n", + fileName); + } + + if( EOF == fputs( "testing", testFile ) ) + { + Fail("Unexpected error: Unable to write to file %S " + "with fputs. \n", + fileName); + } + + if( 0 != fclose(testFile) ) + { + Fail("Unexpected error: Unable to close file %S " + "with fclose. \n", + fileName); + } + + /* Test the Values returned by GetFileAttributesExW + * before and after manipulating a file shouldn't be the same. + */ + + wFileName = convert(fileName); + + res = GetFileAttributesExW(wFileName, + GetFileExInfoStandard, + &beforeAttribs); + + if(res == 0) + { + Fail("ERROR: unable to get initial file attributes with " + "GetFileAttributesEx that returned 0 with error %d.\n", + GetLastError()); + } + + /* Make sure the time are different */ + Sleep(500); + + testFile = fopen(fileName, "w+"); + if( NULL == testFile ) + { + Fail("Unexpected error: Unable to open file %S " + "with fopen. \n", + fileName); + } + + if( EOF == fputs( "testing GetFileAttributesExW", testFile ) ) + { + Fail("Unexpected error: Unable to write to file %S " + "with fputs. \n", + fileName); + } + + if( 0 != fclose(testFile) ) + { + Fail("Unexpected error: Unable to close file %S " + "with fclose. \n", + fileName); + } + + res = GetFileAttributesExW(wFileName, + GetFileExInfoStandard, + &afterAttribs); + + if(res == 0) + { + Fail("ERROR: unable to get file attributes after operations with " + "GetFileAttributesEx that returned 0 with error %d.\n", + GetLastError()); + } + + /* Check the creation time */ + if(!IsFileTimeOk(beforeAttribs.ftCreationTime, + afterAttribs.ftCreationTime)) + { + Fail("ERROR: Creation time after the fputs operation " + "is earlier than the creation time before the fputs.\n"); + } + + /* Check the last access time */ + if(!IsFileTimeOk(beforeAttribs.ftLastAccessTime, + afterAttribs.ftLastAccessTime)) + { + Fail("ERROR: Last access time after the fputs operation " + "is earlier than the last access time before the fputs.\n"); + } + + /* Check the last write time */ + if(!IsFileTimeOk(beforeAttribs.ftLastWriteTime, + afterAttribs.ftLastWriteTime)) + { + Fail("ERROR: Last write time after the fputs operation " + "is earlier than the last write time before the fputs.\n"); + } + + beforeFileSize = ((ULONG64)beforeAttribs.nFileSizeHigh)<< 32 | + ((ULONG64)beforeAttribs.nFileSizeLow); + + afterFileSize = ((ULONG64)afterAttribs.nFileSizeHigh)<< 32 | + ((ULONG64)afterAttribs.nFileSizeLow); + + /* Check the file size */ + if( afterFileSize <= beforeFileSize ) + { + Fail("ERROR: the file should have had a bigger size " + "after(%d) the operations than before(%d)\n", + afterAttribs.nFileSizeLow, + beforeAttribs.nFileSizeLow); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/CMakeLists.txt index 7050484607..bc82f3678e 100644 --- a/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFileAttributesW.c + GetFileAttributesW.cpp ) add_executable(paltest_getfileattributesw_test1 diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/GetFileAttributesW.c b/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/GetFileAttributesW.c deleted file mode 100644 index 9d00da4bd4..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/GetFileAttributesW.c +++ /dev/null @@ -1,345 +0,0 @@ -// 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: GetFileAttributesW.c -** -** Purpose: Tests the PAL implementation of the GetFileAttributesW function by -** checking the attributes of: -** - a normal directory and file -** - a read only directory and file -** - a read write directory and file -** - a hidden directory and file -** - a read only hidden directory and file -** - a directory and a file with no attributes -** - an invalid file name -** -** -**===========================================================================*/ -#include - -const int TYPE_DIR = 0; -const int TYPE_FILE = 1; -/* Structure defining a test case */ -typedef struct -{ - char *name; /* name of the file/directory */ - DWORD expectedAttribs; /* expected attributes */ - HANDLE hFile; /* Handle to the file */ - int isFile; /* is file (1) or dir (0) */ -}TestCaseFile; - -typedef struct -{ - char *name; /* name of the file/directory */ - DWORD expectedAttribs; /* expected attributes */ - HANDLE hFile; /* Handle to the file */ - int isFile; /* is file (1) or dir (0) */ -}TestCaseDir; - -DWORD desiredAccessFile = GENERIC_READ | GENERIC_WRITE; -DWORD shareModeFile = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE; -LPSECURITY_ATTRIBUTES lpAttrFile = NULL; -DWORD dwCreationDispFile = CREATE_NEW; -DWORD dwFlagsAttribFile = FILE_ATTRIBUTE_NORMAL; -HANDLE hTemplateFile = NULL; - -int numFileTests = 6; -TestCaseFile gfaTestsFile[6]; /* GetFileAttributes tests list */ - -int numDirTests = 6; -TestCaseDir gfaTestsDir[6]; /* GetFileAttributes tests list */ - -BOOL CleanUpFiles() -{ - DWORD dwAtt; - int i; - BOOL result = TRUE; - for (i = 0; i < numFileTests - 1 ; i++ ) - { - dwAtt = GetFileAttributesA(gfaTestsFile[i].name); - - if( dwAtt != INVALID_FILE_ATTRIBUTES ) - { - //Trace("Files iteration %d\n", i); - if(!SetFileAttributesA (gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL); - } - - if(!DeleteFileA (gfaTestsFile[i].name)) - { - result = FALSE; - Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, dwAtt); - } - - } - } -// Trace("Value of result is %d\n", result); - return result; -} -BOOL SetUpFiles() -{ - int i = 0; - BOOL result = TRUE; - for (i = 0; i < numFileTests - 1 ; i++ ) - { - gfaTestsFile[i].hFile = CreateFile(gfaTestsFile[i].name, - desiredAccessFile, - shareModeFile, - lpAttrFile, - dwCreationDispFile, - dwFlagsAttribFile, - hTemplateFile); - - if( gfaTestsFile[i].hFile == NULL ) - { - Fail("Error while creating files for iteration %d\n", i); - } - - if(!SetFileAttributesA (gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs); - } - } - - return result; -} - -BOOL CleanUpDirs() -{ - DWORD dwAtt; - int i; - BOOL result = TRUE; - for (i = 0; i < numDirTests - 1; i++ ) - { - dwAtt = GetFileAttributesA(gfaTestsDir[i].name); - - if( dwAtt != INVALID_FILE_ATTRIBUTES ) - { - - if(!SetFileAttributesA (gfaTestsDir[i].name, FILE_ATTRIBUTE_DIRECTORY)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY)); - } - - if(!RemoveDirectoryA (gfaTestsDir[i].name)) - { - result = FALSE; - Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt); - } - - } - } - - return result; -} - -BOOL SetUpDirs() -{ - int i = 0; - BOOL result = TRUE; - DWORD ret = 0; - for (i = 0; i < numDirTests - 1; i++ ) - { - result = CreateDirectory(gfaTestsDir[i].name, - NULL); - - if(!result ) - { - result = FALSE; - Fail("Error while creating directory for iteration %d\n", i); - } - - if(!SetFileAttributesA (gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs)) - { - result = FALSE; - Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); - } - - ret = GetFileAttributesA (gfaTestsDir[i].name); - if(ret != gfaTestsDir[i].expectedAttribs) - { - result = FALSE; - Trace("ERROR: Error setting attributes [%s][%d]\n", gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); - } - // Trace("Setup Dir setting attr [%d], returned [%d]\n", gfaTestsDir[i].expectedAttribs, ret); - - } -// Trace("Setup dirs returning %d\n", result); - return result; -} -int __cdecl main(int argc, char **argv) -{ - int i; - BOOL bFailed = FALSE; - DWORD result; - - char * NormalDirectoryName = "normal_test_directory"; - char * ReadOnlyDirectoryName = "ro_test_directory"; - char * ReadWriteDirectoryName = "rw_directory"; - char * HiddenDirectoryName = ".hidden_directory"; - char * HiddenReadOnlyDirectoryName = ".hidden_ro_directory"; - char * NoDirectoryName = "no_directory"; - - char * NormalFileName = "normal_test_file"; - char * ReadOnlyFileName = "ro_test_file"; - char * ReadWriteFileName = "rw_file"; - char * HiddenFileName = ".hidden_file"; - char * HiddenReadOnlyFileName = ".hidden_ro_file"; - char * NotReallyAFileName = "not_really_a_file"; - - WCHAR *WStr; - /* Tests on directory */ - gfaTestsDir[0].name = NormalDirectoryName; - gfaTestsDir[0].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; - gfaTestsDir[0].isFile = TYPE_DIR; - - gfaTestsDir[1].name = ReadOnlyDirectoryName; - gfaTestsDir[1].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | - FILE_ATTRIBUTE_READONLY; - gfaTestsDir[1].isFile = TYPE_DIR; - - gfaTestsDir[2].name = ReadWriteDirectoryName; - gfaTestsDir[2].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; - gfaTestsDir[2].isFile = TYPE_DIR; - - gfaTestsDir[3].name = HiddenDirectoryName; - gfaTestsDir[3].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; //| - //FILE_ATTRIBUTE_HIDDEN; - gfaTestsDir[3].isFile = TYPE_DIR; - - gfaTestsDir[4].name = HiddenReadOnlyDirectoryName; - gfaTestsDir[4].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | - FILE_ATTRIBUTE_READONLY; //| - //FILE_ATTRIBUTE_HIDDEN; - gfaTestsDir[4].isFile = TYPE_DIR; - - gfaTestsDir[5].name = NoDirectoryName; - gfaTestsDir[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; - gfaTestsDir[5].isFile = TYPE_DIR; - - /* Tests on file */ - gfaTestsFile[0].name = NormalFileName; - gfaTestsFile[0].expectedAttribs = FILE_ATTRIBUTE_NORMAL; - gfaTestsFile[0].isFile = TYPE_FILE; - - - gfaTestsFile[1].name = ReadOnlyFileName; - gfaTestsFile[1].expectedAttribs = FILE_ATTRIBUTE_READONLY; - gfaTestsFile[1].isFile = TYPE_FILE; - - gfaTestsFile[2].name = ReadWriteFileName; - gfaTestsFile[2].expectedAttribs = FILE_ATTRIBUTE_NORMAL; - gfaTestsFile[2].isFile = TYPE_FILE; - - gfaTestsFile[3].name = HiddenFileName; - gfaTestsFile[3].expectedAttribs = FILE_ATTRIBUTE_NORMAL; //FILE_ATTRIBUTE_HIDDEN; - gfaTestsFile[3].isFile = TYPE_FILE; - - gfaTestsFile[4].name = HiddenReadOnlyFileName; - gfaTestsFile[4].expectedAttribs = FILE_ATTRIBUTE_READONLY; //| - //FILE_ATTRIBUTE_HIDDEN; - gfaTestsFile[4].isFile = TYPE_FILE; - - - gfaTestsFile[5].name = NotReallyAFileName; - gfaTestsFile[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; - gfaTestsFile[5].isFile = TYPE_FILE; - - /* Initialize PAL environment */ - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - if(!CleanUpFiles()) - { - Fail("GetFileAttributesW: Pre-Clean Up Files Failed\n"); - } - - if(0 == SetUpFiles()) - { - Fail("GetFileAttributesW: SetUp Files Failed\n"); - } - - if(!CleanUpDirs()) - { - Fail("GetFileAttributesW: Pre-Clean Up Directories Failed\n"); - } - - if(!SetUpDirs()) - { - Fail("GetFileAttributesW: SetUp Directories Failed\n"); - } - - /* - * Go through all the test cases above, - * call GetFileAttributesW on the name and - * make sure the return value is the one expected - */ - for( i = 0; i < numFileTests; i++ ) - { - WStr = convert(gfaTestsFile[i].name); - result = GetFileAttributesW(WStr); - - if( result != gfaTestsFile[i].expectedAttribs ) - { - bFailed = TRUE; - - Trace("ERROR: GetFileAttributesW Test#%u on %s " - "returned %u instead of %u. \n", - i, - gfaTestsFile[i].name, - result, - gfaTestsFile[i].expectedAttribs); - - } - free(WStr); - } - - - for( i = 0; i < numDirTests; i++ ) - { - WStr = convert(gfaTestsDir[i].name); - result = GetFileAttributesW(WStr); - - if( result != gfaTestsDir[i].expectedAttribs ) - { - bFailed = TRUE; - - Trace("ERROR: GetFileAttributesW on Directories Test#%u on %s " - "returned %u instead of %u. \n", - i, - gfaTestsDir[i].name, - result, - gfaTestsDir[i].expectedAttribs); - - } - free(WStr); - } - - if(!CleanUpFiles()) - { - Fail("GetFileAttributesW: Post-Clean Up Files Failed\n"); - } - - if(!CleanUpDirs()) - { - Fail("GetFileAttributesW: Post-Clean Up Directories Failed\n"); - } - - /* If any errors, just call Fail() */ - if( bFailed ) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/GetFileAttributesW.cpp b/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/GetFileAttributesW.cpp new file mode 100644 index 0000000000..9d00da4bd4 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileAttributesW/test1/GetFileAttributesW.cpp @@ -0,0 +1,345 @@ +// 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: GetFileAttributesW.c +** +** Purpose: Tests the PAL implementation of the GetFileAttributesW function by +** checking the attributes of: +** - a normal directory and file +** - a read only directory and file +** - a read write directory and file +** - a hidden directory and file +** - a read only hidden directory and file +** - a directory and a file with no attributes +** - an invalid file name +** +** +**===========================================================================*/ +#include + +const int TYPE_DIR = 0; +const int TYPE_FILE = 1; +/* Structure defining a test case */ +typedef struct +{ + char *name; /* name of the file/directory */ + DWORD expectedAttribs; /* expected attributes */ + HANDLE hFile; /* Handle to the file */ + int isFile; /* is file (1) or dir (0) */ +}TestCaseFile; + +typedef struct +{ + char *name; /* name of the file/directory */ + DWORD expectedAttribs; /* expected attributes */ + HANDLE hFile; /* Handle to the file */ + int isFile; /* is file (1) or dir (0) */ +}TestCaseDir; + +DWORD desiredAccessFile = GENERIC_READ | GENERIC_WRITE; +DWORD shareModeFile = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE; +LPSECURITY_ATTRIBUTES lpAttrFile = NULL; +DWORD dwCreationDispFile = CREATE_NEW; +DWORD dwFlagsAttribFile = FILE_ATTRIBUTE_NORMAL; +HANDLE hTemplateFile = NULL; + +int numFileTests = 6; +TestCaseFile gfaTestsFile[6]; /* GetFileAttributes tests list */ + +int numDirTests = 6; +TestCaseDir gfaTestsDir[6]; /* GetFileAttributes tests list */ + +BOOL CleanUpFiles() +{ + DWORD dwAtt; + int i; + BOOL result = TRUE; + for (i = 0; i < numFileTests - 1 ; i++ ) + { + dwAtt = GetFileAttributesA(gfaTestsFile[i].name); + + if( dwAtt != INVALID_FILE_ATTRIBUTES ) + { + //Trace("Files iteration %d\n", i); + if(!SetFileAttributesA (gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, FILE_ATTRIBUTE_NORMAL); + } + + if(!DeleteFileA (gfaTestsFile[i].name)) + { + result = FALSE; + Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, dwAtt); + } + + } + } +// Trace("Value of result is %d\n", result); + return result; +} +BOOL SetUpFiles() +{ + int i = 0; + BOOL result = TRUE; + for (i = 0; i < numFileTests - 1 ; i++ ) + { + gfaTestsFile[i].hFile = CreateFile(gfaTestsFile[i].name, + desiredAccessFile, + shareModeFile, + lpAttrFile, + dwCreationDispFile, + dwFlagsAttribFile, + hTemplateFile); + + if( gfaTestsFile[i].hFile == NULL ) + { + Fail("Error while creating files for iteration %d\n", i); + } + + if(!SetFileAttributesA (gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsFile[i].name, gfaTestsFile[i].expectedAttribs); + } + } + + return result; +} + +BOOL CleanUpDirs() +{ + DWORD dwAtt; + int i; + BOOL result = TRUE; + for (i = 0; i < numDirTests - 1; i++ ) + { + dwAtt = GetFileAttributesA(gfaTestsDir[i].name); + + if( dwAtt != INVALID_FILE_ATTRIBUTES ) + { + + if(!SetFileAttributesA (gfaTestsDir[i].name, FILE_ATTRIBUTE_DIRECTORY)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY)); + } + + if(!RemoveDirectoryA (gfaTestsDir[i].name)) + { + result = FALSE; + Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt); + } + + } + } + + return result; +} + +BOOL SetUpDirs() +{ + int i = 0; + BOOL result = TRUE; + DWORD ret = 0; + for (i = 0; i < numDirTests - 1; i++ ) + { + result = CreateDirectory(gfaTestsDir[i].name, + NULL); + + if(!result ) + { + result = FALSE; + Fail("Error while creating directory for iteration %d\n", i); + } + + if(!SetFileAttributesA (gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs)) + { + result = FALSE; + Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); + } + + ret = GetFileAttributesA (gfaTestsDir[i].name); + if(ret != gfaTestsDir[i].expectedAttribs) + { + result = FALSE; + Trace("ERROR: Error setting attributes [%s][%d]\n", gfaTestsDir[i].name, gfaTestsDir[i].expectedAttribs); + } + // Trace("Setup Dir setting attr [%d], returned [%d]\n", gfaTestsDir[i].expectedAttribs, ret); + + } +// Trace("Setup dirs returning %d\n", result); + return result; +} +int __cdecl main(int argc, char **argv) +{ + int i; + BOOL bFailed = FALSE; + DWORD result; + + char * NormalDirectoryName = "normal_test_directory"; + char * ReadOnlyDirectoryName = "ro_test_directory"; + char * ReadWriteDirectoryName = "rw_directory"; + char * HiddenDirectoryName = ".hidden_directory"; + char * HiddenReadOnlyDirectoryName = ".hidden_ro_directory"; + char * NoDirectoryName = "no_directory"; + + char * NormalFileName = "normal_test_file"; + char * ReadOnlyFileName = "ro_test_file"; + char * ReadWriteFileName = "rw_file"; + char * HiddenFileName = ".hidden_file"; + char * HiddenReadOnlyFileName = ".hidden_ro_file"; + char * NotReallyAFileName = "not_really_a_file"; + + WCHAR *WStr; + /* Tests on directory */ + gfaTestsDir[0].name = NormalDirectoryName; + gfaTestsDir[0].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; + gfaTestsDir[0].isFile = TYPE_DIR; + + gfaTestsDir[1].name = ReadOnlyDirectoryName; + gfaTestsDir[1].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | + FILE_ATTRIBUTE_READONLY; + gfaTestsDir[1].isFile = TYPE_DIR; + + gfaTestsDir[2].name = ReadWriteDirectoryName; + gfaTestsDir[2].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; + gfaTestsDir[2].isFile = TYPE_DIR; + + gfaTestsDir[3].name = HiddenDirectoryName; + gfaTestsDir[3].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY; //| + //FILE_ATTRIBUTE_HIDDEN; + gfaTestsDir[3].isFile = TYPE_DIR; + + gfaTestsDir[4].name = HiddenReadOnlyDirectoryName; + gfaTestsDir[4].expectedAttribs = FILE_ATTRIBUTE_DIRECTORY | + FILE_ATTRIBUTE_READONLY; //| + //FILE_ATTRIBUTE_HIDDEN; + gfaTestsDir[4].isFile = TYPE_DIR; + + gfaTestsDir[5].name = NoDirectoryName; + gfaTestsDir[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; + gfaTestsDir[5].isFile = TYPE_DIR; + + /* Tests on file */ + gfaTestsFile[0].name = NormalFileName; + gfaTestsFile[0].expectedAttribs = FILE_ATTRIBUTE_NORMAL; + gfaTestsFile[0].isFile = TYPE_FILE; + + + gfaTestsFile[1].name = ReadOnlyFileName; + gfaTestsFile[1].expectedAttribs = FILE_ATTRIBUTE_READONLY; + gfaTestsFile[1].isFile = TYPE_FILE; + + gfaTestsFile[2].name = ReadWriteFileName; + gfaTestsFile[2].expectedAttribs = FILE_ATTRIBUTE_NORMAL; + gfaTestsFile[2].isFile = TYPE_FILE; + + gfaTestsFile[3].name = HiddenFileName; + gfaTestsFile[3].expectedAttribs = FILE_ATTRIBUTE_NORMAL; //FILE_ATTRIBUTE_HIDDEN; + gfaTestsFile[3].isFile = TYPE_FILE; + + gfaTestsFile[4].name = HiddenReadOnlyFileName; + gfaTestsFile[4].expectedAttribs = FILE_ATTRIBUTE_READONLY; //| + //FILE_ATTRIBUTE_HIDDEN; + gfaTestsFile[4].isFile = TYPE_FILE; + + + gfaTestsFile[5].name = NotReallyAFileName; + gfaTestsFile[5].expectedAttribs = INVALID_FILE_ATTRIBUTES; + gfaTestsFile[5].isFile = TYPE_FILE; + + /* Initialize PAL environment */ + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + if(!CleanUpFiles()) + { + Fail("GetFileAttributesW: Pre-Clean Up Files Failed\n"); + } + + if(0 == SetUpFiles()) + { + Fail("GetFileAttributesW: SetUp Files Failed\n"); + } + + if(!CleanUpDirs()) + { + Fail("GetFileAttributesW: Pre-Clean Up Directories Failed\n"); + } + + if(!SetUpDirs()) + { + Fail("GetFileAttributesW: SetUp Directories Failed\n"); + } + + /* + * Go through all the test cases above, + * call GetFileAttributesW on the name and + * make sure the return value is the one expected + */ + for( i = 0; i < numFileTests; i++ ) + { + WStr = convert(gfaTestsFile[i].name); + result = GetFileAttributesW(WStr); + + if( result != gfaTestsFile[i].expectedAttribs ) + { + bFailed = TRUE; + + Trace("ERROR: GetFileAttributesW Test#%u on %s " + "returned %u instead of %u. \n", + i, + gfaTestsFile[i].name, + result, + gfaTestsFile[i].expectedAttribs); + + } + free(WStr); + } + + + for( i = 0; i < numDirTests; i++ ) + { + WStr = convert(gfaTestsDir[i].name); + result = GetFileAttributesW(WStr); + + if( result != gfaTestsDir[i].expectedAttribs ) + { + bFailed = TRUE; + + Trace("ERROR: GetFileAttributesW on Directories Test#%u on %s " + "returned %u instead of %u. \n", + i, + gfaTestsDir[i].name, + result, + gfaTestsDir[i].expectedAttribs); + + } + free(WStr); + } + + if(!CleanUpFiles()) + { + Fail("GetFileAttributesW: Post-Clean Up Files Failed\n"); + } + + if(!CleanUpDirs()) + { + Fail("GetFileAttributesW: Post-Clean Up Directories Failed\n"); + } + + /* If any errors, just call Fail() */ + if( bFailed ) + { + Fail(""); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileSize/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileSize/test1/CMakeLists.txt index ff20de5905..f192ba7400 100644 --- a/src/pal/tests/palsuite/file_io/GetFileSize/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileSize/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFileSize.c + GetFileSize.cpp ) add_executable(paltest_getfilesize_test1 diff --git a/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.c b/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.c deleted file mode 100644 index fac01c98c9..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.c +++ /dev/null @@ -1,173 +0,0 @@ -// 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: GetFileSize.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetFileSize function. -** -** -**===================================================================*/ - -#include - -const char* szTextFile = "text.txt"; - -void CleanUp(HANDLE hFile) -{ - if (CloseHandle(hFile) != TRUE) - { - Fail("GetFileSize: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Fail("GetFileSize: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } -} - -void CheckFileSize(HANDLE hFile, DWORD dwOffset, DWORD dwHighOrder) -{ - DWORD dwRc = 0; - DWORD dwReturnedHighOrder = 0; - DWORD dwReturnedOffset = 0; - - dwRc = SetFilePointer(hFile, dwOffset, (PLONG)&dwHighOrder, FILE_BEGIN); - if (dwRc == INVALID_SET_FILE_POINTER) - { - Trace("GetFileSize: ERROR -> Call to SetFilePointer failed with %ld.\n", - GetLastError()); - CleanUp(hFile); - Fail(""); - } - else - { - if (!SetEndOfFile(hFile)) - { - Trace("GetFileSize: ERROR -> Call to SetEndOfFile failed with %ld.\n", - GetLastError()); - CleanUp(hFile); - Fail(""); - } - dwReturnedOffset = GetFileSize(hFile, &dwReturnedHighOrder); - if ((dwReturnedOffset != dwOffset) || - (dwReturnedHighOrder != dwHighOrder)) - { - CleanUp(hFile); - Fail("GetFileSize: ERROR -> File sizes do not match up.\n"); - } - } -} - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwRc = 0; - DWORD dwRc2 = 0; - DWORD dwHighOrder = 0; - DWORD lpNumberOfBytesWritten; - char * data = "1234567890"; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - /* test on a null file handle */ - dwRc = GetFileSize(hFile, NULL); - if (dwRc != INVALID_FILE_SIZE) - { - Fail("GetFileSize: ERROR -> A file size was returned for " - "a null handle.\n"); - } - - /* test on a null file handle using the high order option */ - dwRc = GetFileSize(hFile, &dwHighOrder); - if (dwRc != INVALID_FILE_SIZE) - { - Fail("GetFileSize: ERROR -> A file size was returned for " - "a null handle.\n"); - } - - /* test on an invalid file handle */ - dwRc = GetFileSize(INVALID_HANDLE_VALUE, NULL); - if (dwRc != INVALID_FILE_SIZE) - { - Fail("GetFileSize: ERROR -> A file size was returned for " - "an invalid handle.\n"); - } - - /* test on an invalid file handle using the high order option */ - dwRc = GetFileSize(INVALID_HANDLE_VALUE, &dwHighOrder); - if (dwRc != INVALID_FILE_SIZE) - { - Fail("GetFileSize: ERROR -> A file size was returned for " - "an invalid handle.\n"); - } - - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("GetFileSize: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - /* give the file a size */ - CheckFileSize(hFile, 256, 0); - - /* make the file large using the high order option */ - CheckFileSize(hFile, 256, 1); - - - /* set the file size to zero */ - CheckFileSize(hFile, 0, 0); - - /* test if file size changes by writing to it. */ - /* get file size */ - dwRc = GetFileSize(hFile, NULL); - - /* test writing to the file */ - if(WriteFile(hFile, data, strlen(data), &lpNumberOfBytesWritten, NULL)==0) - { - Trace("GetFileSize: ERROR -> Call to WriteFile failed with %ld.\n", - GetLastError()); - CleanUp(hFile); - Fail(""); - } - - /* make sure the buffer flushed.*/ - if(FlushFileBuffers(hFile)==0) - { - Trace("GetFileSize: ERROR -> Call to FlushFileBuffers failed with %ld.\n", - GetLastError()); - CleanUp(hFile); - Fail(""); - } - - /* get file size after writing some chars */ - dwRc2 = GetFileSize(hFile, NULL); - if((dwRc2-dwRc) !=strlen(data)) - { - CleanUp(hFile); - Fail("GetFileSize: ERROR -> File size did not increase properly after.\n" - "writing %d chars\n", strlen(data)); - } - - CleanUp(hFile); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.cpp b/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.cpp new file mode 100644 index 0000000000..fac01c98c9 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.cpp @@ -0,0 +1,173 @@ +// 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: GetFileSize.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetFileSize function. +** +** +**===================================================================*/ + +#include + +const char* szTextFile = "text.txt"; + +void CleanUp(HANDLE hFile) +{ + if (CloseHandle(hFile) != TRUE) + { + Fail("GetFileSize: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Fail("GetFileSize: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } +} + +void CheckFileSize(HANDLE hFile, DWORD dwOffset, DWORD dwHighOrder) +{ + DWORD dwRc = 0; + DWORD dwReturnedHighOrder = 0; + DWORD dwReturnedOffset = 0; + + dwRc = SetFilePointer(hFile, dwOffset, (PLONG)&dwHighOrder, FILE_BEGIN); + if (dwRc == INVALID_SET_FILE_POINTER) + { + Trace("GetFileSize: ERROR -> Call to SetFilePointer failed with %ld.\n", + GetLastError()); + CleanUp(hFile); + Fail(""); + } + else + { + if (!SetEndOfFile(hFile)) + { + Trace("GetFileSize: ERROR -> Call to SetEndOfFile failed with %ld.\n", + GetLastError()); + CleanUp(hFile); + Fail(""); + } + dwReturnedOffset = GetFileSize(hFile, &dwReturnedHighOrder); + if ((dwReturnedOffset != dwOffset) || + (dwReturnedHighOrder != dwHighOrder)) + { + CleanUp(hFile); + Fail("GetFileSize: ERROR -> File sizes do not match up.\n"); + } + } +} + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwRc = 0; + DWORD dwRc2 = 0; + DWORD dwHighOrder = 0; + DWORD lpNumberOfBytesWritten; + char * data = "1234567890"; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + /* test on a null file handle */ + dwRc = GetFileSize(hFile, NULL); + if (dwRc != INVALID_FILE_SIZE) + { + Fail("GetFileSize: ERROR -> A file size was returned for " + "a null handle.\n"); + } + + /* test on a null file handle using the high order option */ + dwRc = GetFileSize(hFile, &dwHighOrder); + if (dwRc != INVALID_FILE_SIZE) + { + Fail("GetFileSize: ERROR -> A file size was returned for " + "a null handle.\n"); + } + + /* test on an invalid file handle */ + dwRc = GetFileSize(INVALID_HANDLE_VALUE, NULL); + if (dwRc != INVALID_FILE_SIZE) + { + Fail("GetFileSize: ERROR -> A file size was returned for " + "an invalid handle.\n"); + } + + /* test on an invalid file handle using the high order option */ + dwRc = GetFileSize(INVALID_HANDLE_VALUE, &dwHighOrder); + if (dwRc != INVALID_FILE_SIZE) + { + Fail("GetFileSize: ERROR -> A file size was returned for " + "an invalid handle.\n"); + } + + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("GetFileSize: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + /* give the file a size */ + CheckFileSize(hFile, 256, 0); + + /* make the file large using the high order option */ + CheckFileSize(hFile, 256, 1); + + + /* set the file size to zero */ + CheckFileSize(hFile, 0, 0); + + /* test if file size changes by writing to it. */ + /* get file size */ + dwRc = GetFileSize(hFile, NULL); + + /* test writing to the file */ + if(WriteFile(hFile, data, strlen(data), &lpNumberOfBytesWritten, NULL)==0) + { + Trace("GetFileSize: ERROR -> Call to WriteFile failed with %ld.\n", + GetLastError()); + CleanUp(hFile); + Fail(""); + } + + /* make sure the buffer flushed.*/ + if(FlushFileBuffers(hFile)==0) + { + Trace("GetFileSize: ERROR -> Call to FlushFileBuffers failed with %ld.\n", + GetLastError()); + CleanUp(hFile); + Fail(""); + } + + /* get file size after writing some chars */ + dwRc2 = GetFileSize(hFile, NULL); + if((dwRc2-dwRc) !=strlen(data)) + { + CleanUp(hFile); + Fail("GetFileSize: ERROR -> File size did not increase properly after.\n" + "writing %d chars\n", strlen(data)); + } + + CleanUp(hFile); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/CMakeLists.txt index 1369a5dc5a..33a7e2f557 100644 --- a/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFileSizeEx.c + GetFileSizeEx.cpp ) add_executable(paltest_getfilesizeex_test1 diff --git a/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/GetFileSizeEx.c b/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/GetFileSizeEx.c deleted file mode 100644 index ef5afd0e6b..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/GetFileSizeEx.c +++ /dev/null @@ -1,173 +0,0 @@ -// 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: GetFileSizeEx.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetFileSizeEx function. -** -** -**===================================================================*/ - -#include - -const char* szTextFile = "text.txt"; - -void CleanUp(HANDLE hFile) -{ - if (CloseHandle(hFile) != TRUE) - { - Fail("GetFileSizeEx: ERROR -> Unable to close file \"%s\".\n" - " Error is %d\n", - szTextFile, GetLastError()); - } - if (!DeleteFileA(szTextFile)) - { - Fail("GetFileSizeEx: ERROR -> Unable to delete file \"%s\".\n" - " Error is %d\n", - szTextFile, GetLastError()); - } -} - -void CheckFileSize(HANDLE hFile, DWORD dwOffset, DWORD dwHighOrder) -{ - DWORD dwRc = 0; - DWORD dwError = 0; - LARGE_INTEGER qwFileSize; - - dwRc = SetFilePointer(hFile, dwOffset, (PLONG)&dwHighOrder, FILE_BEGIN); - if (dwRc == INVALID_SET_FILE_POINTER) - { - Trace("GetFileSizeEx: ERROR -> Call to SetFilePointer failed with %ld.\n", - GetLastError()); - CleanUp(hFile); - Fail(""); - } - else - { - if (!SetEndOfFile(hFile)) - { - dwError = GetLastError(); - CleanUp(hFile); - if (dwError == 112) - { - Fail("GetFileSizeEx: ERROR -> SetEndOfFile failed due to lack of " - "disk space\n"); - } - else - { - Fail("GetFileSizeEx: ERROR -> SetEndOfFile call failed " - "with error %ld\n", dwError); - } - } - else - { - GetFileSizeEx(hFile, &qwFileSize); - if ((qwFileSize.u.LowPart != dwOffset) || - (qwFileSize.u.HighPart != dwHighOrder)) - { - CleanUp(hFile); - Fail("GetFileSizeEx: ERROR -> File sizes do not match up.\n"); - } - } - } -} - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - BOOL bRc = FALSE; - DWORD lpNumberOfBytesWritten; - LARGE_INTEGER qwFileSize; - LARGE_INTEGER qwFileSize2; - char * data = "1234567890"; - - qwFileSize.QuadPart = 0; - qwFileSize2.QuadPart = 0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - /* test on a null file */ - bRc = GetFileSizeEx(NULL, &qwFileSize); - if (bRc != FALSE) - { - Fail("GetFileSizeEx: ERROR -> Returned status as TRUE for " - "a null handle.\n"); - } - - - /* test on an invalid file */ - bRc = GetFileSizeEx(INVALID_HANDLE_VALUE, &qwFileSize); - if (bRc != FALSE) - { - Fail("GetFileSizeEx: ERROR -> Returned status as TRUE for " - "an invalid handle.\n"); - } - - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("GetFileSizeEx: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - /* give the file a size */ - CheckFileSize(hFile, 256, 0); - - /* make the file large using the high order option */ - CheckFileSize(hFile, 256, 1); - - - /* set the file size to zero */ - CheckFileSize(hFile, 0, 0); - - /* test if file size changes by writing to it. */ - /* get file size */ - GetFileSizeEx(hFile, &qwFileSize); - - /* test writing to the file */ - if(WriteFile(hFile, data, strlen(data), &lpNumberOfBytesWritten, NULL)==0) - { - Trace("GetFileSizeEx: ERROR -> Call to WriteFile failed with %ld.\n", - GetLastError()); - CleanUp(hFile); - Fail(""); - } - - /* make sure the buffer flushed.*/ - if(FlushFileBuffers(hFile)==0) - { - Trace("GetFileSizeEx: ERROR -> Call to FlushFileBuffers failed with %ld.\n", - GetLastError()); - CleanUp(hFile); - Fail(""); - } - - /* get file size after writing some chars */ - GetFileSizeEx(hFile, &qwFileSize2); - if((qwFileSize2.QuadPart-qwFileSize.QuadPart) !=strlen(data)) - { - CleanUp(hFile); - Fail("GetFileSizeEx: ERROR -> File size did not increase properly after.\n" - "writing %d chars\n", strlen(data)); - } - - CleanUp(hFile); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/GetFileSizeEx.cpp b/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/GetFileSizeEx.cpp new file mode 100644 index 0000000000..ef5afd0e6b --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileSizeEx/test1/GetFileSizeEx.cpp @@ -0,0 +1,173 @@ +// 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: GetFileSizeEx.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetFileSizeEx function. +** +** +**===================================================================*/ + +#include + +const char* szTextFile = "text.txt"; + +void CleanUp(HANDLE hFile) +{ + if (CloseHandle(hFile) != TRUE) + { + Fail("GetFileSizeEx: ERROR -> Unable to close file \"%s\".\n" + " Error is %d\n", + szTextFile, GetLastError()); + } + if (!DeleteFileA(szTextFile)) + { + Fail("GetFileSizeEx: ERROR -> Unable to delete file \"%s\".\n" + " Error is %d\n", + szTextFile, GetLastError()); + } +} + +void CheckFileSize(HANDLE hFile, DWORD dwOffset, DWORD dwHighOrder) +{ + DWORD dwRc = 0; + DWORD dwError = 0; + LARGE_INTEGER qwFileSize; + + dwRc = SetFilePointer(hFile, dwOffset, (PLONG)&dwHighOrder, FILE_BEGIN); + if (dwRc == INVALID_SET_FILE_POINTER) + { + Trace("GetFileSizeEx: ERROR -> Call to SetFilePointer failed with %ld.\n", + GetLastError()); + CleanUp(hFile); + Fail(""); + } + else + { + if (!SetEndOfFile(hFile)) + { + dwError = GetLastError(); + CleanUp(hFile); + if (dwError == 112) + { + Fail("GetFileSizeEx: ERROR -> SetEndOfFile failed due to lack of " + "disk space\n"); + } + else + { + Fail("GetFileSizeEx: ERROR -> SetEndOfFile call failed " + "with error %ld\n", dwError); + } + } + else + { + GetFileSizeEx(hFile, &qwFileSize); + if ((qwFileSize.u.LowPart != dwOffset) || + (qwFileSize.u.HighPart != dwHighOrder)) + { + CleanUp(hFile); + Fail("GetFileSizeEx: ERROR -> File sizes do not match up.\n"); + } + } + } +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + BOOL bRc = FALSE; + DWORD lpNumberOfBytesWritten; + LARGE_INTEGER qwFileSize; + LARGE_INTEGER qwFileSize2; + char * data = "1234567890"; + + qwFileSize.QuadPart = 0; + qwFileSize2.QuadPart = 0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + /* test on a null file */ + bRc = GetFileSizeEx(NULL, &qwFileSize); + if (bRc != FALSE) + { + Fail("GetFileSizeEx: ERROR -> Returned status as TRUE for " + "a null handle.\n"); + } + + + /* test on an invalid file */ + bRc = GetFileSizeEx(INVALID_HANDLE_VALUE, &qwFileSize); + if (bRc != FALSE) + { + Fail("GetFileSizeEx: ERROR -> Returned status as TRUE for " + "an invalid handle.\n"); + } + + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("GetFileSizeEx: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + /* give the file a size */ + CheckFileSize(hFile, 256, 0); + + /* make the file large using the high order option */ + CheckFileSize(hFile, 256, 1); + + + /* set the file size to zero */ + CheckFileSize(hFile, 0, 0); + + /* test if file size changes by writing to it. */ + /* get file size */ + GetFileSizeEx(hFile, &qwFileSize); + + /* test writing to the file */ + if(WriteFile(hFile, data, strlen(data), &lpNumberOfBytesWritten, NULL)==0) + { + Trace("GetFileSizeEx: ERROR -> Call to WriteFile failed with %ld.\n", + GetLastError()); + CleanUp(hFile); + Fail(""); + } + + /* make sure the buffer flushed.*/ + if(FlushFileBuffers(hFile)==0) + { + Trace("GetFileSizeEx: ERROR -> Call to FlushFileBuffers failed with %ld.\n", + GetLastError()); + CleanUp(hFile); + Fail(""); + } + + /* get file size after writing some chars */ + GetFileSizeEx(hFile, &qwFileSize2); + if((qwFileSize2.QuadPart-qwFileSize.QuadPart) !=strlen(data)) + { + CleanUp(hFile); + Fail("GetFileSizeEx: ERROR -> File size did not increase properly after.\n" + "writing %d chars\n", strlen(data)); + } + + CleanUp(hFile); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileTime/test1/CMakeLists.txt index 6a89846d21..b95267ab5b 100644 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFileTime.c + GetFileTime.cpp ) add_executable(paltest_getfiletime_test1 diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test1/GetFileTime.c b/src/pal/tests/palsuite/file_io/GetFileTime/test1/GetFileTime.c deleted file mode 100644 index fb7bcb8513..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test1/GetFileTime.c +++ /dev/null @@ -1,180 +0,0 @@ -// 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: GetFileTime.c -** -** Purpose: Tests the PAL implementation of the GetFileTime function. -** This test checks the time of a file, writes to it, then checks the -** time again to ensure that write time has increased. It -** also checks that creation time is the same under WIN32 and has -** increased under FreeBSD. -** -** Depends: -** CreateFile -** WriteFile -** CloseHandle -** -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char **argv) -{ - - FILETIME Creation,LastAccess,LastWrite; - HANDLE TheFileHandle; - ULONG64 FirstWrite, SecondWrite, FirstCreationTime, SecondCreationTime; - DWORD temp; - BOOL result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Open the file to get a HANDLE */ - TheFileHandle = - CreateFile( - "the_file", // File Name - GENERIC_READ|GENERIC_WRITE, // Access Mode - 0, // Share Mode - NULL, // SD - OPEN_ALWAYS, // Howto Create - FILE_ATTRIBUTE_NORMAL, // File Attributes - NULL // Template file - ); - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to open the file. The error number " - "returned was %d.",GetLastError()); - } - - - /* Get the Last Write, Creation and Access File time of that File */ - if(!GetFileTime(TheFileHandle,&Creation,&LastAccess,&LastWrite)) - { - Fail("ERROR: GetFileTime returned 0, indicating failure."); - } - - /* Convert the structure to an ULONG64 */ - - FirstCreationTime = ((((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - FirstWrite = ((((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - /* Sleep for 3 seconds, this will ensure the time changes */ - Sleep(3000); - - /* Write to the file -- this should change write access and - last access - */ - - result = WriteFile(TheFileHandle, // File handle - "something", // String to write - 9, // Bytes to write - &temp, // Bytes written - NULL); - - if(result == 0) - { - Fail("ERROR: Failed to write to file. The file must be " - "written to in order to test that the write time is " - "updated."); - } - - /* Close the File, so the changes are recorded */ - result = CloseHandle(TheFileHandle); - - if(result == 0) - { - Fail("ERROR: Failed to close the file handle."); - } - - - /* Reopen the file */ - TheFileHandle = - CreateFile( - "the_file", /* file name */ - GENERIC_READ|GENERIC_WRITE, /* access mode */ - 0, /* share mode */ - NULL, /* SD */ - OPEN_ALWAYS, /* how to create */ - FILE_ATTRIBUTE_NORMAL, /* file attributes */ - NULL /* handle to template file */ - ); - - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to re-open the file. The error number " - "returned was %d.",GetLastError()); - } - - - - /* Call GetFileTime again */ - if(!GetFileTime(TheFileHandle,&Creation,&LastAccess,&LastWrite)) - { - Fail("ERROR: GetFileTime returned 0, indicating failure."); - } - - /* Store the results in a ULONG64 */ - - SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - - /* Now -- to test. We'll ensure that the Second - LastWrite time is larger than the first. It tells us that - time is passing, which is good! - */ - - if(FirstWrite >= SecondWrite) - { - Fail("ERROR: The last-write-file-time after writing did not " - "increase from the original. The second value should be " - "larger."); - } - -#if WIN32 - /* Then we can check to make sure that the creation time - hasn't changed. This should always stay the same. - */ - - if(FirstCreationTime != SecondCreationTime) - { - Fail("ERROR: The creation time after writing should not " - "not change from the original. The second value should be " - "equal."); - } -#else - /* Then we can check to make sure that the creation time - has changed. Under FreeBSD it changes whenever the file is - access or written. - */ - - if(FirstCreationTime >= SecondCreationTime) - { - Fail("ERROR: The creation time after writing should be " - "greater than the original. The second value should be " - "larger."); - } - -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test1/GetFileTime.cpp b/src/pal/tests/palsuite/file_io/GetFileTime/test1/GetFileTime.cpp new file mode 100644 index 0000000000..fb7bcb8513 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test1/GetFileTime.cpp @@ -0,0 +1,180 @@ +// 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: GetFileTime.c +** +** Purpose: Tests the PAL implementation of the GetFileTime function. +** This test checks the time of a file, writes to it, then checks the +** time again to ensure that write time has increased. It +** also checks that creation time is the same under WIN32 and has +** increased under FreeBSD. +** +** Depends: +** CreateFile +** WriteFile +** CloseHandle +** +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME Creation,LastAccess,LastWrite; + HANDLE TheFileHandle; + ULONG64 FirstWrite, SecondWrite, FirstCreationTime, SecondCreationTime; + DWORD temp; + BOOL result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Open the file to get a HANDLE */ + TheFileHandle = + CreateFile( + "the_file", // File Name + GENERIC_READ|GENERIC_WRITE, // Access Mode + 0, // Share Mode + NULL, // SD + OPEN_ALWAYS, // Howto Create + FILE_ATTRIBUTE_NORMAL, // File Attributes + NULL // Template file + ); + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the file. The error number " + "returned was %d.",GetLastError()); + } + + + /* Get the Last Write, Creation and Access File time of that File */ + if(!GetFileTime(TheFileHandle,&Creation,&LastAccess,&LastWrite)) + { + Fail("ERROR: GetFileTime returned 0, indicating failure."); + } + + /* Convert the structure to an ULONG64 */ + + FirstCreationTime = ((((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + FirstWrite = ((((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + /* Sleep for 3 seconds, this will ensure the time changes */ + Sleep(3000); + + /* Write to the file -- this should change write access and + last access + */ + + result = WriteFile(TheFileHandle, // File handle + "something", // String to write + 9, // Bytes to write + &temp, // Bytes written + NULL); + + if(result == 0) + { + Fail("ERROR: Failed to write to file. The file must be " + "written to in order to test that the write time is " + "updated."); + } + + /* Close the File, so the changes are recorded */ + result = CloseHandle(TheFileHandle); + + if(result == 0) + { + Fail("ERROR: Failed to close the file handle."); + } + + + /* Reopen the file */ + TheFileHandle = + CreateFile( + "the_file", /* file name */ + GENERIC_READ|GENERIC_WRITE, /* access mode */ + 0, /* share mode */ + NULL, /* SD */ + OPEN_ALWAYS, /* how to create */ + FILE_ATTRIBUTE_NORMAL, /* file attributes */ + NULL /* handle to template file */ + ); + + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to re-open the file. The error number " + "returned was %d.",GetLastError()); + } + + + + /* Call GetFileTime again */ + if(!GetFileTime(TheFileHandle,&Creation,&LastAccess,&LastWrite)) + { + Fail("ERROR: GetFileTime returned 0, indicating failure."); + } + + /* Store the results in a ULONG64 */ + + SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + + /* Now -- to test. We'll ensure that the Second + LastWrite time is larger than the first. It tells us that + time is passing, which is good! + */ + + if(FirstWrite >= SecondWrite) + { + Fail("ERROR: The last-write-file-time after writing did not " + "increase from the original. The second value should be " + "larger."); + } + +#if WIN32 + /* Then we can check to make sure that the creation time + hasn't changed. This should always stay the same. + */ + + if(FirstCreationTime != SecondCreationTime) + { + Fail("ERROR: The creation time after writing should not " + "not change from the original. The second value should be " + "equal."); + } +#else + /* Then we can check to make sure that the creation time + has changed. Under FreeBSD it changes whenever the file is + access or written. + */ + + if(FirstCreationTime >= SecondCreationTime) + { + Fail("ERROR: The creation time after writing should be " + "greater than the original. The second value should be " + "larger."); + } + +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileTime/test2/CMakeLists.txt index 3d315e44de..fe02e27bbe 100644 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFileTime.c + GetFileTime.cpp ) add_executable(paltest_getfiletime_test2 diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test2/GetFileTime.c b/src/pal/tests/palsuite/file_io/GetFileTime/test2/GetFileTime.c deleted file mode 100644 index 5b14a1e357..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test2/GetFileTime.c +++ /dev/null @@ -1,195 +0,0 @@ -// 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: GetFileTime.c -** -** Purpose: Tests the PAL implementation of the GetFileTime function -** Test to see that access date either stays the same or increases -** when a read is performed. Write -** and creation time should stay unchanged. Note: Under FreeBSD -** the Creation time should not change with just a read. -** -** Depends: -** FileTimeToDosDateTime -** CreateFile -** ReadFile -** CloseHandle -** -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char **argv) -{ - - FILETIME Creation,LastAccess,LastWrite; - HANDLE TheFileHandle; - ULONG64 FirstWrite, SecondWrite, - FirstCreationTime, SecondCreationTime; - DWORD temp; - char ReadBuffer[10]; - BOOL result; - WORD DosDateOne, DosDateTwo, DosTime; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Open the file to get a HANDLE */ - TheFileHandle = - CreateFile( - "the_file", - GENERIC_READ, - 0, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to open the file. The error number " - "returned was %d.",GetLastError()); - } - - - /* Get the Last Write, Creation and Access File time of that File */ - if(GetFileTime(TheFileHandle,&Creation,&LastAccess,&LastWrite)==0) - { - Fail("ERROR: GetFileTime returned 0, indicating failure."); - } - - /* Call FileTimeToDosDateTime so we can aquire just the date - portion of the Last Access FILETIME. - */ - if(FileTimeToDosDateTime(&LastAccess, &DosDateOne, &DosTime) == 0) - { - Fail("ERROR: FiletimeToDosDateTime failed, returning 0. " - "GetLastError returned %d.\n",GetLastError()); - } - - /* Convert the structure to an ULONG64 */ - - FirstCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - FirstWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - /* Sleep for 3 seconds, this will ensure the time changes */ - Sleep(3000); - - /* Read from the file -- this should change - last access, but we'll only check the date portion, because some file - systems have a resolution of a day. - */ - - result = ReadFile(TheFileHandle, // handle to file - &ReadBuffer, // data buffer - 2, // number of bytes to read - &temp, // number of bytes read - NULL); - - if(result == 0) - { - Fail("ERROR: Failed to read from the file."); - } - - - /* Close the File, so the changes are recorded */ - result = CloseHandle(TheFileHandle); - - if(result == 0) - { - Fail("ERROR: Failed to close the file handle."); - } - - - /* Reopen the file */ - TheFileHandle = - CreateFile("the_file", /* file name */ - GENERIC_READ, /* access mode */ - 0, /* share mode */ - NULL, /* SD */ - OPEN_ALWAYS, /* how to create */ - FILE_ATTRIBUTE_NORMAL, /* file attributes */ - NULL /* handle to template file */ - ); - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to re-open the file. The error number " - "returned was %d.",GetLastError()); - } - - /* Call GetFileTime again */ - if(GetFileTime(TheFileHandle,&Creation,&LastAccess,&LastWrite) == 0) - { - Fail("ERROR: GetFileTime returned 0, indicating failure."); - } - - /* Get the Date of the LastAccessTime here again. */ - if(FileTimeToDosDateTime(&LastAccess, &DosDateTwo, &DosTime) == 0) - { - Fail("ERROR: FileTimeToDosDateTime failed, returning 0. " - "GetLastError returned %d.\n",GetLastError()); - } - - - /* Store the results in a ULONG64 */ - - SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - /* Now -- to test. We'll ensure that the Second - LastWrite time is the same as the first. This shouldn't - have changed. - */ - - if(FirstWrite != SecondWrite) - { - Fail("ERROR: The last-write-file-time after reading " - "increased from the original. The second value should be " - "equal."); - } - - - /* - For LastAccessTime, just check that the date is greater or equal - for the second over the first. The time is not conisered on some - file systems. (such as fat32) - */ - - if(DosDateOne > DosDateTwo) - { - Fail("ERROR: The last-access-time after reading should have " - "stayed the same or increased, but it did not.\n"); - } - - - /* Check to ensure CreationTime hasn't changed. This should not - have changed in either environment. - */ - - if(FirstCreationTime != SecondCreationTime) - { - Fail("ERROR: The creation time after reading should not " - "not change from the original. The second value should be " - "equal."); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test2/GetFileTime.cpp b/src/pal/tests/palsuite/file_io/GetFileTime/test2/GetFileTime.cpp new file mode 100644 index 0000000000..5b14a1e357 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test2/GetFileTime.cpp @@ -0,0 +1,195 @@ +// 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: GetFileTime.c +** +** Purpose: Tests the PAL implementation of the GetFileTime function +** Test to see that access date either stays the same or increases +** when a read is performed. Write +** and creation time should stay unchanged. Note: Under FreeBSD +** the Creation time should not change with just a read. +** +** Depends: +** FileTimeToDosDateTime +** CreateFile +** ReadFile +** CloseHandle +** +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME Creation,LastAccess,LastWrite; + HANDLE TheFileHandle; + ULONG64 FirstWrite, SecondWrite, + FirstCreationTime, SecondCreationTime; + DWORD temp; + char ReadBuffer[10]; + BOOL result; + WORD DosDateOne, DosDateTwo, DosTime; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Open the file to get a HANDLE */ + TheFileHandle = + CreateFile( + "the_file", + GENERIC_READ, + 0, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the file. The error number " + "returned was %d.",GetLastError()); + } + + + /* Get the Last Write, Creation and Access File time of that File */ + if(GetFileTime(TheFileHandle,&Creation,&LastAccess,&LastWrite)==0) + { + Fail("ERROR: GetFileTime returned 0, indicating failure."); + } + + /* Call FileTimeToDosDateTime so we can aquire just the date + portion of the Last Access FILETIME. + */ + if(FileTimeToDosDateTime(&LastAccess, &DosDateOne, &DosTime) == 0) + { + Fail("ERROR: FiletimeToDosDateTime failed, returning 0. " + "GetLastError returned %d.\n",GetLastError()); + } + + /* Convert the structure to an ULONG64 */ + + FirstCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + FirstWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + /* Sleep for 3 seconds, this will ensure the time changes */ + Sleep(3000); + + /* Read from the file -- this should change + last access, but we'll only check the date portion, because some file + systems have a resolution of a day. + */ + + result = ReadFile(TheFileHandle, // handle to file + &ReadBuffer, // data buffer + 2, // number of bytes to read + &temp, // number of bytes read + NULL); + + if(result == 0) + { + Fail("ERROR: Failed to read from the file."); + } + + + /* Close the File, so the changes are recorded */ + result = CloseHandle(TheFileHandle); + + if(result == 0) + { + Fail("ERROR: Failed to close the file handle."); + } + + + /* Reopen the file */ + TheFileHandle = + CreateFile("the_file", /* file name */ + GENERIC_READ, /* access mode */ + 0, /* share mode */ + NULL, /* SD */ + OPEN_ALWAYS, /* how to create */ + FILE_ATTRIBUTE_NORMAL, /* file attributes */ + NULL /* handle to template file */ + ); + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to re-open the file. The error number " + "returned was %d.",GetLastError()); + } + + /* Call GetFileTime again */ + if(GetFileTime(TheFileHandle,&Creation,&LastAccess,&LastWrite) == 0) + { + Fail("ERROR: GetFileTime returned 0, indicating failure."); + } + + /* Get the Date of the LastAccessTime here again. */ + if(FileTimeToDosDateTime(&LastAccess, &DosDateTwo, &DosTime) == 0) + { + Fail("ERROR: FileTimeToDosDateTime failed, returning 0. " + "GetLastError returned %d.\n",GetLastError()); + } + + + /* Store the results in a ULONG64 */ + + SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + /* Now -- to test. We'll ensure that the Second + LastWrite time is the same as the first. This shouldn't + have changed. + */ + + if(FirstWrite != SecondWrite) + { + Fail("ERROR: The last-write-file-time after reading " + "increased from the original. The second value should be " + "equal."); + } + + + /* + For LastAccessTime, just check that the date is greater or equal + for the second over the first. The time is not conisered on some + file systems. (such as fat32) + */ + + if(DosDateOne > DosDateTwo) + { + Fail("ERROR: The last-access-time after reading should have " + "stayed the same or increased, but it did not.\n"); + } + + + /* Check to ensure CreationTime hasn't changed. This should not + have changed in either environment. + */ + + if(FirstCreationTime != SecondCreationTime) + { + Fail("ERROR: The creation time after reading should not " + "not change from the original. The second value should be " + "equal."); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileTime/test3/CMakeLists.txt index 34f7310464..bb88966e68 100644 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFileTime.c + GetFileTime.cpp ) add_executable(paltest_getfiletime_test3 diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c b/src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c deleted file mode 100644 index a3f46c2bf8..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c +++ /dev/null @@ -1,142 +0,0 @@ -// 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: GetFileTime.c -** -** Purpose: Tests the PAL implementation of the GetFileTime function -** Test to see that creation time is changed when two different files -** are created. -** -** Depends: -** CreateFile -** ReadFile -** CloseHandle -** -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char **argv) -{ - - FILETIME Creation; - HANDLE TheFileHandle, SecondFileHandle; - ULONG64 FirstCreationTime, SecondCreationTime; - BOOL result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Open the file to get a HANDLE */ - TheFileHandle = - CreateFile( - "the_file", - GENERIC_READ, - 0, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to open the file. The error number " - "returned was %d.",GetLastError()); - } - - - /* Get the Creation time of the File */ - if(GetFileTime(TheFileHandle,&Creation,NULL,NULL)==0) - { - Fail("ERROR: GetFileTime returned 0, indicating failure. " - "Two of the params were NULL in this case, did they " - "cause the probleM?"); - } - - /* Convert the structure to an ULONG64 */ - - FirstCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - - /* Close the File, so the changes are recorded */ - result = CloseHandle(TheFileHandle); - - if(result == 0) - { - Fail("ERROR: Failed to close the file handle."); - } - - - /* Sleep for 3 seconds, this will ensure the time changes */ - Sleep(3000); - - - - /* Open another file */ - SecondFileHandle = - CreateFile("the_other_file", /* file name */ - GENERIC_READ, /* access mode */ - 0, /* share mode */ - NULL, /* SD */ - CREATE_ALWAYS, /* how to create */ - FILE_ATTRIBUTE_NORMAL, /* file attributes */ - NULL /* handle to template file */ - ); - - if(SecondFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to open the second file. The error number " - "returned was %d.",GetLastError()); - } - - - /* Call GetFileTime again */ - if(GetFileTime(SecondFileHandle,&Creation,NULL,NULL) == 0) - { - Fail("ERROR: GetFileTime returned 0, indicating failure. " - "Perhaps the NULLs in the function broke it?"); - } - - /* Close the File*/ - result = CloseHandle(SecondFileHandle); - - if(result == 0) - { - Fail("ERROR: Failed to close the file handle."); - } - - - /* Store the results in a ULONG64 */ - - SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - - - /* Now -- to test. We ensure that the FirstCreationTime is - less than the SecondCreationTime - */ - - - if(FirstCreationTime >= SecondCreationTime) - { - Fail("ERROR: The creation time of the two files should be " - "different. The first file should have a creation " - "time less than the second."); - } - - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.cpp b/src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.cpp new file mode 100644 index 0000000000..a3f46c2bf8 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.cpp @@ -0,0 +1,142 @@ +// 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: GetFileTime.c +** +** Purpose: Tests the PAL implementation of the GetFileTime function +** Test to see that creation time is changed when two different files +** are created. +** +** Depends: +** CreateFile +** ReadFile +** CloseHandle +** +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME Creation; + HANDLE TheFileHandle, SecondFileHandle; + ULONG64 FirstCreationTime, SecondCreationTime; + BOOL result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Open the file to get a HANDLE */ + TheFileHandle = + CreateFile( + "the_file", + GENERIC_READ, + 0, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the file. The error number " + "returned was %d.",GetLastError()); + } + + + /* Get the Creation time of the File */ + if(GetFileTime(TheFileHandle,&Creation,NULL,NULL)==0) + { + Fail("ERROR: GetFileTime returned 0, indicating failure. " + "Two of the params were NULL in this case, did they " + "cause the probleM?"); + } + + /* Convert the structure to an ULONG64 */ + + FirstCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + + /* Close the File, so the changes are recorded */ + result = CloseHandle(TheFileHandle); + + if(result == 0) + { + Fail("ERROR: Failed to close the file handle."); + } + + + /* Sleep for 3 seconds, this will ensure the time changes */ + Sleep(3000); + + + + /* Open another file */ + SecondFileHandle = + CreateFile("the_other_file", /* file name */ + GENERIC_READ, /* access mode */ + 0, /* share mode */ + NULL, /* SD */ + CREATE_ALWAYS, /* how to create */ + FILE_ATTRIBUTE_NORMAL, /* file attributes */ + NULL /* handle to template file */ + ); + + if(SecondFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the second file. The error number " + "returned was %d.",GetLastError()); + } + + + /* Call GetFileTime again */ + if(GetFileTime(SecondFileHandle,&Creation,NULL,NULL) == 0) + { + Fail("ERROR: GetFileTime returned 0, indicating failure. " + "Perhaps the NULLs in the function broke it?"); + } + + /* Close the File*/ + result = CloseHandle(SecondFileHandle); + + if(result == 0) + { + Fail("ERROR: Failed to close the file handle."); + } + + + /* Store the results in a ULONG64 */ + + SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + + + /* Now -- to test. We ensure that the FirstCreationTime is + less than the SecondCreationTime + */ + + + if(FirstCreationTime >= SecondCreationTime) + { + Fail("ERROR: The creation time of the two files should be " + "different. The first file should have a creation " + "time less than the second."); + } + + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileTime/test4/CMakeLists.txt index 0c9dcf7802..e43e7f99a8 100644 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFileTime.c + GetFileTime.cpp ) add_executable(paltest_getfiletime_test4 diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test4/GetFileTime.c b/src/pal/tests/palsuite/file_io/GetFileTime/test4/GetFileTime.c deleted file mode 100644 index ffba516e35..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test4/GetFileTime.c +++ /dev/null @@ -1,98 +0,0 @@ -// 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: GetFileTime.c -** -** Purpose: Tests the PAL implementation of the GetFileTime function -** Test to see that passing NULL values to GetFileTime works and that -** calling the function on a bad HANDLE causes the correct failure. -** -** Depends: -** CreateFile -** CloseHandle -** -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char **argv) -{ - - FILETIME Creation,LastWrite,LastAccess; - HANDLE TheFileHandle; - BOOL result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Open the file to get a HANDLE */ - TheFileHandle = - CreateFile( - "the_file", - GENERIC_READ, - 0, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to open the file. The error number " - "returned was %d.",GetLastError()); - } - - /* Pass all NULLs, this is useless but should still work. */ - if(GetFileTime(TheFileHandle,NULL,NULL,NULL)==0) - { - Fail("ERROR: GetFileTime returned 0, indicating failure. " - "Three of the params were NULL in this case, did they " - "cause the problem?"); - } - - - /* Get the Creation time of the File */ - if(GetFileTime(TheFileHandle,&Creation,NULL,NULL)==0) - { - Fail("ERROR: GetFileTime returned 0, indicating failure. " - "Two of the params were NULL in this case, did they " - "cause the probleM?"); - } - - /* Get the Creation, LastWrite time of the File */ - if(GetFileTime(TheFileHandle,&Creation,&LastWrite,NULL)==0) - { - Fail("ERROR: GetFileTime returned 0, indicating failure. " - "One of the params were NULL in this case, did it " - "cause the problem?"); - } - - - /* Close the File, so the changes are recorded */ - result = CloseHandle(TheFileHandle); - - if(result == 0) - { - Fail("ERROR: Failed to close the file handle."); - } - - /* Call GetFileTime again */ - if(GetFileTime(TheFileHandle,&Creation,&LastWrite,&LastAccess) != 0) - { - Fail("ERROR: GetFileTime returned non zero, indicating success. " - "It was passed an invalid file HANDLE and should have " - "failed."); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test4/GetFileTime.cpp b/src/pal/tests/palsuite/file_io/GetFileTime/test4/GetFileTime.cpp new file mode 100644 index 0000000000..ffba516e35 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test4/GetFileTime.cpp @@ -0,0 +1,98 @@ +// 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: GetFileTime.c +** +** Purpose: Tests the PAL implementation of the GetFileTime function +** Test to see that passing NULL values to GetFileTime works and that +** calling the function on a bad HANDLE causes the correct failure. +** +** Depends: +** CreateFile +** CloseHandle +** +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME Creation,LastWrite,LastAccess; + HANDLE TheFileHandle; + BOOL result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Open the file to get a HANDLE */ + TheFileHandle = + CreateFile( + "the_file", + GENERIC_READ, + 0, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the file. The error number " + "returned was %d.",GetLastError()); + } + + /* Pass all NULLs, this is useless but should still work. */ + if(GetFileTime(TheFileHandle,NULL,NULL,NULL)==0) + { + Fail("ERROR: GetFileTime returned 0, indicating failure. " + "Three of the params were NULL in this case, did they " + "cause the problem?"); + } + + + /* Get the Creation time of the File */ + if(GetFileTime(TheFileHandle,&Creation,NULL,NULL)==0) + { + Fail("ERROR: GetFileTime returned 0, indicating failure. " + "Two of the params were NULL in this case, did they " + "cause the probleM?"); + } + + /* Get the Creation, LastWrite time of the File */ + if(GetFileTime(TheFileHandle,&Creation,&LastWrite,NULL)==0) + { + Fail("ERROR: GetFileTime returned 0, indicating failure. " + "One of the params were NULL in this case, did it " + "cause the problem?"); + } + + + /* Close the File, so the changes are recorded */ + result = CloseHandle(TheFileHandle); + + if(result == 0) + { + Fail("ERROR: Failed to close the file handle."); + } + + /* Call GetFileTime again */ + if(GetFileTime(TheFileHandle,&Creation,&LastWrite,&LastAccess) != 0) + { + Fail("ERROR: GetFileTime returned non zero, indicating success. " + "It was passed an invalid file HANDLE and should have " + "failed."); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test5/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileTime/test5/CMakeLists.txt index a82717e657..4af995d207 100644 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - getfiletime.c + getfiletime.cpp ) add_executable(paltest_getfiletime_test5 diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test5/getfiletime.c b/src/pal/tests/palsuite/file_io/GetFileTime/test5/getfiletime.c deleted file mode 100644 index d8196d84bc..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test5/getfiletime.c +++ /dev/null @@ -1,224 +0,0 @@ -// 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: GetFileTime.c -** -** Purpose: Test the PAL implementation of GetFileTime. This test -** creates a file and compares create and write times between -** writes, but before the close, and verifies the results are -** as expected -** -** Depends: -** CreateFile -** WriteFile -** CloseHandle -** -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char **argv) -{ - FILETIME Creation; - FILETIME LastAccess; - FILETIME LastWrite; - HANDLE hFile; - ULONG64 FirstWrite; - ULONG64 SecondWrite; - ULONG64 FirstCreationTime; - ULONG64 SecondCreationTime; - DWORD temp; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Open the file to get a HANDLE */ - hFile = CreateFile("test.tmp", - GENERIC_READ|GENERIC_WRITE, - 0, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to create the file. The error number " - "returned was %u.\n", - GetLastError()); - } - - /* Write to the file -- this should change write access and - last access - */ - if(!WriteFile(hFile, "something", 9, &temp, NULL)) - { - Trace("ERROR: Failed to write to file. The file must be " - "written to in order to test that the write time is " - "updated. GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - FlushFileBuffers(hFile); - - /* Get the Last Write, Creation and Access File time of that File */ - if(!GetFileTime(hFile, &Creation, &LastAccess, &LastWrite)) - { - Trace("ERROR: GetFileTime returned 0, indicating failure." - " GetLastError returned %u\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Convert the structure to an ULONG64 */ - - FirstCreationTime = ((((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - FirstWrite = ((((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - /* Sleep for 3 seconds, this will ensure the time changes */ - Sleep(3000); - - /* Write to the file again -- this should change write access and - last access - */ - if(!WriteFile(hFile, "something", 9, &temp, NULL)) - { - Trace("ERROR: Failed to write to file. The file must be " - "written to in order to test that the write time is " - "updated. GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - - FlushFileBuffers(hFile); - - /* Call GetFileTime again */ - if(!GetFileTime(hFile,&Creation,&LastAccess,&LastWrite)) - { - Trace("ERROR: GetFileTime returned 0, indicating failure." - "GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Store the results in a ULONG64 */ - - SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - - /* Now -- to test. We'll ensure that the Second - LastWrite time is larger than the first. It tells us that - time is passing, which is good! - */ - - if(FirstWrite >= SecondWrite) - { - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("ERROR: The last-write-file-time after writing did not " - "increase from the original. The second value should be " - "larger.\n"); - } - -#if WIN32 - /* Then we can check to make sure that the creation time - hasn't changed. This should always stay the same. - */ - - if(FirstCreationTime != SecondCreationTime) - { - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("ERROR: The creation time after writing should not " - "not change from the original. The second value should be " - "equal.\n"); - } -#else - /* Then we can check to make sure that the creation time - has changed. Under FreeBSD it changes whenever the file is - access or written. - */ - - if(FirstCreationTime >= SecondCreationTime) - { - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("ERROR: The creation time after writing should be " - "greater than the original. The second value should be " - "larger.\n"); - } - -#endif - - /* Close the File */ - if(!CloseHandle(hFile)) - { - Fail("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test5/getfiletime.cpp b/src/pal/tests/palsuite/file_io/GetFileTime/test5/getfiletime.cpp new file mode 100644 index 0000000000..d8196d84bc --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test5/getfiletime.cpp @@ -0,0 +1,224 @@ +// 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: GetFileTime.c +** +** Purpose: Test the PAL implementation of GetFileTime. This test +** creates a file and compares create and write times between +** writes, but before the close, and verifies the results are +** as expected +** +** Depends: +** CreateFile +** WriteFile +** CloseHandle +** +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char **argv) +{ + FILETIME Creation; + FILETIME LastAccess; + FILETIME LastWrite; + HANDLE hFile; + ULONG64 FirstWrite; + ULONG64 SecondWrite; + ULONG64 FirstCreationTime; + ULONG64 SecondCreationTime; + DWORD temp; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Open the file to get a HANDLE */ + hFile = CreateFile("test.tmp", + GENERIC_READ|GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to create the file. The error number " + "returned was %u.\n", + GetLastError()); + } + + /* Write to the file -- this should change write access and + last access + */ + if(!WriteFile(hFile, "something", 9, &temp, NULL)) + { + Trace("ERROR: Failed to write to file. The file must be " + "written to in order to test that the write time is " + "updated. GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + FlushFileBuffers(hFile); + + /* Get the Last Write, Creation and Access File time of that File */ + if(!GetFileTime(hFile, &Creation, &LastAccess, &LastWrite)) + { + Trace("ERROR: GetFileTime returned 0, indicating failure." + " GetLastError returned %u\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Convert the structure to an ULONG64 */ + + FirstCreationTime = ((((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + FirstWrite = ((((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + /* Sleep for 3 seconds, this will ensure the time changes */ + Sleep(3000); + + /* Write to the file again -- this should change write access and + last access + */ + if(!WriteFile(hFile, "something", 9, &temp, NULL)) + { + Trace("ERROR: Failed to write to file. The file must be " + "written to in order to test that the write time is " + "updated. GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + + FlushFileBuffers(hFile); + + /* Call GetFileTime again */ + if(!GetFileTime(hFile,&Creation,&LastAccess,&LastWrite)) + { + Trace("ERROR: GetFileTime returned 0, indicating failure." + "GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Store the results in a ULONG64 */ + + SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + + /* Now -- to test. We'll ensure that the Second + LastWrite time is larger than the first. It tells us that + time is passing, which is good! + */ + + if(FirstWrite >= SecondWrite) + { + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("ERROR: The last-write-file-time after writing did not " + "increase from the original. The second value should be " + "larger.\n"); + } + +#if WIN32 + /* Then we can check to make sure that the creation time + hasn't changed. This should always stay the same. + */ + + if(FirstCreationTime != SecondCreationTime) + { + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("ERROR: The creation time after writing should not " + "not change from the original. The second value should be " + "equal.\n"); + } +#else + /* Then we can check to make sure that the creation time + has changed. Under FreeBSD it changes whenever the file is + access or written. + */ + + if(FirstCreationTime >= SecondCreationTime) + { + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("ERROR: The creation time after writing should be " + "greater than the original. The second value should be " + "larger.\n"); + } + +#endif + + /* Close the File */ + if(!CloseHandle(hFile)) + { + Fail("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test6/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileTime/test6/CMakeLists.txt index 24992dfa66..87c448b2a6 100644 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - getfiletime.c + getfiletime.cpp ) add_executable(paltest_getfiletime_test6 diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test6/getfiletime.c b/src/pal/tests/palsuite/file_io/GetFileTime/test6/getfiletime.c deleted file mode 100644 index 3eedddf82d..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test6/getfiletime.c +++ /dev/null @@ -1,281 +0,0 @@ -// 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: GetFileTime.c -** -** Purpose: Tests the PAL implementation of the GetFileTime function. -** Perform two reads from a file without closing until the end -** of the test and verify that only the access times change. -** Note: Under Win32, modify time changes as well so we will -** check that it doesn't go backwards -** -** Depends: -** FileTimeToDosDateTime -** CreateFile -** ReadFile -** WriteFile -** CloseHandle -** -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char **argv) -{ - - FILETIME Creation; - FILETIME LastAccess; - FILETIME LastWrite; - HANDLE hFile; - ULONG64 FirstWrite = (ULONG64)0; - ULONG64 SecondWrite = (ULONG64)0; - ULONG64 FirstCreationTime = (ULONG64)0; - ULONG64 SecondCreationTime = (ULONG64)0; - DWORD temp; - char ReadBuffer[10]; - WORD DosDateOne; - WORD DosDateTwo; - WORD DosTime; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - memset(&Creation, 0, sizeof(FILETIME)); - memset(&LastAccess, 0, sizeof(FILETIME)); - memset(&LastWrite, 0, sizeof(FILETIME)); - - /* Create the file to get a HANDLE */ - hFile = CreateFile("test.tmp", - GENERIC_READ|GENERIC_WRITE, - 0, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to create the file. The error number " - "returned was %u.\n", - GetLastError()); - } - - /* give us something to read from the file */ - if(!WriteFile(hFile, "something", 9, &temp, NULL)) - { - Trace("ERROR: Failed to write to file. " - "GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* let's do a read to set the file times for our test */ - if(!ReadFile(hFile, &ReadBuffer, 2, &temp, NULL)) - { - Trace("ERROR: Failed to read from the file. " - "GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Get the Last Write, Creation and Access File time of the file */ - if(GetFileTime(hFile, &Creation, &LastAccess, &LastWrite)==0) - { - Trace("ERROR: GetFileTime returned 0, indicating failure." - " GetLastError returned %u\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Call FileTimeToDosDateTime so we can aquire just the date - portion of the Last Access FILETIME. - */ - if(FileTimeToDosDateTime(&LastAccess, &DosDateOne, &DosTime) == 0) - { - Trace("ERROR: FiletimeToDosDateTime failed, returning 0. " - "GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Convert the structure to an ULONG64 */ - FirstCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - FirstWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - /* Sleep for 3 seconds, this will ensure the time changes */ - Sleep(3000); - - /* Read from the file -- this should change - last access, but we'll only check the date portion, because some file - systems have a resolution of a day. - */ - memset(&Creation, 0, sizeof(FILETIME)); - memset(&LastAccess, 0, sizeof(FILETIME)); - memset(&LastWrite, 0, sizeof(FILETIME)); - - if(!ReadFile(hFile, &ReadBuffer, 2, &temp, NULL)) - { - Trace("ERROR: Failed to read from the file. " - "GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - - /* Call GetFileTime to get the updated time values*/ - if(GetFileTime(hFile, &Creation, &LastAccess, &LastWrite) == 0) - { - Trace("ERROR: GetFileTime returned 0, indicating failure. " - "GetLastError returned %d.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Get the Date of the LastAccessTime here again. */ - if(FileTimeToDosDateTime(&LastAccess, &DosDateTwo, &DosTime) == 0) - { - Trace("ERROR: FileTimeToDosDateTime failed, returning 0. " - "GetLastError returned %d.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - - /* Store the results in a ULONG64 */ - SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - /* Now -- to test. We'll ensure that the SecondWrite - time is not less than the FirstWrite time - */ - - if(SecondWrite < FirstWrite) - { - Trace("ERROR: The write-file-time (%I64d) after the first read " - "is less than the write-file-time (%I64d) after the second " - "read.\n", - FirstWrite, - LastWrite); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* - For LastAccessTime, just check that the date is greater or equal - for the second over the first. The time is not conisered on some - file systems. (such as fat32) - */ - - if(DosDateOne > DosDateTwo) - { - Trace("ERROR: The last-access-time after reading should have " - "stayed the same or increased, but it did not.\n"); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - - /* Check to ensure CreationTime hasn't changed. This should not - have changed in either environment. - */ - - if(FirstCreationTime != SecondCreationTime) - { - Trace("ERROR: The creation time after reading should not " - "not change from the original. The second value should be " - "equal.\n"); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Close the File, so the changes are recorded */ - if(!CloseHandle(hFile)) - { - Fail("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test6/getfiletime.cpp b/src/pal/tests/palsuite/file_io/GetFileTime/test6/getfiletime.cpp new file mode 100644 index 0000000000..3eedddf82d --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test6/getfiletime.cpp @@ -0,0 +1,281 @@ +// 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: GetFileTime.c +** +** Purpose: Tests the PAL implementation of the GetFileTime function. +** Perform two reads from a file without closing until the end +** of the test and verify that only the access times change. +** Note: Under Win32, modify time changes as well so we will +** check that it doesn't go backwards +** +** Depends: +** FileTimeToDosDateTime +** CreateFile +** ReadFile +** WriteFile +** CloseHandle +** +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME Creation; + FILETIME LastAccess; + FILETIME LastWrite; + HANDLE hFile; + ULONG64 FirstWrite = (ULONG64)0; + ULONG64 SecondWrite = (ULONG64)0; + ULONG64 FirstCreationTime = (ULONG64)0; + ULONG64 SecondCreationTime = (ULONG64)0; + DWORD temp; + char ReadBuffer[10]; + WORD DosDateOne; + WORD DosDateTwo; + WORD DosTime; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + memset(&Creation, 0, sizeof(FILETIME)); + memset(&LastAccess, 0, sizeof(FILETIME)); + memset(&LastWrite, 0, sizeof(FILETIME)); + + /* Create the file to get a HANDLE */ + hFile = CreateFile("test.tmp", + GENERIC_READ|GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to create the file. The error number " + "returned was %u.\n", + GetLastError()); + } + + /* give us something to read from the file */ + if(!WriteFile(hFile, "something", 9, &temp, NULL)) + { + Trace("ERROR: Failed to write to file. " + "GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* let's do a read to set the file times for our test */ + if(!ReadFile(hFile, &ReadBuffer, 2, &temp, NULL)) + { + Trace("ERROR: Failed to read from the file. " + "GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Get the Last Write, Creation and Access File time of the file */ + if(GetFileTime(hFile, &Creation, &LastAccess, &LastWrite)==0) + { + Trace("ERROR: GetFileTime returned 0, indicating failure." + " GetLastError returned %u\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Call FileTimeToDosDateTime so we can aquire just the date + portion of the Last Access FILETIME. + */ + if(FileTimeToDosDateTime(&LastAccess, &DosDateOne, &DosTime) == 0) + { + Trace("ERROR: FiletimeToDosDateTime failed, returning 0. " + "GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Convert the structure to an ULONG64 */ + FirstCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + FirstWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + /* Sleep for 3 seconds, this will ensure the time changes */ + Sleep(3000); + + /* Read from the file -- this should change + last access, but we'll only check the date portion, because some file + systems have a resolution of a day. + */ + memset(&Creation, 0, sizeof(FILETIME)); + memset(&LastAccess, 0, sizeof(FILETIME)); + memset(&LastWrite, 0, sizeof(FILETIME)); + + if(!ReadFile(hFile, &ReadBuffer, 2, &temp, NULL)) + { + Trace("ERROR: Failed to read from the file. " + "GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + + /* Call GetFileTime to get the updated time values*/ + if(GetFileTime(hFile, &Creation, &LastAccess, &LastWrite) == 0) + { + Trace("ERROR: GetFileTime returned 0, indicating failure. " + "GetLastError returned %d.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Get the Date of the LastAccessTime here again. */ + if(FileTimeToDosDateTime(&LastAccess, &DosDateTwo, &DosTime) == 0) + { + Trace("ERROR: FileTimeToDosDateTime failed, returning 0. " + "GetLastError returned %d.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + + /* Store the results in a ULONG64 */ + SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + /* Now -- to test. We'll ensure that the SecondWrite + time is not less than the FirstWrite time + */ + + if(SecondWrite < FirstWrite) + { + Trace("ERROR: The write-file-time (%I64d) after the first read " + "is less than the write-file-time (%I64d) after the second " + "read.\n", + FirstWrite, + LastWrite); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* + For LastAccessTime, just check that the date is greater or equal + for the second over the first. The time is not conisered on some + file systems. (such as fat32) + */ + + if(DosDateOne > DosDateTwo) + { + Trace("ERROR: The last-access-time after reading should have " + "stayed the same or increased, but it did not.\n"); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + + /* Check to ensure CreationTime hasn't changed. This should not + have changed in either environment. + */ + + if(FirstCreationTime != SecondCreationTime) + { + Trace("ERROR: The creation time after reading should not " + "not change from the original. The second value should be " + "equal.\n"); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Close the File, so the changes are recorded */ + if(!CloseHandle(hFile)) + { + Fail("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test7/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileTime/test7/CMakeLists.txt index 6646fd9272..cd5cde4d9e 100644 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - getfiletime.c + getfiletime.cpp ) add_executable(paltest_getfiletime_test7 diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test7/getfiletime.c b/src/pal/tests/palsuite/file_io/GetFileTime/test7/getfiletime.c deleted file mode 100644 index d33175b8ec..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileTime/test7/getfiletime.c +++ /dev/null @@ -1,279 +0,0 @@ -// 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: GetFileTime.c -** -** Purpose: Test the PAL implementation of GetFileTime. This test -** creates a file and compares create and write times after -** the buffers are flushed, but before the close, and verifies -** the results are as expected -** -** Depends: -** CreateFile -** WriteFile -** FlushFileBuffers -** CloseHandle -** -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char **argv) -{ - FILETIME Creation; - FILETIME LastAccess; - FILETIME LastWrite; - HANDLE hFile; - ULONG64 FirstWrite; - ULONG64 SecondWrite; - ULONG64 FirstAccess; - ULONG64 SecondAccess; - ULONG64 FirstCreationTime; - ULONG64 SecondCreationTime; - DWORD temp; - const char* someText = "1234567890123456789012345678901234567890"; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Open the file to get a HANDLE */ - hFile = CreateFile("test.tmp", - GENERIC_READ|GENERIC_WRITE, - 0, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to create the file. The error number " - "returned was %u.\n", - GetLastError()); - } - - /* Write to the file -- this should change write access and - last access - */ - if(!WriteFile(hFile, someText, strlen(someText), &temp, NULL)) - { - Trace("ERROR: Failed to write to file. The file must be " - "written to in order to test that the write time is " - "updated. GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Flush the buffers */ - if(!FlushFileBuffers(hFile)) - { - Trace("ERROR: The FlushFileBuffers function failed. " - "GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Get the Last Write, Creation and Access File time of that File */ - if(!GetFileTime(hFile, &Creation, &LastAccess, &LastWrite)) - { - Trace("ERROR: GetFileTime returned 0, indicating failure." - " GetLastError returned %u\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Convert the structures to an ULONG64 */ - FirstCreationTime = ((((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - FirstWrite = ((((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - FirstAccess = ((((ULONG64)LastAccess.dwHighDateTime)<<32) | - ((ULONG64)LastAccess.dwLowDateTime)); - - /* Sleep for 3 seconds, this will ensure the time changes */ - Sleep(3000); - - /* Write to the file again so we have something to flush */ - if(!WriteFile(hFile, someText, strlen(someText), &temp, NULL)) - { - Trace("ERROR: Failed to write to file. The file must be " - "written to in order to test that the write time is " - "updated. GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Flush the buffers forcing the access/mod time to change */ - if(!FlushFileBuffers(hFile)) - { - Trace("ERROR: The FlushFileBuffers function failed. " - "GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - - /* Call GetFileTime again */ - if(!GetFileTime(hFile,&Creation,&LastAccess,&LastWrite)) - { - Trace("ERROR: GetFileTime returned 0, indicating failure." - "GetLastError returned %u.\n", - GetLastError()); - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail(""); - } - - /* Store the results in a ULONG64 */ - - SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | - ((ULONG64)Creation.dwLowDateTime)); - - SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | - ((ULONG64)LastWrite.dwLowDateTime)); - - SecondAccess = ((((ULONG64)LastAccess.dwHighDateTime)<<32) | - ((ULONG64)LastAccess.dwLowDateTime)); - - - /* Now -- to test. We'll ensure that the Second - LastWrite and access times are larger than the first. - It tells us that time is passing, which is good! - */ - - if(FirstWrite >= SecondWrite) - { - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("ERROR: The write-file-time (%I64d) after the first flush " - "should be less than the write-file-time (%I64d) after the second " - "flush.\n", - FirstWrite, - LastWrite); - - } - - - if(SecondAccess < FirstAccess) - { - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("ERROR: The access-file-time (%I64d) after the first flush " - "should be less than or equal to the access-file-time (%I64d) " - "after the second flush.\n", - FirstAccess, - LastAccess); - } - -#if WIN32 - /* Then we can check to make sure that the creation time - hasn't changed. This should always stay the same. - */ - - if(FirstCreationTime != SecondCreationTime) - { - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("ERROR: The creation time after writing should not " - "not change from the original. The second value should be " - "equal.\n"); - } -#else - /* Then we can check to make sure that the creation time - has changed. Under FreeBSD it changes whenever the file is - access or written. - */ - - if(FirstCreationTime >= SecondCreationTime) - { - /* Close the File */ - if(!CloseHandle(hFile)) - { - Trace("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - Fail("ERROR: The creation time after writing should be " - "greater than the original. The second value should be " - "larger.\n"); - } - -#endif - - /* Close the File */ - if(!CloseHandle(hFile)) - { - Fail("ERROR: Failed to close the file handle. " - "GetLastError returned %u.\n", - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test7/getfiletime.cpp b/src/pal/tests/palsuite/file_io/GetFileTime/test7/getfiletime.cpp new file mode 100644 index 0000000000..d33175b8ec --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test7/getfiletime.cpp @@ -0,0 +1,279 @@ +// 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: GetFileTime.c +** +** Purpose: Test the PAL implementation of GetFileTime. This test +** creates a file and compares create and write times after +** the buffers are flushed, but before the close, and verifies +** the results are as expected +** +** Depends: +** CreateFile +** WriteFile +** FlushFileBuffers +** CloseHandle +** +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char **argv) +{ + FILETIME Creation; + FILETIME LastAccess; + FILETIME LastWrite; + HANDLE hFile; + ULONG64 FirstWrite; + ULONG64 SecondWrite; + ULONG64 FirstAccess; + ULONG64 SecondAccess; + ULONG64 FirstCreationTime; + ULONG64 SecondCreationTime; + DWORD temp; + const char* someText = "1234567890123456789012345678901234567890"; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Open the file to get a HANDLE */ + hFile = CreateFile("test.tmp", + GENERIC_READ|GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to create the file. The error number " + "returned was %u.\n", + GetLastError()); + } + + /* Write to the file -- this should change write access and + last access + */ + if(!WriteFile(hFile, someText, strlen(someText), &temp, NULL)) + { + Trace("ERROR: Failed to write to file. The file must be " + "written to in order to test that the write time is " + "updated. GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Flush the buffers */ + if(!FlushFileBuffers(hFile)) + { + Trace("ERROR: The FlushFileBuffers function failed. " + "GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Get the Last Write, Creation and Access File time of that File */ + if(!GetFileTime(hFile, &Creation, &LastAccess, &LastWrite)) + { + Trace("ERROR: GetFileTime returned 0, indicating failure." + " GetLastError returned %u\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Convert the structures to an ULONG64 */ + FirstCreationTime = ((((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + FirstWrite = ((((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + FirstAccess = ((((ULONG64)LastAccess.dwHighDateTime)<<32) | + ((ULONG64)LastAccess.dwLowDateTime)); + + /* Sleep for 3 seconds, this will ensure the time changes */ + Sleep(3000); + + /* Write to the file again so we have something to flush */ + if(!WriteFile(hFile, someText, strlen(someText), &temp, NULL)) + { + Trace("ERROR: Failed to write to file. The file must be " + "written to in order to test that the write time is " + "updated. GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Flush the buffers forcing the access/mod time to change */ + if(!FlushFileBuffers(hFile)) + { + Trace("ERROR: The FlushFileBuffers function failed. " + "GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + + /* Call GetFileTime again */ + if(!GetFileTime(hFile,&Creation,&LastAccess,&LastWrite)) + { + Trace("ERROR: GetFileTime returned 0, indicating failure." + "GetLastError returned %u.\n", + GetLastError()); + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* Store the results in a ULONG64 */ + + SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + SecondWrite = ( (((ULONG64)LastWrite.dwHighDateTime)<<32) | + ((ULONG64)LastWrite.dwLowDateTime)); + + SecondAccess = ((((ULONG64)LastAccess.dwHighDateTime)<<32) | + ((ULONG64)LastAccess.dwLowDateTime)); + + + /* Now -- to test. We'll ensure that the Second + LastWrite and access times are larger than the first. + It tells us that time is passing, which is good! + */ + + if(FirstWrite >= SecondWrite) + { + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("ERROR: The write-file-time (%I64d) after the first flush " + "should be less than the write-file-time (%I64d) after the second " + "flush.\n", + FirstWrite, + LastWrite); + + } + + + if(SecondAccess < FirstAccess) + { + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("ERROR: The access-file-time (%I64d) after the first flush " + "should be less than or equal to the access-file-time (%I64d) " + "after the second flush.\n", + FirstAccess, + LastAccess); + } + +#if WIN32 + /* Then we can check to make sure that the creation time + hasn't changed. This should always stay the same. + */ + + if(FirstCreationTime != SecondCreationTime) + { + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("ERROR: The creation time after writing should not " + "not change from the original. The second value should be " + "equal.\n"); + } +#else + /* Then we can check to make sure that the creation time + has changed. Under FreeBSD it changes whenever the file is + access or written. + */ + + if(FirstCreationTime >= SecondCreationTime) + { + /* Close the File */ + if(!CloseHandle(hFile)) + { + Trace("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("ERROR: The creation time after writing should be " + "greater than the original. The second value should be " + "larger.\n"); + } + +#endif + + /* Close the File */ + if(!CloseHandle(hFile)) + { + Fail("ERROR: Failed to close the file handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetFileType/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileType/test1/CMakeLists.txt index 66467e99c5..cfaba2e738 100644 --- a/src/pal/tests/palsuite/file_io/GetFileType/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileType/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFileType.c + GetFileType.cpp ) add_executable(paltest_getfiletype_test1 diff --git a/src/pal/tests/palsuite/file_io/GetFileType/test1/GetFileType.c b/src/pal/tests/palsuite/file_io/GetFileType/test1/GetFileType.c deleted file mode 100644 index 6558c00bdd..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileType/test1/GetFileType.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: GetFileType.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetFileType function. -** -** -**===================================================================*/ - -#include - -const char* szTextFile = "text.txt"; - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwRc = 0; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - /* test FILE_TYPE_UNKNOWN */ - dwRc = GetFileType(hFile); - if (dwRc != FILE_TYPE_UNKNOWN) - { - Fail("GetFileType: ERROR -> Was expecting a return type of " - "FILE_TYPE_UNKNOWN but the function returned %ld.\n", - dwRc); - } - - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("GetFileType: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - dwRc = GetFileType(hFile); - if (CloseHandle(hFile) != TRUE) - { - Fail("GetFileType: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Fail("GetFileType: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - - if (dwRc != FILE_TYPE_DISK) - { - Fail("GetFileType: ERROR -> Was expecting a return type of " - "FILE_TYPE_DISK but the function returned %ld.\n", - dwRc); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileType/test1/GetFileType.cpp b/src/pal/tests/palsuite/file_io/GetFileType/test1/GetFileType.cpp new file mode 100644 index 0000000000..6558c00bdd --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileType/test1/GetFileType.cpp @@ -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: GetFileType.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetFileType function. +** +** +**===================================================================*/ + +#include + +const char* szTextFile = "text.txt"; + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwRc = 0; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + /* test FILE_TYPE_UNKNOWN */ + dwRc = GetFileType(hFile); + if (dwRc != FILE_TYPE_UNKNOWN) + { + Fail("GetFileType: ERROR -> Was expecting a return type of " + "FILE_TYPE_UNKNOWN but the function returned %ld.\n", + dwRc); + } + + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("GetFileType: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + dwRc = GetFileType(hFile); + if (CloseHandle(hFile) != TRUE) + { + Fail("GetFileType: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Fail("GetFileType: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + + if (dwRc != FILE_TYPE_DISK) + { + Fail("GetFileType: ERROR -> Was expecting a return type of " + "FILE_TYPE_DISK but the function returned %ld.\n", + dwRc); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFileType/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileType/test2/CMakeLists.txt index 382b27e788..07dae0b04a 100644 --- a/src/pal/tests/palsuite/file_io/GetFileType/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileType/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - getfiletype.c + getfiletype.cpp ) add_executable(paltest_getfiletype_test2 diff --git a/src/pal/tests/palsuite/file_io/GetFileType/test2/getfiletype.c b/src/pal/tests/palsuite/file_io/GetFileType/test2/getfiletype.c deleted file mode 100644 index c9d4eb6572..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileType/test2/getfiletype.c +++ /dev/null @@ -1,95 +0,0 @@ -// 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: getfiletype.c -** -** Purpose: Test the PAL implementation of GetFileType to ensure it -** recognizes opened pipes. -** -** Depends: CreatePipe -** CloseHandle -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char **argv) -{ - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - BOOL bRetVal = FALSE; - DWORD dwFileType; - SECURITY_ATTRIBUTES lpPipeAttributes; - - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /* - ** create a pipe and make sure GetFileType returns the correct value - */ - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /*Create a Pipe*/ - bRetVal = CreatePipe(&hReadPipe, /* read handle*/ - &hWritePipe, /* write handle */ - &lpPipeAttributes, /* security attributes*/ - 0); /* pipe size*/ - if (bRetVal == FALSE) - { - Fail("ERROR: %u :Unable to create pipe.\n", GetLastError()); - } - - // Get the file type - dwFileType = GetFileType(hReadPipe); - if (dwFileType != FILE_TYPE_PIPE) - { - if (!CloseHandle(hWritePipe)) - { - Trace("ERROR: %u : Unable to close write pipe handle " - "hWritePipe=0x%lx\n", GetLastError(), hWritePipe); - } - if (!CloseHandle(hReadPipe)) - { - Trace("ERROR: %u : Unable to close read pipe handle " - "hReadPipe=0x%lx\n", GetLastError(), hReadPipe); - } - Fail("ERROR: GetFileType returned %u for a pipe instead of the " - "expected FILE_TYPE_PIPE (%u).\n", - dwFileType, - FILE_TYPE_PIPE); - } - - /*Close write pipe handle*/ - if (!CloseHandle(hWritePipe)) - { - if (!CloseHandle(hReadPipe)) - { - Trace("ERROR: %u : Unable to close read pipe handle " - "hReadPipe=0x%lx\n", GetLastError(), hReadPipe); - } - Fail("ERROR: %u : Unable to close write pipe handle " - "hWritePipe=0x%lx\n", GetLastError(), hWritePipe); - } - - /*Close Read pipe handle*/ - if (!CloseHandle(hReadPipe)) - { - Fail("ERROR: %u : Unable to close read pipe handle " - "hReadPipe=0x%lx\n", GetLastError(), hReadPipe); - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/file_io/GetFileType/test2/getfiletype.cpp b/src/pal/tests/palsuite/file_io/GetFileType/test2/getfiletype.cpp new file mode 100644 index 0000000000..c9d4eb6572 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileType/test2/getfiletype.cpp @@ -0,0 +1,95 @@ +// 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: getfiletype.c +** +** Purpose: Test the PAL implementation of GetFileType to ensure it +** recognizes opened pipes. +** +** Depends: CreatePipe +** CloseHandle +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + DWORD dwFileType; + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /* + ** create a pipe and make sure GetFileType returns the correct value + */ + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, /* read handle*/ + &hWritePipe, /* write handle */ + &lpPipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + if (bRetVal == FALSE) + { + Fail("ERROR: %u :Unable to create pipe.\n", GetLastError()); + } + + // Get the file type + dwFileType = GetFileType(hReadPipe); + if (dwFileType != FILE_TYPE_PIPE) + { + if (!CloseHandle(hWritePipe)) + { + Trace("ERROR: %u : Unable to close write pipe handle " + "hWritePipe=0x%lx\n", GetLastError(), hWritePipe); + } + if (!CloseHandle(hReadPipe)) + { + Trace("ERROR: %u : Unable to close read pipe handle " + "hReadPipe=0x%lx\n", GetLastError(), hReadPipe); + } + Fail("ERROR: GetFileType returned %u for a pipe instead of the " + "expected FILE_TYPE_PIPE (%u).\n", + dwFileType, + FILE_TYPE_PIPE); + } + + /*Close write pipe handle*/ + if (!CloseHandle(hWritePipe)) + { + if (!CloseHandle(hReadPipe)) + { + Trace("ERROR: %u : Unable to close read pipe handle " + "hReadPipe=0x%lx\n", GetLastError(), hReadPipe); + } + Fail("ERROR: %u : Unable to close write pipe handle " + "hWritePipe=0x%lx\n", GetLastError(), hWritePipe); + } + + /*Close Read pipe handle*/ + if (!CloseHandle(hReadPipe)) + { + Fail("ERROR: %u : Unable to close read pipe handle " + "hReadPipe=0x%lx\n", GetLastError(), hReadPipe); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/file_io/GetFileType/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFileType/test3/CMakeLists.txt index 52b6077570..9353c85771 100644 --- a/src/pal/tests/palsuite/file_io/GetFileType/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFileType/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - getfiletype.c + getfiletype.cpp ) add_executable(paltest_getfiletype_test3 diff --git a/src/pal/tests/palsuite/file_io/GetFileType/test3/getfiletype.c b/src/pal/tests/palsuite/file_io/GetFileType/test3/getfiletype.c deleted file mode 100644 index 6a95585bab..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFileType/test3/getfiletype.c +++ /dev/null @@ -1,72 +0,0 @@ -// 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: getfiletype.c -** -** Purpose: Test the PAL implementation of the GetFileType on a handle -** to a console. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile; -#if WIN32 - char *lpFileName = "CONIN$"; -#else - char *lpFileName = "/dev/null"; -#endif - DWORD dwFileType; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* get a handle to the console */ - hFile = CreateFile(lpFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("GetFileType: ERROR: CreateFile failed to open %s with " - "error %u.\n", - lpFileName, - GetLastError()); - } - - /* Get the file type */ - if ((dwFileType = GetFileType(hFile)) != FILE_TYPE_CHAR) - { - if (!CloseHandle(hFile)) - { - Trace("GetFileType: ERROR: %u : Unable to close the handle " - "hFile=0x%lx\n", GetLastError(), hFile); - } - Fail("GetFileType: ERROR: GetFileType returned %u for a device " - "instead of the expected FILE_TYPE_CHAR (%u).\n", - dwFileType, - FILE_TYPE_CHAR); - } - - if (!CloseHandle(hFile)) - { - Fail("GetFileType: ERROR: %u : Unable to close the handle " - "hFile=0x%lx\n", GetLastError(), hFile); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetFileType/test3/getfiletype.cpp b/src/pal/tests/palsuite/file_io/GetFileType/test3/getfiletype.cpp new file mode 100644 index 0000000000..6a95585bab --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileType/test3/getfiletype.cpp @@ -0,0 +1,72 @@ +// 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: getfiletype.c +** +** Purpose: Test the PAL implementation of the GetFileType on a handle +** to a console. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile; +#if WIN32 + char *lpFileName = "CONIN$"; +#else + char *lpFileName = "/dev/null"; +#endif + DWORD dwFileType; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* get a handle to the console */ + hFile = CreateFile(lpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("GetFileType: ERROR: CreateFile failed to open %s with " + "error %u.\n", + lpFileName, + GetLastError()); + } + + /* Get the file type */ + if ((dwFileType = GetFileType(hFile)) != FILE_TYPE_CHAR) + { + if (!CloseHandle(hFile)) + { + Trace("GetFileType: ERROR: %u : Unable to close the handle " + "hFile=0x%lx\n", GetLastError(), hFile); + } + Fail("GetFileType: ERROR: GetFileType returned %u for a device " + "instead of the expected FILE_TYPE_CHAR (%u).\n", + dwFileType, + FILE_TYPE_CHAR); + } + + if (!CloseHandle(hFile)) + { + Fail("GetFileType: ERROR: %u : Unable to close the handle " + "hFile=0x%lx\n", GetLastError(), hFile); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/CMakeLists.txt index 8c10e479fa..6198392000 100644 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFullPathNameA.c + GetFullPathNameA.cpp ) add_executable(paltest_getfullpathnamea_test1 diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.c b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.c deleted file mode 100644 index de9a266f5a..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.c +++ /dev/null @@ -1,122 +0,0 @@ -// 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: GetFullPathNameA.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetFullPathNameA function. -** -** -**===================================================================*/ - -#include - -const char* szFileName = "testing.tmp"; - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwRc = 0; - char szReturnedPath[_MAX_DIR+1]; - char szShortBuff[2]; - LPSTR pPathPtr; - HANDLE hFile = NULL; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* perform a short buffer test */ - if (GetFullPathNameA(szFileName, 2, szShortBuff, &pPathPtr) <= 2) - { - /* this test should have failed but didn't */ - Fail("GetFullPathNameA: ERROR -> The API was passed a buffer that was" - " too small for the path name and yet it apparently passed.\n"); - } - - memset(szReturnedPath, 0, _MAX_DIR+1); - dwRc = GetFullPathNameA(szFileName, - _MAX_DIR, - szReturnedPath, - &pPathPtr); - - if (dwRc == 0) - { - // this test should have passed but didn't - Fail("GetFullPathNameA: ERROR -> Function failed for the " - "file \"%s\" with error code: %ld.\n", szFileName, GetLastError()); - } - - // the returned value should be the current directory with the - // file name appended - hFile = CreateFileA(szFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("GetFullPathNameA: ERROR -> CreateFileA failed to create " - "file \"%s\" with error code: %ld.\n", - szFileName, - GetLastError()); - } - if (CloseHandle(hFile) != TRUE) - { - Fail("GetFullPathNameA: ERROR -> CloseHandle failed with error " - "code: %ld.\n", GetLastError()); - } - - // now try to create the file based on the returned value with the - // CREATE_NEW option which should fail since the file should - // already exist - hFile = CreateFileA(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile != INVALID_HANDLE_VALUE) - { - Fail("GetFullPathNameA: ERROR -> CreateFileA was able to " - "CREATE_NEW the returned file \"%s\". The returned file " - "name is therefore apparently wrong.\n", - szReturnedPath); - if (CloseHandle(hFile) != TRUE) - { - Fail("GetFullPathNameA: ERROR -> CloseHandle failed with " - "error code: %ld.\n", GetLastError()); - } - if ((DeleteFileA(szReturnedPath) != TRUE) || - (DeleteFileA(szFileName) != TRUE)) - { - Fail("GetFullPathNameA: ERROR -> DeleteFileA failed to " - "delete the test files with error code: %ld.\n", - GetLastError()); - } - } - - // now make sure the pPathPtr is the same as the file name - if (strcmp(pPathPtr, szFileName) != 0) - { - Fail("GetFullPathNameA: ERROR -> %s != %s\n", - pPathPtr, szFileName); - } - if (DeleteFileA(szFileName) != TRUE) - { - Fail("GetFullPathNameA: ERROR -> DeleteFileA failed to " - "delete \"%s\" with error code: %ld.\n", - szFileName, - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp new file mode 100644 index 0000000000..de9a266f5a --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp @@ -0,0 +1,122 @@ +// 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: GetFullPathNameA.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetFullPathNameA function. +** +** +**===================================================================*/ + +#include + +const char* szFileName = "testing.tmp"; + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + char szReturnedPath[_MAX_DIR+1]; + char szShortBuff[2]; + LPSTR pPathPtr; + HANDLE hFile = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* perform a short buffer test */ + if (GetFullPathNameA(szFileName, 2, szShortBuff, &pPathPtr) <= 2) + { + /* this test should have failed but didn't */ + Fail("GetFullPathNameA: ERROR -> The API was passed a buffer that was" + " too small for the path name and yet it apparently passed.\n"); + } + + memset(szReturnedPath, 0, _MAX_DIR+1); + dwRc = GetFullPathNameA(szFileName, + _MAX_DIR, + szReturnedPath, + &pPathPtr); + + if (dwRc == 0) + { + // this test should have passed but didn't + Fail("GetFullPathNameA: ERROR -> Function failed for the " + "file \"%s\" with error code: %ld.\n", szFileName, GetLastError()); + } + + // the returned value should be the current directory with the + // file name appended + hFile = CreateFileA(szFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("GetFullPathNameA: ERROR -> CreateFileA failed to create " + "file \"%s\" with error code: %ld.\n", + szFileName, + GetLastError()); + } + if (CloseHandle(hFile) != TRUE) + { + Fail("GetFullPathNameA: ERROR -> CloseHandle failed with error " + "code: %ld.\n", GetLastError()); + } + + // now try to create the file based on the returned value with the + // CREATE_NEW option which should fail since the file should + // already exist + hFile = CreateFileA(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile != INVALID_HANDLE_VALUE) + { + Fail("GetFullPathNameA: ERROR -> CreateFileA was able to " + "CREATE_NEW the returned file \"%s\". The returned file " + "name is therefore apparently wrong.\n", + szReturnedPath); + if (CloseHandle(hFile) != TRUE) + { + Fail("GetFullPathNameA: ERROR -> CloseHandle failed with " + "error code: %ld.\n", GetLastError()); + } + if ((DeleteFileA(szReturnedPath) != TRUE) || + (DeleteFileA(szFileName) != TRUE)) + { + Fail("GetFullPathNameA: ERROR -> DeleteFileA failed to " + "delete the test files with error code: %ld.\n", + GetLastError()); + } + } + + // now make sure the pPathPtr is the same as the file name + if (strcmp(pPathPtr, szFileName) != 0) + { + Fail("GetFullPathNameA: ERROR -> %s != %s\n", + pPathPtr, szFileName); + } + if (DeleteFileA(szFileName) != TRUE) + { + Fail("GetFullPathNameA: ERROR -> DeleteFileA failed to " + "delete \"%s\" with error code: %ld.\n", + szFileName, + GetLastError()); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/CMakeLists.txt index 382b8fa4bd..3449f2d80b 100644 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_getfullpathnamea_test2 diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/test2.c b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/test2.c deleted file mode 100644 index 95a1497331..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/test2.c +++ /dev/null @@ -1,143 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests the PAL implementation of the GetFullPathNameA API. -** GetFullPathA will be passed a directory that contains '..'. -** To add to this test, we will also call SetCurrentDirectory to -** ensure this is handled properly. -** The test will create a file with in the parent directory -** to verify that the returned directory is valid. -** -** -**===================================================================*/ - -#include - -const char* szDotDot = "..\\"; -const char* szFileName = "testing.tmp"; - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwRc = 0; - char szReturnedPath[_MAX_DIR+1]; - char szFullFileName[_MAX_DIR+1]; - LPSTR pPathPtr; - HANDLE hFile = NULL; - - /* Initialize the PAL. - */ - if (0 != PAL_Initialize(argc,argv)) - { - return (FAIL); - } - - /* change the directory */ - if (!SetCurrentDirectoryA(szDotDot)) - { - Fail("ERROR: SetCurrentDirectoryA failed with error code %u" - " when passed \"%s\".\n", - GetLastError(), - szDotDot); - } - - /* Initialize the receiving char buffers. - */ - memset(szReturnedPath, 0, _MAX_DIR+1); - memset(szFullFileName, 0, _MAX_DIR+1); - - /* Create Full filename to pass, will include '..\' - * as a pre-fix. */ - strcat(szFullFileName, szDotDot); - strcat(szFullFileName, szFileName); - - /* Get the full path to the filename. - */ - dwRc = GetFullPathNameA(szFullFileName, - _MAX_DIR, - szReturnedPath, - &pPathPtr); - if (dwRc == 0) - { - Fail("ERROR :%ld: GetFullPathName failed to " - "retrieve the path of \"%s\".\n", - GetLastError(), - szFileName); - } - - /* The returned value should be the parent directory with the - * file name appended. */ - hFile = CreateFileA(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR :%ld: CreateFileA failed to create \"%s\".\n", - GetLastError(), - szReturnedPath); - } - - /* Close the handle to the created file. - */ - if (CloseHandle(hFile) != TRUE) - { - Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", - GetLastError()); - goto terminate; - } - - /* Verify that the file was created, attempt to create - * the file again. */ - hFile = CreateFileA(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); - if ((hFile != INVALID_HANDLE_VALUE) && - (GetLastError() != ERROR_ALREADY_EXISTS)) - { - Fail("ERROR :%ld: CreateFileA succeeded to create file " - "\"%s\", that already existed.\n", - GetLastError(), - szFullFileName); - } - - - /* Verify that the returned filename is the same as the supplied. - */ - if (strcmp(pPathPtr, szFileName) != 0) - { - Trace("ERROR : Returned filename \"%s\" is not equal to " - "supplied filename \"%s\".\n", - pPathPtr, - szFileName); - goto terminate; - } - -terminate: - /* Delete the create file. - */ - if (DeleteFileA(szReturnedPath) != TRUE) - { - Fail("ERROR :%ld: DeleteFileA failed to delete \"%s\".\n", - GetLastError(), - szFileName); - } - - /* Terminate the PAL.*/ - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/test2.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/test2.cpp new file mode 100644 index 0000000000..95a1497331 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test2/test2.cpp @@ -0,0 +1,143 @@ +// 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: test2.c +** +** Purpose: Tests the PAL implementation of the GetFullPathNameA API. +** GetFullPathA will be passed a directory that contains '..'. +** To add to this test, we will also call SetCurrentDirectory to +** ensure this is handled properly. +** The test will create a file with in the parent directory +** to verify that the returned directory is valid. +** +** +**===================================================================*/ + +#include + +const char* szDotDot = "..\\"; +const char* szFileName = "testing.tmp"; + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + char szReturnedPath[_MAX_DIR+1]; + char szFullFileName[_MAX_DIR+1]; + LPSTR pPathPtr; + HANDLE hFile = NULL; + + /* Initialize the PAL. + */ + if (0 != PAL_Initialize(argc,argv)) + { + return (FAIL); + } + + /* change the directory */ + if (!SetCurrentDirectoryA(szDotDot)) + { + Fail("ERROR: SetCurrentDirectoryA failed with error code %u" + " when passed \"%s\".\n", + GetLastError(), + szDotDot); + } + + /* Initialize the receiving char buffers. + */ + memset(szReturnedPath, 0, _MAX_DIR+1); + memset(szFullFileName, 0, _MAX_DIR+1); + + /* Create Full filename to pass, will include '..\' + * as a pre-fix. */ + strcat(szFullFileName, szDotDot); + strcat(szFullFileName, szFileName); + + /* Get the full path to the filename. + */ + dwRc = GetFullPathNameA(szFullFileName, + _MAX_DIR, + szReturnedPath, + &pPathPtr); + if (dwRc == 0) + { + Fail("ERROR :%ld: GetFullPathName failed to " + "retrieve the path of \"%s\".\n", + GetLastError(), + szFileName); + } + + /* The returned value should be the parent directory with the + * file name appended. */ + hFile = CreateFileA(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR :%ld: CreateFileA failed to create \"%s\".\n", + GetLastError(), + szReturnedPath); + } + + /* Close the handle to the created file. + */ + if (CloseHandle(hFile) != TRUE) + { + Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", + GetLastError()); + goto terminate; + } + + /* Verify that the file was created, attempt to create + * the file again. */ + hFile = CreateFileA(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + NULL); + if ((hFile != INVALID_HANDLE_VALUE) && + (GetLastError() != ERROR_ALREADY_EXISTS)) + { + Fail("ERROR :%ld: CreateFileA succeeded to create file " + "\"%s\", that already existed.\n", + GetLastError(), + szFullFileName); + } + + + /* Verify that the returned filename is the same as the supplied. + */ + if (strcmp(pPathPtr, szFileName) != 0) + { + Trace("ERROR : Returned filename \"%s\" is not equal to " + "supplied filename \"%s\".\n", + pPathPtr, + szFileName); + goto terminate; + } + +terminate: + /* Delete the create file. + */ + if (DeleteFileA(szReturnedPath) != TRUE) + { + Fail("ERROR :%ld: DeleteFileA failed to delete \"%s\".\n", + GetLastError(), + szFileName); + } + + /* Terminate the PAL.*/ + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/CMakeLists.txt index f0f8929b4a..9d8d242e26 100644 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_getfullpathnamea_test3 diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/test3.c b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/test3.c deleted file mode 100644 index 0cc39e7300..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/test3.c +++ /dev/null @@ -1,241 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests the PAL implementation of the GetFullPathNameA API. -** GetFullPathA will be passed a directory that contains '..'. -** Example: test_directory\level1\..\testing.tmp. -** To add to this test, we will also call SetCurrentDirectory to -** ensure this is handled properly. -** The test will create a file with in the parent directory -** to verify that the returned directory is valid. -** -** Depends: SetCurrentDirectory, -** CreateDirectory, -** strcat, -** memset, -** CreateFile, -** CloseHandle, -** strcmp, -** DeleteFileA, -** RemoveDirectory. -** - -** -**===================================================================*/ - -#include - -#ifdef WIN32 - const char* szSeperator = "\\"; -#else - const char* szSeperator = "//"; -#endif - -const char* szDotDot = "..\\"; -const char* szFileName = "testing.tmp"; - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwRc = 0; - char szReturnedPath[_MAX_DIR+1]; - char szFullFileName[_MAX_DIR+1]; - char szDirectory[256]; - char* szCreatedDir = {"test_directory"}; - char* szCreatedNextDir = {"level1"}; - WCHAR *szCreatedDirW; - LPSTR pPathPtr; - HANDLE hFile = NULL; - BOOL bRetVal = FAIL; - - /* Initialize the PAL. - */ - if (0 != PAL_Initialize(argc,argv)) - { - return (FAIL); - } - - /* Initialize the buffer. - */ - memset(szDirectory, '\0', 256); - - /* Change the current working directory. - */ - if (!SetCurrentDirectoryA(szDotDot)) - { - Fail("ERROR: SetCurrentDirectoryA failed with error code %u" - " when passed \"%s\".\n", - GetLastError(), - szDotDot); - } - - /* Create the path to the next level of directory to create. - */ - strcat( szDirectory, szCreatedDir ); - - - /* Create a test directory. - */ - if ( !CreateDirectoryA( szDirectory, NULL ) ) - { - Fail("ERROR:%u: Unable to create directories \"%s\".\n", - GetLastError(), - szDirectory); - } - - /* Create the path to the next level of directory to create. - */ - strcat( szDirectory, szSeperator ); - strcat( szDirectory, szCreatedNextDir ); - - /* Create a test directory. - */ - if ( !CreateDirectoryA( szDirectory, NULL ) ) - { - Trace("ERROR:%u: Unable to create directories \"%s\".\n", - GetLastError(), - szDirectory); - bRetVal = FAIL; - goto cleanUpOne; - } - - /* Initialize the receiving char buffers. - */ - memset(szReturnedPath, 0, _MAX_DIR+1); - memset(szFullFileName, 0, _MAX_DIR+1); - - /* Create Full filename to pass, will include '..\' - * in the middle of the path. - */ - strcat(szFullFileName, szCreatedDir); - strcat(szFullFileName, szDotDot); - strcat(szFullFileName, szFileName); - - /* Get the full path to the filename. - */ - dwRc = GetFullPathNameA(szFullFileName, - _MAX_DIR, - szReturnedPath, - &pPathPtr); - if (dwRc == 0) - { - Trace("ERROR :%ld: GetFullPathName failed to " - "retrieve the path of \"%s\".\n", - GetLastError(), - szFileName); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* The returned value should be the parent directory with the - * file name appended. */ - hFile = CreateFileA(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR :%ld: CreateFileA failed to create \"%s\".\n", - GetLastError(), - szReturnedPath); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* Close the handle to the created file. - */ - if (CloseHandle(hFile) != TRUE) - { - Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", - GetLastError()); - bRetVal = FAIL; - goto cleanUpThree; - } - - /* Verify that the file was created, attempt to create - * the file again. */ - hFile = CreateFileA(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); - if ((hFile != INVALID_HANDLE_VALUE) && - (GetLastError() != ERROR_ALREADY_EXISTS)) - { - Trace("ERROR :%ld: CreateFileA succeeded to create file " - "\"%s\", that already existed.\n", - GetLastError(), - szFullFileName); - bRetVal = FAIL; - goto cleanUpThree; - } - - /* Verify that the returned filename is the same as the supplied. - */ - if (strcmp(pPathPtr, szFileName) != 0) - { - Trace("ERROR : Returned filename \"%s\" is not equal to " - "supplied filename \"%s\".\n", - pPathPtr, - szFileName); - bRetVal = FAIL; - goto cleanUpThree; - } - - /* Successful test. - */ - bRetVal = PASS; - -cleanUpThree: - - /* Delete the create file. - */ - if (DeleteFileA(szReturnedPath) != TRUE) - { - Fail("ERROR :%ld: DeleteFileA failed to delete \"%s\".\n", - GetLastError(), - szFileName); - } - -cleanUpTwo: - - /* Remove the empty directory. - */ - szCreatedDirW = convert((LPSTR)szDirectory); - if (!RemoveDirectoryW(szCreatedDirW)) - { - free (szCreatedDirW); - Fail("ERROR:%u: Unable to remove directory \"%s\".\n", - GetLastError(), - szCreatedDir); - } - free (szCreatedDirW); - -cleanUpOne: - - /* Remove the empty directory. - */ - szCreatedDirW = convert((LPSTR)szCreatedDir); - if (!RemoveDirectoryW(szCreatedDirW)) - { - free (szCreatedDirW); - Fail("ERROR:%u: Unable to remove directory \"%s\".\n", - GetLastError(), - szCreatedDir); - } - free (szCreatedDirW); - - /* Terminate the PAL.*/ - PAL_Terminate(); - return bRetVal; -} diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/test3.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/test3.cpp new file mode 100644 index 0000000000..0cc39e7300 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test3/test3.cpp @@ -0,0 +1,241 @@ +// 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: test3.c +** +** Purpose: Tests the PAL implementation of the GetFullPathNameA API. +** GetFullPathA will be passed a directory that contains '..'. +** Example: test_directory\level1\..\testing.tmp. +** To add to this test, we will also call SetCurrentDirectory to +** ensure this is handled properly. +** The test will create a file with in the parent directory +** to verify that the returned directory is valid. +** +** Depends: SetCurrentDirectory, +** CreateDirectory, +** strcat, +** memset, +** CreateFile, +** CloseHandle, +** strcmp, +** DeleteFileA, +** RemoveDirectory. +** + +** +**===================================================================*/ + +#include + +#ifdef WIN32 + const char* szSeperator = "\\"; +#else + const char* szSeperator = "//"; +#endif + +const char* szDotDot = "..\\"; +const char* szFileName = "testing.tmp"; + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + char szReturnedPath[_MAX_DIR+1]; + char szFullFileName[_MAX_DIR+1]; + char szDirectory[256]; + char* szCreatedDir = {"test_directory"}; + char* szCreatedNextDir = {"level1"}; + WCHAR *szCreatedDirW; + LPSTR pPathPtr; + HANDLE hFile = NULL; + BOOL bRetVal = FAIL; + + /* Initialize the PAL. + */ + if (0 != PAL_Initialize(argc,argv)) + { + return (FAIL); + } + + /* Initialize the buffer. + */ + memset(szDirectory, '\0', 256); + + /* Change the current working directory. + */ + if (!SetCurrentDirectoryA(szDotDot)) + { + Fail("ERROR: SetCurrentDirectoryA failed with error code %u" + " when passed \"%s\".\n", + GetLastError(), + szDotDot); + } + + /* Create the path to the next level of directory to create. + */ + strcat( szDirectory, szCreatedDir ); + + + /* Create a test directory. + */ + if ( !CreateDirectoryA( szDirectory, NULL ) ) + { + Fail("ERROR:%u: Unable to create directories \"%s\".\n", + GetLastError(), + szDirectory); + } + + /* Create the path to the next level of directory to create. + */ + strcat( szDirectory, szSeperator ); + strcat( szDirectory, szCreatedNextDir ); + + /* Create a test directory. + */ + if ( !CreateDirectoryA( szDirectory, NULL ) ) + { + Trace("ERROR:%u: Unable to create directories \"%s\".\n", + GetLastError(), + szDirectory); + bRetVal = FAIL; + goto cleanUpOne; + } + + /* Initialize the receiving char buffers. + */ + memset(szReturnedPath, 0, _MAX_DIR+1); + memset(szFullFileName, 0, _MAX_DIR+1); + + /* Create Full filename to pass, will include '..\' + * in the middle of the path. + */ + strcat(szFullFileName, szCreatedDir); + strcat(szFullFileName, szDotDot); + strcat(szFullFileName, szFileName); + + /* Get the full path to the filename. + */ + dwRc = GetFullPathNameA(szFullFileName, + _MAX_DIR, + szReturnedPath, + &pPathPtr); + if (dwRc == 0) + { + Trace("ERROR :%ld: GetFullPathName failed to " + "retrieve the path of \"%s\".\n", + GetLastError(), + szFileName); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* The returned value should be the parent directory with the + * file name appended. */ + hFile = CreateFileA(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR :%ld: CreateFileA failed to create \"%s\".\n", + GetLastError(), + szReturnedPath); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* Close the handle to the created file. + */ + if (CloseHandle(hFile) != TRUE) + { + Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", + GetLastError()); + bRetVal = FAIL; + goto cleanUpThree; + } + + /* Verify that the file was created, attempt to create + * the file again. */ + hFile = CreateFileA(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + NULL); + if ((hFile != INVALID_HANDLE_VALUE) && + (GetLastError() != ERROR_ALREADY_EXISTS)) + { + Trace("ERROR :%ld: CreateFileA succeeded to create file " + "\"%s\", that already existed.\n", + GetLastError(), + szFullFileName); + bRetVal = FAIL; + goto cleanUpThree; + } + + /* Verify that the returned filename is the same as the supplied. + */ + if (strcmp(pPathPtr, szFileName) != 0) + { + Trace("ERROR : Returned filename \"%s\" is not equal to " + "supplied filename \"%s\".\n", + pPathPtr, + szFileName); + bRetVal = FAIL; + goto cleanUpThree; + } + + /* Successful test. + */ + bRetVal = PASS; + +cleanUpThree: + + /* Delete the create file. + */ + if (DeleteFileA(szReturnedPath) != TRUE) + { + Fail("ERROR :%ld: DeleteFileA failed to delete \"%s\".\n", + GetLastError(), + szFileName); + } + +cleanUpTwo: + + /* Remove the empty directory. + */ + szCreatedDirW = convert((LPSTR)szDirectory); + if (!RemoveDirectoryW(szCreatedDirW)) + { + free (szCreatedDirW); + Fail("ERROR:%u: Unable to remove directory \"%s\".\n", + GetLastError(), + szCreatedDir); + } + free (szCreatedDirW); + +cleanUpOne: + + /* Remove the empty directory. + */ + szCreatedDirW = convert((LPSTR)szCreatedDir); + if (!RemoveDirectoryW(szCreatedDirW)) + { + free (szCreatedDirW); + Fail("ERROR:%u: Unable to remove directory \"%s\".\n", + GetLastError(), + szCreatedDir); + } + free (szCreatedDirW); + + /* Terminate the PAL.*/ + PAL_Terminate(); + return bRetVal; +} diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/CMakeLists.txt index cf0d7ff18c..abf2bacd1c 100644 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_getfullpathnamea_test4 diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/test4.c b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/test4.c deleted file mode 100644 index fb22c1f07b..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/test4.c +++ /dev/null @@ -1,203 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests the PAL implementation of the GetFullPathNameA API. -** GetFullPathA will be passed a directory that begins with '..'. -** Example: ..\test_directory\testing.tmp. -** To add to this test, we will also call SetCurrentDirectory to -** ensure this is handled properly. -** The test will create a file with in the parent directory -** to verify that the returned directory is valid. -** -** Depends: SetCurrentDirectory, -** CreateDirectory, -** strcat, -** memset, -** CreateFile, -** CloseHandle, -** strcmp, -** DeleteFileA, -** RemoveDirectory. -** - -** -**===================================================================*/ - -#include - -#ifdef WIN32 - const char* szSeperator = "\\"; -#else - const char* szSeperator = "//"; -#endif - -const char* szDotDot = ".."; -const char* szFileName = "testing.tmp"; - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwRc = 0; - char szReturnedPath[_MAX_DIR+1]; - char szFullFileName[_MAX_DIR+1]; - char szDirectory[256]; - char* szCreatedDir = {"test_directory"}; - WCHAR *szCreatedDirW; - LPSTR pPathPtr; - HANDLE hFile = NULL; - BOOL bRetVal = FAIL; - - /* Initialize the PAL. - */ - if (0 != PAL_Initialize(argc,argv)) - { - return (FAIL); - } - - /* Initialize the buffer. - */ - memset(szDirectory, '\0', 256); - - /* Create the path to the next level of directory to create. - */ - strcat( szDirectory, szDotDot ); /* .. */ - strcat( szDirectory, szSeperator ); /* ../ */ - strcat( szDirectory, szCreatedDir ); /* ../test_directory */ - - /* Create a test directory. - */ - if ( !CreateDirectoryA( szDirectory, NULL ) ) - { - Fail("ERROR:%u: Unable to create directories \"%s\".\n", - GetLastError(), - szDirectory); - } - - /* Initialize the receiving char buffers. - */ - memset(szReturnedPath, 0, _MAX_DIR+1); - memset(szFullFileName, 0, _MAX_DIR+1); - - /* Create Full filename to pass, will include '..\' - * in the middle of the path. - */ - strcat( szFullFileName, szDotDot ); /* .. */ - strcat( szFullFileName, szSeperator ); /* ../ */ - strcat( szFullFileName, szCreatedDir ); /* ../test_directory */ - strcat( szFullFileName, szSeperator ); /* ../test_directory/ */ - strcat( szFullFileName, szFileName ); /* ../test_directory/testing.tmp */ - - /* Get the full path to the filename. - */ - dwRc = GetFullPathNameA(szFullFileName, - _MAX_DIR, - szReturnedPath, - &pPathPtr); - if (dwRc == 0) - { - Trace("ERROR :%ld: GetFullPathName failed to " - "retrieve the path of \"%s\".\n", - GetLastError(), - szFileName); - bRetVal = FAIL; - goto cleanUpOne; - } - - /* The returned value should be the parent directory with the - * file name appended. */ - hFile = CreateFileA(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR :%ld: CreateFileA failed to create \"%s\".\n", - GetLastError(), - szReturnedPath); - bRetVal = FAIL; - goto cleanUpOne; - } - - /* Close the handle to the created file. - */ - if (CloseHandle(hFile) != TRUE) - { - Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", - GetLastError()); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* Verify that the file was created, attempt to create - * the file again. */ - hFile = CreateFileA(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); - if ((hFile != INVALID_HANDLE_VALUE) && - (GetLastError() != ERROR_ALREADY_EXISTS)) - { - Trace("ERROR :%ld: CreateFileA succeeded to create file " - "\"%s\", that already existed.\n", - GetLastError(), - szFullFileName); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* Verify that the returned filename is the same as the supplied. - */ - if (strcmp(pPathPtr, szFileName) != 0) - { - Trace("ERROR : Returned filename \"%s\" is not equal to " - "supplied filename \"%s\".\n", - pPathPtr, - szFileName); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* Successful test. - */ - bRetVal = PASS; - -cleanUpTwo: - - /* Delete the create file. - */ - if (DeleteFileA(szReturnedPath) != TRUE) - { - Fail("ERROR :%ld: DeleteFileA failed to delete \"%s\".\n", - GetLastError(), - szFileName); - } - -cleanUpOne: - - /* Remove the empty directory. - */ - szCreatedDirW = convert((LPSTR)szDirectory); - if (!RemoveDirectoryW(szCreatedDirW)) - { - free (szCreatedDirW); - Fail("ERROR:%u: Unable to remove directory \"%s\".\n", - GetLastError(), - szCreatedDir); - } - free (szCreatedDirW); - - /* Terminate the PAL.*/ - PAL_Terminate(); - return bRetVal; -} diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/test4.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/test4.cpp new file mode 100644 index 0000000000..fb22c1f07b --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test4/test4.cpp @@ -0,0 +1,203 @@ +// 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: test4.c +** +** Purpose: Tests the PAL implementation of the GetFullPathNameA API. +** GetFullPathA will be passed a directory that begins with '..'. +** Example: ..\test_directory\testing.tmp. +** To add to this test, we will also call SetCurrentDirectory to +** ensure this is handled properly. +** The test will create a file with in the parent directory +** to verify that the returned directory is valid. +** +** Depends: SetCurrentDirectory, +** CreateDirectory, +** strcat, +** memset, +** CreateFile, +** CloseHandle, +** strcmp, +** DeleteFileA, +** RemoveDirectory. +** + +** +**===================================================================*/ + +#include + +#ifdef WIN32 + const char* szSeperator = "\\"; +#else + const char* szSeperator = "//"; +#endif + +const char* szDotDot = ".."; +const char* szFileName = "testing.tmp"; + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + char szReturnedPath[_MAX_DIR+1]; + char szFullFileName[_MAX_DIR+1]; + char szDirectory[256]; + char* szCreatedDir = {"test_directory"}; + WCHAR *szCreatedDirW; + LPSTR pPathPtr; + HANDLE hFile = NULL; + BOOL bRetVal = FAIL; + + /* Initialize the PAL. + */ + if (0 != PAL_Initialize(argc,argv)) + { + return (FAIL); + } + + /* Initialize the buffer. + */ + memset(szDirectory, '\0', 256); + + /* Create the path to the next level of directory to create. + */ + strcat( szDirectory, szDotDot ); /* .. */ + strcat( szDirectory, szSeperator ); /* ../ */ + strcat( szDirectory, szCreatedDir ); /* ../test_directory */ + + /* Create a test directory. + */ + if ( !CreateDirectoryA( szDirectory, NULL ) ) + { + Fail("ERROR:%u: Unable to create directories \"%s\".\n", + GetLastError(), + szDirectory); + } + + /* Initialize the receiving char buffers. + */ + memset(szReturnedPath, 0, _MAX_DIR+1); + memset(szFullFileName, 0, _MAX_DIR+1); + + /* Create Full filename to pass, will include '..\' + * in the middle of the path. + */ + strcat( szFullFileName, szDotDot ); /* .. */ + strcat( szFullFileName, szSeperator ); /* ../ */ + strcat( szFullFileName, szCreatedDir ); /* ../test_directory */ + strcat( szFullFileName, szSeperator ); /* ../test_directory/ */ + strcat( szFullFileName, szFileName ); /* ../test_directory/testing.tmp */ + + /* Get the full path to the filename. + */ + dwRc = GetFullPathNameA(szFullFileName, + _MAX_DIR, + szReturnedPath, + &pPathPtr); + if (dwRc == 0) + { + Trace("ERROR :%ld: GetFullPathName failed to " + "retrieve the path of \"%s\".\n", + GetLastError(), + szFileName); + bRetVal = FAIL; + goto cleanUpOne; + } + + /* The returned value should be the parent directory with the + * file name appended. */ + hFile = CreateFileA(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR :%ld: CreateFileA failed to create \"%s\".\n", + GetLastError(), + szReturnedPath); + bRetVal = FAIL; + goto cleanUpOne; + } + + /* Close the handle to the created file. + */ + if (CloseHandle(hFile) != TRUE) + { + Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", + GetLastError()); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* Verify that the file was created, attempt to create + * the file again. */ + hFile = CreateFileA(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + NULL); + if ((hFile != INVALID_HANDLE_VALUE) && + (GetLastError() != ERROR_ALREADY_EXISTS)) + { + Trace("ERROR :%ld: CreateFileA succeeded to create file " + "\"%s\", that already existed.\n", + GetLastError(), + szFullFileName); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* Verify that the returned filename is the same as the supplied. + */ + if (strcmp(pPathPtr, szFileName) != 0) + { + Trace("ERROR : Returned filename \"%s\" is not equal to " + "supplied filename \"%s\".\n", + pPathPtr, + szFileName); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* Successful test. + */ + bRetVal = PASS; + +cleanUpTwo: + + /* Delete the create file. + */ + if (DeleteFileA(szReturnedPath) != TRUE) + { + Fail("ERROR :%ld: DeleteFileA failed to delete \"%s\".\n", + GetLastError(), + szFileName); + } + +cleanUpOne: + + /* Remove the empty directory. + */ + szCreatedDirW = convert((LPSTR)szDirectory); + if (!RemoveDirectoryW(szCreatedDirW)) + { + free (szCreatedDirW); + Fail("ERROR:%u: Unable to remove directory \"%s\".\n", + GetLastError(), + szCreatedDir); + } + free (szCreatedDirW); + + /* Terminate the PAL.*/ + PAL_Terminate(); + return bRetVal; +} diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/CMakeLists.txt index a6f354f5a5..d455ca1193 100644 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetFullPathNameW.c + GetFullPathNameW.cpp ) add_executable(paltest_getfullpathnamew_test1 diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/GetFullPathNameW.c b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/GetFullPathNameW.c deleted file mode 100644 index 592d3ad4c5..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/GetFullPathNameW.c +++ /dev/null @@ -1,157 +0,0 @@ -// 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: GetFullPathNameW.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetFullPathNameW function. -** -** -**===================================================================*/ - -#include - -const char* szFileName = "testing.tmp"; - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwRc = 0; - WCHAR szwReturnedPath[_MAX_DIR+1]; - WCHAR szwShortBuff[2]; - LPWSTR pPathPtr; - HANDLE hFile = NULL; - WCHAR* szwFileName = NULL; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - szwFileName = convert((char*)szFileName); - - /* perform a short buffer test */ - if (GetFullPathNameW(szwFileName, 2, szwShortBuff, &pPathPtr) <= 2) - { - free(szwFileName); - /* this test should have failed but didn't */ - Fail("GetFullPathNameW: ERROR -> The API was passed a buffer that was" - " too small for the path name and yet it apparently passed.\n"); - } - - - memset(szwReturnedPath, 0, _MAX_DIR+1); - dwRc = GetFullPathNameW(szwFileName, - _MAX_DIR, - szwReturnedPath, - &pPathPtr); - - if (dwRc == 0) - { - /* this test should have passed but didn't */ - free(szwFileName); - Fail("GetFullPathNameW: ERROR -> Function failed for the " - "file \"%s\" with error code: %ld.\n", szFileName, GetLastError()); - } - /* - * the returned value should be the current directory with the - * file name appended - */ - hFile = CreateFileW(szwFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - free(szwFileName); - Fail("GetFullPathNameW: ERROR -> CreateFileW failed to create " - "file \"%s\" with error code: %ld.\n", - szFileName, - GetLastError()); - } - if (CloseHandle(hFile) != TRUE) - { - free(szwFileName); - Trace("GetFullPathNameW: ERROR -> CloseHandle failed with error " - "code: %ld.\n", GetLastError()); - if (DeleteFileA(szFileName) != TRUE) - { - Trace("GetFullPathNameW: ERROR -> DeleteFileW failed to " - "delete the test file with error code: %ld.\n", - GetLastError()); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* - * now try to create the file based on the returned value with the - * CREATE_NEW option which should fail since the file should - * already exist - */ - hFile = CreateFileW(szwReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile != INVALID_HANDLE_VALUE) - { - Trace("GetFullPathNameW: ERROR -> CreateFileW was able to " - "CREATE_NEW the returned file \"%s\". The returned file " - "name is therefore apparently wrong.\n", - szwReturnedPath); - if (CloseHandle(hFile) != TRUE) - { - Trace("GetFullPathNameW: ERROR -> CloseHandle failed with " - "error code: %ld.\n", GetLastError()); - } - if ((DeleteFileW(szwReturnedPath) != TRUE) || - (DeleteFileW(szwFileName) != TRUE)) - { - Trace("GetFullPathNameW: ERROR -> DeleteFileW failed to " - "delete the test files with error code: %ld.\n", - GetLastError()); - } - free(szwFileName); - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* now make sure the pPathPtr is the same as the file name */ - if (wcsncmp(pPathPtr, szwFileName, wcslen(szwFileName)) != 0) - { - Trace("GetFullPathNameW: ERROR -> %s != %s\n", - pPathPtr, szFileName); - if ((DeleteFileW(szwReturnedPath) != TRUE) || - (DeleteFileW(szwFileName) != TRUE)) - { - Trace("GetFullPathNameW: ERROR -> DeleteFileW failed to " - "delete the test files with error code: %ld.\n", - GetLastError()); - } - free(szwFileName); - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* clean up */ - free(szwFileName); - if (DeleteFileA(szFileName) != TRUE) - { - Fail("GetFullPathNameW: ERROR -> DeleteFileW failed to " - "delete \"%s\" with error code: %ld.\n", - szFileName, - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/GetFullPathNameW.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/GetFullPathNameW.cpp new file mode 100644 index 0000000000..592d3ad4c5 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test1/GetFullPathNameW.cpp @@ -0,0 +1,157 @@ +// 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: GetFullPathNameW.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetFullPathNameW function. +** +** +**===================================================================*/ + +#include + +const char* szFileName = "testing.tmp"; + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + WCHAR szwReturnedPath[_MAX_DIR+1]; + WCHAR szwShortBuff[2]; + LPWSTR pPathPtr; + HANDLE hFile = NULL; + WCHAR* szwFileName = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + szwFileName = convert((char*)szFileName); + + /* perform a short buffer test */ + if (GetFullPathNameW(szwFileName, 2, szwShortBuff, &pPathPtr) <= 2) + { + free(szwFileName); + /* this test should have failed but didn't */ + Fail("GetFullPathNameW: ERROR -> The API was passed a buffer that was" + " too small for the path name and yet it apparently passed.\n"); + } + + + memset(szwReturnedPath, 0, _MAX_DIR+1); + dwRc = GetFullPathNameW(szwFileName, + _MAX_DIR, + szwReturnedPath, + &pPathPtr); + + if (dwRc == 0) + { + /* this test should have passed but didn't */ + free(szwFileName); + Fail("GetFullPathNameW: ERROR -> Function failed for the " + "file \"%s\" with error code: %ld.\n", szFileName, GetLastError()); + } + /* + * the returned value should be the current directory with the + * file name appended + */ + hFile = CreateFileW(szwFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + free(szwFileName); + Fail("GetFullPathNameW: ERROR -> CreateFileW failed to create " + "file \"%s\" with error code: %ld.\n", + szFileName, + GetLastError()); + } + if (CloseHandle(hFile) != TRUE) + { + free(szwFileName); + Trace("GetFullPathNameW: ERROR -> CloseHandle failed with error " + "code: %ld.\n", GetLastError()); + if (DeleteFileA(szFileName) != TRUE) + { + Trace("GetFullPathNameW: ERROR -> DeleteFileW failed to " + "delete the test file with error code: %ld.\n", + GetLastError()); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* + * now try to create the file based on the returned value with the + * CREATE_NEW option which should fail since the file should + * already exist + */ + hFile = CreateFileW(szwReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile != INVALID_HANDLE_VALUE) + { + Trace("GetFullPathNameW: ERROR -> CreateFileW was able to " + "CREATE_NEW the returned file \"%s\". The returned file " + "name is therefore apparently wrong.\n", + szwReturnedPath); + if (CloseHandle(hFile) != TRUE) + { + Trace("GetFullPathNameW: ERROR -> CloseHandle failed with " + "error code: %ld.\n", GetLastError()); + } + if ((DeleteFileW(szwReturnedPath) != TRUE) || + (DeleteFileW(szwFileName) != TRUE)) + { + Trace("GetFullPathNameW: ERROR -> DeleteFileW failed to " + "delete the test files with error code: %ld.\n", + GetLastError()); + } + free(szwFileName); + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* now make sure the pPathPtr is the same as the file name */ + if (wcsncmp(pPathPtr, szwFileName, wcslen(szwFileName)) != 0) + { + Trace("GetFullPathNameW: ERROR -> %s != %s\n", + pPathPtr, szFileName); + if ((DeleteFileW(szwReturnedPath) != TRUE) || + (DeleteFileW(szwFileName) != TRUE)) + { + Trace("GetFullPathNameW: ERROR -> DeleteFileW failed to " + "delete the test files with error code: %ld.\n", + GetLastError()); + } + free(szwFileName); + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* clean up */ + free(szwFileName); + if (DeleteFileA(szFileName) != TRUE) + { + Fail("GetFullPathNameW: ERROR -> DeleteFileW failed to " + "delete \"%s\" with error code: %ld.\n", + szFileName, + GetLastError()); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/CMakeLists.txt index 199aa1efce..d974e940a7 100644 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_getfullpathnamew_test2 diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.c b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.c deleted file mode 100644 index fae042d229..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.c +++ /dev/null @@ -1,159 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests the PAL implementation of the GetFullPathNameW function. -** Get the full path for a file name and verify the results. -** This test will use a relative path, containing '..\'. To -** add to this test, we will also call SetCurrentDirectory to -** ensure this is handled properly. -** -** -**===================================================================*/ - -#include - -WCHAR szwDotDot[] = {'.','.','\\','\0'}; -WCHAR szwFileName[] = {'t','e','s','t','i','n','g','.','t','m','p','\0'}; - -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; -} - diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp new file mode 100644 index 0000000000..fae042d229 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp @@ -0,0 +1,159 @@ +// 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: test2.c +** +** Purpose: Tests the PAL implementation of the GetFullPathNameW function. +** Get the full path for a file name and verify the results. +** This test will use a relative path, containing '..\'. To +** add to this test, we will also call SetCurrentDirectory to +** ensure this is handled properly. +** +** +**===================================================================*/ + +#include + +WCHAR szwDotDot[] = {'.','.','\\','\0'}; +WCHAR szwFileName[] = {'t','e','s','t','i','n','g','.','t','m','p','\0'}; + +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; +} + diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/CMakeLists.txt index 6284958b07..09439a6372 100644 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_getfullpathnamew_test3 diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.c b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.c deleted file mode 100644 index ba80cf222d..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.c +++ /dev/null @@ -1,240 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests the PAL implementation of the GetFullPathNameW API. -** GetFullPathW will be passed a directory that contains '..'. -** Example: test_directory\level1\..\testing.tmp. -** To add to this test, we will also call SetCurrentDirectory to -** ensure this is handled properly. -** The test will create a file with in the parent directory -** to verify that the returned directory is valid. -** -** Depends: SetCurrentDirectory, -** CreateDirectory, -** strcat, -** memset, -** CreateFile, -** CloseHandle, -** strcmp, -** DeleteFileW, -** RemoveDirectory. -** - -** -**===================================================================*/ -#define UNICODE -#include - -#ifdef WIN32 -const WCHAR szSeperator[] = {'\\','\\','\0'}; -#else -const WCHAR szSeperator[] = {'/','/','\0'}; -#endif - -const WCHAR szDotDot[] = {'.','.','\0'}; -const WCHAR szFileName[] = {'t','e','s','t','i','n','g','.','t','m','p','\0'}; - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwRc = 0; - - WCHAR szReturnedPath[_MAX_DIR+1]; - WCHAR szFullFileName[_MAX_DIR+1]; - WCHAR szDirectory[256]; - WCHAR szCreatedDir[] = {'t','e','s','t','_','d','i','r','\0'}; - WCHAR szCreatedNextDir[] = {'l','e','v','e','l','1','\0'}; - - LPWSTR pPathPtr; - HANDLE hFile = NULL; - BOOL bRetVal = FAIL; - - /* Initialize the PAL. - */ - if ( 0 != PAL_Initialize(argc,argv) ) - { - return (FAIL); - } - - /* Initialize the buffer. - */ - memset( szDirectory, '\0', 256 ); - - /* Change the current working directory. - */ - if ( !SetCurrentDirectoryW(szDotDot) ) - { - Fail("ERROR: SetCurrentDirectoryA failed with error code %u " - "when passed \"%S\".\n", - GetLastError(), - szDotDot); - } - - /* Create the path to the next level of directory to create. - */ - wcscat(szDirectory, szCreatedDir); /* test_dir */ - - - /* Create a test directory. - */ - if (!CreateDirectoryW(szDirectory, NULL)) - { - Fail("ERROR:%u: Unable to create directories \"%S\".\n", - GetLastError(), - szDirectory); - } - - /* Create the path to the next level of directory to create. - */ - wcscat(szDirectory, szSeperator); /* / */ - wcscat(szDirectory, szCreatedNextDir); /* /level1 */ - - /* Create a test directory. - */ - if (!CreateDirectoryW(szDirectory, NULL)) - { - Trace("ERROR:%u: Unable to create directories \"%S\".\n", - GetLastError(), - szDirectory); - bRetVal = FAIL; - goto cleanUpOne; - } - - /* Initialize the receiving char buffers. - */ - memset(szReturnedPath, 0, _MAX_DIR+1); - memset(szFullFileName, 0, _MAX_DIR+1); - - /* Create Full filename to pass, will include '..\' - * in the middle of the path. - */ - wcscat(szFullFileName, szCreatedDir); /*test_dir */ - wcscat(szFullFileName, szSeperator); /*test_dir/ */ - wcscat(szFullFileName, szCreatedNextDir);/*test_dir/level1 */ - wcscat(szFullFileName, szSeperator); /*test_dir/level1/ */ - wcscat(szFullFileName, szDotDot); /*test_dir/level1/.. */ - wcscat(szFullFileName, szSeperator); /*test_dir/level1/../ */ - wcscat(szFullFileName, szFileName); /*test_dir/level1/../testing.tmp */ - - /* Get the full path to the filename. - */ - dwRc = GetFullPathNameW(szFullFileName, - _MAX_DIR, - szReturnedPath, - &pPathPtr); - if (dwRc == 0) - { - Trace("ERROR :%ld: GetFullPathNameW failed to " - "retrieve the path of \"%S\".\n", - GetLastError(), - szFileName); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* The returned value should be the parent directory with the - * file name appended. */ - hFile = CreateFileW(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR :%ld: CreateFileA failed to create \"%S\".\n", - GetLastError(), - szReturnedPath); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* Close the handle to the created file. - */ - if (CloseHandle(hFile) != TRUE) - { - Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", - GetLastError()); - bRetVal = FAIL; - goto cleanUpThree; - } - - /* Verify that the file was created, attempt to create - * the file again. */ - hFile = CreateFileW(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); - if ((hFile != INVALID_HANDLE_VALUE) && - (GetLastError() != ERROR_ALREADY_EXISTS)) - { - Trace("ERROR :%ld: CreateFileA succeeded to create file " - "\"%S\", that already existed.\n", - GetLastError(), - szFullFileName); - bRetVal = FAIL; - goto cleanUpThree; - } - - /* Verify that the returned filename is the same as the supplied. - */ - if (wcscmp(pPathPtr, szFileName) != 0) - { - Trace("ERROR : Returned filename \"%s\" is not equal to " - "supplied filename \"%s\".\n", - pPathPtr, - szFileName); - bRetVal = FAIL; - goto cleanUpThree; - } - - /* Successful test. - */ - bRetVal = PASS; - -cleanUpThree: - - /* Delete the create file. - */ - if (DeleteFileW(szReturnedPath) != TRUE) - { - Fail("ERROR :%ld: DeleteFileA failed to delete \"%S\".\n", - GetLastError(), - szFileName); - } - -cleanUpTwo: - - /* Remove the empty directory. - */ - if (!RemoveDirectoryW(szDirectory)) - { - Fail("ERROR:%u: Unable to remove directory \"%S\".\n", - GetLastError(), - szCreatedDir); - } - -cleanUpOne: - - /* Remove the empty directory. - */ - if (!RemoveDirectoryW(szCreatedDir)) - { - Fail("ERROR:%u: Unable to remove directory \"%s\".\n", - GetLastError(), - szCreatedDir); - } - - /* Terminate the PAL.*/ - PAL_TerminateEx(bRetVal); - return bRetVal; -} diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp new file mode 100644 index 0000000000..ba80cf222d --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp @@ -0,0 +1,240 @@ +// 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: test3.c +** +** Purpose: Tests the PAL implementation of the GetFullPathNameW API. +** GetFullPathW will be passed a directory that contains '..'. +** Example: test_directory\level1\..\testing.tmp. +** To add to this test, we will also call SetCurrentDirectory to +** ensure this is handled properly. +** The test will create a file with in the parent directory +** to verify that the returned directory is valid. +** +** Depends: SetCurrentDirectory, +** CreateDirectory, +** strcat, +** memset, +** CreateFile, +** CloseHandle, +** strcmp, +** DeleteFileW, +** RemoveDirectory. +** + +** +**===================================================================*/ +#define UNICODE +#include + +#ifdef WIN32 +const WCHAR szSeperator[] = {'\\','\\','\0'}; +#else +const WCHAR szSeperator[] = {'/','/','\0'}; +#endif + +const WCHAR szDotDot[] = {'.','.','\0'}; +const WCHAR szFileName[] = {'t','e','s','t','i','n','g','.','t','m','p','\0'}; + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + + WCHAR szReturnedPath[_MAX_DIR+1]; + WCHAR szFullFileName[_MAX_DIR+1]; + WCHAR szDirectory[256]; + WCHAR szCreatedDir[] = {'t','e','s','t','_','d','i','r','\0'}; + WCHAR szCreatedNextDir[] = {'l','e','v','e','l','1','\0'}; + + LPWSTR pPathPtr; + HANDLE hFile = NULL; + BOOL bRetVal = FAIL; + + /* Initialize the PAL. + */ + if ( 0 != PAL_Initialize(argc,argv) ) + { + return (FAIL); + } + + /* Initialize the buffer. + */ + memset( szDirectory, '\0', 256 ); + + /* Change the current working directory. + */ + if ( !SetCurrentDirectoryW(szDotDot) ) + { + Fail("ERROR: SetCurrentDirectoryA failed with error code %u " + "when passed \"%S\".\n", + GetLastError(), + szDotDot); + } + + /* Create the path to the next level of directory to create. + */ + wcscat(szDirectory, szCreatedDir); /* test_dir */ + + + /* Create a test directory. + */ + if (!CreateDirectoryW(szDirectory, NULL)) + { + Fail("ERROR:%u: Unable to create directories \"%S\".\n", + GetLastError(), + szDirectory); + } + + /* Create the path to the next level of directory to create. + */ + wcscat(szDirectory, szSeperator); /* / */ + wcscat(szDirectory, szCreatedNextDir); /* /level1 */ + + /* Create a test directory. + */ + if (!CreateDirectoryW(szDirectory, NULL)) + { + Trace("ERROR:%u: Unable to create directories \"%S\".\n", + GetLastError(), + szDirectory); + bRetVal = FAIL; + goto cleanUpOne; + } + + /* Initialize the receiving char buffers. + */ + memset(szReturnedPath, 0, _MAX_DIR+1); + memset(szFullFileName, 0, _MAX_DIR+1); + + /* Create Full filename to pass, will include '..\' + * in the middle of the path. + */ + wcscat(szFullFileName, szCreatedDir); /*test_dir */ + wcscat(szFullFileName, szSeperator); /*test_dir/ */ + wcscat(szFullFileName, szCreatedNextDir);/*test_dir/level1 */ + wcscat(szFullFileName, szSeperator); /*test_dir/level1/ */ + wcscat(szFullFileName, szDotDot); /*test_dir/level1/.. */ + wcscat(szFullFileName, szSeperator); /*test_dir/level1/../ */ + wcscat(szFullFileName, szFileName); /*test_dir/level1/../testing.tmp */ + + /* Get the full path to the filename. + */ + dwRc = GetFullPathNameW(szFullFileName, + _MAX_DIR, + szReturnedPath, + &pPathPtr); + if (dwRc == 0) + { + Trace("ERROR :%ld: GetFullPathNameW failed to " + "retrieve the path of \"%S\".\n", + GetLastError(), + szFileName); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* The returned value should be the parent directory with the + * file name appended. */ + hFile = CreateFileW(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR :%ld: CreateFileA failed to create \"%S\".\n", + GetLastError(), + szReturnedPath); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* Close the handle to the created file. + */ + if (CloseHandle(hFile) != TRUE) + { + Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", + GetLastError()); + bRetVal = FAIL; + goto cleanUpThree; + } + + /* Verify that the file was created, attempt to create + * the file again. */ + hFile = CreateFileW(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + NULL); + if ((hFile != INVALID_HANDLE_VALUE) && + (GetLastError() != ERROR_ALREADY_EXISTS)) + { + Trace("ERROR :%ld: CreateFileA succeeded to create file " + "\"%S\", that already existed.\n", + GetLastError(), + szFullFileName); + bRetVal = FAIL; + goto cleanUpThree; + } + + /* Verify that the returned filename is the same as the supplied. + */ + if (wcscmp(pPathPtr, szFileName) != 0) + { + Trace("ERROR : Returned filename \"%s\" is not equal to " + "supplied filename \"%s\".\n", + pPathPtr, + szFileName); + bRetVal = FAIL; + goto cleanUpThree; + } + + /* Successful test. + */ + bRetVal = PASS; + +cleanUpThree: + + /* Delete the create file. + */ + if (DeleteFileW(szReturnedPath) != TRUE) + { + Fail("ERROR :%ld: DeleteFileA failed to delete \"%S\".\n", + GetLastError(), + szFileName); + } + +cleanUpTwo: + + /* Remove the empty directory. + */ + if (!RemoveDirectoryW(szDirectory)) + { + Fail("ERROR:%u: Unable to remove directory \"%S\".\n", + GetLastError(), + szCreatedDir); + } + +cleanUpOne: + + /* Remove the empty directory. + */ + if (!RemoveDirectoryW(szCreatedDir)) + { + Fail("ERROR:%u: Unable to remove directory \"%s\".\n", + GetLastError(), + szCreatedDir); + } + + /* Terminate the PAL.*/ + PAL_TerminateEx(bRetVal); + return bRetVal; +} diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/CMakeLists.txt index d479b998cc..11ed9583b6 100644 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_getfullpathnamew_test4 diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.c b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.c deleted file mode 100644 index 25eb10d654..0000000000 --- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.c +++ /dev/null @@ -1,201 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests the PAL implementation of the GetFullPathNameW API. -** GetFullPathNameW will be passed a directory that begins with '..'. -** Example: ..\test_directory\testing.tmp. -** To add to this test, we will also call SetCurrentDirectory to -** ensure this is handled properly. -** The test will create a file with in the parent directory -** to verify that the returned directory is valid. -** -** Depends: SetCurrentDirectory, -** CreateDirectory, -** strcat, -** memset, -** CreateFile, -** CloseHandle, -** strcmp, -** DeleteFileW, -** RemoveDirectory. -** - -** -**===================================================================*/ -#define UNICODE -#include - -#ifdef WIN32 - const WCHAR szSeperator[] = {'\\','\\','\0'}; -#else - const WCHAR szSeperator[] = {'/','/','\0'}; -#endif - -const WCHAR szDotDot[] = {'.','.','\0'}; -const WCHAR szFileName[] = {'t','e','s','t','i','n','g','.','t','m','p','\0'}; - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwRc = 0; - - WCHAR szReturnedPath[_MAX_DIR+1]; - WCHAR szFullFileName[_MAX_DIR+1]; - WCHAR szDirectory[256]; - WCHAR szCreatedDir[] = {'t','e','s','t','_','d','i','r','\0'}; - - LPWSTR pPathPtr; - HANDLE hFile = NULL; - BOOL bRetVal = FAIL; - - /* Initialize the PAL. - */ - if (0 != PAL_Initialize(argc,argv)) - { - return (FAIL); - } - - /* Initialize the buffer. - */ - memset(szDirectory, '\0', 256); - - /* Create the path to the next level of directory to create. - */ - wcscat(szDirectory, szDotDot); /* .. */ - wcscat(szDirectory, szSeperator); /* ../ */ - wcscat(szDirectory, szCreatedDir); /* ../test_directory */ - - /* Create a test directory. - */ - if (!CreateDirectoryW(szDirectory, NULL)) - { - Fail("ERROR:%u: Unable to create directories \"%S\".\n", - GetLastError(), - szDirectory); - } - - /* Initialize the receiving char buffers. - */ - memset(szReturnedPath, 0, _MAX_DIR+1); - memset(szFullFileName, 0, _MAX_DIR+1); - - /* Create Full filename to pass, will include '..\' - * in the middle of the path. - */ - wcscat( szFullFileName, szDotDot ); /* .. */ - wcscat( szFullFileName, szSeperator ); /* ../ */ - wcscat( szFullFileName, szCreatedDir ); /* ../test_directory */ - wcscat( szFullFileName, szSeperator ); /* ../test_directory/ */ - wcscat( szFullFileName, szFileName ); /* ../test_directory/testing.tmp */ - - /* Get the full path to the filename. - */ - dwRc = GetFullPathNameW(szFullFileName, - _MAX_DIR, - szReturnedPath, - &pPathPtr); - if (dwRc == 0) - { - Trace("ERROR :%ld: GetFullPathName failed to " - "retrieve the path of \"%S\".\n", - GetLastError(), - szFileName); - bRetVal = FAIL; - goto cleanUpOne; - } - - /* The returned value should be the parent directory with the - * file name appended. */ - hFile = CreateFileW(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR :%ld: CreateFileA failed to create \"%S\".\n", - GetLastError(), - szReturnedPath); - bRetVal = FAIL; - goto cleanUpOne; - } - - /* Close the handle to the created file. - */ - if (CloseHandle(hFile) != TRUE) - { - Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", - GetLastError()); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* Verify that the file was created, attempt to create - * the file again. */ - hFile = CreateFileW(szReturnedPath, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); - if ((hFile != INVALID_HANDLE_VALUE) && - (GetLastError() != ERROR_ALREADY_EXISTS)) - { - Trace("ERROR :%ld: CreateFileA succeeded to create file " - "\"%S\", that already existed.\n", - GetLastError(), - szFullFileName); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* Verify that the returned filename is the same as the supplied. - */ - if (wcscmp(pPathPtr, szFileName) != 0) - { - Trace("ERROR : Returned filename \"%S\" is not equal to " - "supplied filename \"%S\".\n", - pPathPtr, - szFileName); - bRetVal = FAIL; - goto cleanUpTwo; - } - - /* Successful test. - */ - bRetVal = PASS; - -cleanUpTwo: - - /* Delete the create file. - */ - if (DeleteFileW(szReturnedPath) != TRUE) - { - Fail("ERROR :%ld: DeleteFileA failed to delete \"%S\".\n", - GetLastError(), - szFileName); - } - -cleanUpOne: - - /* Remove the empty directory. - */ - if (!RemoveDirectoryW(szDirectory)) - { - Fail("ERROR:%u: Unable to remove directory \"%s\".\n", - GetLastError(), - szCreatedDir); - } - - /* Terminate the PAL.*/ - PAL_TerminateEx(bRetVal); - return bRetVal; -} diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp new file mode 100644 index 0000000000..25eb10d654 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp @@ -0,0 +1,201 @@ +// 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: test4.c +** +** Purpose: Tests the PAL implementation of the GetFullPathNameW API. +** GetFullPathNameW will be passed a directory that begins with '..'. +** Example: ..\test_directory\testing.tmp. +** To add to this test, we will also call SetCurrentDirectory to +** ensure this is handled properly. +** The test will create a file with in the parent directory +** to verify that the returned directory is valid. +** +** Depends: SetCurrentDirectory, +** CreateDirectory, +** strcat, +** memset, +** CreateFile, +** CloseHandle, +** strcmp, +** DeleteFileW, +** RemoveDirectory. +** + +** +**===================================================================*/ +#define UNICODE +#include + +#ifdef WIN32 + const WCHAR szSeperator[] = {'\\','\\','\0'}; +#else + const WCHAR szSeperator[] = {'/','/','\0'}; +#endif + +const WCHAR szDotDot[] = {'.','.','\0'}; +const WCHAR szFileName[] = {'t','e','s','t','i','n','g','.','t','m','p','\0'}; + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + + WCHAR szReturnedPath[_MAX_DIR+1]; + WCHAR szFullFileName[_MAX_DIR+1]; + WCHAR szDirectory[256]; + WCHAR szCreatedDir[] = {'t','e','s','t','_','d','i','r','\0'}; + + LPWSTR pPathPtr; + HANDLE hFile = NULL; + BOOL bRetVal = FAIL; + + /* Initialize the PAL. + */ + if (0 != PAL_Initialize(argc,argv)) + { + return (FAIL); + } + + /* Initialize the buffer. + */ + memset(szDirectory, '\0', 256); + + /* Create the path to the next level of directory to create. + */ + wcscat(szDirectory, szDotDot); /* .. */ + wcscat(szDirectory, szSeperator); /* ../ */ + wcscat(szDirectory, szCreatedDir); /* ../test_directory */ + + /* Create a test directory. + */ + if (!CreateDirectoryW(szDirectory, NULL)) + { + Fail("ERROR:%u: Unable to create directories \"%S\".\n", + GetLastError(), + szDirectory); + } + + /* Initialize the receiving char buffers. + */ + memset(szReturnedPath, 0, _MAX_DIR+1); + memset(szFullFileName, 0, _MAX_DIR+1); + + /* Create Full filename to pass, will include '..\' + * in the middle of the path. + */ + wcscat( szFullFileName, szDotDot ); /* .. */ + wcscat( szFullFileName, szSeperator ); /* ../ */ + wcscat( szFullFileName, szCreatedDir ); /* ../test_directory */ + wcscat( szFullFileName, szSeperator ); /* ../test_directory/ */ + wcscat( szFullFileName, szFileName ); /* ../test_directory/testing.tmp */ + + /* Get the full path to the filename. + */ + dwRc = GetFullPathNameW(szFullFileName, + _MAX_DIR, + szReturnedPath, + &pPathPtr); + if (dwRc == 0) + { + Trace("ERROR :%ld: GetFullPathName failed to " + "retrieve the path of \"%S\".\n", + GetLastError(), + szFileName); + bRetVal = FAIL; + goto cleanUpOne; + } + + /* The returned value should be the parent directory with the + * file name appended. */ + hFile = CreateFileW(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR :%ld: CreateFileA failed to create \"%S\".\n", + GetLastError(), + szReturnedPath); + bRetVal = FAIL; + goto cleanUpOne; + } + + /* Close the handle to the created file. + */ + if (CloseHandle(hFile) != TRUE) + { + Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", + GetLastError()); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* Verify that the file was created, attempt to create + * the file again. */ + hFile = CreateFileW(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + NULL); + if ((hFile != INVALID_HANDLE_VALUE) && + (GetLastError() != ERROR_ALREADY_EXISTS)) + { + Trace("ERROR :%ld: CreateFileA succeeded to create file " + "\"%S\", that already existed.\n", + GetLastError(), + szFullFileName); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* Verify that the returned filename is the same as the supplied. + */ + if (wcscmp(pPathPtr, szFileName) != 0) + { + Trace("ERROR : Returned filename \"%S\" is not equal to " + "supplied filename \"%S\".\n", + pPathPtr, + szFileName); + bRetVal = FAIL; + goto cleanUpTwo; + } + + /* Successful test. + */ + bRetVal = PASS; + +cleanUpTwo: + + /* Delete the create file. + */ + if (DeleteFileW(szReturnedPath) != TRUE) + { + Fail("ERROR :%ld: DeleteFileA failed to delete \"%S\".\n", + GetLastError(), + szFileName); + } + +cleanUpOne: + + /* Remove the empty directory. + */ + if (!RemoveDirectoryW(szDirectory)) + { + Fail("ERROR:%u: Unable to remove directory \"%s\".\n", + GetLastError(), + szCreatedDir); + } + + /* Terminate the PAL.*/ + PAL_TerminateEx(bRetVal); + return bRetVal; +} diff --git a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/CMakeLists.txt index cf5dcd0bfc..3b9f0b118a 100644 --- a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetLongPathNameW.c + GetLongPathNameW.cpp ) add_executable(paltest_getlongpathnamew_test1 diff --git a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/GetLongPathNameW.c b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/GetLongPathNameW.c deleted file mode 100644 index 22831dda15..0000000000 --- a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/GetLongPathNameW.c +++ /dev/null @@ -1,280 +0,0 @@ -// 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: GetLongPathNameW.c Win32 version(test 1) -** -** Purpose: Tests the PAL implementation of the GetLongPathNameW function. -** as expected under Win32 -** -** Depends on: -** CreateDirectoryA -** RemoveDirectoryW -** -** -**===================================================================*/ -/* -tests: - - test invalid path names - - test an already short path name - - test a long path name - - test with buffer size too small -*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ -/* Since GetLongPathNameW operates differently under FreeBSD and Win32 this test - is for Win32 only. It runs the same tests as the FreeBSD version but checks for - different results -*/ - -#if WIN32 - DWORD dwRc = 0; - WCHAR szwReturnedPath[MAX_LONGPATH]; - WCHAR szwSmallBuff[3]; - const char szShortPathName[] = {"testing"}; - const char szLongPathName[] = {"This_is_a_long_directory_name"}; - const char szShortenedPathName[] = {"THIS_I~1"}; - WCHAR* wLongPathPtr = NULL; - WCHAR* wShortPathPtr = NULL; - - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); - memset(szwSmallBuff, 0, 3*sizeof(WCHAR)); - wLongPathPtr = convert((char*)szLongPathName); - wShortPathPtr = convert((char*)szShortenedPathName); - - /* do some clean up just to be safe */ - RemoveDirectoryW(wLongPathPtr); - RemoveDirectoryW(wShortPathPtr); - - - /* attempt call on an invalid short path name */ - dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); - if (dwRc != 0) - { - Trace("GetLongPathNameW: ERROR -> Call made with an invalid short " - "path \"%S\" returned \"%S\"\n", - wShortPathPtr, - szwReturnedPath); - free (wLongPathPtr); - free (wShortPathPtr); - Fail(""); - } - - - /* attempt call on an invalid long path name */ - dwRc = GetLongPathNameW(wLongPathPtr, szwReturnedPath, MAX_LONGPATH); - if (dwRc != 0) - { - Trace("GetLongPathNameW: ERROR -> Call made with an invalid long " - "path \"%S\" returned \"%S\"\n", - wLongPathPtr, - szwReturnedPath); - free (wLongPathPtr); - free (wShortPathPtr); - Fail(""); - } - - - /* create a long directory name */ - if (TRUE != CreateDirectoryW(wLongPathPtr, NULL)) - { - free(wLongPathPtr); - free(wShortPathPtr); - Fail("GetLongPathNameW: ERROR -> CreateDirectoryW failed with an error" - " code of %ld when asked to create a directory called \"%s\".\n", - GetLastError(), - szLongPathName); - } - - - /* get the long path name */ - memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); - dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); - if (dwRc == 0) - { - Trace("GetLongPathNameW: ERROR -> failed with an error" - " code of %ld when asked for the long version of \"%s\".\n", - GetLastError(), - szShortenedPathName); - if (RemoveDirectoryW(wLongPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wLongPathPtr, - GetLastError()); - } - free(wLongPathPtr); - free(wShortPathPtr); - Fail(""); - } - - /* does the returned match the expected */ - if (wcsncmp(wLongPathPtr, szwReturnedPath, wcslen(wLongPathPtr)) || - (wcslen(wLongPathPtr) != wcslen(szwReturnedPath))) - { - if (RemoveDirectoryW(wLongPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wLongPathPtr, - GetLastError()); - } - free(wLongPathPtr); - free(wShortPathPtr); - Fail("GetLongPathNameW: ERROR -> The returned path, \"%S\" doesn't " - "match the expected return, \"%s\".\n", - szwReturnedPath, - szLongPathName); - } - - /* does the length returned match the actual length */ - if (dwRc != wcslen(szwReturnedPath)) - { - if (RemoveDirectoryW(wLongPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wLongPathPtr, - GetLastError()); - } - free(wLongPathPtr); - free(wShortPathPtr); - Fail("GetLongPathNameW: ERROR -> The returned length, %ld, doesn't " - "match the string length, %ld.\n", - dwRc, - wcslen(szwReturnedPath)); - } - - if (RemoveDirectoryW(wLongPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wLongPathPtr, - GetLastError()); - free(wShortPathPtr); - free(wLongPathPtr); - Fail(""); - } - free(wShortPathPtr); - free(wLongPathPtr); - - - /* test an actual short name */ - /* create a long directory name */ - wShortPathPtr = convert((char*)szShortPathName); - RemoveDirectoryW(wShortPathPtr); - - if (TRUE != CreateDirectoryW(wShortPathPtr, NULL)) - { - Trace("GetLongPathNameW: ERROR -> CreateDirectoryW failed with an error" - " code of %ld when asked to create a directory called \"%s\".\n", - GetLastError(), - szShortPathName); - free(wShortPathPtr); - Fail(""); - } - - - /* get the long path name */ - memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); - dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); - if (dwRc == 0) - { - Trace("GetLongPathNameW: ERROR -> failed with an error" - " code of %ld when asked for the long version of \"%s\".\n", - GetLastError(), - szShortenedPathName); - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - } - free(wShortPathPtr); - Fail(""); - } - - /* does the returned match the expected */ - if (wcsncmp(wShortPathPtr, szwReturnedPath, wcslen(wShortPathPtr)) || - (wcslen(wShortPathPtr) != wcslen(szwReturnedPath))) - { - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - } - free(wShortPathPtr); - Fail("GetLongPathNameW: ERROR -> The returned path, \"%S\" doesn't " - "match the expected return, \"%s\".\n", - szwReturnedPath, - szShortPathName); - } - - /* does the length returned match the actual length */ - if (dwRc != wcslen(szwReturnedPath)) - { - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - } - free(wShortPathPtr); - Fail("GetLongPathNameW: ERROR -> The returned length, %ld, doesn't " - "match the string length, %ld.\n", - dwRc, - wcslen(szwReturnedPath)); - } - - /* test using a too small return buffer */ - dwRc = GetLongPathNameW(wShortPathPtr, szwSmallBuff, 3); - if ((dwRc != (strlen(szShortPathName)+1)) || /* +1 for the required NULL */ - szwSmallBuff[0] != '\0') - { - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - } - free(wShortPathPtr); - Fail("GetLongPathNameW: ERROR -> using a return buffer that was too" - " small was not handled properly.\n"); - } - - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - free(wShortPathPtr); - Fail(""); - } - free(wShortPathPtr); - - PAL_Terminate(); - -#endif /* WIN32 */ - - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/GetLongPathNameW.cpp b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/GetLongPathNameW.cpp new file mode 100644 index 0000000000..22831dda15 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test1/GetLongPathNameW.cpp @@ -0,0 +1,280 @@ +// 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: GetLongPathNameW.c Win32 version(test 1) +** +** Purpose: Tests the PAL implementation of the GetLongPathNameW function. +** as expected under Win32 +** +** Depends on: +** CreateDirectoryA +** RemoveDirectoryW +** +** +**===================================================================*/ +/* +tests: + - test invalid path names + - test an already short path name + - test a long path name + - test with buffer size too small +*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ +/* Since GetLongPathNameW operates differently under FreeBSD and Win32 this test + is for Win32 only. It runs the same tests as the FreeBSD version but checks for + different results +*/ + +#if WIN32 + DWORD dwRc = 0; + WCHAR szwReturnedPath[MAX_LONGPATH]; + WCHAR szwSmallBuff[3]; + const char szShortPathName[] = {"testing"}; + const char szLongPathName[] = {"This_is_a_long_directory_name"}; + const char szShortenedPathName[] = {"THIS_I~1"}; + WCHAR* wLongPathPtr = NULL; + WCHAR* wShortPathPtr = NULL; + + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); + memset(szwSmallBuff, 0, 3*sizeof(WCHAR)); + wLongPathPtr = convert((char*)szLongPathName); + wShortPathPtr = convert((char*)szShortenedPathName); + + /* do some clean up just to be safe */ + RemoveDirectoryW(wLongPathPtr); + RemoveDirectoryW(wShortPathPtr); + + + /* attempt call on an invalid short path name */ + dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); + if (dwRc != 0) + { + Trace("GetLongPathNameW: ERROR -> Call made with an invalid short " + "path \"%S\" returned \"%S\"\n", + wShortPathPtr, + szwReturnedPath); + free (wLongPathPtr); + free (wShortPathPtr); + Fail(""); + } + + + /* attempt call on an invalid long path name */ + dwRc = GetLongPathNameW(wLongPathPtr, szwReturnedPath, MAX_LONGPATH); + if (dwRc != 0) + { + Trace("GetLongPathNameW: ERROR -> Call made with an invalid long " + "path \"%S\" returned \"%S\"\n", + wLongPathPtr, + szwReturnedPath); + free (wLongPathPtr); + free (wShortPathPtr); + Fail(""); + } + + + /* create a long directory name */ + if (TRUE != CreateDirectoryW(wLongPathPtr, NULL)) + { + free(wLongPathPtr); + free(wShortPathPtr); + Fail("GetLongPathNameW: ERROR -> CreateDirectoryW failed with an error" + " code of %ld when asked to create a directory called \"%s\".\n", + GetLastError(), + szLongPathName); + } + + + /* get the long path name */ + memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); + dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); + if (dwRc == 0) + { + Trace("GetLongPathNameW: ERROR -> failed with an error" + " code of %ld when asked for the long version of \"%s\".\n", + GetLastError(), + szShortenedPathName); + if (RemoveDirectoryW(wLongPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wLongPathPtr, + GetLastError()); + } + free(wLongPathPtr); + free(wShortPathPtr); + Fail(""); + } + + /* does the returned match the expected */ + if (wcsncmp(wLongPathPtr, szwReturnedPath, wcslen(wLongPathPtr)) || + (wcslen(wLongPathPtr) != wcslen(szwReturnedPath))) + { + if (RemoveDirectoryW(wLongPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wLongPathPtr, + GetLastError()); + } + free(wLongPathPtr); + free(wShortPathPtr); + Fail("GetLongPathNameW: ERROR -> The returned path, \"%S\" doesn't " + "match the expected return, \"%s\".\n", + szwReturnedPath, + szLongPathName); + } + + /* does the length returned match the actual length */ + if (dwRc != wcslen(szwReturnedPath)) + { + if (RemoveDirectoryW(wLongPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wLongPathPtr, + GetLastError()); + } + free(wLongPathPtr); + free(wShortPathPtr); + Fail("GetLongPathNameW: ERROR -> The returned length, %ld, doesn't " + "match the string length, %ld.\n", + dwRc, + wcslen(szwReturnedPath)); + } + + if (RemoveDirectoryW(wLongPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wLongPathPtr, + GetLastError()); + free(wShortPathPtr); + free(wLongPathPtr); + Fail(""); + } + free(wShortPathPtr); + free(wLongPathPtr); + + + /* test an actual short name */ + /* create a long directory name */ + wShortPathPtr = convert((char*)szShortPathName); + RemoveDirectoryW(wShortPathPtr); + + if (TRUE != CreateDirectoryW(wShortPathPtr, NULL)) + { + Trace("GetLongPathNameW: ERROR -> CreateDirectoryW failed with an error" + " code of %ld when asked to create a directory called \"%s\".\n", + GetLastError(), + szShortPathName); + free(wShortPathPtr); + Fail(""); + } + + + /* get the long path name */ + memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); + dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); + if (dwRc == 0) + { + Trace("GetLongPathNameW: ERROR -> failed with an error" + " code of %ld when asked for the long version of \"%s\".\n", + GetLastError(), + szShortenedPathName); + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + } + free(wShortPathPtr); + Fail(""); + } + + /* does the returned match the expected */ + if (wcsncmp(wShortPathPtr, szwReturnedPath, wcslen(wShortPathPtr)) || + (wcslen(wShortPathPtr) != wcslen(szwReturnedPath))) + { + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + } + free(wShortPathPtr); + Fail("GetLongPathNameW: ERROR -> The returned path, \"%S\" doesn't " + "match the expected return, \"%s\".\n", + szwReturnedPath, + szShortPathName); + } + + /* does the length returned match the actual length */ + if (dwRc != wcslen(szwReturnedPath)) + { + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + } + free(wShortPathPtr); + Fail("GetLongPathNameW: ERROR -> The returned length, %ld, doesn't " + "match the string length, %ld.\n", + dwRc, + wcslen(szwReturnedPath)); + } + + /* test using a too small return buffer */ + dwRc = GetLongPathNameW(wShortPathPtr, szwSmallBuff, 3); + if ((dwRc != (strlen(szShortPathName)+1)) || /* +1 for the required NULL */ + szwSmallBuff[0] != '\0') + { + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + } + free(wShortPathPtr); + Fail("GetLongPathNameW: ERROR -> using a return buffer that was too" + " small was not handled properly.\n"); + } + + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + free(wShortPathPtr); + Fail(""); + } + free(wShortPathPtr); + + PAL_Terminate(); + +#endif /* WIN32 */ + + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/CMakeLists.txt index 5746ef3e04..b92e431095 100644 --- a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - getlongpathnamew.c + getlongpathnamew.cpp ) add_executable(paltest_getlongpathnamew_test2 diff --git a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/getlongpathnamew.c b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/getlongpathnamew.c deleted file mode 100644 index 3b033e9a64..0000000000 --- a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/getlongpathnamew.c +++ /dev/null @@ -1,266 +0,0 @@ -// 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: GetLongPathNameW.c FreeBSD version(test 2) -** -** Purpose: Tests the PAL implementation of the GetLongPathNameW function -** as expected under FreeBSD -** -** Depends on: -** CreateDirectoryA -** RemoveDirectoryW -** -** -**===================================================================*/ -/* -tests: - - test invalid path names - - test an already short path name - - test a long path name - - test with buffer size too small -*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ -/* Since GetLongPathNameW operates differently under FreeBSD and Win32 this test - is for freeBSD only. It runs the same tests as the Win32 version but checks for - different results -*/ -#if !(WIN32) /* Only execute if the is Free BSD */ - - DWORD dwRc = 0; - WCHAR szwReturnedPath[MAX_LONGPATH]; - WCHAR szwSmallBuff[3]; - const char szShortPathName[] = {"testing"}; - const char szLongPathName[] = {"This_is_a_long_directory_name"}; - /* since BSD doesn't shorten long dir names, it will only use the long name */ - const char szShortenedPathName[] = {"This_is_a_long_directory_name"}; - WCHAR* wLongPathPtr = NULL; - WCHAR* wShortPathPtr = NULL; - int StringLen = 0; - - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); - memset(szwSmallBuff, 0, 3*sizeof(WCHAR)); - wLongPathPtr = convert((char*)szLongPathName); - wShortPathPtr = convert((char*)szShortenedPathName); - - - /* do some clean up just to be safe */ - RemoveDirectoryW(wLongPathPtr); - RemoveDirectoryW(wShortPathPtr); - - - /* attempt call on an invalid short path name */ - dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); - if (dwRc != 0) - { - Trace("GetLongPathNameW: ERROR -> Call made with an invalid short " - "path \"%S\" returned \"%S\"\n", - wShortPathPtr, - szwReturnedPath); - free (wLongPathPtr); - free (wShortPathPtr); - Fail(""); - } - - - /* attempt call on an invalid long path name */ - dwRc = GetLongPathNameW(wLongPathPtr, szwReturnedPath, MAX_LONGPATH); - if (dwRc != 0) - { - Trace("GetLongPathNameW: ERROR -> Call made with an invalid long " - "path \"%S\" returned \"%S\"\n", - wLongPathPtr, - szwReturnedPath); - free (wLongPathPtr); - free (wShortPathPtr); - Fail(""); - } - - - /* create a long directory name */ - if (TRUE != CreateDirectoryW(wLongPathPtr, NULL)) - { - free(wLongPathPtr); - free(wShortPathPtr); - Fail("GetLongPathNameW: ERROR -> CreateDirectoryW failed with an error" - " code of %ld when asked to create a directory called \"%s\".\n", - GetLastError(), - szLongPathName); - } - - - /* get the long path name */ - memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); - dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); - StringLen = wcslen(wShortPathPtr); - - if (dwRc != StringLen) - { - Trace("GetLongPathNameW: ERROR -> Under FreeBSD, this test should" - " have returned %d but instead returned %d.\n", - StringLen, dwRc); - if (RemoveDirectoryW(wLongPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wLongPathPtr, - GetLastError()); - } - free(wLongPathPtr); - free(wShortPathPtr); - Fail(""); - } - if (wcsncmp(wShortPathPtr,szwReturnedPath, StringLen) != 0) - { - Trace("GetLongPathNameW: ERROR -> Under Unix," - "the lpszLongPath \"%s\" should have been," - "but was \"%s\".\n", - wShortPathPtr, szwReturnedPath); - - if (RemoveDirectoryW(wLongPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wLongPathPtr, - GetLastError()); - } - free(wLongPathPtr); - free(wShortPathPtr); - Fail(""); - } - - if (RemoveDirectoryW(wLongPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wLongPathPtr, - GetLastError()); - free(wLongPathPtr); - free(wShortPathPtr); - Fail(""); - } - free(wShortPathPtr); - free(wLongPathPtr); - - - /* test an actual short name */ - /* create a long directory name */ - wShortPathPtr = convert((char*)szShortPathName); - RemoveDirectoryW(wShortPathPtr); - - if (TRUE != CreateDirectoryW(wShortPathPtr, NULL)) - { - free(wShortPathPtr); - Fail("GetLongPathNameW: ERROR -> CreateDirectoryW failed with an error" - " code of %ld when asked to create a directory called \"%s\".\n", - GetLastError(), - szShortPathName); - } - - - /* get the long path name */ - memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); - dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); - StringLen = wcslen (wShortPathPtr); - - if (dwRc != StringLen) - { - Trace("GetLongPathNameW: ERROR -> Under FreeBSD, this test should" - " have returned %d but instead returned %d.\n", - StringLen, dwRc); - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - } - free(wShortPathPtr); - Fail(""); - } - if (wcsncmp(wShortPathPtr, szwReturnedPath, StringLen) != 0) - { - Trace("GetLongPathNameW: ERROR -> Under Unix, the lpszLongPath" - "\"%s\" should have been," - "but was \"%s\".\n", - wShortPathPtr, szwReturnedPath); - - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - } - free(wShortPathPtr); - Fail(""); - } - - - /* test using a too small return buffer */ - dwRc = GetLongPathNameW(wShortPathPtr, szwSmallBuff, 3); - StringLen = wcslen (wShortPathPtr); - - - if (dwRc != (StringLen + 1)) //Return size includes NULL char - { - Trace("GetLongPathNameW: ERROR -> Under FreeBSD, this test should" - " have returned %d but instead returned %d.\n", - StringLen, dwRc); - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - } - free(wShortPathPtr); - Fail(""); - } - if (szwSmallBuff[0] != 0) - { - Trace("GetLongPathNameW: ERROR -> Under FreeBSD, this test should" - " not have touched lpszLongPath but instead it returned\"%s\".\n", - szwReturnedPath); - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - } - free(wShortPathPtr); - Fail(""); - } - - /* clean up */ - if (RemoveDirectoryW(wShortPathPtr) != TRUE) - { - Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " - " remove the directory \"%S\" with an error code of %ld.\n", - wShortPathPtr, - GetLastError()); - free(wShortPathPtr); - Fail(""); - } - free(wShortPathPtr); - - PAL_Terminate(); - -#endif /* Free BSD */ - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/getlongpathnamew.cpp b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/getlongpathnamew.cpp new file mode 100644 index 0000000000..3b033e9a64 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetLongPathNameW/test2/getlongpathnamew.cpp @@ -0,0 +1,266 @@ +// 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: GetLongPathNameW.c FreeBSD version(test 2) +** +** Purpose: Tests the PAL implementation of the GetLongPathNameW function +** as expected under FreeBSD +** +** Depends on: +** CreateDirectoryA +** RemoveDirectoryW +** +** +**===================================================================*/ +/* +tests: + - test invalid path names + - test an already short path name + - test a long path name + - test with buffer size too small +*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ +/* Since GetLongPathNameW operates differently under FreeBSD and Win32 this test + is for freeBSD only. It runs the same tests as the Win32 version but checks for + different results +*/ +#if !(WIN32) /* Only execute if the is Free BSD */ + + DWORD dwRc = 0; + WCHAR szwReturnedPath[MAX_LONGPATH]; + WCHAR szwSmallBuff[3]; + const char szShortPathName[] = {"testing"}; + const char szLongPathName[] = {"This_is_a_long_directory_name"}; + /* since BSD doesn't shorten long dir names, it will only use the long name */ + const char szShortenedPathName[] = {"This_is_a_long_directory_name"}; + WCHAR* wLongPathPtr = NULL; + WCHAR* wShortPathPtr = NULL; + int StringLen = 0; + + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); + memset(szwSmallBuff, 0, 3*sizeof(WCHAR)); + wLongPathPtr = convert((char*)szLongPathName); + wShortPathPtr = convert((char*)szShortenedPathName); + + + /* do some clean up just to be safe */ + RemoveDirectoryW(wLongPathPtr); + RemoveDirectoryW(wShortPathPtr); + + + /* attempt call on an invalid short path name */ + dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); + if (dwRc != 0) + { + Trace("GetLongPathNameW: ERROR -> Call made with an invalid short " + "path \"%S\" returned \"%S\"\n", + wShortPathPtr, + szwReturnedPath); + free (wLongPathPtr); + free (wShortPathPtr); + Fail(""); + } + + + /* attempt call on an invalid long path name */ + dwRc = GetLongPathNameW(wLongPathPtr, szwReturnedPath, MAX_LONGPATH); + if (dwRc != 0) + { + Trace("GetLongPathNameW: ERROR -> Call made with an invalid long " + "path \"%S\" returned \"%S\"\n", + wLongPathPtr, + szwReturnedPath); + free (wLongPathPtr); + free (wShortPathPtr); + Fail(""); + } + + + /* create a long directory name */ + if (TRUE != CreateDirectoryW(wLongPathPtr, NULL)) + { + free(wLongPathPtr); + free(wShortPathPtr); + Fail("GetLongPathNameW: ERROR -> CreateDirectoryW failed with an error" + " code of %ld when asked to create a directory called \"%s\".\n", + GetLastError(), + szLongPathName); + } + + + /* get the long path name */ + memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); + dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); + StringLen = wcslen(wShortPathPtr); + + if (dwRc != StringLen) + { + Trace("GetLongPathNameW: ERROR -> Under FreeBSD, this test should" + " have returned %d but instead returned %d.\n", + StringLen, dwRc); + if (RemoveDirectoryW(wLongPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wLongPathPtr, + GetLastError()); + } + free(wLongPathPtr); + free(wShortPathPtr); + Fail(""); + } + if (wcsncmp(wShortPathPtr,szwReturnedPath, StringLen) != 0) + { + Trace("GetLongPathNameW: ERROR -> Under Unix," + "the lpszLongPath \"%s\" should have been," + "but was \"%s\".\n", + wShortPathPtr, szwReturnedPath); + + if (RemoveDirectoryW(wLongPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wLongPathPtr, + GetLastError()); + } + free(wLongPathPtr); + free(wShortPathPtr); + Fail(""); + } + + if (RemoveDirectoryW(wLongPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wLongPathPtr, + GetLastError()); + free(wLongPathPtr); + free(wShortPathPtr); + Fail(""); + } + free(wShortPathPtr); + free(wLongPathPtr); + + + /* test an actual short name */ + /* create a long directory name */ + wShortPathPtr = convert((char*)szShortPathName); + RemoveDirectoryW(wShortPathPtr); + + if (TRUE != CreateDirectoryW(wShortPathPtr, NULL)) + { + free(wShortPathPtr); + Fail("GetLongPathNameW: ERROR -> CreateDirectoryW failed with an error" + " code of %ld when asked to create a directory called \"%s\".\n", + GetLastError(), + szShortPathName); + } + + + /* get the long path name */ + memset(szwReturnedPath, 0, MAX_LONGPATH*sizeof(WCHAR)); + dwRc = GetLongPathNameW(wShortPathPtr, szwReturnedPath, MAX_LONGPATH); + StringLen = wcslen (wShortPathPtr); + + if (dwRc != StringLen) + { + Trace("GetLongPathNameW: ERROR -> Under FreeBSD, this test should" + " have returned %d but instead returned %d.\n", + StringLen, dwRc); + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + } + free(wShortPathPtr); + Fail(""); + } + if (wcsncmp(wShortPathPtr, szwReturnedPath, StringLen) != 0) + { + Trace("GetLongPathNameW: ERROR -> Under Unix, the lpszLongPath" + "\"%s\" should have been," + "but was \"%s\".\n", + wShortPathPtr, szwReturnedPath); + + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + } + free(wShortPathPtr); + Fail(""); + } + + + /* test using a too small return buffer */ + dwRc = GetLongPathNameW(wShortPathPtr, szwSmallBuff, 3); + StringLen = wcslen (wShortPathPtr); + + + if (dwRc != (StringLen + 1)) //Return size includes NULL char + { + Trace("GetLongPathNameW: ERROR -> Under FreeBSD, this test should" + " have returned %d but instead returned %d.\n", + StringLen, dwRc); + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + } + free(wShortPathPtr); + Fail(""); + } + if (szwSmallBuff[0] != 0) + { + Trace("GetLongPathNameW: ERROR -> Under FreeBSD, this test should" + " not have touched lpszLongPath but instead it returned\"%s\".\n", + szwReturnedPath); + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + } + free(wShortPathPtr); + Fail(""); + } + + /* clean up */ + if (RemoveDirectoryW(wShortPathPtr) != TRUE) + { + Trace("GetLongPathNameW: ERROR -> RemoveDirectoryW failed to " + " remove the directory \"%S\" with an error code of %ld.\n", + wShortPathPtr, + GetLastError()); + free(wShortPathPtr); + Fail(""); + } + free(wShortPathPtr); + + PAL_Terminate(); + +#endif /* Free BSD */ + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetStdHandle/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetStdHandle/test1/CMakeLists.txt index 04bcc5fd67..eaa1721b7e 100644 --- a/src/pal/tests/palsuite/file_io/GetStdHandle/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetStdHandle/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetStdHandle.c + GetStdHandle.cpp ) add_executable(paltest_getstdhandle_test1 diff --git a/src/pal/tests/palsuite/file_io/GetStdHandle/test1/GetStdHandle.c b/src/pal/tests/palsuite/file_io/GetStdHandle/test1/GetStdHandle.c deleted file mode 100644 index f4fe03195d..0000000000 --- a/src/pal/tests/palsuite/file_io/GetStdHandle/test1/GetStdHandle.c +++ /dev/null @@ -1,132 +0,0 @@ -// 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: GetStdHandle.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetStdHandle function. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwBytesWritten = 0; - DWORD dwFileType; - BOOL bRc = FALSE; - const char* szText = "this is a test of GetStdHandle\n"; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* - * attempt to get an invalid handle - */ - hFile = GetStdHandle(-2); - if (hFile != INVALID_HANDLE_VALUE) - { - Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " - "returned an invalid handle.\n"); - } - - - /* - * test the STD_INPUT_HANDLE handle - */ - hFile = GetStdHandle(STD_INPUT_HANDLE); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " - "returned an invalid handle.\n"); - } - - /* an attempt to write to the input handle should fail */ - /* I don't know how to automate a read from the input handle */ - bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwBytesWritten, NULL); - if (bRc != FALSE) - { - Fail("GetStdHandle: ERROR -> WriteFile was able to write to " - "STD_INPUT_HANDLE when it should have failed.\n"); - } - - - /* - * test the STD_OUTPUT_HANDLE handle - */ - hFile = GetStdHandle(STD_OUTPUT_HANDLE); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("GetStdHandle: ERROR -> A request for the STD_OUTPUT_HANDLE " - "returned an invalid handle.\n"); - } - - /* try to write to the output handle */ - bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwBytesWritten, NULL); - if (bRc != TRUE) - { - Fail("GetStdHandle: ERROR -> WriteFile failed to write to " - "STD_OUTPUT_HANDLE with the error %ld\n", - GetLastError()); - } - - - /* test the STD_ERROR_HANDLE handle */ - hFile = GetStdHandle(STD_ERROR_HANDLE); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("GetStdHandle: ERROR -> A request for the STD_ERROR_HANDLE " - "returned an invalid handle.\n"); - } - - /* try to write to the error handle */ - bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwBytesWritten, NULL); - if (bRc != TRUE) - { - Fail("GetStdHandle: ERROR -> WriteFile failed to write to " - "STD_ERROR_HANDLE with the error %ld\n", - GetLastError()); - } - - /* check if the file type is correct for the handle */ - if((dwFileType = GetFileType(hFile)) != FILE_TYPE_CHAR) - { - Fail("GetStdHandle: ERROR -> GetFileType returned %u for " - "STD_ERROR_HANDLE instead of the expected FILE_TYPE_CHAR (%u).\n", - dwFileType, - FILE_TYPE_CHAR); - } - - /* check to see if we can CloseHandle works on the STD_ERROR_HANDLE */ - if (!CloseHandle(hFile)) - { - Fail("GetStdHandle: ERROR -> CloseHandle failed. GetLastError " - "returned %u.\n", - GetLastError()); - } - - /* try to write to the closed error handle */ - bRc = WriteFile(hFile, - szText, - (DWORD)strlen(szText), - &dwBytesWritten, - NULL); - if (bRc) - { - Fail("GetStdHandle: ERROR -> WriteFile was able to write to the closed" - " STD_ERROR_HANDLE handle.\n"); - } - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetStdHandle/test1/GetStdHandle.cpp b/src/pal/tests/palsuite/file_io/GetStdHandle/test1/GetStdHandle.cpp new file mode 100644 index 0000000000..f4fe03195d --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetStdHandle/test1/GetStdHandle.cpp @@ -0,0 +1,132 @@ +// 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: GetStdHandle.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetStdHandle function. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwBytesWritten = 0; + DWORD dwFileType; + BOOL bRc = FALSE; + const char* szText = "this is a test of GetStdHandle\n"; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* + * attempt to get an invalid handle + */ + hFile = GetStdHandle(-2); + if (hFile != INVALID_HANDLE_VALUE) + { + Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " + "returned an invalid handle.\n"); + } + + + /* + * test the STD_INPUT_HANDLE handle + */ + hFile = GetStdHandle(STD_INPUT_HANDLE); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " + "returned an invalid handle.\n"); + } + + /* an attempt to write to the input handle should fail */ + /* I don't know how to automate a read from the input handle */ + bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwBytesWritten, NULL); + if (bRc != FALSE) + { + Fail("GetStdHandle: ERROR -> WriteFile was able to write to " + "STD_INPUT_HANDLE when it should have failed.\n"); + } + + + /* + * test the STD_OUTPUT_HANDLE handle + */ + hFile = GetStdHandle(STD_OUTPUT_HANDLE); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("GetStdHandle: ERROR -> A request for the STD_OUTPUT_HANDLE " + "returned an invalid handle.\n"); + } + + /* try to write to the output handle */ + bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwBytesWritten, NULL); + if (bRc != TRUE) + { + Fail("GetStdHandle: ERROR -> WriteFile failed to write to " + "STD_OUTPUT_HANDLE with the error %ld\n", + GetLastError()); + } + + + /* test the STD_ERROR_HANDLE handle */ + hFile = GetStdHandle(STD_ERROR_HANDLE); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("GetStdHandle: ERROR -> A request for the STD_ERROR_HANDLE " + "returned an invalid handle.\n"); + } + + /* try to write to the error handle */ + bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwBytesWritten, NULL); + if (bRc != TRUE) + { + Fail("GetStdHandle: ERROR -> WriteFile failed to write to " + "STD_ERROR_HANDLE with the error %ld\n", + GetLastError()); + } + + /* check if the file type is correct for the handle */ + if((dwFileType = GetFileType(hFile)) != FILE_TYPE_CHAR) + { + Fail("GetStdHandle: ERROR -> GetFileType returned %u for " + "STD_ERROR_HANDLE instead of the expected FILE_TYPE_CHAR (%u).\n", + dwFileType, + FILE_TYPE_CHAR); + } + + /* check to see if we can CloseHandle works on the STD_ERROR_HANDLE */ + if (!CloseHandle(hFile)) + { + Fail("GetStdHandle: ERROR -> CloseHandle failed. GetLastError " + "returned %u.\n", + GetLastError()); + } + + /* try to write to the closed error handle */ + bRc = WriteFile(hFile, + szText, + (DWORD)strlen(szText), + &dwBytesWritten, + NULL); + if (bRc) + { + Fail("GetStdHandle: ERROR -> WriteFile was able to write to the closed" + " STD_ERROR_HANDLE handle.\n"); + } + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetStdHandle/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetStdHandle/test2/CMakeLists.txt index 97816b4319..ef45aa0dec 100644 --- a/src/pal/tests/palsuite/file_io/GetStdHandle/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetStdHandle/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetStdHandle.c + GetStdHandle.cpp ) add_executable(paltest_getstdhandle_test2 diff --git a/src/pal/tests/palsuite/file_io/GetStdHandle/test2/GetStdHandle.c b/src/pal/tests/palsuite/file_io/GetStdHandle/test2/GetStdHandle.c deleted file mode 100644 index 45f5ddd243..0000000000 --- a/src/pal/tests/palsuite/file_io/GetStdHandle/test2/GetStdHandle.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: GetStdHandle.c (test 2) -** -** Purpose: Smoke Tests the PAL implementation of the GetStdHandle function. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* - * attempt to get an invalid handle - */ - hFile = GetStdHandle(-2); - if (hFile != INVALID_HANDLE_VALUE) - { - Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " - "returned an invalid handle.\n"); - } - - - /* - * test the STD_INPUT_HANDLE handle - */ - hFile = GetStdHandle(STD_INPUT_HANDLE); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " - "returned an invalid handle.\n"); - } - - - /* - * test the STD_OUTPUT_HANDLE handle - */ - hFile = GetStdHandle(STD_OUTPUT_HANDLE); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("GetStdHandle: ERROR -> A request for the STD_OUTPUT_HANDLE " - "returned an invalid handle.\n"); - } - - /* test the STD_ERROR_HANDLE handle */ - hFile = GetStdHandle(STD_ERROR_HANDLE); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("GetStdHandle: ERROR -> A request for the STD_ERROR_HANDLE " - "returned an invalid handle.\n"); - } - - - /* check to see if we can CloseHandle works on the STD_ERROR_HANDLE */ - if (!CloseHandle(hFile)) - { - Fail("GetStdHandle: ERROR -> CloseHandle failed. GetLastError " - "returned %u.\n", - GetLastError()); - } - - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetStdHandle/test2/GetStdHandle.cpp b/src/pal/tests/palsuite/file_io/GetStdHandle/test2/GetStdHandle.cpp new file mode 100644 index 0000000000..45f5ddd243 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetStdHandle/test2/GetStdHandle.cpp @@ -0,0 +1,79 @@ +// 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: GetStdHandle.c (test 2) +** +** Purpose: Smoke Tests the PAL implementation of the GetStdHandle function. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* + * attempt to get an invalid handle + */ + hFile = GetStdHandle(-2); + if (hFile != INVALID_HANDLE_VALUE) + { + Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " + "returned an invalid handle.\n"); + } + + + /* + * test the STD_INPUT_HANDLE handle + */ + hFile = GetStdHandle(STD_INPUT_HANDLE); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " + "returned an invalid handle.\n"); + } + + + /* + * test the STD_OUTPUT_HANDLE handle + */ + hFile = GetStdHandle(STD_OUTPUT_HANDLE); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("GetStdHandle: ERROR -> A request for the STD_OUTPUT_HANDLE " + "returned an invalid handle.\n"); + } + + /* test the STD_ERROR_HANDLE handle */ + hFile = GetStdHandle(STD_ERROR_HANDLE); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("GetStdHandle: ERROR -> A request for the STD_ERROR_HANDLE " + "returned an invalid handle.\n"); + } + + + /* check to see if we can CloseHandle works on the STD_ERROR_HANDLE */ + if (!CloseHandle(hFile)) + { + Fail("GetStdHandle: ERROR -> CloseHandle failed. GetLastError " + "returned %u.\n", + GetLastError()); + } + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetSystemTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetSystemTime/test1/CMakeLists.txt index 94d5bcded9..4367e880f7 100644 --- a/src/pal/tests/palsuite/file_io/GetSystemTime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetSystemTime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getsystemtime_test1 diff --git a/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.c b/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.c deleted file mode 100644 index 361dbef33d..0000000000 --- a/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.c +++ /dev/null @@ -1,124 +0,0 @@ -// 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 GetSystemTime() function -** -** -**=========================================================*/ - -/* Note: Some of the range comparisons only check - * the high end of the range. Since the structure - * contains WORDs, negative values can never be included, - * so there is no reason to check and see if the lower - * end of the spectrum is <0 -*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - SYSTEMTIME TheTime; - SYSTEMTIME firstTime; - SYSTEMTIME secondTime; - - WORD avgDeltaFileTime = 0; - - int i=0; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - GetSystemTime(&TheTime); - - /* Go through each item in the structure and ensure it is a valid value. - We can't ensure they have the exact values of the current time, but - at least that they have been set to a valid range of values for that - item. - */ - - /* Year */ - if(TheTime.wYear < (WORD)2001) - { - Fail("ERROR: The year is %d, when it should be at least 2001.", - TheTime.wYear); - } - - /* Month */ - if(TheTime.wMonth > (WORD)12 || TheTime.wMonth < (WORD)1) - { - Fail("ERROR: The month should be between 1 and 12, and it is " - "showing up as %d.",TheTime.wMonth); - } - - /* Weekday */ - if(TheTime.wDayOfWeek > 6) - { - Fail("ERROR: The day of the week should be between 0 and 6, " - "and it is showing up as %d.",TheTime.wDayOfWeek); - } - - /* Day of the Month */ - if(TheTime.wDay > 31 || TheTime.wDay < 1) - { - Fail("ERROR: The day of the month should be between 1 and " - "31, and it is showing up as %d.",TheTime.wDay); - } - - /* Hour */ - if(TheTime.wHour > 23) - { - Fail("ERROR: The hour should be between 0 and 23, and it is " - "showing up as %d.",TheTime.wHour); - } - - /* Minute */ - if(TheTime.wMinute > 59) - { - Fail("ERROR: The minute should be between 0 and 59 and it is " - "showing up as %d.",TheTime.wMinute); - } - - /* Second */ - if(TheTime.wSecond > 59) - { - Fail("ERROR: The second should be between 0 and 59 and it is" - " showing up as %d.",TheTime.wSecond); - } - - /* Millisecond */ - if(TheTime.wMilliseconds > 999) - { - Fail("ERROR: The milliseconds should be between 0 and 999 " - "and it is currently showing %d.",TheTime.wMilliseconds); - } - - /* check if two consecutive calls to system time return */ - /* correct time in ms after sleep() call. */ - for (i = 0; i<5 ;i++) - { - GetSystemTime(&firstTime); - Sleep(1000); - GetSystemTime(&secondTime); - avgDeltaFileTime += abs(firstTime.wSecond - secondTime.wSecond ); - - } - - if( (avgDeltaFileTime/5) < 1.0) - { - Fail("ERROR: 2 calls for GetSystemTime interrupted" - " by a 1000 ms sleep failed Value[%f]", avgDeltaFileTime/5 ); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp b/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp new file mode 100644 index 0000000000..361dbef33d --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp @@ -0,0 +1,124 @@ +// 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 GetSystemTime() function +** +** +**=========================================================*/ + +/* Note: Some of the range comparisons only check + * the high end of the range. Since the structure + * contains WORDs, negative values can never be included, + * so there is no reason to check and see if the lower + * end of the spectrum is <0 +*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + SYSTEMTIME TheTime; + SYSTEMTIME firstTime; + SYSTEMTIME secondTime; + + WORD avgDeltaFileTime = 0; + + int i=0; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + GetSystemTime(&TheTime); + + /* Go through each item in the structure and ensure it is a valid value. + We can't ensure they have the exact values of the current time, but + at least that they have been set to a valid range of values for that + item. + */ + + /* Year */ + if(TheTime.wYear < (WORD)2001) + { + Fail("ERROR: The year is %d, when it should be at least 2001.", + TheTime.wYear); + } + + /* Month */ + if(TheTime.wMonth > (WORD)12 || TheTime.wMonth < (WORD)1) + { + Fail("ERROR: The month should be between 1 and 12, and it is " + "showing up as %d.",TheTime.wMonth); + } + + /* Weekday */ + if(TheTime.wDayOfWeek > 6) + { + Fail("ERROR: The day of the week should be between 0 and 6, " + "and it is showing up as %d.",TheTime.wDayOfWeek); + } + + /* Day of the Month */ + if(TheTime.wDay > 31 || TheTime.wDay < 1) + { + Fail("ERROR: The day of the month should be between 1 and " + "31, and it is showing up as %d.",TheTime.wDay); + } + + /* Hour */ + if(TheTime.wHour > 23) + { + Fail("ERROR: The hour should be between 0 and 23, and it is " + "showing up as %d.",TheTime.wHour); + } + + /* Minute */ + if(TheTime.wMinute > 59) + { + Fail("ERROR: The minute should be between 0 and 59 and it is " + "showing up as %d.",TheTime.wMinute); + } + + /* Second */ + if(TheTime.wSecond > 59) + { + Fail("ERROR: The second should be between 0 and 59 and it is" + " showing up as %d.",TheTime.wSecond); + } + + /* Millisecond */ + if(TheTime.wMilliseconds > 999) + { + Fail("ERROR: The milliseconds should be between 0 and 999 " + "and it is currently showing %d.",TheTime.wMilliseconds); + } + + /* check if two consecutive calls to system time return */ + /* correct time in ms after sleep() call. */ + for (i = 0; i<5 ;i++) + { + GetSystemTime(&firstTime); + Sleep(1000); + GetSystemTime(&secondTime); + avgDeltaFileTime += abs(firstTime.wSecond - secondTime.wSecond ); + + } + + if( (avgDeltaFileTime/5) < 1.0) + { + Fail("ERROR: 2 calls for GetSystemTime interrupted" + " by a 1000 ms sleep failed Value[%f]", avgDeltaFileTime/5 ); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/CMakeLists.txt index 977a826e7a..d149383732 100644 --- a/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetSystemTimeAsFileTime.c + GetSystemTimeAsFileTime.cpp ) add_executable(paltest_getsystemtimeasfiletime_test1 diff --git a/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.c b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.c deleted file mode 100644 index bd7e856abd..0000000000 --- a/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.c +++ /dev/null @@ -1,86 +0,0 @@ -// 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: GetSystemTimeAsFileTime.c -** -** Purpose: Tests the PAL implementation of GetSystemTimeAsFileTime -** Take two times, three seconds apart, and ensure that the time is -** increasing, and that it has increased at least 3 seconds. -** -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char **argv) -{ - - FILETIME TheFirstTime, TheSecondTime; - ULONG64 FullFirstTime, FullSecondTime; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Get two times, 3 seconds apart */ - - GetSystemTimeAsFileTime( &TheFirstTime ); - - Sleep( 3000 ); - - GetSystemTimeAsFileTime( &TheSecondTime ); - - /* Convert them to ULONG64 to work with */ - - FullFirstTime = ((( (ULONG64)TheFirstTime.dwHighDateTime )<<32) | - ( (ULONG64)TheFirstTime.dwLowDateTime )); - - FullSecondTime = ((( (ULONG64)TheSecondTime.dwHighDateTime )<<32) | - ( (ULONG64)TheSecondTime.dwLowDateTime )); - - /* Test to ensure the second value is larger than the first */ - - if( FullSecondTime <= FullFirstTime ) - { - Fail("ERROR: The system time didn't increase in the last " - "three seconds. The second time tested was less than " - "or equal to the first."); - } - - /* Note: The 30000000 magic number is 3 seconds in hundreds of nano - seconds. This test checks to ensure at least 3 seconds passed - between the readings. - */ - - if( ( (LONG64)( FullSecondTime - FullFirstTime ) - 30000000 ) < 0 ) - { - ULONG64 TimeError; - - /* Note: This test used to compare the difference between full times - in terms of hundreds of nanoseconds. But the x86 clock seems to be - precise only to the level of about 10000 nanoseconds, so we would - fail the comparison depending on when we took time slices. - - To fix this, we just check that we're within a millisecond of - sleeping 3000 milliseconds. We're not currently ensuring that we - haven't slept much more than 3000 ms. We may want to do that. - */ - TimeError = 30000000 - ( FullSecondTime - FullFirstTime ); - if ( TimeError > 10000) - { - Fail("ERROR: Two system times were tested, with a sleep of 3 " - "seconds between. The time passed should have been at least " - "3 seconds. But, it was less according to the function."); - } - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.cpp b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.cpp new file mode 100644 index 0000000000..bd7e856abd --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.cpp @@ -0,0 +1,86 @@ +// 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: GetSystemTimeAsFileTime.c +** +** Purpose: Tests the PAL implementation of GetSystemTimeAsFileTime +** Take two times, three seconds apart, and ensure that the time is +** increasing, and that it has increased at least 3 seconds. +** +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME TheFirstTime, TheSecondTime; + ULONG64 FullFirstTime, FullSecondTime; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Get two times, 3 seconds apart */ + + GetSystemTimeAsFileTime( &TheFirstTime ); + + Sleep( 3000 ); + + GetSystemTimeAsFileTime( &TheSecondTime ); + + /* Convert them to ULONG64 to work with */ + + FullFirstTime = ((( (ULONG64)TheFirstTime.dwHighDateTime )<<32) | + ( (ULONG64)TheFirstTime.dwLowDateTime )); + + FullSecondTime = ((( (ULONG64)TheSecondTime.dwHighDateTime )<<32) | + ( (ULONG64)TheSecondTime.dwLowDateTime )); + + /* Test to ensure the second value is larger than the first */ + + if( FullSecondTime <= FullFirstTime ) + { + Fail("ERROR: The system time didn't increase in the last " + "three seconds. The second time tested was less than " + "or equal to the first."); + } + + /* Note: The 30000000 magic number is 3 seconds in hundreds of nano + seconds. This test checks to ensure at least 3 seconds passed + between the readings. + */ + + if( ( (LONG64)( FullSecondTime - FullFirstTime ) - 30000000 ) < 0 ) + { + ULONG64 TimeError; + + /* Note: This test used to compare the difference between full times + in terms of hundreds of nanoseconds. But the x86 clock seems to be + precise only to the level of about 10000 nanoseconds, so we would + fail the comparison depending on when we took time slices. + + To fix this, we just check that we're within a millisecond of + sleeping 3000 milliseconds. We're not currently ensuring that we + haven't slept much more than 3000 ms. We may want to do that. + */ + TimeError = 30000000 - ( FullSecondTime - FullFirstTime ); + if ( TimeError > 10000) + { + Fail("ERROR: Two system times were tested, with a sleep of 3 " + "seconds between. The time passed should have been at least " + "3 seconds. But, it was less according to the function."); + } + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/CMakeLists.txt index 1b759af2eb..4ed0ccb537 100644 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetTempFileNameA.c + GetTempFileNameA.cpp ) add_executable(paltest_gettempfilenamea_test1 diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.c b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.c deleted file mode 100644 index 8ede8bab04..0000000000 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.c +++ /dev/null @@ -1,125 +0,0 @@ -// 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: GetTempFileNameA.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetTempFileNameA function. -** -** Depends on: -** GetFileAttributesA -** DeleteFileA -** -** -**===================================================================*/ - -#include - - - -int __cdecl main(int argc, char *argv[]) -{ - UINT uiError = 0; - const UINT uUnique = 0; - const char* szDot = {"."}; - const char* szValidPrefix = {"cfr"}; - const char* szLongValidPrefix = {"cfrwxyz"}; - char szReturnedName[256]; - char szTempString[256]; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* valid path with null prefix */ - uiError = GetTempFileNameA(szDot, NULL, uUnique, szReturnedName); - if (uiError == 0) - { - Fail("GetTempFileNameA: ERROR -> Call failed with a valid path " - "with the error code: %ld\n", GetLastError()); - } - else - { - /* verify temp file was created */ - if (GetFileAttributesA(szReturnedName) == -1) - { - Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the " - "returned temp file \"%s\" with error code: %ld.\n", - szReturnedName, - GetLastError()); - } - if (DeleteFileA(szReturnedName) != TRUE) - { - Fail("GetTempFileNameA: ERROR -> DeleteFileW failed to delete" - "the created temp file with error code: %ld.\n", GetLastError()); - } - } - - - /* valid path with valid prefix */ - uiError = GetTempFileNameA(szDot, szValidPrefix, uUnique, szReturnedName); - if (uiError == 0) - { - Fail("GetTempFileNameA: ERROR -> Call failed with a valid path and " - "prefix with the error code: %ld\n", GetLastError()); - } - else - { - /* verify temp file was created */ - if (GetFileAttributesA(szReturnedName) == -1) - { - Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the " - "returned temp file \"%s\" with error code: %ld.\n", - szReturnedName, - GetLastError()); - } - if (DeleteFileA(szReturnedName) != TRUE) - { - Fail("GetTempFileNameA: ERROR -> DeleteFileW failed to delete" - "the created temp \"%s\" file with error code: %ld.\n", - szReturnedName, - GetLastError()); - } - } - - /* valid path with long prefix */ - uiError = GetTempFileNameA(szDot, szLongValidPrefix, uUnique, szReturnedName); - if (uiError == 0) - { - Fail("GetTempFileNameA: ERROR -> Call failed with a valid path and " - "prefix with the error code: %ld\n", GetLastError()); - } - else - { - /* verify temp file was created */ - if (GetFileAttributesA(szReturnedName) == -1) - { - Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the " - "returned temp file \"%s\" with error code: %ld.\n", - szReturnedName, - GetLastError()); - } - - /* now verify that it only used the first 3 characters of the prefix */ - sprintf(szTempString, "%s\\%s", szDot, szLongValidPrefix); - if (strncmp(szTempString, szReturnedName, 6) == 0) - { - Fail("GetTempFileNameA: ERROR -> It appears that an improper prefix " - "was used.\n"); - } - - if (DeleteFileA(szReturnedName) != TRUE) - { - Fail("GetTempFileNameA: ERROR -> DeleteFileW failed to delete" - "the created temp file \"%s\" with error code: %ld.\n", - szReturnedName, - GetLastError()); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.cpp b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.cpp new file mode 100644 index 0000000000..bea8e2776e --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.cpp @@ -0,0 +1,125 @@ +// 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: GetTempFileNameA.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetTempFileNameA function. +** +** Depends on: +** GetFileAttributesA +** DeleteFileA +** +** +**===================================================================*/ + +#include + + + +int __cdecl main(int argc, char *argv[]) +{ + UINT uiError = 0; + const UINT uUnique = 0; + const char* szDot = {"."}; + const char* szValidPrefix = {"cfr"}; + const char* szLongValidPrefix = {"cfrwxyz"}; + char szReturnedName[256]; + char szTempString[256]; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* valid path with null prefix */ + uiError = GetTempFileNameA(szDot, NULL, uUnique, szReturnedName); + if (uiError == 0) + { + Fail("GetTempFileNameA: ERROR -> Call failed with a valid path " + "with the error code: %ld\n", GetLastError()); + } + else + { + /* verify temp file was created */ + if (GetFileAttributesA(szReturnedName) == -1) + { + Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the " + "returned temp file \"%s\" with error code: %ld.\n", + szReturnedName, + GetLastError()); + } + if (DeleteFileA(szReturnedName) != TRUE) + { + Fail("GetTempFileNameA: ERROR -> DeleteFileW failed to delete" + "the created temp file with error code: %ld.\n", GetLastError()); + } + } + + + /* valid path with valid prefix */ + uiError = GetTempFileNameA(szDot, szValidPrefix, uUnique, szReturnedName); + if (uiError == 0) + { + Fail("GetTempFileNameA: ERROR -> Call failed with a valid path and " + "prefix with the error code: %ld\n", GetLastError()); + } + else + { + /* verify temp file was created */ + if (GetFileAttributesA(szReturnedName) == -1) + { + Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the " + "returned temp file \"%s\" with error code: %ld.\n", + szReturnedName, + GetLastError()); + } + if (DeleteFileA(szReturnedName) != TRUE) + { + Fail("GetTempFileNameA: ERROR -> DeleteFileW failed to delete" + "the created temp \"%s\" file with error code: %ld.\n", + szReturnedName, + GetLastError()); + } + } + + /* valid path with long prefix */ + uiError = GetTempFileNameA(szDot, szLongValidPrefix, uUnique, szReturnedName); + if (uiError == 0) + { + Fail("GetTempFileNameA: ERROR -> Call failed with a valid path and " + "prefix with the error code: %ld\n", GetLastError()); + } + else + { + /* verify temp file was created */ + if (GetFileAttributesA(szReturnedName) == -1) + { + Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the " + "returned temp file \"%s\" with error code: %ld.\n", + szReturnedName, + GetLastError()); + } + + /* now verify that it only used the first 3 characters of the prefix */ + sprintf_s(szTempString, _countof(szTempString), "%s\\%s", szDot, szLongValidPrefix); + if (strncmp(szTempString, szReturnedName, 6) == 0) + { + Fail("GetTempFileNameA: ERROR -> It appears that an improper prefix " + "was used.\n"); + } + + if (DeleteFileA(szReturnedName) != TRUE) + { + Fail("GetTempFileNameA: ERROR -> DeleteFileW failed to delete" + "the created temp file \"%s\" with error code: %ld.\n", + szReturnedName, + GetLastError()); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/CMakeLists.txt index f4bd9b8797..9d9b6461cd 100644 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetTempFileNameA.c + GetTempFileNameA.cpp ) add_executable(paltest_gettempfilenamea_test2 diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.c b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.c deleted file mode 100644 index 861a8b87e8..0000000000 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.c +++ /dev/null @@ -1,80 +0,0 @@ -// 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: GetTempFileNameA.c (test 2) -** -** Purpose: Tests the number of files GetTempFileNameA can create. -** -** Depends on: -** GetFileAttributesA -** oodles of free disk space (>4.07GB) -** -** -**===================================================================*/ - -#include - - - -int __cdecl main(int argc, char *argv[]) -{ - UINT uiError = 0; - DWORD dwError = 0; - const UINT uUnique = 0; - const char* szDot = {"."}; - const char* szValidPrefix = {"cfr"}; - char szReturnedName[256]; - DWORD i; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* test the number of temp files that can be created */ - for (i = 0; i < 0x10005; i++) - { - uiError = GetTempFileNameA(szDot, szValidPrefix, uUnique, szReturnedName); - if (uiError == 0) - { - dwError = GetLastError(); - if (dwError == ERROR_FILE_EXISTS) - { - /* file already existes so break out of the loop */ - i--; /* decrement the count because it wasn't successful */ - break; - } - else - { - /* it was something other than the file already existing? */ - Fail("GetTempFileNameA: ERROR -> Call failed with a valid " - "path and prefix with the error code: %ld\n", GetLastError()); - } - } - else - { - /* verify temp file was created */ - if (GetFileAttributesA(szReturnedName) == -1) - { - Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed " - "on the returned temp file \"%s\" with error code: %ld.\n", - szReturnedName, - GetLastError()); - } - } - } - - /* did it create more than 0xffff files */ - if (i > 0xffff) - { - Fail("GetTempFileNameA: ERROR -> Was able to create more than 0xffff" - " temp files.\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.cpp b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.cpp new file mode 100644 index 0000000000..861a8b87e8 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.cpp @@ -0,0 +1,80 @@ +// 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: GetTempFileNameA.c (test 2) +** +** Purpose: Tests the number of files GetTempFileNameA can create. +** +** Depends on: +** GetFileAttributesA +** oodles of free disk space (>4.07GB) +** +** +**===================================================================*/ + +#include + + + +int __cdecl main(int argc, char *argv[]) +{ + UINT uiError = 0; + DWORD dwError = 0; + const UINT uUnique = 0; + const char* szDot = {"."}; + const char* szValidPrefix = {"cfr"}; + char szReturnedName[256]; + DWORD i; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* test the number of temp files that can be created */ + for (i = 0; i < 0x10005; i++) + { + uiError = GetTempFileNameA(szDot, szValidPrefix, uUnique, szReturnedName); + if (uiError == 0) + { + dwError = GetLastError(); + if (dwError == ERROR_FILE_EXISTS) + { + /* file already existes so break out of the loop */ + i--; /* decrement the count because it wasn't successful */ + break; + } + else + { + /* it was something other than the file already existing? */ + Fail("GetTempFileNameA: ERROR -> Call failed with a valid " + "path and prefix with the error code: %ld\n", GetLastError()); + } + } + else + { + /* verify temp file was created */ + if (GetFileAttributesA(szReturnedName) == -1) + { + Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed " + "on the returned temp file \"%s\" with error code: %ld.\n", + szReturnedName, + GetLastError()); + } + } + } + + /* did it create more than 0xffff files */ + if (i > 0xffff) + { + Fail("GetTempFileNameA: ERROR -> Was able to create more than 0xffff" + " temp files.\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/CMakeLists.txt index 9c02865575..446f3cf837 100644 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - gettempfilenamea.c + gettempfilenamea.cpp ) add_executable(paltest_gettempfilenamea_test3 diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.c b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.c deleted file mode 100644 index 8eccc3d2e8..0000000000 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.c +++ /dev/null @@ -1,159 +0,0 @@ -// 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: GetTempFileNameA.c (test 3) -** -** Purpose: Tests the PAL implementation of the GetTempFileNameA function. -** Checks the file attributes and ensures that getting a file name, -** deleting the file and getting another doesn't produce the same -** as the just deleted file. Also checks the file size is 0. -** -** Depends on: -** GetFileAttributesA -** CloseHandle -** DeleteFileA -** CreateFileA -** GetFileSize -** -** -**===================================================================*/ - -#include - - - -int __cdecl main(int argc, char *argv[]) -{ - const UINT uUnique = 0; - UINT uiError; - const char* szDot = {"."}; - char szReturnedName[MAX_LONGPATH]; - char szReturnedName_02[MAX_LONGPATH]; - DWORD dwFileSize = 0; - HANDLE hFile; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* valid path with null prefix */ - uiError = GetTempFileNameA(szDot, NULL, uUnique, szReturnedName); - if (uiError == 0) - { - Fail("GetTempFileNameA: ERROR -> Call failed with a valid path " - "with the error code: %u.\n", - GetLastError()); - } - - /* verify temp file was created */ - if (GetFileAttributesA(szReturnedName) == -1) - { - Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the " - "returned temp file \"%s\" with error code: %u.\n", - szReturnedName, - GetLastError()); - } - - /* - ** verify that the file size is 0 bytes - */ - - hFile = CreateFileA(szReturnedName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Trace("GetTempFileNameA: ERROR -> CreateFileA failed to open" - " the created temp file with error code: %u.\n", - GetLastError()); - if (!DeleteFileA(szReturnedName)) - { - Trace("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - Fail(""); - } - - if ((dwFileSize = GetFileSize(hFile, NULL)) != (DWORD)0) - { - Trace("GetTempFileNameA: ERROR -> GetFileSize returned %u whereas" - "it should have returned 0.\n", - dwFileSize); - if (!CloseHandle(hFile)) - { - Trace("GetTempFileNameA: ERROR -> CloseHandle failed. " - "GetLastError returned: %u.\n", - GetLastError()); - } - if (!DeleteFileA(szReturnedName)) - { - Trace("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - Fail(""); - } - - - if (!CloseHandle(hFile)) - { - Fail("GetTempFileNameA: ERROR -> CloseHandle failed. " - "GetLastError returned: %u.\n", - GetLastError()); - } - - if (DeleteFileA(szReturnedName) != TRUE) - { - Fail("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - - /* get another and make sure it's not the same as the last */ - uiError = GetTempFileNameA(szDot, NULL, uUnique, szReturnedName_02); - if (uiError == 0) - { - Fail("GetTempFileNameA: ERROR -> Call failed with a valid path " - "with the error code: %u.\n", - GetLastError()); - } - - /* did we get different names? */ - if (strcmp(szReturnedName, szReturnedName_02) == 0) - { - Trace("GetTempFileNameA: ERROR -> The first call returned \"%s\". " - "The second call returned \"%s\" and the two should not be" - " the same.\n", - szReturnedName, - szReturnedName_02); - if (!DeleteFileA(szReturnedName_02)) - { - Trace("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - Fail(""); - } - - /* clean up */ - if (!DeleteFileA(szReturnedName_02)) - { - Fail("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.cpp b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.cpp new file mode 100644 index 0000000000..8eccc3d2e8 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.cpp @@ -0,0 +1,159 @@ +// 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: GetTempFileNameA.c (test 3) +** +** Purpose: Tests the PAL implementation of the GetTempFileNameA function. +** Checks the file attributes and ensures that getting a file name, +** deleting the file and getting another doesn't produce the same +** as the just deleted file. Also checks the file size is 0. +** +** Depends on: +** GetFileAttributesA +** CloseHandle +** DeleteFileA +** CreateFileA +** GetFileSize +** +** +**===================================================================*/ + +#include + + + +int __cdecl main(int argc, char *argv[]) +{ + const UINT uUnique = 0; + UINT uiError; + const char* szDot = {"."}; + char szReturnedName[MAX_LONGPATH]; + char szReturnedName_02[MAX_LONGPATH]; + DWORD dwFileSize = 0; + HANDLE hFile; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* valid path with null prefix */ + uiError = GetTempFileNameA(szDot, NULL, uUnique, szReturnedName); + if (uiError == 0) + { + Fail("GetTempFileNameA: ERROR -> Call failed with a valid path " + "with the error code: %u.\n", + GetLastError()); + } + + /* verify temp file was created */ + if (GetFileAttributesA(szReturnedName) == -1) + { + Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the " + "returned temp file \"%s\" with error code: %u.\n", + szReturnedName, + GetLastError()); + } + + /* + ** verify that the file size is 0 bytes + */ + + hFile = CreateFileA(szReturnedName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Trace("GetTempFileNameA: ERROR -> CreateFileA failed to open" + " the created temp file with error code: %u.\n", + GetLastError()); + if (!DeleteFileA(szReturnedName)) + { + Trace("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + Fail(""); + } + + if ((dwFileSize = GetFileSize(hFile, NULL)) != (DWORD)0) + { + Trace("GetTempFileNameA: ERROR -> GetFileSize returned %u whereas" + "it should have returned 0.\n", + dwFileSize); + if (!CloseHandle(hFile)) + { + Trace("GetTempFileNameA: ERROR -> CloseHandle failed. " + "GetLastError returned: %u.\n", + GetLastError()); + } + if (!DeleteFileA(szReturnedName)) + { + Trace("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + Fail(""); + } + + + if (!CloseHandle(hFile)) + { + Fail("GetTempFileNameA: ERROR -> CloseHandle failed. " + "GetLastError returned: %u.\n", + GetLastError()); + } + + if (DeleteFileA(szReturnedName) != TRUE) + { + Fail("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + + /* get another and make sure it's not the same as the last */ + uiError = GetTempFileNameA(szDot, NULL, uUnique, szReturnedName_02); + if (uiError == 0) + { + Fail("GetTempFileNameA: ERROR -> Call failed with a valid path " + "with the error code: %u.\n", + GetLastError()); + } + + /* did we get different names? */ + if (strcmp(szReturnedName, szReturnedName_02) == 0) + { + Trace("GetTempFileNameA: ERROR -> The first call returned \"%s\". " + "The second call returned \"%s\" and the two should not be" + " the same.\n", + szReturnedName, + szReturnedName_02); + if (!DeleteFileA(szReturnedName_02)) + { + Trace("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + Fail(""); + } + + /* clean up */ + if (!DeleteFileA(szReturnedName_02)) + { + Fail("GetTempFileNameA: ERROR -> DeleteFileA failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/CMakeLists.txt index 1b6c599da4..6919cf66cd 100644 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetTempFileNameW.c + GetTempFileNameW.cpp ) add_executable(paltest_gettempfilenamew_test1 diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.c b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.c deleted file mode 100644 index 43cda8f447..0000000000 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.c +++ /dev/null @@ -1,129 +0,0 @@ -// 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: GetTempFileNameW.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetTempFileNameW function. -** -** -**===================================================================*/ - -#include - - - -int __cdecl main(int argc, char *argv[]) -{ - UINT uiError = 0; - const UINT uUnique = 0; - WCHAR* wPrefix = NULL; - WCHAR* wPath = NULL; - WCHAR wReturnedName[256]; - WCHAR wTempString[256]; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - // valid path with null ext - wPath = convert("."); - uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); - free (wPath); - if (uiError == 0) - { - Fail("GetTempFileNameW: ERROR -> Call failed with a valid path " - "with the error code: %ld\n", GetLastError()); - } - else - { - // verify temp file was created - if (GetFileAttributesW(wReturnedName) == -1) - { - Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " - "returned temp file with error code: %ld.\n", GetLastError()); - } - if (DeleteFileW(wReturnedName) != TRUE) - { - Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" - "the created temp file with error code: %lld.\n", GetLastError()); - } - } - - - // valid path with valid prefix - wPath = convert("."); - wPrefix = convert("cfr"); - uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); - free (wPath); - free (wPrefix); - if (uiError == 0) - { - Fail("GetTempFileNameW: ERROR -> Call failed with a valid path and " - "prefix with the error code: %ld\n", GetLastError()); - } - else - { - // verify temp file was created - if (GetFileAttributesW(wReturnedName) == -1) - { - Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " - "returned temp file with error code: %ld.\n", GetLastError()); - } - if (DeleteFileW(wReturnedName) != TRUE) - { - Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" - "the created temp file with error code: %lld.\n", GetLastError()); - } - } - - // valid path with long prefix - wPath = convert("."); - wPrefix = convert("cfrwxyz"); - uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); - if (uiError == 0) - { - free (wPath); - free (wPrefix); - Fail("GetTempFileNameW: ERROR -> Call failed with a valid path and " - "prefix with the error code: %ld\n", GetLastError()); - } - else - { - // verify temp file was created - if (GetFileAttributesW(wReturnedName) == -1) - { - free (wPath); - free (wPrefix); - Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " - "returned temp file with error code: %ld.\n", GetLastError()); - } - - // now verify that it only used the first 3 characters of the prefix - swprintf(wTempString, convert("%s\\%s"), wPath, wPrefix); - if (memcmp(wTempString, wReturnedName, wcslen(wTempString)*sizeof(WCHAR)) == 0) - { - free (wPath); - free (wPrefix); - Fail("GetTempFileNameW: ERROR -> It appears that an improper prefix " - "was used.\n"); - } - - if (DeleteFileW(wReturnedName) != TRUE) - { - free (wPath); - free (wPrefix); - Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" - "the created temp file with error code: %lld.\n", GetLastError()); - } - } - - free (wPath); - free (wPrefix); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.cpp b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.cpp new file mode 100644 index 0000000000..43cda8f447 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.cpp @@ -0,0 +1,129 @@ +// 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: GetTempFileNameW.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetTempFileNameW function. +** +** +**===================================================================*/ + +#include + + + +int __cdecl main(int argc, char *argv[]) +{ + UINT uiError = 0; + const UINT uUnique = 0; + WCHAR* wPrefix = NULL; + WCHAR* wPath = NULL; + WCHAR wReturnedName[256]; + WCHAR wTempString[256]; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + // valid path with null ext + wPath = convert("."); + uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); + free (wPath); + if (uiError == 0) + { + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path " + "with the error code: %ld\n", GetLastError()); + } + else + { + // verify temp file was created + if (GetFileAttributesW(wReturnedName) == -1) + { + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " + "returned temp file with error code: %ld.\n", GetLastError()); + } + if (DeleteFileW(wReturnedName) != TRUE) + { + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + "the created temp file with error code: %lld.\n", GetLastError()); + } + } + + + // valid path with valid prefix + wPath = convert("."); + wPrefix = convert("cfr"); + uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); + free (wPath); + free (wPrefix); + if (uiError == 0) + { + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path and " + "prefix with the error code: %ld\n", GetLastError()); + } + else + { + // verify temp file was created + if (GetFileAttributesW(wReturnedName) == -1) + { + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " + "returned temp file with error code: %ld.\n", GetLastError()); + } + if (DeleteFileW(wReturnedName) != TRUE) + { + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + "the created temp file with error code: %lld.\n", GetLastError()); + } + } + + // valid path with long prefix + wPath = convert("."); + wPrefix = convert("cfrwxyz"); + uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); + if (uiError == 0) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path and " + "prefix with the error code: %ld\n", GetLastError()); + } + else + { + // verify temp file was created + if (GetFileAttributesW(wReturnedName) == -1) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " + "returned temp file with error code: %ld.\n", GetLastError()); + } + + // now verify that it only used the first 3 characters of the prefix + swprintf(wTempString, convert("%s\\%s"), wPath, wPrefix); + if (memcmp(wTempString, wReturnedName, wcslen(wTempString)*sizeof(WCHAR)) == 0) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> It appears that an improper prefix " + "was used.\n"); + } + + if (DeleteFileW(wReturnedName) != TRUE) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + "the created temp file with error code: %lld.\n", GetLastError()); + } + } + + free (wPath); + free (wPrefix); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/CMakeLists.txt index 851030d9ae..d077463390 100644 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetTempFileNameW.c + GetTempFileNameW.cpp ) add_executable(paltest_gettempfilenamew_test2 diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.c b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.c deleted file mode 100644 index 2c8b19e081..0000000000 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.c +++ /dev/null @@ -1,84 +0,0 @@ -// 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: GetTempFileNameW.c (test 2) -** -** Purpose: Tests the PAL implementation of the GetTempFileNameW function. -** -** -**===================================================================*/ - -#include - - - -int __cdecl main(int argc, char *argv[]) -{ - UINT uiError = 0; - DWORD dwError = 0; - const UINT uUnique = 0; - WCHAR* wPrefix = NULL; - WCHAR* wPath = NULL; - WCHAR wReturnedName[256]; - DWORD i; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - // test the number of temp files that can be created - wPrefix = convert("cfr"); - wPath = convert("."); - for (i = 0; i < 0x10005; i++) - { - uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); - if (uiError == 0) - { - dwError = GetLastError(); - if (dwError == ERROR_FILE_EXISTS) - { - // file already existes so break out of the loop - i--; // decrement the count because it wasn't successful - break; - } - else - { - // it was something other than the file already existing? - free (wPath); - free (wPrefix); - Fail("GetTempFileNameW: ERROR -> Call failed with a valid " - "path and prefix with the error code: %ld\n", GetLastError()); - } - } - else - { - // verify temp file was created - if (GetFileAttributesW(wReturnedName) == -1) - { - free (wPath); - free (wPrefix); - Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed " - "on the returned temp file with error code: %ld.\n", - GetLastError()); - } - } - } - - free (wPath); - free (wPrefix); - - // did it create more than 0xffff files - if (i > 0xffff) - { - Fail("GetTempFileNameW: ERROR -> Was able to create more than 0xffff" - " temp files.\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.cpp b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.cpp new file mode 100644 index 0000000000..2c8b19e081 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.cpp @@ -0,0 +1,84 @@ +// 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: GetTempFileNameW.c (test 2) +** +** Purpose: Tests the PAL implementation of the GetTempFileNameW function. +** +** +**===================================================================*/ + +#include + + + +int __cdecl main(int argc, char *argv[]) +{ + UINT uiError = 0; + DWORD dwError = 0; + const UINT uUnique = 0; + WCHAR* wPrefix = NULL; + WCHAR* wPath = NULL; + WCHAR wReturnedName[256]; + DWORD i; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + // test the number of temp files that can be created + wPrefix = convert("cfr"); + wPath = convert("."); + for (i = 0; i < 0x10005; i++) + { + uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); + if (uiError == 0) + { + dwError = GetLastError(); + if (dwError == ERROR_FILE_EXISTS) + { + // file already existes so break out of the loop + i--; // decrement the count because it wasn't successful + break; + } + else + { + // it was something other than the file already existing? + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> Call failed with a valid " + "path and prefix with the error code: %ld\n", GetLastError()); + } + } + else + { + // verify temp file was created + if (GetFileAttributesW(wReturnedName) == -1) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed " + "on the returned temp file with error code: %ld.\n", + GetLastError()); + } + } + } + + free (wPath); + free (wPrefix); + + // did it create more than 0xffff files + if (i > 0xffff) + { + Fail("GetTempFileNameW: ERROR -> Was able to create more than 0xffff" + " temp files.\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/CMakeLists.txt index 82dd0a9f3f..3aa0f4a044 100644 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - gettempfilenamew.c + gettempfilenamew.cpp ) add_executable(paltest_gettempfilenamew_test3 diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.c b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.c deleted file mode 100644 index 96d8e66410..0000000000 --- a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.c +++ /dev/null @@ -1,161 +0,0 @@ -// 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: GetTempFileNameW.c (test 3) -** -** Purpose: Tests the PAL implementation of the GetTempFileNameW function. -** Checks the file attributes and ensures that getting a file name, -** deleting the file and getting another doesn't produce the same -** as the just deleted file. Also checks the file size is 0. -** -** Depends on: -** GetFileAttributesW -** DeleteFileW -** CreateFileW -** GetFileSize -** CloseHandle -** -** -**===================================================================*/ - -#include - - - -int __cdecl main(int argc, char *argv[]) -{ - const UINT uUnique = 0; - UINT uiError; - WCHAR szwReturnedName[MAX_LONGPATH]; - WCHAR szwReturnedName_02[MAX_LONGPATH]; - DWORD dwFileSize = 0; - HANDLE hFile; - const WCHAR szwDot[] = {'.','\0'}; - const WCHAR szwPre[] = {'c','\0'}; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* valid path with null prefix */ - uiError = GetTempFileNameW(szwDot, szwPre, uUnique, szwReturnedName); - if (uiError == 0) - { - Fail("GetTempFileNameW: ERROR -> Call failed with a valid path " - "with the error code: %u.\n", - GetLastError()); - } - - /* verify temp file was created */ - if (GetFileAttributesW(szwReturnedName) == -1) - { - Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " - "returned temp file \"%S\" with error code: %u.\n", - szwReturnedName, - GetLastError()); - } - - /* - ** verify that the file size is 0 bytes - */ - - hFile = CreateFileW(szwReturnedName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Trace("GetTempFileNameW: ERROR -> CreateFileW failed to open" - " the created temp file with error code: %u.\n", - GetLastError()); - if (!DeleteFileW(szwReturnedName)) - { - Trace("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - Fail(""); - } - - if ((dwFileSize = GetFileSize(hFile, NULL)) != (DWORD)0) - { - Trace("GetTempFileNameW: ERROR -> GetFileSize returned %u whereas" - "it should have returned 0.\n", - dwFileSize); - if (!CloseHandle(hFile)) - { - Trace("GetTempFileNameW: ERROR -> CloseHandle was unable to close the " - "opened file. GetLastError returned %u.\n", - GetLastError()); - } - if (!DeleteFileW(szwReturnedName)) - { - Trace("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - Fail(""); - } - - if (!CloseHandle(hFile)) - { - Fail("GetTempFileNameW: ERROR -> CloseHandle was unable to close the " - "opened file. GetLastError returned %u.\n", - GetLastError()); - } - - - /* delete the file to see if we get the same name next time around */ - if (DeleteFileW(szwReturnedName) != TRUE) - { - Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - - /* get another and make sure it's not the same as the last */ - uiError = GetTempFileNameW(szwDot, szwPre, uUnique, szwReturnedName_02); - if (uiError == 0) - { - Fail("GetTempFileNameW: ERROR -> Call failed with a valid path " - "with the error code: %u.\n", - GetLastError()); - } - - /* did we get different names? */ - if (wcsncmp(szwReturnedName, szwReturnedName_02, wcslen(szwReturnedName)) == 0) - { - Fail("GetTempFileNameW: ERROR -> The first call returned \"%S\". " - "The second call returned \"%S\" and the two should not be" - " the same.\n", - szwReturnedName, - szwReturnedName_02); - if (!DeleteFileW(szwReturnedName_02)) - { - Trace("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - Fail(""); - } - - /* clean up */ - if (!DeleteFileW(szwReturnedName_02)) - { - Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" - " the created temp file with error code: %u.\n", - GetLastError()); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.cpp b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.cpp new file mode 100644 index 0000000000..96d8e66410 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.cpp @@ -0,0 +1,161 @@ +// 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: GetTempFileNameW.c (test 3) +** +** Purpose: Tests the PAL implementation of the GetTempFileNameW function. +** Checks the file attributes and ensures that getting a file name, +** deleting the file and getting another doesn't produce the same +** as the just deleted file. Also checks the file size is 0. +** +** Depends on: +** GetFileAttributesW +** DeleteFileW +** CreateFileW +** GetFileSize +** CloseHandle +** +** +**===================================================================*/ + +#include + + + +int __cdecl main(int argc, char *argv[]) +{ + const UINT uUnique = 0; + UINT uiError; + WCHAR szwReturnedName[MAX_LONGPATH]; + WCHAR szwReturnedName_02[MAX_LONGPATH]; + DWORD dwFileSize = 0; + HANDLE hFile; + const WCHAR szwDot[] = {'.','\0'}; + const WCHAR szwPre[] = {'c','\0'}; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* valid path with null prefix */ + uiError = GetTempFileNameW(szwDot, szwPre, uUnique, szwReturnedName); + if (uiError == 0) + { + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path " + "with the error code: %u.\n", + GetLastError()); + } + + /* verify temp file was created */ + if (GetFileAttributesW(szwReturnedName) == -1) + { + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " + "returned temp file \"%S\" with error code: %u.\n", + szwReturnedName, + GetLastError()); + } + + /* + ** verify that the file size is 0 bytes + */ + + hFile = CreateFileW(szwReturnedName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Trace("GetTempFileNameW: ERROR -> CreateFileW failed to open" + " the created temp file with error code: %u.\n", + GetLastError()); + if (!DeleteFileW(szwReturnedName)) + { + Trace("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + Fail(""); + } + + if ((dwFileSize = GetFileSize(hFile, NULL)) != (DWORD)0) + { + Trace("GetTempFileNameW: ERROR -> GetFileSize returned %u whereas" + "it should have returned 0.\n", + dwFileSize); + if (!CloseHandle(hFile)) + { + Trace("GetTempFileNameW: ERROR -> CloseHandle was unable to close the " + "opened file. GetLastError returned %u.\n", + GetLastError()); + } + if (!DeleteFileW(szwReturnedName)) + { + Trace("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + Fail(""); + } + + if (!CloseHandle(hFile)) + { + Fail("GetTempFileNameW: ERROR -> CloseHandle was unable to close the " + "opened file. GetLastError returned %u.\n", + GetLastError()); + } + + + /* delete the file to see if we get the same name next time around */ + if (DeleteFileW(szwReturnedName) != TRUE) + { + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + + /* get another and make sure it's not the same as the last */ + uiError = GetTempFileNameW(szwDot, szwPre, uUnique, szwReturnedName_02); + if (uiError == 0) + { + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path " + "with the error code: %u.\n", + GetLastError()); + } + + /* did we get different names? */ + if (wcsncmp(szwReturnedName, szwReturnedName_02, wcslen(szwReturnedName)) == 0) + { + Fail("GetTempFileNameW: ERROR -> The first call returned \"%S\". " + "The second call returned \"%S\" and the two should not be" + " the same.\n", + szwReturnedName, + szwReturnedName_02); + if (!DeleteFileW(szwReturnedName_02)) + { + Trace("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + Fail(""); + } + + /* clean up */ + if (!DeleteFileW(szwReturnedName_02)) + { + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetTempPathW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempPathW/test1/CMakeLists.txt index f2979e9536..04b240997a 100644 --- a/src/pal/tests/palsuite/file_io/GetTempPathW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/GetTempPathW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetTempPathW.c + GetTempPathW.cpp ) add_executable(paltest_gettemppathw_test1 diff --git a/src/pal/tests/palsuite/file_io/GetTempPathW/test1/GetTempPathW.c b/src/pal/tests/palsuite/file_io/GetTempPathW/test1/GetTempPathW.c deleted file mode 100644 index 08c88075ca..0000000000 --- a/src/pal/tests/palsuite/file_io/GetTempPathW/test1/GetTempPathW.c +++ /dev/null @@ -1,103 +0,0 @@ -// 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: GetTempPathW.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetTempPathW function. -** -** -**===================================================================*/ - -#include - -static void SetTmpDir(WCHAR path[]) -{ - DWORD result = SetEnvironmentVariableW(W("TMPDIR"), path); - if (!result) - { - Fail("ERROR -> SetEnvironmentVariableW failed with result %d and error code %d.\n", - result, GetLastError()); - } -} - -static void SetAndCompare(WCHAR tmpDirPath[], WCHAR expected[]) -{ - DWORD dwBufferLength = _MAX_DIR; - WCHAR path[dwBufferLength]; - - SetTmpDir(tmpDirPath); - - DWORD dwResultLen = GetTempPathW(dwBufferLength, path); - if (dwResultLen <= 0) - { - Fail("ERROR: GetTempPathW returned %d with error code %d.\n", dwResultLen, GetLastError()); - } - if (dwResultLen >= dwBufferLength) - { - Fail("ERROR: Buffer of length %d passed to GetTempPathA was too small to hold %d chars..\n", dwBufferLength, dwResultLen); - } - if (wcscmp(expected, path) != 0) - { - Fail("ERROR: GetTempPathW expected to get '%S' but instead got '%S'.\n", expected, path); - } - if (expected[dwResultLen - 1] != '/') - { - Fail("ERROR: GetTempPathW returned '%S', which should have ended in '/'.\n", path); - } -} - -static void SetAndCheckLength(WCHAR tmpDirPath [], int bufferLength, int expectedResultLength) -{ - WCHAR path[bufferLength]; - - SetTmpDir(tmpDirPath); - DWORD dwResultLen = GetTempPathW(bufferLength, path); - - if (dwResultLen != expectedResultLength) - { - Fail("GetTempPathW(%d, %S) expected to return %d but returned %d.\n", - bufferLength, tmpDirPath?tmpDirPath:W("NULL"), expectedResultLength, dwResultLen); - } -} - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - SetAndCompare(W("/tmp"), W("/tmp/")); - SetAndCompare(W("/tmp/"), W("/tmp/")); - SetAndCompare(W(""), W("/tmp/")); - SetAndCompare(NULL, W("/tmp/")); - SetAndCompare(W("/"), W("/")); - SetAndCompare(W("/var/tmp"), W("/var/tmp/")); - SetAndCompare(W("/var/tmp/"), W("/var/tmp/")); - SetAndCompare(W("~"), W("~/")); - SetAndCompare(W("~/"), W("~/")); - SetAndCompare(W(".tmp"), W(".tmp/")); - SetAndCompare(W("./tmp"), W("./tmp/")); - SetAndCompare(W("/home/someuser/sometempdir"), W("/home/someuser/sometempdir/")); - SetAndCompare(NULL, W("/tmp/")); - - DWORD dwResultLen = GetTempPathA(0, NULL); - if (dwResultLen != 0 || GetLastError() != ERROR_INVALID_PARAMETER) - { - Fail("GetTempPathW(NULL, ...) returned %d with error code %d but " - "should have failed with ERROR_INVALID_PARAMETER (%d).\n", - dwResultLen, GetLastError(), ERROR_INVALID_PARAMETER); - } - - SetAndCheckLength(W("abc/"), 5, 4); - SetAndCheckLength(W("abcd"), 5, 6); - SetAndCheckLength(W("abcde"), 5, 7); - SetAndCheckLength(W("abcdef/"), 5, 9); - SetAndCheckLength(NULL, 5, 6); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/GetTempPathW/test1/GetTempPathW.cpp b/src/pal/tests/palsuite/file_io/GetTempPathW/test1/GetTempPathW.cpp new file mode 100644 index 0000000000..bf997def76 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempPathW/test1/GetTempPathW.cpp @@ -0,0 +1,103 @@ +// 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: GetTempPathW.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetTempPathW function. +** +** +**===================================================================*/ + +#include + +static void SetTmpDir(const WCHAR path[]) +{ + DWORD result = SetEnvironmentVariableW(W("TMPDIR"), path); + if (!result) + { + Fail("ERROR -> SetEnvironmentVariableW failed with result %d and error code %d.\n", + result, GetLastError()); + } +} + +static void SetAndCompare(const WCHAR tmpDirPath[], const WCHAR expected[]) +{ + DWORD dwBufferLength = _MAX_DIR; + WCHAR path[dwBufferLength]; + + SetTmpDir(tmpDirPath); + + DWORD dwResultLen = GetTempPathW(dwBufferLength, path); + if (dwResultLen <= 0) + { + Fail("ERROR: GetTempPathW returned %d with error code %d.\n", dwResultLen, GetLastError()); + } + if (dwResultLen >= dwBufferLength) + { + Fail("ERROR: Buffer of length %d passed to GetTempPathA was too small to hold %d chars..\n", dwBufferLength, dwResultLen); + } + if (wcscmp(expected, path) != 0) + { + Fail("ERROR: GetTempPathW expected to get '%S' but instead got '%S'.\n", expected, path); + } + if (expected[dwResultLen - 1] != '/') + { + Fail("ERROR: GetTempPathW returned '%S', which should have ended in '/'.\n", path); + } +} + +static void SetAndCheckLength(const WCHAR tmpDirPath [], int bufferLength, int expectedResultLength) +{ + WCHAR path[bufferLength]; + + SetTmpDir(tmpDirPath); + DWORD dwResultLen = GetTempPathW(bufferLength, path); + + if (dwResultLen != expectedResultLength) + { + Fail("GetTempPathW(%d, %S) expected to return %d but returned %d.\n", + bufferLength, tmpDirPath?tmpDirPath:W("NULL"), expectedResultLength, dwResultLen); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + SetAndCompare(W("/tmp"), W("/tmp/")); + SetAndCompare(W("/tmp/"), W("/tmp/")); + SetAndCompare(W(""), W("/tmp/")); + SetAndCompare(NULL, W("/tmp/")); + SetAndCompare(W("/"), W("/")); + SetAndCompare(W("/var/tmp"), W("/var/tmp/")); + SetAndCompare(W("/var/tmp/"), W("/var/tmp/")); + SetAndCompare(W("~"), W("~/")); + SetAndCompare(W("~/"), W("~/")); + SetAndCompare(W(".tmp"), W(".tmp/")); + SetAndCompare(W("./tmp"), W("./tmp/")); + SetAndCompare(W("/home/someuser/sometempdir"), W("/home/someuser/sometempdir/")); + SetAndCompare(NULL, W("/tmp/")); + + DWORD dwResultLen = GetTempPathA(0, NULL); + if (dwResultLen != 0 || GetLastError() != ERROR_INVALID_PARAMETER) + { + Fail("GetTempPathW(NULL, ...) returned %d with error code %d but " + "should have failed with ERROR_INVALID_PARAMETER (%d).\n", + dwResultLen, GetLastError(), ERROR_INVALID_PARAMETER); + } + + SetAndCheckLength(W("abc/"), 5, 4); + SetAndCheckLength(W("abcd"), 5, 6); + SetAndCheckLength(W("abcde"), 5, 7); + SetAndCheckLength(W("abcdef/"), 5, 9); + SetAndCheckLength(NULL, 5, 6); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/MoveFileA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/MoveFileA/test1/CMakeLists.txt index 9a3d0069db..b096a04653 100644 --- a/src/pal/tests/palsuite/file_io/MoveFileA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/MoveFileA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - MoveFileA.c + MoveFileA.cpp ) add_executable(paltest_movefilea_test1 diff --git a/src/pal/tests/palsuite/file_io/MoveFileA/test1/MoveFileA.c b/src/pal/tests/palsuite/file_io/MoveFileA/test1/MoveFileA.c deleted file mode 100644 index 8d1bc0eded..0000000000 --- a/src/pal/tests/palsuite/file_io/MoveFileA/test1/MoveFileA.c +++ /dev/null @@ -1,469 +0,0 @@ -// 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: MoveFileA.c -** -** Purpose: Tests the PAL implementation of the MoveFileA function. -** -** -**===================================================================*/ - -#include - -LPSTR lpSource[4] = {"src_existing.txt", - "src_non-existant.txt", - "src_dir_existing", - "src_dir_non-existant"}; -LPSTR lpDestination[4] = {"dst_existing.txt", - "dst_non-existant.txt", - "dst_dir_existing", - "dst_dir_non-existant"}; - - -/* Create all the required test files */ -int createExisting(void) -{ - FILE* tempFile = NULL; - DWORD dwError; - BOOL bRc = FALSE; - char szBuffer[100]; - - /* create the src_existing file */ - tempFile = fopen(lpSource[0], "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileA test file: src_existing.txt\n"); - fclose(tempFile); - } - else - { - Trace("ERROR: couldn't create %s\n", lpSource[0]); - return FAIL; - } - - /* create the src_dir_existing directory and files */ - bRc = CreateDirectoryA(lpSource[2], NULL); - if (bRc != TRUE) - { - Trace("MoveFileA: ERROR: couldn't create \"%s\" because of " - "error code %ld\n", - lpSource[2], - GetLastError()); - return FAIL; - } - - memset(szBuffer, 0, 100); - sprintf(szBuffer, "%s/test01.txt", lpSource[2]); - tempFile = fopen(szBuffer, "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileA test file: %s\n", szBuffer); - fclose(tempFile); - } - else - { - Trace("ERROR[%ld]:MoveFileA couldn't create %s\n", GetLastError(), szBuffer); - return FAIL; - } - - memset(szBuffer, 0, 100); - sprintf(szBuffer, "%s/test02.txt", lpSource[2]); - tempFile = fopen(szBuffer, "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileA test file: %s\n", szBuffer); - fclose(tempFile); - } - else - { - Trace("ERROR[%ld]: couldn't create %s\n", GetLastError(), szBuffer); - return FAIL; - } - - - /* create the dst_existing file */ - tempFile = fopen(lpDestination[0], "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileA test file: dst_existing.txt\n"); - fclose(tempFile); - } - else - { - Trace("ERROR[%ld]:MoveFileA couldn't create \"%s\"\n", GetLastError(), lpDestination[0]); - return FAIL; - } - - /* create the dst_dir_existing directory and files */ - bRc = CreateDirectoryA(lpDestination[2], NULL); - if (bRc != TRUE) - { - dwError = GetLastError(); - Trace("Error[%ld]:MoveFileA: couldn't create \"%s\"\n", GetLastError(), lpDestination[2]); - return FAIL; - } - - tempFile = fopen("dst_dir_existing/test01.txt", "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileA test file: dst_dir_existing/test01.txt\n"); - fclose(tempFile); - } - else - { - Trace("ERROR: couldn't create dst_dir_existing/test01.txt\n"); - return FAIL; - } - tempFile = fopen("dst_dir_existing/test02.txt", "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileA test file: dst_dir_existing/test02.txt\n"); - fclose(tempFile); - } - else - { - Trace("ERROR[%ul]: couldn't create dst_dir_existing/test02.txt\n", GetLastError()); - return FAIL; - } - - return PASS; -} - - - -void removeDirectoryHelper(LPSTR dir, int location) -{ - DWORD dwAtt = GetFileAttributesA(dir); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - if(!RemoveDirectoryA(dir)) - { - Fail("ERROR: Failed to remove Directory [%s], Error Code [%d], location [%d]\n", dir, GetLastError(), location); - } - } -} - -void removeFileHelper(LPSTR pfile, int location) -{ - FILE *fp; - fp = fopen( pfile, "r"); - - if (fp != NULL) - { - if(fclose(fp)) - { - Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - - if(!DeleteFileA(pfile)) - { - Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - else - { - // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); - } - } - -} - - -/* remove all created files in preparation for the next test */ -void removeAll(void) -{ - char szTemp[40]; - DWORD dwAtt; - - /* get rid of source dirs and files */ - removeFileHelper(lpSource[0], 1); - removeFileHelper(lpSource[1], 2); - - dwAtt = GetFileAttributesA(lpSource[2]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpSource[2]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpSource[2]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpSource[2], 103); - } - else - { - removeFileHelper(lpSource[2], 17); - } - - - dwAtt = GetFileAttributesA(lpSource[3]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpSource[3]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpSource[3]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpSource[3], 103); - } - else - { - removeFileHelper(lpSource[3], 17); - } - - /* get rid of destination dirs and files */ - dwAtt = GetFileAttributesA(lpDestination[0]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpDestination[0]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpDestination[0]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpDestination[0], 103); - } - else - { - removeFileHelper(lpDestination[0], 17); - } - - dwAtt = GetFileAttributesA(lpDestination[1]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpDestination[1]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpDestination[1]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpDestination[1], 103); - } - else - { - removeFileHelper(lpDestination[1], 17); - } - - dwAtt = GetFileAttributesA(lpDestination[2]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpDestination[2]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpDestination[2]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpDestination[2], 103); - } - else - { - removeFileHelper(lpDestination[2], 17); - } - - dwAtt = GetFileAttributesA(lpDestination[3]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpDestination[3]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpDestination[3]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpDestination[3], 103); - } - else - { - removeFileHelper(lpDestination[3], 17); - } - -} - - - - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bRc = TRUE; - BOOL bSuccess = TRUE; - char results[40]; - FILE* resultsFile = NULL; - int nCounter = 0; - int i, j; - char tempSource[] = {'t','e','m','p','k','.','t','m','p','\0'}; - char tempDest[] = {'t','e','m','p','2','.','t','m','p','\0'}; - HANDLE hFile; - DWORD result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* read in the expected results to compare with actual results */ - memset (results, 0, 20); - resultsFile = fopen("expectedresults.txt", "r"); - if (resultsFile == NULL) - { - Fail("MoveFileA ERROR[%ul]: Unable to open \"expectedresults.txt\"\n", GetLastError()); - } - - fgets(results, 20, resultsFile); - fclose(resultsFile); - - /* clean the slate */ - removeAll(); - - if (createExisting() != 0) - { - removeAll(); - } - - - /* lpSource loop */ - for (i = 0; i < 4; i++) - { - /* lpDestination loop */ - for (j = 0; j < 4; j++) - { - bRc = MoveFileA(lpSource[i], lpDestination[j]); - if (!( - ((bRc == TRUE) && (results[nCounter] == '1')) - || - ((bRc == FALSE ) && (results[nCounter] == '0')) ) - ) - { - Trace("MoveFileA: FAILED: test[%d][%d]: \"%s\" -> \"%s\"\n", - i, j, lpSource[i], lpDestination[j]); - bSuccess = FALSE; - } - - /* undo the last move */ - removeAll(); - createExisting(); - - nCounter++; - } - } - - removeAll(); - if (bSuccess == FALSE) - { - Fail("MoveFileA: Test Failed"); - } - - /* create the temp source file */ - hFile = CreateFileA(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - - if( hFile == INVALID_HANDLE_VALUE ) - { - Fail("Error[%ul]:MoveFileA: CreateFile failed to " - "create the file correctly.\n", GetLastError()); - } - - bRc = CloseHandle(hFile); - if(!bRc) - { - Trace("MoveFileA: CloseHandle failed to close the " - "handle correctly. ERROR:%u\n",GetLastError()); - - /* delete the created file */ - bRc = DeleteFileA(tempSource); - if(!bRc) - { - Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" - "file correctly.\n", GetLastError()); - } - Fail(""); - } - - /* set the file attributes to be readonly */ - bRc = SetFileAttributesA(tempSource, FILE_ATTRIBUTE_READONLY); - if(!bRc) - { - Trace("MoveFileA: SetFileAttributes failed to set file " - "attributes correctly. GetLastError returned %u\n",GetLastError()); - /* delete the created file */ - bRc = DeleteFileA(tempSource); - if(!bRc) - { - Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" - "file correctly.\n", GetLastError()); - } - Fail(""); - } - - /* move the file to the new location */ - bRc = MoveFileA(tempSource, tempDest); - if(!bRc) - { - /* delete the created file */ - bRc = DeleteFileA(tempSource); - if(!bRc) - { - Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" - "file correctly.\n", GetLastError()); - } - - Fail("Error[%ul]:MoveFileA(%S, %S): GetFileAttributes " - "failed to get the file's attributes.\n", - GetLastError(), tempSource, tempDest); - } - - /* check that the newly moved file has the same file attributes - as the original */ - result = GetFileAttributesA(tempDest); - if(result == 0) - { - /* delete the created file */ - bRc = DeleteFileA(tempDest); - if(!bRc) - { - Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" - "file correctly.\n", GetLastError()); - } - - Fail("Error[%ul]:MoveFileA: GetFileAttributes failed to get " - "the file's attributes.\n", GetLastError()); - } - - if((result & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) - { - /* delete the newly moved file */ - bRc = DeleteFileA(tempDest); - if(!bRc) - { - Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" - "file correctly.\n", GetLastError()); - } - - Fail("Error[%ul]MoveFileA: GetFileAttributes failed to get " - "the correct file attributes.\n", GetLastError()); - } - - /* set the file attributes back to normal, to be deleted */ - bRc = SetFileAttributesA(tempDest, FILE_ATTRIBUTE_NORMAL); - if(!bRc) - { - /* delete the newly moved file */ - bRc = DeleteFileA(tempDest); - if(!bRc) - { - Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" - "file correctly.\n", GetLastError()); - } - - Fail("Error[%ul]:MoveFileA: SetFileAttributes failed to set " - "file attributes correctly.\n", GetLastError()); - } - - /* delete the newly moved file */ - bRc = DeleteFileA(tempDest); - if(!bRc) - { - Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" - "file correctly.\n", GetLastError()); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/MoveFileA/test1/MoveFileA.cpp b/src/pal/tests/palsuite/file_io/MoveFileA/test1/MoveFileA.cpp new file mode 100644 index 0000000000..6d1337af03 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/MoveFileA/test1/MoveFileA.cpp @@ -0,0 +1,469 @@ +// 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: MoveFileA.c +** +** Purpose: Tests the PAL implementation of the MoveFileA function. +** +** +**===================================================================*/ + +#include + +LPSTR lpSource[4] = {"src_existing.txt", + "src_non-existant.txt", + "src_dir_existing", + "src_dir_non-existant"}; +LPSTR lpDestination[4] = {"dst_existing.txt", + "dst_non-existant.txt", + "dst_dir_existing", + "dst_dir_non-existant"}; + + +/* Create all the required test files */ +int createExisting(void) +{ + FILE* tempFile = NULL; + DWORD dwError; + BOOL bRc = FALSE; + char szBuffer[100]; + + /* create the src_existing file */ + tempFile = fopen(lpSource[0], "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileA test file: src_existing.txt\n"); + fclose(tempFile); + } + else + { + Trace("ERROR: couldn't create %s\n", lpSource[0]); + return FAIL; + } + + /* create the src_dir_existing directory and files */ + bRc = CreateDirectoryA(lpSource[2], NULL); + if (bRc != TRUE) + { + Trace("MoveFileA: ERROR: couldn't create \"%s\" because of " + "error code %ld\n", + lpSource[2], + GetLastError()); + return FAIL; + } + + memset(szBuffer, 0, 100); + sprintf_s(szBuffer, _countof(szBuffer), "%s/test01.txt", lpSource[2]); + tempFile = fopen(szBuffer, "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileA test file: %s\n", szBuffer); + fclose(tempFile); + } + else + { + Trace("ERROR[%ld]:MoveFileA couldn't create %s\n", GetLastError(), szBuffer); + return FAIL; + } + + memset(szBuffer, 0, 100); + sprintf_s(szBuffer, _countof(szBuffer), "%s/test02.txt", lpSource[2]); + tempFile = fopen(szBuffer, "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileA test file: %s\n", szBuffer); + fclose(tempFile); + } + else + { + Trace("ERROR[%ld]: couldn't create %s\n", GetLastError(), szBuffer); + return FAIL; + } + + + /* create the dst_existing file */ + tempFile = fopen(lpDestination[0], "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileA test file: dst_existing.txt\n"); + fclose(tempFile); + } + else + { + Trace("ERROR[%ld]:MoveFileA couldn't create \"%s\"\n", GetLastError(), lpDestination[0]); + return FAIL; + } + + /* create the dst_dir_existing directory and files */ + bRc = CreateDirectoryA(lpDestination[2], NULL); + if (bRc != TRUE) + { + dwError = GetLastError(); + Trace("Error[%ld]:MoveFileA: couldn't create \"%s\"\n", GetLastError(), lpDestination[2]); + return FAIL; + } + + tempFile = fopen("dst_dir_existing/test01.txt", "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileA test file: dst_dir_existing/test01.txt\n"); + fclose(tempFile); + } + else + { + Trace("ERROR: couldn't create dst_dir_existing/test01.txt\n"); + return FAIL; + } + tempFile = fopen("dst_dir_existing/test02.txt", "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileA test file: dst_dir_existing/test02.txt\n"); + fclose(tempFile); + } + else + { + Trace("ERROR[%ul]: couldn't create dst_dir_existing/test02.txt\n", GetLastError()); + return FAIL; + } + + return PASS; +} + + + +void removeDirectoryHelper(LPSTR dir, int location) +{ + DWORD dwAtt = GetFileAttributesA(dir); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + if(!RemoveDirectoryA(dir)) + { + Fail("ERROR: Failed to remove Directory [%s], Error Code [%d], location [%d]\n", dir, GetLastError(), location); + } + } +} + +void removeFileHelper(LPSTR pfile, int location) +{ + FILE *fp; + fp = fopen( pfile, "r"); + + if (fp != NULL) + { + if(fclose(fp)) + { + Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + + if(!DeleteFileA(pfile)) + { + Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + else + { + // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); + } + } + +} + + +/* remove all created files in preparation for the next test */ +void removeAll(void) +{ + char szTemp[40]; + DWORD dwAtt; + + /* get rid of source dirs and files */ + removeFileHelper(lpSource[0], 1); + removeFileHelper(lpSource[1], 2); + + dwAtt = GetFileAttributesA(lpSource[2]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpSource[2]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpSource[2]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpSource[2], 103); + } + else + { + removeFileHelper(lpSource[2], 17); + } + + + dwAtt = GetFileAttributesA(lpSource[3]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpSource[3]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpSource[3]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpSource[3], 103); + } + else + { + removeFileHelper(lpSource[3], 17); + } + + /* get rid of destination dirs and files */ + dwAtt = GetFileAttributesA(lpDestination[0]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpDestination[0]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpDestination[0]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpDestination[0], 103); + } + else + { + removeFileHelper(lpDestination[0], 17); + } + + dwAtt = GetFileAttributesA(lpDestination[1]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpDestination[1]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpDestination[1]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpDestination[1], 103); + } + else + { + removeFileHelper(lpDestination[1], 17); + } + + dwAtt = GetFileAttributesA(lpDestination[2]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpDestination[2]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpDestination[2]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpDestination[2], 103); + } + else + { + removeFileHelper(lpDestination[2], 17); + } + + dwAtt = GetFileAttributesA(lpDestination[3]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpDestination[3]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpDestination[3]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpDestination[3], 103); + } + else + { + removeFileHelper(lpDestination[3], 17); + } + +} + + + + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bRc = TRUE; + BOOL bSuccess = TRUE; + char results[40]; + FILE* resultsFile = NULL; + int nCounter = 0; + int i, j; + char tempSource[] = {'t','e','m','p','k','.','t','m','p','\0'}; + char tempDest[] = {'t','e','m','p','2','.','t','m','p','\0'}; + HANDLE hFile; + DWORD result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* read in the expected results to compare with actual results */ + memset (results, 0, 20); + resultsFile = fopen("expectedresults.txt", "r"); + if (resultsFile == NULL) + { + Fail("MoveFileA ERROR[%ul]: Unable to open \"expectedresults.txt\"\n", GetLastError()); + } + + fgets(results, 20, resultsFile); + fclose(resultsFile); + + /* clean the slate */ + removeAll(); + + if (createExisting() != 0) + { + removeAll(); + } + + + /* lpSource loop */ + for (i = 0; i < 4; i++) + { + /* lpDestination loop */ + for (j = 0; j < 4; j++) + { + bRc = MoveFileA(lpSource[i], lpDestination[j]); + if (!( + ((bRc == TRUE) && (results[nCounter] == '1')) + || + ((bRc == FALSE ) && (results[nCounter] == '0')) ) + ) + { + Trace("MoveFileA: FAILED: test[%d][%d]: \"%s\" -> \"%s\"\n", + i, j, lpSource[i], lpDestination[j]); + bSuccess = FALSE; + } + + /* undo the last move */ + removeAll(); + createExisting(); + + nCounter++; + } + } + + removeAll(); + if (bSuccess == FALSE) + { + Fail("MoveFileA: Test Failed"); + } + + /* create the temp source file */ + hFile = CreateFileA(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + + if( hFile == INVALID_HANDLE_VALUE ) + { + Fail("Error[%ul]:MoveFileA: CreateFile failed to " + "create the file correctly.\n", GetLastError()); + } + + bRc = CloseHandle(hFile); + if(!bRc) + { + Trace("MoveFileA: CloseHandle failed to close the " + "handle correctly. ERROR:%u\n",GetLastError()); + + /* delete the created file */ + bRc = DeleteFileA(tempSource); + if(!bRc) + { + Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" + "file correctly.\n", GetLastError()); + } + Fail(""); + } + + /* set the file attributes to be readonly */ + bRc = SetFileAttributesA(tempSource, FILE_ATTRIBUTE_READONLY); + if(!bRc) + { + Trace("MoveFileA: SetFileAttributes failed to set file " + "attributes correctly. GetLastError returned %u\n",GetLastError()); + /* delete the created file */ + bRc = DeleteFileA(tempSource); + if(!bRc) + { + Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" + "file correctly.\n", GetLastError()); + } + Fail(""); + } + + /* move the file to the new location */ + bRc = MoveFileA(tempSource, tempDest); + if(!bRc) + { + /* delete the created file */ + bRc = DeleteFileA(tempSource); + if(!bRc) + { + Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" + "file correctly.\n", GetLastError()); + } + + Fail("Error[%ul]:MoveFileA(%S, %S): GetFileAttributes " + "failed to get the file's attributes.\n", + GetLastError(), tempSource, tempDest); + } + + /* check that the newly moved file has the same file attributes + as the original */ + result = GetFileAttributesA(tempDest); + if(result == 0) + { + /* delete the created file */ + bRc = DeleteFileA(tempDest); + if(!bRc) + { + Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" + "file correctly.\n", GetLastError()); + } + + Fail("Error[%ul]:MoveFileA: GetFileAttributes failed to get " + "the file's attributes.\n", GetLastError()); + } + + if((result & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) + { + /* delete the newly moved file */ + bRc = DeleteFileA(tempDest); + if(!bRc) + { + Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" + "file correctly.\n", GetLastError()); + } + + Fail("Error[%ul]MoveFileA: GetFileAttributes failed to get " + "the correct file attributes.\n", GetLastError()); + } + + /* set the file attributes back to normal, to be deleted */ + bRc = SetFileAttributesA(tempDest, FILE_ATTRIBUTE_NORMAL); + if(!bRc) + { + /* delete the newly moved file */ + bRc = DeleteFileA(tempDest); + if(!bRc) + { + Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" + "file correctly.\n", GetLastError()); + } + + Fail("Error[%ul]:MoveFileA: SetFileAttributes failed to set " + "file attributes correctly.\n", GetLastError()); + } + + /* delete the newly moved file */ + bRc = DeleteFileA(tempDest); + if(!bRc) + { + Fail("Error[%ul]:MoveFileA: DeleteFileA failed to delete the" + "file correctly.\n", GetLastError()); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/MoveFileExA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/MoveFileExA/test1/CMakeLists.txt index f41dd7fd08..ef2471738c 100644 --- a/src/pal/tests/palsuite/file_io/MoveFileExA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/MoveFileExA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - MoveFileExA.c + MoveFileExA.cpp ) add_executable(paltest_movefileexa_test1 diff --git a/src/pal/tests/palsuite/file_io/MoveFileExA/test1/MoveFileExA.c b/src/pal/tests/palsuite/file_io/MoveFileExA/test1/MoveFileExA.c deleted file mode 100644 index 0bce2b08d1..0000000000 --- a/src/pal/tests/palsuite/file_io/MoveFileExA/test1/MoveFileExA.c +++ /dev/null @@ -1,360 +0,0 @@ -// 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: MoveFileExA.c -** -** Purpose: Tests the PAL implementation of the MoveFileExA function. -** -** -**===================================================================*/ - -#include - - -LPSTR lpSource[4] = { - "src_existing.tmp", - "src_non-existant.tmp", - "src_dir_existing", - "src_dir_non-existant" - }; -LPSTR lpDestination[4]={ - "dst_existing.tmp", - "dst_non-existant.tmp", - "dst_dir_existing", - "dst_dir_non-existant" - }; - -LPSTR lpFiles[14] ={ - "src_dir_existing\\test01.tmp", - "src_dir_existing\\test02.tmp", - "dst_dir_existing\\test01.tmp", - "dst_dir_existing\\test02.tmp", - "src_dir_non-existant\\test01.tmp", - "src_dir_non-existant\\test02.tmp", - "dst_existing.tmp\\test01.tmp", - "dst_existing.tmp\\test02.tmp", - "dst_non-existant.tmp\\test01.tmp", - "dst_non-existant.tmp\\test02.tmp", - "dst_dir_existing\\test01.tmp", - "dst_dir_existing\\test02.tmp", - "dst_dir_non-existant\\test01.tmp", - "dst_dir_non-existant\\test02.tmp" - }; - -DWORD dwFlag[2] = {MOVEFILE_COPY_ALLOWED, MOVEFILE_REPLACE_EXISTING}; - - - - -int createExisting(void) -{ - HANDLE tempFile = NULL; - HANDLE tempFile2 = NULL; - - /* create the src_existing file and dst_existing file */ - tempFile = CreateFileA(lpSource[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - tempFile2 = CreateFileA(lpDestination[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - CloseHandle(tempFile2); - CloseHandle(tempFile); - - if ((tempFile == NULL) || (tempFile2 == NULL)) - { - Trace("ERROR[%ul]: couldn't create %S or %S\n", GetLastError(), lpSource[0], - lpDestination[0]); - return FAIL; - } - - /* create the src_dir_existing and dst_dir_existing directory and files */ - CreateDirectoryA(lpSource[2], NULL); - - tempFile = CreateFileA(lpFiles[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - tempFile2 = CreateFileA(lpFiles[1], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - CloseHandle(tempFile2); - CloseHandle(tempFile); - - if ((tempFile == NULL) || (tempFile2 == NULL)) - { - Trace("ERROR[%ul]: couldn't create src_dir_existing\\test01.tmp\n", GetLastError()); - return FAIL; - } - - CreateDirectoryA(lpDestination[2], NULL); - tempFile = CreateFileA(lpFiles[2], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - tempFile2 = CreateFileA(lpFiles[3], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - CloseHandle(tempFile2); - CloseHandle(tempFile); - - if ((tempFile == NULL) || (tempFile2 == NULL)) - { - Trace("ERROR[%ul]: couldn't create dst_dir_existing\\test01.tmp\n" , GetLastError()); - return FAIL; - } - return PASS; - -} - -void removeDirectoryHelper(LPSTR dir, int location) -{ - DWORD dwAtt = GetFileAttributesA(dir); - - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - if(!RemoveDirectoryA(dir)) - { - Fail("ERROR: Failed to remove Directory [%s], Error Code [%d], location [%d]\n", dir, GetLastError(), location); - } - } -} - -void removeFileHelper(LPSTR pfile, int location) -{ - FILE *fp; - fp = fopen( pfile, "r"); - - if (fp != NULL) - { - if(fclose(fp)) - { - Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - - if(!DeleteFileA(pfile)) - { - Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - } - -} - -void removeAll(void) -{ - DWORD dwAtt; - /* get rid of destination dirs and files */ - removeFileHelper(lpSource[0], 11); - removeFileHelper(lpSource[1], 12); - removeFileHelper(lpFiles[0], 13); - removeFileHelper(lpFiles[1], 14); - - removeDirectoryHelper(lpSource[2], 101); - removeFileHelper(lpFiles[4], 15); - removeFileHelper(lpFiles[5], 16); - removeDirectoryHelper(lpSource[3], 102); - - /* get rid of destination dirs and files */ - dwAtt = GetFileAttributesA(lpDestination[0]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - removeFileHelper(lpFiles[6], 18); - removeFileHelper(lpFiles[7], 19); - removeDirectoryHelper(lpDestination[0], 103); - } - else - { - removeFileHelper(lpDestination[0], 17); - } - - dwAtt = GetFileAttributesA(lpDestination[1]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - removeFileHelper(lpFiles[8], 21); - removeFileHelper(lpFiles[9], 22); - removeDirectoryHelper(lpDestination[1], 104); - } - else - { - removeFileHelper(lpDestination[1], 19); - } - - dwAtt = GetFileAttributesA(lpDestination[2]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - removeFileHelper(lpFiles[10], 24); - removeFileHelper(lpFiles[11], 25); - removeDirectoryHelper(lpDestination[2], 105); - } - else - { - removeFileHelper(lpDestination[2], 23); - } - - dwAtt = GetFileAttributesA(lpDestination[3]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - removeFileHelper(lpFiles[12], 26); - removeFileHelper(lpFiles[13], 27); - removeDirectoryHelper(lpDestination[3], 106); - } - else - { - removeFileHelper(lpDestination[3], 107); - } - -} - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bRc = TRUE; - char results[40]; - FILE* resultsFile = NULL; - int i, j, k, nCounter = 0; - int res = FAIL; - char tempSource[] = {'t','e','m','p','k','.','t','m','p','\0'}; - char tempDest[] = {'t','e','m','p','2','.','t','m','p','\0'}; - HANDLE hFile; - DWORD result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* read in the expected results to compare with actual results */ - memset (results, 0, 34); - resultsFile = fopen("expectedresults.txt", "r"); - if (resultsFile == NULL) - { - Trace("MoveFileExA ERROR: Unable to open \"expectedresults.txt\"\n"); - goto EXIT; - } - - fgets(results, 34, resultsFile); - fclose(resultsFile); - - nCounter = 0; - - - /* clean the slate */ - removeAll(); - if (createExisting() != PASS) - { - goto EXIT; - } - - /* lpSource loop */ - for (i = 0; i < 4; i++) - { - /* lpDestination loop */ - for (j = 0; j < 4; j++) - { - /* dwFlag loop */ - for (k = 0; k < 2; k++) - { - - /* move the file to the new location */ - bRc = MoveFileExA(lpSource[i], lpDestination[j], dwFlag[k]); - - if (!( - ((bRc == TRUE) && (results[nCounter] == '1')) - || - ((bRc == FALSE ) && (results[nCounter] == '0')) ) - ) - { - Trace("MoveFileExA(%s, %s, %s): Values of i[%d], j[%d], k [%d] and results[%d]=%c LastError[%d]Flag[%d]FAILED\n", - lpSource[i], lpDestination[j], - k == 1 ? - "MOVEFILE_REPLACE_EXISTING":"MOVEFILE_COPY_ALLOWED", i, j, k, nCounter, results[nCounter], GetLastError(), bRc); - goto EXIT; - } - - /* undo the last move */ - removeAll(); - if (createExisting() != PASS) - { - goto EXIT; - } - nCounter++; - } - } - } - - /* create the temp source file */ - hFile = CreateFileA(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - - if( hFile == INVALID_HANDLE_VALUE ) - { - Trace("MoveFileExA: CreateFile failed to " - "create the file correctly.\n"); - goto EXIT; - } - - bRc = CloseHandle(hFile); - if(!bRc) - { - Trace("MoveFileExA: CloseHandle failed to close the " - "handle correctly. yo %u\n",GetLastError()); - goto EXIT; - } - - /* set the file attributes to be readonly */ - bRc = SetFileAttributesA(tempSource, FILE_ATTRIBUTE_READONLY); - if(!bRc) - { - Trace("MoveFileExA: SetFileAttributes failed to set file " - "attributes correctly. ERROR:%u\n",GetLastError()); - goto EXIT; - } - - /* move the file to the new location */ - bRc = MoveFileExA(tempSource, tempDest, MOVEFILE_COPY_ALLOWED ); - if(!bRc) - { - Trace("MoveFileExA(%S, %S, %s): GetFileAttributes " - "failed to get the file's attributes.\n", - tempSource, tempDest, "MOVEFILE_COPY_ALLOWED"); - goto EXIT; - } - - /* check that the newly moved file has the same file attributes - as the original */ - result = GetFileAttributesA(tempDest); - if(result == 0) - { - Trace("MoveFileExA: GetFileAttributes failed to get " - "the file's attributes.\n"); - goto EXIT; - } - - if((result & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) - { - Trace("MoveFileExA: GetFileAttributes failed to get " - "the correct file attributes.\n"); - goto EXIT; - } - - /* set the file attributes back to normal, to be deleted */ - bRc = SetFileAttributesA(tempDest, FILE_ATTRIBUTE_NORMAL); - if(!bRc) - { - Trace("MoveFileExA: SetFileAttributes " - "failed to set file attributes correctly.\n"); - goto EXIT; - } - - /* delete the newly moved file */ - bRc = DeleteFileA(tempDest); - if(!bRc) - { - Trace("MoveFileExA: DeleteFileA failed to delete the" - "file correctly.\n"); - goto EXIT; - } - - res = PASS; - -EXIT: - removeAll(); - - PAL_TerminateEx(res); - return res; -} - diff --git a/src/pal/tests/palsuite/file_io/MoveFileExA/test1/MoveFileExA.cpp b/src/pal/tests/palsuite/file_io/MoveFileExA/test1/MoveFileExA.cpp new file mode 100644 index 0000000000..0bce2b08d1 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/MoveFileExA/test1/MoveFileExA.cpp @@ -0,0 +1,360 @@ +// 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: MoveFileExA.c +** +** Purpose: Tests the PAL implementation of the MoveFileExA function. +** +** +**===================================================================*/ + +#include + + +LPSTR lpSource[4] = { + "src_existing.tmp", + "src_non-existant.tmp", + "src_dir_existing", + "src_dir_non-existant" + }; +LPSTR lpDestination[4]={ + "dst_existing.tmp", + "dst_non-existant.tmp", + "dst_dir_existing", + "dst_dir_non-existant" + }; + +LPSTR lpFiles[14] ={ + "src_dir_existing\\test01.tmp", + "src_dir_existing\\test02.tmp", + "dst_dir_existing\\test01.tmp", + "dst_dir_existing\\test02.tmp", + "src_dir_non-existant\\test01.tmp", + "src_dir_non-existant\\test02.tmp", + "dst_existing.tmp\\test01.tmp", + "dst_existing.tmp\\test02.tmp", + "dst_non-existant.tmp\\test01.tmp", + "dst_non-existant.tmp\\test02.tmp", + "dst_dir_existing\\test01.tmp", + "dst_dir_existing\\test02.tmp", + "dst_dir_non-existant\\test01.tmp", + "dst_dir_non-existant\\test02.tmp" + }; + +DWORD dwFlag[2] = {MOVEFILE_COPY_ALLOWED, MOVEFILE_REPLACE_EXISTING}; + + + + +int createExisting(void) +{ + HANDLE tempFile = NULL; + HANDLE tempFile2 = NULL; + + /* create the src_existing file and dst_existing file */ + tempFile = CreateFileA(lpSource[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + tempFile2 = CreateFileA(lpDestination[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + CloseHandle(tempFile2); + CloseHandle(tempFile); + + if ((tempFile == NULL) || (tempFile2 == NULL)) + { + Trace("ERROR[%ul]: couldn't create %S or %S\n", GetLastError(), lpSource[0], + lpDestination[0]); + return FAIL; + } + + /* create the src_dir_existing and dst_dir_existing directory and files */ + CreateDirectoryA(lpSource[2], NULL); + + tempFile = CreateFileA(lpFiles[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + tempFile2 = CreateFileA(lpFiles[1], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + CloseHandle(tempFile2); + CloseHandle(tempFile); + + if ((tempFile == NULL) || (tempFile2 == NULL)) + { + Trace("ERROR[%ul]: couldn't create src_dir_existing\\test01.tmp\n", GetLastError()); + return FAIL; + } + + CreateDirectoryA(lpDestination[2], NULL); + tempFile = CreateFileA(lpFiles[2], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + tempFile2 = CreateFileA(lpFiles[3], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + CloseHandle(tempFile2); + CloseHandle(tempFile); + + if ((tempFile == NULL) || (tempFile2 == NULL)) + { + Trace("ERROR[%ul]: couldn't create dst_dir_existing\\test01.tmp\n" , GetLastError()); + return FAIL; + } + return PASS; + +} + +void removeDirectoryHelper(LPSTR dir, int location) +{ + DWORD dwAtt = GetFileAttributesA(dir); + + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + if(!RemoveDirectoryA(dir)) + { + Fail("ERROR: Failed to remove Directory [%s], Error Code [%d], location [%d]\n", dir, GetLastError(), location); + } + } +} + +void removeFileHelper(LPSTR pfile, int location) +{ + FILE *fp; + fp = fopen( pfile, "r"); + + if (fp != NULL) + { + if(fclose(fp)) + { + Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + + if(!DeleteFileA(pfile)) + { + Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + } + +} + +void removeAll(void) +{ + DWORD dwAtt; + /* get rid of destination dirs and files */ + removeFileHelper(lpSource[0], 11); + removeFileHelper(lpSource[1], 12); + removeFileHelper(lpFiles[0], 13); + removeFileHelper(lpFiles[1], 14); + + removeDirectoryHelper(lpSource[2], 101); + removeFileHelper(lpFiles[4], 15); + removeFileHelper(lpFiles[5], 16); + removeDirectoryHelper(lpSource[3], 102); + + /* get rid of destination dirs and files */ + dwAtt = GetFileAttributesA(lpDestination[0]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + removeFileHelper(lpFiles[6], 18); + removeFileHelper(lpFiles[7], 19); + removeDirectoryHelper(lpDestination[0], 103); + } + else + { + removeFileHelper(lpDestination[0], 17); + } + + dwAtt = GetFileAttributesA(lpDestination[1]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + removeFileHelper(lpFiles[8], 21); + removeFileHelper(lpFiles[9], 22); + removeDirectoryHelper(lpDestination[1], 104); + } + else + { + removeFileHelper(lpDestination[1], 19); + } + + dwAtt = GetFileAttributesA(lpDestination[2]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + removeFileHelper(lpFiles[10], 24); + removeFileHelper(lpFiles[11], 25); + removeDirectoryHelper(lpDestination[2], 105); + } + else + { + removeFileHelper(lpDestination[2], 23); + } + + dwAtt = GetFileAttributesA(lpDestination[3]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + removeFileHelper(lpFiles[12], 26); + removeFileHelper(lpFiles[13], 27); + removeDirectoryHelper(lpDestination[3], 106); + } + else + { + removeFileHelper(lpDestination[3], 107); + } + +} + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bRc = TRUE; + char results[40]; + FILE* resultsFile = NULL; + int i, j, k, nCounter = 0; + int res = FAIL; + char tempSource[] = {'t','e','m','p','k','.','t','m','p','\0'}; + char tempDest[] = {'t','e','m','p','2','.','t','m','p','\0'}; + HANDLE hFile; + DWORD result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* read in the expected results to compare with actual results */ + memset (results, 0, 34); + resultsFile = fopen("expectedresults.txt", "r"); + if (resultsFile == NULL) + { + Trace("MoveFileExA ERROR: Unable to open \"expectedresults.txt\"\n"); + goto EXIT; + } + + fgets(results, 34, resultsFile); + fclose(resultsFile); + + nCounter = 0; + + + /* clean the slate */ + removeAll(); + if (createExisting() != PASS) + { + goto EXIT; + } + + /* lpSource loop */ + for (i = 0; i < 4; i++) + { + /* lpDestination loop */ + for (j = 0; j < 4; j++) + { + /* dwFlag loop */ + for (k = 0; k < 2; k++) + { + + /* move the file to the new location */ + bRc = MoveFileExA(lpSource[i], lpDestination[j], dwFlag[k]); + + if (!( + ((bRc == TRUE) && (results[nCounter] == '1')) + || + ((bRc == FALSE ) && (results[nCounter] == '0')) ) + ) + { + Trace("MoveFileExA(%s, %s, %s): Values of i[%d], j[%d], k [%d] and results[%d]=%c LastError[%d]Flag[%d]FAILED\n", + lpSource[i], lpDestination[j], + k == 1 ? + "MOVEFILE_REPLACE_EXISTING":"MOVEFILE_COPY_ALLOWED", i, j, k, nCounter, results[nCounter], GetLastError(), bRc); + goto EXIT; + } + + /* undo the last move */ + removeAll(); + if (createExisting() != PASS) + { + goto EXIT; + } + nCounter++; + } + } + } + + /* create the temp source file */ + hFile = CreateFileA(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + + if( hFile == INVALID_HANDLE_VALUE ) + { + Trace("MoveFileExA: CreateFile failed to " + "create the file correctly.\n"); + goto EXIT; + } + + bRc = CloseHandle(hFile); + if(!bRc) + { + Trace("MoveFileExA: CloseHandle failed to close the " + "handle correctly. yo %u\n",GetLastError()); + goto EXIT; + } + + /* set the file attributes to be readonly */ + bRc = SetFileAttributesA(tempSource, FILE_ATTRIBUTE_READONLY); + if(!bRc) + { + Trace("MoveFileExA: SetFileAttributes failed to set file " + "attributes correctly. ERROR:%u\n",GetLastError()); + goto EXIT; + } + + /* move the file to the new location */ + bRc = MoveFileExA(tempSource, tempDest, MOVEFILE_COPY_ALLOWED ); + if(!bRc) + { + Trace("MoveFileExA(%S, %S, %s): GetFileAttributes " + "failed to get the file's attributes.\n", + tempSource, tempDest, "MOVEFILE_COPY_ALLOWED"); + goto EXIT; + } + + /* check that the newly moved file has the same file attributes + as the original */ + result = GetFileAttributesA(tempDest); + if(result == 0) + { + Trace("MoveFileExA: GetFileAttributes failed to get " + "the file's attributes.\n"); + goto EXIT; + } + + if((result & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) + { + Trace("MoveFileExA: GetFileAttributes failed to get " + "the correct file attributes.\n"); + goto EXIT; + } + + /* set the file attributes back to normal, to be deleted */ + bRc = SetFileAttributesA(tempDest, FILE_ATTRIBUTE_NORMAL); + if(!bRc) + { + Trace("MoveFileExA: SetFileAttributes " + "failed to set file attributes correctly.\n"); + goto EXIT; + } + + /* delete the newly moved file */ + bRc = DeleteFileA(tempDest); + if(!bRc) + { + Trace("MoveFileExA: DeleteFileA failed to delete the" + "file correctly.\n"); + goto EXIT; + } + + res = PASS; + +EXIT: + removeAll(); + + PAL_TerminateEx(res); + return res; +} + diff --git a/src/pal/tests/palsuite/file_io/MoveFileExW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/MoveFileExW/test1/CMakeLists.txt index 4c6a70f050..ca6b35e3ac 100644 --- a/src/pal/tests/palsuite/file_io/MoveFileExW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/MoveFileExW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - MoveFileExW.c + MoveFileExW.cpp ) add_executable(paltest_movefileexw_test1 diff --git a/src/pal/tests/palsuite/file_io/MoveFileExW/test1/MoveFileExW.c b/src/pal/tests/palsuite/file_io/MoveFileExW/test1/MoveFileExW.c deleted file mode 100644 index 4f5b72dcf7..0000000000 --- a/src/pal/tests/palsuite/file_io/MoveFileExW/test1/MoveFileExW.c +++ /dev/null @@ -1,431 +0,0 @@ -// 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: MoveFileExW.c -** -** Purpose: Tests the PAL implementation of the MoveFileExW function. -** -** -**===================================================================*/ - -#include - - -LPWSTR lpSource[4]; -LPWSTR lpDestination[4]; -LPWSTR lpFiles[14]; - -DWORD dwFlag[2] = {MOVEFILE_COPY_ALLOWED, MOVEFILE_REPLACE_EXISTING}; - - - -int createExisting(void) -{ - HANDLE tempFile = NULL; - HANDLE tempFile2 = NULL; - - /* create the src_existing file and dst_existing file */ - tempFile = CreateFileW(lpSource[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - tempFile2 = CreateFileW(lpDestination[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - CloseHandle(tempFile2); - CloseHandle(tempFile); - - if ((tempFile == NULL) || (tempFile2 == NULL)) - { - Trace("ERROR: couldn't create %S or %S\n", lpSource[0], - lpDestination[0]); - return FAIL; - } - - /* create the src_dir_existing and dst_dir_existing directory and files */ - CreateDirectoryW(lpSource[2], NULL); - - tempFile = CreateFileW(lpFiles[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - tempFile2 = CreateFileW(lpFiles[1], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - CloseHandle(tempFile2); - CloseHandle(tempFile); - - if ((tempFile == NULL) || (tempFile2 == NULL)) - { - Trace("ERROR: couldn't create src_dir_existing\\test01.tmp\n"); - return FAIL; - } - - CreateDirectoryW(lpDestination[2], NULL); - tempFile = CreateFileW(lpFiles[2], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - tempFile2 = CreateFileW(lpFiles[3], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - CloseHandle(tempFile2); - CloseHandle(tempFile); - - if ((tempFile == NULL) || (tempFile2 == NULL)) - { - Trace("ERROR: couldn't create dst_dir_existing\\test01.tmp\n"); - return FAIL; - } - return PASS; -} - -void removeDirectoryHelper(LPWSTR dir, int location) -{ - DWORD dwAtt = GetFileAttributesW(dir); -// Trace(" Value of location[%d], and directorye [%S]\n", location, dir); - - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - if(!RemoveDirectoryW(dir)) - { - Fail("ERROR: Failed to remove Directory [%S], Error Code [%d], location [%d]\n", dir, GetLastError(), location); - } - } -} - -void removeFileHelper(LPWSTR wfile, int location) -{ - FILE *fp; - char * pfile = convertC(wfile); - -// Trace(" Value of location[%d], and file [%s]\n", location, pfile); - fp = fopen( pfile, "r"); - - if (fp != NULL) - { - if(fclose(fp)) - { - Fail("ERROR: Failed to close the file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); - } - - if(!DeleteFileW(wfile)) - { - Fail("ERROR: Failed to delete file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); - } - else - { - // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); - } - } - - free(pfile); -} - -void removeAll(void) -{ - DWORD dwAtt; - /* get rid of destination dirs and files */ - removeFileHelper(lpSource[0], 11); -// lpSource[0] = convert("src_existing.tmp"); - - removeFileHelper(lpSource[1], 12); - //lpSource[1] = convert("src_non-existant.tmp"); - - removeFileHelper(lpFiles[0], 13); -// lpFiles[0] = convert("src_dir_existing\\test01.tmp"); - - removeFileHelper(lpFiles[1], 14); -// lpFiles[1] = convert("src_dir_existing\\test02.tmp"); - - removeDirectoryHelper(lpSource[2], 101); -// lpSource[2] = convert("src_dir_existing"); - - removeFileHelper(lpFiles[4], 15); -// lpFiles[4] = convert("src_dir_non-existant\\test01.tmp"); - - removeFileHelper(lpFiles[5], 16); -// lpFiles[5] = convert("src_dir_non-existant\\test02.tmp"); - - removeDirectoryHelper(lpSource[3], 102); -// lpSource[3] = convert("src_dir_non-existant"); - - /* get rid of destination dirs and files */ - dwAtt = GetFileAttributesW(lpDestination[0]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - removeFileHelper(lpFiles[6], 18); - // lpFiles[6] = convert("dst_existing.tmp\\test01.tmp"); - removeFileHelper(lpFiles[7], 19); - // lpFiles[7] = convert("dst_existing.tmp\\test02.tmp"); - removeDirectoryHelper(lpDestination[0], 103); - // lpDestination[0] = convert("dst_existing.tmp"); - - } - else - { - removeFileHelper(lpDestination[0], 17); - // lpDestination[0] = convert("dst_existing.tmp"); - } - - dwAtt = GetFileAttributesW(lpDestination[1]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - removeFileHelper(lpFiles[8], 21); - // lpFiles[8] = convert("dst_non-existant.tmp\\test01.tmp"); - removeFileHelper(lpFiles[9], 22); - // lpFiles[9] = convert("dst_non-existant.tmp\\test02.tmp"); - removeDirectoryHelper(lpDestination[1], 104); - // lpDestination[1] = convert("dst_non-existant.tmp"); - - } - else - { - removeFileHelper(lpDestination[1], 19); - //lpDestination[1] = convert("dst_non-existant.tmp"); - } - - dwAtt = GetFileAttributesW(lpDestination[2]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - removeFileHelper(lpFiles[10], 24); - // lpFiles[10] = convert("dst_dir_existing\\test01.tmp"); - removeFileHelper(lpFiles[11], 25); - // lpFiles[11] = convert("dst_dir_existing\\test02.tmp"); - removeDirectoryHelper(lpDestination[2], 105); - // lpDestination[2] = convert("dst_dir_existing"); - - } - else - { - removeFileHelper(lpDestination[2], 23); - // lpDestination[2] = convert("dst_dir_existing"); - - } - - dwAtt = GetFileAttributesW(lpDestination[3]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - removeFileHelper(lpFiles[12], 26); - // lpFiles[12] = convert("dst_dir_non-existant\\test01.tmp"); - removeFileHelper(lpFiles[13], 27); - // lpFiles[13] = convert("dst_dir_non-existant\\test02.tmp"); - removeDirectoryHelper(lpDestination[3], 106); - // lpDestination[3] = convert("dst_dir_non-existant"); - - } - else - { - removeFileHelper(lpDestination[3], 107); - // lpDestination[3] = convert("dst_dir_non-existant"); - - } - -} - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bRc = TRUE; - char results[40]; - FILE* resultsFile = NULL; - int i, j, k, nCounter = 0; - int res = FAIL; - WCHAR tempSource[] = {'t','e','m','p','k','.','t','m','p','\0'}; - WCHAR tempDest[] = {'t','e','m','p','2','.','t','m','p','\0'}; - HANDLE hFile; - DWORD result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - lpSource[0] = convert("src_existing.tmp"); - lpSource[1] = convert("src_non-existant.tmp"); - lpSource[2] = convert("src_dir_existing"); - lpSource[3] = convert("src_dir_non-existant"); - - lpDestination[0] = convert("dst_existing.tmp"); - lpDestination[1] = convert("dst_non-existant.tmp"); - lpDestination[2] = convert("dst_dir_existing"); - lpDestination[3] = convert("dst_dir_non-existant"); - - lpFiles[0] = convert("src_dir_existing\\test01.tmp"); - lpFiles[1] = convert("src_dir_existing\\test02.tmp"); - lpFiles[2] = convert("dst_dir_existing\\test01.tmp"); - lpFiles[3] = convert("dst_dir_existing\\test02.tmp"); - lpFiles[4] = convert("src_dir_non-existant\\test01.tmp"); - lpFiles[5] = convert("src_dir_non-existant\\test02.tmp"); - - lpFiles[6] = convert("dst_existing.tmp\\test01.tmp"); - lpFiles[7] = convert("dst_existing.tmp\\test02.tmp"); - - lpFiles[8] = convert("dst_non-existant.tmp\\test01.tmp"); - lpFiles[9] = convert("dst_non-existant.tmp\\test02.tmp"); - - lpFiles[10] = convert("dst_dir_existing\\test01.tmp"); - lpFiles[11] = convert("dst_dir_existing\\test02.tmp"); - - lpFiles[12] = convert("dst_dir_non-existant\\test01.tmp"); - lpFiles[13] = convert("dst_dir_non-existant\\test02.tmp"); - - /* read in the expected results to compare with actual results */ - memset (results, 0, 34); - resultsFile = fopen("expectedresults.txt", "r"); - if (resultsFile == NULL) - { - Trace("MoveFileExW ERROR: Unable to open \"expectedresults.txt\"\n"); - goto EXIT; - } - - fgets(results, 34, resultsFile); - fclose(resultsFile); - -// Trace("Value of results[%]=%s\n", i, results); - for( i = 0; i < 32; i++) - { - Trace("Value of results[%d]=%c\n", i, results[i]); - } - nCounter = 0; - - - /* clean the slate */ - removeAll(); - if (createExisting() != PASS) - { - goto EXIT; - } - - /* lpSource loop */ - for (i = 0; i < 4; i++) - { - /* lpDestination loop */ - for (j = 0; j < 4; j++) - { - /* dwFlag loop */ - for (k = 0; k < 2; k++) - { - - //if(nCounter == 22) - //{ - //exit(1); - //} - /* move the file to the new location */ - bRc = MoveFileExW(lpSource[i], lpDestination[j], dwFlag[k]); - - if (!( - ((bRc == TRUE) && (results[nCounter] == '1')) - || - ((bRc == FALSE ) && (results[nCounter] == '0')) ) - ) - { - Trace("MoveFileExW(%S, %S, %s): Values of i[%d], j[%d], k [%d] and results[%d]=%c LastError[%d]Flag[%d]FAILED\n", - lpSource[i], lpDestination[j], - k == 1 ? - "MOVEFILE_REPLACE_EXISTING":"MOVEFILE_COPY_ALLOWED", i, j, k, nCounter, results[nCounter], GetLastError(), bRc); - goto EXIT; - } - - //Trace("MoveFileExW(%S, %S, %s): Values of i[%d], j[%d], k [%d] and results[%d]=%c \n", - // lpSource[i], lpDestination[j], - // k == 1 ? - // "MOVEFILE_REPLACE_EXISTING":"MOVEFILE_COPY_ALLOWED", i, j, k, nCounter, results[nCounter]); - - - /* undo the last move */ - removeAll(); - if (createExisting() != PASS) - { - goto EXIT; - } - //Trace("Counter [%d] over \n", nCounter); - nCounter++; - } - } - } - - /* create the temp source file */ - hFile = CreateFileW(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - - if( hFile == INVALID_HANDLE_VALUE ) - { - Trace("MoveFileExW: CreateFile failed to " - "create the file correctly.\n"); - goto EXIT; - } - - bRc = CloseHandle(hFile); - if(!bRc) - { - Trace("MoveFileExW: CloseHandle failed to close the " - "handle correctly. yo %u\n",GetLastError()); - goto EXIT; - } - - /* set the file attributes to be readonly */ - bRc = SetFileAttributesW(tempSource, FILE_ATTRIBUTE_READONLY); - if(!bRc) - { - Trace("MoveFileExW: SetFileAttributes failed to set file " - "attributes correctly. ERROR:%u\n",GetLastError()); - goto EXIT; - } - - /* move the file to the new location */ - bRc = MoveFileExW(tempSource, tempDest, MOVEFILE_COPY_ALLOWED ); - if(!bRc) - { - Trace("MoveFileExW(%S, %S, %s): GetFileAttributes " - "failed to get the file's attributes.\n", - tempSource, tempDest, "MOVEFILE_COPY_ALLOWED"); - goto EXIT; - } - - /* check that the newly moved file has the same file attributes - as the original */ - result = GetFileAttributesW(tempDest); - if(result == 0) - { - Trace("MoveFileExW: GetFileAttributes failed to get " - "the file's attributes.\n"); - goto EXIT; - } - - if((result & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) - { - Trace("MoveFileExW: GetFileAttributes failed to get " - "the correct file attributes.\n"); - goto EXIT; - } - - /* set the file attributes back to normal, to be deleted */ - bRc = SetFileAttributesW(tempDest, FILE_ATTRIBUTE_NORMAL); - if(!bRc) - { - Trace("MoveFileExW: SetFileAttributes " - "failed to set file attributes correctly.\n"); - goto EXIT; - } - - /* delete the newly moved file */ - bRc = DeleteFileW(tempDest); - if(!bRc) - { - Trace("MoveFileExW: DeleteFileW failed to delete the" - "file correctly.\n"); - goto EXIT; - } - - res = PASS; - -EXIT: - removeAll(); - for (i=0; i<4; i++) - { - free(lpSource[i]); - free(lpDestination[i]); - } - for (i=0; i<14; i++) - { - free(lpFiles[i]); - } - - PAL_TerminateEx(res); - return res; -} - diff --git a/src/pal/tests/palsuite/file_io/MoveFileExW/test1/MoveFileExW.cpp b/src/pal/tests/palsuite/file_io/MoveFileExW/test1/MoveFileExW.cpp new file mode 100644 index 0000000000..4f5b72dcf7 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/MoveFileExW/test1/MoveFileExW.cpp @@ -0,0 +1,431 @@ +// 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: MoveFileExW.c +** +** Purpose: Tests the PAL implementation of the MoveFileExW function. +** +** +**===================================================================*/ + +#include + + +LPWSTR lpSource[4]; +LPWSTR lpDestination[4]; +LPWSTR lpFiles[14]; + +DWORD dwFlag[2] = {MOVEFILE_COPY_ALLOWED, MOVEFILE_REPLACE_EXISTING}; + + + +int createExisting(void) +{ + HANDLE tempFile = NULL; + HANDLE tempFile2 = NULL; + + /* create the src_existing file and dst_existing file */ + tempFile = CreateFileW(lpSource[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + tempFile2 = CreateFileW(lpDestination[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + CloseHandle(tempFile2); + CloseHandle(tempFile); + + if ((tempFile == NULL) || (tempFile2 == NULL)) + { + Trace("ERROR: couldn't create %S or %S\n", lpSource[0], + lpDestination[0]); + return FAIL; + } + + /* create the src_dir_existing and dst_dir_existing directory and files */ + CreateDirectoryW(lpSource[2], NULL); + + tempFile = CreateFileW(lpFiles[0], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + tempFile2 = CreateFileW(lpFiles[1], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + CloseHandle(tempFile2); + CloseHandle(tempFile); + + if ((tempFile == NULL) || (tempFile2 == NULL)) + { + Trace("ERROR: couldn't create src_dir_existing\\test01.tmp\n"); + return FAIL; + } + + CreateDirectoryW(lpDestination[2], NULL); + tempFile = CreateFileW(lpFiles[2], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + tempFile2 = CreateFileW(lpFiles[3], GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + CloseHandle(tempFile2); + CloseHandle(tempFile); + + if ((tempFile == NULL) || (tempFile2 == NULL)) + { + Trace("ERROR: couldn't create dst_dir_existing\\test01.tmp\n"); + return FAIL; + } + return PASS; +} + +void removeDirectoryHelper(LPWSTR dir, int location) +{ + DWORD dwAtt = GetFileAttributesW(dir); +// Trace(" Value of location[%d], and directorye [%S]\n", location, dir); + + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + if(!RemoveDirectoryW(dir)) + { + Fail("ERROR: Failed to remove Directory [%S], Error Code [%d], location [%d]\n", dir, GetLastError(), location); + } + } +} + +void removeFileHelper(LPWSTR wfile, int location) +{ + FILE *fp; + char * pfile = convertC(wfile); + +// Trace(" Value of location[%d], and file [%s]\n", location, pfile); + fp = fopen( pfile, "r"); + + if (fp != NULL) + { + if(fclose(fp)) + { + Fail("ERROR: Failed to close the file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); + } + + if(!DeleteFileW(wfile)) + { + Fail("ERROR: Failed to delete file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); + } + else + { + // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); + } + } + + free(pfile); +} + +void removeAll(void) +{ + DWORD dwAtt; + /* get rid of destination dirs and files */ + removeFileHelper(lpSource[0], 11); +// lpSource[0] = convert("src_existing.tmp"); + + removeFileHelper(lpSource[1], 12); + //lpSource[1] = convert("src_non-existant.tmp"); + + removeFileHelper(lpFiles[0], 13); +// lpFiles[0] = convert("src_dir_existing\\test01.tmp"); + + removeFileHelper(lpFiles[1], 14); +// lpFiles[1] = convert("src_dir_existing\\test02.tmp"); + + removeDirectoryHelper(lpSource[2], 101); +// lpSource[2] = convert("src_dir_existing"); + + removeFileHelper(lpFiles[4], 15); +// lpFiles[4] = convert("src_dir_non-existant\\test01.tmp"); + + removeFileHelper(lpFiles[5], 16); +// lpFiles[5] = convert("src_dir_non-existant\\test02.tmp"); + + removeDirectoryHelper(lpSource[3], 102); +// lpSource[3] = convert("src_dir_non-existant"); + + /* get rid of destination dirs and files */ + dwAtt = GetFileAttributesW(lpDestination[0]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + removeFileHelper(lpFiles[6], 18); + // lpFiles[6] = convert("dst_existing.tmp\\test01.tmp"); + removeFileHelper(lpFiles[7], 19); + // lpFiles[7] = convert("dst_existing.tmp\\test02.tmp"); + removeDirectoryHelper(lpDestination[0], 103); + // lpDestination[0] = convert("dst_existing.tmp"); + + } + else + { + removeFileHelper(lpDestination[0], 17); + // lpDestination[0] = convert("dst_existing.tmp"); + } + + dwAtt = GetFileAttributesW(lpDestination[1]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + removeFileHelper(lpFiles[8], 21); + // lpFiles[8] = convert("dst_non-existant.tmp\\test01.tmp"); + removeFileHelper(lpFiles[9], 22); + // lpFiles[9] = convert("dst_non-existant.tmp\\test02.tmp"); + removeDirectoryHelper(lpDestination[1], 104); + // lpDestination[1] = convert("dst_non-existant.tmp"); + + } + else + { + removeFileHelper(lpDestination[1], 19); + //lpDestination[1] = convert("dst_non-existant.tmp"); + } + + dwAtt = GetFileAttributesW(lpDestination[2]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + removeFileHelper(lpFiles[10], 24); + // lpFiles[10] = convert("dst_dir_existing\\test01.tmp"); + removeFileHelper(lpFiles[11], 25); + // lpFiles[11] = convert("dst_dir_existing\\test02.tmp"); + removeDirectoryHelper(lpDestination[2], 105); + // lpDestination[2] = convert("dst_dir_existing"); + + } + else + { + removeFileHelper(lpDestination[2], 23); + // lpDestination[2] = convert("dst_dir_existing"); + + } + + dwAtt = GetFileAttributesW(lpDestination[3]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + removeFileHelper(lpFiles[12], 26); + // lpFiles[12] = convert("dst_dir_non-existant\\test01.tmp"); + removeFileHelper(lpFiles[13], 27); + // lpFiles[13] = convert("dst_dir_non-existant\\test02.tmp"); + removeDirectoryHelper(lpDestination[3], 106); + // lpDestination[3] = convert("dst_dir_non-existant"); + + } + else + { + removeFileHelper(lpDestination[3], 107); + // lpDestination[3] = convert("dst_dir_non-existant"); + + } + +} + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bRc = TRUE; + char results[40]; + FILE* resultsFile = NULL; + int i, j, k, nCounter = 0; + int res = FAIL; + WCHAR tempSource[] = {'t','e','m','p','k','.','t','m','p','\0'}; + WCHAR tempDest[] = {'t','e','m','p','2','.','t','m','p','\0'}; + HANDLE hFile; + DWORD result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + lpSource[0] = convert("src_existing.tmp"); + lpSource[1] = convert("src_non-existant.tmp"); + lpSource[2] = convert("src_dir_existing"); + lpSource[3] = convert("src_dir_non-existant"); + + lpDestination[0] = convert("dst_existing.tmp"); + lpDestination[1] = convert("dst_non-existant.tmp"); + lpDestination[2] = convert("dst_dir_existing"); + lpDestination[3] = convert("dst_dir_non-existant"); + + lpFiles[0] = convert("src_dir_existing\\test01.tmp"); + lpFiles[1] = convert("src_dir_existing\\test02.tmp"); + lpFiles[2] = convert("dst_dir_existing\\test01.tmp"); + lpFiles[3] = convert("dst_dir_existing\\test02.tmp"); + lpFiles[4] = convert("src_dir_non-existant\\test01.tmp"); + lpFiles[5] = convert("src_dir_non-existant\\test02.tmp"); + + lpFiles[6] = convert("dst_existing.tmp\\test01.tmp"); + lpFiles[7] = convert("dst_existing.tmp\\test02.tmp"); + + lpFiles[8] = convert("dst_non-existant.tmp\\test01.tmp"); + lpFiles[9] = convert("dst_non-existant.tmp\\test02.tmp"); + + lpFiles[10] = convert("dst_dir_existing\\test01.tmp"); + lpFiles[11] = convert("dst_dir_existing\\test02.tmp"); + + lpFiles[12] = convert("dst_dir_non-existant\\test01.tmp"); + lpFiles[13] = convert("dst_dir_non-existant\\test02.tmp"); + + /* read in the expected results to compare with actual results */ + memset (results, 0, 34); + resultsFile = fopen("expectedresults.txt", "r"); + if (resultsFile == NULL) + { + Trace("MoveFileExW ERROR: Unable to open \"expectedresults.txt\"\n"); + goto EXIT; + } + + fgets(results, 34, resultsFile); + fclose(resultsFile); + +// Trace("Value of results[%]=%s\n", i, results); + for( i = 0; i < 32; i++) + { + Trace("Value of results[%d]=%c\n", i, results[i]); + } + nCounter = 0; + + + /* clean the slate */ + removeAll(); + if (createExisting() != PASS) + { + goto EXIT; + } + + /* lpSource loop */ + for (i = 0; i < 4; i++) + { + /* lpDestination loop */ + for (j = 0; j < 4; j++) + { + /* dwFlag loop */ + for (k = 0; k < 2; k++) + { + + //if(nCounter == 22) + //{ + //exit(1); + //} + /* move the file to the new location */ + bRc = MoveFileExW(lpSource[i], lpDestination[j], dwFlag[k]); + + if (!( + ((bRc == TRUE) && (results[nCounter] == '1')) + || + ((bRc == FALSE ) && (results[nCounter] == '0')) ) + ) + { + Trace("MoveFileExW(%S, %S, %s): Values of i[%d], j[%d], k [%d] and results[%d]=%c LastError[%d]Flag[%d]FAILED\n", + lpSource[i], lpDestination[j], + k == 1 ? + "MOVEFILE_REPLACE_EXISTING":"MOVEFILE_COPY_ALLOWED", i, j, k, nCounter, results[nCounter], GetLastError(), bRc); + goto EXIT; + } + + //Trace("MoveFileExW(%S, %S, %s): Values of i[%d], j[%d], k [%d] and results[%d]=%c \n", + // lpSource[i], lpDestination[j], + // k == 1 ? + // "MOVEFILE_REPLACE_EXISTING":"MOVEFILE_COPY_ALLOWED", i, j, k, nCounter, results[nCounter]); + + + /* undo the last move */ + removeAll(); + if (createExisting() != PASS) + { + goto EXIT; + } + //Trace("Counter [%d] over \n", nCounter); + nCounter++; + } + } + } + + /* create the temp source file */ + hFile = CreateFileW(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + + if( hFile == INVALID_HANDLE_VALUE ) + { + Trace("MoveFileExW: CreateFile failed to " + "create the file correctly.\n"); + goto EXIT; + } + + bRc = CloseHandle(hFile); + if(!bRc) + { + Trace("MoveFileExW: CloseHandle failed to close the " + "handle correctly. yo %u\n",GetLastError()); + goto EXIT; + } + + /* set the file attributes to be readonly */ + bRc = SetFileAttributesW(tempSource, FILE_ATTRIBUTE_READONLY); + if(!bRc) + { + Trace("MoveFileExW: SetFileAttributes failed to set file " + "attributes correctly. ERROR:%u\n",GetLastError()); + goto EXIT; + } + + /* move the file to the new location */ + bRc = MoveFileExW(tempSource, tempDest, MOVEFILE_COPY_ALLOWED ); + if(!bRc) + { + Trace("MoveFileExW(%S, %S, %s): GetFileAttributes " + "failed to get the file's attributes.\n", + tempSource, tempDest, "MOVEFILE_COPY_ALLOWED"); + goto EXIT; + } + + /* check that the newly moved file has the same file attributes + as the original */ + result = GetFileAttributesW(tempDest); + if(result == 0) + { + Trace("MoveFileExW: GetFileAttributes failed to get " + "the file's attributes.\n"); + goto EXIT; + } + + if((result & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) + { + Trace("MoveFileExW: GetFileAttributes failed to get " + "the correct file attributes.\n"); + goto EXIT; + } + + /* set the file attributes back to normal, to be deleted */ + bRc = SetFileAttributesW(tempDest, FILE_ATTRIBUTE_NORMAL); + if(!bRc) + { + Trace("MoveFileExW: SetFileAttributes " + "failed to set file attributes correctly.\n"); + goto EXIT; + } + + /* delete the newly moved file */ + bRc = DeleteFileW(tempDest); + if(!bRc) + { + Trace("MoveFileExW: DeleteFileW failed to delete the" + "file correctly.\n"); + goto EXIT; + } + + res = PASS; + +EXIT: + removeAll(); + for (i=0; i<4; i++) + { + free(lpSource[i]); + free(lpDestination[i]); + } + for (i=0; i<14; i++) + { + free(lpFiles[i]); + } + + PAL_TerminateEx(res); + return res; +} + diff --git a/src/pal/tests/palsuite/file_io/MoveFileW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/MoveFileW/test1/CMakeLists.txt index 497f654122..4519746e7b 100644 --- a/src/pal/tests/palsuite/file_io/MoveFileW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/MoveFileW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - MoveFileW.c + MoveFileW.cpp ) add_executable(paltest_movefilew_test1 diff --git a/src/pal/tests/palsuite/file_io/MoveFileW/test1/MoveFileW.c b/src/pal/tests/palsuite/file_io/MoveFileW/test1/MoveFileW.c deleted file mode 100644 index 58999302d0..0000000000 --- a/src/pal/tests/palsuite/file_io/MoveFileW/test1/MoveFileW.c +++ /dev/null @@ -1,478 +0,0 @@ -// 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: MoveFileW.c -** -** Purpose: Tests the PAL implementation of the MoveFileW function. -** -** -**===================================================================*/ - -#include - -LPSTR lpSource[4] = {"src_existing.txt", - "src_non-existant.txt", - "src_dir_existing", - "src_dir_non-existant"}; -LPSTR lpDestination[4] = {"dst_existing.txt", - "dst_non-existant.txt", - "dst_dir_existing", - "dst_dir_non-existant"}; - - -/* Create all the required test files */ -int createExisting(void) -{ - FILE* tempFile = NULL; - DWORD dwError; - BOOL bRc = FALSE; - WCHAR* wPtr = NULL; - char szBuffer[100]; - - /* create the src_existing file */ - tempFile = fopen(lpSource[0], "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFile test file: src_existing.txt\n"); - fclose(tempFile); - } - else - { - Trace("ERROR: couldn't create %s\n", lpSource[0]); - return FAIL; - } - - /* create the src_dir_existing directory and files */ - wPtr = convert(lpSource[2]); - bRc = CreateDirectoryW(wPtr, NULL); - free(wPtr); - if (bRc != TRUE) - { - Trace("MoveFileW: ERROR: couldn't create \"%s\" because of " - "error code %ld\n", - lpSource[2], - GetLastError()); - return FAIL; - } - - memset(szBuffer, 0, 100); - sprintf(szBuffer, "%s/test01.txt", lpSource[2]); - tempFile = fopen(szBuffer, "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileW test file: %s\n", szBuffer); - fclose(tempFile); - } - else - { - Trace("ERROR: couldn't create %s\n", szBuffer); - return FAIL; - } - - memset(szBuffer, 0, 100); - sprintf(szBuffer, "%s/test02.txt", lpSource[2]); - tempFile = fopen(szBuffer, "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileW test file: %s\n", szBuffer); - fclose(tempFile); - } - else - { - Trace("ERROR: couldn't create %s\n", szBuffer); - return FAIL; - } - - - /* create the dst_existing file */ - tempFile = fopen(lpDestination[0], "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileW test file: dst_existing.txt\n"); - fclose(tempFile); - } - else - { - Trace("ERROR: couldn't create \"%s\"\n", lpDestination[0]); - return FAIL; - } - - /* create the dst_dir_existing directory and files */ - wPtr = convert(lpDestination[2]); - bRc = CreateDirectoryW(wPtr, NULL); - free(wPtr); - if (bRc != TRUE) - { - dwError = GetLastError(); - Trace("MoveFileW: ERROR: couldn't create \"%s\"\n", lpDestination[2]); - return FAIL; - } - - tempFile = fopen("dst_dir_existing/test01.txt", "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileW test file: dst_dir_existing/test01.txt\n"); - fclose(tempFile); - } - else - { - Trace("ERROR: couldn't create dst_dir_existing/test01.txt\n"); - return FAIL; - } - tempFile = fopen("dst_dir_existing/test02.txt", "w"); - if (tempFile != NULL) - { - fprintf(tempFile, "MoveFileW test file: dst_dir_existing/test02.txt\n"); - fclose(tempFile); - } - else - { - Trace("ERROR: couldn't create dst_dir_existing/test02.txt\n"); - return FAIL; - } - - return PASS; -} - -void removeDirectoryHelper(LPSTR dir, int location) -{ - DWORD dwAtt = GetFileAttributesA(dir); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - if(!RemoveDirectoryA(dir)) - { - Fail("ERROR: Failed to remove Directory [%s], Error Code [%d], location [%d]\n", dir, GetLastError(), location); - } - } -} - -void removeFileHelper(LPSTR pfile, int location) -{ - FILE *fp; - fp = fopen( pfile, "r"); - - if (fp != NULL) - { - if(fclose(fp)) - { - Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - - if(!DeleteFileA(pfile)) - { - Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - else - { - // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); - } - } - -} - -/* remove all created files in preparation for the next test */ -void removeAll(void) -{ - char szTemp[40]; - DWORD dwAtt; - - /* get rid of source dirs and files */ - removeFileHelper(lpSource[0], 1); - removeFileHelper(lpSource[1], 2); - - dwAtt = GetFileAttributesA(lpSource[2]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpSource[2]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpSource[2]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpSource[2], 103); - } - else - { - removeFileHelper(lpSource[2], 17); - } - - - dwAtt = GetFileAttributesA(lpSource[3]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpSource[3]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpSource[3]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpSource[3], 103); - } - else - { - removeFileHelper(lpSource[3], 17); - } - - /* get rid of destination dirs and files */ - dwAtt = GetFileAttributesA(lpDestination[0]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpDestination[0]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpDestination[0]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpDestination[0], 103); - } - else - { - removeFileHelper(lpDestination[0], 17); - } - - dwAtt = GetFileAttributesA(lpDestination[1]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpDestination[1]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpDestination[1]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpDestination[1], 103); - } - else - { - removeFileHelper(lpDestination[1], 17); - } - - dwAtt = GetFileAttributesA(lpDestination[2]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpDestination[2]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpDestination[2]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpDestination[2], 103); - } - else - { - removeFileHelper(lpDestination[2], 17); - } - - dwAtt = GetFileAttributesA(lpDestination[3]); - if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) - { - sprintf(szTemp, "%s/test01.txt", lpDestination[3]); - removeFileHelper(szTemp, 18); - - sprintf(szTemp, "%s/test02.txt", lpDestination[3]); - removeFileHelper(szTemp, 19); - removeDirectoryHelper(lpDestination[3], 103); - } - else - { - removeFileHelper(lpDestination[3], 17); - } - -} - - - - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bRc = TRUE; - BOOL bSuccess = TRUE; - char results[40]; - FILE* resultsFile = NULL; - int nCounter = 0; - int i, j; - WCHAR* wSource = NULL; - WCHAR* wDest = NULL; - WCHAR tempSource[] = {'t','e','m','p','k','.','t','m','p','\0'}; - WCHAR tempDest[] = {'t','e','m','p','2','.','t','m','p','\0'}; - HANDLE hFile; - DWORD result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* read in the expected results to compare with actual results */ - memset (results, 0, 20); - resultsFile = fopen("expectedresults.txt", "r"); - if (resultsFile == NULL) - { - Fail("MoveFileW ERROR: Unable to open \"expectedresults.txt\"\n"); - } - - fgets(results, 20, resultsFile); - fclose(resultsFile); - - /* clean the slate */ - removeAll(); - - if (createExisting() != 0) - { - removeAll(); - } - - - /* lpSource loop */ - for (i = 0; i < 4; i++) - { - /* lpDestination loop */ - for (j = 0; j < 4; j++) - { - - wSource = convert(lpSource[i]); - wDest = convert(lpDestination[j]); - bRc = MoveFileW(wSource, wDest); - free(wSource); - free(wDest); - if (!( - ((bRc == TRUE) && (results[nCounter] == '1')) - || - ((bRc == FALSE ) && (results[nCounter] == '0')) ) - ) - { - Trace("MoveFileW: FAILED: test[%d][%d]: \"%s\" -> \"%s\"\n", - i, j, lpSource[i], lpDestination[j]); - bSuccess = FALSE; - } - - /* undo the last move */ - removeAll(); - createExisting(); - - nCounter++; - } - } - - removeAll(); - if (bSuccess == FALSE) - { - Fail("MoveFileW: Test Failed"); - } - - /* create the temp source file */ - hFile = CreateFileW(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - - if( hFile == INVALID_HANDLE_VALUE ) - { - Fail("MoveFileW: CreateFile failed to " - "create the file correctly.\n"); - } - - bRc = CloseHandle(hFile); - if(!bRc) - { - Trace("MoveFileW: CloseHandle failed to close the " - "handle correctly. ERROR:%u\n",GetLastError()); - - /* delete the created file */ - bRc = DeleteFileW(tempSource); - if(!bRc) - { - Fail("MoveFileW: DeleteFileW failed to delete the" - "file correctly.\n"); - } - Fail(""); - } - - /* set the file attributes to be readonly */ - bRc = SetFileAttributesW(tempSource, FILE_ATTRIBUTE_READONLY); - if(!bRc) - { - Trace("MoveFileW: SetFileAttributes failed to set file " - "attributes correctly. GetLastError returned %u\n",GetLastError()); - /* delete the created file */ - bRc = DeleteFileW(tempSource); - if(!bRc) - { - Fail("MoveFileW: DeleteFileW failed to delete the" - "file correctly.\n"); - } - Fail(""); - } - - /* move the file to the new location */ - bRc = MoveFileW(tempSource, tempDest); - if(!bRc) - { - /* delete the created file */ - bRc = DeleteFileW(tempSource); - if(!bRc) - { - Fail("MoveFileW: DeleteFileW failed to delete the" - "file correctly.\n"); - } - - Fail("MoveFileW(%S, %S): GetFileAttributes " - "failed to get the file's attributes.\n", - tempSource, tempDest); - } - - /* check that the newly moved file has the same file attributes - as the original */ - result = GetFileAttributesW(tempDest); - if(result == 0) - { - /* delete the created file */ - bRc = DeleteFileW(tempDest); - if(!bRc) - { - Fail("MoveFileW: DeleteFileW failed to delete the" - "file correctly.\n"); - } - - Fail("MoveFileW: GetFileAttributes failed to get " - "the file's attributes.\n"); - } - - if((result & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) - { - /* delete the newly moved file */ - bRc = DeleteFileW(tempDest); - if(!bRc) - { - Fail("MoveFileW: DeleteFileW failed to delete the" - "file correctly.\n"); - } - - Fail("MoveFileW: GetFileAttributes failed to get " - "the correct file attributes.\n"); - } - - /* set the file attributes back to normal, to be deleted */ - bRc = SetFileAttributesW(tempDest, FILE_ATTRIBUTE_NORMAL); - if(!bRc) - { - /* delete the newly moved file */ - bRc = DeleteFileW(tempDest); - if(!bRc) - { - Fail("MoveFileW: DeleteFileW failed to delete the" - "file correctly.\n"); - } - - Fail("MoveFileW: SetFileAttributes failed to set " - "file attributes correctly.\n"); - } - - /* delete the newly moved file */ - bRc = DeleteFileW(tempDest); - if(!bRc) - { - Fail("MoveFileW: DeleteFileW failed to delete the" - "file correctly.\n"); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/MoveFileW/test1/MoveFileW.cpp b/src/pal/tests/palsuite/file_io/MoveFileW/test1/MoveFileW.cpp new file mode 100644 index 0000000000..8a7fae5983 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/MoveFileW/test1/MoveFileW.cpp @@ -0,0 +1,478 @@ +// 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: MoveFileW.c +** +** Purpose: Tests the PAL implementation of the MoveFileW function. +** +** +**===================================================================*/ + +#include + +LPSTR lpSource[4] = {"src_existing.txt", + "src_non-existant.txt", + "src_dir_existing", + "src_dir_non-existant"}; +LPSTR lpDestination[4] = {"dst_existing.txt", + "dst_non-existant.txt", + "dst_dir_existing", + "dst_dir_non-existant"}; + + +/* Create all the required test files */ +int createExisting(void) +{ + FILE* tempFile = NULL; + DWORD dwError; + BOOL bRc = FALSE; + WCHAR* wPtr = NULL; + char szBuffer[100]; + + /* create the src_existing file */ + tempFile = fopen(lpSource[0], "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFile test file: src_existing.txt\n"); + fclose(tempFile); + } + else + { + Trace("ERROR: couldn't create %s\n", lpSource[0]); + return FAIL; + } + + /* create the src_dir_existing directory and files */ + wPtr = convert(lpSource[2]); + bRc = CreateDirectoryW(wPtr, NULL); + free(wPtr); + if (bRc != TRUE) + { + Trace("MoveFileW: ERROR: couldn't create \"%s\" because of " + "error code %ld\n", + lpSource[2], + GetLastError()); + return FAIL; + } + + memset(szBuffer, 0, 100); + sprintf_s(szBuffer, _countof(szBuffer), "%s/test01.txt", lpSource[2]); + tempFile = fopen(szBuffer, "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileW test file: %s\n", szBuffer); + fclose(tempFile); + } + else + { + Trace("ERROR: couldn't create %s\n", szBuffer); + return FAIL; + } + + memset(szBuffer, 0, 100); + sprintf_s(szBuffer, _countof(szBuffer), "%s/test02.txt", lpSource[2]); + tempFile = fopen(szBuffer, "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileW test file: %s\n", szBuffer); + fclose(tempFile); + } + else + { + Trace("ERROR: couldn't create %s\n", szBuffer); + return FAIL; + } + + + /* create the dst_existing file */ + tempFile = fopen(lpDestination[0], "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileW test file: dst_existing.txt\n"); + fclose(tempFile); + } + else + { + Trace("ERROR: couldn't create \"%s\"\n", lpDestination[0]); + return FAIL; + } + + /* create the dst_dir_existing directory and files */ + wPtr = convert(lpDestination[2]); + bRc = CreateDirectoryW(wPtr, NULL); + free(wPtr); + if (bRc != TRUE) + { + dwError = GetLastError(); + Trace("MoveFileW: ERROR: couldn't create \"%s\"\n", lpDestination[2]); + return FAIL; + } + + tempFile = fopen("dst_dir_existing/test01.txt", "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileW test file: dst_dir_existing/test01.txt\n"); + fclose(tempFile); + } + else + { + Trace("ERROR: couldn't create dst_dir_existing/test01.txt\n"); + return FAIL; + } + tempFile = fopen("dst_dir_existing/test02.txt", "w"); + if (tempFile != NULL) + { + fprintf(tempFile, "MoveFileW test file: dst_dir_existing/test02.txt\n"); + fclose(tempFile); + } + else + { + Trace("ERROR: couldn't create dst_dir_existing/test02.txt\n"); + return FAIL; + } + + return PASS; +} + +void removeDirectoryHelper(LPSTR dir, int location) +{ + DWORD dwAtt = GetFileAttributesA(dir); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + if(!RemoveDirectoryA(dir)) + { + Fail("ERROR: Failed to remove Directory [%s], Error Code [%d], location [%d]\n", dir, GetLastError(), location); + } + } +} + +void removeFileHelper(LPSTR pfile, int location) +{ + FILE *fp; + fp = fopen( pfile, "r"); + + if (fp != NULL) + { + if(fclose(fp)) + { + Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + + if(!DeleteFileA(pfile)) + { + Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + else + { + // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); + } + } + +} + +/* remove all created files in preparation for the next test */ +void removeAll(void) +{ + char szTemp[40]; + DWORD dwAtt; + + /* get rid of source dirs and files */ + removeFileHelper(lpSource[0], 1); + removeFileHelper(lpSource[1], 2); + + dwAtt = GetFileAttributesA(lpSource[2]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpSource[2]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpSource[2]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpSource[2], 103); + } + else + { + removeFileHelper(lpSource[2], 17); + } + + + dwAtt = GetFileAttributesA(lpSource[3]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpSource[3]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpSource[3]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpSource[3], 103); + } + else + { + removeFileHelper(lpSource[3], 17); + } + + /* get rid of destination dirs and files */ + dwAtt = GetFileAttributesA(lpDestination[0]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpDestination[0]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpDestination[0]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpDestination[0], 103); + } + else + { + removeFileHelper(lpDestination[0], 17); + } + + dwAtt = GetFileAttributesA(lpDestination[1]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpDestination[1]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpDestination[1]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpDestination[1], 103); + } + else + { + removeFileHelper(lpDestination[1], 17); + } + + dwAtt = GetFileAttributesA(lpDestination[2]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpDestination[2]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpDestination[2]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpDestination[2], 103); + } + else + { + removeFileHelper(lpDestination[2], 17); + } + + dwAtt = GetFileAttributesA(lpDestination[3]); + if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) + { + sprintf_s(szTemp, _countof(szTemp), "%s/test01.txt", lpDestination[3]); + removeFileHelper(szTemp, 18); + + sprintf_s(szTemp, _countof(szTemp), "%s/test02.txt", lpDestination[3]); + removeFileHelper(szTemp, 19); + removeDirectoryHelper(lpDestination[3], 103); + } + else + { + removeFileHelper(lpDestination[3], 17); + } + +} + + + + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bRc = TRUE; + BOOL bSuccess = TRUE; + char results[40]; + FILE* resultsFile = NULL; + int nCounter = 0; + int i, j; + WCHAR* wSource = NULL; + WCHAR* wDest = NULL; + WCHAR tempSource[] = {'t','e','m','p','k','.','t','m','p','\0'}; + WCHAR tempDest[] = {'t','e','m','p','2','.','t','m','p','\0'}; + HANDLE hFile; + DWORD result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* read in the expected results to compare with actual results */ + memset (results, 0, 20); + resultsFile = fopen("expectedresults.txt", "r"); + if (resultsFile == NULL) + { + Fail("MoveFileW ERROR: Unable to open \"expectedresults.txt\"\n"); + } + + fgets(results, 20, resultsFile); + fclose(resultsFile); + + /* clean the slate */ + removeAll(); + + if (createExisting() != 0) + { + removeAll(); + } + + + /* lpSource loop */ + for (i = 0; i < 4; i++) + { + /* lpDestination loop */ + for (j = 0; j < 4; j++) + { + + wSource = convert(lpSource[i]); + wDest = convert(lpDestination[j]); + bRc = MoveFileW(wSource, wDest); + free(wSource); + free(wDest); + if (!( + ((bRc == TRUE) && (results[nCounter] == '1')) + || + ((bRc == FALSE ) && (results[nCounter] == '0')) ) + ) + { + Trace("MoveFileW: FAILED: test[%d][%d]: \"%s\" -> \"%s\"\n", + i, j, lpSource[i], lpDestination[j]); + bSuccess = FALSE; + } + + /* undo the last move */ + removeAll(); + createExisting(); + + nCounter++; + } + } + + removeAll(); + if (bSuccess == FALSE) + { + Fail("MoveFileW: Test Failed"); + } + + /* create the temp source file */ + hFile = CreateFileW(tempSource, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + + if( hFile == INVALID_HANDLE_VALUE ) + { + Fail("MoveFileW: CreateFile failed to " + "create the file correctly.\n"); + } + + bRc = CloseHandle(hFile); + if(!bRc) + { + Trace("MoveFileW: CloseHandle failed to close the " + "handle correctly. ERROR:%u\n",GetLastError()); + + /* delete the created file */ + bRc = DeleteFileW(tempSource); + if(!bRc) + { + Fail("MoveFileW: DeleteFileW failed to delete the" + "file correctly.\n"); + } + Fail(""); + } + + /* set the file attributes to be readonly */ + bRc = SetFileAttributesW(tempSource, FILE_ATTRIBUTE_READONLY); + if(!bRc) + { + Trace("MoveFileW: SetFileAttributes failed to set file " + "attributes correctly. GetLastError returned %u\n",GetLastError()); + /* delete the created file */ + bRc = DeleteFileW(tempSource); + if(!bRc) + { + Fail("MoveFileW: DeleteFileW failed to delete the" + "file correctly.\n"); + } + Fail(""); + } + + /* move the file to the new location */ + bRc = MoveFileW(tempSource, tempDest); + if(!bRc) + { + /* delete the created file */ + bRc = DeleteFileW(tempSource); + if(!bRc) + { + Fail("MoveFileW: DeleteFileW failed to delete the" + "file correctly.\n"); + } + + Fail("MoveFileW(%S, %S): GetFileAttributes " + "failed to get the file's attributes.\n", + tempSource, tempDest); + } + + /* check that the newly moved file has the same file attributes + as the original */ + result = GetFileAttributesW(tempDest); + if(result == 0) + { + /* delete the created file */ + bRc = DeleteFileW(tempDest); + if(!bRc) + { + Fail("MoveFileW: DeleteFileW failed to delete the" + "file correctly.\n"); + } + + Fail("MoveFileW: GetFileAttributes failed to get " + "the file's attributes.\n"); + } + + if((result & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) + { + /* delete the newly moved file */ + bRc = DeleteFileW(tempDest); + if(!bRc) + { + Fail("MoveFileW: DeleteFileW failed to delete the" + "file correctly.\n"); + } + + Fail("MoveFileW: GetFileAttributes failed to get " + "the correct file attributes.\n"); + } + + /* set the file attributes back to normal, to be deleted */ + bRc = SetFileAttributesW(tempDest, FILE_ATTRIBUTE_NORMAL); + if(!bRc) + { + /* delete the newly moved file */ + bRc = DeleteFileW(tempDest); + if(!bRc) + { + Fail("MoveFileW: DeleteFileW failed to delete the" + "file correctly.\n"); + } + + Fail("MoveFileW: SetFileAttributes failed to set " + "file attributes correctly.\n"); + } + + /* delete the newly moved file */ + bRc = DeleteFileW(tempDest); + if(!bRc) + { + Fail("MoveFileW: DeleteFileW failed to delete the" + "file correctly.\n"); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/ReadFile/test1/CMakeLists.txt index 7b166e17b0..0aceb3708e 100644 --- a/src/pal/tests/palsuite/file_io/ReadFile/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/ReadFile/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - ReadFile.c + ReadFile.cpp ) add_executable(paltest_readfile_test1 diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test1/ReadFile.c b/src/pal/tests/palsuite/file_io/ReadFile/test1/ReadFile.c deleted file mode 100644 index a59e29212e..0000000000 --- a/src/pal/tests/palsuite/file_io/ReadFile/test1/ReadFile.c +++ /dev/null @@ -1,82 +0,0 @@ -// 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: ReadFile.c (test 1) -** -** Purpose: Tests the PAL implementation of the ReadFile function. -** This test will attempt to read from a NULL handle and from -** a file without read permissions set. -** -** -**===================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwByteCount = 0; - DWORD dwBytesRead = 0; - BOOL bRc = FALSE; - char szBuffer[256]; - char* szNonReadableFile = {"nonreadablefile.txt"}; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - memset(szBuffer, 0, 256); - - /* Read from a NULL handle - */ - - bRc = ReadFile(hFile, szBuffer, 20, &dwBytesRead, NULL); - - if (bRc == TRUE) - { - Fail("ReadFile: ERROR -> Able to read from a NULL handle\n"); - } - - - /* Read from a file without read permissions - */ - -#if WIN32 - -#else - /* attempt to read from the unreadable file - * open a file without read permissions - */ - hFile = CreateFile(szNonReadableFile, - GENERIC_WRITE, - FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - dwByteCount = GetLastError(); - Fail("ReadFile: ERROR -> Unable to create file \"%s\".\n", - szNonReadableFile); - } - - bRc = ReadFile(hFile, szBuffer, 20, &dwBytesRead, NULL); - - if (bRc == TRUE) - { - Fail("ReadFile: ERROR -> Able to read from a file without read " - "permissions\n"); - } -#endif - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test1/ReadFile.cpp b/src/pal/tests/palsuite/file_io/ReadFile/test1/ReadFile.cpp new file mode 100644 index 0000000000..a59e29212e --- /dev/null +++ b/src/pal/tests/palsuite/file_io/ReadFile/test1/ReadFile.cpp @@ -0,0 +1,82 @@ +// 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: ReadFile.c (test 1) +** +** Purpose: Tests the PAL implementation of the ReadFile function. +** This test will attempt to read from a NULL handle and from +** a file without read permissions set. +** +** +**===================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwByteCount = 0; + DWORD dwBytesRead = 0; + BOOL bRc = FALSE; + char szBuffer[256]; + char* szNonReadableFile = {"nonreadablefile.txt"}; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + memset(szBuffer, 0, 256); + + /* Read from a NULL handle + */ + + bRc = ReadFile(hFile, szBuffer, 20, &dwBytesRead, NULL); + + if (bRc == TRUE) + { + Fail("ReadFile: ERROR -> Able to read from a NULL handle\n"); + } + + + /* Read from a file without read permissions + */ + +#if WIN32 + +#else + /* attempt to read from the unreadable file + * open a file without read permissions + */ + hFile = CreateFile(szNonReadableFile, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + dwByteCount = GetLastError(); + Fail("ReadFile: ERROR -> Unable to create file \"%s\".\n", + szNonReadableFile); + } + + bRc = ReadFile(hFile, szBuffer, 20, &dwBytesRead, NULL); + + if (bRc == TRUE) + { + Fail("ReadFile: ERROR -> Able to read from a file without read " + "permissions\n"); + } +#endif + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/ReadFile/test2/CMakeLists.txt index fc4870e73d..f28ac117a2 100644 --- a/src/pal/tests/palsuite/file_io/ReadFile/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/ReadFile/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - ReadFile.c + ReadFile.cpp ) add_executable(paltest_readfile_test2 diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.c b/src/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.c deleted file mode 100644 index f16858e573..0000000000 --- a/src/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.c +++ /dev/null @@ -1,198 +0,0 @@ -// 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: ReadFile.c (test 2) -** -** Purpose: Tests the PAL implementation of the ReadFile function. -** Creates a test file and performs an array of read tests. -** -** Assumes successful: -** CreateFile -** CloseHandle -** WriteFile -** GetLastError -** -** -**===================================================================*/ - - -#include - - -const char* szStringTest = "The quick fox jumped over the lazy dog's back.\0"; -const char* szEmptyString = ""; -const char* szReadableFile = "Readable.txt"; -const char* szResultsFile = "Results.txt"; - -//Previously number of tests was 6, now 4 refer VSW 312690 -#define NOOFTESTS 4 - -#ifdef __sparc__ -const int PAGESIZE = 8192; -#else // __sparc__ -const int PAGESIZE = 4096; -#endif // __sparc__ - -char *readBuffer; - -BOOL validateResults(const char* szString, // string read - DWORD dwByteCount, // amount requested - DWORD dwBytesRead) // amount read -{ - // were the correct number of bytes read? - if (dwBytesRead > dwByteCount) - { - Trace("bytes read > bytes asked for\n"); - return FALSE; - } - if (dwBytesRead != strlen(szString)) - { - Trace("bytes read != length of read string\n"); - return FALSE; - } - - // - // compare results - // - - if (memcmp(szString, szStringTest, dwBytesRead) != 0) - { - Trace("read = %s string = %s", szString, szStringTest); - return FALSE; - } - - return TRUE; -} - -BOOL readTest(DWORD dwByteCount, char cResult) -{ - HANDLE hFile = NULL; - DWORD dwBytesRead; - BOOL bRc = FALSE; - - // open the test file - hFile = CreateFile(szReadableFile, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - if(hFile == INVALID_HANDLE_VALUE) - { - Trace("ReadFile: ERROR -> Unable to open file \"%s\".\n", - szReadableFile); - return FALSE; - } - - memset(readBuffer, 0, PAGESIZE); - - bRc = ReadFile(hFile, readBuffer, dwByteCount, &dwBytesRead, NULL); - - if (bRc == FALSE) - { - // if it failed, was it supposed to fail? - if (cResult == '1') - { - Trace("\nbRc = %d\n", bRc); - Trace("readBuffer = [%s] dwByteCount = %d dwBytesRead = %d\n", readBuffer, dwByteCount, dwBytesRead); - Trace("cresult = 1\n"); - Trace("getlasterror = %d\n", GetLastError()); - CloseHandle(hFile); - return FALSE; - } - } - else - { - CloseHandle(hFile); - // if it passed, was it supposed to pass? - if (cResult == '0') - { - Trace("cresult = 0\n"); - return FALSE; - } - else - { - return (validateResults(readBuffer, dwByteCount, dwBytesRead)); - } - } - - CloseHandle(hFile); - return TRUE; -} - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - const int BUFFER_SIZE = 2 * PAGESIZE; - - DWORD dwByteCount[] = { 0, - 10, - strlen(szStringTest), - PAGESIZE - // Commented out two negative test cases : Refer VSW 312690 - // 2 * PAGESIZE, - // -1 - }; - - DWORD oldProt; - char szResults[] = "1111"; // Was "111100": Refer VSW 312690 - int i; - BOOL bRc = FALSE; - DWORD dwBytesWritten = 0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* aloocate read-write memery for readBuffer */ - if (!(readBuffer = (char*) VirtualAlloc(NULL, BUFFER_SIZE, MEM_COMMIT, PAGE_READWRITE))) - { - Fail("VirtualAlloc failed: GetLastError returns %d\n", GetLastError()); - return FAIL; - } - - /* write protect the second page of readBuffer */ - if (!VirtualProtect(&readBuffer[PAGESIZE], PAGESIZE, PAGE_NOACCESS, &oldProt)) - { - Fail("VirtualProtect failed: GetLastError returns %d\n", GetLastError()); - return FAIL; - } - - // create the test file - hFile = CreateFile(szReadableFile, - GENERIC_WRITE, - FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("ReadFile: ERROR -> Unable to create file \"%s\" (%d).\n", - szReadableFile, GetLastError()); - } - - bRc = WriteFile(hFile, szStringTest, strlen(szStringTest), &dwBytesWritten, NULL); - CloseHandle(hFile); - - - for (i = 0; i< NOOFTESTS; i++) - { - bRc = readTest(dwByteCount[i], szResults[i]); - if (bRc != TRUE) - { - Fail("ReadFile: ERROR -> Failed on test[%d]\n", i); - } - } - - VirtualFree(readBuffer, BUFFER_SIZE, MEM_RELEASE); - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.cpp b/src/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.cpp new file mode 100644 index 0000000000..f16858e573 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.cpp @@ -0,0 +1,198 @@ +// 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: ReadFile.c (test 2) +** +** Purpose: Tests the PAL implementation of the ReadFile function. +** Creates a test file and performs an array of read tests. +** +** Assumes successful: +** CreateFile +** CloseHandle +** WriteFile +** GetLastError +** +** +**===================================================================*/ + + +#include + + +const char* szStringTest = "The quick fox jumped over the lazy dog's back.\0"; +const char* szEmptyString = ""; +const char* szReadableFile = "Readable.txt"; +const char* szResultsFile = "Results.txt"; + +//Previously number of tests was 6, now 4 refer VSW 312690 +#define NOOFTESTS 4 + +#ifdef __sparc__ +const int PAGESIZE = 8192; +#else // __sparc__ +const int PAGESIZE = 4096; +#endif // __sparc__ + +char *readBuffer; + +BOOL validateResults(const char* szString, // string read + DWORD dwByteCount, // amount requested + DWORD dwBytesRead) // amount read +{ + // were the correct number of bytes read? + if (dwBytesRead > dwByteCount) + { + Trace("bytes read > bytes asked for\n"); + return FALSE; + } + if (dwBytesRead != strlen(szString)) + { + Trace("bytes read != length of read string\n"); + return FALSE; + } + + // + // compare results + // + + if (memcmp(szString, szStringTest, dwBytesRead) != 0) + { + Trace("read = %s string = %s", szString, szStringTest); + return FALSE; + } + + return TRUE; +} + +BOOL readTest(DWORD dwByteCount, char cResult) +{ + HANDLE hFile = NULL; + DWORD dwBytesRead; + BOOL bRc = FALSE; + + // open the test file + hFile = CreateFile(szReadableFile, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + if(hFile == INVALID_HANDLE_VALUE) + { + Trace("ReadFile: ERROR -> Unable to open file \"%s\".\n", + szReadableFile); + return FALSE; + } + + memset(readBuffer, 0, PAGESIZE); + + bRc = ReadFile(hFile, readBuffer, dwByteCount, &dwBytesRead, NULL); + + if (bRc == FALSE) + { + // if it failed, was it supposed to fail? + if (cResult == '1') + { + Trace("\nbRc = %d\n", bRc); + Trace("readBuffer = [%s] dwByteCount = %d dwBytesRead = %d\n", readBuffer, dwByteCount, dwBytesRead); + Trace("cresult = 1\n"); + Trace("getlasterror = %d\n", GetLastError()); + CloseHandle(hFile); + return FALSE; + } + } + else + { + CloseHandle(hFile); + // if it passed, was it supposed to pass? + if (cResult == '0') + { + Trace("cresult = 0\n"); + return FALSE; + } + else + { + return (validateResults(readBuffer, dwByteCount, dwBytesRead)); + } + } + + CloseHandle(hFile); + return TRUE; +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + const int BUFFER_SIZE = 2 * PAGESIZE; + + DWORD dwByteCount[] = { 0, + 10, + strlen(szStringTest), + PAGESIZE + // Commented out two negative test cases : Refer VSW 312690 + // 2 * PAGESIZE, + // -1 + }; + + DWORD oldProt; + char szResults[] = "1111"; // Was "111100": Refer VSW 312690 + int i; + BOOL bRc = FALSE; + DWORD dwBytesWritten = 0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* aloocate read-write memery for readBuffer */ + if (!(readBuffer = (char*) VirtualAlloc(NULL, BUFFER_SIZE, MEM_COMMIT, PAGE_READWRITE))) + { + Fail("VirtualAlloc failed: GetLastError returns %d\n", GetLastError()); + return FAIL; + } + + /* write protect the second page of readBuffer */ + if (!VirtualProtect(&readBuffer[PAGESIZE], PAGESIZE, PAGE_NOACCESS, &oldProt)) + { + Fail("VirtualProtect failed: GetLastError returns %d\n", GetLastError()); + return FAIL; + } + + // create the test file + hFile = CreateFile(szReadableFile, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("ReadFile: ERROR -> Unable to create file \"%s\" (%d).\n", + szReadableFile, GetLastError()); + } + + bRc = WriteFile(hFile, szStringTest, strlen(szStringTest), &dwBytesWritten, NULL); + CloseHandle(hFile); + + + for (i = 0; i< NOOFTESTS; i++) + { + bRc = readTest(dwByteCount[i], szResults[i]); + if (bRc != TRUE) + { + Fail("ReadFile: ERROR -> Failed on test[%d]\n", i); + } + } + + VirtualFree(readBuffer, BUFFER_SIZE, MEM_RELEASE); + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/ReadFile/test3/CMakeLists.txt index 77397743d4..26cb675c40 100644 --- a/src/pal/tests/palsuite/file_io/ReadFile/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/ReadFile/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - ReadFile.c + ReadFile.cpp ) add_executable(paltest_readfile_test3 diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test3/ReadFile.c b/src/pal/tests/palsuite/file_io/ReadFile/test3/ReadFile.c deleted file mode 100644 index c5d6b1d155..0000000000 --- a/src/pal/tests/palsuite/file_io/ReadFile/test3/ReadFile.c +++ /dev/null @@ -1,184 +0,0 @@ -// 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: ReadFile.c (test 3) -** -** Purpose: Tests the PAL implementation of the ReadFile function. -** Creates a test file and performs an array of sequential read -** tests. -** -** Assumes successful: -** CreateFile -** CloseHandle -** memset -** WriteFile -** CreateFile -** CloseHandle -** GetLastError -** -** -**===================================================================*/ - -#include - -const char* szStringTest = "The quick fox jumped over the lazy dog's back.\0"; -const char* szEmptyString = ""; -const char* szReadableFile = "Readable.txt"; -const char* szResultsFile = "Results.txt"; - - -BOOL validateResults(const char* szString, // string read - DWORD dwByteCount, // amount requested - DWORD dwBytesRead) // amount read -{ - // were the correct number of bytes read? - if (dwBytesRead > dwByteCount) - { - Trace("bytes read > bytes asked for\n"); - return FALSE; - } - if (dwBytesRead != strlen(szString)) - { - Trace("bytes read != length of read string\n"); - return FALSE; - } - - - // - // compare results - // - - if (memcmp(szString, szStringTest, dwByteCount) != 0) - { - Trace("read = %s string = %s", szString, szStringTest); - return FALSE; - } - - return TRUE; -} - - - - -BOOL readTest(DWORD dwByteCount, char cResult) -{ - HANDLE hFile = NULL; - DWORD dwBytesRead = 0; - DWORD dwTotal = 0; - DWORD dwRequested = 0; - BOOL bRc = FALSE; - char szString[100]; - char* szPtr = szString; - int i = 0; - - // open the test file - hFile = CreateFile(szReadableFile, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - if(hFile == INVALID_HANDLE_VALUE) - { - Trace("ReadFile: ERROR -> Unable to open file \"%s\".\n", - szReadableFile); - return FALSE; - } - - memset(szString, 0, 100); - - for (i = 0; i < 5; i++) - { - bRc = ReadFile(hFile, szPtr, dwByteCount, &dwBytesRead, NULL); - szPtr += dwByteCount; - dwTotal += dwBytesRead; - dwRequested += dwByteCount; - } - - if (bRc == FALSE) - { - // if it failed, was it supposed to fail? - if (cResult == '1') - { - Trace("\nbRc = %d\n", bRc); - Trace("szString = [%s] dwByteCount = %d dwBytesRead = %d\n", - szString, - dwByteCount, - dwBytesRead); - Trace ("cresult = 1\n"); - Trace ("getlasterror = %d\n", GetLastError()); - CloseHandle(hFile); - return FALSE; - } - } - else - { - CloseHandle(hFile); - // if it passed, was it supposed to pass? - if (cResult == '0') - { - Trace ("cresult = 0\n"); - return FALSE; - } - else - { - return (validateResults(szString, dwRequested, dwTotal)); - } - } - - CloseHandle(hFile); - return TRUE; -} - - - -int __cdecl main(int argc, char **argv) -{ - HANDLE hFile = NULL; - DWORD dwByteCount[4] = {0, 1, 2, 3}; - char szResults[4] = {'1', '1', '1', '1'}; - int i; - BOOL bRc = FALSE; - DWORD dwBytesWritten = 0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - // create the test file - hFile = CreateFile(szReadableFile, - GENERIC_WRITE, - FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("ReadFile: ERROR -> Unable to create file \"%s\".\n", - szReadableFile); - } - - bRc = WriteFile(hFile, szStringTest, strlen(szStringTest), - &dwBytesWritten, - NULL); - CloseHandle(hFile); - - for (i = 0; i < 4; i++) - { - bRc = readTest(dwByteCount[i], szResults[i]); - if (bRc != TRUE) - { - Fail("ReadFile: ERROR -> Failed on test[%d]\n", i); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test3/ReadFile.cpp b/src/pal/tests/palsuite/file_io/ReadFile/test3/ReadFile.cpp new file mode 100644 index 0000000000..c5d6b1d155 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/ReadFile/test3/ReadFile.cpp @@ -0,0 +1,184 @@ +// 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: ReadFile.c (test 3) +** +** Purpose: Tests the PAL implementation of the ReadFile function. +** Creates a test file and performs an array of sequential read +** tests. +** +** Assumes successful: +** CreateFile +** CloseHandle +** memset +** WriteFile +** CreateFile +** CloseHandle +** GetLastError +** +** +**===================================================================*/ + +#include + +const char* szStringTest = "The quick fox jumped over the lazy dog's back.\0"; +const char* szEmptyString = ""; +const char* szReadableFile = "Readable.txt"; +const char* szResultsFile = "Results.txt"; + + +BOOL validateResults(const char* szString, // string read + DWORD dwByteCount, // amount requested + DWORD dwBytesRead) // amount read +{ + // were the correct number of bytes read? + if (dwBytesRead > dwByteCount) + { + Trace("bytes read > bytes asked for\n"); + return FALSE; + } + if (dwBytesRead != strlen(szString)) + { + Trace("bytes read != length of read string\n"); + return FALSE; + } + + + // + // compare results + // + + if (memcmp(szString, szStringTest, dwByteCount) != 0) + { + Trace("read = %s string = %s", szString, szStringTest); + return FALSE; + } + + return TRUE; +} + + + + +BOOL readTest(DWORD dwByteCount, char cResult) +{ + HANDLE hFile = NULL; + DWORD dwBytesRead = 0; + DWORD dwTotal = 0; + DWORD dwRequested = 0; + BOOL bRc = FALSE; + char szString[100]; + char* szPtr = szString; + int i = 0; + + // open the test file + hFile = CreateFile(szReadableFile, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + if(hFile == INVALID_HANDLE_VALUE) + { + Trace("ReadFile: ERROR -> Unable to open file \"%s\".\n", + szReadableFile); + return FALSE; + } + + memset(szString, 0, 100); + + for (i = 0; i < 5; i++) + { + bRc = ReadFile(hFile, szPtr, dwByteCount, &dwBytesRead, NULL); + szPtr += dwByteCount; + dwTotal += dwBytesRead; + dwRequested += dwByteCount; + } + + if (bRc == FALSE) + { + // if it failed, was it supposed to fail? + if (cResult == '1') + { + Trace("\nbRc = %d\n", bRc); + Trace("szString = [%s] dwByteCount = %d dwBytesRead = %d\n", + szString, + dwByteCount, + dwBytesRead); + Trace ("cresult = 1\n"); + Trace ("getlasterror = %d\n", GetLastError()); + CloseHandle(hFile); + return FALSE; + } + } + else + { + CloseHandle(hFile); + // if it passed, was it supposed to pass? + if (cResult == '0') + { + Trace ("cresult = 0\n"); + return FALSE; + } + else + { + return (validateResults(szString, dwRequested, dwTotal)); + } + } + + CloseHandle(hFile); + return TRUE; +} + + + +int __cdecl main(int argc, char **argv) +{ + HANDLE hFile = NULL; + DWORD dwByteCount[4] = {0, 1, 2, 3}; + char szResults[4] = {'1', '1', '1', '1'}; + int i; + BOOL bRc = FALSE; + DWORD dwBytesWritten = 0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + // create the test file + hFile = CreateFile(szReadableFile, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("ReadFile: ERROR -> Unable to create file \"%s\".\n", + szReadableFile); + } + + bRc = WriteFile(hFile, szStringTest, strlen(szStringTest), + &dwBytesWritten, + NULL); + CloseHandle(hFile); + + for (i = 0; i < 4; i++) + { + bRc = readTest(dwByteCount[i], szResults[i]); + if (bRc != TRUE) + { + Fail("ReadFile: ERROR -> Failed on test[%d]\n", i); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/ReadFile/test4/CMakeLists.txt index 37f227aced..bbf12777b6 100644 --- a/src/pal/tests/palsuite/file_io/ReadFile/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/ReadFile/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - readfile.c + readfile.cpp ) add_executable(paltest_readfile_test4 diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test4/readfile.c b/src/pal/tests/palsuite/file_io/ReadFile/test4/readfile.c deleted file mode 100644 index 3ec939f63a..0000000000 --- a/src/pal/tests/palsuite/file_io/ReadFile/test4/readfile.c +++ /dev/null @@ -1,147 +0,0 @@ -// 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: ReadFile.c (test 4) -** -** Purpose: Tests the PAL implementation of the ReadFile function. -** Creates a file and writes a small string to it, attempt -** to read many more characters that exist. The returned -** number of chars should be the amount written originally -** not the number requested. -** -** -**===================================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwBytesWritten; - BOOL bRc = FALSE; - char szBuffer[256]; - DWORD dwBytesRead = 0; - int szRequestSize = 256; - char testFile[] = "testfile.tmp"; - char testString[] = "people stop and stare"; - DWORD res = 0; - - /* Initialize the PAL. - */ - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Initialize the buffer. - */ - memset(szBuffer, 0, 256); - - /* Create a file to test with. - */ - hFile = CreateFile(testFile, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_WRITE|FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR:%u: Unable to create file \"%s\".\n", - GetLastError(), - testFile); - } - - /* Write to the File handle. - */ - bRc = WriteFile(hFile, - testString, - strlen(testString), - &dwBytesWritten, - NULL); - - if (bRc == FALSE) - { - Trace("ERROR:%u: Unable to write to file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - if (!CloseHandle(hFile)) - { - Trace("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - /* Set the file pointer to beginning of file. - */ - res = SetFilePointer(hFile, (LONG)NULL, NULL, FILE_BEGIN); - - if( (res == INVALID_SET_FILE_POINTER) && - (GetLastError() != NO_ERROR)) - { - Trace("ERROR:%u: Unable to set file pointer to the beginning of file.", - GetLastError()); - - if (!CloseHandle(hFile)) - { - Trace("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - - /* Attempt to read 256 characters from a file - * that does not contain that many. - */ - bRc = ReadFile(hFile, - szBuffer, - szRequestSize, - &dwBytesRead, - NULL); - - if (bRc == FALSE) - { - Trace("ERROR:%u: Unable to read from file handle 0x%lx.\n", - GetLastError(), - hFile); - if (!CloseHandle(hFile)) - { - Trace("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - /* Confirm the number of bytes read with that requested. - */ - if (dwBytesRead != strlen(testString)) - { - Trace("ERROR: The number of bytes read \"%d\" is not equal to the " - "number originally written \"%d\" to the file.\n", - dwBytesRead, - strlen(testString)); - if (!CloseHandle(hFile)) - { - Trace("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/ReadFile/test4/readfile.cpp b/src/pal/tests/palsuite/file_io/ReadFile/test4/readfile.cpp new file mode 100644 index 0000000000..3ec939f63a --- /dev/null +++ b/src/pal/tests/palsuite/file_io/ReadFile/test4/readfile.cpp @@ -0,0 +1,147 @@ +// 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: ReadFile.c (test 4) +** +** Purpose: Tests the PAL implementation of the ReadFile function. +** Creates a file and writes a small string to it, attempt +** to read many more characters that exist. The returned +** number of chars should be the amount written originally +** not the number requested. +** +** +**===================================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwBytesWritten; + BOOL bRc = FALSE; + char szBuffer[256]; + DWORD dwBytesRead = 0; + int szRequestSize = 256; + char testFile[] = "testfile.tmp"; + char testString[] = "people stop and stare"; + DWORD res = 0; + + /* Initialize the PAL. + */ + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Initialize the buffer. + */ + memset(szBuffer, 0, 256); + + /* Create a file to test with. + */ + hFile = CreateFile(testFile, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_WRITE|FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR:%u: Unable to create file \"%s\".\n", + GetLastError(), + testFile); + } + + /* Write to the File handle. + */ + bRc = WriteFile(hFile, + testString, + strlen(testString), + &dwBytesWritten, + NULL); + + if (bRc == FALSE) + { + Trace("ERROR:%u: Unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + if (!CloseHandle(hFile)) + { + Trace("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + /* Set the file pointer to beginning of file. + */ + res = SetFilePointer(hFile, (LONG)NULL, NULL, FILE_BEGIN); + + if( (res == INVALID_SET_FILE_POINTER) && + (GetLastError() != NO_ERROR)) + { + Trace("ERROR:%u: Unable to set file pointer to the beginning of file.", + GetLastError()); + + if (!CloseHandle(hFile)) + { + Trace("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + + /* Attempt to read 256 characters from a file + * that does not contain that many. + */ + bRc = ReadFile(hFile, + szBuffer, + szRequestSize, + &dwBytesRead, + NULL); + + if (bRc == FALSE) + { + Trace("ERROR:%u: Unable to read from file handle 0x%lx.\n", + GetLastError(), + hFile); + if (!CloseHandle(hFile)) + { + Trace("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + /* Confirm the number of bytes read with that requested. + */ + if (dwBytesRead != strlen(testString)) + { + Trace("ERROR: The number of bytes read \"%d\" is not equal to the " + "number originally written \"%d\" to the file.\n", + dwBytesRead, + strlen(testString)); + if (!CloseHandle(hFile)) + { + Trace("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/RemoveDirectoryA/test1/RemoveDirectoryA.cpp b/src/pal/tests/palsuite/file_io/RemoveDirectoryA/test1/RemoveDirectoryA.cpp index 167af58163..4eb53d0d0a 100644 --- a/src/pal/tests/palsuite/file_io/RemoveDirectoryA/test1/RemoveDirectoryA.cpp +++ b/src/pal/tests/palsuite/file_io/RemoveDirectoryA/test1/RemoveDirectoryA.cpp @@ -48,7 +48,7 @@ int __cdecl main(int argc, char *argv[]) * remove a directory that does not exist */ szTemp = (char *) malloc (sizeof("test_directory")); - sprintf(szTemp, "test_directory"); + sprintf_s(szTemp, sizeof("test_directory"), "test_directory"); bRc = RemoveDirectoryA(szTemp); if (bRc != FALSE) { @@ -69,7 +69,7 @@ int __cdecl main(int argc, char *argv[]) } char *szSymlinkName = (char *) malloc (sizeof("test_directory_symlink")); - sprintf(szSymlinkName, "test_directory_symlink"); + sprintf_s(szSymlinkName, sizeof("test_directory_symlink"), "test_directory_symlink"); if (symlink(szTemp, szSymlinkName) != 0) { Fail("Error:RemoveDirectoryA: Failed to create a symlink to the directory \"test_directory\".\n"); @@ -140,7 +140,7 @@ int __cdecl main(int argc, char *argv[]) * directories with dots */ memset(szDirName, 0, 252); - sprintf(szDirName, ".dotDirectory"); + sprintf_s(szDirName, _countof(szDirName), ".dotDirectory"); szTemp = (char *) malloc (sizeof(szDirName)); szTemp = strncpy(szTemp, szDirName, strlen(szDirName) + 1); @@ -170,7 +170,7 @@ int __cdecl main(int argc, char *argv[]) * Try calling RemoveDirectory with a file name */ memset(szDirName, 0, 252); - sprintf(szDirName, "removedirectoryw.c"); + sprintf_s(szDirName, _countof(szDirName), "removedirectoryw.c"); szTemp = (char *) malloc (sizeof(szDirName)); szTemp = strncpy(szTemp, szDirName, strlen(szDirName) + 1); @@ -201,7 +201,7 @@ int __cdecl main(int argc, char *argv[]) } /* Create non_empty_dir */ - sprintf( szDirName, "non_empty_dir"); + sprintf_s(szDirName, _countof(szDirName), "non_empty_dir"); szTemp = (char *) malloc (sizeof(szDirName)); szTemp = strncpy(szTemp, szDirName, strlen(szDirName) + 1); bRc = CreateDirectoryA(szTemp, NULL); @@ -229,7 +229,7 @@ int __cdecl main(int argc, char *argv[]) } /* Create sub_dir */ - sprintf (szDirName, "sub_dir"); + sprintf_s(szDirName, _countof(szDirName), "sub_dir"); szTemp2 = (char *) malloc (sizeof(szDirName)); szTemp2 = strncpy(szTemp2, szDirName, strlen(szDirName) + 1); bRc = CreateDirectoryA(szTemp2, NULL); diff --git a/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/CMakeLists.txt index 45b51cec30..6223bc6197 100644 --- a/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - RemoveDirectoryW.c + RemoveDirectoryW.cpp ) add_executable(paltest_removedirectoryw_test1 diff --git a/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/RemoveDirectoryW.c b/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/RemoveDirectoryW.c deleted file mode 100644 index ae1dd0fb97..0000000000 --- a/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/RemoveDirectoryW.c +++ /dev/null @@ -1,282 +0,0 @@ -// 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: RemoveDirectoryW.c -** -** Purpose: Tests the PAL implementation of the RemoveDirectoryW function. -** -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - BOOL bRc = FALSE; - char szDirName[252]; - DWORD curDirLen; - WCHAR *szwTemp = NULL; - WCHAR *szwTemp2 = NULL; - WCHAR szwCurrentDir[MAX_PATH]; - WCHAR szwSubDir[MAX_PATH]; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* - * remove a NULL directory - */ - bRc = RemoveDirectoryW(NULL); - if (bRc != FALSE) - { - Fail("RemoveDirectoryW: Failed since it was able to remove a" - " NULL directory name\n"); - } - - /* - * remove a directory that does not exist - */ - szwTemp = convert("test_directory"); - bRc = RemoveDirectoryW(szwTemp); - if (bRc != FALSE) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed since it was able to remove" - " the non-existant directory \"test_directory\"\n"); - } - - /* - * remove a directory that exists - */ - bRc = CreateDirectoryW(szwTemp, NULL); - if (bRc != TRUE) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to create the directory " - "\"test_directory\" when it exists already.\n"); - } - bRc = RemoveDirectoryW(szwTemp); - if (bRc == FALSE) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to remove the directory " - "\"test_directory\" (error code %d)\n", - GetLastError()); - } - /* Make sure the directory was removed */ - if( -1 != GetFileAttributesW(szwTemp) ) - { - free(szwTemp); - Fail("RemoveDirectoryW: Able to get the attributes of " - "the removed directory\n"); - } - free(szwTemp); - - /* - * remove long directory names (245 characters) - */ - curDirLen = GetCurrentDirectoryA(0, NULL) + 1; - memset(szDirName, 0, 252); - memset(szDirName, 'a', 245 - curDirLen); - szwTemp = convert(szDirName); - bRc = CreateDirectoryW(szwTemp, NULL); - if (bRc == FALSE) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to create a directory name " - "245 chars long\n"); - } - bRc = RemoveDirectoryW(szwTemp); - if (bRc == FALSE) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to remove a 245 char " - "long directory\n"); - } - - /* Make sure the directory was removed */ - if( -1 != GetFileAttributesW(szwTemp) ) - { - free(szwTemp); - Fail("RemoveDirectoryW: Able to get the attributes of " - "the removed directory\n"); - } - free(szwTemp); - - /* - * directories with dots - */ - memset(szDirName, 0, 252); - sprintf(szDirName, ".dotDirectory"); - szwTemp = convert(szDirName); - bRc = CreateDirectoryW(szwTemp, NULL); - if (bRc == FALSE) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to create \"%s\"\n", szDirName); - } - bRc = RemoveDirectoryW(szwTemp); - if (bRc == FALSE) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to remove \"%s\"\n", szDirName); - } - - /* Make sure the directory was removed */ - if( -1 != GetFileAttributesW(szwTemp) ) - { - free(szwTemp); - Fail("RemoveDirectoryW: Able to get the attributes of " - "the removed directory\n"); - } - free(szwTemp); - - /* - * Try calling RemoveDirectory with a file name - */ - memset(szDirName, 0, 252); - sprintf(szDirName, "removedirectoryw.c"); - szwTemp = convert(szDirName); - - bRc = RemoveDirectoryW(szwTemp); - free(szwTemp); - if (bRc != FALSE) - { - Fail("RemoveDirectoryW: should have failed when " - "called with a valid file name" ); - } - - /* - * remove a non empty directory - * - * To test that, we'll first create non_empty_dir, we'll - * set the current dir to non_empty_dir in which we'll - * create sub_dir. We'll go back to the root of non_empty_dir - * and we'll try to delete it (it shouldn't work). - * After that we'll cleanup sub_dir and non_empty_dir - */ - - /* Get the current directory so it is easy to get back - to it later */ - if( 0 == GetCurrentDirectoryW(MAX_PATH, szwCurrentDir) ) - { - Fail("RemoveDirectoryW: Failed to get current directory " - "with GetCurrentDirectoryW.\n"); - } - - /* Create non_empty_dir */ - szwTemp = convert("non_empty_dir"); - bRc = CreateDirectoryW(szwTemp, NULL); - if (bRc != TRUE) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to create the directory " - "\"non_empty_dir\" when it exists already.\n"); - } - - if( 0 == SetCurrentDirectoryW(szwTemp) ) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to set current directory to " - "\"non_empty_dir\" with SetCurrentDirectoryW.\n"); - } - - /* Get the directory full path so it is easy to get back - to it later */ - if( 0 == GetCurrentDirectoryW(MAX_PATH, szwSubDir) ) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to get current directory " - "with GetCurrentDirectoryW.\n"); - } - - /* Create sub_dir */ - szwTemp2 = convert("sub_dir"); - bRc = CreateDirectoryW(szwTemp2, NULL); - if (bRc != TRUE) - { - free(szwTemp); - free(szwTemp2); - Fail("RemoveDirectoryW: Failed to create the directory " - "\"sub_dir\" when it exists already.\n"); - } - - /* Set the current dir to the parent of non_empty_dir/sub_dir */ - if( 0 == SetCurrentDirectoryW(szwCurrentDir) ) - { - free(szwTemp); - free(szwTemp2); - Fail("RemoveDirectoryW: Failed to set current directory to " - "\"non_empty_dir\" with SetCurrentDirectoryW.\n"); - } - - /* Try to remove non_empty_dir (shouldn't work) */ - bRc = RemoveDirectoryW(szwTemp); - if (bRc == TRUE) - { - free(szwTemp); - free(szwTemp2); - Fail("RemoveDirectoryW: shouldn't have been able to remove " - "the non empty directory \"non_empty_dir\"\n"); - } - - /* Go back to non_empty_dir and remove sub_dir */ - if( 0 == SetCurrentDirectoryW(szwSubDir) ) - { - free(szwTemp); - free(szwTemp2); - Fail("RemoveDirectoryW: Failed to set current directory to " - "\"non_empty_dir\" with SetCurrentDirectoryW.\n"); - } - - bRc = RemoveDirectoryW(szwTemp2); - if (bRc == FALSE) - { - free(szwTemp); - free(szwTemp2); - Fail("RemoveDirectoryW: unable to remove " - "directory \"sub_dir\"(error code %d)\n", - GetLastError()); - } - /* Make sure the directory was removed */ - if( -1 != GetFileAttributesW(szwTemp2) ) - { - Fail("RemoveDirectoryW: Able to get the attributes of " - "the removed directory\n"); - } - free(szwTemp2); - - /* Go back to parent of non_empty_dir and remove non_empty_dir */ - if( 0 == SetCurrentDirectoryW(szwCurrentDir) ) - { - free(szwTemp); - Fail("RemoveDirectoryW: Failed to set current directory to " - "\"..\non_empty_dir\" with SetCurrentDirectoryW.\n"); - } - bRc = RemoveDirectoryW(szwTemp); - if (bRc == FALSE) - { - free(szwTemp); - Fail("RemoveDirectoryW: unable to remove " - "the directory \"non_empty_dir\"(error code %d)\n", - GetLastError()); - } - /* Make sure the directory was removed */ - if( -1 != GetFileAttributesW(szwTemp) ) - { - Fail("RemoveDirectoryW: Able to get the attributes of " - "the removed directory\n"); - } - free(szwTemp); - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/RemoveDirectoryW.cpp b/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/RemoveDirectoryW.cpp new file mode 100644 index 0000000000..ec90528069 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/RemoveDirectoryW/test1/RemoveDirectoryW.cpp @@ -0,0 +1,282 @@ +// 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: RemoveDirectoryW.c +** +** Purpose: Tests the PAL implementation of the RemoveDirectoryW function. +** +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bRc = FALSE; + char szDirName[252]; + DWORD curDirLen; + WCHAR *szwTemp = NULL; + WCHAR *szwTemp2 = NULL; + WCHAR szwCurrentDir[MAX_PATH]; + WCHAR szwSubDir[MAX_PATH]; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* + * remove a NULL directory + */ + bRc = RemoveDirectoryW(NULL); + if (bRc != FALSE) + { + Fail("RemoveDirectoryW: Failed since it was able to remove a" + " NULL directory name\n"); + } + + /* + * remove a directory that does not exist + */ + szwTemp = convert("test_directory"); + bRc = RemoveDirectoryW(szwTemp); + if (bRc != FALSE) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed since it was able to remove" + " the non-existant directory \"test_directory\"\n"); + } + + /* + * remove a directory that exists + */ + bRc = CreateDirectoryW(szwTemp, NULL); + if (bRc != TRUE) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to create the directory " + "\"test_directory\" when it exists already.\n"); + } + bRc = RemoveDirectoryW(szwTemp); + if (bRc == FALSE) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to remove the directory " + "\"test_directory\" (error code %d)\n", + GetLastError()); + } + /* Make sure the directory was removed */ + if( -1 != GetFileAttributesW(szwTemp) ) + { + free(szwTemp); + Fail("RemoveDirectoryW: Able to get the attributes of " + "the removed directory\n"); + } + free(szwTemp); + + /* + * remove long directory names (245 characters) + */ + curDirLen = GetCurrentDirectoryA(0, NULL) + 1; + memset(szDirName, 0, 252); + memset(szDirName, 'a', 245 - curDirLen); + szwTemp = convert(szDirName); + bRc = CreateDirectoryW(szwTemp, NULL); + if (bRc == FALSE) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to create a directory name " + "245 chars long\n"); + } + bRc = RemoveDirectoryW(szwTemp); + if (bRc == FALSE) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to remove a 245 char " + "long directory\n"); + } + + /* Make sure the directory was removed */ + if( -1 != GetFileAttributesW(szwTemp) ) + { + free(szwTemp); + Fail("RemoveDirectoryW: Able to get the attributes of " + "the removed directory\n"); + } + free(szwTemp); + + /* + * directories with dots + */ + memset(szDirName, 0, 252); + sprintf_s(szDirName, _countof(szDirName), ".dotDirectory"); + szwTemp = convert(szDirName); + bRc = CreateDirectoryW(szwTemp, NULL); + if (bRc == FALSE) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to create \"%s\"\n", szDirName); + } + bRc = RemoveDirectoryW(szwTemp); + if (bRc == FALSE) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to remove \"%s\"\n", szDirName); + } + + /* Make sure the directory was removed */ + if( -1 != GetFileAttributesW(szwTemp) ) + { + free(szwTemp); + Fail("RemoveDirectoryW: Able to get the attributes of " + "the removed directory\n"); + } + free(szwTemp); + + /* + * Try calling RemoveDirectory with a file name + */ + memset(szDirName, 0, 252); + sprintf_s(szDirName, _countof(szDirName), "removedirectoryw.c"); + szwTemp = convert(szDirName); + + bRc = RemoveDirectoryW(szwTemp); + free(szwTemp); + if (bRc != FALSE) + { + Fail("RemoveDirectoryW: should have failed when " + "called with a valid file name" ); + } + + /* + * remove a non empty directory + * + * To test that, we'll first create non_empty_dir, we'll + * set the current dir to non_empty_dir in which we'll + * create sub_dir. We'll go back to the root of non_empty_dir + * and we'll try to delete it (it shouldn't work). + * After that we'll cleanup sub_dir and non_empty_dir + */ + + /* Get the current directory so it is easy to get back + to it later */ + if( 0 == GetCurrentDirectoryW(MAX_PATH, szwCurrentDir) ) + { + Fail("RemoveDirectoryW: Failed to get current directory " + "with GetCurrentDirectoryW.\n"); + } + + /* Create non_empty_dir */ + szwTemp = convert("non_empty_dir"); + bRc = CreateDirectoryW(szwTemp, NULL); + if (bRc != TRUE) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to create the directory " + "\"non_empty_dir\" when it exists already.\n"); + } + + if( 0 == SetCurrentDirectoryW(szwTemp) ) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to set current directory to " + "\"non_empty_dir\" with SetCurrentDirectoryW.\n"); + } + + /* Get the directory full path so it is easy to get back + to it later */ + if( 0 == GetCurrentDirectoryW(MAX_PATH, szwSubDir) ) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to get current directory " + "with GetCurrentDirectoryW.\n"); + } + + /* Create sub_dir */ + szwTemp2 = convert("sub_dir"); + bRc = CreateDirectoryW(szwTemp2, NULL); + if (bRc != TRUE) + { + free(szwTemp); + free(szwTemp2); + Fail("RemoveDirectoryW: Failed to create the directory " + "\"sub_dir\" when it exists already.\n"); + } + + /* Set the current dir to the parent of non_empty_dir/sub_dir */ + if( 0 == SetCurrentDirectoryW(szwCurrentDir) ) + { + free(szwTemp); + free(szwTemp2); + Fail("RemoveDirectoryW: Failed to set current directory to " + "\"non_empty_dir\" with SetCurrentDirectoryW.\n"); + } + + /* Try to remove non_empty_dir (shouldn't work) */ + bRc = RemoveDirectoryW(szwTemp); + if (bRc == TRUE) + { + free(szwTemp); + free(szwTemp2); + Fail("RemoveDirectoryW: shouldn't have been able to remove " + "the non empty directory \"non_empty_dir\"\n"); + } + + /* Go back to non_empty_dir and remove sub_dir */ + if( 0 == SetCurrentDirectoryW(szwSubDir) ) + { + free(szwTemp); + free(szwTemp2); + Fail("RemoveDirectoryW: Failed to set current directory to " + "\"non_empty_dir\" with SetCurrentDirectoryW.\n"); + } + + bRc = RemoveDirectoryW(szwTemp2); + if (bRc == FALSE) + { + free(szwTemp); + free(szwTemp2); + Fail("RemoveDirectoryW: unable to remove " + "directory \"sub_dir\"(error code %d)\n", + GetLastError()); + } + /* Make sure the directory was removed */ + if( -1 != GetFileAttributesW(szwTemp2) ) + { + Fail("RemoveDirectoryW: Able to get the attributes of " + "the removed directory\n"); + } + free(szwTemp2); + + /* Go back to parent of non_empty_dir and remove non_empty_dir */ + if( 0 == SetCurrentDirectoryW(szwCurrentDir) ) + { + free(szwTemp); + Fail("RemoveDirectoryW: Failed to set current directory to " + "\"..\non_empty_dir\" with SetCurrentDirectoryW.\n"); + } + bRc = RemoveDirectoryW(szwTemp); + if (bRc == FALSE) + { + free(szwTemp); + Fail("RemoveDirectoryW: unable to remove " + "the directory \"non_empty_dir\"(error code %d)\n", + GetLastError()); + } + /* Make sure the directory was removed */ + if( -1 != GetFileAttributesW(szwTemp) ) + { + Fail("RemoveDirectoryW: Able to get the attributes of " + "the removed directory\n"); + } + free(szwTemp); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SearchPathA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SearchPathA/test1/CMakeLists.txt index d1ac975d18..c020a86b61 100644 --- a/src/pal/tests/palsuite/file_io/SearchPathA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SearchPathA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SearchPathA.c + SearchPathA.cpp ) add_executable(paltest_searchpatha_test1 diff --git a/src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.c b/src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.c deleted file mode 100644 index ab9eecdebc..0000000000 --- a/src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.c +++ /dev/null @@ -1,144 +0,0 @@ -// 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: SearchPathA.c -** -** Purpose: Tests the PAL implementation of the SearchFileA function. -** -** -** TODO: Write a test where complete path is passed (say c:\?) -**===================================================================*/ -//SearchPath -// -//The SearchPath function searches for the specified file in the specified path. -// - - -#include -char* szDir = "."; - -char* szNoFileName = "333asdf"; -char* szNoFileNameExt = ".x77t"; - -char* szFileNameExists = "searchfile"; -char* szFileNameExtExists = ".txt"; - -char* szFileNameExistsWithExt = "searchfile.txt"; -char fileloc[_MAX_PATH]; - -void removeFileHelper(LPSTR pfile, int location) -{ - FILE *fp; - fp = fopen( pfile, "r"); - - if (fp != NULL) - { - if(fclose(fp)) - { - Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - - if(!DeleteFileA(pfile)) - { - Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - } - -} - - -void RemoveAll() -{ - removeFileHelper(fileloc, 1); -} - -int __cdecl main(int argc, char *argv[]) { - - char* lpPath = NULL; - char* lpFileName = NULL; - char* lpExtension = NULL; - DWORD nBufferLength = 0; - char lpBuffer[_MAX_PATH]; - char** lpFilePart = NULL; - DWORD error = 0; - DWORD result = 0; - - HANDLE hsearchfile; - char fname[_MAX_FNAME]; - char ext[_MAX_EXT]; - char fullPath[_MAX_DIR]; - char drive[_MAX_DRIVE]; - char dir[_MAX_DIR]; - - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - - /* Initalize the buffer. - */ - memset(fullPath, 0, _MAX_DIR); - - /* Get the full path to the library (DLL). - */ - - if ( NULL != _fullpath( fullPath, argv[0], _MAX_DIR )) { - _splitpath(fullPath,drive,dir,fname,ext); - _makepath(fullPath,drive,dir,"",""); - } else { - Fail("ERROR: conversion from relative path \" %s \" to absolute path failed. _fullpath returned NULL\n",argv[0]); - } - - memset(fileloc, 0, _MAX_PATH); - sprintf(fileloc, "%s%s", fullPath, szFileNameExistsWithExt); - - RemoveAll(); - - hsearchfile = CreateFileA(fileloc, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - - if (hsearchfile == INVALID_HANDLE_VALUE) - { - Trace("ERROR[%ul]: couldn't create %s\n", GetLastError(), fileloc); - return FAIL; - } - - CloseHandle(hsearchfile); - - // - // find a file that doesn't exist - // - ZeroMemory( lpBuffer, sizeof(lpBuffer)); - lpPath = fullPath; - lpFileName = szNoFileName; - lpExtension = NULL; - - if( SearchPathA( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart) != 0 ){ - error = GetLastError(); - Fail ("SearchPathA: ERROR1 -> Found invalid file[%s][%s][%s][%d]\n", lpPath, szNoFileName, szNoFileNameExt, error); - } - - // - // find a file that exists, when path is mentioned explicitly - // - ZeroMemory( lpBuffer, sizeof(lpBuffer)); - lpPath = fullPath; - lpFileName = szFileNameExistsWithExt; - lpExtension = NULL; - - result = SearchPathA( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart); - - if( result == 0 ){ - error = GetLastError(); - Fail ("SearchPathA: ERROR2 -> Did not Find valid file[%s][%s][%d]\n", lpPath, szFileNameExistsWithExt, error); - } - - RemoveAll(); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.cpp b/src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.cpp new file mode 100644 index 0000000000..57afdefc7b --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.cpp @@ -0,0 +1,139 @@ +// 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: SearchPathA.c +** +** Purpose: Tests the PAL implementation of the SearchFileA function. +** +** +** TODO: Write a test where complete path is passed (say c:\?) +**===================================================================*/ +//SearchPath +// +//The SearchPath function searches for the specified file in the specified path. +// + + +#include +char* szDir = "."; + +char* szNoFileName = "333asdf"; +char* szNoFileNameExt = ".x77t"; + +char* szFileNameExists = "searchfile"; +char* szFileNameExtExists = ".txt"; + +char* szFileNameExistsWithExt = "searchfile.txt"; +char fileloc[_MAX_PATH]; + +void removeFileHelper(LPSTR pfile, int location) +{ + FILE *fp; + fp = fopen( pfile, "r"); + + if (fp != NULL) + { + if(fclose(fp)) + { + Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + + if(!DeleteFileA(pfile)) + { + Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + } + +} + + +void RemoveAll() +{ + removeFileHelper(fileloc, 1); +} + +int __cdecl main(int argc, char *argv[]) { + + char* lpPath = NULL; + char* lpFileName = NULL; + char* lpExtension = NULL; + DWORD nBufferLength = 0; + char lpBuffer[_MAX_PATH]; + char** lpFilePart = NULL; + DWORD error = 0; + DWORD result = 0; + + HANDLE hsearchfile; + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + char fullPath[_MAX_DIR]; + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + + /* Initalize the buffer. + */ + memset(fullPath, 0, _MAX_DIR); + + if (GetTempPathA(_MAX_DIR, fullPath) == 0) + { + Fail("ERROR: GetTempPathA failed to get a path\n"); + } + + memset(fileloc, 0, _MAX_PATH); + sprintf_s(fileloc, _countof(fileloc), "%s%s", fullPath, szFileNameExistsWithExt); + + RemoveAll(); + + hsearchfile = CreateFileA(fileloc, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + + if (hsearchfile == INVALID_HANDLE_VALUE) + { + Trace("ERROR[%ul]: couldn't create %s\n", GetLastError(), fileloc); + return FAIL; + } + + CloseHandle(hsearchfile); + + // + // find a file that doesn't exist + // + ZeroMemory( lpBuffer, sizeof(lpBuffer)); + lpPath = fullPath; + lpFileName = szNoFileName; + lpExtension = NULL; + + if( SearchPathA( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart) != 0 ){ + error = GetLastError(); + Fail ("SearchPathA: ERROR1 -> Found invalid file[%s][%s][%s][%d]\n", lpPath, szNoFileName, szNoFileNameExt, error); + } + + // + // find a file that exists, when path is mentioned explicitly + // + ZeroMemory( lpBuffer, sizeof(lpBuffer)); + lpPath = fullPath; + lpFileName = szFileNameExistsWithExt; + lpExtension = NULL; + + result = SearchPathA( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart); + + if( result == 0 ){ + error = GetLastError(); + Fail ("SearchPathA: ERROR2 -> Did not Find valid file[%s][%s][%d]\n", lpPath, szFileNameExistsWithExt, error); + } + + RemoveAll(); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SearchPathW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SearchPathW/test1/CMakeLists.txt index d0c6252472..a77d875505 100644 --- a/src/pal/tests/palsuite/file_io/SearchPathW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SearchPathW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SearchPathW.c + SearchPathW.cpp ) add_executable(paltest_searchpathw_test1 diff --git a/src/pal/tests/palsuite/file_io/SearchPathW/test1/SearchPathW.c b/src/pal/tests/palsuite/file_io/SearchPathW/test1/SearchPathW.c deleted file mode 100644 index 2bc7694dc0..0000000000 --- a/src/pal/tests/palsuite/file_io/SearchPathW/test1/SearchPathW.c +++ /dev/null @@ -1,198 +0,0 @@ -// 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: SearchPathW.c -** -** Purpose: Tests the PAL implementation of the SearchFileW function. -** -** -** TODO: Write a test where complete path is passed (say c:\?) -**===================================================================*/ -//SearchPath -// -//The SearchPath function searches for the specified file in the specified path. -// -// -//DWORD SearchPath( -// LPCTSTR lpPath, -// LPCTSTR lpFileName, -// LPCTSTR lpExtension, -// DWORD nBufferLength, -// LPTSTR lpBuffer, -// LPTSTR* lpFilePart -//); -// -//Parameters -//lpPath -//[in] Pointer to a null-terminated string that specifies the path to be searched for the file. If this parameter is NULL, the function searches for a matching file in the following directories in the following sequence: -//The directory from which the application loaded. -//The current directory. -//The system directory. Use the GetSystemDirectory function to get the path of this directory. -//The 16-bit system directory. There is no function that retrieves the path of this directory, but it is searched. -//The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. -//The directories that are listed in the PATH environment variable. - -//lpFileName -//[in] Pointer to a null-terminated string that specifies the name of the file to search for. - -//lpExtension -//[in] Pointer to a null-terminated string that specifies an extension to be added to the file name when searching for the file. The first character of the file name extension must be a period (.). The extension is added only if the specified file name does not end with an extension. -//If a file name extension is not required or if the file name contains an extension, this parameter can be NULL. -// -//nBufferLength -//[in] Size of the buffer that receives the valid path and file name, in TCHARs. - -//lpBuffer -//[out] Pointer to the buffer that receives the path and file name of the file found. - -//lpFilePart -//[out] Pointer to the variable that receives the address (within lpBuffer) of the last component of the valid path and file name, which is the address of the character immediately following the final backslash (\) in the path. - -//Return Values -//If the function succeeds, the value returned is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character. If the return value is greater than nBufferLength, the value returned is the size of the buffer required to hold the path. -// -//If the function fails, the return value is zero. To get extended error information, call GetLastError. - - -#include -const char* szDir = "."; - -const char* szNoFileName = "333asdf"; -const char* szNoFileNameExt = ".x77t"; - -const char* szFileNameExists = "searchpathw"; -const char* szFileNameExtExists = ".c"; - -const char* szFileNameExistsWithExt = "searchpathw.c"; - -char fileloc[_MAX_PATH]; - -void removeFileHelper(LPSTR pfile, int location) -{ - FILE *fp; - fp = fopen( pfile, "r"); - - if (fp != NULL) - { - if(fclose(fp)) - { - Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - - if(!DeleteFileA(pfile)) - { - Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); - } - else - { - // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); - } - } - -} - -void RemoveAll() -{ - removeFileHelper(fileloc, 1); -} - -int __cdecl main(int argc, char *argv[]) { - - WCHAR* lpPath = NULL; - WCHAR* lpFileName = NULL; - WCHAR* lpExtension = NULL; - DWORD nBufferLength = 0; - WCHAR lpBuffer[_MAX_PATH]; - WCHAR** lpFilePart = NULL; - DWORD error = 0; - DWORD result = 0; - - HANDLE hsearchfile; - char fname[_MAX_FNAME]; - char ext[_MAX_EXT]; - char fullPath[_MAX_DIR]; - char drive[_MAX_DRIVE]; - char dir[_MAX_DIR]; - - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Initalize the buffer. - */ - memset(fullPath, 0, _MAX_DIR); - - /* Get the full path to the library (DLL). - */ - - if ( NULL != _fullpath( fullPath, argv[0], _MAX_DIR )) { - _splitpath(fullPath,drive,dir,fname,ext); - _makepath(fullPath,drive,dir,"",""); - } else { - Fail("ERROR: conversion from relative path \" %s \" to absolute path failed. _fullpath returned NULL\n",argv[0]); - } - - memset(fileloc, 0, _MAX_PATH); - sprintf(fileloc, "%s%s", fullPath, szFileNameExistsWithExt); - - RemoveAll(); - - hsearchfile = CreateFileA(fileloc, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, 0); - - if (hsearchfile == NULL) - { - Trace("ERROR[%ul]: couldn't create %s\n", GetLastError(), fileloc); - return FAIL; - } - - CloseHandle(hsearchfile); - - // - // find a file that doesn't exist - // - ZeroMemory( lpBuffer, sizeof(lpBuffer)); - lpPath = convert((LPSTR)fullPath); - lpFileName = convert((LPSTR)szNoFileName); - lpExtension = NULL; - - if( SearchPathW( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart) != 0 ){ - error = GetLastError(); - free(lpPath); - free(lpFileName); - Fail ("SearchPathW: ERROR1 -> Found invalid file[%s][%s][%s][%d]\n", lpPath, szNoFileName, szNoFileNameExt, error); - } - - free(lpPath); - free(lpFileName); - - // - // find a file that exists, when path is mentioned explicitly - // - ZeroMemory( lpBuffer, sizeof(lpBuffer)); - lpPath = convert((LPSTR)fullPath); - lpFileName = convert((LPSTR)szFileNameExistsWithExt); - lpExtension = NULL; - - result = SearchPathW( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart); - - if( result == 0 ){ - error = GetLastError(); - free(lpPath); - free(lpFileName); - Fail ("SearchPathA: ERROR2 -> Did not Find valid file[%s][%s][%d]\n", lpPath, szFileNameExistsWithExt, error); - } - - free(lpPath); - free(lpFileName); - - RemoveAll(); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SearchPathW/test1/SearchPathW.cpp b/src/pal/tests/palsuite/file_io/SearchPathW/test1/SearchPathW.cpp new file mode 100644 index 0000000000..6880a864cb --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SearchPathW/test1/SearchPathW.cpp @@ -0,0 +1,193 @@ +// 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: SearchPathW.c +** +** Purpose: Tests the PAL implementation of the SearchFileW function. +** +** +** TODO: Write a test where complete path is passed (say c:\?) +**===================================================================*/ +//SearchPath +// +//The SearchPath function searches for the specified file in the specified path. +// +// +//DWORD SearchPath( +// LPCTSTR lpPath, +// LPCTSTR lpFileName, +// LPCTSTR lpExtension, +// DWORD nBufferLength, +// LPTSTR lpBuffer, +// LPTSTR* lpFilePart +//); +// +//Parameters +//lpPath +//[in] Pointer to a null-terminated string that specifies the path to be searched for the file. If this parameter is NULL, the function searches for a matching file in the following directories in the following sequence: +//The directory from which the application loaded. +//The current directory. +//The system directory. Use the GetSystemDirectory function to get the path of this directory. +//The 16-bit system directory. There is no function that retrieves the path of this directory, but it is searched. +//The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. +//The directories that are listed in the PATH environment variable. + +//lpFileName +//[in] Pointer to a null-terminated string that specifies the name of the file to search for. + +//lpExtension +//[in] Pointer to a null-terminated string that specifies an extension to be added to the file name when searching for the file. The first character of the file name extension must be a period (.). The extension is added only if the specified file name does not end with an extension. +//If a file name extension is not required or if the file name contains an extension, this parameter can be NULL. +// +//nBufferLength +//[in] Size of the buffer that receives the valid path and file name, in TCHARs. + +//lpBuffer +//[out] Pointer to the buffer that receives the path and file name of the file found. + +//lpFilePart +//[out] Pointer to the variable that receives the address (within lpBuffer) of the last component of the valid path and file name, which is the address of the character immediately following the final backslash (\) in the path. + +//Return Values +//If the function succeeds, the value returned is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character. If the return value is greater than nBufferLength, the value returned is the size of the buffer required to hold the path. +// +//If the function fails, the return value is zero. To get extended error information, call GetLastError. + + +#include +const char* szDir = "."; + +const char* szNoFileName = "333asdf"; +const char* szNoFileNameExt = ".x77t"; + +const char* szFileNameExists = "searchpathw"; +const char* szFileNameExtExists = ".c"; + +const char* szFileNameExistsWithExt = "searchpathw.c"; + +char fileloc[_MAX_PATH]; + +void removeFileHelper(LPSTR pfile, int location) +{ + FILE *fp; + fp = fopen( pfile, "r"); + + if (fp != NULL) + { + if(fclose(fp)) + { + Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + + if(!DeleteFileA(pfile)) + { + Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + else + { + // Trace("Success: deleted file [%S], Error Code [%d], location [%d]\n", wfile, GetLastError(), location); + } + } + +} + +void RemoveAll() +{ + removeFileHelper(fileloc, 1); +} + +int __cdecl main(int argc, char *argv[]) { + + WCHAR* lpPath = NULL; + WCHAR* lpFileName = NULL; + WCHAR* lpExtension = NULL; + DWORD nBufferLength = 0; + WCHAR lpBuffer[_MAX_PATH]; + WCHAR** lpFilePart = NULL; + DWORD error = 0; + DWORD result = 0; + + HANDLE hsearchfile; + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + char fullPath[_MAX_DIR]; + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Initalize the buffer. + */ + memset(fullPath, 0, _MAX_DIR); + + if (GetTempPathA(_MAX_DIR, fullPath) == 0) + { + Fail("ERROR: GetTempPathA failed to get a path\n"); + } + + memset(fileloc, 0, _MAX_PATH); + sprintf_s(fileloc, _countof(fileloc), "%s%s", fullPath, szFileNameExistsWithExt); + + RemoveAll(); + + hsearchfile = CreateFileA(fileloc, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + + if (hsearchfile == NULL) + { + Trace("ERROR[%ul]: couldn't create %s\n", GetLastError(), fileloc); + return FAIL; + } + + CloseHandle(hsearchfile); + + // + // find a file that doesn't exist + // + ZeroMemory( lpBuffer, sizeof(lpBuffer)); + lpPath = convert((LPSTR)fullPath); + lpFileName = convert((LPSTR)szNoFileName); + lpExtension = NULL; + + if( SearchPathW( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart) != 0 ){ + error = GetLastError(); + free(lpPath); + free(lpFileName); + Fail ("SearchPathW: ERROR1 -> Found invalid file[%s][%s][%s][%d]\n", lpPath, szNoFileName, szNoFileNameExt, error); + } + + free(lpPath); + free(lpFileName); + + // + // find a file that exists, when path is mentioned explicitly + // + ZeroMemory( lpBuffer, sizeof(lpBuffer)); + lpPath = convert((LPSTR)fullPath); + lpFileName = convert((LPSTR)szFileNameExistsWithExt); + lpExtension = NULL; + + result = SearchPathW( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart); + + if( result == 0 ){ + error = GetLastError(); + free(lpPath); + free(lpFileName); + Fail ("SearchPathA: ERROR2 -> Did not Find valid file[%s][%s][%d]\n", lpPath, szFileNameExistsWithExt, error); + } + + free(lpPath); + free(lpFileName); + + RemoveAll(); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/CMakeLists.txt index 7376b22226..5d0da64ba7 100644 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetCurrentDirectoryA.c + SetCurrentDirectoryA.cpp ) add_executable(paltest_setcurrentdirectorya_test1 diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/SetCurrentDirectoryA.c b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/SetCurrentDirectoryA.c deleted file mode 100644 index c07a62412b..0000000000 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/SetCurrentDirectoryA.c +++ /dev/null @@ -1,215 +0,0 @@ -// 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: SetCurrentDirectoryA.c (test 1) -** -** Purpose: Tests the PAL implementation of the SetCurrentDirectoryA function. -** -** -**===================================================================*/ - -#include - - - -/* In order to avoid the "chicken and egg" scenario, this is another - method of getting the current directory. GetFullPathNameA is called with - a dummy file name and then the file name is stripped off leaving the - current working directory -*/ - -BOOL GetCurrentDir(char* szCurrentDir) -{ - const char* szFileName = "blah"; - DWORD dwRc = 0; - char szReturnedPath[_MAX_DIR+1]; - LPSTR pPathPtr; - size_t nCount = 0; - - /* use GetFullPathNameA to to get the current path by stripping - the file name off the end */ - memset(szReturnedPath, 0, (_MAX_DIR+1)); - dwRc = GetFullPathNameA(szFileName, - _MAX_DIR, - szReturnedPath, - &pPathPtr); - - if (dwRc == 0) - { - /* GetFullPathNameA failed */ - Trace("SetCurrentDirectoryA: ERROR -> GetFullPathNameA failed " - "with error code: %ld.\n", GetLastError()); - return(FALSE); - } - - /* now strip the file name from the full path to get the current path */ - nCount = strlen(szReturnedPath) - strlen(szFileName); - memset(szCurrentDir, 0, (_MAX_DIR+1)); - strncpy(szCurrentDir, szReturnedPath, nCount); - - return(TRUE); -} - - - -int __cdecl main(int argc, char *argv[]) -{ - const char* szDirName = "testing"; - /* directory name longer than MAX_PATH characters */ - char szLongDirName[MAX_LONGPATH+1]; - char szNewDir[_MAX_DIR+1]; - char szBuiltDir[_MAX_DIR+1]; - char szHomeDir[_MAX_DIR+1]; - WCHAR* szwPtr = NULL; - - memset(szLongDirName, 'a', MAX_LONGPATH+1); - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* remove the directory just in case a previous run of the test didn't */ - szwPtr = convert((LPSTR)szDirName); - - /* clean up. Remove the directory - * if it exists */ - RemoveDirectoryW(szwPtr); - - /* create a temp directory off the current directory */ - if (CreateDirectoryA(szDirName, NULL) != TRUE) - { - free(szwPtr); - Fail("SetCurrentDirectoryA: ERROR -> CreateDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - - /* find out what the current "home" directory is */ - memset(szHomeDir, 0, (_MAX_DIR+1)); - if(GetCurrentDir(szHomeDir) != TRUE) - { - if (!RemoveDirectoryW(szwPtr)) - { - Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - free(szwPtr); - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* set the current directory to the temp directory */ - - if (SetCurrentDirectoryA(szDirName) != TRUE) - { - Trace("SetCurrentDirectoryA: ERROR -> Unable to set current " - "directory. Failed with error code: %ld.\n", GetLastError()); - if (!RemoveDirectoryW(szwPtr)) - { - Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - free(szwPtr); - Fail(""); - } - - /* append the temp name to the "home" directory */ - memset(szBuiltDir, 0, (_MAX_DIR+1)); -#if WIN32 - sprintf(szBuiltDir,"%s%s\\", szHomeDir, szDirName); -#else - sprintf(szBuiltDir,"%s%s/", szHomeDir, szDirName); -#endif - - /* get the new current directory */ - memset(szNewDir, 0, (_MAX_DIR+1)); - if(GetCurrentDir(szNewDir) != TRUE) - { - if (!RemoveDirectoryW(szwPtr)) - { - Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - free(szwPtr); - PAL_TerminateEx(FAIL); - return FAIL; - } - - /*compare the new current dir to the compiled current dir */ - if (strncmp(szNewDir, szBuiltDir, strlen(szNewDir)) != 0) - { - if (!RemoveDirectoryW(szwPtr)) - { - Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - free(szwPtr); - Fail("SetCurrentDirectoryA: ERROR -> The set directory \"%s\" does not" - " compare to the built directory \"%s\".\n", - szNewDir, - szBuiltDir); - } - - - - /* set the current dir back to the original */ - if (SetCurrentDirectoryA(szHomeDir) != TRUE) - { - Trace("SetCurrentDirectoryA: ERROR -> Unable to set current " - "directory. Failed with error code: %ld.\n", GetLastError()); - if (!RemoveDirectoryW(szwPtr)) - { - Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - free(szwPtr); - Fail(""); - } - - - /* get the new current directory */ - memset(szNewDir, 0, sizeof(char)*(_MAX_DIR+1)); - if(GetCurrentDir(szNewDir) != TRUE) - { - if (!RemoveDirectoryW(szwPtr)) - { - Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - free(szwPtr); - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* ensure it compares to the "home" directory which is where - we should be now */ - if (strncmp(szNewDir, szHomeDir, strlen(szNewDir)) != 0) - { - if (!RemoveDirectoryW(szwPtr)) - { - Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - free(szwPtr); - Fail("SetCurrentDirectoryA: ERROR -> The set directory does not " - "compare to the built directory.\n"); - } - - - /* clean up */ - if (!RemoveDirectoryW(szwPtr)) - { - free(szwPtr); - Fail("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - } - - free(szwPtr); - PAL_Terminate(); - - return PASS; -} - - diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/SetCurrentDirectoryA.cpp b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/SetCurrentDirectoryA.cpp new file mode 100644 index 0000000000..f227aa3268 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test1/SetCurrentDirectoryA.cpp @@ -0,0 +1,215 @@ +// 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: SetCurrentDirectoryA.c (test 1) +** +** Purpose: Tests the PAL implementation of the SetCurrentDirectoryA function. +** +** +**===================================================================*/ + +#include + + + +/* In order to avoid the "chicken and egg" scenario, this is another + method of getting the current directory. GetFullPathNameA is called with + a dummy file name and then the file name is stripped off leaving the + current working directory +*/ + +BOOL GetCurrentDir(char* szCurrentDir) +{ + const char* szFileName = "blah"; + DWORD dwRc = 0; + char szReturnedPath[_MAX_DIR+1]; + LPSTR pPathPtr; + size_t nCount = 0; + + /* use GetFullPathNameA to to get the current path by stripping + the file name off the end */ + memset(szReturnedPath, 0, (_MAX_DIR+1)); + dwRc = GetFullPathNameA(szFileName, + _MAX_DIR, + szReturnedPath, + &pPathPtr); + + if (dwRc == 0) + { + /* GetFullPathNameA failed */ + Trace("SetCurrentDirectoryA: ERROR -> GetFullPathNameA failed " + "with error code: %ld.\n", GetLastError()); + return(FALSE); + } + + /* now strip the file name from the full path to get the current path */ + nCount = strlen(szReturnedPath) - strlen(szFileName); + memset(szCurrentDir, 0, (_MAX_DIR+1)); + strncpy(szCurrentDir, szReturnedPath, nCount); + + return(TRUE); +} + + + +int __cdecl main(int argc, char *argv[]) +{ + const char* szDirName = "testing"; + /* directory name longer than MAX_PATH characters */ + char szLongDirName[MAX_LONGPATH+1]; + char szNewDir[_MAX_DIR+1]; + char szBuiltDir[_MAX_DIR+1]; + char szHomeDir[_MAX_DIR+1]; + WCHAR* szwPtr = NULL; + + memset(szLongDirName, 'a', MAX_LONGPATH+1); + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* remove the directory just in case a previous run of the test didn't */ + szwPtr = convert((LPSTR)szDirName); + + /* clean up. Remove the directory + * if it exists */ + RemoveDirectoryW(szwPtr); + + /* create a temp directory off the current directory */ + if (CreateDirectoryA(szDirName, NULL) != TRUE) + { + free(szwPtr); + Fail("SetCurrentDirectoryA: ERROR -> CreateDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + + /* find out what the current "home" directory is */ + memset(szHomeDir, 0, (_MAX_DIR+1)); + if(GetCurrentDir(szHomeDir) != TRUE) + { + if (!RemoveDirectoryW(szwPtr)) + { + Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + free(szwPtr); + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* set the current directory to the temp directory */ + + if (SetCurrentDirectoryA(szDirName) != TRUE) + { + Trace("SetCurrentDirectoryA: ERROR -> Unable to set current " + "directory. Failed with error code: %ld.\n", GetLastError()); + if (!RemoveDirectoryW(szwPtr)) + { + Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + free(szwPtr); + Fail(""); + } + + /* append the temp name to the "home" directory */ + memset(szBuiltDir, 0, (_MAX_DIR+1)); +#if WIN32 + sprintf_s(szBuiltDir, _countof(szBuiltDir),"%s%s\\", szHomeDir, szDirName); +#else + sprintf_s(szBuiltDir, _countof(szBuiltDir),"%s%s/", szHomeDir, szDirName); +#endif + + /* get the new current directory */ + memset(szNewDir, 0, (_MAX_DIR+1)); + if(GetCurrentDir(szNewDir) != TRUE) + { + if (!RemoveDirectoryW(szwPtr)) + { + Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + free(szwPtr); + PAL_TerminateEx(FAIL); + return FAIL; + } + + /*compare the new current dir to the compiled current dir */ + if (strncmp(szNewDir, szBuiltDir, strlen(szNewDir)) != 0) + { + if (!RemoveDirectoryW(szwPtr)) + { + Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + free(szwPtr); + Fail("SetCurrentDirectoryA: ERROR -> The set directory \"%s\" does not" + " compare to the built directory \"%s\".\n", + szNewDir, + szBuiltDir); + } + + + + /* set the current dir back to the original */ + if (SetCurrentDirectoryA(szHomeDir) != TRUE) + { + Trace("SetCurrentDirectoryA: ERROR -> Unable to set current " + "directory. Failed with error code: %ld.\n", GetLastError()); + if (!RemoveDirectoryW(szwPtr)) + { + Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + free(szwPtr); + Fail(""); + } + + + /* get the new current directory */ + memset(szNewDir, 0, sizeof(char)*(_MAX_DIR+1)); + if(GetCurrentDir(szNewDir) != TRUE) + { + if (!RemoveDirectoryW(szwPtr)) + { + Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + free(szwPtr); + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* ensure it compares to the "home" directory which is where + we should be now */ + if (strncmp(szNewDir, szHomeDir, strlen(szNewDir)) != 0) + { + if (!RemoveDirectoryW(szwPtr)) + { + Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + free(szwPtr); + Fail("SetCurrentDirectoryA: ERROR -> The set directory does not " + "compare to the built directory.\n"); + } + + + /* clean up */ + if (!RemoveDirectoryW(szwPtr)) + { + free(szwPtr); + Fail("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + } + + free(szwPtr); + PAL_Terminate(); + + return PASS; +} + + diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/CMakeLists.txt index 7c9caf8081..243e80b9a4 100644 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - setcurrentdirectorya.c + setcurrentdirectorya.cpp ) add_executable(paltest_setcurrentdirectorya_test2 diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/setcurrentdirectorya.c b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/setcurrentdirectorya.c deleted file mode 100644 index 415dbbf045..0000000000 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/setcurrentdirectorya.c +++ /dev/null @@ -1,142 +0,0 @@ -// 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: SetCurrentDirectoryA.c (test 2) -** -** Purpose: Tests the PAL implementation of the SetCurrentDirectoryA function -** by setting the current directory with ../ -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - const char szDirName[MAX_PATH] = "testing"; - char szBuiltDir[_MAX_DIR+1]; - char szHomeDirBefore[_MAX_DIR+1]; - char szHomeDirAfter[_MAX_DIR+1]; - WCHAR* szwPtr = NULL; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a temp directory off the current directory */ - szwPtr = convert((LPSTR)szDirName); - - if (CreateDirectoryA(szDirName, NULL) != TRUE) - { - free(szwPtr); - Fail("Unexpected error: CreateDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - - /* find out what the current "home" directory is */ - memset(szHomeDirBefore, 0, (_MAX_DIR+1)); - - if( 0 == GetCurrentDirectoryA((_MAX_DIR+1), szHomeDirBefore) ) - { - Trace("Unexpected error: Unable to get current directory " - "with GetCurrentDirectoryA that returned %ld\n", - GetLastError()); - - if (!RemoveDirectoryW(szwPtr)) - { - Trace("Unexpected error: RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - free(szwPtr); - - Fail(""); - } - - /* append the temp name to the "home" directory */ - memset(szBuiltDir, 0, (_MAX_DIR+1)); -#if WIN32 - sprintf(szBuiltDir,"%s\\..\\", szDirName); -#else - sprintf(szBuiltDir,"%s/../", szDirName); -#endif - - - /* set the current directory to the temp directory */ - if (SetCurrentDirectoryA(szBuiltDir) != TRUE) - { - Trace("ERROR: Unable to set current " - "directory to %s. Failed with error code: %ld.\n", - szBuiltDir, - GetLastError()); - - if (!RemoveDirectoryW(szwPtr)) - { - Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - free(szwPtr); - Fail(""); - } - - /* find out what the current "home" directory is */ - memset(szHomeDirAfter, 0, (_MAX_DIR+1)); - - if( 0 == GetCurrentDirectoryA((_MAX_DIR+1), szHomeDirAfter) ) - { - Trace("Unexpected error: Unable to get current directory " - "with GetCurrentDirectoryA that returned %ld\n", - GetLastError()); - - if (!RemoveDirectoryW(szwPtr)) - { - Trace("Unexpected error: RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - free(szwPtr); - - Fail(""); - } - - /*compare the new current dir to the compiled current dir */ - if (strncmp(szHomeDirBefore, szHomeDirAfter, strlen(szHomeDirBefore)) != 0) - { - Trace("ERROR: The set directory \"%s\" does not " - "compare to the built directory \"%s\".\n", - szHomeDirAfter, - szHomeDirBefore); - - if (!RemoveDirectoryW(szwPtr)) - { - Trace("Unexpected error: RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - free(szwPtr); - Fail(""); - } - - /* clean up */ - if (!RemoveDirectoryW(szwPtr)) - { - free(szwPtr); - Fail("Unexpected error: RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - - free(szwPtr); - PAL_Terminate(); - - return PASS; -} - - diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/setcurrentdirectorya.cpp b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/setcurrentdirectorya.cpp new file mode 100644 index 0000000000..4b1c1c8790 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test2/setcurrentdirectorya.cpp @@ -0,0 +1,142 @@ +// 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: SetCurrentDirectoryA.c (test 2) +** +** Purpose: Tests the PAL implementation of the SetCurrentDirectoryA function +** by setting the current directory with ../ +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + const char szDirName[MAX_PATH] = "testing"; + char szBuiltDir[_MAX_DIR+1]; + char szHomeDirBefore[_MAX_DIR+1]; + char szHomeDirAfter[_MAX_DIR+1]; + WCHAR* szwPtr = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a temp directory off the current directory */ + szwPtr = convert((LPSTR)szDirName); + + if (CreateDirectoryA(szDirName, NULL) != TRUE) + { + free(szwPtr); + Fail("Unexpected error: CreateDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + + /* find out what the current "home" directory is */ + memset(szHomeDirBefore, 0, (_MAX_DIR+1)); + + if( 0 == GetCurrentDirectoryA((_MAX_DIR+1), szHomeDirBefore) ) + { + Trace("Unexpected error: Unable to get current directory " + "with GetCurrentDirectoryA that returned %ld\n", + GetLastError()); + + if (!RemoveDirectoryW(szwPtr)) + { + Trace("Unexpected error: RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + free(szwPtr); + + Fail(""); + } + + /* append the temp name to the "home" directory */ + memset(szBuiltDir, 0, (_MAX_DIR+1)); +#if WIN32 + sprintf_s(szBuiltDir, _countof(szBuiltDir),"%s\\..\\", szDirName); +#else + sprintf_s(szBuiltDir, _countof(szBuiltDir),"%s/../", szDirName); +#endif + + + /* set the current directory to the temp directory */ + if (SetCurrentDirectoryA(szBuiltDir) != TRUE) + { + Trace("ERROR: Unable to set current " + "directory to %s. Failed with error code: %ld.\n", + szBuiltDir, + GetLastError()); + + if (!RemoveDirectoryW(szwPtr)) + { + Trace("SetCurrentDirectoryA: ERROR -> RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + free(szwPtr); + Fail(""); + } + + /* find out what the current "home" directory is */ + memset(szHomeDirAfter, 0, (_MAX_DIR+1)); + + if( 0 == GetCurrentDirectoryA((_MAX_DIR+1), szHomeDirAfter) ) + { + Trace("Unexpected error: Unable to get current directory " + "with GetCurrentDirectoryA that returned %ld\n", + GetLastError()); + + if (!RemoveDirectoryW(szwPtr)) + { + Trace("Unexpected error: RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + free(szwPtr); + + Fail(""); + } + + /*compare the new current dir to the compiled current dir */ + if (strncmp(szHomeDirBefore, szHomeDirAfter, strlen(szHomeDirBefore)) != 0) + { + Trace("ERROR: The set directory \"%s\" does not " + "compare to the built directory \"%s\".\n", + szHomeDirAfter, + szHomeDirBefore); + + if (!RemoveDirectoryW(szwPtr)) + { + Trace("Unexpected error: RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + free(szwPtr); + Fail(""); + } + + /* clean up */ + if (!RemoveDirectoryW(szwPtr)) + { + free(szwPtr); + Fail("Unexpected error: RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + + free(szwPtr); + PAL_Terminate(); + + return PASS; +} + + diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/CMakeLists.txt index 57d3577d8f..8560ff0187 100644 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - setcurrentdirectorya.c + setcurrentdirectorya.cpp ) add_executable(paltest_setcurrentdirectorya_test3 diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/setcurrentdirectorya.c b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/setcurrentdirectorya.c deleted file mode 100644 index a23a7a6314..0000000000 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/setcurrentdirectorya.c +++ /dev/null @@ -1,56 +0,0 @@ -// 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: SetCurrentDirectoryA.c (test 3) -** -** Purpose: Try calling SetCurrentDirectoryA with an invalid path, -** with a valid filename and with NULL -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - const char szDirName[MAX_PATH] = "testing"; - const char szFileName[MAX_PATH] = "setcurrentdirectorya.c"; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* set the current directory to an unexistant folder */ - if (0 != SetCurrentDirectoryA(szDirName)) - { - Fail("ERROR: SetCurrentDirectoryA should have failed " - "when trying to set the current directory to " - "an invalid folder\n"); - } - - /* set the current directory to an unexistant folder */ - if (0 != SetCurrentDirectoryA(szFileName)) - { - Fail("ERROR: SetCurrentDirectoryA should have failed " - "when trying to set the current directory to " - "a valid file name\n"); - } - - /* set the current directory to NULL */ - if (0 != SetCurrentDirectoryA(NULL)) - { - Fail("ERROR: SetCurrentDirectoryA should have failed " - "when trying to set the current directory to " - "NULL\n"); - } - - PAL_Terminate(); - - return PASS; -} - - diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/setcurrentdirectorya.cpp b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/setcurrentdirectorya.cpp new file mode 100644 index 0000000000..a23a7a6314 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryA/test3/setcurrentdirectorya.cpp @@ -0,0 +1,56 @@ +// 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: SetCurrentDirectoryA.c (test 3) +** +** Purpose: Try calling SetCurrentDirectoryA with an invalid path, +** with a valid filename and with NULL +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + const char szDirName[MAX_PATH] = "testing"; + const char szFileName[MAX_PATH] = "setcurrentdirectorya.c"; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* set the current directory to an unexistant folder */ + if (0 != SetCurrentDirectoryA(szDirName)) + { + Fail("ERROR: SetCurrentDirectoryA should have failed " + "when trying to set the current directory to " + "an invalid folder\n"); + } + + /* set the current directory to an unexistant folder */ + if (0 != SetCurrentDirectoryA(szFileName)) + { + Fail("ERROR: SetCurrentDirectoryA should have failed " + "when trying to set the current directory to " + "a valid file name\n"); + } + + /* set the current directory to NULL */ + if (0 != SetCurrentDirectoryA(NULL)) + { + Fail("ERROR: SetCurrentDirectoryA should have failed " + "when trying to set the current directory to " + "NULL\n"); + } + + PAL_Terminate(); + + return PASS; +} + + diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/CMakeLists.txt index a0c1dff62a..9149221008 100644 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetCurrentDirectoryW.c + SetCurrentDirectoryW.cpp ) add_executable(paltest_setcurrentdirectoryw_test1 diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/SetCurrentDirectoryW.c b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/SetCurrentDirectoryW.c deleted file mode 100644 index 257d016ffb..0000000000 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/SetCurrentDirectoryW.c +++ /dev/null @@ -1,178 +0,0 @@ -// 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: SetCurrentDirectoryW.c (test 1) -** -** Purpose: Tests the PAL implementation of the SetCurrentDirectoryW function. -** -** -**===================================================================*/ - -#include - -const char* szFileName = "blah"; -const char* szDirName = "testing"; - - -// In order to avoid the "chicken and egg" scenario, this is another -// method of getting the current directory. GetFullPathNameW is called with -// a dummy file name and then the file name is stripped off leaving the -// current working directory -BOOL GetCurrentDir(WCHAR* szwCurrentDir) -{ - DWORD dwRc = 0; - WCHAR szwReturnedPath[_MAX_DIR+1]; - LPWSTR pPathPtr; - WCHAR* szwFileName = NULL; - WCHAR* szwDirName = NULL; - int nCount = 0; - - // use GetFullPathName to to get the current path by stripping - // the file name off the end - memset(szwReturnedPath, 0, sizeof(WCHAR)*(_MAX_DIR+1)); - szwFileName = convert((char*)szFileName); - dwRc = GetFullPathNameW(szwFileName, - _MAX_DIR, - szwReturnedPath, - &pPathPtr); - - if (dwRc == 0) - { - // GetFullPathName failed - Trace("SetCurrentDirectoryW: ERROR -> GetFullPathNameW failed " - "with error code: %ld.\n", GetLastError()); - RemoveDirectoryW(szwDirName); - free(szwFileName); - return(FALSE); - } - - // now strip the file name from the full path to get the current path - nCount = lstrlenW(szwReturnedPath) - lstrlenW(szwFileName); - memset(szwCurrentDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); - lstrcpynW(szwCurrentDir, szwReturnedPath, nCount); - - free(szwFileName); - return(TRUE); -} - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR* szwDirName = NULL; - WCHAR szwNewDir[_MAX_DIR+1]; - WCHAR szwBuiltDir[_MAX_DIR+1]; - WCHAR szwHomeDir[_MAX_DIR+1]; -#if WIN32 - WCHAR szwSlash[] = {'\\','\0'}; -#else - WCHAR szwSlash[] = {'/','\0'}; -#endif - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // remove the directory just in case a previous run of the test didn't - szwDirName = convert((char*)szDirName); - RemoveDirectoryW(szwDirName); - - // create a temp directory off the current directory - if (CreateDirectoryW(szwDirName, NULL) != TRUE) - { - Trace("SetCurrentDirectoryW: ERROR -> CreateDirectoryW failed " - "with error code: %ld.\n", GetLastError()); - RemoveDirectoryW(szwDirName); - free(szwDirName); - Fail(""); - } - - // find out what the current "home" directory is - memset(szwHomeDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); - if(GetCurrentDir(szwHomeDir) != TRUE) - { - RemoveDirectoryW(szwDirName); - free(szwDirName); - PAL_TerminateEx(FAIL); - return FAIL; - } - - // set the current directory to the temp directory - if (SetCurrentDirectoryW(szwDirName) != TRUE) - { - Trace("SetCurrentDirectoryW: ERROR -> Unable to set current " - "directory. Failed with error code: %ld.\n", GetLastError()); - RemoveDirectoryW(szwDirName); - free(szwDirName); - Fail(""); - } - - // append the temp name to the "home" directory - memset(szwBuiltDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); - wcscpy(szwBuiltDir, szwHomeDir); - wcscat(szwBuiltDir, szwSlash); - wcscat(szwBuiltDir, szwDirName); - - // get the new current directory - memset(szwNewDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); - if(GetCurrentDir(szwNewDir) != TRUE) - { - RemoveDirectoryW(szwDirName); - free(szwDirName); - PAL_TerminateEx(FAIL); - return FAIL; - } - - // compare the new current dir to the compiled current dir - if (wcsncmp(szwNewDir, szwBuiltDir, wcslen(szwNewDir)) != 0) - { - RemoveDirectoryW(szwDirName); - free(szwDirName); - Fail("SetCurrentDirectoryW: ERROR -> The set directory does not " - "compare to the built directory.\n"); - } - - - - // set the current dir back to the original - if (SetCurrentDirectoryW(szwHomeDir) != TRUE) - { - Trace("SetCurrentDirectoryW: ERROR -> Unable to set current " - "directory. Failed with error code: %ld.\n", GetLastError()); - RemoveDirectoryW(szwDirName); - free(szwDirName); - Fail(""); - } - - - // get the new current directory - memset(szwNewDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); - if(GetCurrentDir(szwNewDir) != TRUE) - { - RemoveDirectoryW(szwDirName); - free(szwDirName); - PAL_TerminateEx(FAIL); - return FAIL; - } - - // ensure it compares to the "home" directory which is where - // we should be now - if (wcsncmp(szwNewDir, szwHomeDir, wcslen(szwNewDir)) != 0) - { - RemoveDirectoryW(szwDirName); - free(szwDirName); - Fail("SetCurrentDirectoryW: ERROR -> The set directory does not " - "compare to the built directory.\n"); - } - - - RemoveDirectoryW(szwDirName); - free(szwDirName); - PAL_Terminate(); - - return PASS; -} - - diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/SetCurrentDirectoryW.cpp b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/SetCurrentDirectoryW.cpp new file mode 100644 index 0000000000..e10f2ea8a1 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test1/SetCurrentDirectoryW.cpp @@ -0,0 +1,178 @@ +// 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: SetCurrentDirectoryW.c (test 1) +** +** Purpose: Tests the PAL implementation of the SetCurrentDirectoryW function. +** +** +**===================================================================*/ + +#include + +const char* szFileName = "blah"; +const char* szDirName = "testing"; + + +// In order to avoid the "chicken and egg" scenario, this is another +// method of getting the current directory. GetFullPathNameW is called with +// a dummy file name and then the file name is stripped off leaving the +// current working directory +BOOL GetCurrentDir(WCHAR* szwCurrentDir) +{ + DWORD dwRc = 0; + WCHAR szwReturnedPath[_MAX_DIR+1]; + LPWSTR pPathPtr; + WCHAR* szwFileName = NULL; + WCHAR* szwDirName = NULL; + int nCount = 0; + + // use GetFullPathName to to get the current path by stripping + // the file name off the end + memset(szwReturnedPath, 0, sizeof(WCHAR)*(_MAX_DIR+1)); + szwFileName = convert((char*)szFileName); + dwRc = GetFullPathNameW(szwFileName, + _MAX_DIR, + szwReturnedPath, + &pPathPtr); + + if (dwRc == 0) + { + // GetFullPathName failed + Trace("SetCurrentDirectoryW: ERROR -> GetFullPathNameW failed " + "with error code: %ld.\n", GetLastError()); + RemoveDirectoryW(szwDirName); + free(szwFileName); + return(FALSE); + } + + // now strip the file name from the full path to get the current path + nCount = lstrlenW(szwReturnedPath) - lstrlenW(szwFileName); + memset(szwCurrentDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); + wcsncpy(szwCurrentDir, szwReturnedPath, nCount - 1); + + free(szwFileName); + return(TRUE); +} + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR* szwDirName = NULL; + WCHAR szwNewDir[_MAX_DIR+1]; + WCHAR szwBuiltDir[_MAX_DIR+1]; + WCHAR szwHomeDir[_MAX_DIR+1]; +#if WIN32 + WCHAR szwSlash[] = {'\\','\0'}; +#else + WCHAR szwSlash[] = {'/','\0'}; +#endif + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // remove the directory just in case a previous run of the test didn't + szwDirName = convert((char*)szDirName); + RemoveDirectoryW(szwDirName); + + // create a temp directory off the current directory + if (CreateDirectoryW(szwDirName, NULL) != TRUE) + { + Trace("SetCurrentDirectoryW: ERROR -> CreateDirectoryW failed " + "with error code: %ld.\n", GetLastError()); + RemoveDirectoryW(szwDirName); + free(szwDirName); + Fail(""); + } + + // find out what the current "home" directory is + memset(szwHomeDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); + if(GetCurrentDir(szwHomeDir) != TRUE) + { + RemoveDirectoryW(szwDirName); + free(szwDirName); + PAL_TerminateEx(FAIL); + return FAIL; + } + + // set the current directory to the temp directory + if (SetCurrentDirectoryW(szwDirName) != TRUE) + { + Trace("SetCurrentDirectoryW: ERROR -> Unable to set current " + "directory. Failed with error code: %ld.\n", GetLastError()); + RemoveDirectoryW(szwDirName); + free(szwDirName); + Fail(""); + } + + // append the temp name to the "home" directory + memset(szwBuiltDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); + wcscpy(szwBuiltDir, szwHomeDir); + wcscat(szwBuiltDir, szwSlash); + wcscat(szwBuiltDir, szwDirName); + + // get the new current directory + memset(szwNewDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); + if(GetCurrentDir(szwNewDir) != TRUE) + { + RemoveDirectoryW(szwDirName); + free(szwDirName); + PAL_TerminateEx(FAIL); + return FAIL; + } + + // compare the new current dir to the compiled current dir + if (wcsncmp(szwNewDir, szwBuiltDir, wcslen(szwNewDir)) != 0) + { + RemoveDirectoryW(szwDirName); + free(szwDirName); + Fail("SetCurrentDirectoryW: ERROR -> The set directory does not " + "compare to the built directory.\n"); + } + + + + // set the current dir back to the original + if (SetCurrentDirectoryW(szwHomeDir) != TRUE) + { + Trace("SetCurrentDirectoryW: ERROR -> Unable to set current " + "directory. Failed with error code: %ld.\n", GetLastError()); + RemoveDirectoryW(szwDirName); + free(szwDirName); + Fail(""); + } + + + // get the new current directory + memset(szwNewDir, 0, sizeof(WCHAR)*(_MAX_DIR+1)); + if(GetCurrentDir(szwNewDir) != TRUE) + { + RemoveDirectoryW(szwDirName); + free(szwDirName); + PAL_TerminateEx(FAIL); + return FAIL; + } + + // ensure it compares to the "home" directory which is where + // we should be now + if (wcsncmp(szwNewDir, szwHomeDir, wcslen(szwNewDir)) != 0) + { + RemoveDirectoryW(szwDirName); + free(szwDirName); + Fail("SetCurrentDirectoryW: ERROR -> The set directory does not " + "compare to the built directory.\n"); + } + + + RemoveDirectoryW(szwDirName); + free(szwDirName); + PAL_Terminate(); + + return PASS; +} + + diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/CMakeLists.txt index a032462d19..455ddc828d 100644 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - setcurrentdirectoryw.c + setcurrentdirectoryw.cpp ) add_executable(paltest_setcurrentdirectoryw_test2 diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/setcurrentdirectoryw.c b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/setcurrentdirectoryw.c deleted file mode 100644 index 7e3d7b785f..0000000000 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/setcurrentdirectoryw.c +++ /dev/null @@ -1,147 +0,0 @@ -// 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: SetCurrentDirectoryW.c (test 2) -** -** Purpose: Tests the PAL implementation of the SetCurrentDirectoryW function -** by setting the current directory with ../ -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - const char szDirName[MAX_PATH] = "testing"; - char szBuiltDir[MAX_PATH]; - WCHAR* szwBuiltDir = NULL; - WCHAR szwHomeDirBefore[MAX_PATH]; - WCHAR szwHomeDirAfter[MAX_PATH]; - WCHAR* szwPtr = NULL; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a temp directory off the current directory */ - szwPtr = convert((LPSTR)szDirName); - - if (CreateDirectoryW(szwPtr, NULL) != TRUE) - { - free(szwPtr); - Fail("Unexpected error: CreateDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - - /* find out what the current "home" directory is */ - memset(szwHomeDirBefore, 0, MAX_PATH * sizeof(WCHAR)); - - if( 0 == GetCurrentDirectoryW(MAX_PATH, szwHomeDirBefore) ) - { - Trace("Unexpected error: Unable to get current directory " - "with GetCurrentDirectoryW that returned %ld\n", - GetLastError()); - - if (!RemoveDirectoryW(szwPtr)) - { - Trace("Unexpected error: RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - free(szwPtr); - - Fail(""); - } - - /* append the temp name to the "home" directory */ - memset(szBuiltDir, 0, MAX_PATH); -#if WIN32 - sprintf(szBuiltDir,"%s\\..\\", szDirName); -#else - sprintf(szBuiltDir,"%s/../", szDirName); -#endif - - szwBuiltDir = convert(szBuiltDir); - - /* set the current directory to the temp directory */ - if (SetCurrentDirectoryW(szwBuiltDir) != TRUE) - { - Trace("ERROR: Unable to set current " - "directory to %S. Failed with error code: %ld.\n", - szwBuiltDir, - GetLastError()); - - if (!RemoveDirectoryW(szwPtr)) - { - Trace("Unexpected error: RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - free(szwPtr); - free(szwBuiltDir); - Fail(""); - } - - free(szwBuiltDir); - - /* find out what the current "home" directory is */ - memset(szwHomeDirAfter, 0, MAX_PATH * sizeof(WCHAR)); - - if( 0 == GetCurrentDirectoryW(MAX_PATH, szwHomeDirAfter) ) - { - Trace("Unexpected error: Unable to get current directory " - "with GetCurrentDirectoryW that returned %ld\n", - GetLastError()); - - if (!RemoveDirectoryW(szwPtr)) - { - Trace("ERROR: RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - free(szwPtr); - - Fail(""); - } - - /*compare the new current dir to the compiled current dir */ - if (wcsncmp(szwHomeDirBefore, szwHomeDirAfter, wcslen(szwHomeDirBefore)) != 0) - { - Trace("ERROR:The set directory \"%S\" does not " - "compare to the built directory \"%S\".\n", - szwHomeDirAfter, - szwHomeDirBefore); - - if (!RemoveDirectoryW(szwPtr)) - { - Trace("Unexpected error: RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - free(szwPtr); - Fail(""); - } - - /* clean up */ - if (!RemoveDirectoryW(szwPtr)) - { - free(szwPtr); - Fail("Unexpected error: RemoveDirectoryW failed " - "with error code: %ld.\n", - GetLastError()); - } - - free(szwPtr); - PAL_Terminate(); - - return PASS; -} - - diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/setcurrentdirectoryw.cpp b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/setcurrentdirectoryw.cpp new file mode 100644 index 0000000000..7f833baabc --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test2/setcurrentdirectoryw.cpp @@ -0,0 +1,147 @@ +// 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: SetCurrentDirectoryW.c (test 2) +** +** Purpose: Tests the PAL implementation of the SetCurrentDirectoryW function +** by setting the current directory with ../ +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + const char szDirName[MAX_PATH] = "testing"; + char szBuiltDir[MAX_PATH]; + WCHAR* szwBuiltDir = NULL; + WCHAR szwHomeDirBefore[MAX_PATH]; + WCHAR szwHomeDirAfter[MAX_PATH]; + WCHAR* szwPtr = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a temp directory off the current directory */ + szwPtr = convert((LPSTR)szDirName); + + if (CreateDirectoryW(szwPtr, NULL) != TRUE) + { + free(szwPtr); + Fail("Unexpected error: CreateDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + + /* find out what the current "home" directory is */ + memset(szwHomeDirBefore, 0, MAX_PATH * sizeof(WCHAR)); + + if( 0 == GetCurrentDirectoryW(MAX_PATH, szwHomeDirBefore) ) + { + Trace("Unexpected error: Unable to get current directory " + "with GetCurrentDirectoryW that returned %ld\n", + GetLastError()); + + if (!RemoveDirectoryW(szwPtr)) + { + Trace("Unexpected error: RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + free(szwPtr); + + Fail(""); + } + + /* append the temp name to the "home" directory */ + memset(szBuiltDir, 0, MAX_PATH); +#if WIN32 + sprintf_s(szBuiltDir, _countof(szBuiltDir),"%s\\..\\", szDirName); +#else + sprintf_s(szBuiltDir, _countof(szBuiltDir),"%s/../", szDirName); +#endif + + szwBuiltDir = convert(szBuiltDir); + + /* set the current directory to the temp directory */ + if (SetCurrentDirectoryW(szwBuiltDir) != TRUE) + { + Trace("ERROR: Unable to set current " + "directory to %S. Failed with error code: %ld.\n", + szwBuiltDir, + GetLastError()); + + if (!RemoveDirectoryW(szwPtr)) + { + Trace("Unexpected error: RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + free(szwPtr); + free(szwBuiltDir); + Fail(""); + } + + free(szwBuiltDir); + + /* find out what the current "home" directory is */ + memset(szwHomeDirAfter, 0, MAX_PATH * sizeof(WCHAR)); + + if( 0 == GetCurrentDirectoryW(MAX_PATH, szwHomeDirAfter) ) + { + Trace("Unexpected error: Unable to get current directory " + "with GetCurrentDirectoryW that returned %ld\n", + GetLastError()); + + if (!RemoveDirectoryW(szwPtr)) + { + Trace("ERROR: RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + free(szwPtr); + + Fail(""); + } + + /*compare the new current dir to the compiled current dir */ + if (wcsncmp(szwHomeDirBefore, szwHomeDirAfter, wcslen(szwHomeDirBefore)) != 0) + { + Trace("ERROR:The set directory \"%S\" does not " + "compare to the built directory \"%S\".\n", + szwHomeDirAfter, + szwHomeDirBefore); + + if (!RemoveDirectoryW(szwPtr)) + { + Trace("Unexpected error: RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + free(szwPtr); + Fail(""); + } + + /* clean up */ + if (!RemoveDirectoryW(szwPtr)) + { + free(szwPtr); + Fail("Unexpected error: RemoveDirectoryW failed " + "with error code: %ld.\n", + GetLastError()); + } + + free(szwPtr); + PAL_Terminate(); + + return PASS; +} + + diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/CMakeLists.txt index 3b981f9564..1cb1150a61 100644 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - setcurrentdirectoryw.c + setcurrentdirectoryw.cpp ) add_executable(paltest_setcurrentdirectoryw_test3 diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/setcurrentdirectoryw.c b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/setcurrentdirectoryw.c deleted file mode 100644 index e8c4be2ad4..0000000000 --- a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/setcurrentdirectoryw.c +++ /dev/null @@ -1,64 +0,0 @@ -// 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: SetCurrentDirectoryW.c (test 3) -** -** Purpose: Try calling SetCurrentDirectoryW with an invalid path, -** with a valid filename and with NULL -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - char szDirName[MAX_PATH] = "testing"; - WCHAR* szwDirName = NULL; - char szFileName[MAX_PATH] = "setcurrentdirectorya.c"; - WCHAR* szwFileName = NULL; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* set the current directory to an unexistant folder */ - szwDirName = convert(szDirName); - if (0 != SetCurrentDirectoryW(szwDirName)) - { - free(szwDirName); - Fail("ERROR: SetCurrentDirectoryW should have failed " - "when trying to set the current directory to " - "an invalid folder\n"); - } - free(szwDirName); - - /* set the current directory to an unexistant folder */ - szwFileName = convert(szFileName); - if (0 != SetCurrentDirectoryW(szwFileName)) - { - free(szwFileName); - Fail("ERROR: SetCurrentDirectoryW should have failed " - "when trying to set the current directory to " - "a valid file name\n"); - } - free(szwFileName); - - /* set the current directory to NULL */ - if (0 != SetCurrentDirectoryW(NULL)) - { - Fail("ERROR: SetCurrentDirectoryW should have failed " - "when trying to set the current directory to " - "NULL\n"); - } - - PAL_Terminate(); - - return PASS; -} - - diff --git a/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/setcurrentdirectoryw.cpp b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/setcurrentdirectoryw.cpp new file mode 100644 index 0000000000..e8c4be2ad4 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetCurrentDirectoryW/test3/setcurrentdirectoryw.cpp @@ -0,0 +1,64 @@ +// 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: SetCurrentDirectoryW.c (test 3) +** +** Purpose: Try calling SetCurrentDirectoryW with an invalid path, +** with a valid filename and with NULL +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + char szDirName[MAX_PATH] = "testing"; + WCHAR* szwDirName = NULL; + char szFileName[MAX_PATH] = "setcurrentdirectorya.c"; + WCHAR* szwFileName = NULL; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* set the current directory to an unexistant folder */ + szwDirName = convert(szDirName); + if (0 != SetCurrentDirectoryW(szwDirName)) + { + free(szwDirName); + Fail("ERROR: SetCurrentDirectoryW should have failed " + "when trying to set the current directory to " + "an invalid folder\n"); + } + free(szwDirName); + + /* set the current directory to an unexistant folder */ + szwFileName = convert(szFileName); + if (0 != SetCurrentDirectoryW(szwFileName)) + { + free(szwFileName); + Fail("ERROR: SetCurrentDirectoryW should have failed " + "when trying to set the current directory to " + "a valid file name\n"); + } + free(szwFileName); + + /* set the current directory to NULL */ + if (0 != SetCurrentDirectoryW(NULL)) + { + Fail("ERROR: SetCurrentDirectoryW should have failed " + "when trying to set the current directory to " + "NULL\n"); + } + + PAL_Terminate(); + + return PASS; +} + + diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/CMakeLists.txt index e77ab30b86..3c0fdeec22 100644 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetEndOfFile.c + SetEndOfFile.cpp ) add_executable(paltest_setendoffile_test1 diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.c b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.c deleted file mode 100644 index 9078ddc65b..0000000000 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: SetEndOfFile.c (test 1) -** -** Purpose: Tests the PAL implementation of the SetEndOfFile function. -** This test will attempt to operate on a NULL file handle and -** also test truncating a file not opened with GENERIC_WRITE -** -** Assumes successful: -** SetEndOfFile -** CreateFile -** CloseHandle -** - -** -**===================================================================*/ - -#include - -const char* szTextFile = "text.txt"; - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - BOOL bRc = FALSE; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - bRc = SetEndOfFile(NULL); - if (bRc == TRUE) - { - Fail("SetEndOfFile: ERROR -> Operation succeeded on a NULL file " - "handle\n"); - } - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - bRc = SetEndOfFile(hFile); - if (bRc == TRUE) - { - Trace("SetEndOfFile: ERROR -> Operation succeeded on read-only" - " file.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.cpp b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.cpp new file mode 100644 index 0000000000..9078ddc65b --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.cpp @@ -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: SetEndOfFile.c (test 1) +** +** Purpose: Tests the PAL implementation of the SetEndOfFile function. +** This test will attempt to operate on a NULL file handle and +** also test truncating a file not opened with GENERIC_WRITE +** +** Assumes successful: +** SetEndOfFile +** CreateFile +** CloseHandle +** + +** +**===================================================================*/ + +#include + +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + BOOL bRc = FALSE; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + bRc = SetEndOfFile(NULL); + if (bRc == TRUE) + { + Fail("SetEndOfFile: ERROR -> Operation succeeded on a NULL file " + "handle\n"); + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + bRc = SetEndOfFile(hFile); + if (bRc == TRUE) + { + Trace("SetEndOfFile: ERROR -> Operation succeeded on read-only" + " file.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/CMakeLists.txt index b04dea04a6..57afdad2fd 100644 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetEndOfFile.c + SetEndOfFile.cpp ) add_executable(paltest_setendoffile_test2 diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/SetEndOfFile.c b/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/SetEndOfFile.c deleted file mode 100644 index 6b3c05088e..0000000000 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/SetEndOfFile.c +++ /dev/null @@ -1,154 +0,0 @@ -// 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: SetEndOfFile.c (test 2) -** -** Purpose: Tests the PAL implementation of the SetEndOfFile function. -** This test will attempt to truncate a file -** -** -**===================================================================*/ - -#include - - -const char* szStringTest = "The quick fox jumped over the lazy dog's back."; -const char* szTextFile = "text.txt"; - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwByteCount = 0; - DWORD dwBytesWritten; - BOOL bRc = FALSE; - char szBuffer[100]; - DWORD dwBytesRead = 0; - FILE *pFile = NULL; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // create a test file - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - bRc = WriteFile(hFile, szStringTest, 20, &dwBytesWritten, NULL); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Uable to write to \"%s\".\n", - szTextFile); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - - // open the test file - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetEndOfFile: ERROR -> Unable to open file \"%s\".\n", - szTextFile); - } - - // read a bit of the file to move the file pointer - dwByteCount = 10; - bRc = ReadFile(hFile, szBuffer, dwByteCount, &dwBytesRead, NULL); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Uable to read from \"%s\".\n", - szTextFile); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - bRc = SetEndOfFile(hFile); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Uable to set end of file.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - - // open and read the test file - pFile = fopen(szTextFile, "r"); - if (pFile == NULL) - { - Fail("SetEndOfFile: ERROR -> fopen was unable to open file \"%s\".\n", - szTextFile); - } - - // since we truncated the file at 10 characters, - // try reading 20 just to be safe - memset(szBuffer, 0, 100); - fgets(szBuffer, 20, pFile); - fclose(pFile); - if (strlen(szBuffer) != dwByteCount) - { - Fail("SetEndOfFile: ERROR -> file apparently not truncated at " - "correct position.\n"); - } - if (strncmp(szBuffer, szStringTest, dwByteCount) != 0) - { - Fail("SetEndOfFile: ERROR -> truncated file contents doesn't " - "compare with what should be there\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/SetEndOfFile.cpp b/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/SetEndOfFile.cpp new file mode 100644 index 0000000000..6b3c05088e --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test2/SetEndOfFile.cpp @@ -0,0 +1,154 @@ +// 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: SetEndOfFile.c (test 2) +** +** Purpose: Tests the PAL implementation of the SetEndOfFile function. +** This test will attempt to truncate a file +** +** +**===================================================================*/ + +#include + + +const char* szStringTest = "The quick fox jumped over the lazy dog's back."; +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwByteCount = 0; + DWORD dwBytesWritten; + BOOL bRc = FALSE; + char szBuffer[100]; + DWORD dwBytesRead = 0; + FILE *pFile = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // create a test file + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + bRc = WriteFile(hFile, szStringTest, 20, &dwBytesWritten, NULL); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Uable to write to \"%s\".\n", + szTextFile); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + + // open the test file + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetEndOfFile: ERROR -> Unable to open file \"%s\".\n", + szTextFile); + } + + // read a bit of the file to move the file pointer + dwByteCount = 10; + bRc = ReadFile(hFile, szBuffer, dwByteCount, &dwBytesRead, NULL); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Uable to read from \"%s\".\n", + szTextFile); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + bRc = SetEndOfFile(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Uable to set end of file.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + + // open and read the test file + pFile = fopen(szTextFile, "r"); + if (pFile == NULL) + { + Fail("SetEndOfFile: ERROR -> fopen was unable to open file \"%s\".\n", + szTextFile); + } + + // since we truncated the file at 10 characters, + // try reading 20 just to be safe + memset(szBuffer, 0, 100); + fgets(szBuffer, 20, pFile); + fclose(pFile); + if (strlen(szBuffer) != dwByteCount) + { + Fail("SetEndOfFile: ERROR -> file apparently not truncated at " + "correct position.\n"); + } + if (strncmp(szBuffer, szStringTest, dwByteCount) != 0) + { + Fail("SetEndOfFile: ERROR -> truncated file contents doesn't " + "compare with what should be there\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/CMakeLists.txt index 1ab177d00a..01575ce09b 100644 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetEndOfFile.c + SetEndOfFile.cpp ) add_executable(paltest_setendoffile_test3 diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/SetEndOfFile.c b/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/SetEndOfFile.c deleted file mode 100644 index dfd9194465..0000000000 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/SetEndOfFile.c +++ /dev/null @@ -1,109 +0,0 @@ -// 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: SetEndOfFile.c (test 3) -** -** Purpose: Tests the PAL implementation of the SetEndOfFile function. -** This test will attempt to expand a file. Assumes successful -** SetFilePointer and GetFileSize tests. -** -** -**===================================================================*/ - -#include - - -const char* szTextFile = "text.txt"; - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwByteCount = 0; - DWORD dwOffset = 25; - DWORD dwRc = 0; - BOOL bRc = FALSE; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - /* move the file pointer */ - /* assumes a successful SetFilePointer test */ - dwRc = SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN); - if (dwRc == INVALID_SET_FILE_POINTER) - { - Trace("SetEndOfFile: ERROR -> Call to SetFilePointer failed\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - PAL_Terminate(); - return FAIL; - } - - bRc = SetEndOfFile(hFile); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Uable to set end of file.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - - /* call GetFileSize to verify pointer position */ - /* assumes a successful GetFileSize test */ - - dwByteCount = GetFileSize(hFile, NULL); - if (dwByteCount != dwOffset) - { - Trace("SetEndOfFile: ERROR -> file apparently not expanded to the" - " correct size.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/SetEndOfFile.cpp b/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/SetEndOfFile.cpp new file mode 100644 index 0000000000..dfd9194465 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test3/SetEndOfFile.cpp @@ -0,0 +1,109 @@ +// 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: SetEndOfFile.c (test 3) +** +** Purpose: Tests the PAL implementation of the SetEndOfFile function. +** This test will attempt to expand a file. Assumes successful +** SetFilePointer and GetFileSize tests. +** +** +**===================================================================*/ + +#include + + +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwByteCount = 0; + DWORD dwOffset = 25; + DWORD dwRc = 0; + BOOL bRc = FALSE; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + /* move the file pointer */ + /* assumes a successful SetFilePointer test */ + dwRc = SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN); + if (dwRc == INVALID_SET_FILE_POINTER) + { + Trace("SetEndOfFile: ERROR -> Call to SetFilePointer failed\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + PAL_Terminate(); + return FAIL; + } + + bRc = SetEndOfFile(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Uable to set end of file.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + + /* call GetFileSize to verify pointer position */ + /* assumes a successful GetFileSize test */ + + dwByteCount = GetFileSize(hFile, NULL); + if (dwByteCount != dwOffset) + { + Trace("SetEndOfFile: ERROR -> file apparently not expanded to the" + " correct size.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt index ff0b6f999c..1dc4f68aef 100644 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - setendoffile.c + setendoffile.cpp ) add_executable(paltest_setendoffile_test4 diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c deleted file mode 100644 index 98a6ec63da..0000000000 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c +++ /dev/null @@ -1,138 +0,0 @@ -// 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: setendoffile.c (test 4) -** -** Purpose: Tests the PAL implementation of the SetEndOfFile function. -** Verify that the file pointer is the same before -** and after a SetEndOfFile using SetFilePointer with -** FILE_BEGIN, FILE_CURRENT and FILE_END -** -** -**===================================================================*/ - -#include - - -const char* szStringTest = "The quick fox jumped over the lazy dog's back."; -const char* szTextFile = "test.tmp"; - -static void Cleanup(HANDLE hFile) -{ - if (!CloseHandle(hFile)) - { - Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\". ", - "GetLastError returned %u.\n", - szTextFile, - GetLastError()); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetEndOfFile: ERROR -> Unable to delete file \"%s\". ", - "GetLastError returned %u.\n", - szTextFile, - GetLastError()); - } -} - -static void DoTest(HANDLE hFile, DWORD dwOffset, DWORD dwMethod) -{ - DWORD dwFP1 = 0; - DWORD dwFP2 = 0; - DWORD dwError; - - /* set the pointer*/ - dwFP1 = SetFilePointer(hFile, dwOffset, NULL, dwMethod); - if ((dwFP1 == INVALID_SET_FILE_POINTER) && - ((dwError = GetLastError()) != ERROR_SUCCESS)) - { - Trace("SetEndOfFile: ERROR -> Unable to set the pointer to the " - "end of the file. GetLastError returned %u.\n", - dwError); - Cleanup(hFile); - Fail(""); - } - - /* set EOF */ - if (!SetEndOfFile(hFile)) - { - Trace("SetEndOfFile: ERROR -> Unable to set end of file. " - "GetLastError returned %u.\n", - GetLastError()); - Cleanup(hFile); - Fail(""); - } - - /* get current file pointer pointer */ - dwFP2 = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); - if ((dwFP1 == INVALID_SET_FILE_POINTER) && - ((dwError = GetLastError()) != ERROR_SUCCESS)) - { - Trace("SetEndOfFile: ERROR -> Unable to set the pointer to the " - "end of the file. GetLastError returned %u.\n", - dwError); - Cleanup(hFile); - Fail(""); - } - - /* are they the same? */ - if (dwFP1 != dwFP2) - { - Trace("SetEndOfFile: ERROR -> File pointer before (%u) the " - "SetEndOfFile call was different than after (%u).\n", - dwFP1, - dwFP2); - Cleanup(hFile); - Fail(""); - } -} - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwBytesWritten; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\". " - "GetLastError returned %u.\n", - szTextFile, - GetLastError()); - } - - if (!WriteFile(hFile, szStringTest, strlen(szStringTest), &dwBytesWritten, NULL)) - { - Trace("SetEndOfFile: ERROR -> Unable to write to \"%s\". ", - "GetLastError returned %u.\n", - szTextFile, - GetLastError()); - Cleanup(hFile); - Fail(""); - } - - DoTest(hFile, -2, FILE_END); /* test the end */ - DoTest(hFile, -10, FILE_CURRENT); /* test the middle-ish */ - DoTest(hFile, 0, FILE_BEGIN); /* test the start */ - - Cleanup(hFile); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.cpp b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.cpp new file mode 100644 index 0000000000..98a6ec63da --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.cpp @@ -0,0 +1,138 @@ +// 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: setendoffile.c (test 4) +** +** Purpose: Tests the PAL implementation of the SetEndOfFile function. +** Verify that the file pointer is the same before +** and after a SetEndOfFile using SetFilePointer with +** FILE_BEGIN, FILE_CURRENT and FILE_END +** +** +**===================================================================*/ + +#include + + +const char* szStringTest = "The quick fox jumped over the lazy dog's back."; +const char* szTextFile = "test.tmp"; + +static void Cleanup(HANDLE hFile) +{ + if (!CloseHandle(hFile)) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\". ", + "GetLastError returned %u.\n", + szTextFile, + GetLastError()); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetEndOfFile: ERROR -> Unable to delete file \"%s\". ", + "GetLastError returned %u.\n", + szTextFile, + GetLastError()); + } +} + +static void DoTest(HANDLE hFile, DWORD dwOffset, DWORD dwMethod) +{ + DWORD dwFP1 = 0; + DWORD dwFP2 = 0; + DWORD dwError; + + /* set the pointer*/ + dwFP1 = SetFilePointer(hFile, dwOffset, NULL, dwMethod); + if ((dwFP1 == INVALID_SET_FILE_POINTER) && + ((dwError = GetLastError()) != ERROR_SUCCESS)) + { + Trace("SetEndOfFile: ERROR -> Unable to set the pointer to the " + "end of the file. GetLastError returned %u.\n", + dwError); + Cleanup(hFile); + Fail(""); + } + + /* set EOF */ + if (!SetEndOfFile(hFile)) + { + Trace("SetEndOfFile: ERROR -> Unable to set end of file. " + "GetLastError returned %u.\n", + GetLastError()); + Cleanup(hFile); + Fail(""); + } + + /* get current file pointer pointer */ + dwFP2 = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); + if ((dwFP1 == INVALID_SET_FILE_POINTER) && + ((dwError = GetLastError()) != ERROR_SUCCESS)) + { + Trace("SetEndOfFile: ERROR -> Unable to set the pointer to the " + "end of the file. GetLastError returned %u.\n", + dwError); + Cleanup(hFile); + Fail(""); + } + + /* are they the same? */ + if (dwFP1 != dwFP2) + { + Trace("SetEndOfFile: ERROR -> File pointer before (%u) the " + "SetEndOfFile call was different than after (%u).\n", + dwFP1, + dwFP2); + Cleanup(hFile); + Fail(""); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwBytesWritten; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\". " + "GetLastError returned %u.\n", + szTextFile, + GetLastError()); + } + + if (!WriteFile(hFile, szStringTest, strlen(szStringTest), &dwBytesWritten, NULL)) + { + Trace("SetEndOfFile: ERROR -> Unable to write to \"%s\". ", + "GetLastError returned %u.\n", + szTextFile, + GetLastError()); + Cleanup(hFile); + Fail(""); + } + + DoTest(hFile, -2, FILE_END); /* test the end */ + DoTest(hFile, -10, FILE_CURRENT); /* test the middle-ish */ + DoTest(hFile, 0, FILE_BEGIN); /* test the start */ + + Cleanup(hFile); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/CMakeLists.txt index cca7167762..19f87a28af 100644 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_setendoffile_test5 diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/test5.c b/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/test5.c deleted file mode 100644 index 7000d1af15..0000000000 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/test5.c +++ /dev/null @@ -1,183 +0,0 @@ -// 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: test5.c -** -** Purpose: Tests the PAL implementation of the SetEndOfFile function. -** Test attempts to read the number of characters up to -** the EOF pointer, which was specified. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwBytesWritten; - DWORD retCode; - BOOL bRc = FALSE; - char szBuffer[256]; - DWORD dwBytesRead = 0; - char testFile[] = "testfile.tmp"; - char testString[] = "watch what happens"; - LONG shiftAmount = 10; - - /* Initialize the PAL. - */ - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Initialize the buffer. - */ - memset(szBuffer, 0, 256); - - /* Create a file to test with. - */ - hFile = CreateFile(testFile, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_WRITE|FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR:%u: Unable to create file \"%s\".\n", - GetLastError(), - testFile); - } - - /* Write to the File handle. - */ - bRc = WriteFile(hFile, - testString, - strlen(testString), - &dwBytesWritten, - NULL); - - if (bRc == FALSE) - { - Trace("ERROR:%u: Unable to write to file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - if (!CloseHandle(hFile)) - { - Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - /* Set the file pointer to shiftAmount bytes from the front of the file - */ - retCode = SetFilePointer(hFile, shiftAmount, NULL, FILE_BEGIN); - if(retCode == INVALID_SET_FILE_POINTER) - { - Trace("ERROR:%u: Unable to set the file pointer to %d\n", - GetLastError(), - shiftAmount); - if (!CloseHandle(hFile)) - { - Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - /* set the end of file pointer to 'shiftAmount' */ - bRc = SetEndOfFile(hFile); - if (bRc == FALSE) - { - Trace("ERROR:%u: Unable to set file pointer of file handle 0x%lx.\n", - GetLastError(), - hFile); - if (!CloseHandle(hFile)) - { - Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - /* Set the file pointer to 10 bytes from the front of the file - */ - retCode = SetFilePointer(hFile, (LONG)NULL, NULL, FILE_BEGIN); - if(retCode == INVALID_SET_FILE_POINTER) - { - Trace("ERROR:%u: Unable to set the file pointer to %d\n", - GetLastError(), - FILE_BEGIN); - if (!CloseHandle(hFile)) - { - Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - /* Attempt to read the entire string, 'testString' from a file - * that has it's end of pointer set at shiftAmount; - */ - bRc = ReadFile(hFile, - szBuffer, - strlen(testString), - &dwBytesRead, - NULL); - - if (bRc == FALSE) - { - Trace("ERROR:%u: Unable to read from file handle 0x%lx.\n", - GetLastError(), - hFile); - if (!CloseHandle(hFile)) - { - Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - /* Confirm the number of bytes read with that requested. - */ - if (dwBytesRead != shiftAmount) - { - Trace("ERROR: The number of bytes read \"%d\" is not equal to the " - "number that should have been written \"%d\".\n", - dwBytesRead, - shiftAmount); - if (!CloseHandle(hFile)) - { - Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", - GetLastError(), - hFile); - } - Fail(""); - } - - bRc = CloseHandle(hFile); - if(!bRc) - { - Fail("ERROR:%u CloseHandle failed to close the handle\n", - GetLastError()); - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/test5.cpp b/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/test5.cpp new file mode 100644 index 0000000000..7000d1af15 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test5/test5.cpp @@ -0,0 +1,183 @@ +// 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: test5.c +** +** Purpose: Tests the PAL implementation of the SetEndOfFile function. +** Test attempts to read the number of characters up to +** the EOF pointer, which was specified. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwBytesWritten; + DWORD retCode; + BOOL bRc = FALSE; + char szBuffer[256]; + DWORD dwBytesRead = 0; + char testFile[] = "testfile.tmp"; + char testString[] = "watch what happens"; + LONG shiftAmount = 10; + + /* Initialize the PAL. + */ + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Initialize the buffer. + */ + memset(szBuffer, 0, 256); + + /* Create a file to test with. + */ + hFile = CreateFile(testFile, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_WRITE|FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR:%u: Unable to create file \"%s\".\n", + GetLastError(), + testFile); + } + + /* Write to the File handle. + */ + bRc = WriteFile(hFile, + testString, + strlen(testString), + &dwBytesWritten, + NULL); + + if (bRc == FALSE) + { + Trace("ERROR:%u: Unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + if (!CloseHandle(hFile)) + { + Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + /* Set the file pointer to shiftAmount bytes from the front of the file + */ + retCode = SetFilePointer(hFile, shiftAmount, NULL, FILE_BEGIN); + if(retCode == INVALID_SET_FILE_POINTER) + { + Trace("ERROR:%u: Unable to set the file pointer to %d\n", + GetLastError(), + shiftAmount); + if (!CloseHandle(hFile)) + { + Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + /* set the end of file pointer to 'shiftAmount' */ + bRc = SetEndOfFile(hFile); + if (bRc == FALSE) + { + Trace("ERROR:%u: Unable to set file pointer of file handle 0x%lx.\n", + GetLastError(), + hFile); + if (!CloseHandle(hFile)) + { + Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + /* Set the file pointer to 10 bytes from the front of the file + */ + retCode = SetFilePointer(hFile, (LONG)NULL, NULL, FILE_BEGIN); + if(retCode == INVALID_SET_FILE_POINTER) + { + Trace("ERROR:%u: Unable to set the file pointer to %d\n", + GetLastError(), + FILE_BEGIN); + if (!CloseHandle(hFile)) + { + Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + /* Attempt to read the entire string, 'testString' from a file + * that has it's end of pointer set at shiftAmount; + */ + bRc = ReadFile(hFile, + szBuffer, + strlen(testString), + &dwBytesRead, + NULL); + + if (bRc == FALSE) + { + Trace("ERROR:%u: Unable to read from file handle 0x%lx.\n", + GetLastError(), + hFile); + if (!CloseHandle(hFile)) + { + Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + /* Confirm the number of bytes read with that requested. + */ + if (dwBytesRead != shiftAmount) + { + Trace("ERROR: The number of bytes read \"%d\" is not equal to the " + "number that should have been written \"%d\".\n", + dwBytesRead, + shiftAmount); + if (!CloseHandle(hFile)) + { + Fail("ERROR:%u%: Unable to close handle 0x%lx.\n", + GetLastError(), + hFile); + } + Fail(""); + } + + bRc = CloseHandle(hFile); + if(!bRc) + { + Fail("ERROR:%u CloseHandle failed to close the handle\n", + GetLastError()); + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/CMakeLists.txt index 81e2dfdea2..638dd5c425 100644 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileAttributesA.c + SetFileAttributesA.cpp ) add_executable(paltest_setfileattributesa_test1 diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/SetFileAttributesA.c b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/SetFileAttributesA.c deleted file mode 100644 index bacab2a0ad..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/SetFileAttributesA.c +++ /dev/null @@ -1,168 +0,0 @@ -// 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: SetFileAttributesA.c -** -** -** Purpose: Tests the PAL implementation of the SetFileAttributesA function -** Test that we can set a file READONLY, and then that we're unable to -** open that file with WRITE access. Then change it to NORMAL attributes, and -** try to open it again -- it should work now. -** -** Depends: -** CreateFile -** CloseHandle -** -** -**===================================================================*/ - -/* According to the spec, only READONLY attribute can be set - in FreeBSD. -*/ - -#include - - - -int __cdecl main(int argc, char **argv) -{ - DWORD TheResult; - HANDLE TheFile; - char* FileName = {"test_file"}; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // Create the test file - FILE *testFile = fopen(FileName, "w"); - if (testFile == NULL) - { - Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); - } - if (fputs("testing", testFile) == EOF) - { - Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); - } - if (fclose(testFile) != 0) - { - Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); - } - testFile = NULL; - - /* Try to set the file to Read-only */ - - TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_READONLY); - - if(TheResult == 0) - { - Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_READONLY attribute."); - } - - /* Attempt to open this READONLY file with WRITE access, - The open should fail and the HANDLE should be invalid. - */ - - TheFile = CreateFileA( - FileName, // file name - GENERIC_READ|GENERIC_WRITE, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile != INVALID_HANDLE_VALUE) - { - TheResult = CloseHandle(TheFile); - if(TheResult == 0) - { - Fail("ERROR: CloseHandle failed. This tests relies upon it " - "working properly."); - } - Fail("ERROR: Tried to open a file that was created as " - "READONLY with the GENERIC_WRITE access mode. This should" - " cause CreateFile to return an INVALID_HANDLE_VALUE."); - } - - /* Try to open the file with READ access, this should be ok. - The HANDLE will be valid. - */ - - TheFile = CreateFileA( - FileName, // file name - GENERIC_READ, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Tried to open a file that was created as " - "READONLY with the GENERIC_READ access mode. This should" - " cause CreateFile to return an valid handle, but " - "INVALID_HANDLE_VALUE was returned!."); - } - - /* Close that HANDLE */ - - TheResult = CloseHandle(TheFile); - - if(TheResult == 0) - { - Fail("ERROR: CloseHandle failed. This tests relies upon it " - "working properly."); - } - - /* Set the file to NORMAL */ - - TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_NORMAL); - - if(TheResult == 0) - { - Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_NORMAL attribute."); - } - - /* To ensure that the set worked correctly, try to open the file - with WRITE access again -- this time it should succeed. - */ - - TheFile = CreateFileA( - FileName, // file name - GENERIC_READ|GENERIC_WRITE, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Tried to open a file that was created as " - "NORMAL with the GENERIC_WRITE access mode. This should" - " cause CreateFile to return an valid handle, but " - "INVALID_HANDLE_VALUE was returned!."); - } - - TheResult = CloseHandle(TheFile); - - if(TheResult == 0) - { - Fail("ERROR: CloseHandle failed. This tests relies upon it " - "working properly."); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/SetFileAttributesA.cpp b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/SetFileAttributesA.cpp new file mode 100644 index 0000000000..bacab2a0ad --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test1/SetFileAttributesA.cpp @@ -0,0 +1,168 @@ +// 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: SetFileAttributesA.c +** +** +** Purpose: Tests the PAL implementation of the SetFileAttributesA function +** Test that we can set a file READONLY, and then that we're unable to +** open that file with WRITE access. Then change it to NORMAL attributes, and +** try to open it again -- it should work now. +** +** Depends: +** CreateFile +** CloseHandle +** +** +**===================================================================*/ + +/* According to the spec, only READONLY attribute can be set + in FreeBSD. +*/ + +#include + + + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + HANDLE TheFile; + char* FileName = {"test_file"}; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // Create the test file + FILE *testFile = fopen(FileName, "w"); + if (testFile == NULL) + { + Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); + } + if (fputs("testing", testFile) == EOF) + { + Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); + } + if (fclose(testFile) != 0) + { + Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); + } + testFile = NULL; + + /* Try to set the file to Read-only */ + + TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_READONLY); + + if(TheResult == 0) + { + Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_READONLY attribute."); + } + + /* Attempt to open this READONLY file with WRITE access, + The open should fail and the HANDLE should be invalid. + */ + + TheFile = CreateFileA( + FileName, // file name + GENERIC_READ|GENERIC_WRITE, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile != INVALID_HANDLE_VALUE) + { + TheResult = CloseHandle(TheFile); + if(TheResult == 0) + { + Fail("ERROR: CloseHandle failed. This tests relies upon it " + "working properly."); + } + Fail("ERROR: Tried to open a file that was created as " + "READONLY with the GENERIC_WRITE access mode. This should" + " cause CreateFile to return an INVALID_HANDLE_VALUE."); + } + + /* Try to open the file with READ access, this should be ok. + The HANDLE will be valid. + */ + + TheFile = CreateFileA( + FileName, // file name + GENERIC_READ, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Tried to open a file that was created as " + "READONLY with the GENERIC_READ access mode. This should" + " cause CreateFile to return an valid handle, but " + "INVALID_HANDLE_VALUE was returned!."); + } + + /* Close that HANDLE */ + + TheResult = CloseHandle(TheFile); + + if(TheResult == 0) + { + Fail("ERROR: CloseHandle failed. This tests relies upon it " + "working properly."); + } + + /* Set the file to NORMAL */ + + TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_NORMAL); + + if(TheResult == 0) + { + Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_NORMAL attribute."); + } + + /* To ensure that the set worked correctly, try to open the file + with WRITE access again -- this time it should succeed. + */ + + TheFile = CreateFileA( + FileName, // file name + GENERIC_READ|GENERIC_WRITE, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Tried to open a file that was created as " + "NORMAL with the GENERIC_WRITE access mode. This should" + " cause CreateFile to return an valid handle, but " + "INVALID_HANDLE_VALUE was returned!."); + } + + TheResult = CloseHandle(TheFile); + + if(TheResult == 0) + { + Fail("ERROR: CloseHandle failed. This tests relies upon it " + "working properly."); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/CMakeLists.txt index 03445c1df0..51bee5af39 100644 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileAttributesA.c + SetFileAttributesA.cpp ) add_executable(paltest_setfileattributesa_test2 diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/SetFileAttributesA.c b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/SetFileAttributesA.c deleted file mode 100644 index 5c04a6b181..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/SetFileAttributesA.c +++ /dev/null @@ -1,114 +0,0 @@ -// 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: SetFileAttributesA.c -** -** -** Purpose: Tests the PAL implementation of the SetFileAttributesA function -** Test that we can set the defined attributes aside from READONLY on a -** file, and that it doesn't return failure. Note, these attributes won't -** do anything to the file, however. -** -** -**===================================================================*/ - - -#include - -/* this cleanup method tries to revert the file back to its initial attributes */ -void do_cleanup(char* filename, DWORD attributes) -{ - DWORD result; - result = SetFileAttributesA(filename, attributes); - if (result == 0) - { - Fail("ERROR:SetFileAttributesA returned 0,failure in the do_cleanup " - "method when trying to revert the file back to its initial attributes (%u)", GetLastError()); - } -} - -int __cdecl main(int argc, char **argv) -{ - DWORD TheResult; - DWORD initialAttr; - - char* FileName = {"test_file"}; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // Create the test file - FILE *testFile = fopen(FileName, "w"); - if (testFile == NULL) - { - Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); - } - if (fputs("testing", testFile) == EOF) - { - Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); - } - if (fclose(testFile) != 0) - { - Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); - } - testFile = NULL; - - /* Get the initial attributes of the file */ - - initialAttr = GetFileAttributesA(FileName); - - /* Try to set the file to HIDDEN */ - - TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_HIDDEN); - - if(TheResult == 0) - { - do_cleanup(FileName,initialAttr); - Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_HIDDEN attribute. This should " - "not do anything in FreeBSD, but it shouldn't fail."); - } - - /* Try to set the file to ARCHIVE */ - - TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_ARCHIVE); - - if(TheResult == 0) - { - do_cleanup(FileName,initialAttr); - Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_ARCHIVE attribute."); - } - - /* Try to set the file to SYSTEM */ - - TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_SYSTEM); - - if(TheResult == 0) - { - do_cleanup(FileName,initialAttr); - Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_SYSTEM attribute."); - } - - /* Try to set the file to DIRECTORY */ - - TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_DIRECTORY); - - if(TheResult == 0) - { - do_cleanup(FileName,initialAttr); - Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_DIRECTORY attribute."); - } - - - do_cleanup(FileName,initialAttr); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/SetFileAttributesA.cpp b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/SetFileAttributesA.cpp new file mode 100644 index 0000000000..5c04a6b181 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test2/SetFileAttributesA.cpp @@ -0,0 +1,114 @@ +// 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: SetFileAttributesA.c +** +** +** Purpose: Tests the PAL implementation of the SetFileAttributesA function +** Test that we can set the defined attributes aside from READONLY on a +** file, and that it doesn't return failure. Note, these attributes won't +** do anything to the file, however. +** +** +**===================================================================*/ + + +#include + +/* this cleanup method tries to revert the file back to its initial attributes */ +void do_cleanup(char* filename, DWORD attributes) +{ + DWORD result; + result = SetFileAttributesA(filename, attributes); + if (result == 0) + { + Fail("ERROR:SetFileAttributesA returned 0,failure in the do_cleanup " + "method when trying to revert the file back to its initial attributes (%u)", GetLastError()); + } +} + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + DWORD initialAttr; + + char* FileName = {"test_file"}; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // Create the test file + FILE *testFile = fopen(FileName, "w"); + if (testFile == NULL) + { + Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); + } + if (fputs("testing", testFile) == EOF) + { + Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); + } + if (fclose(testFile) != 0) + { + Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); + } + testFile = NULL; + + /* Get the initial attributes of the file */ + + initialAttr = GetFileAttributesA(FileName); + + /* Try to set the file to HIDDEN */ + + TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_HIDDEN); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_HIDDEN attribute. This should " + "not do anything in FreeBSD, but it shouldn't fail."); + } + + /* Try to set the file to ARCHIVE */ + + TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_ARCHIVE); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_ARCHIVE attribute."); + } + + /* Try to set the file to SYSTEM */ + + TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_SYSTEM); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_SYSTEM attribute."); + } + + /* Try to set the file to DIRECTORY */ + + TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_DIRECTORY); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_DIRECTORY attribute."); + } + + + do_cleanup(FileName,initialAttr); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/CMakeLists.txt index 3c35172d7c..4597e1d22c 100644 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileAttributesA.c + SetFileAttributesA.cpp ) add_executable(paltest_setfileattributesa_test3 diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/SetFileAttributesA.c b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/SetFileAttributesA.c deleted file mode 100644 index 445b515c7f..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/SetFileAttributesA.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: SetFileAttributesA.c -** -** -** Purpose: Tests the PAL implementation of the SetFileAttributesA function -** Test that the function fails if the file doesn't exist.. -** -** -**===================================================================*/ - - -#include - - -int __cdecl main(int argc, char **argv) -{ - DWORD TheResult; - char* FileName = {"no_file"}; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - /* Try to set the file to NORMAL on a file that doesn't - exist. - */ - - TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_NORMAL); - - if(TheResult != 0) - { - Fail("ERROR: SetFileAttributesA returned non-zero0, success, when" - " trying to set the FILE_ATTRIBUTE_NORMAL attribute on a non " - "existant file. This should fail."); - } - - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/SetFileAttributesA.cpp b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/SetFileAttributesA.cpp new file mode 100644 index 0000000000..445b515c7f --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test3/SetFileAttributesA.cpp @@ -0,0 +1,48 @@ +// 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: SetFileAttributesA.c +** +** +** Purpose: Tests the PAL implementation of the SetFileAttributesA function +** Test that the function fails if the file doesn't exist.. +** +** +**===================================================================*/ + + +#include + + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + char* FileName = {"no_file"}; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + /* Try to set the file to NORMAL on a file that doesn't + exist. + */ + + TheResult = SetFileAttributesA(FileName, FILE_ATTRIBUTE_NORMAL); + + if(TheResult != 0) + { + Fail("ERROR: SetFileAttributesA returned non-zero0, success, when" + " trying to set the FILE_ATTRIBUTE_NORMAL attribute on a non " + "existant file. This should fail."); + } + + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/CMakeLists.txt index f30969ad04..1807027123 100644 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileAttributesA.c + SetFileAttributesA.cpp ) add_executable(paltest_setfileattributesa_test4 diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/SetFileAttributesA.c b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/SetFileAttributesA.c deleted file mode 100644 index 240e89ff6f..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/SetFileAttributesA.c +++ /dev/null @@ -1,128 +0,0 @@ -// 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: SetFileAttributesA.c -** -** -** Purpose: Tests the PAL implementation of the SetFileAttributesA function -** Check that using two flags (READONLY and NORMAL) only sets the file -** as READONLY, as MSDN notes that everything else overrides NORMAL. -** -** Depends: -** CreateFileA -** CloseHandle -** -** -**===================================================================*/ - - -#include - - - -int __cdecl main(int argc, char **argv) -{ - DWORD TheResult; - HANDLE TheFile; - char* FileName = {"test_file"}; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // Create the test file - FILE *testFile = fopen(FileName, "w"); - if (testFile == NULL) - { - Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); - } - if (fputs("testing", testFile) == EOF) - { - Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); - } - if (fclose(testFile) != 0) - { - Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); - } - testFile = NULL; - - /* Try to set the file to Read-only|Normal ... It should - end up as Readonly, since this overrides Normal*/ - - TheResult = SetFileAttributesA(FileName, - FILE_ATTRIBUTE_NORMAL| - FILE_ATTRIBUTE_READONLY); - - if(TheResult == 0) - { - Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_NORMAL " - "attribute."); - } - - /* Attempt to open this READONLY file with WRITE access, - The open should fail and the HANDLE should be invalid. - */ - - TheFile = CreateFileA( - FileName, // file name - GENERIC_READ|GENERIC_WRITE, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile != INVALID_HANDLE_VALUE) - { - TheResult = CloseHandle(TheFile); - if(TheResult == 0) - { - Trace("ERROR: CloseHandle failed. This tests relies upon it " - "working properly."); - } - Fail("ERROR: Tried to open a file that was created as " - "READONLY with the GENERIC_WRITE access mode. This should" - " cause CreateFileA to return an INVALID_HANDLE_VALUE."); - } - - /* Try to open the file with READ access, this should be ok. - The HANDLE will be valid. - */ - - TheFile = CreateFileA( - FileName, // file name - GENERIC_READ, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Tried to open a file that was created as " - "READONLY with the GENERIC_READ access mode. This should" - " cause CreateFileA to return an valid handle, but " - "INVALID_HANDLE_VALUE was returned!."); - } - - /* Close that HANDLE */ - - TheResult = CloseHandle(TheFile); - - if(TheResult == 0) - { - Fail("ERROR: CloseHandle failed. This tests relies upon it " - "working properly."); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/SetFileAttributesA.cpp b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/SetFileAttributesA.cpp new file mode 100644 index 0000000000..240e89ff6f --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesA/test4/SetFileAttributesA.cpp @@ -0,0 +1,128 @@ +// 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: SetFileAttributesA.c +** +** +** Purpose: Tests the PAL implementation of the SetFileAttributesA function +** Check that using two flags (READONLY and NORMAL) only sets the file +** as READONLY, as MSDN notes that everything else overrides NORMAL. +** +** Depends: +** CreateFileA +** CloseHandle +** +** +**===================================================================*/ + + +#include + + + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + HANDLE TheFile; + char* FileName = {"test_file"}; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // Create the test file + FILE *testFile = fopen(FileName, "w"); + if (testFile == NULL) + { + Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); + } + if (fputs("testing", testFile) == EOF) + { + Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); + } + if (fclose(testFile) != 0) + { + Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); + } + testFile = NULL; + + /* Try to set the file to Read-only|Normal ... It should + end up as Readonly, since this overrides Normal*/ + + TheResult = SetFileAttributesA(FileName, + FILE_ATTRIBUTE_NORMAL| + FILE_ATTRIBUTE_READONLY); + + if(TheResult == 0) + { + Fail("ERROR: SetFileAttributesA returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_NORMAL " + "attribute."); + } + + /* Attempt to open this READONLY file with WRITE access, + The open should fail and the HANDLE should be invalid. + */ + + TheFile = CreateFileA( + FileName, // file name + GENERIC_READ|GENERIC_WRITE, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile != INVALID_HANDLE_VALUE) + { + TheResult = CloseHandle(TheFile); + if(TheResult == 0) + { + Trace("ERROR: CloseHandle failed. This tests relies upon it " + "working properly."); + } + Fail("ERROR: Tried to open a file that was created as " + "READONLY with the GENERIC_WRITE access mode. This should" + " cause CreateFileA to return an INVALID_HANDLE_VALUE."); + } + + /* Try to open the file with READ access, this should be ok. + The HANDLE will be valid. + */ + + TheFile = CreateFileA( + FileName, // file name + GENERIC_READ, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Tried to open a file that was created as " + "READONLY with the GENERIC_READ access mode. This should" + " cause CreateFileA to return an valid handle, but " + "INVALID_HANDLE_VALUE was returned!."); + } + + /* Close that HANDLE */ + + TheResult = CloseHandle(TheFile); + + if(TheResult == 0) + { + Fail("ERROR: CloseHandle failed. This tests relies upon it " + "working properly."); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/CMakeLists.txt index 35927b4b1d..825554da74 100644 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileAttributesW.c + SetFileAttributesW.cpp ) add_executable(paltest_setfileattributesw_test1 diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.c b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.c deleted file mode 100644 index 753c396d1f..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.c +++ /dev/null @@ -1,167 +0,0 @@ -// 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: SetFileAttributesW.c -** -** Purpose: Tests the PAL implementation of the SetFileAttributesW function -** Test that we can set a file READONLY, and then that we're unable to -** open that file with WRITE access. Then change it to NORMAL attributes, and -** try to open it again -- it should work now. -** -** Depends: -** CreateFile -** CloseHandle -** -** -**===================================================================*/ - -/* According to the spec, only READONLY attribute can be set - in FreeBSD. -*/ - -#define UNICODE - -#include - - - -int __cdecl main(int argc, char **argv) -{ - DWORD TheResult; - HANDLE TheFile; - CHAR *FileName_Multibyte = "test_file"; - WCHAR FileName[MAX_PATH]; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // Create the test file - FILE *testFile = fopen(FileName_Multibyte, "w"); - if (testFile == NULL) - { - Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); - } - if (fputs("testing", testFile) == EOF) - { - Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); - } - if (fclose(testFile) != 0) - { - Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); - } - testFile = NULL; - - /* Make a wide character string for the file name */ - - MultiByteToWideChar(CP_ACP, - 0, - FileName_Multibyte, - -1, - FileName, - MAX_PATH); - - - /* Try to set the file to Read-only */ - - TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_READONLY); - - if(TheResult == 0) - { - Fail("ERROR: SetFileAttributes returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_READONLY attribute."); - } - - /* Attempt to open this READONLY file with WRITE access, - The open should fail and the HANDLE should be invalid. - */ - - TheFile = CreateFile( - FileName, // file name - GENERIC_READ|GENERIC_WRITE, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile != INVALID_HANDLE_VALUE) - { - Fail("ERROR: Tried to open a file that was created as " - "READONLY with the GENERIC_WRITE access mode. This should" - " cause CreateFile to return an INVALID_HANDLE_VALUE."); - } - - /* Try to open the file with READ access, this should be ok. - The HANDLE will be valid. - */ - - TheFile = CreateFile( - FileName, // file name - GENERIC_READ, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Tried to open a file that was created as " - "READONLY with the GENERIC_READ access mode. This should" - " cause CreateFile to return an valid handle, but " - "INVALID_HANDLE_VALUE was returned!."); - } - - /* Close that HANDLE */ - - TheResult = CloseHandle(TheFile); - - if(TheResult == 0) - { - Fail("ERROR: CloseHandle failed. This tests relies upon it " - "working properly."); - } - - /* Set the file to NORMAL */ - - TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL); - - if(TheResult == 0) - { - Fail("ERROR: SetFileAttributes returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_NORMAL attribute."); - } - - /* To ensure that the set worked correctly, try to open the file - with WRITE access again -- this time it should succeed. - */ - - TheFile = CreateFile( - FileName, // file name - GENERIC_READ|GENERIC_WRITE, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Tried to open a file that was created as " - "NORMAL with the GENERIC_WRITE access mode. This should" - " cause CreateFile to return an valid handle, but " - "INVALID_HANDLE_VALUE was returned!."); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.cpp b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.cpp new file mode 100644 index 0000000000..753c396d1f --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test1/SetFileAttributesW.cpp @@ -0,0 +1,167 @@ +// 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: SetFileAttributesW.c +** +** Purpose: Tests the PAL implementation of the SetFileAttributesW function +** Test that we can set a file READONLY, and then that we're unable to +** open that file with WRITE access. Then change it to NORMAL attributes, and +** try to open it again -- it should work now. +** +** Depends: +** CreateFile +** CloseHandle +** +** +**===================================================================*/ + +/* According to the spec, only READONLY attribute can be set + in FreeBSD. +*/ + +#define UNICODE + +#include + + + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + HANDLE TheFile; + CHAR *FileName_Multibyte = "test_file"; + WCHAR FileName[MAX_PATH]; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // Create the test file + FILE *testFile = fopen(FileName_Multibyte, "w"); + if (testFile == NULL) + { + Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); + } + if (fputs("testing", testFile) == EOF) + { + Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); + } + if (fclose(testFile) != 0) + { + Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); + } + testFile = NULL; + + /* Make a wide character string for the file name */ + + MultiByteToWideChar(CP_ACP, + 0, + FileName_Multibyte, + -1, + FileName, + MAX_PATH); + + + /* Try to set the file to Read-only */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_READONLY); + + if(TheResult == 0) + { + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_READONLY attribute."); + } + + /* Attempt to open this READONLY file with WRITE access, + The open should fail and the HANDLE should be invalid. + */ + + TheFile = CreateFile( + FileName, // file name + GENERIC_READ|GENERIC_WRITE, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile != INVALID_HANDLE_VALUE) + { + Fail("ERROR: Tried to open a file that was created as " + "READONLY with the GENERIC_WRITE access mode. This should" + " cause CreateFile to return an INVALID_HANDLE_VALUE."); + } + + /* Try to open the file with READ access, this should be ok. + The HANDLE will be valid. + */ + + TheFile = CreateFile( + FileName, // file name + GENERIC_READ, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Tried to open a file that was created as " + "READONLY with the GENERIC_READ access mode. This should" + " cause CreateFile to return an valid handle, but " + "INVALID_HANDLE_VALUE was returned!."); + } + + /* Close that HANDLE */ + + TheResult = CloseHandle(TheFile); + + if(TheResult == 0) + { + Fail("ERROR: CloseHandle failed. This tests relies upon it " + "working properly."); + } + + /* Set the file to NORMAL */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL); + + if(TheResult == 0) + { + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_NORMAL attribute."); + } + + /* To ensure that the set worked correctly, try to open the file + with WRITE access again -- this time it should succeed. + */ + + TheFile = CreateFile( + FileName, // file name + GENERIC_READ|GENERIC_WRITE, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Tried to open a file that was created as " + "NORMAL with the GENERIC_WRITE access mode. This should" + " cause CreateFile to return an valid handle, but " + "INVALID_HANDLE_VALUE was returned!."); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/CMakeLists.txt index 81fa02c1dd..fda1cec1d7 100644 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileAttributesW.c + SetFileAttributesW.cpp ) add_executable(paltest_setfileattributesw_test2 diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.c b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.c deleted file mode 100644 index f657436845..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.c +++ /dev/null @@ -1,121 +0,0 @@ -// 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: SetFileAttributesW.c -** -** Purpose: Tests the PAL implementation of the SetFileAttributesW function -** Test that we can set the defined attributes aside from READONLY on a -** file, and that it doesn't return failure. Note, these attributes won't -** do anything to the file, however. -** -** -**===================================================================*/ - -#define UNICODE - -#include - -/* this cleanup method tries to revert the file back to its initial attributes */ -void do_cleanup(WCHAR* filename, DWORD attributes) -{ - DWORD result; - result = SetFileAttributes(filename, attributes); - if (result == 0) - { - Fail("ERROR:SetFileAttributesW returned 0,failure in the do_cleanup " - "method when trying to revert the file back to its initial attributes (%u)", GetLastError()); - } -} - -int __cdecl main(int argc, char **argv) -{ - DWORD TheResult; - DWORD initialAttr; - CHAR *FileName_Multibyte = "test_file"; - WCHAR FileName[MAX_PATH]; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // Create the test file - FILE *testFile = fopen(FileName_Multibyte, "w"); - if (testFile == NULL) - { - Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); - } - if (fputs("testing", testFile) == EOF) - { - Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); - } - if (fclose(testFile) != 0) - { - Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); - } - testFile = NULL; - - /* Make a wide character string for the file name */ - - MultiByteToWideChar(CP_ACP, - 0, - FileName_Multibyte, - -1, - FileName, - MAX_PATH); - - /* Get the initial attributes of the file */ - initialAttr = GetFileAttributesW(FileName); - - /* Try to set the file to HIDDEN */ - - TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_HIDDEN); - - if(TheResult == 0) - { - do_cleanup(FileName,initialAttr); - Fail("ERROR: SetFileAttributes returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_HIDDEN attribute. This should " - "not do anything in FreeBSD, but it shouldn't fail."); - } - - /* Try to set the file to ARCHIVE */ - - TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_ARCHIVE); - - if(TheResult == 0) - { - do_cleanup(FileName,initialAttr); - Fail("ERROR: SetFileAttributes returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_ARCHIVE attribute."); - } - - /* Try to set the file to SYSTEM */ - - TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_SYSTEM); - - if(TheResult == 0) - { - do_cleanup(FileName,initialAttr); - Fail("ERROR: SetFileAttributes returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_SYSTEM attribute."); - } - - /* Try to set the file to DIRECTORY */ - - TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_DIRECTORY); - - if(TheResult == 0) - { - do_cleanup(FileName,initialAttr); - Fail("ERROR: SetFileAttributes returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_DIRECTORY attribute."); - } - - do_cleanup(FileName,initialAttr); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.cpp b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.cpp new file mode 100644 index 0000000000..f657436845 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test2/SetFileAttributesW.cpp @@ -0,0 +1,121 @@ +// 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: SetFileAttributesW.c +** +** Purpose: Tests the PAL implementation of the SetFileAttributesW function +** Test that we can set the defined attributes aside from READONLY on a +** file, and that it doesn't return failure. Note, these attributes won't +** do anything to the file, however. +** +** +**===================================================================*/ + +#define UNICODE + +#include + +/* this cleanup method tries to revert the file back to its initial attributes */ +void do_cleanup(WCHAR* filename, DWORD attributes) +{ + DWORD result; + result = SetFileAttributes(filename, attributes); + if (result == 0) + { + Fail("ERROR:SetFileAttributesW returned 0,failure in the do_cleanup " + "method when trying to revert the file back to its initial attributes (%u)", GetLastError()); + } +} + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + DWORD initialAttr; + CHAR *FileName_Multibyte = "test_file"; + WCHAR FileName[MAX_PATH]; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // Create the test file + FILE *testFile = fopen(FileName_Multibyte, "w"); + if (testFile == NULL) + { + Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); + } + if (fputs("testing", testFile) == EOF) + { + Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); + } + if (fclose(testFile) != 0) + { + Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); + } + testFile = NULL; + + /* Make a wide character string for the file name */ + + MultiByteToWideChar(CP_ACP, + 0, + FileName_Multibyte, + -1, + FileName, + MAX_PATH); + + /* Get the initial attributes of the file */ + initialAttr = GetFileAttributesW(FileName); + + /* Try to set the file to HIDDEN */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_HIDDEN); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_HIDDEN attribute. This should " + "not do anything in FreeBSD, but it shouldn't fail."); + } + + /* Try to set the file to ARCHIVE */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_ARCHIVE); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_ARCHIVE attribute."); + } + + /* Try to set the file to SYSTEM */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_SYSTEM); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_SYSTEM attribute."); + } + + /* Try to set the file to DIRECTORY */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_DIRECTORY); + + if(TheResult == 0) + { + do_cleanup(FileName,initialAttr); + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_DIRECTORY attribute."); + } + + do_cleanup(FileName,initialAttr); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/CMakeLists.txt index c2cdacb0d0..1757f88bfe 100644 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileAttributesW.c + SetFileAttributesW.cpp ) add_executable(paltest_setfileattributesw_test3 diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.c b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.c deleted file mode 100644 index 8a8bafac68..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.c +++ /dev/null @@ -1,57 +0,0 @@ -// 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: SetFileAttributesW.c -** -** Purpose: Tests the PAL implementation of the SetFileAttributesW function -** Test that the function fails if the file doesn't exist.. -** -** -**===================================================================*/ - -#define UNICODE - -#include - - -int __cdecl main(int argc, char **argv) -{ - DWORD TheResult; - WCHAR FileName[MAX_PATH]; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Make a wide character string for the file name */ - - MultiByteToWideChar(CP_ACP, - 0, - "no_file", - -1, - FileName, - MAX_PATH); - - - /* Try to set the file to NORMAL on a file that doesn't - exist. - */ - - TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL); - - if(TheResult != 0) - { - Fail("ERROR: SetFileAttributes returned non-zero0, success, when" - " trying to set the FILE_ATTRIBUTE_NORMAL attribute on a non " - "existant file. This should fail."); - } - - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.cpp b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.cpp new file mode 100644 index 0000000000..8a8bafac68 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test3/SetFileAttributesW.cpp @@ -0,0 +1,57 @@ +// 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: SetFileAttributesW.c +** +** Purpose: Tests the PAL implementation of the SetFileAttributesW function +** Test that the function fails if the file doesn't exist.. +** +** +**===================================================================*/ + +#define UNICODE + +#include + + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + WCHAR FileName[MAX_PATH]; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Make a wide character string for the file name */ + + MultiByteToWideChar(CP_ACP, + 0, + "no_file", + -1, + FileName, + MAX_PATH); + + + /* Try to set the file to NORMAL on a file that doesn't + exist. + */ + + TheResult = SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL); + + if(TheResult != 0) + { + Fail("ERROR: SetFileAttributes returned non-zero0, success, when" + " trying to set the FILE_ATTRIBUTE_NORMAL attribute on a non " + "existant file. This should fail."); + } + + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/CMakeLists.txt index 6a4aa8adc3..d1cfcdd07d 100644 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileAttributesW.c + SetFileAttributesW.cpp ) add_executable(paltest_setfileattributesw_test4 diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.c b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.c deleted file mode 100644 index bebadfa264..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.c +++ /dev/null @@ -1,133 +0,0 @@ -// 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: SetFileAttributesW.c -** -** Purpose: Tests the PAL implementation of the SetFileAttributesW function -** Check that using two flags (READONLY and NORMAL) only sets the file -** as READONLY, as MSDN notes that everything else overrides NORMAL. -** -** Depends: -** CreateFile -** CloseHandle -** -** -**===================================================================*/ - -#define UNICODE - -#include - - - -int __cdecl main(int argc, char **argv) -{ - DWORD TheResult; - HANDLE TheFile; - CHAR *FileName_Multibyte = "test_file"; - WCHAR FileName[MAX_PATH]; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // Create the test file - FILE *testFile = fopen(FileName_Multibyte, "w"); - if (testFile == NULL) - { - Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); - } - if (fputs("testing", testFile) == EOF) - { - Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); - } - if (fclose(testFile) != 0) - { - Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); - } - testFile = NULL; - - /* Make a wide character string for the file name */ - - MultiByteToWideChar(CP_ACP, - 0, - FileName_Multibyte, - -1, - FileName, - MAX_PATH); - - - /* Try to set the file to Read-only|Normal ... It should - end up as Readonly, since this overrides Normal*/ - - TheResult = SetFileAttributes(FileName, - FILE_ATTRIBUTE_NORMAL| - FILE_ATTRIBUTE_READONLY); - - if(TheResult == 0) - { - Fail("ERROR: SetFileAttributes returned 0, failure, when trying " - "to set the FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_NORMAL " - "attribute."); - } - - /* Attempt to open this READONLY file with WRITE access, - The open should fail and the HANDLE should be invalid. - */ - - TheFile = CreateFile( - FileName, // file name - GENERIC_READ|GENERIC_WRITE, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile != INVALID_HANDLE_VALUE) - { - Fail("ERROR: Tried to open a file that was created as " - "READONLY with the GENERIC_WRITE access mode. This should" - " cause CreateFile to return an INVALID_HANDLE_VALUE."); - } - - /* Try to open the file with READ access, this should be ok. - The HANDLE will be valid. - */ - - TheFile = CreateFile( - FileName, // file name - GENERIC_READ, // access mode - 0, // share mode - NULL, // SD - OPEN_ALWAYS, // how to create - FILE_ATTRIBUTE_NORMAL, // file attributes - NULL // handle to template file - ); - - if(TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Tried to open a file that was created as " - "READONLY with the GENERIC_READ access mode. This should" - " cause CreateFile to return an valid handle, but " - "INVALID_HANDLE_VALUE was returned!."); - } - - /* Close that HANDLE */ - - TheResult = CloseHandle(TheFile); - - if(TheResult == 0) - { - Fail("ERROR: CloseHandle failed. This tests relies upon it " - "working properly."); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.cpp b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.cpp new file mode 100644 index 0000000000..bebadfa264 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileAttributesW/test4/SetFileAttributesW.cpp @@ -0,0 +1,133 @@ +// 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: SetFileAttributesW.c +** +** Purpose: Tests the PAL implementation of the SetFileAttributesW function +** Check that using two flags (READONLY and NORMAL) only sets the file +** as READONLY, as MSDN notes that everything else overrides NORMAL. +** +** Depends: +** CreateFile +** CloseHandle +** +** +**===================================================================*/ + +#define UNICODE + +#include + + + +int __cdecl main(int argc, char **argv) +{ + DWORD TheResult; + HANDLE TheFile; + CHAR *FileName_Multibyte = "test_file"; + WCHAR FileName[MAX_PATH]; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // Create the test file + FILE *testFile = fopen(FileName_Multibyte, "w"); + if (testFile == NULL) + { + Fail("Unexpected error: Unable to open file %S with fopen. \n", FileName); + } + if (fputs("testing", testFile) == EOF) + { + Fail("Unexpected error: Unable to write to file %S with fputs. \n", FileName); + } + if (fclose(testFile) != 0) + { + Fail("Unexpected error: Unable to close file %S with fclose. \n", FileName); + } + testFile = NULL; + + /* Make a wide character string for the file name */ + + MultiByteToWideChar(CP_ACP, + 0, + FileName_Multibyte, + -1, + FileName, + MAX_PATH); + + + /* Try to set the file to Read-only|Normal ... It should + end up as Readonly, since this overrides Normal*/ + + TheResult = SetFileAttributes(FileName, + FILE_ATTRIBUTE_NORMAL| + FILE_ATTRIBUTE_READONLY); + + if(TheResult == 0) + { + Fail("ERROR: SetFileAttributes returned 0, failure, when trying " + "to set the FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_NORMAL " + "attribute."); + } + + /* Attempt to open this READONLY file with WRITE access, + The open should fail and the HANDLE should be invalid. + */ + + TheFile = CreateFile( + FileName, // file name + GENERIC_READ|GENERIC_WRITE, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile != INVALID_HANDLE_VALUE) + { + Fail("ERROR: Tried to open a file that was created as " + "READONLY with the GENERIC_WRITE access mode. This should" + " cause CreateFile to return an INVALID_HANDLE_VALUE."); + } + + /* Try to open the file with READ access, this should be ok. + The HANDLE will be valid. + */ + + TheFile = CreateFile( + FileName, // file name + GENERIC_READ, // access mode + 0, // share mode + NULL, // SD + OPEN_ALWAYS, // how to create + FILE_ATTRIBUTE_NORMAL, // file attributes + NULL // handle to template file + ); + + if(TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Tried to open a file that was created as " + "READONLY with the GENERIC_READ access mode. This should" + " cause CreateFile to return an valid handle, but " + "INVALID_HANDLE_VALUE was returned!."); + } + + /* Close that HANDLE */ + + TheResult = CloseHandle(TheFile); + + if(TheResult == 0) + { + Fail("ERROR: CloseHandle failed. This tests relies upon it " + "working properly."); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFilePointer/test1/CMakeLists.txt index e352449981..bb09a981e9 100644 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFilePointer.c + SetFilePointer.cpp ) add_executable(paltest_setfilepointer_test1 diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.c b/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.c deleted file mode 100644 index 14b5f85e69..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.c +++ /dev/null @@ -1,123 +0,0 @@ -// 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: SetFilePointer.c (test 1) -** -** Purpose: Tests the PAL implementation of the SetFilePointer function. -** Set the file pointer using a NULL handle and other invalid -** options. -** -** -**===================================================================*/ - -#include - - -const char* szTextFile = "text.txt"; - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwByteCount = 0; - DWORD dwOffset = 25; - DWORD dwRc = 0; - BOOL bRc = FALSE; - char buffer[100]; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* set the file pointer on a NULL file handle */ - dwRc = SetFilePointer(NULL, dwOffset, NULL, FILE_BEGIN); - if (dwRc != INVALID_SET_FILE_POINTER) - { - Fail("SetFilePointer: ERROR -> Call to SetFilePointer succeeded " - "with a NULL pointer\n"); - } - - - /* create a test file without proper permission */ - hFile = CreateFile(szTextFile, - 0, - 0, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - /* ReadFile fails as expected */ - bRc = ReadFile(hFile, buffer, 1, &dwByteCount, NULL); - if (bRc != FALSE) - { - Trace("SetFilePointer: ERROR -> ReadFile was successful when it was " - "expected to fail\n"); - if (!CloseHandle(hFile)) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* move the file pointer before the beginning of the file */ - dwRc = SetFilePointer(hFile, -1, NULL, FILE_BEGIN); - if (dwRc != INVALID_SET_FILE_POINTER) - { - Trace("SetFilePointer: ERROR -> Was able to move the pointer before " - "the beginning of the file.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - if (!DeleteFileA(szTextFile)) - { - Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp b/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp new file mode 100644 index 0000000000..14b5f85e69 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp @@ -0,0 +1,123 @@ +// 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: SetFilePointer.c (test 1) +** +** Purpose: Tests the PAL implementation of the SetFilePointer function. +** Set the file pointer using a NULL handle and other invalid +** options. +** +** +**===================================================================*/ + +#include + + +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwByteCount = 0; + DWORD dwOffset = 25; + DWORD dwRc = 0; + BOOL bRc = FALSE; + char buffer[100]; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* set the file pointer on a NULL file handle */ + dwRc = SetFilePointer(NULL, dwOffset, NULL, FILE_BEGIN); + if (dwRc != INVALID_SET_FILE_POINTER) + { + Fail("SetFilePointer: ERROR -> Call to SetFilePointer succeeded " + "with a NULL pointer\n"); + } + + + /* create a test file without proper permission */ + hFile = CreateFile(szTextFile, + 0, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + /* ReadFile fails as expected */ + bRc = ReadFile(hFile, buffer, 1, &dwByteCount, NULL); + if (bRc != FALSE) + { + Trace("SetFilePointer: ERROR -> ReadFile was successful when it was " + "expected to fail\n"); + if (!CloseHandle(hFile)) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* move the file pointer before the beginning of the file */ + dwRc = SetFilePointer(hFile, -1, NULL, FILE_BEGIN); + if (dwRc != INVALID_SET_FILE_POINTER) + { + Trace("SetFilePointer: ERROR -> Was able to move the pointer before " + "the beginning of the file.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + if (!DeleteFileA(szTextFile)) + { + Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFilePointer/test2/CMakeLists.txt index 290a01107f..2e76f00c99 100644 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFilePointer.c + SetFilePointer.cpp ) add_executable(paltest_setfilepointer_test2 diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test2/SetFilePointer.c b/src/pal/tests/palsuite/file_io/SetFilePointer/test2/SetFilePointer.c deleted file mode 100644 index 19e99a74b3..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test2/SetFilePointer.c +++ /dev/null @@ -1,356 +0,0 @@ -// 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: SetFilePointer.c (test 2) -** -** Purpose: Tests the PAL implementation of the SetFilePointer function. -** Test the FILE_BEGIN option -** -** Assumes Successful: -** CreateFile -** ReadFile -** WriteFile -** strlen -** CloseHandle -** strcmp -** GetFileSize -** -** -**===================================================================*/ - -#include - -const char * const szText = - "The quick brown fox jumped over the lazy dog's back."; -const char* szTextFile = "text.txt"; - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwByteCount = 0; - DWORD dwRc = 0; - BOOL bRc = FALSE; - char szBuffer[100]; - const char *szPtr; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwByteCount, NULL); - if (bRc == FALSE) - { - Trace("SetFilePointer: ERROR -> Unable to write to file \"%s\".\n", - szTextFile); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - - /* move -1 from beginning which should fail */ - dwRc = SetFilePointer(hFile, -1, NULL, FILE_BEGIN); - if ((dwRc != INVALID_SET_FILE_POINTER) || - (GetLastError() == ERROR_SUCCESS)) - { - Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " - "before the beginning of the file.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* move the file pointer 0 bytes from the beginning and verify */ - dwRc = SetFilePointer(hFile, 0, NULL, FILE_BEGIN); - if (dwRc != 0) - { - Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " - "beginning of the file but moved %ld bytes.\n", dwRc); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* move the pointer ahead in the file and verify */ - dwRc = SetFilePointer(hFile, 20, NULL, FILE_BEGIN); - if (dwRc != 20) - { - Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " - "beginning of the file but moved %ld bytes.\n", dwRc); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify results */ - memset(szBuffer, 0, 100); - bRc = ReadFile(hFile, szBuffer, (DWORD)strlen(szText)-20, &dwByteCount, - NULL); - if ((bRc != TRUE) || (dwByteCount != strlen(szText)-20)) - { - Trace("SetFilePointer: ERROR -> ReadFile failed to read correctly"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - "\"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - "\"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - szPtr = szText + 20; - if (strcmp(szPtr, szBuffer) != 0) - { - Trace("SetFilePointer: ERROR -> Apparently failed to move the " - "pointer properly\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - /* move the file pointer back to the beginning and verify */ - dwRc = SetFilePointer(hFile, 0, NULL, FILE_BEGIN); - if (dwRc != 0) - { - Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " - "beginning of the file but moved %ld bytes.\n", dwRc); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify results */ - memset(szBuffer, 0, 100); - bRc = ReadFile(hFile, szBuffer, (DWORD)strlen(szText), &dwByteCount, - NULL); - if ((bRc != TRUE) || (dwByteCount != strlen(szText))) - { - Trace("SetFilePointer: ERROR -> ReadFile failed to read correctly"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - if (strcmp(szText, szBuffer) != 0) - { - Trace("SetFilePointer: ERROR -> Failed to return the pointer " - "properly to the beginning of the file\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - /* return the pointer to the beginning of the file */ - dwRc = SetFilePointer(hFile, 0, NULL, FILE_BEGIN); - if (dwRc != 0) - { - Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " - "beginning of the file but moved %ld bytes.\n", dwRc); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* set the pointer past the end of the file and verify */ - dwRc = SetFilePointer(hFile, (DWORD)strlen(szText)+20, NULL, FILE_BEGIN); - if ((dwRc == INVALID_SET_FILE_POINTER) && (GetLastError() != ERROR_SUCCESS)) - { - Trace("SetFilePointer: ERROR -> Failed to move pointer past EOF.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify */ - bRc = SetEndOfFile(hFile); - if (bRc != TRUE) - { - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - if (GetFileSize(hFile, NULL) != strlen(szText)+20) - { - Trace("SetFilePointer: ERROR -> Failed to move pointer past" - " EOF.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - - - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - if (!DeleteFileA(szTextFile)) - { - Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test2/SetFilePointer.cpp b/src/pal/tests/palsuite/file_io/SetFilePointer/test2/SetFilePointer.cpp new file mode 100644 index 0000000000..19e99a74b3 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test2/SetFilePointer.cpp @@ -0,0 +1,356 @@ +// 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: SetFilePointer.c (test 2) +** +** Purpose: Tests the PAL implementation of the SetFilePointer function. +** Test the FILE_BEGIN option +** +** Assumes Successful: +** CreateFile +** ReadFile +** WriteFile +** strlen +** CloseHandle +** strcmp +** GetFileSize +** +** +**===================================================================*/ + +#include + +const char * const szText = + "The quick brown fox jumped over the lazy dog's back."; +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwByteCount = 0; + DWORD dwRc = 0; + BOOL bRc = FALSE; + char szBuffer[100]; + const char *szPtr; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwByteCount, NULL); + if (bRc == FALSE) + { + Trace("SetFilePointer: ERROR -> Unable to write to file \"%s\".\n", + szTextFile); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + + /* move -1 from beginning which should fail */ + dwRc = SetFilePointer(hFile, -1, NULL, FILE_BEGIN); + if ((dwRc != INVALID_SET_FILE_POINTER) || + (GetLastError() == ERROR_SUCCESS)) + { + Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " + "before the beginning of the file.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* move the file pointer 0 bytes from the beginning and verify */ + dwRc = SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + if (dwRc != 0) + { + Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " + "beginning of the file but moved %ld bytes.\n", dwRc); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* move the pointer ahead in the file and verify */ + dwRc = SetFilePointer(hFile, 20, NULL, FILE_BEGIN); + if (dwRc != 20) + { + Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " + "beginning of the file but moved %ld bytes.\n", dwRc); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify results */ + memset(szBuffer, 0, 100); + bRc = ReadFile(hFile, szBuffer, (DWORD)strlen(szText)-20, &dwByteCount, + NULL); + if ((bRc != TRUE) || (dwByteCount != strlen(szText)-20)) + { + Trace("SetFilePointer: ERROR -> ReadFile failed to read correctly"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + "\"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + "\"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + szPtr = szText + 20; + if (strcmp(szPtr, szBuffer) != 0) + { + Trace("SetFilePointer: ERROR -> Apparently failed to move the " + "pointer properly\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + /* move the file pointer back to the beginning and verify */ + dwRc = SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + if (dwRc != 0) + { + Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " + "beginning of the file but moved %ld bytes.\n", dwRc); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify results */ + memset(szBuffer, 0, 100); + bRc = ReadFile(hFile, szBuffer, (DWORD)strlen(szText), &dwByteCount, + NULL); + if ((bRc != TRUE) || (dwByteCount != strlen(szText))) + { + Trace("SetFilePointer: ERROR -> ReadFile failed to read correctly"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + if (strcmp(szText, szBuffer) != 0) + { + Trace("SetFilePointer: ERROR -> Failed to return the pointer " + "properly to the beginning of the file\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + /* return the pointer to the beginning of the file */ + dwRc = SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + if (dwRc != 0) + { + Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " + "beginning of the file but moved %ld bytes.\n", dwRc); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* set the pointer past the end of the file and verify */ + dwRc = SetFilePointer(hFile, (DWORD)strlen(szText)+20, NULL, FILE_BEGIN); + if ((dwRc == INVALID_SET_FILE_POINTER) && (GetLastError() != ERROR_SUCCESS)) + { + Trace("SetFilePointer: ERROR -> Failed to move pointer past EOF.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify */ + bRc = SetEndOfFile(hFile); + if (bRc != TRUE) + { + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + if (GetFileSize(hFile, NULL) != strlen(szText)+20) + { + Trace("SetFilePointer: ERROR -> Failed to move pointer past" + " EOF.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + + + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + if (!DeleteFileA(szTextFile)) + { + Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFilePointer/test3/CMakeLists.txt index daa7553a1a..bcc3faca09 100644 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFilePointer.c + SetFilePointer.cpp ) add_executable(paltest_setfilepointer_test3 diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test3/SetFilePointer.c b/src/pal/tests/palsuite/file_io/SetFilePointer/test3/SetFilePointer.c deleted file mode 100644 index dd53829629..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test3/SetFilePointer.c +++ /dev/null @@ -1,350 +0,0 @@ -// 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: SetFilePointer.c (test 3) -** -** Purpose: Tests the PAL implementation of the SetFilePointer function. -** Test the FILE_CURRENT option -** -** Assumes Successful: -** CreateFile -** ReadFile -** WriteFile -** strlen -** CloseHandle -** strcmp -** GetFileSize -** -** -**===================================================================*/ - -#include - -const char* const szText = - "The quick brown fox jumped over the lazy dog's back."; -const char* szTextFile = "text.txt"; - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwByteCount = 0; - DWORD dwRc = 0; - BOOL bRc = FALSE; - char szBuffer[100]; - const char* szPtr; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwByteCount, NULL); - if (bRc == FALSE) - { - Trace("SetFilePointer: ERROR -> Unable to write to file \"%s\".\n", - szTextFile); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* reset the pointer to the beginning */ - if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - { - if (GetLastError() != ERROR_SUCCESS) - { - Trace("SetFilePointer: ERROR -> Unable to reset the pointer to the " - "beginning of the file"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - /* move -1 from beginning which should fail */ - dwRc = SetFilePointer(hFile, -1, NULL, FILE_CURRENT); - if ((dwRc != INVALID_SET_FILE_POINTER) || - (GetLastError() == ERROR_SUCCESS)) - { - Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " - "before the beginning of the file.\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - - /* move the file pointer 0 bytes from the beginning and verify */ - dwRc = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); - if (dwRc != 0) - { - Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " - "beginning of the file but moved %ld bytes.\n", dwRc); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* move the pointer ahead in the file and verify */ - dwRc = SetFilePointer(hFile, 20, NULL, FILE_CURRENT); - if (dwRc != 20) - { - Trace("SetFilePointer: ERROR -> Asked to move 20 bytes from the " - "beginning of the file but moved %ld bytes.\n", dwRc); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify results */ - memset(szBuffer, 0, 100); - bRc = ReadFile(hFile, szBuffer, (DWORD)strlen(szText)-20, &dwByteCount, - NULL); - if ((bRc != TRUE) || (dwByteCount != strlen(szText)-20)) - { - Trace("SetFilePointer: ERROR -> ReadFile failed to read correctly"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - szPtr = szText + 20;; - if (strcmp(szPtr, szBuffer) != 0) - { - Trace("SetFilePointer: ERROR -> Apparently failed to move the" - " pointer properly\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - - /* get the current file pointer position (should be 52) */ - dwRc = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); - if (dwRc != 52) - { - Trace("SetFilePointer: ERROR -> Asked for current position." - " Should be 52 but was %ld.\n", dwRc); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - - /* move the pointer backwards in the file and verify */ - dwRc = SetFilePointer(hFile, -10, NULL, FILE_CURRENT); - if (dwRc != 42) - { - Trace("SetFilePointer: ERROR -> Asked to move back 10 bytes from the" - "end of the file but moved it to position %ld.\n", dwRc); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify results */ - memset(szBuffer, 0, 100); - bRc = ReadFile(hFile, szBuffer, 10, &dwByteCount, NULL); - if ((bRc != TRUE) || (dwByteCount != 10)) - { - Trace("SetFilePointer: ERROR -> ReadFile failed to read correctly"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - szPtr = szText + 42; - if (strcmp(szPtr, szBuffer) != 0) - { - Trace("SetFilePointer: ERROR -> Apparently failed to move the" - " pointer properly\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - /* - * the file pointer is currently at the end of the file so... - * set the pointer past the end of the file and verify - */ - dwRc = SetFilePointer(hFile, 20, NULL, FILE_CURRENT); - if ((dwRc == INVALID_SET_FILE_POINTER) && (GetLastError() != ERROR_SUCCESS)) - { - Trace("SetFilePointer: ERROR -> Failed to move pointer past EOF.\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - if (SetFilePointer(hFile, 0, NULL, FILE_CURRENT) != strlen(szText)+20) - { - Trace("SetFilePointer: ERROR -> Failed to move pointer past" - " EOF.\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - if (!DeleteFileA(szTextFile)) - { - Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test3/SetFilePointer.cpp b/src/pal/tests/palsuite/file_io/SetFilePointer/test3/SetFilePointer.cpp new file mode 100644 index 0000000000..dd53829629 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test3/SetFilePointer.cpp @@ -0,0 +1,350 @@ +// 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: SetFilePointer.c (test 3) +** +** Purpose: Tests the PAL implementation of the SetFilePointer function. +** Test the FILE_CURRENT option +** +** Assumes Successful: +** CreateFile +** ReadFile +** WriteFile +** strlen +** CloseHandle +** strcmp +** GetFileSize +** +** +**===================================================================*/ + +#include + +const char* const szText = + "The quick brown fox jumped over the lazy dog's back."; +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwByteCount = 0; + DWORD dwRc = 0; + BOOL bRc = FALSE; + char szBuffer[100]; + const char* szPtr; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwByteCount, NULL); + if (bRc == FALSE) + { + Trace("SetFilePointer: ERROR -> Unable to write to file \"%s\".\n", + szTextFile); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* reset the pointer to the beginning */ + if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + { + if (GetLastError() != ERROR_SUCCESS) + { + Trace("SetFilePointer: ERROR -> Unable to reset the pointer to the " + "beginning of the file"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + /* move -1 from beginning which should fail */ + dwRc = SetFilePointer(hFile, -1, NULL, FILE_CURRENT); + if ((dwRc != INVALID_SET_FILE_POINTER) || + (GetLastError() == ERROR_SUCCESS)) + { + Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " + "before the beginning of the file.\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + + /* move the file pointer 0 bytes from the beginning and verify */ + dwRc = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); + if (dwRc != 0) + { + Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " + "beginning of the file but moved %ld bytes.\n", dwRc); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* move the pointer ahead in the file and verify */ + dwRc = SetFilePointer(hFile, 20, NULL, FILE_CURRENT); + if (dwRc != 20) + { + Trace("SetFilePointer: ERROR -> Asked to move 20 bytes from the " + "beginning of the file but moved %ld bytes.\n", dwRc); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify results */ + memset(szBuffer, 0, 100); + bRc = ReadFile(hFile, szBuffer, (DWORD)strlen(szText)-20, &dwByteCount, + NULL); + if ((bRc != TRUE) || (dwByteCount != strlen(szText)-20)) + { + Trace("SetFilePointer: ERROR -> ReadFile failed to read correctly"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + szPtr = szText + 20;; + if (strcmp(szPtr, szBuffer) != 0) + { + Trace("SetFilePointer: ERROR -> Apparently failed to move the" + " pointer properly\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + + /* get the current file pointer position (should be 52) */ + dwRc = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); + if (dwRc != 52) + { + Trace("SetFilePointer: ERROR -> Asked for current position." + " Should be 52 but was %ld.\n", dwRc); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + + /* move the pointer backwards in the file and verify */ + dwRc = SetFilePointer(hFile, -10, NULL, FILE_CURRENT); + if (dwRc != 42) + { + Trace("SetFilePointer: ERROR -> Asked to move back 10 bytes from the" + "end of the file but moved it to position %ld.\n", dwRc); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify results */ + memset(szBuffer, 0, 100); + bRc = ReadFile(hFile, szBuffer, 10, &dwByteCount, NULL); + if ((bRc != TRUE) || (dwByteCount != 10)) + { + Trace("SetFilePointer: ERROR -> ReadFile failed to read correctly"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + szPtr = szText + 42; + if (strcmp(szPtr, szBuffer) != 0) + { + Trace("SetFilePointer: ERROR -> Apparently failed to move the" + " pointer properly\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + /* + * the file pointer is currently at the end of the file so... + * set the pointer past the end of the file and verify + */ + dwRc = SetFilePointer(hFile, 20, NULL, FILE_CURRENT); + if ((dwRc == INVALID_SET_FILE_POINTER) && (GetLastError() != ERROR_SUCCESS)) + { + Trace("SetFilePointer: ERROR -> Failed to move pointer past EOF.\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + if (SetFilePointer(hFile, 0, NULL, FILE_CURRENT) != strlen(szText)+20) + { + Trace("SetFilePointer: ERROR -> Failed to move pointer past" + " EOF.\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + if (!DeleteFileA(szTextFile)) + { + Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFilePointer/test4/CMakeLists.txt index 1117893350..3fcc4066f2 100644 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFilePointer.c + SetFilePointer.cpp ) add_executable(paltest_setfilepointer_test4 diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test4/SetFilePointer.c b/src/pal/tests/palsuite/file_io/SetFilePointer/test4/SetFilePointer.c deleted file mode 100644 index 2993cfd354..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test4/SetFilePointer.c +++ /dev/null @@ -1,242 +0,0 @@ -// 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: SetFilePointer.c (test 4) -** -** Purpose: Tests the PAL implementation of the SetFilePointer function. -** Test the FILE_END option -** -** Assumes Successful: -** CreateFile -** ReadFile -** WriteFile -** strlen -** CloseHandle -** strcmp -** GetFileSize -** -** -**===================================================================*/ - -#include - -const char* szText = "The quick brown fox jumped over the lazy dog's back."; -const char* szTextFile = "text.txt"; - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwByteCount = 0; - DWORD dwOffset = 0; - DWORD dwRc = 0; - BOOL bRc = FALSE; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwByteCount, NULL); - if (bRc == FALSE) - { - Trace("SetFilePointer: ERROR -> Unable to write to file \"%s\".\n", - szTextFile); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - - /* - * move -1 from the end - */ - dwRc = SetFilePointer(hFile, -1, NULL, FILE_END); - if (dwRc == INVALID_SET_FILE_POINTER) - { - if (GetLastError() != ERROR_SUCCESS) - { - Trace("SetFilePointer: ERROR -> Failed to move the pointer " - "back one character from EOF.\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - else - { - /* verify */ - if ((dwRc != strlen(szText)-1)) - { - Trace("SetFilePointer: ERROR -> Failed to move the pointer" - " -1 bytes from EOF\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - /* - * move the file pointer 0 bytes from the end and verify - */ - dwRc = SetFilePointer(hFile, 0, NULL, FILE_END); - if (dwRc != strlen(szText)) - { - Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " - "end of the file. Function returned %ld instead of 52.\n", dwRc); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* - * move the pointer past the end of the file and verify - */ - dwRc = SetFilePointer(hFile, 20, NULL, FILE_END); - if (dwRc != strlen(szText)+20) - { - Trace("SetFilePointer: ERROR -> Asked to move 20 bytes past the " - "end of the file. Function returned %ld instead of %d.\n", - dwRc, - strlen(szText)+20); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify results */ - bRc = SetEndOfFile(hFile); - if ((dwRc = GetFileSize(hFile, NULL)) != strlen(szText)+20) - { - Trace("SetFilePointer: ERROR -> Asked to move back 20 bytes past" - " theend of the file. GetFileSize returned %ld whereas it " - "should have been %d.\n", - dwRc, - strlen(szText)+20); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - - /* - * move the pointer backwards to before the start of the file and verify - */ - - dwOffset = (dwRc + 20) * -1; - dwRc = SetFilePointer(hFile, dwOffset, NULL, FILE_END); - if ((dwRc != INVALID_SET_FILE_POINTER) || - (GetLastError() == ERROR_SUCCESS)) - { - Trace("SetFilePointer: ERROR -> Was able to move the pointer " - "to before the beginning of the file.\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - if (!DeleteFileA(szTextFile)) - { - Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test4/SetFilePointer.cpp b/src/pal/tests/palsuite/file_io/SetFilePointer/test4/SetFilePointer.cpp new file mode 100644 index 0000000000..2993cfd354 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test4/SetFilePointer.cpp @@ -0,0 +1,242 @@ +// 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: SetFilePointer.c (test 4) +** +** Purpose: Tests the PAL implementation of the SetFilePointer function. +** Test the FILE_END option +** +** Assumes Successful: +** CreateFile +** ReadFile +** WriteFile +** strlen +** CloseHandle +** strcmp +** GetFileSize +** +** +**===================================================================*/ + +#include + +const char* szText = "The quick brown fox jumped over the lazy dog's back."; +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwByteCount = 0; + DWORD dwOffset = 0; + DWORD dwRc = 0; + BOOL bRc = FALSE; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwByteCount, NULL); + if (bRc == FALSE) + { + Trace("SetFilePointer: ERROR -> Unable to write to file \"%s\".\n", + szTextFile); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + + /* + * move -1 from the end + */ + dwRc = SetFilePointer(hFile, -1, NULL, FILE_END); + if (dwRc == INVALID_SET_FILE_POINTER) + { + if (GetLastError() != ERROR_SUCCESS) + { + Trace("SetFilePointer: ERROR -> Failed to move the pointer " + "back one character from EOF.\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + else + { + /* verify */ + if ((dwRc != strlen(szText)-1)) + { + Trace("SetFilePointer: ERROR -> Failed to move the pointer" + " -1 bytes from EOF\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + /* + * move the file pointer 0 bytes from the end and verify + */ + dwRc = SetFilePointer(hFile, 0, NULL, FILE_END); + if (dwRc != strlen(szText)) + { + Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the " + "end of the file. Function returned %ld instead of 52.\n", dwRc); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* + * move the pointer past the end of the file and verify + */ + dwRc = SetFilePointer(hFile, 20, NULL, FILE_END); + if (dwRc != strlen(szText)+20) + { + Trace("SetFilePointer: ERROR -> Asked to move 20 bytes past the " + "end of the file. Function returned %ld instead of %d.\n", + dwRc, + strlen(szText)+20); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify results */ + bRc = SetEndOfFile(hFile); + if ((dwRc = GetFileSize(hFile, NULL)) != strlen(szText)+20) + { + Trace("SetFilePointer: ERROR -> Asked to move back 20 bytes past" + " theend of the file. GetFileSize returned %ld whereas it " + "should have been %d.\n", + dwRc, + strlen(szText)+20); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + + /* + * move the pointer backwards to before the start of the file and verify + */ + + dwOffset = (dwRc + 20) * -1; + dwRc = SetFilePointer(hFile, dwOffset, NULL, FILE_END); + if ((dwRc != INVALID_SET_FILE_POINTER) || + (GetLastError() == ERROR_SUCCESS)) + { + Trace("SetFilePointer: ERROR -> Was able to move the pointer " + "to before the beginning of the file.\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + if (!DeleteFileA(szTextFile)) + { + Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test5/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFilePointer/test5/CMakeLists.txt index b37bf42ffc..3012009e4f 100644 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFilePointer.c + SetFilePointer.cpp ) add_executable(paltest_setfilepointer_test5 diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test5/SetFilePointer.c b/src/pal/tests/palsuite/file_io/SetFilePointer/test5/SetFilePointer.c deleted file mode 100644 index f1d392da38..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test5/SetFilePointer.c +++ /dev/null @@ -1,182 +0,0 @@ -// 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: SetFilePointer.c (test 5) -** -** Purpose: Tests the PAL implementation of the SetFilePointer function. -** Test the FILE_BEGIN option using the high word parameter -** -** Assumes Successful: -** CreateFile -** ReadFile -** WriteFile -** strlen -** CloseHandle -** strcmp -** GetFileSize -** -** -**===================================================================*/ - -#include - -const char* szTextFile = "text.txt"; - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwOffset = 1; - LONG dwHighWord = 1; - DWORD dwReturnedOffset = 0; - DWORD dwReturnedHighWord = 0; - DWORD dwRc = 0; - DWORD dwError = 0; - BOOL bRc = FALSE; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - dwError = GetLastError(); - Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n with " - "error %ld", - szTextFile, - GetLastError()); - } - - - - /* move -1 from beginning which should fail */ - dwRc = SetFilePointer(hFile, -1, &dwHighWord, FILE_BEGIN); - if (dwRc != INVALID_SET_FILE_POINTER) - { - Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " - "before the beginning of the file using the high word.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* set the pointer past the end of the file and verify */ - dwRc = SetFilePointer(hFile, dwOffset, &dwHighWord, FILE_BEGIN); - if ((dwRc == INVALID_SET_FILE_POINTER) && - ((dwError = GetLastError()) != ERROR_SUCCESS)) - { - Trace("SetFilePointer: ERROR -> Failed to move pointer past EOF.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify */ - bRc = SetEndOfFile(hFile); - if (bRc != TRUE) - { - dwError = GetLastError(); - if (dwError == 112) - { - Trace("SetFilePointer: ERROR -> SetEndOfFile failed due to " - "lack of disk space\n"); - } - else - { - Trace("SetFilePointer: ERROR -> SetEndOfFile call failed with " - "error %ld\n", dwError); - } - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - dwReturnedOffset = GetFileSize(hFile, &dwReturnedHighWord); - if ((dwOffset != dwReturnedOffset) || - (dwHighWord != dwReturnedHighWord)) - { - Trace("SetFilePointer: ERROR -> Failed to move pointer past" - " EOF.\n"); - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - if (!DeleteFileA(szTextFile)) - { - Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test5/SetFilePointer.cpp b/src/pal/tests/palsuite/file_io/SetFilePointer/test5/SetFilePointer.cpp new file mode 100644 index 0000000000..f1d392da38 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test5/SetFilePointer.cpp @@ -0,0 +1,182 @@ +// 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: SetFilePointer.c (test 5) +** +** Purpose: Tests the PAL implementation of the SetFilePointer function. +** Test the FILE_BEGIN option using the high word parameter +** +** Assumes Successful: +** CreateFile +** ReadFile +** WriteFile +** strlen +** CloseHandle +** strcmp +** GetFileSize +** +** +**===================================================================*/ + +#include + +const char* szTextFile = "text.txt"; + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwOffset = 1; + LONG dwHighWord = 1; + DWORD dwReturnedOffset = 0; + DWORD dwReturnedHighWord = 0; + DWORD dwRc = 0; + DWORD dwError = 0; + BOOL bRc = FALSE; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + dwError = GetLastError(); + Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n with " + "error %ld", + szTextFile, + GetLastError()); + } + + + + /* move -1 from beginning which should fail */ + dwRc = SetFilePointer(hFile, -1, &dwHighWord, FILE_BEGIN); + if (dwRc != INVALID_SET_FILE_POINTER) + { + Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " + "before the beginning of the file using the high word.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* set the pointer past the end of the file and verify */ + dwRc = SetFilePointer(hFile, dwOffset, &dwHighWord, FILE_BEGIN); + if ((dwRc == INVALID_SET_FILE_POINTER) && + ((dwError = GetLastError()) != ERROR_SUCCESS)) + { + Trace("SetFilePointer: ERROR -> Failed to move pointer past EOF.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify */ + bRc = SetEndOfFile(hFile); + if (bRc != TRUE) + { + dwError = GetLastError(); + if (dwError == 112) + { + Trace("SetFilePointer: ERROR -> SetEndOfFile failed due to " + "lack of disk space\n"); + } + else + { + Trace("SetFilePointer: ERROR -> SetEndOfFile call failed with " + "error %ld\n", dwError); + } + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + dwReturnedOffset = GetFileSize(hFile, &dwReturnedHighWord); + if ((dwOffset != dwReturnedOffset) || + (dwHighWord != dwReturnedHighWord)) + { + Trace("SetFilePointer: ERROR -> Failed to move pointer past" + " EOF.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + if (!DeleteFileA(szTextFile)) + { + Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test6/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFilePointer/test6/CMakeLists.txt index 8f99ed2d76..a376acbe28 100644 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFilePointer.c + SetFilePointer.cpp ) add_executable(paltest_setfilepointer_test6 diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test6/SetFilePointer.c b/src/pal/tests/palsuite/file_io/SetFilePointer/test6/SetFilePointer.c deleted file mode 100644 index b35247ec24..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test6/SetFilePointer.c +++ /dev/null @@ -1,213 +0,0 @@ -// 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: SetFilePointer.c (test 6) -** -** Purpose: Tests the PAL implementation of the SetFilePointer function. -** Test the FILE_CURRENT option with high order support -** -** Assumes Successful: -** CreateFile -** ReadFile -** WriteFile -** strlen -** CloseHandle -** strcmp -** GetFileSize -** -** -**===================================================================*/ - -#include - -const char* szTextFile = "text.txt"; - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwOffset = 0; - LONG dwHighOrder = 0; - DWORD dwReturnedOffset = 0; - LONG dwReturnedHighOrder = 0; - DWORD dwRc = 0; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - - /* move waaaay before the beginning which should fail */ - dwHighOrder = -1; - dwOffset = 0; - dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_CURRENT); - if (dwRc != INVALID_SET_FILE_POINTER) - { - Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " - "before the beginning of the file.\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* move the pointer ahead in the file and verify */ - dwHighOrder = 1; - dwOffset = 10; - dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_CURRENT); - if ((dwRc != 10) || (dwHighOrder != 1)) - { - Trace("SetFilePointer: ERROR -> Asked to move 2GB plus 10 bytes from " - "the beginning of the file but didn't.\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify results */ - if (SetEndOfFile(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Call to SetEndOfFile failed with " - "error code: %d\n", GetLastError()); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - dwReturnedOffset = GetFileSize(hFile, (DWORD*)&dwReturnedHighOrder); - if ((dwReturnedOffset != dwOffset) || - (dwReturnedHighOrder != dwHighOrder)) - { - Trace("SetFilePointer: ERROR -> Asked to move far past the " - "current file pointer. " - "low order sent: %ld low order returned: %ld " - "high order sent: %ld high order returned: %ld", - dwOffset, dwReturnedOffset, - dwHighOrder, dwReturnedHighOrder); - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - - /* - * move the pointer backwards in the file and verify - */ - dwOffset = 0; - dwHighOrder = -1; - dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_CURRENT); - if (dwRc != 10) - { - Trace("SetFilePointer: ERROR -> Asked to move back to 10 bytes from the" - "beginning of the file but moved it to position %ld.\n", dwRc); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify results */ - dwReturnedHighOrder = 0; - dwRc = SetFilePointer(hFile, 0, &dwReturnedHighOrder, FILE_CURRENT); - if (dwRc != 10) - { - Trace("SetFilePointer: ERROR -> Asked for current position. " - "Should be 10 but was %ld.\n", dwRc); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - - /* clean up, clean up, everybody do their share... */ - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - if (!DeleteFileA(szTextFile)) - { - Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test6/SetFilePointer.cpp b/src/pal/tests/palsuite/file_io/SetFilePointer/test6/SetFilePointer.cpp new file mode 100644 index 0000000000..b35247ec24 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test6/SetFilePointer.cpp @@ -0,0 +1,213 @@ +// 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: SetFilePointer.c (test 6) +** +** Purpose: Tests the PAL implementation of the SetFilePointer function. +** Test the FILE_CURRENT option with high order support +** +** Assumes Successful: +** CreateFile +** ReadFile +** WriteFile +** strlen +** CloseHandle +** strcmp +** GetFileSize +** +** +**===================================================================*/ + +#include + +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwOffset = 0; + LONG dwHighOrder = 0; + DWORD dwReturnedOffset = 0; + LONG dwReturnedHighOrder = 0; + DWORD dwRc = 0; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + + /* move waaaay before the beginning which should fail */ + dwHighOrder = -1; + dwOffset = 0; + dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_CURRENT); + if (dwRc != INVALID_SET_FILE_POINTER) + { + Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " + "before the beginning of the file.\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* move the pointer ahead in the file and verify */ + dwHighOrder = 1; + dwOffset = 10; + dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_CURRENT); + if ((dwRc != 10) || (dwHighOrder != 1)) + { + Trace("SetFilePointer: ERROR -> Asked to move 2GB plus 10 bytes from " + "the beginning of the file but didn't.\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify results */ + if (SetEndOfFile(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Call to SetEndOfFile failed with " + "error code: %d\n", GetLastError()); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + dwReturnedOffset = GetFileSize(hFile, (DWORD*)&dwReturnedHighOrder); + if ((dwReturnedOffset != dwOffset) || + (dwReturnedHighOrder != dwHighOrder)) + { + Trace("SetFilePointer: ERROR -> Asked to move far past the " + "current file pointer. " + "low order sent: %ld low order returned: %ld " + "high order sent: %ld high order returned: %ld", + dwOffset, dwReturnedOffset, + dwHighOrder, dwReturnedHighOrder); + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + + /* + * move the pointer backwards in the file and verify + */ + dwOffset = 0; + dwHighOrder = -1; + dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_CURRENT); + if (dwRc != 10) + { + Trace("SetFilePointer: ERROR -> Asked to move back to 10 bytes from the" + "beginning of the file but moved it to position %ld.\n", dwRc); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify results */ + dwReturnedHighOrder = 0; + dwRc = SetFilePointer(hFile, 0, &dwReturnedHighOrder, FILE_CURRENT); + if (dwRc != 10) + { + Trace("SetFilePointer: ERROR -> Asked for current position. " + "Should be 10 but was %ld.\n", dwRc); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + + /* clean up, clean up, everybody do their share... */ + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + if (!DeleteFileA(szTextFile)) + { + Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test7/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFilePointer/test7/CMakeLists.txt index c5a46a531a..2b5c0bbb45 100644 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFilePointer.c + SetFilePointer.cpp ) add_executable(paltest_setfilepointer_test7 diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test7/SetFilePointer.c b/src/pal/tests/palsuite/file_io/SetFilePointer/test7/SetFilePointer.c deleted file mode 100644 index 33dfd5e711..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFilePointer/test7/SetFilePointer.c +++ /dev/null @@ -1,213 +0,0 @@ -// 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: SetFilePointer.c (test 7) -** -** Purpose: Tests the PAL implementation of the SetFilePointer function. -** Test the FILE_END option with high order support -** -** Assumes Successful: -** CreateFile -** ReadFile -** WriteFile -** strlen -** CloseHandle -** strcmp -** GetFileSize -** -** -**===================================================================*/ - -#include - -const char* szTextFile = "text.txt"; - - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwOffset = 0; - LONG dwHighOrder = 0; - DWORD dwReturnedOffset = 0; - LONG dwReturnedHighOrder = 0; - DWORD dwRc = 0; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create a test file */ - hFile = CreateFile(szTextFile, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", - szTextFile); - } - - - /* move -1 from beginning which should fail */ - dwHighOrder = -1; - dwOffset = 0; - dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_END); - if (dwRc != INVALID_SET_FILE_POINTER) - { - Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " - "before the beginning of the file.\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* move the pointer ahead in the file and verify */ - dwHighOrder = 1; - dwOffset = 10; - dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_END); - if ((dwRc != 10) || (dwHighOrder != 1)) - { - Trace("SetFilePointer: ERROR -> Asked to move 4GB plus 10 bytes from " - "the beginning of the file but didn't.\n"); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify results */ - if (SetEndOfFile(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Call to SetEndOfFile failed with " - "error code: %d\n", - GetLastError()); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - dwReturnedOffset = GetFileSize(hFile, (DWORD*)&dwReturnedHighOrder); - if ((dwReturnedOffset != dwOffset) || (dwReturnedHighOrder != dwHighOrder)) - { - Trace("SetFilePointer: ERROR -> Asked to move far past the " - "end of the file. low order sent: %ld low order returned: %ld " - "high order sent: %ld high order returned: %ld", - dwOffset, dwReturnedOffset, - dwHighOrder, dwReturnedHighOrder); - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - - /* - * move the pointer backwards in the file and verify - */ - dwOffset = 0; - dwHighOrder = -1; - dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_END); - if (dwRc != 10) - { - Trace("SetFilePointer: ERROR -> Asked to move back to 10 bytes from the" - "beginning of the file but moved it to position %ld.\n", dwRc); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - else - { - /* verify results */ - dwReturnedHighOrder = 0; - dwRc = SetFilePointer(hFile, 0, &dwReturnedHighOrder, FILE_CURRENT); - if (dwRc != 10) - { - Trace("SetFilePointer: ERROR -> Asked for current position. " - "Should be 10 but was %ld.\n", dwRc); - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file" - " \"%s\".\n", szTextFile); - } - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file" - " \"%s\".\n", szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - } - - - /* clean up, clean up, everybody do their share... */ - if (CloseHandle(hFile) != TRUE) - { - Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", - szTextFile); - if (!DeleteFileA(szTextFile)) - { - Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - PAL_TerminateEx(FAIL); - return FAIL; - } - - if (!DeleteFileA(szTextFile)) - { - Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", - szTextFile); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test7/SetFilePointer.cpp b/src/pal/tests/palsuite/file_io/SetFilePointer/test7/SetFilePointer.cpp new file mode 100644 index 0000000000..33dfd5e711 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test7/SetFilePointer.cpp @@ -0,0 +1,213 @@ +// 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: SetFilePointer.c (test 7) +** +** Purpose: Tests the PAL implementation of the SetFilePointer function. +** Test the FILE_END option with high order support +** +** Assumes Successful: +** CreateFile +** ReadFile +** WriteFile +** strlen +** CloseHandle +** strcmp +** GetFileSize +** +** +**===================================================================*/ + +#include + +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwOffset = 0; + LONG dwHighOrder = 0; + DWORD dwReturnedOffset = 0; + LONG dwReturnedHighOrder = 0; + DWORD dwRc = 0; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + + /* move -1 from beginning which should fail */ + dwHighOrder = -1; + dwOffset = 0; + dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_END); + if (dwRc != INVALID_SET_FILE_POINTER) + { + Trace("SetFilePointer: ERROR -> Succeeded to move the pointer " + "before the beginning of the file.\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* move the pointer ahead in the file and verify */ + dwHighOrder = 1; + dwOffset = 10; + dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_END); + if ((dwRc != 10) || (dwHighOrder != 1)) + { + Trace("SetFilePointer: ERROR -> Asked to move 4GB plus 10 bytes from " + "the beginning of the file but didn't.\n"); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify results */ + if (SetEndOfFile(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Call to SetEndOfFile failed with " + "error code: %d\n", + GetLastError()); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + dwReturnedOffset = GetFileSize(hFile, (DWORD*)&dwReturnedHighOrder); + if ((dwReturnedOffset != dwOffset) || (dwReturnedHighOrder != dwHighOrder)) + { + Trace("SetFilePointer: ERROR -> Asked to move far past the " + "end of the file. low order sent: %ld low order returned: %ld " + "high order sent: %ld high order returned: %ld", + dwOffset, dwReturnedOffset, + dwHighOrder, dwReturnedHighOrder); + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + + /* + * move the pointer backwards in the file and verify + */ + dwOffset = 0; + dwHighOrder = -1; + dwRc = SetFilePointer(hFile, dwOffset, &dwHighOrder, FILE_END); + if (dwRc != 10) + { + Trace("SetFilePointer: ERROR -> Asked to move back to 10 bytes from the" + "beginning of the file but moved it to position %ld.\n", dwRc); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + else + { + /* verify results */ + dwReturnedHighOrder = 0; + dwRc = SetFilePointer(hFile, 0, &dwReturnedHighOrder, FILE_CURRENT); + if (dwRc != 10) + { + Trace("SetFilePointer: ERROR -> Asked for current position. " + "Should be 10 but was %ld.\n", dwRc); + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file" + " \"%s\".\n", szTextFile); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file" + " \"%s\".\n", szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + } + + + /* clean up, clean up, everybody do their share... */ + if (CloseHandle(hFile) != TRUE) + { + Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + if (!DeleteFileA(szTextFile)) + { + Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + if (!DeleteFileA(szTextFile)) + { + Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", + szTextFile); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileTime/test1/CMakeLists.txt index 4c4b5d7611..b94bd05d76 100644 --- a/src/pal/tests/palsuite/file_io/SetFileTime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileTime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileTime.c + SetFileTime.cpp ) add_executable(paltest_setfiletime_test1 diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.c b/src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.c deleted file mode 100644 index 4711aeba89..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.c +++ /dev/null @@ -1,129 +0,0 @@ -// 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: SetFileTime.c -** -** Purpose: Tests the PAL implementation of the SetFileTime function. -** This test first sets a valid file time on the file which is opened. -** Then it calls GetFileTime, and compares the values. They should -** be the same. Note: Access time isn't checked in this test. It will -** be dealt with seperatly due to odd behaviour. -** -** Depends: -** CreateFile -** GetFileTime -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - -#if WIN32 - FILETIME Creation; - FILETIME SetCreation; -#endif - FILETIME LastWrite; - FILETIME SetLastWrite; - HANDLE TheFileHandle; - BOOL result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Populate some FILETIME structures with values - These values are valid Creation, Access and Write times - which I generated, and should work properly. - */ -#if WIN32 - SetCreation.dwLowDateTime = 458108416; - SetCreation.dwHighDateTime = 29436904; -#endif - - SetLastWrite.dwLowDateTime = -1995099136; - SetLastWrite.dwHighDateTime = 29436915; - - - /* Open the file to get a HANDLE */ - TheFileHandle = CreateFile("the_file", - GENERIC_READ|GENERIC_WRITE, - 0, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to open the file. The error number " - "returned was %d.\n",GetLastError()); - } - - /* Set the new file time */ -#if WIN32 - result = SetFileTime(TheFileHandle, - &SetCreation, NULL, &SetLastWrite); -#else - result = SetFileTime(TheFileHandle, - NULL, NULL, &SetLastWrite); -#endif - if(result == 0) - { - Fail("ERROR: SetFileTime failed when trying to set the " - "new file time. The GetLastError was %d.\n",GetLastError()); - } - - - /* Then get the file time of the file */ -#if WIN32 - result = GetFileTime(TheFileHandle, &Creation, NULL, &LastWrite); -#else - result = GetFileTime(TheFileHandle, NULL, NULL, &LastWrite); -#endif - - if(result == 0) - { - Fail("ERROR: GetFileTime failed, and this tests depends " - "upon it working properly, in order to ensure that the " - "file time was set with SetFileTime. GetLastError() " - "returned %d.\n",GetLastError()); - } - - /* Compare the write time we Set to the write time aquired with - Get. They should be the same. - */ - - if(LastWrite.dwLowDateTime != SetLastWrite.dwLowDateTime || - LastWrite.dwHighDateTime != SetLastWrite.dwHighDateTime) - { - Fail("ERROR: After setting the write time, it is not " - "equal to what it was set to. Either Set of GetFileTime are " - "broken.\n"); - } - - /* Within FreeBSD, the Creation time is ignored when SetFileTime - is called. Since FreeBSD has no equivalent. For that reason, - it is not checked with the following test. - */ - -#if WIN32 - if(Creation.dwHighDateTime != SetCreation.dwHighDateTime || - Creation.dwLowDateTime != SetCreation.dwLowDateTime) - { - Fail("ERROR: After setting the file time, the Creation " - "time is not what it should be. Either Set or GetFileTime " - "are broken."); - } -#endif - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.cpp b/src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.cpp new file mode 100644 index 0000000000..4711aeba89 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.cpp @@ -0,0 +1,129 @@ +// 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: SetFileTime.c +** +** Purpose: Tests the PAL implementation of the SetFileTime function. +** This test first sets a valid file time on the file which is opened. +** Then it calls GetFileTime, and compares the values. They should +** be the same. Note: Access time isn't checked in this test. It will +** be dealt with seperatly due to odd behaviour. +** +** Depends: +** CreateFile +** GetFileTime +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + +#if WIN32 + FILETIME Creation; + FILETIME SetCreation; +#endif + FILETIME LastWrite; + FILETIME SetLastWrite; + HANDLE TheFileHandle; + BOOL result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Populate some FILETIME structures with values + These values are valid Creation, Access and Write times + which I generated, and should work properly. + */ +#if WIN32 + SetCreation.dwLowDateTime = 458108416; + SetCreation.dwHighDateTime = 29436904; +#endif + + SetLastWrite.dwLowDateTime = -1995099136; + SetLastWrite.dwHighDateTime = 29436915; + + + /* Open the file to get a HANDLE */ + TheFileHandle = CreateFile("the_file", + GENERIC_READ|GENERIC_WRITE, + 0, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the file. The error number " + "returned was %d.\n",GetLastError()); + } + + /* Set the new file time */ +#if WIN32 + result = SetFileTime(TheFileHandle, + &SetCreation, NULL, &SetLastWrite); +#else + result = SetFileTime(TheFileHandle, + NULL, NULL, &SetLastWrite); +#endif + if(result == 0) + { + Fail("ERROR: SetFileTime failed when trying to set the " + "new file time. The GetLastError was %d.\n",GetLastError()); + } + + + /* Then get the file time of the file */ +#if WIN32 + result = GetFileTime(TheFileHandle, &Creation, NULL, &LastWrite); +#else + result = GetFileTime(TheFileHandle, NULL, NULL, &LastWrite); +#endif + + if(result == 0) + { + Fail("ERROR: GetFileTime failed, and this tests depends " + "upon it working properly, in order to ensure that the " + "file time was set with SetFileTime. GetLastError() " + "returned %d.\n",GetLastError()); + } + + /* Compare the write time we Set to the write time aquired with + Get. They should be the same. + */ + + if(LastWrite.dwLowDateTime != SetLastWrite.dwLowDateTime || + LastWrite.dwHighDateTime != SetLastWrite.dwHighDateTime) + { + Fail("ERROR: After setting the write time, it is not " + "equal to what it was set to. Either Set of GetFileTime are " + "broken.\n"); + } + + /* Within FreeBSD, the Creation time is ignored when SetFileTime + is called. Since FreeBSD has no equivalent. For that reason, + it is not checked with the following test. + */ + +#if WIN32 + if(Creation.dwHighDateTime != SetCreation.dwHighDateTime || + Creation.dwLowDateTime != SetCreation.dwLowDateTime) + { + Fail("ERROR: After setting the file time, the Creation " + "time is not what it should be. Either Set or GetFileTime " + "are broken."); + } +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileTime/test2/CMakeLists.txt index 35c18c8d8d..5478aa3703 100644 --- a/src/pal/tests/palsuite/file_io/SetFileTime/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileTime/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileTime.c + SetFileTime.cpp ) add_executable(paltest_setfiletime_test2 diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.c b/src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.c deleted file mode 100644 index e950153bb0..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.c +++ /dev/null @@ -1,101 +0,0 @@ -// 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: SetFileTime.c -** -** Purpose: Tests the PAL implementation of the SetFileTime -** This test first tries to SetFileTime on a HANDLE which doesn't have -** GENERIC_WRITE set, which should fail. -** -** -** Depends: -** CreateFile -** CloseHandle -** -** -**===================================================================*/ - -#include - - - - -int __cdecl main(int argc, char **argv) -{ - - FILETIME SetCreation,SetLastAccess,SetLastWrite; - HANDLE TheFileHandle; - BOOL result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Populate some FILETIME structures with values - These values are valid Creation, Access and Write times - which I generated, and should work properly. - - The access times are not seperated into WIN32 and FreeBSD here, - but it should be fine, as no comparisons are being done in this - test. - */ - - SetCreation.dwLowDateTime = 458108416; - SetCreation.dwHighDateTime = 29436904; - - SetLastAccess.dwLowDateTime = 341368832; - SetLastAccess.dwHighDateTime = 29436808; - - SetLastWrite.dwLowDateTime = -1995099136; - SetLastWrite.dwHighDateTime = 29436915; - - -/* Open the file to get a HANDLE, without GENERIC WRITE */ - - TheFileHandle = - CreateFile( - "the_file", - GENERIC_READ, - 0, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to open the file. The error number " - "returned was %d.",GetLastError()); - } - - /* This SetFileTime should fail, because the HANDLE isn't set with - GENERIC_WRITE - */ - result = SetFileTime(TheFileHandle, - &SetCreation,&SetLastAccess,&SetLastWrite); - - if(result != 0) - { - Fail("ERROR: SetFileTime should have failed, but returned a " - "non-zero result. The File HANDLE passed was no set Writable " - "which should cause failure."); - } - - result = CloseHandle(TheFileHandle); - - if(result == 0) - { - Fail("ERROR: CloseHandle failed. This test depends upon " - "it working."); - } - - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.cpp b/src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.cpp new file mode 100644 index 0000000000..e950153bb0 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.cpp @@ -0,0 +1,101 @@ +// 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: SetFileTime.c +** +** Purpose: Tests the PAL implementation of the SetFileTime +** This test first tries to SetFileTime on a HANDLE which doesn't have +** GENERIC_WRITE set, which should fail. +** +** +** Depends: +** CreateFile +** CloseHandle +** +** +**===================================================================*/ + +#include + + + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME SetCreation,SetLastAccess,SetLastWrite; + HANDLE TheFileHandle; + BOOL result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Populate some FILETIME structures with values + These values are valid Creation, Access and Write times + which I generated, and should work properly. + + The access times are not seperated into WIN32 and FreeBSD here, + but it should be fine, as no comparisons are being done in this + test. + */ + + SetCreation.dwLowDateTime = 458108416; + SetCreation.dwHighDateTime = 29436904; + + SetLastAccess.dwLowDateTime = 341368832; + SetLastAccess.dwHighDateTime = 29436808; + + SetLastWrite.dwLowDateTime = -1995099136; + SetLastWrite.dwHighDateTime = 29436915; + + +/* Open the file to get a HANDLE, without GENERIC WRITE */ + + TheFileHandle = + CreateFile( + "the_file", + GENERIC_READ, + 0, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the file. The error number " + "returned was %d.",GetLastError()); + } + + /* This SetFileTime should fail, because the HANDLE isn't set with + GENERIC_WRITE + */ + result = SetFileTime(TheFileHandle, + &SetCreation,&SetLastAccess,&SetLastWrite); + + if(result != 0) + { + Fail("ERROR: SetFileTime should have failed, but returned a " + "non-zero result. The File HANDLE passed was no set Writable " + "which should cause failure."); + } + + result = CloseHandle(TheFileHandle); + + if(result == 0) + { + Fail("ERROR: CloseHandle failed. This test depends upon " + "it working."); + } + + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileTime/test3/CMakeLists.txt index 0a85d30c51..26e178a328 100644 --- a/src/pal/tests/palsuite/file_io/SetFileTime/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileTime/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileTime.c + SetFileTime.cpp ) add_executable(paltest_setfiletime_test3 diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.c b/src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.c deleted file mode 100644 index 97f49495d7..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: SetFileTime.c -** -** Purpose: Tests the PAL implementation of the SetFileTime function. -** This test checks to ensure that the function fails when passed an -** invalid file HANDLE -** -** -**===================================================================*/ - - - -#include - - - - -int __cdecl main(int argc, char **argv) -{ - - FILETIME SetCreation, SetLastWrite, SetLastAccess; - HANDLE TheFileHandle = NULL; - BOOL result; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Populate some FILETIME structures with values - These values are valid Creation, Access and Write times - which I generated, and should work properly. - */ - - SetCreation.dwLowDateTime = 458108416; - SetCreation.dwHighDateTime = 29436904; - - SetLastAccess.dwLowDateTime = 341368832; - SetLastAccess.dwHighDateTime = 29436808; - - SetLastWrite.dwLowDateTime = -1995099136; - SetLastWrite.dwHighDateTime = 29436915; - - - /* Pass this function an invalid file HANDLE and it should - fail. - */ - - result = SetFileTime(TheFileHandle, - &SetCreation,&SetLastAccess,&SetLastWrite); - - if(result != 0) - { - Fail("ERROR: Passed an invalid file HANDLE to SetFileTime, but it " - "returned non-zero. This should return zero for failure."); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.cpp b/src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.cpp new file mode 100644 index 0000000000..97f49495d7 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.cpp @@ -0,0 +1,66 @@ +// 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: SetFileTime.c +** +** Purpose: Tests the PAL implementation of the SetFileTime function. +** This test checks to ensure that the function fails when passed an +** invalid file HANDLE +** +** +**===================================================================*/ + + + +#include + + + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME SetCreation, SetLastWrite, SetLastAccess; + HANDLE TheFileHandle = NULL; + BOOL result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Populate some FILETIME structures with values + These values are valid Creation, Access and Write times + which I generated, and should work properly. + */ + + SetCreation.dwLowDateTime = 458108416; + SetCreation.dwHighDateTime = 29436904; + + SetLastAccess.dwLowDateTime = 341368832; + SetLastAccess.dwHighDateTime = 29436808; + + SetLastWrite.dwLowDateTime = -1995099136; + SetLastWrite.dwHighDateTime = 29436915; + + + /* Pass this function an invalid file HANDLE and it should + fail. + */ + + result = SetFileTime(TheFileHandle, + &SetCreation,&SetLastAccess,&SetLastWrite); + + if(result != 0) + { + Fail("ERROR: Passed an invalid file HANDLE to SetFileTime, but it " + "returned non-zero. This should return zero for failure."); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileTime/test4/CMakeLists.txt index 086e35e535..b85a92bf63 100644 --- a/src/pal/tests/palsuite/file_io/SetFileTime/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetFileTime/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - SetFileTime.c + SetFileTime.cpp ) add_executable(paltest_setfiletime_test4 diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.c b/src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.c deleted file mode 100644 index 3edd2403c4..0000000000 --- a/src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.c +++ /dev/null @@ -1,108 +0,0 @@ -// 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: SetFileTime.c -** -** Purpose: Tests the PAL implementation of the SetFileTime function -** This passes a variety of NULL values as parameters to the function. -** It should still succeed. -** -** Depends: -** CreateFile -** - -** -**===================================================================*/ - -#include - - - -int __cdecl main(int argc, char **argv) -{ -#if WIN32 - FILETIME Creation; -#endif - FILETIME LastWrite,LastAccess; - HANDLE TheFileHandle; - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Populate some FILETIME structures with values - These values are valid Creation, Access and Write times - which I generated, and should work properly. - - These values aren't being used for comparison, so they should - work ok, even though they weren't generated specifically for - FreeBSD or WIN32 ... - */ -#if WIN32 - Creation.dwLowDateTime = 458108416; - Creation.dwHighDateTime = 29436904; -#endif - LastAccess.dwLowDateTime = 341368832; - LastAccess.dwHighDateTime = 29436808; - - LastWrite.dwLowDateTime = -1995099136; - LastWrite.dwHighDateTime = 29436915; - - /* Open the file to get a HANDLE */ - TheFileHandle = - CreateFile( - "the_file", - GENERIC_READ|GENERIC_WRITE, - 0, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - - if(TheFileHandle == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Failed to open the file. The error number " - "returned was %d.",GetLastError()); - } - - /* Pass all NULLs, this is useless but should still work. */ - if(SetFileTime(TheFileHandle,NULL,NULL,NULL)==0) - { - Fail("ERROR: SetFileTime returned 0, indicating failure. " - "Three of the params were NULL in this case, did they " - "cause the problem?"); - } - -#if WIN32 - /* Set the Creation time of the File */ - if(SetFileTime(TheFileHandle,&Creation,NULL,NULL)==0) - { - Fail("ERROR: SetFileTime returned 0, indicating failure. " - "Two of the params were NULL in this case, did they " - "cause the problem?"); - } -#endif - -#if WIN32 - /* Set the Creation, LastWrite time of the File */ - if(SetFileTime(TheFileHandle,&Creation,&LastWrite,NULL)==0) -#else - /* Set the LastWrite time of the File */ - if(SetFileTime(TheFileHandle,NULL,&LastWrite,NULL)==0) -#endif - { - Fail("ERROR: SetFileTime returned 0, indicating failure. " - "One of the params were NULL in this case, did it " - "cause the problem?"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.cpp b/src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.cpp new file mode 100644 index 0000000000..3edd2403c4 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.cpp @@ -0,0 +1,108 @@ +// 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: SetFileTime.c +** +** Purpose: Tests the PAL implementation of the SetFileTime function +** This passes a variety of NULL values as parameters to the function. +** It should still succeed. +** +** Depends: +** CreateFile +** + +** +**===================================================================*/ + +#include + + + +int __cdecl main(int argc, char **argv) +{ +#if WIN32 + FILETIME Creation; +#endif + FILETIME LastWrite,LastAccess; + HANDLE TheFileHandle; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Populate some FILETIME structures with values + These values are valid Creation, Access and Write times + which I generated, and should work properly. + + These values aren't being used for comparison, so they should + work ok, even though they weren't generated specifically for + FreeBSD or WIN32 ... + */ +#if WIN32 + Creation.dwLowDateTime = 458108416; + Creation.dwHighDateTime = 29436904; +#endif + LastAccess.dwLowDateTime = 341368832; + LastAccess.dwHighDateTime = 29436808; + + LastWrite.dwLowDateTime = -1995099136; + LastWrite.dwHighDateTime = 29436915; + + /* Open the file to get a HANDLE */ + TheFileHandle = + CreateFile( + "the_file", + GENERIC_READ|GENERIC_WRITE, + 0, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the file. The error number " + "returned was %d.",GetLastError()); + } + + /* Pass all NULLs, this is useless but should still work. */ + if(SetFileTime(TheFileHandle,NULL,NULL,NULL)==0) + { + Fail("ERROR: SetFileTime returned 0, indicating failure. " + "Three of the params were NULL in this case, did they " + "cause the problem?"); + } + +#if WIN32 + /* Set the Creation time of the File */ + if(SetFileTime(TheFileHandle,&Creation,NULL,NULL)==0) + { + Fail("ERROR: SetFileTime returned 0, indicating failure. " + "Two of the params were NULL in this case, did they " + "cause the problem?"); + } +#endif + +#if WIN32 + /* Set the Creation, LastWrite time of the File */ + if(SetFileTime(TheFileHandle,&Creation,&LastWrite,NULL)==0) +#else + /* Set the LastWrite time of the File */ + if(SetFileTime(TheFileHandle,NULL,&LastWrite,NULL)==0) +#endif + { + Fail("ERROR: SetFileTime returned 0, indicating failure. " + "One of the params were NULL in this case, did it " + "cause the problem?"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/WriteFile/test1/CMakeLists.txt index 0c6760a2ce..3d5a735a83 100644 --- a/src/pal/tests/palsuite/file_io/WriteFile/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/WriteFile/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - WriteFile.c + WriteFile.cpp ) add_executable(paltest_writefile_test1 diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test1/WriteFile.c b/src/pal/tests/palsuite/file_io/WriteFile/test1/WriteFile.c deleted file mode 100644 index 1ac38ddaf0..0000000000 --- a/src/pal/tests/palsuite/file_io/WriteFile/test1/WriteFile.c +++ /dev/null @@ -1,114 +0,0 @@ -// 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: WriteFile.c (test 1) -** -** Purpose: Tests the PAL implementation of the WriteFile function. -** This test will attempt to write to a NULL handle and a -** read-only file -** -** -**===================================================================*/ - -#include - - -const char* szStringTest = "The quick fox jumped over the lazy dog's back."; -const char* szReadOnlyFile = "ReadOnly.txt"; -void do_cleanup() -{ - BOOL bRc = FALSE; - bRc = DeleteFileA(szReadOnlyFile); - if (bRc != TRUE) - { - Fail ("DeleteFileA: ERROR[%ld]: During Cleanup: Couldn't delete WriteFile's" - " \"ReadOnly.txt\"\n", GetLastError()); - } - -} - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFile = NULL; - DWORD dwBytesWritten; - BOOL bRc = FALSE; - DWORD last_error; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - // - // Write to a NULL handle - // - - bRc = WriteFile(hFile, szStringTest, 20, &dwBytesWritten, NULL); - - if (bRc == TRUE) - { - last_error = GetLastError(); - Fail("WriteFile: ERROR[%ld] -> Able to write to a NULL handle\n", last_error); - } - - - // - // Write to a file with read-only permissions - // - - // create a file without write permissions - hFile = CreateFile(szReadOnlyFile, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - last_error = GetLastError(); - Fail("WriteFile: ERROR[%ld] -> Unable to create file \"%s\".\n", - last_error, szReadOnlyFile); - } - - if (!SetFileAttributes(szReadOnlyFile, FILE_ATTRIBUTE_READONLY)) - { - last_error = GetLastError(); - Trace("WriteFile: ERROR[%ld] -> Unable to make the file read-only.\n", last_error); - do_cleanup(); - Fail("WriteFile: ERROR[%ld] -> Unable to make the file read-only.\n", last_error); - } - - bRc = WriteFile(hFile, szStringTest, 20, &dwBytesWritten, NULL); - if (bRc == TRUE) - { last_error = GetLastError(); - Trace("WriteFile: ERROR[%ld] -> Able to write to a read-only file.\n", last_error); - do_cleanup(); - Fail("WriteFile: ERROR[%ld] -> Able to write to a read-only file.\n", last_error); - } - - - bRc = CloseHandle(hFile); - if (bRc != TRUE) - { last_error = GetLastError(); - Trace("WriteFile: ERROR[%ld] -> Unable to close file \"%s\".\n", last_error, szReadOnlyFile); - do_cleanup(); - Fail("WriteFile: ERROR -> Unable to close file \"%s\".\n", - szReadOnlyFile); - } - - //To delete file need to make it normal - if(!SetFileAttributesA(szReadOnlyFile,FILE_ATTRIBUTE_NORMAL)) - { - last_error = GetLastError(); - Fail("WriteFile: ERROR[%ld] -> Unable to make the file attribute NORMAL.\n", last_error); - - } - do_cleanup(); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test1/WriteFile.cpp b/src/pal/tests/palsuite/file_io/WriteFile/test1/WriteFile.cpp new file mode 100644 index 0000000000..1ac38ddaf0 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/WriteFile/test1/WriteFile.cpp @@ -0,0 +1,114 @@ +// 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: WriteFile.c (test 1) +** +** Purpose: Tests the PAL implementation of the WriteFile function. +** This test will attempt to write to a NULL handle and a +** read-only file +** +** +**===================================================================*/ + +#include + + +const char* szStringTest = "The quick fox jumped over the lazy dog's back."; +const char* szReadOnlyFile = "ReadOnly.txt"; +void do_cleanup() +{ + BOOL bRc = FALSE; + bRc = DeleteFileA(szReadOnlyFile); + if (bRc != TRUE) + { + Fail ("DeleteFileA: ERROR[%ld]: During Cleanup: Couldn't delete WriteFile's" + " \"ReadOnly.txt\"\n", GetLastError()); + } + +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwBytesWritten; + BOOL bRc = FALSE; + DWORD last_error; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + // + // Write to a NULL handle + // + + bRc = WriteFile(hFile, szStringTest, 20, &dwBytesWritten, NULL); + + if (bRc == TRUE) + { + last_error = GetLastError(); + Fail("WriteFile: ERROR[%ld] -> Able to write to a NULL handle\n", last_error); + } + + + // + // Write to a file with read-only permissions + // + + // create a file without write permissions + hFile = CreateFile(szReadOnlyFile, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + last_error = GetLastError(); + Fail("WriteFile: ERROR[%ld] -> Unable to create file \"%s\".\n", + last_error, szReadOnlyFile); + } + + if (!SetFileAttributes(szReadOnlyFile, FILE_ATTRIBUTE_READONLY)) + { + last_error = GetLastError(); + Trace("WriteFile: ERROR[%ld] -> Unable to make the file read-only.\n", last_error); + do_cleanup(); + Fail("WriteFile: ERROR[%ld] -> Unable to make the file read-only.\n", last_error); + } + + bRc = WriteFile(hFile, szStringTest, 20, &dwBytesWritten, NULL); + if (bRc == TRUE) + { last_error = GetLastError(); + Trace("WriteFile: ERROR[%ld] -> Able to write to a read-only file.\n", last_error); + do_cleanup(); + Fail("WriteFile: ERROR[%ld] -> Able to write to a read-only file.\n", last_error); + } + + + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { last_error = GetLastError(); + Trace("WriteFile: ERROR[%ld] -> Unable to close file \"%s\".\n", last_error, szReadOnlyFile); + do_cleanup(); + Fail("WriteFile: ERROR -> Unable to close file \"%s\".\n", + szReadOnlyFile); + } + + //To delete file need to make it normal + if(!SetFileAttributesA(szReadOnlyFile,FILE_ATTRIBUTE_NORMAL)) + { + last_error = GetLastError(); + Fail("WriteFile: ERROR[%ld] -> Unable to make the file attribute NORMAL.\n", last_error); + + } + do_cleanup(); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/WriteFile/test2/CMakeLists.txt index a9b51efa3d..3d7d18826a 100644 --- a/src/pal/tests/palsuite/file_io/WriteFile/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/WriteFile/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - WriteFile.c + WriteFile.cpp ) add_executable(paltest_writefile_test2 diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test2/WriteFile.c b/src/pal/tests/palsuite/file_io/WriteFile/test2/WriteFile.c deleted file mode 100644 index 24c148afb8..0000000000 --- a/src/pal/tests/palsuite/file_io/WriteFile/test2/WriteFile.c +++ /dev/null @@ -1,109 +0,0 @@ -// 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: WriteFile.c (test 2) -** -** Purpose: Tests the PAL implementation of the WriteFile function. -** Creates a number of files and writes different amounts of -** data and verifies the writes. -** -** -**===================================================================*/ - - -#include - - -char* writeBuffer; -const char* szWritableFile = "Writeable.txt"; -const char* szResultsFile = "Results.txt"; -#ifdef __sparc__ -const int PAGESIZE = 8192; -#else // __sparc__ -const int PAGESIZE = 4096; -#endif // __sparc__ - -BOOL writeTest(DWORD dwByteCount, DWORD dwBytesWrittenResult, BOOL bResult) -{ - HANDLE hFile = NULL; - DWORD dwBytesWritten; - BOOL bRc = FALSE; - - /* create the test file */ - DeleteFile(szWritableFile); - hFile = CreateFile(szWritableFile, GENERIC_WRITE, FILE_SHARE_WRITE, - NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Trace("WriteFile: ERROR -> Unable to create file \"%s\".\n", - szWritableFile); - return FALSE; - } - - bRc = WriteFile(hFile, writeBuffer, dwByteCount, &dwBytesWritten, NULL); - CloseHandle(hFile); - - if ((bRc != bResult) || (dwBytesWrittenResult != dwBytesWritten)) - { - Trace("WriteFile returned BOOL:%d and dwWritten:%d what we do expect is" - " BOOL:%d and dwWritten:%d\n", bRc, dwBytesWritten, bResult, - dwBytesWrittenResult); - return FALSE; - } - - return TRUE; -} - -int __cdecl main(int argc, char *argv[]) -{ - const char * testString = "The quick fox jumped over the lazy dog's back."; - const int testStringLen = strlen(testString); - - DWORD dwByteCount[4] = {-1, 10, testStringLen, 0}; - DWORD dwByteWritten[4] = {0, 10, testStringLen, 0}; - BOOL bResults[] = {FALSE, TRUE, TRUE, TRUE}; - - const int BUFFER_SIZE = 2 * PAGESIZE; - int j; - BOOL bRc = FALSE; - DWORD oldProt; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* allocate read-write memery for writeBuffer */ - if (!(writeBuffer = (char*) VirtualAlloc(NULL, BUFFER_SIZE, MEM_COMMIT, - PAGE_READWRITE))) - { - Fail("VirtualAlloc failed: GetLastError returns %d\n", GetLastError()); - return FAIL; - } - - memset((void*) writeBuffer, '.', BUFFER_SIZE); - strcpy(writeBuffer, testString); - - /* write protect the second page of writeBuffer */ - if (!VirtualProtect(&writeBuffer[PAGESIZE], PAGESIZE, PAGE_NOACCESS, &oldProt)) - { - Fail("VirtualProtect failed: GetLastError returns %d\n", GetLastError()); - return FAIL; - } - - for (j = 0; j< 4; j++) - { - bRc = writeTest(dwByteCount[j], dwByteWritten[j], bResults[j]); - if (bRc != TRUE) - { - Fail("WriteFile: ERROR -> Failed on test[%d]\n", j); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test2/WriteFile.cpp b/src/pal/tests/palsuite/file_io/WriteFile/test2/WriteFile.cpp new file mode 100644 index 0000000000..24c148afb8 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/WriteFile/test2/WriteFile.cpp @@ -0,0 +1,109 @@ +// 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: WriteFile.c (test 2) +** +** Purpose: Tests the PAL implementation of the WriteFile function. +** Creates a number of files and writes different amounts of +** data and verifies the writes. +** +** +**===================================================================*/ + + +#include + + +char* writeBuffer; +const char* szWritableFile = "Writeable.txt"; +const char* szResultsFile = "Results.txt"; +#ifdef __sparc__ +const int PAGESIZE = 8192; +#else // __sparc__ +const int PAGESIZE = 4096; +#endif // __sparc__ + +BOOL writeTest(DWORD dwByteCount, DWORD dwBytesWrittenResult, BOOL bResult) +{ + HANDLE hFile = NULL; + DWORD dwBytesWritten; + BOOL bRc = FALSE; + + /* create the test file */ + DeleteFile(szWritableFile); + hFile = CreateFile(szWritableFile, GENERIC_WRITE, FILE_SHARE_WRITE, + NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Trace("WriteFile: ERROR -> Unable to create file \"%s\".\n", + szWritableFile); + return FALSE; + } + + bRc = WriteFile(hFile, writeBuffer, dwByteCount, &dwBytesWritten, NULL); + CloseHandle(hFile); + + if ((bRc != bResult) || (dwBytesWrittenResult != dwBytesWritten)) + { + Trace("WriteFile returned BOOL:%d and dwWritten:%d what we do expect is" + " BOOL:%d and dwWritten:%d\n", bRc, dwBytesWritten, bResult, + dwBytesWrittenResult); + return FALSE; + } + + return TRUE; +} + +int __cdecl main(int argc, char *argv[]) +{ + const char * testString = "The quick fox jumped over the lazy dog's back."; + const int testStringLen = strlen(testString); + + DWORD dwByteCount[4] = {-1, 10, testStringLen, 0}; + DWORD dwByteWritten[4] = {0, 10, testStringLen, 0}; + BOOL bResults[] = {FALSE, TRUE, TRUE, TRUE}; + + const int BUFFER_SIZE = 2 * PAGESIZE; + int j; + BOOL bRc = FALSE; + DWORD oldProt; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* allocate read-write memery for writeBuffer */ + if (!(writeBuffer = (char*) VirtualAlloc(NULL, BUFFER_SIZE, MEM_COMMIT, + PAGE_READWRITE))) + { + Fail("VirtualAlloc failed: GetLastError returns %d\n", GetLastError()); + return FAIL; + } + + memset((void*) writeBuffer, '.', BUFFER_SIZE); + strcpy(writeBuffer, testString); + + /* write protect the second page of writeBuffer */ + if (!VirtualProtect(&writeBuffer[PAGESIZE], PAGESIZE, PAGE_NOACCESS, &oldProt)) + { + Fail("VirtualProtect failed: GetLastError returns %d\n", GetLastError()); + return FAIL; + } + + for (j = 0; j< 4; j++) + { + bRc = writeTest(dwByteCount[j], dwByteWritten[j], bResults[j]); + if (bRc != TRUE) + { + Fail("WriteFile: ERROR -> Failed on test[%d]\n", j); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/WriteFile/test3/CMakeLists.txt index e16e8a48f6..bffcf35482 100644 --- a/src/pal/tests/palsuite/file_io/WriteFile/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/WriteFile/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - WriteFile.c + WriteFile.cpp ) add_executable(paltest_writefile_test3 diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test3/WriteFile.c b/src/pal/tests/palsuite/file_io/WriteFile/test3/WriteFile.c deleted file mode 100644 index 751f89ff2c..0000000000 --- a/src/pal/tests/palsuite/file_io/WriteFile/test3/WriteFile.c +++ /dev/null @@ -1,136 +0,0 @@ -// 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: WriteFile.c (test 3) -** -** Purpose: Tests the PAL implementation of the WriteFile function. -** Performs multiple writes to a file and verifies the results. -** -** -**===================================================================*/ - - -#include - - -const char* szStringTest = "The quick fox jumped over the lazy dog's back.\0"; -const char* szWritableFile = "writeable.txt"; - - -BOOL validateResults(const char* szString) -{ - FILE *pFile = NULL; - char szReadString[100]; - DWORD dwBytesRead; - DWORD dwStringLength = strlen(szString); - - - - memset(szReadString, 0, 100); - - /* open the file */ - pFile = fopen(szWritableFile, "r"); - if (pFile == NULL) - { - Trace("couldn't open test file\n"); - return FALSE; - } - - dwBytesRead = fread(szReadString, sizeof(char), dwStringLength, pFile); - fclose(pFile); - - if(dwBytesRead != dwStringLength) - { - Trace("dwbyteread != string length\n"); - return FALSE; - } - - if (strcmp(szReadString, szString)) - { - Trace("read = %s string = %s", szReadString, szString); - return FALSE; - } - return TRUE; -} - - - - -BOOL writeTest(const char* szString) -{ - HANDLE hFile = NULL; - DWORD dwBytesWritten; - BOOL bRc = FALSE; - BOOL bAllPassed = TRUE; - int nStringLength = 0; - char* szPtr = NULL; - int i = 0; - - // create the test file - hFile = CreateFile(szWritableFile, - GENERIC_WRITE, - FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Trace("WriteFile: ERROR -> Unable to create file \"%s\".\n", - szWritableFile); - return FALSE; - } - - nStringLength = strlen(szString); - szPtr = (char*) szString; - - for (i = 0; i < nStringLength; i++) - { - bRc = WriteFile(hFile, szPtr++, 1, &dwBytesWritten, NULL); - if ((bRc == FALSE) || (dwBytesWritten != 1)) - { - bAllPassed = FALSE; - } - } - CloseHandle(hFile); - - if (bAllPassed == FALSE) - { - Trace ("WriteFile: ERROR: Failed to write data.\n"); - return FALSE; - } - else - { - return (validateResults(szString)); - } - - return TRUE; -} - - - - -int __cdecl main(int argc, char *argv[]) -{ - const char *pString = szStringTest; - BOOL bRc = FALSE; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - - bRc = writeTest(pString); - if (bRc != TRUE) - { - Fail("WriteFile: ERROR -> Failed\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test3/WriteFile.cpp b/src/pal/tests/palsuite/file_io/WriteFile/test3/WriteFile.cpp new file mode 100644 index 0000000000..751f89ff2c --- /dev/null +++ b/src/pal/tests/palsuite/file_io/WriteFile/test3/WriteFile.cpp @@ -0,0 +1,136 @@ +// 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: WriteFile.c (test 3) +** +** Purpose: Tests the PAL implementation of the WriteFile function. +** Performs multiple writes to a file and verifies the results. +** +** +**===================================================================*/ + + +#include + + +const char* szStringTest = "The quick fox jumped over the lazy dog's back.\0"; +const char* szWritableFile = "writeable.txt"; + + +BOOL validateResults(const char* szString) +{ + FILE *pFile = NULL; + char szReadString[100]; + DWORD dwBytesRead; + DWORD dwStringLength = strlen(szString); + + + + memset(szReadString, 0, 100); + + /* open the file */ + pFile = fopen(szWritableFile, "r"); + if (pFile == NULL) + { + Trace("couldn't open test file\n"); + return FALSE; + } + + dwBytesRead = fread(szReadString, sizeof(char), dwStringLength, pFile); + fclose(pFile); + + if(dwBytesRead != dwStringLength) + { + Trace("dwbyteread != string length\n"); + return FALSE; + } + + if (strcmp(szReadString, szString)) + { + Trace("read = %s string = %s", szReadString, szString); + return FALSE; + } + return TRUE; +} + + + + +BOOL writeTest(const char* szString) +{ + HANDLE hFile = NULL; + DWORD dwBytesWritten; + BOOL bRc = FALSE; + BOOL bAllPassed = TRUE; + int nStringLength = 0; + char* szPtr = NULL; + int i = 0; + + // create the test file + hFile = CreateFile(szWritableFile, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Trace("WriteFile: ERROR -> Unable to create file \"%s\".\n", + szWritableFile); + return FALSE; + } + + nStringLength = strlen(szString); + szPtr = (char*) szString; + + for (i = 0; i < nStringLength; i++) + { + bRc = WriteFile(hFile, szPtr++, 1, &dwBytesWritten, NULL); + if ((bRc == FALSE) || (dwBytesWritten != 1)) + { + bAllPassed = FALSE; + } + } + CloseHandle(hFile); + + if (bAllPassed == FALSE) + { + Trace ("WriteFile: ERROR: Failed to write data.\n"); + return FALSE; + } + else + { + return (validateResults(szString)); + } + + return TRUE; +} + + + + +int __cdecl main(int argc, char *argv[]) +{ + const char *pString = szStringTest; + BOOL bRc = FALSE; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + bRc = writeTest(pString); + if (bRc != TRUE) + { + Fail("WriteFile: ERROR -> Failed\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/WriteFile/test4/CMakeLists.txt index fff886b430..402a61ac2c 100644 --- a/src/pal/tests/palsuite/file_io/WriteFile/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/WriteFile/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - writefile.c + writefile.cpp ) add_executable(paltest_writefile_test4 diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test4/writefile.c b/src/pal/tests/palsuite/file_io/WriteFile/test4/writefile.c deleted file mode 100644 index 47a0066ec9..0000000000 --- a/src/pal/tests/palsuite/file_io/WriteFile/test4/writefile.c +++ /dev/null @@ -1,155 +0,0 @@ -// 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: WriteFile.c (test 4) -** -** Purpose: Tests the PAL implementation of the WriteFile function. -** Performs multiple writes to a file at different locations -** then verifies the results with GetFileSize. -** -** dependency: -** CreateFile. -** GetFileSize. -** FlushFileBuffers -** SetFilePointer. -** CloseHandle. -** DeleteFile. -** -** -** -**===================================================================*/ - - -#include - -BOOL CleanUp(HANDLE hFile, const char * fileName) -{ - BOOL bRc = TRUE; - if (CloseHandle(hFile) != TRUE) - { - bRc = FALSE; - Trace("WriteFile: ERROR -> Unable to close file \"%s\"," - " error: %ld.\n", fileName, GetLastError()); - } - if (!DeleteFileA(fileName)) - { - bRc = FALSE; - Trace("WriteFile: ERROR -> Unable to delete file \"%s\"," - " error: %ld.\n", fileName, GetLastError()); - } - return bRc; -} - -int __cdecl main(int argc, char *argv[]) -{ - const char* szStringTest = "1234567890"; - const char* szWritableFile = "writeable.txt"; - HANDLE hFile = NULL; - DWORD dwBytesWritten; - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create the test file */ - hFile = CreateFile(szWritableFile, - GENERIC_WRITE, - FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("WriteFile: ERROR -> Unable to create file \"%s\".\n", - szWritableFile); - } - - - /* test wtriting to the file */ - if( WriteFile(hFile, /* HANDLE handle to file */ - szStringTest, /* data buffer */ - strlen(szStringTest), /* number of bytes to write */ - &dwBytesWritten, /* number of bytes written */ - NULL) /* overlapped buffer */ - ==0) - { - Trace("WriteFile: ERROR -> Unable to write to file error: %ld \n", - GetLastError()); - CleanUp(hFile,szWritableFile); - Fail(""); - } - - if(!FlushFileBuffers(hFile)) - { Trace("WriteFile: ERROR -> Call to FlushFile Buffers failed " - "error %ld \n",GetLastError()); - CleanUp(hFile,szWritableFile); - Fail(""); - } - - /* check the file size */ - if(GetFileSize(hFile, NULL)!=strlen(szStringTest)) - { - Trace("WriteFile: ERROR -> writing %u chars to empty file " - "caused its size to become %u\n",strlen(szStringTest), - GetFileSize(hFile, NULL)); - CleanUp(hFile,szWritableFile); - Fail(""); - } - - /* test writing to the file at position 5. */ - SetFilePointer( - hFile, /* handle to file */ - 0x5, /* bytes to move pointer */ - NULL, /* bytes to move pointer */ - FILE_BEGIN /* starting point */ - ); - - - if( WriteFile(hFile, /* HANDLE handle to file */ - szStringTest, /* data buffer */ - strlen(szStringTest), /* number of bytes to write */ - &dwBytesWritten, /* number of bytes written */ - NULL) /* overlapped buffer */ - ==0) - { - Trace("WriteFile: ERROR -> Unable to write to file after " - " moiving the file poiner to 5 error: %ld \n", - GetLastError()); - CleanUp(hFile,szWritableFile); - Fail(""); - } - - - if(!FlushFileBuffers(hFile)) - { - Trace("WriteFile: ERROR -> Call to FlushFile Buffers failed " - "error %ld \n",GetLastError()); - CleanUp(hFile,szWritableFile); - Fail(""); - } - - /* Check the file size */ - if(GetFileSize(hFile, NULL)!=(strlen(szStringTest)+5)) - { - Trace("WriteFile: ERROR -> writing %u chars to the file after " - "sitting the file pointer to 5 resulted in wrong file size; " - "Expected %u resulted %u.",strlen(szStringTest), - (strlen(szStringTest)+5),GetFileSize(hFile, NULL)); - CleanUp(hFile,szWritableFile); - Fail(""); - } - - if (!CleanUp(hFile,szWritableFile)) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test4/writefile.cpp b/src/pal/tests/palsuite/file_io/WriteFile/test4/writefile.cpp new file mode 100644 index 0000000000..47a0066ec9 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/WriteFile/test4/writefile.cpp @@ -0,0 +1,155 @@ +// 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: WriteFile.c (test 4) +** +** Purpose: Tests the PAL implementation of the WriteFile function. +** Performs multiple writes to a file at different locations +** then verifies the results with GetFileSize. +** +** dependency: +** CreateFile. +** GetFileSize. +** FlushFileBuffers +** SetFilePointer. +** CloseHandle. +** DeleteFile. +** +** +** +**===================================================================*/ + + +#include + +BOOL CleanUp(HANDLE hFile, const char * fileName) +{ + BOOL bRc = TRUE; + if (CloseHandle(hFile) != TRUE) + { + bRc = FALSE; + Trace("WriteFile: ERROR -> Unable to close file \"%s\"," + " error: %ld.\n", fileName, GetLastError()); + } + if (!DeleteFileA(fileName)) + { + bRc = FALSE; + Trace("WriteFile: ERROR -> Unable to delete file \"%s\"," + " error: %ld.\n", fileName, GetLastError()); + } + return bRc; +} + +int __cdecl main(int argc, char *argv[]) +{ + const char* szStringTest = "1234567890"; + const char* szWritableFile = "writeable.txt"; + HANDLE hFile = NULL; + DWORD dwBytesWritten; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create the test file */ + hFile = CreateFile(szWritableFile, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("WriteFile: ERROR -> Unable to create file \"%s\".\n", + szWritableFile); + } + + + /* test wtriting to the file */ + if( WriteFile(hFile, /* HANDLE handle to file */ + szStringTest, /* data buffer */ + strlen(szStringTest), /* number of bytes to write */ + &dwBytesWritten, /* number of bytes written */ + NULL) /* overlapped buffer */ + ==0) + { + Trace("WriteFile: ERROR -> Unable to write to file error: %ld \n", + GetLastError()); + CleanUp(hFile,szWritableFile); + Fail(""); + } + + if(!FlushFileBuffers(hFile)) + { Trace("WriteFile: ERROR -> Call to FlushFile Buffers failed " + "error %ld \n",GetLastError()); + CleanUp(hFile,szWritableFile); + Fail(""); + } + + /* check the file size */ + if(GetFileSize(hFile, NULL)!=strlen(szStringTest)) + { + Trace("WriteFile: ERROR -> writing %u chars to empty file " + "caused its size to become %u\n",strlen(szStringTest), + GetFileSize(hFile, NULL)); + CleanUp(hFile,szWritableFile); + Fail(""); + } + + /* test writing to the file at position 5. */ + SetFilePointer( + hFile, /* handle to file */ + 0x5, /* bytes to move pointer */ + NULL, /* bytes to move pointer */ + FILE_BEGIN /* starting point */ + ); + + + if( WriteFile(hFile, /* HANDLE handle to file */ + szStringTest, /* data buffer */ + strlen(szStringTest), /* number of bytes to write */ + &dwBytesWritten, /* number of bytes written */ + NULL) /* overlapped buffer */ + ==0) + { + Trace("WriteFile: ERROR -> Unable to write to file after " + " moiving the file poiner to 5 error: %ld \n", + GetLastError()); + CleanUp(hFile,szWritableFile); + Fail(""); + } + + + if(!FlushFileBuffers(hFile)) + { + Trace("WriteFile: ERROR -> Call to FlushFile Buffers failed " + "error %ld \n",GetLastError()); + CleanUp(hFile,szWritableFile); + Fail(""); + } + + /* Check the file size */ + if(GetFileSize(hFile, NULL)!=(strlen(szStringTest)+5)) + { + Trace("WriteFile: ERROR -> writing %u chars to the file after " + "sitting the file pointer to 5 resulted in wrong file size; " + "Expected %u resulted %u.",strlen(szStringTest), + (strlen(szStringTest)+5),GetFileSize(hFile, NULL)); + CleanUp(hFile,szWritableFile); + Fail(""); + } + + if (!CleanUp(hFile,szWritableFile)) + { + Fail(""); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test5/CMakeLists.txt b/src/pal/tests/palsuite/file_io/WriteFile/test5/CMakeLists.txt index 978eb7f1e7..f1f5037f98 100644 --- a/src/pal/tests/palsuite/file_io/WriteFile/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/WriteFile/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - writefile.c + writefile.cpp ) add_executable(paltest_writefile_test5 diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test5/writefile.c b/src/pal/tests/palsuite/file_io/WriteFile/test5/writefile.c deleted file mode 100644 index 46920b3335..0000000000 --- a/src/pal/tests/palsuite/file_io/WriteFile/test5/writefile.c +++ /dev/null @@ -1,117 +0,0 @@ -// 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: WriteFile.c (test 5) -** -** Purpose: Tests the PAL implementation of the WriteFile function. -** Performs writing a huge file. -** -** dependency: -** CreateFile. -** GetFileSize. -** FlushFileBuffers -** CloseHandle -** DeleteFile -** -** -**===================================================================*/ - - -#include - -BOOL CleanUp(HANDLE hFile, const char * fileName) -{ - BOOL bRc = TRUE; - if (CloseHandle(hFile) != TRUE) - { - bRc = FALSE; - Trace("WriteFile: ERROR -> Unable to close file \"%s\"," - " error: %ld.\n", fileName, GetLastError()); - } - if (!DeleteFileA(fileName)) - { - bRc = FALSE; - Trace("WriteFile: ERROR -> Unable to delete file \"%s\"," - " error: %ld.\n", fileName, GetLastError()); - } - return bRc; -} - - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile = NULL; - DWORD dwBytesWritten; - const char* hugeStringTest = - "1234567890123456789012345678901234567890"; - const char* szWritableFile = "writeable.txt"; - int i =0; - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* create the test file */ - hFile = CreateFile(szWritableFile, - GENERIC_WRITE, - FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if(hFile == INVALID_HANDLE_VALUE) - { - Fail("WriteFile: ERROR -> Unable to create file \"%s\".\n", - szWritableFile); - } - - /* write 4000 000 chars to the file.*/ - for (i=0; i<100000;i++) - { - if( WriteFile(hFile, /* HANDLE handle to file */ - hugeStringTest, /* data buffer */ - strlen(hugeStringTest), /* number of bytes to write */ - &dwBytesWritten, /* number of bytes written */ - NULL) /* overlapped buffer */ - ==0) - { - Trace("WriteFile: ERROR -> Unable to write to file error: %ld \n", - GetLastError()); - CleanUp(hFile,szWritableFile); - Fail(""); - - } - } - - if(!FlushFileBuffers(hFile)) - { - Trace("WriteFile: ERROR -> Call to FlushFileBuffers failed" - "error %ld \n",GetLastError()); - CleanUp(hFile,szWritableFile); - Fail(""); - } - - /* test if the size changed properly. */ - if(GetFileSize(hFile,NULL) != 4000000) - { - Trace("WriteFile: ERROR -> file size did not change properly" - " after writing 4000 000 chars to it ( size= %u )\n", - GetFileSize(hFile,NULL)); - CleanUp(hFile,szWritableFile); - Fail(""); - - } - - if (!CleanUp(hFile,szWritableFile)) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/WriteFile/test5/writefile.cpp b/src/pal/tests/palsuite/file_io/WriteFile/test5/writefile.cpp new file mode 100644 index 0000000000..46920b3335 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/WriteFile/test5/writefile.cpp @@ -0,0 +1,117 @@ +// 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: WriteFile.c (test 5) +** +** Purpose: Tests the PAL implementation of the WriteFile function. +** Performs writing a huge file. +** +** dependency: +** CreateFile. +** GetFileSize. +** FlushFileBuffers +** CloseHandle +** DeleteFile +** +** +**===================================================================*/ + + +#include + +BOOL CleanUp(HANDLE hFile, const char * fileName) +{ + BOOL bRc = TRUE; + if (CloseHandle(hFile) != TRUE) + { + bRc = FALSE; + Trace("WriteFile: ERROR -> Unable to close file \"%s\"," + " error: %ld.\n", fileName, GetLastError()); + } + if (!DeleteFileA(fileName)) + { + bRc = FALSE; + Trace("WriteFile: ERROR -> Unable to delete file \"%s\"," + " error: %ld.\n", fileName, GetLastError()); + } + return bRc; +} + + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile = NULL; + DWORD dwBytesWritten; + const char* hugeStringTest = + "1234567890123456789012345678901234567890"; + const char* szWritableFile = "writeable.txt"; + int i =0; + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create the test file */ + hFile = CreateFile(szWritableFile, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("WriteFile: ERROR -> Unable to create file \"%s\".\n", + szWritableFile); + } + + /* write 4000 000 chars to the file.*/ + for (i=0; i<100000;i++) + { + if( WriteFile(hFile, /* HANDLE handle to file */ + hugeStringTest, /* data buffer */ + strlen(hugeStringTest), /* number of bytes to write */ + &dwBytesWritten, /* number of bytes written */ + NULL) /* overlapped buffer */ + ==0) + { + Trace("WriteFile: ERROR -> Unable to write to file error: %ld \n", + GetLastError()); + CleanUp(hFile,szWritableFile); + Fail(""); + + } + } + + if(!FlushFileBuffers(hFile)) + { + Trace("WriteFile: ERROR -> Call to FlushFileBuffers failed" + "error %ld \n",GetLastError()); + CleanUp(hFile,szWritableFile); + Fail(""); + } + + /* test if the size changed properly. */ + if(GetFileSize(hFile,NULL) != 4000000) + { + Trace("WriteFile: ERROR -> file size did not change properly" + " after writing 4000 000 chars to it ( size= %u )\n", + GetFileSize(hFile,NULL)); + CleanUp(hFile,szWritableFile); + Fail(""); + + } + + if (!CleanUp(hFile,szWritableFile)) + { + Fail(""); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/CMakeLists.txt index 91b7db1f03..4c4f6416ce 100644 --- a/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_errorpathnotfound_test1 diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/test1.c b/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/test1.c deleted file mode 100644 index eaf3db3a30..0000000000 --- a/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/test1.c +++ /dev/null @@ -1,783 +0,0 @@ -// 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: test1.c - -** - -** Purpose: Test the return value of GetLastError() after calling - -** some file_io functions with an invalid path. - -** - -** Functions covered by this test are: - -** CopyFileA, CopyFileW, CreateFileA,CreateFileW, - -** DeleteFileA and DeleteFileW. - -** -** - - - -** - -**===================================================================*/ - - - -#include - - - -int __cdecl main(int argc, char *argv[]) - -{ - - - - BOOL testPass = TRUE; - - BOOL bRc = TRUE; - - HANDLE hFile; - - - - const char* sBadFilePath = "bad/badPath.tmp"; - - const char* sBadFileName = "badName.tmp"; - - const char* sDest = "dest.tmp"; - - const WCHAR wBadFilePath[] = - - {'w','b','a','d','/','b','a', - - 'd','.','t','m','p','\0'}; - - const WCHAR wBadFileName[] = - - {'w','B','a','d','.','t','m','p','\0'}; - - const WCHAR wDest[] = - - {'w','d','e','s','t','.','t','m','p','\0'}; - - - - - - if (0 != PAL_Initialize(argc,argv)) - - { - - return FAIL; - - } - - - - /*...................Test CopyFileW.............................*/ - - - - /* test with an invalid path */ - - bRc = CopyFileW(wBadFilePath,wDest,TRUE); - - if(!bRc) - - { - - if(GetLastError()!= ERROR_PATH_NOT_FOUND) - - { - - Trace("CopyFileW: calling GetLastError() after copying a file" - - " with wrong path returned [%u] while it should return [%u]\n" - - ,GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - testPass = FALSE; - - } - - - - /* test with invalid file name */ - - bRc = CopyFileW(wBadFileName,wDest,TRUE); - - if(!bRc) - - { - - if(GetLastError()!= ERROR_FILE_NOT_FOUND) - - { - - Trace("CopyFileW: calling GetLastError() after copying a file" - - " with wrong name returned [%u] while it should return [%u]\n" - - ,GetLastError(), ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("CopyFileW: managed to copy a file with wrong name\n"); - - testPass = FALSE; - - } - - - - - - - - /*..................CopyFileA...................................*/ - - - - /* test with an invalid path */ - - bRc = CopyFileA(sBadFilePath,sDest,TRUE); - - if(! bRc) - - { - - if(GetLastError()!= ERROR_PATH_NOT_FOUND) - - { - - Trace("CopyFileA: calling GetLastError() after copying a file" - - " with wrong path returned [%u] while it should return [%u]\n" - - ,GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("CopyFileA: managed to copy a file with wrong path\n"); - - testPass = FALSE; - - } - - - - /* test with an invalid file name */ - - bRc = CopyFileA(sBadFileName,sDest,TRUE); - - if(! bRc) - - { - - if(GetLastError()!= ERROR_FILE_NOT_FOUND) - - { - - Trace("CopyFileA: calling GetLastError() after copying a file" - - " with wrong name returned [%u] while it should return [%u]\n" - - ,GetLastError(), ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("CopyFileA: managed to copy a file with wrong name\n"); - - testPass = FALSE; - - } - - - - - - - - /*............. Test CreateFileA..................................*/ - - - - /* test with an invalid file name */ - - hFile = CreateFileA(sBadFileName, - - GENERIC_READ, /* open for reading */ - - FILE_SHARE_READ, /* share for reading */ - - NULL, /* no security */ - - OPEN_EXISTING, /* existing file only */ - - FILE_ATTRIBUTE_NORMAL, /* normal file */ - - NULL); /* no attr. template */ - - - - if (hFile == INVALID_HANDLE_VALUE) - - { - - if(GetLastError() != ERROR_FILE_NOT_FOUND) - - { - - Trace("CreateFileA: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad File Name\n", - - GetLastError(),ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("CreateFileA: managed to create a file with an incorrect " - - "filename\n"); - - testPass = FALSE; - - - - if(!CloseHandle(hFile)) - - { - - Trace("CreateFileA: Call to CloseHandle failed with ErrorCode " - - "[%u]\n", GetLastError()); - - - - } - - if(!DeleteFile(sBadFileName)) - - { - - Trace("CreateFileA: Call to DeleteFile failed with ErrorCode " - - "[%u]\n", GetLastError()); - - } - - } - - - - /* test with an invalid path */ - - hFile = CreateFileA(sBadFilePath, - - GENERIC_READ, /* open for reading */ - - FILE_SHARE_READ, /* share for reading */ - - NULL, /* no security */ - - OPEN_EXISTING, /* existing file only */ - - FILE_ATTRIBUTE_NORMAL, /* normal file */ - - NULL); /* no attr. template */ - - - - if (hFile == INVALID_HANDLE_VALUE) - - { - - if(GetLastError() != ERROR_PATH_NOT_FOUND) - - { - - Trace("CreateFileA: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad file path name\n", - - GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("CreateFileA: managed to create a file with an incorrect " - - "filename\n"); - - testPass = FALSE; - - /*this should not happen*/ - - if(!CloseHandle(hFile)) - - { - - Trace("CreateFileA: Call to CloseHandle Failed with ErrorCode " - - "[%u]\n", GetLastError()); - - - - } - - if(!DeleteFile(sBadFilePath)) - - { - - Trace("CreateFileA: Call to DeleteFile Failed with ErrorCode " - - "[%u]\n", GetLastError()); - - } - - } - - - - - - - - - - /*............. Test CreateFileW..................................*/ - - - - /* test with an invalid file name */ - - hFile = CreateFileW(wBadFileName, - - GENERIC_READ, /* open for reading */ - - FILE_SHARE_READ, /* share for reading */ - - NULL, /* no security */ - - OPEN_EXISTING, /* existing file only */ - - FILE_ATTRIBUTE_NORMAL, /* normal file */ - - NULL); /* no attr. template */ - - - - if (hFile == INVALID_HANDLE_VALUE) - - { - - if(GetLastError() != ERROR_FILE_NOT_FOUND) - - { - - Trace("CreateFileW: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad filename\n", - - GetLastError(), ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("CreateFileW: managed to create a file with an incorrect " - - "filename\n"); - - testPass = FALSE; - - - - if(!CloseHandle(hFile)) - - { - - Trace("CreateFileW: Call to CloseHandle Failed with ErrorCode " - - "[%u]\n", GetLastError()); - - - - } - - - - if(!DeleteFileW(wBadFileName)) - - { - - Trace("CreateFileW: Call to DeleteFile Failed with ErrorCode " - - "[%u]\n", GetLastError()); - - } - - } - - - - - - - - /* test with an invalid path */ - - hFile = CreateFileW(wBadFilePath, - - GENERIC_READ, /* open for reading */ - - FILE_SHARE_READ, /* share for reading */ - - NULL, /* no security */ - - OPEN_EXISTING, /* existing file only */ - - FILE_ATTRIBUTE_NORMAL, /* normal file */ - - NULL); /* no attr. template */ - - - - if (hFile == INVALID_HANDLE_VALUE) - - { - - - - if(GetLastError() != ERROR_PATH_NOT_FOUND) - - { - - Trace("CreateFileW: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad file path \n", - - GetLastError(), ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("CreateFileW: managed to create a file with an incorrect " - - "filename\n"); - - testPass = FALSE; - - - - if(!CloseHandle(hFile)) - - { - - Trace("CreateFileW: Call to CloseHandle Failed with ErrorCode " - - "[%u]\n", GetLastError()); - - - - } - - if(!DeleteFileW(wBadFilePath)) - - { - - Trace("CreateFileW: Call to DeleteFile Failed with ErrorCode " - - "[%u]\n", GetLastError()); - - } - - } - - - - - - - - /* ............. DeleteFileW..................................*/ - - - - /* test with an invalid path */ - - if(DeleteFileW(wBadFilePath)) - - { - - Trace("DeleteFileW: Call to DeleteFileW to delete a file" - - " that does not exist succeeded\n"); - - testPass = FALSE; - - - - } - - else - - { - - if(GetLastError() != ERROR_PATH_NOT_FOUND) - - { - - Trace("DeleteFileW: Call GetLastError()returned " - - "[%u] while it should return ERROR_PATH_NOT_FOUND [%u]\n", - - GetLastError(),ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - - - } - - - - } - - - - /* test with an invalid file name */ - - if(DeleteFileW(wBadFileName)) - - { - - Trace("DeleteFileW: Call to DeleteFileW to delete a file" - - " that does not exist succeeded\n"); - - testPass = FALSE; - - - - } - - else - - { - - if(GetLastError() != ERROR_FILE_NOT_FOUND) - - { - - Trace("DeleteFileW: Call GetLastError()returned [%u]" - - " while it should return ERROR_FILE_NOT_FOUND [%u]\n", - - GetLastError(),ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - - - } - - - - } - - - - - - /* ............. DeleteFileA..................................*/ - - - - /* test with an invalid path */ - - if(DeleteFileA(sBadFilePath)) - - { - - Trace("DeleteFileA: Call to DeleteFileA to delete a file" - - " that does not exist succeeded\n"); - - testPass = FALSE; - - - - } - - else - - { - - if(GetLastError() != ERROR_PATH_NOT_FOUND) - - { - - Trace("DeleteFileA: Call GetLastError() returned [%u]" - - " while it should return ERROR_PATH_NOT_FOUND [%u]\n", - - GetLastError(),ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - - - } - - - - } - - - - /* test with an invalid file name */ - - if(DeleteFileA(sBadFileName)) - - { - - Trace("DeleteFileA: Call to DeleteFileA to delete a file" - - " that does not exist succeeded\n"); - - testPass = FALSE; - - - - } - - else - - { - - if(GetLastError() != ERROR_FILE_NOT_FOUND) - - { - - Trace("DeleteFileA: Call GetLastError() returned [%u]" - - " while it should return ERROR_FILE_NOT_FOUND [%u]\n", - - GetLastError(),ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - - - } - - - - } - - - - - - - - if(! testPass) - - { - - Fail(""); - - } - - PAL_Terminate(); - - return PASS; - -} - - - diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/test1.cpp b/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/test1.cpp new file mode 100644 index 0000000000..eaf3db3a30 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/errorpathnotfound/test1/test1.cpp @@ -0,0 +1,783 @@ +// 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: test1.c + +** + +** Purpose: Test the return value of GetLastError() after calling + +** some file_io functions with an invalid path. + +** + +** Functions covered by this test are: + +** CopyFileA, CopyFileW, CreateFileA,CreateFileW, + +** DeleteFileA and DeleteFileW. + +** +** + + + +** + +**===================================================================*/ + + + +#include + + + +int __cdecl main(int argc, char *argv[]) + +{ + + + + BOOL testPass = TRUE; + + BOOL bRc = TRUE; + + HANDLE hFile; + + + + const char* sBadFilePath = "bad/badPath.tmp"; + + const char* sBadFileName = "badName.tmp"; + + const char* sDest = "dest.tmp"; + + const WCHAR wBadFilePath[] = + + {'w','b','a','d','/','b','a', + + 'd','.','t','m','p','\0'}; + + const WCHAR wBadFileName[] = + + {'w','B','a','d','.','t','m','p','\0'}; + + const WCHAR wDest[] = + + {'w','d','e','s','t','.','t','m','p','\0'}; + + + + + + if (0 != PAL_Initialize(argc,argv)) + + { + + return FAIL; + + } + + + + /*...................Test CopyFileW.............................*/ + + + + /* test with an invalid path */ + + bRc = CopyFileW(wBadFilePath,wDest,TRUE); + + if(!bRc) + + { + + if(GetLastError()!= ERROR_PATH_NOT_FOUND) + + { + + Trace("CopyFileW: calling GetLastError() after copying a file" + + " with wrong path returned [%u] while it should return [%u]\n" + + ,GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + testPass = FALSE; + + } + + + + /* test with invalid file name */ + + bRc = CopyFileW(wBadFileName,wDest,TRUE); + + if(!bRc) + + { + + if(GetLastError()!= ERROR_FILE_NOT_FOUND) + + { + + Trace("CopyFileW: calling GetLastError() after copying a file" + + " with wrong name returned [%u] while it should return [%u]\n" + + ,GetLastError(), ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("CopyFileW: managed to copy a file with wrong name\n"); + + testPass = FALSE; + + } + + + + + + + + /*..................CopyFileA...................................*/ + + + + /* test with an invalid path */ + + bRc = CopyFileA(sBadFilePath,sDest,TRUE); + + if(! bRc) + + { + + if(GetLastError()!= ERROR_PATH_NOT_FOUND) + + { + + Trace("CopyFileA: calling GetLastError() after copying a file" + + " with wrong path returned [%u] while it should return [%u]\n" + + ,GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("CopyFileA: managed to copy a file with wrong path\n"); + + testPass = FALSE; + + } + + + + /* test with an invalid file name */ + + bRc = CopyFileA(sBadFileName,sDest,TRUE); + + if(! bRc) + + { + + if(GetLastError()!= ERROR_FILE_NOT_FOUND) + + { + + Trace("CopyFileA: calling GetLastError() after copying a file" + + " with wrong name returned [%u] while it should return [%u]\n" + + ,GetLastError(), ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("CopyFileA: managed to copy a file with wrong name\n"); + + testPass = FALSE; + + } + + + + + + + + /*............. Test CreateFileA..................................*/ + + + + /* test with an invalid file name */ + + hFile = CreateFileA(sBadFileName, + + GENERIC_READ, /* open for reading */ + + FILE_SHARE_READ, /* share for reading */ + + NULL, /* no security */ + + OPEN_EXISTING, /* existing file only */ + + FILE_ATTRIBUTE_NORMAL, /* normal file */ + + NULL); /* no attr. template */ + + + + if (hFile == INVALID_HANDLE_VALUE) + + { + + if(GetLastError() != ERROR_FILE_NOT_FOUND) + + { + + Trace("CreateFileA: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad File Name\n", + + GetLastError(),ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("CreateFileA: managed to create a file with an incorrect " + + "filename\n"); + + testPass = FALSE; + + + + if(!CloseHandle(hFile)) + + { + + Trace("CreateFileA: Call to CloseHandle failed with ErrorCode " + + "[%u]\n", GetLastError()); + + + + } + + if(!DeleteFile(sBadFileName)) + + { + + Trace("CreateFileA: Call to DeleteFile failed with ErrorCode " + + "[%u]\n", GetLastError()); + + } + + } + + + + /* test with an invalid path */ + + hFile = CreateFileA(sBadFilePath, + + GENERIC_READ, /* open for reading */ + + FILE_SHARE_READ, /* share for reading */ + + NULL, /* no security */ + + OPEN_EXISTING, /* existing file only */ + + FILE_ATTRIBUTE_NORMAL, /* normal file */ + + NULL); /* no attr. template */ + + + + if (hFile == INVALID_HANDLE_VALUE) + + { + + if(GetLastError() != ERROR_PATH_NOT_FOUND) + + { + + Trace("CreateFileA: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad file path name\n", + + GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("CreateFileA: managed to create a file with an incorrect " + + "filename\n"); + + testPass = FALSE; + + /*this should not happen*/ + + if(!CloseHandle(hFile)) + + { + + Trace("CreateFileA: Call to CloseHandle Failed with ErrorCode " + + "[%u]\n", GetLastError()); + + + + } + + if(!DeleteFile(sBadFilePath)) + + { + + Trace("CreateFileA: Call to DeleteFile Failed with ErrorCode " + + "[%u]\n", GetLastError()); + + } + + } + + + + + + + + + + /*............. Test CreateFileW..................................*/ + + + + /* test with an invalid file name */ + + hFile = CreateFileW(wBadFileName, + + GENERIC_READ, /* open for reading */ + + FILE_SHARE_READ, /* share for reading */ + + NULL, /* no security */ + + OPEN_EXISTING, /* existing file only */ + + FILE_ATTRIBUTE_NORMAL, /* normal file */ + + NULL); /* no attr. template */ + + + + if (hFile == INVALID_HANDLE_VALUE) + + { + + if(GetLastError() != ERROR_FILE_NOT_FOUND) + + { + + Trace("CreateFileW: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad filename\n", + + GetLastError(), ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("CreateFileW: managed to create a file with an incorrect " + + "filename\n"); + + testPass = FALSE; + + + + if(!CloseHandle(hFile)) + + { + + Trace("CreateFileW: Call to CloseHandle Failed with ErrorCode " + + "[%u]\n", GetLastError()); + + + + } + + + + if(!DeleteFileW(wBadFileName)) + + { + + Trace("CreateFileW: Call to DeleteFile Failed with ErrorCode " + + "[%u]\n", GetLastError()); + + } + + } + + + + + + + + /* test with an invalid path */ + + hFile = CreateFileW(wBadFilePath, + + GENERIC_READ, /* open for reading */ + + FILE_SHARE_READ, /* share for reading */ + + NULL, /* no security */ + + OPEN_EXISTING, /* existing file only */ + + FILE_ATTRIBUTE_NORMAL, /* normal file */ + + NULL); /* no attr. template */ + + + + if (hFile == INVALID_HANDLE_VALUE) + + { + + + + if(GetLastError() != ERROR_PATH_NOT_FOUND) + + { + + Trace("CreateFileW: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad file path \n", + + GetLastError(), ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("CreateFileW: managed to create a file with an incorrect " + + "filename\n"); + + testPass = FALSE; + + + + if(!CloseHandle(hFile)) + + { + + Trace("CreateFileW: Call to CloseHandle Failed with ErrorCode " + + "[%u]\n", GetLastError()); + + + + } + + if(!DeleteFileW(wBadFilePath)) + + { + + Trace("CreateFileW: Call to DeleteFile Failed with ErrorCode " + + "[%u]\n", GetLastError()); + + } + + } + + + + + + + + /* ............. DeleteFileW..................................*/ + + + + /* test with an invalid path */ + + if(DeleteFileW(wBadFilePath)) + + { + + Trace("DeleteFileW: Call to DeleteFileW to delete a file" + + " that does not exist succeeded\n"); + + testPass = FALSE; + + + + } + + else + + { + + if(GetLastError() != ERROR_PATH_NOT_FOUND) + + { + + Trace("DeleteFileW: Call GetLastError()returned " + + "[%u] while it should return ERROR_PATH_NOT_FOUND [%u]\n", + + GetLastError(),ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + + + } + + + + } + + + + /* test with an invalid file name */ + + if(DeleteFileW(wBadFileName)) + + { + + Trace("DeleteFileW: Call to DeleteFileW to delete a file" + + " that does not exist succeeded\n"); + + testPass = FALSE; + + + + } + + else + + { + + if(GetLastError() != ERROR_FILE_NOT_FOUND) + + { + + Trace("DeleteFileW: Call GetLastError()returned [%u]" + + " while it should return ERROR_FILE_NOT_FOUND [%u]\n", + + GetLastError(),ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + + + } + + + + } + + + + + + /* ............. DeleteFileA..................................*/ + + + + /* test with an invalid path */ + + if(DeleteFileA(sBadFilePath)) + + { + + Trace("DeleteFileA: Call to DeleteFileA to delete a file" + + " that does not exist succeeded\n"); + + testPass = FALSE; + + + + } + + else + + { + + if(GetLastError() != ERROR_PATH_NOT_FOUND) + + { + + Trace("DeleteFileA: Call GetLastError() returned [%u]" + + " while it should return ERROR_PATH_NOT_FOUND [%u]\n", + + GetLastError(),ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + + + } + + + + } + + + + /* test with an invalid file name */ + + if(DeleteFileA(sBadFileName)) + + { + + Trace("DeleteFileA: Call to DeleteFileA to delete a file" + + " that does not exist succeeded\n"); + + testPass = FALSE; + + + + } + + else + + { + + if(GetLastError() != ERROR_FILE_NOT_FOUND) + + { + + Trace("DeleteFileA: Call GetLastError() returned [%u]" + + " while it should return ERROR_FILE_NOT_FOUND [%u]\n", + + GetLastError(),ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + + + } + + + + } + + + + + + + + if(! testPass) + + { + + Fail(""); + + } + + PAL_Terminate(); + + return PASS; + +} + + + diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/CMakeLists.txt index 7d525c21d5..284933f950 100644 --- a/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_errorpathnotfound_test2 diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/test2.c b/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/test2.c deleted file mode 100644 index 5c2ab86b99..0000000000 --- a/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/test2.c +++ /dev/null @@ -1,785 +0,0 @@ -// 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: test2.c - -** - -** Purpose: Test the return value of GetLastError() after calling - -** some file_io functions with an invalid path. - -** - -** Functions covered by this test are: - -** MoveFileW, FindFirstFileA, FindFirstFileW, - -** GetFileAttributesA, GetFileAttributesW, - -** SetFileAttributesA, SetFileAttributesW. - -** -** - -** - - - -** - -**===================================================================*/ - - - -#include - - - -int __cdecl main(int argc, char *argv[]) - -{ - - - - BOOL testPass = TRUE; - - BOOL bRc = TRUE; - - HANDLE hFile; - - WIN32_FIND_DATA findFileData; - - WIN32_FIND_DATAW wFindFileData; - - DWORD fileAttrib; - - - - const char* sBadFilePath = "bad/badPath.tmp"; - - const char* sBadFileName = "badName.tmp"; - - - - const WCHAR wBadFilePath[] = - - {'w','b','a','d','/','b','a', - - 'd','.','t','m','p','\0'}; - - const WCHAR wBadFileName[] = - - {'w','B','a','d','.','t','m','p','\0'}; - - const WCHAR wDest[] = - - {'w','d','e','s','t','.','t','m','p','\0'}; - - - - - - if (0 != PAL_Initialize(argc,argv)) - - { - - return FAIL; - - } - - - - /*...................Test MoveFileW.............................*/ - - - - /* test with an invalid path */ - - bRc = MoveFileW(wBadFilePath,wDest); - - if(!bRc) - - { - - if(GetLastError()!= ERROR_PATH_NOT_FOUND) - - { - - Trace("MoveFileW: calling GetLastError() after moving a file" - - " with wrong path returned [%u] while it should return [%u]\n" - - ,GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - testPass = FALSE; - - } - - - - /* test with invalid file name */ - - bRc = MoveFileW(wBadFileName,wDest); - - if(!bRc) - - { - - if(GetLastError()!= ERROR_FILE_NOT_FOUND) - - { - - Trace("MoveFileW: calling GetLastError() after moving a file" - - " with wrong name returned [%u] while it should return [%u]\n" - - ,GetLastError(), ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("MoveFileW: managed to move a file with wrong name\n"); - - testPass = FALSE; - - } - - - - /*............. Test FindFirstFileA..................................*/ - - - - /* test with an invalid file name */ - - hFile = FindFirstFileA(sBadFileName,&findFileData ); - - - - if (hFile == INVALID_HANDLE_VALUE) - - { - - if(GetLastError() != ERROR_FILE_NOT_FOUND) - - { - - Trace("FindFirstFileA: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad File Name\n", - - GetLastError(),ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("FindFirstFileA: managed to find a file with an incorrect " - - "filename\n"); - - testPass = FALSE; - - - - if(!FindClose(hFile)) - - { - - Trace("FindFirstFileA: Call to FindClose failed with ErrorCode" - - " [%u]\n", GetLastError()); - - - - } - - - - } - - - - /* test with an invalid path */ - - hFile = FindFirstFileA(sBadFilePath,&findFileData); - - - - if (hFile == INVALID_HANDLE_VALUE) - - { - - if(GetLastError() != ERROR_PATH_NOT_FOUND) - - { - - Trace("FindFirstFileA: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad file path name\n", - - GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("FindFirstFileA: managed to find a file with an incorrect" - - " filename\n"); - - testPass = FALSE; - - /*this should not happen*/ - - if(!FindClose(hFile)) - - { - - Trace("FindFirstFileA: Call to FindClose Failed with ErrorCode" - - " [%u]\n", GetLastError()); - - - - } - - - - } - - - - - - - - /*............. Test FindFirstFileW..................................*/ - - - - /* test with an invalid file name */ - - hFile = FindFirstFileW(wBadFileName,&wFindFileData ); - - - - if (hFile == INVALID_HANDLE_VALUE) - - { - - if(GetLastError() != ERROR_FILE_NOT_FOUND) - - { - - Trace("FindFirstFileW: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad File Name\n", - - GetLastError(),ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("FindFirstFileW: managed to find a file with an incorrect " - - "filename\n"); - - testPass = FALSE; - - - - if(!FindClose(hFile)) - - { - - Trace("FindFirstFileW: Call to FindClose failed with ErrorCode" - - " [%u]\n", GetLastError()); - - - - } - - - - } - - - - /* test with an invalid path */ - - hFile = FindFirstFileW(wBadFilePath,&wFindFileData); - - - - if (hFile == INVALID_HANDLE_VALUE) - - { - - if(GetLastError() != ERROR_PATH_NOT_FOUND) - - { - - Trace("FindFirstFileW: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad file path name\n", - - GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("FindFirstFileW: managed to find a file with an incorrect " - - "filename\n"); - - testPass = FALSE; - - /*this should not happen*/ - - if(!FindClose(hFile)) - - { - - Trace("FindFirstFileW: Call to FindClose Failed with ErrorCode " - - "[%u]\n", GetLastError()); - - - - } - - - - } - - - - - - /*...................Test GetFileAttributesW.............................*/ - - - - /* test with an invalid path */ - - fileAttrib = GetFileAttributesW(wBadFilePath); - - if(fileAttrib == -1) - - { - - if(GetLastError()!= ERROR_PATH_NOT_FOUND) - - { - - Trace("GetFileAttributesW: calling GetLastError() after getting" - - " the attributes of a file with wrong path returned [%u]" - - " while it should return [%u]\n", - - GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("GetFileAttributesW: managed to get the attrib of a file" - - " with wrong path\n"); - - testPass = FALSE; - - } - - - - /* test with invalid file name */ - - fileAttrib = GetFileAttributesW(wBadFileName); - - if(fileAttrib == -1) - - { - - if(GetLastError()!= ERROR_FILE_NOT_FOUND) - - { - - Trace("GetFileAttributesW: calling GetLastError() after getting" - - " the attributes of a file with wrong name returned [%u] " - - "while it should return [%u]\n" - - ,GetLastError(), ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("GetFileAttributesW: managed to get the attrib of a file" - - " with wrong name\n"); - - testPass = FALSE; - - } - - - - /*...................Test GetFileAttributesA.............................*/ - - - - /* test with an invalid path */ - - fileAttrib = GetFileAttributesA(sBadFilePath); - - if(fileAttrib == -1) - - { - - if(GetLastError()!= ERROR_PATH_NOT_FOUND) - - { - - Trace("GetFileAttributesA: calling GetLastError() after getting" - - " the attributes of a file with wrong path returned [%u] while" - - " it should return [%u]\n", - - GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("GetFileAttributesA: managed to get the attrib of a file" - - " with wrong path\n"); - - testPass = FALSE; - - } - - - - /* test with invalid file name */ - - fileAttrib = GetFileAttributesA(sBadFileName); - - if(fileAttrib == -1) - - { - - if(GetLastError()!= ERROR_FILE_NOT_FOUND) - - { - - Trace("GetFileAttributesA: calling GetLastError() after getting " - - "the attributes of a file with wrong name returned [%u] " - - "while it should return [%u]\n" - - ,GetLastError(), ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("GetFileAttributesA: managed to get the attrib of a file with" - - " wrong name\n"); - - testPass = FALSE; - - } - - - - - - - - - - /*...................Test SetFileAttributesW.............................*/ - - - - /* test with an invalid path */ - - bRc = SetFileAttributesW(wBadFilePath,FILE_ATTRIBUTE_NORMAL); - - if(!bRc) - - { - - if(GetLastError()!= ERROR_PATH_NOT_FOUND) - - { - - Trace("SetFileAttributesW: calling GetLastError() after setting" - - " the attributes of a file with wrong path returned [%u] " - - "while it should return [%u]\n", - - GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("SetFileAttributesW: managed to get the attrib of a file" - - " with wrong path\n"); - - testPass = FALSE; - - } - - - - /* test with invalid file name */ - - bRc = SetFileAttributesW(wBadFileName,FILE_ATTRIBUTE_NORMAL); - - if(!bRc) - - { - - if(GetLastError()!= ERROR_FILE_NOT_FOUND) - - { - - Trace("SetFileAttributesW: calling GetLastError() after setting" - - " the attributes of a file with wrong name returned [%u]" - - " while it should return [%u]\n", - - GetLastError(), ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("SetFileAttributesW: managed to get the attrib of a file with" - - " wrong name\n"); - - testPass = FALSE; - - } - - - - - - /*...................Test SetFileAttributesA.............................*/ - - - - /* test with an invalid path */ - - bRc = SetFileAttributesA(sBadFilePath,FILE_ATTRIBUTE_NORMAL); - - if(!bRc) - - { - - if(GetLastError()!= ERROR_PATH_NOT_FOUND) - - { - - Trace("SetFileAttributesA: calling GetLastError() after setting " - - "the attributes of a file with wrong path returned [%u] " - - "while it should return [%u]\n" - - ,GetLastError(), ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("SetFileAttributesA: managed to get the attrib of a file " - - "with wrong path\n"); - - testPass = FALSE; - - } - - - - /* test with invalid file name */ - - bRc = SetFileAttributesA(sBadFileName,FILE_ATTRIBUTE_NORMAL); - - if(!bRc) - - { - - if(GetLastError()!= ERROR_FILE_NOT_FOUND) - - { - - Trace("SetFileAttributesA: calling GetLastError() after setting" - - " the attributes of a file with wrong name returned [%u]" - - " while it should return [%u]\n", - - GetLastError(), ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - - - } - - else - - { - - Trace("SetFileAttributesA: managed to get the attrib of a file with " - - "wrong name\n"); - - testPass = FALSE; - - } - - - - - - if(! testPass) - - { - - Fail(""); - - } - - PAL_Terminate(); - - return PASS; - -} - - - diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/test2.cpp b/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/test2.cpp new file mode 100644 index 0000000000..5c2ab86b99 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/errorpathnotfound/test2/test2.cpp @@ -0,0 +1,785 @@ +// 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: test2.c + +** + +** Purpose: Test the return value of GetLastError() after calling + +** some file_io functions with an invalid path. + +** + +** Functions covered by this test are: + +** MoveFileW, FindFirstFileA, FindFirstFileW, + +** GetFileAttributesA, GetFileAttributesW, + +** SetFileAttributesA, SetFileAttributesW. + +** +** + +** + + + +** + +**===================================================================*/ + + + +#include + + + +int __cdecl main(int argc, char *argv[]) + +{ + + + + BOOL testPass = TRUE; + + BOOL bRc = TRUE; + + HANDLE hFile; + + WIN32_FIND_DATA findFileData; + + WIN32_FIND_DATAW wFindFileData; + + DWORD fileAttrib; + + + + const char* sBadFilePath = "bad/badPath.tmp"; + + const char* sBadFileName = "badName.tmp"; + + + + const WCHAR wBadFilePath[] = + + {'w','b','a','d','/','b','a', + + 'd','.','t','m','p','\0'}; + + const WCHAR wBadFileName[] = + + {'w','B','a','d','.','t','m','p','\0'}; + + const WCHAR wDest[] = + + {'w','d','e','s','t','.','t','m','p','\0'}; + + + + + + if (0 != PAL_Initialize(argc,argv)) + + { + + return FAIL; + + } + + + + /*...................Test MoveFileW.............................*/ + + + + /* test with an invalid path */ + + bRc = MoveFileW(wBadFilePath,wDest); + + if(!bRc) + + { + + if(GetLastError()!= ERROR_PATH_NOT_FOUND) + + { + + Trace("MoveFileW: calling GetLastError() after moving a file" + + " with wrong path returned [%u] while it should return [%u]\n" + + ,GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + testPass = FALSE; + + } + + + + /* test with invalid file name */ + + bRc = MoveFileW(wBadFileName,wDest); + + if(!bRc) + + { + + if(GetLastError()!= ERROR_FILE_NOT_FOUND) + + { + + Trace("MoveFileW: calling GetLastError() after moving a file" + + " with wrong name returned [%u] while it should return [%u]\n" + + ,GetLastError(), ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("MoveFileW: managed to move a file with wrong name\n"); + + testPass = FALSE; + + } + + + + /*............. Test FindFirstFileA..................................*/ + + + + /* test with an invalid file name */ + + hFile = FindFirstFileA(sBadFileName,&findFileData ); + + + + if (hFile == INVALID_HANDLE_VALUE) + + { + + if(GetLastError() != ERROR_FILE_NOT_FOUND) + + { + + Trace("FindFirstFileA: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad File Name\n", + + GetLastError(),ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("FindFirstFileA: managed to find a file with an incorrect " + + "filename\n"); + + testPass = FALSE; + + + + if(!FindClose(hFile)) + + { + + Trace("FindFirstFileA: Call to FindClose failed with ErrorCode" + + " [%u]\n", GetLastError()); + + + + } + + + + } + + + + /* test with an invalid path */ + + hFile = FindFirstFileA(sBadFilePath,&findFileData); + + + + if (hFile == INVALID_HANDLE_VALUE) + + { + + if(GetLastError() != ERROR_PATH_NOT_FOUND) + + { + + Trace("FindFirstFileA: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad file path name\n", + + GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("FindFirstFileA: managed to find a file with an incorrect" + + " filename\n"); + + testPass = FALSE; + + /*this should not happen*/ + + if(!FindClose(hFile)) + + { + + Trace("FindFirstFileA: Call to FindClose Failed with ErrorCode" + + " [%u]\n", GetLastError()); + + + + } + + + + } + + + + + + + + /*............. Test FindFirstFileW..................................*/ + + + + /* test with an invalid file name */ + + hFile = FindFirstFileW(wBadFileName,&wFindFileData ); + + + + if (hFile == INVALID_HANDLE_VALUE) + + { + + if(GetLastError() != ERROR_FILE_NOT_FOUND) + + { + + Trace("FindFirstFileW: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad File Name\n", + + GetLastError(),ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("FindFirstFileW: managed to find a file with an incorrect " + + "filename\n"); + + testPass = FALSE; + + + + if(!FindClose(hFile)) + + { + + Trace("FindFirstFileW: Call to FindClose failed with ErrorCode" + + " [%u]\n", GetLastError()); + + + + } + + + + } + + + + /* test with an invalid path */ + + hFile = FindFirstFileW(wBadFilePath,&wFindFileData); + + + + if (hFile == INVALID_HANDLE_VALUE) + + { + + if(GetLastError() != ERROR_PATH_NOT_FOUND) + + { + + Trace("FindFirstFileW: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad file path name\n", + + GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("FindFirstFileW: managed to find a file with an incorrect " + + "filename\n"); + + testPass = FALSE; + + /*this should not happen*/ + + if(!FindClose(hFile)) + + { + + Trace("FindFirstFileW: Call to FindClose Failed with ErrorCode " + + "[%u]\n", GetLastError()); + + + + } + + + + } + + + + + + /*...................Test GetFileAttributesW.............................*/ + + + + /* test with an invalid path */ + + fileAttrib = GetFileAttributesW(wBadFilePath); + + if(fileAttrib == -1) + + { + + if(GetLastError()!= ERROR_PATH_NOT_FOUND) + + { + + Trace("GetFileAttributesW: calling GetLastError() after getting" + + " the attributes of a file with wrong path returned [%u]" + + " while it should return [%u]\n", + + GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("GetFileAttributesW: managed to get the attrib of a file" + + " with wrong path\n"); + + testPass = FALSE; + + } + + + + /* test with invalid file name */ + + fileAttrib = GetFileAttributesW(wBadFileName); + + if(fileAttrib == -1) + + { + + if(GetLastError()!= ERROR_FILE_NOT_FOUND) + + { + + Trace("GetFileAttributesW: calling GetLastError() after getting" + + " the attributes of a file with wrong name returned [%u] " + + "while it should return [%u]\n" + + ,GetLastError(), ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("GetFileAttributesW: managed to get the attrib of a file" + + " with wrong name\n"); + + testPass = FALSE; + + } + + + + /*...................Test GetFileAttributesA.............................*/ + + + + /* test with an invalid path */ + + fileAttrib = GetFileAttributesA(sBadFilePath); + + if(fileAttrib == -1) + + { + + if(GetLastError()!= ERROR_PATH_NOT_FOUND) + + { + + Trace("GetFileAttributesA: calling GetLastError() after getting" + + " the attributes of a file with wrong path returned [%u] while" + + " it should return [%u]\n", + + GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("GetFileAttributesA: managed to get the attrib of a file" + + " with wrong path\n"); + + testPass = FALSE; + + } + + + + /* test with invalid file name */ + + fileAttrib = GetFileAttributesA(sBadFileName); + + if(fileAttrib == -1) + + { + + if(GetLastError()!= ERROR_FILE_NOT_FOUND) + + { + + Trace("GetFileAttributesA: calling GetLastError() after getting " + + "the attributes of a file with wrong name returned [%u] " + + "while it should return [%u]\n" + + ,GetLastError(), ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("GetFileAttributesA: managed to get the attrib of a file with" + + " wrong name\n"); + + testPass = FALSE; + + } + + + + + + + + + + /*...................Test SetFileAttributesW.............................*/ + + + + /* test with an invalid path */ + + bRc = SetFileAttributesW(wBadFilePath,FILE_ATTRIBUTE_NORMAL); + + if(!bRc) + + { + + if(GetLastError()!= ERROR_PATH_NOT_FOUND) + + { + + Trace("SetFileAttributesW: calling GetLastError() after setting" + + " the attributes of a file with wrong path returned [%u] " + + "while it should return [%u]\n", + + GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("SetFileAttributesW: managed to get the attrib of a file" + + " with wrong path\n"); + + testPass = FALSE; + + } + + + + /* test with invalid file name */ + + bRc = SetFileAttributesW(wBadFileName,FILE_ATTRIBUTE_NORMAL); + + if(!bRc) + + { + + if(GetLastError()!= ERROR_FILE_NOT_FOUND) + + { + + Trace("SetFileAttributesW: calling GetLastError() after setting" + + " the attributes of a file with wrong name returned [%u]" + + " while it should return [%u]\n", + + GetLastError(), ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("SetFileAttributesW: managed to get the attrib of a file with" + + " wrong name\n"); + + testPass = FALSE; + + } + + + + + + /*...................Test SetFileAttributesA.............................*/ + + + + /* test with an invalid path */ + + bRc = SetFileAttributesA(sBadFilePath,FILE_ATTRIBUTE_NORMAL); + + if(!bRc) + + { + + if(GetLastError()!= ERROR_PATH_NOT_FOUND) + + { + + Trace("SetFileAttributesA: calling GetLastError() after setting " + + "the attributes of a file with wrong path returned [%u] " + + "while it should return [%u]\n" + + ,GetLastError(), ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("SetFileAttributesA: managed to get the attrib of a file " + + "with wrong path\n"); + + testPass = FALSE; + + } + + + + /* test with invalid file name */ + + bRc = SetFileAttributesA(sBadFileName,FILE_ATTRIBUTE_NORMAL); + + if(!bRc) + + { + + if(GetLastError()!= ERROR_FILE_NOT_FOUND) + + { + + Trace("SetFileAttributesA: calling GetLastError() after setting" + + " the attributes of a file with wrong name returned [%u]" + + " while it should return [%u]\n", + + GetLastError(), ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + + + } + + else + + { + + Trace("SetFileAttributesA: managed to get the attrib of a file with " + + "wrong name\n"); + + testPass = FALSE; + + } + + + + + + if(! testPass) + + { + + Fail(""); + + } + + PAL_Terminate(); + + return PASS; + +} + + + diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/CMakeLists.txt index c7434f3dba..b418c9dbdb 100644 --- a/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_errorpathnotfound_test3 diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/test3.c b/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/test3.c deleted file mode 100644 index 414cbab176..0000000000 --- a/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/test3.c +++ /dev/null @@ -1,244 +0,0 @@ -// 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: test3.c - -** - -** Purpose: Test the return value of GetLastError() after calling - -** some file_io functions with an invalid path. - -** - -** Functions covered by this test are: - -** CreateDirectoryA, CreateDirectoryW, RemoveDirectoryW, - -** -** - - - -** - -**===================================================================*/ - - - -#include - - - -int __cdecl main(int argc, char *argv[]) - -{ - - - - BOOL testPass = TRUE; - - BOOL bRc = TRUE; - - DWORD errCode; - - - - const char* sBadSubDirectory = "bad/badDir"; - - - - /* Needed for RemoveDirectoryW */ - - const WCHAR tempName[] = {'b','a','d','/', - - 'b','a','d','D','i','r'}; - - - - const WCHAR wBadSubDirectory[] = - - {'w','b','a','d','/','b','a', - - 'd','D','i','r','\0'}; - - - - if (0 != PAL_Initialize(argc,argv)) - - { - - return FAIL; - - } - - - - /* ---------------------CreateDirectoryA------------------------- */ - - - - - - /* Testing of CreateDirectoryA */ - - bRc = CreateDirectoryA(sBadSubDirectory,NULL); - - if(!bRc) - - { - - errCode = GetLastError(); - - if(errCode != ERROR_PATH_NOT_FOUND) - - { - - Trace("CreateDirectoryA: calling GetLastError() after creating a " - - "directory with invalid path returned [%u] while it should " - - "return [%u]\n",errCode, ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("CreateDirectoryA: Created a directory with an invalid path.\n"); - - bRc = RemoveDirectoryW(tempName); - - if(!bRc) - - { - - Trace("Failed to remove %s with error %u.\n", - - sBadSubDirectory,GetLastError()); - - } - - testPass = FALSE; - - } - - - - /* ---------------------CreateDirectoryW------------------------- */ - - - - /* Testing of CreateDirectoryW */ - - bRc = CreateDirectoryW(wBadSubDirectory,NULL); - - if(!bRc) - - { - - errCode = GetLastError(); - - if(errCode != ERROR_PATH_NOT_FOUND) - - { - - Trace("CreateDirectoryW: calling GetLastError() after creating a " - - "directory with invalid path returned [%u] while it should " - - "return [%u]\n",errCode, ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("CreateDirectoryW: Created a directory with an invalid path.\n"); - - bRc = RemoveDirectoryW(wBadSubDirectory); - - if(!bRc) - - { - - Trace("Failed to remove %S with error %u.\n", - - wBadSubDirectory,GetLastError()); - - } - - testPass = FALSE; - - } - - - - /* ---------------------RemoveDirectoryW------------------------ */ - - - - /* Testing of RemoveDirectoryW */ - - bRc = RemoveDirectoryW(wBadSubDirectory); - - if(!bRc) - - { - - errCode = GetLastError(); - - if(errCode != ERROR_PATH_NOT_FOUND) - - { - - Trace("RemoveDirectoryW: calling GetLastError() after removing a " - - "sub directory with invalid path returned [%u] while it should " - - "return [%u]\n",errCode, ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("RemoveDirectoryW: Removed a directory that did not exist.\n"); - - } - - int exitCode = testPass ? PASS : FAIL; - PAL_TerminateEx(exitCode); - return exitCode; - - - - - - - - - - -} - diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/test3.cpp b/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/test3.cpp new file mode 100644 index 0000000000..414cbab176 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/errorpathnotfound/test3/test3.cpp @@ -0,0 +1,244 @@ +// 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: test3.c + +** + +** Purpose: Test the return value of GetLastError() after calling + +** some file_io functions with an invalid path. + +** + +** Functions covered by this test are: + +** CreateDirectoryA, CreateDirectoryW, RemoveDirectoryW, + +** +** + + + +** + +**===================================================================*/ + + + +#include + + + +int __cdecl main(int argc, char *argv[]) + +{ + + + + BOOL testPass = TRUE; + + BOOL bRc = TRUE; + + DWORD errCode; + + + + const char* sBadSubDirectory = "bad/badDir"; + + + + /* Needed for RemoveDirectoryW */ + + const WCHAR tempName[] = {'b','a','d','/', + + 'b','a','d','D','i','r'}; + + + + const WCHAR wBadSubDirectory[] = + + {'w','b','a','d','/','b','a', + + 'd','D','i','r','\0'}; + + + + if (0 != PAL_Initialize(argc,argv)) + + { + + return FAIL; + + } + + + + /* ---------------------CreateDirectoryA------------------------- */ + + + + + + /* Testing of CreateDirectoryA */ + + bRc = CreateDirectoryA(sBadSubDirectory,NULL); + + if(!bRc) + + { + + errCode = GetLastError(); + + if(errCode != ERROR_PATH_NOT_FOUND) + + { + + Trace("CreateDirectoryA: calling GetLastError() after creating a " + + "directory with invalid path returned [%u] while it should " + + "return [%u]\n",errCode, ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("CreateDirectoryA: Created a directory with an invalid path.\n"); + + bRc = RemoveDirectoryW(tempName); + + if(!bRc) + + { + + Trace("Failed to remove %s with error %u.\n", + + sBadSubDirectory,GetLastError()); + + } + + testPass = FALSE; + + } + + + + /* ---------------------CreateDirectoryW------------------------- */ + + + + /* Testing of CreateDirectoryW */ + + bRc = CreateDirectoryW(wBadSubDirectory,NULL); + + if(!bRc) + + { + + errCode = GetLastError(); + + if(errCode != ERROR_PATH_NOT_FOUND) + + { + + Trace("CreateDirectoryW: calling GetLastError() after creating a " + + "directory with invalid path returned [%u] while it should " + + "return [%u]\n",errCode, ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("CreateDirectoryW: Created a directory with an invalid path.\n"); + + bRc = RemoveDirectoryW(wBadSubDirectory); + + if(!bRc) + + { + + Trace("Failed to remove %S with error %u.\n", + + wBadSubDirectory,GetLastError()); + + } + + testPass = FALSE; + + } + + + + /* ---------------------RemoveDirectoryW------------------------ */ + + + + /* Testing of RemoveDirectoryW */ + + bRc = RemoveDirectoryW(wBadSubDirectory); + + if(!bRc) + + { + + errCode = GetLastError(); + + if(errCode != ERROR_PATH_NOT_FOUND) + + { + + Trace("RemoveDirectoryW: calling GetLastError() after removing a " + + "sub directory with invalid path returned [%u] while it should " + + "return [%u]\n",errCode, ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("RemoveDirectoryW: Removed a directory that did not exist.\n"); + + } + + int exitCode = testPass ? PASS : FAIL; + PAL_TerminateEx(exitCode); + return exitCode; + + + + + + + + + + +} + diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/CMakeLists.txt index f8062fd127..e0322dd8e4 100644 --- a/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_errorpathnotfound_test4 diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/test4.c b/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/test4.c deleted file mode 100644 index e1b68995b0..0000000000 --- a/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/test4.c +++ /dev/null @@ -1,351 +0,0 @@ -// 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: test4.c - -** - -** Purpose: Test the return value of GetLastError() after calling - -** some file_io functions with an invalid path. - -** - -** Functions covered by this test are: - -** GetDiskFreeSpaceW, GetTempFileNameA - -** and GetTempFileNameW - -** -** - -** - - - -** - -**===================================================================*/ - - - -#include - - - -int __cdecl main(int argc, char *argv[]) - -{ - - - - BOOL testPass = TRUE; - - BOOL bRc = TRUE; - - DWORD lastErr=-50; - - DWORD dwSectorsPerCluster_02; /* sectors per cluster */ - - DWORD dwBytesPerSector_02; /* bytes per sector */ - - DWORD dwNumberOfFreeClusters; /* free clusters */ - - DWORD dwTotalNumberOfClusters; /* total clusters */ - - - - UINT uiError = 0; - - char szReturnedName[256]; - - const UINT uUnique = 0; - - const char* sDot = {"tmpr"}; - - const char* sPrefix = {"cfr"}; - - - - WCHAR wzReturnedName[256]; - - const WCHAR wDot[] = {'t','m','p','r','\0'}; - - const WCHAR wPrefix[] = {'c','f','r','\0'}; - - - - - - const WCHAR wBadFilePath[] = - - {'w','b','a','d','/','b','a', - - 'd','.','t','m','p','\0'}; - - const WCHAR wBadFileName[] = - - {'w','B','a','d','.','t','m','p','\0'}; - - - - - - - - if (0 != PAL_Initialize(argc,argv)) - - { - - return FAIL; - - } - - - - /* test .................. GetDiskFreeSpaceW .................. */ - - - - /* test with invalid file name */ - - bRc = GetDiskFreeSpaceW(wBadFileName, - - &dwSectorsPerCluster_02, - - &dwBytesPerSector_02, - - &dwNumberOfFreeClusters, - - &dwTotalNumberOfClusters); - - if (bRc != TRUE) - - - - { - - lastErr=GetLastError(); - - - - if(lastErr != ERROR_FILE_NOT_FOUND) - - { - - Trace("GetDiskFreeSpaceW: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad File Name\n", - - lastErr,ERROR_FILE_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("GetDiskFreeSpaceW: GetDiskFreeSpaceW succeeded when given " - - "a bad fileName\n"); - - testPass = FALSE; - - - - } - - - - - - /* test with invalid path name */ - - bRc = GetDiskFreeSpaceW(wBadFilePath, - - &dwSectorsPerCluster_02, - - &dwBytesPerSector_02, - - &dwNumberOfFreeClusters, - - &dwTotalNumberOfClusters); - - if (bRc != TRUE) - - - - { - - lastErr=GetLastError(); - - if(lastErr != ERROR_PATH_NOT_FOUND) - - { - - Trace("GetDiskFreeSpaceW: calling GetLastError() returned [%u] " - - "while it should return [%u] for a bad File Name\n", - - lastErr,ERROR_PATH_NOT_FOUND); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("GetDiskFreeSpaceW: GetDiskFreeSpaceW succeeded when given " - - "a bad fileName\n"); - - testPass = FALSE; - - - - - - } - - - - - - /* test .................. GetTempFileNameA .................. */ - - - - /* test with invalid path name */ - - uiError = GetTempFileNameA(sDot, sPrefix, uUnique, szReturnedName); - - if (uiError == 0) - - { - - lastErr=GetLastError(); - - if(lastErr != ERROR_DIRECTORY) - - { - - - - Trace("GetTempFileNameA: calling GetLastError() returned [%u] " - - "while it should return [%u] for invalid path name\n", - - lastErr,ERROR_DIRECTORY); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("GetTempFileNameA: GetTempFileNameA succeeded when given " - - "invalid path name\n"); - - testPass = FALSE; - - } - - - - - - - - /* test .................. GetTempFileNameW .................. */ - - - - /* test with invalid path name */ - - uiError = GetTempFileNameW(wDot, wPrefix, uUnique, wzReturnedName); - - if (uiError == 0) - - { - - lastErr=GetLastError(); - - if(lastErr != ERROR_DIRECTORY) - - { - - - - Trace("GetTempFileNameW: calling GetLastError() returned [%u] " - - "while it should return [%u] for an invalid path name\n", - - lastErr,ERROR_DIRECTORY); - - testPass = FALSE; - - } - - } - - else - - { - - Trace("GetTempFileNameW: GetTempFileNameW succeeded when given" - - " an invalid path name\n"); - - testPass = FALSE; - - } - - - - if(! testPass) - - { - - Fail(""); - - } - - - - - - - - - - - - - - PAL_Terminate(); - - return PASS; - -} - - - diff --git a/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/test4.cpp b/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/test4.cpp new file mode 100644 index 0000000000..e1b68995b0 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/errorpathnotfound/test4/test4.cpp @@ -0,0 +1,351 @@ +// 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: test4.c + +** + +** Purpose: Test the return value of GetLastError() after calling + +** some file_io functions with an invalid path. + +** + +** Functions covered by this test are: + +** GetDiskFreeSpaceW, GetTempFileNameA + +** and GetTempFileNameW + +** +** + +** + + + +** + +**===================================================================*/ + + + +#include + + + +int __cdecl main(int argc, char *argv[]) + +{ + + + + BOOL testPass = TRUE; + + BOOL bRc = TRUE; + + DWORD lastErr=-50; + + DWORD dwSectorsPerCluster_02; /* sectors per cluster */ + + DWORD dwBytesPerSector_02; /* bytes per sector */ + + DWORD dwNumberOfFreeClusters; /* free clusters */ + + DWORD dwTotalNumberOfClusters; /* total clusters */ + + + + UINT uiError = 0; + + char szReturnedName[256]; + + const UINT uUnique = 0; + + const char* sDot = {"tmpr"}; + + const char* sPrefix = {"cfr"}; + + + + WCHAR wzReturnedName[256]; + + const WCHAR wDot[] = {'t','m','p','r','\0'}; + + const WCHAR wPrefix[] = {'c','f','r','\0'}; + + + + + + const WCHAR wBadFilePath[] = + + {'w','b','a','d','/','b','a', + + 'd','.','t','m','p','\0'}; + + const WCHAR wBadFileName[] = + + {'w','B','a','d','.','t','m','p','\0'}; + + + + + + + + if (0 != PAL_Initialize(argc,argv)) + + { + + return FAIL; + + } + + + + /* test .................. GetDiskFreeSpaceW .................. */ + + + + /* test with invalid file name */ + + bRc = GetDiskFreeSpaceW(wBadFileName, + + &dwSectorsPerCluster_02, + + &dwBytesPerSector_02, + + &dwNumberOfFreeClusters, + + &dwTotalNumberOfClusters); + + if (bRc != TRUE) + + + + { + + lastErr=GetLastError(); + + + + if(lastErr != ERROR_FILE_NOT_FOUND) + + { + + Trace("GetDiskFreeSpaceW: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad File Name\n", + + lastErr,ERROR_FILE_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("GetDiskFreeSpaceW: GetDiskFreeSpaceW succeeded when given " + + "a bad fileName\n"); + + testPass = FALSE; + + + + } + + + + + + /* test with invalid path name */ + + bRc = GetDiskFreeSpaceW(wBadFilePath, + + &dwSectorsPerCluster_02, + + &dwBytesPerSector_02, + + &dwNumberOfFreeClusters, + + &dwTotalNumberOfClusters); + + if (bRc != TRUE) + + + + { + + lastErr=GetLastError(); + + if(lastErr != ERROR_PATH_NOT_FOUND) + + { + + Trace("GetDiskFreeSpaceW: calling GetLastError() returned [%u] " + + "while it should return [%u] for a bad File Name\n", + + lastErr,ERROR_PATH_NOT_FOUND); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("GetDiskFreeSpaceW: GetDiskFreeSpaceW succeeded when given " + + "a bad fileName\n"); + + testPass = FALSE; + + + + + + } + + + + + + /* test .................. GetTempFileNameA .................. */ + + + + /* test with invalid path name */ + + uiError = GetTempFileNameA(sDot, sPrefix, uUnique, szReturnedName); + + if (uiError == 0) + + { + + lastErr=GetLastError(); + + if(lastErr != ERROR_DIRECTORY) + + { + + + + Trace("GetTempFileNameA: calling GetLastError() returned [%u] " + + "while it should return [%u] for invalid path name\n", + + lastErr,ERROR_DIRECTORY); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("GetTempFileNameA: GetTempFileNameA succeeded when given " + + "invalid path name\n"); + + testPass = FALSE; + + } + + + + + + + + /* test .................. GetTempFileNameW .................. */ + + + + /* test with invalid path name */ + + uiError = GetTempFileNameW(wDot, wPrefix, uUnique, wzReturnedName); + + if (uiError == 0) + + { + + lastErr=GetLastError(); + + if(lastErr != ERROR_DIRECTORY) + + { + + + + Trace("GetTempFileNameW: calling GetLastError() returned [%u] " + + "while it should return [%u] for an invalid path name\n", + + lastErr,ERROR_DIRECTORY); + + testPass = FALSE; + + } + + } + + else + + { + + Trace("GetTempFileNameW: GetTempFileNameW succeeded when given" + + " an invalid path name\n"); + + testPass = FALSE; + + } + + + + if(! testPass) + + { + + Fail(""); + + } + + + + + + + + + + + + + + PAL_Terminate(); + + return PASS; + +} + + + diff --git a/src/pal/tests/palsuite/file_io/gettemppatha/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/gettemppatha/test1/CMakeLists.txt index 2aff599e74..9869c9c70f 100644 --- a/src/pal/tests/palsuite/file_io/gettemppatha/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/gettemppatha/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - gettemppatha.c + gettemppatha.cpp ) add_executable(paltest_gettemppatha_test1 diff --git a/src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.c b/src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.c deleted file mode 100644 index b0da528af8..0000000000 --- a/src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.c +++ /dev/null @@ -1,103 +0,0 @@ -// 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: gettemppatha.c (test 1) -** -** Purpose: Tests the PAL implementation of the GetTempPathA function. -** -** -**===================================================================*/ - -#include - -static void SetTmpDir(CHAR path[]) -{ - DWORD result = SetEnvironmentVariableA("TMPDIR", path); - if (!result) - { - Fail("ERROR -> SetEnvironmentVariableA failed with result %d and error code %d.\n", - result, GetLastError()); - } -} - -static void SetAndCompare(CHAR tmpDirPath[], CHAR expected[]) -{ - DWORD dwBufferLength = _MAX_DIR; - CHAR path[dwBufferLength]; - - SetTmpDir(tmpDirPath); - - DWORD dwResultLen = GetTempPathA(dwBufferLength, path); - if (dwResultLen <= 0) - { - Fail("ERROR: GetTempPathA returned %d with error code %d.\n", dwResultLen, GetLastError()); - } - if (dwResultLen >= dwBufferLength) - { - Fail("ERROR: Buffer of length %d passed to GetTempPathA was too small to hold %d chars..\n", dwBufferLength, dwResultLen); - } - if (strcmp(expected, path) != 0) - { - Fail("ERROR: GetTempPathA expected to get '%s' but instead got '%s'.\n", expected, path); - } - if (expected[dwResultLen - 1] != '/') - { - Fail("ERROR: GetTempPathA returned '%s', which should have ended in '/'.\n", path); - } -} - -static void SetAndCheckLength(CHAR tmpDirPath[], int bufferLength, int expectedResultLength) -{ - CHAR path[bufferLength]; - - SetTmpDir(tmpDirPath); - DWORD dwResultLen = GetTempPathA(bufferLength, path); - - if (dwResultLen != expectedResultLength) - { - Fail("GetTempPathA(%d, %s) expected to return %d but returned %d.\n", - bufferLength, tmpDirPath?tmpDirPath:"NULL", expectedResultLength, dwResultLen); - } -} - -int __cdecl main(int argc, char *argv[]) -{ - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - SetAndCompare("/tmp", "/tmp/"); - SetAndCompare("/tmp/", "/tmp/"); - SetAndCompare("", "/tmp/"); - SetAndCompare(NULL, "/tmp/"); - SetAndCompare("/", "/"); - SetAndCompare("/var/tmp", "/var/tmp/"); - SetAndCompare("/var/tmp/", "/var/tmp/"); - SetAndCompare("~", "~/"); - SetAndCompare("~/", "~/"); - SetAndCompare(".tmp", ".tmp/"); - SetAndCompare("./tmp", "./tmp/"); - SetAndCompare("/home/someuser/sometempdir", "/home/someuser/sometempdir/"); - SetAndCompare(NULL, "/tmp/"); - - DWORD dwResultLen = GetTempPathA(0, NULL); - if (dwResultLen != 0 || GetLastError() != ERROR_INVALID_PARAMETER) - { - Fail("GetTempPath(NULL, ...) returned %d with error code %d but " - "should have failed with ERROR_INVALID_PARAMETER (%d).\n", - dwResultLen, GetLastError(), ERROR_INVALID_PARAMETER); - } - - SetAndCheckLength("abc/", 5, 4); - SetAndCheckLength("abcd", 5, 6); - SetAndCheckLength("abcde", 5, 7); - SetAndCheckLength("abcdef/", 5, 9); - SetAndCheckLength(NULL, 5, 6); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.cpp b/src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.cpp new file mode 100644 index 0000000000..b0da528af8 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.cpp @@ -0,0 +1,103 @@ +// 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: gettemppatha.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetTempPathA function. +** +** +**===================================================================*/ + +#include + +static void SetTmpDir(CHAR path[]) +{ + DWORD result = SetEnvironmentVariableA("TMPDIR", path); + if (!result) + { + Fail("ERROR -> SetEnvironmentVariableA failed with result %d and error code %d.\n", + result, GetLastError()); + } +} + +static void SetAndCompare(CHAR tmpDirPath[], CHAR expected[]) +{ + DWORD dwBufferLength = _MAX_DIR; + CHAR path[dwBufferLength]; + + SetTmpDir(tmpDirPath); + + DWORD dwResultLen = GetTempPathA(dwBufferLength, path); + if (dwResultLen <= 0) + { + Fail("ERROR: GetTempPathA returned %d with error code %d.\n", dwResultLen, GetLastError()); + } + if (dwResultLen >= dwBufferLength) + { + Fail("ERROR: Buffer of length %d passed to GetTempPathA was too small to hold %d chars..\n", dwBufferLength, dwResultLen); + } + if (strcmp(expected, path) != 0) + { + Fail("ERROR: GetTempPathA expected to get '%s' but instead got '%s'.\n", expected, path); + } + if (expected[dwResultLen - 1] != '/') + { + Fail("ERROR: GetTempPathA returned '%s', which should have ended in '/'.\n", path); + } +} + +static void SetAndCheckLength(CHAR tmpDirPath[], int bufferLength, int expectedResultLength) +{ + CHAR path[bufferLength]; + + SetTmpDir(tmpDirPath); + DWORD dwResultLen = GetTempPathA(bufferLength, path); + + if (dwResultLen != expectedResultLength) + { + Fail("GetTempPathA(%d, %s) expected to return %d but returned %d.\n", + bufferLength, tmpDirPath?tmpDirPath:"NULL", expectedResultLength, dwResultLen); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + SetAndCompare("/tmp", "/tmp/"); + SetAndCompare("/tmp/", "/tmp/"); + SetAndCompare("", "/tmp/"); + SetAndCompare(NULL, "/tmp/"); + SetAndCompare("/", "/"); + SetAndCompare("/var/tmp", "/var/tmp/"); + SetAndCompare("/var/tmp/", "/var/tmp/"); + SetAndCompare("~", "~/"); + SetAndCompare("~/", "~/"); + SetAndCompare(".tmp", ".tmp/"); + SetAndCompare("./tmp", "./tmp/"); + SetAndCompare("/home/someuser/sometempdir", "/home/someuser/sometempdir/"); + SetAndCompare(NULL, "/tmp/"); + + DWORD dwResultLen = GetTempPathA(0, NULL); + if (dwResultLen != 0 || GetLastError() != ERROR_INVALID_PARAMETER) + { + Fail("GetTempPath(NULL, ...) returned %d with error code %d but " + "should have failed with ERROR_INVALID_PARAMETER (%d).\n", + dwResultLen, GetLastError(), ERROR_INVALID_PARAMETER); + } + + SetAndCheckLength("abc/", 5, 4); + SetAndCheckLength("abcd", 5, 6); + SetAndCheckLength("abcde", 5, 7); + SetAndCheckLength("abcdef/", 5, 9); + SetAndCheckLength(NULL, 5, 6); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CMakeLists.txt index 3fc399fe59..a573dae8cd 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CMakeLists.txt @@ -17,7 +17,7 @@ add_subdirectory(LockFile) add_subdirectory(MapViewOfFile) add_subdirectory(OpenFileMappingA) add_subdirectory(OpenFileMappingW) -add_subdirectory(ReadProcessMemory) +add_subdirectory(ProbeMemory) add_subdirectory(RtlMoveMemory) add_subdirectory(UnlockFile) add_subdirectory(UnmapViewOfFile) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CMakeLists.txt index 36084bf446..c38015ea21 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMapping.c + CreateFileMapping.cpp ) add_executable(paltest_createfilemappinga_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.c deleted file mode 100644 index 91640bfd04..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.c +++ /dev/null @@ -1,173 +0,0 @@ -// 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: createfilemapping.c (test 1) -** -** Purpose: Positive test the CreateFileMapping API. -** Call CreateFileMapping with access PAGE_READONLY. -** -** -**============================================================*/ -#include - -const int MAPPINGSIZE = 2048; - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - char buf[] = "this is a test string"; - char ch[2048]; - char lpFileName[] = "test.tmp"; - DWORD dwBytesWritten; - BOOL err; - int RetVal = PASS; - - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Initialize the buffers. - */ - memset(ch, 0, MAPPINGSIZE); - - /* Write to the File handle. - */ - err = WriteFile(hFile, - buf, - strlen(buf), - &dwBytesWritten, - NULL); - - if (err == FALSE) - { - Trace("ERROR: %u :unable to write to file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Flush to the hard-drive. - */ - FlushFileBuffers(hFile); - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READONLY, /*read and wite*/ - 0, /*high-order size*/ - 0, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_READ, /* access code */ - 0, /*high order offset*/ - 0, /*low order offset*/ - 0); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Copy the MapViewOfFile to buffer, so we can - * compare with value read from file directly. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpThree; - } - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapping) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapping); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFile) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFile); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.cpp new file mode 100644 index 0000000000..91640bfd04 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.cpp @@ -0,0 +1,173 @@ +// 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: createfilemapping.c (test 1) +** +** Purpose: Positive test the CreateFileMapping API. +** Call CreateFileMapping with access PAGE_READONLY. +** +** +**============================================================*/ +#include + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char buf[] = "this is a test string"; + char ch[2048]; + char lpFileName[] = "test.tmp"; + DWORD dwBytesWritten; + BOOL err; + int RetVal = PASS; + + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + + /* Write to the File handle. + */ + err = WriteFile(hFile, + buf, + strlen(buf), + &dwBytesWritten, + NULL); + + if (err == FALSE) + { + Trace("ERROR: %u :unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Flush to the hard-drive. + */ + FlushFileBuffers(hFile); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READONLY, /*read and wite*/ + 0, /*high-order size*/ + 0, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_READ, /* access code */ + 0, /*high order offset*/ + 0, /*low order offset*/ + 0); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapping) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapping); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFile) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFile); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CMakeLists.txt index 374f8f0946..fc152c8161 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMapping.c + CreateFileMapping.cpp ) add_executable(paltest_createfilemappinga_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.c deleted file mode 100644 index 2a849d86b8..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.c +++ /dev/null @@ -1,155 +0,0 @@ -// 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: createfilemapping.c (test 3) -** -** Purpose: Positive test the CreateFileMapping API. -** Call CreateFileMapping with access PAGE_READWRITE. -** -** -**============================================================*/ -#include - -const int MAPPINGSIZE = 2048; - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - char buf[] = "this is a test string"; - char ch[2048]; - char lpFileName[] = "test.tmp"; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - int RetVal = PASS; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Initialize the buffers. - */ - memset(ch, 0, MAPPINGSIZE); - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and wite*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /*high order offset*/ - 0, /*low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write to the Map view. - */ - memcpy(lpMapViewAddress, buf, strlen(buf)); - - /* Read from the Map view. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); - - /* Copy the MapViewOfFile to buffer, so we can - * compare with value read from file directly. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpThree; - } - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapping) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapping); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFile) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFile); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.cpp new file mode 100644 index 0000000000..2a849d86b8 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.cpp @@ -0,0 +1,155 @@ +// 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: createfilemapping.c (test 3) +** +** Purpose: Positive test the CreateFileMapping API. +** Call CreateFileMapping with access PAGE_READWRITE. +** +** +**============================================================*/ +#include + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char buf[] = "this is a test string"; + char ch[2048]; + char lpFileName[] = "test.tmp"; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + int RetVal = PASS; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and wite*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /*high order offset*/ + 0, /*low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write to the Map view. + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map view. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapping) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapping); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFile) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFile); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CMakeLists.txt index 665b10a3f0..bbb4deaa8b 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMapping.c + CreateFileMapping.cpp ) add_executable(paltest_createfilemappinga_test4 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.c deleted file mode 100644 index 64caa88ca0..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.c +++ /dev/null @@ -1,181 +0,0 @@ -// 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: createfilemapping.c (test 4) -** -** Purpose: Positive test the CreateFileMapping API. -** Call CreateFileMapping with access PAGE_WRITECOPY. -** -** -**============================================================*/ -#include - -const int MAPPINGSIZE = 2048; - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - char buf[] = "this is a test string"; - char ch[2048]; - char lpFileName[] = "test.tmp"; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - int RetVal = PASS; - int err; - DWORD dwBytesWritten; - - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Write to the File handle. - */ - err = WriteFile(hFile, - buf, - strlen(buf), - &dwBytesWritten, - NULL); - - if (err == FALSE) - { - Trace("ERROR: %u :unable to write to file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Flush to the hard-drive. - */ - FlushFileBuffers(hFile); - - /* Initialize the buffers. - */ - memset(ch, 0, MAPPINGSIZE); - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_WRITECOPY protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_WRITECOPY, /*write copy*/ - 0, /*high-order size*/ - 0, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_COPY, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - 0); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write to the Map view.3 - */ - memcpy(lpMapViewAddress, buf, strlen(buf)); - - /* Read from the Map view. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); - - /* Copy the MapViewOfFile to buffer, so we can - * compare with value read from file directly. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpThree; - } - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapping) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapping); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFile) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFile); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.cpp new file mode 100644 index 0000000000..64caa88ca0 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.cpp @@ -0,0 +1,181 @@ +// 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: createfilemapping.c (test 4) +** +** Purpose: Positive test the CreateFileMapping API. +** Call CreateFileMapping with access PAGE_WRITECOPY. +** +** +**============================================================*/ +#include + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char buf[] = "this is a test string"; + char ch[2048]; + char lpFileName[] = "test.tmp"; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + int RetVal = PASS; + int err; + DWORD dwBytesWritten; + + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Write to the File handle. + */ + err = WriteFile(hFile, + buf, + strlen(buf), + &dwBytesWritten, + NULL); + + if (err == FALSE) + { + Trace("ERROR: %u :unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Flush to the hard-drive. + */ + FlushFileBuffers(hFile); + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_WRITECOPY protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_WRITECOPY, /*write copy*/ + 0, /*high-order size*/ + 0, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_COPY, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + 0); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write to the Map view.3 + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map view. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapping) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapping); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFile) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFile); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CMakeLists.txt index 6f7f3c3635..b80aa21a42 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMapping.c + CreateFileMapping.cpp ) add_executable(paltest_createfilemappinga_test5 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.c deleted file mode 100644 index c7f9918b08..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.c +++ /dev/null @@ -1,193 +0,0 @@ -// 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: createfilemapping.c (test 5) -** -** Purpose: Positive test the CreateFileMapping API. -** Test CreateFileMapping to a "swap" handle with -** access PAGE_READONLY. -** -** -**============================================================*/ -#include - -const int MAPPINGSIZE = 2048; -HANDLE SWAP_HANDLE = ((VOID *)(-1)); - -int __cdecl main(int argc, char *argv[]) -{ - char testString[] = "this is a test string"; - char lpObjectName[] = "myMappingObject"; - int RetVal = FAIL; - char results[2048]; - - HANDLE hFileMapRO; - HANDLE hFileMapRW; - LPVOID lpMapViewRO; - LPVOID lpMapViewRW; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Initialize the buffers. - */ - memset(results, 0, MAPPINGSIZE); - - /* Create a named file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapRW = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read only*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - lpObjectName); /*named object*/ - - if(NULL == hFileMapRW) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewRW = MapViewOfFile( - hFileMapRW, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRW) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - - hFileMapRO = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READONLY, /*read and write*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - lpObjectName); /*named object*/ - - if(NULL == hFileMapRO) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewRO = MapViewOfFile( - hFileMapRO, - FILE_MAP_READ, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRO) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Write the test string to the Map view. - */ - memcpy(lpMapViewRW, testString, strlen(testString)); - - /* Read from the second Map view. - */ - memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); - - /* Verify the contents of the file mapping, - * by comparing what was written to what was read. - */ - if (memcmp(results, testString, strlen(testString))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - results, - testString); - RetVal = FAIL; - goto CleanUpFour; - } - - /* Test was successful. - */ - RetVal = PASS; - -CleanUpFour: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRO); - RetVal = FAIL; - } - -CleanUpThree: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapRO) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapRO); - RetVal = FAIL; - } - - -CleanUpTwo: - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRW); - RetVal = FAIL; - } - - -CleanUpOne: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapRW) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapRW); - RetVal = FAIL; - } - - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.cpp new file mode 100644 index 0000000000..c7f9918b08 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.cpp @@ -0,0 +1,193 @@ +// 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: createfilemapping.c (test 5) +** +** Purpose: Positive test the CreateFileMapping API. +** Test CreateFileMapping to a "swap" handle with +** access PAGE_READONLY. +** +** +**============================================================*/ +#include + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + char testString[] = "this is a test string"; + char lpObjectName[] = "myMappingObject"; + int RetVal = FAIL; + char results[2048]; + + HANDLE hFileMapRO; + HANDLE hFileMapRW; + LPVOID lpMapViewRO; + LPVOID lpMapViewRW; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Initialize the buffers. + */ + memset(results, 0, MAPPINGSIZE); + + /* Create a named file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapRW = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*named object*/ + + if(NULL == hFileMapRW) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewRW = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + + hFileMapRO = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READONLY, /*read and write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*named object*/ + + if(NULL == hFileMapRO) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewRO = MapViewOfFile( + hFileMapRO, + FILE_MAP_READ, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRO) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Write the test string to the Map view. + */ + memcpy(lpMapViewRW, testString, strlen(testString)); + + /* Read from the second Map view. + */ + memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); + + /* Verify the contents of the file mapping, + * by comparing what was written to what was read. + */ + if (memcmp(results, testString, strlen(testString))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + results, + testString); + RetVal = FAIL; + goto CleanUpFour; + } + + /* Test was successful. + */ + RetVal = PASS; + +CleanUpFour: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRO); + RetVal = FAIL; + } + +CleanUpThree: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapRO) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRO); + RetVal = FAIL; + } + + +CleanUpTwo: + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW); + RetVal = FAIL; + } + + +CleanUpOne: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapRW) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRW); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CMakeLists.txt index 2f5d98b5e6..414127aa35 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMapping.c + CreateFileMapping.cpp ) add_executable(paltest_createfilemappinga_test6 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.c deleted file mode 100644 index 6445295de8..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.c +++ /dev/null @@ -1,164 +0,0 @@ -// 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: createfilemapping.c (test 6) -** -** Purpose: Positive test the CreateFileMapping API. -** Test CreateFileMapping to a "swap" handle with -** access PAGE_READWRITE. -** -** -**============================================================*/ -#include - -const int MAPPINGSIZE = 2048; -HANDLE SWAP_HANDLE = ((VOID *)(-1)); - -int __cdecl main(int argc, char *argv[]) -{ - char testString[] = "this is a test string"; - char lpObjectName[] = "myMappingObject"; - char results[2048]; - int RetVal = PASS; - - HANDLE hFileMapRW; - LPVOID lpMapViewRW; - LPVOID lpMapViewRW2; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Initialize the buffers. - */ - memset(results, 0, MAPPINGSIZE); - - /* Create a named file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapRW = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read write*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - lpObjectName); /*unnamed object*/ - - if(NULL == hFileMapRW) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - /* Create a map view of the READWRITE file mapping. - */ - lpMapViewRW = MapViewOfFile( - hFileMapRW, - FILE_MAP_ALL_ACCESS,/* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRW) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewRW2 = MapViewOfFile( - hFileMapRW, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRW2) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write the test string to the Map view. - */ - memcpy(lpMapViewRW, testString, strlen(testString)); - - /* Read from the second Map view. - */ - memcpy(results, (LPCSTR)lpMapViewRW2, MAPPINGSIZE); - - /* Verify the contents of the file mapping, - * by comparing what was written to what was read. - */ - if (memcmp(results, testString, strlen(testString))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - results, - testString); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Test successful. - */ - RetVal = PASS; - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRW2) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRW2); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRW); - RetVal = FAIL; - } - - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFileMapRW) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapRW); - RetVal = FAIL; - } - - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.cpp new file mode 100644 index 0000000000..6445295de8 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.cpp @@ -0,0 +1,164 @@ +// 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: createfilemapping.c (test 6) +** +** Purpose: Positive test the CreateFileMapping API. +** Test CreateFileMapping to a "swap" handle with +** access PAGE_READWRITE. +** +** +**============================================================*/ +#include + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + char testString[] = "this is a test string"; + char lpObjectName[] = "myMappingObject"; + char results[2048]; + int RetVal = PASS; + + HANDLE hFileMapRW; + LPVOID lpMapViewRW; + LPVOID lpMapViewRW2; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Initialize the buffers. + */ + memset(results, 0, MAPPINGSIZE); + + /* Create a named file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapRW = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*unnamed object*/ + + if(NULL == hFileMapRW) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + /* Create a map view of the READWRITE file mapping. + */ + lpMapViewRW = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS,/* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewRW2 = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW2) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write the test string to the Map view. + */ + memcpy(lpMapViewRW, testString, strlen(testString)); + + /* Read from the second Map view. + */ + memcpy(results, (LPCSTR)lpMapViewRW2, MAPPINGSIZE); + + /* Verify the contents of the file mapping, + * by comparing what was written to what was read. + */ + if (memcmp(results, testString, strlen(testString))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + results, + testString); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Test successful. + */ + RetVal = PASS; + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW2) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW2); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW); + RetVal = FAIL; + } + + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFileMapRW) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRW); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/CMakeLists.txt index 4fd24a63a1..e40a5ad486 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createfilemapping.c + createfilemapping.cpp ) add_executable(paltest_createfilemappinga_test7 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.c deleted file mode 100644 index 7cef9ddcdc..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.c +++ /dev/null @@ -1,164 +0,0 @@ -// 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: createfilemapping.c (test 7) -** -** Purpose: Positive test the CreateFileMapping API. -** Test CreateFileMapping to a "swap" handle with -** access PAGE_READWRITE. -** -** -**============================================================*/ -#include - -const int MAPPINGSIZE = 2048; -HANDLE SWAP_HANDLE = ((VOID *)(-1)); - -int __cdecl main(int argc, char *argv[]) -{ - char testString[] = "this is a test string"; - char lpObjectName[] = "myMappingObject"; - char results[2048]; - int RetVal = PASS; - - HANDLE hFileMapRW; - LPVOID lpMapViewRW; - LPVOID lpMapViewRO; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Initialize the buffers. - */ - memset(results, 0, MAPPINGSIZE); - - /* Create a named file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapRW = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read write*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - lpObjectName); /*unnamed object*/ - - if(NULL == hFileMapRW) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - /* Create a map view to the READWRITE file mapping. - */ - lpMapViewRW = MapViewOfFile( - hFileMapRW, - FILE_MAP_ALL_ACCESS,/* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRW) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - - /* Create a map view to the READWRITE file mapping. - */ - lpMapViewRO = MapViewOfFile( - hFileMapRW, - FILE_MAP_READ, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRO) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write the test string to the Map view. - */ - memcpy(lpMapViewRW, testString, strlen(testString)); - - /* Read from the second Map view. - */ - memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); - - /* Verify the contents of the file mapping, - * by comparing what was written to what was read. - */ - if (memcmp(results, testString, strlen(testString))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - results, - testString); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Test successful. - */ - RetVal = PASS; - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRO); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRW); - RetVal = FAIL; - } - - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFileMapRW) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapRW); - RetVal = FAIL; - } - - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.cpp new file mode 100644 index 0000000000..7cef9ddcdc --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.cpp @@ -0,0 +1,164 @@ +// 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: createfilemapping.c (test 7) +** +** Purpose: Positive test the CreateFileMapping API. +** Test CreateFileMapping to a "swap" handle with +** access PAGE_READWRITE. +** +** +**============================================================*/ +#include + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + char testString[] = "this is a test string"; + char lpObjectName[] = "myMappingObject"; + char results[2048]; + int RetVal = PASS; + + HANDLE hFileMapRW; + LPVOID lpMapViewRW; + LPVOID lpMapViewRO; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Initialize the buffers. + */ + memset(results, 0, MAPPINGSIZE); + + /* Create a named file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapRW = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*unnamed object*/ + + if(NULL == hFileMapRW) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + /* Create a map view to the READWRITE file mapping. + */ + lpMapViewRW = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS,/* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + + /* Create a map view to the READWRITE file mapping. + */ + lpMapViewRO = MapViewOfFile( + hFileMapRW, + FILE_MAP_READ, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRO) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write the test string to the Map view. + */ + memcpy(lpMapViewRW, testString, strlen(testString)); + + /* Read from the second Map view. + */ + memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); + + /* Verify the contents of the file mapping, + * by comparing what was written to what was read. + */ + if (memcmp(results, testString, strlen(testString))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + results, + testString); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Test successful. + */ + RetVal = PASS; + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRO); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW); + RetVal = FAIL; + } + + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFileMapRW) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRW); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/CMakeLists.txt index ae3ee8ddf6..d2e2007545 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createfilemapping.c + createfilemapping.cpp ) add_executable(paltest_createfilemappinga_test8 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.c deleted file mode 100644 index 02b2fb5e61..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: createfilemapping.c (test 8) -** -** Purpose: Positive test the CreateFileMapping API. -** Test the un-verifiable parameter combinations. -** -** -**============================================================*/ -#include - -const int MAPPINGSIZE = 2048; -HANDLE SWAP_HANDLE = ((VOID *)(-1)); - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFileMap; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a READONLY, "swap", un-named file mapping. - * This test is unverifiable since there is no hook back to the file map - * because it is un-named. As well, since it resides in "swap", and is - * initialized to zero, there is nothing to read. - */ - hFileMap = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READONLY, /*read only*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*un-named object*/ - - if(NULL == hFileMap) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - - /* Create a COPYWRITE, "swap", un-named file mapping. - * This test is unverifiable, here is a quote from MSDN: - * - * Copy on write access. If you create the map with PAGE_WRITECOPY and - * the view with FILE_MAP_COPY, you will receive a view to file. If you - * write to it, the pages are automatically swappable and the modifications - * you make will not go to the original data file. - * - */ - hFileMap = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_WRITECOPY, /*read only*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMap) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.cpp new file mode 100644 index 0000000000..02b2fb5e61 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.cpp @@ -0,0 +1,79 @@ +// 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: createfilemapping.c (test 8) +** +** Purpose: Positive test the CreateFileMapping API. +** Test the un-verifiable parameter combinations. +** +** +**============================================================*/ +#include + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFileMap; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a READONLY, "swap", un-named file mapping. + * This test is unverifiable since there is no hook back to the file map + * because it is un-named. As well, since it resides in "swap", and is + * initialized to zero, there is nothing to read. + */ + hFileMap = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READONLY, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*un-named object*/ + + if(NULL == hFileMap) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + + /* Create a COPYWRITE, "swap", un-named file mapping. + * This test is unverifiable, here is a quote from MSDN: + * + * Copy on write access. If you create the map with PAGE_WRITECOPY and + * the view with FILE_MAP_COPY, you will receive a view to file. If you + * write to it, the pages are automatically swappable and the modifications + * you make will not go to the original data file. + * + */ + hFileMap = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_WRITECOPY, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMap) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/CMakeLists.txt index a377632bed..3017dc4aa4 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createfilemapping.c + createfilemapping.cpp ) add_executable(paltest_createfilemappinga_test9 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.c deleted file mode 100644 index 9224c22b4b..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.c +++ /dev/null @@ -1,150 +0,0 @@ -// 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: createfilemapping.c (test 9) -** -** Purpose: Negative test the CreateFileMapping API. -** -** -**============================================================*/ -#include - -const int MAPPINGSIZE = 2048; - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - char lpFileName[] = "test.tmp"; - - HANDLE hFileMapping; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile, as READONLY - */ - hFile = CreateFile( lpFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Attempt to create a unnamed file-mapping object to a READONLY file - * as READWRITE access. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and write*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL != hFileMapping) - { - Trace("ERROR: Able to create READWRITE mapping to a " - "READONLY file.\n" ); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - - /* Attempt to create a unnamed file-mapping object to a zero lenght - * file. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and write*/ - 0, /*high-order size*/ - 0, /*low-order size*/ - NULL); /*unnamed object*/ - - if( NULL != hFileMapping ) - { - Trace("ERROR: Able to create READWRITE mapping to a " - "READONLY file.\n" ); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - if(GetLastError() != ERROR_ACCESS_DENIED) - { - Trace("ERROR: Expected GetLastError() to return " - "ERROR_FILE_INVALID (%d), it returned %u.\n", - ERROR_FILE_INVALID, - GetLastError()); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - - /* Attempt to create a file mapping that is larger than - * the file. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READONLY, /*read only*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*unnamed object*/ - if(NULL != hFileMapping) - { - Trace("ERROR: Able to create file mapping of size %d to " - "file of size 0.\n", - MAPPINGSIZE); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - - if(GetLastError() != ERROR_NOT_ENOUGH_MEMORY ) - { - Trace("ERROR: Expected GetLastError() to return " - "ERROR_NOT_ENOUGH_MEMORY (%d), it returned %u.\n", - ERROR_NOT_ENOUGH_MEMORY, - GetLastError()); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - - if( 0 == CloseHandle(hFile) ) - { - Fail("Unexpected Error: Unable to close file handle\n"); - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.cpp new file mode 100644 index 0000000000..9224c22b4b --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.cpp @@ -0,0 +1,150 @@ +// 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: createfilemapping.c (test 9) +** +** Purpose: Negative test the CreateFileMapping API. +** +** +**============================================================*/ +#include + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char lpFileName[] = "test.tmp"; + + HANDLE hFileMapping; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile, as READONLY + */ + hFile = CreateFile( lpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Attempt to create a unnamed file-mapping object to a READONLY file + * as READWRITE access. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL != hFileMapping) + { + Trace("ERROR: Able to create READWRITE mapping to a " + "READONLY file.\n" ); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + /* Attempt to create a unnamed file-mapping object to a zero lenght + * file. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and write*/ + 0, /*high-order size*/ + 0, /*low-order size*/ + NULL); /*unnamed object*/ + + if( NULL != hFileMapping ) + { + Trace("ERROR: Able to create READWRITE mapping to a " + "READONLY file.\n" ); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + if(GetLastError() != ERROR_ACCESS_DENIED) + { + Trace("ERROR: Expected GetLastError() to return " + "ERROR_FILE_INVALID (%d), it returned %u.\n", + ERROR_FILE_INVALID, + GetLastError()); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + /* Attempt to create a file mapping that is larger than + * the file. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READONLY, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + if(NULL != hFileMapping) + { + Trace("ERROR: Able to create file mapping of size %d to " + "file of size 0.\n", + MAPPINGSIZE); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + if(GetLastError() != ERROR_NOT_ENOUGH_MEMORY ) + { + Trace("ERROR: Expected GetLastError() to return " + "ERROR_NOT_ENOUGH_MEMORY (%d), it returned %u.\n", + ERROR_NOT_ENOUGH_MEMORY, + GetLastError()); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + if( 0 == CloseHandle(hFile) ) + { + Fail("Unexpected Error: Unable to close file handle\n"); + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt index a4ad343ea0..2d24eca8c8 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMapping_neg.c + CreateFileMapping_neg.cpp ) add_executable(paltest_createfilemappingw_createfilemapping_neg1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c deleted file mode 100644 index 8cf79b3c57..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c +++ /dev/null @@ -1,93 +0,0 @@ -// 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: createfilemapping_neg.c -** -** Purpose: Negative test the CreateFileMapping API. -** Call CreateFileMapping to create a unnamed -** file-mapping object with PAGE_READONLY -** protection and try to map a zero length file -** in UNICODE -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE FileHandle; - HANDLE FileMappingHandle; - int err; - WCHAR *lpFileName = NULL; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //conver string to a unicode one - lpFileName = convert("temp.txt"); - - - //create a file and return the file handle - FileHandle = CreateFile(lpFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_ARCHIVE, - NULL); - - //free this memory - free(lpFileName); - - if(INVALID_HANDLE_VALUE == FileHandle) - { - Fail("Failed to call CreateFile to create a file\n"); - } - - //create a unnamed file-mapping object with file handle FileHandle - //and with PAGE_READONLY protection - //try to map a file which is zero length. - FileMappingHandle = CreateFileMapping( - FileHandle, //File Handle - NULL, //not inherited - PAGE_READONLY, //access protection - 0, //high-order of object size - 0, //low-orger of object size - NULL); //unnamed object - - - if(NULL != FileMappingHandle || ERROR_FILE_INVALID != GetLastError()) - {//no error occurred - Trace("\nFailed to call CreateFileMapping API for a negative test!\n"); - err = CloseHandle(FileHandle); - if(0 == err) - { - Fail("\nFailed to call CloseHandle API\n"); - } - err = CloseHandle(FileMappingHandle); - if(0 == err) - { - Fail("\nFailed to call CloseHandle API\n"); - } - Fail(""); - } - - //close the file handle - err = CloseHandle(FileHandle); - if(0 == err) - { - Fail("\nFailed to call CloseHandle API\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.cpp new file mode 100644 index 0000000000..8cf79b3c57 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.cpp @@ -0,0 +1,93 @@ +// 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: createfilemapping_neg.c +** +** Purpose: Negative test the CreateFileMapping API. +** Call CreateFileMapping to create a unnamed +** file-mapping object with PAGE_READONLY +** protection and try to map a zero length file +** in UNICODE +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE FileHandle; + HANDLE FileMappingHandle; + int err; + WCHAR *lpFileName = NULL; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //conver string to a unicode one + lpFileName = convert("temp.txt"); + + + //create a file and return the file handle + FileHandle = CreateFile(lpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_ARCHIVE, + NULL); + + //free this memory + free(lpFileName); + + if(INVALID_HANDLE_VALUE == FileHandle) + { + Fail("Failed to call CreateFile to create a file\n"); + } + + //create a unnamed file-mapping object with file handle FileHandle + //and with PAGE_READONLY protection + //try to map a file which is zero length. + FileMappingHandle = CreateFileMapping( + FileHandle, //File Handle + NULL, //not inherited + PAGE_READONLY, //access protection + 0, //high-order of object size + 0, //low-orger of object size + NULL); //unnamed object + + + if(NULL != FileMappingHandle || ERROR_FILE_INVALID != GetLastError()) + {//no error occurred + Trace("\nFailed to call CreateFileMapping API for a negative test!\n"); + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API\n"); + } + err = CloseHandle(FileMappingHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API\n"); + } + Fail(""); + } + + //close the file handle + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt index 0c569ec9b6..a2fbfa39af 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMappingW.c + CreateFileMappingW.cpp ) add_executable(paltest_createfilemappingw_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c deleted file mode 100644 index 4263a3ad29..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c +++ /dev/null @@ -1,174 +0,0 @@ -// 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: createfilemappingw.c (test 1) -** -** Purpose: Positive test the CreateFileMappingW API. -** Call CreateFileMappingW with access PAGE_READONLY. -** -** -**============================================================*/ -#define UNICODE -#include - -const int MAPPINGSIZE = 2048; - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - char buf[] = "this is a test string"; - char ch[2048]; - WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; - DWORD dwBytesWritten; - BOOL err; - int RetVal = PASS; - - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Initialize the buffers. - */ - memset(ch, 0, MAPPINGSIZE); - - /* Write to the File handle. - */ - err = WriteFile(hFile, - buf, - strlen(buf), - &dwBytesWritten, - NULL); - - if (err == FALSE) - { - Trace("ERROR: %u :unable to write to file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Flush to the hard-drive. - */ - FlushFileBuffers(hFile); - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READONLY, /*read and wite*/ - 0, /*high-order size*/ - 0, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_READ, /* access code */ - 0, /*high order offset*/ - 0, /*low order offset*/ - 0); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Copy the MapViewOfFile to buffer, so we can - * compare with value read from file directly. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpThree; - } - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapping) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapping); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFile) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFile); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.cpp new file mode 100644 index 0000000000..4263a3ad29 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.cpp @@ -0,0 +1,174 @@ +// 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: createfilemappingw.c (test 1) +** +** Purpose: Positive test the CreateFileMappingW API. +** Call CreateFileMappingW with access PAGE_READONLY. +** +** +**============================================================*/ +#define UNICODE +#include + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char buf[] = "this is a test string"; + char ch[2048]; + WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; + DWORD dwBytesWritten; + BOOL err; + int RetVal = PASS; + + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + + /* Write to the File handle. + */ + err = WriteFile(hFile, + buf, + strlen(buf), + &dwBytesWritten, + NULL); + + if (err == FALSE) + { + Trace("ERROR: %u :unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Flush to the hard-drive. + */ + FlushFileBuffers(hFile); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READONLY, /*read and wite*/ + 0, /*high-order size*/ + 0, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_READ, /* access code */ + 0, /*high order offset*/ + 0, /*low order offset*/ + 0); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapping) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapping); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFile) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFile); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt index 992645f48c..8552cc910f 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMappingW.c + CreateFileMappingW.cpp ) add_executable(paltest_createfilemappingw_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c deleted file mode 100644 index 11ff967dfd..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c +++ /dev/null @@ -1,124 +0,0 @@ -// 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: createfilemappingw.c -** -** Purpose: Positive test the CreateFileMapping API. -** Call CreateFileMapping to create a unnamed -** file-mapping object with PAGE_READONLY -** protection and SEC_IMAGE attribute in UNICODE -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE FileHandle; - HANDLE FileMappingHandle; - int err; - WCHAR *wpFileName = NULL; - char executableFileName[256]=""; - - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - -#if WIN32 - sprintf(executableFileName,"%s","executable.exe"); -#else - sprintf(executableFileName,"%s","executable"); -#endif - - //conver string to a unicode one - wpFileName = convert(executableFileName); - - - //create a file and return the file handle - FileHandle = CreateFile(wpFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_ARCHIVE, - NULL); - - //free this memory - free(wpFileName); - - if(INVALID_HANDLE_VALUE == FileHandle) - { - Fail("Failed to call CreateFile to create a file\n"); - } - - //create a unnamed file-mapping object with file handle FileHandle - //and with PAGE_READONLY protection - FileMappingHandle = CreateFileMapping( - FileHandle, //File Handle - NULL, //not inherited - PAGE_READONLY|SEC_IMAGE, //access protection and section attribute - 0, //high-order of object size - 0, //low-orger of object size - NULL); //unnamed object - - - if(NULL == FileMappingHandle) - { - Trace("\nFailed to call CreateFileMapping to create a mapping object!\n"); - err = CloseHandle(FileHandle); - if(0 == err) - { - Fail("\nFailed to call CloseHandle API\n"); - } - Fail(""); - } - if(GetLastError() == ERROR_ALREADY_EXISTS) - { - Trace("\nFile mapping object already exists!\n"); - err = CloseHandle(FileHandle); - if(0 == err) - { - Trace("\nFailed to call CloseHandle API to close a file handle\n"); - err = CloseHandle(FileMappingHandle); - if(0 == err) - { - Fail("\nFailed to call CloseHandle API to close a mapping object handle\n"); - } - Fail(""); - } - err = CloseHandle(FileMappingHandle); - if(0 == err) - { - Fail("\nFailed to call CloseHandle API to close a mapping object handle\n"); - } - Fail(""); - } - err = CloseHandle(FileMappingHandle); - if(0 == err) - { - Trace("\nFailed to call CloseHandle API to close a mapping object handle\n"); - err = CloseHandle(FileHandle); - if(0 == err) - { - Fail("\nFailed to call CloseHandle API to close a file handle\n"); - } - Fail(""); - } - err = CloseHandle(FileHandle); - if(0 == err) - { - Fail("\nFailed to call CloseHandle API to close a file handle\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.cpp new file mode 100644 index 0000000000..5cc6d77709 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.cpp @@ -0,0 +1,124 @@ +// 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: createfilemappingw.c +** +** Purpose: Positive test the CreateFileMapping API. +** Call CreateFileMapping to create a unnamed +** file-mapping object with PAGE_READONLY +** protection and SEC_IMAGE attribute in UNICODE +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE FileHandle; + HANDLE FileMappingHandle; + int err; + WCHAR *wpFileName = NULL; + char executableFileName[256]=""; + + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + +#if WIN32 + sprintf_s(executableFileName, _countof(executableFileName),"%s","executable.exe"); +#else + sprintf_s(executableFileName, _countof(executableFileName),"%s","executable"); +#endif + + //conver string to a unicode one + wpFileName = convert(executableFileName); + + + //create a file and return the file handle + FileHandle = CreateFile(wpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_ARCHIVE, + NULL); + + //free this memory + free(wpFileName); + + if(INVALID_HANDLE_VALUE == FileHandle) + { + Fail("Failed to call CreateFile to create a file\n"); + } + + //create a unnamed file-mapping object with file handle FileHandle + //and with PAGE_READONLY protection + FileMappingHandle = CreateFileMapping( + FileHandle, //File Handle + NULL, //not inherited + PAGE_READONLY|SEC_IMAGE, //access protection and section attribute + 0, //high-order of object size + 0, //low-orger of object size + NULL); //unnamed object + + + if(NULL == FileMappingHandle) + { + Trace("\nFailed to call CreateFileMapping to create a mapping object!\n"); + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API\n"); + } + Fail(""); + } + if(GetLastError() == ERROR_ALREADY_EXISTS) + { + Trace("\nFile mapping object already exists!\n"); + err = CloseHandle(FileHandle); + if(0 == err) + { + Trace("\nFailed to call CloseHandle API to close a file handle\n"); + err = CloseHandle(FileMappingHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API to close a mapping object handle\n"); + } + Fail(""); + } + err = CloseHandle(FileMappingHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API to close a mapping object handle\n"); + } + Fail(""); + } + err = CloseHandle(FileMappingHandle); + if(0 == err) + { + Trace("\nFailed to call CloseHandle API to close a mapping object handle\n"); + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API to close a file handle\n"); + } + Fail(""); + } + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API to close a file handle\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt index 87832ffd9b..97fd712350 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMappingW.c + CreateFileMappingW.cpp ) add_executable(paltest_createfilemappingw_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c deleted file mode 100644 index 1cbeff94a7..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c +++ /dev/null @@ -1,156 +0,0 @@ -// 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: createfilemappingw.c (test 3) -** -** Purpose: Positive test the CreateFileMappingW API. -** Call CreateFileMapping with access PAGE_READWRITE. -** -** -**============================================================*/ -#define UNICODE -#include - -const int MAPPINGSIZE = 2048; - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - char buf[] = "this is a test string"; - char ch[2048]; - WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - int RetVal = PASS; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Initialize the buffers. - */ - memset(ch, 0, MAPPINGSIZE); - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and wite*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /*high order offset*/ - 0, /*low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write to the Map view. - */ - memcpy(lpMapViewAddress, buf, strlen(buf)); - - /* Read from the Map view. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); - - /* Copy the MapViewOfFile to buffer, so we can - * compare with value read from file directly. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpThree; - } - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapping) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapping); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFile) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFile); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.cpp new file mode 100644 index 0000000000..1cbeff94a7 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.cpp @@ -0,0 +1,156 @@ +// 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: createfilemappingw.c (test 3) +** +** Purpose: Positive test the CreateFileMappingW API. +** Call CreateFileMapping with access PAGE_READWRITE. +** +** +**============================================================*/ +#define UNICODE +#include + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char buf[] = "this is a test string"; + char ch[2048]; + WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + int RetVal = PASS; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and wite*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /*high order offset*/ + 0, /*low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write to the Map view. + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map view. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapping) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapping); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFile) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFile); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt index f8a5c9041f..81f248e335 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMappingW.c + CreateFileMappingW.cpp ) add_executable(paltest_createfilemappingw_test4 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c deleted file mode 100644 index 265a317b2f..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c +++ /dev/null @@ -1,182 +0,0 @@ -// 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: createfilemappingw.c (test 4) -** -** Purpose: Positive test the CreateFileMappingW API. -** Call CreateFileMappingW with access PAGE_WRITECOPY. -** -** -**============================================================*/ -#define UNICODE -#include - -const int MAPPINGSIZE = 2048; - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - char buf[] = "this is a test string"; - char ch[2048]; - WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - int RetVal = PASS; - int err; - DWORD dwBytesWritten; - - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Write to the File handle. - */ - err = WriteFile(hFile, - buf, - strlen(buf), - &dwBytesWritten, - NULL); - - if (err == FALSE) - { - Trace("ERROR: %u :unable to write to file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Flush to the hard-drive. - */ - FlushFileBuffers(hFile); - - /* Initialize the buffers. - */ - memset(ch, 0, MAPPINGSIZE); - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_WRITECOPY protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_WRITECOPY, /*write copy*/ - 0, /*high-order size*/ - 0, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_COPY, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - 0); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write to the Map view.3 - */ - memcpy(lpMapViewAddress, buf, strlen(buf)); - - /* Read from the Map view. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); - - /* Copy the MapViewOfFile to buffer, so we can - * compare with value read from file directly. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpThree; - } - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapping) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapping); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFile) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFile); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.cpp new file mode 100644 index 0000000000..265a317b2f --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.cpp @@ -0,0 +1,182 @@ +// 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: createfilemappingw.c (test 4) +** +** Purpose: Positive test the CreateFileMappingW API. +** Call CreateFileMappingW with access PAGE_WRITECOPY. +** +** +**============================================================*/ +#define UNICODE +#include + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char buf[] = "this is a test string"; + char ch[2048]; + WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + int RetVal = PASS; + int err; + DWORD dwBytesWritten; + + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Write to the File handle. + */ + err = WriteFile(hFile, + buf, + strlen(buf), + &dwBytesWritten, + NULL); + + if (err == FALSE) + { + Trace("ERROR: %u :unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Flush to the hard-drive. + */ + FlushFileBuffers(hFile); + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_WRITECOPY protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_WRITECOPY, /*write copy*/ + 0, /*high-order size*/ + 0, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_COPY, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + 0); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write to the Map view.3 + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map view. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapping) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapping); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFile) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFile); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt index 8391fbd721..df25e29a4f 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMappingW.c + CreateFileMappingW.cpp ) add_executable(paltest_createfilemappingw_test5 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c deleted file mode 100644 index 21bf7c6d76..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c +++ /dev/null @@ -1,194 +0,0 @@ -// 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: createfilemappingw.c (test 5) -** -** Purpose: Positive test the CreateFileMappingW API. -** Test CreateFileMappingW to a "swap" handle with -** access PAGE_READONLY. -** -** -**============================================================*/ -#define UNICODE -#include - -const int MAPPINGSIZE = 2048; -HANDLE SWAP_HANDLE = ((VOID *)(-1)); - -int __cdecl main(int argc, char *argv[]) -{ - char testString[] = "this is a test string"; - WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; - int RetVal = FAIL; - char results[2048]; - - HANDLE hFileMapRO; - HANDLE hFileMapRW; - LPVOID lpMapViewRO; - LPVOID lpMapViewRW; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Initialize the buffers. - */ - memset(results, 0, MAPPINGSIZE); - - /* Create a named file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapRW = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read only*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - lpObjectName); /*named object*/ - - if(NULL == hFileMapRW) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewRW = MapViewOfFile( - hFileMapRW, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRW) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - - hFileMapRO = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READONLY, /*read and write*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - lpObjectName); /*named object*/ - - if(NULL == hFileMapRO) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewRO = MapViewOfFile( - hFileMapRO, - FILE_MAP_READ, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRO) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Write the test string to the Map view. - */ - memcpy(lpMapViewRW, testString, strlen(testString)); - - /* Read from the second Map view. - */ - memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); - - /* Verify the contents of the file mapping, - * by comparing what was written to what was read. - */ - if (memcmp(results, testString, strlen(testString))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - results, - testString); - RetVal = FAIL; - goto CleanUpFour; - } - - /* Test was successful. - */ - RetVal = PASS; - -CleanUpFour: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRO); - RetVal = FAIL; - } - -CleanUpThree: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapRO) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapRO); - RetVal = FAIL; - } - - -CleanUpTwo: - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRW); - RetVal = FAIL; - } - - -CleanUpOne: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(hFileMapRW) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapRW); - RetVal = FAIL; - } - - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.cpp new file mode 100644 index 0000000000..21bf7c6d76 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.cpp @@ -0,0 +1,194 @@ +// 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: createfilemappingw.c (test 5) +** +** Purpose: Positive test the CreateFileMappingW API. +** Test CreateFileMappingW to a "swap" handle with +** access PAGE_READONLY. +** +** +**============================================================*/ +#define UNICODE +#include + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + char testString[] = "this is a test string"; + WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; + int RetVal = FAIL; + char results[2048]; + + HANDLE hFileMapRO; + HANDLE hFileMapRW; + LPVOID lpMapViewRO; + LPVOID lpMapViewRW; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Initialize the buffers. + */ + memset(results, 0, MAPPINGSIZE); + + /* Create a named file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapRW = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*named object*/ + + if(NULL == hFileMapRW) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewRW = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + + hFileMapRO = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READONLY, /*read and write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*named object*/ + + if(NULL == hFileMapRO) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewRO = MapViewOfFile( + hFileMapRO, + FILE_MAP_READ, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRO) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Write the test string to the Map view. + */ + memcpy(lpMapViewRW, testString, strlen(testString)); + + /* Read from the second Map view. + */ + memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); + + /* Verify the contents of the file mapping, + * by comparing what was written to what was read. + */ + if (memcmp(results, testString, strlen(testString))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + results, + testString); + RetVal = FAIL; + goto CleanUpFour; + } + + /* Test was successful. + */ + RetVal = PASS; + +CleanUpFour: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRO); + RetVal = FAIL; + } + +CleanUpThree: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapRO) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRO); + RetVal = FAIL; + } + + +CleanUpTwo: + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW); + RetVal = FAIL; + } + + +CleanUpOne: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapRW) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRW); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt index abb62ad950..852c508020 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateFileMappingW.c + CreateFileMappingW.cpp ) add_executable(paltest_createfilemappingw_test6 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c deleted file mode 100644 index acf3ac6dff..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c +++ /dev/null @@ -1,165 +0,0 @@ -// 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: createfilemappingw.c (test 6) -** -** Purpose: Positive test the CreateFileMappingW API. -** Test CreateFileMappingW to a "swap" handle with -** access PAGE_READWRITE. -** -** -**============================================================*/ -#define UNICODE -#include - -const int MAPPINGSIZE = 2048; -HANDLE SWAP_HANDLE = ((VOID *)(-1)); - -int __cdecl main(int argc, char *argv[]) -{ - char testString[] = "this is a test string"; - WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; - char results[2048]; - int RetVal = PASS; - - HANDLE hFileMapRW; - LPVOID lpMapViewRW; - LPVOID lpMapViewRW2; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Initialize the buffers. - */ - memset(results, 0, MAPPINGSIZE); - - /* Create a named file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapRW = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read write*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - lpObjectName); /*named object*/ - - if(NULL == hFileMapRW) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - /* Create a map view of the READWRITE file mapping. - */ - lpMapViewRW = MapViewOfFile( - hFileMapRW, - FILE_MAP_ALL_ACCESS,/* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRW) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewRW2 = MapViewOfFile( - hFileMapRW, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRW2) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write the test string to the Map view. - */ - memcpy(lpMapViewRW, testString, strlen(testString)); - - /* Read from the second Map view. - */ - memcpy(results, (LPCSTR)lpMapViewRW2, MAPPINGSIZE); - - /* Verify the contents of the file mapping, - * by comparing what was written to what was read. - */ - if (memcmp(results, testString, strlen(testString))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - results, - testString); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Test successful. - */ - RetVal = PASS; - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRW2) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRW2); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRW); - RetVal = FAIL; - } - - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFileMapRW) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapRW); - RetVal = FAIL; - } - - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.cpp new file mode 100644 index 0000000000..acf3ac6dff --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.cpp @@ -0,0 +1,165 @@ +// 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: createfilemappingw.c (test 6) +** +** Purpose: Positive test the CreateFileMappingW API. +** Test CreateFileMappingW to a "swap" handle with +** access PAGE_READWRITE. +** +** +**============================================================*/ +#define UNICODE +#include + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + char testString[] = "this is a test string"; + WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; + char results[2048]; + int RetVal = PASS; + + HANDLE hFileMapRW; + LPVOID lpMapViewRW; + LPVOID lpMapViewRW2; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Initialize the buffers. + */ + memset(results, 0, MAPPINGSIZE); + + /* Create a named file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapRW = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*named object*/ + + if(NULL == hFileMapRW) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + /* Create a map view of the READWRITE file mapping. + */ + lpMapViewRW = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS,/* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewRW2 = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW2) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write the test string to the Map view. + */ + memcpy(lpMapViewRW, testString, strlen(testString)); + + /* Read from the second Map view. + */ + memcpy(results, (LPCSTR)lpMapViewRW2, MAPPINGSIZE); + + /* Verify the contents of the file mapping, + * by comparing what was written to what was read. + */ + if (memcmp(results, testString, strlen(testString))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + results, + testString); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Test successful. + */ + RetVal = PASS; + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW2) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW2); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW); + RetVal = FAIL; + } + + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFileMapRW) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRW); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt index b40cfeae96..68be449aec 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createfilemapping.c + createfilemapping.cpp ) add_executable(paltest_createfilemappingw_test7 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c deleted file mode 100644 index e49b9f688d..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c +++ /dev/null @@ -1,165 +0,0 @@ -// 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: createfilemappingw.c (test 7) -** -** Purpose: Positive test the CreateFileMappingW API. -** Test CreateFileMappingW to a "swap" handle with -** access PAGE_READWRITE. -** -** -**============================================================*/ -#define UNICODE -#include - -const int MAPPINGSIZE = 2048; -HANDLE SWAP_HANDLE = ((VOID *)(-1)); - -int __cdecl main(int argc, char *argv[]) -{ - char testString[] = "this is a test string"; - WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; - char results[2048]; - int RetVal = PASS; - - HANDLE hFileMapRW; - LPVOID lpMapViewRW; - LPVOID lpMapViewRO; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Initialize the buffers. - */ - memset(results, 0, MAPPINGSIZE); - - /* Create a named file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapRW = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read write*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - lpObjectName); /*unnamed object*/ - - if(NULL == hFileMapRW) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - /* Create a map view to the READWRITE file mapping. - */ - lpMapViewRW = MapViewOfFile( - hFileMapRW, - FILE_MAP_ALL_ACCESS,/* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRW) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - - /* Create a map view to the READWRITE file mapping. - */ - lpMapViewRO = MapViewOfFile( - hFileMapRW, - FILE_MAP_READ, /* access code */ - 0, /* high order offset*/ - 0, /* low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewRO) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write the test string to the Map view. - */ - memcpy(lpMapViewRW, testString, strlen(testString)); - - /* Read from the second Map view. - */ - memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); - - /* Verify the contents of the file mapping, - * by comparing what was written to what was read. - */ - if (memcmp(results, testString, strlen(testString))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - results, - testString); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Test successful. - */ - RetVal = PASS; - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRO); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewRW); - RetVal = FAIL; - } - - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(hFileMapRW) == FALSE ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - hFileMapRW); - RetVal = FAIL; - } - - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.cpp new file mode 100644 index 0000000000..e49b9f688d --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.cpp @@ -0,0 +1,165 @@ +// 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: createfilemappingw.c (test 7) +** +** Purpose: Positive test the CreateFileMappingW API. +** Test CreateFileMappingW to a "swap" handle with +** access PAGE_READWRITE. +** +** +**============================================================*/ +#define UNICODE +#include + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + char testString[] = "this is a test string"; + WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; + char results[2048]; + int RetVal = PASS; + + HANDLE hFileMapRW; + LPVOID lpMapViewRW; + LPVOID lpMapViewRO; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Initialize the buffers. + */ + memset(results, 0, MAPPINGSIZE); + + /* Create a named file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapRW = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*unnamed object*/ + + if(NULL == hFileMapRW) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + /* Create a map view to the READWRITE file mapping. + */ + lpMapViewRW = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS,/* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + + /* Create a map view to the READWRITE file mapping. + */ + lpMapViewRO = MapViewOfFile( + hFileMapRW, + FILE_MAP_READ, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRO) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write the test string to the Map view. + */ + memcpy(lpMapViewRW, testString, strlen(testString)); + + /* Read from the second Map view. + */ + memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); + + /* Verify the contents of the file mapping, + * by comparing what was written to what was read. + */ + if (memcmp(results, testString, strlen(testString))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + results, + testString); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Test successful. + */ + RetVal = PASS; + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRO); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW); + RetVal = FAIL; + } + + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFileMapRW) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRW); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt index 96658c163a..406331072c 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createfilemapping.c + createfilemapping.cpp ) add_executable(paltest_createfilemappingw_test8 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c deleted file mode 100644 index 1ff137d8d3..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c +++ /dev/null @@ -1,82 +0,0 @@ -// 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: createfilemappingw.c (test 8) -** -** Purpose: Positive test the CreateFileMappingW API. -** Test the un-verifiable parameter combinations. -** -** -**============================================================*/ -#define UNICODE -#include - -const int MAPPINGSIZE = 2048; -HANDLE SWAP_HANDLE = ((VOID *)(-1)); - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; - - HANDLE hFileMap; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a READONLY, "swap", un-named file mapping. - * This test is unverifiable since there is no hook back to the file map - * because it is un-named. As well, since it resides in "swap", and is - * initialized to zero, there is nothing to read. - */ - hFileMap = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_READONLY, /*read only*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*un-named object*/ - - if(NULL == hFileMap) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - - /* Create a COPYWRITE, "swap", un-named file mapping. - * This test is unverifiable, here is a quote from MSDN: - * - * Copy on write access. If you create the map with PAGE_WRITECOPY and - * the view with FILE_MAP_COPY, you will receive a view to file. If you - * write to it, the pages are automatically swappable and the modifications - * you make will not go to the original data file. - * - */ - hFileMap = CreateFileMapping( - SWAP_HANDLE, - NULL, /*not inherited*/ - PAGE_WRITECOPY, /*write copy*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMap) - { - Fail("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - } - - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.cpp new file mode 100644 index 0000000000..1ff137d8d3 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.cpp @@ -0,0 +1,82 @@ +// 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: createfilemappingw.c (test 8) +** +** Purpose: Positive test the CreateFileMappingW API. +** Test the un-verifiable parameter combinations. +** +** +**============================================================*/ +#define UNICODE +#include + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; + + HANDLE hFileMap; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a READONLY, "swap", un-named file mapping. + * This test is unverifiable since there is no hook back to the file map + * because it is un-named. As well, since it resides in "swap", and is + * initialized to zero, there is nothing to read. + */ + hFileMap = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READONLY, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*un-named object*/ + + if(NULL == hFileMap) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + + /* Create a COPYWRITE, "swap", un-named file mapping. + * This test is unverifiable, here is a quote from MSDN: + * + * Copy on write access. If you create the map with PAGE_WRITECOPY and + * the view with FILE_MAP_COPY, you will receive a view to file. If you + * write to it, the pages are automatically swappable and the modifications + * you make will not go to the original data file. + * + */ + hFileMap = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_WRITECOPY, /*write copy*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMap) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt index 5a55e27b33..6d15fea1e6 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createfilemapping.c + createfilemapping.cpp ) add_executable(paltest_createfilemappingw_test9 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c deleted file mode 100644 index 16ae74c126..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c +++ /dev/null @@ -1,151 +0,0 @@ -// 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: createfilemapping.c (test 9) -** -** Purpose: Negative test the CreateFileMappingW API. -** -** -**============================================================*/ -#define UNICODE -#include - -const int MAPPINGSIZE = 2048; - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; - - HANDLE hFileMapping; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile, as READONLY - */ - hFile = CreateFile( lpFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Attempt to create a unnamed file-mapping object to a READONLY file - * as READWRITE access. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and write*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*unnamed object*/ - - if(NULL != hFileMapping) - { - Trace("ERROR: Able to create READWRITE mapping to a " - "READONLY file.\n" ); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - - /* Attempt to create a unnamed file-mapping object to a zero lenght - * file. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and write*/ - 0, /*high-order size*/ - 0, /*low-order size*/ - NULL); /*unnamed object*/ - - if( NULL != hFileMapping ) - { - Trace("ERROR: Able to create READWRITE mapping to a " - "READONLY file.\n" ); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - if(GetLastError() != ERROR_ACCESS_DENIED) - { - Trace("ERROR: Expected GetLastError() to return " - "ERROR_FILE_INVALID (%d), it returned %u.\n", - ERROR_FILE_INVALID, - GetLastError()); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - - /* Attempt to create a file mapping that is larger than - * the file. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READONLY, /*read only*/ - 0, /*high-order size*/ - MAPPINGSIZE, /*low-order size*/ - NULL); /*unnamed object*/ - if(NULL != hFileMapping) - { - Trace("ERROR: Able to create file mapping of size %d to " - "file of size 0.\n", - MAPPINGSIZE); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - - if(GetLastError() != ERROR_NOT_ENOUGH_MEMORY ) - { - Trace("ERROR: Expected GetLastError() to return " - "ERROR_NOT_ENOUGH_MEMORY (%d), it returned %u.\n", - ERROR_NOT_ENOUGH_MEMORY, - GetLastError()); - if( 0 == CloseHandle(hFile) ) - { - Trace("Unexpected Error: Unable to close file handle\n"); - } - Fail(""); - } - - if( 0 == CloseHandle(hFile) ) - { - Fail("Unexpected Error: Unable to close file handle\n"); - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.cpp b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.cpp new file mode 100644 index 0000000000..16ae74c126 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.cpp @@ -0,0 +1,151 @@ +// 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: createfilemapping.c (test 9) +** +** Purpose: Negative test the CreateFileMappingW API. +** +** +**============================================================*/ +#define UNICODE +#include + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; + + HANDLE hFileMapping; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile, as READONLY + */ + hFile = CreateFile( lpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Attempt to create a unnamed file-mapping object to a READONLY file + * as READWRITE access. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL != hFileMapping) + { + Trace("ERROR: Able to create READWRITE mapping to a " + "READONLY file.\n" ); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + /* Attempt to create a unnamed file-mapping object to a zero lenght + * file. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and write*/ + 0, /*high-order size*/ + 0, /*low-order size*/ + NULL); /*unnamed object*/ + + if( NULL != hFileMapping ) + { + Trace("ERROR: Able to create READWRITE mapping to a " + "READONLY file.\n" ); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + if(GetLastError() != ERROR_ACCESS_DENIED) + { + Trace("ERROR: Expected GetLastError() to return " + "ERROR_FILE_INVALID (%d), it returned %u.\n", + ERROR_FILE_INVALID, + GetLastError()); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + /* Attempt to create a file mapping that is larger than + * the file. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READONLY, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + if(NULL != hFileMapping) + { + Trace("ERROR: Able to create file mapping of size %d to " + "file of size 0.\n", + MAPPINGSIZE); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + if(GetLastError() != ERROR_NOT_ENOUGH_MEMORY ) + { + Trace("ERROR: Expected GetLastError() to return " + "ERROR_NOT_ENOUGH_MEMORY (%d), it returned %u.\n", + ERROR_NOT_ENOUGH_MEMORY, + GetLastError()); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + if( 0 == CloseHandle(hFile) ) + { + Fail("Unexpected Error: Unable to close file handle\n"); + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/CMakeLists.txt index 3807621e3f..beaee835c8 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - dlltest.c - FreeLibrary.c + dlltest.cpp + FreeLibrary.cpp ) add_executable(paltest_freelibrary_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.c deleted file mode 100644 index a06a231586..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.c +++ /dev/null @@ -1,128 +0,0 @@ -// 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: -** -** Purpose: Positive test the FreeLibrary API. -** -** -**============================================================*/ -#include - -/*char LibraryName[] = "dlltest";*/ -/* SHLEXT is defined only for Unix variants */ - -#if defined(SHLEXT) -#define LibraryName "dlltest"SHLEXT -#else -#define LibraryName "dlltest" -#endif - - - - -BOOL PALAPI TestDll(HMODULE, int); - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hLib; - - /* Initialize the PAL. */ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /*Load library (DLL). */ - hLib = LoadLibrary(LibraryName); - - if(hLib == NULL) - { - Fail("ERROR:%u:Unable to load library %s\n", - GetLastError(), - LibraryName); - } - - /* Test access to DLL. */ - if(!TestDll(hLib, PASS)) - { - Trace("ERROR: TestDll function returned FALSE " - "expected TRUE\n."); - FreeLibrary(hLib); - Fail(""); - } - - /* Call the FreeLibrary API. */ - if (!FreeLibrary(hLib)) - { - Fail("ERROR:%u: Unable to free library \"%s\"\n", - GetLastError(), - LibraryName); - } - - /* Test access to the free'd DLL. */ - if(!TestDll(hLib, FAIL)) - { - Fail("ERROR: TestDll function returned FALSE " - "expected TRUE\n."); - } - - PAL_Terminate(); - return PASS; - -} - - -BOOL PALAPI TestDll(HMODULE hLib, int testResult) -{ - int RetVal; -#if WIN32 - char FunctName[] = "_DllTest@0"; -#else - char FunctName[] = "DllTest"; -#endif - FARPROC DllAddr; - - /* Attempt to grab the proc address of the dll function. - * This one should succeed.*/ - if(testResult == PASS) - { - DllAddr = GetProcAddress(hLib, FunctName); - if(DllAddr == NULL) - { - Trace("ERROR: Unable to load function \"%s\" library \"%s\"\n", - FunctName, - LibraryName); - return (FALSE); - } - /* Run the function in the DLL, - * to ensure that the DLL was loaded properly.*/ - RetVal = DllAddr(); - if (RetVal != 1) - { - Trace("ERROR: Unable to receive correct information from DLL! " - ":expected \"1\", returned \"%d\"\n", - RetVal); - return (FALSE); - } - } - - /* Attempt to grab the proc address of the dll function. - * This one should fail.*/ - if(testResult == FAIL) - { - DllAddr = GetProcAddress(hLib, FunctName); - if(DllAddr != NULL) - { - Trace("ERROR: Able to load function \"%s\" from free'd" - " library \"%s\"\n", - FunctName, - LibraryName); - return (FALSE); - } - } - return (TRUE); -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.cpp b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.cpp new file mode 100644 index 0000000000..a06a231586 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.cpp @@ -0,0 +1,128 @@ +// 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: +** +** Purpose: Positive test the FreeLibrary API. +** +** +**============================================================*/ +#include + +/*char LibraryName[] = "dlltest";*/ +/* SHLEXT is defined only for Unix variants */ + +#if defined(SHLEXT) +#define LibraryName "dlltest"SHLEXT +#else +#define LibraryName "dlltest" +#endif + + + + +BOOL PALAPI TestDll(HMODULE, int); + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hLib; + + /* Initialize the PAL. */ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Load library (DLL). */ + hLib = LoadLibrary(LibraryName); + + if(hLib == NULL) + { + Fail("ERROR:%u:Unable to load library %s\n", + GetLastError(), + LibraryName); + } + + /* Test access to DLL. */ + if(!TestDll(hLib, PASS)) + { + Trace("ERROR: TestDll function returned FALSE " + "expected TRUE\n."); + FreeLibrary(hLib); + Fail(""); + } + + /* Call the FreeLibrary API. */ + if (!FreeLibrary(hLib)) + { + Fail("ERROR:%u: Unable to free library \"%s\"\n", + GetLastError(), + LibraryName); + } + + /* Test access to the free'd DLL. */ + if(!TestDll(hLib, FAIL)) + { + Fail("ERROR: TestDll function returned FALSE " + "expected TRUE\n."); + } + + PAL_Terminate(); + return PASS; + +} + + +BOOL PALAPI TestDll(HMODULE hLib, int testResult) +{ + int RetVal; +#if WIN32 + char FunctName[] = "_DllTest@0"; +#else + char FunctName[] = "DllTest"; +#endif + FARPROC DllAddr; + + /* Attempt to grab the proc address of the dll function. + * This one should succeed.*/ + if(testResult == PASS) + { + DllAddr = GetProcAddress(hLib, FunctName); + if(DllAddr == NULL) + { + Trace("ERROR: Unable to load function \"%s\" library \"%s\"\n", + FunctName, + LibraryName); + return (FALSE); + } + /* Run the function in the DLL, + * to ensure that the DLL was loaded properly.*/ + RetVal = DllAddr(); + if (RetVal != 1) + { + Trace("ERROR: Unable to receive correct information from DLL! " + ":expected \"1\", returned \"%d\"\n", + RetVal); + return (FALSE); + } + } + + /* Attempt to grab the proc address of the dll function. + * This one should fail.*/ + if(testResult == FAIL) + { + DllAddr = GetProcAddress(hLib, FunctName); + if(DllAddr != NULL) + { + Trace("ERROR: Able to load function \"%s\" from free'd" + " library \"%s\"\n", + FunctName, + LibraryName); + return (FALSE); + } + } + return (TRUE); +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.c deleted file mode 100644 index 44f1b5a903..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.c +++ /dev/null @@ -1,32 +0,0 @@ -// 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: dlltest.c (FreeLibrary test dll) -** -** Purpose: This file will be used to create the shared library -** that will be used in the FreeLibraryAndExitThread -** test. A very simple shared library, with one function -** "DllTest" which merely returns 1. -** -** -**===================================================================*/ -#include "pal.h" - -#if WIN32 -__declspec(dllexport) -#endif - -int __stdcall DllTest() -{ - return 1; -} - -#ifdef WIN32 -int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void * lpvReserved) -{ - return 1; -} -#endif diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.cpp b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.cpp new file mode 100644 index 0000000000..44f1b5a903 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.cpp @@ -0,0 +1,32 @@ +// 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: dlltest.c (FreeLibrary test dll) +** +** Purpose: This file will be used to create the shared library +** that will be used in the FreeLibraryAndExitThread +** test. A very simple shared library, with one function +** "DllTest" which merely returns 1. +** +** +**===================================================================*/ +#include "pal.h" + +#if WIN32 +__declspec(dllexport) +#endif + +int __stdcall DllTest() +{ + return 1; +} + +#ifdef WIN32 +int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void * lpvReserved) +{ + return 1; +} +#endif diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/CMakeLists.txt index 00b1eca8e3..0a5e700ba4 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_freelibrary_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.c deleted file mode 100644 index b43f74d6bc..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test2.c (FreeLibrary) -** -** Purpose: Tests the PAL implementation of the FreeLibrary function. -** This is a negative test that will pass an invalid and a -** null handle to FreeLibrary. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char* argv[]) -{ - HANDLE hLib; - - /* Initialize the PAL. - */ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /* Attempt to pass FreeLibrary an invalid handle. - */ - hLib = INVALID_HANDLE_VALUE; - if (FreeLibrary(hLib)) - { - Fail("ERROR: Able to free library handle = \"0x%lx\".\n", - hLib); - } - - /* Attempt to pass FreeLibrary a NULL handle. - */ - hLib = NULL; - if (FreeLibrary(hLib)) - { - Fail("ERROR: Able to free library handle = \"NULL\".\n"); - } - - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; - -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.cpp b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.cpp new file mode 100644 index 0000000000..b43f74d6bc --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.cpp @@ -0,0 +1,52 @@ +// 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: test2.c (FreeLibrary) +** +** Purpose: Tests the PAL implementation of the FreeLibrary function. +** This is a negative test that will pass an invalid and a +** null handle to FreeLibrary. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char* argv[]) +{ + HANDLE hLib; + + /* Initialize the PAL. + */ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /* Attempt to pass FreeLibrary an invalid handle. + */ + hLib = INVALID_HANDLE_VALUE; + if (FreeLibrary(hLib)) + { + Fail("ERROR: Able to free library handle = \"0x%lx\".\n", + hLib); + } + + /* Attempt to pass FreeLibrary a NULL handle. + */ + hLib = NULL; + if (FreeLibrary(hLib)) + { + Fail("ERROR: Able to free library handle = \"NULL\".\n"); + } + + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; + +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/CMakeLists.txt index cec083583a..03bfe06eb3 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - dlltest.c - test1.c + dlltest.cpp + test1.cpp ) add_executable(paltest_freelibraryandexitthread_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.c deleted file mode 100644 index 954c624d19..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.c +++ /dev/null @@ -1,32 +0,0 @@ -// 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: dlltest.c (FreeLibraryAndExitThread test dll) -** -** Purpose: This file will be used to create the shared library -** that will be used in the FreeLibraryAndExitThread -** test. A very simple shared library, with one function -** "DllTest" which merely returns 1. -** -** -**===================================================================*/ -#include "pal.h" - -#if WIN32 -__declspec(dllexport) -#endif - -int _stdcall DllTest() -{ - return 1; -} - -#if WIN32 -int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void * lpvReserved) -{ - return 1; -} -#endif diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.cpp b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.cpp new file mode 100644 index 0000000000..954c624d19 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.cpp @@ -0,0 +1,32 @@ +// 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: dlltest.c (FreeLibraryAndExitThread test dll) +** +** Purpose: This file will be used to create the shared library +** that will be used in the FreeLibraryAndExitThread +** test. A very simple shared library, with one function +** "DllTest" which merely returns 1. +** +** +**===================================================================*/ +#include "pal.h" + +#if WIN32 +__declspec(dllexport) +#endif + +int _stdcall DllTest() +{ + return 1; +} + +#if WIN32 +int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void * lpvReserved) +{ + return 1; +} +#endif diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.c deleted file mode 100644 index 6aacfc83b4..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.c +++ /dev/null @@ -1,183 +0,0 @@ -// 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: test1.c (FreeLibraryAndExitThread) -** -** Purpose: Tests the PAL implementation of the FreeLibraryAndExitThread -** function. FreeLibraryAndExitThread when run will exit the -** process that it is called within, therefore we create a -** thread to run the API. Then test for the existance of the -** thread and access to the library. -** -** -**===================================================================*/ - -#include - -/*Define platform specific information*/ - -/* SHLEXT is defined only for Unix variants */ -#if defined(SHLEXT) -#define LibraryName "dlltest"SHLEXT -#else -#define LibraryName "dlltest" -#endif - -#define TIMEOUT 60000 - -BOOL PALAPI StartThreadTest(); -DWORD PALAPI CreateTestThread(LPVOID); -BOOL PALAPI TestDll(HMODULE, int); - -int __cdecl main(int argc, char* argv[]) -{ - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - if (!StartThreadTest()) - { - Fail("ERROR: FreeLibraryAndExitThread test failed.\n"); - } - - /*Terminate the PAL*/ - PAL_Terminate(); - return PASS; - -} - - -BOOL PALAPI StartThreadTest() -{ - HMODULE hLib; - HANDLE hThread; - DWORD dwThreadId; - LPTHREAD_START_ROUTINE lpStartAddress = &CreateTestThread; - LPVOID lpParameter = lpStartAddress; - DWORD rc = -1; - /*Load library (DLL).*/ - hLib = LoadLibrary(LibraryName); - if(hLib == NULL) - { - Trace("ERROR: Unable to load library %s\n", LibraryName); - - return (FALSE); - } - - /*Start the test thread*/ - hThread = CreateThread(NULL, - (DWORD)0, - lpParameter, - hLib, - (DWORD)NULL, - &dwThreadId); - if(hThread == NULL) - { - Trace("ERROR:%u: Unable to create thread.\n", - GetLastError()); - - FreeLibrary(hLib); - return (FALSE); - } - - /*Wait on thread.*/ - rc = WaitForSingleObject(hThread, TIMEOUT); - if( rc != WAIT_OBJECT_0 ) - { - Trace("ERROR:%u: hThread=0x%4.4lx not exited by " - "FreeLibraryAndExitThread, RC[%d]\n", - GetLastError(), - hThread, rc); - -// There is a possibility that the other thread might -// still be using the library VSW:337893 -// FreeLibrary(hLib); - CloseHandle(hThread); - return (FALSE); - } - - /*Test access to DLL.*/ - if(!TestDll(hLib, 0)) - { - Trace("ERROR: TestDll function returned FALSE " - "expected TRUE\n."); - - CloseHandle(hThread); - return (FALSE); - } - - FreeLibrary(hLib); - /*Clean-up thread.*/ - CloseHandle(hThread); - - return (TRUE); -} - -BOOL PALAPI TestDll(HMODULE hLib, int testResult) -{ - int RetVal; - char FunctName[] = "DllTest"; - FARPROC DllAddr; - - /* Attempt to grab the proc address of the dll function. - * This one should succeed.*/ - if(testResult == 1) - { - DllAddr = GetProcAddress(hLib, FunctName); - if(DllAddr == NULL) - { - Trace("ERROR: Unable to load function \"%s\" library \"%s\"\n", - FunctName, - LibraryName); - return (FALSE); - } - /* Run the function in the DLL, - * to ensure that the DLL was loaded properly.*/ - RetVal = DllAddr(); - if (RetVal != 1) - { - Trace("ERROR: Unable to receive correct information from DLL! " - ":expected \"1\", returned \"%d\"\n", - RetVal); - return (FALSE); - } - } - - /* Attempt to grab the proc address of the dll function. - * This one should fail.*/ - if(testResult == 0) - { - DllAddr = GetProcAddress(hLib, FunctName); - if(DllAddr != NULL) - { - Trace("ERROR: Able to load function \"%s\" from free'd" - " library \"%s\"\n", - FunctName, - LibraryName); - return (FALSE); - } - } - return (TRUE); -} - -DWORD PALAPI CreateTestThread(LPVOID lpParam) -{ - /* Test access to DLL.*/ - TestDll(lpParam, 1); - - /*Free library and exit thread.*/ - FreeLibraryAndExitThread(lpParam, (DWORD)0); - - /* NOT REACHED */ - - /*Infinite loop, we should not get here.*/ - while(1); - - return (DWORD)0; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.cpp b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.cpp new file mode 100644 index 0000000000..58f6643722 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.cpp @@ -0,0 +1,183 @@ +// 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: test1.c (FreeLibraryAndExitThread) +** +** Purpose: Tests the PAL implementation of the FreeLibraryAndExitThread +** function. FreeLibraryAndExitThread when run will exit the +** process that it is called within, therefore we create a +** thread to run the API. Then test for the existance of the +** thread and access to the library. +** +** +**===================================================================*/ + +#include + +/*Define platform specific information*/ + +/* SHLEXT is defined only for Unix variants */ +#if defined(SHLEXT) +#define LibraryName "dlltest"SHLEXT +#else +#define LibraryName "dlltest" +#endif + +#define TIMEOUT 60000 + +BOOL PALAPI StartThreadTest(); +DWORD PALAPI CreateTestThread(LPVOID); +BOOL PALAPI TestDll(HMODULE, int); + +int __cdecl main(int argc, char* argv[]) +{ + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + if (!StartThreadTest()) + { + Fail("ERROR: FreeLibraryAndExitThread test failed.\n"); + } + + /*Terminate the PAL*/ + PAL_Terminate(); + return PASS; + +} + + +BOOL PALAPI StartThreadTest() +{ + HMODULE hLib; + HANDLE hThread; + DWORD dwThreadId; + LPTHREAD_START_ROUTINE lpStartAddress = &CreateTestThread; + LPVOID lpParameter = (LPVOID)lpStartAddress; + DWORD rc = -1; + /*Load library (DLL).*/ + hLib = LoadLibrary(LibraryName); + if(hLib == NULL) + { + Trace("ERROR: Unable to load library %s\n", LibraryName); + + return (FALSE); + } + + /*Start the test thread*/ + hThread = CreateThread(NULL, + (DWORD)0, + lpStartAddress, + hLib, + (DWORD)NULL, + &dwThreadId); + if(hThread == NULL) + { + Trace("ERROR:%u: Unable to create thread.\n", + GetLastError()); + + FreeLibrary(hLib); + return (FALSE); + } + + /*Wait on thread.*/ + rc = WaitForSingleObject(hThread, TIMEOUT); + if( rc != WAIT_OBJECT_0 ) + { + Trace("ERROR:%u: hThread=0x%4.4lx not exited by " + "FreeLibraryAndExitThread, RC[%d]\n", + GetLastError(), + hThread, rc); + +// There is a possibility that the other thread might +// still be using the library VSW:337893 +// FreeLibrary(hLib); + CloseHandle(hThread); + return (FALSE); + } + + /*Test access to DLL.*/ + if(!TestDll(hLib, 0)) + { + Trace("ERROR: TestDll function returned FALSE " + "expected TRUE\n."); + + CloseHandle(hThread); + return (FALSE); + } + + FreeLibrary(hLib); + /*Clean-up thread.*/ + CloseHandle(hThread); + + return (TRUE); +} + +BOOL PALAPI TestDll(HMODULE hLib, int testResult) +{ + int RetVal; + char FunctName[] = "DllTest"; + FARPROC DllAddr; + + /* Attempt to grab the proc address of the dll function. + * This one should succeed.*/ + if(testResult == 1) + { + DllAddr = GetProcAddress(hLib, FunctName); + if(DllAddr == NULL) + { + Trace("ERROR: Unable to load function \"%s\" library \"%s\"\n", + FunctName, + LibraryName); + return (FALSE); + } + /* Run the function in the DLL, + * to ensure that the DLL was loaded properly.*/ + RetVal = DllAddr(); + if (RetVal != 1) + { + Trace("ERROR: Unable to receive correct information from DLL! " + ":expected \"1\", returned \"%d\"\n", + RetVal); + return (FALSE); + } + } + + /* Attempt to grab the proc address of the dll function. + * This one should fail.*/ + if(testResult == 0) + { + DllAddr = GetProcAddress(hLib, FunctName); + if(DllAddr != NULL) + { + Trace("ERROR: Able to load function \"%s\" from free'd" + " library \"%s\"\n", + FunctName, + LibraryName); + return (FALSE); + } + } + return (TRUE); +} + +DWORD PALAPI CreateTestThread(LPVOID lpParam) +{ + /* Test access to DLL.*/ + TestDll(lpParam, 1); + + /*Free library and exit thread.*/ + FreeLibraryAndExitThread(lpParam, (DWORD)0); + + /* NOT REACHED */ + + /*Infinite loop, we should not get here.*/ + while(1); + + return (DWORD)0; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt index a1128c62b8..9b7a610f0c 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetModuleFileNameA.c + GetModuleFileNameA.cpp ) add_executable(paltest_getmodulefilenamea_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c deleted file mode 100644 index d05f0ac6a9..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c +++ /dev/null @@ -1,92 +0,0 @@ -// 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: getmodulefilenamea.c -** -** Purpose: Positive test the GetModuleFileName API. -** Call GetModuleFileName to retrieve the specified -** module full path and file name -** -** -**============================================================*/ - -#include - -#define MODULENAMEBUFFERSIZE 1024 - -/* SHLEXT is defined only for Unix variants */ - -#if defined(SHLEXT) -#define ModuleName "librotor_pal"SHLEXT -#define Delimiter "/" -#else -#define ModuleName "rotor_pal.dll" -#define Delimiter "\\" -#endif - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - int err; - DWORD ModuleNameLength; - char ModuleFileNameBuf[MODULENAMEBUFFERSIZE]=""; - char* TempBuf = NULL; - char* LastBuf = NULL; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - - //load a module - ModuleHandle = LoadLibrary(ModuleName); - 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); - - //strip out all full path - TempBuf = strtok(ModuleFileNameBuf,Delimiter); - LastBuf = TempBuf; - while(NULL != TempBuf) - { - LastBuf = TempBuf; - TempBuf = strtok(NULL,Delimiter); - } - - - 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; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.cpp b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.cpp new file mode 100644 index 0000000000..d05f0ac6a9 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.cpp @@ -0,0 +1,92 @@ +// 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: getmodulefilenamea.c +** +** Purpose: Positive test the GetModuleFileName API. +** Call GetModuleFileName to retrieve the specified +** module full path and file name +** +** +**============================================================*/ + +#include + +#define MODULENAMEBUFFERSIZE 1024 + +/* SHLEXT is defined only for Unix variants */ + +#if defined(SHLEXT) +#define ModuleName "librotor_pal"SHLEXT +#define Delimiter "/" +#else +#define ModuleName "rotor_pal.dll" +#define Delimiter "\\" +#endif + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + int err; + DWORD ModuleNameLength; + char ModuleFileNameBuf[MODULENAMEBUFFERSIZE]=""; + char* TempBuf = NULL; + char* LastBuf = NULL; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + + //load a module + ModuleHandle = LoadLibrary(ModuleName); + 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); + + //strip out all full path + TempBuf = strtok(ModuleFileNameBuf,Delimiter); + LastBuf = TempBuf; + while(NULL != TempBuf) + { + LastBuf = TempBuf; + TempBuf = strtok(NULL,Delimiter); + } + + + 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; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt index c35e9acc5e..1909be4b42 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetModuleFileNameA.c + GetModuleFileNameA.cpp ) add_executable(paltest_getmodulefilenamea_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c deleted file mode 100644 index e8aed6d30e..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: getmodulefilenamea.c -** -** Purpose: Positive test the GetModuleFileNameA API. -** Call GetModuleFileName to retrieve current process -** full path and file name by passing a NULL module handle -** -** -**============================================================*/ -#include - - -#define MODULENAMEBUFFERSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - - DWORD ModuleNameLength; - char ModuleFileNameBuf[MODULENAMEBUFFERSIZE]=""; - int err; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - - //retrieve the current process full path and file name - //by passing a NULL module handle - ModuleNameLength = GetModuleFileName( - NULL, //a NULL handle - ModuleFileNameBuf,//buffer for module file name - MODULENAMEBUFFERSIZE); - - if(0 == ModuleNameLength) - { - Fail("\nFailed to all GetModuleFileName API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.cpp b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.cpp new file mode 100644 index 0000000000..e8aed6d30e --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.cpp @@ -0,0 +1,49 @@ +// 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: getmodulefilenamea.c +** +** Purpose: Positive test the GetModuleFileNameA API. +** Call GetModuleFileName to retrieve current process +** full path and file name by passing a NULL module handle +** +** +**============================================================*/ +#include + + +#define MODULENAMEBUFFERSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + + DWORD ModuleNameLength; + char ModuleFileNameBuf[MODULENAMEBUFFERSIZE]=""; + int err; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + + //retrieve the current process full path and file name + //by passing a NULL module handle + ModuleNameLength = GetModuleFileName( + NULL, //a NULL handle + ModuleFileNameBuf,//buffer for module file name + MODULENAMEBUFFERSIZE); + + if(0 == ModuleNameLength) + { + Fail("\nFailed to all GetModuleFileName API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/CMakeLists.txt index c702d07908..f3d92b15c9 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetModuleFileNameW.c + GetModuleFileNameW.cpp ) add_executable(paltest_getmodulefilenamew_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.c deleted file mode 100644 index 4c1c3b00ab..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.c +++ /dev/null @@ -1,112 +0,0 @@ -// 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: getmodulefilenamew.c -** -** Purpose: Test the GetModuleFileNameW to retrieve the specified module -** full path and file name in UNICODE. -** -** -**============================================================*/ -#define UNICODE -#include - -#define MODULENAMEBUFFERSIZE 1024 - -/* SHLEXT is defined only for Unix variants */ - -#if defined(SHLEXT) -#define ModuleName "librotor_pal"SHLEXT -#define Delimiter "/" -#else -#define ModuleName "rotor_pal.dll" -#define Delimiter "\\" -#endif - -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; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.cpp new file mode 100644 index 0000000000..c122312d89 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.cpp @@ -0,0 +1,112 @@ +// 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: getmodulefilenamew.c +** +** Purpose: Test the GetModuleFileNameW to retrieve the specified module +** full path and file name in UNICODE. +** +** +**============================================================*/ +#define UNICODE +#include + +#define MODULENAMEBUFFERSIZE 1024 + +/* SHLEXT is defined only for Unix variants */ + +#if defined(SHLEXT) +#define ModuleName "librotor_pal"SHLEXT +#define Delimiter "/" +#else +#define ModuleName "rotor_pal.dll" +#define Delimiter "\\" +#endif + +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 = (WCHAR*)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; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/CMakeLists.txt index 857feb330d..7b23e92772 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetModuleFileNameW.c + GetModuleFileNameW.cpp ) add_executable(paltest_getmodulefilenamew_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.c deleted file mode 100644 index 6009a9d298..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.c +++ /dev/null @@ -1,57 +0,0 @@ -// 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: getmodulefilenamew.c -** -** Purpose: Positive test the GetModuleFileName API. -** Call GetModuleFileName to retrieve current process -** full path and file name by passing a NULL module handle -** in UNICODE -** -** -**============================================================*/ -#define UNICODE -#include - -#define MODULENAMEBUFFERSIZE 1024 - - -int __cdecl main(int argc, char *argv[]) -{ - - DWORD ModuleNameLength; - WCHAR *ModuleFileNameBuf; - int err; - - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - ModuleFileNameBuf = malloc(MODULENAMEBUFFERSIZE*sizeof(WCHAR)); - - //retrieve the current process full path and file name - //by passing a NULL module handle - ModuleNameLength = GetModuleFileName( - NULL, //a NULL handle - ModuleFileNameBuf,//buffer for module file name - MODULENAMEBUFFERSIZE); - - //free the memory - free(ModuleFileNameBuf); - - if(0 == ModuleNameLength) - { - Fail("\nFailed to all GetModuleFileName API!\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.cpp new file mode 100644 index 0000000000..f23d97c138 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.cpp @@ -0,0 +1,57 @@ +// 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: getmodulefilenamew.c +** +** Purpose: Positive test the GetModuleFileName API. +** Call GetModuleFileName to retrieve current process +** full path and file name by passing a NULL module handle +** in UNICODE +** +** +**============================================================*/ +#define UNICODE +#include + +#define MODULENAMEBUFFERSIZE 1024 + + +int __cdecl main(int argc, char *argv[]) +{ + + DWORD ModuleNameLength; + WCHAR *ModuleFileNameBuf; + int err; + + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + ModuleFileNameBuf = (WCHAR*)malloc(MODULENAMEBUFFERSIZE*sizeof(WCHAR)); + + //retrieve the current process full path and file name + //by passing a NULL module handle + ModuleNameLength = GetModuleFileName( + NULL, //a NULL handle + ModuleFileNameBuf,//buffer for module file name + MODULENAMEBUFFERSIZE); + + //free the memory + free(ModuleFileNameBuf); + + if(0 == ModuleNameLength) + { + Fail("\nFailed to all GetModuleFileName API!\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/CMakeLists.txt index 541ef8b98e..3dedba3cce 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c - testlib.c + test1.cpp + testlib.cpp ) add_executable(paltest_getprocaddress_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.c deleted file mode 100644 index f0b76c615f..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.c +++ /dev/null @@ -1,111 +0,0 @@ -// 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: test1.c (filemapping_memmgt\getprocaddress\test1) -** -** Purpose: Positive test the GetProcAddress API. -** The first test calls GetProcAddress to retrieve the -** address of SimpleFunction inside testlib by its name, -** then calls the function and checks that it worked. -** -** -**===========================================================================*/ -#include - -typedef int (__stdcall *SIMPLEFUNCTION)(int); - -/* SHLEXT is defined only for Unix variants */ -#if defined(SHLEXT) -#define lpModuleName "testlib"SHLEXT -#else -#define lpModuleName "testlib.dll" -#endif - -int __cdecl main(int argc, char *argv[]) -{ - int err; - HMODULE hModule; - SIMPLEFUNCTION procAddressByName; - -#if WIN32 - const char *FunctionName = "_SimpleFunction@4"; -#else - const char *FunctionName = "SimpleFunction"; -#endif - - /* Initialize the PAL environment. */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* load a module */ - hModule = LoadLibrary(lpModuleName); - if(!hModule) - { - Fail("Unexpected error: " - "LoadLibrary(%s) failed.\n", - lpModuleName); - } - - /* - * Test 1 - * - * Get the address of a function - */ - procAddressByName = (SIMPLEFUNCTION) GetProcAddress(hModule,FunctionName); - if(!procAddressByName) - { - Trace("ERROR: Unable to get address of SimpleFunction by its name. " - "GetProcAddress returned NULL with error %d\n", - GetLastError()); - - /* Cleanup */ - err = FreeLibrary(hModule); - if(0 == err) - { - Fail("Unexpected error: Failed to FreeLibrary %s\n", - lpModuleName); - } - Fail(""); - } - - /* Call the function to see that it really worked */ - /* Simple function adds 1 to the argument passed */ - if( 2 != ((procAddressByName)(1))) - { - Trace("ERROR: Problem calling the function by its address.\n"); - - /* Cleanup */ - err = FreeLibrary(hModule); - if(0 == err) - { - Fail("Unexpected error: Failed to FreeLibrary %s\n", - lpModuleName); - } - Fail(""); - } - - /* Cleanup */ - err = FreeLibrary(hModule); - if(0 == err) - { - Fail("Unexpected error: Failed to FreeLibrary %s\n", - lpModuleName); - } - - PAL_Terminate(); - return PASS; -} - - - - - - - - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.cpp b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.cpp new file mode 100644 index 0000000000..f0b76c615f --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.cpp @@ -0,0 +1,111 @@ +// 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: test1.c (filemapping_memmgt\getprocaddress\test1) +** +** Purpose: Positive test the GetProcAddress API. +** The first test calls GetProcAddress to retrieve the +** address of SimpleFunction inside testlib by its name, +** then calls the function and checks that it worked. +** +** +**===========================================================================*/ +#include + +typedef int (__stdcall *SIMPLEFUNCTION)(int); + +/* SHLEXT is defined only for Unix variants */ +#if defined(SHLEXT) +#define lpModuleName "testlib"SHLEXT +#else +#define lpModuleName "testlib.dll" +#endif + +int __cdecl main(int argc, char *argv[]) +{ + int err; + HMODULE hModule; + SIMPLEFUNCTION procAddressByName; + +#if WIN32 + const char *FunctionName = "_SimpleFunction@4"; +#else + const char *FunctionName = "SimpleFunction"; +#endif + + /* Initialize the PAL environment. */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* load a module */ + hModule = LoadLibrary(lpModuleName); + if(!hModule) + { + Fail("Unexpected error: " + "LoadLibrary(%s) failed.\n", + lpModuleName); + } + + /* + * Test 1 + * + * Get the address of a function + */ + procAddressByName = (SIMPLEFUNCTION) GetProcAddress(hModule,FunctionName); + if(!procAddressByName) + { + Trace("ERROR: Unable to get address of SimpleFunction by its name. " + "GetProcAddress returned NULL with error %d\n", + GetLastError()); + + /* Cleanup */ + err = FreeLibrary(hModule); + if(0 == err) + { + Fail("Unexpected error: Failed to FreeLibrary %s\n", + lpModuleName); + } + Fail(""); + } + + /* Call the function to see that it really worked */ + /* Simple function adds 1 to the argument passed */ + if( 2 != ((procAddressByName)(1))) + { + Trace("ERROR: Problem calling the function by its address.\n"); + + /* Cleanup */ + err = FreeLibrary(hModule); + if(0 == err) + { + Fail("Unexpected error: Failed to FreeLibrary %s\n", + lpModuleName); + } + Fail(""); + } + + /* Cleanup */ + err = FreeLibrary(hModule); + if(0 == err) + { + Fail("Unexpected error: Failed to FreeLibrary %s\n", + lpModuleName); + } + + PAL_Terminate(); + return PASS; +} + + + + + + + + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.c deleted file mode 100644 index e8fe48e05d..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.c +++ /dev/null @@ -1,33 +0,0 @@ -// 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: testlib.c (filemapping_memmgt\getprocaddress\test1) -** -** Purpose: Create a simple library containing one function -** to test GetProcAddress -** -** -**===========================================================================*/ -#include "pal.h" - -#if WIN32 -__declspec(dllexport) -#endif - -/** - * Simple function that returns i+1 - */ -int __stdcall SimpleFunction(int i) -{ - return i+1; -} - -#if WIN32 -int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void *lpvReserved) -{ - return 1; -} -#endif diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.cpp b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.cpp new file mode 100644 index 0000000000..e8fe48e05d --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.cpp @@ -0,0 +1,33 @@ +// 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: testlib.c (filemapping_memmgt\getprocaddress\test1) +** +** Purpose: Create a simple library containing one function +** to test GetProcAddress +** +** +**===========================================================================*/ +#include "pal.h" + +#if WIN32 +__declspec(dllexport) +#endif + +/** + * Simple function that returns i+1 + */ +int __stdcall SimpleFunction(int i) +{ + return i+1; +} + +#if WIN32 +int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void *lpvReserved) +{ + return 1; +} +#endif diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/CMakeLists.txt index 60a5ba1a6e..983c16f12f 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c - testlib.c + test2.cpp + testlib.cpp ) add_executable(paltest_getprocaddress_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.c deleted file mode 100644 index 9107728423..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.c +++ /dev/null @@ -1,152 +0,0 @@ -// 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: test2.c (filemapping_memmgt\getprocaddress\test2) -** -** Purpose: This test tries to call GetProcAddress with -** a NULL handle, with a NULL function name, with an empty -** function name, with an invalid name and with an -** invalid ordinal value. -** -** -**===========================================================================*/ -#include - - -/* SHLEXT is defined only for Unix variants */ -#if defined(SHLEXT) -#define lpModuleName "testlib"SHLEXT -#else -#define lpModuleName "testlib.dll" -#endif - - -/** - * main - */ -int __cdecl main(int argc, char *argv[]) -{ - int err; - HMODULE hModule; - FARPROC procAddress; - - /* Initialize the PAL environment. */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* load a module */ - hModule = LoadLibrary(lpModuleName); - if(!hModule) - { - Fail("Unexpected error: " - "LoadLibrary(%s) failed.\n", - lpModuleName); - } - - /* - * Test 1 - * - * Call GetProcAddress with a NULL handle - */ - procAddress = GetProcAddress(NULL,"SimpleFunction"); - if(procAddress != NULL) - { - Trace("ERROR: GetProcAddress with a NULL handle " - "returned a non-NULL value when it should have " - "returned a NULL value with an error\n"); - - /* Cleanup */ - err = FreeLibrary(hModule); - if(0 == err) - { - Fail("Unexpected error: Failed to FreeLibrary %s\n", - lpModuleName); - } - Fail(""); - } - - /** - * Test 2 - * - * Call GetProcAddress with a NULL function name - */ - - procAddress = GetProcAddress(hModule,NULL); - if(procAddress != NULL) - { - Trace("ERROR: GetProcAddress with a NULL function name " - "returned a non-NULL value when it should have " - "returned a NULL value with an error\n"); - - /* Cleanup */ - err = FreeLibrary(hModule); - if(0 == err) - { - Fail("Unexpected error: Failed to FreeLibrary %s\n", - lpModuleName); - } - Fail(""); - } - - /** - * Test 3 - * - * Call GetProcAddress with an empty function name string - */ - - procAddress = GetProcAddress(hModule,""); - if(procAddress != NULL) - { - Trace("ERROR: GetProcAddress with an empty function name " - "returned a non-NULL value when it should have " - "returned a NULL value with an error\n"); - - /* Cleanup */ - err = FreeLibrary(hModule); - if(0 == err) - { - Fail("Unexpected error: Failed to FreeLibrary %s\n", - lpModuleName); - } - Fail(""); - } - - /** - * Test 4 - * - * Call GetProcAddress with an invalid name - */ - - procAddress = GetProcAddress(hModule,"Simple Function"); - if(procAddress != NULL) - { - Trace("ERROR: GetProcAddress with an invalid function name " - "returned a non-NULL value when it should have " - "returned a NULL value with an error\n"); - - /* Cleanup */ - err = FreeLibrary(hModule); - if(0 == err) - { - Fail("Unexpected error: Failed to FreeLibrary %s\n", - lpModuleName); - } - Fail(""); - } - - /* cleanup */ - err = FreeLibrary(hModule); - if(0 == err) - { - Fail("Unexpected error: Failed to FreeLibrary %s\n", - lpModuleName); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.cpp b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.cpp new file mode 100644 index 0000000000..9107728423 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.cpp @@ -0,0 +1,152 @@ +// 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: test2.c (filemapping_memmgt\getprocaddress\test2) +** +** Purpose: This test tries to call GetProcAddress with +** a NULL handle, with a NULL function name, with an empty +** function name, with an invalid name and with an +** invalid ordinal value. +** +** +**===========================================================================*/ +#include + + +/* SHLEXT is defined only for Unix variants */ +#if defined(SHLEXT) +#define lpModuleName "testlib"SHLEXT +#else +#define lpModuleName "testlib.dll" +#endif + + +/** + * main + */ +int __cdecl main(int argc, char *argv[]) +{ + int err; + HMODULE hModule; + FARPROC procAddress; + + /* Initialize the PAL environment. */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* load a module */ + hModule = LoadLibrary(lpModuleName); + if(!hModule) + { + Fail("Unexpected error: " + "LoadLibrary(%s) failed.\n", + lpModuleName); + } + + /* + * Test 1 + * + * Call GetProcAddress with a NULL handle + */ + procAddress = GetProcAddress(NULL,"SimpleFunction"); + if(procAddress != NULL) + { + Trace("ERROR: GetProcAddress with a NULL handle " + "returned a non-NULL value when it should have " + "returned a NULL value with an error\n"); + + /* Cleanup */ + err = FreeLibrary(hModule); + if(0 == err) + { + Fail("Unexpected error: Failed to FreeLibrary %s\n", + lpModuleName); + } + Fail(""); + } + + /** + * Test 2 + * + * Call GetProcAddress with a NULL function name + */ + + procAddress = GetProcAddress(hModule,NULL); + if(procAddress != NULL) + { + Trace("ERROR: GetProcAddress with a NULL function name " + "returned a non-NULL value when it should have " + "returned a NULL value with an error\n"); + + /* Cleanup */ + err = FreeLibrary(hModule); + if(0 == err) + { + Fail("Unexpected error: Failed to FreeLibrary %s\n", + lpModuleName); + } + Fail(""); + } + + /** + * Test 3 + * + * Call GetProcAddress with an empty function name string + */ + + procAddress = GetProcAddress(hModule,""); + if(procAddress != NULL) + { + Trace("ERROR: GetProcAddress with an empty function name " + "returned a non-NULL value when it should have " + "returned a NULL value with an error\n"); + + /* Cleanup */ + err = FreeLibrary(hModule); + if(0 == err) + { + Fail("Unexpected error: Failed to FreeLibrary %s\n", + lpModuleName); + } + Fail(""); + } + + /** + * Test 4 + * + * Call GetProcAddress with an invalid name + */ + + procAddress = GetProcAddress(hModule,"Simple Function"); + if(procAddress != NULL) + { + Trace("ERROR: GetProcAddress with an invalid function name " + "returned a non-NULL value when it should have " + "returned a NULL value with an error\n"); + + /* Cleanup */ + err = FreeLibrary(hModule); + if(0 == err) + { + Fail("Unexpected error: Failed to FreeLibrary %s\n", + lpModuleName); + } + Fail(""); + } + + /* cleanup */ + err = FreeLibrary(hModule); + if(0 == err) + { + Fail("Unexpected error: Failed to FreeLibrary %s\n", + lpModuleName); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.c deleted file mode 100644 index 23e58e871e..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.c +++ /dev/null @@ -1,33 +0,0 @@ -// 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: testlib.c (filemapping_memmgt\getprocaddress\test2) -** -** Purpose: Create a simple library containing one function -** to test GetProcAddress -** -** -**===========================================================================*/ -#include "pal.h" - -#if WIN32 -__declspec(dllexport) -#endif - -/** - * Simple function that returns i+1 - */ -int __stdcall SimpleFunction(int i) -{ - return i+1; -} - -#if WIN32 -int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void *lpvReserved) -{ - return 1; -} -#endif diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.cpp b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.cpp new file mode 100644 index 0000000000..23e58e871e --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.cpp @@ -0,0 +1,33 @@ +// 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: testlib.c (filemapping_memmgt\getprocaddress\test2) +** +** Purpose: Create a simple library containing one function +** to test GetProcAddress +** +** +**===========================================================================*/ +#include "pal.h" + +#if WIN32 +__declspec(dllexport) +#endif + +/** + * Simple function that returns i+1 + */ +int __stdcall SimpleFunction(int i) +{ + return i+1; +} + +#if WIN32 +int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void *lpvReserved) +{ + return 1; +} +#endif diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/CMakeLists.txt index 18871abf00..3e9c725f95 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetProcessHeap.c + GetProcessHeap.cpp ) add_executable(paltest_getprocessheap_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.c deleted file mode 100644 index bec6b5c616..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.c +++ /dev/null @@ -1,39 +0,0 @@ -// 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: getprocheap.c -** -** Purpose: Positive test the GetProcessHeap API. -** Call GetProcessHeap to retrieve the handle of -** calling process heap -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - HANDLE ProcessHeapHandle; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Retrieve the calling process heap handle - ProcessHeapHandle = GetProcessHeap(); - - if(!ProcessHeapHandle) - { - Fail("\nFailed to call GetProcessHeap API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.cpp b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.cpp new file mode 100644 index 0000000000..bec6b5c616 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.cpp @@ -0,0 +1,39 @@ +// 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: getprocheap.c +** +** Purpose: Positive test the GetProcessHeap API. +** Call GetProcessHeap to retrieve the handle of +** calling process heap +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + HANDLE ProcessHeapHandle; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Retrieve the calling process heap handle + ProcessHeapHandle = GetProcessHeap(); + + if(!ProcessHeapHandle) + { + Fail("\nFailed to call GetProcessHeap API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt index 3a64a0c58a..b9ce32b35e 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - HeapAlloc.c + HeapAlloc.cpp ) add_executable(paltest_heapalloc_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c deleted file mode 100644 index 04de274e80..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c +++ /dev/null @@ -1,100 +0,0 @@ -// 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: heapalloc.c -** -** Purpose: Positive test the HeapAlloc API. -** Call HeapAlloc by pssing zero as control flag -** Call HeapAlloc by passing HEAP_ZERO_MEMORY as control flag -** Call HeapAlloc to allocate one byte heap memory -** Call HeapAlloc to allocate maximum available heap memory -** -** -**============================================================*/ -#include - -#define HEAPSIZE 64 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - HANDLE ProcessHeapHandle; - LPVOID lpHeap; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - if(0 != 0) - { - ExitProcess(FAIL); - } - - /* Retrieve the calling process heap handle */ - ProcessHeapHandle = GetProcessHeap(); - - if(!ProcessHeapHandle) - { - Fail("\nFailed to call GetProcessHeap API!\n"); - } - - /* allocate a heap memory in specified size */ - lpHeap = HeapAlloc(ProcessHeapHandle, /* HeapHandle */ - 0, /* control flag */ - HEAPSIZE); /* /specify the heap size */ - if(NULL == lpHeap) - { - Fail("Failed to call HeapAlloc API!\n"); - } - - /* free the heap memory */ - err = HeapFree(ProcessHeapHandle, - 0, - lpHeap); - if(0 == err) - { - Fail("Failed to call HeapFree API!\n"); - } - - - /* allocate a heap memory in 1 byte size */ - lpHeap = HeapAlloc(ProcessHeapHandle, /* HeapHandle */ - 0, /* control flag */ - 1); /* specify the heap size*/ - if(NULL == lpHeap) - { - Fail("Failed to call HeapAlloc API to allocate one byte heap memory!\n"); - } - - /* free the heap memory */ - err = HeapFree(ProcessHeapHandle, - 0, - lpHeap); - if(0 == err) - { - Fail("Failed to call HeapFree API!\n"); - } - - /* allocate a heap memory and initialize it to zero */ - lpHeap = HeapAlloc(ProcessHeapHandle,/* HeapHandle */ - HEAP_ZERO_MEMORY,/* control flag */ - HEAPSIZE); /* specify the heap size */ - if(NULL == lpHeap) - { - Fail("Failed to call HeapAlloc API with HEAP_ZERO_MEMORY control flag!\n"); - } - - /* free the heap memory */ - err = HeapFree(ProcessHeapHandle, - 0, - lpHeap); - if(0 == err) - { - Fail("Failed to call HeapFree API!\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.cpp new file mode 100644 index 0000000000..04de274e80 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.cpp @@ -0,0 +1,100 @@ +// 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: heapalloc.c +** +** Purpose: Positive test the HeapAlloc API. +** Call HeapAlloc by pssing zero as control flag +** Call HeapAlloc by passing HEAP_ZERO_MEMORY as control flag +** Call HeapAlloc to allocate one byte heap memory +** Call HeapAlloc to allocate maximum available heap memory +** +** +**============================================================*/ +#include + +#define HEAPSIZE 64 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + HANDLE ProcessHeapHandle; + LPVOID lpHeap; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + if(0 != 0) + { + ExitProcess(FAIL); + } + + /* Retrieve the calling process heap handle */ + ProcessHeapHandle = GetProcessHeap(); + + if(!ProcessHeapHandle) + { + Fail("\nFailed to call GetProcessHeap API!\n"); + } + + /* allocate a heap memory in specified size */ + lpHeap = HeapAlloc(ProcessHeapHandle, /* HeapHandle */ + 0, /* control flag */ + HEAPSIZE); /* /specify the heap size */ + if(NULL == lpHeap) + { + Fail("Failed to call HeapAlloc API!\n"); + } + + /* free the heap memory */ + err = HeapFree(ProcessHeapHandle, + 0, + lpHeap); + if(0 == err) + { + Fail("Failed to call HeapFree API!\n"); + } + + + /* allocate a heap memory in 1 byte size */ + lpHeap = HeapAlloc(ProcessHeapHandle, /* HeapHandle */ + 0, /* control flag */ + 1); /* specify the heap size*/ + if(NULL == lpHeap) + { + Fail("Failed to call HeapAlloc API to allocate one byte heap memory!\n"); + } + + /* free the heap memory */ + err = HeapFree(ProcessHeapHandle, + 0, + lpHeap); + if(0 == err) + { + Fail("Failed to call HeapFree API!\n"); + } + + /* allocate a heap memory and initialize it to zero */ + lpHeap = HeapAlloc(ProcessHeapHandle,/* HeapHandle */ + HEAP_ZERO_MEMORY,/* control flag */ + HEAPSIZE); /* specify the heap size */ + if(NULL == lpHeap) + { + Fail("Failed to call HeapAlloc API with HEAP_ZERO_MEMORY control flag!\n"); + } + + /* free the heap memory */ + err = HeapFree(ProcessHeapHandle, + 0, + lpHeap); + if(0 == err) + { + Fail("Failed to call HeapFree API!\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt index 5253110d8d..1b9655ddba 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - HeapAlloc.c + HeapAlloc.cpp ) add_executable(paltest_heapalloc_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c deleted file mode 100644 index 5f4ff90498..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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: heapalloc.c -** -** Purpose: Positive test the HeapAlloc API. -** Call HeapAlloc with HEAP_ZERO_MEMORY control flag -** -** -**============================================================*/ -#include - -#define HEAPSIZE 64 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - HANDLE ProcessHeapHandle; - LPVOID lpHeap; - - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Retrieve the calling process heap handle - ProcessHeapHandle = GetProcessHeap(); - - if(!ProcessHeapHandle) - { - Fail("\nFailed to call GetProcessHeap API!\n"); - } - - lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle - HEAP_ZERO_MEMORY,//control flag - HEAPSIZE); //specify the heap size - if(NULL == lpHeap) - { - Fail("Failed to call HeapAlloc API!\n"); - } - - //free the heap memory - err = HeapFree(ProcessHeapHandle, - 0, - lpHeap); - if(0 == err) - { - Fail("Failed to call HeapFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.cpp new file mode 100644 index 0000000000..5f4ff90498 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.cpp @@ -0,0 +1,59 @@ +// 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: heapalloc.c +** +** Purpose: Positive test the HeapAlloc API. +** Call HeapAlloc with HEAP_ZERO_MEMORY control flag +** +** +**============================================================*/ +#include + +#define HEAPSIZE 64 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + HANDLE ProcessHeapHandle; + LPVOID lpHeap; + + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Retrieve the calling process heap handle + ProcessHeapHandle = GetProcessHeap(); + + if(!ProcessHeapHandle) + { + Fail("\nFailed to call GetProcessHeap API!\n"); + } + + lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle + HEAP_ZERO_MEMORY,//control flag + HEAPSIZE); //specify the heap size + if(NULL == lpHeap) + { + Fail("Failed to call HeapAlloc API!\n"); + } + + //free the heap memory + err = HeapFree(ProcessHeapHandle, + 0, + lpHeap); + if(0 == err) + { + Fail("Failed to call HeapFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt index f0b89461d2..1c3845c6e9 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - HeapAlloc.c + HeapAlloc.cpp ) add_executable(paltest_heapalloc_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c deleted file mode 100644 index 4a74fe8194..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: heapalloc.c -** -** Purpose: Positive test the HeapAlloc API. -** Call HeapAlloc asking for zero bytes -** with HEAP_ZERO_MEMORY control flag -** -** -**============================================================*/ -#include - -#define HEAPSIZE 0 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - HANDLE ProcessHeapHandle; - LPVOID lpHeap; - - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Retrieve the calling process heap handle - ProcessHeapHandle = GetProcessHeap(); - - if(!ProcessHeapHandle) - { - Fail("\nFailed to call GetProcessHeap API!\n"); - } - - lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle - HEAP_ZERO_MEMORY,//control flag - HEAPSIZE); //specify the heap size - - //lpHeap should be non-NULL pointer - if(NULL == lpHeap) - { - Fail("Failed to call HeapAlloc API, when number of bytes to be allocated is zero!\n"); - } - - //free the heap memory - err = HeapFree(ProcessHeapHandle, - 0, - lpHeap); - if(0 == err) - { - Fail("Failed to call HeapFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.cpp new file mode 100644 index 0000000000..4a74fe8194 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.cpp @@ -0,0 +1,62 @@ +// 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: heapalloc.c +** +** Purpose: Positive test the HeapAlloc API. +** Call HeapAlloc asking for zero bytes +** with HEAP_ZERO_MEMORY control flag +** +** +**============================================================*/ +#include + +#define HEAPSIZE 0 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + HANDLE ProcessHeapHandle; + LPVOID lpHeap; + + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Retrieve the calling process heap handle + ProcessHeapHandle = GetProcessHeap(); + + if(!ProcessHeapHandle) + { + Fail("\nFailed to call GetProcessHeap API!\n"); + } + + lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle + HEAP_ZERO_MEMORY,//control flag + HEAPSIZE); //specify the heap size + + //lpHeap should be non-NULL pointer + if(NULL == lpHeap) + { + Fail("Failed to call HeapAlloc API, when number of bytes to be allocated is zero!\n"); + } + + //free the heap memory + err = HeapFree(ProcessHeapHandle, + 0, + lpHeap); + if(0 == err) + { + Fail("Failed to call HeapFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/CMakeLists.txt index 898047a9ad..004912256c 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - HeapFree.c + HeapFree.cpp ) add_executable(paltest_heapfree_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.c deleted file mode 100644 index 37b6b3bf60..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: heapfree.c -** -** Purpose: Positive test the HeapFree API. -** Call HeapFree to free a memory block -** and try to free an invalid memory block -** -** -**============================================================*/ -#include - -#define HEAPSIZE 64 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - HANDLE ProcessHeapHandle; - LPVOID lpHeap; - - - /* Initialize the PAL environment */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Retrieve the calling process heap handle */ - ProcessHeapHandle = GetProcessHeap(); - - if(!ProcessHeapHandle) - { - Fail("\nFailed to call GetProcessHeap API!\n"); - } - - - lpHeap = HeapAlloc(ProcessHeapHandle,/* HeapHandle */ - HEAP_ZERO_MEMORY,/* control flag */ - HEAPSIZE); /* specify the heap size */ - if(NULL == lpHeap) - { - Fail("Failed to call HeapAlloc API!\n"); - } - - - /* free a allocate heap memory */ - err = HeapFree(ProcessHeapHandle, - 0, - lpHeap); - - if(0 == err) - { - Fail("Failed to call HeapFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.cpp b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.cpp new file mode 100644 index 0000000000..37b6b3bf60 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.cpp @@ -0,0 +1,62 @@ +// 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: heapfree.c +** +** Purpose: Positive test the HeapFree API. +** Call HeapFree to free a memory block +** and try to free an invalid memory block +** +** +**============================================================*/ +#include + +#define HEAPSIZE 64 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + HANDLE ProcessHeapHandle; + LPVOID lpHeap; + + + /* Initialize the PAL environment */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Retrieve the calling process heap handle */ + ProcessHeapHandle = GetProcessHeap(); + + if(!ProcessHeapHandle) + { + Fail("\nFailed to call GetProcessHeap API!\n"); + } + + + lpHeap = HeapAlloc(ProcessHeapHandle,/* HeapHandle */ + HEAP_ZERO_MEMORY,/* control flag */ + HEAPSIZE); /* specify the heap size */ + if(NULL == lpHeap) + { + Fail("Failed to call HeapAlloc API!\n"); + } + + + /* free a allocate heap memory */ + err = HeapFree(ProcessHeapHandle, + 0, + lpHeap); + + if(0 == err) + { + Fail("Failed to call HeapFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/CMakeLists.txt index 1decb02c73..17e0127435 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_heaprealloc_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.c deleted file mode 100644 index 497d208eca..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.c +++ /dev/null @@ -1,72 +0,0 @@ -// 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: test1.c -** -** Purpose: Allocate some memory. Then reallocate that memory. Ensure the -** return values are correct, and also that data placed in the allocated -** memory carries over to the reallocated block. -** -** -**============================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE TheHeap; - char* TheMemory; - char* ReAllocMemory; - int i; - - if(PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - TheHeap = GetProcessHeap(); - - if(TheHeap == NULL) - { - Fail("ERROR: GetProcessHeap() returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Allocate 100 bytes on the heap */ - if((TheMemory = HeapAlloc(TheHeap, 0, 100)) == NULL) - { - Fail("ERROR: HeapAlloc returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Set each byte of that memory block to 'x' */ - memset(TheMemory, 'X', 100); - - /* Reallocate the memory */ - ReAllocMemory = HeapReAlloc(TheHeap, 0, TheMemory, 100); - - if(ReAllocMemory == NULL) - { - Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of " - "heap memory. GetLastError returns %d.",GetLastError()); - } - - /* Check that each byte of the memory Reallocated is 'x' */ - - for(i=0; i<100; ++i) - { - if(ReAllocMemory[i] != 'X') - { - Fail("ERROR: Byte number %d of the reallocated memory block " - "is not set to 'X' as it should be.",i); - } - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.cpp b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.cpp new file mode 100644 index 0000000000..eedd45e45d --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.cpp @@ -0,0 +1,72 @@ +// 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: test1.c +** +** Purpose: Allocate some memory. Then reallocate that memory. Ensure the +** return values are correct, and also that data placed in the allocated +** memory carries over to the reallocated block. +** +** +**============================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE TheHeap; + char* TheMemory; + char* ReAllocMemory; + int i; + + if(PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + TheHeap = GetProcessHeap(); + + if(TheHeap == NULL) + { + Fail("ERROR: GetProcessHeap() returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Allocate 100 bytes on the heap */ + if((TheMemory = (char*)HeapAlloc(TheHeap, 0, 100)) == NULL) + { + Fail("ERROR: HeapAlloc returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Set each byte of that memory block to 'x' */ + memset(TheMemory, 'X', 100); + + /* Reallocate the memory */ + ReAllocMemory = (char*)HeapReAlloc(TheHeap, 0, TheMemory, 100); + + if(ReAllocMemory == NULL) + { + Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of " + "heap memory. GetLastError returns %d.",GetLastError()); + } + + /* Check that each byte of the memory Reallocated is 'x' */ + + for(i=0; i<100; ++i) + { + if(ReAllocMemory[i] != 'X') + { + Fail("ERROR: Byte number %d of the reallocated memory block " + "is not set to 'X' as it should be.",i); + } + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/CMakeLists.txt index 6f5510387a..a9239354ba 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_heaprealloc_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.c deleted file mode 100644 index 13e789f901..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: test2.c -** -** Purpose: Allocate some memory. Then reallocate that memory into less -** space than the original amount. Ensure the -** return values are correct, and also that data placed in the allocated -** memory carries over to the reallocated block. -** -** -**============================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE TheHeap; - char* TheMemory; - char* ReAllocMemory; - int i; - - if(PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - TheHeap = GetProcessHeap(); - - if(TheHeap == NULL) - { - Fail("ERROR: GetProcessHeap() returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Allocate 200 bytes on the heap */ - if((TheMemory = HeapAlloc(TheHeap, 0, 200)) == NULL) - { - Fail("ERROR: HeapAlloc returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Set the first 100 bytes to 'X' */ - memset(TheMemory, 'X', 100); - - /* Set the second 100 bytes to 'Z' */ - memset(TheMemory+100, 'Z', 100); - - /* Reallocate the memory to 100 bytes */ - ReAllocMemory = HeapReAlloc(TheHeap, 0, TheMemory, 100); - - if(ReAllocMemory == NULL) - { - Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of " - "heap memory. GetLastError returns %d.",GetLastError()); - } - - /* Check that each of the first 100 bytes hasn't lost any data. - Anything beyond the first 100 might still be valid, but we can't - gaurentee it. - */ - - for(i=0; i<100; ++i) - { - /* Note: Cast to char* so the function knows the size is 1 */ - if(ReAllocMemory[i] != 'X') - { - Fail("ERROR: Byte number %d of the reallocated memory block " - "is not set to 'X' as it should be.",i); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.cpp b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.cpp new file mode 100644 index 0000000000..a7e3b2a055 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.cpp @@ -0,0 +1,79 @@ +// 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: test2.c +** +** Purpose: Allocate some memory. Then reallocate that memory into less +** space than the original amount. Ensure the +** return values are correct, and also that data placed in the allocated +** memory carries over to the reallocated block. +** +** +**============================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE TheHeap; + char* TheMemory; + char* ReAllocMemory; + int i; + + if(PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + TheHeap = GetProcessHeap(); + + if(TheHeap == NULL) + { + Fail("ERROR: GetProcessHeap() returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Allocate 200 bytes on the heap */ + if((TheMemory = (char*)HeapAlloc(TheHeap, 0, 200)) == NULL) + { + Fail("ERROR: HeapAlloc returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Set the first 100 bytes to 'X' */ + memset(TheMemory, 'X', 100); + + /* Set the second 100 bytes to 'Z' */ + memset(TheMemory+100, 'Z', 100); + + /* Reallocate the memory to 100 bytes */ + ReAllocMemory = (char*)HeapReAlloc(TheHeap, 0, TheMemory, 100); + + if(ReAllocMemory == NULL) + { + Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of " + "heap memory. GetLastError returns %d.",GetLastError()); + } + + /* Check that each of the first 100 bytes hasn't lost any data. + Anything beyond the first 100 might still be valid, but we can't + gaurentee it. + */ + + for(i=0; i<100; ++i) + { + /* Note: Cast to char* so the function knows the size is 1 */ + if(ReAllocMemory[i] != 'X') + { + Fail("ERROR: Byte number %d of the reallocated memory block " + "is not set to 'X' as it should be.",i); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/CMakeLists.txt index 7ad836706a..2d82b6efdd 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_heaprealloc_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.c deleted file mode 100644 index dea9de348d..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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: test3.c -** -** Purpose: Allocate some memory. Then reallocate that memory into a -** bigger space on the heap. Check that the first portion of the data is -** unchanged. Then set the new portion to a value, to ensure that it is -** properly writable memory. -** -** -**============================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE TheHeap; - char* TheMemory; - char* ReAllocMemory; - int i; - - if(PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - TheHeap = GetProcessHeap(); - - if(TheHeap == NULL) - { - Fail("ERROR: GetProcessHeap() returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Allocate 100 bytes on the heap */ - if((TheMemory = HeapAlloc(TheHeap, 0, 100)) == NULL) - { - Fail("ERROR: HeapAlloc returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Set the first 100 bytes to 'X' */ - memset(TheMemory, 'X', 100); - - /* Reallocate the memory to 200 bytes */ - ReAllocMemory = HeapReAlloc(TheHeap, 0, TheMemory, 200); - - if(ReAllocMemory == NULL) - { - Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of " - "heap memory. GetLastError returns %d.",GetLastError()); - } - - /* Check that each of the first 100 bytes hasn't lost any data. */ - for(i=0; i<100; ++i) - { - - if(ReAllocMemory[i] != 'X') - { - Fail("ERROR: Byte number %d of the reallocated memory block " - "is not set to 'X' as it should be.",i); - } - } - - /* Beyond the first 100 bytes is valid free memory. We'll set all this - memory to a value -- though, even if HeapReAlloc didn't work, it might - still be possible to memset this memory without raising an exception. - */ - memset(ReAllocMemory+100, 'Z', 100); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.cpp b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.cpp new file mode 100644 index 0000000000..d4139e8d5e --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.cpp @@ -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: test3.c +** +** Purpose: Allocate some memory. Then reallocate that memory into a +** bigger space on the heap. Check that the first portion of the data is +** unchanged. Then set the new portion to a value, to ensure that it is +** properly writable memory. +** +** +**============================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE TheHeap; + char* TheMemory; + char* ReAllocMemory; + int i; + + if(PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + TheHeap = GetProcessHeap(); + + if(TheHeap == NULL) + { + Fail("ERROR: GetProcessHeap() returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Allocate 100 bytes on the heap */ + if((TheMemory = (char*)HeapAlloc(TheHeap, 0, 100)) == NULL) + { + Fail("ERROR: HeapAlloc returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Set the first 100 bytes to 'X' */ + memset(TheMemory, 'X', 100); + + /* Reallocate the memory to 200 bytes */ + ReAllocMemory = (char*)HeapReAlloc(TheHeap, 0, TheMemory, 200); + + if(ReAllocMemory == NULL) + { + Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of " + "heap memory. GetLastError returns %d.",GetLastError()); + } + + /* Check that each of the first 100 bytes hasn't lost any data. */ + for(i=0; i<100; ++i) + { + + if(ReAllocMemory[i] != 'X') + { + Fail("ERROR: Byte number %d of the reallocated memory block " + "is not set to 'X' as it should be.",i); + } + } + + /* Beyond the first 100 bytes is valid free memory. We'll set all this + memory to a value -- though, even if HeapReAlloc didn't work, it might + still be possible to memset this memory without raising an exception. + */ + memset(ReAllocMemory+100, 'Z', 100); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/CMakeLists.txt index 024a4ef840..129d8a47cd 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_heaprealloc_test4 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.c deleted file mode 100644 index cebf904501..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.c +++ /dev/null @@ -1,80 +0,0 @@ -// 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: test4.c -** -** Purpose: Call HeapReAlloc with a NULL pointer to memory. It should -** return NULL. -** -** -**============================================================*/ - -/* Note: When attempted with a NULL Handle, this test crashes under win32. - As such, the behaviour isn't tested here. -*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE TheHeap; - LPVOID TheMemory = NULL; - - if(PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - TheHeap = GetProcessHeap(); - - if(TheHeap == NULL) - { - Fail("ERROR: GetProcessHeap() returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Allocate 100 bytes on the heap */ - if(HeapAlloc(TheHeap, 0, 100) == NULL) - { - Fail("ERROR: HeapAlloc returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Call HeapReAlloc with a NULL memory pointer. It should fail */ - - if(HeapReAlloc(TheHeap, 0, TheMemory, 100) != NULL) - { - Fail("ERROR: HeapReAlloc was passed an invalid memory pointer. " - "It should have failed and returned NULL upon failure."); - } - - if(GetLastError() != 0) - { - Fail("ERROR: GetLastError should be zero after passing a NULL " - "memory pointer to HeapReAlloc.\n"); - } - - /* Call HeapReAlloc with a size of 0 bytes on a NULL memory pointer. - It should still fail. - */ - - if(HeapReAlloc(TheHeap, 0, TheMemory, 0) != NULL) - { - Fail("ERROR: HeapReAlloc was passed an invalid memory pointer and " - "the amount of memory to reallocate was 0. " - "It should have failed and returned NULL upon failure."); - } - - if(GetLastError() != 0) - { - Fail("ERROR: GetLastError should be zero after passing a NULL " - "memory pointer to HeapReAlloc.\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.cpp b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.cpp new file mode 100644 index 0000000000..cebf904501 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.cpp @@ -0,0 +1,80 @@ +// 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: test4.c +** +** Purpose: Call HeapReAlloc with a NULL pointer to memory. It should +** return NULL. +** +** +**============================================================*/ + +/* Note: When attempted with a NULL Handle, this test crashes under win32. + As such, the behaviour isn't tested here. +*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE TheHeap; + LPVOID TheMemory = NULL; + + if(PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + TheHeap = GetProcessHeap(); + + if(TheHeap == NULL) + { + Fail("ERROR: GetProcessHeap() returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Allocate 100 bytes on the heap */ + if(HeapAlloc(TheHeap, 0, 100) == NULL) + { + Fail("ERROR: HeapAlloc returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Call HeapReAlloc with a NULL memory pointer. It should fail */ + + if(HeapReAlloc(TheHeap, 0, TheMemory, 100) != NULL) + { + Fail("ERROR: HeapReAlloc was passed an invalid memory pointer. " + "It should have failed and returned NULL upon failure."); + } + + if(GetLastError() != 0) + { + Fail("ERROR: GetLastError should be zero after passing a NULL " + "memory pointer to HeapReAlloc.\n"); + } + + /* Call HeapReAlloc with a size of 0 bytes on a NULL memory pointer. + It should still fail. + */ + + if(HeapReAlloc(TheHeap, 0, TheMemory, 0) != NULL) + { + Fail("ERROR: HeapReAlloc was passed an invalid memory pointer and " + "the amount of memory to reallocate was 0. " + "It should have failed and returned NULL upon failure."); + } + + if(GetLastError() != 0) + { + Fail("ERROR: GetLastError should be zero after passing a NULL " + "memory pointer to HeapReAlloc.\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/CMakeLists.txt index 3ab3ec16e8..ed3d390625 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_heaprealloc_test5 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.c deleted file mode 100644 index 230e65e492..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: test5.c -** -** Purpose: Allocate some memory. Then call HeapRealloc with 0 as the -** amount of memory to reallocate. This should work, essentially freeing -** the memory (though we can't verfiy this) -** -** -**============================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE TheHeap; - char* TheMemory; - char* ReAllocMemory; - char* ReAllocMemory2; - - if(PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - TheHeap = GetProcessHeap(); - - if(TheHeap == NULL) - { - Fail("ERROR: GetProcessHeap() returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Allocate 100 bytes on the heap */ - if((TheMemory = HeapAlloc(TheHeap, 0, 100)) == NULL) - { - Fail("ERROR: HeapAlloc returned NULL when it was called. " - "GetLastError() returned %d.",GetLastError()); - } - - /* Set each byte of that memory block to 'x' */ - memset(TheMemory, 'X', 100); - - /* Reallocate the memory into 0 bytes */ - ReAllocMemory = HeapReAlloc(TheHeap, 0, TheMemory, 0); - - if(ReAllocMemory == NULL) - { - Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of " - "heap memory. GetLastError returns %d.",GetLastError()); - } - - /* Reallocate the memory we just put into 0 bytes, into 100 bytes. */ - ReAllocMemory2 = HeapReAlloc(TheHeap, 0, ReAllocMemory, 100); - - if(ReAllocMemory2 == NULL) - { - Fail("ERROR: HeapReAlloc failed to reallocate the 0 bytes of " - "heap memory into 100. GetLastError returns %d.",GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.cpp b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.cpp new file mode 100644 index 0000000000..fcd38376ec --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.cpp @@ -0,0 +1,69 @@ +// 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: test5.c +** +** Purpose: Allocate some memory. Then call HeapRealloc with 0 as the +** amount of memory to reallocate. This should work, essentially freeing +** the memory (though we can't verfiy this) +** +** +**============================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE TheHeap; + char* TheMemory; + char* ReAllocMemory; + char* ReAllocMemory2; + + if(PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + TheHeap = GetProcessHeap(); + + if(TheHeap == NULL) + { + Fail("ERROR: GetProcessHeap() returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Allocate 100 bytes on the heap */ + if((TheMemory = (char*)HeapAlloc(TheHeap, 0, 100)) == NULL) + { + Fail("ERROR: HeapAlloc returned NULL when it was called. " + "GetLastError() returned %d.",GetLastError()); + } + + /* Set each byte of that memory block to 'x' */ + memset(TheMemory, 'X', 100); + + /* Reallocate the memory into 0 bytes */ + ReAllocMemory = (char*)HeapReAlloc(TheHeap, 0, TheMemory, 0); + + if(ReAllocMemory == NULL) + { + Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of " + "heap memory. GetLastError returns %d.",GetLastError()); + } + + /* Reallocate the memory we just put into 0 bytes, into 100 bytes. */ + ReAllocMemory2 = (char*)HeapReAlloc(TheHeap, 0, ReAllocMemory, 100); + + if(ReAllocMemory2 == NULL) + { + Fail("ERROR: HeapReAlloc failed to reallocate the 0 bytes of " + "heap memory into 100. GetLastError returns %d.",GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/CMakeLists.txt index c96e00a170..f74e442d76 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - LocalAlloc.c + LocalAlloc.cpp ) add_executable(paltest_localalloc_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.c deleted file mode 100644 index 17afbc6020..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: LocalAlloc.c -** -** Purpose: Positive test the LocalAlloc API. -** Call LocalAlloc with zero as the allocation attribute -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - HLOCAL LocalHeap; - HLOCAL FreeHeap; - int err; - const SIZE_T heapSize = 64; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*Allocate the specified number of bytes from the heap*/ - /*with allocation attribute: zero which is required by PAL Doc*/ - LocalHeap = LocalAlloc(0, heapSize); - if(!LocalHeap) - { - Fail("\nFailed to call LocalAlloc API, " - "error code=%u\n", GetLastError()); - } - - /*Free the allocated local heap memory*/ - FreeHeap = LocalFree(LocalHeap); - if(FreeHeap) - { - Fail("Failed to call LocalFree API, " - "error code=%u\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.cpp new file mode 100644 index 0000000000..17afbc6020 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.cpp @@ -0,0 +1,49 @@ +// 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: LocalAlloc.c +** +** Purpose: Positive test the LocalAlloc API. +** Call LocalAlloc with zero as the allocation attribute +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + HLOCAL LocalHeap; + HLOCAL FreeHeap; + int err; + const SIZE_T heapSize = 64; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*Allocate the specified number of bytes from the heap*/ + /*with allocation attribute: zero which is required by PAL Doc*/ + LocalHeap = LocalAlloc(0, heapSize); + if(!LocalHeap) + { + Fail("\nFailed to call LocalAlloc API, " + "error code=%u\n", GetLastError()); + } + + /*Free the allocated local heap memory*/ + FreeHeap = LocalFree(LocalHeap); + if(FreeHeap) + { + Fail("Failed to call LocalFree API, " + "error code=%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/CMakeLists.txt index 47ad76ebe6..d92939c7cc 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - LocalFree.c + LocalFree.cpp ) add_executable(paltest_localfree_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.c b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.c deleted file mode 100644 index d9c062e761..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: LocalFree.c -** -** Purpose: Positive test the LocalFree API. -** Call LocalFree to free a specified local memory object -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - HLOCAL LocalHeap; - HLOCAL FreeHeap; - int err; - const SIZE_T heapSize = 64; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*Allocate the specified number of bytes from the heap*/ - /*with zero ad the allocation attribute*/ - LocalHeap = LocalAlloc(0, heapSize); - if(!LocalHeap) - { - Fail("\nFailed to call LocalAlloc API, " - "error code=%u\n", GetLastError()); - } - - /*Free the allocated local heap memory*/ - FreeHeap = LocalFree(LocalHeap); - if(FreeHeap) - { - Fail("Failed to call LocalFree API, " - "error code=%u\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.cpp new file mode 100644 index 0000000000..d9c062e761 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.cpp @@ -0,0 +1,49 @@ +// 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: LocalFree.c +** +** Purpose: Positive test the LocalFree API. +** Call LocalFree to free a specified local memory object +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + HLOCAL LocalHeap; + HLOCAL FreeHeap; + int err; + const SIZE_T heapSize = 64; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*Allocate the specified number of bytes from the heap*/ + /*with zero ad the allocation attribute*/ + LocalHeap = LocalAlloc(0, heapSize); + if(!LocalHeap) + { + Fail("\nFailed to call LocalAlloc API, " + "error code=%u\n", GetLastError()); + } + + /*Free the allocated local heap memory*/ + FreeHeap = LocalFree(LocalHeap); + if(FreeHeap) + { + Fail("Failed to call LocalFree API, " + "error code=%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/CMakeLists.txt index ac7a11a05f..e087b08ad7 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - LocalFree.c + LocalFree.cpp ) add_executable(paltest_localfree_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.c b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.c deleted file mode 100644 index 4d4567dc3f..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.c +++ /dev/null @@ -1,39 +0,0 @@ -// 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: LocalFree.c -** -** Purpose: Positive test the LocalFree API. -** call LocalFree by passing NULL as local memory -** object handle -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - HLOCAL FreeHeap; - int err; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*call LocalFree by passing NULL as local memory object handle*/ - FreeHeap = LocalFree(NULL); - if(FreeHeap) - { - Fail("Failed to call LocalFree API, " - "error code=%u\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.cpp new file mode 100644 index 0000000000..4d4567dc3f --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.cpp @@ -0,0 +1,39 @@ +// 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: LocalFree.c +** +** Purpose: Positive test the LocalFree API. +** call LocalFree by passing NULL as local memory +** object handle +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + HLOCAL FreeHeap; + int err; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*call LocalFree by passing NULL as local memory object handle*/ + FreeHeap = LocalFree(NULL); + if(FreeHeap) + { + Fail("Failed to call LocalFree API, " + "error code=%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/CMakeLists.txt index 0af09480ef..1d08065b2a 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test1.c + test1.cpp ) add_executable(paltest_lockfile_test1 @@ -20,7 +20,7 @@ target_link_libraries(paltest_lockfile_test1 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_lockfile_test1_helper diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.c deleted file mode 100644 index 05b4b8451a..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.c +++ /dev/null @@ -1,86 +0,0 @@ -// 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: helper.c -** -** Purpose: A child process which will attempt to read and write to files -** which were locked in the parent. -** -** -**============================================================*/ - -#include - -#define BUF_SIZE 128 - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile; - int result = 0; - char DataBuffer[BUF_SIZE]; - DWORD BytesRead, BytesWritten; - char fileName[] = "testfile.tmp"; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open the same file that the parent has opened and locked */ - TheFile = CreateFile(fileName, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile.",fileName); - } - - /* Attempt to Read 5 bytes from this file. Since it is locked, this - should fail. - */ - - if(ReadFile(TheFile, DataBuffer, 5, &BytesRead, NULL) != 0) - { - Trace("ERROR: ReadFile should have failed! It was called on " - "a locked file. But, it returned non-zero indicating success."); - result = 1; - } - - /* Attempt to Write 5 bytes to this file. Since it is locked this should - fail. - */ - - memset(DataBuffer,'X',BUF_SIZE); - - if(WriteFile(TheFile, DataBuffer, 5,&BytesWritten, NULL) != 0) - { - Trace("ERROR: WriteFile should have failed! It was called on " - "a locked file. But, it returned non-zero indicating success."); - result = 1; - } - - /* Check to ensure that the number of Bytes read/written is still 0, - since nothing should have been read or written. - */ - - if(BytesRead != 0 || BytesWritten !=0) - { - Trace("ERROR: The number of bytes read is %d and written is %d. " - "These should both be 0, as the file was locked.", - BytesRead,BytesWritten); - result = 1; - } - - PAL_TerminateEx(result); - return result; -} - - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.cpp new file mode 100644 index 0000000000..05b4b8451a --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.cpp @@ -0,0 +1,86 @@ +// 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: helper.c +** +** Purpose: A child process which will attempt to read and write to files +** which were locked in the parent. +** +** +**============================================================*/ + +#include + +#define BUF_SIZE 128 + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile; + int result = 0; + char DataBuffer[BUF_SIZE]; + DWORD BytesRead, BytesWritten; + char fileName[] = "testfile.tmp"; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open the same file that the parent has opened and locked */ + TheFile = CreateFile(fileName, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile.",fileName); + } + + /* Attempt to Read 5 bytes from this file. Since it is locked, this + should fail. + */ + + if(ReadFile(TheFile, DataBuffer, 5, &BytesRead, NULL) != 0) + { + Trace("ERROR: ReadFile should have failed! It was called on " + "a locked file. But, it returned non-zero indicating success."); + result = 1; + } + + /* Attempt to Write 5 bytes to this file. Since it is locked this should + fail. + */ + + memset(DataBuffer,'X',BUF_SIZE); + + if(WriteFile(TheFile, DataBuffer, 5,&BytesWritten, NULL) != 0) + { + Trace("ERROR: WriteFile should have failed! It was called on " + "a locked file. But, it returned non-zero indicating success."); + result = 1; + } + + /* Check to ensure that the number of Bytes read/written is still 0, + since nothing should have been read or written. + */ + + if(BytesRead != 0 || BytesWritten !=0) + { + Trace("ERROR: The number of bytes read is %d and written is %d. " + "These should both be 0, as the file was locked.", + BytesRead,BytesWritten); + result = 1; + } + + PAL_TerminateEx(result); + return result; +} + + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.c deleted file mode 100644 index cee223ef81..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.c +++ /dev/null @@ -1,140 +0,0 @@ -// 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: test1.c -** -** Purpose: Open a file, and lock it from start to EOF. Then create a -** new process, which will attempt to Read and Write from the file. Check -** to ensure both of these operations fail. -** -** -**============================================================*/ - -#include -#include "../LockFile.h" - -#define HELPER "helper" - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE TheFile; - DWORD FileStart = 0; - DWORD FileEnd = 0; - const char lpBuffer[] = "This is a test file."; - DWORD bytesWritten; - BOOL bRc = TRUE; - char fileName[] = "testfile.tmp"; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Important to have sharing enabled, or there is no need for the lock. */ - TheFile = CreateFile(fileName, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile.",fileName); - } - - bRc = WriteFile(TheFile, - lpBuffer, - (DWORD)sizeof(lpBuffer), - &bytesWritten, - NULL); - - if(!bRc) - { - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - - Fail("ERROR: Could not write to file '%s' with WriteFile.",fileName); - } - else if(bytesWritten != (DWORD)sizeof(lpBuffer)) - { - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - - Fail("ERROR: Could not write the correct number of bytes to the " - "file '%s' with WriteFile.",fileName); - } - - /* Find the value for the End of the file */ - FileEnd = SetFilePointer(TheFile,0,NULL,FILE_END); - - if(FileEnd == INVALID_SET_FILE_POINTER) - { - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - - Fail("ERROR: Could not set the file pointer to the end of the file " - "using SetFilePointer. It returned INVALID_SET_FILE_POINTER."); - } - - /* Lock the file from Start to EOF */ - - if(LockFile(TheFile, FileStart, 0, FileEnd, 0) == 0) - { - Trace("ERROR: LockFile failed. GetLastError returns %d.", - GetLastError()); - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Launch another process, which will attempt to read and write from - the locked file. - - If the helper program returns 1, then the test fails. More - specific errors are given by the Helper file itself. - */ - if(RunHelper(HELPER)) - { - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - - Fail("ERROR: The Helper program determined that the file was not " - "locked properly by LockFile."); - } - - if(UnlockFile(TheFile, FileStart, 0, FileEnd, 0) == 0) - { - Trace("ERROR: UnlockFile failed. GetLastError returns %d.", - GetLastError()); - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.cpp new file mode 100644 index 0000000000..cee223ef81 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.cpp @@ -0,0 +1,140 @@ +// 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: test1.c +** +** Purpose: Open a file, and lock it from start to EOF. Then create a +** new process, which will attempt to Read and Write from the file. Check +** to ensure both of these operations fail. +** +** +**============================================================*/ + +#include +#include "../LockFile.h" + +#define HELPER "helper" + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE TheFile; + DWORD FileStart = 0; + DWORD FileEnd = 0; + const char lpBuffer[] = "This is a test file."; + DWORD bytesWritten; + BOOL bRc = TRUE; + char fileName[] = "testfile.tmp"; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Important to have sharing enabled, or there is no need for the lock. */ + TheFile = CreateFile(fileName, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile.",fileName); + } + + bRc = WriteFile(TheFile, + lpBuffer, + (DWORD)sizeof(lpBuffer), + &bytesWritten, + NULL); + + if(!bRc) + { + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + + Fail("ERROR: Could not write to file '%s' with WriteFile.",fileName); + } + else if(bytesWritten != (DWORD)sizeof(lpBuffer)) + { + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + + Fail("ERROR: Could not write the correct number of bytes to the " + "file '%s' with WriteFile.",fileName); + } + + /* Find the value for the End of the file */ + FileEnd = SetFilePointer(TheFile,0,NULL,FILE_END); + + if(FileEnd == INVALID_SET_FILE_POINTER) + { + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + + Fail("ERROR: Could not set the file pointer to the end of the file " + "using SetFilePointer. It returned INVALID_SET_FILE_POINTER."); + } + + /* Lock the file from Start to EOF */ + + if(LockFile(TheFile, FileStart, 0, FileEnd, 0) == 0) + { + Trace("ERROR: LockFile failed. GetLastError returns %d.", + GetLastError()); + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Launch another process, which will attempt to read and write from + the locked file. + + If the helper program returns 1, then the test fails. More + specific errors are given by the Helper file itself. + */ + if(RunHelper(HELPER)) + { + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + + Fail("ERROR: The Helper program determined that the file was not " + "locked properly by LockFile."); + } + + if(UnlockFile(TheFile, FileStart, 0, FileEnd, 0) == 0) + { + Trace("ERROR: UnlockFile failed. GetLastError returns %d.", + GetLastError()); + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/CMakeLists.txt index 157c517e62..ca5e5faed4 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_lockfile_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.c deleted file mode 100644 index 8aef130ef4..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.c +++ /dev/null @@ -1,94 +0,0 @@ -// 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: test2.c -** -** Purpose: Open a file, and lock it from start to EOF. Check to ensure -** the current process can still read and write from/to the file. -** -** -**============================================================*/ - -#include -#include "../LockFile.h" - -#define FILENAME "testfile.txt" - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE TheFile = NULL; - DWORD FileStart = 0; - DWORD FileEnd = 0; - DWORD BytesWritten = 0; - DWORD BytesRead = 0; - char WriteBuffer[] = "This is some test data."; - char DataBuffer[128]; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Call the helper function to Create a file, write 'WriteBuffer' to - the file, and lock the file. - */ - - FileEnd = strlen(WriteBuffer); - TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer, - FileStart, FileEnd); - - /* Move the file pointer to the start of the file */ - if(SetFilePointer(TheFile, 0, NULL, FILE_BEGIN) != 0) - { - Fail("ERROR: SetFilePointer failed to move the file pointer back " - "to the start of the file."); - } - - /* Attempt to Read 5 bytes from this file. Since the lock does not - affect the calling process, this should succeed. - */ - - if(ReadFile(TheFile, DataBuffer, 5, &BytesRead, NULL) == 0) - { - Fail("ERROR: ReadFile has failed. Attempted to read in 5 bytes from " - "the file '%s' after it had LockFile called upon it, but within " - "the same process.",FILENAME); - } - - if(strncmp(DataBuffer, WriteBuffer, 5) != 0) - { - Fail("ERROR: The data read in from ReadFile is not what should have " - "been written in the file. '%s' ",DataBuffer); - } - - /* Attempt to Write 5 bytes to this file. Since the lock does not affect - the calling process, this should succeed. - */ - - memset(WriteBuffer, 'X', strlen(WriteBuffer)); - - if(WriteFile(TheFile, WriteBuffer, 5,&BytesWritten, NULL) == 0) - { - Fail("ERROR: WriteFile has failed. Attempted to write 5 bytes to " - "the file '%s' after it had LockFile called upon it, but within " - "the same process.",FILENAME); - } - - if(UnlockFile(TheFile, FileStart, 0, FileEnd, 0) == 0) - { - Fail("ERROR: UnlockFile failed. GetLastError returns %d.", - GetLastError()); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.cpp new file mode 100644 index 0000000000..8aef130ef4 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.cpp @@ -0,0 +1,94 @@ +// 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: test2.c +** +** Purpose: Open a file, and lock it from start to EOF. Check to ensure +** the current process can still read and write from/to the file. +** +** +**============================================================*/ + +#include +#include "../LockFile.h" + +#define FILENAME "testfile.txt" + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE TheFile = NULL; + DWORD FileStart = 0; + DWORD FileEnd = 0; + DWORD BytesWritten = 0; + DWORD BytesRead = 0; + char WriteBuffer[] = "This is some test data."; + char DataBuffer[128]; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Call the helper function to Create a file, write 'WriteBuffer' to + the file, and lock the file. + */ + + FileEnd = strlen(WriteBuffer); + TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer, + FileStart, FileEnd); + + /* Move the file pointer to the start of the file */ + if(SetFilePointer(TheFile, 0, NULL, FILE_BEGIN) != 0) + { + Fail("ERROR: SetFilePointer failed to move the file pointer back " + "to the start of the file."); + } + + /* Attempt to Read 5 bytes from this file. Since the lock does not + affect the calling process, this should succeed. + */ + + if(ReadFile(TheFile, DataBuffer, 5, &BytesRead, NULL) == 0) + { + Fail("ERROR: ReadFile has failed. Attempted to read in 5 bytes from " + "the file '%s' after it had LockFile called upon it, but within " + "the same process.",FILENAME); + } + + if(strncmp(DataBuffer, WriteBuffer, 5) != 0) + { + Fail("ERROR: The data read in from ReadFile is not what should have " + "been written in the file. '%s' ",DataBuffer); + } + + /* Attempt to Write 5 bytes to this file. Since the lock does not affect + the calling process, this should succeed. + */ + + memset(WriteBuffer, 'X', strlen(WriteBuffer)); + + if(WriteFile(TheFile, WriteBuffer, 5,&BytesWritten, NULL) == 0) + { + Fail("ERROR: WriteFile has failed. Attempted to write 5 bytes to " + "the file '%s' after it had LockFile called upon it, but within " + "the same process.",FILENAME); + } + + if(UnlockFile(TheFile, FileStart, 0, FileEnd, 0) == 0) + { + Fail("ERROR: UnlockFile failed. GetLastError returns %d.", + GetLastError()); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/CMakeLists.txt index 69516de69b..117c715084 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test3.c + test3.cpp ) add_executable(paltest_lockfile_test3 @@ -20,7 +20,7 @@ target_link_libraries(paltest_lockfile_test3 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_lockfile_test3_helper diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.c deleted file mode 100644 index 079417fce8..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.c +++ /dev/null @@ -1,102 +0,0 @@ -// 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: helper.c -** -** Purpose: A child process which will attempt to read and write to files -** which were locked in the parent. -** -** -**============================================================*/ - -#include - -#define FILENAME "testfile.txt" -#define BUF_SIZE 128 - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile; - int result = 0; - char DataBuffer[BUF_SIZE]; - DWORD BytesRead, BytesWritten; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open the same file that the parent has opened and locked */ - TheFile = CreateFile(FILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returns %d.",FILENAME,GetLastError()); - } - - /* Attempt to Read the first 3 bytes from this file. - Since it is unlocked, this should work properly. - */ - - if(ReadFile(TheFile, DataBuffer, 3, &BytesRead, NULL) == 0) - { - Trace("ERROR: ReadFile should have succeeded in reading the first " - "three bytes of the file, as these bytes were not locked. " - "GetLastError() returned %d.",GetLastError()); - result = 1; - } - - /* Now, read the next 10 bytes, which should be locked. Ensure that - ReadFile fails. - */ - - if(ReadFile(TheFile, DataBuffer,10, &BytesRead, NULL) != 0) - { - Trace("ERROR: ReadFile should have failed when attempting to read in " - "bytes between StartOfFile+3 and EndOfFile-3."); - result = 1; - } - - /* Attempt to Write 10 bytes to this file. Since it is locked this should - fail. - */ - - memset(DataBuffer,'X',BUF_SIZE); - - if(WriteFile(TheFile, DataBuffer, 10,&BytesWritten, NULL) != 0) - { - Trace("ERROR: WriteFile should have failed when attempting to write " - "bytes between StartOfFile+3 and EOF-3."); - result = 1; - } - - - /* Move the FilePointer to the EOF-3, where the lock ends */ - if(SetFilePointer(TheFile,-3,NULL,FILE_END) == INVALID_SET_FILE_POINTER) - { - Fail("ERROR: Could not set the file pointer to the EOF-3 " - "using SetFilePointer. It returned INVALID_SET_FILE_POINTER."); - } - - /* Attempt to write to those 3 unlocked bytes on the end of the file */ - if(WriteFile(TheFile, DataBuffer, 3,&BytesWritten, NULL) == 0) - { - Trace("ERROR: WriteFile should have succeeded when attempting " - "to write the last three bytes of the file, as they were not " - "locked. GetLastError() returned %d.",GetLastError()); - result = 1; - } - - PAL_TerminateEx(result); - return result; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.cpp new file mode 100644 index 0000000000..079417fce8 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.cpp @@ -0,0 +1,102 @@ +// 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: helper.c +** +** Purpose: A child process which will attempt to read and write to files +** which were locked in the parent. +** +** +**============================================================*/ + +#include + +#define FILENAME "testfile.txt" +#define BUF_SIZE 128 + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile; + int result = 0; + char DataBuffer[BUF_SIZE]; + DWORD BytesRead, BytesWritten; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open the same file that the parent has opened and locked */ + TheFile = CreateFile(FILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returns %d.",FILENAME,GetLastError()); + } + + /* Attempt to Read the first 3 bytes from this file. + Since it is unlocked, this should work properly. + */ + + if(ReadFile(TheFile, DataBuffer, 3, &BytesRead, NULL) == 0) + { + Trace("ERROR: ReadFile should have succeeded in reading the first " + "three bytes of the file, as these bytes were not locked. " + "GetLastError() returned %d.",GetLastError()); + result = 1; + } + + /* Now, read the next 10 bytes, which should be locked. Ensure that + ReadFile fails. + */ + + if(ReadFile(TheFile, DataBuffer,10, &BytesRead, NULL) != 0) + { + Trace("ERROR: ReadFile should have failed when attempting to read in " + "bytes between StartOfFile+3 and EndOfFile-3."); + result = 1; + } + + /* Attempt to Write 10 bytes to this file. Since it is locked this should + fail. + */ + + memset(DataBuffer,'X',BUF_SIZE); + + if(WriteFile(TheFile, DataBuffer, 10,&BytesWritten, NULL) != 0) + { + Trace("ERROR: WriteFile should have failed when attempting to write " + "bytes between StartOfFile+3 and EOF-3."); + result = 1; + } + + + /* Move the FilePointer to the EOF-3, where the lock ends */ + if(SetFilePointer(TheFile,-3,NULL,FILE_END) == INVALID_SET_FILE_POINTER) + { + Fail("ERROR: Could not set the file pointer to the EOF-3 " + "using SetFilePointer. It returned INVALID_SET_FILE_POINTER."); + } + + /* Attempt to write to those 3 unlocked bytes on the end of the file */ + if(WriteFile(TheFile, DataBuffer, 3,&BytesWritten, NULL) == 0) + { + Trace("ERROR: WriteFile should have succeeded when attempting " + "to write the last three bytes of the file, as they were not " + "locked. GetLastError() returned %d.",GetLastError()); + result = 1; + } + + PAL_TerminateEx(result); + return result; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.c deleted file mode 100644 index 78662c5685..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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: test3.c -** -** Purpose: Open a file, lock a region in the middle. Create a new process -** and attempt to read and write directly before and after that region, which -** should succeed. Also, check to see that reading/writing in the locked -** region fails. -** -** -**============================================================*/ - -#include -#include "../LockFile.h" - -#define HELPER "helper" -#define FILENAME "testfile.txt" - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE TheFile = NULL; - DWORD FileStart = 0; - DWORD FileEnd = 0; - char* WriteBuffer = "12345678901234567890123456"; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Call the helper function to Create a file, write 'WriteBuffer' to - the file, and lock the file. - */ - - FileEnd = strlen(WriteBuffer); - TheFile = CreateAndLockFile(TheFile,FILENAME, WriteBuffer, - FileStart+3, FileEnd-6); - - - /* Launch another process, which will attempt to read and write from - the locked file. - - If the helper program returns 1, then the test fails. More - specific errors are given by the Helper file itself. - */ - if(RunHelper(HELPER)) - { - Fail("ERROR: The Helper program determined that the file was not " - "locked properly by LockFile."); - } - - if(UnlockFile(TheFile, FileStart+3, 0, FileEnd-6, 0) == 0) - { - Fail("ERROR: UnlockFile failed. GetLastError returns %d.", - GetLastError()); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file. " - "GetLastError() returned %d.",GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.cpp new file mode 100644 index 0000000000..78662c5685 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.cpp @@ -0,0 +1,71 @@ +// 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: test3.c +** +** Purpose: Open a file, lock a region in the middle. Create a new process +** and attempt to read and write directly before and after that region, which +** should succeed. Also, check to see that reading/writing in the locked +** region fails. +** +** +**============================================================*/ + +#include +#include "../LockFile.h" + +#define HELPER "helper" +#define FILENAME "testfile.txt" + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE TheFile = NULL; + DWORD FileStart = 0; + DWORD FileEnd = 0; + char* WriteBuffer = "12345678901234567890123456"; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Call the helper function to Create a file, write 'WriteBuffer' to + the file, and lock the file. + */ + + FileEnd = strlen(WriteBuffer); + TheFile = CreateAndLockFile(TheFile,FILENAME, WriteBuffer, + FileStart+3, FileEnd-6); + + + /* Launch another process, which will attempt to read and write from + the locked file. + + If the helper program returns 1, then the test fails. More + specific errors are given by the Helper file itself. + */ + if(RunHelper(HELPER)) + { + Fail("ERROR: The Helper program determined that the file was not " + "locked properly by LockFile."); + } + + if(UnlockFile(TheFile, FileStart+3, 0, FileEnd-6, 0) == 0) + { + Fail("ERROR: UnlockFile failed. GetLastError returns %d.", + GetLastError()); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file. " + "GetLastError() returned %d.",GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/CMakeLists.txt index fb8f6745d4..aee1b1a0be 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_lockfile_test4 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.c deleted file mode 100644 index f5cd359fb5..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.c +++ /dev/null @@ -1,231 +0,0 @@ -// 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: test4.c -** -** Purpose: -** - Attempt to call LockFile on a file without GENERIC_READ or -** GENERIC_WRITE (this should fail) -** - Attempt to overlap two locks, this should fail. -** -** -**============================================================*/ - -#include - -char fileName[] = "testfile.tmp"; - -void OverlapTest() -{ - HANDLE TheFile = NULL; - DWORD FileStart = 0; - const char lpBuffer[] = "This is a test file."; - DWORD bytesWritten; - BOOL bRc = TRUE; - - TheFile = CreateFile(fileName, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.",fileName,GetLastError()); - } - - bRc = WriteFile(TheFile, - lpBuffer, - (DWORD)sizeof(lpBuffer), - &bytesWritten, - NULL); - - if(!bRc) - { - Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - - } - else if(bytesWritten != (DWORD)sizeof(lpBuffer)) - { - Trace("ERROR: Could not write the correct number of bytes to the " - "file '%s' with WriteFile.",fileName); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Lock the First 5 bytes of the File */ - - if(LockFile(TheFile, FileStart, 0, 5, 0) == 0) - { - Trace("ERROR: LockFile failed in Overlap test. " - "GetLastError returns %d.", - GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Lock from Byte 2 until 7 -- this overlaps and should return failure. */ - if(LockFile(TheFile,FileStart+2, 0, 5, 0) != 0) - { - Trace("ERROR: LockFile returned success when it was overlapped on " - "an already locked region of the file."); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Unlock the file */ - if(UnlockFile(TheFile, FileStart, 0, 5, 0) == 0) - { - Trace("ERROR: UnlockFile failed in Overlap test. GetLastError " - "returns %d.",GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Close the File */ - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file in the Overlap " - "test. GetLastError() returned %d.",GetLastError()); - } -} - -void FlagsTest(DWORD TheFlags, int ExpectedResult) -{ - HANDLE TheFile = NULL; - DWORD FileStart = 0; - int result; - - TheFile = CreateFile(fileName, - TheFlags, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.",fileName,GetLastError()); - } - - /* Lock the First 5 bytes of the File. The result of this depends - upon which flags were set with the CreateFile. - */ - - result = LockFile(TheFile, FileStart, 0, 5, 0); - - /* If the expected result is 1, check to ensure the result is non-zero, - as non-zero is returned on success - */ - if(ExpectedResult == 1) - { - if(result == 0) - { - Trace("ERROR: LockFile returned zero when the expected result " - "was non-zero. It was passed the flag value %d.", - TheFlags); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - } - /* If the expected result is 0, check to ensure the result is 0 */ - else - { - if(result != 0) - { - Trace("ERROR: LockFile returned %d when the expected result " - "was zero. It was passed the flag value %d.", - result, TheFlags); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - } - - /* Only unlock the file if we expect it to be successfully locked */ - if(ExpectedResult) - { - if(UnlockFile(TheFile,FileStart,0, 5, 0) == 0) - { - Fail("ERROR: UnlockFile failed in the Flags Test. GetLastError() " - "returned %d.",GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - } - - /* Close the File */ - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file in the Flags " - "test. GetLastError() returned %d.",GetLastError()); - } -} - -int __cdecl main(int argc, char *argv[]) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* This test opens a file, then calls lock twice, overlapping the - regions and checking to ensure that this causes an error. - */ - OverlapTest(); - - /* Test that LockFile fails if no flags are set */ - FlagsTest(0,0); - - /* Test that LockFile passes if only GENERIC_READ is set */ - FlagsTest(GENERIC_READ,1); - - /* Test that LockFile passes if only GENERIC_WRITE is set */ - FlagsTest(GENERIC_WRITE,1); - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.cpp new file mode 100644 index 0000000000..f5cd359fb5 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.cpp @@ -0,0 +1,231 @@ +// 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: test4.c +** +** Purpose: +** - Attempt to call LockFile on a file without GENERIC_READ or +** GENERIC_WRITE (this should fail) +** - Attempt to overlap two locks, this should fail. +** +** +**============================================================*/ + +#include + +char fileName[] = "testfile.tmp"; + +void OverlapTest() +{ + HANDLE TheFile = NULL; + DWORD FileStart = 0; + const char lpBuffer[] = "This is a test file."; + DWORD bytesWritten; + BOOL bRc = TRUE; + + TheFile = CreateFile(fileName, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.",fileName,GetLastError()); + } + + bRc = WriteFile(TheFile, + lpBuffer, + (DWORD)sizeof(lpBuffer), + &bytesWritten, + NULL); + + if(!bRc) + { + Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + + } + else if(bytesWritten != (DWORD)sizeof(lpBuffer)) + { + Trace("ERROR: Could not write the correct number of bytes to the " + "file '%s' with WriteFile.",fileName); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Lock the First 5 bytes of the File */ + + if(LockFile(TheFile, FileStart, 0, 5, 0) == 0) + { + Trace("ERROR: LockFile failed in Overlap test. " + "GetLastError returns %d.", + GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Lock from Byte 2 until 7 -- this overlaps and should return failure. */ + if(LockFile(TheFile,FileStart+2, 0, 5, 0) != 0) + { + Trace("ERROR: LockFile returned success when it was overlapped on " + "an already locked region of the file."); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Unlock the file */ + if(UnlockFile(TheFile, FileStart, 0, 5, 0) == 0) + { + Trace("ERROR: UnlockFile failed in Overlap test. GetLastError " + "returns %d.",GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Close the File */ + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file in the Overlap " + "test. GetLastError() returned %d.",GetLastError()); + } +} + +void FlagsTest(DWORD TheFlags, int ExpectedResult) +{ + HANDLE TheFile = NULL; + DWORD FileStart = 0; + int result; + + TheFile = CreateFile(fileName, + TheFlags, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.",fileName,GetLastError()); + } + + /* Lock the First 5 bytes of the File. The result of this depends + upon which flags were set with the CreateFile. + */ + + result = LockFile(TheFile, FileStart, 0, 5, 0); + + /* If the expected result is 1, check to ensure the result is non-zero, + as non-zero is returned on success + */ + if(ExpectedResult == 1) + { + if(result == 0) + { + Trace("ERROR: LockFile returned zero when the expected result " + "was non-zero. It was passed the flag value %d.", + TheFlags); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + } + /* If the expected result is 0, check to ensure the result is 0 */ + else + { + if(result != 0) + { + Trace("ERROR: LockFile returned %d when the expected result " + "was zero. It was passed the flag value %d.", + result, TheFlags); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + } + + /* Only unlock the file if we expect it to be successfully locked */ + if(ExpectedResult) + { + if(UnlockFile(TheFile,FileStart,0, 5, 0) == 0) + { + Fail("ERROR: UnlockFile failed in the Flags Test. GetLastError() " + "returned %d.",GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + } + + /* Close the File */ + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file in the Flags " + "test. GetLastError() returned %d.",GetLastError()); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* This test opens a file, then calls lock twice, overlapping the + regions and checking to ensure that this causes an error. + */ + OverlapTest(); + + /* Test that LockFile fails if no flags are set */ + FlagsTest(0,0); + + /* Test that LockFile passes if only GENERIC_READ is set */ + FlagsTest(GENERIC_READ,1); + + /* Test that LockFile passes if only GENERIC_WRITE is set */ + FlagsTest(GENERIC_WRITE,1); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/CMakeLists.txt index cc4548a6f0..70e3db4561 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test5.c + test5.cpp ) add_executable(paltest_lockfile_test5 @@ -20,7 +20,7 @@ target_link_libraries(paltest_lockfile_test5 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_lockfile_test5_helper diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.c deleted file mode 100644 index 1fc9b1a9a5..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.c +++ /dev/null @@ -1,122 +0,0 @@ -// 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: helper.c -** -** Purpose: A child process which will attempt to read and write to files -** which were locked in the parent. It will also lock another region of the -** same file. -** -** -**============================================================*/ - -#include -#include "../LockFile.h" - -#define FILENAME "testfile.txt" -#define WAITFILENAME "waitfile" -#define BUF_SIZE 128 - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile, WaitFile; - int result = 0; - char DataBuffer[BUF_SIZE]; - DWORD BytesRead; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open the same file that the parent has opened and locked */ - TheFile = CreateFile(FILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR: Could not open file '%s' with CreateFile.",FILENAME); - result = 1; - } - - /* Open up the WaitFile that we're using for IPC */ - WaitFile = CreateFile(WAITFILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (WaitFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.",WAITFILENAME,GetLastError()); - result = 1; - } - - /* Lock the same file that the parent process locked, but the child - locks bytes 11 through 20 - */ - - if(LockFile(TheFile, 11, 0, 10, 0) == 0) - { - Trace("ERROR: LockFile failed in the child proccess. " - "GetLastError returns %d.", - GetLastError()); - result = 1; - } - - /* Check to ensure the parent lock is respected */ - if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0) - { - Trace("ERROR: ReadFile returned success when it should " - "have failed. Attempted to read the first 10 bytes " - "of a file which was locked by the parent process."); - result = 1; - } - - /* Check to ensure the lock put on by this proccess doesn't restrict - access - */ - - if(SetFilePointer(TheFile, 11, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - { - Trace("ERROR: SetFilePointer was unable to move the file pointer to " - "the 11th byte in the file, within the child proccess. " - "GetLastError() returned %d.",GetLastError()); - result = 1; - } - - if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0) - { - Trace("ERROR: ReadFile failed when attempting to read a section of " - "the file which was locked by the current process. It should " - "have been able to read this. GetLastError() returned %d.", - GetLastError()); - result = 1; - } - - // Sleep for a bit to give the parent a chance to block before we do. - Sleep(1000); - - /* Switch back to the parent, so it can check the child's locks */ - SignalAndBusyWait(WaitFile); - - if(UnlockFile(TheFile, 11, 0, 10, 0) == 0) - { - Fail("ERROR: Failed to Unlock bytes 11-20 in the file. " - "GetLastError returned %d.",GetLastError()); - } - - PAL_TerminateEx(result); - return result; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.cpp new file mode 100644 index 0000000000..1fc9b1a9a5 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.cpp @@ -0,0 +1,122 @@ +// 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: helper.c +** +** Purpose: A child process which will attempt to read and write to files +** which were locked in the parent. It will also lock another region of the +** same file. +** +** +**============================================================*/ + +#include +#include "../LockFile.h" + +#define FILENAME "testfile.txt" +#define WAITFILENAME "waitfile" +#define BUF_SIZE 128 + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile, WaitFile; + int result = 0; + char DataBuffer[BUF_SIZE]; + DWORD BytesRead; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open the same file that the parent has opened and locked */ + TheFile = CreateFile(FILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR: Could not open file '%s' with CreateFile.",FILENAME); + result = 1; + } + + /* Open up the WaitFile that we're using for IPC */ + WaitFile = CreateFile(WAITFILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (WaitFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.",WAITFILENAME,GetLastError()); + result = 1; + } + + /* Lock the same file that the parent process locked, but the child + locks bytes 11 through 20 + */ + + if(LockFile(TheFile, 11, 0, 10, 0) == 0) + { + Trace("ERROR: LockFile failed in the child proccess. " + "GetLastError returns %d.", + GetLastError()); + result = 1; + } + + /* Check to ensure the parent lock is respected */ + if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0) + { + Trace("ERROR: ReadFile returned success when it should " + "have failed. Attempted to read the first 10 bytes " + "of a file which was locked by the parent process."); + result = 1; + } + + /* Check to ensure the lock put on by this proccess doesn't restrict + access + */ + + if(SetFilePointer(TheFile, 11, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + { + Trace("ERROR: SetFilePointer was unable to move the file pointer to " + "the 11th byte in the file, within the child proccess. " + "GetLastError() returned %d.",GetLastError()); + result = 1; + } + + if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0) + { + Trace("ERROR: ReadFile failed when attempting to read a section of " + "the file which was locked by the current process. It should " + "have been able to read this. GetLastError() returned %d.", + GetLastError()); + result = 1; + } + + // Sleep for a bit to give the parent a chance to block before we do. + Sleep(1000); + + /* Switch back to the parent, so it can check the child's locks */ + SignalAndBusyWait(WaitFile); + + if(UnlockFile(TheFile, 11, 0, 10, 0) == 0) + { + Fail("ERROR: Failed to Unlock bytes 11-20 in the file. " + "GetLastError returned %d.",GetLastError()); + } + + PAL_TerminateEx(result); + return result; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.c deleted file mode 100644 index a02a3c5a49..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.c +++ /dev/null @@ -1,161 +0,0 @@ -// 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: test5.c -** -** Purpose: -** Have two processes obtain a lock on a single file, but in different -** regions of the file. Use Read/Write to ensure the locks are respected. -** This requires some IPC, which is done here with a crude busy wait on a -** file (waiting for the file size to change) to avoid too many more -** dependencies. -** -** -**============================================================*/ - -#include -#include "../LockFile.h" - -#define HELPER "helper" -#define FILENAME "testfile.txt" -#define WAITFILENAME "waitfile" -#define BUF_SIZE 128 - -int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile) -{ - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD ChildRetCode = 0; - DWORD ParentRetCode = 0; - DWORD BytesRead; - char DataBuffer[BUF_SIZE]; - - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - /* Load up the helper Process, and then Wait until it signals that it - is finished locking. - */ - if(!CreateProcess( NULL,Helper,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) - { - Fail("ERROR: CreateProcess failed to load executable '%s'.",Helper); - } - - SignalAndBusyWait(WaitFile); - - /* Now the child proccess has locked another section of the file, from - bytes 11 through 20. Let's check that the parent lock is still ignored - by the parent proccess and that the child's lock is respected. - */ - - if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0) - { - Trace("ERROR: ReadFile failed when attempting to read a section of " - "the file which was locked by the current process. It should " - "have been able to read this. GetLastError() returned %d.", - GetLastError()); - ParentRetCode = 1; - } - - SetFilePointer(TheFile, 11, 0, FILE_BEGIN); - - if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0) - { - Trace("ERROR: ReadFile returned success when it should " - "have failed. Attempted to read 10 bytes of the file which " - "were locked by the child."); - ParentRetCode = 1; - } - - /* We're finished testing. Let the child proccess know so it can clean - up, and the parent will wait until it is done. - */ - SignalFinish(WaitFile); - WaitForSingleObject(pi.hProcess,INFINITE); - - /* Get the return value from the helper process */ - if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0) - { - Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve " - "the exit code of the child process."); - } - - if(CloseHandle( pi.hProcess ) == 0) - { - Fail("ERROR: CloseHandle failed to close the process."); - } - - if(CloseHandle( pi.hThread ) == 0) - { - Fail("ERROR: CloseHandle failed to close the thread."); - } - - return (ChildRetCode || ParentRetCode); -} - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile = NULL; - HANDLE WaitFile = NULL; - char* WriteBuffer = "12345678901234567890123456"; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open up the file we'll be using for some crude IPC */ - WaitFile = CreateFile(WAITFILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (WaitFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.",WAITFILENAME,GetLastError()); - } - - /* Call the helper function to Create a file, write 'WriteBuffer' to - the file, and lock the file from bytes 0 to 10. - */ - TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer, - 0, 10); - - /* Run the test. Better errors are displayed by Trace throughout. */ - if(RunTest(HELPER, TheFile, WaitFile)) - { - Fail("ERROR: Attempting to have two processes lock different " - "sections of the same file has failed."); - } - - /* Unlock the first 10 bytes which were locked by the parent proccess */ - if(UnlockFile(TheFile, 0, 0, 10, 0) == 0) - { - Fail("ERROR: Failed to Unlock the first 10 bytes of the file. " - "GetLastError returned %d.",GetLastError()); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file used for " - "testing the locks. GetLastError() returns %d.",GetLastError()); - } - - if(CloseHandle(WaitFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the wait file. " - "GetLastError() returns %d.",GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.cpp new file mode 100644 index 0000000000..a02a3c5a49 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.cpp @@ -0,0 +1,161 @@ +// 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: test5.c +** +** Purpose: +** Have two processes obtain a lock on a single file, but in different +** regions of the file. Use Read/Write to ensure the locks are respected. +** This requires some IPC, which is done here with a crude busy wait on a +** file (waiting for the file size to change) to avoid too many more +** dependencies. +** +** +**============================================================*/ + +#include +#include "../LockFile.h" + +#define HELPER "helper" +#define FILENAME "testfile.txt" +#define WAITFILENAME "waitfile" +#define BUF_SIZE 128 + +int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile) +{ + STARTUPINFO si; + PROCESS_INFORMATION pi; + DWORD ChildRetCode = 0; + DWORD ParentRetCode = 0; + DWORD BytesRead; + char DataBuffer[BUF_SIZE]; + + + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + /* Load up the helper Process, and then Wait until it signals that it + is finished locking. + */ + if(!CreateProcess( NULL,Helper,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) + { + Fail("ERROR: CreateProcess failed to load executable '%s'.",Helper); + } + + SignalAndBusyWait(WaitFile); + + /* Now the child proccess has locked another section of the file, from + bytes 11 through 20. Let's check that the parent lock is still ignored + by the parent proccess and that the child's lock is respected. + */ + + if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0) + { + Trace("ERROR: ReadFile failed when attempting to read a section of " + "the file which was locked by the current process. It should " + "have been able to read this. GetLastError() returned %d.", + GetLastError()); + ParentRetCode = 1; + } + + SetFilePointer(TheFile, 11, 0, FILE_BEGIN); + + if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0) + { + Trace("ERROR: ReadFile returned success when it should " + "have failed. Attempted to read 10 bytes of the file which " + "were locked by the child."); + ParentRetCode = 1; + } + + /* We're finished testing. Let the child proccess know so it can clean + up, and the parent will wait until it is done. + */ + SignalFinish(WaitFile); + WaitForSingleObject(pi.hProcess,INFINITE); + + /* Get the return value from the helper process */ + if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0) + { + Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve " + "the exit code of the child process."); + } + + if(CloseHandle( pi.hProcess ) == 0) + { + Fail("ERROR: CloseHandle failed to close the process."); + } + + if(CloseHandle( pi.hThread ) == 0) + { + Fail("ERROR: CloseHandle failed to close the thread."); + } + + return (ChildRetCode || ParentRetCode); +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile = NULL; + HANDLE WaitFile = NULL; + char* WriteBuffer = "12345678901234567890123456"; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open up the file we'll be using for some crude IPC */ + WaitFile = CreateFile(WAITFILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (WaitFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.",WAITFILENAME,GetLastError()); + } + + /* Call the helper function to Create a file, write 'WriteBuffer' to + the file, and lock the file from bytes 0 to 10. + */ + TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer, + 0, 10); + + /* Run the test. Better errors are displayed by Trace throughout. */ + if(RunTest(HELPER, TheFile, WaitFile)) + { + Fail("ERROR: Attempting to have two processes lock different " + "sections of the same file has failed."); + } + + /* Unlock the first 10 bytes which were locked by the parent proccess */ + if(UnlockFile(TheFile, 0, 0, 10, 0) == 0) + { + Fail("ERROR: Failed to Unlock the first 10 bytes of the file. " + "GetLastError returned %d.",GetLastError()); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file used for " + "testing the locks. GetLastError() returns %d.",GetLastError()); + } + + if(CloseHandle(WaitFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the wait file. " + "GetLastError() returns %d.",GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/CMakeLists.txt index 5049977582..255ecbcc8d 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test6.c + test6.cpp ) add_executable(paltest_lockfile_test6 @@ -20,7 +20,7 @@ target_link_libraries(paltest_lockfile_test6 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_lockfile_test6_helper diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.c deleted file mode 100644 index 98112fc4a5..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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: helper.c -** -** Purpose: A child process which will attempt to append to the end of -** a locked file. -** -** -**============================================================*/ - -#include - -#define FILENAME "testfile.txt" -#define BUF_SIZE 128 - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile; - int result = 0; - char DataBuffer[BUF_SIZE]; - DWORD BytesWritten; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open the same file that the parent has opened and locked */ - TheFile = CreateFile(FILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returns %d.",FILENAME,GetLastError()); - result = -1; - } - - - /* Move the FilePointer to the EOF */ - if(SetFilePointer(TheFile,0,NULL,FILE_END) == INVALID_SET_FILE_POINTER) - { - Trace("ERROR: Could not set the file pointer to the EOF " - "using SetFilePointer. It returned INVALID_SET_FILE_POINTER."); - result = -1; - } - - memset(DataBuffer, 'X', BUF_SIZE); - - /* Return the result of WriteFile -- we want to check in the parent that - this was successful. Note: WriteFile doesn't get run if something - failed during the setup, in that case -1 is returned. - */ - - if(result != -1) - { - result = WriteFile(TheFile, DataBuffer, 3,&BytesWritten, NULL); - } - - PAL_TerminateEx(result); - return result; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.cpp new file mode 100644 index 0000000000..98112fc4a5 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.cpp @@ -0,0 +1,71 @@ +// 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: helper.c +** +** Purpose: A child process which will attempt to append to the end of +** a locked file. +** +** +**============================================================*/ + +#include + +#define FILENAME "testfile.txt" +#define BUF_SIZE 128 + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile; + int result = 0; + char DataBuffer[BUF_SIZE]; + DWORD BytesWritten; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open the same file that the parent has opened and locked */ + TheFile = CreateFile(FILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returns %d.",FILENAME,GetLastError()); + result = -1; + } + + + /* Move the FilePointer to the EOF */ + if(SetFilePointer(TheFile,0,NULL,FILE_END) == INVALID_SET_FILE_POINTER) + { + Trace("ERROR: Could not set the file pointer to the EOF " + "using SetFilePointer. It returned INVALID_SET_FILE_POINTER."); + result = -1; + } + + memset(DataBuffer, 'X', BUF_SIZE); + + /* Return the result of WriteFile -- we want to check in the parent that + this was successful. Note: WriteFile doesn't get run if something + failed during the setup, in that case -1 is returned. + */ + + if(result != -1) + { + result = WriteFile(TheFile, DataBuffer, 3,&BytesWritten, NULL); + } + + PAL_TerminateEx(result); + return result; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.c deleted file mode 100644 index ba01b9710a..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.c +++ /dev/null @@ -1,146 +0,0 @@ -// 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: test6.c -** -** Purpose: -** Append to a file which is locked until the end of the file, and -** append to a file which is locked past the end of the file. (The first -** should succeed, while the second should fail) -** -** -**============================================================*/ - -#include -#include "../LockFile.h" - -#define HELPER "helper" -#define FILENAME "testfile.txt" - -/* This test checks that you can append to a file which is locked from Start - to EOF. -*/ -void Test1() -{ - HANDLE TheFile = NULL; - DWORD FileStart = 0; - DWORD FileEnd = 0; - int result; - char* WriteBuffer = "12345678901234567890123456"; - - /* Call the helper function to Create a file, write 'WriteBuffer' to - the file, and lock the file. - */ - - FileEnd = strlen(WriteBuffer); - TheFile = CreateAndLockFile(TheFile,FILENAME, WriteBuffer, - FileStart, FileEnd); - - - /* - Launch another proccess which will attempt to append to the - end of the file. Note: This returns -1 if the setup failed in some way. - */ - - result = RunHelper(HELPER); - - if(result == -1) - { - Fail("ERROR: The Helper program failed in setting up the " - "test, so it could never be run."); - } - else if(result == 0) - { - Fail("ERROR: Failed to append to the file which was Locked from " - "start until EOF. Should have been able to append to this " - "file still. GetLastError() is %d.",GetLastError()); - } - - if(UnlockFile(TheFile, FileStart, 0, FileEnd, 0) == 0) - { - Fail("ERROR: UnlockFile failed. GetLastError returns %d.", - GetLastError()); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file. " - "GetLastError() returned %d.",GetLastError()); - } - -} - -/* This test checks that you can't append to a file which is locked beyond - EOF. -*/ -void Test2() -{ - HANDLE TheFile = NULL; - DWORD FileStart = 0; - DWORD FileEnd = 0; - int result; - char* WriteBuffer = "12345678901234567890123456"; - - /* Call the helper function to Create a file, write 'WriteBuffer' to - the file, and lock the file. - */ - - FileEnd = strlen(WriteBuffer); - TheFile = CreateAndLockFile(TheFile,FILENAME, WriteBuffer, - FileStart, FileEnd+20); - - - /* - Launch another proccess which will attempt to append to the - end of the file. - */ - - result = RunHelper(HELPER); - - if(result == -1) - { - Fail("ERROR: The Helper program failed in setting up the " - "test, so it could never be run."); - } - else if(result > 0) - { - Fail("ERROR: The Helper program successfully appended to the " - "end of the file, even though it was locked beyond EOF. This " - "should have failed."); - } - - if(UnlockFile(TheFile, FileStart, 0, FileEnd+20, 0) == 0) - { - Fail("ERROR: UnlockFile failed. GetLastError returns %d.", - GetLastError()); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file. " - "GetLastError() returned %d.",GetLastError()); - } - -} - - -int __cdecl main(int argc, char *argv[]) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Test a file which is locked until EOF to see if you can append */ - Test1(); - - /* Test a file which is locked past EOF to ensure you can't append */ - Test2(); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.cpp new file mode 100644 index 0000000000..ba01b9710a --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.cpp @@ -0,0 +1,146 @@ +// 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: test6.c +** +** Purpose: +** Append to a file which is locked until the end of the file, and +** append to a file which is locked past the end of the file. (The first +** should succeed, while the second should fail) +** +** +**============================================================*/ + +#include +#include "../LockFile.h" + +#define HELPER "helper" +#define FILENAME "testfile.txt" + +/* This test checks that you can append to a file which is locked from Start + to EOF. +*/ +void Test1() +{ + HANDLE TheFile = NULL; + DWORD FileStart = 0; + DWORD FileEnd = 0; + int result; + char* WriteBuffer = "12345678901234567890123456"; + + /* Call the helper function to Create a file, write 'WriteBuffer' to + the file, and lock the file. + */ + + FileEnd = strlen(WriteBuffer); + TheFile = CreateAndLockFile(TheFile,FILENAME, WriteBuffer, + FileStart, FileEnd); + + + /* + Launch another proccess which will attempt to append to the + end of the file. Note: This returns -1 if the setup failed in some way. + */ + + result = RunHelper(HELPER); + + if(result == -1) + { + Fail("ERROR: The Helper program failed in setting up the " + "test, so it could never be run."); + } + else if(result == 0) + { + Fail("ERROR: Failed to append to the file which was Locked from " + "start until EOF. Should have been able to append to this " + "file still. GetLastError() is %d.",GetLastError()); + } + + if(UnlockFile(TheFile, FileStart, 0, FileEnd, 0) == 0) + { + Fail("ERROR: UnlockFile failed. GetLastError returns %d.", + GetLastError()); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file. " + "GetLastError() returned %d.",GetLastError()); + } + +} + +/* This test checks that you can't append to a file which is locked beyond + EOF. +*/ +void Test2() +{ + HANDLE TheFile = NULL; + DWORD FileStart = 0; + DWORD FileEnd = 0; + int result; + char* WriteBuffer = "12345678901234567890123456"; + + /* Call the helper function to Create a file, write 'WriteBuffer' to + the file, and lock the file. + */ + + FileEnd = strlen(WriteBuffer); + TheFile = CreateAndLockFile(TheFile,FILENAME, WriteBuffer, + FileStart, FileEnd+20); + + + /* + Launch another proccess which will attempt to append to the + end of the file. + */ + + result = RunHelper(HELPER); + + if(result == -1) + { + Fail("ERROR: The Helper program failed in setting up the " + "test, so it could never be run."); + } + else if(result > 0) + { + Fail("ERROR: The Helper program successfully appended to the " + "end of the file, even though it was locked beyond EOF. This " + "should have failed."); + } + + if(UnlockFile(TheFile, FileStart, 0, FileEnd+20, 0) == 0) + { + Fail("ERROR: UnlockFile failed. GetLastError returns %d.", + GetLastError()); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file. " + "GetLastError() returned %d.",GetLastError()); + } + +} + + +int __cdecl main(int argc, char *argv[]) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Test a file which is locked until EOF to see if you can append */ + Test1(); + + /* Test a file which is locked past EOF to ensure you can't append */ + Test2(); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/CMakeLists.txt index e8434cc787..68a5b9f659 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_lockfile_test7 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.c deleted file mode 100644 index c572a6e653..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.c +++ /dev/null @@ -1,135 +0,0 @@ -// 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: test7.c -** -** Purpose: Try locking an invalid HANDLE and a NULL Handle. -** -** -**============================================================*/ - -#include -#include "../LockFile.h" - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE TheFile = NULL; - DWORD FileEnd = 0; - const char lpBuffer[] = "This is a test file."; - DWORD bytesWritten; - BOOL bRc = TRUE; - char fileName[] = "testfile.tmp"; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - TheFile = CreateFile(fileName, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.",fileName,GetLastError()); - } - - bRc = WriteFile( - TheFile, // handle to file - lpBuffer, // data buffer - (DWORD)sizeof(lpBuffer), // number of bytes to write - &bytesWritten, // number of bytes written - NULL // overlapped buffer - ); - - if(!bRc) - { - Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - - } - else if(bytesWritten != (DWORD)sizeof(lpBuffer)) - { - Trace("ERROR: Could not write the correct number of bytes to the " - "file '%s' with WriteFile.",fileName); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Attempt to lock a region of this file beyond EOF, to ensure this - doesn't cause an error. - */ - FileEnd = SetFilePointer(TheFile, 0, NULL, FILE_END); - - if(LockFile(TheFile, FileEnd+10, 0, 10, 0) == 0) - { - Trace("ERROR: LockFile failed when attempting to lock a region " - "beyond the EOF. GetLastError() returned %d.",GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - if(UnlockFile(TheFile, FileEnd+10, 0, 10, 0) == 0) - { - Trace("ERROR: UnlockFile failed when attempting to unlock the region " - "which was locked beyond the EOF. GetLastError returned %d.", - GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: Failed to call CloseHandle. GetLastError " - "returned %d.",GetLastError()); - } - - /* Attempt to call Lockfile on an HANDLE which has been closed. This - should fail. - */ - if(LockFile(TheFile, 0, 0, 5, 0) != 0) - { - Fail("ERROR: Attempted to Lock an invalid handle and the function " - "returned success."); - } - - /* Attempt to call Lockfile by passing it NULL for a handle. This should - fail. - */ - - if(LockFile(NULL, 0, 0, 5, 0) != 0) - { - Fail("ERROR: Attempted to Lock a NULL handle and the function " - "returned success."); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.cpp b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.cpp new file mode 100644 index 0000000000..c572a6e653 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.cpp @@ -0,0 +1,135 @@ +// 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: test7.c +** +** Purpose: Try locking an invalid HANDLE and a NULL Handle. +** +** +**============================================================*/ + +#include +#include "../LockFile.h" + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE TheFile = NULL; + DWORD FileEnd = 0; + const char lpBuffer[] = "This is a test file."; + DWORD bytesWritten; + BOOL bRc = TRUE; + char fileName[] = "testfile.tmp"; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + TheFile = CreateFile(fileName, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.",fileName,GetLastError()); + } + + bRc = WriteFile( + TheFile, // handle to file + lpBuffer, // data buffer + (DWORD)sizeof(lpBuffer), // number of bytes to write + &bytesWritten, // number of bytes written + NULL // overlapped buffer + ); + + if(!bRc) + { + Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + + } + else if(bytesWritten != (DWORD)sizeof(lpBuffer)) + { + Trace("ERROR: Could not write the correct number of bytes to the " + "file '%s' with WriteFile.",fileName); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Attempt to lock a region of this file beyond EOF, to ensure this + doesn't cause an error. + */ + FileEnd = SetFilePointer(TheFile, 0, NULL, FILE_END); + + if(LockFile(TheFile, FileEnd+10, 0, 10, 0) == 0) + { + Trace("ERROR: LockFile failed when attempting to lock a region " + "beyond the EOF. GetLastError() returned %d.",GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + if(UnlockFile(TheFile, FileEnd+10, 0, 10, 0) == 0) + { + Trace("ERROR: UnlockFile failed when attempting to unlock the region " + "which was locked beyond the EOF. GetLastError returned %d.", + GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: Failed to call CloseHandle. GetLastError " + "returned %d.",GetLastError()); + } + + /* Attempt to call Lockfile on an HANDLE which has been closed. This + should fail. + */ + if(LockFile(TheFile, 0, 0, 5, 0) != 0) + { + Fail("ERROR: Attempted to Lock an invalid handle and the function " + "returned success."); + } + + /* Attempt to call Lockfile by passing it NULL for a handle. This should + fail. + */ + + if(LockFile(NULL, 0, 0, 5, 0) != 0) + { + Fail("ERROR: Attempted to Lock a NULL handle and the function " + "returned success."); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/CMakeLists.txt index ef9838d41e..01679e5387 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - MapViewOfFile.c + MapViewOfFile.cpp ) add_executable(paltest_mapviewoffile_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.c deleted file mode 100644 index 6177e0decf..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.c +++ /dev/null @@ -1,226 +0,0 @@ -// 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: MapViewOfFile.c -** -** -** Purpose: Positive test the MapViewOfFile API. -** Call MapViewOfFile with access FILE_MAP_READ. -** -** -**============================================================*/ -#include -#define MAPPINGSIZE 8192 -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile = INVALID_HANDLE_VALUE; - LPSTR buf = NULL; - CHAR ch[MAPPINGSIZE]; - CHAR lpFileName[] = "test.tmp"; - DWORD dwBytesWritten = 0; - DWORD dwInitialSize = 0; - DWORD dwFinalSize = 0; - BOOL bRetVal = FALSE; - - HANDLE hFileMapping = 0; - LPVOID lpMapViewAddress = NULL; - - /* Initialize the PAL environment. - */ - if( 0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - Fail( "ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), lpFileName); - } - - /* Get the initial size of file, for latter tests. - */ - dwInitialSize = GetFileSize (hFile, NULL); - if ( INVALID_FILE_SIZE == dwInitialSize ) - { - Fail("ERROR:%u: The created file \"%s\" has an invalid " - "file size.\n",GetLastError(),lpFileName); - } - - /* - * An application must meet certain requirements when working - * with files opened with FILE_FLAG_NO_BUFFERING: - * File access must begin at byte offsets within the file that - * are integer multiples of the volume's sector size. To determine a - * volume's sector size, call the GetDiskFreeSpace function. - * - * File access must be for numbers of bytes that are integer - * multiples of the volume's sector size. For example, if the - * sector size is 512 bytes, an application can request reads and - * writes of 512, 1024, or 2048 bytes, but not of 335, 981, or 7171 bytes. - * - * Buffer addresses for read and write operations must be sector - * aligned (aligned on addresses in memory that are integer multiples - * of the volume's sector size). One way to sector align buffers is to use the - * VirtualAlloc function to allocate the buffers. This function allocates memory - * that is aligned on addresses that are integer multiples of the system's page size. - * Because both page and volume sector sizes are powers of 2, memory aligned by multiples - * of the system's page size is also aligned by multiples of the volume's sector size. - */ - buf = (LPSTR)VirtualAlloc( NULL, /* Let the system decide the location. */ - MAPPINGSIZE / 2, /* One page, the smallest you can request */ - MEM_COMMIT, /* Reserve and commit in one pass */ - PAGE_READWRITE ); /* Allow reading and writting. */ - - if ( NULL == buf ) - { - Trace( "VirtualAlloc failed! LastError=%d\n", GetLastError() ); - CloseHandle( hFile ); - Fail(""); - } - - - /* - * Write to the File handle. - * The reminder will be padded with zeros. - */ - strncpy( buf, - "thats not a test string....THIS is a test string", - MAPPINGSIZE / 2 ); - - bRetVal = WriteFile(hFile, - buf, - MAPPINGSIZE / 2, - &dwBytesWritten, - NULL); - - if ( FALSE == bRetVal ) - { - Trace( "ERROR: %u :unable to write to file handle hFile=0x%lx\n", - GetLastError(), hFile); - CloseHandle(hFile); - VirtualFree( buf, 0, MEM_RELEASE ); - Fail(""); - } - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapping = CreateFileMapping( hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and wite*/ - 0, /*high-order of object size*/ - MAPPINGSIZE, /*low-orger of object size*/ - NULL); /*unnamed object*/ - - if( NULL == hFileMapping ) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", GetLastError()); - CloseHandle(hFile); - VirtualFree( buf, 0, MEM_RELEASE ); - Fail(""); - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( hFileMapping, - FILE_MAP_READ, /* access code */ - 0, /*high order offset*/ - 0, /*low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if( NULL == lpMapViewAddress ) - { - Trace( "ERROR:%u: Failed to call MapViewOfFile API to map" - " a view of file!\n", GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - VirtualFree( buf, 0, MEM_RELEASE ); - Fail(""); - } - - /* Verify that the size of the file has increased to - * accomidate the MapView. - */ - dwFinalSize = GetFileSize (hFile, NULL); - if ( (dwFinalSize <= dwInitialSize) && (dwFinalSize != MAPPINGSIZE)) - { - - CloseHandle(hFile); - CloseHandle(hFileMapping); - VirtualFree( buf, 0, MEM_RELEASE ); - UnmapViewOfFile(lpMapViewAddress); - - Fail( "ERROR: Size of the file was expected to " - "increase from \"%d\", to \"%d\".\n ", - dwInitialSize, - dwFinalSize); - } - - /* Copy the MapViewOfFile to buffer, so we can - * compare with value read from file directly. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); - if (memcmp(ch, buf, strlen(buf)) != 0) - { - CloseHandle(hFile); - CloseHandle(hFileMapping); - UnmapViewOfFile(lpMapViewAddress) ; - VirtualFree( buf, 0, MEM_RELEASE ); - - Fail( "ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, - buf); - } - - /* Unmap the view of file. - */ - if( FALSE == UnmapViewOfFile(lpMapViewAddress) ) - { - Trace( "\nFailed to call UnmapViewOfFile API to unmap the " - "view of a file, error code=%u\n", GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - VirtualFree( buf, 0, MEM_RELEASE ); - Fail(""); - } - - /* Close handle to create file. - */ - if( FALSE == CloseHandle(hFile) ) - { - Trace( "ERROR:%u:Failed to call CloseHandle API to close a file handle.", - GetLastError()); - CloseHandle(hFileMapping); - VirtualFree( buf, 0, MEM_RELEASE ); - Fail(""); - } - - if( FALSE == CloseHandle(hFileMapping) ) - { - Trace( "ERROR:%u:Failed to call CloseHandle API to close a " - "filemapping handle.",GetLastError()); - VirtualFree( buf, 0, MEM_RELEASE ); - Fail(""); - } - - VirtualFree( buf, 0, MEM_RELEASE ); - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.cpp b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.cpp new file mode 100644 index 0000000000..6177e0decf --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.cpp @@ -0,0 +1,226 @@ +// 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: MapViewOfFile.c +** +** +** Purpose: Positive test the MapViewOfFile API. +** Call MapViewOfFile with access FILE_MAP_READ. +** +** +**============================================================*/ +#include +#define MAPPINGSIZE 8192 +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile = INVALID_HANDLE_VALUE; + LPSTR buf = NULL; + CHAR ch[MAPPINGSIZE]; + CHAR lpFileName[] = "test.tmp"; + DWORD dwBytesWritten = 0; + DWORD dwInitialSize = 0; + DWORD dwFinalSize = 0; + BOOL bRetVal = FALSE; + + HANDLE hFileMapping = 0; + LPVOID lpMapViewAddress = NULL; + + /* Initialize the PAL environment. + */ + if( 0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail( "ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), lpFileName); + } + + /* Get the initial size of file, for latter tests. + */ + dwInitialSize = GetFileSize (hFile, NULL); + if ( INVALID_FILE_SIZE == dwInitialSize ) + { + Fail("ERROR:%u: The created file \"%s\" has an invalid " + "file size.\n",GetLastError(),lpFileName); + } + + /* + * An application must meet certain requirements when working + * with files opened with FILE_FLAG_NO_BUFFERING: + * File access must begin at byte offsets within the file that + * are integer multiples of the volume's sector size. To determine a + * volume's sector size, call the GetDiskFreeSpace function. + * + * File access must be for numbers of bytes that are integer + * multiples of the volume's sector size. For example, if the + * sector size is 512 bytes, an application can request reads and + * writes of 512, 1024, or 2048 bytes, but not of 335, 981, or 7171 bytes. + * + * Buffer addresses for read and write operations must be sector + * aligned (aligned on addresses in memory that are integer multiples + * of the volume's sector size). One way to sector align buffers is to use the + * VirtualAlloc function to allocate the buffers. This function allocates memory + * that is aligned on addresses that are integer multiples of the system's page size. + * Because both page and volume sector sizes are powers of 2, memory aligned by multiples + * of the system's page size is also aligned by multiples of the volume's sector size. + */ + buf = (LPSTR)VirtualAlloc( NULL, /* Let the system decide the location. */ + MAPPINGSIZE / 2, /* One page, the smallest you can request */ + MEM_COMMIT, /* Reserve and commit in one pass */ + PAGE_READWRITE ); /* Allow reading and writting. */ + + if ( NULL == buf ) + { + Trace( "VirtualAlloc failed! LastError=%d\n", GetLastError() ); + CloseHandle( hFile ); + Fail(""); + } + + + /* + * Write to the File handle. + * The reminder will be padded with zeros. + */ + strncpy( buf, + "thats not a test string....THIS is a test string", + MAPPINGSIZE / 2 ); + + bRetVal = WriteFile(hFile, + buf, + MAPPINGSIZE / 2, + &dwBytesWritten, + NULL); + + if ( FALSE == bRetVal ) + { + Trace( "ERROR: %u :unable to write to file handle hFile=0x%lx\n", + GetLastError(), hFile); + CloseHandle(hFile); + VirtualFree( buf, 0, MEM_RELEASE ); + Fail(""); + } + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and wite*/ + 0, /*high-order of object size*/ + MAPPINGSIZE, /*low-orger of object size*/ + NULL); /*unnamed object*/ + + if( NULL == hFileMapping ) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", GetLastError()); + CloseHandle(hFile); + VirtualFree( buf, 0, MEM_RELEASE ); + Fail(""); + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( hFileMapping, + FILE_MAP_READ, /* access code */ + 0, /*high order offset*/ + 0, /*low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if( NULL == lpMapViewAddress ) + { + Trace( "ERROR:%u: Failed to call MapViewOfFile API to map" + " a view of file!\n", GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + VirtualFree( buf, 0, MEM_RELEASE ); + Fail(""); + } + + /* Verify that the size of the file has increased to + * accomidate the MapView. + */ + dwFinalSize = GetFileSize (hFile, NULL); + if ( (dwFinalSize <= dwInitialSize) && (dwFinalSize != MAPPINGSIZE)) + { + + CloseHandle(hFile); + CloseHandle(hFileMapping); + VirtualFree( buf, 0, MEM_RELEASE ); + UnmapViewOfFile(lpMapViewAddress); + + Fail( "ERROR: Size of the file was expected to " + "increase from \"%d\", to \"%d\".\n ", + dwInitialSize, + dwFinalSize); + } + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + if (memcmp(ch, buf, strlen(buf)) != 0) + { + CloseHandle(hFile); + CloseHandle(hFileMapping); + UnmapViewOfFile(lpMapViewAddress) ; + VirtualFree( buf, 0, MEM_RELEASE ); + + Fail( "ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, + buf); + } + + /* Unmap the view of file. + */ + if( FALSE == UnmapViewOfFile(lpMapViewAddress) ) + { + Trace( "\nFailed to call UnmapViewOfFile API to unmap the " + "view of a file, error code=%u\n", GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + VirtualFree( buf, 0, MEM_RELEASE ); + Fail(""); + } + + /* Close handle to create file. + */ + if( FALSE == CloseHandle(hFile) ) + { + Trace( "ERROR:%u:Failed to call CloseHandle API to close a file handle.", + GetLastError()); + CloseHandle(hFileMapping); + VirtualFree( buf, 0, MEM_RELEASE ); + Fail(""); + } + + if( FALSE == CloseHandle(hFileMapping) ) + { + Trace( "ERROR:%u:Failed to call CloseHandle API to close a " + "filemapping handle.",GetLastError()); + VirtualFree( buf, 0, MEM_RELEASE ); + Fail(""); + } + + VirtualFree( buf, 0, MEM_RELEASE ); + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/CMakeLists.txt index 18a9d105b1..88f3344567 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - MapViewOfFile.c + MapViewOfFile.cpp ) add_executable(paltest_mapviewoffile_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.c deleted file mode 100644 index c08f585c0e..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.c +++ /dev/null @@ -1,203 +0,0 @@ -// 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: MapViewOfFile.c -** -** Purpose: Positive test the MapViewOfFile API. -** Call MapViewOfFile with access FILE_MAP_WRITE. -** -** Depends: CreateFile, -** GetFileSize, -** memset, -** CreateFileMapping, -** CloseHandle, -** memcpy, -** ReadFile, -** memcmp, -** UnMapViewOfFile. -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - char buf[] = "this is a test string"; - const int MAPPINGSIZE = 2048; - char ch[2048]; - char readString[2048]; - char lpFileName[] = "test.tmp"; - DWORD dwBytesRead; - DWORD dwInitialSize = 0; - DWORD dwFinalSize = 0; - BOOL bRetVal; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Get the initial size of file, for latter tests. - */ - dwInitialSize = GetFileSize (hFile, NULL); - if ( dwInitialSize == INVALID_FILE_SIZE ) - { - Fail("ERROR:%u: The created file \"%s\" has an invalid " - "file size.\n", - GetLastError(), - lpFileName); - } - - /* Initialize the buffers. - */ - memset(ch, 0, MAPPINGSIZE); - memset(readString, 0, MAPPINGSIZE); - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and wite*/ - 0, /*high-order of object size*/ - MAPPINGSIZE, /*low-orger of object size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - CloseHandle(hFile); - Fail(""); - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_WRITE, /* access code */ - 0, /*high order offset*/ - 0, /*low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile API to map a view" - " of file!\n", - GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - /* Verify that the size of the file has increased to - * accomidate the MapView. - */ - dwFinalSize = GetFileSize (hFile, NULL); - if ( (dwFinalSize <= dwInitialSize) && (dwFinalSize != MAPPINGSIZE)) - { - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail("ERROR: Size of the file was expected to " - "increase from \"%d\", to \"%d\".\n ", - dwInitialSize, - MAPPINGSIZE); - } - - /* Write to the MapView and copy the MapViewOfFile - * to buffer, so we can compare with value read from - * file directly. - */ - memcpy(lpMapViewAddress, buf, strlen(buf)); - - /* Read from the File handle. - */ - bRetVal = ReadFile(hFile, - readString, - strlen(buf), - &dwBytesRead, - NULL); - - if (bRetVal == FALSE) - { - Trace("ERROR: %u :unable to read from file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - if (memcmp(buf, readString, strlen(readString)) != 0) - { - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail("ERROR: Read string from file \"%s\", is " - "not equal to string written through MapView " - "\"%s\".\n", - readString, - ch); - } - - /* Unmap the view of file. - */ - if(UnmapViewOfFile(lpMapViewAddress) == FALSE) - { - Trace("ERROR: Failed to call UnmapViewOfFile API to" - " unmap the view of a file, error code=%u\n", - GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - /* Close handle to create file. - */ - if(CloseHandle(hFile) == FALSE) - { - Trace("ERROR:%u:Failed to call CloseHandle API " - "to close a file handle.", - GetLastError()); - CloseHandle(hFileMapping); - Fail(""); - } - - if(CloseHandle(hFileMapping) == FALSE) - { - Fail("ERROR:%u:Failed to call CloseHandle API " - "to close a file mapping handle.", - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.cpp b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.cpp new file mode 100644 index 0000000000..c08f585c0e --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.cpp @@ -0,0 +1,203 @@ +// 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: MapViewOfFile.c +** +** Purpose: Positive test the MapViewOfFile API. +** Call MapViewOfFile with access FILE_MAP_WRITE. +** +** Depends: CreateFile, +** GetFileSize, +** memset, +** CreateFileMapping, +** CloseHandle, +** memcpy, +** ReadFile, +** memcmp, +** UnMapViewOfFile. +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + char buf[] = "this is a test string"; + const int MAPPINGSIZE = 2048; + char ch[2048]; + char readString[2048]; + char lpFileName[] = "test.tmp"; + DWORD dwBytesRead; + DWORD dwInitialSize = 0; + DWORD dwFinalSize = 0; + BOOL bRetVal; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Get the initial size of file, for latter tests. + */ + dwInitialSize = GetFileSize (hFile, NULL); + if ( dwInitialSize == INVALID_FILE_SIZE ) + { + Fail("ERROR:%u: The created file \"%s\" has an invalid " + "file size.\n", + GetLastError(), + lpFileName); + } + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + memset(readString, 0, MAPPINGSIZE); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and wite*/ + 0, /*high-order of object size*/ + MAPPINGSIZE, /*low-orger of object size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + CloseHandle(hFile); + Fail(""); + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_WRITE, /* access code */ + 0, /*high order offset*/ + 0, /*low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile API to map a view" + " of file!\n", + GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + /* Verify that the size of the file has increased to + * accomidate the MapView. + */ + dwFinalSize = GetFileSize (hFile, NULL); + if ( (dwFinalSize <= dwInitialSize) && (dwFinalSize != MAPPINGSIZE)) + { + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail("ERROR: Size of the file was expected to " + "increase from \"%d\", to \"%d\".\n ", + dwInitialSize, + MAPPINGSIZE); + } + + /* Write to the MapView and copy the MapViewOfFile + * to buffer, so we can compare with value read from + * file directly. + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the File handle. + */ + bRetVal = ReadFile(hFile, + readString, + strlen(buf), + &dwBytesRead, + NULL); + + if (bRetVal == FALSE) + { + Trace("ERROR: %u :unable to read from file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + if (memcmp(buf, readString, strlen(readString)) != 0) + { + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail("ERROR: Read string from file \"%s\", is " + "not equal to string written through MapView " + "\"%s\".\n", + readString, + ch); + } + + /* Unmap the view of file. + */ + if(UnmapViewOfFile(lpMapViewAddress) == FALSE) + { + Trace("ERROR: Failed to call UnmapViewOfFile API to" + " unmap the view of a file, error code=%u\n", + GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + /* Close handle to create file. + */ + if(CloseHandle(hFile) == FALSE) + { + Trace("ERROR:%u:Failed to call CloseHandle API " + "to close a file handle.", + GetLastError()); + CloseHandle(hFileMapping); + Fail(""); + } + + if(CloseHandle(hFileMapping) == FALSE) + { + Fail("ERROR:%u:Failed to call CloseHandle API " + "to close a file mapping handle.", + GetLastError()); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/CMakeLists.txt index 76bd3276a4..e48ce13408 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - MapViewOfFile.c + MapViewOfFile.cpp ) add_executable(paltest_mapviewoffile_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.c deleted file mode 100644 index 63bee768f9..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.c +++ /dev/null @@ -1,209 +0,0 @@ -// 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: MapViewOfFile.c -** -** Purpose: Positive test the MapViewOfFile API. -** Call MapViewOfFile with access FILE_MAP_ALL_ACCESS. -** -** Depends: CreateFile, -** GetFileSize, -** memset, -** memcpy, -** memcmp, -** ReadFile, -** UnMapViewOfFile, -** CreateFileMapping, -** CloseHandle. -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - char buf[] = "this is a test string"; - const int MAPPINGSIZE = 2048; - char ch[2048]; - char readString[2048]; - char lpFileName[] = "test.tmp"; - DWORD dwBytesRead; - DWORD dwInitialSize = 0; - DWORD dwFinalSize = 0; - BOOL bRetVal; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Get the initial size of file, for latter tests. - */ - dwInitialSize = GetFileSize (hFile, NULL); - if ( dwInitialSize == INVALID_FILE_SIZE ) - { - Trace("ERROR:%u: The created file \"%s\" has an invalid " - "file size.\n", - GetLastError(), - lpFileName); - CloseHandle(hFile); - Fail(""); - } - - /* Initialize the buffers. - */ - memset(ch, 0, MAPPINGSIZE); - memset(readString, 0, MAPPINGSIZE); - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and wite*/ - 0, /*high-order of object size*/ - MAPPINGSIZE, /*low-orger of object size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - CloseHandle(hFile); - Fail(""); - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_ALL_ACCESS, /*access code*/ - 0, /*high order offset*/ - 0, /*low order offset*/ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile API to map a view" - " of file!\n", - GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - /* Verify that the size of the file has increased to - * accomidate the MapView. - */ - dwFinalSize = GetFileSize (hFile, NULL); - if ( (dwFinalSize <= dwInitialSize) && (dwFinalSize != MAPPINGSIZE)) - { - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail("ERROR: Size of the file was expected to " - "increase from \"%d\", to \"%d\".\n ", - dwInitialSize, - MAPPINGSIZE); - } - - /* Write to the MapView and copy the MapViewOfFile - * to buffer, so we can compare with value read from - * file directly. - */ - - memcpy(lpMapViewAddress, buf, strlen(buf)); - memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); - - /* Read from the File handle. - */ - bRetVal = ReadFile(hFile, - readString, - strlen(buf), - &dwBytesRead, - NULL); - - if (bRetVal == FALSE) - { - Trace("ERROR: %u :unable to read from file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - if (memcmp(ch, readString, strlen(readString)) != 0) - { - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail("ERROR: Read string from file \"%s\", is " - "not equal to string written through MapView " - "\"%s\".\n", - readString, - ch); - } - - /* Unmap the view of file. - */ - if(UnmapViewOfFile(lpMapViewAddress) == FALSE) - { - Trace("ERROR: Failed to call UnmapViewOfFile API to" - " unmap the view of a file, error code=%u\n", - GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - /* Close handle to create file. - */ - if(CloseHandle(hFile) == FALSE) - { - Trace("ERROR:%u:Failed to call CloseHandle API " - "to close a file handle.", - GetLastError()); - CloseHandle(hFileMapping); - Fail(""); - } - - /* Close handle to file mapping. - */ - if(CloseHandle(hFileMapping) == FALSE) - { - Fail("ERROR:%u:Failed to call CloseHandle API " - "to close a file handle.", - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.cpp b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.cpp new file mode 100644 index 0000000000..63bee768f9 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.cpp @@ -0,0 +1,209 @@ +// 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: MapViewOfFile.c +** +** Purpose: Positive test the MapViewOfFile API. +** Call MapViewOfFile with access FILE_MAP_ALL_ACCESS. +** +** Depends: CreateFile, +** GetFileSize, +** memset, +** memcpy, +** memcmp, +** ReadFile, +** UnMapViewOfFile, +** CreateFileMapping, +** CloseHandle. +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + char buf[] = "this is a test string"; + const int MAPPINGSIZE = 2048; + char ch[2048]; + char readString[2048]; + char lpFileName[] = "test.tmp"; + DWORD dwBytesRead; + DWORD dwInitialSize = 0; + DWORD dwFinalSize = 0; + BOOL bRetVal; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Get the initial size of file, for latter tests. + */ + dwInitialSize = GetFileSize (hFile, NULL); + if ( dwInitialSize == INVALID_FILE_SIZE ) + { + Trace("ERROR:%u: The created file \"%s\" has an invalid " + "file size.\n", + GetLastError(), + lpFileName); + CloseHandle(hFile); + Fail(""); + } + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + memset(readString, 0, MAPPINGSIZE); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and wite*/ + 0, /*high-order of object size*/ + MAPPINGSIZE, /*low-orger of object size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + CloseHandle(hFile); + Fail(""); + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_ALL_ACCESS, /*access code*/ + 0, /*high order offset*/ + 0, /*low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile API to map a view" + " of file!\n", + GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + /* Verify that the size of the file has increased to + * accomidate the MapView. + */ + dwFinalSize = GetFileSize (hFile, NULL); + if ( (dwFinalSize <= dwInitialSize) && (dwFinalSize != MAPPINGSIZE)) + { + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail("ERROR: Size of the file was expected to " + "increase from \"%d\", to \"%d\".\n ", + dwInitialSize, + MAPPINGSIZE); + } + + /* Write to the MapView and copy the MapViewOfFile + * to buffer, so we can compare with value read from + * file directly. + */ + + memcpy(lpMapViewAddress, buf, strlen(buf)); + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + + /* Read from the File handle. + */ + bRetVal = ReadFile(hFile, + readString, + strlen(buf), + &dwBytesRead, + NULL); + + if (bRetVal == FALSE) + { + Trace("ERROR: %u :unable to read from file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + if (memcmp(ch, readString, strlen(readString)) != 0) + { + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail("ERROR: Read string from file \"%s\", is " + "not equal to string written through MapView " + "\"%s\".\n", + readString, + ch); + } + + /* Unmap the view of file. + */ + if(UnmapViewOfFile(lpMapViewAddress) == FALSE) + { + Trace("ERROR: Failed to call UnmapViewOfFile API to" + " unmap the view of a file, error code=%u\n", + GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + /* Close handle to create file. + */ + if(CloseHandle(hFile) == FALSE) + { + Trace("ERROR:%u:Failed to call CloseHandle API " + "to close a file handle.", + GetLastError()); + CloseHandle(hFileMapping); + Fail(""); + } + + /* Close handle to file mapping. + */ + if(CloseHandle(hFileMapping) == FALSE) + { + Fail("ERROR:%u:Failed to call CloseHandle API " + "to close a file handle.", + GetLastError()); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/CMakeLists.txt index 52381c510f..7f6d905212 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - mapviewoffile.c + mapviewoffile.cpp ) add_executable(paltest_mapviewoffile_test4 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.c deleted file mode 100644 index 7f3252144b..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.c +++ /dev/null @@ -1,166 +0,0 @@ -// 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: MapViewOfFile.c -** -** Purpose: Negative test the MapViewOfFile API. -** Call MapViewOfFile with all access modes, except -** read-only, on a read only map. -** -** Depends: CreateFile, -** CreateFileMapping, -** CloseHandle, -** UnMapViewOfFile. -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE hFile; - BOOL err; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - DWORD dwBytesWritten; - const int MAPPINGSIZE = 2048; - char buf[] = "this is a test string"; - char lpFileName[] = "test.tmp"; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Write to the File handle. - */ - err = WriteFile(hFile, - buf, - strlen(buf), - &dwBytesWritten, - NULL); - - if ( !FlushFileBuffers( hFile ) ) - { - CloseHandle(hFile); - Fail("ERROR: Unable to flush the buffers\n"); - } - - if (err == FALSE) - { - Trace("ERROR: %u :unable to write to file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - CloseHandle(hFile); - Fail(""); - } - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READONLY, /*read and wite*/ - 0, /*high-order of object size*/ - 0, /*low-orger of object size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - CloseHandle(hFile); - Fail(""); - } - - /* map a writeable view of a file to a read-only file map. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_WRITE, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL != lpMapViewAddress) - { - Trace("ERROR:%u: Able to create a writeable MapViewOfFile" - " to a read-only file.\n", - GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - UnmapViewOfFile(lpMapViewAddress); - Fail(""); - } - - /* map an all access view of a file to a read-only file map. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL != lpMapViewAddress) - { - Trace("ERROR:%u: Able to create an all access MapViewOfFile" - " to a read-only file.\n", - GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - UnmapViewOfFile(lpMapViewAddress); - Fail(""); - } - - /* map an copy view of a file to a read-only file map. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_COPY, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL != lpMapViewAddress) - { - Trace("ERROR:%u: Able to create a copy access MapViewOfFile " - "to a read-only file.\n", - GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - /* Clean-up and Teminate. */ - CloseHandle(hFile); - CloseHandle(hFileMapping); - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.cpp b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.cpp new file mode 100644 index 0000000000..7f3252144b --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.cpp @@ -0,0 +1,166 @@ +// 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: MapViewOfFile.c +** +** Purpose: Negative test the MapViewOfFile API. +** Call MapViewOfFile with all access modes, except +** read-only, on a read only map. +** +** Depends: CreateFile, +** CreateFileMapping, +** CloseHandle, +** UnMapViewOfFile. +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + BOOL err; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + DWORD dwBytesWritten; + const int MAPPINGSIZE = 2048; + char buf[] = "this is a test string"; + char lpFileName[] = "test.tmp"; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Write to the File handle. + */ + err = WriteFile(hFile, + buf, + strlen(buf), + &dwBytesWritten, + NULL); + + if ( !FlushFileBuffers( hFile ) ) + { + CloseHandle(hFile); + Fail("ERROR: Unable to flush the buffers\n"); + } + + if (err == FALSE) + { + Trace("ERROR: %u :unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + CloseHandle(hFile); + Fail(""); + } + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READONLY, /*read and wite*/ + 0, /*high-order of object size*/ + 0, /*low-orger of object size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + CloseHandle(hFile); + Fail(""); + } + + /* map a writeable view of a file to a read-only file map. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_WRITE, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL != lpMapViewAddress) + { + Trace("ERROR:%u: Able to create a writeable MapViewOfFile" + " to a read-only file.\n", + GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + UnmapViewOfFile(lpMapViewAddress); + Fail(""); + } + + /* map an all access view of a file to a read-only file map. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL != lpMapViewAddress) + { + Trace("ERROR:%u: Able to create an all access MapViewOfFile" + " to a read-only file.\n", + GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + UnmapViewOfFile(lpMapViewAddress); + Fail(""); + } + + /* map an copy view of a file to a read-only file map. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_COPY, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL != lpMapViewAddress) + { + Trace("ERROR:%u: Able to create a copy access MapViewOfFile " + "to a read-only file.\n", + GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + /* Clean-up and Teminate. */ + CloseHandle(hFile); + CloseHandle(hFileMapping); + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/CMakeLists.txt index f98a4b7779..3911ffa53c 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - mapviewoffile.c + mapviewoffile.cpp ) add_executable(paltest_mapviewoffile_test5 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.c deleted file mode 100644 index 219b3fa12a..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.c +++ /dev/null @@ -1,131 +0,0 @@ -// 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: MapViewOfFile.c -** -** Purpose: Negative test the MapViewOfFile API. -** Passing invalid values for the hFileMappingObject. -** -** Depends: CreatePipe, -** CreateFile, -** CreateFileMapping, -** CloseHandle. -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - - const int MAPPINGSIZE = 2048; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - BOOL bRetVal; - - SECURITY_ATTRIBUTES lpPipeAttributes; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Attempt to create a MapViewOfFile with a NULL handle. - */ - hFileMapping = NULL; - - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_WRITE, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - MAPPINGSIZE); /* number of bytes for map */ - - if((NULL != lpMapViewAddress) && - (GetLastError() != ERROR_INVALID_HANDLE)) - { - Trace("ERROR:%u: Able to create a MapViewOfFile with " - "hFileMapping=0x%lx.\n", - GetLastError()); - UnmapViewOfFile(lpMapViewAddress); - Fail(""); - } - - /* Attempt to create a MapViewOfFile with an invalid handle. - */ - hFileMapping = INVALID_HANDLE_VALUE; - - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_WRITE, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - MAPPINGSIZE); /* number of bytes for map */ - - if((NULL != lpMapViewAddress) && - (GetLastError() != ERROR_INVALID_HANDLE)) - { - Trace("ERROR:%u: Able to create a MapViewOfFile with " - "hFileMapping=0x%lx.\n", - GetLastError()); - UnmapViewOfFile(lpMapViewAddress); - Fail(""); - } - - /* Setup SECURITY_ATTRIBUTES structure for CreatePipe. - */ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /* Create a Pipe. - */ - bRetVal = CreatePipe(&hReadPipe, /* read handle*/ - &hWritePipe, /* write handle */ - &lpPipeAttributes,/* security attributes*/ - 0); /* pipe size*/ - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :Unable to create pipe\n", - GetLastError()); - } - - /* Attempt creating a MapViewOfFile with a Pipe Handle. - */ - lpMapViewAddress = MapViewOfFile( - hReadPipe, - FILE_MAP_WRITE, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - MAPPINGSIZE); /* number of bytes for map */ - - if((NULL != lpMapViewAddress) && - (GetLastError() != ERROR_INVALID_HANDLE)) - { - Trace("ERROR:%u: Able to create a MapViewOfFile with " - "hFileMapping=0x%lx.\n", - GetLastError()); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - UnmapViewOfFile(lpMapViewAddress); - Fail(""); - } - - /* Clean-up and Terminate the PAL. - */ - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.cpp b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.cpp new file mode 100644 index 0000000000..219b3fa12a --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.cpp @@ -0,0 +1,131 @@ +// 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: MapViewOfFile.c +** +** Purpose: Negative test the MapViewOfFile API. +** Passing invalid values for the hFileMappingObject. +** +** Depends: CreatePipe, +** CreateFile, +** CreateFileMapping, +** CloseHandle. +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + + const int MAPPINGSIZE = 2048; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Attempt to create a MapViewOfFile with a NULL handle. + */ + hFileMapping = NULL; + + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_WRITE, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + MAPPINGSIZE); /* number of bytes for map */ + + if((NULL != lpMapViewAddress) && + (GetLastError() != ERROR_INVALID_HANDLE)) + { + Trace("ERROR:%u: Able to create a MapViewOfFile with " + "hFileMapping=0x%lx.\n", + GetLastError()); + UnmapViewOfFile(lpMapViewAddress); + Fail(""); + } + + /* Attempt to create a MapViewOfFile with an invalid handle. + */ + hFileMapping = INVALID_HANDLE_VALUE; + + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_WRITE, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + MAPPINGSIZE); /* number of bytes for map */ + + if((NULL != lpMapViewAddress) && + (GetLastError() != ERROR_INVALID_HANDLE)) + { + Trace("ERROR:%u: Able to create a MapViewOfFile with " + "hFileMapping=0x%lx.\n", + GetLastError()); + UnmapViewOfFile(lpMapViewAddress); + Fail(""); + } + + /* Setup SECURITY_ATTRIBUTES structure for CreatePipe. + */ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /* Create a Pipe. + */ + bRetVal = CreatePipe(&hReadPipe, /* read handle*/ + &hWritePipe, /* write handle */ + &lpPipeAttributes,/* security attributes*/ + 0); /* pipe size*/ + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :Unable to create pipe\n", + GetLastError()); + } + + /* Attempt creating a MapViewOfFile with a Pipe Handle. + */ + lpMapViewAddress = MapViewOfFile( + hReadPipe, + FILE_MAP_WRITE, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + MAPPINGSIZE); /* number of bytes for map */ + + if((NULL != lpMapViewAddress) && + (GetLastError() != ERROR_INVALID_HANDLE)) + { + Trace("ERROR:%u: Able to create a MapViewOfFile with " + "hFileMapping=0x%lx.\n", + GetLastError()); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + UnmapViewOfFile(lpMapViewAddress); + Fail(""); + } + + /* Clean-up and Terminate the PAL. + */ + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/CMakeLists.txt index dad03aaf80..8199981eec 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - mapviewoffile.c + mapviewoffile.cpp ) add_executable(paltest_mapviewoffile_test6 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/mapviewoffile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/mapviewoffile.c deleted file mode 100644 index f7d7302a4c..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/mapviewoffile.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: MapViewOfFile.c -** -** Purpose: Positivve test the MapViewOfFile API. -** Mapping a pagefile allocation into memory -** -** Depends: CreateFileMappingW, -** UnmapViewOfFile -** CloseHandle. -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - - const int MAPPINGSIZE = 2048; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - char *p; - int i; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - hFileMapping = CreateFileMappingW(INVALID_HANDLE_VALUE, - NULL, - PAGE_READWRITE, - 0, - MAPPINGSIZE, - NULL); - - if (hFileMapping == NULL) { - Trace("ERROR:%u: CreateFileMappingW() failed\n", GetLastError()); - Fail(""); - } - - - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_WRITE, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - MAPPINGSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: MapViewOfFile() failed.\n", - GetLastError()); - CloseHandle(hFileMapping); - Fail(""); - } - - p = (char *)lpMapViewAddress; - for (i=0; i + +int __cdecl main(int argc, char *argv[]) +{ + + const int MAPPINGSIZE = 2048; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + char *p; + int i; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + hFileMapping = CreateFileMappingW(INVALID_HANDLE_VALUE, + NULL, + PAGE_READWRITE, + 0, + MAPPINGSIZE, + NULL); + + if (hFileMapping == NULL) { + Trace("ERROR:%u: CreateFileMappingW() failed\n", GetLastError()); + Fail(""); + } + + + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_WRITE, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: MapViewOfFile() failed.\n", + GetLastError()); + CloseHandle(hFileMapping); + Fail(""); + } + + p = (char *)lpMapViewAddress; + for (i=0; i - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE FileMappingHandle; - HANDLE OpenFileMappingHandle; - HANDLE lpMapViewAddress; - const int LOWORDERSIZE = 1024; - char buf[] = "this is a test"; - char MapObject[] = "myMappingObject"; - char ch[1024]; - int err; - int RetVal = PASS; - - /* Initialize the PAL environment. - */ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - - /* Create a named file-mapping object with - * file handle FileHandle. - */ - FileMappingHandle = CreateFileMapping( - INVALID_HANDLE_VALUE, - NULL, /* not inherited */ - PAGE_READWRITE, /* read and write */ - 0, /* high-order size */ - LOWORDERSIZE, /* low-order size */ - MapObject); /* named object */ - - if(NULL == FileMappingHandle) - { - Fail("ERROR:%u:Failed to call CreateFileMapping to " - "create a mapping object.\n", - GetLastError()); - } - if(GetLastError() == ERROR_ALREADY_EXISTS) - { - Trace("ERROR:File mapping object already exists\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a named file-mapping object with - * FILE_MAP_ALL_ACCESS access. - */ - OpenFileMappingHandle = OpenFileMapping( - FILE_MAP_ALL_ACCESS, - TRUE, - MapObject ); - - if(NULL == OpenFileMappingHandle) - { - Trace("ERROR:%u:Failed to Call OpenFileMapping API!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Test the opened map view. - */ - lpMapViewAddress = MapViewOfFile( - OpenFileMappingHandle, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write to the Map View. - */ - memcpy(lpMapViewAddress, buf, strlen(buf)); - - /* Read from the Map View. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); - - /* Compare what was written to the Map View, - * to what was read. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpThree; - - } - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(FileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - FileMappingHandle); - RetVal = FAIL; - } - - - /* Terminat the PAL.*/ - PAL_TerminateEx(RetVal); - return RetVal; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/OpenFileMappingA.cpp b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/OpenFileMappingA.cpp new file mode 100644 index 0000000000..9087285112 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/OpenFileMappingA.cpp @@ -0,0 +1,157 @@ +// 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: openfilemappinga.c (test 1) +** +** Purpose: Positive test the OpenFileMapping API. +** Call OpenFileMapping to open a named file-mapping +** object with FILE_MAP_ALL_ACCESS access +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE FileMappingHandle; + HANDLE OpenFileMappingHandle; + HANDLE lpMapViewAddress; + const int LOWORDERSIZE = 1024; + char buf[] = "this is a test"; + char MapObject[] = "myMappingObject"; + char ch[1024]; + int err; + int RetVal = PASS; + + /* Initialize the PAL environment. + */ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + + /* Create a named file-mapping object with + * file handle FileHandle. + */ + FileMappingHandle = CreateFileMapping( + INVALID_HANDLE_VALUE, + NULL, /* not inherited */ + PAGE_READWRITE, /* read and write */ + 0, /* high-order size */ + LOWORDERSIZE, /* low-order size */ + MapObject); /* named object */ + + if(NULL == FileMappingHandle) + { + Fail("ERROR:%u:Failed to call CreateFileMapping to " + "create a mapping object.\n", + GetLastError()); + } + if(GetLastError() == ERROR_ALREADY_EXISTS) + { + Trace("ERROR:File mapping object already exists\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a named file-mapping object with + * FILE_MAP_ALL_ACCESS access. + */ + OpenFileMappingHandle = OpenFileMapping( + FILE_MAP_ALL_ACCESS, + TRUE, + MapObject ); + + if(NULL == OpenFileMappingHandle) + { + Trace("ERROR:%u:Failed to Call OpenFileMapping API!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Test the opened map view. + */ + lpMapViewAddress = MapViewOfFile( + OpenFileMappingHandle, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write to the Map View. + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map View. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); + + /* Compare what was written to the Map View, + * to what was read. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(FileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + FileMappingHandle); + RetVal = FAIL; + } + + + /* Terminat the PAL.*/ + PAL_TerminateEx(RetVal); + return RetVal; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/CMakeLists.txt index 3a0eff04a7..670346fe3b 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - OpenFileMappingA.c + OpenFileMappingA.cpp ) add_executable(paltest_openfilemappinga_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.c deleted file mode 100644 index 5e41a92024..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.c +++ /dev/null @@ -1,214 +0,0 @@ -// 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: openfilemappinga.c (test 2) -** -** Purpose: Positive test the OpenFileMapping API. -** Call OpenFileMapping to open a named file-mapping -** object with FILE_MAP_WRITE access -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE FileMappingHandle; - HANDLE OpenFileMappingHandle; - HANDLE lpMapViewAddress; - HANDLE OpenFileMappingHandle2; - HANDLE lpMapViewAddress2; - const int LOWORDERSIZE = 1024; - char MapObject[] = "myMappingObject"; - char buf[] = "this is a test"; - char ch[1024]; - int RetVal = PASS; - - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a named file-mapping object with file handle FileHandle. - */ - FileMappingHandle = CreateFileMapping( - INVALID_HANDLE_VALUE, - NULL, /* not inherited */ - PAGE_READWRITE, /* read and write */ - 0, /* high-order size */ - LOWORDERSIZE, /* low-order size */ - MapObject); /* named object */ - - - if(NULL == FileMappingHandle) - { - Fail("\nFailed to call CreateFileMapping to create " - "a mapping object!\n"); - } - if(GetLastError() == ERROR_ALREADY_EXISTS) - { - Trace("\nFile mapping object already exists!\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a named file-mapping object with FILE_MAP_WRITE access. - */ - OpenFileMappingHandle = OpenFileMapping( - FILE_MAP_WRITE, - FALSE, - MapObject); - - if(NULL == OpenFileMappingHandle) - { - Trace("\nFailed to Call OpenFileMapping API!\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a named file-mapping object with - * FILE_MAP_ALL_ACCESS access, to verify - * the FILE_MAP_WRITE access map. - */ - OpenFileMappingHandle2 = OpenFileMapping( - FILE_MAP_ALL_ACCESS, - FALSE, - MapObject); - - if(NULL == OpenFileMappingHandle2) - { - Trace("\nFailed to Call OpenFileMapping API!\n"); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Create map view of the open mapping that has - * FILE_MAP_WRITE access. - */ - lpMapViewAddress = MapViewOfFile( - OpenFileMappingHandle, - FILE_MAP_WRITE, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Create map view of the open mapping that has - * FILE_MAP_ALL_ACCESS access. - */ - lpMapViewAddress2 = MapViewOfFile( - OpenFileMappingHandle2, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress2) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpFour; - } - - /* Write to the Map View. - */ - memcpy(lpMapViewAddress, buf, strlen(buf)); - - /* Read from the Map View. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); - - /* Compare what was written to the Map View, - * to what was read. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Fail("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpFive; - } - -CleanUpFive: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress2); - RetVal = FAIL; - } - -CleanUpFour: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpThree: - - /* Close Handle to opened file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle2) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle2); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opened file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(FileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - FileMappingHandle); - RetVal = FAIL; - } - - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.cpp b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.cpp new file mode 100644 index 0000000000..5e41a92024 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.cpp @@ -0,0 +1,214 @@ +// 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: openfilemappinga.c (test 2) +** +** Purpose: Positive test the OpenFileMapping API. +** Call OpenFileMapping to open a named file-mapping +** object with FILE_MAP_WRITE access +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE FileMappingHandle; + HANDLE OpenFileMappingHandle; + HANDLE lpMapViewAddress; + HANDLE OpenFileMappingHandle2; + HANDLE lpMapViewAddress2; + const int LOWORDERSIZE = 1024; + char MapObject[] = "myMappingObject"; + char buf[] = "this is a test"; + char ch[1024]; + int RetVal = PASS; + + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a named file-mapping object with file handle FileHandle. + */ + FileMappingHandle = CreateFileMapping( + INVALID_HANDLE_VALUE, + NULL, /* not inherited */ + PAGE_READWRITE, /* read and write */ + 0, /* high-order size */ + LOWORDERSIZE, /* low-order size */ + MapObject); /* named object */ + + + if(NULL == FileMappingHandle) + { + Fail("\nFailed to call CreateFileMapping to create " + "a mapping object!\n"); + } + if(GetLastError() == ERROR_ALREADY_EXISTS) + { + Trace("\nFile mapping object already exists!\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a named file-mapping object with FILE_MAP_WRITE access. + */ + OpenFileMappingHandle = OpenFileMapping( + FILE_MAP_WRITE, + FALSE, + MapObject); + + if(NULL == OpenFileMappingHandle) + { + Trace("\nFailed to Call OpenFileMapping API!\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a named file-mapping object with + * FILE_MAP_ALL_ACCESS access, to verify + * the FILE_MAP_WRITE access map. + */ + OpenFileMappingHandle2 = OpenFileMapping( + FILE_MAP_ALL_ACCESS, + FALSE, + MapObject); + + if(NULL == OpenFileMappingHandle2) + { + Trace("\nFailed to Call OpenFileMapping API!\n"); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Create map view of the open mapping that has + * FILE_MAP_WRITE access. + */ + lpMapViewAddress = MapViewOfFile( + OpenFileMappingHandle, + FILE_MAP_WRITE, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Create map view of the open mapping that has + * FILE_MAP_ALL_ACCESS access. + */ + lpMapViewAddress2 = MapViewOfFile( + OpenFileMappingHandle2, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress2) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpFour; + } + + /* Write to the Map View. + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map View. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); + + /* Compare what was written to the Map View, + * to what was read. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Fail("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpFive; + } + +CleanUpFive: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress2); + RetVal = FAIL; + } + +CleanUpFour: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpThree: + + /* Close Handle to opened file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle2) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle2); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opened file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(FileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + FileMappingHandle); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/CMakeLists.txt index 599a09ffc7..dab27b5c74 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - OpenFileMappingA.c + OpenFileMappingA.cpp ) add_executable(paltest_openfilemappinga_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.c deleted file mode 100644 index b01a3e8c0b..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.c +++ /dev/null @@ -1,217 +0,0 @@ -// 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: openfilemappinga.c -** -** Purpose: Positive test the OpenFileMapping API. -** Call OpenFileMapping to open a named file-mapping -** object with FILE_MAP_READ access -** -** -**============================================================*/ -#include - - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE FileMappingHandle; - HANDLE OpenFileMappingHandle; - HANDLE OpenFileMappingHandle2; - HANDLE lpMapViewAddress; - HANDLE lpMapViewAddress2; - const int LOWORDERSIZE = 1024; - char buf[] = "this is a test"; - char MapObject[] = "myMappingObject"; - char ch[1024]; - int RetVal = PASS; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a named file-mapping object with file handle FileHandle. - */ - FileMappingHandle = CreateFileMapping( - INVALID_HANDLE_VALUE, - NULL, /* Not inherited */ - PAGE_READWRITE, /* Read only */ - 0, /* High-order size */ - LOWORDERSIZE, /* Must be none 0 */ - MapObject); /* Named object */ - - - if(NULL == FileMappingHandle) - { - Fail("ERROR:%u:Failed to call CreateFileMapping to create " - "mapping object = \"%s\".\n", - GetLastError(), - MapObject); - } - if(GetLastError() == ERROR_ALREADY_EXISTS) - { - Trace("ERROR:File mapping object \"%s\" already exists!\n", - MapObject); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a named file-mapping object with - * FILE_MAP_READ access. - */ - OpenFileMappingHandle = OpenFileMapping( - FILE_MAP_READ, - 0, - MapObject); - - if(NULL == OpenFileMappingHandle) - { - Trace("ERROR:%u: Failed to Call OpenFileMapping API.\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a named file-mapping object with - * FILE_MAP_ALL_ACCESS access, to verify the - * READ-ONLY Map view. - */ - OpenFileMappingHandle2 = OpenFileMapping( - FILE_MAP_ALL_ACCESS, - 0, - MapObject); - - if(NULL == OpenFileMappingHandle2) - { - Trace("Failed to Call OpenFileMapping API!\n"); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Test the opened map view. - */ - lpMapViewAddress = MapViewOfFile( - OpenFileMappingHandle, - FILE_MAP_READ, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Open the second Map view to verify the writing - * of the READ-ONLY Map view. - */ - lpMapViewAddress2 = MapViewOfFile( - OpenFileMappingHandle2, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress2) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpFour; - } - - /* Write to the ALL_ACCESS Map View. - */ - memcpy(lpMapViewAddress2, buf, strlen(buf)); - - /* Read from the READ-ONLY Map View. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); - - /* Compare what was written to the Map View, - * to what was read. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpFive; - } - -CleanUpFive: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress2); - RetVal = FAIL; - } - -CleanUpFour: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpThree: - - /* Close Handle to opened file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle2) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle2); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opened file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(FileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - FileMappingHandle); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.cpp b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.cpp new file mode 100644 index 0000000000..b01a3e8c0b --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.cpp @@ -0,0 +1,217 @@ +// 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: openfilemappinga.c +** +** Purpose: Positive test the OpenFileMapping API. +** Call OpenFileMapping to open a named file-mapping +** object with FILE_MAP_READ access +** +** +**============================================================*/ +#include + + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE FileMappingHandle; + HANDLE OpenFileMappingHandle; + HANDLE OpenFileMappingHandle2; + HANDLE lpMapViewAddress; + HANDLE lpMapViewAddress2; + const int LOWORDERSIZE = 1024; + char buf[] = "this is a test"; + char MapObject[] = "myMappingObject"; + char ch[1024]; + int RetVal = PASS; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a named file-mapping object with file handle FileHandle. + */ + FileMappingHandle = CreateFileMapping( + INVALID_HANDLE_VALUE, + NULL, /* Not inherited */ + PAGE_READWRITE, /* Read only */ + 0, /* High-order size */ + LOWORDERSIZE, /* Must be none 0 */ + MapObject); /* Named object */ + + + if(NULL == FileMappingHandle) + { + Fail("ERROR:%u:Failed to call CreateFileMapping to create " + "mapping object = \"%s\".\n", + GetLastError(), + MapObject); + } + if(GetLastError() == ERROR_ALREADY_EXISTS) + { + Trace("ERROR:File mapping object \"%s\" already exists!\n", + MapObject); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a named file-mapping object with + * FILE_MAP_READ access. + */ + OpenFileMappingHandle = OpenFileMapping( + FILE_MAP_READ, + 0, + MapObject); + + if(NULL == OpenFileMappingHandle) + { + Trace("ERROR:%u: Failed to Call OpenFileMapping API.\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a named file-mapping object with + * FILE_MAP_ALL_ACCESS access, to verify the + * READ-ONLY Map view. + */ + OpenFileMappingHandle2 = OpenFileMapping( + FILE_MAP_ALL_ACCESS, + 0, + MapObject); + + if(NULL == OpenFileMappingHandle2) + { + Trace("Failed to Call OpenFileMapping API!\n"); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Test the opened map view. + */ + lpMapViewAddress = MapViewOfFile( + OpenFileMappingHandle, + FILE_MAP_READ, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Open the second Map view to verify the writing + * of the READ-ONLY Map view. + */ + lpMapViewAddress2 = MapViewOfFile( + OpenFileMappingHandle2, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress2) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpFour; + } + + /* Write to the ALL_ACCESS Map View. + */ + memcpy(lpMapViewAddress2, buf, strlen(buf)); + + /* Read from the READ-ONLY Map View. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); + + /* Compare what was written to the Map View, + * to what was read. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpFive; + } + +CleanUpFive: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress2); + RetVal = FAIL; + } + +CleanUpFour: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpThree: + + /* Close Handle to opened file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle2) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle2); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opened file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(FileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + FileMappingHandle); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/CMakeLists.txt index 04e9e47ef0..b2f4494ad8 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - OpenFileMappingW.c + OpenFileMappingW.cpp ) add_executable(paltest_openfilemappingw_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.c deleted file mode 100644 index 079af4a5c0..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.c +++ /dev/null @@ -1,155 +0,0 @@ -// 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: openfilemappingw.c (test 1) -** -** Purpose: Positive test the OpenFileMapping API. -** Call OpenFileMapping to open a named file-mapping -** object with FILE_MAP_ALL_ACCESS access -** -** -**============================================================*/ - -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE lpMapViewAddress; - char buf[] = "this is a test"; - char ch[1024]; - - HANDLE FileMappingHandle; - HANDLE OpenFileMappingHandle; - const int LOWORDERSIZE = 1024; - int RetVal = PASS; - WCHAR wpMappingFileObject[] = {'m','y','O','b','j','e','c','t','\0'}; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a unnamed file-mapping object with file handle FileHandle. - */ - FileMappingHandle = CreateFileMapping( - INVALID_HANDLE_VALUE, - NULL, /* Not inherited*/ - PAGE_READWRITE, /* Read and write*/ - 0, /* High-order size*/ - LOWORDERSIZE, /* Low-order size*/ - wpMappingFileObject);/* Named object*/ - - - if(NULL == FileMappingHandle) - { - Fail("\nFailed to call CreateFileMapping to create a " - "mapping object!\n"); - } - if(GetLastError() == ERROR_ALREADY_EXISTS) - { - Trace("\nFile mapping object already exists!\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a named file-mapping object with FILE_MAP_ALL_ACCESS access. - */ - OpenFileMappingHandle = OpenFileMapping( - FILE_MAP_ALL_ACCESS, - FALSE, - wpMappingFileObject); - - if(NULL == OpenFileMappingHandle) - { - Trace("\nFailed to Call OpenFileMapping API!\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Test the opened map view. - */ - lpMapViewAddress = MapViewOfFile( - OpenFileMappingHandle, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Write to the Map View. - */ - memcpy(lpMapViewAddress, buf, strlen(buf)); - - /* Read from the Map View. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); - - /* Compare what was written to the Map View, - * to what was read. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpThree; - } - -CleanUpThree: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opend file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(FileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - FileMappingHandle); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.cpp new file mode 100644 index 0000000000..079af4a5c0 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.cpp @@ -0,0 +1,155 @@ +// 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: openfilemappingw.c (test 1) +** +** Purpose: Positive test the OpenFileMapping API. +** Call OpenFileMapping to open a named file-mapping +** object with FILE_MAP_ALL_ACCESS access +** +** +**============================================================*/ + +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE lpMapViewAddress; + char buf[] = "this is a test"; + char ch[1024]; + + HANDLE FileMappingHandle; + HANDLE OpenFileMappingHandle; + const int LOWORDERSIZE = 1024; + int RetVal = PASS; + WCHAR wpMappingFileObject[] = {'m','y','O','b','j','e','c','t','\0'}; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a unnamed file-mapping object with file handle FileHandle. + */ + FileMappingHandle = CreateFileMapping( + INVALID_HANDLE_VALUE, + NULL, /* Not inherited*/ + PAGE_READWRITE, /* Read and write*/ + 0, /* High-order size*/ + LOWORDERSIZE, /* Low-order size*/ + wpMappingFileObject);/* Named object*/ + + + if(NULL == FileMappingHandle) + { + Fail("\nFailed to call CreateFileMapping to create a " + "mapping object!\n"); + } + if(GetLastError() == ERROR_ALREADY_EXISTS) + { + Trace("\nFile mapping object already exists!\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a named file-mapping object with FILE_MAP_ALL_ACCESS access. + */ + OpenFileMappingHandle = OpenFileMapping( + FILE_MAP_ALL_ACCESS, + FALSE, + wpMappingFileObject); + + if(NULL == OpenFileMappingHandle) + { + Trace("\nFailed to Call OpenFileMapping API!\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Test the opened map view. + */ + lpMapViewAddress = MapViewOfFile( + OpenFileMappingHandle, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write to the Map View. + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map View. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); + + /* Compare what was written to the Map View, + * to what was read. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(FileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + FileMappingHandle); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/CMakeLists.txt index 22e960b788..655fa753f2 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - OpenFileMappingW.c + OpenFileMappingW.cpp ) add_executable(paltest_openfilemappingw_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.c deleted file mode 100644 index e6a69651fa..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.c +++ /dev/null @@ -1,217 +0,0 @@ -// 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: openfilemappingw.c (test 2) -** -** Purpose: Positive test the OpenFileMapping API. -** Call OpenFileMapping to open a named file-mapping -** object with FILE_MAP_WRITE access -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE FileMappingHandle; - HANDLE OpenFileMappingHandle; - HANDLE lpMapViewAddress; - HANDLE OpenFileMappingHandle2; - HANDLE lpMapViewAddress2; - const int LOWORDERSIZE = 1024; - WCHAR MapObject[] = {'m','y','O','b','j','e','c','t','\0'}; - char buf[] = "this is a test"; - char ch[1024]; - int RetVal = PASS; - - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a named file-mapping object with file handle FileHandle. - */ - FileMappingHandle = CreateFileMapping( - INVALID_HANDLE_VALUE, - NULL, /* not inherited */ - PAGE_READWRITE, /* read and wite */ - 0, /* high-order size */ - LOWORDERSIZE, /* low-order size */ - MapObject); /* named object */ - - if(NULL == FileMappingHandle) - { - Fail("\nFailed to call CreateFileMapping to " - "create a mapping object!\n"); - } - if(GetLastError() == ERROR_ALREADY_EXISTS) - { - Trace("\nFile mapping object already exists!\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a named file-mapping object with FILE_MAP_WRITE access. - */ - OpenFileMappingHandle = OpenFileMapping( - FILE_MAP_WRITE, - FALSE, - MapObject); - - if(NULL == OpenFileMappingHandle) - { - Trace("\nFailed to Call OpenFileMappingW API!\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a named file-mapping object with - * FILE_MAP_ALL_ACCESS access, to verify - * the FILE_MAP_WRITE access map. - */ - OpenFileMappingHandle2 = OpenFileMapping( - FILE_MAP_ALL_ACCESS, - FALSE, - MapObject); - - if(NULL == OpenFileMappingHandle2) - { - Trace("\nFailed to Call OpenFileMappingW API!\n"); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Create map view of the open mapping that has - * FILE_MAP_WRITE access. - */ - lpMapViewAddress = MapViewOfFile( - OpenFileMappingHandle, - FILE_MAP_WRITE, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Create map view of the open mapping that has - * FILE_MAP_ALL_ACCESS access. - */ - - lpMapViewAddress2 = MapViewOfFile( - OpenFileMappingHandle2, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress2) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpFour; - } - - /* Write to the Map View. - */ - memcpy(lpMapViewAddress, buf, strlen(buf)); - - /* Read from the Map View. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); - - /* Compare what was written to the Map View, - * to what was read. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, buf); - RetVal = FAIL; - goto CleanUpFive; - } - - -CleanUpFive: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress2); - RetVal = FAIL; - } - -CleanUpFour: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpThree: - - /* Close Handle to opened file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle2) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle2); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opened file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(FileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - FileMappingHandle); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.cpp new file mode 100644 index 0000000000..e6a69651fa --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.cpp @@ -0,0 +1,217 @@ +// 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: openfilemappingw.c (test 2) +** +** Purpose: Positive test the OpenFileMapping API. +** Call OpenFileMapping to open a named file-mapping +** object with FILE_MAP_WRITE access +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE FileMappingHandle; + HANDLE OpenFileMappingHandle; + HANDLE lpMapViewAddress; + HANDLE OpenFileMappingHandle2; + HANDLE lpMapViewAddress2; + const int LOWORDERSIZE = 1024; + WCHAR MapObject[] = {'m','y','O','b','j','e','c','t','\0'}; + char buf[] = "this is a test"; + char ch[1024]; + int RetVal = PASS; + + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a named file-mapping object with file handle FileHandle. + */ + FileMappingHandle = CreateFileMapping( + INVALID_HANDLE_VALUE, + NULL, /* not inherited */ + PAGE_READWRITE, /* read and wite */ + 0, /* high-order size */ + LOWORDERSIZE, /* low-order size */ + MapObject); /* named object */ + + if(NULL == FileMappingHandle) + { + Fail("\nFailed to call CreateFileMapping to " + "create a mapping object!\n"); + } + if(GetLastError() == ERROR_ALREADY_EXISTS) + { + Trace("\nFile mapping object already exists!\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a named file-mapping object with FILE_MAP_WRITE access. + */ + OpenFileMappingHandle = OpenFileMapping( + FILE_MAP_WRITE, + FALSE, + MapObject); + + if(NULL == OpenFileMappingHandle) + { + Trace("\nFailed to Call OpenFileMappingW API!\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a named file-mapping object with + * FILE_MAP_ALL_ACCESS access, to verify + * the FILE_MAP_WRITE access map. + */ + OpenFileMappingHandle2 = OpenFileMapping( + FILE_MAP_ALL_ACCESS, + FALSE, + MapObject); + + if(NULL == OpenFileMappingHandle2) + { + Trace("\nFailed to Call OpenFileMappingW API!\n"); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Create map view of the open mapping that has + * FILE_MAP_WRITE access. + */ + lpMapViewAddress = MapViewOfFile( + OpenFileMappingHandle, + FILE_MAP_WRITE, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Create map view of the open mapping that has + * FILE_MAP_ALL_ACCESS access. + */ + + lpMapViewAddress2 = MapViewOfFile( + OpenFileMappingHandle2, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress2) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpFour; + } + + /* Write to the Map View. + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map View. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); + + /* Compare what was written to the Map View, + * to what was read. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpFive; + } + + +CleanUpFive: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress2); + RetVal = FAIL; + } + +CleanUpFour: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpThree: + + /* Close Handle to opened file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle2) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle2); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opened file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(FileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + FileMappingHandle); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/CMakeLists.txt index 5a54368110..a7039a1c73 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - OpenFileMappingW.c + OpenFileMappingW.cpp ) add_executable(paltest_openfilemappingw_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.c deleted file mode 100644 index 9c83491f6b..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.c +++ /dev/null @@ -1,210 +0,0 @@ -// 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: openfilemappingw.c (test 3) -** -** Purpose: Positive test the OpenFileMappingW API. -** Call OpenFileMappingW to open a named file-mapping -** object with FILE_MAP_READ access -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - char buf[] = "this is a test"; - char ch[1024]; - HANDLE FileMappingHandle; - HANDLE OpenFileMappingHandle; - HANDLE OpenFileMappingHandle2; - HANDLE lpMapViewAddress; - HANDLE lpMapViewAddress2; - const int LOWORDERSIZE = 1024; - int RetVal = PASS; - WCHAR wpMappingFileObject[] = {'m','y','O','b','j','e','c','t','\0'}; - - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a unnamed file-mapping object with file handle FileHandle. - */ - FileMappingHandle = CreateFileMapping( - INVALID_HANDLE_VALUE, - NULL, /* not inherited */ - PAGE_READWRITE, /* read and wite */ - 0, /* high-order size */ - LOWORDERSIZE, /* must be non-zero */ - wpMappingFileObject);/* named object */ - - if(NULL == FileMappingHandle) - { - Fail("\nFailed to call CreateFileMapping to create mapping object!\n"); - } - if(GetLastError() == ERROR_ALREADY_EXISTS) - { - Trace("\nFile mapping object already exists!\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a named file-mapping object with FILE_MAP_ALL_ACCESS access. - */ - OpenFileMappingHandle = OpenFileMapping( - FILE_MAP_READ, - FALSE, - wpMappingFileObject); - - if(NULL == OpenFileMappingHandle) - { - Trace("\nFailed to Call OpenFileMapping API!\n"); - RetVal = FAIL; - goto CleanUpOne; - } - - /* Open a file mapping with FILE_MAP_ALL_ACCESS access, - * to verify the FILE_MAP_READ. - */ - OpenFileMappingHandle2 = OpenFileMapping( - FILE_MAP_ALL_ACCESS, - FALSE, - wpMappingFileObject); - - if(NULL == OpenFileMappingHandle2) - { - Trace("\nFailed to Call OpenFileMapping API!\n"); - RetVal = FAIL; - goto CleanUpTwo; - } - - /* Test the opened map view. - */ - lpMapViewAddress = MapViewOfFile( - OpenFileMappingHandle, - FILE_MAP_READ, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpThree; - } - - /* Open a map view with FILE_MAP_ALL_ACCESS to verify, - * the FILE_MAP_READ view. - */ - lpMapViewAddress2 = MapViewOfFile( - OpenFileMappingHandle2, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - LOWORDERSIZE); /* number of bytes for map */ - - if(NULL == lpMapViewAddress2) - { - Trace("2ERROR:%u: Failed to call MapViewOfFile " - "API to map a view of file!\n", - GetLastError()); - RetVal = FAIL; - goto CleanUpFour; - } - - /* Write to the Map View. - */ - memcpy(lpMapViewAddress2, buf, strlen(buf)); - /* Read from the Map View. - */ - memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); - - /* Compare what was written to the Map View, - * to what was read. - */ - if (memcmp(ch, buf, strlen(buf))!= 0) - { - Trace("ERROR: MapViewOfFile not equal to file contents " - "retrieved \"%s\", expected \"%s\".\n", - ch, - buf); - RetVal = FAIL; - goto CleanUpFive; - } - -CleanUpFive: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress2); - RetVal = FAIL; - } - -CleanUpFour: - - /* Unmap the view of file. - */ - if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) - { - Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", - GetLastError(), - lpMapViewAddress); - RetVal = FAIL; - } - -CleanUpThree: - - /* Close Handle to opened file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle2) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle2); - RetVal = FAIL; - } - -CleanUpTwo: - - /* Close Handle to opened file mapping. - */ - if ( CloseHandle(OpenFileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - OpenFileMappingHandle); - RetVal = FAIL; - } - -CleanUpOne: - - /* Close Handle to create file mapping. - */ - if ( CloseHandle(FileMappingHandle) == 0 ) - { - Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", - GetLastError(), - FileMappingHandle); - RetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_TerminateEx(RetVal); - return RetVal; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.cpp b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.cpp new file mode 100644 index 0000000000..9c83491f6b --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.cpp @@ -0,0 +1,210 @@ +// 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: openfilemappingw.c (test 3) +** +** Purpose: Positive test the OpenFileMappingW API. +** Call OpenFileMappingW to open a named file-mapping +** object with FILE_MAP_READ access +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + char buf[] = "this is a test"; + char ch[1024]; + HANDLE FileMappingHandle; + HANDLE OpenFileMappingHandle; + HANDLE OpenFileMappingHandle2; + HANDLE lpMapViewAddress; + HANDLE lpMapViewAddress2; + const int LOWORDERSIZE = 1024; + int RetVal = PASS; + WCHAR wpMappingFileObject[] = {'m','y','O','b','j','e','c','t','\0'}; + + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a unnamed file-mapping object with file handle FileHandle. + */ + FileMappingHandle = CreateFileMapping( + INVALID_HANDLE_VALUE, + NULL, /* not inherited */ + PAGE_READWRITE, /* read and wite */ + 0, /* high-order size */ + LOWORDERSIZE, /* must be non-zero */ + wpMappingFileObject);/* named object */ + + if(NULL == FileMappingHandle) + { + Fail("\nFailed to call CreateFileMapping to create mapping object!\n"); + } + if(GetLastError() == ERROR_ALREADY_EXISTS) + { + Trace("\nFile mapping object already exists!\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a named file-mapping object with FILE_MAP_ALL_ACCESS access. + */ + OpenFileMappingHandle = OpenFileMapping( + FILE_MAP_READ, + FALSE, + wpMappingFileObject); + + if(NULL == OpenFileMappingHandle) + { + Trace("\nFailed to Call OpenFileMapping API!\n"); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Open a file mapping with FILE_MAP_ALL_ACCESS access, + * to verify the FILE_MAP_READ. + */ + OpenFileMappingHandle2 = OpenFileMapping( + FILE_MAP_ALL_ACCESS, + FALSE, + wpMappingFileObject); + + if(NULL == OpenFileMappingHandle2) + { + Trace("\nFailed to Call OpenFileMapping API!\n"); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Test the opened map view. + */ + lpMapViewAddress = MapViewOfFile( + OpenFileMappingHandle, + FILE_MAP_READ, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Open a map view with FILE_MAP_ALL_ACCESS to verify, + * the FILE_MAP_READ view. + */ + lpMapViewAddress2 = MapViewOfFile( + OpenFileMappingHandle2, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + LOWORDERSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress2) + { + Trace("2ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpFour; + } + + /* Write to the Map View. + */ + memcpy(lpMapViewAddress2, buf, strlen(buf)); + /* Read from the Map View. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); + + /* Compare what was written to the Map View, + * to what was read. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, + buf); + RetVal = FAIL; + goto CleanUpFive; + } + +CleanUpFive: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress2); + RetVal = FAIL; + } + +CleanUpFour: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpThree: + + /* Close Handle to opened file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle2) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle2); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opened file mapping. + */ + if ( CloseHandle(OpenFileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + OpenFileMappingHandle); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(FileMappingHandle) == 0 ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + FileMappingHandle); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/CMakeLists.txt new file mode 100644 index 0000000000..c6eddf74e8 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(ProbeMemory_neg1) +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/CMakeLists.txt new file mode 100644 index 0000000000..e96c92e2ae --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + ProbeMemory_neg.cpp +) + +add_executable(paltest_probememory_probememory_neg1 + ${SOURCES} +) + +add_dependencies(paltest_probememory_probememory_neg1 coreclrpal) + +target_link_libraries(paltest_probememory_probememory_neg1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/ProbeMemory_neg.cpp b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/ProbeMemory_neg.cpp new file mode 100644 index 0000000000..80de809e14 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/ProbeMemory_neg.cpp @@ -0,0 +1,95 @@ +// 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: ReadProcessMemory_neg.c +** +** Purpose: Negative test the ReadProcessMemory API. +** Call ReadProcessMemory to read unreadabel memory area +** +** +**============================================================*/ +#include + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + BOOL bResult; + LPVOID lpProcessAddress = NULL; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*allocate the virtual memory*/ + lpProcessAddress = VirtualAlloc( + NULL, /*system determine where to allocate the region*/ + REGIONSIZE, /*specify the size*/ + MEM_RESERVE, /*allocation type*/ + PAGE_READONLY); /*access protection*/ + + if(NULL == lpProcessAddress) + { + Fail("\nFailed to call VirtualAlloc API to allocate " + "virtual memory, error code=%u\n", GetLastError()); + } + + /*try to probe the unreadable memory area*/ + bResult = PAL_ProbeMemory( + lpProcessAddress, /*base of memory area*/ + REGIONSIZE, /*buffer length in bytes*/ + FALSE); /*read access*/ + + /*check the return value*/ + if(bResult) + { + Trace("\nProbeMemory for read didn't FAILED\n"); + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + Fail(""); + } + + /*try to probe the unwriteable memory area*/ + bResult = PAL_ProbeMemory( + lpProcessAddress, /*base of memory area*/ + REGIONSIZE, /*buffer length in bytes*/ + FALSE); /*write access */ + + /*check the return value*/ + if(bResult) + { + Trace("\nProbeMemory for write didn't FAILED\n"); + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + Fail(""); + } + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/testinfo.dat new file mode 100644 index 0000000000..4d11a71bdb --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/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 = Filemapping_memmgt +Function = PAL_ProbeMemory +Name = Negative test PAL_ProbeMemory API to read unreadable memory area +TYPE = DEFAULT +EXE1 = probememory_neg +Description +=Test the PAL_ProbeMemory to read unreadable memory area diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/CMakeLists.txt new file mode 100644 index 0000000000..739ba62284 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + ProbeMemory.cpp +) + +add_executable(paltest_probememory_test1 + ${SOURCES} +) + +add_dependencies(paltest_probememory_test1 coreclrpal) + +target_link_libraries(paltest_probememory_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/ProbeMemory.cpp b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/ProbeMemory.cpp new file mode 100644 index 0000000000..30b358d315 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/ProbeMemory.cpp @@ -0,0 +1,94 @@ +// 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: ReadProcessMemory.c +** +** Purpose: Positive test the ReadProcessMemory API. +** Call ReadProcessMemory to read memory contents +** inside current process. +** +** +**============================================================*/ +#include + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + BOOL bResult; + LPVOID lpProcessAddress = NULL; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*allocate the virtual memory*/ + lpProcessAddress = VirtualAlloc( + NULL, /*system determine where to allocate the region*/ + REGIONSIZE, /*specify the size*/ + MEM_COMMIT, /*allocation type*/ + PAGE_READWRITE); /*access protection*/ + + if(NULL == lpProcessAddress) + { + Fail("\nFailed to call VirtualAlloc API to allocate " + "virtual memory, error code=%u!\n", GetLastError()); + } + + /*probe the memory for read*/ + bResult = PAL_ProbeMemory( + lpProcessAddress, /*base of memory area*/ + REGIONSIZE, /*buffer length in bytes*/ + FALSE); /*read access*/ + + if(!bResult) + { + Trace("\nProbeMemory for read access FAILED\n"); + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + Fail(""); + } + + /*probe the memory for write */ + bResult = PAL_ProbeMemory( + lpProcessAddress, /*base of memory area*/ + REGIONSIZE, /*buffer length in bytes*/ + TRUE); /*write access*/ + + if(!bResult) + { + Trace("\nProbeMemory for write access FAILED\n"); + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + Fail(""); + } + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/testinfo.dat new file mode 100644 index 0000000000..512b945c4a --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/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 = Filemapping_memmgt +Function = PAL_ProbeMemory +Name = Positive test for PAL_ProbeMemory API to probe for read/write +TYPE = DEFAULT +EXE1 = probememory +Description +=Test the PAL_ProbeMemory to probe for read and write diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/CMakeLists.txt deleted file mode 100644 index d2ae61f923..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(ReadProcessMemory_neg1) -add_subdirectory(test1) -add_subdirectory(test2) - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/CMakeLists.txt deleted file mode 100644 index 400c9219f6..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - ReadProcessMemory_neg.c -) - -add_executable(paltest_readprocessmemory_readprocessmemory_neg1 - ${SOURCES} -) - -add_dependencies(paltest_readprocessmemory_readprocessmemory_neg1 coreclrpal) - -target_link_libraries(paltest_readprocessmemory_readprocessmemory_neg1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/ReadProcessMemory_neg.c b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/ReadProcessMemory_neg.c deleted file mode 100644 index aecd5ad576..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/ReadProcessMemory_neg.c +++ /dev/null @@ -1,127 +0,0 @@ -// 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: ReadProcessMemory_neg.c -** -** Purpose: Negative test the ReadProcessMemory API. -** Call ReadProcessMemory to read unreadabel memory area -** -** -**============================================================*/ -#include - -#define REGIONSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - BOOL bResult; - HANDLE ProcessHandle; - DWORD ProcessID; - LPVOID lpProcessAddress = NULL; - char ProcessBuffer[REGIONSIZE]; - ULONG_PTR size = 0; - - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*retrieve the current process ID*/ - ProcessID = GetCurrentProcessId(); - - /*retrieve the current process handle*/ - ProcessHandle = OpenProcess( - PROCESS_ALL_ACCESS, - FALSE, /*not inherited*/ - ProcessID); - - if(NULL == ProcessHandle) - { - Fail("\nFailed to call OpenProcess API to retrieve " - "current process handle error code=%u\n", - GetLastError()); - } - - - - /*allocate the virtual memory*/ - lpProcessAddress = VirtualAlloc( - NULL, /*system determine where to allocate the region*/ - REGIONSIZE, /*specify the size*/ - MEM_RESERVE, /*allocation type*/ - PAGE_READONLY); /*access protection*/ - - if(NULL == lpProcessAddress) - { - Fail("\nFailed to call VirtualAlloc API to allocate " - "virtual memory, error code=%u\n", GetLastError()); - } - - /*zero the memory*/ - memset(ProcessBuffer, 0, REGIONSIZE); - /*try to retrieve the unreadable memory area*/ - bResult = ReadProcessMemory( - ProcessHandle, /*current process handle*/ - lpProcessAddress, /*base of memory area*/ - (LPVOID)ProcessBuffer, - REGIONSIZE, /*buffer length in bytes*/ - &size); - - - /*check the return value*/ - if(0 != bResult) - { - Trace("\nFailed to call ReadProcessMemory API for a negative test, " - "Try to read an unreadable memory area will cause fail " - "but it successes\n"); - - err = CloseHandle(ProcessHandle); - if(0 == err) - { - Trace("\nFailed to call CloseHandle API, error code=%u\n", - GetLastError()); - } - - /*decommit the specified region*/ - err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); - if(0 == err) - { - Trace("\nFailed to call VirtualFree API, error code=%u\n", - GetLastError()); - } - Fail(""); - } - - err = CloseHandle(ProcessHandle); - if(0 == err) - { - Trace("\nFailed to call CloseHandle API, error code = %u\n", - GetLastError()); - - err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); - if(0 == err) - { - Trace("\nFailed to call VirtualFree API, error code=%u\n", - GetLastError()); - } - - Fail(""); - } - /*decommit the specified region*/ - err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API, error code=%u\n", - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/testinfo.dat deleted file mode 100644 index 08c8f3291d..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = Filemapping_memmgt -Function = ReadProcessMemory -Name = Negative test ReadProcessMemory API to read unreadable memory area -TYPE = DEFAULT -EXE1 = readprocessmemory_neg -Description -=Test the ReadProcessMemory to read unreadable memory area diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/CMakeLists.txt deleted file mode 100644 index 8c21f01562..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - ReadProcessMemory.c -) - -add_executable(paltest_readprocessmemory_test1 - ${SOURCES} -) - -add_dependencies(paltest_readprocessmemory_test1 coreclrpal) - -target_link_libraries(paltest_readprocessmemory_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/ReadProcessMemory.c b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/ReadProcessMemory.c deleted file mode 100644 index c9475f13f1..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/ReadProcessMemory.c +++ /dev/null @@ -1,126 +0,0 @@ -// 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: ReadProcessMemory.c -** -** Purpose: Positive test the ReadProcessMemory API. -** Call ReadProcessMemory to read memory contents -** inside current process. -** -** -**============================================================*/ -#include - -#define REGIONSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - BOOL bResult; - HANDLE ProcessHandle; - DWORD ProcessID; - LPVOID lpProcessAddress = NULL; - char ProcessBuffer[REGIONSIZE]; - ULONG_PTR size = 0; - - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*retrieve the current process ID*/ - ProcessID = GetCurrentProcessId(); - - /*retrieve the current process handle*/ - ProcessHandle = OpenProcess( - PROCESS_VM_READ,/*access flag*/ - FALSE, /*not inherited*/ - ProcessID); - - if(NULL == ProcessHandle) - { - Fail("\nFailed to call OpenProcess API to retrieve " - "current process handle error code=%u\n", - GetLastError()); - } - - /*allocate the virtual memory*/ - lpProcessAddress = VirtualAlloc( - NULL, /*system determine where to allocate the region*/ - REGIONSIZE, /*specify the size*/ - MEM_COMMIT, /*allocation type*/ - PAGE_READONLY); /*access protection*/ - - if(NULL == lpProcessAddress) - { - Fail("\nFailed to call VirtualAlloc API to allocate " - "virtual memory, error code=%u!\n", GetLastError()); - } - - /*zero the memory*/ - memset(ProcessBuffer, 0, REGIONSIZE); - - /*retrieve the memory contents*/ - bResult = ReadProcessMemory( - ProcessHandle, /*current process handle*/ - lpProcessAddress, /*base of memory area*/ - (LPVOID)ProcessBuffer, - REGIONSIZE, /*buffer length in bytes*/ - &size); - - if(!bResult || REGIONSIZE != size) - { - Trace("\nFailed to call ReadProcessMemory API " - "to retrieve the memory contents, error code=%u\n", - GetLastError()); - - err = CloseHandle(ProcessHandle); - if(0 == err) - { - Trace("\nFailed to call CloseHandle API, error code=%u\n", - GetLastError()); - } - - /*decommit the specified region*/ - err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); - if(0 == err) - { - Trace("\nFailed to call VirtualFree API, error code=%u\n", - GetLastError()); - } - Fail(""); - } - - err = CloseHandle(ProcessHandle); - if(0 == err) - { - Trace("\nFailed to call CloseHandle API, error code = %u\n", - GetLastError()); - - err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); - if(0 == err) - { - Trace("\nFailed to call VirtualFree API, error code=%u\n", - GetLastError()); - } - - Fail(""); - } - - /*decommit the specified region*/ - err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API, error code=%u\n", - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/testinfo.dat deleted file mode 100644 index c56920d206..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = Filemapping_memmgt -Function = ReadProcessMemory -Name = Positive test for ReadProcessMemory API to read memory contents -TYPE = DEFAULT -EXE1 = readprocessmemory -Description -=Test the ReadProcessMemory to read the memory contents diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/CMakeLists.txt deleted file mode 100644 index 9e0de95a0a..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(TESTSOURCES - test2.c -) - -add_executable(paltest_readprocessmemory_test2 - ${TESTSOURCES} -) - -add_dependencies(paltest_readprocessmemory_test2 coreclrpal) - -target_link_libraries(paltest_readprocessmemory_test2 - pthread - m - coreclrpal -) - - -set(HELPERSOURCES - helper.c -) - -add_executable(paltest_readprocessmemory_test2_helper - ${HELPERSOURCES} -) - -add_dependencies(paltest_readprocessmemory_test2_helper coreclrpal) - -target_link_libraries(paltest_readprocessmemory_test2_helper - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/commonconsts.h b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/commonconsts.h deleted file mode 100644 index 433d820f0f..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/commonconsts.h +++ /dev/null @@ -1,48 +0,0 @@ -// 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: commonconsts.h -** -** -**============================================================*/ - -#ifndef _COMMONCONSTS_H_ -#define _COMMONCONSTS_H_ - -#include -#define REGIONSIZE 1024 - -const int TIMEOUT = 40000; - -const WCHAR szcToHelperEvName[] = { 'T', 'o', '\0' }; -const WCHAR szcFromHelperEvName[] = { 'F', 'r', 'o', 'm', '\0' }; - -const char initialValue = '-'; -const char nextValue = '|'; -const char guardValue = '*'; -const char *commsFileName = "AddrNLen.dat"; - - -/* PEDANTIC and PEDANTIC0 is a helper macro that just grumps about any - * zero return codes in a generic way. with little typing */ -#define PEDANTIC(function, parameters) \ -{ \ - if (! (function parameters) ) \ - { \ - Trace("%s: NonFatal failure of %s%s for reasons %u and %u\n", \ - __FILE__, #function, #parameters, GetLastError(), errno); \ - } \ -} -#define PEDANTIC1(function, parameters) \ -{ \ - if ( (function parameters) ) \ - { \ - Trace("%s: NonFatal failure of %s%s for reasons %u and %u\n", \ - __FILE__, #function, #parameters, GetLastError(), errno); \ - } \ -} - -#endif diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/helper.c deleted file mode 100644 index 59e882fc1f..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/helper.c +++ /dev/null @@ -1,249 +0,0 @@ -// 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: helper.c -** -** Purpose: This helper process sets up a several blocks of memory, -** then uses a file to tell its parent process where that memory is -** So it can do a WriteProcessMemory on it. When the parent process is done -** we check here that it was written properly. -** -** -**============================================================*/ - -#include "commonconsts.h" - -#include - -#if defined(BIT64) && defined(PLATFORM_UNIX) -#define LLFORMAT "%I64u" -#else -#define LLFORMAT "%u" -#endif - -struct allhandles_t -{ - HANDLE hEvToHelper; - HANDLE hEvFromHelper; - char *valuesFileName; -}; - - -/* function: wpmDoIt - * - * This is a general WriteProcessMemory testing function that sets up - * the RAM pointed to and tells the companion process on the other end - * of the handles in 'Comms' to attempt to alter 'lenDest' bytes at - * '*pDest'. - * - * '*pBuffer'[0..'lenBuffer'] is expected to be a guard region - * surrounding the '*pDest'[0..'lenDest'] region so that this function - * can verify that only the proper bytes were altered. - */ - -int wpmDoIt(struct allhandles_t Comms, - char * pBuffer, unsigned int lenBuffer, - char * pDest, unsigned int lenDest, - const char* storageDescription) -{ - char *pCurr; - FILE *commsFile; - DWORD dwRet; - - if (pBuffer > pDest || lenDest > lenBuffer) - { - Trace("WriteProcessMemory::DoIt() test implementation: " - "(pBuffer > pDest || lenDest > lenBuffer)\n"); - return FALSE; - } - - /* set up the storage */ - memset(pBuffer, guardValue, lenBuffer); - memset(pDest, initialValue, lenDest); - - /* tell the parent what RAM to adjust */ - if(!(commsFile = fopen(Comms.valuesFileName, "w"))) - { - Trace("WriteProcessMemory: fopen of '%S' failed (%u). \n", - Comms.valuesFileName, GetLastError()); - return FALSE; - } - if (!fprintf(commsFile, LLFORMAT " " LLFORMAT " '%s'\n", - pDest, lenDest, storageDescription)) - { - Trace("WriteProcessMemory: fprintf to '%S' failed (%u). \n", - Comms.valuesFileName, GetLastError()); - return FALSE; - } - PEDANTIC1(fclose, (commsFile)); - - /* Tell the parent the data is ready for it to adjust */ - PEDANTIC(ResetEvent, (Comms.hEvToHelper)); - PEDANTIC(SetEvent, (Comms.hEvFromHelper)); - - dwRet = WaitForSingleObject(Comms.hEvToHelper, TIMEOUT); /* parent is done */ - if (dwRet != WAIT_OBJECT_0) - { - Trace("helper WaitForSingleObjectTest: WaitForSingleObject " - "failed (%u)\n", GetLastError()); - return FALSE; - } - - /* check the stuff that SHOULD have changed */ - for (pCurr = pDest; pCurr < (pDest + lenDest); pCurr++) - { - if ( *pCurr != nextValue) - { - Trace("When testing '%s': alteration test failed " - "at " LLFORMAT " offset " LLFORMAT " Found '%c' instead of '%c'\n.", - storageDescription, pDest, pCurr - pDest, *pCurr, nextValue); - Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer); - return FALSE; - } - } - /* check the stuff that should NOT have changed */ - for (pCurr = pBuffer; pCurr < pDest; pCurr++ ) - { - if ( *pCurr != guardValue) - { - Trace("When testing '%s': leading guard zone test failed " - "at " LLFORMAT " offset " LLFORMAT ". Found '%c' instead of '%c'\n.", - storageDescription, pDest, pCurr - pBuffer, *pCurr, guardValue); - Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer); - return FALSE; - } - } - for (pCurr = pDest + lenDest; pCurr < (pBuffer + lenBuffer); pCurr++ ) - { - if ( *pCurr != guardValue) - { - Trace("When testing '%s': trailing guard zone test failed " - "at " LLFORMAT " offset " LLFORMAT ". Found '%c' instead of '%c'\n.", - storageDescription, pDest + lenDest, pCurr - pBuffer, *pCurr, guardValue); - Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer); - return FALSE; - } - } - - return TRUE; -} - -int __cdecl main(int argc, char *argv[]) -{ - - BOOL success = TRUE; /* assume success */ - struct allhandles_t Comms = {0,0,0} ; - - /* variables to track storage to alter */ - char *pTarget = NULL; - unsigned int sizeTarget; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* hook up with the events created by the parent */ - Comms.hEvToHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcToHelperEvName); - if (!Comms.hEvToHelper) - { - Fail("WriteProcessMemory: OpenEvent of '%S' failed (%u). " - "(the event should already exist!)\n", - szcToHelperEvName, GetLastError()); - } - Comms.hEvFromHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcFromHelperEvName); - if (!Comms.hEvToHelper) - { - Trace("WriteProcessMemory: OpenEvent of '%S' failed (%u). " - "(the event should already exist!)\n", - szcFromHelperEvName, GetLastError()); - success = FALSE; - goto EXIT; - } - Comms.valuesFileName = argv[1]; - - { - char autoAllocatedOnStack[51]; - - /* Get the parent process to write to the local stack */ - success &= wpmDoIt(Comms, autoAllocatedOnStack, - sizeof(autoAllocatedOnStack), - autoAllocatedOnStack + sizeof(int), - sizeof(autoAllocatedOnStack) - 2 * sizeof(int), - "const size array on stack with int sized guards"); - } - - /* Get the parent process to write to stuff on the heap */ - sizeTarget = 2 * sizeof(int) + 23 ; /* 23 is just a random prime > 16 */ - if (!(pTarget = malloc(sizeTarget))) - { - Trace("WriteProcessMemory helper: unable to allocate '%s'->%d bytes of memory" - "(%u).\n", - argv[3], sizeTarget, GetLastError()); - success = FALSE; - goto EXIT; - - } - success &= wpmDoIt(Comms, pTarget, sizeTarget, - pTarget + sizeof(int), - sizeTarget - 2 * sizeof(int), - "array on heap with int sized guards"); - - /* just to be nice try something 16 - 2 * sizeof(int) bytes long */ - { - char autoAllocatedOnStack[16]; - - /* Get the parent process to write to the local stack */ - success &= wpmDoIt(Comms, autoAllocatedOnStack, - sizeof(autoAllocatedOnStack), - autoAllocatedOnStack + sizeof(int), - sizeof(autoAllocatedOnStack) - 2 * sizeof(int), - "another 16 byte array on stack with int sized guards inside"); - } - - /* NOTE: Don't try 0 bytes long. Win32 WriteProcessMemory claims - * it writes 8 bytes in that case! */ - - /* and 1 byte long... */ - { - char autoAllocatedOnStack[1+ 2 * sizeof(int)]; - - /* Get the parent process to write to the local stack */ - success &= wpmDoIt(Comms, autoAllocatedOnStack, - sizeof(autoAllocatedOnStack), - autoAllocatedOnStack + sizeof(int), - 1, - "no bytes with int sized guards outside on stack"); - } - - -EXIT: - /* Tell the parent that we are done */ - if (!DeleteFile(Comms.valuesFileName)) - { - Trace("helper: DeleteFile failed so parent (test1) is unlikely " - "to exit cleanly\n"); - } - PEDANTIC(ResetEvent, (Comms.hEvToHelper)); - if (!SetEvent(Comms.hEvFromHelper)) - { - Trace("helper: SetEvent failed so parent (test1) is unlikely " - "to exit cleanly\n"); - } - - free(pTarget); - PEDANTIC(CloseHandle, (Comms.hEvToHelper)); - PEDANTIC(CloseHandle, (Comms.hEvFromHelper)); - - if (!success) - { - Fail(""); - } - - PAL_Terminate(); - - return success ? PASS : FAIL; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/test2.c deleted file mode 100644 index eda40599ce..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/test2.c +++ /dev/null @@ -1,258 +0,0 @@ -// 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: test2.c -** -** Purpose: Create a child process and some events for communications with it. -** When the child gets back to us with a memory location and a length, -** Call WriteProcessMemory on this location and check to see that it -** writes successfully. Then call ReadProcessMemory to check if the -** contents read are same as those written -** -** -**============================================================*/ - -#define UNICODE - -#include "commonconsts.h" - -#include - -#if defined(BIT64) && defined(PLATFORM_UNIX) -#define LLFORMAT "%I64u" -#else -#define LLFORMAT "%u" -#endif - -int __cdecl main(int argc, char *argv[]) -{ - - PROCESS_INFORMATION pi; - STARTUPINFO si; - HANDLE hEvToHelper; - HANDLE hEvFromHelper; - DWORD dwExitCode; - - DWORD dwRet; - char cmdComposeBuf[MAX_PATH]; - PWCHAR uniString; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Create the signals we need for cross process communication */ - hEvToHelper = CreateEvent(NULL, TRUE, FALSE, szcToHelperEvName); - if (!hEvToHelper) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "GetLastError() returned %d.\n", szcToHelperEvName, - GetLastError()); - } - if (GetLastError() == ERROR_ALREADY_EXISTS) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "(already exists!)\n", szcToHelperEvName); - } - hEvFromHelper = CreateEvent(NULL, TRUE, FALSE, szcFromHelperEvName); - if (!hEvToHelper) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "GetLastError() returned %d.\n", szcFromHelperEvName, - GetLastError()); - } - if (GetLastError() == ERROR_ALREADY_EXISTS) - { - Fail("WriteProcessMemory: CreateEvent of '%S' failed. " - "(already exists!)\n", szcFromHelperEvName); - } - ResetEvent(hEvFromHelper); - ResetEvent(hEvToHelper); - - if (!sprintf(cmdComposeBuf, "helper %s", commsFileName)) - { - Fail("Could not convert command line\n"); - } - uniString = convert(cmdComposeBuf); - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - /* Create a new process. This is the process that will ask for - * memory munging */ - if(!CreateProcess( NULL, uniString, NULL, NULL, - FALSE, 0, NULL, NULL, &si, &pi)) - { - Trace("ERROR: CreateProcess failed to load executable '%S'. " - "GetLastError() returned %u.\n", - uniString, GetLastError()); - free(uniString); - Fail(""); - } - free(uniString); - - - while(1) - { - FILE *commsFile; - char* pSrcMemory; - char* pDestMemory; - SIZE_T Count; - SIZE_T wpmCount; - char incomingCMDBuffer[MAX_PATH + 1]; - - int err; - HANDLE readProcessHandle; - DWORD readProcessID; - char readProcessBuffer[REGIONSIZE]; // size 1024 - BOOL bResult; - size_t size = 0; - - readProcessID = pi.dwProcessId; - - /* wait until the helper tells us that it has given us - * something to do */ - dwRet = WaitForSingleObject(hEvFromHelper, TIMEOUT); - if (dwRet != WAIT_OBJECT_0) - { - Trace("test1 WaitForSingleObjectTest: WaitForSingleObject " - "failed (%u)\n", GetLastError()); - break; /* no more work incoming */ - } - - /* get the parameters to test WriteProcessMemory with */ - if (!(commsFile = fopen(commsFileName, "r"))) - { - /* no file means there is no more work */ - break; - } - if ( NULL == fgets(incomingCMDBuffer, MAX_PATH, commsFile)) - { - Fail ("unable to read from communication file %s " - "for reasons %u & %u\n", - errno, GetLastError()); - } - PEDANTIC1(fclose,(commsFile)); - sscanf(incomingCMDBuffer, LLFORMAT " " LLFORMAT, &pDestMemory, &Count); - if (argc > 1) - { - Trace("Preparing to write to " LLFORMAT " bytes @ " LLFORMAT "('%s')\n", - Count, pDestMemory, incomingCMDBuffer); - } - - /* compose some data to write to the client process */ - if (!(pSrcMemory = malloc(Count))) - { - Trace("could not dynamically allocate memory to copy from " - "for reasons %u & %u\n", - errno, GetLastError()); - goto doneIteration; - } - memset(pSrcMemory, nextValue, Count); - Trace("Preparing to write to " LLFORMAT " bytes @ " LLFORMAT " ('%s')[%u]\n", - Count, pDestMemory, incomingCMDBuffer, pSrcMemory); - - /* do the work */ - dwRet = WriteProcessMemory(pi.hProcess, - pDestMemory, - pSrcMemory, - Count, - &wpmCount); - - if (!dwRet) - { - Trace("%s: Problem: on a write to "LLFORMAT " bytes @ " LLFORMAT " ('%s')\n", - argv[0], Count, pDestMemory, incomingCMDBuffer); - Trace("test1 WriteProcessMemory returned a (!=0) (GLE=%u)\n", - GetLastError()); - } - if(Count != wpmCount) - { - Trace("%s: Problem: on a write to " LLFORMAT " bytes @ " LLFORMAT " ('%s')\n", - argv[0], Count, pDestMemory, incomingCMDBuffer); - Trace("The number of bytes written should have been " - LLFORMAT ", but was reported as " LLFORMAT " \n", Count, wpmCount); - } - - readProcessHandle = OpenProcess( - PROCESS_VM_READ, - FALSE, - readProcessID); - - if(NULL == readProcessHandle) - { - Fail("\nFailed to call OpenProcess API to retrieve " - "current process handle error code=%u\n", - GetLastError()); - } - - /*zero the memory*/ - memset(readProcessBuffer, 0, size); - - /*retrieve the memory contents*/ - bResult = ReadProcessMemory( - readProcessHandle, /*current process handle*/ - pDestMemory, /*base of memory area*/ - (LPVOID)readProcessBuffer, - Count, /*buffer length in bytes*/ - &size); - - - if( !bResult || (Count != size) ) - { - Trace("\nFailed to call ReadProcessMemory API " - "to retrieve the memory contents, error code=%u; Bresult[%u] Count[" LLFORMAT "], Size[%d]\n", - GetLastError(), bResult, Count, size); - - err = CloseHandle(readProcessHandle); - - if(0 == err) - { - Trace("\nFailed to call CloseHandle API, error code=%u\n", - GetLastError()); - } - dwExitCode = FAIL; - } - - if( !memcmp (pDestMemory, readProcessBuffer, Count ) ) - { - Trace("Difference in memory contents, expected [%s], but received [%s]\n", pDestMemory, readProcessBuffer); - dwExitCode = FAIL; - } - - Trace("ReadProcessBuffer contains [%s]\n", readProcessBuffer); - err = CloseHandle(readProcessHandle); - - free(pSrcMemory); - - doneIteration: - PEDANTIC(ResetEvent, (hEvFromHelper)); - PEDANTIC(SetEvent, (hEvToHelper)); - } - - /* wait for the child process to complete */ - WaitForSingleObject ( pi.hProcess, TIMEOUT ); - /* this may return a failure code on a success path */ - - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) - { - Trace( "GetExitCodeProcess call failed with error code %u\n", - GetLastError() ); - dwExitCode = FAIL; - } - - - PEDANTIC(CloseHandle, (hEvToHelper)); - PEDANTIC(CloseHandle, (hEvFromHelper)); - PEDANTIC(CloseHandle, (pi.hThread)); - PEDANTIC(CloseHandle, (pi.hProcess)); - - PAL_TerminateEx(dwExitCode); - return dwExitCode; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/testinfo.dat deleted file mode 100644 index 58a9935a08..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/testinfo.dat +++ /dev/null @@ -1,18 +0,0 @@ -# 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 = Debug -Function = ReadProcessMemory -Name = Check that writing/reading text to/from process memory succeeds. -TYPE = DEFAULT -EXE1 = test2 -EXE2 = helper -Description -= Create a child process and attempt to write to its memory -= at the places and lengths it specifies via a data file. -= the child verifies that all the specified memory was altered -= with no overruns. Parent then tries to read memory from child -= and does memory compare to ensure it read memory contents -= correctly diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/CMakeLists.txt index 987c413d03..8aa1c80368 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_rtlmovememory_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/test1.c deleted file mode 100644 index 7fc56510d8..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/test1.c +++ /dev/null @@ -1,56 +0,0 @@ -// 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: test1.c -** -** Purpose: Simple test -- have two 128 blocks of memory allocated. Then -** move one block to the other and check to see that the data was not -** corrupted. -** -** -**============================================================*/ - -#include - -enum Memory -{ - MEMORY_AMOUNT = 128 -}; - -int __cdecl main(int argc, char *argv[]) -{ - char NewAddress[MEMORY_AMOUNT]; - char OldAddress[MEMORY_AMOUNT]; - int i; - char temp; - - if(PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Put some data into the block we'll be moving */ - memset(OldAddress, 'X', MEMORY_AMOUNT); - - /* Move the block to the NewAddress */ - RtlMoveMemory(NewAddress, OldAddress, MEMORY_AMOUNT); - - /* Check to ensure the data didn't get corrupted */ - for(i=0; i + +enum Memory +{ + MEMORY_AMOUNT = 128 +}; + +int __cdecl main(int argc, char *argv[]) +{ + char NewAddress[MEMORY_AMOUNT]; + char OldAddress[MEMORY_AMOUNT]; + int i; + char temp; + + if(PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Put some data into the block we'll be moving */ + memset(OldAddress, 'X', MEMORY_AMOUNT); + + /* Move the block to the NewAddress */ + RtlMoveMemory(NewAddress, OldAddress, MEMORY_AMOUNT); + + /* Check to ensure the data didn't get corrupted */ + for(i=0; i - -enum Memory -{ - NEW_MEMORY_AMOUNT = 128, - OLD_MEMORY_AMOUNT = 10 -}; - -int __cdecl main(int argc, char *argv[]) -{ - char NewAddress[NEW_MEMORY_AMOUNT]; - char OldAddress[OLD_MEMORY_AMOUNT]; - int i; - - - if(PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Put some data into the block we'll be moving */ - memset(OldAddress, 'X', OLD_MEMORY_AMOUNT); - - /* Put some data into the block we're moving to */ - memset(NewAddress, 'Z', NEW_MEMORY_AMOUNT); - - /* Move the block to the NewAddress */ - RtlMoveMemory(NewAddress, OldAddress, OLD_MEMORY_AMOUNT); - - /* Check to ensure the moved data didn't get corrupted */ - for(i=0; i + +enum Memory +{ + NEW_MEMORY_AMOUNT = 128, + OLD_MEMORY_AMOUNT = 10 +}; + +int __cdecl main(int argc, char *argv[]) +{ + char NewAddress[NEW_MEMORY_AMOUNT]; + char OldAddress[OLD_MEMORY_AMOUNT]; + int i; + + + if(PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Put some data into the block we'll be moving */ + memset(OldAddress, 'X', OLD_MEMORY_AMOUNT); + + /* Put some data into the block we're moving to */ + memset(NewAddress, 'Z', NEW_MEMORY_AMOUNT); + + /* Move the block to the NewAddress */ + RtlMoveMemory(NewAddress, OldAddress, OLD_MEMORY_AMOUNT); + + /* Check to ensure the moved data didn't get corrupted */ + for(i=0; i i+50 Check to make sure -** no data is lost. -** -** -**============================================================*/ - -#include - -enum Memory -{ - MEMORY_AMOUNT = 128 -}; - -int __cdecl main(int argc, char *argv[]) -{ - char* NewAddress; - char OldAddress[MEMORY_AMOUNT]; - int i; - - if(PAL_Initialize(argc, argv)) - { - return FAIL; - } - - NewAddress = OldAddress+50; - - /* Put some data into the block we'll be moving - The first 50 byes will be 'X' and the rest set to 'Z' - */ - memset(OldAddress, 'X', 50); - memset(NewAddress, 'Z', MEMORY_AMOUNT-50); - - /* Move the first 50 bytes of OldAddress to OldAddress+50. This - is to test that the source and destination addresses can overlap. - */ - RtlMoveMemory(NewAddress, OldAddress, 50); - - /* Check to ensure the moved data didn't get corrupted - The first 50 bytes should be 'X' - */ - for(i=0; i<50; ++i) - { - if(NewAddress[i] != 'X') - { - Fail("ERROR: When the memory was moved to a new location, the " - "data which was stored in it was somehow corrupted. " - "Character %d should have been 'X' but instead is %c.\n", - i, NewAddress[i]); - } - } - - /* The rest of the memory should be 'Z' */ - for(i=50; i i+50 Check to make sure +** no data is lost. +** +** +**============================================================*/ + +#include + +enum Memory +{ + MEMORY_AMOUNT = 128 +}; + +int __cdecl main(int argc, char *argv[]) +{ + char* NewAddress; + char OldAddress[MEMORY_AMOUNT]; + int i; + + if(PAL_Initialize(argc, argv)) + { + return FAIL; + } + + NewAddress = OldAddress+50; + + /* Put some data into the block we'll be moving + The first 50 byes will be 'X' and the rest set to 'Z' + */ + memset(OldAddress, 'X', 50); + memset(NewAddress, 'Z', MEMORY_AMOUNT-50); + + /* Move the first 50 bytes of OldAddress to OldAddress+50. This + is to test that the source and destination addresses can overlap. + */ + RtlMoveMemory(NewAddress, OldAddress, 50); + + /* Check to ensure the moved data didn't get corrupted + The first 50 bytes should be 'X' + */ + for(i=0; i<50; ++i) + { + if(NewAddress[i] != 'X') + { + Fail("ERROR: When the memory was moved to a new location, the " + "data which was stored in it was somehow corrupted. " + "Character %d should have been 'X' but instead is %c.\n", + i, NewAddress[i]); + } + } + + /* The rest of the memory should be 'Z' */ + for(i=50; i - -enum Memory -{ - MEMORY_AMOUNT = 128 -}; - -int __cdecl main(int argc, char *argv[]) -{ - char* NewAddress; - char* SectionToMove; - char TheMemory[MEMORY_AMOUNT]; - int i; - - if(PAL_Initialize(argc, argv)) - { - return FAIL; - } - - NewAddress = TheMemory; - SectionToMove = TheMemory+50; - - /* Put some data into the first 50 bytes */ - memset(TheMemory, 'X', 50); - - /* Put some data into the rest of the memory */ - memset(SectionToMove, 'Z', MEMORY_AMOUNT-50); - - /* Move the section in the middle of TheMemory back to the start of - TheMemory -- but have it also overlap itself. (ie. the section - to be move is overlapping itself) - */ - RtlMoveMemory(NewAddress, SectionToMove, MEMORY_AMOUNT-50); - - /* Check to ensure the moved data didn't get corrupted */ - for(i=0; i + +enum Memory +{ + MEMORY_AMOUNT = 128 +}; + +int __cdecl main(int argc, char *argv[]) +{ + char* NewAddress; + char* SectionToMove; + char TheMemory[MEMORY_AMOUNT]; + int i; + + if(PAL_Initialize(argc, argv)) + { + return FAIL; + } + + NewAddress = TheMemory; + SectionToMove = TheMemory+50; + + /* Put some data into the first 50 bytes */ + memset(TheMemory, 'X', 50); + + /* Put some data into the rest of the memory */ + memset(SectionToMove, 'Z', MEMORY_AMOUNT-50); + + /* Move the section in the middle of TheMemory back to the start of + TheMemory -- but have it also overlap itself. (ie. the section + to be move is overlapping itself) + */ + RtlMoveMemory(NewAddress, SectionToMove, MEMORY_AMOUNT-50); + + /* Check to ensure the moved data didn't get corrupted */ + for(i=0; i -#include "../UnlockFile.h" - -#define FILENAME "testfile.txt" -#define WAITFILENAME "waitfile" -#define BUF_SIZE 128 - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile, WaitFile; - int result = 0; - char DataBuffer[BUF_SIZE]; - DWORD BytesRead; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open the same file that the parent has opened and locked */ - TheFile = CreateFile(FILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR: Could not open file '%s' with CreateFile.\n",FILENAME); - result = 1; - } - - /* Open up the WaitFile that we're using for IPC */ - WaitFile = CreateFile(WAITFILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (WaitFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.\n",WAITFILENAME,GetLastError()); - result = 1; - } - - - /* Check to ensure the parent lock is respected */ - if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0) - { - Trace("ERROR: ReadFile returned success when it should " - "have failed. Attempted to read the first 10 bytes " - "of a file which was locked by the parent process.\n"); - result = 1; - } - - // Sleep for a bit to give the parent a chance to block before we do. - Sleep(1000); - - /* Switch back to the parent, so it can unlock the file */ - SignalAndBusyWait(WaitFile); - - if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0) - { - Trace("ERROR: ReadFile was unable to read from the file after it " - "had been unlocked. Attempted to read 10 bytes and ReadFile " - "returned 0. GetLastError() returned %d.\n",GetLastError()); - result = 1; - } - - PAL_TerminateEx(result); - return result; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/helper.cpp b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/helper.cpp new file mode 100644 index 0000000000..c2ef5a6736 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/helper.cpp @@ -0,0 +1,92 @@ +// 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: helper.c +** +** Purpose: A child process which will attempt to read from the +** locked file to ensure it is locked. After it has been unlocked, it +** will then read again to check that Unlock worked. +** +** +**============================================================*/ + +#include +#include "../UnlockFile.h" + +#define FILENAME "testfile.txt" +#define WAITFILENAME "waitfile" +#define BUF_SIZE 128 + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile, WaitFile; + int result = 0; + char DataBuffer[BUF_SIZE]; + DWORD BytesRead; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open the same file that the parent has opened and locked */ + TheFile = CreateFile(FILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR: Could not open file '%s' with CreateFile.\n",FILENAME); + result = 1; + } + + /* Open up the WaitFile that we're using for IPC */ + WaitFile = CreateFile(WAITFILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (WaitFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.\n",WAITFILENAME,GetLastError()); + result = 1; + } + + + /* Check to ensure the parent lock is respected */ + if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0) + { + Trace("ERROR: ReadFile returned success when it should " + "have failed. Attempted to read the first 10 bytes " + "of a file which was locked by the parent process.\n"); + result = 1; + } + + // Sleep for a bit to give the parent a chance to block before we do. + Sleep(1000); + + /* Switch back to the parent, so it can unlock the file */ + SignalAndBusyWait(WaitFile); + + if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0) + { + Trace("ERROR: ReadFile was unable to read from the file after it " + "had been unlocked. Attempted to read 10 bytes and ReadFile " + "returned 0. GetLastError() returned %d.\n",GetLastError()); + result = 1; + } + + PAL_TerminateEx(result); + return result; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.c deleted file mode 100644 index 14634c7f7a..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.c +++ /dev/null @@ -1,154 +0,0 @@ -// 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: test1.c -** -** Purpose: -** Have the parent Lock a file, then have the child check the lock, then -** have the parent unlock the file, and the child check again. -** This requires some IPC, which is done here with a crude busy wait on a -** file (waiting for the file size to change) to avoid too many more -** dependencies. -** -** -**============================================================*/ - -#include -#include "../UnlockFile.h" - -#define HELPER "helper" -#define FILENAME "testfile.txt" -#define WAITFILENAME "waitfile" -#define BUF_SIZE 128 - -int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile) -{ - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD ChildRetCode = 0; - DWORD ParentRetCode = 0; - DWORD FileEnd; - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - /* Load up the helper Process, and then Wait until it signals that it - is finished locking. - */ - if(!CreateProcess( NULL, Helper, NULL, - NULL, FALSE, 0, - NULL, NULL, &si, &pi)) - { - Fail("ERROR: CreateProcess failed to load executable '%s'.\n",Helper); - } - - SignalAndBusyWait(WaitFile); - - /* When the child proccess is finished verifying the lock, find the end - of the file and unlock the file. - */ - - FileEnd = SetFilePointer(TheFile, 0, NULL, FILE_END); - - if(FileEnd == INVALID_SET_FILE_POINTER) - { - Trace("ERROR: SetFilePointer failed to set the file pointer to the " - "end of the file. GetLastError() returned %d.\n", - GetLastError()); - ParentRetCode = 1; - } - - if(UnlockFile(TheFile, 0, 0, FileEnd, 0) == 0) - { - Trace("ERROR: The call to UnlockFile returned 0 when attempting to " - "unlock the file within the parent. This should have " - "succeeded. GetLastError returned %d.\n",GetLastError()); - ParentRetCode = 1; - } - - /* Switch back to the child so that it can ensure the unlock worked - properly. - */ - - SignalFinish(WaitFile); - WaitForSingleObject(pi.hProcess,INFINITE); - - /* Get the return value from the helper process */ - if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0) - { - Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve " - "the exit code of the child process.\n"); - } - - if(CloseHandle( pi.hProcess ) == 0) - { - Fail("ERROR: CloseHandle failed to close the process.\n"); - } - - if(CloseHandle( pi.hThread ) == 0) - { - Fail("ERROR: CloseHandle failed to close the thread.\n"); - } - - return (ChildRetCode || ParentRetCode); -} - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile = NULL; - HANDLE WaitFile = NULL; - char* WriteBuffer = "12345678901234567890123456"; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open up the file we'll be using for some crude IPC */ - WaitFile = CreateFile(WAITFILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (WaitFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.\n",WAITFILENAME,GetLastError()); - } - - /* Call the helper function to Create a file, write 'WriteBuffer' to - the file, and lock the file from start to end. - */ - TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer, - 0, strlen(WriteBuffer)); - - /* Run the test. Better errors are displayed by Trace throughout. */ - if(RunTest(HELPER, TheFile, WaitFile)) - { - Fail("ERROR: Checking to ensure that Unlock successfully unlocked " - "a file failed.\n"); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file used for " - "testing the locks. GetLastError() returns %d.\n", - GetLastError()); - } - - if(CloseHandle(WaitFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the wait file. " - "GetLastError() returns %d.\n",GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.cpp b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.cpp new file mode 100644 index 0000000000..14634c7f7a --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.cpp @@ -0,0 +1,154 @@ +// 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: test1.c +** +** Purpose: +** Have the parent Lock a file, then have the child check the lock, then +** have the parent unlock the file, and the child check again. +** This requires some IPC, which is done here with a crude busy wait on a +** file (waiting for the file size to change) to avoid too many more +** dependencies. +** +** +**============================================================*/ + +#include +#include "../UnlockFile.h" + +#define HELPER "helper" +#define FILENAME "testfile.txt" +#define WAITFILENAME "waitfile" +#define BUF_SIZE 128 + +int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile) +{ + STARTUPINFO si; + PROCESS_INFORMATION pi; + DWORD ChildRetCode = 0; + DWORD ParentRetCode = 0; + DWORD FileEnd; + + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + /* Load up the helper Process, and then Wait until it signals that it + is finished locking. + */ + if(!CreateProcess( NULL, Helper, NULL, + NULL, FALSE, 0, + NULL, NULL, &si, &pi)) + { + Fail("ERROR: CreateProcess failed to load executable '%s'.\n",Helper); + } + + SignalAndBusyWait(WaitFile); + + /* When the child proccess is finished verifying the lock, find the end + of the file and unlock the file. + */ + + FileEnd = SetFilePointer(TheFile, 0, NULL, FILE_END); + + if(FileEnd == INVALID_SET_FILE_POINTER) + { + Trace("ERROR: SetFilePointer failed to set the file pointer to the " + "end of the file. GetLastError() returned %d.\n", + GetLastError()); + ParentRetCode = 1; + } + + if(UnlockFile(TheFile, 0, 0, FileEnd, 0) == 0) + { + Trace("ERROR: The call to UnlockFile returned 0 when attempting to " + "unlock the file within the parent. This should have " + "succeeded. GetLastError returned %d.\n",GetLastError()); + ParentRetCode = 1; + } + + /* Switch back to the child so that it can ensure the unlock worked + properly. + */ + + SignalFinish(WaitFile); + WaitForSingleObject(pi.hProcess,INFINITE); + + /* Get the return value from the helper process */ + if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0) + { + Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve " + "the exit code of the child process.\n"); + } + + if(CloseHandle( pi.hProcess ) == 0) + { + Fail("ERROR: CloseHandle failed to close the process.\n"); + } + + if(CloseHandle( pi.hThread ) == 0) + { + Fail("ERROR: CloseHandle failed to close the thread.\n"); + } + + return (ChildRetCode || ParentRetCode); +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile = NULL; + HANDLE WaitFile = NULL; + char* WriteBuffer = "12345678901234567890123456"; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open up the file we'll be using for some crude IPC */ + WaitFile = CreateFile(WAITFILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (WaitFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.\n",WAITFILENAME,GetLastError()); + } + + /* Call the helper function to Create a file, write 'WriteBuffer' to + the file, and lock the file from start to end. + */ + TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer, + 0, strlen(WriteBuffer)); + + /* Run the test. Better errors are displayed by Trace throughout. */ + if(RunTest(HELPER, TheFile, WaitFile)) + { + Fail("ERROR: Checking to ensure that Unlock successfully unlocked " + "a file failed.\n"); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file used for " + "testing the locks. GetLastError() returns %d.\n", + GetLastError()); + } + + if(CloseHandle(WaitFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the wait file. " + "GetLastError() returns %d.\n",GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/CMakeLists.txt index 142b2763cb..3033876f80 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_unlockfile_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.c deleted file mode 100644 index 22c2cce2fb..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.c +++ /dev/null @@ -1,154 +0,0 @@ -// 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: test2.c -** -** Purpose: Open a file, and call Unlock on the file, even though it has yet -** to be locked. Then lock a portion of the file, and attempt to call unlock -** on a larger portion of the file. Also, try to unlock a smaller portion -** than was locked. -** -** -**============================================================*/ - -#include -#include "../UnlockFile.h" - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile = NULL; - const char lpBuffer[] = "This is a test file."; - DWORD bytesWritten; - BOOL bRc = TRUE; - char fileName[] = "testfile.tmp"; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open a file which is in the directory */ - TheFile = CreateFile(fileName, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.\n",fileName,GetLastError()); - } - - bRc = WriteFile( - TheFile, // handle to file - lpBuffer, // data buffer - (DWORD)sizeof(lpBuffer), // number of bytes to write - &bytesWritten, // number of bytes written - NULL // overlapped buffer - ); - - if(!bRc) - { - Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - - } - else if(bytesWritten != (DWORD)sizeof(lpBuffer)) - { - Trace("ERROR: Could not write the correct number of bytes to the " - "file '%s' with WriteFile.",fileName); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Call unlock file on an unlocked file, this should return 0 */ - if(UnlockFile(TheFile, 0, 0, 5, 0) != 0) - { - Trace("ERROR: Attempted to unlock a file which was not locked and " - "the UnlockFile call was successful.\n"); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Lock the file */ - if(LockFile(TheFile, 0, 0, 5, 0) == 0) - { - Trace("ERROR: Failed to call LockFile on a valid file handle. " - "GetLastError returned %d.\n",GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Try to unlock more of the file than was locked by LockFile */ - if(UnlockFile(TheFile, 0, 0, 10, 0) != 0) - { - Trace("ERROR: Attempted to unlock bytes 0 to 9, but only bytes " - "0 to 4 are locked. But, UnlockFile was successful, when it " - "should have failed.\n"); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Try to unlock less of the file than was locked by LockFile */ - if(UnlockFile(TheFile, 0, 0, 3, 0) != 0) - { - Trace("ERROR: Attempted to unlock bytes 0 to 2, but the bytes 0 to " - "4 were locked by LockFile. Unlockfile should have failed " - "when attempting this operation.\n"); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Properly unlock the file */ - if(UnlockFile(TheFile, 0, 0, 5, 0) == 0) - { - Trace("ERROR: UnlockFile failed to unlock bytes 0 to 4 of the file. " - "GetLastError returned %d.\n",GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file.\n"); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.cpp b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.cpp new file mode 100644 index 0000000000..22c2cce2fb --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.cpp @@ -0,0 +1,154 @@ +// 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: test2.c +** +** Purpose: Open a file, and call Unlock on the file, even though it has yet +** to be locked. Then lock a portion of the file, and attempt to call unlock +** on a larger portion of the file. Also, try to unlock a smaller portion +** than was locked. +** +** +**============================================================*/ + +#include +#include "../UnlockFile.h" + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile = NULL; + const char lpBuffer[] = "This is a test file."; + DWORD bytesWritten; + BOOL bRc = TRUE; + char fileName[] = "testfile.tmp"; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open a file which is in the directory */ + TheFile = CreateFile(fileName, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.\n",fileName,GetLastError()); + } + + bRc = WriteFile( + TheFile, // handle to file + lpBuffer, // data buffer + (DWORD)sizeof(lpBuffer), // number of bytes to write + &bytesWritten, // number of bytes written + NULL // overlapped buffer + ); + + if(!bRc) + { + Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + + } + else if(bytesWritten != (DWORD)sizeof(lpBuffer)) + { + Trace("ERROR: Could not write the correct number of bytes to the " + "file '%s' with WriteFile.",fileName); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Call unlock file on an unlocked file, this should return 0 */ + if(UnlockFile(TheFile, 0, 0, 5, 0) != 0) + { + Trace("ERROR: Attempted to unlock a file which was not locked and " + "the UnlockFile call was successful.\n"); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Lock the file */ + if(LockFile(TheFile, 0, 0, 5, 0) == 0) + { + Trace("ERROR: Failed to call LockFile on a valid file handle. " + "GetLastError returned %d.\n",GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Try to unlock more of the file than was locked by LockFile */ + if(UnlockFile(TheFile, 0, 0, 10, 0) != 0) + { + Trace("ERROR: Attempted to unlock bytes 0 to 9, but only bytes " + "0 to 4 are locked. But, UnlockFile was successful, when it " + "should have failed.\n"); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Try to unlock less of the file than was locked by LockFile */ + if(UnlockFile(TheFile, 0, 0, 3, 0) != 0) + { + Trace("ERROR: Attempted to unlock bytes 0 to 2, but the bytes 0 to " + "4 were locked by LockFile. Unlockfile should have failed " + "when attempting this operation.\n"); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Properly unlock the file */ + if(UnlockFile(TheFile, 0, 0, 5, 0) == 0) + { + Trace("ERROR: UnlockFile failed to unlock bytes 0 to 4 of the file. " + "GetLastError returned %d.\n",GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file.\n"); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/CMakeLists.txt index b4ec37c88c..d46d7db344 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test3.c + test3.cpp ) add_executable(paltest_unlockfile_test3 @@ -20,7 +20,7 @@ target_link_libraries(paltest_unlockfile_test3 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_unlockfile_test3_helper diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.c deleted file mode 100644 index 650abf49ad..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.c +++ /dev/null @@ -1,103 +0,0 @@ -// 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: helper.c -** -** Purpose: A child process which will lock a portion of the file, -** then try to unlock a portion of the file which was locked by the parent. -** -** -**============================================================*/ - -#include -#include "../UnlockFile.h" - -#define FILENAME "testfile.txt" -#define WAITFILENAME "waitfile" -#define BUF_SIZE 128 - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile, WaitFile; - int result = 0; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open the same file that the parent has opened and locked */ - TheFile = CreateFile(FILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR: Could not open file '%s' with CreateFile.\n",FILENAME); - result = 1; - } - - /* Open up the WaitFile that we're using for IPC */ - WaitFile = CreateFile(WAITFILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (WaitFile == INVALID_HANDLE_VALUE) - { - Trace("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.\n",WAITFILENAME,GetLastError()); - result = 1; - } - - /* Lock a section of the file different from which was locked in the - parent proccess - */ - if(LockFile(TheFile, 10, 0, 10, 0) == 0) - { - Trace("ERROR: The LockFile call within the child failed to lock " - "the file. GetLastError() returned %d.\n",GetLastError()); - result = 1; - } - - /* Attempt to unlock the portion of the file which was locked within the - parent process. - */ - if(UnlockFile(TheFile, 0, 0, 10, 0) != 0) - { - Trace("ERROR: The UnlockFile call within the child succeeded in " - "calling UnlockFile on the portion of the file which was " - "locked by the parent.\n"); - result = 1; - } - - // Sleep for a bit to give the parent a chance to block before we do. - Sleep(1000); - - /* Switch back to the parent, so it can check the child lock */ - SignalAndBusyWait(WaitFile); - - /* Finally, clean up the lock which was done within this proccess and - exit. - */ - if(UnlockFile(TheFile, 10, 0, 10, 0) == 0) - { - Trace("ERROR: The UnlockFile call within the child failed to unlock " - "the portion of the file which was locked by the child. " - "GetLastError() returned %d.\n", GetLastError()); - result = 1; - } - - PAL_TerminateEx(result); - return result; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.cpp b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.cpp new file mode 100644 index 0000000000..650abf49ad --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.cpp @@ -0,0 +1,103 @@ +// 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: helper.c +** +** Purpose: A child process which will lock a portion of the file, +** then try to unlock a portion of the file which was locked by the parent. +** +** +**============================================================*/ + +#include +#include "../UnlockFile.h" + +#define FILENAME "testfile.txt" +#define WAITFILENAME "waitfile" +#define BUF_SIZE 128 + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile, WaitFile; + int result = 0; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open the same file that the parent has opened and locked */ + TheFile = CreateFile(FILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR: Could not open file '%s' with CreateFile.\n",FILENAME); + result = 1; + } + + /* Open up the WaitFile that we're using for IPC */ + WaitFile = CreateFile(WAITFILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (WaitFile == INVALID_HANDLE_VALUE) + { + Trace("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.\n",WAITFILENAME,GetLastError()); + result = 1; + } + + /* Lock a section of the file different from which was locked in the + parent proccess + */ + if(LockFile(TheFile, 10, 0, 10, 0) == 0) + { + Trace("ERROR: The LockFile call within the child failed to lock " + "the file. GetLastError() returned %d.\n",GetLastError()); + result = 1; + } + + /* Attempt to unlock the portion of the file which was locked within the + parent process. + */ + if(UnlockFile(TheFile, 0, 0, 10, 0) != 0) + { + Trace("ERROR: The UnlockFile call within the child succeeded in " + "calling UnlockFile on the portion of the file which was " + "locked by the parent.\n"); + result = 1; + } + + // Sleep for a bit to give the parent a chance to block before we do. + Sleep(1000); + + /* Switch back to the parent, so it can check the child lock */ + SignalAndBusyWait(WaitFile); + + /* Finally, clean up the lock which was done within this proccess and + exit. + */ + if(UnlockFile(TheFile, 10, 0, 10, 0) == 0) + { + Trace("ERROR: The UnlockFile call within the child failed to unlock " + "the portion of the file which was locked by the child. " + "GetLastError() returned %d.\n", GetLastError()); + result = 1; + } + + PAL_TerminateEx(result); + return result; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.c deleted file mode 100644 index cf27aba0a3..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.c +++ /dev/null @@ -1,142 +0,0 @@ -// 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: test3.c -** -** Purpose: -** Lock a portion of the file with the parent. Then have the child lock -** another portion. Have the child attempt to call Unlock on the parent's -** locked data, and the parent do the same to the child. Ensure that the -** locks are respected. -** -** -**============================================================*/ - -#include -#include "../UnlockFile.h" - -#define HELPER "helper" -#define FILENAME "testfile.txt" -#define WAITFILENAME "waitfile" -#define BUF_SIZE 128 - -int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile) -{ - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD ChildRetCode = 0; - DWORD ParentRetCode = 0; - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - /* Load up the helper Process, and then Wait until it signals that it - is finished locking. - */ - if(!CreateProcess( NULL, Helper, NULL, - NULL, FALSE, 0, - NULL, NULL, &si, &pi)) - { - Fail("ERROR: CreateProcess failed to load executable '%s'.\n",Helper); - } - - SignalAndBusyWait(WaitFile); - - /* When the child proccess is finished setting its lock and testing the - parent lock, then the parent can test the child's lock. - */ - - if(UnlockFile(TheFile, 10, 0, 10, 0) != 0) - { - Trace("ERROR: The parent proccess called Unlock on the child " - "proccesses lock, and the function returned non-zero, when " - "it should have failed.\n"); - ParentRetCode = 1; - } - - /* Switch back to the child so that it can unlock its portion and - cleanup. - */ - - SignalFinish(WaitFile); - WaitForSingleObject(pi.hProcess,INFINITE); - - /* Get the return value from the helper process */ - if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0) - { - Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve " - "the exit code of the child process.\n"); - } - - if(CloseHandle( pi.hProcess ) == 0) - { - Fail("ERROR: CloseHandle failed to close the process.\n"); - } - - if(CloseHandle( pi.hThread ) == 0) - { - Fail("ERROR: CloseHandle failed to close the thread.\n"); - } - - return (ChildRetCode || ParentRetCode); -} - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile = NULL; - HANDLE WaitFile = NULL; - char* WriteBuffer = "12345678901234567890123456"; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open up the file we'll be using for some crude IPC */ - WaitFile = CreateFile(WAITFILENAME, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (WaitFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.\n",WAITFILENAME,GetLastError()); - } - - /* Call the helper function to Create a file, write 'WriteBuffer' to - the file, and lock the file from bytes 0-9. - */ - TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer, - 0, 10); - - /* Run the test. Better errors are displayed by Trace throughout. */ - if(RunTest(HELPER, TheFile, WaitFile)) - { - Fail("ERROR: The test to check that the Unlock will not work on " - "on locks set by other proccesses failed.\n"); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file used for " - "testing the locks. GetLastError() returns %d.\n", - GetLastError()); - } - - if(CloseHandle(WaitFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the wait file. " - "GetLastError() returns %d.\n",GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.cpp b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.cpp new file mode 100644 index 0000000000..cf27aba0a3 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.cpp @@ -0,0 +1,142 @@ +// 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: test3.c +** +** Purpose: +** Lock a portion of the file with the parent. Then have the child lock +** another portion. Have the child attempt to call Unlock on the parent's +** locked data, and the parent do the same to the child. Ensure that the +** locks are respected. +** +** +**============================================================*/ + +#include +#include "../UnlockFile.h" + +#define HELPER "helper" +#define FILENAME "testfile.txt" +#define WAITFILENAME "waitfile" +#define BUF_SIZE 128 + +int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile) +{ + STARTUPINFO si; + PROCESS_INFORMATION pi; + DWORD ChildRetCode = 0; + DWORD ParentRetCode = 0; + + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + /* Load up the helper Process, and then Wait until it signals that it + is finished locking. + */ + if(!CreateProcess( NULL, Helper, NULL, + NULL, FALSE, 0, + NULL, NULL, &si, &pi)) + { + Fail("ERROR: CreateProcess failed to load executable '%s'.\n",Helper); + } + + SignalAndBusyWait(WaitFile); + + /* When the child proccess is finished setting its lock and testing the + parent lock, then the parent can test the child's lock. + */ + + if(UnlockFile(TheFile, 10, 0, 10, 0) != 0) + { + Trace("ERROR: The parent proccess called Unlock on the child " + "proccesses lock, and the function returned non-zero, when " + "it should have failed.\n"); + ParentRetCode = 1; + } + + /* Switch back to the child so that it can unlock its portion and + cleanup. + */ + + SignalFinish(WaitFile); + WaitForSingleObject(pi.hProcess,INFINITE); + + /* Get the return value from the helper process */ + if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0) + { + Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve " + "the exit code of the child process.\n"); + } + + if(CloseHandle( pi.hProcess ) == 0) + { + Fail("ERROR: CloseHandle failed to close the process.\n"); + } + + if(CloseHandle( pi.hThread ) == 0) + { + Fail("ERROR: CloseHandle failed to close the thread.\n"); + } + + return (ChildRetCode || ParentRetCode); +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile = NULL; + HANDLE WaitFile = NULL; + char* WriteBuffer = "12345678901234567890123456"; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open up the file we'll be using for some crude IPC */ + WaitFile = CreateFile(WAITFILENAME, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (WaitFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.\n",WAITFILENAME,GetLastError()); + } + + /* Call the helper function to Create a file, write 'WriteBuffer' to + the file, and lock the file from bytes 0-9. + */ + TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer, + 0, 10); + + /* Run the test. Better errors are displayed by Trace throughout. */ + if(RunTest(HELPER, TheFile, WaitFile)) + { + Fail("ERROR: The test to check that the Unlock will not work on " + "on locks set by other proccesses failed.\n"); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file used for " + "testing the locks. GetLastError() returns %d.\n", + GetLastError()); + } + + if(CloseHandle(WaitFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the wait file. " + "GetLastError() returns %d.\n",GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/CMakeLists.txt index d6bee307c2..635a1ca07c 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_unlockfile_test4 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.c deleted file mode 100644 index 55abcd24bc..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.c +++ /dev/null @@ -1,187 +0,0 @@ -// 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: test4.c -** -** Purpose: Pass an invalid handle to UnlockFile. Pass a null handle to -** UnlockFile. Create a file and lock two consecuative regions and call -** UnlockFile on the whole region (this should fail, see msdn) -** -** -**============================================================*/ - -#include -#include "../UnlockFile.h" - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE TheFile = NULL; - const char lpBuffer[] = "This is a test file."; - DWORD bytesWritten; - BOOL bRc = TRUE; - char fileName[] = "testfile.tmp"; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open a file which is in the directory */ - TheFile = CreateFile(fileName, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.\n",fileName,GetLastError()); - } - - bRc = WriteFile( - TheFile, // handle to file - lpBuffer, // data buffer - (DWORD)sizeof(lpBuffer), // number of bytes to write - &bytesWritten, // number of bytes written - NULL // overlapped buffer - ); - - if(!bRc) - { - Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - - } - else if(bytesWritten != (DWORD)sizeof(lpBuffer)) - { - Trace("ERROR: Could not write the correct number of bytes to the " - "file '%s' with WriteFile.",fileName); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file.\n"); - } - - - /* Test an invalid handle and a NULL handle */ - if(UnlockFile(TheFile, 0, 0, 0, 0) != 0) - { - Fail("ERROR: Called UnlockFile on an invalid HANDLE and it " - "returned a success value.\n"); - } - - if(UnlockFile(NULL, 0, 0, 0, 0) != 0) - { - Fail("ERROR: Called UnlockFile with NULL passed for the HANDLE and " - "it returned a success value.\n"); - } - - /* Re-open the file */ - TheFile = CreateFile(fileName, - GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (TheFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: Could not open file '%s' with CreateFile. " - "GetLastError() returned %d.\n",fileName,GetLastError()); - } - - /* Lock two consecuative regions of this file */ - if(LockFile(TheFile, 0, 0, 5, 0) == 0) - { - Trace("ERROR: LockFile failed attempting to lock bytes 0-4. " - "GetLastError() returned %d.\n",GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - if(LockFile(TheFile, 5, 0, 5, 0) == 0) - { - Fail("ERROR: LockFile failed attempting to lock bytes 5-9. " - "GetLastError() returned %d.\n",GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - /* Attempt to unlock the entire region which was locked with one - call to UnlockFile. This should fail. - */ - if(UnlockFile(TheFile, 0, 0, 10, 0) != 0) - { - Fail("ERROR: Called UnlockFile on bytes 0-9 which were locked with " - "two seperate LockFile calls. This should have failed. " - "UnlockFile will not unlock consecuative locked regions.\n"); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - - /* Now, unlock the regions one at a time. */ - if(UnlockFile(TheFile, 0, 0, 5, 0) == 0) - { - Fail("ERROR: UnlockFile failed when attempting to unlock bytes " - "0-4 of the file. GetLastError() returned %d.\n",GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - if(UnlockFile(TheFile, 5, 0, 5, 0) == 0) - { - Fail("ERROR: UnlockFile failed when attempting to unlock bytes " - "5-9 of the file. GetLastError() returned %d.\n",GetLastError()); - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file."); - } - Fail(""); - } - - if(CloseHandle(TheFile) == 0) - { - Fail("ERROR: CloseHandle failed to close the file.\n"); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.cpp b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.cpp new file mode 100644 index 0000000000..55abcd24bc --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.cpp @@ -0,0 +1,187 @@ +// 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: test4.c +** +** Purpose: Pass an invalid handle to UnlockFile. Pass a null handle to +** UnlockFile. Create a file and lock two consecuative regions and call +** UnlockFile on the whole region (this should fail, see msdn) +** +** +**============================================================*/ + +#include +#include "../UnlockFile.h" + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE TheFile = NULL; + const char lpBuffer[] = "This is a test file."; + DWORD bytesWritten; + BOOL bRc = TRUE; + char fileName[] = "testfile.tmp"; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open a file which is in the directory */ + TheFile = CreateFile(fileName, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.\n",fileName,GetLastError()); + } + + bRc = WriteFile( + TheFile, // handle to file + lpBuffer, // data buffer + (DWORD)sizeof(lpBuffer), // number of bytes to write + &bytesWritten, // number of bytes written + NULL // overlapped buffer + ); + + if(!bRc) + { + Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + + } + else if(bytesWritten != (DWORD)sizeof(lpBuffer)) + { + Trace("ERROR: Could not write the correct number of bytes to the " + "file '%s' with WriteFile.",fileName); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file.\n"); + } + + + /* Test an invalid handle and a NULL handle */ + if(UnlockFile(TheFile, 0, 0, 0, 0) != 0) + { + Fail("ERROR: Called UnlockFile on an invalid HANDLE and it " + "returned a success value.\n"); + } + + if(UnlockFile(NULL, 0, 0, 0, 0) != 0) + { + Fail("ERROR: Called UnlockFile with NULL passed for the HANDLE and " + "it returned a success value.\n"); + } + + /* Re-open the file */ + TheFile = CreateFile(fileName, + GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (TheFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Could not open file '%s' with CreateFile. " + "GetLastError() returned %d.\n",fileName,GetLastError()); + } + + /* Lock two consecuative regions of this file */ + if(LockFile(TheFile, 0, 0, 5, 0) == 0) + { + Trace("ERROR: LockFile failed attempting to lock bytes 0-4. " + "GetLastError() returned %d.\n",GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + if(LockFile(TheFile, 5, 0, 5, 0) == 0) + { + Fail("ERROR: LockFile failed attempting to lock bytes 5-9. " + "GetLastError() returned %d.\n",GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + /* Attempt to unlock the entire region which was locked with one + call to UnlockFile. This should fail. + */ + if(UnlockFile(TheFile, 0, 0, 10, 0) != 0) + { + Fail("ERROR: Called UnlockFile on bytes 0-9 which were locked with " + "two seperate LockFile calls. This should have failed. " + "UnlockFile will not unlock consecuative locked regions.\n"); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + + /* Now, unlock the regions one at a time. */ + if(UnlockFile(TheFile, 0, 0, 5, 0) == 0) + { + Fail("ERROR: UnlockFile failed when attempting to unlock bytes " + "0-4 of the file. GetLastError() returned %d.\n",GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + if(UnlockFile(TheFile, 5, 0, 5, 0) == 0) + { + Fail("ERROR: UnlockFile failed when attempting to unlock bytes " + "5-9 of the file. GetLastError() returned %d.\n",GetLastError()); + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file."); + } + Fail(""); + } + + if(CloseHandle(TheFile) == 0) + { + Fail("ERROR: CloseHandle failed to close the file.\n"); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/CMakeLists.txt index 5ebda77ba6..1b8062ff9c 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - UnmapViewOfFile.c + UnmapViewOfFile.cpp ) add_executable(paltest_unmapviewoffile_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.c b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.c deleted file mode 100644 index a970ccc3b5..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.c +++ /dev/null @@ -1,184 +0,0 @@ -// 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: UnMapViewOfFile.c -** -** Purpose: Positive test the MapViewOfFile API. -** Call MapViewOfFile with access FILE_MAP_ALL_ACCESS. -** -** Depends: CreateFile, -** GetFileSize, -** memset, -** memcpy, -** memcmp, -** ReadFile, -** UnMapViewOfFile, -** CreateFileMapping, -** CloseHandle. - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - const int MappingSize = 2048; - HANDLE hFile; - HANDLE hFileMapping; - LPVOID lpMapViewAddress; - char buf[] = "this is a test string"; - char ch[2048]; - char readString[2048]; - char lpFileName[] = "test.tmp"; - DWORD dwBytesRead; - BOOL bRetVal; - - /* Initialize the PAL environment. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file handle with CreateFile. - */ - hFile = CreateFile( lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /* Initialize the buffers. - */ - memset(ch, 0, MappingSize); - memset(readString, 0, MappingSize); - - /* Create a unnamed file-mapping object with file handle FileHandle - * and with PAGE_READWRITE protection. - */ - hFileMapping = CreateFileMapping( - hFile, - NULL, /*not inherited*/ - PAGE_READWRITE, /*read and wite*/ - 0, /*high-order of object size*/ - MappingSize, /*low-orger of object size*/ - NULL); /*unnamed object*/ - - if(NULL == hFileMapping) - { - Trace("ERROR:%u: Failed to create File Mapping.\n", - GetLastError()); - CloseHandle(hFile); - Fail(""); - } - - /* maps a view of a file into the address space of the calling process. - */ - lpMapViewAddress = MapViewOfFile( - hFileMapping, - FILE_MAP_ALL_ACCESS, /* access code */ - 0, /* high order offset */ - 0, /* low order offset */ - MappingSize); /* number of bytes for map */ - - if(NULL == lpMapViewAddress) - { - Trace("ERROR:%u: Failed to call MapViewOfFile API to map a view" - " of file!\n", - GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - /* Write to the MapView and copy the MapViewOfFile - * to buffer, so we can compare with value read from - * file directly. - */ - - memcpy(lpMapViewAddress, buf, strlen(buf)); - memcpy(ch, (LPCSTR)lpMapViewAddress, MappingSize); - - /* Read from the File handle. - */ - bRetVal = ReadFile(hFile, - readString, - strlen(buf), - &dwBytesRead, - NULL); - - if (bRetVal == FALSE) - { - Trace("ERROR: %u :unable to read from file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - if (memcmp(ch, readString, strlen(readString)) != 0) - { - Trace("ERROR: Read string from file \"%s\", is " - "not equal to string written through MapView " - "\"%s\".\n", - readString, - ch); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - /* Unmap the view of file. - */ - if(UnmapViewOfFile(lpMapViewAddress) == FALSE) - { - Trace("ERROR: Failed to call UnmapViewOfFile API to" - " unmap the view of a file, error code=%u\n", - GetLastError()); - CloseHandle(hFile); - CloseHandle(hFileMapping); - Fail(""); - } - - /* Re-initialize the buffer. - */ - memset(ch, 0, MappingSize); - - /* Close handle to created file mapping. - */ - if(CloseHandle(hFileMapping) == FALSE) - { - Trace("ERROR:%u:Failed to call CloseHandle API " - "to close a file mapping handle.", - GetLastError()); - CloseHandle(hFile); - Fail(""); - } - - /* Close handle to create file. - */ - if(CloseHandle(hFile) == FALSE) - { - Fail("ERROR:%u:Failed to call CloseHandle API " - "to close a file handle.", - GetLastError()); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.cpp b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.cpp new file mode 100644 index 0000000000..a970ccc3b5 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.cpp @@ -0,0 +1,184 @@ +// 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: UnMapViewOfFile.c +** +** Purpose: Positive test the MapViewOfFile API. +** Call MapViewOfFile with access FILE_MAP_ALL_ACCESS. +** +** Depends: CreateFile, +** GetFileSize, +** memset, +** memcpy, +** memcmp, +** ReadFile, +** UnMapViewOfFile, +** CreateFileMapping, +** CloseHandle. + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + const int MappingSize = 2048; + HANDLE hFile; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + char buf[] = "this is a test string"; + char ch[2048]; + char readString[2048]; + char lpFileName[] = "test.tmp"; + DWORD dwBytesRead; + BOOL bRetVal; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Initialize the buffers. + */ + memset(ch, 0, MappingSize); + memset(readString, 0, MappingSize); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and wite*/ + 0, /*high-order of object size*/ + MappingSize, /*low-orger of object size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + CloseHandle(hFile); + Fail(""); + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset */ + 0, /* low order offset */ + MappingSize); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile API to map a view" + " of file!\n", + GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + /* Write to the MapView and copy the MapViewOfFile + * to buffer, so we can compare with value read from + * file directly. + */ + + memcpy(lpMapViewAddress, buf, strlen(buf)); + memcpy(ch, (LPCSTR)lpMapViewAddress, MappingSize); + + /* Read from the File handle. + */ + bRetVal = ReadFile(hFile, + readString, + strlen(buf), + &dwBytesRead, + NULL); + + if (bRetVal == FALSE) + { + Trace("ERROR: %u :unable to read from file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + if (memcmp(ch, readString, strlen(readString)) != 0) + { + Trace("ERROR: Read string from file \"%s\", is " + "not equal to string written through MapView " + "\"%s\".\n", + readString, + ch); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + /* Unmap the view of file. + */ + if(UnmapViewOfFile(lpMapViewAddress) == FALSE) + { + Trace("ERROR: Failed to call UnmapViewOfFile API to" + " unmap the view of a file, error code=%u\n", + GetLastError()); + CloseHandle(hFile); + CloseHandle(hFileMapping); + Fail(""); + } + + /* Re-initialize the buffer. + */ + memset(ch, 0, MappingSize); + + /* Close handle to created file mapping. + */ + if(CloseHandle(hFileMapping) == FALSE) + { + Trace("ERROR:%u:Failed to call CloseHandle API " + "to close a file mapping handle.", + GetLastError()); + CloseHandle(hFile); + Fail(""); + } + + /* Close handle to create file. + */ + if(CloseHandle(hFile) == FALSE) + { + Fail("ERROR:%u:Failed to call CloseHandle API " + "to close a file handle.", + GetLastError()); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/CMakeLists.txt index 5c12cf9825..750e446a17 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - unmapviewoffile.c + unmapviewoffile.cpp ) add_executable(paltest_unmapviewoffile_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.c b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.c deleted file mode 100644 index 2ca185d234..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.c +++ /dev/null @@ -1,42 +0,0 @@ -// 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: UnmapViewOfFile.c (test 2) -** -** Purpose: Negative test the UnmapViewOfFile API. -** Call UnmapViewOfFile to unmap a view of -** NULL. -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /* Negative test the UnmapViewOfFile by passing a NULL*/ - /* mapping address handle*/ - err = UnmapViewOfFile(NULL); - if(0 != err) - { - Fail("ERROR: Able to call UnmapViewOfFile API " - "by passing a NULL mapping address.\n" ); - - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.cpp b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.cpp new file mode 100644 index 0000000000..2ca185d234 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.cpp @@ -0,0 +1,42 @@ +// 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: UnmapViewOfFile.c (test 2) +** +** Purpose: Negative test the UnmapViewOfFile API. +** Call UnmapViewOfFile to unmap a view of +** NULL. +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /* Negative test the UnmapViewOfFile by passing a NULL*/ + /* mapping address handle*/ + err = UnmapViewOfFile(NULL); + if(0 != err) + { + Fail("ERROR: Able to call UnmapViewOfFile API " + "by passing a NULL mapping address.\n" ); + + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt index eafaa66856..b2cafde93a 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt @@ -14,6 +14,7 @@ add_subdirectory(test19) add_subdirectory(test2) add_subdirectory(test20) add_subdirectory(test21) +add_subdirectory(test22) add_subdirectory(test3) add_subdirectory(test4) add_subdirectory(test5) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/CMakeLists.txt index 90ba41bd79..f8c0645a4b 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.c deleted file mode 100644 index 26ee942ba1..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT allocation type -** and PAGE_READONLY access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.cpp new file mode 100644 index 0000000000..26ee942ba1 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.cpp @@ -0,0 +1,50 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT allocation type +** and PAGE_READONLY access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/CMakeLists.txt index 51b0e1d92e..1b66f0d7cb 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test10 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.c deleted file mode 100644 index ac06b9b5c8..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_RESERVE allocation type -** and PAGE_EXECUTE_READ access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_RESERVE, //allocation type - PAGE_EXECUTE_READ); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.cpp new file mode 100644 index 0000000000..ac06b9b5c8 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_RESERVE allocation type +** and PAGE_EXECUTE_READ access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_RESERVE, //allocation type + PAGE_EXECUTE_READ); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/CMakeLists.txt index adff47087b..95e1a06f55 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test11 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.c deleted file mode 100644 index a3df39b634..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_RESERVE allocation type -** and PAGE_READONLY access protection -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_RESERVE, //allocation type - PAGE_EXECUTE_READWRITE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.cpp new file mode 100644 index 0000000000..a3df39b634 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.cpp @@ -0,0 +1,49 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_RESERVE allocation type +** and PAGE_READONLY access protection +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_RESERVE, //allocation type + PAGE_EXECUTE_READWRITE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/CMakeLists.txt index 26f303573e..7564f960fe 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test12 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.c deleted file mode 100644 index 8b3508635f..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_RESERVE allocation type -** and PAGE_NOACCESS access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_RESERVE, //allocation type - PAGE_NOACCESS); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.cpp new file mode 100644 index 0000000000..8b3508635f --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_RESERVE allocation type +** and PAGE_NOACCESS access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_RESERVE, //allocation type + PAGE_NOACCESS); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/CMakeLists.txt index f85cbdc694..a49dcfc81d 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test13 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.c deleted file mode 100644 index d2109c0339..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type -** and PAGE_READONLY access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT|MEM_TOP_DOWN, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.cpp new file mode 100644 index 0000000000..d2109c0339 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type +** and PAGE_READONLY access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT|MEM_TOP_DOWN, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/CMakeLists.txt index 41ed0ca208..180a48e74d 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test14 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.c deleted file mode 100644 index 49bd21875e..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type -** and PAGE_READWRITE access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT|MEM_TOP_DOWN, //allocation type - PAGE_READWRITE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.cpp new file mode 100644 index 0000000000..49bd21875e --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type +** and PAGE_READWRITE access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT|MEM_TOP_DOWN, //allocation type + PAGE_READWRITE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/CMakeLists.txt index 87b29108b2..4ba219472e 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test15 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.c deleted file mode 100644 index 3cf1502f26..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type -** and PAGE_EXECUTE access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT|MEM_TOP_DOWN, //allocation type - PAGE_EXECUTE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.cpp new file mode 100644 index 0000000000..3cf1502f26 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type +** and PAGE_EXECUTE access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT|MEM_TOP_DOWN, //allocation type + PAGE_EXECUTE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/CMakeLists.txt index 90e3f3bdb2..1c5f63dce5 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test16 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.c deleted file mode 100644 index ce61b9aa39..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type -** and PAGE_EXECUTE_READ access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT|MEM_TOP_DOWN, //allocation type - PAGE_EXECUTE_READ); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.cpp new file mode 100644 index 0000000000..ce61b9aa39 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type +** and PAGE_EXECUTE_READ access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT|MEM_TOP_DOWN, //allocation type + PAGE_EXECUTE_READ); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/CMakeLists.txt index 461b48ccc0..6523bb9292 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test17 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.c deleted file mode 100644 index eb609f14e4..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type -** and PAGE_READONLY access protection -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT|MEM_TOP_DOWN, //allocation type - PAGE_EXECUTE_READWRITE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.cpp new file mode 100644 index 0000000000..eb609f14e4 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.cpp @@ -0,0 +1,49 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type +** and PAGE_READONLY access protection +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT|MEM_TOP_DOWN, //allocation type + PAGE_EXECUTE_READWRITE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/CMakeLists.txt index 69823be14b..3fe65b4ac8 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test18 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.c deleted file mode 100644 index e46da851db..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type -** and PAGE_NOACCESS access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT|MEM_TOP_DOWN, //allocation type - PAGE_NOACCESS); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.cpp new file mode 100644 index 0000000000..e46da851db --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.cpp @@ -0,0 +1,49 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type +** and PAGE_NOACCESS access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT|MEM_TOP_DOWN, //allocation type + PAGE_NOACCESS); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/CMakeLists.txt index fa65b4fa46..1795b8ba54 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test19 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.c deleted file mode 100644 index 5cbe48b15e..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc to reserve and commit -** simultaneously with MEM_COMMIT|MEM_RESERVE|MEM_TOP_DOWN -** allocation type and PAGE_READONLY access -** protection -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //reserve and commit simultaneously by using MEM_COMMIT|MEM_RESERVE - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT|MEM_RESERVE|MEM_TOP_DOWN, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.cpp new file mode 100644 index 0000000000..5cbe48b15e --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.cpp @@ -0,0 +1,51 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc to reserve and commit +** simultaneously with MEM_COMMIT|MEM_RESERVE|MEM_TOP_DOWN +** allocation type and PAGE_READONLY access +** protection +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //reserve and commit simultaneously by using MEM_COMMIT|MEM_RESERVE + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT|MEM_RESERVE|MEM_TOP_DOWN, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/CMakeLists.txt index 1753b1edc5..20da178bfc 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.c deleted file mode 100644 index 99cf76a523..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT allocation type -** and PAGE_READWRITE access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT, //allocation type - PAGE_READWRITE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.cpp new file mode 100644 index 0000000000..99cf76a523 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.cpp @@ -0,0 +1,49 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT allocation type +** and PAGE_READWRITE access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT, //allocation type + PAGE_READWRITE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/CMakeLists.txt index 2c55071149..5c23fe2b0d 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - virtualalloc.c + virtualalloc.cpp ) add_executable(paltest_virtualalloc_test20 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.c deleted file mode 100644 index 7aec3c7f55..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Ensure that memory re-committed through VirtualAlloc -** is not changed. -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - int *ptr; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - ptr = (int *) VirtualAlloc(NULL, 4096, MEM_COMMIT | MEM_RESERVE, - PAGE_READWRITE); - if (ptr == NULL) - { - Fail("First VirtualAlloc failed!\n"); - } - - *ptr = 123; - - ptr = (int *) VirtualAlloc(ptr, 4096, MEM_COMMIT, PAGE_READWRITE); - if (ptr == NULL) - { - Fail("Second VirtualAlloc failed!\n"); - } - if (*ptr != 123) - { - Fail("VirtualAlloc modified (probably zeroed) re-committed memory!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.cpp new file mode 100644 index 0000000000..7aec3c7f55 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.cpp @@ -0,0 +1,50 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Ensure that memory re-committed through VirtualAlloc +** is not changed. +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + int *ptr; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + ptr = (int *) VirtualAlloc(NULL, 4096, MEM_COMMIT | MEM_RESERVE, + PAGE_READWRITE); + if (ptr == NULL) + { + Fail("First VirtualAlloc failed!\n"); + } + + *ptr = 123; + + ptr = (int *) VirtualAlloc(ptr, 4096, MEM_COMMIT, PAGE_READWRITE); + if (ptr == NULL) + { + Fail("Second VirtualAlloc failed!\n"); + } + if (*ptr != 123) + { + Fail("VirtualAlloc modified (probably zeroed) re-committed memory!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/CMakeLists.txt index f97c32af75..96a3144e8a 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - virtualalloc.c + virtualalloc.cpp ) add_executable(paltest_virtualalloc_test21 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.c deleted file mode 100644 index 065a2ff5c8..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Ensure that memory committed through VirtualAlloc, -** then freed, then committed again is zeroed. -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - int *ptr; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - ptr = (int *) VirtualAlloc(NULL, 4096, MEM_COMMIT | MEM_RESERVE, - PAGE_READWRITE); - if (ptr == NULL) - { - Fail("First VirtualAlloc failed!\n"); - } - *ptr = 123; - - if (!VirtualFree(ptr, 4096, MEM_DECOMMIT)) - { - Fail("VirtualFree failed!\n"); - } - - ptr = (int *) VirtualAlloc(ptr, 4096, MEM_COMMIT, PAGE_READWRITE); - if (ptr == NULL) - { - Fail("Second VirtualAlloc failed!\n"); - } - if (*ptr != 0) - { - Fail("VirtualAlloc failed to zero its memory!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.cpp new file mode 100644 index 0000000000..065a2ff5c8 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.cpp @@ -0,0 +1,54 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Ensure that memory committed through VirtualAlloc, +** then freed, then committed again is zeroed. +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + int *ptr; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + ptr = (int *) VirtualAlloc(NULL, 4096, MEM_COMMIT | MEM_RESERVE, + PAGE_READWRITE); + if (ptr == NULL) + { + Fail("First VirtualAlloc failed!\n"); + } + *ptr = 123; + + if (!VirtualFree(ptr, 4096, MEM_DECOMMIT)) + { + Fail("VirtualFree failed!\n"); + } + + ptr = (int *) VirtualAlloc(ptr, 4096, MEM_COMMIT, PAGE_READWRITE); + if (ptr == NULL) + { + Fail("Second VirtualAlloc failed!\n"); + } + if (*ptr != 0) + { + Fail("VirtualAlloc failed to zero its memory!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt new file mode 100644 index 0000000000..cdad2ca19d --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + VirtualAlloc.cpp +) + +add_executable(paltest_virtualalloc_test22 + ${SOURCES} +) + +add_dependencies(paltest_virtualalloc_test22 coreclrpal) + +target_link_libraries(paltest_virtualalloc_test22 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp new file mode 100644 index 0000000000..489926f48d --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp @@ -0,0 +1,44 @@ +// 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: virtualalloc.c +** +** Purpose: Negative test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT allocation type +** and PAGE_READWRITE access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + (SIZE_T)(2147483647000000), //specify the size to be int32.maxvalue mega bytes + MEM_COMMIT, //allocation type + PAGE_READWRITE); //access protection + if(NULL != lpVirtualAddress) + { + Fail("\nWelcome to the Future, where Unlimited Memory is Available, disregard this test!\n"); + } + + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat new file mode 100644 index 0000000000..3d5962c7af --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat @@ -0,0 +1,13 @@ +# 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 = Filemapping_memmgt +Function = VirtualAlloc +Name = Negative test for VirtualAlloc API +TYPE = DEFAULT +EXE1 = virtualalloc +Description +=Test the VirtualAlloc with MEM_COMMIT allocation type +=and PAGE_READWRITEaccess protection diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/CMakeLists.txt index 035594bd79..77822f7862 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.c deleted file mode 100644 index 5c57ec337f..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT allocation type -** and PAGE_EXECUTE access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT, //allocation type - PAGE_EXECUTE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.cpp new file mode 100644 index 0000000000..5c57ec337f --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT allocation type +** and PAGE_EXECUTE access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT, //allocation type + PAGE_EXECUTE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/CMakeLists.txt index 5ce80bf52f..0e2c448659 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test4 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.c deleted file mode 100644 index c134a14eb1..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT allocation type -** and PAGE_EXECUTE_READ access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT, //allocation type - PAGE_EXECUTE_READ); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.cpp new file mode 100644 index 0000000000..c134a14eb1 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.cpp @@ -0,0 +1,49 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT allocation type +** and PAGE_EXECUTE_READ access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT, //allocation type + PAGE_EXECUTE_READ); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/CMakeLists.txt index 138d9c9727..247053ff0f 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test5 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.c deleted file mode 100644 index 8c4f9dcdb6..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT allocation type -** and PAGE_READONLY access protection -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT, //allocation type - PAGE_EXECUTE_READWRITE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.cpp new file mode 100644 index 0000000000..8c4f9dcdb6 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.cpp @@ -0,0 +1,50 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT allocation type +** and PAGE_READONLY access protection +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT, //allocation type + PAGE_EXECUTE_READWRITE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/CMakeLists.txt index c61add9db4..d19391d294 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test6 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.c deleted file mode 100644 index e9c33d86df..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_COMMIT allocation type -** and PAGE_NOACCESS access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT, //allocation type - PAGE_NOACCESS); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.cpp new file mode 100644 index 0000000000..e9c33d86df --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_COMMIT allocation type +** and PAGE_NOACCESS access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT, //allocation type + PAGE_NOACCESS); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/CMakeLists.txt index b5452a0c48..8c01e041de 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test7 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.c deleted file mode 100644 index bee2735c9f..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_RESERVE allocation type -** and PAGE_READONLY access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_RESERVE, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - PAL_Terminate(); - return 1; - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - PAL_Terminate(); - return 1; - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.cpp new file mode 100644 index 0000000000..bee2735c9f --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.cpp @@ -0,0 +1,53 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_RESERVE allocation type +** and PAGE_READONLY access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_RESERVE, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + PAL_Terminate(); + return 1; + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + PAL_Terminate(); + return 1; + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/CMakeLists.txt index 584a0c505a..db2a7447be 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test8 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.c deleted file mode 100644 index d548e0c8db..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_RESERVE allocation type -** and PAGE_READWRITE access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_RESERVE, //allocation type - PAGE_READWRITE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.cpp new file mode 100644 index 0000000000..d548e0c8db --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_RESERVE allocation type +** and PAGE_READWRITE access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_RESERVE, //allocation type + PAGE_READWRITE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/CMakeLists.txt index aee950b2e4..254fc6fcf2 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualAlloc.c + VirtualAlloc.cpp ) add_executable(paltest_virtualalloc_test9 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.c deleted file mode 100644 index 2711addacc..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualalloc.c -** -** Purpose: Positive test the VirtualAlloc API. -** Call VirtualAlloc with MEM_RESERVE allocation type -** and PAGE_EXECUTE access protection - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_RESERVE, //allocation type - PAGE_EXECUTE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.cpp new file mode 100644 index 0000000000..2711addacc --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.cpp @@ -0,0 +1,48 @@ +// 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: virtualalloc.c +** +** Purpose: Positive test the VirtualAlloc API. +** Call VirtualAlloc with MEM_RESERVE allocation type +** and PAGE_EXECUTE access protection + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_RESERVE, //allocation type + PAGE_EXECUTE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/CMakeLists.txt index 1914f76fe6..d2319506f2 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualFree.c + VirtualFree.cpp ) add_executable(paltest_virtualfree_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.c deleted file mode 100644 index 0f4f144aa5..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: virtualfree.c -** -** Purpose: Positive test the VirtualFree API. -** Call VirtualFree with MEM_DECOMMIT -** free operation type -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.cpp new file mode 100644 index 0000000000..0f4f144aa5 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.cpp @@ -0,0 +1,48 @@ +// 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: virtualfree.c +** +** Purpose: Positive test the VirtualFree API. +** Call VirtualFree with MEM_DECOMMIT +** free operation type +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/CMakeLists.txt index a288b37154..9a3bc7ac61 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualFree.c + VirtualFree.cpp ) add_executable(paltest_virtualfree_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.c deleted file mode 100644 index 70064a3bf9..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: virtualfree.c -** -** Purpose: Positive test the VirtualFree API. -** Call VirtualFree with MEM_RELEASE -** free operation type -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - 1024, //specify the size - MEM_COMMIT, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - PAL_Terminate(); - return 1; - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,//base address - 0, //must be zero with MEM_RELEASE - MEM_RELEASE);//free operation - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - PAL_Terminate(); - return 1; - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.cpp new file mode 100644 index 0000000000..70064a3bf9 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.cpp @@ -0,0 +1,54 @@ +// 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: virtualfree.c +** +** Purpose: Positive test the VirtualFree API. +** Call VirtualFree with MEM_RELEASE +** free operation type +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + 1024, //specify the size + MEM_COMMIT, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + PAL_Terminate(); + return 1; + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,//base address + 0, //must be zero with MEM_RELEASE + MEM_RELEASE);//free operation + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + PAL_Terminate(); + return 1; + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/CMakeLists.txt index 993189c1aa..8484c0fd94 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualFree.c + VirtualFree.cpp ) add_executable(paltest_virtualfree_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.c deleted file mode 100644 index 27f1936be7..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: virtualfree.c -** -** Purpose: Positive test the VirtualFree API. -** Call VirtualFree with MEM_RELEASE -** and MEM_DECOMMIT free operation type -** -** -**============================================================*/ -#include - -#define VIRTUALSIZE 1024 - - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - VIRTUALSIZE, //specify the size - MEM_RESERVE, //allocation type - PAGE_NOACCESS); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //decommit and release the specified region - err = VirtualFree(lpVirtualAddress, //base address - VIRTUALSIZE, //decommited size - MEM_DECOMMIT|MEM_RELEASE);//free operation - if(0 != err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.cpp new file mode 100644 index 0000000000..27f1936be7 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.cpp @@ -0,0 +1,53 @@ +// 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: virtualfree.c +** +** Purpose: Positive test the VirtualFree API. +** Call VirtualFree with MEM_RELEASE +** and MEM_DECOMMIT free operation type +** +** +**============================================================*/ +#include + +#define VIRTUALSIZE 1024 + + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + VIRTUALSIZE, //specify the size + MEM_RESERVE, //allocation type + PAGE_NOACCESS); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //decommit and release the specified region + err = VirtualFree(lpVirtualAddress, //base address + VIRTUALSIZE, //decommited size + MEM_DECOMMIT|MEM_RELEASE);//free operation + if(0 != err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/CMakeLists.txt index 214cf460ae..4283398a6f 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualProtect.c + VirtualProtect.cpp ) add_executable(paltest_virtualprotect_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.c deleted file mode 100644 index 1a28bd156d..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: virtualprotect.c -** -** Purpose: Positive test the VirtualProtect API. -** Call VirtualProtect to set new protect as -** PAGE_READWRITE -** -** -**============================================================*/ -#include - -#define REGIONSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - DWORD OldProtect; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region - REGIONSIZE, //specify the size - MEM_COMMIT, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - OldProtect = PAGE_READONLY; - //Set new access protection - err = VirtualProtect(lpVirtualAddress, - REGIONSIZE, //specify the region size - PAGE_READWRITE,//desied access protection - &OldProtect);//old access protection - if(0 == err) - { - Trace("\nFailed to call VirtualProtect API!\n"); - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - Fail(""); - } - - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.cpp new file mode 100644 index 0000000000..1a28bd156d --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.cpp @@ -0,0 +1,69 @@ +// 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: virtualprotect.c +** +** Purpose: Positive test the VirtualProtect API. +** Call VirtualProtect to set new protect as +** PAGE_READWRITE +** +** +**============================================================*/ +#include + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + DWORD OldProtect; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region + REGIONSIZE, //specify the size + MEM_COMMIT, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + OldProtect = PAGE_READONLY; + //Set new access protection + err = VirtualProtect(lpVirtualAddress, + REGIONSIZE, //specify the region size + PAGE_READWRITE,//desied access protection + &OldProtect);//old access protection + if(0 == err) + { + Trace("\nFailed to call VirtualProtect API!\n"); + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + Fail(""); + } + + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/CMakeLists.txt index 27f43477ea..aed68fd27f 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualProtect.c + VirtualProtect.cpp ) add_executable(paltest_virtualprotect_test2 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.c deleted file mode 100644 index 64a08d7885..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: virtualprotect.c -** -** Purpose: Positive test the VirtualProtect API. -** Call VirtualProtect to set new protect as -** PAGE_EXECUTE -** -** -**============================================================*/ -#include - -#define REGIONSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - DWORD OldProtect; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region - REGIONSIZE, //specify the size - MEM_COMMIT, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - OldProtect = PAGE_READONLY; - //Set new access protection - err = VirtualProtect(lpVirtualAddress, - REGIONSIZE, //specify the region size - PAGE_EXECUTE,//desied access protection - &OldProtect);//old access protection - if(0 == err) - { - Trace("\nFailed to call VirtualProtect API!\n"); - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - Fail(""); - } - - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.cpp new file mode 100644 index 0000000000..64a08d7885 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.cpp @@ -0,0 +1,69 @@ +// 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: virtualprotect.c +** +** Purpose: Positive test the VirtualProtect API. +** Call VirtualProtect to set new protect as +** PAGE_EXECUTE +** +** +**============================================================*/ +#include + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + DWORD OldProtect; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region + REGIONSIZE, //specify the size + MEM_COMMIT, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + OldProtect = PAGE_READONLY; + //Set new access protection + err = VirtualProtect(lpVirtualAddress, + REGIONSIZE, //specify the region size + PAGE_EXECUTE,//desied access protection + &OldProtect);//old access protection + if(0 == err) + { + Trace("\nFailed to call VirtualProtect API!\n"); + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + Fail(""); + } + + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/CMakeLists.txt index 994d4e2f41..70728592ad 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualProtect.c + VirtualProtect.cpp ) add_executable(paltest_virtualprotect_test3 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.c deleted file mode 100644 index 0f738630ee..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: virtualprotect.c -** -** Purpose: Positive test the VirtualProtect API. -** Call VirtualProtect to set new protect as -** PAGE_EXECUTE_READ -** -** -**============================================================*/ -#include - -#define REGIONSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - DWORD OldProtect; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region - REGIONSIZE, //specify the size - MEM_COMMIT, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - OldProtect = PAGE_READONLY; - //Set new access protection - err = VirtualProtect(lpVirtualAddress, - REGIONSIZE, //specify the region size - PAGE_EXECUTE_READ,//desied access protection - &OldProtect);//old access protection - if(0 == err) - { - Trace("\nFailed to call VirtualProtect API!\n"); - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - Fail(""); - } - - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.cpp new file mode 100644 index 0000000000..0f738630ee --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.cpp @@ -0,0 +1,69 @@ +// 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: virtualprotect.c +** +** Purpose: Positive test the VirtualProtect API. +** Call VirtualProtect to set new protect as +** PAGE_EXECUTE_READ +** +** +**============================================================*/ +#include + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + DWORD OldProtect; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region + REGIONSIZE, //specify the size + MEM_COMMIT, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + OldProtect = PAGE_READONLY; + //Set new access protection + err = VirtualProtect(lpVirtualAddress, + REGIONSIZE, //specify the region size + PAGE_EXECUTE_READ,//desied access protection + &OldProtect);//old access protection + if(0 == err) + { + Trace("\nFailed to call VirtualProtect API!\n"); + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + Fail(""); + } + + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/CMakeLists.txt index 2e0fba50bb..5ad64a74eb 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualProtect.c + VirtualProtect.cpp ) add_executable(paltest_virtualprotect_test4 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.c deleted file mode 100644 index 926d501d0d..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: virtualprotect.c -** -** Purpose: Positive test the VirtualProtect API. -** Call VirtualProtect to set new protect as -** PAGE_EXECUTE_READWRITE -** -** -**============================================================*/ -#include - -#define REGIONSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - DWORD OldProtect; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region - REGIONSIZE, //specify the size - MEM_COMMIT, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - OldProtect = PAGE_READONLY; - //Set new access protection - err = VirtualProtect(lpVirtualAddress, - REGIONSIZE, //specify the region size - PAGE_EXECUTE_READWRITE,//desied access protection - &OldProtect);//old access protection - if(0 == err) - { - Trace("\nFailed to call VirtualProtect API!\n"); - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - Fail(""); - } - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.cpp new file mode 100644 index 0000000000..926d501d0d --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.cpp @@ -0,0 +1,68 @@ +// 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: virtualprotect.c +** +** Purpose: Positive test the VirtualProtect API. +** Call VirtualProtect to set new protect as +** PAGE_EXECUTE_READWRITE +** +** +**============================================================*/ +#include + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + DWORD OldProtect; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region + REGIONSIZE, //specify the size + MEM_COMMIT, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + OldProtect = PAGE_READONLY; + //Set new access protection + err = VirtualProtect(lpVirtualAddress, + REGIONSIZE, //specify the region size + PAGE_EXECUTE_READWRITE,//desied access protection + &OldProtect);//old access protection + if(0 == err) + { + Trace("\nFailed to call VirtualProtect API!\n"); + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + Fail(""); + } + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/CMakeLists.txt index 6d6fd07df8..78932ef453 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualProtect.c + VirtualProtect.cpp ) add_executable(paltest_virtualprotect_test6 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.c deleted file mode 100644 index d60b323ec6..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: virtualprotect.c -** -** Purpose: Positive test the VirtualProtect API. -** Call VirtualProtect to set new protect as -** PAGE_NOACCESS -** -** -**============================================================*/ -#include - -#define REGIONSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - DWORD OldProtect; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region - REGIONSIZE, //specify the size - MEM_COMMIT, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - OldProtect = PAGE_READONLY; - //Set new access protection - err = VirtualProtect(lpVirtualAddress, - REGIONSIZE, //specify the region size - PAGE_NOACCESS,//desied access protection - &OldProtect);//old access protection - if(0 == err) - { - Trace("\nFailed to call VirtualProtect API!\n"); - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - Fail(""); - } - - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.cpp new file mode 100644 index 0000000000..d60b323ec6 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.cpp @@ -0,0 +1,68 @@ +// 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: virtualprotect.c +** +** Purpose: Positive test the VirtualProtect API. +** Call VirtualProtect to set new protect as +** PAGE_NOACCESS +** +** +**============================================================*/ +#include + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + DWORD OldProtect; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region + REGIONSIZE, //specify the size + MEM_COMMIT, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + OldProtect = PAGE_READONLY; + //Set new access protection + err = VirtualProtect(lpVirtualAddress, + REGIONSIZE, //specify the region size + PAGE_NOACCESS,//desied access protection + &OldProtect);//old access protection + if(0 == err) + { + Trace("\nFailed to call VirtualProtect API!\n"); + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + Fail(""); + } + + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/CMakeLists.txt index 06af860559..caf5ef91f4 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualProtect.c + VirtualProtect.cpp ) add_executable(paltest_virtualprotect_test7 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.c deleted file mode 100644 index edc37711f4..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: virtualprotect.c -** -** Purpose: Positive test the VirtualProtect API. -** Call VirtualProtect to set new protect as -** PAGE_READONLY -** -** -**============================================================*/ -#include - -#define REGIONSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - DWORD OldProtect; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region - REGIONSIZE, //specify the size - MEM_COMMIT, //allocation type - PAGE_READWRITE); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - OldProtect = PAGE_READONLY; - //Set new access protection - err = VirtualProtect(lpVirtualAddress, - REGIONSIZE, //specify the region size - PAGE_READONLY,//desied access protection - &OldProtect);//old access protection - if(0 == err) - { - Trace("\nFailed to call VirtualProtect API!\n"); - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - Fail(""); - } - - - //decommit the specified region - err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.cpp new file mode 100644 index 0000000000..edc37711f4 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.cpp @@ -0,0 +1,69 @@ +// 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: virtualprotect.c +** +** Purpose: Positive test the VirtualProtect API. +** Call VirtualProtect to set new protect as +** PAGE_READONLY +** +** +**============================================================*/ +#include + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + DWORD OldProtect; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region + REGIONSIZE, //specify the size + MEM_COMMIT, //allocation type + PAGE_READWRITE); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + OldProtect = PAGE_READONLY; + //Set new access protection + err = VirtualProtect(lpVirtualAddress, + REGIONSIZE, //specify the region size + PAGE_READONLY,//desied access protection + &OldProtect);//old access protection + if(0 == err) + { + Trace("\nFailed to call VirtualProtect API!\n"); + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + Fail(""); + } + + + //decommit the specified region + err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/CMakeLists.txt index 4f4e4bc5f0..17cbdee4a5 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - VirtualQuery.c + VirtualQuery.cpp ) add_executable(paltest_virtualquery_test1 diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.c deleted file mode 100644 index 44216ae563..0000000000 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: virtualquery.c -** -** Purpose: Positive test the VirtualQuery API. -** Call VirtualQuery to get the virtual -** page info -** -** -**============================================================*/ -#include - -#define VIRTUALMEMORYSIZE 1024 - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LPVOID lpVirtualAddress; - MEMORY_BASIC_INFORMATION PageInfo; - DWORD dwBufferSize; - - //Initialize the PAL environment - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - //Allocate the physical storage in memory or in the paging file on disk - lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region - VIRTUALMEMORYSIZE, //specify the size - MEM_COMMIT, //allocation type - PAGE_READONLY); //access protection - if(NULL == lpVirtualAddress) - { - Fail("\nFailed to call VirtualAlloc API!\n"); - } - - //get the virtual page info - dwBufferSize = - VirtualQuery(lpVirtualAddress,&PageInfo,sizeof(MEMORY_BASIC_INFORMATION)); - - if(dwBufferSize <= 0 || - PageInfo.RegionSize <=0 || - PAGE_READONLY != PageInfo.AllocationProtect || - MEM_COMMIT != PageInfo.State) - { - Fail("\nFailed to call VirtualQuery API!\n"); - } - - - - //decommit the specified region - err = VirtualFree(lpVirtualAddress, //virtual page base address - VIRTUALMEMORYSIZE,//specify the size - MEM_DECOMMIT);//free operation - if(0 == err) - { - Fail("\nFailed to call VirtualFree API!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.cpp new file mode 100644 index 0000000000..44216ae563 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.cpp @@ -0,0 +1,68 @@ +// 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: virtualquery.c +** +** Purpose: Positive test the VirtualQuery API. +** Call VirtualQuery to get the virtual +** page info +** +** +**============================================================*/ +#include + +#define VIRTUALMEMORYSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LPVOID lpVirtualAddress; + MEMORY_BASIC_INFORMATION PageInfo; + DWORD dwBufferSize; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //Allocate the physical storage in memory or in the paging file on disk + lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region + VIRTUALMEMORYSIZE, //specify the size + MEM_COMMIT, //allocation type + PAGE_READONLY); //access protection + if(NULL == lpVirtualAddress) + { + Fail("\nFailed to call VirtualAlloc API!\n"); + } + + //get the virtual page info + dwBufferSize = + VirtualQuery(lpVirtualAddress,&PageInfo,sizeof(MEMORY_BASIC_INFORMATION)); + + if(dwBufferSize <= 0 || + PageInfo.RegionSize <=0 || + PAGE_READONLY != PageInfo.AllocationProtect || + MEM_COMMIT != PageInfo.State) + { + Fail("\nFailed to call VirtualQuery API!\n"); + } + + + + //decommit the specified region + err = VirtualFree(lpVirtualAddress, //virtual page base address + VIRTUALMEMORYSIZE,//specify the size + MEM_DECOMMIT);//free operation + if(0 == err) + { + Fail("\nFailed to call VirtualFree API!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test1/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryA/test1/CMakeLists.txt index 542f8d3277..62b896df65 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - LoadLibraryA.c + LoadLibraryA.cpp ) add_executable(paltest_loadlibrarya_test1 diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test1/LoadLibraryA.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test1/LoadLibraryA.c deleted file mode 100644 index b4a8de1367..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test1/LoadLibraryA.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: loadlibrarya.c -** -** Purpose: Positive test the LoadLibrary API. -** Call LoadLibrary to map a module into the calling -** process address space(DLL file) -** -** -**============================================================*/ -#include - -/* SHLEXT is defined only for Unix variants */ - -#if defined(SHLEXT) -#define ModuleName "librotor_pal"SHLEXT -#else -#define ModuleName "rotor_pal.dll" -#endif - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - int err; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - /* load a module */ - ModuleHandle = LoadLibrary(ModuleName); - if(!ModuleHandle) - { - Fail("Failed to call LoadLibrary API!\n"); - } - - /* 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; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test1/LoadLibraryA.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test1/LoadLibraryA.cpp new file mode 100644 index 0000000000..b4a8de1367 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test1/LoadLibraryA.cpp @@ -0,0 +1,53 @@ +// 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: loadlibrarya.c +** +** Purpose: Positive test the LoadLibrary API. +** Call LoadLibrary to map a module into the calling +** process address space(DLL file) +** +** +**============================================================*/ +#include + +/* SHLEXT is defined only for Unix variants */ + +#if defined(SHLEXT) +#define ModuleName "librotor_pal"SHLEXT +#else +#define ModuleName "rotor_pal.dll" +#endif + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + int err; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + /* load a module */ + ModuleHandle = LoadLibrary(ModuleName); + if(!ModuleHandle) + { + Fail("Failed to call LoadLibrary API!\n"); + } + + /* 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; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test2/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryA/test2/CMakeLists.txt index 63cfb22545..48a4c36cd0 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - LoadLibraryA.c + LoadLibraryA.cpp ) add_executable(paltest_loadlibrarya_test2 diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test2/LoadLibraryA.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test2/LoadLibraryA.c deleted file mode 100644 index d7cd9cb875..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test2/LoadLibraryA.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: loadlibrarya.c -** -** Purpose: Negative test the LoadLibraryA API. -** Call LoadLibraryA with a not exist module Name -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - int err; - const char *pModuleName = "Not-exist-module-name"; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*try to load a not exist module */ - ModuleHandle = LoadLibraryA(pModuleName); - if(NULL != ModuleHandle) - { - Trace("Failed to call LoadLibraryA with a not exist mudule name, " - "a NULL module handle is expected, but no NULL module handle " - "is returned, error code=%u\n", GetLastError()); - - /* decrement the reference count of the loaded module */ - err = FreeLibrary(ModuleHandle); - if(0 == err) - { - Trace("\nFailed to all FreeLibrary API to decrement " - "the reference count of the loaded module, " - "error code = %u\n", GetLastError()); - - } - - Fail(""); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test2/LoadLibraryA.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test2/LoadLibraryA.cpp new file mode 100644 index 0000000000..d7cd9cb875 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test2/LoadLibraryA.cpp @@ -0,0 +1,52 @@ +// 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: loadlibrarya.c +** +** Purpose: Negative test the LoadLibraryA API. +** Call LoadLibraryA with a not exist module Name +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + int err; + const char *pModuleName = "Not-exist-module-name"; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*try to load a not exist module */ + ModuleHandle = LoadLibraryA(pModuleName); + if(NULL != ModuleHandle) + { + Trace("Failed to call LoadLibraryA with a not exist mudule name, " + "a NULL module handle is expected, but no NULL module handle " + "is returned, error code=%u\n", GetLastError()); + + /* decrement the reference count of the loaded module */ + err = FreeLibrary(ModuleHandle); + if(0 == err) + { + Trace("\nFailed to all FreeLibrary API to decrement " + "the reference count of the loaded module, " + "error code = %u\n", GetLastError()); + + } + + Fail(""); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test2/MyModule.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test2/MyModule.c deleted file mode 100644 index 883b3fbc4a..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test2/MyModule.c +++ /dev/null @@ -1,19 +0,0 @@ -// 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: mymoduale.c -** -** Purpose: Positive test the LoadLibrary API. -** - -** -**============================================================*/ - -int __cdecl main(int argc, char *argv[]) -{ - //only for testing LoadLibrary - return 0; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test2/MyModule.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test2/MyModule.cpp new file mode 100644 index 0000000000..883b3fbc4a --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test2/MyModule.cpp @@ -0,0 +1,19 @@ +// 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: mymoduale.c +** +** Purpose: Positive test the LoadLibrary API. +** + +** +**============================================================*/ + +int __cdecl main(int argc, char *argv[]) +{ + //only for testing LoadLibrary + return 0; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test3/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryA/test3/CMakeLists.txt index 143d0ec096..ae05b3560d 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - loadlibrarya.c + loadlibrarya.cpp ) add_executable(paltest_loadlibrarya_test3 diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test3/loadlibrarya.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test3/loadlibrarya.c deleted file mode 100644 index da38f98d04..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test3/loadlibrarya.c +++ /dev/null @@ -1,40 +0,0 @@ -// 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: loadlibrarya.c -** -** Purpose: Negative test the LoadLibrary API with NULL module -** name. -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - int err; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*load a module by passing a NULL module name*/ - ModuleHandle = LoadLibraryA(NULL); - if(NULL != ModuleHandle) - { - Fail("\nFailed to call loadlibrarya API for a negative test, " - "call loadibrarya with NULL moudle name, a NULL module " - "handle is expected, but no NULL module handle is returned, " - "error code =%u\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test3/loadlibrarya.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test3/loadlibrarya.cpp new file mode 100644 index 0000000000..da38f98d04 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test3/loadlibrarya.cpp @@ -0,0 +1,40 @@ +// 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: loadlibrarya.c +** +** Purpose: Negative test the LoadLibrary API with NULL module +** name. +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + int err; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*load a module by passing a NULL module name*/ + ModuleHandle = LoadLibraryA(NULL); + if(NULL != ModuleHandle) + { + Fail("\nFailed to call loadlibrarya API for a negative test, " + "call loadibrarya with NULL moudle name, a NULL module " + "handle is expected, but no NULL module handle is returned, " + "error code =%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test5/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryA/test5/CMakeLists.txt index a9d791c916..99915eea2c 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - loadlibrarya.c + loadlibrarya.cpp ) add_executable(paltest_loadlibrarya_test5 diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test5/loadlibrarya.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test5/loadlibrarya.c deleted file mode 100644 index d1e6b6d1dc..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test5/loadlibrarya.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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: loadlibrarya.c -** -** Purpose: Negative test the LoadLibraryA API. -** Call LoadLibraryA by passing a module name -** without extension but with a trailing dot. -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - char ModuleName[_MAX_FNAME]; - int err; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - memset(ModuleName, 0, _MAX_FNAME); - - /*Module name without extension but with a trailing dot*/ -#if WIN32 - sprintf(ModuleName, "%s", "rotor_pal."); -#else - /* Under FreeBSD */ - sprintf(ModuleName, "%s", "librotor_pal."); -#endif - - /* load a module which does not have the file extension, - * but has a trailing dot - */ - ModuleHandle = LoadLibraryA(ModuleName); - if(NULL != ModuleHandle) - { - Trace("Failed to call LoadLibraryA API for a negative test " - "call LoadLibraryA with module name which does not have " - "extension except a trailing dot, a NULL module handle is" - "expected, but no NULL module handle is returned, " - "error code = %u\n", GetLastError()); - - - /* decrement the reference count of the loaded dll */ - err = FreeLibrary(ModuleHandle); - if(0 == err) - { - Trace("\nFailed to call FreeLibrary API, " - "error code = %u\n", GetLastError()); - } - - Fail(""); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test5/loadlibrarya.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test5/loadlibrarya.cpp new file mode 100644 index 0000000000..ab38d1a632 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test5/loadlibrarya.cpp @@ -0,0 +1,67 @@ +// 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: loadlibrarya.c +** +** Purpose: Negative test the LoadLibraryA API. +** Call LoadLibraryA by passing a module name +** without extension but with a trailing dot. +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + char ModuleName[_MAX_FNAME]; + int err; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + memset(ModuleName, 0, _MAX_FNAME); + + /*Module name without extension but with a trailing dot*/ +#if WIN32 + sprintf_s(ModuleName, _countof(ModuleName), "%s", "rotor_pal."); +#else + /* Under FreeBSD */ + sprintf_s(ModuleName, _countof(ModuleName), "%s", "librotor_pal."); +#endif + + /* load a module which does not have the file extension, + * but has a trailing dot + */ + ModuleHandle = LoadLibraryA(ModuleName); + if(NULL != ModuleHandle) + { + Trace("Failed to call LoadLibraryA API for a negative test " + "call LoadLibraryA with module name which does not have " + "extension except a trailing dot, a NULL module handle is" + "expected, but no NULL module handle is returned, " + "error code = %u\n", GetLastError()); + + + /* decrement the reference count of the loaded dll */ + err = FreeLibrary(ModuleHandle); + if(0 == err) + { + Trace("\nFailed to call FreeLibrary API, " + "error code = %u\n", GetLastError()); + } + + Fail(""); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test6/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/CMakeLists.txt index bb66adef77..0fac8785a8 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - loadlibrarya.c + loadlibrarya.cpp ) add_executable(paltest_loadlibrarya_test6 @@ -20,7 +20,7 @@ target_link_libraries(paltest_loadlibrarya_test6 set(HELPERSOURCES - dlltest.c + dlltest.cpp ) add_executable(paltest_loadlibrarya_test6_dlltest diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test6/dlltest.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/dlltest.c deleted file mode 100644 index 72380eebb5..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test6/dlltest.c +++ /dev/null @@ -1,72 +0,0 @@ -// 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: dllmain.c -** -** Purpose: Test to ensure DllMain() is called with DLL_THREAD_DETACH -** only the initial time that the library is loaded. -** -** Depends: None -** - -** -**===========================================================================*/ - -#include - -/* count of the number of times DllMain() - * was called with THREAD_ATTACH. - */ -static int g_attachCount = 0; - -/* standard DllMain() */ -BOOL __stdcall DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) -{ - switch( reason ) - { - case DLL_PROCESS_ATTACH: - { - g_attachCount++; - break; - } - - case DLL_PROCESS_DETACH: - { - break; - } - - case DLL_THREAD_ATTACH: - { - break; - } - - case DLL_THREAD_DETACH: - { - break; - } - } - - return TRUE; -} - -#if _WIN32 -BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) -{ - return DllMain(hinstDLL, reason, lpvReserved); -} -#endif - - - -/* function to return the current attach count */ -#if _WIN32 -__declspec(dllexport) -#endif -int PALAPI GetAttachCount( void ) -{ - return g_attachCount; -} - diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test6/dlltest.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/dlltest.cpp new file mode 100644 index 0000000000..72380eebb5 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/dlltest.cpp @@ -0,0 +1,72 @@ +// 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: dllmain.c +** +** Purpose: Test to ensure DllMain() is called with DLL_THREAD_DETACH +** only the initial time that the library is loaded. +** +** Depends: None +** + +** +**===========================================================================*/ + +#include + +/* count of the number of times DllMain() + * was called with THREAD_ATTACH. + */ +static int g_attachCount = 0; + +/* standard DllMain() */ +BOOL __stdcall DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) +{ + switch( reason ) + { + case DLL_PROCESS_ATTACH: + { + g_attachCount++; + break; + } + + case DLL_PROCESS_DETACH: + { + break; + } + + case DLL_THREAD_ATTACH: + { + break; + } + + case DLL_THREAD_DETACH: + { + break; + } + } + + return TRUE; +} + +#if _WIN32 +BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) +{ + return DllMain(hinstDLL, reason, lpvReserved); +} +#endif + + + +/* function to return the current attach count */ +#if _WIN32 +__declspec(dllexport) +#endif +int PALAPI GetAttachCount( void ) +{ + return g_attachCount; +} + diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.c deleted file mode 100644 index ee825e6439..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.c +++ /dev/null @@ -1,172 +0,0 @@ -// 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: loadlibrary.c (test 6) -** -** Purpose: Positive test the LoadLibrary API. Test will verify -** that it is unable to load the library twice. Once by -** using the full path name and secondly by using the -** short name. -** - -** -**============================================================*/ -#include - -/*Define platform specific information*/ -#if defined(SHLEXT) -#define LibraryName "dlltest"SHLEXT -#define GETATTACHCOUNTNAME "GetAttachCount" -#else -typedef int (*dllfunct)(); -#define LibraryName "dlltest.dll" -#define GETATTACHCOUNTNAME "_GetAttachCount@0" -#endif - - -/* Helper function to test the loaded library. - */ -BOOL PALAPI TestDll(HMODULE hLib) -{ - int RetVal; - char FunctName[] = GETATTACHCOUNTNAME; - FARPROC DllFunc; - - /* Access a function from the loaded library. - */ - DllFunc = GetProcAddress(hLib, FunctName); - if(DllFunc == NULL) - { - Trace("ERROR: Unable to load function \"%s\" from library \"%s\"\n", - FunctName, - LibraryName); - return (FALSE); - } - - /* Verify that the DLL_PROCESS_ATTACH is only - * accessed once.*/ - RetVal = DllFunc(); - if (RetVal != 1) - { - Trace("ERROR: Unable to receive correct information from DLL! " - ":expected \"1\", returned \"%d\"\n", - RetVal); - return (FALSE); - } - - return (TRUE); -} - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFullLib; - HANDLE hShortLib; - int iRetVal = FAIL; - char fullPath[_MAX_DIR]; - char drive[_MAX_DRIVE]; - char dir[_MAX_DIR]; - char fname[_MAX_FNAME]; - char ext[_MAX_EXT]; - - - - /* Initialize the PAL. */ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /* Initalize the buffer. - */ - memset(fullPath, 0, _MAX_DIR); - - /* Get the full path to the library (DLL). - */ - - if (NULL != _fullpath(fullPath,argv[0],_MAX_DIR)) { - - _splitpath(fullPath,drive,dir,fname,ext); - _makepath(fullPath,drive,dir,LibraryName,""); - - - } else { - Fail("ERROR: conversion from relative path \" %s \" to absolute path failed. _fullpath returned NULL\n",argv[0]); - } - - /* Call Load library with the short name of - * the dll. - */ - hShortLib = LoadLibrary(LibraryName); - if(hShortLib == NULL) - { - Fail("ERROR:%u:Unable to load library %s\n", - GetLastError(), - LibraryName); - } - - /* Test the loaded library. - */ - if (!TestDll(hShortLib)) - { - iRetVal = FAIL; - goto cleanUpOne; - } - - /* Call Load library with the full name of - * the dll. - */ - hFullLib = LoadLibrary(fullPath); - if(hFullLib == NULL) - { - Trace("ERROR:%u:Unable to load library %s\n", - GetLastError(), - fullPath); - iRetVal = FAIL; - goto cleanUpTwo; - } - - /* Test the loaded library. - */ - if (!TestDll(hFullLib)) - { - iRetVal = FAIL; - goto cleanUpTwo; - } - - /* Test Succeeded. - */ - iRetVal = PASS; - -cleanUpTwo: - - /* Call the FreeLibrary API. - */ - if (!FreeLibrary(hFullLib)) - { - Trace("ERROR:%u: Unable to free library \"%s\"\n", - GetLastError(), - fullPath); - iRetVal = FAIL; - } - -cleanUpOne: - - /* Call the FreeLibrary API. - */ - if (!FreeLibrary(hShortLib)) - { - Trace("ERROR:%u: Unable to free library \"%s\"\n", - GetLastError(), - LibraryName); - iRetVal = FAIL; - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return iRetVal; - -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp new file mode 100644 index 0000000000..ee825e6439 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp @@ -0,0 +1,172 @@ +// 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: loadlibrary.c (test 6) +** +** Purpose: Positive test the LoadLibrary API. Test will verify +** that it is unable to load the library twice. Once by +** using the full path name and secondly by using the +** short name. +** + +** +**============================================================*/ +#include + +/*Define platform specific information*/ +#if defined(SHLEXT) +#define LibraryName "dlltest"SHLEXT +#define GETATTACHCOUNTNAME "GetAttachCount" +#else +typedef int (*dllfunct)(); +#define LibraryName "dlltest.dll" +#define GETATTACHCOUNTNAME "_GetAttachCount@0" +#endif + + +/* Helper function to test the loaded library. + */ +BOOL PALAPI TestDll(HMODULE hLib) +{ + int RetVal; + char FunctName[] = GETATTACHCOUNTNAME; + FARPROC DllFunc; + + /* Access a function from the loaded library. + */ + DllFunc = GetProcAddress(hLib, FunctName); + if(DllFunc == NULL) + { + Trace("ERROR: Unable to load function \"%s\" from library \"%s\"\n", + FunctName, + LibraryName); + return (FALSE); + } + + /* Verify that the DLL_PROCESS_ATTACH is only + * accessed once.*/ + RetVal = DllFunc(); + if (RetVal != 1) + { + Trace("ERROR: Unable to receive correct information from DLL! " + ":expected \"1\", returned \"%d\"\n", + RetVal); + return (FALSE); + } + + return (TRUE); +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFullLib; + HANDLE hShortLib; + int iRetVal = FAIL; + char fullPath[_MAX_DIR]; + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + + + + /* Initialize the PAL. */ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /* Initalize the buffer. + */ + memset(fullPath, 0, _MAX_DIR); + + /* Get the full path to the library (DLL). + */ + + if (NULL != _fullpath(fullPath,argv[0],_MAX_DIR)) { + + _splitpath(fullPath,drive,dir,fname,ext); + _makepath(fullPath,drive,dir,LibraryName,""); + + + } else { + Fail("ERROR: conversion from relative path \" %s \" to absolute path failed. _fullpath returned NULL\n",argv[0]); + } + + /* Call Load library with the short name of + * the dll. + */ + hShortLib = LoadLibrary(LibraryName); + if(hShortLib == NULL) + { + Fail("ERROR:%u:Unable to load library %s\n", + GetLastError(), + LibraryName); + } + + /* Test the loaded library. + */ + if (!TestDll(hShortLib)) + { + iRetVal = FAIL; + goto cleanUpOne; + } + + /* Call Load library with the full name of + * the dll. + */ + hFullLib = LoadLibrary(fullPath); + if(hFullLib == NULL) + { + Trace("ERROR:%u:Unable to load library %s\n", + GetLastError(), + fullPath); + iRetVal = FAIL; + goto cleanUpTwo; + } + + /* Test the loaded library. + */ + if (!TestDll(hFullLib)) + { + iRetVal = FAIL; + goto cleanUpTwo; + } + + /* Test Succeeded. + */ + iRetVal = PASS; + +cleanUpTwo: + + /* Call the FreeLibrary API. + */ + if (!FreeLibrary(hFullLib)) + { + Trace("ERROR:%u: Unable to free library \"%s\"\n", + GetLastError(), + fullPath); + iRetVal = FAIL; + } + +cleanUpOne: + + /* Call the FreeLibrary API. + */ + if (!FreeLibrary(hShortLib)) + { + Trace("ERROR:%u: Unable to free library \"%s\"\n", + GetLastError(), + LibraryName); + iRetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return iRetVal; + +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test7/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryA/test7/CMakeLists.txt index 6c0d174600..bb403c6466 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - LoadLibraryA.c + LoadLibraryA.cpp ) add_executable(paltest_loadlibrarya_test7 diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test7/LoadLibraryA.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test7/LoadLibraryA.c deleted file mode 100644 index 5e6db8bb68..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test7/LoadLibraryA.c +++ /dev/null @@ -1,83 +0,0 @@ -// 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: loadlibrarya.c -** -** Purpose: Positive test the LoadLibrary API by calling it multiple times. -** Call LoadLibrary to map a module into the calling -** process address space(DLL file) -** -** -**============================================================*/ -#include - -/* SHLEXT is defined only for Unix variants */ - -#if defined(SHLEXT) -#define ModuleName "librotor_pal"SHLEXT -#else -#define ModuleName "rotor_pal.dll" -#endif - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - HMODULE ReturnHandle; - int err; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - /* load a module */ - ModuleHandle = LoadLibrary(ModuleName); - if(!ModuleHandle) - { - Fail("Error[%u]:Failed to call LoadLibrary API!\n", GetLastError()); - } - - /* Call LoadLibrary again, should return same handle as returned for first time */ - ReturnHandle = LoadLibrary(ModuleName); - if(!ReturnHandle) - { - Fail("Error[%u]:Failed to call LoadLibrary API second time!\n", GetLastError()); - } - - if(ModuleHandle != ReturnHandle) - { - Fail("Error[%u]:Failed to return the same handle while calling LoadLibrary API twice!\n", GetLastError()); - } - - Trace("Value of handle ModuleHandle[%x], ReturnHandle[%x]\n", ModuleHandle, ReturnHandle); - /* decrement the reference count of the loaded dll */ - err = FreeLibrary(ModuleHandle); - - if(0 == err) - { - Fail("Error[%u]:Failed to FreeLibrary API!\n", GetLastError()); - } - - /* Try Freeing a library again, should not fail */ - err = FreeLibrary(ReturnHandle); - - if(0 == err) - { - Fail("Error[%u][%d]: Was not successful in freeing a Library twice using FreeLibrary!\n", GetLastError(), err); - } - - /* Try Freeing a library again, should fail */ - err = FreeLibrary(ReturnHandle); - - if(1 != err) - { - Fail("Error[%u][%d]: Was successful in freeing a Library thrice using FreeLibrary!\n", GetLastError(), err); - } - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test7/LoadLibraryA.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test7/LoadLibraryA.cpp new file mode 100644 index 0000000000..5e6db8bb68 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test7/LoadLibraryA.cpp @@ -0,0 +1,83 @@ +// 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: loadlibrarya.c +** +** Purpose: Positive test the LoadLibrary API by calling it multiple times. +** Call LoadLibrary to map a module into the calling +** process address space(DLL file) +** +** +**============================================================*/ +#include + +/* SHLEXT is defined only for Unix variants */ + +#if defined(SHLEXT) +#define ModuleName "librotor_pal"SHLEXT +#else +#define ModuleName "rotor_pal.dll" +#endif + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + HMODULE ReturnHandle; + int err; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + /* load a module */ + ModuleHandle = LoadLibrary(ModuleName); + if(!ModuleHandle) + { + Fail("Error[%u]:Failed to call LoadLibrary API!\n", GetLastError()); + } + + /* Call LoadLibrary again, should return same handle as returned for first time */ + ReturnHandle = LoadLibrary(ModuleName); + if(!ReturnHandle) + { + Fail("Error[%u]:Failed to call LoadLibrary API second time!\n", GetLastError()); + } + + if(ModuleHandle != ReturnHandle) + { + Fail("Error[%u]:Failed to return the same handle while calling LoadLibrary API twice!\n", GetLastError()); + } + + Trace("Value of handle ModuleHandle[%x], ReturnHandle[%x]\n", ModuleHandle, ReturnHandle); + /* decrement the reference count of the loaded dll */ + err = FreeLibrary(ModuleHandle); + + if(0 == err) + { + Fail("Error[%u]:Failed to FreeLibrary API!\n", GetLastError()); + } + + /* Try Freeing a library again, should not fail */ + err = FreeLibrary(ReturnHandle); + + if(0 == err) + { + Fail("Error[%u][%d]: Was not successful in freeing a Library twice using FreeLibrary!\n", GetLastError(), err); + } + + /* Try Freeing a library again, should fail */ + err = FreeLibrary(ReturnHandle); + + if(1 != err) + { + Fail("Error[%u][%d]: Was successful in freeing a Library thrice using FreeLibrary!\n", GetLastError(), err); + } + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test8/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryA/test8/CMakeLists.txt index b663a7b5bc..9e3449166b 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - loadlibrarya.c + loadlibrarya.cpp ) add_executable(paltest_loadlibrarya_test8 @@ -20,7 +20,7 @@ target_link_libraries(paltest_loadlibrarya_test8 set(HELPERSOURCES - dlltest.c + dlltest.cpp ) add_executable(paltest_loadlibrarya_test8_dlltest diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test8/dlltest.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test8/dlltest.c deleted file mode 100644 index 72380eebb5..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test8/dlltest.c +++ /dev/null @@ -1,72 +0,0 @@ -// 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: dllmain.c -** -** Purpose: Test to ensure DllMain() is called with DLL_THREAD_DETACH -** only the initial time that the library is loaded. -** -** Depends: None -** - -** -**===========================================================================*/ - -#include - -/* count of the number of times DllMain() - * was called with THREAD_ATTACH. - */ -static int g_attachCount = 0; - -/* standard DllMain() */ -BOOL __stdcall DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) -{ - switch( reason ) - { - case DLL_PROCESS_ATTACH: - { - g_attachCount++; - break; - } - - case DLL_PROCESS_DETACH: - { - break; - } - - case DLL_THREAD_ATTACH: - { - break; - } - - case DLL_THREAD_DETACH: - { - break; - } - } - - return TRUE; -} - -#if _WIN32 -BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) -{ - return DllMain(hinstDLL, reason, lpvReserved); -} -#endif - - - -/* function to return the current attach count */ -#if _WIN32 -__declspec(dllexport) -#endif -int PALAPI GetAttachCount( void ) -{ - return g_attachCount; -} - diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test8/dlltest.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test8/dlltest.cpp new file mode 100644 index 0000000000..72380eebb5 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test8/dlltest.cpp @@ -0,0 +1,72 @@ +// 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: dllmain.c +** +** Purpose: Test to ensure DllMain() is called with DLL_THREAD_DETACH +** only the initial time that the library is loaded. +** +** Depends: None +** + +** +**===========================================================================*/ + +#include + +/* count of the number of times DllMain() + * was called with THREAD_ATTACH. + */ +static int g_attachCount = 0; + +/* standard DllMain() */ +BOOL __stdcall DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) +{ + switch( reason ) + { + case DLL_PROCESS_ATTACH: + { + g_attachCount++; + break; + } + + case DLL_PROCESS_DETACH: + { + break; + } + + case DLL_THREAD_ATTACH: + { + break; + } + + case DLL_THREAD_DETACH: + { + break; + } + } + + return TRUE; +} + +#if _WIN32 +BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) +{ + return DllMain(hinstDLL, reason, lpvReserved); +} +#endif + + + +/* function to return the current attach count */ +#if _WIN32 +__declspec(dllexport) +#endif +int PALAPI GetAttachCount( void ) +{ + return g_attachCount; +} + diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test8/loadlibrarya.c b/src/pal/tests/palsuite/loader/LoadLibraryA/test8/loadlibrarya.c deleted file mode 100644 index 6556e9c896..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryA/test8/loadlibrarya.c +++ /dev/null @@ -1,235 +0,0 @@ -// 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: loadlibrary.c (test 8) -** -** Purpose: Positive test the LoadLibrary API. Test will verify -** that it is unable to load the library twice. Once by -** using the full path name and secondly by using the -** short name. -** - -** -**============================================================*/ -#include - -/*Define platform specific information*/ -#if defined(SHLEXT) -#define LibraryName "dlltest"SHLEXT -#define GETATTACHCOUNTNAME "GetAttachCount" -#else -typedef int (*dllfunct)(); -#define LibraryName "dlltest.dll" -#define GETATTACHCOUNTNAME "_GetAttachCount@0" -#endif - - -/* Helper function to test the loaded library. - */ -BOOL PALAPI TestDll(HMODULE hLib) -{ - int RetVal; - char FunctName[] = GETATTACHCOUNTNAME; - FARPROC DllFunc; - - /* Access a function from the loaded library. - */ - DllFunc = GetProcAddress(hLib, FunctName); - if(DllFunc == NULL) - { - Trace("ERROR: Unable to load function \"%s\" from library \"%s\"\n", - FunctName, - LibraryName); - return (FALSE); - } - - /* Verify that the DLL_PROCESS_ATTACH is only - * accessed once.*/ - RetVal = DllFunc(); - if (RetVal != 1) - { - Trace("ERROR: Unable to receive correct information from DLL! " - ":expected \"1\", returned \"%d\"\n", - RetVal); - return (FALSE); - } - - return (TRUE); -} - -int __cdecl main(int argc, char *argv[]) -{ - HANDLE hFullLib; - HANDLE hShortLib; - HANDLE hRelLib; - - int iRetVal = FAIL; - char fullPath[_MAX_DIR]; - char drive[_MAX_DRIVE]; - char dir[_MAX_DIR]; - char relTestDir[_MAX_DIR]; - char fname[_MAX_FNAME]; - char ext[_MAX_EXT]; - - BOOL bRc = FALSE; - char relLibPath[_MAX_DIR]; - - - /* Initialize the PAL. */ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /* Initalize the buffer. - */ - memset(fullPath, 0, _MAX_DIR); - - /* Get the full path to the library (DLL). - */ - - if (NULL != _fullpath(fullPath,argv[0],_MAX_DIR)) { - - _splitpath(fullPath,drive,dir,fname,ext); - _makepath(fullPath,drive,dir,LibraryName,""); - - - } else { - Fail("ERROR: conversion from relative path \" %s \" to absolute path failed. _fullpath returned NULL\n",argv[0]); - } - - /* Get relative path to the library - */ - _splitpath(argv[0], drive, relTestDir, fname, ext); - _makepath(relLibPath,drive,relTestDir,LibraryName,""); - - - /* Call Load library with the short name of - * the dll. - */ - hShortLib = LoadLibrary(LibraryName); - if(hShortLib == NULL) - { - Fail("ERROR:%u:Short:Unable to load library %s\n", - GetLastError(), - LibraryName); - } - - /* Test the loaded library. - */ - if (!TestDll(hShortLib)) - { - iRetVal = FAIL; - goto cleanUpOne; - } - - /* Call Load library with the full name of - * the dll. - */ - hFullLib = LoadLibrary(fullPath); - if(hFullLib == NULL) - { - Trace("ERROR:%u:Full:Unable to load library %s\n", - GetLastError(), - fullPath); - iRetVal = FAIL; - goto cleanUpTwo; - } - - /* Test the loaded library. - */ - if (!TestDll(hFullLib)) - { - iRetVal = FAIL; - goto cleanUpTwo; - } - - /* - ** Call the load library with the relative path - ** wrt to the directory ./testloadlibrary/.. - ** since we don't want to make any assumptions - ** regarding the type of build - */ - hRelLib = LoadLibrary(relLibPath); - if(hRelLib == NULL) - { - Trace("ERROR:%u:Rel:Unable to load library at %s\n", - GetLastError(), relLibPath); - iRetVal = FAIL; - goto cleanUpTwo; - } - - /* Test the loaded library. - */ - if (!TestDll(hRelLib)) - { - iRetVal = FAIL; - goto cleanUpThree; - } - - if( hRelLib != hFullLib ) - { - Trace("Relative and Absolute Paths to libraries don't have same handle\n"); - iRetVal = FAIL; - goto cleanUpThree; - } - - if( hRelLib != hShortLib ) - { - Trace("Relative and Short Paths to libraries don't have same handle\n"); - iRetVal = FAIL; - goto cleanUpThree; - } - - - /* Test Succeeded. - */ - iRetVal = PASS; - -cleanUpThree: - - /* Call the FreeLibrary API. - */ - - if (!FreeLibrary(hRelLib)) - { - Trace("ERROR:%u: Unable to free library \"%s\"\n", - GetLastError(), - relLibPath); - iRetVal = FAIL; - } - -cleanUpTwo: - - /* Call the FreeLibrary API. - */ - if (!FreeLibrary(hFullLib)) - { - Trace("ERROR:%u: Unable to free library \"%s\"\n", - GetLastError(), - fullPath); - iRetVal = FAIL; - } - -cleanUpOne: - - /* Call the FreeLibrary API. - */ - if (!FreeLibrary(hShortLib)) - { - Trace("ERROR:%u: Unable to free library \"%s\"\n", - GetLastError(), - LibraryName); - iRetVal = FAIL; - } - - - /* Terminate the PAL. - */ - PAL_TerminateEx(iRetVal); - return iRetVal; - -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test8/loadlibrarya.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test8/loadlibrarya.cpp new file mode 100644 index 0000000000..6556e9c896 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test8/loadlibrarya.cpp @@ -0,0 +1,235 @@ +// 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: loadlibrary.c (test 8) +** +** Purpose: Positive test the LoadLibrary API. Test will verify +** that it is unable to load the library twice. Once by +** using the full path name and secondly by using the +** short name. +** + +** +**============================================================*/ +#include + +/*Define platform specific information*/ +#if defined(SHLEXT) +#define LibraryName "dlltest"SHLEXT +#define GETATTACHCOUNTNAME "GetAttachCount" +#else +typedef int (*dllfunct)(); +#define LibraryName "dlltest.dll" +#define GETATTACHCOUNTNAME "_GetAttachCount@0" +#endif + + +/* Helper function to test the loaded library. + */ +BOOL PALAPI TestDll(HMODULE hLib) +{ + int RetVal; + char FunctName[] = GETATTACHCOUNTNAME; + FARPROC DllFunc; + + /* Access a function from the loaded library. + */ + DllFunc = GetProcAddress(hLib, FunctName); + if(DllFunc == NULL) + { + Trace("ERROR: Unable to load function \"%s\" from library \"%s\"\n", + FunctName, + LibraryName); + return (FALSE); + } + + /* Verify that the DLL_PROCESS_ATTACH is only + * accessed once.*/ + RetVal = DllFunc(); + if (RetVal != 1) + { + Trace("ERROR: Unable to receive correct information from DLL! " + ":expected \"1\", returned \"%d\"\n", + RetVal); + return (FALSE); + } + + return (TRUE); +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFullLib; + HANDLE hShortLib; + HANDLE hRelLib; + + int iRetVal = FAIL; + char fullPath[_MAX_DIR]; + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + char relTestDir[_MAX_DIR]; + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + + BOOL bRc = FALSE; + char relLibPath[_MAX_DIR]; + + + /* Initialize the PAL. */ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /* Initalize the buffer. + */ + memset(fullPath, 0, _MAX_DIR); + + /* Get the full path to the library (DLL). + */ + + if (NULL != _fullpath(fullPath,argv[0],_MAX_DIR)) { + + _splitpath(fullPath,drive,dir,fname,ext); + _makepath(fullPath,drive,dir,LibraryName,""); + + + } else { + Fail("ERROR: conversion from relative path \" %s \" to absolute path failed. _fullpath returned NULL\n",argv[0]); + } + + /* Get relative path to the library + */ + _splitpath(argv[0], drive, relTestDir, fname, ext); + _makepath(relLibPath,drive,relTestDir,LibraryName,""); + + + /* Call Load library with the short name of + * the dll. + */ + hShortLib = LoadLibrary(LibraryName); + if(hShortLib == NULL) + { + Fail("ERROR:%u:Short:Unable to load library %s\n", + GetLastError(), + LibraryName); + } + + /* Test the loaded library. + */ + if (!TestDll(hShortLib)) + { + iRetVal = FAIL; + goto cleanUpOne; + } + + /* Call Load library with the full name of + * the dll. + */ + hFullLib = LoadLibrary(fullPath); + if(hFullLib == NULL) + { + Trace("ERROR:%u:Full:Unable to load library %s\n", + GetLastError(), + fullPath); + iRetVal = FAIL; + goto cleanUpTwo; + } + + /* Test the loaded library. + */ + if (!TestDll(hFullLib)) + { + iRetVal = FAIL; + goto cleanUpTwo; + } + + /* + ** Call the load library with the relative path + ** wrt to the directory ./testloadlibrary/.. + ** since we don't want to make any assumptions + ** regarding the type of build + */ + hRelLib = LoadLibrary(relLibPath); + if(hRelLib == NULL) + { + Trace("ERROR:%u:Rel:Unable to load library at %s\n", + GetLastError(), relLibPath); + iRetVal = FAIL; + goto cleanUpTwo; + } + + /* Test the loaded library. + */ + if (!TestDll(hRelLib)) + { + iRetVal = FAIL; + goto cleanUpThree; + } + + if( hRelLib != hFullLib ) + { + Trace("Relative and Absolute Paths to libraries don't have same handle\n"); + iRetVal = FAIL; + goto cleanUpThree; + } + + if( hRelLib != hShortLib ) + { + Trace("Relative and Short Paths to libraries don't have same handle\n"); + iRetVal = FAIL; + goto cleanUpThree; + } + + + /* Test Succeeded. + */ + iRetVal = PASS; + +cleanUpThree: + + /* Call the FreeLibrary API. + */ + + if (!FreeLibrary(hRelLib)) + { + Trace("ERROR:%u: Unable to free library \"%s\"\n", + GetLastError(), + relLibPath); + iRetVal = FAIL; + } + +cleanUpTwo: + + /* Call the FreeLibrary API. + */ + if (!FreeLibrary(hFullLib)) + { + Trace("ERROR:%u: Unable to free library \"%s\"\n", + GetLastError(), + fullPath); + iRetVal = FAIL; + } + +cleanUpOne: + + /* Call the FreeLibrary API. + */ + if (!FreeLibrary(hShortLib)) + { + Trace("ERROR:%u: Unable to free library \"%s\"\n", + GetLastError(), + LibraryName); + iRetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(iRetVal); + return iRetVal; + +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test1/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryW/test1/CMakeLists.txt index 87038012b7..171d1d59d4 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - LoadLibraryW.c + LoadLibraryW.cpp ) add_executable(paltest_loadlibraryw_test1 diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test1/LoadLibraryW.c b/src/pal/tests/palsuite/loader/LoadLibraryW/test1/LoadLibraryW.c deleted file mode 100644 index 4c1a551de1..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryW/test1/LoadLibraryW.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: loadlibraryw.c -** -** Purpose: Positive test the LoadLibrary API. -** Call LoadLibrary to map a module into the calling -** process address space(DLL file) -** -** -**============================================================*/ -#define UNICODE -#include -/* SHLEXT is defined only for Unix variants */ - -#if defined(SHLEXT) -#define ModuleName "librotor_pal"SHLEXT -#else -#define ModuleName "rotor_pal.dll" -#endif - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - int err; - WCHAR *lpModuleName; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - ExitProcess(FAIL); - } - - /* 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"); - } - - - /* 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; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test1/LoadLibraryW.cpp b/src/pal/tests/palsuite/loader/LoadLibraryW/test1/LoadLibraryW.cpp new file mode 100644 index 0000000000..4c1a551de1 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryW/test1/LoadLibraryW.cpp @@ -0,0 +1,62 @@ +// 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: loadlibraryw.c +** +** Purpose: Positive test the LoadLibrary API. +** Call LoadLibrary to map a module into the calling +** process address space(DLL file) +** +** +**============================================================*/ +#define UNICODE +#include +/* SHLEXT is defined only for Unix variants */ + +#if defined(SHLEXT) +#define ModuleName "librotor_pal"SHLEXT +#else +#define ModuleName "rotor_pal.dll" +#endif + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + int err; + WCHAR *lpModuleName; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + /* 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"); + } + + + /* 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; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test2/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryW/test2/CMakeLists.txt index 5e8486d23b..9873e1332d 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - loadlibraryw.c + loadlibraryw.cpp ) add_executable(paltest_loadlibraryw_test2 diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.c b/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.c deleted file mode 100644 index e8aebf77e9..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: loadlibraryw.c -** -** Purpose: Negative test the LoadLibraryW API. -** Call LoadLibraryW with a not exist module Name -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - int err; - WCHAR *pwModuleName; - const char *pModuleName = "Not-exist-module-name"; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /* convert a normal string to a wide one */ - pwModuleName = convert((char *)pModuleName); - - - /*try to load a not exist module */ - ModuleHandle = LoadLibraryW(pwModuleName); - - /* free the memory */ - free(pwModuleName); - - if(NULL != ModuleHandle) - { - Trace("Failed to call LoadLibraryW with a not exist mudule name, " - "a NULL module handle is expected, but no NULL module handle " - "is returned, error code=%u\n", GetLastError()); - - /* decrement the reference count of the loaded module */ - err = FreeLibrary(ModuleHandle); - if(0 == err) - { - Trace("\nFailed to all FreeLibrary API to decrement " - "the reference count of the loaded module, " - "error code = %u\n", GetLastError()); - - } - - Fail(""); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp b/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp new file mode 100644 index 0000000000..e8aebf77e9 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp @@ -0,0 +1,62 @@ +// 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: loadlibraryw.c +** +** Purpose: Negative test the LoadLibraryW API. +** Call LoadLibraryW with a not exist module Name +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + int err; + WCHAR *pwModuleName; + const char *pModuleName = "Not-exist-module-name"; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /* convert a normal string to a wide one */ + pwModuleName = convert((char *)pModuleName); + + + /*try to load a not exist module */ + ModuleHandle = LoadLibraryW(pwModuleName); + + /* free the memory */ + free(pwModuleName); + + if(NULL != ModuleHandle) + { + Trace("Failed to call LoadLibraryW with a not exist mudule name, " + "a NULL module handle is expected, but no NULL module handle " + "is returned, error code=%u\n", GetLastError()); + + /* decrement the reference count of the loaded module */ + err = FreeLibrary(ModuleHandle); + if(0 == err) + { + Trace("\nFailed to all FreeLibrary API to decrement " + "the reference count of the loaded module, " + "error code = %u\n", GetLastError()); + + } + + Fail(""); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test3/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryW/test3/CMakeLists.txt index 2c96fa23da..be758643fa 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - loadlibraryw.c + loadlibraryw.cpp ) add_executable(paltest_loadlibraryw_test3 diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test3/loadlibraryw.c b/src/pal/tests/palsuite/loader/LoadLibraryW/test3/loadlibraryw.c deleted file mode 100644 index c722edaf13..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryW/test3/loadlibraryw.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: loadlibraryw.c -** -** Purpose: Negative test the loadlibraryw API. -** Call loadlibraryw with NULL module name -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - int err; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /* load a module with a NULL module name */ - ModuleHandle = LoadLibraryW(NULL); - if(NULL != ModuleHandle) - { - Fail("\nFailed to call loadlibraryw API for a negative test, " - "call loadibraryw with NULL moudle name, a NULL module " - "handle is expected, but no NULL module handle is returned, " - "error code =%u\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test3/loadlibraryw.cpp b/src/pal/tests/palsuite/loader/LoadLibraryW/test3/loadlibraryw.cpp new file mode 100644 index 0000000000..c722edaf13 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryW/test3/loadlibraryw.cpp @@ -0,0 +1,41 @@ +// 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: loadlibraryw.c +** +** Purpose: Negative test the loadlibraryw API. +** Call loadlibraryw with NULL module name +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + int err; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /* load a module with a NULL module name */ + ModuleHandle = LoadLibraryW(NULL); + if(NULL != ModuleHandle) + { + Fail("\nFailed to call loadlibraryw API for a negative test, " + "call loadibraryw with NULL moudle name, a NULL module " + "handle is expected, but no NULL module handle is returned, " + "error code =%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test5/CMakeLists.txt b/src/pal/tests/palsuite/loader/LoadLibraryW/test5/CMakeLists.txt index 7b8931a961..1ca990b514 100644 --- a/src/pal/tests/palsuite/loader/LoadLibraryW/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/loader/LoadLibraryW/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - loadlibraryw.c + loadlibraryw.cpp ) add_executable(paltest_loadlibraryw_test5 diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test5/loadlibraryw.c b/src/pal/tests/palsuite/loader/LoadLibraryW/test5/loadlibraryw.c deleted file mode 100644 index acaa200a06..0000000000 --- a/src/pal/tests/palsuite/loader/LoadLibraryW/test5/loadlibraryw.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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: loadlibraryw.c -** -** Purpose: Negative test the LoadLibraryW API. -** Call LoadLibraryW by passing a module name -** without extension but with a trailing dot. -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - int err; - WCHAR *lpModuleName; - char ModuleName[_MAX_FNAME]; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - memset(ModuleName, 0, _MAX_FNAME); - - /*Module name without extension but with a trailing dot*/ -#if WIN32 - sprintf(ModuleName,"%s","rotor_pal."); -#else - sprintf(ModuleName,"%s","librotor_pal."); -#endif - - /* convert a normal string to a wide one */ - lpModuleName = convert(ModuleName); - - /* load a module */ - ModuleHandle = LoadLibraryW(lpModuleName); - - /* free the memory */ - free(lpModuleName); - - if(NULL != ModuleHandle) - { - Trace("Failed to call LoadLibraryW API for a negative test " - "call LoadLibraryW with module name which does not have " - "extension except a trailing dot, a NULL module handle is" - "expected, but no NULL module handle is returned, " - "error code = %u\n", GetLastError()); - - /* decrement the reference count of the loaded dll */ - err = FreeLibrary(ModuleHandle); - if(0 == err) - { - Trace("\nFailed to call FreeLibrary API, " - "error code = %u\n", GetLastError()); - } - - Fail(""); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test5/loadlibraryw.cpp b/src/pal/tests/palsuite/loader/LoadLibraryW/test5/loadlibraryw.cpp new file mode 100644 index 0000000000..6d92f029e4 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryW/test5/loadlibraryw.cpp @@ -0,0 +1,71 @@ +// 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: loadlibraryw.c +** +** Purpose: Negative test the LoadLibraryW API. +** Call LoadLibraryW by passing a module name +** without extension but with a trailing dot. +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + int err; + WCHAR *lpModuleName; + char ModuleName[_MAX_FNAME]; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + memset(ModuleName, 0, _MAX_FNAME); + + /*Module name without extension but with a trailing dot*/ +#if WIN32 + sprintf_s(ModuleName, _countof(ModuleName),"%s","rotor_pal."); +#else + sprintf_s(ModuleName, _countof(ModuleName),"%s","librotor_pal."); +#endif + + /* convert a normal string to a wide one */ + lpModuleName = convert(ModuleName); + + /* load a module */ + ModuleHandle = LoadLibraryW(lpModuleName); + + /* free the memory */ + free(lpModuleName); + + if(NULL != ModuleHandle) + { + Trace("Failed to call LoadLibraryW API for a negative test " + "call LoadLibraryW with module name which does not have " + "extension except a trailing dot, a NULL module handle is" + "expected, but no NULL module handle is returned, " + "error code = %u\n", GetLastError()); + + /* decrement the reference count of the loaded dll */ + err = FreeLibrary(ModuleHandle); + if(0 == err) + { + Trace("\nFailed to call FreeLibrary API, " + "error code = %u\n", GetLastError()); + } + + Fail(""); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/locale_info/CompareStringA/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/CompareStringA/test1/CMakeLists.txt index 96ee18d857..171d5b77e8 100644 --- a/src/pal/tests/palsuite/locale_info/CompareStringA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/CompareStringA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_comparestringa_test1 diff --git a/src/pal/tests/palsuite/locale_info/CompareStringA/test1/test1.c b/src/pal/tests/palsuite/locale_info/CompareStringA/test1/test1.c deleted file mode 100644 index 98c147af48..0000000000 --- a/src/pal/tests/palsuite/locale_info/CompareStringA/test1/test1.c +++ /dev/null @@ -1,99 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that CompareStringA returns the correct value and can handle -** invalid parameters. -** -** -**==========================================================================*/ - -#define CSTR_LESS_THAN 1 -#define CSTR_EQUAL 2 -#define CSTR_GREATER_THAN 3 - -#include - -int __cdecl main(int argc, char *argv[]) -{ - char str1[] = {'f','o','o',0}; - char str2[] = {'f','o','o','x',0}; - char str3[] = {'f','O','o',0}; - int flags = NORM_IGNORECASE | NORM_IGNOREWIDTH; - int ret; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - ret = CompareStringA(0x0409, flags, str1, -1, str2, -1); - if (ret != CSTR_LESS_THAN) - { - Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_LESS_THAN!\n", str1, -1, str2, -1); - } - - ret = CompareStringA(0x0409, flags, str1, -1, str2, 3); - if (ret != CSTR_EQUAL) - { - Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_EQUAL!\n", str1, -1, str2, 3); - } - - ret = CompareStringA(0x0409, flags, str2, -1, str1, -1); - if (ret != CSTR_GREATER_THAN) - { - Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_GREATER_THAN!\n", str2, -1, str1, -1); - } - - ret = CompareStringA(0x0409, flags, str1, -1, str3, -1); - if (ret != CSTR_EQUAL) - { - Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_EQUAL!\n", str1, -1, str3, -1); - } - - ret = CompareStringA(0x0409, flags, str3, -1, str1, -1); - if (ret != CSTR_EQUAL) - { - Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_EQUAL!\n", str3, -1, str1, -1); - } - - ret = CompareStringA(0x0409, flags, str3, -1, str1, -1); - if (ret != CSTR_EQUAL) - { - Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_EQUAL!\n", str3, -1, str1, -1); - } - - ret = CompareStringA(0x0409, flags, str1, 0, str3, -1); - if (ret != CSTR_LESS_THAN) - { - Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_GREATER_THAN!\n", str1, 0, str3, -1); - } - - - ret = CompareStringA(0x0409, flags, NULL, -1, str3, -1); - if (ret != 0) - { - Fail("CompareStringA should have returned 0, got %d!\n", ret); - } - if (GetLastError() != ERROR_INVALID_PARAMETER) - { - Fail("CompareStringA should have set the last error to " - "ERROR_INVALID_PARAMETER!\n"); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/CompareStringA/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/CompareStringA/test1/test1.cpp new file mode 100644 index 0000000000..98c147af48 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/CompareStringA/test1/test1.cpp @@ -0,0 +1,99 @@ +// 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: test1.c +** +** Purpose: Tests that CompareStringA returns the correct value and can handle +** invalid parameters. +** +** +**==========================================================================*/ + +#define CSTR_LESS_THAN 1 +#define CSTR_EQUAL 2 +#define CSTR_GREATER_THAN 3 + +#include + +int __cdecl main(int argc, char *argv[]) +{ + char str1[] = {'f','o','o',0}; + char str2[] = {'f','o','o','x',0}; + char str3[] = {'f','O','o',0}; + int flags = NORM_IGNORECASE | NORM_IGNOREWIDTH; + int ret; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + ret = CompareStringA(0x0409, flags, str1, -1, str2, -1); + if (ret != CSTR_LESS_THAN) + { + Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_LESS_THAN!\n", str1, -1, str2, -1); + } + + ret = CompareStringA(0x0409, flags, str1, -1, str2, 3); + if (ret != CSTR_EQUAL) + { + Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_EQUAL!\n", str1, -1, str2, 3); + } + + ret = CompareStringA(0x0409, flags, str2, -1, str1, -1); + if (ret != CSTR_GREATER_THAN) + { + Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_GREATER_THAN!\n", str2, -1, str1, -1); + } + + ret = CompareStringA(0x0409, flags, str1, -1, str3, -1); + if (ret != CSTR_EQUAL) + { + Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_EQUAL!\n", str1, -1, str3, -1); + } + + ret = CompareStringA(0x0409, flags, str3, -1, str1, -1); + if (ret != CSTR_EQUAL) + { + Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_EQUAL!\n", str3, -1, str1, -1); + } + + ret = CompareStringA(0x0409, flags, str3, -1, str1, -1); + if (ret != CSTR_EQUAL) + { + Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_EQUAL!\n", str3, -1, str1, -1); + } + + ret = CompareStringA(0x0409, flags, str1, 0, str3, -1); + if (ret != CSTR_LESS_THAN) + { + Fail("CompareStringA with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_GREATER_THAN!\n", str1, 0, str3, -1); + } + + + ret = CompareStringA(0x0409, flags, NULL, -1, str3, -1); + if (ret != 0) + { + Fail("CompareStringA should have returned 0, got %d!\n", ret); + } + if (GetLastError() != ERROR_INVALID_PARAMETER) + { + Fail("CompareStringA should have set the last error to " + "ERROR_INVALID_PARAMETER!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/CompareStringW/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/CompareStringW/test1/CMakeLists.txt index 8652977387..15a7fe7685 100644 --- a/src/pal/tests/palsuite/locale_info/CompareStringW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/CompareStringW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_comparestringw_test1 diff --git a/src/pal/tests/palsuite/locale_info/CompareStringW/test1/test1.c b/src/pal/tests/palsuite/locale_info/CompareStringW/test1/test1.c deleted file mode 100644 index bdf2c3dcf3..0000000000 --- a/src/pal/tests/palsuite/locale_info/CompareStringW/test1/test1.c +++ /dev/null @@ -1,99 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that CompareStringW returns the correct value and can handle -** invalid parameters. -** -** -**==========================================================================*/ - -#define CSTR_LESS_THAN 1 -#define CSTR_EQUAL 2 -#define CSTR_GREATER_THAN 3 - -#include - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR str1[] = {'f','o','o',0}; - WCHAR str2[] = {'f','o','o','x',0}; - WCHAR str3[] = {'f','O','o',0}; - int flags = NORM_IGNORECASE | NORM_IGNOREWIDTH; - int ret; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - ret = CompareStringW(0x0409, flags, str1, -1, str2, -1); - if (ret != CSTR_LESS_THAN) - { - Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_LESS_THAN!\n", str1, -1, str2, -1); - } - - ret = CompareStringW(0x0409, flags, str1, -1, str2, 3); - if (ret != CSTR_EQUAL) - { - Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_EQUAL!\n", str1, -1, str2, 3); - } - - ret = CompareStringW(0x0409, flags, str2, -1, str1, -1); - if (ret != CSTR_GREATER_THAN) - { - Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_GREATER_THAN!\n", str2, -1, str1, -1); - } - - ret = CompareStringW(0x0409, flags, str1, -1, str3, -1); - if (ret != CSTR_EQUAL) - { - Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_EQUAL!\n", str1, -1, str3, -1); - } - - ret = CompareStringW(0x0409, flags, str3, -1, str1, -1); - if (ret != CSTR_EQUAL) - { - Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_EQUAL!\n", str3, -1, str1, -1); - } - - ret = CompareStringW(0x0409, flags, str3, -1, str1, -1); - if (ret != CSTR_EQUAL) - { - Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_EQUAL!\n", str3, -1, str1, -1); - } - - ret = CompareStringW(0x0409, flags, str1, 0, str3, -1); - if (ret != CSTR_LESS_THAN) - { - Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " - "CSTR_GREATER_THAN!\n", str1, 0, str3, -1); - } - - - ret = CompareStringW(0x0409, flags, NULL, -1, str3, -1); - if (ret != 0) - { - Fail("CompareStringW should have returned 0, got %d!\n", ret); - } - if (GetLastError() != ERROR_INVALID_PARAMETER) - { - Fail("CompareStringW should have set the last error to " - "ERROR_INVALID_PARAMETER!\n"); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/CompareStringW/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/CompareStringW/test1/test1.cpp new file mode 100644 index 0000000000..bdf2c3dcf3 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/CompareStringW/test1/test1.cpp @@ -0,0 +1,99 @@ +// 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: test1.c +** +** Purpose: Tests that CompareStringW returns the correct value and can handle +** invalid parameters. +** +** +**==========================================================================*/ + +#define CSTR_LESS_THAN 1 +#define CSTR_EQUAL 2 +#define CSTR_GREATER_THAN 3 + +#include + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR str1[] = {'f','o','o',0}; + WCHAR str2[] = {'f','o','o','x',0}; + WCHAR str3[] = {'f','O','o',0}; + int flags = NORM_IGNORECASE | NORM_IGNOREWIDTH; + int ret; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + ret = CompareStringW(0x0409, flags, str1, -1, str2, -1); + if (ret != CSTR_LESS_THAN) + { + Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_LESS_THAN!\n", str1, -1, str2, -1); + } + + ret = CompareStringW(0x0409, flags, str1, -1, str2, 3); + if (ret != CSTR_EQUAL) + { + Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_EQUAL!\n", str1, -1, str2, 3); + } + + ret = CompareStringW(0x0409, flags, str2, -1, str1, -1); + if (ret != CSTR_GREATER_THAN) + { + Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_GREATER_THAN!\n", str2, -1, str1, -1); + } + + ret = CompareStringW(0x0409, flags, str1, -1, str3, -1); + if (ret != CSTR_EQUAL) + { + Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_EQUAL!\n", str1, -1, str3, -1); + } + + ret = CompareStringW(0x0409, flags, str3, -1, str1, -1); + if (ret != CSTR_EQUAL) + { + Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_EQUAL!\n", str3, -1, str1, -1); + } + + ret = CompareStringW(0x0409, flags, str3, -1, str1, -1); + if (ret != CSTR_EQUAL) + { + Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_EQUAL!\n", str3, -1, str1, -1); + } + + ret = CompareStringW(0x0409, flags, str1, 0, str3, -1); + if (ret != CSTR_LESS_THAN) + { + Fail("CompareStringW with \"%S\" (%d) and \"%S\" (%d) did not return " + "CSTR_GREATER_THAN!\n", str1, 0, str3, -1); + } + + + ret = CompareStringW(0x0409, flags, NULL, -1, str3, -1); + if (ret != 0) + { + Fail("CompareStringW should have returned 0, got %d!\n", ret); + } + if (GetLastError() != ERROR_INVALID_PARAMETER) + { + Fail("CompareStringW should have set the last error to " + "ERROR_INVALID_PARAMETER!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/GetACP/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/GetACP/test1/CMakeLists.txt index c5513da2c1..cf4431ea94 100644 --- a/src/pal/tests/palsuite/locale_info/GetACP/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/GetACP/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getacp_test1 diff --git a/src/pal/tests/palsuite/locale_info/GetACP/test1/test1.c b/src/pal/tests/palsuite/locale_info/GetACP/test1/test1.c deleted file mode 100644 index 8ea078ee69..0000000000 --- a/src/pal/tests/palsuite/locale_info/GetACP/test1/test1.c +++ /dev/null @@ -1,42 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that GetACP returns the expected default code page. -** -** -**==========================================================================*/ - - -#include - -/* - * NOTE: We only support code page 65001 (UTF-8). - */ - -#define EXPECTED_CP 65001 - -int __cdecl main(int argc, char *argv[]) -{ - int ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - ret = GetACP(); - if (ret != EXPECTED_CP) - { - Fail("ERROR: got incorrect result for current ANSI code page!\n" - "Expected %d, got %d\n", EXPECTED_CP, ret); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/GetACP/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/GetACP/test1/test1.cpp new file mode 100644 index 0000000000..8ea078ee69 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/GetACP/test1/test1.cpp @@ -0,0 +1,42 @@ +// 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: test1.c +** +** Purpose: Tests that GetACP returns the expected default code page. +** +** +**==========================================================================*/ + + +#include + +/* + * NOTE: We only support code page 65001 (UTF-8). + */ + +#define EXPECTED_CP 65001 + +int __cdecl main(int argc, char *argv[]) +{ + int ret; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + ret = GetACP(); + if (ret != EXPECTED_CP) + { + Fail("ERROR: got incorrect result for current ANSI code page!\n" + "Expected %d, got %d\n", EXPECTED_CP, ret); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/CMakeLists.txt index c209b121b2..b4cf017c2b 100644 --- a/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getcpinfo_test1 diff --git a/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.c b/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.c deleted file mode 100644 index ed9bbf93fc..0000000000 --- a/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that GetCPInfo works for CP_ACP and 0x4E4 (default codepage) -** Also makes sure it correctly handles an invalid code page. -** -** -**==========================================================================*/ - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - CPINFO cpinfo; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - if (!GetCPInfo(CP_ACP, &cpinfo)) - { - Fail("GetCPInfo() unable to get info for CP_ACP\n"); - } - - if (!GetCPInfo(65001, &cpinfo)) - { - Fail("GetCPInfo() unable to get info for code page 65001 (utf8)\n"); - } - - if (GetCPInfo(-1, &cpinfo)) - { - Fail("GetCPInfo() did not error on invalid code page!\n"); - } - - if (GetLastError() != ERROR_INVALID_PARAMETER) - { - Fail("GetCPInfo() failed to set the last error to" - " ERROR_INVALID_PARAMETER!\n"); - } - - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.cpp new file mode 100644 index 0000000000..ed9bbf93fc --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/GetCPInfo/test1/test1.cpp @@ -0,0 +1,54 @@ +// 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: test1.c +** +** Purpose: Tests that GetCPInfo works for CP_ACP and 0x4E4 (default codepage) +** Also makes sure it correctly handles an invalid code page. +** +** +**==========================================================================*/ + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + CPINFO cpinfo; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + if (!GetCPInfo(CP_ACP, &cpinfo)) + { + Fail("GetCPInfo() unable to get info for CP_ACP\n"); + } + + if (!GetCPInfo(65001, &cpinfo)) + { + Fail("GetCPInfo() unable to get info for code page 65001 (utf8)\n"); + } + + if (GetCPInfo(-1, &cpinfo)) + { + Fail("GetCPInfo() did not error on invalid code page!\n"); + } + + if (GetLastError() != ERROR_INVALID_PARAMETER) + { + Fail("GetCPInfo() failed to set the last error to" + " ERROR_INVALID_PARAMETER!\n"); + } + + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/CMakeLists.txt index 6132e9b3fa..b366f3ce8d 100644 --- a/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_getcpinfo_test2 diff --git a/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/test2.c b/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/test2.c deleted file mode 100644 index f52320f167..0000000000 --- a/src/pal/tests/palsuite/locale_info/GetCPInfo/test2/test2.c +++ /dev/null @@ -1,60 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests that GetCPInfo gives the correct information for codepage 0x4E4 -** (the default). -** -** -**==========================================================================*/ - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - CPINFO cpinfo; - int codepage; - unsigned int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* - * codepage 1252 (0x4E4): Windows 3.1 Latin 1 (U.S., Western Europe) - */ - codepage = 1252; - - if (!GetCPInfo(codepage, &cpinfo)) - { - Fail("GetCPInfo() failed on default ansi code page!\n"); - } - if (cpinfo.MaxCharSize != 1) - { - Fail("GetCPInfo() returned incorrect MaxCharSize information!\n"); - } - if (cpinfo.DefaultChar[0] != '?' || cpinfo.DefaultChar[1] != 0) - { - Fail("GetCPInfo() returned incorrect DefaultChar information"); - } - - for (i = 0; i + + +int __cdecl main(int argc, char *argv[]) +{ + CPINFO cpinfo; + int codepage; + unsigned int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* + * codepage 1252 (0x4E4): Windows 3.1 Latin 1 (U.S., Western Europe) + */ + codepage = 1252; + + if (!GetCPInfo(codepage, &cpinfo)) + { + Fail("GetCPInfo() failed on default ansi code page!\n"); + } + if (cpinfo.MaxCharSize != 1) + { + Fail("GetCPInfo() returned incorrect MaxCharSize information!\n"); + } + if (cpinfo.DefaultChar[0] != '?' || cpinfo.DefaultChar[1] != 0) + { + Fail("GetCPInfo() returned incorrect DefaultChar information"); + } + + for (i = 0; i - -/* Currently only one CodePage "CP_ACP" is supported by the PAL */ - -int __cdecl main(int argc, char *argv[]) -{ - CPINFO cpinfo; - - /* Initialize the PAL. - */ - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Test GetCPInfo with CP_ACP. - */ - if (!GetCPInfo(CP_ACP, &cpinfo)) - { - Fail("GetCPInfo() unable to get info for code page %d!\n", CP_ACP); - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/GetCPInfo/test3/test3.cpp b/src/pal/tests/palsuite/locale_info/GetCPInfo/test3/test3.cpp new file mode 100644 index 0000000000..aa9df935b8 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/GetCPInfo/test3/test3.cpp @@ -0,0 +1,41 @@ +// 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: test3.c +** +** Purpose: Test that passes CP_ACP to GetCPInfo, verifying the results. +** +** +**==========================================================================*/ + +#include + +/* Currently only one CodePage "CP_ACP" is supported by the PAL */ + +int __cdecl main(int argc, char *argv[]) +{ + CPINFO cpinfo; + + /* Initialize the PAL. + */ + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Test GetCPInfo with CP_ACP. + */ + if (!GetCPInfo(CP_ACP, &cpinfo)) + { + Fail("GetCPInfo() unable to get info for code page %d!\n", CP_ACP); + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test1/CMakeLists.txt index f373b98f7c..4f685cb8a4 100644 --- a/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getlocaleinfow_test1 diff --git a/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test1/test1.c b/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test1/test1.c deleted file mode 100644 index 0994940a57..0000000000 --- a/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test1/test1.c +++ /dev/null @@ -1,89 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that GetLocaleInfoW gives the correction information for -** LOCALE_NEUTRAL. -** -** -**==========================================================================*/ - -#include - - -int Types[] = { LOCALE_SDECIMAL, LOCALE_STHOUSAND, LOCALE_ILZERO, - LOCALE_SCURRENCY, LOCALE_SMONDECIMALSEP, LOCALE_SMONTHOUSANDSEP }; - -char *TypeStrings[] = { "LOCALE_SDECIMAL", "LOCALE_STHOUSAND", "LOCALE_ILZERO", - "LOCALE_SCURRENCY", "LOCALE_SMONDECIMALSEP", "LOCALE_SMONTHOUSANDSEP" }; - -#define NUM_TYPES (sizeof(Types) / sizeof(Types[0])) - -typedef WCHAR InfoStrings[NUM_TYPES][4]; - -typedef struct -{ - LCID lcid; - InfoStrings Strings; -} LocalInfoType; - -LocalInfoType Locales[] = -{ - {LOCALE_NEUTRAL, - {{'.',0}, {',',0}, {'1',0}, {'$',0}, {'.',0}, {',',0}}}, -}; - -int NumLocales = sizeof(Locales) / sizeof(Locales[0]); - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR buffer[256] = { 0 }; - int ret; - int i,j; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i + + +int Types[] = { LOCALE_SDECIMAL, LOCALE_STHOUSAND, LOCALE_ILZERO, + LOCALE_SCURRENCY, LOCALE_SMONDECIMALSEP, LOCALE_SMONTHOUSANDSEP }; + +char *TypeStrings[] = { "LOCALE_SDECIMAL", "LOCALE_STHOUSAND", "LOCALE_ILZERO", + "LOCALE_SCURRENCY", "LOCALE_SMONDECIMALSEP", "LOCALE_SMONTHOUSANDSEP" }; + +#define NUM_TYPES (sizeof(Types) / sizeof(Types[0])) + +typedef WCHAR InfoStrings[NUM_TYPES][4]; + +typedef struct +{ + LCID lcid; + InfoStrings Strings; +} LocalInfoType; + +LocalInfoType Locales[] = +{ + {LOCALE_NEUTRAL, + {{'.',0}, {',',0}, {'1',0}, {'$',0}, {'.',0}, {',',0}}}, +}; + +int NumLocales = sizeof(Locales) / sizeof(Locales[0]); + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR buffer[256] = { 0 }; + int ret; + int i,j; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR buffer[256] = { 0 }; - int ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - ret = GetLocaleInfoW(LOCALE_NEUTRAL, LOCALE_SDECIMAL, buffer, 0); - if (ret != 2) - { - Fail("GetLocaleInfoW gave incorrect desired length for buffer.\n" - "Expected 2, got %d.\n", ret); - } - - ret = GetLocaleInfoW(LOCALE_NEUTRAL, LOCALE_SDECIMAL, buffer, 1); - if (ret != 0) - { - Fail("GetLocaleInfoW expected to return 0, returned %d", ret); - } - - if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) - { - Fail("GetLocaleInfoW failed to set last error to " - "ERROR_INSUFFICIENT_BUFFER!\n"); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test2/test2.cpp b/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test2/test2.cpp new file mode 100644 index 0000000000..f00fa79c59 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/GetLocaleInfoW/test2/test2.cpp @@ -0,0 +1,51 @@ +// 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: test2.c +** +** Purpose: Tests that GetLocaleInfoW will correctly return the amount of +** buffer space required. Also tests that it correctly handles a +** buffer of insufficient space. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR buffer[256] = { 0 }; + int ret; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + ret = GetLocaleInfoW(LOCALE_NEUTRAL, LOCALE_SDECIMAL, buffer, 0); + if (ret != 2) + { + Fail("GetLocaleInfoW gave incorrect desired length for buffer.\n" + "Expected 2, got %d.\n", ret); + } + + ret = GetLocaleInfoW(LOCALE_NEUTRAL, LOCALE_SDECIMAL, buffer, 1); + if (ret != 0) + { + Fail("GetLocaleInfoW expected to return 0, returned %d", ret); + } + + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) + { + Fail("GetLocaleInfoW failed to set last error to " + "ERROR_INSUFFICIENT_BUFFER!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/GetStringTypeExW/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/GetStringTypeExW/test1/CMakeLists.txt index 5bb7b8c8b5..e68621681a 100644 --- a/src/pal/tests/palsuite/locale_info/GetStringTypeExW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/GetStringTypeExW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getstringtypeexw_test1 diff --git a/src/pal/tests/palsuite/locale_info/GetStringTypeExW/test1/test1.c b/src/pal/tests/palsuite/locale_info/GetStringTypeExW/test1/test1.c deleted file mode 100644 index e15c3d66cd..0000000000 --- a/src/pal/tests/palsuite/locale_info/GetStringTypeExW/test1/test1.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests GetStringTypeExW with values that will ensure all possible -** flags get set once. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR wideStr[] = {'9',' '}; - WORD values1[] = { C1_DIGIT, C1_SPACE }; - int len = 2; - WORD Info[256]; - BOOL ret; - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR wideStr[] = {'9',' '}; + WORD values1[] = { C1_DIGIT, C1_SPACE }; + int len = 2; + WORD Info[256]; + BOOL ret; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i - - -/* - * A random selection of unicode characters, each representing a distinct - * unicode category - */ -WCHAR TestStr[] = -{ - 0x05D0, /* 4, HEBREW LETTER ALEF */ - 0x0488, /* 7, COMBINING CYRILLIC HUNDRED THOUSANDS SIGN */ - 0x0030, /* 8, DIGIT ZERO */ - 0x0020, /* 22, SPACE */ -}; - -#define TEST_LEN (sizeof(TestStr) / sizeof(WCHAR)) - -WORD TestFlags[TEST_LEN] = -{ - C1_ALPHA, - 0, - C1_DIGIT, - C1_BLANK|C1_SPACE -}; - -int __cdecl main(int argc, char *argv[]) -{ - WORD Info; - BOOL ret; - int i; - - /* check only the bits listed in rotor_pal.doc */ - const WORD PAL_VALID_C1_BITS = C1_DIGIT | C1_SPACE; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i + + +/* + * A random selection of unicode characters, each representing a distinct + * unicode category + */ +WCHAR TestStr[] = +{ + 0x05D0, /* 4, HEBREW LETTER ALEF */ + 0x0488, /* 7, COMBINING CYRILLIC HUNDRED THOUSANDS SIGN */ + 0x0030, /* 8, DIGIT ZERO */ + 0x0020, /* 22, SPACE */ +}; + +#define TEST_LEN (sizeof(TestStr) / sizeof(WCHAR)) + +WORD TestFlags[TEST_LEN] = +{ + C1_ALPHA, + 0, + C1_DIGIT, + C1_BLANK|C1_SPACE +}; + +int __cdecl main(int argc, char *argv[]) +{ + WORD Info; + BOOL ret; + int i; + + /* check only the bits listed in rotor_pal.doc */ + const WORD PAL_VALID_C1_BITS = C1_DIGIT | C1_SPACE; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i - -int __cdecl main(int argc, char *argv[]) -{ - - LCID lcid; - LANGID LangID; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - LangID = GetSystemDefaultLangID(); - if (LangID == 0) - { - Fail("GetSystemDefaultLangID failed!\n"); - } - - /* Try using the langid (with default sort) as a locale */ - if (!SetThreadLocale(MAKELCID(LangID, SORT_DEFAULT))) - { - Fail("Unable to use GetSystemDefaultLangID as a locale!\n"); - } - lcid = GetThreadLocale(); - if (!IsValidLocale(lcid, LCID_INSTALLED)) - { - Fail("Unable to use GetSystemDefaultLangID as a locale!\n"); - } - - /* Make sure results consistent with using LOCALE_USER_DEFAULT */ - if (!SetThreadLocale(LOCALE_USER_DEFAULT)) - { - Fail("Unexpected error testing GetSystemDefaultLangID!\n"); - } - if (GetThreadLocale() != lcid) - { - Fail("Results from GetSystemDefaultLangID inconsistent with " - "LOCALE_USER_DEFAULT!\n"); - } - - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/locale_info/GetSystemDefaultLangID/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/GetSystemDefaultLangID/test1/test1.cpp new file mode 100644 index 0000000000..1bc5120815 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/GetSystemDefaultLangID/test1/test1.cpp @@ -0,0 +1,59 @@ +// 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: test1.c +** +** Purpose: Checks that GetSystemDefaultLangID can be used to make a valid +** locale, and that it is consistent with LOCALE_USER_DEFAULT. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + LCID lcid; + LANGID LangID; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + LangID = GetSystemDefaultLangID(); + if (LangID == 0) + { + Fail("GetSystemDefaultLangID failed!\n"); + } + + /* Try using the langid (with default sort) as a locale */ + if (!SetThreadLocale(MAKELCID(LangID, SORT_DEFAULT))) + { + Fail("Unable to use GetSystemDefaultLangID as a locale!\n"); + } + lcid = GetThreadLocale(); + if (!IsValidLocale(lcid, LCID_INSTALLED)) + { + Fail("Unable to use GetSystemDefaultLangID as a locale!\n"); + } + + /* Make sure results consistent with using LOCALE_USER_DEFAULT */ + if (!SetThreadLocale(LOCALE_USER_DEFAULT)) + { + Fail("Unexpected error testing GetSystemDefaultLangID!\n"); + } + if (GetThreadLocale() != lcid) + { + Fail("Results from GetSystemDefaultLangID inconsistent with " + "LOCALE_USER_DEFAULT!\n"); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/CMakeLists.txt index 8cec9d8306..8abbd822c2 100644 --- a/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getthreadlocale_test1 diff --git a/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/test1.c b/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/test1.c deleted file mode 100644 index 8eb7252e37..0000000000 --- a/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/test1.c +++ /dev/null @@ -1,36 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that GetThreadLocale returns a valid locale. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - LCID lcid; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - lcid = GetThreadLocale(); - - if (!IsValidLocale(lcid, LCID_INSTALLED)) - { - Fail("GetThreadLocale returned a locale that is not installed!\n"); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/test1.cpp new file mode 100644 index 0000000000..8eb7252e37 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/GetThreadLocale/test1/test1.cpp @@ -0,0 +1,36 @@ +// 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: test1.c +** +** Purpose: Tests that GetThreadLocale returns a valid locale. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + LCID lcid; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + lcid = GetThreadLocale(); + + if (!IsValidLocale(lcid, LCID_INSTALLED)) + { + Fail("GetThreadLocale returned a locale that is not installed!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/CMakeLists.txt index 281f3bf9c3..8bf0a6ca23 100644 --- a/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_gettimezoneinformation_test1 diff --git a/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/test1.c b/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/test1.c deleted file mode 100644 index bb83ade231..0000000000 --- a/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/test1.c +++ /dev/null @@ -1,73 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that GetTimeZoneInformation gives reasonable values. -** -** -**==========================================================================*/ - - -#include - -int __cdecl main(int argc, char *argv[]) -{ - TIME_ZONE_INFORMATION tzi; - DWORD ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - ret = GetTimeZoneInformation(&tzi); - if (ret == TIME_ZONE_ID_UNKNOWN) - { - /* Occurs in time zones that do not use daylight savings time. */ - if (tzi.StandardBias != 0) - { - Fail("GetTimeZoneInformation() gave invalid data!\n" - "Returned TIME_ZONE_ID_UNKNOWN but StandardBias != 0!\n"); - } - if (tzi.DaylightBias != 0) - { - Fail("GetTimeZoneInformation() gave invalid data!\n" - "Returned TIME_ZONE_ID_UNKNOWN but DaylightBias != 0!\n"); - } - } - else if (ret == TIME_ZONE_ID_STANDARD) - { - if (tzi.StandardBias != 0) - { - Fail("GetTimeZoneInformation() gave invalid data!\n" - "StandardBias is %d, should be 0!\n", tzi.StandardBias); - } - } - else if (ret == TIME_ZONE_ID_DAYLIGHT) - { - if (tzi.DaylightBias != -60 && tzi.DaylightBias != 0) - { - Fail("GetTimeZoneInformation() gave invalid data!\n" - "DaylightBias is %d, should be 0 or -60!\n", tzi.DaylightBias); - } - } - else - { - Fail("GetTimeZoneInformation() returned an invalid value!\n"); - } - - if (tzi.Bias % 30 != 0) - { - Fail("GetTimeZoneInformation() gave an invalid bias of %d!\n", - tzi.Bias); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/test1.cpp new file mode 100644 index 0000000000..bb83ade231 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/GetTimeZoneInformation/test1/test1.cpp @@ -0,0 +1,73 @@ +// 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: test1.c +** +** Purpose: Tests that GetTimeZoneInformation gives reasonable values. +** +** +**==========================================================================*/ + + +#include + +int __cdecl main(int argc, char *argv[]) +{ + TIME_ZONE_INFORMATION tzi; + DWORD ret; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + ret = GetTimeZoneInformation(&tzi); + if (ret == TIME_ZONE_ID_UNKNOWN) + { + /* Occurs in time zones that do not use daylight savings time. */ + if (tzi.StandardBias != 0) + { + Fail("GetTimeZoneInformation() gave invalid data!\n" + "Returned TIME_ZONE_ID_UNKNOWN but StandardBias != 0!\n"); + } + if (tzi.DaylightBias != 0) + { + Fail("GetTimeZoneInformation() gave invalid data!\n" + "Returned TIME_ZONE_ID_UNKNOWN but DaylightBias != 0!\n"); + } + } + else if (ret == TIME_ZONE_ID_STANDARD) + { + if (tzi.StandardBias != 0) + { + Fail("GetTimeZoneInformation() gave invalid data!\n" + "StandardBias is %d, should be 0!\n", tzi.StandardBias); + } + } + else if (ret == TIME_ZONE_ID_DAYLIGHT) + { + if (tzi.DaylightBias != -60 && tzi.DaylightBias != 0) + { + Fail("GetTimeZoneInformation() gave invalid data!\n" + "DaylightBias is %d, should be 0 or -60!\n", tzi.DaylightBias); + } + } + else + { + Fail("GetTimeZoneInformation() returned an invalid value!\n"); + } + + if (tzi.Bias % 30 != 0) + { + Fail("GetTimeZoneInformation() gave an invalid bias of %d!\n", + tzi.Bias); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/CMakeLists.txt index e039d46ccd..b6f08b1f7d 100644 --- a/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getuserdefaultlcid_test1 diff --git a/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/test1.c b/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/test1.c deleted file mode 100644 index 4a336f9bb7..0000000000 --- a/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/test1.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that GetUserDefaultLCID returns a valid locale that is -** consistent with LOCALE_USER_DEFAULT. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - LCID lcid; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - lcid = GetUserDefaultLCID(); - if (lcid == 0) - { - Fail("GetUserDefaultLCID failed!\n"); - } - - if (!IsValidLocale(lcid, LCID_INSTALLED)) - { - Fail("GetUserDefaultLCID gave an invalid locale!\n"); - } - - /* Make sure results consistent with using LOCALE_USER_DEFAULT */ - if (!SetThreadLocale(LOCALE_USER_DEFAULT)) - { - Fail("Unexpected error testing GetUserDefaultLCID!\n"); - } - if (GetThreadLocale() != lcid) - { - Fail("Results from GetUserDefaultLCID inconsistent with " - "LOCALE_USER_DEFAULT!\n"); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/test1.cpp new file mode 100644 index 0000000000..4a336f9bb7 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/GetUserDefaultLCID/test1/test1.cpp @@ -0,0 +1,52 @@ +// 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: test1.c +** +** Purpose: Tests that GetUserDefaultLCID returns a valid locale that is +** consistent with LOCALE_USER_DEFAULT. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + LCID lcid; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + lcid = GetUserDefaultLCID(); + if (lcid == 0) + { + Fail("GetUserDefaultLCID failed!\n"); + } + + if (!IsValidLocale(lcid, LCID_INSTALLED)) + { + Fail("GetUserDefaultLCID gave an invalid locale!\n"); + } + + /* Make sure results consistent with using LOCALE_USER_DEFAULT */ + if (!SetThreadLocale(LOCALE_USER_DEFAULT)) + { + Fail("Unexpected error testing GetUserDefaultLCID!\n"); + } + if (GetThreadLocale() != lcid) + { + Fail("Results from GetUserDefaultLCID inconsistent with " + "LOCALE_USER_DEFAULT!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/CMakeLists.txt index 71fa0464bb..8fc795a52b 100644 --- a/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getuserdefaultlangid_test1 diff --git a/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/test1.c b/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/test1.c deleted file mode 100644 index 51c5678086..0000000000 --- a/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/test1.c +++ /dev/null @@ -1,60 +0,0 @@ -// 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: test1.c -** -** Purpose: Checks that GetUserDefaultLangID can be used to make a valid -** locale, and that it is consistent with LOCALE_USER_DEFAULT. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - LCID lcid; - LANGID LangID; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - LangID = GetUserDefaultLangID(); - if (LangID == 0) - { - Fail("GetUserDefaultLangID failed!\n"); - } - - /* Try using the langid (with default sort) as a locale */ - if (!SetThreadLocale(MAKELCID(LangID, SORT_DEFAULT))) - { - Fail("Unable to use GetUserDefaultLangID as a locale!\n"); - } - lcid = GetThreadLocale(); - if (!IsValidLocale(lcid, LCID_INSTALLED)) - { - Fail("Unable to use GetUserDefaultLangID as a locale!\n"); - } - - /* Make sure results consistent with using LOCALE_USER_DEFAULT */ - if (!SetThreadLocale(LOCALE_USER_DEFAULT)) - { - Fail("Unexpected error testing GetUserDefaultLangID!\n"); - } - if (GetThreadLocale() != lcid) - { - Fail("Results from GetUserDefaultLangID inconsistent with " - "LOCALE_USER_DEFAULT!\n"); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/test1.cpp new file mode 100644 index 0000000000..51c5678086 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/GetUserDefaultLangID/test1/test1.cpp @@ -0,0 +1,60 @@ +// 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: test1.c +** +** Purpose: Checks that GetUserDefaultLangID can be used to make a valid +** locale, and that it is consistent with LOCALE_USER_DEFAULT. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + LCID lcid; + LANGID LangID; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + LangID = GetUserDefaultLangID(); + if (LangID == 0) + { + Fail("GetUserDefaultLangID failed!\n"); + } + + /* Try using the langid (with default sort) as a locale */ + if (!SetThreadLocale(MAKELCID(LangID, SORT_DEFAULT))) + { + Fail("Unable to use GetUserDefaultLangID as a locale!\n"); + } + lcid = GetThreadLocale(); + if (!IsValidLocale(lcid, LCID_INSTALLED)) + { + Fail("Unable to use GetUserDefaultLangID as a locale!\n"); + } + + /* Make sure results consistent with using LOCALE_USER_DEFAULT */ + if (!SetThreadLocale(LOCALE_USER_DEFAULT)) + { + Fail("Unexpected error testing GetUserDefaultLangID!\n"); + } + if (GetThreadLocale() != lcid) + { + Fail("Results from GetUserDefaultLangID inconsistent with " + "LOCALE_USER_DEFAULT!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/CMakeLists.txt index ad5ad7508d..e9b22dcfc5 100644 --- a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isdbcsleadbyte_test1 diff --git a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.c b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.c deleted file mode 100644 index ad326be084..0000000000 --- a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.c +++ /dev/null @@ -1,64 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that IsDBCSLeadByte does not find any lead-bytes in the -** current ansi code page -** -** -** TODO: Test for positive, i.e., if it is potentially isdbcsleadbyte -**==========================================================================*/ - - -#include - -void DoTest() -{ - int value; - int ret; - int i; - - - for (i=0; i<256; i++) - { - value = IsDBCSLeadByte(i); - - ret = GetLastError(); - if (ret == ERROR_INVALID_PARAMETER) - { - Fail("IsDBCSLeadByte unexpectedly errored with ERROR_INVALID_PARAMETER for %d!\n", i); - } - else if (ret != 0) - { - Fail("IsDBCSLeadByte had an unexpected error [%d] for %d!\n", ret, i); - } - else if (value) - { - Fail("IsDBCSLeadByte incorrectly found a lead byte in value [%d] for" - " %d\n", value, i); - } - - } -} - -int __cdecl main(int argc, char *argv[]) -{ - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - DoTest(); - - PAL_Terminate(); - -// setlocale( "japan", ); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.cpp new file mode 100644 index 0000000000..ad326be084 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByte/test1/test1.cpp @@ -0,0 +1,64 @@ +// 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: test1.c +** +** Purpose: Tests that IsDBCSLeadByte does not find any lead-bytes in the +** current ansi code page +** +** +** TODO: Test for positive, i.e., if it is potentially isdbcsleadbyte +**==========================================================================*/ + + +#include + +void DoTest() +{ + int value; + int ret; + int i; + + + for (i=0; i<256; i++) + { + value = IsDBCSLeadByte(i); + + ret = GetLastError(); + if (ret == ERROR_INVALID_PARAMETER) + { + Fail("IsDBCSLeadByte unexpectedly errored with ERROR_INVALID_PARAMETER for %d!\n", i); + } + else if (ret != 0) + { + Fail("IsDBCSLeadByte had an unexpected error [%d] for %d!\n", ret, i); + } + else if (value) + { + Fail("IsDBCSLeadByte incorrectly found a lead byte in value [%d] for" + " %d\n", value, i); + } + + } +} + +int __cdecl main(int argc, char *argv[]) +{ + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + DoTest(); + + PAL_Terminate(); + +// setlocale( "japan", ); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/CMakeLists.txt index 9d53ee9b3b..f3a232b143 100644 --- a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isdbcsleadbyteex_test1 diff --git a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.c b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.c deleted file mode 100644 index 9466f4817f..0000000000 --- a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.c +++ /dev/null @@ -1,72 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that IsDBCSLeadByteEx does not find any lead-bytes in the -** current ansi code page or the default code page. Also tests that -** it correctly handles an invalid codepage. -** -** -**==========================================================================*/ - - -#include - -void DoTest(int codepage) -{ - int value; - int ret; - int i; - - - for (i=0; i<256; i++) - { - value = IsDBCSLeadByteEx(codepage, i); - - ret = GetLastError(); - if (ret == ERROR_INVALID_PARAMETER) - { - Fail("IsDBCSLeadByteEx unexpectedly errored with ERROR_INVALID_PARAMETER!\n"); - } - else if (ret != 0) - { - Fail("IsDBCSLeadByteEx had an unexpected error!\n"); - } - else if (value) - { - Fail("IsDBCSLeadByteEx incorrectly found a lead byte in code " - "page %d\n", codepage); - } - - } -} - -int __cdecl main(int argc, char *argv[]) -{ - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - if (IsDBCSLeadByteEx(-1, 0)) - { - Fail("IsDBCSLeadByteEx did not error on an invalid code page!\n"); - } - - /* Clear the last error. */ - SetLastError(0); - - - DoTest(0); - DoTest(CP_ACP); - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.cpp new file mode 100644 index 0000000000..9466f4817f --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/IsDBCSLeadByteEx/test1/test1.cpp @@ -0,0 +1,72 @@ +// 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: test1.c +** +** Purpose: Tests that IsDBCSLeadByteEx does not find any lead-bytes in the +** current ansi code page or the default code page. Also tests that +** it correctly handles an invalid codepage. +** +** +**==========================================================================*/ + + +#include + +void DoTest(int codepage) +{ + int value; + int ret; + int i; + + + for (i=0; i<256; i++) + { + value = IsDBCSLeadByteEx(codepage, i); + + ret = GetLastError(); + if (ret == ERROR_INVALID_PARAMETER) + { + Fail("IsDBCSLeadByteEx unexpectedly errored with ERROR_INVALID_PARAMETER!\n"); + } + else if (ret != 0) + { + Fail("IsDBCSLeadByteEx had an unexpected error!\n"); + } + else if (value) + { + Fail("IsDBCSLeadByteEx incorrectly found a lead byte in code " + "page %d\n", codepage); + } + + } +} + +int __cdecl main(int argc, char *argv[]) +{ + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + if (IsDBCSLeadByteEx(-1, 0)) + { + Fail("IsDBCSLeadByteEx did not error on an invalid code page!\n"); + } + + /* Clear the last error. */ + SetLastError(0); + + + DoTest(0); + DoTest(CP_ACP); + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/IsValidCodePage/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/IsValidCodePage/test1/CMakeLists.txt index d87e8c0d6b..ae12b37950 100644 --- a/src/pal/tests/palsuite/locale_info/IsValidCodePage/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/IsValidCodePage/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isvalidcodepage_test1 diff --git a/src/pal/tests/palsuite/locale_info/IsValidCodePage/test1/test1.c b/src/pal/tests/palsuite/locale_info/IsValidCodePage/test1/test1.c deleted file mode 100644 index deb6a7ae72..0000000000 --- a/src/pal/tests/palsuite/locale_info/IsValidCodePage/test1/test1.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests IsValidCodePage with a collection of valid and invalid -** code pages. -** -** -**==========================================================================*/ - - -#include - - -UINT InvalidCodePages[] = -{ - 0, 0x1, 0x2, 0x3, 0xfff -}; - -int NumInvalidPages = sizeof(InvalidCodePages) / sizeof(InvalidCodePages[0]); - -int __cdecl main(int argc, char *argv[]) -{ - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - - for (i=0; i + + +UINT InvalidCodePages[] = +{ + 0, 0x1, 0x2, 0x3, 0xfff +}; + +int NumInvalidPages = sizeof(InvalidCodePages) / sizeof(InvalidCodePages[0]); + +int __cdecl main(int argc, char *argv[]) +{ + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + + for (i=0; i - -UINT ValidCodePages[] = -{ - 0x25, 0x1b5, 0x1f4, 0x352, 0x35c, 0x35d, 0x35f, 0x361, - 0x36a, 0x3a4, 0x3a8, 0x3b5, 0x3b6, 0x4e2, 0x4e3, 0x4e4, 0x4e5, 0x4e6, - 0x4e7, 0x4e8, 0x4e9, 0x4ea, 0x2710, 0x275f, 0x4e9f, 0x4f25, 0x5182, 0x6faf, - 0x6fb0, 0x6fbd, 0xfde8, 0xfde9 -}; - - -int NumValidPages = sizeof(ValidCodePages) / sizeof(ValidCodePages[0]); -int __cdecl main(int argc, char *argv[]) -{ - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i + +UINT ValidCodePages[] = +{ + 0x25, 0x1b5, 0x1f4, 0x352, 0x35c, 0x35d, 0x35f, 0x361, + 0x36a, 0x3a4, 0x3a8, 0x3b5, 0x3b6, 0x4e2, 0x4e3, 0x4e4, 0x4e5, 0x4e6, + 0x4e7, 0x4e8, 0x4e9, 0x4ea, 0x2710, 0x275f, 0x4e9f, 0x4f25, 0x5182, 0x6faf, + 0x6fb0, 0x6fbd, 0xfde8, 0xfde9 +}; + + +int NumValidPages = sizeof(ValidCodePages) / sizeof(ValidCodePages[0]); +int __cdecl main(int argc, char *argv[]) +{ + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i - - -int __cdecl main(int argc, char *argv[]) -{ - - LCID lcid; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* - * Passing LOCALE_USER_DEFAULT to IsValidLocale will fail, so instead - * the current thread localed is changed to it, and that lcid is passed - * to IsValidLocale (which should always pass) - */ - if (!SetThreadLocale(LOCALE_USER_DEFAULT)) - { - Fail("Unable to set locale to LOCALE_USER_DEFAULT!\n"); - } - - lcid = GetThreadLocale(); - - if (!IsValidLocale(lcid, LCID_SUPPORTED)) - { - Fail("IsValidLocale found the default user locale unsupported!\n"); - } - if (!IsValidLocale(lcid, LCID_INSTALLED)) - { - Fail("IsValidLocale found the default user locale uninstalled!\n"); - } - - /* - * Test out bad parameters - */ - if (IsValidLocale(-1, LCID_SUPPORTED)) - { - Fail("IsValideLocale passed with an invalid LCID!\n"); - } - if (IsValidLocale(-1, LCID_INSTALLED)) - { - Fail("IsValideLocale passed with an invalid LCID!\n"); - } - - if (IsValidLocale(LOCALE_USER_DEFAULT, LCID_SUPPORTED)) - { - Fail("IsValidLocale passed with LOCALE_USER_DEFAULT!\n"); - } - if (IsValidLocale(LOCALE_USER_DEFAULT, LCID_INSTALLED)) - { - Fail("IsValidLocale passed with LOCALE_USER_DEFAULT!\n"); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/IsValidLocale/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/IsValidLocale/test1/test1.cpp new file mode 100644 index 0000000000..4dd63653f5 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/IsValidLocale/test1/test1.cpp @@ -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: test1.c +** +** Purpose: Tests IsValidLocale with the current locale, -1, and +** LOCALE_USER_DEFAULT (which actually isn't valid). +** +** +**==========================================================================*/ + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + + LCID lcid; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* + * Passing LOCALE_USER_DEFAULT to IsValidLocale will fail, so instead + * the current thread localed is changed to it, and that lcid is passed + * to IsValidLocale (which should always pass) + */ + if (!SetThreadLocale(LOCALE_USER_DEFAULT)) + { + Fail("Unable to set locale to LOCALE_USER_DEFAULT!\n"); + } + + lcid = GetThreadLocale(); + + if (!IsValidLocale(lcid, LCID_SUPPORTED)) + { + Fail("IsValidLocale found the default user locale unsupported!\n"); + } + if (!IsValidLocale(lcid, LCID_INSTALLED)) + { + Fail("IsValidLocale found the default user locale uninstalled!\n"); + } + + /* + * Test out bad parameters + */ + if (IsValidLocale(-1, LCID_SUPPORTED)) + { + Fail("IsValideLocale passed with an invalid LCID!\n"); + } + if (IsValidLocale(-1, LCID_INSTALLED)) + { + Fail("IsValideLocale passed with an invalid LCID!\n"); + } + + if (IsValidLocale(LOCALE_USER_DEFAULT, LCID_SUPPORTED)) + { + Fail("IsValidLocale passed with LOCALE_USER_DEFAULT!\n"); + } + if (IsValidLocale(LOCALE_USER_DEFAULT, LCID_INSTALLED)) + { + Fail("IsValidLocale passed with LOCALE_USER_DEFAULT!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/CMakeLists.txt index 044c47712b..7bf79e36a7 100644 --- a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_multibytetowidechar_test1 diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.c b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.c deleted file mode 100644 index 81f58a532c..0000000000 --- a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.c +++ /dev/null @@ -1,81 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests MultiByteToWideChar with all the ASCII characters (0-127). -** Also tests that WideCharToMultiByte handles different buffer -** lengths correctly (0, -1, and a valid length) -** -** -**==========================================================================*/ - -#include - -/* - * For now, it is assumed that MultiByteToWideChar will only be used in the PAL - * with CP_ACP, and that dwFlags will be 0. - */ - -int __cdecl main(int argc, char *argv[]) -{ - char mbStr[128]; - WCHAR wideStr[128]; - int ret; - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i<128; i++) - { - mbStr[i] = 127 - i; - wideStr[i] = 0; - } - - - ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0); - if (ret != 128) - { - Fail("MultiByteToWideChar did not return correct string length!\n" - "Got %d, expected %d\n", ret, 128); - } - - /* Make sure the ASCII set (0-127) gets translated correctly */ - ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 128); - if (ret != 128) - { - Fail("MultiByteToWideChar did not return correct string length!\n" - "Got %d, expected %d\n", ret, 128); - } - - for (i=0; i<128; i++) - { - if (wideStr[i] != (WCHAR)(127 - i)) - { - Fail("MultiByteToWideChar failed to translate correctly!\n" - "Expected character %d to be %c (%x), got %c (%x)\n", - i, 127 - i, 127 - i,wideStr[i], wideStr[i]); - } - } - - - /* try a 0 length string */ - mbStr[0] = 0; - ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0); - if (ret != 1) - { - Fail("MultiByteToWideChar did not return correct string length!\n" - "Got %d, expected %d\n", ret, 1); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.cpp new file mode 100644 index 0000000000..81f58a532c --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.cpp @@ -0,0 +1,81 @@ +// 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: test1.c +** +** Purpose: Tests MultiByteToWideChar with all the ASCII characters (0-127). +** Also tests that WideCharToMultiByte handles different buffer +** lengths correctly (0, -1, and a valid length) +** +** +**==========================================================================*/ + +#include + +/* + * For now, it is assumed that MultiByteToWideChar will only be used in the PAL + * with CP_ACP, and that dwFlags will be 0. + */ + +int __cdecl main(int argc, char *argv[]) +{ + char mbStr[128]; + WCHAR wideStr[128]; + int ret; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i<128; i++) + { + mbStr[i] = 127 - i; + wideStr[i] = 0; + } + + + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0); + if (ret != 128) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 128); + } + + /* Make sure the ASCII set (0-127) gets translated correctly */ + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 128); + if (ret != 128) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 128); + } + + for (i=0; i<128; i++) + { + if (wideStr[i] != (WCHAR)(127 - i)) + { + Fail("MultiByteToWideChar failed to translate correctly!\n" + "Expected character %d to be %c (%x), got %c (%x)\n", + i, 127 - i, 127 - i,wideStr[i], wideStr[i]); + } + } + + + /* try a 0 length string */ + mbStr[0] = 0; + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0); + if (ret != 1) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 1); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/CMakeLists.txt index 0367d53938..b3e3f64c5c 100644 --- a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_multibytetowidechar_test2 diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.c b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.c deleted file mode 100644 index 1370dba894..0000000000 --- a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests that MultiByteToWideChar respects the length of the wide -** character string. - -** -**==========================================================================*/ - -#include - -/* - * For now, it is assumed that MultiByteToWideChar will only be used in the PAL - * with CP_ACP, and that dwFlags will be 0. - */ - -int __cdecl main(int argc, char *argv[]) -{ - char mbStr[128]; - WCHAR wideStr[128]; - int ret; - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i<128; i++) - { - mbStr[i] = 'a'; - wideStr[i] = 0; - } - - mbStr[127] = 0; - - - ret = MultiByteToWideChar(CP_ACP, 0, mbStr, 10, wideStr, 0); - if (ret != 10) - { - Fail("MultiByteToWideChar did not return correct string length!\n" - "Got %d, expected %d\n", ret, 10); - } - - wideStr[10] = (WCHAR) 'b'; - - ret = MultiByteToWideChar(CP_ACP, 0, mbStr, 10, wideStr, 128); - if (ret != 10) - { - Fail("MultiByteToWideChar did not return correct string length!\n" - "Got %d, expected %d\n", ret, 10); - } - - if (wideStr[10] != 'b') - { - Fail("WideCharToMultiByte overflowed the destination buffer!\n"); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.cpp b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.cpp new file mode 100644 index 0000000000..1370dba894 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.cpp @@ -0,0 +1,68 @@ +// 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: test2.c +** +** Purpose: Tests that MultiByteToWideChar respects the length of the wide +** character string. + +** +**==========================================================================*/ + +#include + +/* + * For now, it is assumed that MultiByteToWideChar will only be used in the PAL + * with CP_ACP, and that dwFlags will be 0. + */ + +int __cdecl main(int argc, char *argv[]) +{ + char mbStr[128]; + WCHAR wideStr[128]; + int ret; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i<128; i++) + { + mbStr[i] = 'a'; + wideStr[i] = 0; + } + + mbStr[127] = 0; + + + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, 10, wideStr, 0); + if (ret != 10) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 10); + } + + wideStr[10] = (WCHAR) 'b'; + + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, 10, wideStr, 128); + if (ret != 10) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 10); + } + + if (wideStr[10] != 'b') + { + Fail("WideCharToMultiByte overflowed the destination buffer!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/CMakeLists.txt index 57e3d66faf..c6eac9bd60 100644 --- a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_multibytetowidechar_test3 diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.c b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.c deleted file mode 100644 index 1b3a4bd4f5..0000000000 --- a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.c +++ /dev/null @@ -1,73 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests that MultiByteToWideChar correctly handles the following -** error conditions: insufficient buffer space, invalid code pages, -** and invalid flags. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char mbStr[128]; - WCHAR wideStr[128]; - int ret; - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - for (i=0; i<128; i++) - { - mbStr[i] = 'a'; - wideStr[i] = 0; - } - - mbStr[127] = 0; - - /* try with insufficient buffer space */ - ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 10); - if (ret != 0) - { - Fail("MultiByteToWideChar did not return an error!\n" - "Expected return of 0, got %d", ret); - } - - ret = GetLastError(); - if (ret != ERROR_INSUFFICIENT_BUFFER) - { - Fail("MultiByteToWideChar did not set the last error to " - "ERROR_INSUFFICIENT_BUFFER!\n"); - } - - /* try with a wacky code page */ - ret = MultiByteToWideChar(-1, 0, mbStr, -1, wideStr, 128); - if (ret != 0) - { - Fail("MultiByteToWideChar did not return an error!\n" - "Expected return of 0, got %d", ret); - } - - ret = GetLastError(); - if (ret != ERROR_INVALID_PARAMETER) - { - Fail("MultiByteToWideChar did not set the last error to " - "ERROR_INVALID_PARAMETER!\n"); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.cpp b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.cpp new file mode 100644 index 0000000000..1b3a4bd4f5 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.cpp @@ -0,0 +1,73 @@ +// 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: test3.c +** +** Purpose: Tests that MultiByteToWideChar correctly handles the following +** error conditions: insufficient buffer space, invalid code pages, +** and invalid flags. +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char mbStr[128]; + WCHAR wideStr[128]; + int ret; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i<128; i++) + { + mbStr[i] = 'a'; + wideStr[i] = 0; + } + + mbStr[127] = 0; + + /* try with insufficient buffer space */ + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 10); + if (ret != 0) + { + Fail("MultiByteToWideChar did not return an error!\n" + "Expected return of 0, got %d", ret); + } + + ret = GetLastError(); + if (ret != ERROR_INSUFFICIENT_BUFFER) + { + Fail("MultiByteToWideChar did not set the last error to " + "ERROR_INSUFFICIENT_BUFFER!\n"); + } + + /* try with a wacky code page */ + ret = MultiByteToWideChar(-1, 0, mbStr, -1, wideStr, 128); + if (ret != 0) + { + Fail("MultiByteToWideChar did not return an error!\n" + "Expected return of 0, got %d", ret); + } + + ret = GetLastError(); + if (ret != ERROR_INVALID_PARAMETER) + { + Fail("MultiByteToWideChar did not set the last error to " + "ERROR_INVALID_PARAMETER!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/CMakeLists.txt index 3d167dff7c..c9c92952f2 100644 --- a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_multibytetowidechar_test4 diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.c b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.c deleted file mode 100644 index 2ba606cf35..0000000000 --- a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.c +++ /dev/null @@ -1,230 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests MultiByteToWideChar with a UTF-8 encoding -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - int ret; - int ret2; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - const char * const utf8Strings[] = - { - // Correct strings - - // Empty string - "", - // 1 byte encoded 1 character long string - "A", - // 2 byte encoded 1 character long string - "\xC2\x80", - // 3 byte encoded 1 character long string - "\xE0\xA0\x80", - // 1 byte encoded characters only - "ABCDEFGHIJKLMNOPQRSTUVWXYZ", - // valid 2 byte encoded characters only - "\xC2\x80\xC3\xBF\xC7\x81\xDF\xBF", - // valid 3 byte encoded characters only - "\xE0\xA0\x80\xE1\xB6\x88\xE1\x80\x80\xEF\xBF\xBF", - // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char - "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", - // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one - "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", - // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one - "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", - // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char - "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", - // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char - "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", - // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one - "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", - // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one - "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", - // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char - "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", - // surrogates - "\xF0\x90\x80\x80\xF0\x90\x89\x80\xF3\x80\x8E\xB0\xF4\x8F\xBF\xBF", - - // Strings with errors - // Incomplete 2 byte encoded character 1 byte missing standalone - "\xC2", - // Incomplete 3 byte encoded character 1 byte missing standalone - "\xE0\xA0", - // Incomplete 3 byte encoded character 2 bytes missing standalone - "\xE0", - // Incomplete surrogate character 1 byte missing standalone - "\xF0\x90\x80", - // Incomplete surrogate character 2 bytes missing standalone - "\xF0\x90", - // Incomplete surrogate character 3 bytes missing standalone - "\xF0", - // Trailing byte with no lead byte standalone - "\x80", - // Incomplete 2 byte encoded character 1 byte missing between 1 byte chars - "\x41\xC2\x42", - // Incomplete 3 byte encoded character 1 byte missing between 1 byte chars - "\x41\xE0\xA0\x42", - // Incomplete 3 byte encoded character 2 bytes missing between 1 byte chars - "\x41\xE0\x42", - // Trailing byte with no lead byte between 1 byte chars - "\x41\x80\x42", - // Incomplete 2 byte encoded character 1 byte missing before 1 byte char - "\xC2\x42", - // Incomplete 3 byte encoded character 1 byte missing before 1 byte char - "\xE0\xA0\x42", - // Incomplete 3 byte encoded character 2 bytes missing before 1 byte char - "\xE0\x42", - // Trailing byte with no lead byte before 1 byte char - "\x80\x42", - // Incomplete 2 byte encoded character 1 byte missing after 1 byte char - "\x41\xC2", - // Incomplete 3 byte encoded character 1 byte missing after 1 byte char - "\x41\xE0\xA0", - // Incomplete 3 byte encoded character 2 bytes missing after 1 byte char - "\x41\xE0", - // Trailing byte with no lead byte after 1 byte char - "\x41\x80", - // Incomplete 2 byte encoded character 1 byte missing between 2 byte chars - "\xC2\x80\xC2\xC3\xBF", - // Incomplete 3 byte encoded character 1 byte missing between 2 byte chars - "\xC2\x80\xE0\xA0\xC3\xBF", - // Incomplete 3 byte encoded character 2 bytes missing between 2 byte chars - "\xC2\x80\xE0\xC3\xBF", - // Trailing byte with no lead byte between 2 byte chars - "\xC2\x80\x80\xC3\xBF", - // 2 byte encoded character in non-shortest form encodings (these are not allowed) - "\xC0\x80", - // 3 byte encoded character in non-shortest form encodings (these are not allowed) - "\xE0\x80\x80", - // 4 byte encoded character in non-shortest form encodings (these are not allowed) - "\xF0\x80\x80\x80", - }; - - const WCHAR * const unicodeStrings[] = - { - // Empty string - W(""), - // 1 byte encoded 1 character long string - W("A"), - // 2 byte encoded 1 character long string - W("\x0080"), - // 3 byte encoded 1 character long string - W("\x0800"), - // 1 byte encoded characters only - W("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), - // 2 byte encoded characters only - W("\x0080\x00FF\x01C1\x07FF"), - // valid 3 byte encoded characters only - W("\x0800\x1D88\x1000\xFFFF"), - // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char - W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), - // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one - W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), - // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one - W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), - // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char - W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), - // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char - W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), - // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one - W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF"), - // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one - W("\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), - // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char - W("\x0080\x00FF\x0043\x0044\x01C1\x07FF"), - // surrogates - W("\xD800\xDC00\xD800\xDE40\xDAC0\xDFB0\xDBFF\xDFFF"), - - // Strings with errors - // Incomplete 2 byte encoded character standalone - W(""), - // Incomplete 3 byte encoded character 1 byte missing standalone - W(""), - // Incomplete 3 byte encoded character 2 bytes missing standalone - W(""), - // Incomplete surrogate character 1 byte missing standalone - W(""), - // Incomplete surrogate character 2 bytes missing standalone - W(""), - // Incomplete surrogate character 3 bytes missing standalone - W(""), - // Trailing byte with no lead byte standalone - W(""), - // Incomplete 2 byte encoded character 1 byte missing between 1 byte chars - W("\x0041\x0042"), - // Incomplete 3 byte encoded character 1 byte missing between 1 byte chars - W("\x0041\x0042"), - // Incomplete 3 byte encoded character 2 bytes missing between 1 byte chars - W("\x0041\x0042"), - // Trailing byte with no lead byte between 1 byte chars - W("\x0041\x0042"), - // Incomplete 2 byte encoded character 1 byte missing before 1 byte char - W("\x0042"), - // Incomplete 3 byte encoded character 1 byte missing before 1 byte char - W("\x0042"), - // Incomplete 3 byte encoded character 2 bytes missing before 1 byte char - W("\x0042"), - // Trailing byte with no lead byte before 1 byte char - W("\x0042"), - // Incomplete 2 byte encoded character 1 byte missing after 1 byte char - W("\x0041"), - // Incomplete 3 byte encoded character 1 byte missing after 1 byte char - W("\x0041"), - // Incomplete 3 byte encoded character 2 bytes missing after 1 byte char - W("\x0041"), - // Trailing byte with no lead byte after 1 byte char - W("\x0041"), - // Incomplete 2 byte encoded character 1 byte missing between 2 byte chars - W("\x0080\x00FF"), - // Incomplete 3 byte encoded character 1 byte missing between 2 byte chars - W("\x0080\x00FF"), - // Incomplete 3 byte encoded character 2 bytes missing between 2 byte chars - W("\x0080\x00FF"), - // Trailing byte with no lead byte between 2 byte chars - W("\x0080\x00FF"), - // 2 byte encoded character in non-shortest form encodings (these are not allowed) - W(""), - // 3 byte encoded character in non-shortest form encodings (these are not allowed) - W(""), - // 4 byte encoded character in non-shortest form encodings (these are not allowed) - W(""), - }; - - for (int i = 0; i < (sizeof(utf8Strings) / sizeof(utf8Strings[0])); i++) - { - ret = MultiByteToWideChar(CP_UTF8, 0, utf8Strings[i], -1, NULL, 0); - WCHAR* wideBuffer = malloc(ret * sizeof(WCHAR)); - ret2 = MultiByteToWideChar(CP_UTF8, 0, utf8Strings[i], -1, wideBuffer, ret); - if (ret != ret2) - { - Fail("MultiByteToWideChar string %d: returned different string length for empty and real dest buffers!\n" - "Got %d for the empty one, %d for real one.\n", i, ret2, ret); - } - - if (wcscmp(wideBuffer, unicodeStrings[i]) != 0) - { - Fail("MultiByteToWideChar string %d: the resulting string doesn't match the expected one!\n", i); - } - - free(wideBuffer); - } - - PAL_Terminate(); - - return PASS; -} \ No newline at end of file diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.cpp b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.cpp new file mode 100644 index 0000000000..1d7234640b --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.cpp @@ -0,0 +1,230 @@ +// 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: test4.c +** +** Purpose: Tests MultiByteToWideChar with a UTF-8 encoding +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + int ret; + int ret2; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + const char * const utf8Strings[] = + { + // Correct strings + + // Empty string + "", + // 1 byte encoded 1 character long string + "A", + // 2 byte encoded 1 character long string + "\xC2\x80", + // 3 byte encoded 1 character long string + "\xE0\xA0\x80", + // 1 byte encoded characters only + "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + // valid 2 byte encoded characters only + "\xC2\x80\xC3\xBF\xC7\x81\xDF\xBF", + // valid 3 byte encoded characters only + "\xE0\xA0\x80\xE1\xB6\x88\xE1\x80\x80\xEF\xBF\xBF", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char + "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one + "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one + "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char + "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char + "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one + "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one + "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char + "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", + // surrogates + "\xF0\x90\x80\x80\xF0\x90\x89\x80\xF3\x80\x8E\xB0\xF4\x8F\xBF\xBF", + + // Strings with errors + // Incomplete 2 byte encoded character 1 byte missing standalone + "\xC2", + // Incomplete 3 byte encoded character 1 byte missing standalone + "\xE0\xA0", + // Incomplete 3 byte encoded character 2 bytes missing standalone + "\xE0", + // Incomplete surrogate character 1 byte missing standalone + "\xF0\x90\x80", + // Incomplete surrogate character 2 bytes missing standalone + "\xF0\x90", + // Incomplete surrogate character 3 bytes missing standalone + "\xF0", + // Trailing byte with no lead byte standalone + "\x80", + // Incomplete 2 byte encoded character 1 byte missing between 1 byte chars + "\x41\xC2\x42", + // Incomplete 3 byte encoded character 1 byte missing between 1 byte chars + "\x41\xE0\xA0\x42", + // Incomplete 3 byte encoded character 2 bytes missing between 1 byte chars + "\x41\xE0\x42", + // Trailing byte with no lead byte between 1 byte chars + "\x41\x80\x42", + // Incomplete 2 byte encoded character 1 byte missing before 1 byte char + "\xC2\x42", + // Incomplete 3 byte encoded character 1 byte missing before 1 byte char + "\xE0\xA0\x42", + // Incomplete 3 byte encoded character 2 bytes missing before 1 byte char + "\xE0\x42", + // Trailing byte with no lead byte before 1 byte char + "\x80\x42", + // Incomplete 2 byte encoded character 1 byte missing after 1 byte char + "\x41\xC2", + // Incomplete 3 byte encoded character 1 byte missing after 1 byte char + "\x41\xE0\xA0", + // Incomplete 3 byte encoded character 2 bytes missing after 1 byte char + "\x41\xE0", + // Trailing byte with no lead byte after 1 byte char + "\x41\x80", + // Incomplete 2 byte encoded character 1 byte missing between 2 byte chars + "\xC2\x80\xC2\xC3\xBF", + // Incomplete 3 byte encoded character 1 byte missing between 2 byte chars + "\xC2\x80\xE0\xA0\xC3\xBF", + // Incomplete 3 byte encoded character 2 bytes missing between 2 byte chars + "\xC2\x80\xE0\xC3\xBF", + // Trailing byte with no lead byte between 2 byte chars + "\xC2\x80\x80\xC3\xBF", + // 2 byte encoded character in non-shortest form encodings (these are not allowed) + "\xC0\x80", + // 3 byte encoded character in non-shortest form encodings (these are not allowed) + "\xE0\x80\x80", + // 4 byte encoded character in non-shortest form encodings (these are not allowed) + "\xF0\x80\x80\x80", + }; + + const WCHAR * const unicodeStrings[] = + { + // Empty string + W(""), + // 1 byte encoded 1 character long string + W("A"), + // 2 byte encoded 1 character long string + W("\x0080"), + // 3 byte encoded 1 character long string + W("\x0800"), + // 1 byte encoded characters only + W("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), + // 2 byte encoded characters only + W("\x0080\x00FF\x01C1\x07FF"), + // valid 3 byte encoded characters only + W("\x0800\x1D88\x1000\xFFFF"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char + W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one + W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one + W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char + W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char + W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one + W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one + W("\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char + W("\x0080\x00FF\x0043\x0044\x01C1\x07FF"), + // surrogates + W("\xD800\xDC00\xD800\xDE40\xDAC0\xDFB0\xDBFF\xDFFF"), + + // Strings with errors + // Incomplete 2 byte encoded character standalone + W(""), + // Incomplete 3 byte encoded character 1 byte missing standalone + W(""), + // Incomplete 3 byte encoded character 2 bytes missing standalone + W(""), + // Incomplete surrogate character 1 byte missing standalone + W(""), + // Incomplete surrogate character 2 bytes missing standalone + W(""), + // Incomplete surrogate character 3 bytes missing standalone + W(""), + // Trailing byte with no lead byte standalone + W(""), + // Incomplete 2 byte encoded character 1 byte missing between 1 byte chars + W("\x0041\x0042"), + // Incomplete 3 byte encoded character 1 byte missing between 1 byte chars + W("\x0041\x0042"), + // Incomplete 3 byte encoded character 2 bytes missing between 1 byte chars + W("\x0041\x0042"), + // Trailing byte with no lead byte between 1 byte chars + W("\x0041\x0042"), + // Incomplete 2 byte encoded character 1 byte missing before 1 byte char + W("\x0042"), + // Incomplete 3 byte encoded character 1 byte missing before 1 byte char + W("\x0042"), + // Incomplete 3 byte encoded character 2 bytes missing before 1 byte char + W("\x0042"), + // Trailing byte with no lead byte before 1 byte char + W("\x0042"), + // Incomplete 2 byte encoded character 1 byte missing after 1 byte char + W("\x0041"), + // Incomplete 3 byte encoded character 1 byte missing after 1 byte char + W("\x0041"), + // Incomplete 3 byte encoded character 2 bytes missing after 1 byte char + W("\x0041"), + // Trailing byte with no lead byte after 1 byte char + W("\x0041"), + // Incomplete 2 byte encoded character 1 byte missing between 2 byte chars + W("\x0080\x00FF"), + // Incomplete 3 byte encoded character 1 byte missing between 2 byte chars + W("\x0080\x00FF"), + // Incomplete 3 byte encoded character 2 bytes missing between 2 byte chars + W("\x0080\x00FF"), + // Trailing byte with no lead byte between 2 byte chars + W("\x0080\x00FF"), + // 2 byte encoded character in non-shortest form encodings (these are not allowed) + W(""), + // 3 byte encoded character in non-shortest form encodings (these are not allowed) + W(""), + // 4 byte encoded character in non-shortest form encodings (these are not allowed) + W(""), + }; + + for (int i = 0; i < (sizeof(utf8Strings) / sizeof(utf8Strings[0])); i++) + { + ret = MultiByteToWideChar(CP_UTF8, 0, utf8Strings[i], -1, NULL, 0); + WCHAR* wideBuffer = (WCHAR*)malloc(ret * sizeof(WCHAR)); + ret2 = MultiByteToWideChar(CP_UTF8, 0, utf8Strings[i], -1, wideBuffer, ret); + if (ret != ret2) + { + Fail("MultiByteToWideChar string %d: returned different string length for empty and real dest buffers!\n" + "Got %d for the empty one, %d for real one.\n", i, ret2, ret); + } + + if (wcscmp(wideBuffer, unicodeStrings[i]) != 0) + { + Fail("MultiByteToWideChar string %d: the resulting string doesn't match the expected one!\n", i); + } + + free(wideBuffer); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/CMakeLists.txt index 85824dd836..5ac7433c98 100644 --- a/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_setthreadlocale_test1 diff --git a/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/test1.c b/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/test1.c deleted file mode 100644 index 794093cf4c..0000000000 --- a/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/test1.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests SetThreadLocale with every valid locale to see that it passes -** and that it actually sets the locale. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - int i; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Try all possible locale's */ - for (i=0; i<0x000fffff; i++) - { - if (!IsValidLocale(i, LCID_INSTALLED)) - { - continue; - } - - if (!SetThreadLocale(i)) - { - Fail("SetThreadLocale failed for an installed locale!\n"); - } - - if (GetThreadLocale() != i) - { - Fail("SetThreadLocale didn't actually change to LCID %#x!\n", i); - } - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/test1.cpp new file mode 100644 index 0000000000..794093cf4c --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/SetThreadLocale/test1/test1.cpp @@ -0,0 +1,50 @@ +// 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: test1.c +** +** Purpose: Tests SetThreadLocale with every valid locale to see that it passes +** and that it actually sets the locale. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + int i; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Try all possible locale's */ + for (i=0; i<0x000fffff; i++) + { + if (!IsValidLocale(i, LCID_INSTALLED)) + { + continue; + } + + if (!SetThreadLocale(i)) + { + Fail("SetThreadLocale failed for an installed locale!\n"); + } + + if (GetThreadLocale() != i) + { + Fail("SetThreadLocale didn't actually change to LCID %#x!\n", i); + } + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/CMakeLists.txt index 0d1d12b41e..07dae640f1 100644 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_widechartomultibyte_test1 diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/test1.c b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/test1.c deleted file mode 100644 index cd763f33be..0000000000 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/test1.c +++ /dev/null @@ -1,102 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests WideCharToMultiByte with all the ASCII characters (0-127). -** Also tests that WideCharToMultiByte handles different buffer -** lengths correctly (0, -1, and a valid length) -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - char mbStr[128]; - WCHAR wideStr[128]; - int ret; - int i; - int k; - BOOL bRet=TRUE; - - /* These codepages are currently supported by the PAL */ - int codePages[] ={ - CP_ACP, - CP_UTF8 - }; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Go through all of the code pages */ - for(i=0; i<(sizeof(codePages)/sizeof(int)); i++) - { - - for (k=0; k<128; k++) - { - wideStr[k] = 127 - k; - mbStr[k] = 0; - } - - /* Convert with buffer size of 0 */ - ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, - mbStr, 0, NULL, NULL); - if (ret != 128) - { - Trace("WideCharToMultiByte did not return correct string length!\n" - "Got %d, expected %d for code page %d with error %u.\n", - ret, 128,codePages[i],GetLastError()); - bRet=FALSE; - } - - /* Make sure the ASCII set (0-127) gets translated correctly */ - ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, - mbStr, 128, NULL, NULL); - if (ret != 128) - { - Trace("WideCharToMultiByte did not return correct string length!\n" - "Got %d, expected %d for code page %d with error %u.\n", - ret, 128,codePages[i],GetLastError()); - bRet=FALSE; - } - - for (k=0; k<128; k++) - { - if (mbStr[k] != 127 - k) - { - Trace("WideCharToMultiByte failed to translate correctly!\n" - "Expected character %d to be %c (%x), got %c (%x) for " - "code page %d\n",k, 127 - k, 127 - k,mbStr[k], mbStr[k], - codePages[i]); - bRet=FALSE; - } - } - - - /* try a 0 length string ("") */ - wideStr[0] = '\0'; - ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, - mbStr, 0, NULL, NULL); - if (ret != 1) - { - Trace("WideCharToMultiByte did not return correct string length!\n" - "Got %d, expected %d for code page %d with error %u.\n", - ret, 1,codePages[i],GetLastError()); - bRet=FALSE; - } - } - - int result = bRet ? PASS : FAIL; - PAL_TerminateEx(result); - return result; -} - diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/test1.cpp b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/test1.cpp new file mode 100644 index 0000000000..cd763f33be --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/test1.cpp @@ -0,0 +1,102 @@ +// 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: test1.c +** +** Purpose: Tests WideCharToMultiByte with all the ASCII characters (0-127). +** Also tests that WideCharToMultiByte handles different buffer +** lengths correctly (0, -1, and a valid length) +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + char mbStr[128]; + WCHAR wideStr[128]; + int ret; + int i; + int k; + BOOL bRet=TRUE; + + /* These codepages are currently supported by the PAL */ + int codePages[] ={ + CP_ACP, + CP_UTF8 + }; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* Go through all of the code pages */ + for(i=0; i<(sizeof(codePages)/sizeof(int)); i++) + { + + for (k=0; k<128; k++) + { + wideStr[k] = 127 - k; + mbStr[k] = 0; + } + + /* Convert with buffer size of 0 */ + ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, + mbStr, 0, NULL, NULL); + if (ret != 128) + { + Trace("WideCharToMultiByte did not return correct string length!\n" + "Got %d, expected %d for code page %d with error %u.\n", + ret, 128,codePages[i],GetLastError()); + bRet=FALSE; + } + + /* Make sure the ASCII set (0-127) gets translated correctly */ + ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, + mbStr, 128, NULL, NULL); + if (ret != 128) + { + Trace("WideCharToMultiByte did not return correct string length!\n" + "Got %d, expected %d for code page %d with error %u.\n", + ret, 128,codePages[i],GetLastError()); + bRet=FALSE; + } + + for (k=0; k<128; k++) + { + if (mbStr[k] != 127 - k) + { + Trace("WideCharToMultiByte failed to translate correctly!\n" + "Expected character %d to be %c (%x), got %c (%x) for " + "code page %d\n",k, 127 - k, 127 - k,mbStr[k], mbStr[k], + codePages[i]); + bRet=FALSE; + } + } + + + /* try a 0 length string ("") */ + wideStr[0] = '\0'; + ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, + mbStr, 0, NULL, NULL); + if (ret != 1) + { + Trace("WideCharToMultiByte did not return correct string length!\n" + "Got %d, expected %d for code page %d with error %u.\n", + ret, 1,codePages[i],GetLastError()); + bRet=FALSE; + } + } + + int result = bRet ? PASS : FAIL; + PAL_TerminateEx(result); + return result; +} + diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/CMakeLists.txt index bbfad2ca9f..99c64afa2a 100644 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_widechartomultibyte_test2 diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/test2.c b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/test2.c deleted file mode 100644 index f5d40ae903..0000000000 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/test2.c +++ /dev/null @@ -1,88 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests that WideCharToMultiByte respects the length of the wide -** character string. -** -** -**==========================================================================*/ - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char mbStr[128]; - WCHAR wideStr[128]; - int ret; - int i; - int k; - BOOL bRet=TRUE; - - /* These codepages are currently supported by the PAL */ - int codePages[] ={ - CP_ACP, - CP_UTF8 - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Go through all of the code pages */ - for(i=0; i<(sizeof(codePages)/sizeof(int)); i++) - { - - /* Filling the arrays */ - for (k=0; k<128; k++) - { - wideStr[k] = 'a'; - mbStr[i] = 0; - } - - wideStr[127] = 0; - - /* Passing a buffer that is too small */ - ret = WideCharToMultiByte(codePages[i], 0, wideStr, 10, - mbStr, 0, NULL, NULL); - if (ret != 10) - { - Trace("WideCharToMultiByte did not return correct string length!\n" - "Got %d, expected %d for %d with error %u.\n", ret, 10, - codePages[i], GetLastError()); - bRet = FALSE; - } - - /* Passing a sufficiently large buffer */ - mbStr[10] = 'b'; - ret = WideCharToMultiByte(codePages[i], 0, wideStr, 10, - mbStr, 128, NULL, NULL); - if (ret != 10) - { - Trace("WideCharToMultiByte did not return correct string length!\n" - "Got %d, expected %d for code page %d with error %u.\n", - ret, 10, codePages[i], GetLastError()); - bRet = FALSE; - } - - /* Verifying overflow of the destination string did not occur */ - if (mbStr[10] != 'b') - { - Trace("WideCharToMultiByte overflowed the destination buffer for " - "code page %d.\n", codePages[i]); - bRet = FALSE; - } - - } - - int result = bRet ? PASS : FAIL; - PAL_TerminateEx(result); - return result; -} - diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/test2.cpp b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/test2.cpp new file mode 100644 index 0000000000..f5d40ae903 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/test2.cpp @@ -0,0 +1,88 @@ +// 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: test2.c +** +** Purpose: Tests that WideCharToMultiByte respects the length of the wide +** character string. +** +** +**==========================================================================*/ + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char mbStr[128]; + WCHAR wideStr[128]; + int ret; + int i; + int k; + BOOL bRet=TRUE; + + /* These codepages are currently supported by the PAL */ + int codePages[] ={ + CP_ACP, + CP_UTF8 + }; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Go through all of the code pages */ + for(i=0; i<(sizeof(codePages)/sizeof(int)); i++) + { + + /* Filling the arrays */ + for (k=0; k<128; k++) + { + wideStr[k] = 'a'; + mbStr[i] = 0; + } + + wideStr[127] = 0; + + /* Passing a buffer that is too small */ + ret = WideCharToMultiByte(codePages[i], 0, wideStr, 10, + mbStr, 0, NULL, NULL); + if (ret != 10) + { + Trace("WideCharToMultiByte did not return correct string length!\n" + "Got %d, expected %d for %d with error %u.\n", ret, 10, + codePages[i], GetLastError()); + bRet = FALSE; + } + + /* Passing a sufficiently large buffer */ + mbStr[10] = 'b'; + ret = WideCharToMultiByte(codePages[i], 0, wideStr, 10, + mbStr, 128, NULL, NULL); + if (ret != 10) + { + Trace("WideCharToMultiByte did not return correct string length!\n" + "Got %d, expected %d for code page %d with error %u.\n", + ret, 10, codePages[i], GetLastError()); + bRet = FALSE; + } + + /* Verifying overflow of the destination string did not occur */ + if (mbStr[10] != 'b') + { + Trace("WideCharToMultiByte overflowed the destination buffer for " + "code page %d.\n", codePages[i]); + bRet = FALSE; + } + + } + + int result = bRet ? PASS : FAIL; + PAL_TerminateEx(result); + return result; +} + diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/CMakeLists.txt index 0edfd73931..70dabead6f 100644 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_widechartomultibyte_test3 diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/test3.c b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/test3.c deleted file mode 100644 index ecd26addb4..0000000000 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/test3.c +++ /dev/null @@ -1,100 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests that WideCharToMultiByte correctly handles the following -** error conditions: insufficient buffer space, invalid code pages, -** and invalid flags. -** -** -**==========================================================================*/ - - -#include - - -int __cdecl main(int argc, char *argv[]) -{ - char mbStr[128]; - WCHAR wideStr[128]; - int ret; - int i; - int k; - BOOL bRet=TRUE; - - /* These codepages are currently supported by the PAL */ - int codePages[] ={ - CP_ACP, - CP_UTF8 - }; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Go through all of the code pages */ - for(i=0; i<(sizeof(codePages)/sizeof(int)); i++) - { - - for (k=0; k<128; k++) - { - wideStr[k] = 'a'; - mbStr[k] = 0; - } - - wideStr[127] = 0; - - /* try with insufficient buffer space */ - ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, - mbStr, 10, NULL, NULL); - if (ret != 0) - { - Trace("WideCharToMultiByte did not return an error!\n" - "Expected return of 0, got %d for code page %d.\n", ret, - codePages[i]); - bRet = FALSE; - } - - ret = GetLastError(); - if (ret != ERROR_INSUFFICIENT_BUFFER) - { - Fail("WideCharToMultiByte set the last error to %u instead of " - "ERROR_INSUFFICIENT_BUFFER for code page %d.\n", - GetLastError(),codePages[i]); - bRet = FALSE; - } - } - - /* Return failure if any of the code pages returned the wrong results */ - if(!bRet) - { - return FAIL; - } - - /* try with a wacky code page */ - ret = WideCharToMultiByte(-1, 0, wideStr, -1, mbStr, 128, NULL, NULL); - if (ret != 0) - { - Fail("WideCharToMultiByte did not return an error!\n" - "Expected return of 0, got %d for invalid code page.\n", ret); - } - - ret = GetLastError(); - if (ret != ERROR_INVALID_PARAMETER) - { - Fail("WideCharToMultiByte set the last error to %u instead of " - "ERROR_INVALID_PARAMETER for invalid code page -1.\n", - GetLastError()); - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/test3.cpp b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/test3.cpp new file mode 100644 index 0000000000..ecd26addb4 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/test3.cpp @@ -0,0 +1,100 @@ +// 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: test3.c +** +** Purpose: Tests that WideCharToMultiByte correctly handles the following +** error conditions: insufficient buffer space, invalid code pages, +** and invalid flags. +** +** +**==========================================================================*/ + + +#include + + +int __cdecl main(int argc, char *argv[]) +{ + char mbStr[128]; + WCHAR wideStr[128]; + int ret; + int i; + int k; + BOOL bRet=TRUE; + + /* These codepages are currently supported by the PAL */ + int codePages[] ={ + CP_ACP, + CP_UTF8 + }; + + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Go through all of the code pages */ + for(i=0; i<(sizeof(codePages)/sizeof(int)); i++) + { + + for (k=0; k<128; k++) + { + wideStr[k] = 'a'; + mbStr[k] = 0; + } + + wideStr[127] = 0; + + /* try with insufficient buffer space */ + ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, + mbStr, 10, NULL, NULL); + if (ret != 0) + { + Trace("WideCharToMultiByte did not return an error!\n" + "Expected return of 0, got %d for code page %d.\n", ret, + codePages[i]); + bRet = FALSE; + } + + ret = GetLastError(); + if (ret != ERROR_INSUFFICIENT_BUFFER) + { + Fail("WideCharToMultiByte set the last error to %u instead of " + "ERROR_INSUFFICIENT_BUFFER for code page %d.\n", + GetLastError(),codePages[i]); + bRet = FALSE; + } + } + + /* Return failure if any of the code pages returned the wrong results */ + if(!bRet) + { + return FAIL; + } + + /* try with a wacky code page */ + ret = WideCharToMultiByte(-1, 0, wideStr, -1, mbStr, 128, NULL, NULL); + if (ret != 0) + { + Fail("WideCharToMultiByte did not return an error!\n" + "Expected return of 0, got %d for invalid code page.\n", ret); + } + + ret = GetLastError(); + if (ret != ERROR_INVALID_PARAMETER) + { + Fail("WideCharToMultiByte set the last error to %u instead of " + "ERROR_INVALID_PARAMETER for invalid code page -1.\n", + GetLastError()); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/CMakeLists.txt index f0ffd84ee9..8839c19183 100644 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_widechartomultibyte_test4 diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/test4.c b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/test4.c deleted file mode 100644 index 8ab5fe90af..0000000000 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/test4.c +++ /dev/null @@ -1,131 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests that WideCharToMultiByte correctly handles WC_NO_BEST_FIT_CHARS -** -** -**==========================================================================*/ - - -#include - -/* C with a circumflex */ -wchar_t ustr[2] = { 0x108, 0 }; - -/* expected conversion when best fit is allowed on Windows */ -char* lpBestFitRes = "C"; - -/* expected conversion when no default character is specified */ -char* lpResStr1 = "?"; - -/* expected conversion when the default character is 'k' */ -char myDefaultChar = 'k'; -char* lpResStr2 = "k"; - -int -TestWideCharToMultiByte( - IN UINT CodePage, - IN DWORD dwFlags, - IN LPCSTR lpDefaultChar, - IN LPSTR lpResStr) -{ - char mbstr[30]; - int ret; - int testStatus = PASS; - BOOL usedDefaultChar = FALSE; - - printf("WideCharToMultiByte (CodePage=%d, dwFlags=%#x, default=%c)\n", - CodePage, dwFlags, lpDefaultChar?*lpDefaultChar:' '); - ret = WideCharToMultiByte(CodePage, dwFlags, ustr, -1, mbstr, sizeof(mbstr), - lpDefaultChar, &usedDefaultChar); - if (ret != 0) { - printf(" converted C with circumflex to in Unicode to multibyte: " - "\"%s\"\n", mbstr); - printf(" used default character?: %d\n", usedDefaultChar); - if (strcmp(mbstr, lpResStr) != 0 || usedDefaultChar != TRUE) - { - printf("!!!! failed conversion !!!!\n"); - testStatus = FAIL; - } - } - else { - printf("!!!! failed conversion !!!!\n"); - testStatus = FAIL; - } - return testStatus; -} - -int __cdecl main(int argc, char *argv[]) -{ - int testStatus = PASS; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Use WideCharToMultiByte to convert the string in code page CP_ACP. - * Note that the resulting string will be different on Windows PAL and - * Unix PAL. On Windows, the default best fit behavior will map C with - * circumflex to C. - * - * testStatus |= TestWideCharToMultiByte(CP_ACP, 0, NULL, lpBestFitRes); - * - * On Unix, where there is no support for finding best fit, it will be - * mapped to a '?'. In addition, it will trigger an ASSERT in the dbg/chk - * builds. - * - * testStatus |= TestWideCharToMultiByte(CP_ACP, 0, NULL, lpResStr1); - */ - - /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS to convert the string - * in CP_ACP (1252 by default). This will prevent it from mapping the C - * with circumflex to its closest match in the ANSI code page: C - */ - testStatus |= TestWideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, NULL, lpResStr1); - - - /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS and a default character - * to convert the string. This will prevent it from mapping the C with - * circumflex to its closest match in the ANSI code page: C. It will be - * replaced with the specified default character. - */ - testStatus |= TestWideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, &myDefaultChar, lpResStr2); - - /* Use WideCharToMultiByte to convert the string in code page 1253 - * Note that the resulting string will be different on Windows PAL and - * Unix PAL. On Windows, the default best fit behavior will map C with - * circumflex to C. - * - * testStatus |= TestWideCharToMultiByte(1253, 0, NULL, lpBestFitRes); - * - * On Unix, where there is no support for finding best fit, it will be - * mapped to a '?'. In addition, it will trigger an ASSERT in the dbg/chk - * builds. - * - * testStatus |= TestWideCharToMultiByte(1253, 0, NULL, lpResStr1); - */ - - /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS to convert the string - * in 1253. This will prevent it from mapping the C - * with circumflex to its closest match in the ANSI code page: C - */ - testStatus |= TestWideCharToMultiByte(1253, WC_NO_BEST_FIT_CHARS, NULL, lpResStr1); - - /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS and a default - * character to convert the string in 1253. This will prevent it from - * mapping the C with circumflex to its closest match in the ANSI code - * page: C. It will be replaced with the specified default character. - */ - testStatus |= TestWideCharToMultiByte(1253, WC_NO_BEST_FIT_CHARS, &myDefaultChar, lpResStr2); - - PAL_TerminateEx(testStatus); - - return testStatus; -} - diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/test4.cpp b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/test4.cpp new file mode 100644 index 0000000000..8ab5fe90af --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/test4.cpp @@ -0,0 +1,131 @@ +// 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: test4.c +** +** Purpose: Tests that WideCharToMultiByte correctly handles WC_NO_BEST_FIT_CHARS +** +** +**==========================================================================*/ + + +#include + +/* C with a circumflex */ +wchar_t ustr[2] = { 0x108, 0 }; + +/* expected conversion when best fit is allowed on Windows */ +char* lpBestFitRes = "C"; + +/* expected conversion when no default character is specified */ +char* lpResStr1 = "?"; + +/* expected conversion when the default character is 'k' */ +char myDefaultChar = 'k'; +char* lpResStr2 = "k"; + +int +TestWideCharToMultiByte( + IN UINT CodePage, + IN DWORD dwFlags, + IN LPCSTR lpDefaultChar, + IN LPSTR lpResStr) +{ + char mbstr[30]; + int ret; + int testStatus = PASS; + BOOL usedDefaultChar = FALSE; + + printf("WideCharToMultiByte (CodePage=%d, dwFlags=%#x, default=%c)\n", + CodePage, dwFlags, lpDefaultChar?*lpDefaultChar:' '); + ret = WideCharToMultiByte(CodePage, dwFlags, ustr, -1, mbstr, sizeof(mbstr), + lpDefaultChar, &usedDefaultChar); + if (ret != 0) { + printf(" converted C with circumflex to in Unicode to multibyte: " + "\"%s\"\n", mbstr); + printf(" used default character?: %d\n", usedDefaultChar); + if (strcmp(mbstr, lpResStr) != 0 || usedDefaultChar != TRUE) + { + printf("!!!! failed conversion !!!!\n"); + testStatus = FAIL; + } + } + else { + printf("!!!! failed conversion !!!!\n"); + testStatus = FAIL; + } + return testStatus; +} + +int __cdecl main(int argc, char *argv[]) +{ + int testStatus = PASS; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Use WideCharToMultiByte to convert the string in code page CP_ACP. + * Note that the resulting string will be different on Windows PAL and + * Unix PAL. On Windows, the default best fit behavior will map C with + * circumflex to C. + * + * testStatus |= TestWideCharToMultiByte(CP_ACP, 0, NULL, lpBestFitRes); + * + * On Unix, where there is no support for finding best fit, it will be + * mapped to a '?'. In addition, it will trigger an ASSERT in the dbg/chk + * builds. + * + * testStatus |= TestWideCharToMultiByte(CP_ACP, 0, NULL, lpResStr1); + */ + + /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS to convert the string + * in CP_ACP (1252 by default). This will prevent it from mapping the C + * with circumflex to its closest match in the ANSI code page: C + */ + testStatus |= TestWideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, NULL, lpResStr1); + + + /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS and a default character + * to convert the string. This will prevent it from mapping the C with + * circumflex to its closest match in the ANSI code page: C. It will be + * replaced with the specified default character. + */ + testStatus |= TestWideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, &myDefaultChar, lpResStr2); + + /* Use WideCharToMultiByte to convert the string in code page 1253 + * Note that the resulting string will be different on Windows PAL and + * Unix PAL. On Windows, the default best fit behavior will map C with + * circumflex to C. + * + * testStatus |= TestWideCharToMultiByte(1253, 0, NULL, lpBestFitRes); + * + * On Unix, where there is no support for finding best fit, it will be + * mapped to a '?'. In addition, it will trigger an ASSERT in the dbg/chk + * builds. + * + * testStatus |= TestWideCharToMultiByte(1253, 0, NULL, lpResStr1); + */ + + /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS to convert the string + * in 1253. This will prevent it from mapping the C + * with circumflex to its closest match in the ANSI code page: C + */ + testStatus |= TestWideCharToMultiByte(1253, WC_NO_BEST_FIT_CHARS, NULL, lpResStr1); + + /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS and a default + * character to convert the string in 1253. This will prevent it from + * mapping the C with circumflex to its closest match in the ANSI code + * page: C. It will be replaced with the specified default character. + */ + testStatus |= TestWideCharToMultiByte(1253, WC_NO_BEST_FIT_CHARS, &myDefaultChar, lpResStr2); + + PAL_TerminateEx(testStatus); + + return testStatus; +} + diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/CMakeLists.txt index 6ca2a628bf..e00657879d 100644 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_widechartomultibyte_test5 diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/test5.c b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/test5.c deleted file mode 100644 index 3ca0d90d0f..0000000000 --- a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/test5.c +++ /dev/null @@ -1,154 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests WideCharMultiByte with UTF-8 encoding -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - int ret; - int ret2; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - const WCHAR * const unicodeStrings[] = - { - // Correct strings - - // Empty string - W(""), - // 1 byte encoded 1 character long string - W("A"), - // 2 byte encoded 1 character long string - W("\x0080"), - // 3 byte encoded 1 character long string - W("\x0800"), - // 1 byte encoded characters only - W("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), - // 2 byte encoded characters only - W("\x0080\x00FF\x01C1\x07FF"), - // valid 3 byte encoded characters only - W("\x0800\x1D88\x1000\xFFFF"), - // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char - W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), - // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one - W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), - // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one - W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), - // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char - W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), - // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char - W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), - // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one - W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF"), - // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one - W("\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), - // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char - W("\x0080\x00FF\x0043\x0044\x01C1\x07FF"), - // Surrogates - W("\xD800\xDC00\xD800\xDE40\xDAC0\xDFB0\xDBFF\xDFFF"), - - // Strings with errors - - // Single high surrogate - W("\xD800"), - // Single low surrogate - W("\xDC00"), - // Character followed by single high surrogate - W("\x0041\xD800"), - // Character followed by single low surrogate - W("\x0041\xDC00"), - // Single high surrogate between two characters - W("\x0041\xD800\x0042"), - // Single low surrogate between two characters - W("\x0041\xDC00\x0042"), - }; - - const char * const utf8Strings[] = - { - // Correct strings - - // Empty string - "", - // 1 byte encoded 1 character long string - "A", - // 2 byte encoded 1 character long string - "\xC2\x80", - // 3 byte encoded 1 character long string - "\xE0\xA0\x80", - // 1 byte encoded characters only - "ABCDEFGHIJKLMNOPQRSTUVWXYZ", - // valid 2 byte encoded characters only - "\xC2\x80\xC3\xBF\xC7\x81\xDF\xBF", - // valid 3 byte encoded characters only - "\xE0\xA0\x80\xE1\xB6\x88\xE1\x80\x80\xEF\xBF\xBF", - // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char - "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", - // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one - "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", - // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one - "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", - // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char - "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", - // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char - "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", - // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one - "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", - // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one - "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", - // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char - "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", - // Surrogates - "\xF0\x90\x80\x80\xF0\x90\x89\x80\xF3\x80\x8E\xB0\xF4\x8F\xBF\xBF", - - // Strings with errors - - // Single high surrogate - "\xEF\xBF\xBD", - // Single low surrogate - "\xEF\xBF\xBD", - // Character followed by single high surrogate - "\x41\xEF\xBF\xBD", - // Character followed by single low surrogate - "\x41\xEF\xBF\xBD", - // Single high surrogate between two characters - "\x41\xEF\xBF\xBD\x42", - // Single low surrogate between two characters - "\x41\xEF\xBF\xBD\x42", - }; - - for (int i = 0; i < (sizeof(unicodeStrings) / sizeof(unicodeStrings[0])); i++) - { - ret = WideCharToMultiByte(CP_UTF8, 0, unicodeStrings[i], -1, NULL, 0, NULL, NULL); - CHAR* utf8Buffer = malloc(ret * sizeof(CHAR)); - ret2 = WideCharToMultiByte(CP_UTF8, 0, unicodeStrings[i], -1, utf8Buffer, ret, NULL, NULL); - if (ret != ret2) - { - Fail("WideCharToMultiByte string %d: returned different string length for empty and real dest buffers!\n" - "Got %d for the empty one, %d for real one.\n", i, ret2, ret); - } - - if (strcmp(utf8Buffer, utf8Strings[i]) != 0) - { - Fail("WideCharToMultiByte string %d: the resulting string doesn't match the expected one!\n", i); - } - - free(utf8Buffer); - } - - PAL_Terminate(); - - return PASS; -} \ No newline at end of file diff --git a/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/test5.cpp b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/test5.cpp new file mode 100644 index 0000000000..393516a198 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/test5.cpp @@ -0,0 +1,154 @@ +// 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: test4.c +** +** Purpose: Tests WideCharMultiByte with UTF-8 encoding +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + int ret; + int ret2; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + const WCHAR * const unicodeStrings[] = + { + // Correct strings + + // Empty string + W(""), + // 1 byte encoded 1 character long string + W("A"), + // 2 byte encoded 1 character long string + W("\x0080"), + // 3 byte encoded 1 character long string + W("\x0800"), + // 1 byte encoded characters only + W("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), + // 2 byte encoded characters only + W("\x0080\x00FF\x01C1\x07FF"), + // valid 3 byte encoded characters only + W("\x0800\x1D88\x1000\xFFFF"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char + W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one + W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one + W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char + W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char + W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one + W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one + W("\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char + W("\x0080\x00FF\x0043\x0044\x01C1\x07FF"), + // Surrogates + W("\xD800\xDC00\xD800\xDE40\xDAC0\xDFB0\xDBFF\xDFFF"), + + // Strings with errors + + // Single high surrogate + W("\xD800"), + // Single low surrogate + W("\xDC00"), + // Character followed by single high surrogate + W("\x0041\xD800"), + // Character followed by single low surrogate + W("\x0041\xDC00"), + // Single high surrogate between two characters + W("\x0041\xD800\x0042"), + // Single low surrogate between two characters + W("\x0041\xDC00\x0042"), + }; + + const char * const utf8Strings[] = + { + // Correct strings + + // Empty string + "", + // 1 byte encoded 1 character long string + "A", + // 2 byte encoded 1 character long string + "\xC2\x80", + // 3 byte encoded 1 character long string + "\xE0\xA0\x80", + // 1 byte encoded characters only + "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + // valid 2 byte encoded characters only + "\xC2\x80\xC3\xBF\xC7\x81\xDF\xBF", + // valid 3 byte encoded characters only + "\xE0\xA0\x80\xE1\xB6\x88\xE1\x80\x80\xEF\xBF\xBF", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char + "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one + "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one + "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char + "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char + "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one + "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one + "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char + "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", + // Surrogates + "\xF0\x90\x80\x80\xF0\x90\x89\x80\xF3\x80\x8E\xB0\xF4\x8F\xBF\xBF", + + // Strings with errors + + // Single high surrogate + "\xEF\xBF\xBD", + // Single low surrogate + "\xEF\xBF\xBD", + // Character followed by single high surrogate + "\x41\xEF\xBF\xBD", + // Character followed by single low surrogate + "\x41\xEF\xBF\xBD", + // Single high surrogate between two characters + "\x41\xEF\xBF\xBD\x42", + // Single low surrogate between two characters + "\x41\xEF\xBF\xBD\x42", + }; + + for (int i = 0; i < (sizeof(unicodeStrings) / sizeof(unicodeStrings[0])); i++) + { + ret = WideCharToMultiByte(CP_UTF8, 0, unicodeStrings[i], -1, NULL, 0, NULL, NULL); + CHAR* utf8Buffer = (CHAR*)malloc(ret * sizeof(CHAR)); + ret2 = WideCharToMultiByte(CP_UTF8, 0, unicodeStrings[i], -1, utf8Buffer, ret, NULL, NULL); + if (ret != ret2) + { + Fail("WideCharToMultiByte string %d: returned different string length for empty and real dest buffers!\n" + "Got %d for the empty one, %d for real one.\n", i, ret2, ret); + } + + if (strcmp(utf8Buffer, utf8Strings[i]) != 0) + { + Fail("WideCharToMultiByte string %d: the resulting string doesn't match the expected one!\n", i); + } + + free(utf8Buffer); + } + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CMakeLists.txt index 86f194198b..0fd4df8ad5 100644 --- a/src/pal/tests/palsuite/miscellaneous/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/CMakeLists.txt @@ -27,9 +27,6 @@ add_subdirectory(InterLockedExchangeAdd) add_subdirectory(InterlockedExchangePointer) add_subdirectory(InterlockedIncrement) add_subdirectory(InterlockedIncrement64) -add_subdirectory(lstrcatW) -add_subdirectory(lstrcpynW) -add_subdirectory(lstrcpyW) add_subdirectory(lstrlenA) add_subdirectory(lstrlenW) add_subdirectory(queryperformancecounter) @@ -37,8 +34,5 @@ add_subdirectory(queryperformancefrequency) add_subdirectory(SetEnvironmentVariableA) add_subdirectory(SetEnvironmentVariableW) add_subdirectory(SetLastError) -add_subdirectory(wsprintfA) -add_subdirectory(wsprintfW) add_subdirectory(_i64tow) -add_subdirectory(_ui64tow) diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/CMakeLists.txt index 8506d86737..23df52b430 100644 --- a/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_charnexta_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/test.c b/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/test.c deleted file mode 100644 index d2a3db31d5..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/test.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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 CharNextA, ensures it returns the proper char for an -** entire string -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc,char *argv[]) -{ - - char * AnExampleString = "this is the string"; - char * StringPointer = AnExampleString; - int count = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Use CharNext to move through an entire string. Ensure the pointer that - is returned points to the correct character, by comparing it with - 'StringPointer' which isn't touched by CharNext. - */ - - while(*AnExampleString != '\0') - { - - /* Fail if any characters are different. This is comparing the - * addresses of both characters, not the characters themselves. - */ - - if(AnExampleString != &StringPointer[count]) - { - Fail("ERROR: %#x and %#x are different. These should be the same " - " address.\n",AnExampleString,&StringPointer[count]); - - - } - - AnExampleString = CharNextA(AnExampleString); - ++count; - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/test.cpp new file mode 100644 index 0000000000..d2a3db31d5 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/CharNextA/test1/test.cpp @@ -0,0 +1,62 @@ +// 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 CharNextA, ensures it returns the proper char for an +** entire string +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc,char *argv[]) +{ + + char * AnExampleString = "this is the string"; + char * StringPointer = AnExampleString; + int count = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Use CharNext to move through an entire string. Ensure the pointer that + is returned points to the correct character, by comparing it with + 'StringPointer' which isn't touched by CharNext. + */ + + while(*AnExampleString != '\0') + { + + /* Fail if any characters are different. This is comparing the + * addresses of both characters, not the characters themselves. + */ + + if(AnExampleString != &StringPointer[count]) + { + Fail("ERROR: %#x and %#x are different. These should be the same " + " address.\n",AnExampleString,&StringPointer[count]); + + + } + + AnExampleString = CharNextA(AnExampleString); + ++count; + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/CMakeLists.txt index 04f4679630..5f089e963c 100644 --- a/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_charnexta_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/test.c b/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/test.c deleted file mode 100644 index 7261959021..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/test.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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 CharNextA, ensures it returns an LPTSTR -** -** -**=========================================================*/ - -/* Depends on strcmp() */ - -#include - -void testString(LPSTR input, LPSTR expected) -{ - - LPTSTR pReturned = NULL; - - pReturned = CharNextA(input); - - /* Compare the Returned String to what it should be */ - if(strcmp(expected,pReturned) != 0) - { - Fail("ERROR: CharNextA Failed: [%s] and [%s] are not equal, " - "they should be after calling CharNextA.\n", - pReturned,expected); - } - - -} - -int __cdecl main(int argc, char *argv[]) -{ - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* test several Strings */ - testString("this is the string", "his is the string"); - testString("t", ""); - testString("", ""); - testString("a\t", "\t"); - testString("a\a", "\a"); - testString("a\b", "\b"); - testString("a\"", "\""); - testString("a\\", "\\"); - testString("\\", ""); - testString("\f", ""); - testString("\b", ""); - - PAL_Terminate(); - return PASS; -} - - - - diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/test.cpp new file mode 100644 index 0000000000..7261959021 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/CharNextA/test2/test.cpp @@ -0,0 +1,67 @@ +// 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 CharNextA, ensures it returns an LPTSTR +** +** +**=========================================================*/ + +/* Depends on strcmp() */ + +#include + +void testString(LPSTR input, LPSTR expected) +{ + + LPTSTR pReturned = NULL; + + pReturned = CharNextA(input); + + /* Compare the Returned String to what it should be */ + if(strcmp(expected,pReturned) != 0) + { + Fail("ERROR: CharNextA Failed: [%s] and [%s] are not equal, " + "they should be after calling CharNextA.\n", + pReturned,expected); + } + + +} + +int __cdecl main(int argc, char *argv[]) +{ + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* test several Strings */ + testString("this is the string", "his is the string"); + testString("t", ""); + testString("", ""); + testString("a\t", "\t"); + testString("a\a", "\a"); + testString("a\b", "\b"); + testString("a\"", "\""); + testString("a\\", "\\"); + testString("\\", ""); + testString("\f", ""); + testString("\b", ""); + + PAL_Terminate(); + return PASS; +} + + + + diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/CMakeLists.txt index bfa12b5526..ae1433f089 100644 --- a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_charnextexa_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/test.c b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/test.c deleted file mode 100644 index 9671ca86b8..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/test.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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 CharNextExA function -** -** -**=========================================================*/ - -/* - This test is FINISHED. This function is the same as CharNextA it seems, - since the only fields that differ are always 0. -*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - char * AnExampleString = "this is the string"; - char * StringPointer = AnExampleString; - int count = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Use CharNext to move through an entire string. Ensure the pointer - * that is returned points to the correct character, by comparing it with - * 'stringPointer' which isn't touched by CharNext. - */ - - while(*AnExampleString != 0) - { - /* Fail if any characters are different. This is comparing the - * addresses of both characters, not the characters themselves. - */ - - if(AnExampleString != &StringPointer[count]) - { - Fail("ERROR: %#x and %#x are different. These should be the " - "same address.\n",AnExampleString,&StringPointer[count]); - } - - AnExampleString = CharNextExA(0,AnExampleString,0); - ++count; - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/test.cpp new file mode 100644 index 0000000000..9671ca86b8 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test1/test.cpp @@ -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 CharNextExA function +** +** +**=========================================================*/ + +/* + This test is FINISHED. This function is the same as CharNextA it seems, + since the only fields that differ are always 0. +*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + char * AnExampleString = "this is the string"; + char * StringPointer = AnExampleString; + int count = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Use CharNext to move through an entire string. Ensure the pointer + * that is returned points to the correct character, by comparing it with + * 'stringPointer' which isn't touched by CharNext. + */ + + while(*AnExampleString != 0) + { + /* Fail if any characters are different. This is comparing the + * addresses of both characters, not the characters themselves. + */ + + if(AnExampleString != &StringPointer[count]) + { + Fail("ERROR: %#x and %#x are different. These should be the " + "same address.\n",AnExampleString,&StringPointer[count]); + } + + AnExampleString = CharNextExA(0,AnExampleString,0); + ++count; + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/CMakeLists.txt index 556043abcd..1c81d1f9a4 100644 --- a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_charnextexa_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/test.c b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/test.c deleted file mode 100644 index ffc153f5e6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/test.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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 CharNextExA, ensures it returns an LPTSTR -** -** -**=========================================================*/ - -/* Depends on strcmp() */ - -#include - -void testString(LPSTR input, LPSTR expected) -{ - - LPTSTR pReturned = NULL; - - pReturned = CharNextExA(0,input,0); - - /* Compare the Returned String to what it should be */ - if(strcmp(expected,pReturned) != 0) - { - Fail("ERROR: CharNextExA Failed: [%s] and [%s] are not equal, " - "they should be after calling CharNextExA.\n", - pReturned,expected); - } - - -} - -int __cdecl main(int argc, char *argv[]) -{ - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* test several Strings */ - testString("this is the string", "his is the string"); - testString("t", ""); - testString("", ""); - testString("a\t", "\t"); - testString("a\a", "\a"); - testString("a\b", "\b"); - testString("a\"", "\""); - testString("a\\", "\\"); - testString("\\", ""); - testString("\f", ""); - testString("\bx", "x"); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/test.cpp new file mode 100644 index 0000000000..ffc153f5e6 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/CharNextExA/test2/test.cpp @@ -0,0 +1,66 @@ +// 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 CharNextExA, ensures it returns an LPTSTR +** +** +**=========================================================*/ + +/* Depends on strcmp() */ + +#include + +void testString(LPSTR input, LPSTR expected) +{ + + LPTSTR pReturned = NULL; + + pReturned = CharNextExA(0,input,0); + + /* Compare the Returned String to what it should be */ + if(strcmp(expected,pReturned) != 0) + { + Fail("ERROR: CharNextExA Failed: [%s] and [%s] are not equal, " + "they should be after calling CharNextExA.\n", + pReturned,expected); + } + + +} + +int __cdecl main(int argc, char *argv[]) +{ + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* test several Strings */ + testString("this is the string", "his is the string"); + testString("t", ""); + testString("", ""); + testString("a\t", "\t"); + testString("a\a", "\a"); + testString("a\b", "\b"); + testString("a\"", "\""); + testString("a\\", "\\"); + testString("\\", ""); + testString("\f", ""); + testString("\bx", "x"); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/CMakeLists.txt index bbe37ddd19..78bb701959 100644 --- a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_closehandle_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/test.c b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/test.c deleted file mode 100644 index 8e42229c29..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/test.c +++ /dev/null @@ -1,64 +0,0 @@ -// 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 CloseHandle function -** -** -**=========================================================*/ - -/* Depends on: CreateFile and WriteFile */ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE FileHandle = NULL; - LPDWORD WriteBuffer; /* Used with WriteFile */ - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - WriteBuffer = malloc(sizeof(WORD)); - - if ( WriteBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for WriteBuffer pointer. " - "Can't properly exec test case without this.\n"); - } - - - /* Create a file, since this returns to us a HANDLE we can use */ - FileHandle = CreateFile("testfile", - GENERIC_READ | GENERIC_WRITE,0,NULL,CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - /* Should be able to close this handle */ - if(CloseHandle(FileHandle) == 0) - { - free(WriteBuffer); - Fail("ERROR: (Test 1) Attempted to close a HANDLE on a file, but the " - "return value was <=0, indicating failure.\n"); - } - - free(WriteBuffer); - - PAL_Terminate(); - return PASS; -} - - - - diff --git a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/test.cpp new file mode 100644 index 0000000000..443f89bace --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test1/test.cpp @@ -0,0 +1,64 @@ +// 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 CloseHandle function +** +** +**=========================================================*/ + +/* Depends on: CreateFile and WriteFile */ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE FileHandle = NULL; + LPDWORD WriteBuffer; /* Used with WriteFile */ + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + WriteBuffer = (LPDWORD)malloc(sizeof(WORD)); + + if ( WriteBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for WriteBuffer pointer. " + "Can't properly exec test case without this.\n"); + } + + + /* Create a file, since this returns to us a HANDLE we can use */ + FileHandle = CreateFile("testfile", + GENERIC_READ | GENERIC_WRITE,0,NULL,CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + /* Should be able to close this handle */ + if(CloseHandle(FileHandle) == 0) + { + free(WriteBuffer); + Fail("ERROR: (Test 1) Attempted to close a HANDLE on a file, but the " + "return value was <=0, indicating failure.\n"); + } + + free(WriteBuffer); + + PAL_Terminate(); + return PASS; +} + + + + diff --git a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/CMakeLists.txt index 75de513be7..18350f20ad 100644 --- a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_closehandle_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/test.c b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/test.c deleted file mode 100644 index c1eea44070..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/test.c +++ /dev/null @@ -1,46 +0,0 @@ -// 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 CloseHandle function, try to close an unopened HANDLE -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - HANDLE SomeHandle = NULL; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* If the handle is already closed and you can close it again, - * something is wrong. - */ - - if(CloseHandle(SomeHandle) != 0) - { - Fail("ERROR: Called CloseHandle on an already closed Handle " - "and it still returned as a success.\n"); - } - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/test.cpp new file mode 100644 index 0000000000..c1eea44070 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/CloseHandle/test2/test.cpp @@ -0,0 +1,46 @@ +// 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 CloseHandle function, try to close an unopened HANDLE +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE SomeHandle = NULL; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* If the handle is already closed and you can close it again, + * something is wrong. + */ + + if(CloseHandle(SomeHandle) != 0) + { + Fail("ERROR: Called CloseHandle on an already closed Handle " + "and it still returned as a success.\n"); + } + + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/CMakeLists.txt index af878cb873..15a0f572bb 100644 --- a/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_createpipe_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.c b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.c deleted file mode 100644 index 3930183b60..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.c +++ /dev/null @@ -1,113 +0,0 @@ -// 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: test1.c (CreatePipe) -** -** Purpose: Tests the PAL implementation of the CreatePipe function. -** This test will create two pipes, a read and a write. Once -** the pipes have been created, they will be tested by writing -** and then reading, then comparing the results. -** -** Depends: WriteFile -** ReadFile -** memcmp -** CloseHandle -** -** -**===================================================================*/ - -#include - -const char* cTestString = "one fish, two fish, red fish, blue fish."; - -int __cdecl main(int argc, char **argv) -{ - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - BOOL bRetVal = FALSE; - DWORD dwBytesWritten; - DWORD dwBytesRead; - char buffer[256]; - - SECURITY_ATTRIBUTES lpPipeAttributes; - - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /*Create a Pipe*/ - bRetVal = CreatePipe(&hReadPipe, /* read handle*/ - &hWritePipe, /* write handle */ - &lpPipeAttributes, /* security attributes*/ - 0); /* pipe size*/ - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :Unable to create pipe\n", GetLastError()); - } - - /*Write to the write pipe handle*/ - bRetVal = WriteFile(hWritePipe, /* handle to write pipe*/ - cTestString, /* buffer to write*/ - strlen(cTestString),/* number of bytes to write*/ - &dwBytesWritten, /* number of bytes written*/ - NULL); /* overlapped buffer*/ - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :unable to write to write pipe handle " - "hWritePipe=0x%lx\n", GetLastError(), hWritePipe); - } - - /*Read, 256 bytes, more bytes then actually written. - This will give allow us to use the value that ReadFile - returns for comparision.*/ - bRetVal = ReadFile(hReadPipe, /* handle to read pipe*/ - buffer, /* buffer to write to*/ - 256, /* number of bytes to read*/ - &dwBytesRead, /* number of bytes read*/ - NULL); /* overlapped buffer*/ - if (bRetVal == FALSE) - { - Fail("ERROR: %ld : unable read hWritePipe=0x%lx\n", - GetLastError(), hWritePipe); - } - - /*Compare what was read with what was written.*/ - if ((memcmp(cTestString, buffer, dwBytesRead)) != 0) - { - Fail("ERROR: read \"%s\" expected \"%s\" \n", buffer, cTestString); - } - - /*Compare values returned from WriteFile and ReadFile.*/ - if (dwBytesWritten != dwBytesRead) - { - Fail("ERROR: WriteFile wrote \"%d\", but ReadFile read \"%d\"," - " these should be the same\n", buffer, cTestString); - } - - /*Close write pipe handle*/ - if (CloseHandle(hWritePipe) == 0) - { - Fail("ERROR: %ld : Unable to close write pipe handle " - "hWritePipe=0x%lx\n",GetLastError(), hWritePipe); - } - - /*Close Read pipe handle*/ - if (CloseHandle(hReadPipe) == 0) - { - Fail("ERROR: %ld : Unable to close read pipe handle " - "hReadPipe=0x%lx\n", GetLastError(), hReadPipe); - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.cpp b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.cpp new file mode 100644 index 0000000000..3930183b60 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.cpp @@ -0,0 +1,113 @@ +// 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: test1.c (CreatePipe) +** +** Purpose: Tests the PAL implementation of the CreatePipe function. +** This test will create two pipes, a read and a write. Once +** the pipes have been created, they will be tested by writing +** and then reading, then comparing the results. +** +** Depends: WriteFile +** ReadFile +** memcmp +** CloseHandle +** +** +**===================================================================*/ + +#include + +const char* cTestString = "one fish, two fish, red fish, blue fish."; + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + DWORD dwBytesWritten; + DWORD dwBytesRead; + char buffer[256]; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, /* read handle*/ + &hWritePipe, /* write handle */ + &lpPipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :Unable to create pipe\n", GetLastError()); + } + + /*Write to the write pipe handle*/ + bRetVal = WriteFile(hWritePipe, /* handle to write pipe*/ + cTestString, /* buffer to write*/ + strlen(cTestString),/* number of bytes to write*/ + &dwBytesWritten, /* number of bytes written*/ + NULL); /* overlapped buffer*/ + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :unable to write to write pipe handle " + "hWritePipe=0x%lx\n", GetLastError(), hWritePipe); + } + + /*Read, 256 bytes, more bytes then actually written. + This will give allow us to use the value that ReadFile + returns for comparision.*/ + bRetVal = ReadFile(hReadPipe, /* handle to read pipe*/ + buffer, /* buffer to write to*/ + 256, /* number of bytes to read*/ + &dwBytesRead, /* number of bytes read*/ + NULL); /* overlapped buffer*/ + if (bRetVal == FALSE) + { + Fail("ERROR: %ld : unable read hWritePipe=0x%lx\n", + GetLastError(), hWritePipe); + } + + /*Compare what was read with what was written.*/ + if ((memcmp(cTestString, buffer, dwBytesRead)) != 0) + { + Fail("ERROR: read \"%s\" expected \"%s\" \n", buffer, cTestString); + } + + /*Compare values returned from WriteFile and ReadFile.*/ + if (dwBytesWritten != dwBytesRead) + { + Fail("ERROR: WriteFile wrote \"%d\", but ReadFile read \"%d\"," + " these should be the same\n", buffer, cTestString); + } + + /*Close write pipe handle*/ + if (CloseHandle(hWritePipe) == 0) + { + Fail("ERROR: %ld : Unable to close write pipe handle " + "hWritePipe=0x%lx\n",GetLastError(), hWritePipe); + } + + /*Close Read pipe handle*/ + if (CloseHandle(hReadPipe) == 0) + { + Fail("ERROR: %ld : Unable to close read pipe handle " + "hReadPipe=0x%lx\n", GetLastError(), hReadPipe); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/CMakeLists.txt index fbd8b0f87d..47ee4b0abd 100644 --- a/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_flushinstructioncache_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/test1.c b/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/test1.c deleted file mode 100644 index cdbefd01cc..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/test1.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that FlushInstructionCache returns the correct value for a -** number of different inputs. -** -** -** Note : -** For this function, what constitutes "invalid parameters" will depend entirely -** on the platform; because of this we can't simply test values on Windows and -** then ask for the same results everywhere. Because of this, this test can -** ensure that the function succeeds for some "obviously" valid values, but -** can't make sure that it fails for invalid values. -** -**=========================================================*/ - -#include - -void DoTest(void *Buffer, int Size, int Expected) -{ - int ret; - - SetLastError(0); - ret = FlushInstructionCache(GetCurrentProcess(), Buffer, Size); - if (!ret && Expected) - { - Fail("Expected FlushInstructionCache to return non-zero, got zero!\n" - "region: %p, size: %d, GetLastError: %d\n", Buffer, Size, - GetLastError()); - } - else if (ret && !Expected) - { - Fail("Expected FlushInstructionCache to return zero, got non-zero!\n" - "region: %p, size: %d, GetLastError: %d\n", Buffer, Size, - GetLastError()); - } - - if (!Expected && ERROR_NOACCESS != GetLastError()) - { - Fail("FlushInstructionCache failed to set the last error to " - "ERROR_NOACCESS!\n"); - } - -} - -int __cdecl main(int argc,char *argv[]) -{ - char ValidPtr[256]; - - if(PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* with valid pointer, zero-size and valid size must succeed */ - DoTest(ValidPtr, 0, 1); - DoTest(ValidPtr, 42, 1); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/test1.cpp b/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/test1.cpp new file mode 100644 index 0000000000..cdbefd01cc --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FlushInstructionCache/test1/test1.cpp @@ -0,0 +1,66 @@ +// 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: test1.c +** +** Purpose: Tests that FlushInstructionCache returns the correct value for a +** number of different inputs. +** +** +** Note : +** For this function, what constitutes "invalid parameters" will depend entirely +** on the platform; because of this we can't simply test values on Windows and +** then ask for the same results everywhere. Because of this, this test can +** ensure that the function succeeds for some "obviously" valid values, but +** can't make sure that it fails for invalid values. +** +**=========================================================*/ + +#include + +void DoTest(void *Buffer, int Size, int Expected) +{ + int ret; + + SetLastError(0); + ret = FlushInstructionCache(GetCurrentProcess(), Buffer, Size); + if (!ret && Expected) + { + Fail("Expected FlushInstructionCache to return non-zero, got zero!\n" + "region: %p, size: %d, GetLastError: %d\n", Buffer, Size, + GetLastError()); + } + else if (ret && !Expected) + { + Fail("Expected FlushInstructionCache to return zero, got non-zero!\n" + "region: %p, size: %d, GetLastError: %d\n", Buffer, Size, + GetLastError()); + } + + if (!Expected && ERROR_NOACCESS != GetLastError()) + { + Fail("FlushInstructionCache failed to set the last error to " + "ERROR_NOACCESS!\n"); + } + +} + +int __cdecl main(int argc,char *argv[]) +{ + char ValidPtr[256]; + + if(PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* with valid pointer, zero-size and valid size must succeed */ + DoTest(ValidPtr, 0, 1); + DoTest(ValidPtr, 42, 1); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/CMakeLists.txt index 0f242e9b30..df91482855 100644 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_formatmessagew_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.c deleted file mode 100644 index 0cc4c43432..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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 - - -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/test.cpp b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.cpp new file mode 100644 index 0000000000..0cc4c43432 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.cpp @@ -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 + + +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/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/CMakeLists.txt index 26092ac300..818649aac7 100644 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_formatmessagew_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.c deleted file mode 100644 index 6c2d80b3f4..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.c +++ /dev/null @@ -1,581 +0,0 @@ -// 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 - -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/test.cpp b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp new file mode 100644 index 0000000000..6c2d80b3f4 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp @@ -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 + +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/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/CMakeLists.txt index b430511c4c..516d4bcc9a 100644 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_formatmessagew_test3 diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.c deleted file mode 100644 index a390c00fea..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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 - -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/test.cpp b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.cpp new file mode 100644 index 0000000000..a390c00fea --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.cpp @@ -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 + +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/test4/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/CMakeLists.txt index cae8ff149c..642727c6dc 100644 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_formatmessagew_test4 diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.c deleted file mode 100644 index 4f865efe7e..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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 - -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/test.cpp b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.cpp new file mode 100644 index 0000000000..4f865efe7e --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.cpp @@ -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 + +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/test5/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/CMakeLists.txt index 6779f94ff9..bae113475d 100644 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_formatmessagew_test5 diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.c deleted file mode 100644 index 148c2ff236..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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 - -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/test.cpp b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.cpp new file mode 100644 index 0000000000..148c2ff236 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.cpp @@ -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 + +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/test6/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/CMakeLists.txt index 450b2b808b..f403cba0f4 100644 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_formatmessagew_test6 diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.c deleted file mode 100644 index 48f5e3e93d..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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 - - -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/test.cpp b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.cpp new file mode 100644 index 0000000000..48f5e3e93d --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.cpp @@ -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 + + +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/FreeEnvironmentStringsW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/CMakeLists.txt index be39b63ec9..206707efa6 100644 --- a/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_freeenvironmentstringsw_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/test.c deleted file mode 100644 index 56010039d7..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/test.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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 FreeEnvironmentStringsW() function -** -** -**=========================================================*/ - -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - - LPWSTR CapturedEnvironment = NULL; - BOOL TheResult = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - CapturedEnvironment = GetEnvironmentStrings(); - - /* If it's pointing to NULL, it failed. This checks the dependency */ - if(CapturedEnvironment == NULL) { - Fail("The function GetEnvironmentStrings() failed, and the " - "FreeEnvironmentStrings() tests is dependant on it.\n"); - } - - /* This should return 1, if it succeeds, otherwise, test fails */ - TheResult = FreeEnvironmentStrings(CapturedEnvironment); - if(TheResult != 1) { - Fail("The function returned %d which indicates failure to Free the " - "Environment Strings.\n",TheResult); - } - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/test.cpp new file mode 100644 index 0000000000..56010039d7 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test1/test.cpp @@ -0,0 +1,53 @@ +// 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 FreeEnvironmentStringsW() function +** +** +**=========================================================*/ + +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + + LPWSTR CapturedEnvironment = NULL; + BOOL TheResult = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + CapturedEnvironment = GetEnvironmentStrings(); + + /* If it's pointing to NULL, it failed. This checks the dependency */ + if(CapturedEnvironment == NULL) { + Fail("The function GetEnvironmentStrings() failed, and the " + "FreeEnvironmentStrings() tests is dependant on it.\n"); + } + + /* This should return 1, if it succeeds, otherwise, test fails */ + TheResult = FreeEnvironmentStrings(CapturedEnvironment); + if(TheResult != 1) { + Fail("The function returned %d which indicates failure to Free the " + "Environment Strings.\n",TheResult); + } + + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/CMakeLists.txt index a3688dd24a..d8197d1c90 100644 --- a/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_freeenvironmentstringsw_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/test.c b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/test.c deleted file mode 100644 index 1bb05cdb12..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/test.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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 FreeEnvironmentStringsW() function -** -** -**=========================================================*/ - -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - - WCHAR CapturedEnvironment[] = {'T','E','S','T','\0'}; - BOOL TheResult = 0; - LPWSTR lpCapturedEnvironment = NULL; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - lpCapturedEnvironment = (LPWSTR)malloc( sizeof(CapturedEnvironment) / - sizeof(CapturedEnvironment[0]) ); - - if ( lpCapturedEnvironment ) - { - memcpy( lpCapturedEnvironment, CapturedEnvironment, - sizeof(CapturedEnvironment) / sizeof(CapturedEnvironment[0]) ); - } - else - { - Fail( "malloc() failed to allocate memory.\n" ); - } - /* Even if this is not a valid Environment block, the function will - still return success - */ - - TheResult = FreeEnvironmentStrings( lpCapturedEnvironment ); - if(TheResult == 0) - { - Fail("The function should still return a success value even if it is " - "passed a LPWSTR which is not an environment block properly " - "aquired from GetEnvironmentStrings\n"); - } - - /* Even passing this function NULL, should still return a success value */ - TheResult = FreeEnvironmentStrings(NULL); - if(TheResult == 0) - { - Fail("The function should still return a success value even if pass " - "NULL.\n"); - } - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/test.cpp new file mode 100644 index 0000000000..1bb05cdb12 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FreeEnvironmentStringsW/test2/test.cpp @@ -0,0 +1,71 @@ +// 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 FreeEnvironmentStringsW() function +** +** +**=========================================================*/ + +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + + WCHAR CapturedEnvironment[] = {'T','E','S','T','\0'}; + BOOL TheResult = 0; + LPWSTR lpCapturedEnvironment = NULL; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + lpCapturedEnvironment = (LPWSTR)malloc( sizeof(CapturedEnvironment) / + sizeof(CapturedEnvironment[0]) ); + + if ( lpCapturedEnvironment ) + { + memcpy( lpCapturedEnvironment, CapturedEnvironment, + sizeof(CapturedEnvironment) / sizeof(CapturedEnvironment[0]) ); + } + else + { + Fail( "malloc() failed to allocate memory.\n" ); + } + /* Even if this is not a valid Environment block, the function will + still return success + */ + + TheResult = FreeEnvironmentStrings( lpCapturedEnvironment ); + if(TheResult == 0) + { + Fail("The function should still return a success value even if it is " + "passed a LPWSTR which is not an environment block properly " + "aquired from GetEnvironmentStrings\n"); + } + + /* Even passing this function NULL, should still return a success value */ + TheResult = FreeEnvironmentStrings(NULL); + if(TheResult == 0) + { + Fail("The function should still return a success value even if pass " + "NULL.\n"); + } + + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/CMakeLists.txt index e3acf4061a..92cabba428 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetCalendarInfoW.c + GetCalendarInfoW.cpp ) add_executable(paltest_getcalendarinfow_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/GetCalendarInfoW.c b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/GetCalendarInfoW.c deleted file mode 100644 index 4876fe180f..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/GetCalendarInfoW.c +++ /dev/null @@ -1,57 +0,0 @@ -// 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: GetCalendarInfoW.c -** -** Purpose: Positive test the GetCalendarInfoW API. -** Call GetCalendarInfoW to retrieve the information of a -** calendar -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - LCID Locale = LOCALE_USER_DEFAULT; - CALTYPE CalType = CAL_ITWODIGITYEARMAX|CAL_RETURN_NUMBER; - DWORD dwValue; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - err = GetCalendarInfoW(Locale,/*locale idendifier*/ - CAL_GREGORIAN, /*calendar identifier*/ - CalType, /*calendar tyope*/ - NULL, /*buffer to store the retrieve info*/ - 0, /*alwayse zero*/ - &dwValue);/*to store the requrest data*/ - if (0 == err) - { - Fail("GetCalendarInfoW failed for CAL_GREGORIAN!\n"); - } - - err = GetCalendarInfoW(Locale,/*locale idendifier*/ - CAL_GREGORIAN_US, /*calendar identifier*/ - CalType, /*calendar tyope*/ - NULL, /*buffer to store the retreive info*/ - 0, /*alwayse zero*/ - &dwValue);/*to store the requrest data*/ - if (0 == err) - { - Fail("GetCalendarInfoW failed for CAL_GREGORIAN_US!\n"); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/GetCalendarInfoW.cpp b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/GetCalendarInfoW.cpp new file mode 100644 index 0000000000..4876fe180f --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test1/GetCalendarInfoW.cpp @@ -0,0 +1,57 @@ +// 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: GetCalendarInfoW.c +** +** Purpose: Positive test the GetCalendarInfoW API. +** Call GetCalendarInfoW to retrieve the information of a +** calendar +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + LCID Locale = LOCALE_USER_DEFAULT; + CALTYPE CalType = CAL_ITWODIGITYEARMAX|CAL_RETURN_NUMBER; + DWORD dwValue; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + err = GetCalendarInfoW(Locale,/*locale idendifier*/ + CAL_GREGORIAN, /*calendar identifier*/ + CalType, /*calendar tyope*/ + NULL, /*buffer to store the retrieve info*/ + 0, /*alwayse zero*/ + &dwValue);/*to store the requrest data*/ + if (0 == err) + { + Fail("GetCalendarInfoW failed for CAL_GREGORIAN!\n"); + } + + err = GetCalendarInfoW(Locale,/*locale idendifier*/ + CAL_GREGORIAN_US, /*calendar identifier*/ + CalType, /*calendar tyope*/ + NULL, /*buffer to store the retreive info*/ + 0, /*alwayse zero*/ + &dwValue);/*to store the requrest data*/ + if (0 == err) + { + Fail("GetCalendarInfoW failed for CAL_GREGORIAN_US!\n"); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/CMakeLists.txt index cbfd1aa5db..0cfc9679e7 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetCalendarInfoW.c + GetCalendarInfoW.cpp ) add_executable(paltest_getcalendarinfow_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/GetCalendarInfoW.c b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/GetCalendarInfoW.c deleted file mode 100644 index d8a59a0fc0..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/GetCalendarInfoW.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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: GetCalendarInfoW.c -** -** Purpose: Positive test the GetCalendarInfoW API. -** Call GetCalendarInfoW to retrieve the information of all -** calendars -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - int index = 0; - LCID Locale = LOCALE_USER_DEFAULT; - CALID Calendar; - CALTYPE CalType = CAL_ITWODIGITYEARMAX|CAL_RETURN_NUMBER; - DWORD dwValue; - char *CalendarID[]={"CAL_GREGORIAN", - "CAL_GREGORIAN_US", - "CAL_JAPAN", - "CAL_TAIWAN", - "CAL_KOREA", - "CAL_HIJRI", - "CAL_THAI", - "CAL_HEBREW", - "CAL_GREGORIAN_ME_FRENCH", - "CAL_GREGORIAN_ARABIC", - "CAL_GREGORIAN_XLIT_ENGLISH", - "CAL_GREGORIAN_XLIT_FRENCH", - "CAL_JULIAN"}; - - char errBuffer[1024]; - - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - memset(errBuffer, 0, 1024); - - for(index=0; index<13; index++) - { - Calendar = index + 1; - /*retrieve the specified calendar info*/ - err = GetCalendarInfoW(Locale,/*locale idendifier*/ - Calendar, /*calendar identifier*/ - CalType, /*calendar tyope*/ - NULL, /*buffer to store the retreive info*/ - 0, /*alwayse zero*/ - &dwValue);/*to store the requrest data*/ - if(0 == err) - { - strcat(errBuffer, CalendarID[index]); - strcat(errBuffer, ", "); - } - } - - - if(strlen(errBuffer) > 0) - { - Fail("\nFailed to call GetCalendarInfoW API by passing %s" - " Calendar identifier(s)\n",errBuffer); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/GetCalendarInfoW.cpp b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/GetCalendarInfoW.cpp new file mode 100644 index 0000000000..d8a59a0fc0 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetCalendarInfoW/test2/GetCalendarInfoW.cpp @@ -0,0 +1,79 @@ +// 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: GetCalendarInfoW.c +** +** Purpose: Positive test the GetCalendarInfoW API. +** Call GetCalendarInfoW to retrieve the information of all +** calendars +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + int index = 0; + LCID Locale = LOCALE_USER_DEFAULT; + CALID Calendar; + CALTYPE CalType = CAL_ITWODIGITYEARMAX|CAL_RETURN_NUMBER; + DWORD dwValue; + char *CalendarID[]={"CAL_GREGORIAN", + "CAL_GREGORIAN_US", + "CAL_JAPAN", + "CAL_TAIWAN", + "CAL_KOREA", + "CAL_HIJRI", + "CAL_THAI", + "CAL_HEBREW", + "CAL_GREGORIAN_ME_FRENCH", + "CAL_GREGORIAN_ARABIC", + "CAL_GREGORIAN_XLIT_ENGLISH", + "CAL_GREGORIAN_XLIT_FRENCH", + "CAL_JULIAN"}; + + char errBuffer[1024]; + + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + memset(errBuffer, 0, 1024); + + for(index=0; index<13; index++) + { + Calendar = index + 1; + /*retrieve the specified calendar info*/ + err = GetCalendarInfoW(Locale,/*locale idendifier*/ + Calendar, /*calendar identifier*/ + CalType, /*calendar tyope*/ + NULL, /*buffer to store the retreive info*/ + 0, /*alwayse zero*/ + &dwValue);/*to store the requrest data*/ + if(0 == err) + { + strcat(errBuffer, CalendarID[index]); + strcat(errBuffer, ", "); + } + } + + + if(strlen(errBuffer) > 0) + { + Fail("\nFailed to call GetCalendarInfoW API by passing %s" + " Calendar identifier(s)\n",errBuffer); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/CMakeLists.txt index 491fdca9b5..d15b84a59e 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getcommandlinew_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/test.c deleted file mode 100644 index d8a81746b6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/test.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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 GetCommandLineW() function -** -** -**=========================================================*/ - -#define UNICODE -#include - -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 = malloc(1024); - wcscpy(CommandLine,convert(argv[0])); - - for(i=1;i + +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 - -int __cdecl main(int argc, char *argv[]) -{ - - int HOST_NAME_MAX = 255; - WCHAR wzComputerName[HOST_NAME_MAX+1]; - DWORD dwSize = sizeof(wzComputerName)/sizeof(wzComputerName[0]); - - // Initialize the PAL and return FAILURE if this fails - if(0 != (PAL_Initialize(argc, argv))) - { - Fail ("ERROR: PAL_Initialize() call failed!\n"); - } - - if (0 == GetComputerName(wzComputerName, &dwSize)) - { - Fail("ERROR: GetComputerName failed with %d!\n", GetLastError()); - } - - // dwSize is the length of wzComputerName without NULL - if (dwSize < 0 || dwSize > (sizeof(wzComputerName)/sizeof(wzComputerName[0]) - 1)) - { - Fail("ERROR: GetComputerName returned %S with dwSize = %u whereas the passed in buffer size is %d!\n", - wzComputerName, dwSize, sizeof(wzComputerName)/sizeof(wzComputerName[0])); - } - - // dwSize is the length of wzComputerName without NULL - if (dwSize != wcslen(wzComputerName)) - { - Fail("ERROR: GetComputerName returned %S of length %d which is not equal to dwSize = %u!\n", - wzComputerName, wcslen(wzComputerName), dwSize); - } - - printf ("GetComputerName returned %S of length %u\n", wzComputerName, dwSize); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/GetComputerNameW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetComputerNameW/test1/test.cpp new file mode 100644 index 0000000000..7a00cad598 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetComputerNameW/test1/test.cpp @@ -0,0 +1,53 @@ +// 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: Positive Test for GetComputerName() function +** +** +**=========================================================*/ + +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + + int HOST_NAME_MAX = 255; + WCHAR wzComputerName[HOST_NAME_MAX+1]; + DWORD dwSize = sizeof(wzComputerName)/sizeof(wzComputerName[0]); + + // Initialize the PAL and return FAILURE if this fails + if(0 != (PAL_Initialize(argc, argv))) + { + Fail ("ERROR: PAL_Initialize() call failed!\n"); + } + + if (0 == GetComputerName(wzComputerName, &dwSize)) + { + Fail("ERROR: GetComputerName failed with %d!\n", GetLastError()); + } + + // dwSize is the length of wzComputerName without NULL + if (dwSize < 0 || dwSize > (sizeof(wzComputerName)/sizeof(wzComputerName[0]) - 1)) + { + Fail("ERROR: GetComputerName returned %S with dwSize = %u whereas the passed in buffer size is %d!\n", + wzComputerName, dwSize, sizeof(wzComputerName)/sizeof(wzComputerName[0])); + } + + // dwSize is the length of wzComputerName without NULL + if (dwSize != wcslen(wzComputerName)) + { + Fail("ERROR: GetComputerName returned %S of length %d which is not equal to dwSize = %u!\n", + wzComputerName, wcslen(wzComputerName), dwSize); + } + + printf ("GetComputerName returned %S of length %u\n", wzComputerName, dwSize); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/CMakeLists.txt index 5a340c6cfb..04ef85b74d 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetDateFormatW_neg.c + GetDateFormatW_neg.cpp ) add_executable(paltest_getdateformatw_getdateformatw_neg1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.c b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.c deleted file mode 100644 index c64dc74cb6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: GetDateFormatW_neg.c -** -** Purpose: Negative test the GetDateFormatW API. -** Call GetDateFormatW by passing an invalid parameter -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - WCHAR *wpFormat; - LPCSTR lpString = "gg"; - CONST SYSTEMTIME *lpDate = NULL; - LCID DefaultLocale; - DWORD dwFlags; - int DateSize; - WCHAR *wpBuffer = NULL; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*convert to a wide character string*/ - wpFormat = convert((char *)lpString); - - dwFlags = DATE_USE_ALT_CALENDAR; /*set the flags*/ - - - DateSize = 0; - - /*retrieve the buffer size*/ - DateSize = GetDateFormatW( - DefaultLocale, /*system default locale*/ - dwFlags, /*function option*/ - (SYSTEMTIME *)lpDate, /*always is NULL*/ - wpFormat, /*pointer to a picture string*/ - wpBuffer, /*out buffer*/ - DateSize); /*buffer size*/ - - if(DateSize <= 0) - { - free(wpFormat); - Fail("\nRetrieved an invalid buffer size\n"); - } - - wpBuffer = malloc((DateSize + 1)*sizeof(WCHAR)); - if(NULL == wpBuffer) - { - free(wpFormat); - Fail("\nFailed to allocate memory to store the formatted string\n"); - } - - /*format a date by passing an invalid locale indentifier*/ - err = GetDateFormatW( - -1, /*invalid locale identifier*/ - dwFlags, /*function option*/ - (SYSTEMTIME *)lpDate, /*always is NULL, or use system date*/ - wpFormat, /*pointer to a picture string*/ - wpBuffer, /*out buffer*/ - DateSize); /*buffer size*/ - - free(wpBuffer); - free(wpFormat); - - if(0 != err || GetLastError() != ERROR_INVALID_PARAMETER) - { - Fail("\nFailed to call GetDateFormatW for a negative test by " - "passing an invalid parameter, error code=%d\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.cpp b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.cpp new file mode 100644 index 0000000000..96a481167f --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.cpp @@ -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: GetDateFormatW_neg.c +** +** Purpose: Negative test the GetDateFormatW API. +** Call GetDateFormatW by passing an invalid parameter +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + WCHAR *wpFormat; + LPCSTR lpString = "gg"; + CONST SYSTEMTIME *lpDate = NULL; + LCID DefaultLocale; + DWORD dwFlags; + int DateSize; + WCHAR *wpBuffer = NULL; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*convert to a wide character string*/ + wpFormat = convert((char *)lpString); + + dwFlags = DATE_USE_ALT_CALENDAR; /*set the flags*/ + + + DateSize = 0; + + /*retrieve the buffer size*/ + DateSize = GetDateFormatW( + DefaultLocale, /*system default locale*/ + dwFlags, /*function option*/ + (SYSTEMTIME *)lpDate, /*always is NULL*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + if(DateSize <= 0) + { + free(wpFormat); + Fail("\nRetrieved an invalid buffer size\n"); + } + + wpBuffer = (WCHAR*)malloc((DateSize + 1)*sizeof(WCHAR)); + if(NULL == wpBuffer) + { + free(wpFormat); + Fail("\nFailed to allocate memory to store the formatted string\n"); + } + + /*format a date by passing an invalid locale indentifier*/ + err = GetDateFormatW( + -1, /*invalid locale identifier*/ + dwFlags, /*function option*/ + (SYSTEMTIME *)lpDate, /*always is NULL, or use system date*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + free(wpBuffer); + free(wpFormat); + + if(0 != err || GetLastError() != ERROR_INVALID_PARAMETER) + { + Fail("\nFailed to call GetDateFormatW for a negative test by " + "passing an invalid parameter, error code=%d\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/CMakeLists.txt index 646de9160b..fcd56fc7f2 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetDateFormatW_neg.c + GetDateFormatW_neg.cpp ) add_executable(paltest_getdateformatw_getdateformatw_neg2 diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.c b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.c deleted file mode 100644 index 676038f03a..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.c +++ /dev/null @@ -1,98 +0,0 @@ -// 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: GetDateFormatW_neg.c -** -** Purpose: Negative test the GetDateFormatW API. -** Call GetDateFormatW by passing an invalid flag -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - WCHAR *wpFormat; - LPCSTR lpString = "gg"; - CONST SYSTEMTIME *lpDate = NULL; - LCID DefaultLocale; - DWORD dwFlags; - int DateSize; - WCHAR *wpBuffer = NULL; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*convert to a wide character string*/ - wpFormat = convert((char *)lpString); - - /* - DefaultLocale = GetSystemDefaultLCID() which is not defined in PAL; - - LOCALE_SYSTEM_DEFAULT = MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT) - - LANG_SYSTEM_DEFAULT = MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT); - SUBLANG_SYS_DEFAULT is not defined in PAL, here use hardcoding, - the value is from winnt.h - */ - - DefaultLocale = MAKELCID(MAKELANGID(LANG_NEUTRAL, 0x02), SORT_DEFAULT); - - dwFlags = DATE_USE_ALT_CALENDAR; /*set the flags*/ - - - DateSize = 0; - - /*retrieve the buffer size*/ - DateSize = GetDateFormatW( - DefaultLocale, /*system default locale*/ - dwFlags, /*function option*/ - (SYSTEMTIME *)lpDate, /*always is NULL*/ - wpFormat, /*pointer to a picture string*/ - wpBuffer, /*out buffer*/ - DateSize); /*buffer size*/ - - if(DateSize <= 0) - { - free(wpFormat); - Fail("\nRetrieved an invalid buffer size\n"); - } - - wpBuffer = malloc((DateSize + 1)*sizeof(WCHAR)); - if(NULL == wpBuffer) - { - free(wpFormat); - Fail("\nFailed to allocate memory to store the formatted string\n"); - } - - err = GetDateFormatW( - DefaultLocale, /*system default locale*/ - 0x00000001|0x00000008,/*DATE_SHORTDATE|DATE_YEARMONTH */ - /*an invalid flag*/ - (SYSTEMTIME *)lpDate, /*always is NULL, or use system date*/ - wpFormat, /*pointer to a picture string*/ - wpBuffer, /*out buffer*/ - DateSize); /*buffer size*/ - - free(wpBuffer); - free(wpFormat); - - if(0 != err || GetLastError() != ERROR_INVALID_FLAGS) - { - Fail("\nFailed to call GetDateFormatW for a negative test by " - "passing an invalid flag, error code=%d\n", GetLastError()); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.cpp b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.cpp new file mode 100644 index 0000000000..43f32cf69e --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.cpp @@ -0,0 +1,98 @@ +// 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: GetDateFormatW_neg.c +** +** Purpose: Negative test the GetDateFormatW API. +** Call GetDateFormatW by passing an invalid flag +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + WCHAR *wpFormat; + LPCSTR lpString = "gg"; + CONST SYSTEMTIME *lpDate = NULL; + LCID DefaultLocale; + DWORD dwFlags; + int DateSize; + WCHAR *wpBuffer = NULL; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*convert to a wide character string*/ + wpFormat = convert((char *)lpString); + + /* + DefaultLocale = GetSystemDefaultLCID() which is not defined in PAL; + + LOCALE_SYSTEM_DEFAULT = MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT) + + LANG_SYSTEM_DEFAULT = MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT); + SUBLANG_SYS_DEFAULT is not defined in PAL, here use hardcoding, + the value is from winnt.h + */ + + DefaultLocale = MAKELCID(MAKELANGID(LANG_NEUTRAL, 0x02), SORT_DEFAULT); + + dwFlags = DATE_USE_ALT_CALENDAR; /*set the flags*/ + + + DateSize = 0; + + /*retrieve the buffer size*/ + DateSize = GetDateFormatW( + DefaultLocale, /*system default locale*/ + dwFlags, /*function option*/ + (SYSTEMTIME *)lpDate, /*always is NULL*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + if(DateSize <= 0) + { + free(wpFormat); + Fail("\nRetrieved an invalid buffer size\n"); + } + + wpBuffer = (WCHAR*)malloc((DateSize + 1)*sizeof(WCHAR)); + if(NULL == wpBuffer) + { + free(wpFormat); + Fail("\nFailed to allocate memory to store the formatted string\n"); + } + + err = GetDateFormatW( + DefaultLocale, /*system default locale*/ + 0x00000001|0x00000008,/*DATE_SHORTDATE|DATE_YEARMONTH */ + /*an invalid flag*/ + (SYSTEMTIME *)lpDate, /*always is NULL, or use system date*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + free(wpBuffer); + free(wpFormat); + + if(0 != err || GetLastError() != ERROR_INVALID_FLAGS) + { + Fail("\nFailed to call GetDateFormatW for a negative test by " + "passing an invalid flag, error code=%d\n", GetLastError()); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/CMakeLists.txt index 8c1e4b024e..bd86370611 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - GetDateFormatW.c + GetDateFormatW.cpp ) add_executable(paltest_getdateformatw_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c deleted file mode 100644 index 264e397a49..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c +++ /dev/null @@ -1,100 +0,0 @@ -// 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: GetDateFormatW.c -** -** Purpose: Positive test the GetDateFormatW API. -** Call GetDateFormatW to format a date string for -** a specified locale -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - WCHAR *wpFormat; - LPCSTR lpString = "gg"; - CONST SYSTEMTIME *lpDate = NULL; - LCID DefaultLocale; - DWORD dwFlags; - int DateSize; - WCHAR *wpBuffer = NULL; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*convert to a wide character string*/ - wpFormat = convert((char *)lpString); - - /* - DefaultLocale = GetSystemDefaultLCID() which is not defined in PAL; - - LOCALE_SYSTEM_DEFAULT = MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT) - - LANG_SYSTEM_DEFAULT = MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT); - SUBLANG_SYS_DEFAULT is not defined in PAL, here use hardcoding, - the value is from winnt.h - */ - DefaultLocale = MAKELCID(MAKELANGID(LANG_NEUTRAL, 0x02), SORT_DEFAULT); - - dwFlags = DATE_USE_ALT_CALENDAR; /*set the flags*/ - - - DateSize = 0; - - /*retrieve the buffer size*/ - DateSize = GetDateFormatW( - DefaultLocale, /*system default locale*/ - dwFlags, /*function option*/ - (SYSTEMTIME *)lpDate, /*always is NULL*/ - wpFormat, /*pointer to a picture string*/ - wpBuffer, /*out buffer*/ - DateSize); /*buffer size*/ - - if(DateSize <= 0) - { - free(wpFormat); - Fail("\nRetrieved an invalid buffer size\n"); - } - - - wpBuffer = malloc((DateSize+1)*sizeof(WCHAR)); - if(NULL == wpBuffer) - { - free(wpFormat); - Fail("\nFailed to allocate memory to store a formatted string\n"); - } - - /*retrieve the formatted string for a specified locale*/ - err = GetDateFormatW( - DefaultLocale, /*system default locale*/ - dwFlags, /*function option*/ - (SYSTEMTIME *)lpDate, /*always is NULL*/ - wpFormat, /*pointer to a picture string*/ - wpBuffer, /*out buffer*/ - DateSize); /*buffer size*/ - - if(0 == err) - { - free(wpBuffer); - free(wpFormat); - Fail("\nFailed to call GetDateFormatW to format a system data " - "as a data string for system default locale!\n"); - } - - free(wpBuffer); - free(wpFormat); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.cpp b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.cpp new file mode 100644 index 0000000000..6e3c3b4894 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.cpp @@ -0,0 +1,100 @@ +// 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: GetDateFormatW.c +** +** Purpose: Positive test the GetDateFormatW API. +** Call GetDateFormatW to format a date string for +** a specified locale +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + WCHAR *wpFormat; + LPCSTR lpString = "gg"; + CONST SYSTEMTIME *lpDate = NULL; + LCID DefaultLocale; + DWORD dwFlags; + int DateSize; + WCHAR *wpBuffer = NULL; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*convert to a wide character string*/ + wpFormat = convert((char *)lpString); + + /* + DefaultLocale = GetSystemDefaultLCID() which is not defined in PAL; + + LOCALE_SYSTEM_DEFAULT = MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT) + + LANG_SYSTEM_DEFAULT = MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT); + SUBLANG_SYS_DEFAULT is not defined in PAL, here use hardcoding, + the value is from winnt.h + */ + DefaultLocale = MAKELCID(MAKELANGID(LANG_NEUTRAL, 0x02), SORT_DEFAULT); + + dwFlags = DATE_USE_ALT_CALENDAR; /*set the flags*/ + + + DateSize = 0; + + /*retrieve the buffer size*/ + DateSize = GetDateFormatW( + DefaultLocale, /*system default locale*/ + dwFlags, /*function option*/ + (SYSTEMTIME *)lpDate, /*always is NULL*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + if(DateSize <= 0) + { + free(wpFormat); + Fail("\nRetrieved an invalid buffer size\n"); + } + + + wpBuffer = (WCHAR*)malloc((DateSize+1)*sizeof(WCHAR)); + if(NULL == wpBuffer) + { + free(wpFormat); + Fail("\nFailed to allocate memory to store a formatted string\n"); + } + + /*retrieve the formatted string for a specified locale*/ + err = GetDateFormatW( + DefaultLocale, /*system default locale*/ + dwFlags, /*function option*/ + (SYSTEMTIME *)lpDate, /*always is NULL*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + if(0 == err) + { + free(wpBuffer); + free(wpFormat); + Fail("\nFailed to call GetDateFormatW to format a system data " + "as a data string for system default locale!\n"); + } + + free(wpBuffer); + free(wpFormat); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/CMakeLists.txt index 306400e558..3a745fdbd3 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getenvironmentstringsw_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/test.c deleted file mode 100644 index 2bd9153e59..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/test.c +++ /dev/null @@ -1,81 +0,0 @@ -// 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 GetEnvironmentStringsW() function -** -** -**=========================================================*/ - -/* Depends on SetEnvironmentVariable(), wcsstr() and wcslen() */ - -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) { - - LPWSTR CapturedEnvironmentStrings = NULL; - LPWSTR EnviroStringReturned = NULL; - WCHAR EnvironmentVariableBuffer[] = - {'P','A','L','T','E','S','T','I','N','G','\0'}; - WCHAR EnvironmentValueBuffer[] = {'T','e','s','t','i','n','g','\0'}; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* This test depends on SetEnvironmentVariableW working. - We need to set a variable so we can test and ensure it's there - when we get them back - */ - - SetEnvironmentVariable(EnvironmentVariableBuffer,EnvironmentValueBuffer); - - CapturedEnvironmentStrings = GetEnvironmentStrings(); - - /* If it's pointing to NULL, it failed. */ - if(CapturedEnvironmentStrings == NULL) { - Fail("The function returned a pointer to NULL, which it shouldn't do. " - "It should point to a block of Environment Strings.\n"); - } - - /* Now that we've grabbed the list of envrionment strings, go through - each one, and check for a match to 'PALTESTING'. If this is missing - it's not pointing at the environment block. - */ - - while(*CapturedEnvironmentStrings != 0) - { - EnviroStringReturned = wcsstr(CapturedEnvironmentStrings, - EnvironmentVariableBuffer); - CapturedEnvironmentStrings += wcslen(CapturedEnvironmentStrings)+1; - if(EnviroStringReturned != NULL) - { - break; - } - } - - if(EnviroStringReturned == NULL) - { - Fail("The memory block returned was searched, but nothing was found to " - "prove this was really the environment block. Either this " - "function, SetEnvironmentVariable or wcsstr() is broken.\n"); - } - - - PAL_Terminate(); - return PASS; -} - - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/test.cpp new file mode 100644 index 0000000000..2bd9153e59 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/test.cpp @@ -0,0 +1,81 @@ +// 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 GetEnvironmentStringsW() function +** +** +**=========================================================*/ + +/* Depends on SetEnvironmentVariable(), wcsstr() and wcslen() */ + +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) { + + LPWSTR CapturedEnvironmentStrings = NULL; + LPWSTR EnviroStringReturned = NULL; + WCHAR EnvironmentVariableBuffer[] = + {'P','A','L','T','E','S','T','I','N','G','\0'}; + WCHAR EnvironmentValueBuffer[] = {'T','e','s','t','i','n','g','\0'}; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* This test depends on SetEnvironmentVariableW working. + We need to set a variable so we can test and ensure it's there + when we get them back + */ + + SetEnvironmentVariable(EnvironmentVariableBuffer,EnvironmentValueBuffer); + + CapturedEnvironmentStrings = GetEnvironmentStrings(); + + /* If it's pointing to NULL, it failed. */ + if(CapturedEnvironmentStrings == NULL) { + Fail("The function returned a pointer to NULL, which it shouldn't do. " + "It should point to a block of Environment Strings.\n"); + } + + /* Now that we've grabbed the list of envrionment strings, go through + each one, and check for a match to 'PALTESTING'. If this is missing + it's not pointing at the environment block. + */ + + while(*CapturedEnvironmentStrings != 0) + { + EnviroStringReturned = wcsstr(CapturedEnvironmentStrings, + EnvironmentVariableBuffer); + CapturedEnvironmentStrings += wcslen(CapturedEnvironmentStrings)+1; + if(EnviroStringReturned != NULL) + { + break; + } + } + + if(EnviroStringReturned == NULL) + { + Fail("The memory block returned was searched, but nothing was found to " + "prove this was really the environment block. Either this " + "function, SetEnvironmentVariable or wcsstr() is broken.\n"); + } + + + PAL_Terminate(); + return PASS; +} + + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/CMakeLists.txt index 184a6ef1f0..0721fd60b7 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getenvironmentvariablea_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/test.c deleted file mode 100644 index 8862e823bc..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/test.c +++ /dev/null @@ -1,84 +0,0 @@ -// 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 GetEnvironmentVariable() function -** Assign a properly sized buffer and get an environment -** variable, check to ensure it returns the correct values. -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) { - - /* Define some buffers needed for the function */ - char * pResultBuffer = NULL; - int size = 0; - - /* A place to stash the returned values */ - int ReturnValueForLargeBuffer = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Recieve and allocate the correct amount of memory for the buffer */ - size = ReturnValueForLargeBuffer = GetEnvironmentVariable("PATH", - pResultBuffer, - 0); - pResultBuffer = malloc(size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer. " - "Can't properly exec test case without this.\n"); - } - - - /* Normal case, PATH should fit into this buffer */ - ReturnValueForLargeBuffer = GetEnvironmentVariable("PATH", - pResultBuffer, - size); - - /* Ensure that it returned a positive value */ - if(ReturnValueForLargeBuffer <= 0) - { - free(pResultBuffer); - - Fail("The return was %d, which indicates that the function failed.\n", - ReturnValueForLargeBuffer); - } - - /* Ensure that it succeeded and copied the correct number of characters. - If this is true, then the return value should be one less of the size of - the buffer. (Doesn't include that NULL byte) - */ - - if(ReturnValueForLargeBuffer != size-1) - { - free(pResultBuffer); - - Fail("The value returned was %d when it should have been %d. " - "This should be the number of characters copied, minus the " - "NULL byte.\n",ReturnValueForLargeBuffer, size-1); - } - - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/test.cpp new file mode 100644 index 0000000000..23e9974467 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test1/test.cpp @@ -0,0 +1,84 @@ +// 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 GetEnvironmentVariable() function +** Assign a properly sized buffer and get an environment +** variable, check to ensure it returns the correct values. +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) { + + /* Define some buffers needed for the function */ + char * pResultBuffer = NULL; + int size = 0; + + /* A place to stash the returned values */ + int ReturnValueForLargeBuffer = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Recieve and allocate the correct amount of memory for the buffer */ + size = ReturnValueForLargeBuffer = GetEnvironmentVariable("PATH", + pResultBuffer, + 0); + pResultBuffer = (char*)malloc(size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer. " + "Can't properly exec test case without this.\n"); + } + + + /* Normal case, PATH should fit into this buffer */ + ReturnValueForLargeBuffer = GetEnvironmentVariable("PATH", + pResultBuffer, + size); + + /* Ensure that it returned a positive value */ + if(ReturnValueForLargeBuffer <= 0) + { + free(pResultBuffer); + + Fail("The return was %d, which indicates that the function failed.\n", + ReturnValueForLargeBuffer); + } + + /* Ensure that it succeeded and copied the correct number of characters. + If this is true, then the return value should be one less of the size of + the buffer. (Doesn't include that NULL byte) + */ + + if(ReturnValueForLargeBuffer != size-1) + { + free(pResultBuffer); + + Fail("The value returned was %d when it should have been %d. " + "This should be the number of characters copied, minus the " + "NULL byte.\n",ReturnValueForLargeBuffer, size-1); + } + + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/CMakeLists.txt index abfd73f458..a9be983369 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getenvironmentvariablea_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/test.c deleted file mode 100644 index d26588e907..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/test.c +++ /dev/null @@ -1,56 +0,0 @@ -// 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 GetEnvironmentVariable() function -** Pass a small buffer to GetEnvironmentVariableA to ensure -** it returns the size it requires. -** -** -**=========================================================*/ - -#include - -#define SMALL_BUFFER_SIZE 1 - -int __cdecl main(int argc, char *argv[]) { - - /* A place to stash the returned values */ - int ReturnValueForSmallBuffer = 0; - - char pSmallBuffer[SMALL_BUFFER_SIZE]; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* PATH won't fit in this buffer, it should return how many - characters it needs - */ - - ReturnValueForSmallBuffer = GetEnvironmentVariable("PATH", - pSmallBuffer, - SMALL_BUFFER_SIZE); - if(ReturnValueForSmallBuffer <= 0) - { - Fail("The return value was %d when it should have been greater " - "than 0. " - "This should return the number of characters needed to contained " - "the contents of PATH in a buffer.\n",ReturnValueForSmallBuffer); - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/test.cpp new file mode 100644 index 0000000000..d26588e907 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test2/test.cpp @@ -0,0 +1,56 @@ +// 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 GetEnvironmentVariable() function +** Pass a small buffer to GetEnvironmentVariableA to ensure +** it returns the size it requires. +** +** +**=========================================================*/ + +#include + +#define SMALL_BUFFER_SIZE 1 + +int __cdecl main(int argc, char *argv[]) { + + /* A place to stash the returned values */ + int ReturnValueForSmallBuffer = 0; + + char pSmallBuffer[SMALL_BUFFER_SIZE]; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* PATH won't fit in this buffer, it should return how many + characters it needs + */ + + ReturnValueForSmallBuffer = GetEnvironmentVariable("PATH", + pSmallBuffer, + SMALL_BUFFER_SIZE); + if(ReturnValueForSmallBuffer <= 0) + { + Fail("The return value was %d when it should have been greater " + "than 0. " + "This should return the number of characters needed to contained " + "the contents of PATH in a buffer.\n",ReturnValueForSmallBuffer); + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/CMakeLists.txt index a63c11b1a3..1c35eba54d 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getenvironmentvariablea_test3 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/test.c deleted file mode 100644 index b51e139c95..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/test.c +++ /dev/null @@ -1,67 +0,0 @@ -// 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 GetEnvironmentVariable() function -** Pass a nonexisting environment variable and a null to -** the function to check return values. -** -** -**=========================================================*/ - -#include - -#define BUFFER_SIZE 5000 -#define SMALL_BUFFER_SIZE 5 - -int __cdecl main(int argc, char *argv[]) -{ - - int ReturnValueForNonExisting = 0; - int ReturnValueForNull = 0; - - char pResultBuffer[BUFFER_SIZE]; - char pSmallBuffer[SMALL_BUFFER_SIZE]; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* This variable doesn't exist, it should return 0 */ - ReturnValueForNonExisting = GetEnvironmentVariable("NonExistingVariable", - pSmallBuffer, - SMALL_BUFFER_SIZE); - - if(ReturnValueForNonExisting != 0) - { - Fail("ERROR: The return should have been 0, but it was %d. " - "The function attempted to get an Environment Variable that " - "doesn't exist and should return 0 as a result.\n", - ReturnValueForNonExisting); - } - - - /* Passing a NULL string should return 0 */ - ReturnValueForNull = GetEnvironmentVariable(NULL, - pResultBuffer, - BUFFER_SIZE); - - if(ReturnValueForNull != 0) - { - Fail("ERROR: The return should have been 0, but it was %d. " - "The function attempted to get a NULL pointer and should return " - "0 as a result.\n",ReturnValueForNull); - - } - - PAL_Terminate(); - return PASS; - } - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/test.cpp new file mode 100644 index 0000000000..b51e139c95 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test3/test.cpp @@ -0,0 +1,67 @@ +// 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 GetEnvironmentVariable() function +** Pass a nonexisting environment variable and a null to +** the function to check return values. +** +** +**=========================================================*/ + +#include + +#define BUFFER_SIZE 5000 +#define SMALL_BUFFER_SIZE 5 + +int __cdecl main(int argc, char *argv[]) +{ + + int ReturnValueForNonExisting = 0; + int ReturnValueForNull = 0; + + char pResultBuffer[BUFFER_SIZE]; + char pSmallBuffer[SMALL_BUFFER_SIZE]; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* This variable doesn't exist, it should return 0 */ + ReturnValueForNonExisting = GetEnvironmentVariable("NonExistingVariable", + pSmallBuffer, + SMALL_BUFFER_SIZE); + + if(ReturnValueForNonExisting != 0) + { + Fail("ERROR: The return should have been 0, but it was %d. " + "The function attempted to get an Environment Variable that " + "doesn't exist and should return 0 as a result.\n", + ReturnValueForNonExisting); + } + + + /* Passing a NULL string should return 0 */ + ReturnValueForNull = GetEnvironmentVariable(NULL, + pResultBuffer, + BUFFER_SIZE); + + if(ReturnValueForNull != 0) + { + Fail("ERROR: The return should have been 0, but it was %d. " + "The function attempted to get a NULL pointer and should return " + "0 as a result.\n",ReturnValueForNull); + + } + + PAL_Terminate(); + return PASS; + } + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/CMakeLists.txt index 76cfdb6d49..331ea8ca6b 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getenvironmentvariablea_test4 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/test.c deleted file mode 100644 index 1fea5719b4..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/test.c +++ /dev/null @@ -1,75 +0,0 @@ -// 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 GetEnvironmentVariable() function -** Set an Environment Variable, then use GetEnvironmentVariable to -** retrieve it -- ensure that it retrieves properly. -** -** -**=========================================================*/ - -/* Depends on SetEnvironmentVariableW (because we're implmenting - the wide version) and strcmp() -*/ - -#include - -int __cdecl main(int argc, char *argv[]) { - - /* Define some buffers needed for the function */ - char * pResultBuffer = NULL; - WCHAR SomeEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; - WCHAR TheEnvironmentValue[] = {'T','E','S','T','\0'}; - int size = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - SetEnvironmentVariableW(SomeEnvironmentVariable, - TheEnvironmentValue); - - - /* Normal case, PATH should fit into this buffer */ - size = GetEnvironmentVariable("PALTEST", // Variable Name - pResultBuffer, // Buffer for Value - 0); // Buffer size - - pResultBuffer = malloc(size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer. " - "Can't properly exec test case without this.\n"); - } - - - GetEnvironmentVariable("PALTEST", - pResultBuffer, - size); - - if(strcmp(pResultBuffer,"TEST") != 0) - { - free(pResultBuffer); - Fail("ERROR: The value in the buffer should have been 'TEST' but " - "was really '%s'.\n",pResultBuffer); - - } - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/test.cpp new file mode 100644 index 0000000000..a09eb883e3 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test4/test.cpp @@ -0,0 +1,75 @@ +// 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 GetEnvironmentVariable() function +** Set an Environment Variable, then use GetEnvironmentVariable to +** retrieve it -- ensure that it retrieves properly. +** +** +**=========================================================*/ + +/* Depends on SetEnvironmentVariableW (because we're implmenting + the wide version) and strcmp() +*/ + +#include + +int __cdecl main(int argc, char *argv[]) { + + /* Define some buffers needed for the function */ + char * pResultBuffer = NULL; + WCHAR SomeEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR TheEnvironmentValue[] = {'T','E','S','T','\0'}; + int size = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + SetEnvironmentVariableW(SomeEnvironmentVariable, + TheEnvironmentValue); + + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariable("PALTEST", // Variable Name + pResultBuffer, // Buffer for Value + 0); // Buffer size + + pResultBuffer = (char*)malloc(size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer. " + "Can't properly exec test case without this.\n"); + } + + + GetEnvironmentVariable("PALTEST", + pResultBuffer, + size); + + if(strcmp(pResultBuffer,"TEST") != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been 'TEST' but " + "was really '%s'.\n",pResultBuffer); + + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/CMakeLists.txt index 548d86bb03..69bedf4947 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_getenvironmentvariablea_test5 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/test5.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/test5.c deleted file mode 100644 index 8d63a1aecb..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/test5.c +++ /dev/null @@ -1,145 +0,0 @@ -// 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 : test5.c -** -** Purpose: Test for GetEnvironmentVariableA() function -** Create environment variables that differ only -** in case and verify that they return the appropriate -** value on the BSD environment. -** -** -===========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - - return PASS; - -#else - - /* Define some buffers needed for the function */ - char * pResultBuffer = NULL; - - char FirstEnvironmentVariable[] = {"PALTEST"}; - char FirstEnvironmentValue[] = {"FIRST"}; - - char SecondEnvironmentVariable[] = {"paltest"}; - char SecondEnvironmentValue[] = {"SECOND"}; - - DWORD size = 0; - BOOL bRc = TRUE; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Set the first environment variable */ - bRc = SetEnvironmentVariableA(FirstEnvironmentVariable, - FirstEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", GetLastError()); - } - - - /* Normal case, PATH should fit into this buffer */ - size = GetEnvironmentVariableA(FirstEnvironmentVariable, - pResultBuffer, - 0); - - /* To account for the null character at the end of the string */ - size = size + 1; - - pResultBuffer = malloc(sizeof(char)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer\n."); - } - - /* Try to retrieve the value of the first environment variable */ - GetEnvironmentVariableA(FirstEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - free(pResultBuffer); - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the strings to see that the correct variable was returned */ - if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) - { - free(pResultBuffer); - Fail("ERROR: The value in the buffer should have been '%s' but " - "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer); - } - - free(pResultBuffer); - - /* Set the second environment Variable */ - bRc = SetEnvironmentVariableA(SecondEnvironmentVariable, - SecondEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - /* Reallocate the memory for the string */ - pResultBuffer = malloc(sizeof(char)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer."); - } - - /* Try retrieving the value of the first variable, even though the - second variable has the same spelling and only differs in case */ - GetEnvironmentVariableA(FirstEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - free(pResultBuffer); - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the two strings to confirm that the right value is returned */ - if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) - { - free(pResultBuffer); - Fail("ERROR: The value in the buffer should have been '%s' but " - "was really '%s'.\n",FirstEnvironmentValue,pResultBuffer); - } - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; - -#endif -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/test5.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/test5.cpp new file mode 100644 index 0000000000..19a4d25b64 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test5/test5.cpp @@ -0,0 +1,145 @@ +// 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 : test5.c +** +** Purpose: Test for GetEnvironmentVariableA() function +** Create environment variables that differ only +** in case and verify that they return the appropriate +** value on the BSD environment. +** +** +===========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + + return PASS; + +#else + + /* Define some buffers needed for the function */ + char * pResultBuffer = NULL; + + char FirstEnvironmentVariable[] = {"PALTEST"}; + char FirstEnvironmentValue[] = {"FIRST"}; + + char SecondEnvironmentVariable[] = {"paltest"}; + char SecondEnvironmentValue[] = {"SECOND"}; + + DWORD size = 0; + BOOL bRc = TRUE; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set the first environment variable */ + bRc = SetEnvironmentVariableA(FirstEnvironmentVariable, + FirstEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", GetLastError()); + } + + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariableA(FirstEnvironmentVariable, + pResultBuffer, + 0); + + /* To account for the null character at the end of the string */ + size = size + 1; + + pResultBuffer = (char*)malloc(sizeof(char)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer\n."); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariableA(FirstEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + free(pResultBuffer); + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the strings to see that the correct variable was returned */ + if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been '%s' but " + "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer); + } + + free(pResultBuffer); + + /* Set the second environment Variable */ + bRc = SetEnvironmentVariableA(SecondEnvironmentVariable, + SecondEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Reallocate the memory for the string */ + pResultBuffer = (char*)malloc(sizeof(char)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer."); + } + + /* Try retrieving the value of the first variable, even though the + second variable has the same spelling and only differs in case */ + GetEnvironmentVariableA(FirstEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + free(pResultBuffer); + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the two strings to confirm that the right value is returned */ + if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been '%s' but " + "was really '%s'.\n",FirstEnvironmentValue,pResultBuffer); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + +#endif +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/CMakeLists.txt index a0873bb7e7..38c186740f 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_getenvironmentvariablea_test6 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/test6.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/test6.c deleted file mode 100644 index 8ef7571f59..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/test6.c +++ /dev/null @@ -1,99 +0,0 @@ -// 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 : test6.c -** -** Purpose: Test for GetEnvironmentVariableA() function -** Create environment variables that differ only -** in case and verify that they return the appropriate -** value on the BSD environment. -** - -** -===========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - - /* Define some buffers needed for the function */ - char * pResultBuffer = NULL; - - char FirstEnvironmentVariable[] = {"PALTEST"}; - char FirstEnvironmentValue[] = {"FIRST"}; - char ModifiedEnvVar[] = {"paltest"}; - - DWORD size = 0; - BOOL bRc = TRUE; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Set the first environment variable */ - bRc = SetEnvironmentVariableA(FirstEnvironmentVariable, - FirstEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - /* Normal case, PATH should fit into this buffer */ - size = GetEnvironmentVariableA(ModifiedEnvVar, - pResultBuffer, - 0); - - /* To account for the nul character at the end of the string */ - size = size + 1; - - pResultBuffer = malloc(sizeof(char)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try to retrieve the value of the first environment variable */ - GetEnvironmentVariableA(ModifiedEnvVar, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - free(pResultBuffer); - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the strings to see that the correct variable was returned */ - if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) - { - free(pResultBuffer); - Fail("ERROR: The value in the buffer should have been '%s' but " - "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer); - } - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; - - -#else - - return PASS; -#endif -} diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/test6.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/test6.cpp new file mode 100644 index 0000000000..837036a0a9 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableA/test6/test6.cpp @@ -0,0 +1,99 @@ +// 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 : test6.c +** +** Purpose: Test for GetEnvironmentVariableA() function +** Create environment variables that differ only +** in case and verify that they return the appropriate +** value on the BSD environment. +** + +** +===========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + + /* Define some buffers needed for the function */ + char * pResultBuffer = NULL; + + char FirstEnvironmentVariable[] = {"PALTEST"}; + char FirstEnvironmentValue[] = {"FIRST"}; + char ModifiedEnvVar[] = {"paltest"}; + + DWORD size = 0; + BOOL bRc = TRUE; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set the first environment variable */ + bRc = SetEnvironmentVariableA(FirstEnvironmentVariable, + FirstEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariableA(ModifiedEnvVar, + pResultBuffer, + 0); + + /* To account for the nul character at the end of the string */ + size = size + 1; + + pResultBuffer = (char*)malloc(sizeof(char)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariableA(ModifiedEnvVar, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + free(pResultBuffer); + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the strings to see that the correct variable was returned */ + if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been '%s' but " + "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + + +#else + + return PASS; +#endif +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/CMakeLists.txt index 567c992461..a3cb878ef4 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getenvironmentvariablew_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.c deleted file mode 100644 index 6c764509d0..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.c +++ /dev/null @@ -1,79 +0,0 @@ -// 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 GetEnvironmentVariable() function -** -** -**=========================================================*/ - -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - - /* Define some buffers needed for the function */ - WCHAR * pResultBuffer = NULL; - int size = 0; - - /* A place to stash the returned values */ - int ReturnValueForLargeBuffer = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Recieve and allocate the correct amount of memory for the buffer */ - size = ReturnValueForLargeBuffer = - GetEnvironmentVariable(convert("PATH"), - pResultBuffer, - 0); - - pResultBuffer = malloc(size*sizeof(WCHAR)); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer. " - "Can't properly exec test case without this.\n"); - } - - - /* Normal case, PATH should fit into this buffer */ - ReturnValueForLargeBuffer = GetEnvironmentVariable(convert("PATH"), - pResultBuffer, - size); - free(pResultBuffer); - - /* Ensure that it returned a positive value */ - if(ReturnValueForLargeBuffer <= 0) - { - Fail("The return was %d, which indicates that the function failed.\n", - ReturnValueForLargeBuffer); - } - - /* Ensure that it succeeded and copied the correct number of characters. - If this is true, then the return value should be one less of the - size of the buffer. (Doesn't include that NULL byte) - */ - if(ReturnValueForLargeBuffer != size-1) - { - Fail("The value returned was %d when it should have been %d. This " - "should be the number of characters copied, " - "minus the NULL byte.\n", ReturnValueForLargeBuffer, size-1); - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.cpp new file mode 100644 index 0000000000..cb5fc00554 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test1/test.cpp @@ -0,0 +1,79 @@ +// 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 GetEnvironmentVariable() function +** +** +**=========================================================*/ + +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + + /* Define some buffers needed for the function */ + WCHAR * pResultBuffer = NULL; + int size = 0; + + /* A place to stash the returned values */ + int ReturnValueForLargeBuffer = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Recieve and allocate the correct amount of memory for the buffer */ + size = ReturnValueForLargeBuffer = + GetEnvironmentVariable(convert("PATH"), + pResultBuffer, + 0); + + pResultBuffer = (WCHAR*)malloc(size*sizeof(WCHAR)); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer. " + "Can't properly exec test case without this.\n"); + } + + + /* Normal case, PATH should fit into this buffer */ + ReturnValueForLargeBuffer = GetEnvironmentVariable(convert("PATH"), + pResultBuffer, + size); + free(pResultBuffer); + + /* Ensure that it returned a positive value */ + if(ReturnValueForLargeBuffer <= 0) + { + Fail("The return was %d, which indicates that the function failed.\n", + ReturnValueForLargeBuffer); + } + + /* Ensure that it succeeded and copied the correct number of characters. + If this is true, then the return value should be one less of the + size of the buffer. (Doesn't include that NULL byte) + */ + if(ReturnValueForLargeBuffer != size-1) + { + Fail("The value returned was %d when it should have been %d. This " + "should be the number of characters copied, " + "minus the NULL byte.\n", ReturnValueForLargeBuffer, size-1); + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/CMakeLists.txt index 7234f61ed3..2c6ec6247e 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getenvironmentvariablew_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.c deleted file mode 100644 index 6fa753c8d3..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.c +++ /dev/null @@ -1,56 +0,0 @@ -// 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 GetEnvironmentVariable() function -** -** -**=========================================================*/ - -#define UNICODE - -#include - -#define SMALL_BUFFER_SIZE 1 - -int __cdecl main(int argc, char *argv[]) -{ - - WCHAR pSmallBuffer[SMALL_BUFFER_SIZE]; - - /* A place to stash the returned values */ - int ReturnValueForSmallBuffer; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* PATH won't fit in this buffer, it should return how many characters - it needs - */ - - ReturnValueForSmallBuffer = GetEnvironmentVariable(convert("PATH"), - pSmallBuffer, - SMALL_BUFFER_SIZE); - - if(ReturnValueForSmallBuffer <= 0) - { - Fail("The return value was %d when it should have been greater " - "than 0. This should return the number of characters needed " - "to contained the contents of PATH in a buffer.\n", - ReturnValueForSmallBuffer); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.cpp new file mode 100644 index 0000000000..6fa753c8d3 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test2/test.cpp @@ -0,0 +1,56 @@ +// 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 GetEnvironmentVariable() function +** +** +**=========================================================*/ + +#define UNICODE + +#include + +#define SMALL_BUFFER_SIZE 1 + +int __cdecl main(int argc, char *argv[]) +{ + + WCHAR pSmallBuffer[SMALL_BUFFER_SIZE]; + + /* A place to stash the returned values */ + int ReturnValueForSmallBuffer; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* PATH won't fit in this buffer, it should return how many characters + it needs + */ + + ReturnValueForSmallBuffer = GetEnvironmentVariable(convert("PATH"), + pSmallBuffer, + SMALL_BUFFER_SIZE); + + if(ReturnValueForSmallBuffer <= 0) + { + Fail("The return value was %d when it should have been greater " + "than 0. This should return the number of characters needed " + "to contained the contents of PATH in a buffer.\n", + ReturnValueForSmallBuffer); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/CMakeLists.txt index bafd75e52e..6af382b6cd 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getenvironmentvariablew_test3 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.c deleted file mode 100644 index 03781e723f..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.c +++ /dev/null @@ -1,71 +0,0 @@ -// 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 GetEnvironmentVariable() function -** -** -**=========================================================*/ - -#define UNICODE -#include - -#define BUFFER_SIZE 5000 -#define SMALL_BUFFER_SIZE 5 - -int __cdecl main(int argc, char *argv[]) -{ - - /* Define some buffers needed for the function */ - WCHAR pResultBuffer[BUFFER_SIZE]; - WCHAR pSmallBuffer[SMALL_BUFFER_SIZE]; - - /* A place to stash the returned values */ - int ReturnValueForNonExisting, ReturnValueForNull; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* This variable doesn't exist, it should return 0 */ - ReturnValueForNonExisting = - GetEnvironmentVariable(convert("NonExistingVariable"), - pSmallBuffer, - SMALL_BUFFER_SIZE); - - if(ReturnValueForNonExisting != 0) - { - Fail("ERROR: The return should have been 0, but it was %d. The " - "function attempted to get an Environment Variable that doesn't " - "exist and should return 0 as a result.\n", - ReturnValueForNonExisting); - } - - - /* Passing a NULL string should return 0 */ - ReturnValueForNull = GetEnvironmentVariable(NULL, - pResultBuffer, - BUFFER_SIZE); - - if(ReturnValueForNull != 0) - { - Fail("ERROR: The return should have been 0, but it was %d. The " - "function attempted to get a NULL pointer and should return 0 " - "as a result.\n",ReturnValueForNull); - } - - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.cpp new file mode 100644 index 0000000000..03781e723f --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test3/test.cpp @@ -0,0 +1,71 @@ +// 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 GetEnvironmentVariable() function +** +** +**=========================================================*/ + +#define UNICODE +#include + +#define BUFFER_SIZE 5000 +#define SMALL_BUFFER_SIZE 5 + +int __cdecl main(int argc, char *argv[]) +{ + + /* Define some buffers needed for the function */ + WCHAR pResultBuffer[BUFFER_SIZE]; + WCHAR pSmallBuffer[SMALL_BUFFER_SIZE]; + + /* A place to stash the returned values */ + int ReturnValueForNonExisting, ReturnValueForNull; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* This variable doesn't exist, it should return 0 */ + ReturnValueForNonExisting = + GetEnvironmentVariable(convert("NonExistingVariable"), + pSmallBuffer, + SMALL_BUFFER_SIZE); + + if(ReturnValueForNonExisting != 0) + { + Fail("ERROR: The return should have been 0, but it was %d. The " + "function attempted to get an Environment Variable that doesn't " + "exist and should return 0 as a result.\n", + ReturnValueForNonExisting); + } + + + /* Passing a NULL string should return 0 */ + ReturnValueForNull = GetEnvironmentVariable(NULL, + pResultBuffer, + BUFFER_SIZE); + + if(ReturnValueForNull != 0) + { + Fail("ERROR: The return should have been 0, but it was %d. The " + "function attempted to get a NULL pointer and should return 0 " + "as a result.\n",ReturnValueForNull); + } + + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/CMakeLists.txt index f870bd6b22..674b187fa7 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getenvironmentvariablew_test4 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.c deleted file mode 100644 index b5894efc6e..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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 GetEnvironmentVariable() function -** -** -**=========================================================*/ - -/* Depends on SetEnvironmentVariableW (because we're implmenting the wide - version) and strcmp() */ - -#define UNICODE -#include - -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; -} - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.cpp new file mode 100644 index 0000000000..1ee3e72c9d --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.cpp @@ -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 GetEnvironmentVariable() function +** +** +**=========================================================*/ + +/* Depends on SetEnvironmentVariableW (because we're implmenting the wide + version) and strcmp() */ + +#define UNICODE +#include + +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 = (WCHAR*)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; +} + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/CMakeLists.txt index ab44781279..71e974703b 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_getenvironmentvariablew_test5 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.c deleted file mode 100644 index 58eba3a380..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.c +++ /dev/null @@ -1,144 +0,0 @@ -// 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 : test5.c -** -** Purpose: Test for GetEnvironmentVariableW() function -** Create environment variables that differ only -** in case and verify that they return the appropriate -** value on the BSD environment. -** -** -===========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - - return PASS; - -#else - - /* Define some buffers needed for the function */ - WCHAR * pResultBuffer = NULL; - - WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; - WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; - - WCHAR SecondEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; - WCHAR SecondEnvironmentValue[] = {'S','E','C','O','N','D','\0'}; - - DWORD size = 0; - BOOL bRc = TRUE; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Set the first environment variable */ - bRc = SetEnvironmentVariableW(FirstEnvironmentVariable, - FirstEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", GetLastError()); - } - - /* Normal case, PATH should fit into this buffer */ - size = GetEnvironmentVariableW(FirstEnvironmentVariable, - pResultBuffer, - 0); - - /* To account for the nul character at the end of the string */ - size = size + 1; - - pResultBuffer = malloc(sizeof(WCHAR)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try to retrieve the value of the first environment variable */ - GetEnvironmentVariableW(FirstEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - free(pResultBuffer); - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the strings to see that the correct variable was returned */ - if(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) - { - free(pResultBuffer); - Fail("ERROR: The value in the buffer should have been '%S' but " - "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); - } - - free(pResultBuffer); - - /* Set the second environment Variable */ - bRc = SetEnvironmentVariableW(SecondEnvironmentVariable, - SecondEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - /* Reallocate the memory for the string */ - pResultBuffer = malloc(sizeof(WCHAR)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try retrieving the value of the first variable, even though the - second variable has the same spelling and only differs in case */ - GetEnvironmentVariableW(FirstEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - free(pResultBuffer); - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the two strings to confirm that the right value is returned */ - if(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) - { - free(pResultBuffer); - Fail("ERROR: The value in the buffer should have been '%S' but " - "was really '%S'.\n",FirstEnvironmentValue,pResultBuffer); - } - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; - -#endif -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.cpp new file mode 100644 index 0000000000..179fc17f0b --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.cpp @@ -0,0 +1,144 @@ +// 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 : test5.c +** +** Purpose: Test for GetEnvironmentVariableW() function +** Create environment variables that differ only +** in case and verify that they return the appropriate +** value on the BSD environment. +** +** +===========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + + return PASS; + +#else + + /* Define some buffers needed for the function */ + WCHAR * pResultBuffer = NULL; + + WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; + + WCHAR SecondEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; + WCHAR SecondEnvironmentValue[] = {'S','E','C','O','N','D','\0'}; + + DWORD size = 0; + BOOL bRc = TRUE; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set the first environment variable */ + bRc = SetEnvironmentVariableW(FirstEnvironmentVariable, + FirstEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", GetLastError()); + } + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariableW(FirstEnvironmentVariable, + pResultBuffer, + 0); + + /* To account for the nul character at the end of the string */ + size = size + 1; + + pResultBuffer = (WCHAR*)malloc(sizeof(WCHAR)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariableW(FirstEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + free(pResultBuffer); + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the strings to see that the correct variable was returned */ + if(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been '%S' but " + "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); + } + + free(pResultBuffer); + + /* Set the second environment Variable */ + bRc = SetEnvironmentVariableW(SecondEnvironmentVariable, + SecondEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Reallocate the memory for the string */ + pResultBuffer = (WCHAR*)malloc(sizeof(WCHAR)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try retrieving the value of the first variable, even though the + second variable has the same spelling and only differs in case */ + GetEnvironmentVariableW(FirstEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + free(pResultBuffer); + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the two strings to confirm that the right value is returned */ + if(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been '%S' but " + "was really '%S'.\n",FirstEnvironmentValue,pResultBuffer); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + +#endif +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/CMakeLists.txt index e504c8323a..8771ab0cc8 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_getenvironmentvariablew_test6 diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.c b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.c deleted file mode 100644 index 85f31be9c2..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.c +++ /dev/null @@ -1,99 +0,0 @@ -// 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 : test6.c -** -** Purpose: Test for GetEnvironmentVariableW() function -** Create environment variables that differ only -** in case and verify that they return the appropriate -** value on the BSD environment. -** -** -===========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - - /* Define some buffers needed for the function */ - WCHAR * pResultBuffer = NULL; - - WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; - WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; - - WCHAR ModifiedEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; - - DWORD size = 0; - BOOL bRc = TRUE; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Set the first environment variable */ - bRc = SetEnvironmentVariableW(FirstEnvironmentVariable, - FirstEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - /* Normal case, PATH should fit into this buffer */ - size = GetEnvironmentVariableW(ModifiedEnvironmentVariable, - pResultBuffer, - 0); - - /* To account for the nul character at the end of the string */ - size = size + 1; - - pResultBuffer = malloc(sizeof(WCHAR)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try to retrieve the value of the first environment variable */ - GetEnvironmentVariableW(ModifiedEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - free(pResultBuffer); - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the strings to see that the correct variable was returned */ - if(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) - { - free(pResultBuffer); - Fail("ERROR: The value in the buffer should have been '%S' but " - "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); - } - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; - - -#else - - return PASS; -#endif -} diff --git a/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.cpp b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.cpp new file mode 100644 index 0000000000..e376950841 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.cpp @@ -0,0 +1,99 @@ +// 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 : test6.c +** +** Purpose: Test for GetEnvironmentVariableW() function +** Create environment variables that differ only +** in case and verify that they return the appropriate +** value on the BSD environment. +** +** +===========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + + /* Define some buffers needed for the function */ + WCHAR * pResultBuffer = NULL; + + WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; + + WCHAR ModifiedEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; + + DWORD size = 0; + BOOL bRc = TRUE; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set the first environment variable */ + bRc = SetEnvironmentVariableW(FirstEnvironmentVariable, + FirstEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariableW(ModifiedEnvironmentVariable, + pResultBuffer, + 0); + + /* To account for the nul character at the end of the string */ + size = size + 1; + + pResultBuffer = (WCHAR*)malloc(sizeof(WCHAR)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariableW(ModifiedEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + free(pResultBuffer); + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the strings to see that the correct variable was returned */ + if(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) + { + free(pResultBuffer); + Fail("ERROR: The value in the buffer should have been '%S' but " + "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + + +#else + + return PASS; +#endif +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/CMakeLists.txt index 09e650c924..3c851c7260 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getlasterror_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/test.c deleted file mode 100644 index 65f56e595f..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/test.c +++ /dev/null @@ -1,63 +0,0 @@ -// 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 GetLastError() function -** -** -**=========================================================*/ - -/* Depends on SetLastError() */ - -#include - -/** - * Helper functions that does the actual test - */ -static void test(DWORD error ) -{ - DWORD TheResult; - - /* Set error */ - SetLastError(error); - - /* Check to make sure it returns the error value we just set */ - TheResult = GetLastError(); - if(TheResult!= error) - { - Fail("ERROR: The last error should have been %u, but when " - "GetLastError was called, it returned %u.\n",error,TheResult); - } - -} - -int __cdecl main(int argc, char *argv[]) { - - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* test setting and getting some values */ - test(5); - test(0xffffffff); - test(0xEEEEEEEE); - test(0xAAAAAAAA); - - PAL_Terminate(); - return PASS; -} - - - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/test.cpp new file mode 100644 index 0000000000..65f56e595f --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetLastError/test1/test.cpp @@ -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 GetLastError() function +** +** +**=========================================================*/ + +/* Depends on SetLastError() */ + +#include + +/** + * Helper functions that does the actual test + */ +static void test(DWORD error ) +{ + DWORD TheResult; + + /* Set error */ + SetLastError(error); + + /* Check to make sure it returns the error value we just set */ + TheResult = GetLastError(); + if(TheResult!= error) + { + Fail("ERROR: The last error should have been %u, but when " + "GetLastError was called, it returned %u.\n",error,TheResult); + } + +} + +int __cdecl main(int argc, char *argv[]) { + + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* test setting and getting some values */ + test(5); + test(0xffffffff); + test(0xEEEEEEEE); + test(0xAAAAAAAA); + + PAL_Terminate(); + return PASS; +} + + + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/CMakeLists.txt index 960291fe79..9419517128 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getsysteminfo_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/test.c deleted file mode 100644 index 5f3608fb70..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/test.c +++ /dev/null @@ -1,70 +0,0 @@ -// 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 GetSystemInfo() function -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) { - - SYSTEM_INFO TheSystemInfo; - SYSTEM_INFO* pSystemInfo = &TheSystemInfo; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - GetSystemInfo(pSystemInfo); - - /* Ensure both valules are > than 0 */ - if(pSystemInfo->dwNumberOfProcessors < 1) - { - Fail("ERROR: The dwNumberofProcessors values should be > 0."); - } - - if(pSystemInfo->dwPageSize < 1) - { - Fail("ERROR: The dwPageSize should be greater than 0."); - } - - /* If this isn't WIN32, ensure all the other variables are 0 */ - -#if UNIX - if(pSystemInfo->dwOemId != 0 || - pSystemInfo->wProcessorArchitecture != 0 || - pSystemInfo->wReserved != 0 || - pSystemInfo->lpMinimumApplicationAddress != 0 || - pSystemInfo->lpMaximumApplicationAddress != 0 || - pSystemInfo->dwActiveProcessorMask != 0 || - pSystemInfo->dwProcessorType !=0 || - pSystemInfo->dwAllocationGranularity !=0 || - pSystemInfo->wProcessorLevel != 0 || - pSystemInfo->wProcessorRevision != 0) { - Fail("ERROR: Under FreeBSD, OemId, ProcessorArchitecture, Reserved, " - "MinimumApplicationAddress, MaximumApplicationAddress, " - "ActiveProcessorMask, ProcessorType, AllocationGranularity, " - "ProcessorLevel and ProcessorRevision should be equal to 0."); - - - } -#endif - - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/test.cpp new file mode 100644 index 0000000000..5f3608fb70 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetSystemInfo/test1/test.cpp @@ -0,0 +1,70 @@ +// 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 GetSystemInfo() function +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) { + + SYSTEM_INFO TheSystemInfo; + SYSTEM_INFO* pSystemInfo = &TheSystemInfo; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + GetSystemInfo(pSystemInfo); + + /* Ensure both valules are > than 0 */ + if(pSystemInfo->dwNumberOfProcessors < 1) + { + Fail("ERROR: The dwNumberofProcessors values should be > 0."); + } + + if(pSystemInfo->dwPageSize < 1) + { + Fail("ERROR: The dwPageSize should be greater than 0."); + } + + /* If this isn't WIN32, ensure all the other variables are 0 */ + +#if UNIX + if(pSystemInfo->dwOemId != 0 || + pSystemInfo->wProcessorArchitecture != 0 || + pSystemInfo->wReserved != 0 || + pSystemInfo->lpMinimumApplicationAddress != 0 || + pSystemInfo->lpMaximumApplicationAddress != 0 || + pSystemInfo->dwActiveProcessorMask != 0 || + pSystemInfo->dwProcessorType !=0 || + pSystemInfo->dwAllocationGranularity !=0 || + pSystemInfo->wProcessorLevel != 0 || + pSystemInfo->wProcessorRevision != 0) { + Fail("ERROR: Under FreeBSD, OemId, ProcessorArchitecture, Reserved, " + "MinimumApplicationAddress, MaximumApplicationAddress, " + "ActiveProcessorMask, ProcessorType, AllocationGranularity, " + "ProcessorLevel and ProcessorRevision should be equal to 0."); + + + } +#endif + + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/CMakeLists.txt index 5c6ea26a41..f7be23bc0b 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_gettickcount_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/test.c deleted file mode 100644 index ad71ba5d6c..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/test.c +++ /dev/null @@ -1,58 +0,0 @@ -// 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: -** -** Source : test1.c -** -** Purpose: Test for GetTickCount() function -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) { - - DWORD FirstCount = 0; - DWORD SecondCount = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Grab a FirstCount, then loop for a bit to make the clock increase */ - FirstCount = GetTickCount(); - - /* Make sure some time passes */ - Sleep(60); //Since the get tick count is accurate within 55 milliseconds. - - /* Get a second count */ - SecondCount = GetTickCount(); - - /* Make sure the second one is bigger than the first. - This isn't the best test, but it at least shows that it's returning a - DWORD which is increasing. - */ - - if(FirstCount >= SecondCount) - { - Fail("ERROR: The first time (%d) was greater/equal than the second time " - " (%d). The tick count should have increased.\n", - FirstCount,SecondCount); - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/test.cpp new file mode 100644 index 0000000000..ad71ba5d6c --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetTickCount/test1/test.cpp @@ -0,0 +1,58 @@ +// 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: +** +** Source : test1.c +** +** Purpose: Test for GetTickCount() function +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) { + + DWORD FirstCount = 0; + DWORD SecondCount = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Grab a FirstCount, then loop for a bit to make the clock increase */ + FirstCount = GetTickCount(); + + /* Make sure some time passes */ + Sleep(60); //Since the get tick count is accurate within 55 milliseconds. + + /* Get a second count */ + SecondCount = GetTickCount(); + + /* Make sure the second one is bigger than the first. + This isn't the best test, but it at least shows that it's returning a + DWORD which is increasing. + */ + + if(FirstCount >= SecondCount) + { + Fail("ERROR: The first time (%d) was greater/equal than the second time " + " (%d). The tick count should have increased.\n", + FirstCount,SecondCount); + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/CMakeLists.txt index a1d5ab21b8..8ed7ace073 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getusernamew_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/test.c deleted file mode 100644 index 809f14c12d..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/test.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: Positive Test for GetUserName() function -** -** -**=========================================================*/ - -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - - WCHAR wzUserName[UNLEN+1]; - DWORD dwSize = sizeof(wzUserName)/sizeof(wzUserName[0]); - - // Initialize the PAL and return FAILURE if this fails - if(0 != (PAL_Initialize(argc, argv))) - { - Fail ("ERROR: PAL_Initialize() call failed!\n"); - } - - if (0 == GetUserName(wzUserName, &dwSize)) - { - Fail("ERROR: GetUserName failed with %d!\n", GetLastError()); - } - - // dwSize is the length of wzUserName with NULL - if (dwSize <= 0 || dwSize > (sizeof(wzUserName)/sizeof(wzUserName[0]))) - { - Fail("ERROR: GetUserName returned %S with dwSize = %u whereas the passed in buffer size is %d!\n", - wzUserName, dwSize, sizeof(wzUserName)/sizeof(wzUserName[0])); - } - - // dwSize is the length of wzUserName with NULL - if (dwSize != wcslen(wzUserName)+1) - { - Fail("ERROR: GetUserName returned %S of length %d which is not equal to dwSize-1 = %u!\n", - wzUserName, wcslen(wzUserName), dwSize-1); - } - - printf ("GetUserName returned %S of length %u\n", wzUserName, dwSize-1); - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/test.cpp new file mode 100644 index 0000000000..809f14c12d --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetUserNameW/test1/test.cpp @@ -0,0 +1,52 @@ +// 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: Positive Test for GetUserName() function +** +** +**=========================================================*/ + +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + + WCHAR wzUserName[UNLEN+1]; + DWORD dwSize = sizeof(wzUserName)/sizeof(wzUserName[0]); + + // Initialize the PAL and return FAILURE if this fails + if(0 != (PAL_Initialize(argc, argv))) + { + Fail ("ERROR: PAL_Initialize() call failed!\n"); + } + + if (0 == GetUserName(wzUserName, &dwSize)) + { + Fail("ERROR: GetUserName failed with %d!\n", GetLastError()); + } + + // dwSize is the length of wzUserName with NULL + if (dwSize <= 0 || dwSize > (sizeof(wzUserName)/sizeof(wzUserName[0]))) + { + Fail("ERROR: GetUserName returned %S with dwSize = %u whereas the passed in buffer size is %d!\n", + wzUserName, dwSize, sizeof(wzUserName)/sizeof(wzUserName[0])); + } + + // dwSize is the length of wzUserName with NULL + if (dwSize != wcslen(wzUserName)+1) + { + Fail("ERROR: GetUserName returned %S of length %d which is not equal to dwSize-1 = %u!\n", + wzUserName, wcslen(wzUserName), dwSize-1); + } + + printf ("GetUserName returned %S of length %u\n", wzUserName, dwSize-1); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/CMakeLists.txt index b9dd711d36..2cb305f22b 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getversionexa_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/test.c deleted file mode 100644 index 5dd20c6576..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/test.c +++ /dev/null @@ -1,83 +0,0 @@ -// 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 GetVersionExA() function -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) { - - OSVERSIONINFO TheVersionInfo; - OSVERSIONINFO* pVersionInfo = &TheVersionInfo; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - - /* This needs to be done before using GetVersionEx */ - pVersionInfo->dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - - /* If GetVersionEx fails, then the test fails */ - if(GetVersionEx(pVersionInfo) == 0) - { - Fail("ERROR: The GetVersionEx function returned 0, which indicates " - "failure."); - } - - /* These values are fixed, ensure they're set properly */ - if(pVersionInfo->dwMajorVersion != 5) - { - Fail("ERROR: The fixed value of dwMajorVersion shoud be 5, " - "but is really %d.",pVersionInfo->dwMajorVersion); - } - - /* The minor version values for Win2k and XP are different - for Win2k minor version equals 0 and for XP minor version - equals 1. Both values are excepted here. */ - if((pVersionInfo->dwMinorVersion != 0) && - (pVersionInfo->dwMinorVersion != 1)) - { - Fail("ERROR: The fixed value of dwMinorVersion shoud be 0 or 1, " - "but is really %d.",pVersionInfo->dwMinorVersion); - } - if(pVersionInfo->dwBuildNumber_PAL_Undefined < 0) - { - Fail("ERROR: The value of dwBuildNumber shoud be at least 0, but " - "is really %d.",pVersionInfo->dwBuildNumber_PAL_Undefined); - } - -#if !WIN32 - /* Under BSD, the PlatformID should be UNIX and the Service Pack - version should be set to "". - */ - - if(pVersionInfo->dwPlatformId != VER_PLATFORM_UNIX || - pVersionInfo->szCSDVersion_PAL_Undefined[0] != 0) - { - Fail("ERROR: The dwPlatformId should be %d but is really %d. And the " - "szCSDVerion should be NULL.", - VER_PLATFORM_UNIX,pVersionInfo->dwPlatformId); - } -#endif - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/test.cpp new file mode 100644 index 0000000000..5dd20c6576 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetVersionExA/test1/test.cpp @@ -0,0 +1,83 @@ +// 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 GetVersionExA() function +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) { + + OSVERSIONINFO TheVersionInfo; + OSVERSIONINFO* pVersionInfo = &TheVersionInfo; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + + /* This needs to be done before using GetVersionEx */ + pVersionInfo->dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + + /* If GetVersionEx fails, then the test fails */ + if(GetVersionEx(pVersionInfo) == 0) + { + Fail("ERROR: The GetVersionEx function returned 0, which indicates " + "failure."); + } + + /* These values are fixed, ensure they're set properly */ + if(pVersionInfo->dwMajorVersion != 5) + { + Fail("ERROR: The fixed value of dwMajorVersion shoud be 5, " + "but is really %d.",pVersionInfo->dwMajorVersion); + } + + /* The minor version values for Win2k and XP are different + for Win2k minor version equals 0 and for XP minor version + equals 1. Both values are excepted here. */ + if((pVersionInfo->dwMinorVersion != 0) && + (pVersionInfo->dwMinorVersion != 1)) + { + Fail("ERROR: The fixed value of dwMinorVersion shoud be 0 or 1, " + "but is really %d.",pVersionInfo->dwMinorVersion); + } + if(pVersionInfo->dwBuildNumber_PAL_Undefined < 0) + { + Fail("ERROR: The value of dwBuildNumber shoud be at least 0, but " + "is really %d.",pVersionInfo->dwBuildNumber_PAL_Undefined); + } + +#if !WIN32 + /* Under BSD, the PlatformID should be UNIX and the Service Pack + version should be set to "". + */ + + if(pVersionInfo->dwPlatformId != VER_PLATFORM_UNIX || + pVersionInfo->szCSDVersion_PAL_Undefined[0] != 0) + { + Fail("ERROR: The dwPlatformId should be %d but is really %d. And the " + "szCSDVerion should be NULL.", + VER_PLATFORM_UNIX,pVersionInfo->dwPlatformId); + } +#endif + + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/CMakeLists.txt index d7eb683343..09494240cc 100644 --- a/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_getversionexw_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/test.c deleted file mode 100644 index 69aae54bcf..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/test.c +++ /dev/null @@ -1,88 +0,0 @@ -// 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 GetVersionExW() function -** -** -**=========================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - OSVERSIONINFO TheVersionInfo; - OSVERSIONINFO* pVersionInfo = &TheVersionInfo; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* This needs to be done before using GetVersionEx */ - pVersionInfo->dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - - /* If GetVersionEx fails, then the test fails */ - if(GetVersionEx(pVersionInfo) == 0) - { - Fail("ERROR: The GetVersionEx function returned 0, which indicates " - "failure."); - } - - /* These values are fixed, ensure they're set properly */ - if(pVersionInfo->dwMajorVersion != 5) - { - Fail("ERROR: The fixed value of dwMajorVersion shoud be 5, but is " - " really %d.",pVersionInfo->dwMajorVersion); - } - - /* The minor version values for Win2k and XP are different - for Win2k minor version equals 0 and for XP minor version - equals 1. Both values are excepted here. */ - if((pVersionInfo->dwMinorVersion != 0) && - (pVersionInfo->dwMinorVersion != 1)) - { - Fail("ERROR: The fixed value of dwMinorVersion shoud be 0 or 1, " - "but is really %d.",pVersionInfo->dwMinorVersion); - } - - if(pVersionInfo->dwBuildNumber_PAL_Undefined < 0) - { - Fail("ERROR: The value of dwBuildNumber shoud be at least 0, but is " - "really %d.",pVersionInfo->dwBuildNumber_PAL_Undefined); - } - -#if !WIN32 - - - /* Under BSD, the PlatformID should be UNIX and the Service Pack - version should be set to "". - */ - - if(pVersionInfo->dwPlatformId != VER_PLATFORM_UNIX || - pVersionInfo->szCSDVersion_PAL_Undefined[0] != 0) - { - Fail("ERROR: The dwPlatformId should be %d but is really %d. And the " - "szCSDVerion should be NULL.",VER_PLATFORM_UNIX, - pVersionInfo->dwPlatformId); - } -#endif - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/test.cpp new file mode 100644 index 0000000000..69aae54bcf --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetVersionExW/test1/test.cpp @@ -0,0 +1,88 @@ +// 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 GetVersionExW() function +** +** +**=========================================================*/ + +#define UNICODE + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + OSVERSIONINFO TheVersionInfo; + OSVERSIONINFO* pVersionInfo = &TheVersionInfo; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* This needs to be done before using GetVersionEx */ + pVersionInfo->dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + + /* If GetVersionEx fails, then the test fails */ + if(GetVersionEx(pVersionInfo) == 0) + { + Fail("ERROR: The GetVersionEx function returned 0, which indicates " + "failure."); + } + + /* These values are fixed, ensure they're set properly */ + if(pVersionInfo->dwMajorVersion != 5) + { + Fail("ERROR: The fixed value of dwMajorVersion shoud be 5, but is " + " really %d.",pVersionInfo->dwMajorVersion); + } + + /* The minor version values for Win2k and XP are different + for Win2k minor version equals 0 and for XP minor version + equals 1. Both values are excepted here. */ + if((pVersionInfo->dwMinorVersion != 0) && + (pVersionInfo->dwMinorVersion != 1)) + { + Fail("ERROR: The fixed value of dwMinorVersion shoud be 0 or 1, " + "but is really %d.",pVersionInfo->dwMinorVersion); + } + + if(pVersionInfo->dwBuildNumber_PAL_Undefined < 0) + { + Fail("ERROR: The value of dwBuildNumber shoud be at least 0, but is " + "really %d.",pVersionInfo->dwBuildNumber_PAL_Undefined); + } + +#if !WIN32 + + + /* Under BSD, the PlatformID should be UNIX and the Service Pack + version should be set to "". + */ + + if(pVersionInfo->dwPlatformId != VER_PLATFORM_UNIX || + pVersionInfo->szCSDVersion_PAL_Undefined[0] != 0) + { + Fail("ERROR: The dwPlatformId should be %d but is really %d. And the " + "szCSDVerion should be NULL.",VER_PLATFORM_UNIX, + pVersionInfo->dwPlatformId); + } +#endif + + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/CMakeLists.txt index d41e6bc5ab..bc3f11b705 100644 --- a/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_isbadcodeptr_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/test1.c b/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/test1.c deleted file mode 100644 index 4b2763d457..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/test1.c +++ /dev/null @@ -1,60 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure that IsBadCodePtr return 0 when -** it can read memory or non zero when it can't. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** - -** -**===========================================================================*/ - -#include - -/** - * main - * - * executable entry point - */ -INT __cdecl main(INT argc, CHAR **argv) -{ - BOOL ResultValue = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* This should be readable, and return 0 */ - ResultValue = IsBadCodePtr((FARPROC)main); - if(ResultValue != 0) - { - Fail("ERROR: IsBadCodePtr returned %d instead of 0, when pointing " - "at readable memory.\n",ResultValue); - } - - /* 0x00 is usually unreadable memory so the function should - return non zero */ - ResultValue = IsBadCodePtr((FARPROC)0x00); - - if(ResultValue == 0) - { - Fail("ERROR: IsBadCodePtr returned %d instead of non zero " - "when checking on unreadable memory.\n",ResultValue); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/test1.cpp b/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/test1.cpp new file mode 100644 index 0000000000..4b2763d457 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/IsBadCodePtr/test1/test1.cpp @@ -0,0 +1,60 @@ +// 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: test1.c +** +** Purpose: Test to ensure that IsBadCodePtr return 0 when +** it can read memory or non zero when it can't. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** + +** +**===========================================================================*/ + +#include + +/** + * main + * + * executable entry point + */ +INT __cdecl main(INT argc, CHAR **argv) +{ + BOOL ResultValue = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* This should be readable, and return 0 */ + ResultValue = IsBadCodePtr((FARPROC)main); + if(ResultValue != 0) + { + Fail("ERROR: IsBadCodePtr returned %d instead of 0, when pointing " + "at readable memory.\n",ResultValue); + } + + /* 0x00 is usually unreadable memory so the function should + return non zero */ + ResultValue = IsBadCodePtr((FARPROC)0x00); + + if(ResultValue == 0) + { + Fail("ERROR: IsBadCodePtr returned %d instead of non zero " + "when checking on unreadable memory.\n",ResultValue); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/CMakeLists.txt index f1e84d73b8..82aecefa70 100644 --- a/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_isbadreadptr_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/test.c b/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/test.c deleted file mode 100644 index 24b7ceb7e6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/test.c +++ /dev/null @@ -1,138 +0,0 @@ -// 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: IsBadReadPtr() function -** -** -**=========================================================*/ - -#include - -#define MEMORY_AMOUNT 16 - -int __cdecl main(int argc, char *argv[]) -{ - LPVOID TestingPointer = NULL; - BOOL ResultValue = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - TestingPointer = malloc(MEMORY_AMOUNT); - if ( TestingPointer == NULL ) - { - Fail("ERROR: Failed to allocate memory for TestingPointer pointer. " - "Can't properly exec test case without this.\n"); - } - - - /* This should be readable, and return 0 */ - ResultValue = IsBadReadPtr(TestingPointer,MEMORY_AMOUNT); - if(ResultValue != 0) - { - free(TestingPointer); - - Fail("ERROR: The function returned %d instead of 0, when pointing " - "at readable memory.\n",ResultValue); - } - - /* If we pass 0, the result should be 0 as well */ - ResultValue = IsBadReadPtr(TestingPointer,0); - if(ResultValue != 0) - { - free(TestingPointer); - - Fail("ERROR: The function returned %d instead of 0, when the " - "function was passed a range of 0 bytes.\n",ResultValue); - } - free(TestingPointer); /* we are done with this */ - - /* create a READABLE address */ - TestingPointer = VirtualAlloc( - NULL, /* system selects address */ - 80, /* size of allocation*/ - MEM_COMMIT, /* commit */ - PAGE_READONLY); /* protection = read only */ - - if (TestingPointer == NULL ) - { - Fail("ERROR: call to VirtualAlloc failed\n"); - } - - ResultValue = IsBadReadPtr(TestingPointer,16); - if(ResultValue != 0) /* if no access */ - { - if(!VirtualFree(TestingPointer, 0, MEM_RELEASE)) - { - Trace("ERROR: Call to VirtualFree failed with error" - " code[ %u ]\n",GetLastError()); - } - - Fail("ERROR: The function returned %d instead of 1 when checking " - "on unreadable memory.\n",ResultValue); - } - - if(!VirtualFree(TestingPointer,0, MEM_RELEASE)) - { - Fail("ERROR: Call to VirtualFree failed with error" - " code[ %u ]\n",GetLastError()); - } - - /* create an unreadable address */ - TestingPointer = VirtualAlloc( - NULL, /* system selects address */ - 80, /* size of allocation */ - MEM_COMMIT, /* commit */ - PAGE_NOACCESS); /* protection = no access */ - - if (TestingPointer == NULL ) - { - Fail("ERROR: call to VirtualAlloc failed\n"); - } - - ResultValue = IsBadReadPtr(TestingPointer,16); - - if(ResultValue == 0) /* if access */ - { - if(!VirtualFree(TestingPointer, 0, MEM_RELEASE)) - { - Trace("ERROR: Call to VirtualFree failed with error" - " code[ %u ]\n",GetLastError()); - } - - Fail("ERROR: The function returned %d instead of 1 when checking " - "on unreadable memory.\n",ResultValue); - } - - if(!VirtualFree(TestingPointer,0, MEM_RELEASE)) - { - Fail("ERROR: Call to VirtualFree failed with error" - " code[ %u ]\n",GetLastError()); - } - - - /* This should be unreadable and return 1 */ - ResultValue = IsBadReadPtr(NULL,16); - if(ResultValue != 1) - { - Fail("ERROR: The function returned %d instead of 1 when checking " - "to see if NULL was readable.\n",ResultValue); - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/test.cpp new file mode 100644 index 0000000000..24b7ceb7e6 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/IsBadReadPtr/test1/test.cpp @@ -0,0 +1,138 @@ +// 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: IsBadReadPtr() function +** +** +**=========================================================*/ + +#include + +#define MEMORY_AMOUNT 16 + +int __cdecl main(int argc, char *argv[]) +{ + LPVOID TestingPointer = NULL; + BOOL ResultValue = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + TestingPointer = malloc(MEMORY_AMOUNT); + if ( TestingPointer == NULL ) + { + Fail("ERROR: Failed to allocate memory for TestingPointer pointer. " + "Can't properly exec test case without this.\n"); + } + + + /* This should be readable, and return 0 */ + ResultValue = IsBadReadPtr(TestingPointer,MEMORY_AMOUNT); + if(ResultValue != 0) + { + free(TestingPointer); + + Fail("ERROR: The function returned %d instead of 0, when pointing " + "at readable memory.\n",ResultValue); + } + + /* If we pass 0, the result should be 0 as well */ + ResultValue = IsBadReadPtr(TestingPointer,0); + if(ResultValue != 0) + { + free(TestingPointer); + + Fail("ERROR: The function returned %d instead of 0, when the " + "function was passed a range of 0 bytes.\n",ResultValue); + } + free(TestingPointer); /* we are done with this */ + + /* create a READABLE address */ + TestingPointer = VirtualAlloc( + NULL, /* system selects address */ + 80, /* size of allocation*/ + MEM_COMMIT, /* commit */ + PAGE_READONLY); /* protection = read only */ + + if (TestingPointer == NULL ) + { + Fail("ERROR: call to VirtualAlloc failed\n"); + } + + ResultValue = IsBadReadPtr(TestingPointer,16); + if(ResultValue != 0) /* if no access */ + { + if(!VirtualFree(TestingPointer, 0, MEM_RELEASE)) + { + Trace("ERROR: Call to VirtualFree failed with error" + " code[ %u ]\n",GetLastError()); + } + + Fail("ERROR: The function returned %d instead of 1 when checking " + "on unreadable memory.\n",ResultValue); + } + + if(!VirtualFree(TestingPointer,0, MEM_RELEASE)) + { + Fail("ERROR: Call to VirtualFree failed with error" + " code[ %u ]\n",GetLastError()); + } + + /* create an unreadable address */ + TestingPointer = VirtualAlloc( + NULL, /* system selects address */ + 80, /* size of allocation */ + MEM_COMMIT, /* commit */ + PAGE_NOACCESS); /* protection = no access */ + + if (TestingPointer == NULL ) + { + Fail("ERROR: call to VirtualAlloc failed\n"); + } + + ResultValue = IsBadReadPtr(TestingPointer,16); + + if(ResultValue == 0) /* if access */ + { + if(!VirtualFree(TestingPointer, 0, MEM_RELEASE)) + { + Trace("ERROR: Call to VirtualFree failed with error" + " code[ %u ]\n",GetLastError()); + } + + Fail("ERROR: The function returned %d instead of 1 when checking " + "on unreadable memory.\n",ResultValue); + } + + if(!VirtualFree(TestingPointer,0, MEM_RELEASE)) + { + Fail("ERROR: Call to VirtualFree failed with error" + " code[ %u ]\n",GetLastError()); + } + + + /* This should be unreadable and return 1 */ + ResultValue = IsBadReadPtr(NULL,16); + if(ResultValue != 1) + { + Fail("ERROR: The function returned %d instead of 1 when checking " + "to see if NULL was readable.\n",ResultValue); + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/CMakeLists.txt index 2b2e6aae2e..e3a08167b3 100644 --- a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_isbadwriteptr_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/test.c b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/test.c deleted file mode 100644 index 018d7beae0..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/test.c +++ /dev/null @@ -1,81 +0,0 @@ -// 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: IsBadWritePtr() function -** -** -**=========================================================*/ - -#include - -#define MEMORY_AMOUNT 16 - -int __cdecl main(int argc, char *argv[]) { - - void * TestingPointer = NULL; - BOOL ResultValue = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - TestingPointer = malloc(MEMORY_AMOUNT); - if ( TestingPointer == NULL ) - { - Fail("ERROR: Failed to allocate memory for TestingPointer pointer. " - "Can't properly exec test case without this.\n"); - } - - - /* This should be writeable, return 0 */ - ResultValue = IsBadWritePtr(TestingPointer,MEMORY_AMOUNT); - - if(ResultValue != 0) - { - free(TestingPointer); - - Fail("ERROR: Returned %d when 0 should have been returned, checking " - "to see if writable memory is unwriteable.\n",ResultValue); - } - - free(TestingPointer); - - /* This should be !writeable, return nonezero */ - TestingPointer = (void*)0x08; /* non writeable address */ - ResultValue = IsBadWritePtr(TestingPointer,sizeof(int)); - - if(ResultValue == 0) - { - Fail("ERROR: Returned %d when nonezero should have been returned, " - "checking to see if unwriteable memory is writeable.\n", - ResultValue); - } - - /* This should be !writeable, return Nonezero */ - ResultValue = IsBadWritePtr(NULL,MEMORY_AMOUNT); - - if(ResultValue == 0) - { - Fail("ERROR: Returned %d when nonezero should have been " - "returned,checking " - "to see if a NULL pointer is writeable.\n", - ResultValue); - } - - PAL_Terminate(); - return PASS; -} - - - - diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/test.cpp new file mode 100644 index 0000000000..018d7beae0 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test1/test.cpp @@ -0,0 +1,81 @@ +// 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: IsBadWritePtr() function +** +** +**=========================================================*/ + +#include + +#define MEMORY_AMOUNT 16 + +int __cdecl main(int argc, char *argv[]) { + + void * TestingPointer = NULL; + BOOL ResultValue = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + TestingPointer = malloc(MEMORY_AMOUNT); + if ( TestingPointer == NULL ) + { + Fail("ERROR: Failed to allocate memory for TestingPointer pointer. " + "Can't properly exec test case without this.\n"); + } + + + /* This should be writeable, return 0 */ + ResultValue = IsBadWritePtr(TestingPointer,MEMORY_AMOUNT); + + if(ResultValue != 0) + { + free(TestingPointer); + + Fail("ERROR: Returned %d when 0 should have been returned, checking " + "to see if writable memory is unwriteable.\n",ResultValue); + } + + free(TestingPointer); + + /* This should be !writeable, return nonezero */ + TestingPointer = (void*)0x08; /* non writeable address */ + ResultValue = IsBadWritePtr(TestingPointer,sizeof(int)); + + if(ResultValue == 0) + { + Fail("ERROR: Returned %d when nonezero should have been returned, " + "checking to see if unwriteable memory is writeable.\n", + ResultValue); + } + + /* This should be !writeable, return Nonezero */ + ResultValue = IsBadWritePtr(NULL,MEMORY_AMOUNT); + + if(ResultValue == 0) + { + Fail("ERROR: Returned %d when nonezero should have been " + "returned,checking " + "to see if a NULL pointer is writeable.\n", + ResultValue); + } + + PAL_Terminate(); + return PASS; +} + + + + diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/CMakeLists.txt index c033f8054f..718cbaa297 100644 --- a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_isbadwriteptr_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/test2.c b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/test2.c deleted file mode 100644 index 2d4d53e3b7..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/test2.c +++ /dev/null @@ -1,128 +0,0 @@ -// 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: test2.c -** -** Purpose: -** Create three consecuative pages, NOACCES, READWRITE and -** NOACCESS. Check to ensure that the READWRITE page returns 0, to -** ensure that IsBadWritePtr isn't overflowing. Also check the other two -** pages to see that they return non-zero. -** -** -**=========================================================*/ - -#include -#define PAGE_SIZE 4096 - -int __cdecl main(int argc, char *argv[]) { - - LPVOID PageOne, PageTwo, PageThree; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Reserve enough space for four pages. We'll commit this memory - and set the correct access for each page below. - */ - - PageOne = VirtualAlloc(NULL, - PAGE_SIZE*4, - MEM_RESERVE, - PAGE_NOACCESS); - - if(PageOne == NULL) - { - Fail("ERROR: VirtualAlloc failed to reserve the required memory.\n"); - } - - /* Set the first Page to PAGE_NOACCESS */ - - PageOne = VirtualAlloc(PageOne, - PAGE_SIZE, - MEM_COMMIT, - PAGE_NOACCESS); - - if(PageOne == NULL) - { - VirtualFree(PageOne,0,MEM_RELEASE); - - Fail("ERROR: VirtualAlloc failed to commit the required memory " - "for the first page.\n"); - } - - /* Set the second Page to PAGE_READWRITE */ - - PageTwo = VirtualAlloc(((BYTE*)PageOne)+PAGE_SIZE, - PAGE_SIZE, - MEM_COMMIT, - PAGE_READWRITE); - if(PageTwo == NULL) - { - VirtualFree(PageOne,0,MEM_RELEASE); - - Fail("ERROR: VirtualAlloc failed to allocate the required memory " - "for the second page. %d\n",GetLastError()); - } - - /* Set the third Page to PAGE_NOACCESS */ - - PageThree = VirtualAlloc(((BYTE*)PageTwo) + (2 * PAGE_SIZE), - PAGE_SIZE, - MEM_COMMIT, - PAGE_NOACCESS); - - if(PageThree == NULL) - { - VirtualFree(PageOne,0,MEM_RELEASE); - - Fail("ERROR: VirtualAlloc failed to allocate the required memory. " - "For the third page.\n"); - } - - -/* Check that calling IsBadWritePtr on the first page returns non-zero */ - - if(IsBadWritePtr(PageThree,PAGE_SIZE) == 0) - { - VirtualFree(PageOne,0,MEM_RELEASE); - - Fail("ERROR: Called IsBadWritePtr on a page which was set NOACCESS " - "but the return value was 0, indicating that the memory is " - "writable.\n"); - } - - /* Check that calling IsBadWritePtr on the middle page returns 0 */ - - if(IsBadWritePtr(PageTwo,PAGE_SIZE) != 0) - { - VirtualFree(PageOne,0,MEM_RELEASE); - - Fail("ERROR: IsBadWritePtr didn't return 0 when called on a " - "page which should have been writable.\n"); - } - - /* Check that calling IsBadWritePtr on the third page returns non-zero */ - - if(IsBadWritePtr(PageThree,PAGE_SIZE) == 0) - { - VirtualFree(PageOne,0,MEM_RELEASE); - - Fail("ERROR: Called IsBadWritePtr on a page which was set NOACCESS " - "but the return value was 0, indicating that the memory is " - "writable.\n"); - } - VirtualFree(PageOne,0,MEM_RELEASE); - PAL_Terminate(); - return PASS; -} - - - - - diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/test2.cpp b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/test2.cpp new file mode 100644 index 0000000000..2d4d53e3b7 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/test2.cpp @@ -0,0 +1,128 @@ +// 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: test2.c +** +** Purpose: +** Create three consecuative pages, NOACCES, READWRITE and +** NOACCESS. Check to ensure that the READWRITE page returns 0, to +** ensure that IsBadWritePtr isn't overflowing. Also check the other two +** pages to see that they return non-zero. +** +** +**=========================================================*/ + +#include +#define PAGE_SIZE 4096 + +int __cdecl main(int argc, char *argv[]) { + + LPVOID PageOne, PageTwo, PageThree; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Reserve enough space for four pages. We'll commit this memory + and set the correct access for each page below. + */ + + PageOne = VirtualAlloc(NULL, + PAGE_SIZE*4, + MEM_RESERVE, + PAGE_NOACCESS); + + if(PageOne == NULL) + { + Fail("ERROR: VirtualAlloc failed to reserve the required memory.\n"); + } + + /* Set the first Page to PAGE_NOACCESS */ + + PageOne = VirtualAlloc(PageOne, + PAGE_SIZE, + MEM_COMMIT, + PAGE_NOACCESS); + + if(PageOne == NULL) + { + VirtualFree(PageOne,0,MEM_RELEASE); + + Fail("ERROR: VirtualAlloc failed to commit the required memory " + "for the first page.\n"); + } + + /* Set the second Page to PAGE_READWRITE */ + + PageTwo = VirtualAlloc(((BYTE*)PageOne)+PAGE_SIZE, + PAGE_SIZE, + MEM_COMMIT, + PAGE_READWRITE); + if(PageTwo == NULL) + { + VirtualFree(PageOne,0,MEM_RELEASE); + + Fail("ERROR: VirtualAlloc failed to allocate the required memory " + "for the second page. %d\n",GetLastError()); + } + + /* Set the third Page to PAGE_NOACCESS */ + + PageThree = VirtualAlloc(((BYTE*)PageTwo) + (2 * PAGE_SIZE), + PAGE_SIZE, + MEM_COMMIT, + PAGE_NOACCESS); + + if(PageThree == NULL) + { + VirtualFree(PageOne,0,MEM_RELEASE); + + Fail("ERROR: VirtualAlloc failed to allocate the required memory. " + "For the third page.\n"); + } + + +/* Check that calling IsBadWritePtr on the first page returns non-zero */ + + if(IsBadWritePtr(PageThree,PAGE_SIZE) == 0) + { + VirtualFree(PageOne,0,MEM_RELEASE); + + Fail("ERROR: Called IsBadWritePtr on a page which was set NOACCESS " + "but the return value was 0, indicating that the memory is " + "writable.\n"); + } + + /* Check that calling IsBadWritePtr on the middle page returns 0 */ + + if(IsBadWritePtr(PageTwo,PAGE_SIZE) != 0) + { + VirtualFree(PageOne,0,MEM_RELEASE); + + Fail("ERROR: IsBadWritePtr didn't return 0 when called on a " + "page which should have been writable.\n"); + } + + /* Check that calling IsBadWritePtr on the third page returns non-zero */ + + if(IsBadWritePtr(PageThree,PAGE_SIZE) == 0) + { + VirtualFree(PageOne,0,MEM_RELEASE); + + Fail("ERROR: Called IsBadWritePtr on a page which was set NOACCESS " + "but the return value was 0, indicating that the memory is " + "writable.\n"); + } + VirtualFree(PageOne,0,MEM_RELEASE); + PAL_Terminate(); + return PASS; +} + + + + + diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/CMakeLists.txt index 32cb901e8d..0efd3179db 100644 --- a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_isbadwriteptr_test3 diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/test3.c b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/test3.c deleted file mode 100644 index 4c058a8987..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/test3.c +++ /dev/null @@ -1,58 +0,0 @@ -// 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: test3.c -** -** Purpose: -** Check that IsBadWritePtr returns non-zero on Read-only memory. -** -** -**=========================================================*/ - -#include - -#define PAGE_SIZE 4096 - -int __cdecl main(int argc, char *argv[]) { - - LPVOID PageOne; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Reserve enough space for four pages. We'll commit this memory - and set the correct access for each page below. - */ - - PageOne = VirtualAlloc(NULL, - PAGE_SIZE, - MEM_COMMIT, - PAGE_READONLY); - - if(PageOne == NULL) - { - Fail("ERROR: VirtualAlloc failed to commit the required memory.\n"); - } - - if(IsBadWritePtr(PageOne,PAGE_SIZE) == 0) - { - VirtualFree(PageOne,0,MEM_RELEASE); - - Fail("ERROR: IsBadWritePtr returned 0 when checking a section of " - "read-only memory. It should be non-zero.\n"); - } - - VirtualFree(PageOne,0,MEM_RELEASE); - PAL_Terminate(); - return PASS; -} - - - - - diff --git a/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/test3.cpp b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/test3.cpp new file mode 100644 index 0000000000..4c058a8987 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test3/test3.cpp @@ -0,0 +1,58 @@ +// 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: test3.c +** +** Purpose: +** Check that IsBadWritePtr returns non-zero on Read-only memory. +** +** +**=========================================================*/ + +#include + +#define PAGE_SIZE 4096 + +int __cdecl main(int argc, char *argv[]) { + + LPVOID PageOne; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Reserve enough space for four pages. We'll commit this memory + and set the correct access for each page below. + */ + + PageOne = VirtualAlloc(NULL, + PAGE_SIZE, + MEM_COMMIT, + PAGE_READONLY); + + if(PageOne == NULL) + { + Fail("ERROR: VirtualAlloc failed to commit the required memory.\n"); + } + + if(IsBadWritePtr(PageOne,PAGE_SIZE) == 0) + { + VirtualFree(PageOne,0,MEM_RELEASE); + + Fail("ERROR: IsBadWritePtr returned 0 when checking a section of " + "read-only memory. It should be non-zero.\n"); + } + + VirtualFree(PageOne,0,MEM_RELEASE); + PAL_Terminate(); + return PASS; +} + + + + + diff --git a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/CMakeLists.txt index 5e77e8ba98..bc80853ea1 100644 --- a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_messageboxw_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/test.c deleted file mode 100644 index 8eb8c0eb7e..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/test.c +++ /dev/null @@ -1,81 +0,0 @@ -// 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 MessageBoxW() function -** -** -**=========================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char *argv[]) -{ - /* Declare Variables to use with convert()*/ - WCHAR * PalTitle = NULL; - WCHAR * OkTesting = NULL; - WCHAR * AbortTesting = NULL; - WCHAR * YesTesting = NULL; - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - PalTitle = convert("Pal Testing"); - OkTesting = convert("Click OK Please!"); - - /* Handle, text, title, style */ - if(MessageBox(NULL, OkTesting, - PalTitle, - MB_OK) != IDOK) - { - free(OkTesting); - free(PalTitle); - Fail("ERROR: The MB_OK style should return IDOK."); - } - - free(OkTesting); - AbortTesting = convert("Click Abort Please!"); - if(MessageBox(NULL, - AbortTesting, - PalTitle, - MB_ABORTRETRYIGNORE) != IDABORT) - { - free(AbortTesting); - free(PalTitle); - Fail("ERROR: The MB_ABORTRETRYIGNORE style should " - "return IDABORT."); - } - - free(AbortTesting); - YesTesting = convert("Click No Please!"); - - if(MessageBox(NULL, - YesTesting, - PalTitle, - MB_YESNO) != IDNO) - { - free(PalTitle); - free(YesTesting); - Fail("ERROR: The MB_YESNO style should return IDNO."); - } - - free(YesTesting); - free(PalTitle); - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/test.cpp new file mode 100644 index 0000000000..8eb8c0eb7e --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test1/test.cpp @@ -0,0 +1,81 @@ +// 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 MessageBoxW() function +** +** +**=========================================================*/ + +#define UNICODE + +#include + +int __cdecl main(int argc, char *argv[]) +{ + /* Declare Variables to use with convert()*/ + WCHAR * PalTitle = NULL; + WCHAR * OkTesting = NULL; + WCHAR * AbortTesting = NULL; + WCHAR * YesTesting = NULL; + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + PalTitle = convert("Pal Testing"); + OkTesting = convert("Click OK Please!"); + + /* Handle, text, title, style */ + if(MessageBox(NULL, OkTesting, + PalTitle, + MB_OK) != IDOK) + { + free(OkTesting); + free(PalTitle); + Fail("ERROR: The MB_OK style should return IDOK."); + } + + free(OkTesting); + AbortTesting = convert("Click Abort Please!"); + if(MessageBox(NULL, + AbortTesting, + PalTitle, + MB_ABORTRETRYIGNORE) != IDABORT) + { + free(AbortTesting); + free(PalTitle); + Fail("ERROR: The MB_ABORTRETRYIGNORE style should " + "return IDABORT."); + } + + free(AbortTesting); + YesTesting = convert("Click No Please!"); + + if(MessageBox(NULL, + YesTesting, + PalTitle, + MB_YESNO) != IDNO) + { + free(PalTitle); + free(YesTesting); + Fail("ERROR: The MB_YESNO style should return IDNO."); + } + + free(YesTesting); + free(PalTitle); + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/CMakeLists.txt index 4b0af2e77e..b8993af4cf 100644 --- a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_messageboxw_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/test.c b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/test.c deleted file mode 100644 index e2ff0cf6d6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/test.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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 MessageBoxW() function -** -** -**=========================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char *argv[]) { - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Check to make sure there are no problems accepting all the ICON - styles and FLAG styles. These don't change anything, unless - they don't work at all. - */ - - if(MessageBox(NULL, - convert("Pal Testing"), - convert("Pal Title"), - MB_OK |MB_ICONEXCLAMATION|MB_TASKMODAL) != IDOK) - { - Fail("ERROR: The MB_OK style should always return IDOK."); - } - - if(MessageBox(NULL, - convert("Pal Testing"), - convert("Pal Title"), - MB_OK |MB_ICONINFORMATION|MB_SYSTEMMODAL) != IDOK) - { - Fail("ERROR: The MB_OK style should always return IDOK."); - } - - /* MB_SERVICE_NOTIFICATION doesn't seem to be available under windows? - It claims it exists and it should be supported under FreeBSD. - */ - -#if UNIX - if(MessageBox(NULL, - convert("Pal Testing"), - convert("Pal Title"), - MB_OK |MB_ICONSTOP|MB_SERVICE_NOTIFICATION) != IDOK) - { - Fail("ERROR: The MB_OK style should always return IDOK."); - } -#endif - - if(MessageBox(NULL, - convert("Pal Testing"), - convert("Pal Title"), - MB_OK |MB_ICONQUESTION) != IDOK) - { - Fail("ERROR: The MB_OK style should always return IDOK."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/test.cpp new file mode 100644 index 0000000000..e2ff0cf6d6 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/MessageBoxW/test2/test.cpp @@ -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 MessageBoxW() function +** +** +**=========================================================*/ + +#define UNICODE + +#include + +int __cdecl main(int argc, char *argv[]) { + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Check to make sure there are no problems accepting all the ICON + styles and FLAG styles. These don't change anything, unless + they don't work at all. + */ + + if(MessageBox(NULL, + convert("Pal Testing"), + convert("Pal Title"), + MB_OK |MB_ICONEXCLAMATION|MB_TASKMODAL) != IDOK) + { + Fail("ERROR: The MB_OK style should always return IDOK."); + } + + if(MessageBox(NULL, + convert("Pal Testing"), + convert("Pal Title"), + MB_OK |MB_ICONINFORMATION|MB_SYSTEMMODAL) != IDOK) + { + Fail("ERROR: The MB_OK style should always return IDOK."); + } + + /* MB_SERVICE_NOTIFICATION doesn't seem to be available under windows? + It claims it exists and it should be supported under FreeBSD. + */ + +#if UNIX + if(MessageBox(NULL, + convert("Pal Testing"), + convert("Pal Title"), + MB_OK |MB_ICONSTOP|MB_SERVICE_NOTIFICATION) != IDOK) + { + Fail("ERROR: The MB_OK style should always return IDOK."); + } +#endif + + if(MessageBox(NULL, + convert("Pal Testing"), + convert("Pal Title"), + MB_OK |MB_ICONQUESTION) != IDOK) + { + Fail("ERROR: The MB_OK style should always return IDOK."); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/CMakeLists.txt index b66248522b..5d63281eab 100644 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_setenvironmentvariablea_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/test1.c b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/test1.c deleted file mode 100644 index 86a44218f1..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/test1.c +++ /dev/null @@ -1,168 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for SetEnvironmentVariableA() function. Set an -** environment variable and check to ensure success was returned. Then -** get the environment variable and compare to the correct value. Also, check -** that calling the function again, resets the variable properly. And that -** calling with NULL deletes the variable. -** -** Depends: -** GetEnvironmentVariable -** memcmp -** memset -** strlen -** -** -**=========================================================*/ - -#include -#define BUF_SIZE 128 - -int __cdecl main(int argc, char *argv[]) -{ - - /* Define some buffers needed for the function */ - char* VariableBuffer = "PALTEST"; - char* ValueBuffer = "Testing"; - char* SecondValueBuffer = "SecondTest"; - char NewValue[BUF_SIZE]; - int SetResult = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - - - /* - Test #1 - ======= - */ - - SetResult = SetEnvironmentVariable(VariableBuffer, - ValueBuffer); - - /* If result is 0, the SetEnviron function failed */ - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " - "it failed, even though it should have succeeded in setting the " - "variable PALTEST.\n"); - } - - memset(NewValue,0,BUF_SIZE); - - /* Grab the Environment variable we just set */ - if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0) - { - Fail("ERROR: GetEnvironmentVariable returned 0 or less, which " - "indicates that no value was read in from the given variable."); - } - - /* Make sure that the value put into NewValue was indeed the environment - variable we set. - */ - - if(memcmp(NewValue,ValueBuffer,strlen(ValueBuffer)+1) != 0) - { - Fail("ERROR: When retrieving the variable that was just set, a " - "difference was found. Instead of the value being '%s' it " - "was instead '%s'.\n",ValueBuffer,NewValue); - } - - - - /* - Test #2 - ======= - */ - - /* If we set the same environment variable with a different value, the - old value should be replaced. - */ - - SetResult = SetEnvironmentVariable(VariableBuffer, - SecondValueBuffer); - - /* If result is 0, the SetEnviron function failed */ - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " - "it failed, even though it should have succeeded in re-setting " - "the variable PALTEST.\n"); - } - - memset(NewValue,0,BUF_SIZE); - - /* Grab the Environment variable we just set */ - if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0) - { - Fail("ERROR: GetEnvironmentVariable returned 0 or less, which " - "indicates that no value was read in from the given variable."); - } - - /* Make sure that the value put into NewValue was indeed the environment - variable we set. - */ - - if(memcmp(NewValue,SecondValueBuffer,strlen(SecondValueBuffer)+1) != 0) - { - Fail("ERROR: When retrieving the variable that was just set, a " - "difference was found. Instead of the value being '%s' it " - "was instead '%s'.\n",SecondValueBuffer,NewValue); - } - - - - /* - Test #3 - ======= - */ - - /* Finally, set this variable with NULL, which should delete it from the - current environment. - */ - - SetResult = SetEnvironmentVariable(VariableBuffer, NULL); - - /* If result is 0, the SetEnviron function failed */ - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " - "it failed, even though it should have succeeded in deleting " - "the variable PALTEST.\n"); - } - - memset(NewValue,0,BUF_SIZE); - - /* Grab the Environment variable we just set, ensure that it's - empty now. - */ - if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) != 0) - { - Fail("ERROR: GetEnvironmentVariable returned a non-zero value, " - "even though the environment variable which was checked should " - "have been empty."); - } - - - /* - Clean Up - */ - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/test1.cpp b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/test1.cpp new file mode 100644 index 0000000000..86a44218f1 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test1/test1.cpp @@ -0,0 +1,168 @@ +// 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: test1.c +** +** Purpose: Test for SetEnvironmentVariableA() function. Set an +** environment variable and check to ensure success was returned. Then +** get the environment variable and compare to the correct value. Also, check +** that calling the function again, resets the variable properly. And that +** calling with NULL deletes the variable. +** +** Depends: +** GetEnvironmentVariable +** memcmp +** memset +** strlen +** +** +**=========================================================*/ + +#include +#define BUF_SIZE 128 + +int __cdecl main(int argc, char *argv[]) +{ + + /* Define some buffers needed for the function */ + char* VariableBuffer = "PALTEST"; + char* ValueBuffer = "Testing"; + char* SecondValueBuffer = "SecondTest"; + char NewValue[BUF_SIZE]; + int SetResult = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + + + /* + Test #1 + ======= + */ + + SetResult = SetEnvironmentVariable(VariableBuffer, + ValueBuffer); + + /* If result is 0, the SetEnviron function failed */ + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " + "it failed, even though it should have succeeded in setting the " + "variable PALTEST.\n"); + } + + memset(NewValue,0,BUF_SIZE); + + /* Grab the Environment variable we just set */ + if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0) + { + Fail("ERROR: GetEnvironmentVariable returned 0 or less, which " + "indicates that no value was read in from the given variable."); + } + + /* Make sure that the value put into NewValue was indeed the environment + variable we set. + */ + + if(memcmp(NewValue,ValueBuffer,strlen(ValueBuffer)+1) != 0) + { + Fail("ERROR: When retrieving the variable that was just set, a " + "difference was found. Instead of the value being '%s' it " + "was instead '%s'.\n",ValueBuffer,NewValue); + } + + + + /* + Test #2 + ======= + */ + + /* If we set the same environment variable with a different value, the + old value should be replaced. + */ + + SetResult = SetEnvironmentVariable(VariableBuffer, + SecondValueBuffer); + + /* If result is 0, the SetEnviron function failed */ + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " + "it failed, even though it should have succeeded in re-setting " + "the variable PALTEST.\n"); + } + + memset(NewValue,0,BUF_SIZE); + + /* Grab the Environment variable we just set */ + if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0) + { + Fail("ERROR: GetEnvironmentVariable returned 0 or less, which " + "indicates that no value was read in from the given variable."); + } + + /* Make sure that the value put into NewValue was indeed the environment + variable we set. + */ + + if(memcmp(NewValue,SecondValueBuffer,strlen(SecondValueBuffer)+1) != 0) + { + Fail("ERROR: When retrieving the variable that was just set, a " + "difference was found. Instead of the value being '%s' it " + "was instead '%s'.\n",SecondValueBuffer,NewValue); + } + + + + /* + Test #3 + ======= + */ + + /* Finally, set this variable with NULL, which should delete it from the + current environment. + */ + + SetResult = SetEnvironmentVariable(VariableBuffer, NULL); + + /* If result is 0, the SetEnviron function failed */ + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " + "it failed, even though it should have succeeded in deleting " + "the variable PALTEST.\n"); + } + + memset(NewValue,0,BUF_SIZE); + + /* Grab the Environment variable we just set, ensure that it's + empty now. + */ + if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) != 0) + { + Fail("ERROR: GetEnvironmentVariable returned a non-zero value, " + "even though the environment variable which was checked should " + "have been empty."); + } + + + /* + Clean Up + */ + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/CMakeLists.txt index c062c6df65..fe05887c3e 100644 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_setenvironmentvariablea_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/test2.c b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/test2.c deleted file mode 100644 index 984007e6f1..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/test2.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: test2.c -** -** Purpose: Test for SetEnvironmentVariableA() function -** Test to see that passing NULL to the first param fails. -** Test that passing NULL to both params fails. -** Set an environment variable, then pass NULL to the second param -** to delete it. Then make the same call again, to check that it fails. -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - /* Define some buffers needed for the function */ - char* VariableBuffer = "PALTEST"; - char* ValueBuffer = "testing"; - int SetResult; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Check that it fails if the first param is NULL */ - - SetResult = SetEnvironmentVariable(NULL,ValueBuffer); - - if(SetResult != 0) - { - Fail("ERROR: SetEnvironmentVariable returned a success value, " - "even though it was passed NULL as the first parameter and " - "should have failed.\n"); - } - - /* Check that it fails when both params are NULL */ - SetResult = SetEnvironmentVariable(NULL,NULL); - if(SetResult != 0) - { - Fail("ERROR: SetEnvironmentVariable returned a success value, even " - "though it was passed NULL as the first and second parameter and " - "should have failed.\n"); - } - - - /* First, set the variable, which should be ok. Then call the - function with the second parameter NULL twice -- the first call should - pass, the second should fail. - */ - - SetResult = SetEnvironmentVariable(VariableBuffer,ValueBuffer); - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned failure, when " - "attempting to set a valid variable.\n"); - } - - SetResult = SetEnvironmentVariable(VariableBuffer,NULL); - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned failure, when " - "attempting to delete a variable.\n"); - } - - SetResult = SetEnvironmentVariable(VariableBuffer,NULL); - if(SetResult != 0) - { - Fail("ERROR: SetEnvironmentVariable returned success, when " - "attempting to delete a variable which doesn't exist.\n"); - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/test2.cpp b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/test2.cpp new file mode 100644 index 0000000000..984007e6f1 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test2/test2.cpp @@ -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: test2.c +** +** Purpose: Test for SetEnvironmentVariableA() function +** Test to see that passing NULL to the first param fails. +** Test that passing NULL to both params fails. +** Set an environment variable, then pass NULL to the second param +** to delete it. Then make the same call again, to check that it fails. +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + /* Define some buffers needed for the function */ + char* VariableBuffer = "PALTEST"; + char* ValueBuffer = "testing"; + int SetResult; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Check that it fails if the first param is NULL */ + + SetResult = SetEnvironmentVariable(NULL,ValueBuffer); + + if(SetResult != 0) + { + Fail("ERROR: SetEnvironmentVariable returned a success value, " + "even though it was passed NULL as the first parameter and " + "should have failed.\n"); + } + + /* Check that it fails when both params are NULL */ + SetResult = SetEnvironmentVariable(NULL,NULL); + if(SetResult != 0) + { + Fail("ERROR: SetEnvironmentVariable returned a success value, even " + "though it was passed NULL as the first and second parameter and " + "should have failed.\n"); + } + + + /* First, set the variable, which should be ok. Then call the + function with the second parameter NULL twice -- the first call should + pass, the second should fail. + */ + + SetResult = SetEnvironmentVariable(VariableBuffer,ValueBuffer); + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned failure, when " + "attempting to set a valid variable.\n"); + } + + SetResult = SetEnvironmentVariable(VariableBuffer,NULL); + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned failure, when " + "attempting to delete a variable.\n"); + } + + SetResult = SetEnvironmentVariable(VariableBuffer,NULL); + if(SetResult != 0) + { + Fail("ERROR: SetEnvironmentVariable returned success, when " + "attempting to delete a variable which doesn't exist.\n"); + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/CMakeLists.txt index 159f574abe..98c9dc0a63 100644 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_setenvironmentvariablea_test3 diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.c b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.c deleted file mode 100644 index fa24275da7..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.c +++ /dev/null @@ -1,144 +0,0 @@ -// 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 : test3.c -** -** Purpose: Test for SetEnvironmentVariableA() function -** Create environment variables that differ only -** in case and verify that they return the appropriate -** value on the BSD environment. -** -** -===========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - - return PASS; - -#else - - /* Define some buffers needed for the function */ - char * pResultBuffer = NULL; - - char FirstEnvironmentVariable[] = {"PALTEST"}; - char FirstEnvironmentValue[] = {"FIRST"}; - - char SecondEnvironmentVariable[] = {"paltest"}; - char SecondEnvironmentValue[] = {"SECOND"}; - - DWORD size = 0; - BOOL bRc = TRUE; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Set the first environment variable */ - bRc = SetEnvironmentVariableA(FirstEnvironmentVariable, - FirstEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - /* Set the second environment Variable */ - bRc = SetEnvironmentVariableA(SecondEnvironmentVariable, - SecondEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - - /* Normal case, PATH should fit into this buffer */ - size = GetEnvironmentVariableA(FirstEnvironmentVariable, - pResultBuffer, - 0); - - /* increase size to account for the null char at the end */ - size = size + 1; - - pResultBuffer = malloc(sizeof(char)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try to retrieve the value of the first environment variable */ - GetEnvironmentVariable(FirstEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - free(pResultBuffer); - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the strings to see that the correct variable was returned */ - if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) - { - Trace("ERROR: The value in the buffer should have been '%s' but " - "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer); - free(pResultBuffer); - Fail(""); - } - - free(pResultBuffer); - - /* Reallocate the memory for the string */ - pResultBuffer = malloc(sizeof(char)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try retrieving the value of the first variable, even though the - second variable has the same spelling and only differs in case */ - GetEnvironmentVariable(SecondEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the two strings to confirm that the right value is returned */ - if(strcmp(pResultBuffer,SecondEnvironmentValue) != 0) - { - Trace("ERROR: The value in the buffer should have been '%s' but " - "was really '%s'.\n",SecondEnvironmentValue,pResultBuffer); - free(pResultBuffer); - Fail(""); - } - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; - -#endif -} diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.cpp b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.cpp new file mode 100644 index 0000000000..539e33004b --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test3/test3.cpp @@ -0,0 +1,144 @@ +// 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 : test3.c +** +** Purpose: Test for SetEnvironmentVariableA() function +** Create environment variables that differ only +** in case and verify that they return the appropriate +** value on the BSD environment. +** +** +===========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + + return PASS; + +#else + + /* Define some buffers needed for the function */ + char * pResultBuffer = NULL; + + char FirstEnvironmentVariable[] = {"PALTEST"}; + char FirstEnvironmentValue[] = {"FIRST"}; + + char SecondEnvironmentVariable[] = {"paltest"}; + char SecondEnvironmentValue[] = {"SECOND"}; + + DWORD size = 0; + BOOL bRc = TRUE; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set the first environment variable */ + bRc = SetEnvironmentVariableA(FirstEnvironmentVariable, + FirstEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Set the second environment Variable */ + bRc = SetEnvironmentVariableA(SecondEnvironmentVariable, + SecondEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariableA(FirstEnvironmentVariable, + pResultBuffer, + 0); + + /* increase size to account for the null char at the end */ + size = size + 1; + + pResultBuffer = (char*)malloc(sizeof(char)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariable(FirstEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + free(pResultBuffer); + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the strings to see that the correct variable was returned */ + if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) + { + Trace("ERROR: The value in the buffer should have been '%s' but " + "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer); + free(pResultBuffer); + Fail(""); + } + + free(pResultBuffer); + + /* Reallocate the memory for the string */ + pResultBuffer = (char*)malloc(sizeof(char)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try retrieving the value of the first variable, even though the + second variable has the same spelling and only differs in case */ + GetEnvironmentVariable(SecondEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the two strings to confirm that the right value is returned */ + if(strcmp(pResultBuffer,SecondEnvironmentValue) != 0) + { + Trace("ERROR: The value in the buffer should have been '%s' but " + "was really '%s'.\n",SecondEnvironmentValue,pResultBuffer); + free(pResultBuffer); + Fail(""); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + +#endif +} diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/CMakeLists.txt index 29cca8d7b4..1c53d4b6a1 100644 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_setenvironmentvariablea_test4 diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/test4.c b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/test4.c deleted file mode 100644 index 557cef74c9..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/test4.c +++ /dev/null @@ -1,100 +0,0 @@ -// 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 : test4.c -** -** Purpose: Test for SetEnvironmentVariableA() function -** Create environment variables that differ only -** in case and verify that they return the appropriate -** value in the WIN32 Environment -** - -** -===========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - - /* Define some buffers needed for the function */ - char * pResultBuffer = NULL; - - char FirstEnvironmentVariable[] = {"PALTEST"}; - char FirstEnvironmentValue[] = {"FIRST"}; - char ModifiedEnvVar[] = {"paltest"}; - - DWORD size = 0; - BOOL bRc = TRUE; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Set the first environment variable */ - bRc = SetEnvironmentVariableA(FirstEnvironmentVariable, - FirstEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - /* Normal case, PATH should fit into this buffer */ - size = GetEnvironmentVariableA(ModifiedEnvVar, - pResultBuffer, - 0); - - /* To account for the null character at the end of the string */ - size = size + 1; - - pResultBuffer = malloc(sizeof(char)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try to retrieve the value of the first environment variable */ - GetEnvironmentVariableA(ModifiedEnvVar, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - free(pResultBuffer); - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the strings to see that the correct variable was returned */ - if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) - { - Trace("ERROR: The value in the buffer should have been '%s' but " - "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer); - free(pResultBuffer); - Fail(""); - } - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; - - -#else - - return PASS; -#endif -} diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/test4.cpp b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/test4.cpp new file mode 100644 index 0000000000..de3059c8d8 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableA/test4/test4.cpp @@ -0,0 +1,100 @@ +// 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 : test4.c +** +** Purpose: Test for SetEnvironmentVariableA() function +** Create environment variables that differ only +** in case and verify that they return the appropriate +** value in the WIN32 Environment +** + +** +===========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + + /* Define some buffers needed for the function */ + char * pResultBuffer = NULL; + + char FirstEnvironmentVariable[] = {"PALTEST"}; + char FirstEnvironmentValue[] = {"FIRST"}; + char ModifiedEnvVar[] = {"paltest"}; + + DWORD size = 0; + BOOL bRc = TRUE; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set the first environment variable */ + bRc = SetEnvironmentVariableA(FirstEnvironmentVariable, + FirstEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariableA(ModifiedEnvVar, + pResultBuffer, + 0); + + /* To account for the null character at the end of the string */ + size = size + 1; + + pResultBuffer = (char*)malloc(sizeof(char)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariableA(ModifiedEnvVar, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + free(pResultBuffer); + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the strings to see that the correct variable was returned */ + if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0) + { + Trace("ERROR: The value in the buffer should have been '%s' but " + "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer); + free(pResultBuffer); + Fail(""); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + + +#else + + return PASS; +#endif +} diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/CMakeLists.txt index 247dceefd9..6eb52ab92e 100644 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_setenvironmentvariablew_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.c deleted file mode 100644 index bddbba7940..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.c +++ /dev/null @@ -1,142 +0,0 @@ -// 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: -** Set an environment variable and check to ensure success was returned. Then -** get the environment variable and compare to the correct value. Also, check -** that calling the function again, resets the variable properly. And that -** calling with NULL deletes the variable. -** -** -**=========================================================*/ - -#define UNICODE -#define BUF_SIZE 128 - -#include - -/* Depends on GetEnvironmentVariable */ - -int __cdecl main(int argc, char *argv[]) -{ - - /* Define some buffers needed for the function */ - WCHAR VariableBuffer[] = {'P','A','L','T','E','S','T','\0'}; - WCHAR ValueBuffer[] = {'T','e','s','t','i','n','g','\0'}; - WCHAR SecondValueBuffer[] = {'S','e','c','o','n','d','T','e','s','t','\0'}; - WCHAR NewValue[BUF_SIZE]; - int SetResult = 0; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - SetResult = SetEnvironmentVariable(VariableBuffer, - ValueBuffer); - - /* If result is 0, the SetEnviron function failed */ - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " - "it failed, even though it should have succeeded in setting the " - "variable PALTEST.\n"); - } - - - /* Grab the Environment variable we just set */ - if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0) - { - Fail("ERROR: GetEnvironmentVariable returned 0 or less, which " - "indicates that no value was read in from the given variable."); - } - - /* Make sure that the value put into NewValue was indeed the environment - variable we set. - */ - - if(memcmp(NewValue,ValueBuffer,wcslen(ValueBuffer)*sizeof(WCHAR)+2) != 0) - { - Fail("ERROR: When retrieving the variable that was just set, a " - "difference was found. Instead of the value being '%s' it " - "was instead '%s'.\n",convertC(ValueBuffer),convertC(NewValue)); - } - - /* If we set the same environment variable with a different value, the - old value should be replaced. - */ - - SetResult = SetEnvironmentVariable(VariableBuffer, - SecondValueBuffer); - - /* If result is 0, the SetEnviron function failed */ - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " - "it failed, even though it should have succeeded in re-setting " - "the variable PALTEST.\n"); - } - - memset(NewValue,0,BUF_SIZE); - - /* Grab the Environment variable we just set */ - if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0) - { - Fail("ERROR: GetEnvironmentVariable returned 0 or less, which " - "indicates that no value was read in from the given variable."); - } - - /* Make sure that the value put into NewValue was indeed the environment - variable we set. - */ - - if(memcmp(NewValue,SecondValueBuffer, - wcslen(SecondValueBuffer)*sizeof(WCHAR)+2) != 0) - { - Fail("ERROR: When retrieving the variable that was just set, a " - "difference was found. Instead of the value being '%s' it " - "was instead '%s'.\n", - convertC(SecondValueBuffer),convertC(NewValue)); - } - - /* Finally, set this variable with NULL, which should delete it from the - current environment. - */ - - SetResult = SetEnvironmentVariable(VariableBuffer, NULL); - - /* If result is 0, the SetEnviron function failed */ - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " - "it failed, even though it should have succeeded in deleting " - "the variable PALTEST.\n"); - } - - memset(NewValue,0,BUF_SIZE); - - /* Grab the Environment variable we just set, ensure that it's - empty now. - */ - if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) != 0) - { - Fail("ERROR: GetEnvironmentVariable returned a non-zero value, " - "even though the environment variable which was checked should " - "have been empty."); - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp new file mode 100644 index 0000000000..bddbba7940 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp @@ -0,0 +1,142 @@ +// 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: +** Set an environment variable and check to ensure success was returned. Then +** get the environment variable and compare to the correct value. Also, check +** that calling the function again, resets the variable properly. And that +** calling with NULL deletes the variable. +** +** +**=========================================================*/ + +#define UNICODE +#define BUF_SIZE 128 + +#include + +/* Depends on GetEnvironmentVariable */ + +int __cdecl main(int argc, char *argv[]) +{ + + /* Define some buffers needed for the function */ + WCHAR VariableBuffer[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR ValueBuffer[] = {'T','e','s','t','i','n','g','\0'}; + WCHAR SecondValueBuffer[] = {'S','e','c','o','n','d','T','e','s','t','\0'}; + WCHAR NewValue[BUF_SIZE]; + int SetResult = 0; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + SetResult = SetEnvironmentVariable(VariableBuffer, + ValueBuffer); + + /* If result is 0, the SetEnviron function failed */ + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " + "it failed, even though it should have succeeded in setting the " + "variable PALTEST.\n"); + } + + + /* Grab the Environment variable we just set */ + if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0) + { + Fail("ERROR: GetEnvironmentVariable returned 0 or less, which " + "indicates that no value was read in from the given variable."); + } + + /* Make sure that the value put into NewValue was indeed the environment + variable we set. + */ + + if(memcmp(NewValue,ValueBuffer,wcslen(ValueBuffer)*sizeof(WCHAR)+2) != 0) + { + Fail("ERROR: When retrieving the variable that was just set, a " + "difference was found. Instead of the value being '%s' it " + "was instead '%s'.\n",convertC(ValueBuffer),convertC(NewValue)); + } + + /* If we set the same environment variable with a different value, the + old value should be replaced. + */ + + SetResult = SetEnvironmentVariable(VariableBuffer, + SecondValueBuffer); + + /* If result is 0, the SetEnviron function failed */ + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " + "it failed, even though it should have succeeded in re-setting " + "the variable PALTEST.\n"); + } + + memset(NewValue,0,BUF_SIZE); + + /* Grab the Environment variable we just set */ + if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0) + { + Fail("ERROR: GetEnvironmentVariable returned 0 or less, which " + "indicates that no value was read in from the given variable."); + } + + /* Make sure that the value put into NewValue was indeed the environment + variable we set. + */ + + if(memcmp(NewValue,SecondValueBuffer, + wcslen(SecondValueBuffer)*sizeof(WCHAR)+2) != 0) + { + Fail("ERROR: When retrieving the variable that was just set, a " + "difference was found. Instead of the value being '%s' it " + "was instead '%s'.\n", + convertC(SecondValueBuffer),convertC(NewValue)); + } + + /* Finally, set this variable with NULL, which should delete it from the + current environment. + */ + + SetResult = SetEnvironmentVariable(VariableBuffer, NULL); + + /* If result is 0, the SetEnviron function failed */ + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned 0, which indicates that " + "it failed, even though it should have succeeded in deleting " + "the variable PALTEST.\n"); + } + + memset(NewValue,0,BUF_SIZE); + + /* Grab the Environment variable we just set, ensure that it's + empty now. + */ + if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) != 0) + { + Fail("ERROR: GetEnvironmentVariable returned a non-zero value, " + "even though the environment variable which was checked should " + "have been empty."); + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/CMakeLists.txt index a69343ccd5..a82d849bde 100644 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_setenvironmentvariablew_test2 diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/test.c b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/test.c deleted file mode 100644 index 12f4887b6d..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/test.c +++ /dev/null @@ -1,88 +0,0 @@ -// 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 SetEnvironmentVariableW() function -** Test to see that passing NULL to the first param fails. -** Test that passing NULL to both params fails. -** Set an environment variable, then pass NULL to the second param -** to delete it. Then make the same call again, to check that it fails. -** -** -**=========================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - /* Define some buffers needed for the function */ - WCHAR VariableBuffer[] = {'P','A','L','T','E','S','T','\0'}; - WCHAR ValueBuffer[] = {'T','e','s','t','i','n','g','\0'}; - int SetResult; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - SetResult = SetEnvironmentVariable(NULL,ValueBuffer); - - /* Check that it fails if the first param is NULL */ - if(SetResult != 0) - { - Fail("ERROR: SetEnvironmentVariable returned a success value, " - "even though it was passed NULL as the first parameter and " - "should have failed.\n"); - } - - /* Check that it fails when both params are NULL */ - SetResult = SetEnvironmentVariable(NULL,NULL); - if(SetResult != 0) - { - Fail("ERROR: SetEnvironmentVariable returned a success value, even " - "though it was passed NULL as the first and second parameter and " - "should have failed.\n"); - } - - /* First, set the variable, which should be ok. Then call the - function with the second parameter NULL twice -- the first call should - pass, the second should fail. - */ - SetResult = SetEnvironmentVariable(VariableBuffer,ValueBuffer); - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned failure, when " - "attempting to set a valid variable.\n"); - } - - SetResult = SetEnvironmentVariable(VariableBuffer,NULL); - if(SetResult == 0) - { - Fail("ERROR: SetEnvironmentVariable returned failure, when " - "attempting to delete a variable.\n"); - } - - SetResult = SetEnvironmentVariable(VariableBuffer,NULL); - if(SetResult != 0) - { - Fail("ERROR: SetEnvironmentVariable returned success, when " - "attempting to delete a variable which doesn't exist.\n"); - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/test.cpp new file mode 100644 index 0000000000..12f4887b6d --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test2/test.cpp @@ -0,0 +1,88 @@ +// 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 SetEnvironmentVariableW() function +** Test to see that passing NULL to the first param fails. +** Test that passing NULL to both params fails. +** Set an environment variable, then pass NULL to the second param +** to delete it. Then make the same call again, to check that it fails. +** +** +**=========================================================*/ + +#define UNICODE + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + /* Define some buffers needed for the function */ + WCHAR VariableBuffer[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR ValueBuffer[] = {'T','e','s','t','i','n','g','\0'}; + int SetResult; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + SetResult = SetEnvironmentVariable(NULL,ValueBuffer); + + /* Check that it fails if the first param is NULL */ + if(SetResult != 0) + { + Fail("ERROR: SetEnvironmentVariable returned a success value, " + "even though it was passed NULL as the first parameter and " + "should have failed.\n"); + } + + /* Check that it fails when both params are NULL */ + SetResult = SetEnvironmentVariable(NULL,NULL); + if(SetResult != 0) + { + Fail("ERROR: SetEnvironmentVariable returned a success value, even " + "though it was passed NULL as the first and second parameter and " + "should have failed.\n"); + } + + /* First, set the variable, which should be ok. Then call the + function with the second parameter NULL twice -- the first call should + pass, the second should fail. + */ + SetResult = SetEnvironmentVariable(VariableBuffer,ValueBuffer); + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned failure, when " + "attempting to set a valid variable.\n"); + } + + SetResult = SetEnvironmentVariable(VariableBuffer,NULL); + if(SetResult == 0) + { + Fail("ERROR: SetEnvironmentVariable returned failure, when " + "attempting to delete a variable.\n"); + } + + SetResult = SetEnvironmentVariable(VariableBuffer,NULL); + if(SetResult != 0) + { + Fail("ERROR: SetEnvironmentVariable returned success, when " + "attempting to delete a variable which doesn't exist.\n"); + } + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/CMakeLists.txt index e9072c7143..266231e6e9 100644 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_setenvironmentvariablew_test3 diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/test3.c b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/test3.c deleted file mode 100644 index 02d0a2d6d9..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/test3.c +++ /dev/null @@ -1,143 +0,0 @@ -// 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 : test3.c -** -** Purpose: Test for SetEnvironmentVariableW() function -** Create environment variables that differ only -** in case and verify that they return the appropriate -** value on the BSD environment. -** -** -===========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - - return PASS; - -#else - - /* Define some buffers needed for the function */ - WCHAR * pResultBuffer = NULL; - - WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; - WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; - - WCHAR SecondEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; - WCHAR SecondEnvironmentValue[] = {'S','E','C','O','N','D','\0'}; - - DWORD size = 0; - BOOL bRc = TRUE; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Set the first environment variable */ - bRc = SetEnvironmentVariableW(FirstEnvironmentVariable, - FirstEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - /* Set the second environment Variable */ - bRc = SetEnvironmentVariableW(SecondEnvironmentVariable, - SecondEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - - /* Normal case, PATH should fit into this buffer */ - size = GetEnvironmentVariableW(FirstEnvironmentVariable, - pResultBuffer, - 0); - - /* Increase size to account for the null char at the end */ - size = size + 1; - - pResultBuffer = malloc(sizeof(WCHAR)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try to retrieve the value of the first environment variable */ - GetEnvironmentVariableW(FirstEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the strings to see that the correct variable was returned */ - if(wcscmp(pResultBuffer,FirstEnvironmentValue) != 0) - { - Trace("ERROR: The value in the buffer should have been '%S' but " - "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); - free(pResultBuffer); - Fail(""); - } - - free(pResultBuffer); - - /* Reallocate the memory for the string */ - pResultBuffer = malloc(sizeof(WCHAR)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try retrieving the value of the first variable, even though the - second variable has the same spelling and only differs in case */ - GetEnvironmentVariableW(SecondEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the two strings to confirm that the right value is returned */ - if(wcscmp(pResultBuffer,SecondEnvironmentValue) != 0) - { - Trace("ERROR: The value in the buffer should have been '%S' but " - "was really '%S'.\n",SecondEnvironmentValue,pResultBuffer); - free(pResultBuffer); - Fail(""); - } - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; - -#endif -} diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/test3.cpp b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/test3.cpp new file mode 100644 index 0000000000..5c4d4eba42 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/test3.cpp @@ -0,0 +1,143 @@ +// 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 : test3.c +** +** Purpose: Test for SetEnvironmentVariableW() function +** Create environment variables that differ only +** in case and verify that they return the appropriate +** value on the BSD environment. +** +** +===========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + + return PASS; + +#else + + /* Define some buffers needed for the function */ + WCHAR * pResultBuffer = NULL; + + WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; + + WCHAR SecondEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; + WCHAR SecondEnvironmentValue[] = {'S','E','C','O','N','D','\0'}; + + DWORD size = 0; + BOOL bRc = TRUE; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set the first environment variable */ + bRc = SetEnvironmentVariableW(FirstEnvironmentVariable, + FirstEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Set the second environment Variable */ + bRc = SetEnvironmentVariableW(SecondEnvironmentVariable, + SecondEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariableW(FirstEnvironmentVariable, + pResultBuffer, + 0); + + /* Increase size to account for the null char at the end */ + size = size + 1; + + pResultBuffer = (WCHAR*)malloc(sizeof(WCHAR)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariableW(FirstEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the strings to see that the correct variable was returned */ + if(wcscmp(pResultBuffer,FirstEnvironmentValue) != 0) + { + Trace("ERROR: The value in the buffer should have been '%S' but " + "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); + free(pResultBuffer); + Fail(""); + } + + free(pResultBuffer); + + /* Reallocate the memory for the string */ + pResultBuffer = (WCHAR*)malloc(sizeof(WCHAR)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try retrieving the value of the first variable, even though the + second variable has the same spelling and only differs in case */ + GetEnvironmentVariableW(SecondEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the two strings to confirm that the right value is returned */ + if(wcscmp(pResultBuffer,SecondEnvironmentValue) != 0) + { + Trace("ERROR: The value in the buffer should have been '%S' but " + "was really '%S'.\n",SecondEnvironmentValue,pResultBuffer); + free(pResultBuffer); + Fail(""); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + +#endif +} diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/CMakeLists.txt index f5f48bab33..c82e0f0394 100644 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_setenvironmentvariablew_test4 diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/test4.c b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/test4.c deleted file mode 100644 index b8f7734de4..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/test4.c +++ /dev/null @@ -1,99 +0,0 @@ -// 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 : test4.c -** -** Purpose: Test for SetEnvironmentVariableW() function -** Create environment variables that differ only -** in case and verify that they return the appropriate -** value on the BSD environment. -** -** -===========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - -#if WIN32 - - /* Define some buffers needed for the function */ - WCHAR * pResultBuffer = NULL; - - WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; - WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; - - WCHAR ModifiedEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; - - DWORD size = 0; - BOOL bRc = TRUE; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Set the first environment variable */ - bRc = SetEnvironmentVariableW(FirstEnvironmentVariable, - FirstEnvironmentValue); - - if(!bRc) - { - Fail("ERROR: SetEnvironmentVariable failed to set a " - "proper environment variable with error %u.\n", - GetLastError()); - } - - /* Normal case, PATH should fit into this buffer */ - size = GetEnvironmentVariableW(ModifiedEnvironmentVariable, - pResultBuffer, - 0); - - /* To account for the nul character at the end of the string */ - size = size + 1; - - pResultBuffer = malloc(sizeof(WCHAR)*size); - if ( pResultBuffer == NULL ) - { - Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); - } - - /* Try to retrieve the value of the first environment variable */ - GetEnvironmentVariableW(ModifiedEnvironmentVariable, - pResultBuffer, - size); - - if ( pResultBuffer == NULL ) - { - Fail("ERROR: GetEnvironmentVariable failed to return a value " - "from a proper environment variable with error %u.\n", - GetLastError()); - } - - /* Compare the strings to see that the correct variable was returned */ - if(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) - { - Trace("ERROR: The value in the buffer should have been '%S' but " - "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); - free(pResultBuffer); - Fail(""); - } - - free(pResultBuffer); - - PAL_Terminate(); - return PASS; - - -#else - - return PASS; -#endif -} diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/test4.cpp b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/test4.cpp new file mode 100644 index 0000000000..50c59d6e97 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/test4.cpp @@ -0,0 +1,99 @@ +// 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 : test4.c +** +** Purpose: Test for SetEnvironmentVariableW() function +** Create environment variables that differ only +** in case and verify that they return the appropriate +** value on the BSD environment. +** +** +===========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + +#if WIN32 + + /* Define some buffers needed for the function */ + WCHAR * pResultBuffer = NULL; + + WCHAR FirstEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; + WCHAR FirstEnvironmentValue[] = {'F','I','R','S','T','\0'}; + + WCHAR ModifiedEnvironmentVariable[] = {'p','a','l','t','e','s','t','\0'}; + + DWORD size = 0; + BOOL bRc = TRUE; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set the first environment variable */ + bRc = SetEnvironmentVariableW(FirstEnvironmentVariable, + FirstEnvironmentValue); + + if(!bRc) + { + Fail("ERROR: SetEnvironmentVariable failed to set a " + "proper environment variable with error %u.\n", + GetLastError()); + } + + /* Normal case, PATH should fit into this buffer */ + size = GetEnvironmentVariableW(ModifiedEnvironmentVariable, + pResultBuffer, + 0); + + /* To account for the nul character at the end of the string */ + size = size + 1; + + pResultBuffer = (WCHAR*)malloc(sizeof(WCHAR)*size); + if ( pResultBuffer == NULL ) + { + Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n"); + } + + /* Try to retrieve the value of the first environment variable */ + GetEnvironmentVariableW(ModifiedEnvironmentVariable, + pResultBuffer, + size); + + if ( pResultBuffer == NULL ) + { + Fail("ERROR: GetEnvironmentVariable failed to return a value " + "from a proper environment variable with error %u.\n", + GetLastError()); + } + + /* Compare the strings to see that the correct variable was returned */ + if(wcsncmp(pResultBuffer,FirstEnvironmentValue,wcslen(pResultBuffer)) != 0) + { + Trace("ERROR: The value in the buffer should have been '%S' but " + "was really '%S'.\n",FirstEnvironmentValue, pResultBuffer); + free(pResultBuffer); + Fail(""); + } + + free(pResultBuffer); + + PAL_Terminate(); + return PASS; + + +#else + + return PASS; +#endif +} diff --git a/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/CMakeLists.txt index 5248d6ce97..40eb2ff865 100644 --- a/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_setlasterror_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/test.c b/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/test.c deleted file mode 100644 index d414626dd2..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/test.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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 SetLastError() function -** -** -**=========================================================*/ -/* Depends on GetLastError() */ - - -#include - -int __cdecl main(int argc, char *argv[]) { - - /* Error value that we can set to test */ - const unsigned int FAKE_ERROR = 5; - const int NEGATIVE_ERROR = -1; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Set error */ - SetLastError(FAKE_ERROR); - - /* Check to make sure it returns the error value we just set */ - if(GetLastError() != FAKE_ERROR) - { - Fail("ERROR: The last error should have been '%d' but the error " - "returned was '%d'\n",FAKE_ERROR,GetLastError()); - } - - /* Set the error to a negative */ - SetLastError(NEGATIVE_ERROR); - - /* Check to make sure it returns the error value we just set */ - if((signed)GetLastError() != NEGATIVE_ERROR) - { - Fail("ERROR: The last error should have been '%d' but the error " - "returned was '%d'\n",NEGATIVE_ERROR,GetLastError()); - } - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/test.cpp new file mode 100644 index 0000000000..d414626dd2 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/SetLastError/test1/test.cpp @@ -0,0 +1,59 @@ +// 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 SetLastError() function +** +** +**=========================================================*/ +/* Depends on GetLastError() */ + + +#include + +int __cdecl main(int argc, char *argv[]) { + + /* Error value that we can set to test */ + const unsigned int FAKE_ERROR = 5; + const int NEGATIVE_ERROR = -1; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Set error */ + SetLastError(FAKE_ERROR); + + /* Check to make sure it returns the error value we just set */ + if(GetLastError() != FAKE_ERROR) + { + Fail("ERROR: The last error should have been '%d' but the error " + "returned was '%d'\n",FAKE_ERROR,GetLastError()); + } + + /* Set the error to a negative */ + SetLastError(NEGATIVE_ERROR); + + /* Check to make sure it returns the error value we just set */ + if((signed)GetLastError() != NEGATIVE_ERROR) + { + Fail("ERROR: The last error should have been '%d' but the error " + "returned was '%d'\n",NEGATIVE_ERROR,GetLastError()); + } + + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/_i64tow/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/_i64tow/test1/CMakeLists.txt index 6876d1b24e..c3c4b61999 100644 --- a/src/pal/tests/palsuite/miscellaneous/_i64tow/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/_i64tow/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_i64tow_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/_i64tow/test1/test1.c b/src/pal/tests/palsuite/miscellaneous/_i64tow/test1/test1.c deleted file mode 100644 index 9a87328b0d..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/_i64tow/test1/test1.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests _i64tow with normal values and different radices, negative -** values, as well as the highest and lowest values. -** -** -**============================================================*/ - -#include - -typedef struct -{ - INT64 value; - int radix; - char *result; -} testCase; - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR buffer[256]; - WCHAR *testStr; - WCHAR *ret; - int i; - testCase testCases[] = - { - {42, 10, "42"}, - {42, 2, "101010"}, - {29, 32, "t"}, - {-1, 10, "-1"}, - {-1, 8, "1777777777777777777777"}, - {-1, 32, "fvvvvvvvvvvvv"}, - {I64(0x7FFFFFFFFFFFFFFF), 10, "9223372036854775807"}, - {I64(0x8000000000000000), 10, "-9223372036854775808"}, - {0,2,"0"}, - {0,16,"0"}, - {3,16,"3"}, - {15,16,"f"}, - {16,16,"10"}, - - }; - - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - for (i=0; i + +typedef struct +{ + INT64 value; + int radix; + char *result; +} testCase; + + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR buffer[256]; + WCHAR *testStr; + WCHAR *ret; + int i; + testCase testCases[] = + { + {42, 10, "42"}, + {42, 2, "101010"}, + {29, 32, "t"}, + {-1, 10, "-1"}, + {-1, 8, "1777777777777777777777"}, + {-1, 32, "fvvvvvvvvvvvv"}, + {I64(0x7FFFFFFFFFFFFFFF), 10, "9223372036854775807"}, + {I64(0x8000000000000000), 10, "-9223372036854775808"}, + {0,2,"0"}, + {0,16,"0"}, + {3,16,"3"}, + {15,16,"f"}, + {16,16,"10"}, + + }; + + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + for (i=0; i - -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; -} diff --git a/src/pal/tests/palsuite/miscellaneous/_ui64tow/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/_ui64tow/test1/testinfo.dat deleted file mode 100644 index a60f27a14a..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/_ui64tow/test1/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = _ui64tow -Name = Positive test _ui64tow to convert an integer to a wide character string -TYPE = DEFAULT -EXE1 = _ui64tow -Description -=Test the _ui64tow API to convert an integer to a wide character string diff --git a/src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/CMakeLists.txt deleted file mode 100644 index b4feb4b8fd..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - _ui64tow.c -) - -add_executable(paltest_ui64tow_test2 - ${SOURCES} -) - -add_dependencies(paltest_ui64tow_test2 coreclrpal) - -target_link_libraries(paltest_ui64tow_test2 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/_ui64tow.c b/src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/_ui64tow.c deleted file mode 100644 index f13250578c..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/_ui64tow.c +++ /dev/null @@ -1,88 +0,0 @@ -// 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: _ui64tow.c -** -** Purpose: Tests _ui64tow with normal values and different -** radices,highest and lowest values. -** -** -**============================================================*/ - -#include - -typedef struct -{ - unsigned __int64 value; - int radix; - char* result; -} testCase; - - -int __cdecl main(int argc, char *argv[]) -{ - WCHAR buffer[256]; - WCHAR *testStr; - WCHAR *ret; - int i; - testCase testCases[] = - { - /* test limits */ - {UI64(0xFFFFFFFFFFFFFFFF), 2, - "1111111111111111111111111111111111111111111111111111111111111111"}, - {UI64(0xFFFFFFFFFFFFFFFF), 8, "1777777777777777777777"}, - {UI64(0xFFFFFFFFFFFFFFFF), 10, "18446744073709551615"}, - {UI64(0xFFFFFFFFFFFFFFFF), 16, "ffffffffffffffff"}, - {47, 2, "101111"}, - {47, 8, "57"}, - {47, 10, "47"}, - {47, 16, "2f"}, - {12, 2, "1100"}, - {12, 8, "14"}, - {12, 10, "12"}, - {12, 16, "c"}, - - /* test with 0. */ - {0, 2, "0"}, - {0, 8, "0"}, - {0, 10, "0"}, - {0, 16, "0"} - }; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - for (i=0; i, got <%S>.\n", - i,testStr, buffer); - free(testStr); - Fail(""); - } - - free(testStr); - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/testinfo.dat deleted file mode 100644 index 0abbca2d11..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/_ui64tow/test2/testinfo.dat +++ /dev/null @@ -1,13 +0,0 @@ -# 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 = _ui64tow -Name = Positive test _ui64tow to convert an integer to a wide character string -TYPE = DEFAULT -EXE1 = _ui64tow -Description -=Test the _ui64tow API to convert an integer to a wide character string -=Test the limits. and 0. diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrcatW/CMakeLists.txt deleted file mode 100644 index a3847f8ca9..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) -add_subdirectory(test2) -add_subdirectory(test3) -add_subdirectory(test4) - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/CMakeLists.txt deleted file mode 100644 index aa5b0c2646..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_lstrcatw_test1 - ${SOURCES} -) - -add_dependencies(paltest_lstrcatw_test1 coreclrpal) - -target_link_libraries(paltest_lstrcatw_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/test.c deleted file mode 100644 index ad1095e014..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/test.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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 lstrcatW() function -** -** -**=========================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char *argv[]) { - - WCHAR FirstString[10] = {'T','E','S','T','\0'}; - const WCHAR SecondString[] = {'P','A','L','!','\0'}; - WCHAR CorrectString[] = {'T','E','S','T','P','A','L','!','\0'}; - WCHAR* ReturnedPointer = NULL; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ReturnedPointer = lstrcat(FirstString,SecondString); - - /* Check to see if the pointer returned points to the concat string */ - if(ReturnedPointer != &FirstString[0]) - { - Fail("ERROR: The function was supposed to return a pointer to " - "the concatentated string, but it did not.\n"); - } - - /* Check to make sure the Concat string is the same as the predetermined - 'CorrectString' */ - if(memcmp(FirstString,CorrectString, - wcslen(FirstString)*sizeof(WCHAR)) != 0) - { - Fail("ERROR: The concatenated string should be %s but %s was the " - "result.\n", - convertC(CorrectString), - convertC(FirstString)); - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/testinfo.dat deleted file mode 100644 index 006e83b882..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test1/testinfo.dat +++ /dev/null @@ -1,16 +0,0 @@ -# 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 = lstrcatW -Name = Positive test of lstrcatW -TYPE = DEFAULT -EXE1 = test -Description -= Test to see that concatenating two strings works, -= and also check return values in successful and failing situations. - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/CMakeLists.txt deleted file mode 100644 index 8a11c8f154..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test2.c -) - -add_executable(paltest_lstrcatw_test2 - ${SOURCES} -) - -add_dependencies(paltest_lstrcatw_test2 coreclrpal) - -target_link_libraries(paltest_lstrcatw_test2 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/test2.c b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/test2.c deleted file mode 100644 index 6c66bc8976..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/test2.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: test2.c -** -** Purpose: Negative test for lstrcatW() function -** -** -**=========================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char *argv[]) { - - WCHAR FirstString[10] = {'T','E','S','T','\0'}; - const WCHAR SecondString[] = {'P','A','L','!','\0'}; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* If either of these is NULL, function should fail and return NULL. */ - if(lstrcat(NULL,SecondString) != NULL) - { - Fail("ERROR: When NULL was passed to the first parameter of the " - "function, it should have returned " - "NULL as a result, but did not.\n"); - } - - if(lstrcat(FirstString,NULL) != NULL) - { - Fail("ERROR: When NULL was passed to the second parameter of the " - "function, it should have returned " - "NULL as a result, but did not.\n"); - } - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/testinfo.dat deleted file mode 100644 index cc1ee644dc..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test2/testinfo.dat +++ /dev/null @@ -1,12 +0,0 @@ -# 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 = lstrcatW -Name = Negtive test of lstrcatW -TYPE = DEFAULT -EXE1 = test2 -Description -= Test to see lstrcat reports error with failing situations. diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/CMakeLists.txt deleted file mode 100644 index 1cdecedf1a..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test3.c -) - -add_executable(paltest_lstrcatw_test3 - ${SOURCES} -) - -add_dependencies(paltest_lstrcatw_test3 coreclrpal) - -target_link_libraries(paltest_lstrcatw_test3 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/test3.c b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/test3.c deleted file mode 100644 index 49a9c57555..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/test3.c +++ /dev/null @@ -1,46 +0,0 @@ -// 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: test3.c -** -** Purpose: Testing lstrcatw with two NULL strings passed on -** -** -**=========================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - - /* testing the behaviour of lstrcatW with two NULL strings */ - if( lstrcat(NULL,NULL) != NULL) - { - - Fail("lstrcat:ERROR: the function should returned NULL\n"); - - } - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/testinfo.dat deleted file mode 100644 index 794bcdbff7..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test3/testinfo.dat +++ /dev/null @@ -1,26 +0,0 @@ -# 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 = lstrcatW - -Name = Negative testing for lstrcatW - -TYPE = DEFAULT - -EXE1 = test3 - -Description - -= Testing the behaviour after sending two strings contained NULL - - - - - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/CMakeLists.txt deleted file mode 100644 index 640c224f83..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test4.c -) - -add_executable(paltest_lstrcatw_test4 - ${SOURCES} -) - -add_dependencies(paltest_lstrcatw_test4 coreclrpal) - -target_link_libraries(paltest_lstrcatw_test4 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/test4.c b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/test4.c deleted file mode 100644 index abc9021518..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/test4.c +++ /dev/null @@ -1,101 +0,0 @@ -// 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: test4.c -** -** Purpose: Testing the behaviour of lstrcatw when string2 contains -** special characters, this test case depends on: -** memcmp -** wcslen -** lstrcpyn -** -** -**=========================================================*/ - -#define UNICODE - -#include - -struct testCase -{ - WCHAR SecondString[5]; - WCHAR CorrectString[10]; -}; - -int __cdecl main(int argc, char *argv[]) -{ - - WCHAR FirstString[10] = {'T','E','S','T','\0'}; - WCHAR TestString[10] = {'T','E','S','T','\0'}; - int i = 0; - - /* - * this structure includes several strings to be tested with - * lstrcatW function and the expected results - */ - - struct testCase testCases[]= - { - {{'\t','T','A','B','\0'}, - {'T','E','S','T','\t','T','A','B','\0'}}, - {{'2','T','\?','B','\0'}, - {'T','E','S','T','2','T','\?','B','\0'}}, - {{'\v','T','E','\v','\0'}, - {'T','E','S','T','\v','T','E','\v','\0'}}, - {{'T','\a','E','\a','\0'}, - {'T','E','S','T','T','\a','E','\a','\0'}}, - {{'0','\f','Z','\f','\0'}, - {'T','E','S','T','0','\f','Z','\f','\0'}}, - {{'\r','H','I','\r','\0'}, - {'T','E','S','T','\r','H','I','\r','\0'}}, - {{'H','I','\"','\"','\0'}, - {'T','E','S','T','H','I','\"','\"','\0'}}, - {{'H','\b','I','\b','\0'}, - {'T','E','S','T','H','\b','I','\b','\0'}}, - {{'H','\n','I','\n','\0'}, - {'T','E','S','T','H','\n','I','\n','\0'}} - }; - - - - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - - /* Loop through the struct and validate the resulted string */ - for( i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) - { - - lstrcat(FirstString, testCases[i].SecondString); - - if(memcmp(FirstString,testCases[i].CorrectString, - wcslen(FirstString)*sizeof(WCHAR))) - { - - Fail("ERROR: the function failed with a special character.\n"); - } - - /* reinitialize the first string */ - lstrcpyn(FirstString,TestString,10); - - } - - - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/testinfo.dat deleted file mode 100644 index 96235fb257..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcatW/test4/testinfo.dat +++ /dev/null @@ -1,28 +0,0 @@ -# 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 = lstrcatW - -Name = Positive testing for lstrcatW - -TYPE = DEFAULT - -EXE1 = test4 - -Description - -= Testing the behaviour of lstrcatw when string2 contains - -= special characters and validate the resulted string - - - - - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcpyW/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrcpyW/CMakeLists.txt deleted file mode 100644 index f6aa0cb2d9..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcpyW/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/CMakeLists.txt deleted file mode 100644 index e39c9a6098..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_lstrcpyw_test1 - ${SOURCES} -) - -add_dependencies(paltest_lstrcpyw_test1 coreclrpal) - -target_link_libraries(paltest_lstrcpyw_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/test.c deleted file mode 100644 index 881ba033e8..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/test.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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 lstrcpyW() function -** -** -**=========================================================*/ - -#define UNICODE - -#include - -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; -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/testinfo.dat deleted file mode 100644 index 37c9835236..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcpyW/test1/testinfo.dat +++ /dev/null @@ -1,16 +0,0 @@ -# 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 = lstrcpyW -Name = Positive test of lstrcpyW -TYPE = DEFAULT -EXE1 = test -Description -= Ensure that a copy of a string works, and that the return values -= are correct for success and failure. - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcpynW/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrcpynW/CMakeLists.txt deleted file mode 100644 index f6aa0cb2d9..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcpynW/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/CMakeLists.txt deleted file mode 100644 index 4344b89402..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_lstrcpynw_test1 - ${SOURCES} -) - -add_dependencies(paltest_lstrcpynw_test1 coreclrpal) - -target_link_libraries(paltest_lstrcpynw_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/test.c deleted file mode 100644 index 1ae0c51474..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/test.c +++ /dev/null @@ -1,73 +0,0 @@ -// 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 lstrcpynW() function -** -** -**=========================================================*/ - -#define UNICODE - -#include - -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; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/testinfo.dat deleted file mode 100644 index 111a57928a..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrcpynW/test1/testinfo.dat +++ /dev/null @@ -1,16 +0,0 @@ -# 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 = lstrcpynW -Name = Positive test of lstrcpynW -TYPE = DEFAULT -EXE1 = test -Description -= Ensure that a copy of a string works, and that the return values -= are correct for success and failure. - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/CMakeLists.txt index 807a5d83b9..6bb520100d 100644 --- a/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_lstrlena_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/test.c b/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/test.c deleted file mode 100644 index 13e935ba50..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/test.c +++ /dev/null @@ -1,49 +0,0 @@ -// 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 lstrlenA() function -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) { - - char * FirstString = "Pal Testing"; /* 11 characters */ - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* The string size should be 11 */ - if(lstrlen(FirstString) != 11) - { - Fail("ERROR: The string size returned was %d but it should have " - "been 11 in this test.\n",lstrlen(FirstString)); - } - - /* A NULL pointer should return 0 length */ - if(lstrlen(NULL) != 0) - { - Fail("ERROR: Checking the length of NULL pointer should return " - "a value of 0, but %d was returned.\n",lstrlen(NULL)); - } - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/test.cpp new file mode 100644 index 0000000000..13e935ba50 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/lstrlenA/test1/test.cpp @@ -0,0 +1,49 @@ +// 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 lstrlenA() function +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) { + + char * FirstString = "Pal Testing"; /* 11 characters */ + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* The string size should be 11 */ + if(lstrlen(FirstString) != 11) + { + Fail("ERROR: The string size returned was %d but it should have " + "been 11 in this test.\n",lstrlen(FirstString)); + } + + /* A NULL pointer should return 0 length */ + if(lstrlen(NULL) != 0) + { + Fail("ERROR: Checking the length of NULL pointer should return " + "a value of 0, but %d was returned.\n",lstrlen(NULL)); + } + + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/CMakeLists.txt index fe6fc9691b..4209cbee89 100644 --- a/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_lstrlenw_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/test.c deleted file mode 100644 index 49bc6d8f67..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/test.c +++ /dev/null @@ -1,51 +0,0 @@ -// 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 lstrlenW() function -** -** -**=========================================================*/ - -#define UNICODE - -#include - -int __cdecl main(int argc, char *argv[]) { - - WCHAR FirstString[] = {'T','E','S','T','\0'}; /* 4 characters */ - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* The string size should be 4, as noted just above */ - if(lstrlen(FirstString) != 4) - { - Fail("ERROR: The return value was %d when it should have shown the " - "size to be 4 characters.\n",lstrlen(FirstString)); - } - - /* A NULL pointer should return 0 length */ - if(lstrlen(NULL) != 0) - { - Fail("ERROR: The return value was %d when it should have been 0, the " - "length of a NULL pointer.\n",lstrlen(NULL)); - } - - - PAL_Terminate(); - return PASS; -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/test.cpp new file mode 100644 index 0000000000..49bc6d8f67 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/lstrlenW/test1/test.cpp @@ -0,0 +1,51 @@ +// 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 lstrlenW() function +** +** +**=========================================================*/ + +#define UNICODE + +#include + +int __cdecl main(int argc, char *argv[]) { + + WCHAR FirstString[] = {'T','E','S','T','\0'}; /* 4 characters */ + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* The string size should be 4, as noted just above */ + if(lstrlen(FirstString) != 4) + { + Fail("ERROR: The return value was %d when it should have shown the " + "size to be 4 characters.\n",lstrlen(FirstString)); + } + + /* A NULL pointer should return 0 length */ + if(lstrlen(NULL) != 0) + { + Fail("ERROR: The return value was %d when it should have been 0, the " + "length of a NULL pointer.\n",lstrlen(NULL)); + } + + + PAL_Terminate(); + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/CMakeLists.txt index d76467aeab..ba53f42ccc 100644 --- a/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_queryperformancecounter_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/test1.c b/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/test1.c deleted file mode 100644 index 55b173add7..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/test1.c +++ /dev/null @@ -1,107 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for QueryPerformanceCounter function -** -** -**=========================================================*/ - -/* Depends on: QueryPerformanceFrequency. */ - -#include - -/* Milliseconds of error which are acceptable Function execution time, etc. - FreeBSD has a "standard" resolution of 50ms for waiting operations, so we - must take that into account as well */ -DWORD AcceptableTimeError = 15; - -int __cdecl main(int argc, char *argv[]) -{ - - int i; - int NumIterations = 100; - DWORD AvgTimeDiff; - DWORD TimeDiff[100]; - DWORD TotalTimeDiff = 0; - DWORD SleepInterval = 50; - LARGE_INTEGER StartTime; - LARGE_INTEGER EndTime; - LARGE_INTEGER Freq; - - /* Initialize the PAL. - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Get the frequency of the High-Performance Counter, - * in order to convert counter time to milliseconds. - */ - if (!QueryPerformanceFrequency(&Freq)) - { - Fail("ERROR:%u:Unable to retrieve the frequency of the " - "high-resolution performance counter.\n", - GetLastError()); - } - - /* Perform this set of sleep timings a number of times. - */ - for(i=0; i < NumIterations; i++) - { - - /* Get the current counter value. - */ - if (!QueryPerformanceCounter(&StartTime)) - { - Fail("ERROR:%u:Unable to retrieve the current value of the " - "high-resolution performance counter.\n", - GetLastError()); - } - - /* Sleep a predetermined interval. - */ - Sleep(SleepInterval); - - /* Get the new current counter value. - */ - if (!QueryPerformanceCounter(&EndTime)) - { - Fail("ERROR:%u:Unable to retrieve the current value of the " - "high-resolution performance counter.\n", - GetLastError()); - } - - /* Determine elapsed time, in milliseconds. Compare the elapsed time - * with the sleep interval, and add to counter. - */ - TimeDiff[i] = (DWORD)(((EndTime.QuadPart - StartTime.QuadPart)*1000)/ - (Freq.QuadPart)); - TotalTimeDiff += TimeDiff[i] - SleepInterval; - - } - - /* Verify that the average of the difference between the performance - * counter and the sleep interval is within our acceptable range. - */ - AvgTimeDiff = TotalTimeDiff / NumIterations; - if (AvgTimeDiff > AcceptableTimeError) - { - Fail("ERROR: average diff %u acceptable %u.\n", - AvgTimeDiff, - AcceptableTimeError); - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/test1.cpp b/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/test1.cpp new file mode 100644 index 0000000000..55b173add7 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/queryperformancecounter/test1/test1.cpp @@ -0,0 +1,107 @@ +// 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: test1.c +** +** Purpose: Test for QueryPerformanceCounter function +** +** +**=========================================================*/ + +/* Depends on: QueryPerformanceFrequency. */ + +#include + +/* Milliseconds of error which are acceptable Function execution time, etc. + FreeBSD has a "standard" resolution of 50ms for waiting operations, so we + must take that into account as well */ +DWORD AcceptableTimeError = 15; + +int __cdecl main(int argc, char *argv[]) +{ + + int i; + int NumIterations = 100; + DWORD AvgTimeDiff; + DWORD TimeDiff[100]; + DWORD TotalTimeDiff = 0; + DWORD SleepInterval = 50; + LARGE_INTEGER StartTime; + LARGE_INTEGER EndTime; + LARGE_INTEGER Freq; + + /* Initialize the PAL. + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Get the frequency of the High-Performance Counter, + * in order to convert counter time to milliseconds. + */ + if (!QueryPerformanceFrequency(&Freq)) + { + Fail("ERROR:%u:Unable to retrieve the frequency of the " + "high-resolution performance counter.\n", + GetLastError()); + } + + /* Perform this set of sleep timings a number of times. + */ + for(i=0; i < NumIterations; i++) + { + + /* Get the current counter value. + */ + if (!QueryPerformanceCounter(&StartTime)) + { + Fail("ERROR:%u:Unable to retrieve the current value of the " + "high-resolution performance counter.\n", + GetLastError()); + } + + /* Sleep a predetermined interval. + */ + Sleep(SleepInterval); + + /* Get the new current counter value. + */ + if (!QueryPerformanceCounter(&EndTime)) + { + Fail("ERROR:%u:Unable to retrieve the current value of the " + "high-resolution performance counter.\n", + GetLastError()); + } + + /* Determine elapsed time, in milliseconds. Compare the elapsed time + * with the sleep interval, and add to counter. + */ + TimeDiff[i] = (DWORD)(((EndTime.QuadPart - StartTime.QuadPart)*1000)/ + (Freq.QuadPart)); + TotalTimeDiff += TimeDiff[i] - SleepInterval; + + } + + /* Verify that the average of the difference between the performance + * counter and the sleep interval is within our acceptable range. + */ + AvgTimeDiff = TotalTimeDiff / NumIterations; + if (AvgTimeDiff > AcceptableTimeError) + { + Fail("ERROR: average diff %u acceptable %u.\n", + AvgTimeDiff, + AcceptableTimeError); + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/CMakeLists.txt index 352e51342d..bc6bd22d5d 100644 --- a/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_queryperformancefrequency_test1 diff --git a/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/test1.c b/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/test1.c deleted file mode 100644 index de08063a74..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/test1.c +++ /dev/null @@ -1,59 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for QueryPerformanceFrequency function -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) -{ - - LARGE_INTEGER Freq; - - /* Initialize the PAL. - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Check the return value of the performance - * frequency, a value of zero indicates that - * either the call has failed or the - * high-resolution performance counter is not - * installed. - */ - if (!QueryPerformanceFrequency(&Freq)) - { - - Fail("ERROR:%u:Unable to retrieve the frequency of the " - "high-resolution performance counter.\n", - GetLastError()); - } - - - /* Check the return value the frequency the - * value should be non-zero. - */ - if (Freq.QuadPart == 0) - { - - Fail("ERROR: The frequency has been determined to be 0 " - "the frequency should be non-zero.\n"); - - } - - /* Terminate the PAL. - */ - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/test1.cpp b/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/test1.cpp new file mode 100644 index 0000000000..de08063a74 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/queryperformancefrequency/test1/test1.cpp @@ -0,0 +1,59 @@ +// 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: test1.c +** +** Purpose: Test for QueryPerformanceFrequency function +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) +{ + + LARGE_INTEGER Freq; + + /* Initialize the PAL. + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Check the return value of the performance + * frequency, a value of zero indicates that + * either the call has failed or the + * high-resolution performance counter is not + * installed. + */ + if (!QueryPerformanceFrequency(&Freq)) + { + + Fail("ERROR:%u:Unable to retrieve the frequency of the " + "high-resolution performance counter.\n", + GetLastError()); + } + + + /* Check the return value the frequency the + * value should be non-zero. + */ + if (Freq.QuadPart == 0) + { + + Fail("ERROR: The frequency has been determined to be 0 " + "the frequency should be non-zero.\n"); + + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/CMakeLists.txt deleted file mode 100644 index f40d4151d6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) -add_subdirectory(test11) -add_subdirectory(test12) -add_subdirectory(test13) -add_subdirectory(test2) -add_subdirectory(test3) -add_subdirectory(test6) -add_subdirectory(test7) -add_subdirectory(test8) -add_subdirectory(test9) - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/CMakeLists.txt deleted file mode 100644 index ef589329f0..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test1 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test1 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/test.c deleted file mode 100644 index 722270965d..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/test.c +++ /dev/null @@ -1,58 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - - char * ErrorMessage; - char buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -int test1() -{ - char checkstr[] = "hello world"; - - wsprintf(buf, "hello world"); - - /* Error message */ - ErrorMessage = "ERROR: (Test 1) Failed on 'hello world' test. The " - "correct string is 'hello world' and the result returned was "; - - return (memcmp(checkstr, buf, strlen(checkstr)+1) != 0); -} - -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,buf); - } - - PAL_Terminate(); - return PASS; - -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/testinfo.dat deleted file mode 100644 index c06f4c01aa..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test1/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the very basic functionality of wsprintf. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/CMakeLists.txt deleted file mode 100644 index 92c44b9341..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test11 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test11 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test11 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/test.c deleted file mode 100644 index b43299a045..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/test.c +++ /dev/null @@ -1,128 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -char * ErrorMessage; -char buf[256]; - -BOOL test1() -{ - int pos = 42; - - - /* Test 1 */ - wsprintf(buf, "foo %u", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 2 */ - wsprintf(buf, "foo %lu", 0xFFFF); - if (memcmp(buf, "foo 65535", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is " - "'foo 65535' and the result returned was "; - return FAIL; - } - - /* Test 3 */ - wsprintf(buf, "foo %hu", 0xFFFF); - if (memcmp(buf, "foo 65535", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is " - "'foo 65535' and the result returned was "; - return FAIL; - } - - /* Test 4 */ - wsprintf(buf, "foo %3u", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 5 */ - wsprintf(buf, "foo %-3u", pos); - if (memcmp(buf, "foo 42 ", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 6 */ - wsprintf(buf, "foo %.1u", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 7 */ - wsprintf(buf, "foo %.3u", pos); - if (memcmp(buf, "foo 042", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is " - "'foo 042' and the result returned was "; - return FAIL; - } - - /* Test 8 */ - wsprintf(buf, "foo %03u", pos); - if (memcmp(buf, "foo 042", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is " - "'foo 042' and the result returned was "; - return FAIL; - } - - /* Test 9 */ - wsprintf(buf, "foo %#u", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 9) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - return PASS; -} - - -int __cdecl main(int argc, char *argv[]) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if(test1()) - { - Fail("%s'%s'\n",ErrorMessage,buf); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/testinfo.dat deleted file mode 100644 index c5f1ec1975..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test11/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the %u formatter. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/CMakeLists.txt deleted file mode 100644 index e4013ad9e3..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test12 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test12 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test12 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/test.c deleted file mode 100644 index dcc61019d4..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/test.c +++ /dev/null @@ -1,119 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -char * ErrorMessage; -char buf[256]; - -BOOL test1() -{ - int pos = 0x1234ab; - - /* Test 1 */ - wsprintf(buf, "foo %x", pos); - if (memcmp(buf, "foo 1234ab", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct " - "string is 'foo 1234ab' and the result returned was "; - return FAIL; - } - - /* Test 2 */ - wsprintf(buf, "foo %lx", pos); - if (memcmp(buf, "foo 1234ab", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct " - "string is 'foo 1234ab' and the result returned was "; - return FAIL; - } - - - /* Test 3 */ - wsprintf(buf, "foo %7x", pos); - if (memcmp(buf, "foo 1234ab", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is " - "'foo 1234ab' and the result returned was "; - return FAIL; - } - - /* Test 4 */ - wsprintf(buf, "foo %-7x", pos); - if (memcmp(buf, "foo 1234ab ", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is " - "'foo 1234ab' and the result returned was "; - return FAIL; - } - - /* Test 5 */ - wsprintf(buf, "foo %.1x", pos); - if (memcmp(buf, "foo 1234ab", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is " - "'foo 1234ab' and the result returned was "; - return FAIL; - } - - /* Test 6 */ - wsprintf(buf, "foo %.7x", pos); - if (memcmp(buf, "foo 01234ab", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is " - "'foo 01234ab' and the result returned was "; - return FAIL; - } - - /* Test 7 */ - wsprintf(buf, "foo %07x", pos); - if (memcmp(buf, "foo 01234ab", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is " - "'foo 01234ab' and the result returned was "; - return FAIL; - } - - /* Test 8 */ - wsprintf(buf, "foo %#x", pos); - if (memcmp(buf, "foo 0x1234ab", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is " - "'foo 0x1234ab' and the result returned was "; - return FAIL; - } - - return PASS; -} - -int __cdecl main(int argc, char *argv[]) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if(test1()) - { - Fail("%s '%s'\n",ErrorMessage,buf); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/testinfo.dat deleted file mode 100644 index 71c8386f27..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test12/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the %x formatter. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/CMakeLists.txt deleted file mode 100644 index 423b05d8d9..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test13 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test13 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test13 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/test.c deleted file mode 100644 index e1f7d80a0f..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/test.c +++ /dev/null @@ -1,120 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -char * ErrorMessage; -char buf[256]; - -BOOL test1() -{ - int pos = 0x1234ab; - - /* Test 1 */ - wsprintf(buf, "foo %X", pos); - if (memcmp(buf, "foo 1234AB", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is " - " 'foo 1234AB' and the result returned was "; - return FAIL; - } - - /* Test 2 */ - wsprintf(buf, "foo %lX", pos); - if (memcmp(buf, "foo 1234AB", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is " - "'foo 1234AB' and the result returned was "; - return FAIL; - } - - - /* Test 3 */ - wsprintf(buf, "foo %7X", pos); - if (memcmp(buf, "foo 1234AB", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is " - "'foo 1234AB' and the result returned was "; - return FAIL; - } - - /* Test 4 */ - wsprintf(buf, "foo %-7X", pos); - if (memcmp(buf, "foo 1234AB ", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is " - "'foo 1234AB' and the result returned was "; - return FAIL; - } - - /* Test 5 */ - wsprintf(buf, "foo %.1X", pos); - if (memcmp(buf, "foo 1234AB", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is " - "'foo 1234AB' and the result returned was "; - return FAIL; - } - - /* Test 6 */ - wsprintf(buf, "foo %.7X", pos); - if (memcmp(buf, "foo 01234AB", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is " - "'foo 01234AB' and the result returned was "; - return FAIL; - } - - /* Test 7 */ - wsprintf(buf, "foo %07X", pos); - if (memcmp(buf, "foo 01234AB", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is " - "'foo 01234AB' and the result returned was "; - return FAIL; - } - - /* Test 8 */ - wsprintf(buf, "foo %#X", pos); - if (memcmp(buf, "foo 0X1234AB", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is " - "'foo 0X1234AB' and the result returned was "; - return FAIL; - } - - return PASS; -} - -int __cdecl main(int argc, char *argv[]) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if(test1()) - { - Fail("%s '%s'\n",ErrorMessage,buf); - } - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/testinfo.dat deleted file mode 100644 index 0e0d1b4633..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test13/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the %X formatter. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/CMakeLists.txt deleted file mode 100644 index 546a1daa38..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test2 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test2 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test2 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/test.c deleted file mode 100644 index b879e54043..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/test.c +++ /dev/null @@ -1,123 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -char * ErrorMessage; -char * BadResult; -char buf[256]; - -BOOL test1() -{ - - - /* Test 1 */ - wsprintf(buf, "foo %s", "bar"); - if (memcmp(buf, "foo bar", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is " - "'foo bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - /* Test 2 */ - wsprintf(buf, "foo %hs", "bar"); - if (memcmp(buf, "foo bar", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is " - "'foo bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - - /* Test 3 */ - wsprintf(buf, "foo %5s", "bar"); - if (memcmp(buf, "foo bar", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is " - "'foo bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - /* Test 4 */ - wsprintf(buf, "foo %.2s", "bar"); - if (memcmp(buf, "foo ba", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is " - "'foo ba' and the result returned was "; - BadResult = buf; - return FAIL; - } - - /* Test 5 */ - wsprintf(buf, "foo %5.2s", "bar"); - if (memcmp(buf, "foo ba", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is " - "'foo ba' and the result returned was "; - BadResult = buf; - return FAIL; - } - - /* Test 6 */ - wsprintf(buf, "foo %-5s", "bar"); - if (memcmp(buf, "foo bar ", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is " - "'foo bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - /* Test 7 */ - wsprintf(buf, "foo %05s", "bar"); - if (memcmp(buf, "foo 00bar", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is " - "'foo 00bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - 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,BadResult); - } - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/testinfo.dat deleted file mode 100644 index 32e51df28b..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test2/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the %s and %ls formatters with various flags. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/CMakeLists.txt deleted file mode 100644 index 8043ccd60b..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test3 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test3 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test3 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/test.c deleted file mode 100644 index bb598d9d63..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/test.c +++ /dev/null @@ -1,121 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -char * ErrorMessage; -char buf[256]; - -BOOL test1() -{ - - /* Test 1 */ - wsprintf(buf, "foo %S", convert("bar")); - if (memcmp(buf, "foo bar", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is " - "'foo bar' and the result returned was "; - return FAIL; - } - - /* Test 2 */ - wsprintf(buf, "foo %hS", "bar"); - if (memcmp(buf, "foo bar", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is " - "'foo bar' and the result returned was "; - return FAIL; - } - - /* Test 3 */ - wsprintf(buf, "foo %lS", convert("bar")); - if (memcmp(buf, "foo bar", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is '" - "foo bar' and the result returned was "; - return FAIL; - } - - - /* Test 4 */ - wsprintf(buf, "foo %5S", convert("bar")); - if (memcmp(buf, "foo bar", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is " - "'foo bar' and the result returned was "; - return FAIL; - } - - /* Test 5 */ - wsprintf(buf, "foo %.2S", convert("bar")); - if (memcmp(buf, "foo ba", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is " - "'foo ba' and the result returned was "; - return FAIL; - } - - /* Test 6 */ - wsprintf(buf, "foo %5.2S", convert("bar")); - if (memcmp(buf, "foo ba", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is " - "'foo ba' and the result returned was "; - return FAIL; - } - - /* Test 7 */ - wsprintf(buf, "foo %-5S", convert("bar")); - if (memcmp(buf, "foo bar ", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is " - "'foo bar ' and the result returned was "; - return FAIL; - } - - /* Test 8 */ - wsprintf(buf, "foo %05S", convert("bar")); - if (memcmp(buf, "foo 00bar", strlen(buf) + 1) != 0) { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is " - "'foo 00bar' and the result returned was "; - return FAIL; - } - 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,buf); - - } - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/testinfo.dat deleted file mode 100644 index 0660aa17a3..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test3/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the %S and wide characters in general. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/CMakeLists.txt deleted file mode 100644 index 6a5caf95c2..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test6 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test6 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test6 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/test.c deleted file mode 100644 index 08d97f467a..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/test.c +++ /dev/null @@ -1,114 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -char * ErrorMessage; -char buf[256]; - -BOOL test1() -{ - WCHAR wc = 'c'; - - /* Test 1 */ - wsprintf(buf, "foo %c", 'b'); - if (memcmp(buf, "foo b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is " - "'foo b' and the result returned was "; - return FAIL; - } - - /* Test 2 */ - wsprintf(buf, "foo %hc", 'b'); - if (memcmp(buf, "foo b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is " - "'foo b' and the result returned was "; - return FAIL; - } - - /* Test 3 */ - wsprintf(buf, "foo %lc", wc); - if (memcmp(buf, "foo c", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is " - "'foo c' and the result returned was "; - return FAIL; - } - - - /* Test 4 */ - wsprintf(buf, "foo %5c", 'b'); - if (memcmp(buf, "foo b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is " - "'foo bar' and the result returned was "; - return FAIL; - } - - /* Test 5 */ - wsprintf(buf, "foo %-5c", 'b'); - if (memcmp(buf, "foo b ", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is " - "'foo b ' and the result returned was "; - return FAIL; - } - - /* Test 6 */ - wsprintf(buf, "foo %05c", 'b'); - if (memcmp(buf, "foo 0000b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is " - "'foo 0000b' and the result returned was "; - return FAIL; - } - - /* Test 7 */ - wsprintf(buf, "foo %#c", 'b'); - if (memcmp(buf, "foo b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is " - "'foo b' and the result returned was "; - return FAIL; - } - 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,buf); - } - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/testinfo.dat deleted file mode 100644 index 31b0f667b6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test6/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the %c formatter. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/CMakeLists.txt deleted file mode 100644 index 0885f0f21e..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test7 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test7 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test7 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/test.c deleted file mode 100644 index 6d380efaa9..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/test.c +++ /dev/null @@ -1,112 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -char * ErrorMessage; -char buf[256]; - -BOOL test1() -{ - WCHAR wb = 'b'; - - /* Test 1 */ - wsprintf(buf, "foo %C", wb); - if (memcmp(buf, "foo b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is " - "'foo b' and the result returned was "; - return FAIL; - } - - /* Test 2 */ - wsprintf(buf, "foo %hC", wb); - if (memcmp(buf, "foo b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is " - "'foo b' and the result returned was "; - return FAIL; - } - - /* Test 3 */ - wsprintf(buf, "foo %lC", 'c'); - if (memcmp(buf, "foo c", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is " - "'foo c' and the result returned was "; - return FAIL; - } - - - /* Test 4 */ - wsprintf(buf, "foo %5C", wb); - if (memcmp(buf, "foo b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is " - "'foo b' and the result returned was "; - return FAIL; - } - - /* Test 5 */ - wsprintf(buf, "foo %-5C", wb); - if (memcmp(buf, "foo b ", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is " - "'foo b ' and the result returned was "; - return FAIL; - } - - /* Test 6 */ - wsprintf(buf, "foo %05C", wb); - if (memcmp(buf, "foo 0000b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is " - "'foo 0000b' and the result returned was "; - return FAIL; - } - - /* Test 7 */ - wsprintf(buf, "foo %#C", wb); - if (memcmp(buf, "foo b", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is " - "'foo b' and the result returned was "; - return FAIL; - } - return PASS; -} - -int __cdecl main(int argc, char *argv[]) -{ - - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if(test1()) - { - Fail("%s '%s'\n",ErrorMessage,buf); - - } - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/testinfo.dat deleted file mode 100644 index 31b0f667b6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test7/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the %c formatter. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/CMakeLists.txt deleted file mode 100644 index 3c4b5ed36e..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test8 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test8 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test8 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/test.c deleted file mode 100644 index 7367461544..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/test.c +++ /dev/null @@ -1,120 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -char * ErrorMessage; -char buf[256]; - -BOOL test1() -{ - int pos = 42; - - /* Test 1 */ - wsprintf(buf, "foo %d", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 2 */ - wsprintf(buf, "foo %ld", 0xFFFF); - if (memcmp(buf, "foo 65535", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is " - "'foo 65535' and the result returned was "; - return FAIL; - } - - /* Test 3 */ - wsprintf(buf, "foo %3d", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 4 */ - wsprintf(buf, "foo %-3d", pos); - if (memcmp(buf, "foo 42 ", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is " - "'foo 42 ' and the result returned was "; - return FAIL; - } - - /* Test 5 */ - wsprintf(buf, "foo %.1d", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 6 */ - wsprintf(buf, "foo %.3d", pos); - if (memcmp(buf, "foo 042", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is " - "'foo 042' and the result returned was "; - return FAIL; - } - - /* Test 7 */ - wsprintf(buf, "foo %03d", pos); - if (memcmp(buf, "foo 042", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is " - "'foo 042' and the result returned was "; - return FAIL; - } - - /* Test 8 */ - wsprintf(buf, "foo %#d", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - return PASS; -} - -int __cdecl main(int argc, char *argv[]) -{ - - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if(test1()) - { - Fail("%s '%s'\n",ErrorMessage,buf); - } - - PAL_Terminate(); - return PASS; - -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/testinfo.dat deleted file mode 100644 index 75f4fbf121..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test8/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the %d formatter. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/CMakeLists.txt deleted file mode 100644 index dcbb22ebb5..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfa_test9 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfa_test9 coreclrpal) - -target_link_libraries(paltest_wsprintfa_test9 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/test.c deleted file mode 100644 index 9f123bcc6d..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/test.c +++ /dev/null @@ -1,122 +0,0 @@ -// 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 wsprintfA() function -** -** -**=========================================================*/ - -#include - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -char * ErrorMessage; -char buf[256]; - -BOOL test1() -{ - - int pos = 42; - - - /* Test 1 */ - wsprintf(buf, "foo %i", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 2 */ - wsprintf(buf, "foo %li", 0xFFFF); - if (memcmp(buf, "foo 65535", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is " - "'foo 65535' and the result returned was "; - return FAIL; - } - - - /* Test 3 */ - wsprintf(buf, "foo %3i", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 4 */ - wsprintf(buf, "foo %-3i", pos); - if (memcmp(buf, "foo 42 ", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is " - "'foo 42 ' and the result returned was "; - return FAIL; - } - - /* Test 5 */ - wsprintf(buf, "foo %.1i", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - /* Test 6 */ - wsprintf(buf, "foo %.3i", pos); - if (memcmp(buf, "foo 042", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is " - "'foo 042' and the result returned was "; - return FAIL; - } - - /* Test 7 */ - wsprintf(buf, "foo %03i", pos); - if (memcmp(buf, "foo 042", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is " - "'foo 042' and the result returned was "; - return FAIL; - } - - /* Test 8 */ - wsprintf(buf, "foo %#i", pos); - if (memcmp(buf, "foo 42", strlen(buf) + 1) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is " - "'foo 42' and the result returned was "; - return FAIL; - } - - return PASS; -} - -int __cdecl main(int argc, char *argv[]) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if(test1()) - { - Fail("%s '%s'\n",ErrorMessage,buf); - } - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/testinfo.dat deleted file mode 100644 index 2a3689e4dd..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfA/test9/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfA -Name = Positive test of wsprintfA -TYPE = DEFAULT -EXE1 = test -Description -= Test the %i formatter. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/CMakeLists.txt deleted file mode 100644 index f40d4151d6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -add_subdirectory(test1) -add_subdirectory(test11) -add_subdirectory(test12) -add_subdirectory(test13) -add_subdirectory(test2) -add_subdirectory(test3) -add_subdirectory(test6) -add_subdirectory(test7) -add_subdirectory(test8) -add_subdirectory(test9) - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/CMakeLists.txt deleted file mode 100644 index b1c0fb3d0b..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test1 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test1 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test1 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/test.c deleted file mode 100644 index 700cb134bd..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/test.c +++ /dev/null @@ -1,64 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ - -#define UNICODE -#include - - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - - -BOOL test1() -{ - char checkstr[] = "hello world"; - - WCHAR buf[256]; - - /* Test a simple string */ - wsprintf(buf, convert("hello world")); - - /* Error message */ - ErrorMessage = "ERROR: (Test 1) Failed on 'hello world' test. " - "The correct string is 'hello world' and the result returned was "; - BadResult = buf; - - return (memcmp(convert(checkstr), buf, wcslen(buf)*2+2) != 0); -} - -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; - -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/testinfo.dat deleted file mode 100644 index f36aced027..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test1/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test the very basic functionality of wsprintfW. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/CMakeLists.txt deleted file mode 100644 index a5d73ed413..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test11 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test11 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test11 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/test.c deleted file mode 100644 index dc1e7a7758..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/test.c +++ /dev/null @@ -1,139 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ - -#define UNICODE -#include - - - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; -WCHAR buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - - -BOOL test1() -{ - - int pos = 42; - - wsprintf(buf, convert("foo %u"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %lu"), 0xFFFF); - if (memcmp(buf, convert("foo 65535"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is" - " 'foo 65535' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %hu"), 0xFFFF); - if (memcmp(buf, convert("foo 65535"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is" - " 'foo 65535' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %3u"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %-3u"), pos); - if (memcmp(buf, convert("foo 42 "), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is" - " 'foo 42 ' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.1u"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.3u"), pos); - if (memcmp(buf, convert("foo 042"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is" - " 'foo 042' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %03u"), pos); - if (memcmp(buf, convert("foo 042"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is" - " 'foo 042' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %#u"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 9) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - 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; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/testinfo.dat deleted file mode 100644 index bb85d63f1b..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test11/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test %u formatter with wsprintfW. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/CMakeLists.txt deleted file mode 100644 index 3811fb07c9..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test12 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test12 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test12 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/test.c deleted file mode 100644 index 6ba456b3bc..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/test.c +++ /dev/null @@ -1,128 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ - -#define UNICODE -#include - - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; -WCHAR buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -BOOL test1() -{ - int pos = 0x1234ab; - - wsprintf(buf, convert("foo %x"), pos); - if (memcmp(buf, convert("foo 1234ab"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is" - " 'foo 1234ab' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %lx"), pos); - if (memcmp(buf, convert("foo 1234ab"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is" - " 'foo 1234ab' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %7x"), pos); - if (memcmp(buf, convert("foo 1234ab"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is" - " 'foo 1234ab' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %-7x"), pos); - if (memcmp(buf, convert("foo 1234ab "), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is" - " 'foo 1234ab ' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.1x"), pos); - if (memcmp(buf, convert("foo 1234ab"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is" - " 'foo 1234ab' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.7x"), pos); - if (memcmp(buf, convert("foo 01234ab"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is" - " 'foo 01234ab' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %07x"), pos); - if (memcmp(buf, convert("foo 01234ab"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is" - " 'foo 01234ab' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %#x"), pos); - if (memcmp(buf, convert("foo 0x1234ab"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is" - " 'foo 0x1234ab' and the result returned was "; - BadResult = buf; - return FAIL; - } - - 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; - -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/testinfo.dat deleted file mode 100644 index 0d38a20bcc..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test12/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test %x formatter with wsprintfW. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/CMakeLists.txt deleted file mode 100644 index 617abb854c..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test13 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test13 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test13 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/test.c deleted file mode 100644 index dd0daae0a0..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/test.c +++ /dev/null @@ -1,126 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ - -#define UNICODE -#include - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; -WCHAR buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -BOOL test1() -{ - int pos = 0x1234ab; - - wsprintf(buf, convert("foo %X"), pos); - if (memcmp(buf, convert("foo 1234AB"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is" - " 'foo 1234AB' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %lX"), pos); - if (memcmp(buf, convert("foo 1234AB"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is" - " 'foo 1234AB' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %7X"), pos); - if (memcmp(buf, convert("foo 1234AB"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is" - " 'foo 1234AB' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %-7X"), pos); - if (memcmp(buf, convert("foo 1234AB "), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is" - " 'foo 1234AB ' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.1X"), pos); - if (memcmp(buf, convert("foo 1234AB"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is" - " 'foo 1234AB' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.7X"), pos); - if (memcmp(buf, convert("foo 01234AB"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is" - " 'foo 01234AB' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %07X"), pos); - if (memcmp(buf, convert("foo 01234AB"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is" - " 'foo 01234AB' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %#X"), pos); - if (memcmp(buf, convert("foo 0X1234AB"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is" - " 'foo 0X1234AB' and the result returned was "; - BadResult = buf; - return FAIL; - } - - 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; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/testinfo.dat deleted file mode 100644 index c16a43f7b7..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test13/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test %X formatter with wsprintfW. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/CMakeLists.txt deleted file mode 100644 index 00b26da2e6..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test2 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test2 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test2 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/test.c deleted file mode 100644 index f25ab6c2f4..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/test.c +++ /dev/null @@ -1,108 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ -#define UNICODE -#include - - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; -WCHAR buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - - -BOOL test1() -{ - - wsprintf(buf, convert("foo %s"), convert("bar")); - if (memcmp(buf, convert("foo bar"), wcslen(buf)*2+2) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is 'foo bar'" - " and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %ls"), convert("bar")); - if (memcmp(buf, convert("foo bar"), wcslen(buf)*2 + 2) != 0){ - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is 'foo bar'" - " and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %5s"), convert("bar")); - if (memcmp(buf, convert("foo bar"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is" - " 'foo bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - wsprintf(buf, convert("foo %.2s"), convert("bar")); - if (memcmp(buf, convert("foo ba"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is 'foo ba'" - " and the result returned was "; - BadResult = buf; - return FAIL; - } - wsprintf(buf, convert("foo %5.2s"), convert("bar")); - if (memcmp(buf, convert("foo ba"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is" - " 'foo ba' and the result returned was "; - BadResult = buf; - return FAIL; - } - wsprintf(buf, convert("foo %-5s"), convert("bar")); - if (memcmp(buf, convert("foo bar "), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is" - " 'foo bar ' and the result returned was "; - BadResult = buf; - return FAIL; - } - wsprintf(buf, convert("foo %05s"), convert("bar")); - if (memcmp(buf, convert("foo 00bar"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is" - " 'foo 00bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - 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; - -} diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/testinfo.dat deleted file mode 100644 index a2a7bb2d39..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test2/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test %s formatter with wsprintfW. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/CMakeLists.txt deleted file mode 100644 index 25c6185d12..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test3 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test3 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test3 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/test.c deleted file mode 100644 index a52d617e47..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/test.c +++ /dev/null @@ -1,127 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ -#define UNICODE -#include - - - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; -WCHAR buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - - -BOOL test1() -{ - - wsprintf(buf, convert("foo %S"), "bar"); - if (memcmp(buf, convert("foo bar"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is" - " 'foo bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %hS"), "bar"); - if (memcmp(buf, convert("foo bar"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is" - " 'foo bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %lS"), convert("bar")); - if (memcmp(buf, convert("foo bar"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is" - " 'foo bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %5S"), "bar"); - if (memcmp(buf, convert("foo bar"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is" - " 'foo bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.2S"), "bar"); - if (memcmp(buf, convert("foo ba"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is" - " 'foo ba' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %5.2S"), "bar"); - if (memcmp(buf, convert("foo ba"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is" - " 'foo ba' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %-5S"), "bar"); - if (memcmp(buf, convert("foo bar "), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is" - " 'foo bar ' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %05S"), "bar"); - if (memcmp(buf, convert("foo 00bar"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is" - " 'foo 00bar' and the result returned was "; - BadResult = buf; - return FAIL; - } - - 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; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/testinfo.dat deleted file mode 100644 index 46b7b7459d..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test3/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test %S formatter with wsprintfW. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/CMakeLists.txt deleted file mode 100644 index c63a4d5c82..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test6 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test6 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test6 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/test.c deleted file mode 100644 index 513f1f7941..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/test.c +++ /dev/null @@ -1,115 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ -#define UNICODE -#include - - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; -WCHAR buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - -BOOL test1() -{ - WCHAR wc = 'b'; - - wsprintf(buf, convert("foo %c"), wc); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is" - " 'foo b' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %hc"), wc); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is 'foo b'" - " and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %lc"), wc); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is 'foo b'" - " and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %5c"), wc); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is" - " 'foo b' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %-5c"), wc); - if (memcmp(buf, convert("foo b "), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is" - " 'foo b ' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %05c"), wc); - if (memcmp(buf, convert("foo 0000b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is" - " 'foo 0000b' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %#c"), wc); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is 'foo b'" - " and the result returned was "; - BadResult = buf; - return FAIL; - } - 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; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/testinfo.dat deleted file mode 100644 index 627b76f602..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test6/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test %c formatter with wsprintfW. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/CMakeLists.txt deleted file mode 100644 index 25e43107ff..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test7 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test7 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test7 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/test.c deleted file mode 100644 index 99e73b13ce..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/test.c +++ /dev/null @@ -1,117 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ -#define UNICODE -#include - - - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; -WCHAR buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - - -BOOL test1() -{ - WCHAR wb = 'b'; - - wsprintf(buf, convert("foo %C"), 'b'); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is" - " 'foo b' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %hC"), 'b'); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is" - " 'foo b' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %lC"), wb); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is" - " 'foo b' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %5C"), 'b'); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is" - " 'foo b' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %-5C"), 'b'); - if (memcmp(buf, convert("foo b "), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is" - " 'foo b ' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %05C"), 'b'); - if (memcmp(buf, convert("foo 0000b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is" - " 'foo 0000b' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %#C"), 'b'); - if (memcmp(buf, convert("foo b"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is" - " 'foo b' and the result returned was "; - BadResult = buf; - return FAIL; - } - 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; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/testinfo.dat deleted file mode 100644 index ffcb47a37f..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test7/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test %C formatter with wsprintfW. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/CMakeLists.txt deleted file mode 100644 index a6478a2af0..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test8 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test8 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test8 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/test.c deleted file mode 100644 index 63c296eb22..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/test.c +++ /dev/null @@ -1,128 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ -#define UNICODE -#include - - - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; -WCHAR buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - - -BOOL test1() -{ - int pos = 42; - - wsprintf(buf, convert("foo %d"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %ld"), 0xFFFF); - if (memcmp(buf, convert("foo 65535"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is" - " 'foo 65535' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %3d"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %-3d"), pos); - if (memcmp(buf, convert("foo 42 "), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is" - " 'foo 42 ' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.1d"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.3d"), pos); - if (memcmp(buf, convert("foo 042"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is" - " 'foo 042' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %03d"), pos); - if (memcmp(buf, convert("foo 042"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is" - " 'foo 042' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %#d"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - 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; - -} - - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/testinfo.dat deleted file mode 100644 index 4238671918..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test8/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test %d formatter with wsprintfW. - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/CMakeLists.txt deleted file mode 100644 index e09867b1a7..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12.2) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(SOURCES - test.c -) - -add_executable(paltest_wsprintfw_test9 - ${SOURCES} -) - -add_dependencies(paltest_wsprintfw_test9 coreclrpal) - -target_link_libraries(paltest_wsprintfw_test9 - pthread - m - coreclrpal -) diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/test.c b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/test.c deleted file mode 100644 index 0a49d9c2c5..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/test.c +++ /dev/null @@ -1,128 +0,0 @@ -// 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 wsprintfW() function -** -** -**=========================================================*/ - -#define UNICODE -#include - - -char * ErrorMessage = NULL; -WCHAR * BadResult = NULL; -WCHAR buf[256]; - -/* memcmp is used to verify the results, so this test is dependent on it. */ -/* ditto with strlen */ - - -BOOL test1() -{ - int pos = 42; - - wsprintf(buf, convert("foo %i"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 1) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %li"), 0xFFFF); - if (memcmp(buf, convert("foo 65535"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 2) Failed. The correct string is" - " 'foo 65535' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %3i"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 3) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %-3i"), pos); - if (memcmp(buf, convert("foo 42 "), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 4) Failed. The correct string is" - " 'foo 42 ' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.1i"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 5) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %.3i"), pos); - if (memcmp(buf, convert("foo 042"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 6) Failed. The correct string is" - " 'foo 042' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %03i"), pos); - if (memcmp(buf, convert("foo 042"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 7) Failed. The correct string is" - " 'foo 042' and the result returned was "; - BadResult = buf; - return FAIL; - } - - wsprintf(buf, convert("foo %#i"), pos); - if (memcmp(buf, convert("foo 42"), wcslen(buf)*2 + 2) != 0) - { - ErrorMessage = "ERROR: (Test 8) Failed. The correct string is" - " 'foo 42' and the result returned was "; - BadResult = buf; - return FAIL; - } - - 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; - -} - - diff --git a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/testinfo.dat deleted file mode 100644 index 3006aa87bc..0000000000 --- a/src/pal/tests/palsuite/miscellaneous/wsprintfW/test9/testinfo.dat +++ /dev/null @@ -1,14 +0,0 @@ -# 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 = wsprintfW -Name = Positive test of wsprintfW -TYPE = DEFAULT -EXE1 = test -Description -= Test %i formatter with wsprintfW. - - diff --git a/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/CMakeLists.txt index bf1d3a91e7..515815f9d2 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_GetPALDirectoryW.c + PAL_GetPALDirectoryW.cpp ) add_executable(paltest_pal_getpaldirectoryw_test1 diff --git a/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.c b/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.c deleted file mode 100644 index 2c67aa4954..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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: pal_getpaldirectoryw.c -** -** Purpose: Positive test the PAL_GetPALDirectoryW API. -** Call this API to retrieve a fully-qualified -** directory name where the PAL DLL is loaded from. -** -** -**============================================================*/ -#define UNICODE -#include - -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"); - } - - UINT size = MAX_PATH; - /*retrieve the machine configuration directory*/ - bValue = PAL_GetPALDirectoryW(wpDirectoryName, &size); - 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; -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.cpp b/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.cpp new file mode 100644 index 0000000000..856bfe8659 --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.cpp @@ -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: pal_getpaldirectoryw.c +** +** Purpose: Positive test the PAL_GetPALDirectoryW API. +** Call this API to retrieve a fully-qualified +** directory name where the PAL DLL is loaded from. +** +** +**============================================================*/ +#define UNICODE +#include + +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 = (WCHAR*)malloc(MAX_PATH*sizeof(WCHAR)); + if(NULL == wpDirectoryName) + { + Fail("\nFailed to allocate memory for storing directory name!\n"); + } + + UINT size = MAX_PATH; + /*retrieve the machine configuration directory*/ + bValue = PAL_GetPALDirectoryW(wpDirectoryName, &size); + 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; +} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/CMakeLists.txt index e8d3c40565..26eb1a860b 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_GetUserTempDirectoryW.c + PAL_GetUserTempDirectoryW.cpp ) add_executable(paltest_pal_getusertempdirectoryw_test1 diff --git a/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.c b/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.c deleted file mode 100644 index 65cc426c74..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.c +++ /dev/null @@ -1,58 +0,0 @@ -// 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: pal_getusertempdirectoryw.c -** -** Purpose: Positive test the PAL_GetUserTempDirectoryW API. -** Call PAL_GetUserTempDirectoryW to retrieve the user -** temp directory. -** -** -**============================================================*/ -#define UNICODE -#include - -#define DIRECTORYLENGTH 1024 - -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); - } - - //retrieve 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"); - } - - - //retrieve the attributes of a file or directory - dwFileAttribute = GetFileAttributesW(wDirectoryName); - - - //check if the retrieved 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; - -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.cpp b/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.cpp new file mode 100644 index 0000000000..65cc426c74 --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.cpp @@ -0,0 +1,58 @@ +// 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: pal_getusertempdirectoryw.c +** +** Purpose: Positive test the PAL_GetUserTempDirectoryW API. +** Call PAL_GetUserTempDirectoryW to retrieve the user +** temp directory. +** +** +**============================================================*/ +#define UNICODE +#include + +#define DIRECTORYLENGTH 1024 + +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); + } + + //retrieve 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"); + } + + + //retrieve the attributes of a file or directory + dwFileAttribute = GetFileAttributesW(wDirectoryName); + + + //check if the retrieved 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; + +} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/CMakeLists.txt index 416439d650..281efcd8be 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_Initialize_Terminate.c + PAL_Initialize_Terminate.cpp ) add_executable(paltest_pal_initialize_terminate_test1 diff --git a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/PAL_Initialize_Terminate.c b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/PAL_Initialize_Terminate.c deleted file mode 100644 index 29bb2c3b4f..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/PAL_Initialize_Terminate.c +++ /dev/null @@ -1,33 +0,0 @@ -// 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: pal_initialize_terminate.c -** -** Purpose: Positive test the PAL_Initialize and PAL_Terminate API. -** Call PAL_Initialize to initialize the PAL -** environment and call PAL_Terminate to clean up the PAL -** environment. -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - - if(0 != err) - { - ExitProcess(1); - } - - PAL_Terminate(); - return 0; -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/PAL_Initialize_Terminate.cpp b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/PAL_Initialize_Terminate.cpp new file mode 100644 index 0000000000..29bb2c3b4f --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test1/PAL_Initialize_Terminate.cpp @@ -0,0 +1,33 @@ +// 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: pal_initialize_terminate.c +** +** Purpose: Positive test the PAL_Initialize and PAL_Terminate API. +** Call PAL_Initialize to initialize the PAL +** environment and call PAL_Terminate to clean up the PAL +** environment. +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + + if(0 != err) + { + ExitProcess(1); + } + + PAL_Terminate(); + return 0; +} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/CMakeLists.txt index b7661fd240..46b42aa714 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - pal_initialize_twice.c + pal_initialize_twice.cpp ) add_executable(paltest_pal_initialize_terminate_test2 diff --git a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.c b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.c deleted file mode 100644 index fc460bc1ad..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: pal_initialize_twice.c -** -** Purpose: Positive test of PAL_Initialize and PAL_Terminate APIs. -** Calls PAL_Initialize twice to ensure that doing so -** will not cause unexpected failures in the PAL. -** Calls PAL_Terminate twice to clean up the PAL. -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - /* Initialize the PAL environment */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Try calling PAL_Initialize again - should just increment the init_count. */ - if (0 != (PAL_Initialize(argc, argv))) - { - // Call terminate due to the first PAL initialization. - PAL_TerminateEx(FAIL); - return FAIL; - } - - /* If both calls to PAL_Initialize succeed, then PAL_Terminate must be - called twice. The first call just decrements the init_count to 1. */ - - PAL_Terminate(); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.cpp b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.cpp new file mode 100644 index 0000000000..fc460bc1ad --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.cpp @@ -0,0 +1,41 @@ +// 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: pal_initialize_twice.c +** +** Purpose: Positive test of PAL_Initialize and PAL_Terminate APIs. +** Calls PAL_Initialize twice to ensure that doing so +** will not cause unexpected failures in the PAL. +** Calls PAL_Terminate twice to clean up the PAL. +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + /* Initialize the PAL environment */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Try calling PAL_Initialize again - should just increment the init_count. */ + if (0 != (PAL_Initialize(argc, argv))) + { + // Call terminate due to the first PAL initialization. + PAL_TerminateEx(FAIL); + return FAIL; + } + + /* If both calls to PAL_Initialize succeed, then PAL_Terminate must be + called twice. The first call just decrements the init_count to 1. */ + + PAL_Terminate(); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/CMakeLists.txt index 2379694b24..573ab3834a 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_RegisterLibraryW_UnregisterLibraryW.c + PAL_RegisterLibraryW_UnregisterLibraryW.cpp ) add_executable(paltest_pal_registerlibraryw_unregisterlibraryw_test1 diff --git a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/PAL_RegisterLibraryW_UnregisterLibraryW.c b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/PAL_RegisterLibraryW_UnregisterLibraryW.c deleted file mode 100644 index ff0d33879c..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/PAL_RegisterLibraryW_UnregisterLibraryW.c +++ /dev/null @@ -1,64 +0,0 @@ -// 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: pal_registerlibrary_unregisterlibrary -** -** Purpose: Positive test the PAL_RegisterLibrary API and -** PAL_UnRegisterLibrary. -** Call PAL_RegisterLibrary to map a module into the calling -** process address space and call PAL_UnRegisterLibrary -** to unmap this module. -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - char ModuleName[64]; - WCHAR *wpModuleName = NULL; - int err; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*zero the buffer*/ - memset(ModuleName,0,64); - sprintf(ModuleName, "%s", "rotor_pal"); - - /*convert a normal string to a wide one*/ - wpModuleName = convert(ModuleName); - - /*load a module*/ - ModuleHandle = PAL_RegisterLibrary(wpModuleName); - - /*free the memory*/ - free(wpModuleName); - - if(!ModuleHandle) - { - Fail("Failed to call PAL_RegisterLibrary API to map a module " - "into calling process, error code=%u!\n", GetLastError()); - } - - /*decrement the reference count of the loaded DLL*/ - err = PAL_UnregisterLibrary(ModuleHandle); - if(0 == err) - { - Fail("\nFailed to call PAL_UnregisterLibrary API to " - "decrement the count of the loaded DLL module, " - "error code=%u!\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/PAL_RegisterLibraryW_UnregisterLibraryW.cpp b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/PAL_RegisterLibraryW_UnregisterLibraryW.cpp new file mode 100644 index 0000000000..8eb8776107 --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/PAL_RegisterLibraryW_UnregisterLibraryW.cpp @@ -0,0 +1,64 @@ +// 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: pal_registerlibrary_unregisterlibrary +** +** Purpose: Positive test the PAL_RegisterLibrary API and +** PAL_UnRegisterLibrary. +** Call PAL_RegisterLibrary to map a module into the calling +** process address space and call PAL_UnRegisterLibrary +** to unmap this module. +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + char ModuleName[64]; + WCHAR *wpModuleName = NULL; + int err; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*zero the buffer*/ + memset(ModuleName,0,64); + sprintf_s(ModuleName, _countof(ModuleName), "%s", "rotor_pal"); + + /*convert a normal string to a wide one*/ + wpModuleName = convert(ModuleName); + + /*load a module*/ + ModuleHandle = PAL_RegisterLibrary(wpModuleName); + + /*free the memory*/ + free(wpModuleName); + + if(!ModuleHandle) + { + Fail("Failed to call PAL_RegisterLibrary API to map a module " + "into calling process, error code=%u!\n", GetLastError()); + } + + /*decrement the reference count of the loaded DLL*/ + err = PAL_UnregisterLibrary(ModuleHandle); + if(0 == err) + { + Fail("\nFailed to call PAL_UnregisterLibrary API to " + "decrement the count of the loaded DLL module, " + "error code=%u!\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/CMakeLists.txt index bbcb35933e..ef5c0479b7 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - reg_unreg_libraryw_neg.c + reg_unreg_libraryw_neg.cpp ) add_executable(paltest_reg_unreg_libraryw_neg diff --git a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/reg_unreg_libraryw_neg.c b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/reg_unreg_libraryw_neg.c deleted file mode 100644 index a15ff5745b..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/reg_unreg_libraryw_neg.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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: pal_registerlibraryw_unregisterlibraryw_neg.c -** -** Purpose: Negative test the PAL_RegisterLibrary API. -** Call PAL_RegisterLibrary to map a non-existant module -** into the calling process address space. -** -** -**============================================================*/ -#define UNICODE -#include - -int __cdecl main(int argc, char *argv[]) -{ - HMODULE ModuleHandle; - char ModuleName[64]; - WCHAR *wpModuleName = NULL; - int err; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - memset(ModuleName, 0, 64); - sprintf(ModuleName, "%s", "not_exist_module_name"); - - /*convert a normal string to a wide one*/ - wpModuleName = convert(ModuleName); - - /*load a not exist module*/ - ModuleHandle = PAL_RegisterLibrary(wpModuleName); - - /*free the memory*/ - free(wpModuleName); - - if(NULL != ModuleHandle) - { - Trace("ERROR: PAL_RegisterLibrary successfully mapped " - "a module that does not exist into the calling process\n"); - - /*decrement the reference count of the loaded DLL*/ - err = PAL_UnregisterLibrary(ModuleHandle); - if(0 == err) - { - Trace("\nFailed to call PAL_UnregisterLibrary API to decrement the " - "count of the loaded DLL module!\n"); - } - Fail(""); - - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/reg_unreg_libraryw_neg.cpp b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/reg_unreg_libraryw_neg.cpp new file mode 100644 index 0000000000..c6fa4ad074 --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test2_neg/reg_unreg_libraryw_neg.cpp @@ -0,0 +1,62 @@ +// 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: pal_registerlibraryw_unregisterlibraryw_neg.c +** +** Purpose: Negative test the PAL_RegisterLibrary API. +** Call PAL_RegisterLibrary to map a non-existant module +** into the calling process address space. +** +** +**============================================================*/ +#define UNICODE +#include + +int __cdecl main(int argc, char *argv[]) +{ + HMODULE ModuleHandle; + char ModuleName[64]; + WCHAR *wpModuleName = NULL; + int err; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + memset(ModuleName, 0, 64); + sprintf_s(ModuleName, _countof(ModuleName), "%s", "not_exist_module_name"); + + /*convert a normal string to a wide one*/ + wpModuleName = convert(ModuleName); + + /*load a not exist module*/ + ModuleHandle = PAL_RegisterLibrary(wpModuleName); + + /*free the memory*/ + free(wpModuleName); + + if(NULL != ModuleHandle) + { + Trace("ERROR: PAL_RegisterLibrary successfully mapped " + "a module that does not exist into the calling process\n"); + + /*decrement the reference count of the loaded DLL*/ + err = PAL_UnregisterLibrary(ModuleHandle); + if(0 == err) + { + Trace("\nFailed to call PAL_UnregisterLibrary API to decrement the " + "count of the loaded DLL module!\n"); + } + Fail(""); + + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/CMakeLists.txt index 59922b194b..d20ddd9a43 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_errno.c + PAL_errno.cpp ) add_executable(paltest_pal_errno_test1 diff --git a/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.c b/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.c deleted file mode 100644 index 32e8487d07..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.c +++ /dev/null @@ -1,53 +0,0 @@ -// 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: pal_errno.c -** -** Purpose: Positive test the PAL_errno API. -** call PAL_errno to retrieve the pointer to -** the per-thread errno value. -** -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - FILE *pFile = NULL; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if( 0 != err) - { - return FAIL; - } - - /*Try to open a not-exist file to read to generate an error*/ - pFile = fopen( "no_exist_file_name", "r" ); - - if( NULL != pFile ) - { - Trace("\nFailed to call fopen to open a not exist for reading, " - "an error is expected, but no error occurred\n"); - - if( EOF == fclose( pFile ) ) - { - Trace("\nFailed to call fclose to close a file stream\n"); - } - Fail( "Test failed! fopen() Should not have worked!" ); - } - - /*retrieve the per-thread error value pointer*/ - if( 2 != errno ) - { - Fail("\nFailed to call PAL_errno API, this value is not correct." - " The correct value is ENOENT[2] ( No such file or directory.).\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.cpp b/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.cpp new file mode 100644 index 0000000000..32e8487d07 --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.cpp @@ -0,0 +1,53 @@ +// 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: pal_errno.c +** +** Purpose: Positive test the PAL_errno API. +** call PAL_errno to retrieve the pointer to +** the per-thread errno value. +** +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + FILE *pFile = NULL; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if( 0 != err) + { + return FAIL; + } + + /*Try to open a not-exist file to read to generate an error*/ + pFile = fopen( "no_exist_file_name", "r" ); + + if( NULL != pFile ) + { + Trace("\nFailed to call fopen to open a not exist for reading, " + "an error is expected, but no error occurred\n"); + + if( EOF == fclose( pFile ) ) + { + Trace("\nFailed to call fclose to close a file stream\n"); + } + Fail( "Test failed! fopen() Should not have worked!" ); + } + + /*retrieve the per-thread error value pointer*/ + if( 2 != errno ) + { + Fail("\nFailed to call PAL_errno API, this value is not correct." + " The correct value is ENOENT[2] ( No such file or directory.).\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/CMakeLists.txt index 3436a2dfdb..dbedac95f5 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_get_stderr.c + PAL_get_stderr.cpp ) add_executable(paltest_pal_get_stderr_test1 diff --git a/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.c b/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.c deleted file mode 100644 index da53460101..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: pal_get_stderr.c -** -** Purpose: Positive test the PAL_get_stderr API. -** Call PAL_get_stderr to retrieve the PAL standard error -** output stream pointer. -** This test case should be run manually and automatically. -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - FILE *pPAL_stderr = NULL; - const char *pMsg = "\nThis is a PAL_get_stderr test message, " - "not an error message!\n"; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*retrieve the PAL standard error output stream pointer*/ - pPAL_stderr = PAL_get_stderr(); - - if(NULL == pPAL_stderr) - { - Fail("\nFailed to call PAL_get_stderr API, error code = %u\n", - GetLastError()); - } - - /*output a test message through PAL standard error stream*/ - err = fputs(pMsg, pPAL_stderr); - if(EOF == err) - { - Fail("\nFailed to call fputs to output message to PAL stdandard " - "error stream, error code=%u\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp b/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp new file mode 100644 index 0000000000..da53460101 --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp @@ -0,0 +1,52 @@ +// 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: pal_get_stderr.c +** +** Purpose: Positive test the PAL_get_stderr API. +** Call PAL_get_stderr to retrieve the PAL standard error +** output stream pointer. +** This test case should be run manually and automatically. +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + FILE *pPAL_stderr = NULL; + const char *pMsg = "\nThis is a PAL_get_stderr test message, " + "not an error message!\n"; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*retrieve the PAL standard error output stream pointer*/ + pPAL_stderr = PAL_get_stderr(); + + if(NULL == pPAL_stderr) + { + Fail("\nFailed to call PAL_get_stderr API, error code = %u\n", + GetLastError()); + } + + /*output a test message through PAL standard error stream*/ + err = fputs(pMsg, pPAL_stderr); + if(EOF == err) + { + Fail("\nFailed to call fputs to output message to PAL stdandard " + "error stream, error code=%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/CMakeLists.txt index 592895b18c..4d714a3735 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_get_stdin.c + PAL_get_stdin.cpp ) add_executable(paltest_pal_get_stdin_test1 diff --git a/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.c b/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.c deleted file mode 100644 index 5d1fd23f92..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: pal_get_stdin.c -** -** Purpose: Positive test the PAL_get_stdout API. -** Call PAL_get_stdin to retrieve the PAL standard input -** stream pointer. -** This test case should be run manually. -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - FILE *pPAL_stdin = NULL; - char Buffer[256]; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*retrieve the PAL standard input stream pointer*/ - pPAL_stdin = PAL_get_stdin(); - if(NULL == pPAL_stdin) - { - Fail("\nFailed to call PAL_get_stdin API to retrieve the " - "PAL standard input stream pointer, " - "error code = %u\n", GetLastError()); - } - - /*zero the buffer*/ - memset(Buffer, 0, 256); - - printf("\nPlease input some words: (less than 255 characters)\n"); - - /*further test the input stream*/ - /*read message from the PAL standard input stream*/ - if(NULL == fgets(Buffer, 255, pPAL_stdin)) - { - Fail( "Failed to call fgets to get a string from PAL standard " - "input stream, error code=%u\n", GetLastError()); - } - else - { - if(1 == strlen(Buffer) && Buffer[0] == '\n') - { - printf("\nEmpty input!\n"); - } - else - { - printf("\nYour input words are:\n%s\n", Buffer); - } - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp b/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp new file mode 100644 index 0000000000..5d1fd23f92 --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp @@ -0,0 +1,68 @@ +// 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: pal_get_stdin.c +** +** Purpose: Positive test the PAL_get_stdout API. +** Call PAL_get_stdin to retrieve the PAL standard input +** stream pointer. +** This test case should be run manually. +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + FILE *pPAL_stdin = NULL; + char Buffer[256]; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*retrieve the PAL standard input stream pointer*/ + pPAL_stdin = PAL_get_stdin(); + if(NULL == pPAL_stdin) + { + Fail("\nFailed to call PAL_get_stdin API to retrieve the " + "PAL standard input stream pointer, " + "error code = %u\n", GetLastError()); + } + + /*zero the buffer*/ + memset(Buffer, 0, 256); + + printf("\nPlease input some words: (less than 255 characters)\n"); + + /*further test the input stream*/ + /*read message from the PAL standard input stream*/ + if(NULL == fgets(Buffer, 255, pPAL_stdin)) + { + Fail( "Failed to call fgets to get a string from PAL standard " + "input stream, error code=%u\n", GetLastError()); + } + else + { + if(1 == strlen(Buffer) && Buffer[0] == '\n') + { + printf("\nEmpty input!\n"); + } + else + { + printf("\nYour input words are:\n%s\n", Buffer); + } + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/CMakeLists.txt index 865dd52f16..4c2f51b50d 100644 --- a/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - PAL_get_stdout.c + PAL_get_stdout.cpp ) add_executable(paltest_pal_get_stdout_test1 diff --git a/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.c b/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.c deleted file mode 100644 index ebfee47ae9..0000000000 --- a/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.c +++ /dev/null @@ -1,52 +0,0 @@ -// 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: pal_get_stdout.c -** -** Purpose: Positive test the PAL_get_stdout API. -** Call PAL_get_stdout to retrieve the PAL standard output -** stream pointer. -** This test case should be run manually and automatically. -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - FILE *pPAL_stdout = NULL; - const char *pMsg = "\nThis is a PAL_get_stdout test output message, " - "not an error message!\n"; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*retrieve the PAL output stream pointer*/ - pPAL_stdout = PAL_get_stdout(); - if(NULL == pPAL_stdout) - { - Fail("\nFailed to call PAL_get_stdout API to retrieve the " - "standard PAL output stream pointer, error code=%u\n", - GetLastError()); - } - - /*output a test message through PAL standard output stream*/ - err = fputs(pMsg, pPAL_stdout); - if(EOF == err) - { - Fail("\nFailed to call fputs to output message to PAL stdandard " - "output stream, error code=%u\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.cpp b/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.cpp new file mode 100644 index 0000000000..ebfee47ae9 --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.cpp @@ -0,0 +1,52 @@ +// 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: pal_get_stdout.c +** +** Purpose: Positive test the PAL_get_stdout API. +** Call PAL_get_stdout to retrieve the PAL standard output +** stream pointer. +** This test case should be run manually and automatically. +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + FILE *pPAL_stdout = NULL; + const char *pMsg = "\nThis is a PAL_get_stdout test output message, " + "not an error message!\n"; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*retrieve the PAL output stream pointer*/ + pPAL_stdout = PAL_get_stdout(); + if(NULL == pPAL_stdout) + { + Fail("\nFailed to call PAL_get_stdout API to retrieve the " + "standard PAL output stream pointer, error code=%u\n", + GetLastError()); + } + + /*output a test message through PAL standard output stream*/ + err = fputs(pMsg, pPAL_stdout); + if(EOF == err) + { + Fail("\nFailed to call fputs to output message to PAL stdandard " + "output stream, error code=%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/CMakeLists.txt index cd18b76958..82ff9225de 100644 --- a/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - pal_entrypoint.c + pal_entrypoint.cpp ) add_executable(paltest_pal_entrypoint_test1 diff --git a/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/pal_entrypoint.c b/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/pal_entrypoint.c deleted file mode 100644 index c1b66944aa..0000000000 --- a/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/pal_entrypoint.c +++ /dev/null @@ -1,54 +0,0 @@ -// 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: pal_entrypoint.c -** -** Purpose: Positive test the PAL_EntryPoint API. -** -** Test the PAL_EntryPoint, Call a PAL function, and let main return -** as expected.. -** - -** -**============================================================*/ - -#include "palstartup.h" - -/* Test case copied and stream lined from isalpha\test1*/ -struct testCase -{ - int CorrectResult; - int character; -}; - -int __cdecl main(int argc, char *argv[]) -{ - int result; - int i; - - struct testCase testCases[] = - { - {1, 'a'} - }; - - - i = 0; - result = isalpha(testCases[i].character); - /* The return value is 'non-zero' for success. This if condition - * will still work if that non-zero isn't just 1 - */ - if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || - ( (testCases[i].CorrectResult == 0) && (result != 0) )) - { - Fail("ERROR: isalpha returned %i instead of %i for character " - "%c.\n", - result, - testCases[i].CorrectResult, - testCases[i].character); - } - - return PASS; -} diff --git a/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/pal_entrypoint.cpp b/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/pal_entrypoint.cpp new file mode 100644 index 0000000000..c1b66944aa --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/pal_entrypoint/test1/pal_entrypoint.cpp @@ -0,0 +1,54 @@ +// 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: pal_entrypoint.c +** +** Purpose: Positive test the PAL_EntryPoint API. +** +** Test the PAL_EntryPoint, Call a PAL function, and let main return +** as expected.. +** + +** +**============================================================*/ + +#include "palstartup.h" + +/* Test case copied and stream lined from isalpha\test1*/ +struct testCase +{ + int CorrectResult; + int character; +}; + +int __cdecl main(int argc, char *argv[]) +{ + int result; + int i; + + struct testCase testCases[] = + { + {1, 'a'} + }; + + + i = 0; + result = isalpha(testCases[i].character); + /* The return value is 'non-zero' for success. This if condition + * will still work if that non-zero isn't just 1 + */ + if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || + ( (testCases[i].CorrectResult == 0) && (result != 0) )) + { + Fail("ERROR: isalpha returned %i instead of %i for character " + "%c.\n", + result, + testCases[i].CorrectResult, + testCases[i].character); + } + + return PASS; +} diff --git a/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/CMakeLists.txt b/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/CMakeLists.txt index f6e243d0c4..56c9d02eaa 100644 --- a/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - pal_initializedebug.c + pal_initializedebug.cpp ) add_executable(paltest_pal_initializedebug_test1 diff --git a/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/pal_initializedebug.c b/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/pal_initializedebug.c deleted file mode 100644 index d14c316013..0000000000 --- a/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/pal_initializedebug.c +++ /dev/null @@ -1,36 +0,0 @@ -// 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: pal_initializedebug.c -** -** Purpose: Positive test the PAL_InitializeDebug API. -** -** Test the PAL_InitializeDebug, it will be NOPs for all -** platforms other than Mac. There is no other way of testing it -** currently -** - -** -**============================================================*/ -#include - -int __cdecl main(int argc, char *argv[]) -{ - int err; - - /* Initialize the PAL environment */ - err = PAL_Initialize(argc, argv); - - if(0 != err) - { - return FAIL; - } - - PAL_InitializeDebug(); - - PAL_Terminate(); - return 0; -} diff --git a/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/pal_initializedebug.cpp b/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/pal_initializedebug.cpp new file mode 100644 index 0000000000..d14c316013 --- /dev/null +++ b/src/pal/tests/palsuite/pal_specific/pal_initializedebug/test1/pal_initializedebug.cpp @@ -0,0 +1,36 @@ +// 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: pal_initializedebug.c +** +** Purpose: Positive test the PAL_InitializeDebug API. +** +** Test the PAL_InitializeDebug, it will be NOPs for all +** platforms other than Mac. There is no other way of testing it +** currently +** + +** +**============================================================*/ +#include + +int __cdecl main(int argc, char *argv[]) +{ + int err; + + /* Initialize the PAL environment */ + err = PAL_Initialize(argc, argv); + + if(0 != err) + { + return FAIL; + } + + PAL_InitializeDebug(); + + PAL_Terminate(); + return 0; +} diff --git a/src/pal/tests/palsuite/paltestlist.txt b/src/pal/tests/palsuite/paltestlist.txt index d0a76e9573..2cedca2b97 100644 --- a/src/pal/tests/palsuite/paltestlist.txt +++ b/src/pal/tests/palsuite/paltestlist.txt @@ -1,20 +1,28 @@ c_runtime/abs/test1/paltest_abs_test1 c_runtime/acos/test1/paltest_acos_test1 +c_runtime/acosf/test1/paltest_acosf_test1 c_runtime/asin/test1/paltest_asin_test1 +c_runtime/asinf/test1/paltest_asinf_test1 c_runtime/atan/test1/paltest_atan_test1 c_runtime/atan2/test1/paltest_atan2_test1 +c_runtime/atan2f/test1/paltest_atan2f_test1 +c_runtime/atanf/test1/paltest_atanf_test1 c_runtime/atof/test1/paltest_atof_test1 c_runtime/atoi/test1/paltest_atoi_test1 c_runtime/atol/test1/paltest_atol_test1 c_runtime/bsearch/test1/paltest_bsearch_test1 c_runtime/bsearch/test2/paltest_bsearch_test2 c_runtime/ceil/test1/paltest_ceil_test1 +c_runtime/ceilf/test1/paltest_ceilf_test1 c_runtime/cos/test1/paltest_cos_test1 +c_runtime/cosf/test1/paltest_cosf_test1 c_runtime/cosh/test1/paltest_cosh_test1 +c_runtime/coshf/test1/paltest_coshf_test1 c_runtime/errno/test1/paltest_errno_test1 c_runtime/errno/test2/paltest_errno_test2 c_runtime/exit/test1/paltest_exit_test1 c_runtime/exp/test1/paltest_exp_test1 +c_runtime/expf/test1/paltest_expf_test1 c_runtime/fabs/test1/paltest_fabs_test1 c_runtime/fabsf/test1/paltest_fabsf_test1 c_runtime/fclose/test1/paltest_fclose_test1 @@ -24,6 +32,7 @@ c_runtime/fgets/test1/paltest_fgets_test1 c_runtime/fgets/test2/paltest_fgets_test2 c_runtime/fgets/test3/paltest_fgets_test3 c_runtime/floor/test1/paltest_floor_test1 +c_runtime/floorf/test1/paltest_floorf_test1 c_runtime/fmod/test1/paltest_fmod_test1 c_runtime/fmodf/test1/paltest_fmodf_test1 c_runtime/fopen/test1/paltest_fopen_test1 @@ -94,6 +103,8 @@ c_runtime/llabs/test1/paltest_llabs_test1 c_runtime/localtime/test1/paltest_localtime_test1 c_runtime/log/test1/paltest_log_test1 c_runtime/log10/test1/paltest_log10_test1 +c_runtime/log10f/test1/paltest_log10f_test1 +c_runtime/logf/test1/paltest_logf_test1 c_runtime/malloc/test1/paltest_malloc_test1 c_runtime/malloc/test2/paltest_malloc_test2 c_runtime/memchr/test1/paltest_memchr_test1 @@ -104,6 +115,7 @@ c_runtime/memset/test1/paltest_memset_test1 c_runtime/modf/test1/paltest_modf_test1 c_runtime/modff/test1/paltest_modff_test1 c_runtime/pow/test1/paltest_pow_test1 +c_runtime/powf/test1/paltest_powf_test1 c_runtime/printf/test1/paltest_printf_test1 c_runtime/printf/test10/paltest_printf_test10 c_runtime/printf/test11/paltest_printf_test11 @@ -128,44 +140,46 @@ c_runtime/qsort/test2/paltest_qsort_test2 c_runtime/rand_srand/test1/paltest_rand_srand_test1 c_runtime/realloc/test1/paltest_realloc_test1 c_runtime/sin/test1/paltest_sin_test1 +c_runtime/sinf/test1/paltest_sinf_test1 c_runtime/sinh/test1/paltest_sinh_test1 -c_runtime/sprintf/test1/paltest_sprintf_test1 -c_runtime/sprintf/test10/paltest_sprintf_test10 -c_runtime/sprintf/test11/paltest_sprintf_test11 -c_runtime/sprintf/test12/paltest_sprintf_test12 -c_runtime/sprintf/test13/paltest_sprintf_test13 -c_runtime/sprintf/test14/paltest_sprintf_test14 -c_runtime/sprintf/test15/paltest_sprintf_test15 -c_runtime/sprintf/test16/paltest_sprintf_test16 -c_runtime/sprintf/test17/paltest_sprintf_test17 -c_runtime/sprintf/test18/paltest_sprintf_test18 -c_runtime/sprintf/test19/paltest_sprintf_test19 -c_runtime/sprintf/test2/paltest_sprintf_test2 -c_runtime/sprintf/test3/paltest_sprintf_test3 -c_runtime/sprintf/test4/paltest_sprintf_test4 -c_runtime/sprintf/test5/paltest_sprintf_test5 -c_runtime/sprintf/test6/paltest_sprintf_test6 -c_runtime/sprintf/test7/paltest_sprintf_test7 -c_runtime/sprintf/test8/paltest_sprintf_test8 -c_runtime/sprintf/test9/paltest_sprintf_test9 +c_runtime/sinhf/test1/paltest_sinhf_test1 +c_runtime/sprintf_s/test1/paltest_sprintf_test1 +c_runtime/sprintf_s/test10/paltest_sprintf_test10 +c_runtime/sprintf_s/test11/paltest_sprintf_test11 +c_runtime/sprintf_s/test12/paltest_sprintf_test12 +c_runtime/sprintf_s/test13/paltest_sprintf_test13 +c_runtime/sprintf_s/test14/paltest_sprintf_test14 +c_runtime/sprintf_s/test15/paltest_sprintf_test15 +c_runtime/sprintf_s/test16/paltest_sprintf_test16 +c_runtime/sprintf_s/test17/paltest_sprintf_test17 +c_runtime/sprintf_s/test18/paltest_sprintf_test18 +c_runtime/sprintf_s/test19/paltest_sprintf_test19 +c_runtime/sprintf_s/test2/paltest_sprintf_test2 +c_runtime/sprintf_s/test3/paltest_sprintf_test3 +c_runtime/sprintf_s/test4/paltest_sprintf_test4 +c_runtime/sprintf_s/test6/paltest_sprintf_test6 +c_runtime/sprintf_s/test7/paltest_sprintf_test7 +c_runtime/sprintf_s/test8/paltest_sprintf_test8 +c_runtime/sprintf_s/test9/paltest_sprintf_test9 c_runtime/sqrt/test1/paltest_sqrt_test1 -c_runtime/sscanf/test1/paltest_sscanf_test1 -c_runtime/sscanf/test10/paltest_sscanf_test10 -c_runtime/sscanf/test11/paltest_sscanf_test11 -c_runtime/sscanf/test12/paltest_sscanf_test12 -c_runtime/sscanf/test13/paltest_sscanf_test13 -c_runtime/sscanf/test14/paltest_sscanf_test14 -c_runtime/sscanf/test15/paltest_sscanf_test15 -c_runtime/sscanf/test16/paltest_sscanf_test16 -c_runtime/sscanf/test17/paltest_sscanf_test17 -c_runtime/sscanf/test2/paltest_sscanf_test2 -c_runtime/sscanf/test3/paltest_sscanf_test3 -c_runtime/sscanf/test4/paltest_sscanf_test4 -c_runtime/sscanf/test5/paltest_sscanf_test5 -c_runtime/sscanf/test6/paltest_sscanf_test6 -c_runtime/sscanf/test7/paltest_sscanf_test7 -c_runtime/sscanf/test8/paltest_sscanf_test8 -c_runtime/sscanf/test9/paltest_sscanf_test9 +c_runtime/sqrtf/test1/paltest_sqrtf_test1 +c_runtime/sscanf_s/test1/paltest_sscanf_test1 +c_runtime/sscanf_s/test10/paltest_sscanf_test10 +c_runtime/sscanf_s/test11/paltest_sscanf_test11 +c_runtime/sscanf_s/test12/paltest_sscanf_test12 +c_runtime/sscanf_s/test13/paltest_sscanf_test13 +c_runtime/sscanf_s/test14/paltest_sscanf_test14 +c_runtime/sscanf_s/test15/paltest_sscanf_test15 +c_runtime/sscanf_s/test16/paltest_sscanf_test16 +c_runtime/sscanf_s/test17/paltest_sscanf_test17 +c_runtime/sscanf_s/test2/paltest_sscanf_test2 +c_runtime/sscanf_s/test3/paltest_sscanf_test3 +c_runtime/sscanf_s/test4/paltest_sscanf_test4 +c_runtime/sscanf_s/test5/paltest_sscanf_test5 +c_runtime/sscanf_s/test6/paltest_sscanf_test6 +c_runtime/sscanf_s/test7/paltest_sscanf_test7 +c_runtime/sscanf_s/test8/paltest_sscanf_test8 +c_runtime/sscanf_s/test9/paltest_sscanf_test9 c_runtime/strcat/test1/paltest_strcat_test1 c_runtime/strchr/test1/paltest_strchr_test1 c_runtime/strcmp/test1/paltest_strcmp_test1 @@ -218,7 +232,9 @@ c_runtime/swscanf/test7/paltest_swscanf_test7 c_runtime/swscanf/test8/paltest_swscanf_test8 c_runtime/swscanf/test9/paltest_swscanf_test9 c_runtime/tan/test1/paltest_tan_test1 +c_runtime/tanf/test1/paltest_tanf_test1 c_runtime/tanh/test1/paltest_tanh_test1 +c_runtime/tanhf/test1/paltest_tanhf_test1 c_runtime/time/test1/paltest_time_test1 c_runtime/tolower/test1/paltest_tolower_test1 c_runtime/toupper/test1/paltest_toupper_test1 @@ -328,13 +344,13 @@ c_runtime/wprintf/test1/paltest_wprintf_test1 c_runtime/_alloca/test1/paltest_alloca_test1 c_runtime/_fdopen/test1/paltest_fdopen_test1 c_runtime/_finite/test1/paltest_finite_test1 +c_runtime/_finitef/test1/paltest_finitef_test1 c_runtime/_fullpath/test1/paltest_fullpath_test1 c_runtime/_isnan/test1/paltest_isnan_test1 +c_runtime/_isnanf/test1/paltest_isnanf_test1 c_runtime/_itow/test1/paltest_itow_test1 -c_runtime/_makepath/test1/paltest_makepath_test1 c_runtime/_mbsdec/test1/paltest_mbsdec_test1 c_runtime/_mbsinc/test1/paltest_mbsinc_test1 -c_runtime/_mbslen/test1/paltest_mbslen_test1 c_runtime/_mbsninc/test1/paltest_mbsninc_test1 c_runtime/_open_osfhandle/test1/paltest_open_osfhandle_test1 c_runtime/_open_osfhandle/test2/paltest_open_osfhandle_test2 @@ -345,47 +361,43 @@ c_runtime/_putenv/test4/paltest_putenv_test4 c_runtime/_putw/test1/paltest_putw_test1 c_runtime/_rotl/test1/paltest_rotl_test1 c_runtime/_rotr/test1/paltest_rotr_test1 -c_runtime/_snprintf/test1/paltest_snprintf_test1 -c_runtime/_snprintf/test10/paltest_snprintf_test10 -c_runtime/_snprintf/test11/paltest_snprintf_test11 -c_runtime/_snprintf/test12/paltest_snprintf_test12 -c_runtime/_snprintf/test13/paltest_snprintf_test13 -c_runtime/_snprintf/test14/paltest_snprintf_test14 -c_runtime/_snprintf/test15/paltest_snprintf_test15 -c_runtime/_snprintf/test16/paltest_snprintf_test16 -c_runtime/_snprintf/test17/paltest_snprintf_test17 -c_runtime/_snprintf/test18/paltest_snprintf_test18 -c_runtime/_snprintf/test19/paltest_snprintf_test19 -c_runtime/_snprintf/test2/paltest_snprintf_test2 -c_runtime/_snprintf/test3/paltest_snprintf_test3 -c_runtime/_snprintf/test4/paltest_snprintf_test4 -c_runtime/_snprintf/test5/paltest_snprintf_test5 -c_runtime/_snprintf/test6/paltest_snprintf_test6 -c_runtime/_snprintf/test7/paltest_snprintf_test7 -c_runtime/_snprintf/test8/paltest_snprintf_test8 -c_runtime/_snprintf/test9/paltest_snprintf_test9 -c_runtime/_snwprintf/test1/paltest_snwprintf_test1 -c_runtime/_snwprintf/test10/paltest_snwprintf_test10 -c_runtime/_snwprintf/test11/paltest_snwprintf_test11 -c_runtime/_snwprintf/test12/paltest_snwprintf_test12 -c_runtime/_snwprintf/test13/paltest_snwprintf_test13 -c_runtime/_snwprintf/test14/paltest_snwprintf_test14 -c_runtime/_snwprintf/test15/paltest_snwprintf_test15 -c_runtime/_snwprintf/test16/paltest_snwprintf_test16 -c_runtime/_snwprintf/test17/paltest_snwprintf_test17 -c_runtime/_snwprintf/test18/paltest_snwprintf_test18 -c_runtime/_snwprintf/test19/paltest_snwprintf_test19 -c_runtime/_snwprintf/test3/paltest_snwprintf_test3 -c_runtime/_snwprintf/test4/paltest_snwprintf_test4 -c_runtime/_snwprintf/test5/paltest_snwprintf_test5 -c_runtime/_snwprintf/test6/paltest_snwprintf_test6 -c_runtime/_snwprintf/test8/paltest_snwprintf_test8 -c_runtime/_snwprintf/test9/paltest_snwprintf_test9 -c_runtime/_splitpath/test1/paltest_splitpath_test1 +c_runtime/_snprintf_s/test1/paltest_snprintf_test1 +c_runtime/_snprintf_s/test10/paltest_snprintf_test10 +c_runtime/_snprintf_s/test11/paltest_snprintf_test11 +c_runtime/_snprintf_s/test12/paltest_snprintf_test12 +c_runtime/_snprintf_s/test13/paltest_snprintf_test13 +c_runtime/_snprintf_s/test14/paltest_snprintf_test14 +c_runtime/_snprintf_s/test15/paltest_snprintf_test15 +c_runtime/_snprintf_s/test16/paltest_snprintf_test16 +c_runtime/_snprintf_s/test17/paltest_snprintf_test17 +c_runtime/_snprintf_s/test18/paltest_snprintf_test18 +c_runtime/_snprintf_s/test19/paltest_snprintf_test19 +c_runtime/_snprintf_s/test2/paltest_snprintf_test2 +c_runtime/_snprintf_s/test3/paltest_snprintf_test3 +c_runtime/_snprintf_s/test4/paltest_snprintf_test4 +c_runtime/_snprintf_s/test6/paltest_snprintf_test6 +c_runtime/_snprintf_s/test7/paltest_snprintf_test7 +c_runtime/_snprintf_s/test8/paltest_snprintf_test8 +c_runtime/_snprintf_s/test9/paltest_snprintf_test9 +c_runtime/_snwprintf_s/test1/paltest_snwprintf_test1 +c_runtime/_snwprintf_s/test10/paltest_snwprintf_test10 +c_runtime/_snwprintf_s/test11/paltest_snwprintf_test11 +c_runtime/_snwprintf_s/test12/paltest_snwprintf_test12 +c_runtime/_snwprintf_s/test13/paltest_snwprintf_test13 +c_runtime/_snwprintf_s/test14/paltest_snwprintf_test14 +c_runtime/_snwprintf_s/test15/paltest_snwprintf_test15 +c_runtime/_snwprintf_s/test16/paltest_snwprintf_test16 +c_runtime/_snwprintf_s/test17/paltest_snwprintf_test17 +c_runtime/_snwprintf_s/test18/paltest_snwprintf_test18 +c_runtime/_snwprintf_s/test19/paltest_snwprintf_test19 +c_runtime/_snwprintf_s/test3/paltest_snwprintf_test3 +c_runtime/_snwprintf_s/test4/paltest_snwprintf_test4 +c_runtime/_snwprintf_s/test6/paltest_snwprintf_test6 +c_runtime/_snwprintf_s/test8/paltest_snwprintf_test8 +c_runtime/_snwprintf_s/test9/paltest_snwprintf_test9 c_runtime/_stricmp/test1/paltest_stricmp_test1 c_runtime/_strlwr/test1/paltest_strlwr_test1 c_runtime/_strnicmp/test1/paltest_strnicmp_test1 -c_runtime/_swab/test1/paltest_swab_test1 c_runtime/_vsnprintf/test1/paltest_vsnprintf_test1 c_runtime/_vsnprintf/test10/paltest_vsnprintf_test10 c_runtime/_vsnprintf/test11/paltest_vsnprintf_test11 @@ -405,23 +417,22 @@ c_runtime/_vsnprintf/test6/paltest_vsnprintf_test6 c_runtime/_vsnprintf/test7/paltest_vsnprintf_test7 c_runtime/_vsnprintf/test8/paltest_vsnprintf_test8 c_runtime/_vsnprintf/test9/paltest_vsnprintf_test9 -c_runtime/_vsnwprintf/test1/paltest_vsnwprintf_test1 -c_runtime/_vsnwprintf/test10/paltest_vsnwprintf_test10 -c_runtime/_vsnwprintf/test11/paltest_vsnwprintf_test11 -c_runtime/_vsnwprintf/test12/paltest_vsnwprintf_test12 -c_runtime/_vsnwprintf/test13/paltest_vsnwprintf_test13 -c_runtime/_vsnwprintf/test14/paltest_vsnwprintf_test14 -c_runtime/_vsnwprintf/test15/paltest_vsnwprintf_test15 -c_runtime/_vsnwprintf/test16/paltest_vsnwprintf_test16 -c_runtime/_vsnwprintf/test17/paltest_vsnwprintf_test17 -c_runtime/_vsnwprintf/test18/paltest_vsnwprintf_test18 -c_runtime/_vsnwprintf/test19/paltest_vsnwprintf_test19 -c_runtime/_vsnwprintf/test3/paltest_vsnwprintf_test3 -c_runtime/_vsnwprintf/test4/paltest_vsnwprintf_test4 -c_runtime/_vsnwprintf/test5/paltest_vsnwprintf_test5 -c_runtime/_vsnwprintf/test6/paltest_vsnwprintf_test6 -c_runtime/_vsnwprintf/test8/paltest_vsnwprintf_test8 -c_runtime/_vsnwprintf/test9/paltest_vsnwprintf_test9 +c_runtime/_vsnwprintf_s/test1/paltest_vsnwprintf_test1 +c_runtime/_vsnwprintf_s/test10/paltest_vsnwprintf_test10 +c_runtime/_vsnwprintf_s/test11/paltest_vsnwprintf_test11 +c_runtime/_vsnwprintf_s/test12/paltest_vsnwprintf_test12 +c_runtime/_vsnwprintf_s/test13/paltest_vsnwprintf_test13 +c_runtime/_vsnwprintf_s/test14/paltest_vsnwprintf_test14 +c_runtime/_vsnwprintf_s/test15/paltest_vsnwprintf_test15 +c_runtime/_vsnwprintf_s/test16/paltest_vsnwprintf_test16 +c_runtime/_vsnwprintf_s/test17/paltest_vsnwprintf_test17 +c_runtime/_vsnwprintf_s/test18/paltest_vsnwprintf_test18 +c_runtime/_vsnwprintf_s/test19/paltest_vsnwprintf_test19 +c_runtime/_vsnwprintf_s/test3/paltest_vsnwprintf_test3 +c_runtime/_vsnwprintf_s/test4/paltest_vsnwprintf_test4 +c_runtime/_vsnwprintf_s/test6/paltest_vsnwprintf_test6 +c_runtime/_vsnwprintf_s/test8/paltest_vsnwprintf_test8 +c_runtime/_vsnwprintf_s/test9/paltest_vsnwprintf_test9 c_runtime/_wcsicmp/test1/paltest_wcsicmp_test1 c_runtime/_wcslwr/test1/paltest_wcslwr_test1 c_runtime/_wcsnicmp/test1/paltest_wcsnicmp_test1 @@ -432,7 +443,6 @@ c_runtime/_wfopen/test4/paltest_wfopen_test4 c_runtime/_wfopen/test5/paltest_wfopen_test5 c_runtime/_wfopen/test6/paltest_wfopen_test6 c_runtime/_wfopen/test7/paltest_wfopen_test7 -c_runtime/_wsplitpath/test1/paltest_wsplitpath_test1 c_runtime/_wtoi/test1/paltest_wtoi_test1 c_runtime/__iscsym/test1/paltest_iscsym_test1 debug_api/OutputDebugStringW/test1/paltest_outputdebugstringw_test1 @@ -473,6 +483,8 @@ filemapping_memmgt/MapViewOfFile/test3/paltest_mapviewoffile_test3 filemapping_memmgt/MapViewOfFile/test4/paltest_mapviewoffile_test4 filemapping_memmgt/MapViewOfFile/test5/paltest_mapviewoffile_test5 filemapping_memmgt/MapViewOfFile/test6/paltest_mapviewoffile_test6 +filemapping_memmgt/ProbeMemory/test1/paltest_probememory_test1 +filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/paltest_probememory_probememory_neg1 filemapping_memmgt/RtlMoveMemory/test1/paltest_rtlmovememory_test1 filemapping_memmgt/RtlMoveMemory/test3/paltest_rtlmovememory_test3 filemapping_memmgt/RtlMoveMemory/test4/paltest_rtlmovememory_test4 @@ -678,12 +690,6 @@ miscellaneous/InterlockedIncrement/test1/paltest_interlockedincrement_test1 miscellaneous/InterlockedIncrement/test2/paltest_interlockedincrement_test2 miscellaneous/InterlockedIncrement64/test1/paltest_interlockedincrement64_test1 miscellaneous/InterlockedIncrement64/test2/paltest_interlockedincrement64_test2 -miscellaneous/lstrcatW/test1/paltest_lstrcatw_test1 -miscellaneous/lstrcatW/test2/paltest_lstrcatw_test2 -miscellaneous/lstrcatW/test3/paltest_lstrcatw_test3 -miscellaneous/lstrcatW/test4/paltest_lstrcatw_test4 -miscellaneous/lstrcpynW/test1/paltest_lstrcpynw_test1 -miscellaneous/lstrcpyW/test1/paltest_lstrcpyw_test1 miscellaneous/lstrlenA/test1/paltest_lstrlena_test1 miscellaneous/lstrlenW/test1/paltest_lstrlenw_test1 miscellaneous/queryperformancecounter/test1/paltest_queryperformancecounter_test1 @@ -697,27 +703,7 @@ miscellaneous/SetEnvironmentVariableW/test2/paltest_setenvironmentvariablew_test miscellaneous/SetEnvironmentVariableW/test3/paltest_setenvironmentvariablew_test3 miscellaneous/SetEnvironmentVariableW/test4/paltest_setenvironmentvariablew_test4 miscellaneous/SetLastError/test1/paltest_setlasterror_test1 -miscellaneous/wsprintfA/test1/paltest_wsprintfa_test1 -miscellaneous/wsprintfA/test11/paltest_wsprintfa_test11 -miscellaneous/wsprintfA/test12/paltest_wsprintfa_test12 -miscellaneous/wsprintfA/test13/paltest_wsprintfa_test13 -miscellaneous/wsprintfA/test2/paltest_wsprintfa_test2 -miscellaneous/wsprintfA/test3/paltest_wsprintfa_test3 -miscellaneous/wsprintfA/test6/paltest_wsprintfa_test6 -miscellaneous/wsprintfA/test7/paltest_wsprintfa_test7 -miscellaneous/wsprintfA/test8/paltest_wsprintfa_test8 -miscellaneous/wsprintfA/test9/paltest_wsprintfa_test9 -miscellaneous/wsprintfW/test1/paltest_wsprintfw_test1 -miscellaneous/wsprintfW/test11/paltest_wsprintfw_test11 -miscellaneous/wsprintfW/test12/paltest_wsprintfw_test12 -miscellaneous/wsprintfW/test13/paltest_wsprintfw_test13 -miscellaneous/wsprintfW/test3/paltest_wsprintfw_test3 -miscellaneous/wsprintfW/test6/paltest_wsprintfw_test6 -miscellaneous/wsprintfW/test8/paltest_wsprintfw_test8 -miscellaneous/wsprintfW/test9/paltest_wsprintfw_test9 miscellaneous/_i64tow/test1/paltest_i64tow_test1 -miscellaneous/_ui64tow/test1/paltest_ui64tow_test1 -miscellaneous/_ui64tow/test2/paltest_ui64tow_test2 pal_specific/pal_entrypoint/test1/paltest_pal_entrypoint_test1 pal_specific/PAL_errno/test1/paltest_pal_errno_test1 pal_specific/pal_initializedebug/test1/paltest_pal_initializedebug_test1 diff --git a/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt b/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt index ac0a2ee4eb..0e12ccbf55 100644 --- a/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt +++ b/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt @@ -26,11 +26,10 @@ c_runtime/_ecvt/test1/paltest_ecvt_test1 c_runtime/_gcvt/test1/paltest_gcvt_test1 c_runtime/_gcvt/test2/paltest_gcvt_test2 c_runtime/_getw/test1/paltest_getw_test1 -c_runtime/_snwprintf/test2/paltest_snwprintf_test2 -c_runtime/_snwprintf/test7/paltest_snwprintf_test7 -c_runtime/_vsnwprintf/test2/paltest_vsnwprintf_test2 -c_runtime/_vsnwprintf/test7/paltest_vsnwprintf_test7 -c_runtime/_wmakepath/test1/paltest_wmakepath_test1 +c_runtime/_snwprintf_s/test2/paltest_snwprintf_test2 +c_runtime/_snwprintf_s/test7/paltest_snwprintf_test7 +c_runtime/_vsnwprintf_s/test2/paltest_vsnwprintf_test2 +c_runtime/_vsnwprintf_s/test7/paltest_vsnwprintf_test7 debug_api/DebugBreak/test1/paltest_debugbreak_test1 debug_api/OutputDebugStringA/test1/paltest_outputdebugstringa_test1 debug_api/WriteProcessMemory/test1/paltest_writeprocessmemory_test1 diff --git a/src/pal/tests/palsuite/palverify.dat b/src/pal/tests/palsuite/palverify.dat index 36b48d66e8..d6e113b670 100644 --- a/src/pal/tests/palsuite/palverify.dat +++ b/src/pal/tests/palsuite/palverify.dat @@ -7,16 +7,16 @@ c_runtime/_alloca/test1,1 c_runtime/_ecvt/test1,1 c_runtime/_fdopen/test1,1 c_runtime/_finite/test1,1 +c_runtime/_finitef/test1,1 c_runtime/_fullpath/test1,1 c_runtime/_gcvt/test1,1 c_runtime/_gcvt/test2,1 c_runtime/_getw/test1,1 c_runtime/_isnan/test1,1 +c_runtime/_isnanf/test1,1 c_runtime/_itow/test1,1 -c_runtime/_makepath/test1,1 c_runtime/_mbsdec/test1,1 c_runtime/_mbsinc/test1,1 -c_runtime/_mbslen/test1,1 c_runtime/_mbsninc/test1,1 c_runtime/_open_osfhandle/test1,1 c_runtime/_open_osfhandle/test2,1 @@ -27,49 +27,45 @@ c_runtime/_putenv/test4,1 c_runtime/_putw/test1,1 c_runtime/_rotl/test1,1 c_runtime/_rotr/test1,1 -c_runtime/_snprintf/test1,1 -c_runtime/_snprintf/test2,1 -c_runtime/_snprintf/test3,1 -c_runtime/_snprintf/test4,1 -c_runtime/_snprintf/test5,1 -c_runtime/_snprintf/test6,1 -c_runtime/_snprintf/test7,1 -c_runtime/_snprintf/test8,1 -c_runtime/_snprintf/test9,1 -c_runtime/_snprintf/test10,1 -c_runtime/_snprintf/test11,1 -c_runtime/_snprintf/test12,1 -c_runtime/_snprintf/test13,1 -c_runtime/_snprintf/test14,1 -c_runtime/_snprintf/test15,1 -c_runtime/_snprintf/test16,1 -c_runtime/_snprintf/test17,1 -c_runtime/_snprintf/test18,1 -c_runtime/_snprintf/test19,1 -c_runtime/_snwprintf/test1,1 -c_runtime/_snwprintf/test2,1 -c_runtime/_snwprintf/test3,1 -c_runtime/_snwprintf/test4,1 -c_runtime/_snwprintf/test5,1 -c_runtime/_snwprintf/test6,1 -c_runtime/_snwprintf/test7,1 -c_runtime/_snwprintf/test8,1 -c_runtime/_snwprintf/test9,1 -c_runtime/_snwprintf/test10,1 -c_runtime/_snwprintf/test11,1 -c_runtime/_snwprintf/test12,1 -c_runtime/_snwprintf/test13,1 -c_runtime/_snwprintf/test14,1 -c_runtime/_snwprintf/test15,1 -c_runtime/_snwprintf/test16,1 -c_runtime/_snwprintf/test17,1 -c_runtime/_snwprintf/test18,1 -c_runtime/_snwprintf/test19,1 -c_runtime/_splitpath/test1,1 +c_runtime/_snprintf_s/test1,1 +c_runtime/_snprintf_s/test2,1 +c_runtime/_snprintf_s/test3,1 +c_runtime/_snprintf_s/test4,1 +c_runtime/_snprintf_s/test6,1 +c_runtime/_snprintf_s/test7,1 +c_runtime/_snprintf_s/test8,1 +c_runtime/_snprintf_s/test9,1 +c_runtime/_snprintf_s/test10,1 +c_runtime/_snprintf_s/test11,1 +c_runtime/_snprintf_s/test12,1 +c_runtime/_snprintf_s/test13,1 +c_runtime/_snprintf_s/test14,1 +c_runtime/_snprintf_s/test15,1 +c_runtime/_snprintf_s/test16,1 +c_runtime/_snprintf_s/test17,1 +c_runtime/_snprintf_s/test18,1 +c_runtime/_snprintf_s/test19,1 +c_runtime/_snwprintf_s/test1,1 +c_runtime/_snwprintf_s/test2,1 +c_runtime/_snwprintf_s/test3,1 +c_runtime/_snwprintf_s/test4,1 +c_runtime/_snwprintf_s/test6,1 +c_runtime/_snwprintf_s/test7,1 +c_runtime/_snwprintf_s/test8,1 +c_runtime/_snwprintf_s/test9,1 +c_runtime/_snwprintf_s/test10,1 +c_runtime/_snwprintf_s/test11,1 +c_runtime/_snwprintf_s/test12,1 +c_runtime/_snwprintf_s/test13,1 +c_runtime/_snwprintf_s/test14,1 +c_runtime/_snwprintf_s/test15,1 +c_runtime/_snwprintf_s/test16,1 +c_runtime/_snwprintf_s/test17,1 +c_runtime/_snwprintf_s/test18,1 +c_runtime/_snwprintf_s/test19,1 c_runtime/_stricmp/test1,1 c_runtime/_strlwr/test1,1 c_runtime/_strnicmp/test1,1 -c_runtime/_swab/test1,1 c_runtime/_vsnprintf/test1,1 c_runtime/_vsnprintf/test2,1 c_runtime/_vsnprintf/test3,1 @@ -89,25 +85,25 @@ c_runtime/_vsnprintf/test16,1 c_runtime/_vsnprintf/test17,1 c_runtime/_vsnprintf/test18,1 c_runtime/_vsnprintf/test19,1 -c_runtime/_vsnwprintf/test1,1 -c_runtime/_vsnwprintf/test2,1 -c_runtime/_vsnwprintf/test3,1 -c_runtime/_vsnwprintf/test4,1 -c_runtime/_vsnwprintf/test5,1 -c_runtime/_vsnwprintf/test6,1 -c_runtime/_vsnwprintf/test7,1 -c_runtime/_vsnwprintf/test8,1 -c_runtime/_vsnwprintf/test9,1 -c_runtime/_vsnwprintf/test10,1 -c_runtime/_vsnwprintf/test11,1 -c_runtime/_vsnwprintf/test12,1 -c_runtime/_vsnwprintf/test13,1 -c_runtime/_vsnwprintf/test14,1 -c_runtime/_vsnwprintf/test15,1 -c_runtime/_vsnwprintf/test16,1 -c_runtime/_vsnwprintf/test17,1 -c_runtime/_vsnwprintf/test18,1 -c_runtime/_vsnwprintf/test19,1 +c_runtime/_vsnwprintf_s/test1,1 +c_runtime/_vsnwprintf_s/test2,1 +c_runtime/_vsnwprintf_s/test3,1 +c_runtime/_vsnwprintf_s/test4,1 +c_runtime/_vsnwprintf_s/test5,1 +c_runtime/_vsnwprintf_s/test6,1 +c_runtime/_vsnwprintf_s/test7,1 +c_runtime/_vsnwprintf_s/test8,1 +c_runtime/_vsnwprintf_s/test9,1 +c_runtime/_vsnwprintf_s/test10,1 +c_runtime/_vsnwprintf_s/test11,1 +c_runtime/_vsnwprintf_s/test12,1 +c_runtime/_vsnwprintf_s/test13,1 +c_runtime/_vsnwprintf_s/test14,1 +c_runtime/_vsnwprintf_s/test15,1 +c_runtime/_vsnwprintf_s/test16,1 +c_runtime/_vsnwprintf_s/test17,1 +c_runtime/_vsnwprintf_s/test18,1 +c_runtime/_vsnwprintf_s/test19,1 c_runtime/_wcsicmp/test1,1 c_runtime/_wcslwr/test1,1 c_runtime/_wcsnicmp/test1,1 @@ -118,27 +114,33 @@ c_runtime/_wfopen/test4,1 c_runtime/_wfopen/test5,1 c_runtime/_wfopen/test6,1 c_runtime/_wfopen/test7,1 -c_runtime/_wmakepath/test1,1 -c_runtime/_wsplitpath/test1,1 c_runtime/_wtoi/test1,1 c_runtime/abs/test1,1 c_runtime/acos/test1,1 +c_runtime/acosf/test1,1 c_runtime/asin/test1,1 +c_runtime/asinf/test1,1 c_runtime/atan/test1,1 c_runtime/atan2/test1,1 +c_runtime/atan2f/test1,1 +c_runtime/atanf/test1,1 c_runtime/atof/test1,1 c_runtime/atoi/test1,1 c_runtime/atol/test1,1 c_runtime/bsearch/test1,1 c_runtime/bsearch/test2,1 c_runtime/ceil/test1,1 +c_runtime/ceilf/test1,1 c_runtime/cos/test1,1 +c_runtime/cosf/test1,1 c_runtime/cosh/test1,1 +c_runtime/coshf/test1,1 c_runtime/ctime/test1,1 c_runtime/errno/test1,1 c_runtime/errno/test2,1 c_runtime/exit/test1,1 c_runtime/exp/test1,1 +c_runtime/expf/test1,1 c_runtime/fabs/test1,1 c_runtime/fabsf/test1,1 c_runtime/fclose/test1,1 @@ -151,6 +153,7 @@ c_runtime/fgets/test1,1 c_runtime/fgets/test2,1 c_runtime/fgets/test3,1 c_runtime/floor/test1,1 +c_runtime/floorf/test1,1 c_runtime/fmod/test1,1 c_runtime/fmodf/test1,1 c_runtime/fopen/test1,1 @@ -230,6 +233,8 @@ c_runtime/llabs/test1,1 c_runtime/localtime/test1,1 c_runtime/log/test1,1 c_runtime/log10/test1,1 +c_runtime/log10f/test1,1 +c_runtime/logf/test1,1 c_runtime/malloc/test1,1 c_runtime/memchr/test1,1 c_runtime/memcmp/test1,1 @@ -238,6 +243,7 @@ c_runtime/memmove/test1,1 c_runtime/memset/test1,1 c_runtime/modf/test1,1 c_runtime/pow/test1,1 +c_runtime/powf/test1,1 c_runtime/printf/test1,1 c_runtime/printf/test2,1 c_runtime/printf/test3,1 @@ -262,44 +268,46 @@ c_runtime/qsort/test2,1 c_runtime/rand_srand/test1,1 c_runtime/realloc/test1,1 c_runtime/sin/test1,1 +c_runtime/sinf/test1,1 c_runtime/sinh/test1,1 -c_runtime/sprintf/test1,1 -c_runtime/sprintf/test2,1 -c_runtime/sprintf/test3,1 -c_runtime/sprintf/test4,1 -c_runtime/sprintf/test5,1 -c_runtime/sprintf/test6,1 -c_runtime/sprintf/test7,1 -c_runtime/sprintf/test8,1 -c_runtime/sprintf/test9,1 -c_runtime/sprintf/test10,1 -c_runtime/sprintf/test11,1 -c_runtime/sprintf/test12,1 -c_runtime/sprintf/test13,1 -c_runtime/sprintf/test14,1 -c_runtime/sprintf/test15,1 -c_runtime/sprintf/test16,1 -c_runtime/sprintf/test17,1 -c_runtime/sprintf/test18,1 -c_runtime/sprintf/test19,1 +c_runtime/sinhf/test1,1 +c_runtime/sprintf_s/test1,1 +c_runtime/sprintf_s/test2,1 +c_runtime/sprintf_s/test3,1 +c_runtime/sprintf_s/test4,1 +c_runtime/sprintf_s/test6,1 +c_runtime/sprintf_s/test7,1 +c_runtime/sprintf_s/test8,1 +c_runtime/sprintf_s/test9,1 +c_runtime/sprintf_s/test10,1 +c_runtime/sprintf_s/test11,1 +c_runtime/sprintf_s/test12,1 +c_runtime/sprintf_s/test13,1 +c_runtime/sprintf_s/test14,1 +c_runtime/sprintf_s/test15,1 +c_runtime/sprintf_s/test16,1 +c_runtime/sprintf_s/test17,1 +c_runtime/sprintf_s/test18,1 +c_runtime/sprintf_s/test19,1 c_runtime/sqrt/test1,1 -c_runtime/sscanf/test1,1 -c_runtime/sscanf/test2,1 -c_runtime/sscanf/test3,1 -c_runtime/sscanf/test4,1 -c_runtime/sscanf/test5,1 -c_runtime/sscanf/test6,1 -c_runtime/sscanf/test7,1 -c_runtime/sscanf/test8,1 -c_runtime/sscanf/test9,1 -c_runtime/sscanf/test10,1 -c_runtime/sscanf/test11,1 -c_runtime/sscanf/test12,1 -c_runtime/sscanf/test13,1 -c_runtime/sscanf/test14,1 -c_runtime/sscanf/test15,1 -c_runtime/sscanf/test16,1 -c_runtime/sscanf/test17,1 +c_runtime/sqrtf/test1,1 +c_runtime/sscanf_s/test1,1 +c_runtime/sscanf_s/test2,1 +c_runtime/sscanf_s/test3,1 +c_runtime/sscanf_s/test4,1 +c_runtime/sscanf_s/test5,1 +c_runtime/sscanf_s/test6,1 +c_runtime/sscanf_s/test7,1 +c_runtime/sscanf_s/test8,1 +c_runtime/sscanf_s/test9,1 +c_runtime/sscanf_s/test10,1 +c_runtime/sscanf_s/test11,1 +c_runtime/sscanf_s/test12,1 +c_runtime/sscanf_s/test13,1 +c_runtime/sscanf_s/test14,1 +c_runtime/sscanf_s/test15,1 +c_runtime/sscanf_s/test16,1 +c_runtime/sscanf_s/test17,1 c_runtime/strcat/test1,1 c_runtime/strchr/test1,1 c_runtime/strcmp/test1,1 @@ -354,7 +362,9 @@ c_runtime/swscanf/test15,1 c_runtime/swscanf/test16,1 c_runtime/swscanf/test17,1 c_runtime/tan/test1,1 +c_runtime/tanf/test1,1 c_runtime/tanh/test1,1 +c_runtime/tanhf/test1,1 c_runtime/time/test1,1 c_runtime/tolower/test1,1 c_runtime/toupper/test1,1 @@ -715,8 +725,6 @@ locale_info/widechartomultibyte/test1,1 locale_info/widechartomultibyte/test2,1 locale_info/widechartomultibyte/test3,1 miscellaneous/_i64tow/test1,1 -miscellaneous/_ui64tow/test1,1 -miscellaneous/_ui64tow/test2,1 miscellaneous/charnexta/test1,1 miscellaneous/charnexta/test2,1 miscellaneous/charnextexa/test1,1 diff --git a/src/pal/tests/palsuite/samples/test1/CMakeLists.txt b/src/pal/tests/palsuite/samples/test1/CMakeLists.txt index da5892cfa6..42f2ebdcdd 100644 --- a/src/pal/tests/palsuite/samples/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/samples/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_samples_test1 diff --git a/src/pal/tests/palsuite/samples/test1/test.c b/src/pal/tests/palsuite/samples/test1/test.c deleted file mode 100644 index 2eed6f6f44..0000000000 --- a/src/pal/tests/palsuite/samples/test1/test.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: This test is an example of the basic structure of a PAL test -** suite test case. -** -** -**==========================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - /* Initialize the PAL. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - Trace("\nTest #1...\n"); - -#ifdef WIN32 - Trace("\nWe are testing under Win32 environment.\n"); -#else - Trace("\nWe are testing under Non-Win32 environment.\n"); -#endif - - Trace("\nThis test has passed.\n"); - - /* Shutdown the PAL. - */ - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/samples/test1/test.cpp b/src/pal/tests/palsuite/samples/test1/test.cpp new file mode 100644 index 0000000000..2eed6f6f44 --- /dev/null +++ b/src/pal/tests/palsuite/samples/test1/test.cpp @@ -0,0 +1,41 @@ +// 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: This test is an example of the basic structure of a PAL test +** suite test case. +** +** +**==========================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + /* Initialize the PAL. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + Trace("\nTest #1...\n"); + +#ifdef WIN32 + Trace("\nWe are testing under Win32 environment.\n"); +#else + Trace("\nWe are testing under Non-Win32 environment.\n"); +#endif + + Trace("\nThis test has passed.\n"); + + /* Shutdown the PAL. + */ + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/samples/test2/CMakeLists.txt b/src/pal/tests/palsuite/samples/test2/CMakeLists.txt index fdef2aac6b..1a7ce2918e 100644 --- a/src/pal/tests/palsuite/samples/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/samples/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_samples_test2 diff --git a/src/pal/tests/palsuite/samples/test2/test.c b/src/pal/tests/palsuite/samples/test2/test.c deleted file mode 100644 index 53d4158b9d..0000000000 --- a/src/pal/tests/palsuite/samples/test2/test.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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: A sample to show how to structure a test case. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - int exampleInt = 9; - - /* Initialize the PAL. - */ - if(0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - Trace("\nTest #2...\n"); - -#ifdef WIN32 - Trace("\nWe are testing under Win32 environment.\n"); -#else - Trace("\nWe are testing under Non-Win32 environment.\n"); -#endif - - if (exampleInt == 9) - { - Fail("This is an example to how to code a failure. " - "This failure was caused by exampleInt equalling %d\n", - exampleInt); - } - - /* Shutdown the PAL. - */ - PAL_Terminate(); - - return PASS; -} diff --git a/src/pal/tests/palsuite/samples/test2/test.cpp b/src/pal/tests/palsuite/samples/test2/test.cpp new file mode 100644 index 0000000000..53d4158b9d --- /dev/null +++ b/src/pal/tests/palsuite/samples/test2/test.cpp @@ -0,0 +1,48 @@ +// 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: A sample to show how to structure a test case. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + int exampleInt = 9; + + /* Initialize the PAL. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + Trace("\nTest #2...\n"); + +#ifdef WIN32 + Trace("\nWe are testing under Win32 environment.\n"); +#else + Trace("\nWe are testing under Non-Win32 environment.\n"); +#endif + + if (exampleInt == 9) + { + Fail("This is an example to how to code a failure. " + "This failure was caused by exampleInt equalling %d\n", + exampleInt); + } + + /* Shutdown the PAL. + */ + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventA/test1/CMakeLists.txt index da1232eea4..7be9481150 100644 --- a/src/pal/tests/palsuite/threading/CreateEventA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateEventA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_createeventa_test1 diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test1/test1.c b/src/pal/tests/palsuite/threading/CreateEventA/test1/test1.c deleted file mode 100644 index d8ef0f58a3..0000000000 --- a/src/pal/tests/palsuite/threading/CreateEventA/test1/test1.c +++ /dev/null @@ -1,95 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for CreateEvent. Create an event, ensure the -** HANDLE is valid. Then check to ensure that the object is in the -** signaled state. Close the HANDLE and done. -** -** -**=========================================================*/ - -/* - Note: From the rotor_pal documentation: - - lpEventAttributes will always be NULL, bManualReset can be either - TRUE or FALSE, bInitialState can be either TRUE or FALSE, the lpName - may be non-NULL - -*/ - - -#include - -BOOL CreateEventTest() -{ - BOOL bRet = FALSE; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = TRUE; - - /* Call CreateEvent, and check to ensure the returned HANDLE is a - valid event HANDLE - */ - - HANDLE hEvent = CreateEvent( lpEventAttributes, - bManualReset, - bInitialState, - NULL); - - if (hEvent != NULL) - { - /* Wait for the Object (for 0 time) and ensure that it returns - the value indicating that the event is signaled. - */ - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("CreateEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); - } - else - { - /* If we make it here, and CloseHandle succeeds, then the - entire test has passed. Otherwise bRet will still show - failure - */ - bRet = CloseHandle(hEvent); - - if (!bRet) - { - Trace("CreateEventTest:CloseHandle failed (%x)\n", GetLastError()); - } - } - } - else - { - Trace("CreateEventTest:CreateEvent failed (%x)\n", GetLastError()); - } - - return bRet; -} - -int __cdecl main(int argc, char **argv) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!CreateEventTest()) - { - Fail ("Test failed\n"); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test1/test1.cpp b/src/pal/tests/palsuite/threading/CreateEventA/test1/test1.cpp new file mode 100644 index 0000000000..d8ef0f58a3 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test1/test1.cpp @@ -0,0 +1,95 @@ +// 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: test1.c +** +** Purpose: Test for CreateEvent. Create an event, ensure the +** HANDLE is valid. Then check to ensure that the object is in the +** signaled state. Close the HANDLE and done. +** +** +**=========================================================*/ + +/* + Note: From the rotor_pal documentation: + + lpEventAttributes will always be NULL, bManualReset can be either + TRUE or FALSE, bInitialState can be either TRUE or FALSE, the lpName + may be non-NULL + +*/ + + +#include + +BOOL CreateEventTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = TRUE; + + /* Call CreateEvent, and check to ensure the returned HANDLE is a + valid event HANDLE + */ + + HANDLE hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL); + + if (hEvent != NULL) + { + /* Wait for the Object (for 0 time) and ensure that it returns + the value indicating that the event is signaled. + */ + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("CreateEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + /* If we make it here, and CloseHandle succeeds, then the + entire test has passed. Otherwise bRet will still show + failure + */ + bRet = CloseHandle(hEvent); + + if (!bRet) + { + Trace("CreateEventTest:CloseHandle failed (%x)\n", GetLastError()); + } + } + } + else + { + Trace("CreateEventTest:CreateEvent failed (%x)\n", GetLastError()); + } + + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!CreateEventTest()) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventA/test2/CMakeLists.txt index f87e5bea87..9725c89721 100644 --- a/src/pal/tests/palsuite/threading/CreateEventA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateEventA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_createeventa_test2 diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test2/test2.c b/src/pal/tests/palsuite/threading/CreateEventA/test2/test2.c deleted file mode 100644 index a24d20eeea..0000000000 --- a/src/pal/tests/palsuite/threading/CreateEventA/test2/test2.c +++ /dev/null @@ -1,84 +0,0 @@ -// 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: test2.c -** -** Purpose: Test for CreateEvent. Create the event with the -** initial state being not signaled. Check to ensure that it -** times out when the event is triggered. -** -** -**=========================================================*/ - -#include - -BOOL CreateEventTest() -{ - BOOL bRet = FALSE; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpEventAttributes = 0; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - - /* Create an event with the Initial State set to FALSE */ - - HANDLE hEvent = CreateEvent( lpEventAttributes, - bManualReset, - bInitialState, - NULL); - - if (hEvent != NULL) - { - /* This should ensure that the object is reset, or - non-signaled. - */ - - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_TIMEOUT) - { - Trace("CloseEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); - } - else - { - /* At this point, we've tested the function with success. - So long as the HANDLE can be closed, this test should - pass. - */ - - bRet = CloseHandle(hEvent); - - if (!bRet) - { - Trace("CloseEventTest:CloseHandle failed (%x)\n", GetLastError()); - } - } - } - else - { - Trace("CloseEventTest:CreateEvent failed (%x)\n", GetLastError()); - } - - return bRet; -} - -int __cdecl main(int argc, char **argv) -{ - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!CreateEventTest()) - { - Fail ("Test failed\n"); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test2/test2.cpp b/src/pal/tests/palsuite/threading/CreateEventA/test2/test2.cpp new file mode 100644 index 0000000000..a24d20eeea --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test2/test2.cpp @@ -0,0 +1,84 @@ +// 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: test2.c +** +** Purpose: Test for CreateEvent. Create the event with the +** initial state being not signaled. Check to ensure that it +** times out when the event is triggered. +** +** +**=========================================================*/ + +#include + +BOOL CreateEventTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = 0; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + /* Create an event with the Initial State set to FALSE */ + + HANDLE hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL); + + if (hEvent != NULL) + { + /* This should ensure that the object is reset, or + non-signaled. + */ + + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("CloseEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + /* At this point, we've tested the function with success. + So long as the HANDLE can be closed, this test should + pass. + */ + + bRet = CloseHandle(hEvent); + + if (!bRet) + { + Trace("CloseEventTest:CloseHandle failed (%x)\n", GetLastError()); + } + } + } + else + { + Trace("CloseEventTest:CreateEvent failed (%x)\n", GetLastError()); + } + + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!CreateEventTest()) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventA/test3/CMakeLists.txt index e33c404a79..b596a881d5 100644 --- a/src/pal/tests/palsuite/threading/CreateEventA/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateEventA/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_createeventa_test3 diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test3/test3.c b/src/pal/tests/palsuite/threading/CreateEventA/test3/test3.c deleted file mode 100644 index 56d107b22d..0000000000 --- a/src/pal/tests/palsuite/threading/CreateEventA/test3/test3.c +++ /dev/null @@ -1,219 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests for CreateEventA. Create an event with an empty name, -** create an event with the same name as an already created event -** object. -** -** -**=========================================================*/ - -#include - -#define SWAPPTR ((VOID *)(-1)) - -struct testCase -{ - LPSECURITY_ATTRIBUTES lpEventAttributes; - BOOL bManualReset; - BOOL bInitialState; - char lpName[MAX_PATH + 2]; - DWORD dwNameLen; - DWORD lastError; - BOOL bResult; -}; - -struct testCase testCases[]= -{ - {0, TRUE, FALSE, "", 0, ERROR_SUCCESS, PASS}, - {0, TRUE, FALSE, "", 5, ERROR_SUCCESS, PASS}, - {0, TRUE, FALSE, "", 5, ERROR_ALREADY_EXISTS, PASS}, - {0, TRUE, FALSE, "", 6, ERROR_INVALID_HANDLE, PASS}, - {0, TRUE, FALSE, "", MAX_PATH - 1 - 60, ERROR_SUCCESS, PASS}, - {0, TRUE, FALSE, "", MAX_PATH + 1, ERROR_FILENAME_EXCED_RANGE, PASS} -}; - -static HANDLE hEvent[sizeof(testCases)/sizeof(struct testCase)]; - -DWORD result[sizeof(testCases)/sizeof(struct testCase)]; - -int __cdecl main(int argc, char **argv) -{ - - BOOL bRet = TRUE; - const char *nonEventName = "aaaaaa"; - HANDLE hUnnamedEvent; - HANDLE hFMap; - DWORD dwRet; - int i; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - hUnnamedEvent = CreateEventA(0, TRUE, FALSE, NULL); - - if ( NULL == hUnnamedEvent ) - { - bRet = FALSE; - Trace ( "PALSUITE ERROR: CreateEventA (%d, %d, %d, NULL) call " - "returned NULL.\nGetLastError returned %u.\n", 0, TRUE, FALSE, - GetLastError()); - } - - if (!CloseHandle(hUnnamedEvent)) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CreateEventA: CloseHandle(%lp); call " - "failed\nGetLastError returned '%u'.\n", hUnnamedEvent, - GetLastError()); - } - - /* Create non-event with the same name as one of the testCases */ - hFMap = CreateFileMappingA( SWAPPTR, NULL, PAGE_READONLY, 0, 1, - nonEventName ); - - if ( NULL == hFMap ) - { - bRet = FALSE; - Trace ( "PALSUITE ERROR: CreateFileMapping (%p, %p, %d, %d, %d, %s)" - " call returned NULL.\nGetLastError returned %u.\n", - SWAPPTR, NULL, PAGE_READONLY, 0, 0, nonEventName, - GetLastError()); - goto done; - } - - /* Create Events */ - for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) - { - /* create name */ - memset (testCases[i].lpName, '\0', (MAX_PATH + 2)); - memset (testCases[i].lpName, 'a', testCases[i].dwNameLen ); - - SetLastError(ERROR_SUCCESS); - - hEvent[i] = CreateEventA( testCases[i].lpEventAttributes, - testCases[i].bManualReset, - testCases[i].bInitialState, - testCases[i].lpName); - - if (hEvent[i] != INVALID_HANDLE_VALUE) - { - DWORD dwError = GetLastError(); - - if (dwError != testCases[i].lastError) - { - bRet = FALSE; - Trace ("PALSUITE ERROR:\nCreateEventA(%lp, %d, %d, %s)" - "\nGetLastError returned '%u', it should have returned" - "'%d' at index '%d'.\n", testCases[i].lpEventAttributes, - testCases[i].bManualReset, testCases[i].bInitialState, - testCases[i].lpName, dwError, - testCases[i].lastError, i); - } - if ( ERROR_FILENAME_EXCED_RANGE == testCases[i].lastError ) - { - result [i] = 1; - } - if ( ERROR_INVALID_HANDLE == testCases[i].lastError ) - { - result [i] = 1; - } - /* - * If we expected the testcase to FAIL and it passed, - * report an error. - */ - if (testCases[i].bResult == FAIL) - { - bRet = FALSE; - Trace ("PALSUITE ERROR:\nCreateEventA(%lp, %d, %d, %s)" - "\nShould have returned INVALID_HANDLE_VALUE but " - "didn't at index '%d'.\n", - testCases[i].lpEventAttributes, - testCases[i].bManualReset, - testCases[i].bInitialState, - testCases[i].lpName, i); - } - /* - * If result hasn't been set already set it to 0 so all the - * resources will be freed. - */ - if (!result[i] ) - { - result[i] = 0; - } - } - else - { - /* - * If we get an INVALID_HANDLE_VALUE and we expected the - * test case to pass, report an error. - */ - result[i] = 1; - - if (testCases[i].bResult == PASS) - { - bRet = FALSE; - Trace ("PALSUITE ERROR:\nCreateEventA(%lp, %d, %d, %s);" - "\nReturned INVALID_HANDLE_VALUE at index '%d'.\n", - testCases[i].lpEventAttributes, - testCases[i].bManualReset, testCases[i].bInitialState, - testCases[i].lpName, i); - } - } - } - - /* cleanup */ - for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) - { - if (result[i]) - { - continue; - } - dwRet = WaitForSingleObject ( hEvent[i], 0 ); - - if (dwRet != WAIT_TIMEOUT) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CreateEventA:\nWaitForSingleObject (%lp, " - "%d) call failed at index %d .\nGetLastError returned " - "'%u'.\n", hEvent[i], 0, i, GetLastError()); - } - - if (!CloseHandle(hEvent[i])) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CreateEventA: CloseHandle(%lp) call " - "failed at index %d\nGetLastError returned '%u'.\n", - hEvent[i], i, GetLastError()); - } - } - -done: - if (!CloseHandle(hFMap)) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CreateEventW: CloseHandle(%p) call " - "failed\nGetLastError returned '%u'.\n", hFMap, - GetLastError()); - } - - if (FALSE == bRet) - { - bRet = FAIL; - } - else - { - bRet = PASS; - } - - PAL_TerminateEx(bRet); - - return(bRet); -} diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test3/test3.cpp b/src/pal/tests/palsuite/threading/CreateEventA/test3/test3.cpp new file mode 100644 index 0000000000..56d107b22d --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test3/test3.cpp @@ -0,0 +1,219 @@ +// 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: test3.c +** +** Purpose: Tests for CreateEventA. Create an event with an empty name, +** create an event with the same name as an already created event +** object. +** +** +**=========================================================*/ + +#include + +#define SWAPPTR ((VOID *)(-1)) + +struct testCase +{ + LPSECURITY_ATTRIBUTES lpEventAttributes; + BOOL bManualReset; + BOOL bInitialState; + char lpName[MAX_PATH + 2]; + DWORD dwNameLen; + DWORD lastError; + BOOL bResult; +}; + +struct testCase testCases[]= +{ + {0, TRUE, FALSE, "", 0, ERROR_SUCCESS, PASS}, + {0, TRUE, FALSE, "", 5, ERROR_SUCCESS, PASS}, + {0, TRUE, FALSE, "", 5, ERROR_ALREADY_EXISTS, PASS}, + {0, TRUE, FALSE, "", 6, ERROR_INVALID_HANDLE, PASS}, + {0, TRUE, FALSE, "", MAX_PATH - 1 - 60, ERROR_SUCCESS, PASS}, + {0, TRUE, FALSE, "", MAX_PATH + 1, ERROR_FILENAME_EXCED_RANGE, PASS} +}; + +static HANDLE hEvent[sizeof(testCases)/sizeof(struct testCase)]; + +DWORD result[sizeof(testCases)/sizeof(struct testCase)]; + +int __cdecl main(int argc, char **argv) +{ + + BOOL bRet = TRUE; + const char *nonEventName = "aaaaaa"; + HANDLE hUnnamedEvent; + HANDLE hFMap; + DWORD dwRet; + int i; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + hUnnamedEvent = CreateEventA(0, TRUE, FALSE, NULL); + + if ( NULL == hUnnamedEvent ) + { + bRet = FALSE; + Trace ( "PALSUITE ERROR: CreateEventA (%d, %d, %d, NULL) call " + "returned NULL.\nGetLastError returned %u.\n", 0, TRUE, FALSE, + GetLastError()); + } + + if (!CloseHandle(hUnnamedEvent)) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventA: CloseHandle(%lp); call " + "failed\nGetLastError returned '%u'.\n", hUnnamedEvent, + GetLastError()); + } + + /* Create non-event with the same name as one of the testCases */ + hFMap = CreateFileMappingA( SWAPPTR, NULL, PAGE_READONLY, 0, 1, + nonEventName ); + + if ( NULL == hFMap ) + { + bRet = FALSE; + Trace ( "PALSUITE ERROR: CreateFileMapping (%p, %p, %d, %d, %d, %s)" + " call returned NULL.\nGetLastError returned %u.\n", + SWAPPTR, NULL, PAGE_READONLY, 0, 0, nonEventName, + GetLastError()); + goto done; + } + + /* Create Events */ + for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) + { + /* create name */ + memset (testCases[i].lpName, '\0', (MAX_PATH + 2)); + memset (testCases[i].lpName, 'a', testCases[i].dwNameLen ); + + SetLastError(ERROR_SUCCESS); + + hEvent[i] = CreateEventA( testCases[i].lpEventAttributes, + testCases[i].bManualReset, + testCases[i].bInitialState, + testCases[i].lpName); + + if (hEvent[i] != INVALID_HANDLE_VALUE) + { + DWORD dwError = GetLastError(); + + if (dwError != testCases[i].lastError) + { + bRet = FALSE; + Trace ("PALSUITE ERROR:\nCreateEventA(%lp, %d, %d, %s)" + "\nGetLastError returned '%u', it should have returned" + "'%d' at index '%d'.\n", testCases[i].lpEventAttributes, + testCases[i].bManualReset, testCases[i].bInitialState, + testCases[i].lpName, dwError, + testCases[i].lastError, i); + } + if ( ERROR_FILENAME_EXCED_RANGE == testCases[i].lastError ) + { + result [i] = 1; + } + if ( ERROR_INVALID_HANDLE == testCases[i].lastError ) + { + result [i] = 1; + } + /* + * If we expected the testcase to FAIL and it passed, + * report an error. + */ + if (testCases[i].bResult == FAIL) + { + bRet = FALSE; + Trace ("PALSUITE ERROR:\nCreateEventA(%lp, %d, %d, %s)" + "\nShould have returned INVALID_HANDLE_VALUE but " + "didn't at index '%d'.\n", + testCases[i].lpEventAttributes, + testCases[i].bManualReset, + testCases[i].bInitialState, + testCases[i].lpName, i); + } + /* + * If result hasn't been set already set it to 0 so all the + * resources will be freed. + */ + if (!result[i] ) + { + result[i] = 0; + } + } + else + { + /* + * If we get an INVALID_HANDLE_VALUE and we expected the + * test case to pass, report an error. + */ + result[i] = 1; + + if (testCases[i].bResult == PASS) + { + bRet = FALSE; + Trace ("PALSUITE ERROR:\nCreateEventA(%lp, %d, %d, %s);" + "\nReturned INVALID_HANDLE_VALUE at index '%d'.\n", + testCases[i].lpEventAttributes, + testCases[i].bManualReset, testCases[i].bInitialState, + testCases[i].lpName, i); + } + } + } + + /* cleanup */ + for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) + { + if (result[i]) + { + continue; + } + dwRet = WaitForSingleObject ( hEvent[i], 0 ); + + if (dwRet != WAIT_TIMEOUT) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventA:\nWaitForSingleObject (%lp, " + "%d) call failed at index %d .\nGetLastError returned " + "'%u'.\n", hEvent[i], 0, i, GetLastError()); + } + + if (!CloseHandle(hEvent[i])) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventA: CloseHandle(%lp) call " + "failed at index %d\nGetLastError returned '%u'.\n", + hEvent[i], i, GetLastError()); + } + } + +done: + if (!CloseHandle(hFMap)) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventW: CloseHandle(%p) call " + "failed\nGetLastError returned '%u'.\n", hFMap, + GetLastError()); + } + + if (FALSE == bRet) + { + bRet = FAIL; + } + else + { + bRet = PASS; + } + + PAL_TerminateEx(bRet); + + return(bRet); +} diff --git a/src/pal/tests/palsuite/threading/CreateEventW/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventW/test1/CMakeLists.txt index 0e8ba5bc2a..ef18312cda 100644 --- a/src/pal/tests/palsuite/threading/CreateEventW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateEventW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_createeventw_test1 diff --git a/src/pal/tests/palsuite/threading/CreateEventW/test1/test1.c b/src/pal/tests/palsuite/threading/CreateEventW/test1/test1.c deleted file mode 100644 index 8d99e41934..0000000000 --- a/src/pal/tests/palsuite/threading/CreateEventW/test1/test1.c +++ /dev/null @@ -1,93 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for CreateEventW -** -** -**=========================================================*/ - -/* - * Note: From the rotor_pal documentation: lpEventAttributes will - * always be NULL, bManualReset can be either TRUE or FALSE, - * bInitialState can be either TRUE or FALSE, the lpName may be - * non-NULL. -*/ -#define UNICODE -#include - -BOOL CreateEventTest() -{ - BOOL bRet = FALSE; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = TRUE; - - /* - * Call CreateEvent, and check to ensure the returned HANDLE is a - * valid event HANDLE - */ - - HANDLE hEvent = CreateEventW(lpEventAttributes, - bManualReset, - bInitialState, - NULL); - - if (hEvent != NULL) - { - /* - * Wait for the Object (for 0 time) and ensure that it returns - * the value indicating that the event is signaled. - */ - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("CreateEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); - } - else - { - /* - * If we make it here, and CloseHandle succeeds, then the - * entire test has passed. Otherwise bRet will still show - * failure - */ - bRet = CloseHandle(hEvent); - - if (!bRet) - { - Trace("CreateEventTest:CloseHandle failed (%x)\n", GetLastError()); - } - } - } - else - { - Trace("CreateEventTest:CreateEvent failed (%x)\n", GetLastError()); - } - - return bRet; -} - -int __cdecl main(int argc, char **argv) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!CreateEventTest()) - { - Fail ("Test failed\n"); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateEventW/test1/test1.cpp b/src/pal/tests/palsuite/threading/CreateEventW/test1/test1.cpp new file mode 100644 index 0000000000..8d99e41934 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventW/test1/test1.cpp @@ -0,0 +1,93 @@ +// 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: test1.c +** +** Purpose: Test for CreateEventW +** +** +**=========================================================*/ + +/* + * Note: From the rotor_pal documentation: lpEventAttributes will + * always be NULL, bManualReset can be either TRUE or FALSE, + * bInitialState can be either TRUE or FALSE, the lpName may be + * non-NULL. +*/ +#define UNICODE +#include + +BOOL CreateEventTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = TRUE; + + /* + * Call CreateEvent, and check to ensure the returned HANDLE is a + * valid event HANDLE + */ + + HANDLE hEvent = CreateEventW(lpEventAttributes, + bManualReset, + bInitialState, + NULL); + + if (hEvent != NULL) + { + /* + * Wait for the Object (for 0 time) and ensure that it returns + * the value indicating that the event is signaled. + */ + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("CreateEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + /* + * If we make it here, and CloseHandle succeeds, then the + * entire test has passed. Otherwise bRet will still show + * failure + */ + bRet = CloseHandle(hEvent); + + if (!bRet) + { + Trace("CreateEventTest:CloseHandle failed (%x)\n", GetLastError()); + } + } + } + else + { + Trace("CreateEventTest:CreateEvent failed (%x)\n", GetLastError()); + } + + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!CreateEventTest()) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateEventW/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventW/test2/CMakeLists.txt index f624377474..7f9543e0cb 100644 --- a/src/pal/tests/palsuite/threading/CreateEventW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateEventW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_createeventw_test2 diff --git a/src/pal/tests/palsuite/threading/CreateEventW/test2/test2.c b/src/pal/tests/palsuite/threading/CreateEventW/test2/test2.c deleted file mode 100644 index 4df218995a..0000000000 --- a/src/pal/tests/palsuite/threading/CreateEventW/test2/test2.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: test2.c -** -** Purpose: Test for CreateEventW. Create the event with the -** initial state being not signaled. Check to ensure that it -** times out when the event is triggered. -** -** -**=========================================================*/ -#define UNICODE -#include - -BOOL CreateEventTest() -{ - BOOL bRet = FALSE; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpEventAttributes = 0; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - - - /* Create an event with the Initial State set to FALSE */ - - HANDLE hEvent = CreateEventW(lpEventAttributes, - bManualReset, - bInitialState, - NULL); - - if (hEvent != NULL) - { - /* This should ensure that the object is reset, or - non-signaled. - */ - - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_TIMEOUT) - { - Trace("CloseEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); - } - else - { - /* At this point, we've tested the function with success. - So long as the HANDLE can be closed, this test should - pass. - */ - - bRet = CloseHandle(hEvent); - - if (!bRet) - { - Trace("CloseEventTest:CloseHandle failed (%x)\n", GetLastError()); - } - } - } - else - { - Trace("CloseEventTest:CreateEvent failed (%x)\n", GetLastError()); - } - - return bRet; -} - -int __cdecl main(int argc, char **argv) -{ - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!CreateEventTest()) - { - Fail ("Test failed\n"); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateEventW/test2/test2.cpp b/src/pal/tests/palsuite/threading/CreateEventW/test2/test2.cpp new file mode 100644 index 0000000000..4df218995a --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventW/test2/test2.cpp @@ -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: test2.c +** +** Purpose: Test for CreateEventW. Create the event with the +** initial state being not signaled. Check to ensure that it +** times out when the event is triggered. +** +** +**=========================================================*/ +#define UNICODE +#include + +BOOL CreateEventTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = 0; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + + /* Create an event with the Initial State set to FALSE */ + + HANDLE hEvent = CreateEventW(lpEventAttributes, + bManualReset, + bInitialState, + NULL); + + if (hEvent != NULL) + { + /* This should ensure that the object is reset, or + non-signaled. + */ + + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("CloseEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + /* At this point, we've tested the function with success. + So long as the HANDLE can be closed, this test should + pass. + */ + + bRet = CloseHandle(hEvent); + + if (!bRet) + { + Trace("CloseEventTest:CloseHandle failed (%x)\n", GetLastError()); + } + } + } + else + { + Trace("CloseEventTest:CreateEvent failed (%x)\n", GetLastError()); + } + + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!CreateEventTest()) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateEventW/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventW/test3/CMakeLists.txt index 4493ba3872..6778740f7e 100644 --- a/src/pal/tests/palsuite/threading/CreateEventW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateEventW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_createeventw_test3 diff --git a/src/pal/tests/palsuite/threading/CreateEventW/test3/test3.c b/src/pal/tests/palsuite/threading/CreateEventW/test3/test3.c deleted file mode 100644 index 22f0fcfc49..0000000000 --- a/src/pal/tests/palsuite/threading/CreateEventW/test3/test3.c +++ /dev/null @@ -1,233 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests for CreateEvent. Create an unnamed event, create -** an event with an empty name, create an event with a name longer than -** MAX_PATH, MAX_PATH + 1, create an event with a name already taken -** by a non-event object, create an event with a name already taken -** by an event object. -** -** -**=========================================================*/ -#include - -#define SWAPPTR ((VOID *) (-1)) - -struct testCase -{ - LPSECURITY_ATTRIBUTES lpEventAttributes; - BOOL bManualReset; - BOOL bInitialState; - WCHAR lpName[MAX_PATH + 2]; - DWORD dwNameLen; - DWORD lastError; - BOOL bResult; -}; - -struct testCase testCases[]= -{ - {0, TRUE, FALSE, {'\0'}, 0, ERROR_SUCCESS, PASS}, - {0, TRUE, FALSE, {'\0'}, 5, ERROR_SUCCESS, PASS}, - {0, TRUE, FALSE, {'\0'}, 5, ERROR_ALREADY_EXISTS, PASS}, - {0, TRUE, FALSE, {'\0'}, 6, ERROR_INVALID_HANDLE, PASS}, - {0, TRUE, FALSE, {'\0'}, MAX_PATH - 1 - 60, ERROR_SUCCESS, PASS}, - {0, TRUE, FALSE, {'\0'}, MAX_PATH - 60, ERROR_SUCCESS, PASS}, -}; - -static HANDLE hEvent[sizeof(testCases)/sizeof(struct testCase)]; - -DWORD result[sizeof(testCases)/sizeof(struct testCase)]; - -int __cdecl main(int argc, char **argv) -{ - - BOOL bRet = TRUE; - WCHAR nonEventName[] = {'a','a','a','a','a','a','\0'}; - char name[MAX_PATH + 2]; - WCHAR *wName; - HANDLE hFMap = NULL; - HANDLE hUnnamedEvent; - DWORD dwRet; - int i; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - hUnnamedEvent = CreateEventW(0, TRUE, FALSE, NULL); - - if ( NULL == hUnnamedEvent ) - { - bRet = FALSE; - Trace ( "PALSUITE ERROR: CreateEventW (%d, %d, %d, NULL) call " - "returned NULL.\nGetLastError returned %u.\n", 0, TRUE, FALSE, - GetLastError()); - goto done; - } - - if (!CloseHandle(hUnnamedEvent)) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CreateEventW: CloseHandle(%lp); call " - "failed\nGetLastError returned '%u'.\n", hUnnamedEvent, - GetLastError()); - } - - /* Create non-event with the same name as one of the testCases */ - hFMap = CreateFileMappingW( SWAPPTR, NULL, PAGE_READONLY, 0, 1, - nonEventName ); - - if ( NULL == hFMap ) - { - bRet = FALSE; - Trace ( "PALSUITE ERROR: CreateFileMapping (%p, %p, %d, %d, %d, %S)" - " call returned NULL.\nGetLastError returned %u\n", - SWAPPTR, NULL, PAGE_READONLY, 0, 0, nonEventName, - GetLastError()); - } - - /* Create Events */ - for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) - { - /* create name */ - memset (name, '\0', MAX_PATH + 2); - memset (name, 'a', testCases[i].dwNameLen ); - - wName = convert(name); - - wcsncpy(testCases[i].lpName, wName, - testCases[i].dwNameLen); - - free(wName); - - SetLastError(ERROR_SUCCESS); - - hEvent[i] = CreateEventW( testCases[i].lpEventAttributes, - testCases[i].bManualReset, - testCases[i].bInitialState, - testCases[i].lpName); - - if (hEvent[i] != INVALID_HANDLE_VALUE) - { - DWORD dwError = GetLastError(); - - if (dwError != testCases[i].lastError) - { - bRet = FALSE; - Trace ("PALSUITE ERROR:\nCreateEvent(%lp, %d, %d, %S)" - "\nGetLastError returned '%u', it should have returned" - "'%d' at index '%d'.\n", testCases[i].lpEventAttributes, - testCases[i].bManualReset, testCases[i].bInitialState, - testCases[i].lpName, dwError, - testCases[i].lastError, i); - } - if ( ERROR_FILENAME_EXCED_RANGE == testCases[i].lastError ) - { - result [i] = 1; - } - if ( ERROR_INVALID_HANDLE == testCases[i].lastError ) - { - result [i] = 1; - } - /* - * If we expected the testcase to FAIL and it passed, - * report an error. - */ - if (testCases[i].bResult == FAIL) - { - bRet = FALSE; - Trace ("PALSUITE ERROR:\nCreateEvent(%lp, %d, %d, %S)" - "\nShould have returned INVALID_HANDLE_VALUE but " - "didn't at index '%d'.\n", - testCases[i].lpEventAttributes, - testCases[i].bManualReset, - testCases[i].bInitialState, - testCases[i].lpName, i); - } - /* - * If result hasn't been set already set it to 0 so all the - * resources will be freed. - */ - if (!result[i]) - { - result[i] = 0; - } - } - else - { - /* - * If we get an INVALID_HANDLE_VALUE and we expected the - * test case to pass, report an error. - */ - result[i] = 1; - - if (testCases[i].bResult == PASS) - { - bRet = FALSE; - Trace ("PALSUITE ERROR:\nCreateEvent(%lp, %d, %d, %S);" - "\nReturned INVALID_HANDLE_VALUE at index '%d'.\n", - testCases[i].lpEventAttributes, - testCases[i].bManualReset, testCases[i].bInitialState, - testCases[i].lpName, i); - } - } - } - - /* cleanup */ - for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) - { - if (result[i]) - { - continue; - } - dwRet = WaitForSingleObject ( hEvent[i], 0 ); - - if (dwRet != WAIT_TIMEOUT) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CreateEventW:\nWaitForSingleObject (%lp, " - "%d) call failed at index %d .\nGetLastError returned " - "'%u'.\n", hEvent[i], 0, i, GetLastError()); - } - - if (!CloseHandle(hEvent[i])) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CreateEventW: CloseHandle(%lp) call " - "failed at index %d\nGetLastError returned '%u'.\n", - hEvent[i], i, GetLastError()); - } - } - -done: - if (hFMap != NULL && !CloseHandle(hFMap)) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CreateEventW: CloseHandle(%p) call " - "failed\nGetLastError returned '%u'.\n", hFMap, - GetLastError()); - } - - if (FALSE == bRet) - { - bRet = FAIL; - } - else - { - bRet = PASS; - } - - PAL_TerminateEx(bRet); - - return(bRet); - -} - - - diff --git a/src/pal/tests/palsuite/threading/CreateEventW/test3/test3.cpp b/src/pal/tests/palsuite/threading/CreateEventW/test3/test3.cpp new file mode 100644 index 0000000000..22f0fcfc49 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventW/test3/test3.cpp @@ -0,0 +1,233 @@ +// 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: test3.c +** +** Purpose: Tests for CreateEvent. Create an unnamed event, create +** an event with an empty name, create an event with a name longer than +** MAX_PATH, MAX_PATH + 1, create an event with a name already taken +** by a non-event object, create an event with a name already taken +** by an event object. +** +** +**=========================================================*/ +#include + +#define SWAPPTR ((VOID *) (-1)) + +struct testCase +{ + LPSECURITY_ATTRIBUTES lpEventAttributes; + BOOL bManualReset; + BOOL bInitialState; + WCHAR lpName[MAX_PATH + 2]; + DWORD dwNameLen; + DWORD lastError; + BOOL bResult; +}; + +struct testCase testCases[]= +{ + {0, TRUE, FALSE, {'\0'}, 0, ERROR_SUCCESS, PASS}, + {0, TRUE, FALSE, {'\0'}, 5, ERROR_SUCCESS, PASS}, + {0, TRUE, FALSE, {'\0'}, 5, ERROR_ALREADY_EXISTS, PASS}, + {0, TRUE, FALSE, {'\0'}, 6, ERROR_INVALID_HANDLE, PASS}, + {0, TRUE, FALSE, {'\0'}, MAX_PATH - 1 - 60, ERROR_SUCCESS, PASS}, + {0, TRUE, FALSE, {'\0'}, MAX_PATH - 60, ERROR_SUCCESS, PASS}, +}; + +static HANDLE hEvent[sizeof(testCases)/sizeof(struct testCase)]; + +DWORD result[sizeof(testCases)/sizeof(struct testCase)]; + +int __cdecl main(int argc, char **argv) +{ + + BOOL bRet = TRUE; + WCHAR nonEventName[] = {'a','a','a','a','a','a','\0'}; + char name[MAX_PATH + 2]; + WCHAR *wName; + HANDLE hFMap = NULL; + HANDLE hUnnamedEvent; + DWORD dwRet; + int i; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + hUnnamedEvent = CreateEventW(0, TRUE, FALSE, NULL); + + if ( NULL == hUnnamedEvent ) + { + bRet = FALSE; + Trace ( "PALSUITE ERROR: CreateEventW (%d, %d, %d, NULL) call " + "returned NULL.\nGetLastError returned %u.\n", 0, TRUE, FALSE, + GetLastError()); + goto done; + } + + if (!CloseHandle(hUnnamedEvent)) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventW: CloseHandle(%lp); call " + "failed\nGetLastError returned '%u'.\n", hUnnamedEvent, + GetLastError()); + } + + /* Create non-event with the same name as one of the testCases */ + hFMap = CreateFileMappingW( SWAPPTR, NULL, PAGE_READONLY, 0, 1, + nonEventName ); + + if ( NULL == hFMap ) + { + bRet = FALSE; + Trace ( "PALSUITE ERROR: CreateFileMapping (%p, %p, %d, %d, %d, %S)" + " call returned NULL.\nGetLastError returned %u\n", + SWAPPTR, NULL, PAGE_READONLY, 0, 0, nonEventName, + GetLastError()); + } + + /* Create Events */ + for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) + { + /* create name */ + memset (name, '\0', MAX_PATH + 2); + memset (name, 'a', testCases[i].dwNameLen ); + + wName = convert(name); + + wcsncpy(testCases[i].lpName, wName, + testCases[i].dwNameLen); + + free(wName); + + SetLastError(ERROR_SUCCESS); + + hEvent[i] = CreateEventW( testCases[i].lpEventAttributes, + testCases[i].bManualReset, + testCases[i].bInitialState, + testCases[i].lpName); + + if (hEvent[i] != INVALID_HANDLE_VALUE) + { + DWORD dwError = GetLastError(); + + if (dwError != testCases[i].lastError) + { + bRet = FALSE; + Trace ("PALSUITE ERROR:\nCreateEvent(%lp, %d, %d, %S)" + "\nGetLastError returned '%u', it should have returned" + "'%d' at index '%d'.\n", testCases[i].lpEventAttributes, + testCases[i].bManualReset, testCases[i].bInitialState, + testCases[i].lpName, dwError, + testCases[i].lastError, i); + } + if ( ERROR_FILENAME_EXCED_RANGE == testCases[i].lastError ) + { + result [i] = 1; + } + if ( ERROR_INVALID_HANDLE == testCases[i].lastError ) + { + result [i] = 1; + } + /* + * If we expected the testcase to FAIL and it passed, + * report an error. + */ + if (testCases[i].bResult == FAIL) + { + bRet = FALSE; + Trace ("PALSUITE ERROR:\nCreateEvent(%lp, %d, %d, %S)" + "\nShould have returned INVALID_HANDLE_VALUE but " + "didn't at index '%d'.\n", + testCases[i].lpEventAttributes, + testCases[i].bManualReset, + testCases[i].bInitialState, + testCases[i].lpName, i); + } + /* + * If result hasn't been set already set it to 0 so all the + * resources will be freed. + */ + if (!result[i]) + { + result[i] = 0; + } + } + else + { + /* + * If we get an INVALID_HANDLE_VALUE and we expected the + * test case to pass, report an error. + */ + result[i] = 1; + + if (testCases[i].bResult == PASS) + { + bRet = FALSE; + Trace ("PALSUITE ERROR:\nCreateEvent(%lp, %d, %d, %S);" + "\nReturned INVALID_HANDLE_VALUE at index '%d'.\n", + testCases[i].lpEventAttributes, + testCases[i].bManualReset, testCases[i].bInitialState, + testCases[i].lpName, i); + } + } + } + + /* cleanup */ + for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) + { + if (result[i]) + { + continue; + } + dwRet = WaitForSingleObject ( hEvent[i], 0 ); + + if (dwRet != WAIT_TIMEOUT) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventW:\nWaitForSingleObject (%lp, " + "%d) call failed at index %d .\nGetLastError returned " + "'%u'.\n", hEvent[i], 0, i, GetLastError()); + } + + if (!CloseHandle(hEvent[i])) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventW: CloseHandle(%lp) call " + "failed at index %d\nGetLastError returned '%u'.\n", + hEvent[i], i, GetLastError()); + } + } + +done: + if (hFMap != NULL && !CloseHandle(hFMap)) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventW: CloseHandle(%p) call " + "failed\nGetLastError returned '%u'.\n", hFMap, + GetLastError()); + } + + if (FALSE == bRet) + { + bRet = FAIL; + } + else + { + bRet = PASS; + } + + PAL_TerminateEx(bRet); + + return(bRet); + +} + + + diff --git a/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test1/CMakeLists.txt index ffdf13228e..782c671b84 100644 --- a/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateMutexA.c + CreateMutexA.cpp ) add_executable(paltest_createmutexa_releasemutex_test1 diff --git a/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test1/CreateMutexA.c b/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test1/CreateMutexA.c deleted file mode 100644 index 52bab351fb..0000000000 --- a/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test1/CreateMutexA.c +++ /dev/null @@ -1,345 +0,0 @@ -// 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: CreateMutexA_ReleaseMutex/test1/CreateMutexA.c -** -** Purpose: This test case tests whether a Mutex object created -** with CreateMutex really works by mutually excluding -** threads from accessing a data structure at the same -** time. Here we have a buffer that can be filled or -** emptied, we use a Mutex object to ensure that one -** operation cannot be started until the other is -** finished. If one operation detects that the other -** has not finished, it fails. There is a Producer -** thread which will try to fill the buffer 25 times, -** and a consumer thread which try to empty the buffer -** 25 times. If either the fill or empty operations -** fails because the Mutex failed to mutually exclude -** them, the corresponding thread will set an error -** flag and return. This will cause the test case to -** fail. -** -** To increase the probability of identifying problems, -** the Fill opeartion has been slowed down with a call -** to Sleep. This ensures that one operation will try -** to access the shared buffer while the other is in -** progress. -** -** NOTE: this test case also serves as a test case for -** WaitForSingleObject. -** -** -** Dependencies: CreateThread -** ReleaseMutex -** WaitForSingleObject -** WaitForMultipleObjects -** Sleep -** memset -** - -** -**=========================================================*/ - -#define UNICODE -#include - -/* Define some values that we will using many times */ -#define MAIN_BUF_SIZE 40 -#define NUM_OF_CYCLES 40 - -/* Buffer Operation return codes */ -#define OP_OK 0 -#define OP_ERR 1 -#define OP_NONE 2 - - -HANDLE hMutex; /* handle to mutex */ - -BOOL bProdErr; /* Producer error Flag */ -BOOL bConErr; /* Consumer error Flag */ - -/* Test Buffer */ -char Buffer[MAIN_BUF_SIZE]; - -/* - * EmptyBuffer implements the empty operation for test buffer. - */ -int -EmptyBuffer() -{ - int i; - - if ( WaitForSingleObject(hMutex, INFINITE) == WAIT_FAILED) - { - Fail("ERROR: WaitForSingleObject failed.\n"); - } - - /* Check to see if the buffer is already completely empty */ - for (i=0; i + +/* Define some values that we will using many times */ +#define MAIN_BUF_SIZE 40 +#define NUM_OF_CYCLES 40 + +/* Buffer Operation return codes */ +#define OP_OK 0 +#define OP_ERR 1 +#define OP_NONE 2 + + +HANDLE hMutex; /* handle to mutex */ + +BOOL bProdErr; /* Producer error Flag */ +BOOL bConErr; /* Consumer error Flag */ + +/* Test Buffer */ +char Buffer[MAIN_BUF_SIZE]; + +/* + * EmptyBuffer implements the empty operation for test buffer. + */ +int +EmptyBuffer() +{ + int i; + + if ( WaitForSingleObject(hMutex, INFINITE) == WAIT_FAILED) + { + Fail("ERROR: WaitForSingleObject failed.\n"); + } + + /* Check to see if the buffer is already completely empty */ + for (i=0; i - -const char *szMutex = "MyMutex"; -const char *szEmpty = ""; - -/* Function Prototypes */ -BOOL TestNamedMutex(const char *szMutexName); -DWORD NamedMutexThread(LPVOID lpParam); -BOOL NegativeReleaseMutexTests(); - -struct ThreadData -{ - HANDLE hMutex; - BOOL bReturnCode; -}; -typedef struct ThreadData THREADDATA; - - -int __cdecl main (int argc, char **argv) -{ - BOOL bFailures = FALSE; - char *szMaxPath; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - - /* - * Test named Mutexes with ordinary string - */ - - if (!TestNamedMutex(szMutex)) - { - bFailures = TRUE; - } - - - /* - * Test named Mutexes with empty ("") string - */ - - if (!TestNamedMutex(szEmpty)) - { - bFailures = TRUE; - } - - - /* - * Test named Mutexes with string of length MAX_LONGPATHPATH - */ - - szMaxPath = (char *)malloc(MAX_LONGPATH+2); - memset(szMaxPath, 'A', MAX_LONGPATH-60); - szMaxPath[MAX_LONGPATH-60] = 0; - - if (!TestNamedMutex(szMaxPath)) - { - bFailures = TRUE; - } - - free(szMaxPath); - - - /* - * Run some negative tests on ReleaseMutex - */ - - if (!NegativeReleaseMutexTests()) - { - bFailures = TRUE; - } - - - /* - * If there were any failures, then abort with a call to Fail - */ - - if (bFailures == TRUE) - { - Fail("ERROR: There some failures in the Mutex tests.\n"); - } - - PAL_Terminate(); - return ( PASS ); -} - - -/* - * Testing Function - * - * Try to get multiple handles to a named Mutex and test - * to make sure they actually refer to same Mutex object. - */ -BOOL TestNamedMutex(const char *szMutexName) -{ - DWORD dwData; - HANDLE hMutex1; - HANDLE hMutex2; - HANDLE hThread; - THREADDATA threadData; - - /* Create a mutex and take ownership immediately */ - hMutex1 = CreateMutexA (NULL, TRUE, szMutexName); - - if (NULL == hMutex1) - { - Trace("ERROR: CreateMutexA #1 failed. GetLastError returned %u\n", - GetLastError()); - return FALSE; - } - - /* Try to wait on the Mutex we just created. We should not block. */ - if (WaitForSingleObject(hMutex1, 1000) == WAIT_TIMEOUT) - { - Trace("WaitForSingleObject blocked on a Mutex that we owned.\n"); - return FALSE; - } - /* We have to call ReleaseMutex here because of the Wait */ - if (ReleaseMutex(hMutex1) == FALSE) - { - Trace("ReleaseMutex Failed.\n"); - return FALSE; - } - - /* Get a second handle to the same mutex */ - hMutex2 = CreateMutexA (NULL, FALSE, szMutexName); - - if (NULL == hMutex2) - { - Trace("ERROR: CreateMutex #2 failed. GetLastError returned %u\n", - GetLastError()); - free(szMutexName); - return FALSE; - } - - /* - * Create a thread that will Wait on the second handle. - */ - threadData.hMutex = hMutex2; - hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)NamedMutexThread, - (LPVOID)&threadData, 0, &dwData); - - if (NULL == hThread) - { - Trace("ERROR: CreateThread failed. GetLastError returned %u\n", - GetLastError()); - return FALSE; - } - - /* Give the thread a little time to execute & wait*/ - Sleep(500); - - /* Signal the the first handle */ - if (ReleaseMutex(hMutex1) == FALSE) - { - Trace("ReleaseMutex Failed.\n"); - return FALSE; - } - - /* Give the thread some time to finish */ - Sleep(2000); - - /* Clean Up */ - if (CloseHandle(hMutex1) == FALSE || - CloseHandle(hMutex2) == FALSE || - CloseHandle(hThread) == FALSE) - { - Trace("ERROR: CloseHandle failed.\n"); - return FALSE; - } - - /* Check the return code to see if signalling the first */ - /* Mutex handle woke up the thread which was Waiting on */ - /* the second handle. */ - if (threadData.bReturnCode != FALSE) - { - Trace("ERROR: The handles did not refer to the same Mutex object.\n"); - return FALSE; - } - - return TRUE; -} - - -/* - * Thread function used with above testing function. - */ -DWORD NamedMutexThread(LPVOID lpParam) -{ - BOOL bTimedOut = FALSE; - THREADDATA *lpThreadData = (THREADDATA *)lpParam; - - /* Wait on the Mutex that was passed to us */ - if (WaitForSingleObject(lpThreadData->hMutex, 10000) == WAIT_TIMEOUT) - { - /* The Mutex was not signaled in the allotted time */ - bTimedOut = TRUE; - } - if (ReleaseMutex(lpThreadData->hMutex) == FALSE) - { - Trace("ERROR: ReleaseMutex failed.\n"); - lpThreadData->bReturnCode = FALSE; - return 0; - } - - /* Indicate whether we timed out Waiting on the Mutex */ - lpThreadData->bReturnCode = bTimedOut; - - return 0; -} - - -/* - * Testing Function - * - * Try some negative tests on ReleaseMutex - */ -BOOL NegativeReleaseMutexTests() -{ - HANDLE hMutex; - BOOL bRet; - BOOL bResults = TRUE; - - - /* - * Try calling ReleaseMutex on a null handle - */ - hMutex = 0; - bRet = ReleaseMutex(hMutex); - - if (bRet != 0) - { - Trace("Error: ReleaseMutex accepted null handle.\n"); - bResults = FALSE; - } - - - /* - * Try calling ReleaseMutex on an handle that we don't own - */ - hMutex = CreateMutexA (NULL, TRUE, NULL); - if (hMutex == 0) - { - Trace("Error: CreateMutex failed.\n"); - bResults = FALSE; - } - - bRet = ReleaseMutex(hMutex); - bRet = ReleaseMutex(hMutex); - - if (bRet != FALSE) - { - Trace("Error: ReleaseMutex accepted unowned handle.\n"); - bResults = FALSE; - } - - if (CloseHandle(hMutex) == FALSE) - { - Trace("Error: CloseHandle failed.\n"); - bResults = FALSE; - } - - - - /* - * Try calling ReleaseMutex on an handle that has been closed - */ - hMutex = CreateMutexA (NULL, TRUE, NULL); - if (hMutex == 0) - { - Trace("Error: CreateMutex failed.\n"); - bResults = FALSE; - } - - if (ReleaseMutex(hMutex) == FALSE) - { - Trace("Error: ReleaseMutex failed.\n"); - bResults = FALSE; - } - if (CloseHandle(hMutex) == FALSE) - { - Trace("Error: CloseHandle failed.\n"); - bResults = FALSE; - } - - bRet = ReleaseMutex(hMutex); - - if (bRet != FALSE) - { - Trace("Error: ReleaseMutex accepted invalid handle.\n"); - bResults = FALSE; - } - - return bResults; -} diff --git a/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test2/CreateMutexA.cpp b/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test2/CreateMutexA.cpp new file mode 100644 index 0000000000..36295855e0 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateMutexA_ReleaseMutex/test2/CreateMutexA.cpp @@ -0,0 +1,331 @@ +// 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: CreateMutexA_ReleaseMutex/test2/CreateMutexA.c +** +** Purpose: This test case tests the following things +** - Creation of named Mutexes +** - Creating multiple handles to a single named Mutex +** - Ensuring that these handles work interchangeably +** - Setting bInitialOwnerFlag to TRUE will cause the +** initial call to a Wait function on the same Mutex +** to actually wait. +** - Waiting on a Mutex that a thread already owns does +** not block. +** - Create Named mutex with empty string ("") +** - Create Named mutex with string of MAX_LONGPATH length +** - Calling RelaseMutex with invalid Mutex handles and +** valid but unowned Mutexes. +** +** Dependencies: CreateThread +** ReleaseMutex +** WaitForSingleObject +** CloseHandle +** Sleep +** memset +** + +** +**=========================================================*/ + +#define UNICODE +#include + +const char *szMutex = "MyMutex"; +const char *szEmpty = ""; + +/* Function Prototypes */ +BOOL TestNamedMutex(const char *szMutexName); +DWORD NamedMutexThread(LPVOID lpParam); +BOOL NegativeReleaseMutexTests(); + +struct ThreadData +{ + HANDLE hMutex; + BOOL bReturnCode; +}; +typedef struct ThreadData THREADDATA; + + +int __cdecl main (int argc, char **argv) +{ + BOOL bFailures = FALSE; + char *szMaxPath; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + + /* + * Test named Mutexes with ordinary string + */ + + if (!TestNamedMutex(szMutex)) + { + bFailures = TRUE; + } + + + /* + * Test named Mutexes with empty ("") string + */ + + if (!TestNamedMutex(szEmpty)) + { + bFailures = TRUE; + } + + + /* + * Test named Mutexes with string of length MAX_LONGPATHPATH + */ + + szMaxPath = (char *)malloc(MAX_LONGPATH+2); + memset(szMaxPath, 'A', MAX_LONGPATH-60); + szMaxPath[MAX_LONGPATH-60] = 0; + + if (!TestNamedMutex(szMaxPath)) + { + bFailures = TRUE; + } + + free((void*)szMaxPath); + + + /* + * Run some negative tests on ReleaseMutex + */ + + if (!NegativeReleaseMutexTests()) + { + bFailures = TRUE; + } + + + /* + * If there were any failures, then abort with a call to Fail + */ + + if (bFailures == TRUE) + { + Fail("ERROR: There some failures in the Mutex tests.\n"); + } + + PAL_Terminate(); + return ( PASS ); +} + + +/* + * Testing Function + * + * Try to get multiple handles to a named Mutex and test + * to make sure they actually refer to same Mutex object. + */ +BOOL TestNamedMutex(const char *szMutexName) +{ + DWORD dwData; + HANDLE hMutex1; + HANDLE hMutex2; + HANDLE hThread; + THREADDATA threadData; + + /* Create a mutex and take ownership immediately */ + hMutex1 = CreateMutexA (NULL, TRUE, szMutexName); + + if (NULL == hMutex1) + { + Trace("ERROR: CreateMutexA #1 failed. GetLastError returned %u\n", + GetLastError()); + return FALSE; + } + + /* Try to wait on the Mutex we just created. We should not block. */ + if (WaitForSingleObject(hMutex1, 1000) == WAIT_TIMEOUT) + { + Trace("WaitForSingleObject blocked on a Mutex that we owned.\n"); + return FALSE; + } + /* We have to call ReleaseMutex here because of the Wait */ + if (ReleaseMutex(hMutex1) == FALSE) + { + Trace("ReleaseMutex Failed.\n"); + return FALSE; + } + + /* Get a second handle to the same mutex */ + hMutex2 = CreateMutexA (NULL, FALSE, szMutexName); + + if (NULL == hMutex2) + { + Trace("ERROR: CreateMutex #2 failed. GetLastError returned %u\n", + GetLastError()); + free((void*)szMutexName); + return FALSE; + } + + /* + * Create a thread that will Wait on the second handle. + */ + threadData.hMutex = hMutex2; + hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)NamedMutexThread, + (LPVOID)&threadData, 0, &dwData); + + if (NULL == hThread) + { + Trace("ERROR: CreateThread failed. GetLastError returned %u\n", + GetLastError()); + return FALSE; + } + + /* Give the thread a little time to execute & wait*/ + Sleep(500); + + /* Signal the the first handle */ + if (ReleaseMutex(hMutex1) == FALSE) + { + Trace("ReleaseMutex Failed.\n"); + return FALSE; + } + + /* Give the thread some time to finish */ + Sleep(2000); + + /* Clean Up */ + if (CloseHandle(hMutex1) == FALSE || + CloseHandle(hMutex2) == FALSE || + CloseHandle(hThread) == FALSE) + { + Trace("ERROR: CloseHandle failed.\n"); + return FALSE; + } + + /* Check the return code to see if signalling the first */ + /* Mutex handle woke up the thread which was Waiting on */ + /* the second handle. */ + if (threadData.bReturnCode != FALSE) + { + Trace("ERROR: The handles did not refer to the same Mutex object.\n"); + return FALSE; + } + + return TRUE; +} + + +/* + * Thread function used with above testing function. + */ +DWORD NamedMutexThread(LPVOID lpParam) +{ + BOOL bTimedOut = FALSE; + THREADDATA *lpThreadData = (THREADDATA *)lpParam; + + /* Wait on the Mutex that was passed to us */ + if (WaitForSingleObject(lpThreadData->hMutex, 10000) == WAIT_TIMEOUT) + { + /* The Mutex was not signaled in the allotted time */ + bTimedOut = TRUE; + } + if (ReleaseMutex(lpThreadData->hMutex) == FALSE) + { + Trace("ERROR: ReleaseMutex failed.\n"); + lpThreadData->bReturnCode = FALSE; + return 0; + } + + /* Indicate whether we timed out Waiting on the Mutex */ + lpThreadData->bReturnCode = bTimedOut; + + return 0; +} + + +/* + * Testing Function + * + * Try some negative tests on ReleaseMutex + */ +BOOL NegativeReleaseMutexTests() +{ + HANDLE hMutex; + BOOL bRet; + BOOL bResults = TRUE; + + + /* + * Try calling ReleaseMutex on a null handle + */ + hMutex = 0; + bRet = ReleaseMutex(hMutex); + + if (bRet != 0) + { + Trace("Error: ReleaseMutex accepted null handle.\n"); + bResults = FALSE; + } + + + /* + * Try calling ReleaseMutex on an handle that we don't own + */ + hMutex = CreateMutexA (NULL, TRUE, NULL); + if (hMutex == 0) + { + Trace("Error: CreateMutex failed.\n"); + bResults = FALSE; + } + + bRet = ReleaseMutex(hMutex); + bRet = ReleaseMutex(hMutex); + + if (bRet != FALSE) + { + Trace("Error: ReleaseMutex accepted unowned handle.\n"); + bResults = FALSE; + } + + if (CloseHandle(hMutex) == FALSE) + { + Trace("Error: CloseHandle failed.\n"); + bResults = FALSE; + } + + + + /* + * Try calling ReleaseMutex on an handle that has been closed + */ + hMutex = CreateMutexA (NULL, TRUE, NULL); + if (hMutex == 0) + { + Trace("Error: CreateMutex failed.\n"); + bResults = FALSE; + } + + if (ReleaseMutex(hMutex) == FALSE) + { + Trace("Error: ReleaseMutex failed.\n"); + bResults = FALSE; + } + if (CloseHandle(hMutex) == FALSE) + { + Trace("Error: CloseHandle failed.\n"); + bResults = FALSE; + } + + bRet = ReleaseMutex(hMutex); + + if (bRet != FALSE) + { + Trace("Error: ReleaseMutex accepted invalid handle.\n"); + bResults = FALSE; + } + + return bResults; +} diff --git a/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test1/CMakeLists.txt index a73ee045a3..aa1f7831c0 100644 --- a/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateMutexW.c + CreateMutexW.cpp ) add_executable(paltest_createmutexw_releasemutex_test1 diff --git a/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test1/CreateMutexW.c b/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test1/CreateMutexW.c deleted file mode 100644 index c21bfb6a50..0000000000 --- a/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test1/CreateMutexW.c +++ /dev/null @@ -1,345 +0,0 @@ -// 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: CreateMutexW_ReleaseMutex/test1/CreateMutexW.c -** -** Purpose: This test case tests whether a Mutex object created -** with CreateMutex really works by mutually excluding -** threads from accessing a data structure at the same -** time. Here we have a buffer that can be filled or -** emptied, we use a Mutex object to ensure that one -** operation cannot be started until the other is -** finished. If one operation detects that the other -** has not finished, it fails. There is a Producer -** thread which will try to fill the buffer 25 times, -** and a consumer thread which try to empty the buffer -** 25 times. If either the fill or empty operations -** fails because the Mutex failed to mutually exclude -** them, the corresponding thread will set an error -** flag and return. This will cause the test case to -** fail. -** -** To increase the probability of identifying problems, -** the Fill opeartion has been slowed dowm with a call -** to Sleep. This ensures that one operation will try -** to access the shared buffer while the other is in -** progress. -** -** NOTE: this test case also serves as a test case for -** WaitForSingleObject. -** -** -** Dependencies: CreateThread -** ReleaseMutex -** WaitForSingleObject -** WaitForMultipleObjects -** Sleep -** memset -** - -** -**=========================================================*/ - -#define UNICODE -#include - -/* Define some values that we will using many times */ -#define MAIN_BUF_SIZE 40 -#define NUM_OF_CYCLES 40 - -/* Buffer Operation return codes */ -#define OP_OK 0 -#define OP_ERR 1 -#define OP_NONE 2 - - -HANDLE hMutex; /* handle to mutex */ - -BOOL bProdErr; /* Producer error Flag */ -BOOL bConErr; /* Consumer error Flag */ - -/* Test Buffer */ -char Buffer[MAIN_BUF_SIZE]; - -/* - * EmptyBuffer implements the empty operation for test buffer. - */ -int -EmptyBuffer() -{ - int i; - - if ( WaitForSingleObject(hMutex, INFINITE) == WAIT_FAILED) - { - Fail("ERROR: WaitForSingleObject failed.\n"); - } - - /* Check to see if the buffer is already completely empty */ - for (i=0; i + +/* Define some values that we will using many times */ +#define MAIN_BUF_SIZE 40 +#define NUM_OF_CYCLES 40 + +/* Buffer Operation return codes */ +#define OP_OK 0 +#define OP_ERR 1 +#define OP_NONE 2 + + +HANDLE hMutex; /* handle to mutex */ + +BOOL bProdErr; /* Producer error Flag */ +BOOL bConErr; /* Consumer error Flag */ + +/* Test Buffer */ +char Buffer[MAIN_BUF_SIZE]; + +/* + * EmptyBuffer implements the empty operation for test buffer. + */ +int +EmptyBuffer() +{ + int i; + + if ( WaitForSingleObject(hMutex, INFINITE) == WAIT_FAILED) + { + Fail("ERROR: WaitForSingleObject failed.\n"); + } + + /* Check to see if the buffer is already completely empty */ + for (i=0; i - -const char *szMutex = "MyMutex"; -const char *szEmpty = ""; - -/* Function Prototypes */ -BOOL TestNamedMutex(const char *szMutexName); -DWORD NamedMutexThread(LPVOID lpParam); -BOOL NegativeReleaseMutexTests(); - -struct ThreadData -{ - HANDLE hMutex; - BOOL bReturnCode; -}; -typedef struct ThreadData THREADDATA; - - -int __cdecl main (int argc, char **argv) -{ - BOOL bFailures = FALSE; - char *szMaxPath; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - - /* - * Test named Mutexes with ordinary string - */ - - if (!TestNamedMutex(szMutex)) - { - bFailures = TRUE; - } - - - /* - * Test named Mutexes with empty ("") string - */ - - if (!TestNamedMutex(szEmpty)) - { - bFailures = TRUE; - } - - - /* - * Test named Mutexes with string of length MAX_LONGPATH - */ - - szMaxPath = (char *)malloc(MAX_LONGPATH+2); - memset(szMaxPath, 'A', MAX_LONGPATH-60); - szMaxPath[MAX_LONGPATH-60] = 0; - - if (!TestNamedMutex(szMaxPath)) - { - bFailures = TRUE; - } - - free(szMaxPath); - - - /* - * Run some negative tests on ReleaseMutex - */ - - if (!NegativeReleaseMutexTests()) - { - bFailures = TRUE; - } - - - /* - * If there were any failures, then abort with a call to Fail - */ - - if (bFailures == TRUE) - { - Fail("ERROR: There some failures in the Mutex tests.\n"); - } - - PAL_Terminate(); - return ( PASS ); -} - - -/* - * Testing Function - * - * Try to get multiple handles to a named Mutex and test - * to make sure they actually refer to same Mutex object. - */ -BOOL TestNamedMutex(const char *szMutexName) -{ - DWORD dwData; - HANDLE hMutex1; - HANDLE hMutex2; - HANDLE hThread; - WCHAR *swzMutexName; - THREADDATA threadData; - - /* Convert the Mutex name to wide characters */ - swzMutexName = convert((char *)szMutexName); - - /* Create a mutex and take ownership immediately */ - hMutex1 = CreateMutexW (NULL, TRUE, swzMutexName); - - if (NULL == hMutex1) - { - Trace("ERROR: CreateMutex #1 failed. GetLastError returned %u\n", - GetLastError()); - free(swzMutexName); - return FALSE; - } - - /* Try to wait on the Mutex we just created. We should not block. */ - if (WaitForSingleObject(hMutex1, 1000) == WAIT_TIMEOUT) - { - Trace("WaitForSingleObject blocked on a Mutex that we owned.\n"); - free(swzMutexName); - return FALSE; - } - /* We have to call ReleaseMutex here because of the Wait */ - if (ReleaseMutex(hMutex1) == FALSE) - { - Trace("ReleaseMutex Failed.\n"); - return FALSE; - } - - /* Get a second handle to the same mutex */ - hMutex2 = CreateMutexW (NULL, FALSE, swzMutexName); - - if (NULL == hMutex2) - { - Trace("ERROR: CreateMutex #2 failed. GetLastError returned %u\n", - GetLastError()); - free(swzMutexName); - return FALSE; - } - - /* Get rid of the wide character string */ - free(swzMutexName); - - /* - * Create a thread that will Wait on the second handle. - */ - threadData.hMutex = hMutex2; - hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)NamedMutexThread, - (LPVOID)&threadData, 0, &dwData); - - if (NULL == hThread) - { - Trace("ERROR: CreateThread failed. GetLastError returned %u\n", - GetLastError()); - return FALSE; - } - - /* Give the thread a little time to execute & wait*/ - Sleep(500); - - /* Signal the the first handle */ - if (ReleaseMutex(hMutex1) == FALSE) - { - Trace("ReleaseMutex Failed.\n"); - return FALSE; - } - - /* Give the thread some time to finish */ - Sleep(2000); - - /* Clean Up */ - if (CloseHandle(hMutex1) == FALSE || - CloseHandle(hMutex2) == FALSE || - CloseHandle(hThread) == FALSE) - { - Trace("ERROR: CloseHandle failed.\n"); - return FALSE; - } - - /* Check the return code to see if signalling the first */ - /* Mutex handle woke up the thread which was Waiting on */ - /* the second handle. */ - if (threadData.bReturnCode != FALSE) - { - Trace("ERROR: The handles did not refer to the same Mutex object.\n"); - return FALSE; - } - - return TRUE; -} - - -/* - * Thread function used with above testing function. - */ -DWORD NamedMutexThread(LPVOID lpParam) -{ - BOOL bTimedOut = FALSE; - THREADDATA *lpThreadData = (THREADDATA *)lpParam; - - /* Wait on the Mutex that was passed to us */ - if (WaitForSingleObject(lpThreadData->hMutex, 10000) == WAIT_TIMEOUT) - { - /* The Mutex was not signaled in the allotted time */ - bTimedOut = TRUE; - } - if (ReleaseMutex(lpThreadData->hMutex) == FALSE) - { - Trace("ERROR: ReleaseMutex failed.\n"); - lpThreadData->bReturnCode = FALSE; - return 0; - } - - /* Indicate whether we timed out Waiting on the Mutex */ - lpThreadData->bReturnCode = bTimedOut; - - return 0; -} - - -/* - * Testing Function - * - * Try some negative tests on ReleaseMutex - */ -BOOL NegativeReleaseMutexTests() -{ - HANDLE hMutex; - BOOL bRet; - BOOL bResults = TRUE; - - - /* - * Try calling ReleaseMutex on a null handle - */ - hMutex = 0; - bRet = ReleaseMutex(hMutex); - - if (bRet != 0) - { - Trace("Error: ReleaseMutex accepted null handle.\n"); - bResults = FALSE; - } - - - /* - * Try calling ReleaseMutex on an handle that we don't own - */ - hMutex = CreateMutexW (NULL, TRUE, NULL); - if (hMutex == 0) - { - Trace("Error: CreateMutex failed.\n"); - bResults = FALSE; - } - - bRet = ReleaseMutex(hMutex); - bRet = ReleaseMutex(hMutex); - - if (bRet != FALSE) - { - Trace("Error: ReleaseMutex accepted unowned handle.\n"); - bResults = FALSE; - } - - if (CloseHandle(hMutex) == FALSE) - { - Trace("Error: CloseHandle failed.\n"); - bResults = FALSE; - } - - - - /* - * Try calling ReleaseMutex on an handle that has been closed - */ - hMutex = CreateMutexW (NULL, TRUE, NULL); - if (hMutex == 0) - { - Trace("Error: CreateMutex failed.\n"); - bResults = FALSE; - } - - if (ReleaseMutex(hMutex) == FALSE) - { - Trace("Error: ReleaseMutex failed.\n"); - bResults = FALSE; - } - if (CloseHandle(hMutex) == FALSE) - { - Trace("Error: CloseHandle failed.\n"); - bResults = FALSE; - } - - bRet = ReleaseMutex(hMutex); - - if (bRet != FALSE) - { - Trace("Error: ReleaseMutex accepted invalid handle.\n"); - bResults = FALSE; - } - - return bResults; -} diff --git a/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test2/CreateMutexW.cpp b/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test2/CreateMutexW.cpp new file mode 100644 index 0000000000..41b7798a6e --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateMutexW_ReleaseMutex/test2/CreateMutexW.cpp @@ -0,0 +1,340 @@ +// 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: CreateMutexW_ReleaseMutex/test2/CreateMutexW.c +** +** Purpose: This test case tests the following things +** - Creation of named Mutexes +** - Creating multiple handles to a single named Mutex +** - Ensuring that these handles work interchangeably +** - Setting bInitialOwnerFlag to TRUE will cause the +** initial call to a Wait function on the same Mutex +** to actually wait. +** - Waiting on a Mutex that a thread already owns does +** not block. +** - Create Named mutex with empty string ("") +** - Create Named mutex with string of MAX_LONGPATH length +** - Calling RelaseMutex with invalid Mutex handles and +** valid but unowned Mutexes. +** +** Dependencies: CreateThread +** ReleaseMutex +** WaitForSingleObject +** CloseHandle +** Sleep +** memset +** + +** +**=========================================================*/ + +#define UNICODE +#include + +const char *szMutex = "MyMutex"; +const char *szEmpty = ""; + +/* Function Prototypes */ +BOOL TestNamedMutex(const char *szMutexName); +DWORD NamedMutexThread(LPVOID lpParam); +BOOL NegativeReleaseMutexTests(); + +struct ThreadData +{ + HANDLE hMutex; + BOOL bReturnCode; +}; +typedef struct ThreadData THREADDATA; + + +int __cdecl main (int argc, char **argv) +{ + BOOL bFailures = FALSE; + char *szMaxPath; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + + /* + * Test named Mutexes with ordinary string + */ + + if (!TestNamedMutex(szMutex)) + { + bFailures = TRUE; + } + + + /* + * Test named Mutexes with empty ("") string + */ + + if (!TestNamedMutex(szEmpty)) + { + bFailures = TRUE; + } + + + /* + * Test named Mutexes with string of length MAX_LONGPATH + */ + + szMaxPath = (char *)malloc(MAX_LONGPATH+2); + memset(szMaxPath, 'A', MAX_LONGPATH-60); + szMaxPath[MAX_LONGPATH-60] = 0; + + if (!TestNamedMutex(szMaxPath)) + { + bFailures = TRUE; + } + + free(szMaxPath); + + + /* + * Run some negative tests on ReleaseMutex + */ + + if (!NegativeReleaseMutexTests()) + { + bFailures = TRUE; + } + + + /* + * If there were any failures, then abort with a call to Fail + */ + + if (bFailures == TRUE) + { + Fail("ERROR: There some failures in the Mutex tests.\n"); + } + + PAL_Terminate(); + return ( PASS ); +} + + +/* + * Testing Function + * + * Try to get multiple handles to a named Mutex and test + * to make sure they actually refer to same Mutex object. + */ +BOOL TestNamedMutex(const char *szMutexName) +{ + DWORD dwData; + HANDLE hMutex1; + HANDLE hMutex2; + HANDLE hThread; + WCHAR *swzMutexName; + THREADDATA threadData; + + /* Convert the Mutex name to wide characters */ + swzMutexName = convert((char *)szMutexName); + + /* Create a mutex and take ownership immediately */ + hMutex1 = CreateMutexW (NULL, TRUE, swzMutexName); + + if (NULL == hMutex1) + { + Trace("ERROR: CreateMutex #1 failed. GetLastError returned %u\n", + GetLastError()); + free(swzMutexName); + return FALSE; + } + + /* Try to wait on the Mutex we just created. We should not block. */ + if (WaitForSingleObject(hMutex1, 1000) == WAIT_TIMEOUT) + { + Trace("WaitForSingleObject blocked on a Mutex that we owned.\n"); + free(swzMutexName); + return FALSE; + } + /* We have to call ReleaseMutex here because of the Wait */ + if (ReleaseMutex(hMutex1) == FALSE) + { + Trace("ReleaseMutex Failed.\n"); + return FALSE; + } + + /* Get a second handle to the same mutex */ + hMutex2 = CreateMutexW (NULL, FALSE, swzMutexName); + + if (NULL == hMutex2) + { + Trace("ERROR: CreateMutex #2 failed. GetLastError returned %u\n", + GetLastError()); + free(swzMutexName); + return FALSE; + } + + /* Get rid of the wide character string */ + free(swzMutexName); + + /* + * Create a thread that will Wait on the second handle. + */ + threadData.hMutex = hMutex2; + hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)NamedMutexThread, + (LPVOID)&threadData, 0, &dwData); + + if (NULL == hThread) + { + Trace("ERROR: CreateThread failed. GetLastError returned %u\n", + GetLastError()); + return FALSE; + } + + /* Give the thread a little time to execute & wait*/ + Sleep(500); + + /* Signal the the first handle */ + if (ReleaseMutex(hMutex1) == FALSE) + { + Trace("ReleaseMutex Failed.\n"); + return FALSE; + } + + /* Give the thread some time to finish */ + Sleep(2000); + + /* Clean Up */ + if (CloseHandle(hMutex1) == FALSE || + CloseHandle(hMutex2) == FALSE || + CloseHandle(hThread) == FALSE) + { + Trace("ERROR: CloseHandle failed.\n"); + return FALSE; + } + + /* Check the return code to see if signalling the first */ + /* Mutex handle woke up the thread which was Waiting on */ + /* the second handle. */ + if (threadData.bReturnCode != FALSE) + { + Trace("ERROR: The handles did not refer to the same Mutex object.\n"); + return FALSE; + } + + return TRUE; +} + + +/* + * Thread function used with above testing function. + */ +DWORD NamedMutexThread(LPVOID lpParam) +{ + BOOL bTimedOut = FALSE; + THREADDATA *lpThreadData = (THREADDATA *)lpParam; + + /* Wait on the Mutex that was passed to us */ + if (WaitForSingleObject(lpThreadData->hMutex, 10000) == WAIT_TIMEOUT) + { + /* The Mutex was not signaled in the allotted time */ + bTimedOut = TRUE; + } + if (ReleaseMutex(lpThreadData->hMutex) == FALSE) + { + Trace("ERROR: ReleaseMutex failed.\n"); + lpThreadData->bReturnCode = FALSE; + return 0; + } + + /* Indicate whether we timed out Waiting on the Mutex */ + lpThreadData->bReturnCode = bTimedOut; + + return 0; +} + + +/* + * Testing Function + * + * Try some negative tests on ReleaseMutex + */ +BOOL NegativeReleaseMutexTests() +{ + HANDLE hMutex; + BOOL bRet; + BOOL bResults = TRUE; + + + /* + * Try calling ReleaseMutex on a null handle + */ + hMutex = 0; + bRet = ReleaseMutex(hMutex); + + if (bRet != 0) + { + Trace("Error: ReleaseMutex accepted null handle.\n"); + bResults = FALSE; + } + + + /* + * Try calling ReleaseMutex on an handle that we don't own + */ + hMutex = CreateMutexW (NULL, TRUE, NULL); + if (hMutex == 0) + { + Trace("Error: CreateMutex failed.\n"); + bResults = FALSE; + } + + bRet = ReleaseMutex(hMutex); + bRet = ReleaseMutex(hMutex); + + if (bRet != FALSE) + { + Trace("Error: ReleaseMutex accepted unowned handle.\n"); + bResults = FALSE; + } + + if (CloseHandle(hMutex) == FALSE) + { + Trace("Error: CloseHandle failed.\n"); + bResults = FALSE; + } + + + + /* + * Try calling ReleaseMutex on an handle that has been closed + */ + hMutex = CreateMutexW (NULL, TRUE, NULL); + if (hMutex == 0) + { + Trace("Error: CreateMutex failed.\n"); + bResults = FALSE; + } + + if (ReleaseMutex(hMutex) == FALSE) + { + Trace("Error: ReleaseMutex failed.\n"); + bResults = FALSE; + } + if (CloseHandle(hMutex) == FALSE) + { + Trace("Error: CloseHandle failed.\n"); + bResults = FALSE; + } + + bRet = ReleaseMutex(hMutex); + + if (bRet != FALSE) + { + Trace("Error: ReleaseMutex accepted invalid handle.\n"); + bResults = FALSE; + } + + return bResults; +} diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateProcessA/test1/CMakeLists.txt index 67e53edccd..9cd0aa5dfd 100644 --- a/src/pal/tests/palsuite/threading/CreateProcessA/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateProcessA/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - parentProcess.c + parentProcess.cpp ) add_executable(paltest_createprocessa_test1 @@ -20,7 +20,7 @@ target_link_libraries(paltest_createprocessa_test1 set(HELPERSOURCES - childProcess.c + childProcess.cpp ) add_executable(paltest_createprocessa_test1_child diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test1/childProcess.c b/src/pal/tests/palsuite/threading/CreateProcessA/test1/childProcess.c deleted file mode 100644 index ccbb050c04..0000000000 --- a/src/pal/tests/palsuite/threading/CreateProcessA/test1/childProcess.c +++ /dev/null @@ -1,131 +0,0 @@ -// 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: CreateProcessA/test1/childprocess.c -** -** Purpose: Test to ensure CreateProcessA starts a new process. This test -** launches a child process, and examines a file written by the child. -** This code is the child code. -** -** Dependencies: GetCurrentDirectory -** strlen -** fopen -** fclose -** fprintf -** - -** -**=========================================================*/ - -#include - -const char *szCommonFileA = "childdata.tmp"; - -const char *szPathDelimA = "\\"; - -const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0"; - -/* - * Take two wide strings representing file and directory names - * (dirName, fileName), join the strings with the appropriate path - * delimiter and populate a wide character buffer (absPathName) with - * the resulting string. - * - * Returns: The number of wide characters in the resulting string. - * 0 is returned on Error. - */ -int -mkAbsoluteFilenameA ( - LPSTR dirName, - DWORD dwDirLength, - LPCSTR fileName, - DWORD dwFileLength, - LPSTR absPathName ) -{ - extern const char *szPathDelimA; - - DWORD sizeDN, sizeFN, sizeAPN; - - sizeDN = strlen( dirName ); - sizeFN = strlen( fileName ); - sizeAPN = (sizeDN + 1 + sizeFN + 1); - - /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ - if ( sizeAPN > _MAX_PATH ) - { - return ( 0 ); - } - - strncpy(absPathName, dirName, dwDirLength +1); - strncpy(absPathName, szPathDelimA, 2); - strncpy(absPathName, fileName, dwFileLength +1); - - return (sizeAPN); - -} - -int __cdecl main( int argc, char **argv ) -{ - - static FILE * fp; - - DWORD dwFileLength; - DWORD dwDirLength; - DWORD dwSize; - - char szDirNameA[_MAX_DIR]; - char szAbsPathNameA[_MAX_PATH]; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - dwDirLength = GetCurrentDirectory( _MAX_PATH, szDirNameA ); - - if (0 == dwDirLength) - { - Fail ("GetCurrentDirectory call failed. Could not get " - "current working directory\n. Exiting.\n"); - } - - dwFileLength = strlen( szCommonFileA ); - - dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szCommonFileA, - dwFileLength, szAbsPathNameA ); - - if (0 == dwSize) - { - Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " - "not build absolute path name to file\n. Exiting.\n"); - } - - if ( NULL == ( fp = fopen ( szAbsPathNameA , "w+" ) ) ) - { - /* - * A return value of NULL indicates an error condition or an - * EOF condition - */ - Fail ("%s unable to open %s for writing. Exiting.\n", argv[0] - , szAbsPathNameA ); - } - - if ( 0 >= ( fprintf ( fp, "%s", szCommonStringA ))) - { - Fail("%s unable to write to %s. Exiting.\n", argv[0] - , szAbsPathNameA ); - } - - if (0 != (fclose ( fp ))) - { - Fail ("%s unable to close file %s. Pid may not be " - "written to file. Exiting.\n", argv[0], szAbsPathNameA ); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test1/childProcess.cpp b/src/pal/tests/palsuite/threading/CreateProcessA/test1/childProcess.cpp new file mode 100644 index 0000000000..ccbb050c04 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateProcessA/test1/childProcess.cpp @@ -0,0 +1,131 @@ +// 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: CreateProcessA/test1/childprocess.c +** +** Purpose: Test to ensure CreateProcessA starts a new process. This test +** launches a child process, and examines a file written by the child. +** This code is the child code. +** +** Dependencies: GetCurrentDirectory +** strlen +** fopen +** fclose +** fprintf +** + +** +**=========================================================*/ + +#include + +const char *szCommonFileA = "childdata.tmp"; + +const char *szPathDelimA = "\\"; + +const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0"; + +/* + * Take two wide strings representing file and directory names + * (dirName, fileName), join the strings with the appropriate path + * delimiter and populate a wide character buffer (absPathName) with + * the resulting string. + * + * Returns: The number of wide characters in the resulting string. + * 0 is returned on Error. + */ +int +mkAbsoluteFilenameA ( + LPSTR dirName, + DWORD dwDirLength, + LPCSTR fileName, + DWORD dwFileLength, + LPSTR absPathName ) +{ + extern const char *szPathDelimA; + + DWORD sizeDN, sizeFN, sizeAPN; + + sizeDN = strlen( dirName ); + sizeFN = strlen( fileName ); + sizeAPN = (sizeDN + 1 + sizeFN + 1); + + /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ + if ( sizeAPN > _MAX_PATH ) + { + return ( 0 ); + } + + strncpy(absPathName, dirName, dwDirLength +1); + strncpy(absPathName, szPathDelimA, 2); + strncpy(absPathName, fileName, dwFileLength +1); + + return (sizeAPN); + +} + +int __cdecl main( int argc, char **argv ) +{ + + static FILE * fp; + + DWORD dwFileLength; + DWORD dwDirLength; + DWORD dwSize; + + char szDirNameA[_MAX_DIR]; + char szAbsPathNameA[_MAX_PATH]; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + dwDirLength = GetCurrentDirectory( _MAX_PATH, szDirNameA ); + + if (0 == dwDirLength) + { + Fail ("GetCurrentDirectory call failed. Could not get " + "current working directory\n. Exiting.\n"); + } + + dwFileLength = strlen( szCommonFileA ); + + dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szCommonFileA, + dwFileLength, szAbsPathNameA ); + + if (0 == dwSize) + { + Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " + "not build absolute path name to file\n. Exiting.\n"); + } + + if ( NULL == ( fp = fopen ( szAbsPathNameA , "w+" ) ) ) + { + /* + * A return value of NULL indicates an error condition or an + * EOF condition + */ + Fail ("%s unable to open %s for writing. Exiting.\n", argv[0] + , szAbsPathNameA ); + } + + if ( 0 >= ( fprintf ( fp, "%s", szCommonStringA ))) + { + Fail("%s unable to write to %s. Exiting.\n", argv[0] + , szAbsPathNameA ); + } + + if (0 != (fclose ( fp ))) + { + Fail ("%s unable to close file %s. Pid may not be " + "written to file. Exiting.\n", argv[0], szAbsPathNameA ); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test1/parentProcess.c b/src/pal/tests/palsuite/threading/CreateProcessA/test1/parentProcess.c deleted file mode 100644 index b0c5808a7e..0000000000 --- a/src/pal/tests/palsuite/threading/CreateProcessA/test1/parentProcess.c +++ /dev/null @@ -1,201 +0,0 @@ -// 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: CreateProcessA/test1/parentprocess.c -** -** Purpose: Test to ensure CreateProcessA starts a new process. This test -** launches a child process, and examines a file written by the child. -** This process (the parent process) reads the file created by the child and -** compares the value the child wrote to the file. (a const char *) -** -** Dependencies: GetCurrentDirectory -** strlen -** WaitForSingleObject -** fopen -** fclose -** Fail -** - -** -**=========================================================*/ - -#include - -const char *szCommonFileA = "childdata.tmp"; - -const char *szChildFileA = "paltest_createprocessa_test1_child"; - -const char *szPathDelimA = "\\"; - -const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0"; - -/* - * Take two wide strings representing file and directory names - * (dirName, fileName), join the strings with the appropriate path - * delimiter and populate a wide character buffer (absPathName) with - * the resulting string. - * - * Returns: The number of wide characters in the resulting string. - * 0 is returned on Error. - */ -int -mkAbsoluteFilenameA ( - LPSTR dirName, - DWORD dwDirLength, - LPCSTR fileName, - DWORD dwFileLength, - LPSTR absPathName ) -{ - extern const char *szPathDelimA; - - DWORD sizeDN, sizeFN, sizeAPN; - - sizeDN = strlen( dirName ); - sizeFN = strlen( fileName ); - sizeAPN = (sizeDN + 1 + sizeFN + 1); - - /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ - if ( sizeAPN > _MAX_PATH ) - { - return ( 0 ); - } - - strncpy(absPathName, dirName, dwDirLength +1); - strncpy(absPathName, szPathDelimA, 2); - strncpy(absPathName, fileName, dwFileLength +1); - - return (sizeAPN); - -} - -int __cdecl main( int argc, char **argv ) - -{ - - STARTUPINFO si; - PROCESS_INFORMATION pi; - - static FILE * fp; - - DWORD dwFileLength; - DWORD dwDirLength; - DWORD dwSize; - - size_t cslen; - - char szReadStringA[256]; - - char szDirNameA[_MAX_DIR]; - char absPathBuf[_MAX_PATH]; - char *szAbsPathNameA; - - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - ZeroMemory ( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory ( &pi, sizeof(pi) ); - - szAbsPathNameA=&absPathBuf[0]; - dwFileLength = strlen( szChildFileA ); - - dwDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameA); - - if (0 == dwDirLength) - { - Fail ("GetCurrentDirectory call failed. Could not get " - "current working directory\n. Exiting.\n"); - } - - dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szChildFileA, - dwFileLength, szAbsPathNameA ); - - if (0 == dwSize) - { - Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " - "not build absolute path name to file\n. Exiting.\n"); - } - - if ( !CreateProcessA ( NULL, - szAbsPathNameA, - NULL, - NULL, - FALSE, - CREATE_NEW_CONSOLE, - NULL, - NULL, - &si, - &pi ) - ) - { - Fail ( "CreateProcess call failed. GetLastError returned %d\n", - GetLastError() ); - } - - WaitForSingleObject ( pi.hProcess, INFINITE ); - - szAbsPathNameA=&absPathBuf[0]; - - dwFileLength = strlen( szCommonFileA ); - - dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szCommonFileA, - dwFileLength, szAbsPathNameA ); - - /* set the string length for the open call*/ - - if (0 == dwSize) - { - Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " - "not build absolute path name to file\n. Exiting.\n"); - } - - if ( NULL == ( fp = fopen ( szAbsPathNameA , "r" ) ) ) - { - Fail ("%s\nunable to open %s\nfor reading. Exiting.\n", argv[0], - szAbsPathNameA ); - } - - cslen = strlen ( szCommonStringA ); - - if ( NULL == fgets( szReadStringA, (cslen + 1), fp )) - { - /* - * A return value of NULL indicates an error condition or an - * EOF condition - */ - Fail ("%s\nunable to read file\n%s\nszReadStringA is %s\n" - "Exiting.\n", argv[0], szAbsPathNameA, - szReadStringA ); - - } - if ( 0 != strncmp( szReadStringA, szCommonStringA, cslen )) - { - Fail ("string comparison failed.\n szReadStringA is %s and\n" - "szCommonStringA is %s\n", szReadStringA, - szCommonStringA ); - } - else - { - Trace ("string comparison passed.\n"); - } - - if (0 != (fclose ( fp ))) - { - Trace ("%s unable to close file %s. This may cause a file pointer " - "leak. Continuing.\n", argv[0], szAbsPathNameA ); - } - - /* Close process and thread handle */ - CloseHandle ( pi.hProcess ); - CloseHandle ( pi.hThread ); - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test1/parentProcess.cpp b/src/pal/tests/palsuite/threading/CreateProcessA/test1/parentProcess.cpp new file mode 100644 index 0000000000..b0c5808a7e --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateProcessA/test1/parentProcess.cpp @@ -0,0 +1,201 @@ +// 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: CreateProcessA/test1/parentprocess.c +** +** Purpose: Test to ensure CreateProcessA starts a new process. This test +** launches a child process, and examines a file written by the child. +** This process (the parent process) reads the file created by the child and +** compares the value the child wrote to the file. (a const char *) +** +** Dependencies: GetCurrentDirectory +** strlen +** WaitForSingleObject +** fopen +** fclose +** Fail +** + +** +**=========================================================*/ + +#include + +const char *szCommonFileA = "childdata.tmp"; + +const char *szChildFileA = "paltest_createprocessa_test1_child"; + +const char *szPathDelimA = "\\"; + +const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0"; + +/* + * Take two wide strings representing file and directory names + * (dirName, fileName), join the strings with the appropriate path + * delimiter and populate a wide character buffer (absPathName) with + * the resulting string. + * + * Returns: The number of wide characters in the resulting string. + * 0 is returned on Error. + */ +int +mkAbsoluteFilenameA ( + LPSTR dirName, + DWORD dwDirLength, + LPCSTR fileName, + DWORD dwFileLength, + LPSTR absPathName ) +{ + extern const char *szPathDelimA; + + DWORD sizeDN, sizeFN, sizeAPN; + + sizeDN = strlen( dirName ); + sizeFN = strlen( fileName ); + sizeAPN = (sizeDN + 1 + sizeFN + 1); + + /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ + if ( sizeAPN > _MAX_PATH ) + { + return ( 0 ); + } + + strncpy(absPathName, dirName, dwDirLength +1); + strncpy(absPathName, szPathDelimA, 2); + strncpy(absPathName, fileName, dwFileLength +1); + + return (sizeAPN); + +} + +int __cdecl main( int argc, char **argv ) + +{ + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + static FILE * fp; + + DWORD dwFileLength; + DWORD dwDirLength; + DWORD dwSize; + + size_t cslen; + + char szReadStringA[256]; + + char szDirNameA[_MAX_DIR]; + char absPathBuf[_MAX_PATH]; + char *szAbsPathNameA; + + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + ZeroMemory ( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory ( &pi, sizeof(pi) ); + + szAbsPathNameA=&absPathBuf[0]; + dwFileLength = strlen( szChildFileA ); + + dwDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameA); + + if (0 == dwDirLength) + { + Fail ("GetCurrentDirectory call failed. Could not get " + "current working directory\n. Exiting.\n"); + } + + dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szChildFileA, + dwFileLength, szAbsPathNameA ); + + if (0 == dwSize) + { + Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " + "not build absolute path name to file\n. Exiting.\n"); + } + + if ( !CreateProcessA ( NULL, + szAbsPathNameA, + NULL, + NULL, + FALSE, + CREATE_NEW_CONSOLE, + NULL, + NULL, + &si, + &pi ) + ) + { + Fail ( "CreateProcess call failed. GetLastError returned %d\n", + GetLastError() ); + } + + WaitForSingleObject ( pi.hProcess, INFINITE ); + + szAbsPathNameA=&absPathBuf[0]; + + dwFileLength = strlen( szCommonFileA ); + + dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szCommonFileA, + dwFileLength, szAbsPathNameA ); + + /* set the string length for the open call*/ + + if (0 == dwSize) + { + Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " + "not build absolute path name to file\n. Exiting.\n"); + } + + if ( NULL == ( fp = fopen ( szAbsPathNameA , "r" ) ) ) + { + Fail ("%s\nunable to open %s\nfor reading. Exiting.\n", argv[0], + szAbsPathNameA ); + } + + cslen = strlen ( szCommonStringA ); + + if ( NULL == fgets( szReadStringA, (cslen + 1), fp )) + { + /* + * A return value of NULL indicates an error condition or an + * EOF condition + */ + Fail ("%s\nunable to read file\n%s\nszReadStringA is %s\n" + "Exiting.\n", argv[0], szAbsPathNameA, + szReadStringA ); + + } + if ( 0 != strncmp( szReadStringA, szCommonStringA, cslen )) + { + Fail ("string comparison failed.\n szReadStringA is %s and\n" + "szCommonStringA is %s\n", szReadStringA, + szCommonStringA ); + } + else + { + Trace ("string comparison passed.\n"); + } + + if (0 != (fclose ( fp ))) + { + Trace ("%s unable to close file %s. This may cause a file pointer " + "leak. Continuing.\n", argv[0], szAbsPathNameA ); + } + + /* Close process and thread handle */ + CloseHandle ( pi.hProcess ); + CloseHandle ( pi.hThread ); + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateProcessA/test2/CMakeLists.txt index b81ea2e978..f035f0a888 100644 --- a/src/pal/tests/palsuite/threading/CreateProcessA/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateProcessA/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - parentprocess.c + parentprocess.cpp ) add_executable(paltest_createprocessa_test2 @@ -20,7 +20,7 @@ target_link_libraries(paltest_createprocessa_test2 set(HELPERSOURCES - childprocess.c + childprocess.cpp ) add_executable(paltest_createprocessa_test2_child diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test2/childprocess.c b/src/pal/tests/palsuite/threading/CreateProcessA/test2/childprocess.c deleted file mode 100644 index baa20c2d3c..0000000000 --- a/src/pal/tests/palsuite/threading/CreateProcessA/test2/childprocess.c +++ /dev/null @@ -1,69 +0,0 @@ -// 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: createprocessa/test2/childprocess.c -** -** Purpose: This child process reads a string from stdin -** and writes it out to stdout & stderr -** -** Dependencies: memset -** fgets -** gputs -** - -** -**=========================================================*/ - -#include -#include "test2.h" - - - -int __cdecl main( int argc, char **argv ) -{ - int iRetCode = EXIT_OK_CODE; /* preset exit code to OK */ - char szBuf[BUF_LEN]; - - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if (argc != 4) - { - return EXIT_ERR_CODE3; - } - - if (strcmp(argv[1], szArg1) != 0 - || strcmp(argv[2], szArg2) != 0 - || strcmp(argv[3], szArg3) != 0) - { - return EXIT_ERR_CODE4; - } - - - memset(szBuf, 0, BUF_LEN); - - /* Read the string that was written by the parent */ - if (fgets(szBuf, BUF_LEN, stdin) == NULL) - { - return EXIT_ERR_CODE1; - } - - /* Write the string out to the stdout & stderr pipes */ - if (fputs(szBuf, stdout) == EOF - || fputs(szBuf, stderr) == EOF) - { - return EXIT_ERR_CODE2; - } - - /* The exit code will indicate success or failure */ - PAL_TerminateEx(iRetCode); - - /* Return special exit code to indicate success or failure */ - return iRetCode; -} diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test2/childprocess.cpp b/src/pal/tests/palsuite/threading/CreateProcessA/test2/childprocess.cpp new file mode 100644 index 0000000000..baa20c2d3c --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateProcessA/test2/childprocess.cpp @@ -0,0 +1,69 @@ +// 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: createprocessa/test2/childprocess.c +** +** Purpose: This child process reads a string from stdin +** and writes it out to stdout & stderr +** +** Dependencies: memset +** fgets +** gputs +** + +** +**=========================================================*/ + +#include +#include "test2.h" + + + +int __cdecl main( int argc, char **argv ) +{ + int iRetCode = EXIT_OK_CODE; /* preset exit code to OK */ + char szBuf[BUF_LEN]; + + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + if (argc != 4) + { + return EXIT_ERR_CODE3; + } + + if (strcmp(argv[1], szArg1) != 0 + || strcmp(argv[2], szArg2) != 0 + || strcmp(argv[3], szArg3) != 0) + { + return EXIT_ERR_CODE4; + } + + + memset(szBuf, 0, BUF_LEN); + + /* Read the string that was written by the parent */ + if (fgets(szBuf, BUF_LEN, stdin) == NULL) + { + return EXIT_ERR_CODE1; + } + + /* Write the string out to the stdout & stderr pipes */ + if (fputs(szBuf, stdout) == EOF + || fputs(szBuf, stderr) == EOF) + { + return EXIT_ERR_CODE2; + } + + /* The exit code will indicate success or failure */ + PAL_TerminateEx(iRetCode); + + /* Return special exit code to indicate success or failure */ + return iRetCode; +} diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test2/parentprocess.c b/src/pal/tests/palsuite/threading/CreateProcessA/test2/parentprocess.c deleted file mode 100644 index ef3340c5d9..0000000000 --- a/src/pal/tests/palsuite/threading/CreateProcessA/test2/parentprocess.c +++ /dev/null @@ -1,243 +0,0 @@ -// 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: createprocessa/test2/parentprocess.c -** -** Purpose: Test the following features of CreateProcessA: -** - Check to see if hProcess & hThread are set in -** return PROCESS_INFORMATION structure -** - Check to see if stdin, stdout, & stderr handles -** are used when STARTF_USESTDHANDLES is specified -** in STARUPINFO flags and bInheritHandles = TRUE -** - Check to see that proper arguments are passed to -** child process -** -** Dependencies: CreatePipe -** strcpy, strlen, strncmp, memset -** WaitForSingleObject -** WriteFile, ReadFile -** GetExitCodeProcess -** - -** -**=========================================================*/ - -#include -#include "test2.h" - - - -int __cdecl main( int argc, char **argv ) -{ - - /******************************************* - * Declarations - *******************************************/ - STARTUPINFO si; - PROCESS_INFORMATION pi; - - HANDLE hTestStdInR = NULL; - HANDLE hTestStdInW = NULL; - HANDLE hTestStdOutR = NULL; - HANDLE hTestStdOutW = NULL; - HANDLE hTestStdErrR = NULL; - HANDLE hTestStdErrW = NULL; - - BOOL bRetVal = FALSE; - DWORD dwBytesWritten = 0; - DWORD dwBytesRead = 0; - DWORD dwExitCode = 0; - - SECURITY_ATTRIBUTES pipeAttributes; - - char szStdOutBuf[BUF_LEN]; - char szStdErrBuf[BUF_LEN]; - char szFullPathNameA[_MAX_PATH]; - - - /******************************************* - * Initialization - *******************************************/ - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - pipeAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); - pipeAttributes.lpSecurityDescriptor = NULL; - pipeAttributes.bInheritHandle = TRUE; - - - /*Create a StdIn pipe for child*/ - bRetVal = CreatePipe(&hTestStdInR, /* read handle*/ - &hTestStdInW, /* write handle */ - &pipeAttributes, /* security attributes*/ - 1024); /* pipe size*/ - - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :Unable to create stdin pipe\n", GetLastError()); - } - - - /*Create a StdOut pipe for child*/ - bRetVal = CreatePipe(&hTestStdOutR, /* read handle*/ - &hTestStdOutW, /* write handle */ - &pipeAttributes, /* security attributes*/ - 0); /* pipe size*/ - - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :Unable to create stdout pipe\n", GetLastError()); - } - - - /*Create a StdErr pipe for child*/ - bRetVal = CreatePipe(&hTestStdErrR, /* read handle*/ - &hTestStdErrW, /* write handle */ - &pipeAttributes, /* security attributes*/ - 0); /* pipe size*/ - - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :Unable to create stderr pipe\n", GetLastError()); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi, sizeof(pi) ); - ZeroMemory ( &si, sizeof(si) ); - - /* Set the process flags and standard io handles */ - si.cb = sizeof(si); - si.dwFlags = STARTF_USESTDHANDLES; - si.hStdInput = hTestStdInR; - si.hStdOutput = hTestStdOutW; - si.hStdError = hTestStdErrW; - - strcpy(szFullPathNameA, szChildFileA); - strcat(szFullPathNameA, szArgs); - - /******************************************* - * Start Testing - *******************************************/ - - /* Launch the child */ - if ( !CreateProcessA (NULL, szFullPathNameA, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi )) - { - Fail("ERROR: CreateProcess call failed. GetLastError returned %d\n", - GetLastError() ); - } - - /* Check the returned process information for validity */ - if (pi.hProcess == 0 || pi.hThread == 0) - { - Fail("ERROR: CreateProcess Error: Process Handle = %u, Thread Handle = %u\n", - pi.hProcess, pi.hThread); - } - - /* Write the Constructed string to stdin pipe for the child process */ - if (WriteFile(hTestStdInW, szTestString, strlen(szTestString), &dwBytesWritten, NULL) == FALSE - || WriteFile(hTestStdInW, "\n", strlen("\n"), &dwBytesWritten, NULL) == FALSE) - { - Fail("ERROR: %ld :unable to write to write pipe handle " - "hTestStdInW=0x%lx\n", GetLastError(), hTestStdInW); - } - - /* Wait for the child to finish, Max 20 seconds */ - dwExitCode = WaitForSingleObject(pi.hProcess, 20000); - - /* If the child failed then whole thing fails */ - if (dwExitCode != WAIT_OBJECT_0) - { - TerminateProcess(pi.hProcess, 0); - Fail("ERROR: The child failed to run properly.\n"); - } - - /* Check for problems in the child process */ - if (GetExitCodeProcess(pi.hProcess, &dwExitCode) == FALSE) - { - Fail("ERROR: Call to GetExitCodeProcess failed.\n"); - } - else if (dwExitCode == EXIT_ERR_CODE1) - { - Fail("ERROR: The Child process could not reead the string " - "written to the stdin pipe.\n"); - } - else if (dwExitCode == EXIT_ERR_CODE2) - { - Fail("ERROR: The Child process could not write the string " - "the stdout pipe or stderr pipe.\n"); - } - else if (dwExitCode == EXIT_ERR_CODE3) - { - Fail("ERROR: The Child received the wrong number of " - "command line arguments.\n"); - } - else if (dwExitCode == EXIT_ERR_CODE4) - { - Fail("ERROR: The Child received the wrong " - "command line arguments.\n"); - } - else if (dwExitCode != EXIT_OK_CODE) - { - Fail("ERROR: Unexpected exit code returned: %u. Child process " - "did not complete its part of the test.\n", dwExitCode); - } - - - /* The child ran ok, so check to see if we received the proper */ - /* strings through the pipes. */ - - /* clear our buffers */ - memset(szStdOutBuf, 0, BUF_LEN); - memset(szStdErrBuf, 0, BUF_LEN); - - /* Read the data back from the child process stdout */ - bRetVal = ReadFile(hTestStdOutR, /* handle to read pipe*/ - szStdOutBuf, /* buffer to write to*/ - BUF_LEN, /* number of bytes to read*/ - &dwBytesRead, /* number of bytes read*/ - NULL); /* overlapped buffer*/ - - /*Read the data back from the child process stderr */ - bRetVal = ReadFile(hTestStdErrR, /* handle to read pipe*/ - szStdErrBuf, /* buffer to write to*/ - BUF_LEN, /* number of bytes to read*/ - &dwBytesRead, /* number of bytes read*/ - NULL); /* overlapped buffer*/ - - - /* Confirm that we recieved the same string that we originally */ - /* wrote to the child and was received on both stdout & stderr.*/ - if (strncmp(szTestString, szStdOutBuf, strlen(szTestString)) != 0 - || strncmp(szTestString, szStdErrBuf, strlen(szTestString)) != 0) - { - Fail("ERROR: The data read back from child does not match " - "what was written. STDOUT: %s STDERR: %s\n", - szStdOutBuf, szStdErrBuf); - } - - - /******************************************* - * Clean Up - *******************************************/ - - /* Close process and thread handle */ - CloseHandle ( pi.hProcess ); - CloseHandle ( pi.hThread ); - - CloseHandle(hTestStdInR); - CloseHandle(hTestStdInW); - CloseHandle(hTestStdOutR); - CloseHandle(hTestStdOutW); - CloseHandle(hTestStdErrR); - CloseHandle(hTestStdErrW); - - PAL_Terminate(); - return ( PASS ); -} diff --git a/src/pal/tests/palsuite/threading/CreateProcessA/test2/parentprocess.cpp b/src/pal/tests/palsuite/threading/CreateProcessA/test2/parentprocess.cpp new file mode 100644 index 0000000000..ef3340c5d9 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateProcessA/test2/parentprocess.cpp @@ -0,0 +1,243 @@ +// 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: createprocessa/test2/parentprocess.c +** +** Purpose: Test the following features of CreateProcessA: +** - Check to see if hProcess & hThread are set in +** return PROCESS_INFORMATION structure +** - Check to see if stdin, stdout, & stderr handles +** are used when STARTF_USESTDHANDLES is specified +** in STARUPINFO flags and bInheritHandles = TRUE +** - Check to see that proper arguments are passed to +** child process +** +** Dependencies: CreatePipe +** strcpy, strlen, strncmp, memset +** WaitForSingleObject +** WriteFile, ReadFile +** GetExitCodeProcess +** + +** +**=========================================================*/ + +#include +#include "test2.h" + + + +int __cdecl main( int argc, char **argv ) +{ + + /******************************************* + * Declarations + *******************************************/ + STARTUPINFO si; + PROCESS_INFORMATION pi; + + HANDLE hTestStdInR = NULL; + HANDLE hTestStdInW = NULL; + HANDLE hTestStdOutR = NULL; + HANDLE hTestStdOutW = NULL; + HANDLE hTestStdErrR = NULL; + HANDLE hTestStdErrW = NULL; + + BOOL bRetVal = FALSE; + DWORD dwBytesWritten = 0; + DWORD dwBytesRead = 0; + DWORD dwExitCode = 0; + + SECURITY_ATTRIBUTES pipeAttributes; + + char szStdOutBuf[BUF_LEN]; + char szStdErrBuf[BUF_LEN]; + char szFullPathNameA[_MAX_PATH]; + + + /******************************************* + * Initialization + *******************************************/ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + pipeAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); + pipeAttributes.lpSecurityDescriptor = NULL; + pipeAttributes.bInheritHandle = TRUE; + + + /*Create a StdIn pipe for child*/ + bRetVal = CreatePipe(&hTestStdInR, /* read handle*/ + &hTestStdInW, /* write handle */ + &pipeAttributes, /* security attributes*/ + 1024); /* pipe size*/ + + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :Unable to create stdin pipe\n", GetLastError()); + } + + + /*Create a StdOut pipe for child*/ + bRetVal = CreatePipe(&hTestStdOutR, /* read handle*/ + &hTestStdOutW, /* write handle */ + &pipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :Unable to create stdout pipe\n", GetLastError()); + } + + + /*Create a StdErr pipe for child*/ + bRetVal = CreatePipe(&hTestStdErrR, /* read handle*/ + &hTestStdErrW, /* write handle */ + &pipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :Unable to create stderr pipe\n", GetLastError()); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi, sizeof(pi) ); + ZeroMemory ( &si, sizeof(si) ); + + /* Set the process flags and standard io handles */ + si.cb = sizeof(si); + si.dwFlags = STARTF_USESTDHANDLES; + si.hStdInput = hTestStdInR; + si.hStdOutput = hTestStdOutW; + si.hStdError = hTestStdErrW; + + strcpy(szFullPathNameA, szChildFileA); + strcat(szFullPathNameA, szArgs); + + /******************************************* + * Start Testing + *******************************************/ + + /* Launch the child */ + if ( !CreateProcessA (NULL, szFullPathNameA, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi )) + { + Fail("ERROR: CreateProcess call failed. GetLastError returned %d\n", + GetLastError() ); + } + + /* Check the returned process information for validity */ + if (pi.hProcess == 0 || pi.hThread == 0) + { + Fail("ERROR: CreateProcess Error: Process Handle = %u, Thread Handle = %u\n", + pi.hProcess, pi.hThread); + } + + /* Write the Constructed string to stdin pipe for the child process */ + if (WriteFile(hTestStdInW, szTestString, strlen(szTestString), &dwBytesWritten, NULL) == FALSE + || WriteFile(hTestStdInW, "\n", strlen("\n"), &dwBytesWritten, NULL) == FALSE) + { + Fail("ERROR: %ld :unable to write to write pipe handle " + "hTestStdInW=0x%lx\n", GetLastError(), hTestStdInW); + } + + /* Wait for the child to finish, Max 20 seconds */ + dwExitCode = WaitForSingleObject(pi.hProcess, 20000); + + /* If the child failed then whole thing fails */ + if (dwExitCode != WAIT_OBJECT_0) + { + TerminateProcess(pi.hProcess, 0); + Fail("ERROR: The child failed to run properly.\n"); + } + + /* Check for problems in the child process */ + if (GetExitCodeProcess(pi.hProcess, &dwExitCode) == FALSE) + { + Fail("ERROR: Call to GetExitCodeProcess failed.\n"); + } + else if (dwExitCode == EXIT_ERR_CODE1) + { + Fail("ERROR: The Child process could not reead the string " + "written to the stdin pipe.\n"); + } + else if (dwExitCode == EXIT_ERR_CODE2) + { + Fail("ERROR: The Child process could not write the string " + "the stdout pipe or stderr pipe.\n"); + } + else if (dwExitCode == EXIT_ERR_CODE3) + { + Fail("ERROR: The Child received the wrong number of " + "command line arguments.\n"); + } + else if (dwExitCode == EXIT_ERR_CODE4) + { + Fail("ERROR: The Child received the wrong " + "command line arguments.\n"); + } + else if (dwExitCode != EXIT_OK_CODE) + { + Fail("ERROR: Unexpected exit code returned: %u. Child process " + "did not complete its part of the test.\n", dwExitCode); + } + + + /* The child ran ok, so check to see if we received the proper */ + /* strings through the pipes. */ + + /* clear our buffers */ + memset(szStdOutBuf, 0, BUF_LEN); + memset(szStdErrBuf, 0, BUF_LEN); + + /* Read the data back from the child process stdout */ + bRetVal = ReadFile(hTestStdOutR, /* handle to read pipe*/ + szStdOutBuf, /* buffer to write to*/ + BUF_LEN, /* number of bytes to read*/ + &dwBytesRead, /* number of bytes read*/ + NULL); /* overlapped buffer*/ + + /*Read the data back from the child process stderr */ + bRetVal = ReadFile(hTestStdErrR, /* handle to read pipe*/ + szStdErrBuf, /* buffer to write to*/ + BUF_LEN, /* number of bytes to read*/ + &dwBytesRead, /* number of bytes read*/ + NULL); /* overlapped buffer*/ + + + /* Confirm that we recieved the same string that we originally */ + /* wrote to the child and was received on both stdout & stderr.*/ + if (strncmp(szTestString, szStdOutBuf, strlen(szTestString)) != 0 + || strncmp(szTestString, szStdErrBuf, strlen(szTestString)) != 0) + { + Fail("ERROR: The data read back from child does not match " + "what was written. STDOUT: %s STDERR: %s\n", + szStdOutBuf, szStdErrBuf); + } + + + /******************************************* + * Clean Up + *******************************************/ + + /* Close process and thread handle */ + CloseHandle ( pi.hProcess ); + CloseHandle ( pi.hThread ); + + CloseHandle(hTestStdInR); + CloseHandle(hTestStdInW); + CloseHandle(hTestStdOutR); + CloseHandle(hTestStdOutW); + CloseHandle(hTestStdErrR); + CloseHandle(hTestStdErrW); + + PAL_Terminate(); + return ( PASS ); +} diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateProcessW/test1/CMakeLists.txt index 394b124526..174d6fe3c7 100644 --- a/src/pal/tests/palsuite/threading/CreateProcessW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateProcessW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - parentProcess.c + parentProcess.cpp ) add_executable(paltest_createprocessw_test1 @@ -20,7 +20,7 @@ target_link_libraries(paltest_createprocessw_test1 set(HELPERSOURCES - childProcess.c + childProcess.cpp ) add_executable(paltest_createprocessw_test1_child diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test1/childProcess.c b/src/pal/tests/palsuite/threading/CreateProcessW/test1/childProcess.c deleted file mode 100644 index c71f967b65..0000000000 --- a/src/pal/tests/palsuite/threading/CreateProcessW/test1/childProcess.c +++ /dev/null @@ -1,150 +0,0 @@ -// 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: CreateProcessW/test1/childprocess.c -** -** Purpose: Test to ensure CreateProcessW starts a new process. This test -** launches a child process, and examines a file written by the child. -** This code is the child code. -** -** Dependencies: GetCurrentDirectory -** MultiByteToWideChar -** wcslen -** strlen -** WideCharToMultiByte -** fopen -** fclose -** fprintf -** - -** -**=========================================================*/ - -#define UNICODE -#include - -const WCHAR szCommonFileW[] = - {'c','h','i','l','d','d','a','t','a','.','t','m','p','\0'}; - -const WCHAR szPathDelimW[] = {'\\','\0'}; - -const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0"; - -/* - * Take two wide strings representing file and directory names - * (dirName, fileName), join the strings with the appropriate path - * delimiter and populate a wide character buffer (absPathName) with - * the resulting string. - * - * Returns: The number of wide characters in the resulting string. - * 0 is returned on Error. - */ -int -mkAbsoluteFilenameW ( - LPWSTR dirName, - DWORD dwDirLength, - LPCWSTR fileName, - DWORD dwFileLength, - LPWSTR absPathName ) -{ - extern const WCHAR szPathDelimW[]; - - DWORD sizeDN, sizeFN, sizeAPN; - - sizeDN = wcslen( dirName ); - sizeFN = wcslen( fileName ); - sizeAPN = (sizeDN + 1 + sizeFN + 1); - - /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ - if ( sizeAPN > _MAX_PATH ) - { - return ( 0 ); - } - - wcsncpy(absPathName, dirName, dwDirLength +1); - wcsncpy(absPathName, szPathDelimW, 2); - wcsncpy(absPathName, fileName, dwFileLength +1); - - return (sizeAPN); - -} - -int __cdecl main( int argc, char **argv ) -{ - - static FILE * fp; - - DWORD dwFileLength; - DWORD dwDirLength; - DWORD dwSize; - - char *szAbsPathNameA; - WCHAR szDirNameW[_MAX_DIR]; - WCHAR szAbsPathNameW[_MAX_PATH]; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - dwDirLength = GetCurrentDirectory( _MAX_PATH, szDirNameW ); - - if (0 == dwDirLength) - { - Fail ("GetCurrentDirectory call failed. Could not get " - "current working directory\n. Exiting.\n"); - } - - dwFileLength = wcslen( szCommonFileW ); - - dwSize = mkAbsoluteFilenameW( szDirNameW, dwDirLength, szCommonFileW, - dwFileLength, szAbsPathNameW ); - - if (0 == dwSize) - { - Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " - "not build absolute path name to file\n. Exiting.\n"); - } - - /* set the string length for the open call */ - szAbsPathNameA = malloc (dwSize +1); - - if (NULL == szAbsPathNameA) - { - Fail ("Unable to malloc (%d) bytes. Exiting\n", (dwSize +1) ); - } - - WideCharToMultiByte (CP_ACP, 0, szAbsPathNameW, -1, szAbsPathNameA, - (dwSize + 1), NULL, NULL); - - if ( NULL == ( fp = fopen ( szAbsPathNameA , "w+" ) ) ) - { - /* - * A return value of NULL indicates an error condition or an - * EOF condition - */ - Fail ("%s unable to open %s for writing. Exiting.\n", argv[0] - , szAbsPathNameA ); - } - - free (szAbsPathNameA); - - if ( 0 >= ( fprintf ( fp, "%s", szCommonStringA ))) - { - Fail("%s unable to write to %s. Exiting.\n", argv[0] - , szAbsPathNameA ); - } - - if (0 != (fclose ( fp ))) - { - Fail ("%s unable to close file %s. Pid may not be " - "written to file. Exiting.\n", argv[0], szAbsPathNameA ); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test1/childProcess.cpp b/src/pal/tests/palsuite/threading/CreateProcessW/test1/childProcess.cpp new file mode 100644 index 0000000000..a7730c6d51 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateProcessW/test1/childProcess.cpp @@ -0,0 +1,150 @@ +// 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: CreateProcessW/test1/childprocess.c +** +** Purpose: Test to ensure CreateProcessW starts a new process. This test +** launches a child process, and examines a file written by the child. +** This code is the child code. +** +** Dependencies: GetCurrentDirectory +** MultiByteToWideChar +** wcslen +** strlen +** WideCharToMultiByte +** fopen +** fclose +** fprintf +** + +** +**=========================================================*/ + +#define UNICODE +#include + +const WCHAR szCommonFileW[] = + {'c','h','i','l','d','d','a','t','a','.','t','m','p','\0'}; + +const WCHAR szPathDelimW[] = {'\\','\0'}; + +const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0"; + +/* + * Take two wide strings representing file and directory names + * (dirName, fileName), join the strings with the appropriate path + * delimiter and populate a wide character buffer (absPathName) with + * the resulting string. + * + * Returns: The number of wide characters in the resulting string. + * 0 is returned on Error. + */ +int +mkAbsoluteFilenameW ( + LPWSTR dirName, + DWORD dwDirLength, + LPCWSTR fileName, + DWORD dwFileLength, + LPWSTR absPathName ) +{ + extern const WCHAR szPathDelimW[]; + + DWORD sizeDN, sizeFN, sizeAPN; + + sizeDN = wcslen( dirName ); + sizeFN = wcslen( fileName ); + sizeAPN = (sizeDN + 1 + sizeFN + 1); + + /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ + if ( sizeAPN > _MAX_PATH ) + { + return ( 0 ); + } + + wcsncpy(absPathName, dirName, dwDirLength +1); + wcsncpy(absPathName, szPathDelimW, 2); + wcsncpy(absPathName, fileName, dwFileLength +1); + + return (sizeAPN); + +} + +int __cdecl main( int argc, char **argv ) +{ + + static FILE * fp; + + DWORD dwFileLength; + DWORD dwDirLength; + DWORD dwSize; + + char *szAbsPathNameA; + WCHAR szDirNameW[_MAX_DIR]; + WCHAR szAbsPathNameW[_MAX_PATH]; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + dwDirLength = GetCurrentDirectory( _MAX_PATH, szDirNameW ); + + if (0 == dwDirLength) + { + Fail ("GetCurrentDirectory call failed. Could not get " + "current working directory\n. Exiting.\n"); + } + + dwFileLength = wcslen( szCommonFileW ); + + dwSize = mkAbsoluteFilenameW( szDirNameW, dwDirLength, szCommonFileW, + dwFileLength, szAbsPathNameW ); + + if (0 == dwSize) + { + Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " + "not build absolute path name to file\n. Exiting.\n"); + } + + /* set the string length for the open call */ + szAbsPathNameA = (char*)malloc(dwSize +1); + + if (NULL == szAbsPathNameA) + { + Fail ("Unable to malloc (%d) bytes. Exiting\n", (dwSize +1) ); + } + + WideCharToMultiByte (CP_ACP, 0, szAbsPathNameW, -1, szAbsPathNameA, + (dwSize + 1), NULL, NULL); + + if ( NULL == ( fp = fopen ( szAbsPathNameA , "w+" ) ) ) + { + /* + * A return value of NULL indicates an error condition or an + * EOF condition + */ + Fail ("%s unable to open %s for writing. Exiting.\n", argv[0] + , szAbsPathNameA ); + } + + free (szAbsPathNameA); + + if ( 0 >= ( fprintf ( fp, "%s", szCommonStringA ))) + { + Fail("%s unable to write to %s. Exiting.\n", argv[0] + , szAbsPathNameA ); + } + + if (0 != (fclose ( fp ))) + { + Fail ("%s unable to close file %s. Pid may not be " + "written to file. Exiting.\n", argv[0], szAbsPathNameA ); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test1/parentProcess.c b/src/pal/tests/palsuite/threading/CreateProcessW/test1/parentProcess.c deleted file mode 100644 index db1fb6356d..0000000000 --- a/src/pal/tests/palsuite/threading/CreateProcessW/test1/parentProcess.c +++ /dev/null @@ -1,210 +0,0 @@ -// 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: CreateProcessW/test1/parentprocess.c -** -** Purpose: Test to ensure CreateProcessW starts a new process. This test -** launches a child process, and examines a file written by the child. -** This process (the parent process) reads the file created by the child and -** compares the value the child wrote to the file. (a const char *) -** -** Dependencies: GetCurrentDirectory -** MultiByteToWideChar -** wcslen -** strlen -** WideCharToMultiByte -** WaitForSingleObject -** fopen -** fclose -** Fail -** - -** -**=========================================================*/ - -#define UNICODE -#include - -const WCHAR szCommonFileW[] = - {'c','h','i','l','d','d','a','t','a','.','t','m','p','\0'}; - -const WCHAR szChildFileW[] = u"paltest_createprocessw_test1_child"; - -const WCHAR szPathDelimW[] = {'\\','\0'}; - -const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0"; - -/* - * Take two wide strings representing file and directory names - * (dirName, fileName), join the strings with the appropriate path - * delimiter and populate a wide character buffer (absPathName) with - * the resulting string. - * - * Returns: The number of wide characters in the resulting string. - * 0 is returned on Error. - */ -int -mkAbsoluteFilenameW ( - LPWSTR dirName, - DWORD dwDirLength, - LPCWSTR fileName, - DWORD dwFileLength, - LPWSTR absPathName ) -{ - extern const WCHAR szPathDelimW[]; - - DWORD sizeDN, sizeFN, sizeAPN; - - sizeDN = wcslen( dirName ); - sizeFN = wcslen( fileName ); - sizeAPN = (sizeDN + 1 + sizeFN + 1); - - /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ - if ( sizeAPN > _MAX_PATH ) - { - return ( 0 ); - } - - wcsncpy(absPathName, dirName, dwDirLength +1); - wcsncpy(absPathName, szPathDelimW, 2); - wcsncpy(absPathName, fileName, dwFileLength +1); - - return (sizeAPN); - -} - -int __cdecl main( int argc, char **argv ) - -{ - - STARTUPINFOW si; - PROCESS_INFORMATION pi; - - static FILE * fp; - - DWORD dwFileLength; - DWORD dwDirLength; - DWORD dwSize; - - size_t cslen; - - char szReadStringA[256]; - - char szAbsPathNameA[_MAX_PATH]; - WCHAR szDirNameW[_MAX_DIR]; - WCHAR absPathBuf[_MAX_PATH]; - WCHAR *szAbsPathNameW; - - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - ZeroMemory ( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory ( &pi, sizeof(pi) ); - - szAbsPathNameW=&absPathBuf[0]; - dwFileLength = wcslen( szChildFileW ); - - dwDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameW); - - if (0 == dwDirLength) - { - Fail ("GetCurrentDirectory call failed. Could not get " - "current working directory\n. Exiting.\n"); - } - - dwSize = mkAbsoluteFilenameW( szDirNameW, dwDirLength, szChildFileW, - dwFileLength, szAbsPathNameW ); - - if (0 == dwSize) - { - Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " - "not build absolute path name to file\n. Exiting.\n"); - } - - if ( !CreateProcessW ( NULL, - szAbsPathNameW, - NULL, - NULL, - FALSE, - CREATE_NEW_CONSOLE, - NULL, - NULL, - &si, - &pi ) - ) - { - Fail ( "CreateProcess call failed. GetLastError returned %d\n", - GetLastError() ); - } - - WaitForSingleObject ( pi.hProcess, INFINITE ); - - szAbsPathNameW=&absPathBuf[0]; - - dwFileLength = wcslen( szCommonFileW ); - - dwSize = mkAbsoluteFilenameW( szDirNameW, dwDirLength, szCommonFileW, - dwFileLength, szAbsPathNameW ); - - /* set the string length for the open call*/ - - if (0 == dwSize) - { - Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " - "not build absolute path name to file\n. Exiting.\n"); - } - - WideCharToMultiByte (CP_ACP, 0, szAbsPathNameW, -1, szAbsPathNameA, - (dwSize + 1), NULL, NULL); - - if ( NULL == ( fp = fopen ( szAbsPathNameA , "r" ) ) ) - { - Fail ("%s\nunable to open %s\nfor reading. Exiting.\n", argv[0], - szAbsPathNameA ); - } - - cslen = strlen ( szCommonStringA ); - - if ( NULL == fgets( szReadStringA, (cslen + 1), fp )) - { - /* - * A return value of NULL indicates an error condition or an - * EOF condition - */ - Fail ("%s\nunable to read file\n%s\nszReadStringA is %s\n" - "Exiting.\n", argv[0], szAbsPathNameA, - szReadStringA ); - } - - if ( 0 != strncmp( szReadStringA, szCommonStringA, cslen )) - { - Fail ("string comparison failed.\n szReadStringA is %s and\n" - "szCommonStringA is %s\n", szReadStringA, - szCommonStringA ); - } - else - { - Trace ("string comparison passed.\n"); - } - - if (0 != (fclose ( fp ))) - { - Trace ("%s unable to close file %s. This may cause a file pointer " - "leak. Continuing.\n", argv[0], szAbsPathNameA ); - } - - /* Close process and thread handle */ - CloseHandle ( pi.hProcess ); - CloseHandle ( pi.hThread ); - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test1/parentProcess.cpp b/src/pal/tests/palsuite/threading/CreateProcessW/test1/parentProcess.cpp new file mode 100644 index 0000000000..db1fb6356d --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateProcessW/test1/parentProcess.cpp @@ -0,0 +1,210 @@ +// 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: CreateProcessW/test1/parentprocess.c +** +** Purpose: Test to ensure CreateProcessW starts a new process. This test +** launches a child process, and examines a file written by the child. +** This process (the parent process) reads the file created by the child and +** compares the value the child wrote to the file. (a const char *) +** +** Dependencies: GetCurrentDirectory +** MultiByteToWideChar +** wcslen +** strlen +** WideCharToMultiByte +** WaitForSingleObject +** fopen +** fclose +** Fail +** + +** +**=========================================================*/ + +#define UNICODE +#include + +const WCHAR szCommonFileW[] = + {'c','h','i','l','d','d','a','t','a','.','t','m','p','\0'}; + +const WCHAR szChildFileW[] = u"paltest_createprocessw_test1_child"; + +const WCHAR szPathDelimW[] = {'\\','\0'}; + +const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0"; + +/* + * Take two wide strings representing file and directory names + * (dirName, fileName), join the strings with the appropriate path + * delimiter and populate a wide character buffer (absPathName) with + * the resulting string. + * + * Returns: The number of wide characters in the resulting string. + * 0 is returned on Error. + */ +int +mkAbsoluteFilenameW ( + LPWSTR dirName, + DWORD dwDirLength, + LPCWSTR fileName, + DWORD dwFileLength, + LPWSTR absPathName ) +{ + extern const WCHAR szPathDelimW[]; + + DWORD sizeDN, sizeFN, sizeAPN; + + sizeDN = wcslen( dirName ); + sizeFN = wcslen( fileName ); + sizeAPN = (sizeDN + 1 + sizeFN + 1); + + /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ + if ( sizeAPN > _MAX_PATH ) + { + return ( 0 ); + } + + wcsncpy(absPathName, dirName, dwDirLength +1); + wcsncpy(absPathName, szPathDelimW, 2); + wcsncpy(absPathName, fileName, dwFileLength +1); + + return (sizeAPN); + +} + +int __cdecl main( int argc, char **argv ) + +{ + + STARTUPINFOW si; + PROCESS_INFORMATION pi; + + static FILE * fp; + + DWORD dwFileLength; + DWORD dwDirLength; + DWORD dwSize; + + size_t cslen; + + char szReadStringA[256]; + + char szAbsPathNameA[_MAX_PATH]; + WCHAR szDirNameW[_MAX_DIR]; + WCHAR absPathBuf[_MAX_PATH]; + WCHAR *szAbsPathNameW; + + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + ZeroMemory ( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory ( &pi, sizeof(pi) ); + + szAbsPathNameW=&absPathBuf[0]; + dwFileLength = wcslen( szChildFileW ); + + dwDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameW); + + if (0 == dwDirLength) + { + Fail ("GetCurrentDirectory call failed. Could not get " + "current working directory\n. Exiting.\n"); + } + + dwSize = mkAbsoluteFilenameW( szDirNameW, dwDirLength, szChildFileW, + dwFileLength, szAbsPathNameW ); + + if (0 == dwSize) + { + Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " + "not build absolute path name to file\n. Exiting.\n"); + } + + if ( !CreateProcessW ( NULL, + szAbsPathNameW, + NULL, + NULL, + FALSE, + CREATE_NEW_CONSOLE, + NULL, + NULL, + &si, + &pi ) + ) + { + Fail ( "CreateProcess call failed. GetLastError returned %d\n", + GetLastError() ); + } + + WaitForSingleObject ( pi.hProcess, INFINITE ); + + szAbsPathNameW=&absPathBuf[0]; + + dwFileLength = wcslen( szCommonFileW ); + + dwSize = mkAbsoluteFilenameW( szDirNameW, dwDirLength, szCommonFileW, + dwFileLength, szAbsPathNameW ); + + /* set the string length for the open call*/ + + if (0 == dwSize) + { + Fail ("Palsuite Code: mkAbsoluteFilename() call failed. Could " + "not build absolute path name to file\n. Exiting.\n"); + } + + WideCharToMultiByte (CP_ACP, 0, szAbsPathNameW, -1, szAbsPathNameA, + (dwSize + 1), NULL, NULL); + + if ( NULL == ( fp = fopen ( szAbsPathNameA , "r" ) ) ) + { + Fail ("%s\nunable to open %s\nfor reading. Exiting.\n", argv[0], + szAbsPathNameA ); + } + + cslen = strlen ( szCommonStringA ); + + if ( NULL == fgets( szReadStringA, (cslen + 1), fp )) + { + /* + * A return value of NULL indicates an error condition or an + * EOF condition + */ + Fail ("%s\nunable to read file\n%s\nszReadStringA is %s\n" + "Exiting.\n", argv[0], szAbsPathNameA, + szReadStringA ); + } + + if ( 0 != strncmp( szReadStringA, szCommonStringA, cslen )) + { + Fail ("string comparison failed.\n szReadStringA is %s and\n" + "szCommonStringA is %s\n", szReadStringA, + szCommonStringA ); + } + else + { + Trace ("string comparison passed.\n"); + } + + if (0 != (fclose ( fp ))) + { + Trace ("%s unable to close file %s. This may cause a file pointer " + "leak. Continuing.\n", argv[0], szAbsPathNameA ); + } + + /* Close process and thread handle */ + CloseHandle ( pi.hProcess ); + CloseHandle ( pi.hThread ); + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateProcessW/test2/CMakeLists.txt index 3feef213c4..021a0d2da2 100644 --- a/src/pal/tests/palsuite/threading/CreateProcessW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateProcessW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - parentprocess.c + parentprocess.cpp ) add_executable(paltest_createprocessw_test2 @@ -20,7 +20,7 @@ target_link_libraries(paltest_createprocessw_test2 set(HELPERSOURCES - childprocess.c + childprocess.cpp ) add_executable(paltest_createprocessw_test2_child diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test2/childprocess.c b/src/pal/tests/palsuite/threading/CreateProcessW/test2/childprocess.c deleted file mode 100644 index b4ab9366d9..0000000000 --- a/src/pal/tests/palsuite/threading/CreateProcessW/test2/childprocess.c +++ /dev/null @@ -1,78 +0,0 @@ -// 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: createprocessw/test2/childprocess.c -** -** Purpose: This child process reads a string from stdin -** and writes it out to stdout & stderr -** -** Dependencies: memset -** fgets -** gputs -** - -** -**=========================================================*/ - -#define UNICODE -#include -#include "test2.h" - - -int __cdecl main( int argc, char **argv ) -{ - int iRetCode = EXIT_OK_CODE; /* preset exit code to OK */ - char szBuf[BUF_LEN]; - - WCHAR *swzParam1, *swzParam2, *swzParam3 = NULL; - - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - if (argc != 4) - { - return EXIT_ERR_CODE3; - } - - swzParam1 = convert(argv[1]); - swzParam2 = convert(argv[2]); - swzParam3 = convert(argv[3]); - - if (wcscmp(swzParam1, szArg1) != 0 - || wcscmp(swzParam2, szArg2) != 0 - || wcscmp(swzParam3, szArg3) != 0) - { - return EXIT_ERR_CODE4; - } - - free(swzParam1); - free(swzParam2); - free(swzParam3); - - memset(szBuf, 0, BUF_LEN); - - /* Read the string that was written by the parent */ - if (fgets(szBuf, BUF_LEN, stdin) == NULL) - { - return EXIT_ERR_CODE1; - } - - - /* Write the string out to the stdout & stderr pipes */ - if (fputs(szBuf, stdout) == EOF - || fputs(szBuf, stderr) == EOF) - { - return EXIT_ERR_CODE2; - } - - /* The exit code will indicate success or failure */ - PAL_TerminateEx(iRetCode); - - /* Return special exit code to indicate success or failure */ - return iRetCode; -} diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test2/childprocess.cpp b/src/pal/tests/palsuite/threading/CreateProcessW/test2/childprocess.cpp new file mode 100644 index 0000000000..b4ab9366d9 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateProcessW/test2/childprocess.cpp @@ -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: createprocessw/test2/childprocess.c +** +** Purpose: This child process reads a string from stdin +** and writes it out to stdout & stderr +** +** Dependencies: memset +** fgets +** gputs +** + +** +**=========================================================*/ + +#define UNICODE +#include +#include "test2.h" + + +int __cdecl main( int argc, char **argv ) +{ + int iRetCode = EXIT_OK_CODE; /* preset exit code to OK */ + char szBuf[BUF_LEN]; + + WCHAR *swzParam1, *swzParam2, *swzParam3 = NULL; + + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + if (argc != 4) + { + return EXIT_ERR_CODE3; + } + + swzParam1 = convert(argv[1]); + swzParam2 = convert(argv[2]); + swzParam3 = convert(argv[3]); + + if (wcscmp(swzParam1, szArg1) != 0 + || wcscmp(swzParam2, szArg2) != 0 + || wcscmp(swzParam3, szArg3) != 0) + { + return EXIT_ERR_CODE4; + } + + free(swzParam1); + free(swzParam2); + free(swzParam3); + + memset(szBuf, 0, BUF_LEN); + + /* Read the string that was written by the parent */ + if (fgets(szBuf, BUF_LEN, stdin) == NULL) + { + return EXIT_ERR_CODE1; + } + + + /* Write the string out to the stdout & stderr pipes */ + if (fputs(szBuf, stdout) == EOF + || fputs(szBuf, stderr) == EOF) + { + return EXIT_ERR_CODE2; + } + + /* The exit code will indicate success or failure */ + PAL_TerminateEx(iRetCode); + + /* Return special exit code to indicate success or failure */ + return iRetCode; +} diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test2/parentprocess.c b/src/pal/tests/palsuite/threading/CreateProcessW/test2/parentprocess.c deleted file mode 100644 index 439b7b5eef..0000000000 --- a/src/pal/tests/palsuite/threading/CreateProcessW/test2/parentprocess.c +++ /dev/null @@ -1,245 +0,0 @@ -// 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: createprocessw/test2/parentprocess.c -** -** Purpose: Test the following features of CreateProcessW: -** - Check to see if hProcess & hThread are set in -** return PROCESS_INFORMATION structure -** - Check to see if stdin, stdout, & stderr handles -** are used when STARTF_USESTDHANDLES is specified -** in STARUPINFO flags and bInheritHandles = TRUE -** - Check to see that proper arguments are passed to -** child process -** -** Dependencies: CreatePipe -** strcpy, strlen, strncmp, memset -** WaitForSingleObject -** WriteFile, ReadFile -** GetExitCodeProcess -** - -** -**=========================================================*/ - -#define UNICODE -#include -#include "test2.h" - - - -int __cdecl main( int argc, char **argv ) -{ - - /******************************************* - * Declarations - *******************************************/ - STARTUPINFO si; - PROCESS_INFORMATION pi; - - HANDLE hTestStdInR = NULL; - HANDLE hTestStdInW = NULL; - HANDLE hTestStdOutR = NULL; - HANDLE hTestStdOutW = NULL; - HANDLE hTestStdErrR = NULL; - HANDLE hTestStdErrW = NULL; - - BOOL bRetVal = FALSE; - DWORD dwBytesWritten = 0; - DWORD dwBytesRead = 0; - DWORD dwExitCode = 0; - - SECURITY_ATTRIBUTES pipeAttributes; - - char szStdOutBuf[BUF_LEN]; - char szStdErrBuf[BUF_LEN]; - WCHAR szFullPathNameW[_MAX_PATH]; - - - /******************************************* - * Initialization - *******************************************/ - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - pipeAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); - pipeAttributes.lpSecurityDescriptor = NULL; - pipeAttributes.bInheritHandle = TRUE; - - - /*Create a StdIn pipe for child*/ - bRetVal = CreatePipe(&hTestStdInR, /* read handle*/ - &hTestStdInW, /* write handle */ - &pipeAttributes, /* security attributes*/ - 1024); /* pipe size*/ - - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :Unable to create stdin pipe\n", GetLastError()); - } - - - /*Create a StdOut pipe for child*/ - bRetVal = CreatePipe(&hTestStdOutR, /* read handle*/ - &hTestStdOutW, /* write handle */ - &pipeAttributes, /* security attributes*/ - 0); /* pipe size*/ - - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :Unable to create stdout pipe\n", GetLastError()); - } - - - /*Create a StdErr pipe for child*/ - bRetVal = CreatePipe(&hTestStdErrR, /* read handle*/ - &hTestStdErrW, /* write handle */ - &pipeAttributes, /* security attributes*/ - 0); /* pipe size*/ - - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :Unable to create stderr pipe\n", GetLastError()); - } - - /* Zero the data structure space */ - ZeroMemory ( &pi, sizeof(pi) ); - ZeroMemory ( &si, sizeof(si) ); - - /* Set the process flags and standard io handles */ - si.cb = sizeof(si); - si.dwFlags = STARTF_USESTDHANDLES; - si.hStdInput = hTestStdInR; - si.hStdOutput = hTestStdOutW; - si.hStdError = hTestStdErrW; - - wcscpy(szFullPathNameW, szChildFileW); - wcscat(szFullPathNameW, szArgs); - - /******************************************* - * Start Testing - *******************************************/ - - /* Launch the child */ - if ( !CreateProcess (NULL, szFullPathNameW, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi )) - { - Fail("ERROR: CreateProcess call failed. GetLastError returned %d\n", - GetLastError() ); - } - - /* Check the returned process information for validity */ - if (pi.hProcess == 0 || pi.hThread == 0) - { - Fail("ERROR: CreateProcess Error: Process Handle = %u, Thread Handle = %u\n", - pi.hProcess, pi.hThread); - } - - - /* Write the Constructed string to stdin pipe for the child process */ - if (WriteFile(hTestStdInW, szTestString, strlen(szTestString), &dwBytesWritten, NULL) == FALSE - || WriteFile(hTestStdInW, "\n", strlen("\n"), &dwBytesWritten, NULL) == FALSE) - { - Fail("ERROR: %ld :unable to write to write pipe handle " - "hTestStdInW=0x%lx\n", GetLastError(), hTestStdInW); - } - - /* Wait for the child to finish, Max 20 seconds */ - dwExitCode = WaitForSingleObject(pi.hProcess, 20000); - - /* If the child failed then whole thing fails */ - if (dwExitCode != WAIT_OBJECT_0) - { - TerminateProcess(pi.hProcess, 0); - Fail("ERROR: The child failed to run properly.\n"); - } - - /* Check for problems in the child process */ - if (GetExitCodeProcess(pi.hProcess, &dwExitCode) == FALSE) - { - Fail("ERROR: Call to GetExitCodeProcess failed.\n"); - } - else if (dwExitCode == EXIT_ERR_CODE1) - { - Fail("ERROR: The Child process could not reead the string " - "written to the stdin pipe.\n"); - } - else if (dwExitCode == EXIT_ERR_CODE2) - { - Fail("ERROR: The Child process could not write the string " - "the stdout pipe or stderr pipe.\n"); - } - else if (dwExitCode == EXIT_ERR_CODE3) - { - Fail("ERROR: The Child received the wrong number of " - "command line arguments.\n"); - } - else if (dwExitCode == EXIT_ERR_CODE4) - { - Fail("ERROR: The Child received the wrong " - "command line arguments.\n"); - } - else if (dwExitCode != EXIT_OK_CODE) - { - Fail("ERROR: Unexpected exit code returned: %u. Child process " - "did not complete its part of the test.\n", dwExitCode); - } - - - /* The child ran ok, so check to see if we received the proper */ - /* strings through the pipes. */ - - /* clear our buffers */ - memset(szStdOutBuf, 0, BUF_LEN); - memset(szStdErrBuf, 0, BUF_LEN); - - /* Read the data back from the child process stdout */ - bRetVal = ReadFile(hTestStdOutR, /* handle to read pipe*/ - szStdOutBuf, /* buffer to write to*/ - BUF_LEN, /* number of bytes to read*/ - &dwBytesRead, /* number of bytes read*/ - NULL); /* overlapped buffer*/ - - /*Read the data back from the child process stderr */ - bRetVal = ReadFile(hTestStdErrR, /* handle to read pipe*/ - szStdErrBuf, /* buffer to write to*/ - BUF_LEN, /* number of bytes to read*/ - &dwBytesRead, /* number of bytes read*/ - NULL); /* overlapped buffer*/ - - - /* Confirm that we recieved the same string that we originally */ - /* wrote to the child and was received on both stdout & stderr.*/ - if (strncmp(szTestString, szStdOutBuf, strlen(szTestString)) != 0 - || strncmp(szTestString, szStdErrBuf, strlen(szTestString)) != 0) - { - Fail("ERROR: The data read back from child does not match " - "what was written. STDOUT: %s STDERR: %s\n", - szStdOutBuf, szStdErrBuf); - } - - - /******************************************* - * Clean Up - *******************************************/ - - /* Close process and thread handle */ - CloseHandle ( pi.hProcess ); - CloseHandle ( pi.hThread ); - - CloseHandle(hTestStdInR); - CloseHandle(hTestStdInW); - CloseHandle(hTestStdOutR); - CloseHandle(hTestStdOutW); - CloseHandle(hTestStdErrR); - CloseHandle(hTestStdErrW); - - PAL_Terminate(); - return ( PASS ); -} diff --git a/src/pal/tests/palsuite/threading/CreateProcessW/test2/parentprocess.cpp b/src/pal/tests/palsuite/threading/CreateProcessW/test2/parentprocess.cpp new file mode 100644 index 0000000000..439b7b5eef --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateProcessW/test2/parentprocess.cpp @@ -0,0 +1,245 @@ +// 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: createprocessw/test2/parentprocess.c +** +** Purpose: Test the following features of CreateProcessW: +** - Check to see if hProcess & hThread are set in +** return PROCESS_INFORMATION structure +** - Check to see if stdin, stdout, & stderr handles +** are used when STARTF_USESTDHANDLES is specified +** in STARUPINFO flags and bInheritHandles = TRUE +** - Check to see that proper arguments are passed to +** child process +** +** Dependencies: CreatePipe +** strcpy, strlen, strncmp, memset +** WaitForSingleObject +** WriteFile, ReadFile +** GetExitCodeProcess +** + +** +**=========================================================*/ + +#define UNICODE +#include +#include "test2.h" + + + +int __cdecl main( int argc, char **argv ) +{ + + /******************************************* + * Declarations + *******************************************/ + STARTUPINFO si; + PROCESS_INFORMATION pi; + + HANDLE hTestStdInR = NULL; + HANDLE hTestStdInW = NULL; + HANDLE hTestStdOutR = NULL; + HANDLE hTestStdOutW = NULL; + HANDLE hTestStdErrR = NULL; + HANDLE hTestStdErrW = NULL; + + BOOL bRetVal = FALSE; + DWORD dwBytesWritten = 0; + DWORD dwBytesRead = 0; + DWORD dwExitCode = 0; + + SECURITY_ATTRIBUTES pipeAttributes; + + char szStdOutBuf[BUF_LEN]; + char szStdErrBuf[BUF_LEN]; + WCHAR szFullPathNameW[_MAX_PATH]; + + + /******************************************* + * Initialization + *******************************************/ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + pipeAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); + pipeAttributes.lpSecurityDescriptor = NULL; + pipeAttributes.bInheritHandle = TRUE; + + + /*Create a StdIn pipe for child*/ + bRetVal = CreatePipe(&hTestStdInR, /* read handle*/ + &hTestStdInW, /* write handle */ + &pipeAttributes, /* security attributes*/ + 1024); /* pipe size*/ + + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :Unable to create stdin pipe\n", GetLastError()); + } + + + /*Create a StdOut pipe for child*/ + bRetVal = CreatePipe(&hTestStdOutR, /* read handle*/ + &hTestStdOutW, /* write handle */ + &pipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :Unable to create stdout pipe\n", GetLastError()); + } + + + /*Create a StdErr pipe for child*/ + bRetVal = CreatePipe(&hTestStdErrR, /* read handle*/ + &hTestStdErrW, /* write handle */ + &pipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :Unable to create stderr pipe\n", GetLastError()); + } + + /* Zero the data structure space */ + ZeroMemory ( &pi, sizeof(pi) ); + ZeroMemory ( &si, sizeof(si) ); + + /* Set the process flags and standard io handles */ + si.cb = sizeof(si); + si.dwFlags = STARTF_USESTDHANDLES; + si.hStdInput = hTestStdInR; + si.hStdOutput = hTestStdOutW; + si.hStdError = hTestStdErrW; + + wcscpy(szFullPathNameW, szChildFileW); + wcscat(szFullPathNameW, szArgs); + + /******************************************* + * Start Testing + *******************************************/ + + /* Launch the child */ + if ( !CreateProcess (NULL, szFullPathNameW, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi )) + { + Fail("ERROR: CreateProcess call failed. GetLastError returned %d\n", + GetLastError() ); + } + + /* Check the returned process information for validity */ + if (pi.hProcess == 0 || pi.hThread == 0) + { + Fail("ERROR: CreateProcess Error: Process Handle = %u, Thread Handle = %u\n", + pi.hProcess, pi.hThread); + } + + + /* Write the Constructed string to stdin pipe for the child process */ + if (WriteFile(hTestStdInW, szTestString, strlen(szTestString), &dwBytesWritten, NULL) == FALSE + || WriteFile(hTestStdInW, "\n", strlen("\n"), &dwBytesWritten, NULL) == FALSE) + { + Fail("ERROR: %ld :unable to write to write pipe handle " + "hTestStdInW=0x%lx\n", GetLastError(), hTestStdInW); + } + + /* Wait for the child to finish, Max 20 seconds */ + dwExitCode = WaitForSingleObject(pi.hProcess, 20000); + + /* If the child failed then whole thing fails */ + if (dwExitCode != WAIT_OBJECT_0) + { + TerminateProcess(pi.hProcess, 0); + Fail("ERROR: The child failed to run properly.\n"); + } + + /* Check for problems in the child process */ + if (GetExitCodeProcess(pi.hProcess, &dwExitCode) == FALSE) + { + Fail("ERROR: Call to GetExitCodeProcess failed.\n"); + } + else if (dwExitCode == EXIT_ERR_CODE1) + { + Fail("ERROR: The Child process could not reead the string " + "written to the stdin pipe.\n"); + } + else if (dwExitCode == EXIT_ERR_CODE2) + { + Fail("ERROR: The Child process could not write the string " + "the stdout pipe or stderr pipe.\n"); + } + else if (dwExitCode == EXIT_ERR_CODE3) + { + Fail("ERROR: The Child received the wrong number of " + "command line arguments.\n"); + } + else if (dwExitCode == EXIT_ERR_CODE4) + { + Fail("ERROR: The Child received the wrong " + "command line arguments.\n"); + } + else if (dwExitCode != EXIT_OK_CODE) + { + Fail("ERROR: Unexpected exit code returned: %u. Child process " + "did not complete its part of the test.\n", dwExitCode); + } + + + /* The child ran ok, so check to see if we received the proper */ + /* strings through the pipes. */ + + /* clear our buffers */ + memset(szStdOutBuf, 0, BUF_LEN); + memset(szStdErrBuf, 0, BUF_LEN); + + /* Read the data back from the child process stdout */ + bRetVal = ReadFile(hTestStdOutR, /* handle to read pipe*/ + szStdOutBuf, /* buffer to write to*/ + BUF_LEN, /* number of bytes to read*/ + &dwBytesRead, /* number of bytes read*/ + NULL); /* overlapped buffer*/ + + /*Read the data back from the child process stderr */ + bRetVal = ReadFile(hTestStdErrR, /* handle to read pipe*/ + szStdErrBuf, /* buffer to write to*/ + BUF_LEN, /* number of bytes to read*/ + &dwBytesRead, /* number of bytes read*/ + NULL); /* overlapped buffer*/ + + + /* Confirm that we recieved the same string that we originally */ + /* wrote to the child and was received on both stdout & stderr.*/ + if (strncmp(szTestString, szStdOutBuf, strlen(szTestString)) != 0 + || strncmp(szTestString, szStdErrBuf, strlen(szTestString)) != 0) + { + Fail("ERROR: The data read back from child does not match " + "what was written. STDOUT: %s STDERR: %s\n", + szStdOutBuf, szStdErrBuf); + } + + + /******************************************* + * Clean Up + *******************************************/ + + /* Close process and thread handle */ + CloseHandle ( pi.hProcess ); + CloseHandle ( pi.hThread ); + + CloseHandle(hTestStdInR); + CloseHandle(hTestStdInW); + CloseHandle(hTestStdOutR); + CloseHandle(hTestStdOutW); + CloseHandle(hTestStdErrR); + CloseHandle(hTestStdErrW); + + PAL_Terminate(); + return ( PASS ); +} diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CMakeLists.txt index f89e150a32..8a9255ce7a 100644 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateSemaphore.c + CreateSemaphore.cpp ) add_executable(paltest_createsemaphorea_releasesemaphore_test1 diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CreateSemaphore.c b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CreateSemaphore.c deleted file mode 100644 index 342b15ec29..0000000000 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CreateSemaphore.c +++ /dev/null @@ -1,322 +0,0 @@ -// 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: createsemaphorea_releasesemaphore/test1/createsemaphore.c -** -** Purpose: Test Semaphore operation using classic IPC problem: -** "Producer-Consumer Problem". -** -** Dependencies: CreateThread -** ReleaseSemaphore -** WaitForSingleObject -** Sleep -** fflush -** - -** -**=========================================================*/ - -#include - -#define PRODUCTION_TOTAL 26 - -#define _BUF_SIZE 10 - -DWORD dwThreadId; /* consumer thread identifier */ - -HANDLE hThread; /* handle to consumer thread */ - -HANDLE hSemaphoreM; /* handle to mutual exclusion semaphore */ - -HANDLE hSemaphoreE; /* handle to semaphore that counts empty buffer slots */ - -HANDLE hSemaphoreF; /* handle to semaphore that counts full buffer slots */ - -typedef struct Buffer -{ - short readIndex; - short writeIndex; - CHAR message[_BUF_SIZE]; - -} BufferStructure; - -CHAR producerItems[PRODUCTION_TOTAL + 1]; - -CHAR consumerItems[PRODUCTION_TOTAL + 1]; - -/* - * Read next message from the Buffer into provided pointer. - * Returns: 0 on failure, 1 on success. - */ -int -readBuf(BufferStructure *Buffer, char *c) -{ - if( Buffer -> writeIndex == Buffer -> readIndex ) - { - return 0; - } - *c = Buffer -> message[Buffer -> readIndex++]; - Buffer -> readIndex %= _BUF_SIZE; - return 1; -} - -/* - * Write message generated by the producer to Buffer. - * Returns: 0 on failure, 1 on success. - */ -int -writeBuf(BufferStructure *Buffer, CHAR c) -{ - if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == - (Buffer -> readIndex) ) - { - return 0; - } - Buffer -> message[Buffer -> writeIndex++] = c; - Buffer -> writeIndex %= _BUF_SIZE; - return 1; -} - -/* - * Atomic decrement of semaphore value. - */ -VOID -down(HANDLE hSemaphore) -{ - switch ( (WaitForSingleObject ( - hSemaphore, - 10000))) /* Wait 10 seconds */ - { - case WAIT_OBJECT_0: /* - * Semaphore was signaled. OK to access - * semaphore. - */ - break; - case WAIT_ABANDONED: /* - * Object was mutex object whose owning - * thread has terminated. Shouldn't occur. - */ - Fail("WaitForSingleObject call returned 'WAIT_ABANDONED'.\n" - "Failing Test.\n"); - break; - case WAIT_FAILED: /* WaitForSingleObject function failed */ - Fail("WaitForSingleObject call returned 'WAIT_FAILED'.\n" - "GetLastError returned %d\nFailing Test.\n",GetLastError()); - break; - default: - Fail("WaitForSingleObject call returned an unexpected value.\n" - "Failing Test.\n"); - break; - } - -} - -/* - * Atomic increment of semaphore value. - */ -VOID -up(HANDLE hSemaphore) -{ - if (!ReleaseSemaphore ( - hSemaphore, - 1, - NULL) - ) - { - Fail("ReleaseSemaphore call failed. GetLastError returned %d\n", - GetLastError()); - } -} - -/* - * Sleep 500 milleseconds. - */ -VOID -consumerSleep(VOID) -{ - Sleep(500); -} - -/* - * Sleep between 10 milleseconds. - */ -VOID -producerSleep(VOID) -{ - Sleep(10); -} - -/* - * Produce a message and write the message to Buffer. - */ -VOID -producer(BufferStructure *Buffer) -{ - - int n = 0; - char c; - - while (n < PRODUCTION_TOTAL) - { - c = 'A' + n ; /* Produce Item */ - - down(hSemaphoreE); - down(hSemaphoreM); - - if (writeBuf(Buffer, c)) - { - Trace("Producer produces %c.\n", c); - fflush(stdout); - producerItems[n++] = c; - } - - up(hSemaphoreM); - up(hSemaphoreF); - - producerSleep(); - } - - return; -} - -/* - * Read and "Consume" the messages in Buffer. - */ -DWORD -PALAPI -consumer( LPVOID lpParam ) -{ - int n = 0; - char c; - - consumerSleep(); - - while (n < PRODUCTION_TOTAL) - { - - down(hSemaphoreF); - down(hSemaphoreM); - - if (readBuf((BufferStructure*)lpParam, &c)) - { - Trace("\tConsumer consumes %c.\n", c); - fflush(stdout); - consumerItems[n++] = c; - } - - up(hSemaphoreM); - up(hSemaphoreE); - - consumerSleep(); - } - - return 0; -} - -int __cdecl main (int argc, char **argv) -{ - - BufferStructure Buffer, *pBuffer; - - pBuffer = &Buffer; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - /* - * Create Semaphores - */ - hSemaphoreM = CreateSemaphoreA ( - NULL, - 1, - 1, - NULL); - - if ( NULL == hSemaphoreM ) - { - Fail ( "hSemaphoreM = CreateSemaphoreA () - returned NULL\n" - "Failing Test.\nGetLastError returned %d\n", GetLastError()); - } - - - hSemaphoreE = CreateSemaphoreA ( - NULL, - _BUF_SIZE , - _BUF_SIZE , - NULL); - - if ( NULL == hSemaphoreE ) - { - Fail ( "hSemaphoreE = CreateSemaphoreA () - returned NULL\n" - "Failing Test.\nGetLastError returned %d\n", GetLastError()); - } - - hSemaphoreF = CreateSemaphoreA ( - NULL, - 0, - _BUF_SIZE , - NULL); - - if ( NULL == hSemaphoreF ) - { - Fail ( "hSemaphoreF = CreateSemaphoreA () - returned NULL\n" - "Failing Test.\nGetLastError returned %d\n", GetLastError()); - } - - - /* - * Initialize Buffer - */ - pBuffer->writeIndex = pBuffer->readIndex = 0; - - /* - * Create Consumer - */ - hThread = CreateThread( - NULL, - 0, - consumer, - &Buffer, - 0, - &dwThreadId); - - if ( NULL == hThread ) - { - Fail ( "CreateThread() returned NULL. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - /* - * Start producing - */ - producer(pBuffer); - - /* - * Wait for consumer to complete - */ - WaitForSingleObject (hThread, INFINITE); - - /* - * Compare items produced vs. items consumed - */ - if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) - { - Fail("The producerItems string %s\n and the consumerItems string " - "%s\ndo not match. This could be a problem with the strncmp()" - " function\n FailingTest\nGetLastError() returned %d\n", - producerItems, consumerItems, GetLastError()); - } - - Trace ("producerItems and consumerItems arrays match. All %d\nitems " - "were produced and consumed in order.\nTest passed.\n", - PRODUCTION_TOTAL); - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CreateSemaphore.cpp b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CreateSemaphore.cpp new file mode 100644 index 0000000000..342b15ec29 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test1/CreateSemaphore.cpp @@ -0,0 +1,322 @@ +// 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: createsemaphorea_releasesemaphore/test1/createsemaphore.c +** +** Purpose: Test Semaphore operation using classic IPC problem: +** "Producer-Consumer Problem". +** +** Dependencies: CreateThread +** ReleaseSemaphore +** WaitForSingleObject +** Sleep +** fflush +** + +** +**=========================================================*/ + +#include + +#define PRODUCTION_TOTAL 26 + +#define _BUF_SIZE 10 + +DWORD dwThreadId; /* consumer thread identifier */ + +HANDLE hThread; /* handle to consumer thread */ + +HANDLE hSemaphoreM; /* handle to mutual exclusion semaphore */ + +HANDLE hSemaphoreE; /* handle to semaphore that counts empty buffer slots */ + +HANDLE hSemaphoreF; /* handle to semaphore that counts full buffer slots */ + +typedef struct Buffer +{ + short readIndex; + short writeIndex; + CHAR message[_BUF_SIZE]; + +} BufferStructure; + +CHAR producerItems[PRODUCTION_TOTAL + 1]; + +CHAR consumerItems[PRODUCTION_TOTAL + 1]; + +/* + * Read next message from the Buffer into provided pointer. + * Returns: 0 on failure, 1 on success. + */ +int +readBuf(BufferStructure *Buffer, char *c) +{ + if( Buffer -> writeIndex == Buffer -> readIndex ) + { + return 0; + } + *c = Buffer -> message[Buffer -> readIndex++]; + Buffer -> readIndex %= _BUF_SIZE; + return 1; +} + +/* + * Write message generated by the producer to Buffer. + * Returns: 0 on failure, 1 on success. + */ +int +writeBuf(BufferStructure *Buffer, CHAR c) +{ + if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == + (Buffer -> readIndex) ) + { + return 0; + } + Buffer -> message[Buffer -> writeIndex++] = c; + Buffer -> writeIndex %= _BUF_SIZE; + return 1; +} + +/* + * Atomic decrement of semaphore value. + */ +VOID +down(HANDLE hSemaphore) +{ + switch ( (WaitForSingleObject ( + hSemaphore, + 10000))) /* Wait 10 seconds */ + { + case WAIT_OBJECT_0: /* + * Semaphore was signaled. OK to access + * semaphore. + */ + break; + case WAIT_ABANDONED: /* + * Object was mutex object whose owning + * thread has terminated. Shouldn't occur. + */ + Fail("WaitForSingleObject call returned 'WAIT_ABANDONED'.\n" + "Failing Test.\n"); + break; + case WAIT_FAILED: /* WaitForSingleObject function failed */ + Fail("WaitForSingleObject call returned 'WAIT_FAILED'.\n" + "GetLastError returned %d\nFailing Test.\n",GetLastError()); + break; + default: + Fail("WaitForSingleObject call returned an unexpected value.\n" + "Failing Test.\n"); + break; + } + +} + +/* + * Atomic increment of semaphore value. + */ +VOID +up(HANDLE hSemaphore) +{ + if (!ReleaseSemaphore ( + hSemaphore, + 1, + NULL) + ) + { + Fail("ReleaseSemaphore call failed. GetLastError returned %d\n", + GetLastError()); + } +} + +/* + * Sleep 500 milleseconds. + */ +VOID +consumerSleep(VOID) +{ + Sleep(500); +} + +/* + * Sleep between 10 milleseconds. + */ +VOID +producerSleep(VOID) +{ + Sleep(10); +} + +/* + * Produce a message and write the message to Buffer. + */ +VOID +producer(BufferStructure *Buffer) +{ + + int n = 0; + char c; + + while (n < PRODUCTION_TOTAL) + { + c = 'A' + n ; /* Produce Item */ + + down(hSemaphoreE); + down(hSemaphoreM); + + if (writeBuf(Buffer, c)) + { + Trace("Producer produces %c.\n", c); + fflush(stdout); + producerItems[n++] = c; + } + + up(hSemaphoreM); + up(hSemaphoreF); + + producerSleep(); + } + + return; +} + +/* + * Read and "Consume" the messages in Buffer. + */ +DWORD +PALAPI +consumer( LPVOID lpParam ) +{ + int n = 0; + char c; + + consumerSleep(); + + while (n < PRODUCTION_TOTAL) + { + + down(hSemaphoreF); + down(hSemaphoreM); + + if (readBuf((BufferStructure*)lpParam, &c)) + { + Trace("\tConsumer consumes %c.\n", c); + fflush(stdout); + consumerItems[n++] = c; + } + + up(hSemaphoreM); + up(hSemaphoreE); + + consumerSleep(); + } + + return 0; +} + +int __cdecl main (int argc, char **argv) +{ + + BufferStructure Buffer, *pBuffer; + + pBuffer = &Buffer; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + /* + * Create Semaphores + */ + hSemaphoreM = CreateSemaphoreA ( + NULL, + 1, + 1, + NULL); + + if ( NULL == hSemaphoreM ) + { + Fail ( "hSemaphoreM = CreateSemaphoreA () - returned NULL\n" + "Failing Test.\nGetLastError returned %d\n", GetLastError()); + } + + + hSemaphoreE = CreateSemaphoreA ( + NULL, + _BUF_SIZE , + _BUF_SIZE , + NULL); + + if ( NULL == hSemaphoreE ) + { + Fail ( "hSemaphoreE = CreateSemaphoreA () - returned NULL\n" + "Failing Test.\nGetLastError returned %d\n", GetLastError()); + } + + hSemaphoreF = CreateSemaphoreA ( + NULL, + 0, + _BUF_SIZE , + NULL); + + if ( NULL == hSemaphoreF ) + { + Fail ( "hSemaphoreF = CreateSemaphoreA () - returned NULL\n" + "Failing Test.\nGetLastError returned %d\n", GetLastError()); + } + + + /* + * Initialize Buffer + */ + pBuffer->writeIndex = pBuffer->readIndex = 0; + + /* + * Create Consumer + */ + hThread = CreateThread( + NULL, + 0, + consumer, + &Buffer, + 0, + &dwThreadId); + + if ( NULL == hThread ) + { + Fail ( "CreateThread() returned NULL. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + /* + * Start producing + */ + producer(pBuffer); + + /* + * Wait for consumer to complete + */ + WaitForSingleObject (hThread, INFINITE); + + /* + * Compare items produced vs. items consumed + */ + if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) + { + Fail("The producerItems string %s\n and the consumerItems string " + "%s\ndo not match. This could be a problem with the strncmp()" + " function\n FailingTest\nGetLastError() returned %d\n", + producerItems, consumerItems, GetLastError()); + } + + Trace ("producerItems and consumerItems arrays match. All %d\nitems " + "were produced and consumed in order.\nTest passed.\n", + PRODUCTION_TOTAL); + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CMakeLists.txt index f3e01749b8..6d1249bf05 100644 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateSemaphore.c + CreateSemaphore.cpp ) add_executable(paltest_createsemaphorea_releasesemaphore_test2 diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CreateSemaphore.c b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CreateSemaphore.c deleted file mode 100644 index bff5b51c33..0000000000 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CreateSemaphore.c +++ /dev/null @@ -1,313 +0,0 @@ -// 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: CreateSemaphoreA_ReleaseSemaphore/test2/createsemaphore.c -** -** Purpose: Test Semaphore operation using classic IPC problem: -** "Producer-Consumer Problem". -** -** Dependencies: CreateThread -** ReleaseSemaphore -** WaitForSingleObject -** Sleep -** fflush -** - -** -**=========================================================*/ - -#include - -#define PRODUCTION_TOTAL 26 - -#define _BUF_SIZE 10 - -DWORD dwThreadId; /* consumer thread identifier */ - -HANDLE hThread; /* handle to consumer thread */ - -HANDLE hSemaphoreM; /* handle to mutual exclusion semaphore */ - -HANDLE hSemaphoreE; /* handle to semaphore that counts empty buffer slots */ - -HANDLE hSemaphoreF; /* handle to semaphore that counts full buffer slots */ - -typedef struct Buffer -{ - short readIndex; - short writeIndex; - CHAR message[_BUF_SIZE]; - -} BufferStructure; - -CHAR producerItems[PRODUCTION_TOTAL + 1]; - -CHAR consumerItems[PRODUCTION_TOTAL + 1]; - -/* - * Read next message from the Buffer into provided pointer. - * Returns: 0 on failure, 1 on success. - */ -int -readBuf(BufferStructure *Buffer, char *c) -{ - if( Buffer -> writeIndex == Buffer -> readIndex ) - { - return 0; - } - *c = Buffer -> message[Buffer -> readIndex++]; - Buffer -> readIndex %= _BUF_SIZE; - return 1; -} - -/* - * Write message generated by the producer to Buffer. - * Returns: 0 on failure, 1 on success. - */ -int -writeBuf(BufferStructure *Buffer, CHAR c) -{ - if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == - (Buffer -> readIndex) ) - { - return 0; - } - Buffer -> message[Buffer -> writeIndex++] = c; - Buffer -> writeIndex %= _BUF_SIZE; - return 1; -} - -/* - * Atomic decrement of semaphore value. - */ -VOID -down(HANDLE hSemaphore) -{ - switch ( (WaitForSingleObject ( - hSemaphore, - 10000))) - { - case WAIT_OBJECT_0: /* - * Semaphore was signaled. OK to access semaphore. - */ - break; - case WAIT_ABANDONED: /* - * Object was mutex object whose owning - * thread has terminated. Shouldn't occur. - */ - Fail("WaitForSingleObject call returned 'WAIT_ABANDONED'.\n" - "Failing Test.\n"); - break; - case WAIT_FAILED: /* WaitForSingleObject function failed */ - Fail("WaitForSingleObject call returned 'WAIT_FAILED'.\n" - "GetLastError returned %d\nFailing Test.\n",GetLastError()); - break; - default: - Fail("WaitForSingleObject call returned an unexpected value.\n" - "Failing Test.\n"); - break; - } - -} - -/* - * Atomic increment of semaphore value. - */ -VOID -up(HANDLE hSemaphore) -{ - if (!ReleaseSemaphore ( - hSemaphore, - 1, - NULL) - ) - { - Fail("ReleaseSemaphore call failed. GetLastError returned %d\n", - GetLastError()); - } -} - -/* - * Sleep 10 milleseconds. - */ -VOID -consumerSleep(VOID) -{ - Sleep(10); -} - -/* - * Sleep 500 milleseconds. - */ -VOID -producerSleep(VOID) -{ - Sleep(500); -} - -/* - * Produce a message and write the message to Buffer. - */ -VOID -producer(BufferStructure *Buffer) -{ - - int n = 0; - char c; - - while (n < PRODUCTION_TOTAL) - { - c = 'A' + n ; /* Produce Item */ - - down(hSemaphoreE); - down(hSemaphoreM); - - if (writeBuf(Buffer, c)) - { - Trace("Producer produces %c.\n", c); - fflush(stdout); - producerItems[n++] = c; - } - - up(hSemaphoreM); - up(hSemaphoreF); - - producerSleep(); - } - return; -} - -/* - * Read and "Consume" the messages in Buffer. - */ -DWORD -PALAPI -consumer( LPVOID lpParam ) -{ - int n = 0; - char c; - - consumerSleep(); - - while (n < PRODUCTION_TOTAL) - { - - down(hSemaphoreF); - down(hSemaphoreM); - - if (readBuf((BufferStructure*)lpParam, &c)) - { - Trace("\tConsumer consumes %c.\n", c); - fflush(stdout); - consumerItems[n++] = c; - } - - up(hSemaphoreM); - up(hSemaphoreE); - - consumerSleep(); - } - return 0; -} - -int __cdecl main (int argc, char **argv) -{ - - BufferStructure Buffer, *pBuffer; - - pBuffer = &Buffer; - - if(0 != (PAL_Initialize(argc, argv))) - { - return (FAIL); - } - - /* - * Create Semaphores - */ - hSemaphoreM = CreateSemaphoreA ( - NULL, - 1, - 1, - NULL); - - if ( NULL == hSemaphoreM ) - { - Fail ( "hSemaphoreM = CreateSemaphoreA () - returned NULL\n" - "Failing Test.\n"); - } - - hSemaphoreE = CreateSemaphoreA ( - NULL, - _BUF_SIZE , - _BUF_SIZE , - NULL); - - if ( NULL == hSemaphoreE ) - { - Fail ( "hSemaphoreE = CreateSemaphoreA () - returned NULL\n" - "Failing Test.\n"); - } - - hSemaphoreF = CreateSemaphoreA ( - NULL, - 0, - _BUF_SIZE , - NULL); - - if ( NULL == hSemaphoreF ) - { - Fail ( "hSemaphoreF = CreateSemaphoreA () - returned NULL\n" - "Failing Test.\n"); - } - - /* - * Initialize Buffer - */ - pBuffer->writeIndex = pBuffer->readIndex = 0; - - /* - * Create Consumer - */ - hThread = CreateThread( - NULL, - 0, - consumer, - &Buffer, - 0, - &dwThreadId); - - if ( NULL == hThread ) - { - Fail ( "CreateThread() returned NULL. Failing test.\n"); - } - - /* - * Start producing - */ - producer(pBuffer); - - /* - * Wait for consumer to complete - */ - WaitForSingleObject (hThread, INFINITE); - - if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) - { - Fail("The producerItems string %s\n and the consumerItems string " - "%s\ndo not match. This could be a problem with the strncmp()" - " function\n FailingTest\nGetLastError() returned %d\n", - producerItems, consumerItems, GetLastError()); - } - - Trace ("producerItems and consumerItems arrays match. All %d\nitems " - "were produced and consumed in order.\nTest passed.\n", - PRODUCTION_TOTAL); - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CreateSemaphore.cpp b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CreateSemaphore.cpp new file mode 100644 index 0000000000..bff5b51c33 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test2/CreateSemaphore.cpp @@ -0,0 +1,313 @@ +// 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: CreateSemaphoreA_ReleaseSemaphore/test2/createsemaphore.c +** +** Purpose: Test Semaphore operation using classic IPC problem: +** "Producer-Consumer Problem". +** +** Dependencies: CreateThread +** ReleaseSemaphore +** WaitForSingleObject +** Sleep +** fflush +** + +** +**=========================================================*/ + +#include + +#define PRODUCTION_TOTAL 26 + +#define _BUF_SIZE 10 + +DWORD dwThreadId; /* consumer thread identifier */ + +HANDLE hThread; /* handle to consumer thread */ + +HANDLE hSemaphoreM; /* handle to mutual exclusion semaphore */ + +HANDLE hSemaphoreE; /* handle to semaphore that counts empty buffer slots */ + +HANDLE hSemaphoreF; /* handle to semaphore that counts full buffer slots */ + +typedef struct Buffer +{ + short readIndex; + short writeIndex; + CHAR message[_BUF_SIZE]; + +} BufferStructure; + +CHAR producerItems[PRODUCTION_TOTAL + 1]; + +CHAR consumerItems[PRODUCTION_TOTAL + 1]; + +/* + * Read next message from the Buffer into provided pointer. + * Returns: 0 on failure, 1 on success. + */ +int +readBuf(BufferStructure *Buffer, char *c) +{ + if( Buffer -> writeIndex == Buffer -> readIndex ) + { + return 0; + } + *c = Buffer -> message[Buffer -> readIndex++]; + Buffer -> readIndex %= _BUF_SIZE; + return 1; +} + +/* + * Write message generated by the producer to Buffer. + * Returns: 0 on failure, 1 on success. + */ +int +writeBuf(BufferStructure *Buffer, CHAR c) +{ + if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == + (Buffer -> readIndex) ) + { + return 0; + } + Buffer -> message[Buffer -> writeIndex++] = c; + Buffer -> writeIndex %= _BUF_SIZE; + return 1; +} + +/* + * Atomic decrement of semaphore value. + */ +VOID +down(HANDLE hSemaphore) +{ + switch ( (WaitForSingleObject ( + hSemaphore, + 10000))) + { + case WAIT_OBJECT_0: /* + * Semaphore was signaled. OK to access semaphore. + */ + break; + case WAIT_ABANDONED: /* + * Object was mutex object whose owning + * thread has terminated. Shouldn't occur. + */ + Fail("WaitForSingleObject call returned 'WAIT_ABANDONED'.\n" + "Failing Test.\n"); + break; + case WAIT_FAILED: /* WaitForSingleObject function failed */ + Fail("WaitForSingleObject call returned 'WAIT_FAILED'.\n" + "GetLastError returned %d\nFailing Test.\n",GetLastError()); + break; + default: + Fail("WaitForSingleObject call returned an unexpected value.\n" + "Failing Test.\n"); + break; + } + +} + +/* + * Atomic increment of semaphore value. + */ +VOID +up(HANDLE hSemaphore) +{ + if (!ReleaseSemaphore ( + hSemaphore, + 1, + NULL) + ) + { + Fail("ReleaseSemaphore call failed. GetLastError returned %d\n", + GetLastError()); + } +} + +/* + * Sleep 10 milleseconds. + */ +VOID +consumerSleep(VOID) +{ + Sleep(10); +} + +/* + * Sleep 500 milleseconds. + */ +VOID +producerSleep(VOID) +{ + Sleep(500); +} + +/* + * Produce a message and write the message to Buffer. + */ +VOID +producer(BufferStructure *Buffer) +{ + + int n = 0; + char c; + + while (n < PRODUCTION_TOTAL) + { + c = 'A' + n ; /* Produce Item */ + + down(hSemaphoreE); + down(hSemaphoreM); + + if (writeBuf(Buffer, c)) + { + Trace("Producer produces %c.\n", c); + fflush(stdout); + producerItems[n++] = c; + } + + up(hSemaphoreM); + up(hSemaphoreF); + + producerSleep(); + } + return; +} + +/* + * Read and "Consume" the messages in Buffer. + */ +DWORD +PALAPI +consumer( LPVOID lpParam ) +{ + int n = 0; + char c; + + consumerSleep(); + + while (n < PRODUCTION_TOTAL) + { + + down(hSemaphoreF); + down(hSemaphoreM); + + if (readBuf((BufferStructure*)lpParam, &c)) + { + Trace("\tConsumer consumes %c.\n", c); + fflush(stdout); + consumerItems[n++] = c; + } + + up(hSemaphoreM); + up(hSemaphoreE); + + consumerSleep(); + } + return 0; +} + +int __cdecl main (int argc, char **argv) +{ + + BufferStructure Buffer, *pBuffer; + + pBuffer = &Buffer; + + if(0 != (PAL_Initialize(argc, argv))) + { + return (FAIL); + } + + /* + * Create Semaphores + */ + hSemaphoreM = CreateSemaphoreA ( + NULL, + 1, + 1, + NULL); + + if ( NULL == hSemaphoreM ) + { + Fail ( "hSemaphoreM = CreateSemaphoreA () - returned NULL\n" + "Failing Test.\n"); + } + + hSemaphoreE = CreateSemaphoreA ( + NULL, + _BUF_SIZE , + _BUF_SIZE , + NULL); + + if ( NULL == hSemaphoreE ) + { + Fail ( "hSemaphoreE = CreateSemaphoreA () - returned NULL\n" + "Failing Test.\n"); + } + + hSemaphoreF = CreateSemaphoreA ( + NULL, + 0, + _BUF_SIZE , + NULL); + + if ( NULL == hSemaphoreF ) + { + Fail ( "hSemaphoreF = CreateSemaphoreA () - returned NULL\n" + "Failing Test.\n"); + } + + /* + * Initialize Buffer + */ + pBuffer->writeIndex = pBuffer->readIndex = 0; + + /* + * Create Consumer + */ + hThread = CreateThread( + NULL, + 0, + consumer, + &Buffer, + 0, + &dwThreadId); + + if ( NULL == hThread ) + { + Fail ( "CreateThread() returned NULL. Failing test.\n"); + } + + /* + * Start producing + */ + producer(pBuffer); + + /* + * Wait for consumer to complete + */ + WaitForSingleObject (hThread, INFINITE); + + if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) + { + Fail("The producerItems string %s\n and the consumerItems string " + "%s\ndo not match. This could be a problem with the strncmp()" + " function\n FailingTest\nGetLastError() returned %d\n", + producerItems, consumerItems, GetLastError()); + } + + Trace ("producerItems and consumerItems arrays match. All %d\nitems " + "were produced and consumed in order.\nTest passed.\n", + PRODUCTION_TOTAL); + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/CMakeLists.txt index 0c604d6ced..94998f59a9 100644 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createsemaphore.c + createsemaphore.cpp ) add_executable(paltest_createsemaphorea_releasesemaphore_test3 diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/createsemaphore.c b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/createsemaphore.c deleted file mode 100644 index 7c6db6b055..0000000000 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/createsemaphore.c +++ /dev/null @@ -1,200 +0,0 @@ -// 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: createsemaphorea_releasesemaphore/test3/createsemaphore.c -** -** Purpose: Test attributes of CreateSemaphoreA and ReleaseSemaphore. -** Insure for CreateSemaphore that lInitialCount and lMaximumCount -** constraints are respected. Validate that CreateSemaphore rejects -** conditions where initial count and / or maximum count are negative -** and conditions where the initial count is greater than the maximum -** count. For ReleaseSemaphore validate that lpPreviousCount gets set -** to the previous semaphore count and lpPreviousCount can be NULL. -** Also establish ReleaseSemaphore fails when called in a semaphore -** with count equal to lMaximumCount. -** -** -**==========================================================================*/ - -#include - -struct testcase -{ - LPSECURITY_ATTRIBUTES lpSemaphoreAttributes; - LONG lInitialCount; - LONG lMaximumCount; - LPCTSTR lpName; - BOOL bNegativeTest; -}; - -struct testcase testCases[] = -{ - {NULL, -1, 1, NULL, TRUE}, - {NULL, 1, -1, NULL, TRUE}, - {NULL, -1, -1, NULL, TRUE}, - {NULL, 2, 1, NULL, TRUE}, - {NULL, 1, 2, NULL, FALSE}, - {NULL, 0, 10, NULL, FALSE}, - {NULL, INT_MAX - 1, INT_MAX, NULL, FALSE}, - {NULL, INT_MAX, INT_MAX, NULL, FALSE} -}; - -HANDLE hSemaphore[sizeof(testCases)/sizeof(struct testcase)]; - -BOOL cleanup(int index) -{ - int i; - BOOL bRet = TRUE; - for (i = 0; i < index; i++) - { - if (!CloseHandle(hSemaphore[i])) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CloseHandle(%p) call failed for index %d\n", - hSemaphore[i], i); - } - } - return(bRet); -} - -int __cdecl main (int argc, char **argv) -{ - int i; - int j; - - if(0 != (PAL_Initialize(argc, argv))) - { - return (FAIL); - } - /* create semaphores */ - for (i = 0; i < sizeof(testCases)/sizeof(struct testcase); i++) - { - hSemaphore[i] = CreateSemaphoreA (testCases[i].lpSemaphoreAttributes, - testCases[i].lInitialCount, - testCases[i].lMaximumCount, - testCases[i].lpName); - - if (NULL == hSemaphore[i]) - { - if (!testCases[i].bNegativeTest) - { - Trace("PALSUITE ERROR: CreateSemaphoreA('%p' '%ld' '%ld' " - "'%p') returned NULL at index %d.\nGetLastError " - "returned %d.\n", testCases[i].lpSemaphoreAttributes, - testCases[i].lInitialCount, testCases[i].lMaximumCount, - testCases[i].lpName, i, GetLastError()); - if (i > 0) - { - cleanup(i - 1); - } - Fail(""); - } - else - { - continue; - } - } - - /* increment semaphore count to lMaximumCount */ - for (j = testCases[i].lInitialCount; (ULONG)j <= (ULONG)testCases[i].lMaximumCount; - j++) - { - if (testCases[i].lMaximumCount == j) - { - /* Call ReleaseSemaphore once more to ensure ReleaseSemaphore - fails */ - if(ReleaseSemaphore(hSemaphore[i], 1, NULL)) - { - Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " - "call returned %d\nwhen it should have returned " - "%d.\nThe semaphore's count was %d.\nGetLastError " - "returned %d.\n", hSemaphore[i], 1, NULL, TRUE, - FALSE, j, GetLastError()); - cleanup(i); - Fail(""); - } - } - else - { - int previous; - BOOL bRet = ReleaseSemaphore(hSemaphore[i], 1, &previous); - DWORD dwError = GetLastError(); - - if(!bRet) - { - Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " - "call returned %d\nwhen it should have returned " - "%d.\nThe semaphore count was %d and it's " - "lMaxCount was %d.\nGetLastError returned %d.\n", - hSemaphore[i], 1, &previous, bRet, TRUE, j, - testCases[i].lMaximumCount, dwError); - cleanup(i); - Fail(""); - } - if (previous != j) - { - Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " - "call set %p to %d instead of %d.\n The semaphore " - "count was %d and GetLastError returned %d.\n", - hSemaphore[i], 1, &previous, &previous, previous, - j, j, dwError); - cleanup(i); - Fail(""); - } - } - } - - // Skip exhaustive decrement tests for too large an initial count - if(testCases[i].lInitialCount >= INT_MAX - 1) - { - continue; - } - - /* decrement semaphore count to 0 */ - for (j = testCases[i].lMaximumCount; j >= 0; j--) - { - DWORD dwRet = WaitForSingleObject(hSemaphore[i], 0); - DWORD dwError = GetLastError(); - - if (0 == j) - { - /* WaitForSingleObject should report that the - semaphore is nonsignaled */ - if (WAIT_TIMEOUT != dwRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject('%p' '%u') " - "call returned %d\nwhen it should have returned " - "%d.\nThe semaphore's count was %d.\nGetLastError " - "returned %d.\n", hSemaphore[i], 0, dwRet, - WAIT_TIMEOUT, j, dwError); - cleanup(i); - Fail(""); - } - } - else - { - /* WaitForSingleObject should report that the - semaphore is signaled */ - if (WAIT_OBJECT_0 != dwRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject('%p' '%u') " - "call returned %d\nwhen it should have returned " - "%d.\nThe semaphore's count was %d.\nGetLastError " - "returned %d.\n", hSemaphore[i], 0, dwRet, - WAIT_OBJECT_0, j, dwError); - cleanup(i); - Fail(""); - } - } - } - } - PAL_Terminate(); - return (PASS); -} - - - - diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/createsemaphore.cpp b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/createsemaphore.cpp new file mode 100644 index 0000000000..7c6db6b055 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreA_ReleaseSemaphore/test3/createsemaphore.cpp @@ -0,0 +1,200 @@ +// 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: createsemaphorea_releasesemaphore/test3/createsemaphore.c +** +** Purpose: Test attributes of CreateSemaphoreA and ReleaseSemaphore. +** Insure for CreateSemaphore that lInitialCount and lMaximumCount +** constraints are respected. Validate that CreateSemaphore rejects +** conditions where initial count and / or maximum count are negative +** and conditions where the initial count is greater than the maximum +** count. For ReleaseSemaphore validate that lpPreviousCount gets set +** to the previous semaphore count and lpPreviousCount can be NULL. +** Also establish ReleaseSemaphore fails when called in a semaphore +** with count equal to lMaximumCount. +** +** +**==========================================================================*/ + +#include + +struct testcase +{ + LPSECURITY_ATTRIBUTES lpSemaphoreAttributes; + LONG lInitialCount; + LONG lMaximumCount; + LPCTSTR lpName; + BOOL bNegativeTest; +}; + +struct testcase testCases[] = +{ + {NULL, -1, 1, NULL, TRUE}, + {NULL, 1, -1, NULL, TRUE}, + {NULL, -1, -1, NULL, TRUE}, + {NULL, 2, 1, NULL, TRUE}, + {NULL, 1, 2, NULL, FALSE}, + {NULL, 0, 10, NULL, FALSE}, + {NULL, INT_MAX - 1, INT_MAX, NULL, FALSE}, + {NULL, INT_MAX, INT_MAX, NULL, FALSE} +}; + +HANDLE hSemaphore[sizeof(testCases)/sizeof(struct testcase)]; + +BOOL cleanup(int index) +{ + int i; + BOOL bRet = TRUE; + for (i = 0; i < index; i++) + { + if (!CloseHandle(hSemaphore[i])) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CloseHandle(%p) call failed for index %d\n", + hSemaphore[i], i); + } + } + return(bRet); +} + +int __cdecl main (int argc, char **argv) +{ + int i; + int j; + + if(0 != (PAL_Initialize(argc, argv))) + { + return (FAIL); + } + /* create semaphores */ + for (i = 0; i < sizeof(testCases)/sizeof(struct testcase); i++) + { + hSemaphore[i] = CreateSemaphoreA (testCases[i].lpSemaphoreAttributes, + testCases[i].lInitialCount, + testCases[i].lMaximumCount, + testCases[i].lpName); + + if (NULL == hSemaphore[i]) + { + if (!testCases[i].bNegativeTest) + { + Trace("PALSUITE ERROR: CreateSemaphoreA('%p' '%ld' '%ld' " + "'%p') returned NULL at index %d.\nGetLastError " + "returned %d.\n", testCases[i].lpSemaphoreAttributes, + testCases[i].lInitialCount, testCases[i].lMaximumCount, + testCases[i].lpName, i, GetLastError()); + if (i > 0) + { + cleanup(i - 1); + } + Fail(""); + } + else + { + continue; + } + } + + /* increment semaphore count to lMaximumCount */ + for (j = testCases[i].lInitialCount; (ULONG)j <= (ULONG)testCases[i].lMaximumCount; + j++) + { + if (testCases[i].lMaximumCount == j) + { + /* Call ReleaseSemaphore once more to ensure ReleaseSemaphore + fails */ + if(ReleaseSemaphore(hSemaphore[i], 1, NULL)) + { + Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " + "call returned %d\nwhen it should have returned " + "%d.\nThe semaphore's count was %d.\nGetLastError " + "returned %d.\n", hSemaphore[i], 1, NULL, TRUE, + FALSE, j, GetLastError()); + cleanup(i); + Fail(""); + } + } + else + { + int previous; + BOOL bRet = ReleaseSemaphore(hSemaphore[i], 1, &previous); + DWORD dwError = GetLastError(); + + if(!bRet) + { + Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " + "call returned %d\nwhen it should have returned " + "%d.\nThe semaphore count was %d and it's " + "lMaxCount was %d.\nGetLastError returned %d.\n", + hSemaphore[i], 1, &previous, bRet, TRUE, j, + testCases[i].lMaximumCount, dwError); + cleanup(i); + Fail(""); + } + if (previous != j) + { + Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " + "call set %p to %d instead of %d.\n The semaphore " + "count was %d and GetLastError returned %d.\n", + hSemaphore[i], 1, &previous, &previous, previous, + j, j, dwError); + cleanup(i); + Fail(""); + } + } + } + + // Skip exhaustive decrement tests for too large an initial count + if(testCases[i].lInitialCount >= INT_MAX - 1) + { + continue; + } + + /* decrement semaphore count to 0 */ + for (j = testCases[i].lMaximumCount; j >= 0; j--) + { + DWORD dwRet = WaitForSingleObject(hSemaphore[i], 0); + DWORD dwError = GetLastError(); + + if (0 == j) + { + /* WaitForSingleObject should report that the + semaphore is nonsignaled */ + if (WAIT_TIMEOUT != dwRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject('%p' '%u') " + "call returned %d\nwhen it should have returned " + "%d.\nThe semaphore's count was %d.\nGetLastError " + "returned %d.\n", hSemaphore[i], 0, dwRet, + WAIT_TIMEOUT, j, dwError); + cleanup(i); + Fail(""); + } + } + else + { + /* WaitForSingleObject should report that the + semaphore is signaled */ + if (WAIT_OBJECT_0 != dwRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject('%p' '%u') " + "call returned %d\nwhen it should have returned " + "%d.\nThe semaphore's count was %d.\nGetLastError " + "returned %d.\n", hSemaphore[i], 0, dwRet, + WAIT_OBJECT_0, j, dwError); + cleanup(i); + Fail(""); + } + } + } + } + PAL_Terminate(); + return (PASS); +} + + + + diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CMakeLists.txt index b40f2695bc..32902cf914 100644 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateSemaphore.c + CreateSemaphore.cpp ) add_executable(paltest_createsemaphorew_releasesemaphore_test1 diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.c b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.c deleted file mode 100644 index 854d16d0ef..0000000000 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.c +++ /dev/null @@ -1,323 +0,0 @@ -// 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: CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.c -** -** Purpose: Test Semaphore operation using classic IPC problem: -** "Producer-Consumer Problem". -** -** Dependencies: CreateThread -** ReleaseSemaphore -** WaitForSingleObject -** Sleep -** fflush -** - -** -**=========================================================*/ - -#define UNICODE -#include - -#define PRODUCTION_TOTAL 26 - -#define _BUF_SIZE 10 - -DWORD dwThreadId; /* consumer thread identifier */ - -HANDLE hThread; /* handle to consumer thread */ - -HANDLE hSemaphoreM; /* handle to mutual exclusion semaphore */ - -HANDLE hSemaphoreE; /* handle to semaphore that counts empty buffer slots */ - -HANDLE hSemaphoreF; /* handle to semaphore that counts full buffer slots */ - -typedef struct Buffer -{ - short readIndex; - short writeIndex; - CHAR message[_BUF_SIZE]; - -} BufferStructure; - -CHAR producerItems[PRODUCTION_TOTAL + 1]; - -CHAR consumerItems[PRODUCTION_TOTAL + 1]; - -/* - * Read next message from the Buffer into provided pointer. - * Returns: 0 on failure, 1 on success. - */ -int -readBuf(BufferStructure *Buffer, char *c) -{ - if( Buffer -> writeIndex == Buffer -> readIndex ) - { - return 0; - } - *c = Buffer -> message[Buffer -> readIndex++]; - Buffer -> readIndex %= _BUF_SIZE; - return 1; -} - -/* - * Write message generated by the producer to Buffer. - * Returns: 0 on failure, 1 on success. - */ -int -writeBuf(BufferStructure *Buffer, CHAR c) -{ - if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == - (Buffer -> readIndex) ) - { - return 0; - } - Buffer -> message[Buffer -> writeIndex++] = c; - Buffer -> writeIndex %= _BUF_SIZE; - return 1; -} - -/* - * Atomic decrement of semaphore value. - */ -VOID -down(HANDLE hSemaphore) -{ - switch ( (WaitForSingleObject ( - hSemaphore, - 10000))) /* Wait 10 seconds */ - { - case WAIT_OBJECT_0: /* - * Semaphore was signaled. OK to access - * semaphore. - */ - break; - case WAIT_ABANDONED: /* - * Object was mutex object whose owning - * thread has terminated. Shouldn't occur. - */ - Fail("WaitForSingleObject call returned 'WAIT_ABANDONED'.\n" - "Failing Test.\n"); - break; - case WAIT_FAILED: /* WaitForSingleObject function failed */ - Fail("WaitForSingleObject call returned 'WAIT_FAILED'.\n" - "GetLastError returned %d\nFailing Test.\n",GetLastError()); - break; - default: - Fail("WaitForSingleObject call returned an unexpected value.\n" - "Failing Test.\n"); - break; - } - -} - -/* - * Atomic increment of semaphore value. - */ -VOID -up(HANDLE hSemaphore) -{ - if (!ReleaseSemaphore ( - hSemaphore, - 1, - NULL) - ) - { - Fail("ReleaseSemaphore call failed. GetLastError returned %d\n", - GetLastError()); - } -} - -/* - * Sleep 500 milleseconds. - */ -VOID -consumerSleep(VOID) -{ - Sleep(500); -} - -/* - * Sleep between 10 milleseconds. - */ -VOID -producerSleep(VOID) -{ - Sleep(10); -} - -/* - * Produce a message and write the message to Buffer. - */ -VOID -producer(BufferStructure *Buffer) -{ - - int n = 0; - char c; - - while (n < PRODUCTION_TOTAL) - { - c = 'A' + n ; /* Produce Item */ - - down(hSemaphoreE); - down(hSemaphoreM); - - if (writeBuf(Buffer, c)) - { - Trace("Producer produces %c.\n", c); - fflush(stdout); - producerItems[n++] = c; - } - - up(hSemaphoreM); - up(hSemaphoreF); - - producerSleep(); - } - - return; -} - -/* - * Read and "Consume" the messages in Buffer. - */ -DWORD -PALAPI -consumer( LPVOID lpParam ) -{ - int n = 0; - char c; - - consumerSleep(); - - while (n < PRODUCTION_TOTAL) - { - - down(hSemaphoreF); - down(hSemaphoreM); - - if (readBuf((BufferStructure*)lpParam, &c)) - { - Trace("\tConsumer consumes %c.\n", c); - fflush(stdout); - consumerItems[n++] = c; - } - - up(hSemaphoreM); - up(hSemaphoreE); - - consumerSleep(); - } - - return 0; -} - -int __cdecl main (int argc, char **argv) -{ - - BufferStructure Buffer, *pBuffer; - - pBuffer = &Buffer; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - /* - * Create Semaphores - */ - hSemaphoreM = CreateSemaphoreW ( - NULL, - 1, - 1, - NULL); - - if ( NULL == hSemaphoreM ) - { - Fail ( "hSemaphoreM = CreateSemaphoreW () - returned NULL\n" - "Failing Test.\nGetLastError returned %d\n", GetLastError()); - } - - - hSemaphoreE = CreateSemaphoreW ( - NULL, - _BUF_SIZE , - _BUF_SIZE , - NULL); - - if ( NULL == hSemaphoreE ) - { - Fail ( "hSemaphoreE = CreateSemaphoreW () - returned NULL\n" - "Failing Test.\nGetLastError returned %d\n", GetLastError()); - } - - hSemaphoreF = CreateSemaphoreW ( - NULL, - 0, - _BUF_SIZE , - NULL); - - if ( NULL == hSemaphoreF ) - { - Fail ( "hSemaphoreF = CreateSemaphoreW () - returned NULL\n" - "Failing Test.\nGetLastError returned %d\n", GetLastError()); - } - - - /* - * Initialize Buffer - */ - pBuffer->writeIndex = pBuffer->readIndex = 0; - - /* - * Create Consumer - */ - hThread = CreateThread( - NULL, - 0, - consumer, - &Buffer, - 0, - &dwThreadId); - - if ( NULL == hThread ) - { - Fail ( "CreateThread() returned NULL. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - /* - * Start producing - */ - producer(pBuffer); - - /* - * Wait for consumer to complete - */ - WaitForSingleObject (hThread, INFINITE); - - /* - * Compare items produced vs. items consumed - */ - if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) - { - Fail("The producerItems string %s\n and the consumerItems string " - "%s\ndo not match. This could be a problem with the strncmp()" - " function\n FailingTest\nGetLastError() returned %d\n", - producerItems, consumerItems, GetLastError()); - } - - Trace ("producerItems and consumerItems arrays match. All %d\nitems " - "were produced and consumed in order.\nTest passed.\n", - PRODUCTION_TOTAL); - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.cpp b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.cpp new file mode 100644 index 0000000000..854d16d0ef --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.cpp @@ -0,0 +1,323 @@ +// 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: CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.c +** +** Purpose: Test Semaphore operation using classic IPC problem: +** "Producer-Consumer Problem". +** +** Dependencies: CreateThread +** ReleaseSemaphore +** WaitForSingleObject +** Sleep +** fflush +** + +** +**=========================================================*/ + +#define UNICODE +#include + +#define PRODUCTION_TOTAL 26 + +#define _BUF_SIZE 10 + +DWORD dwThreadId; /* consumer thread identifier */ + +HANDLE hThread; /* handle to consumer thread */ + +HANDLE hSemaphoreM; /* handle to mutual exclusion semaphore */ + +HANDLE hSemaphoreE; /* handle to semaphore that counts empty buffer slots */ + +HANDLE hSemaphoreF; /* handle to semaphore that counts full buffer slots */ + +typedef struct Buffer +{ + short readIndex; + short writeIndex; + CHAR message[_BUF_SIZE]; + +} BufferStructure; + +CHAR producerItems[PRODUCTION_TOTAL + 1]; + +CHAR consumerItems[PRODUCTION_TOTAL + 1]; + +/* + * Read next message from the Buffer into provided pointer. + * Returns: 0 on failure, 1 on success. + */ +int +readBuf(BufferStructure *Buffer, char *c) +{ + if( Buffer -> writeIndex == Buffer -> readIndex ) + { + return 0; + } + *c = Buffer -> message[Buffer -> readIndex++]; + Buffer -> readIndex %= _BUF_SIZE; + return 1; +} + +/* + * Write message generated by the producer to Buffer. + * Returns: 0 on failure, 1 on success. + */ +int +writeBuf(BufferStructure *Buffer, CHAR c) +{ + if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == + (Buffer -> readIndex) ) + { + return 0; + } + Buffer -> message[Buffer -> writeIndex++] = c; + Buffer -> writeIndex %= _BUF_SIZE; + return 1; +} + +/* + * Atomic decrement of semaphore value. + */ +VOID +down(HANDLE hSemaphore) +{ + switch ( (WaitForSingleObject ( + hSemaphore, + 10000))) /* Wait 10 seconds */ + { + case WAIT_OBJECT_0: /* + * Semaphore was signaled. OK to access + * semaphore. + */ + break; + case WAIT_ABANDONED: /* + * Object was mutex object whose owning + * thread has terminated. Shouldn't occur. + */ + Fail("WaitForSingleObject call returned 'WAIT_ABANDONED'.\n" + "Failing Test.\n"); + break; + case WAIT_FAILED: /* WaitForSingleObject function failed */ + Fail("WaitForSingleObject call returned 'WAIT_FAILED'.\n" + "GetLastError returned %d\nFailing Test.\n",GetLastError()); + break; + default: + Fail("WaitForSingleObject call returned an unexpected value.\n" + "Failing Test.\n"); + break; + } + +} + +/* + * Atomic increment of semaphore value. + */ +VOID +up(HANDLE hSemaphore) +{ + if (!ReleaseSemaphore ( + hSemaphore, + 1, + NULL) + ) + { + Fail("ReleaseSemaphore call failed. GetLastError returned %d\n", + GetLastError()); + } +} + +/* + * Sleep 500 milleseconds. + */ +VOID +consumerSleep(VOID) +{ + Sleep(500); +} + +/* + * Sleep between 10 milleseconds. + */ +VOID +producerSleep(VOID) +{ + Sleep(10); +} + +/* + * Produce a message and write the message to Buffer. + */ +VOID +producer(BufferStructure *Buffer) +{ + + int n = 0; + char c; + + while (n < PRODUCTION_TOTAL) + { + c = 'A' + n ; /* Produce Item */ + + down(hSemaphoreE); + down(hSemaphoreM); + + if (writeBuf(Buffer, c)) + { + Trace("Producer produces %c.\n", c); + fflush(stdout); + producerItems[n++] = c; + } + + up(hSemaphoreM); + up(hSemaphoreF); + + producerSleep(); + } + + return; +} + +/* + * Read and "Consume" the messages in Buffer. + */ +DWORD +PALAPI +consumer( LPVOID lpParam ) +{ + int n = 0; + char c; + + consumerSleep(); + + while (n < PRODUCTION_TOTAL) + { + + down(hSemaphoreF); + down(hSemaphoreM); + + if (readBuf((BufferStructure*)lpParam, &c)) + { + Trace("\tConsumer consumes %c.\n", c); + fflush(stdout); + consumerItems[n++] = c; + } + + up(hSemaphoreM); + up(hSemaphoreE); + + consumerSleep(); + } + + return 0; +} + +int __cdecl main (int argc, char **argv) +{ + + BufferStructure Buffer, *pBuffer; + + pBuffer = &Buffer; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + /* + * Create Semaphores + */ + hSemaphoreM = CreateSemaphoreW ( + NULL, + 1, + 1, + NULL); + + if ( NULL == hSemaphoreM ) + { + Fail ( "hSemaphoreM = CreateSemaphoreW () - returned NULL\n" + "Failing Test.\nGetLastError returned %d\n", GetLastError()); + } + + + hSemaphoreE = CreateSemaphoreW ( + NULL, + _BUF_SIZE , + _BUF_SIZE , + NULL); + + if ( NULL == hSemaphoreE ) + { + Fail ( "hSemaphoreE = CreateSemaphoreW () - returned NULL\n" + "Failing Test.\nGetLastError returned %d\n", GetLastError()); + } + + hSemaphoreF = CreateSemaphoreW ( + NULL, + 0, + _BUF_SIZE , + NULL); + + if ( NULL == hSemaphoreF ) + { + Fail ( "hSemaphoreF = CreateSemaphoreW () - returned NULL\n" + "Failing Test.\nGetLastError returned %d\n", GetLastError()); + } + + + /* + * Initialize Buffer + */ + pBuffer->writeIndex = pBuffer->readIndex = 0; + + /* + * Create Consumer + */ + hThread = CreateThread( + NULL, + 0, + consumer, + &Buffer, + 0, + &dwThreadId); + + if ( NULL == hThread ) + { + Fail ( "CreateThread() returned NULL. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + /* + * Start producing + */ + producer(pBuffer); + + /* + * Wait for consumer to complete + */ + WaitForSingleObject (hThread, INFINITE); + + /* + * Compare items produced vs. items consumed + */ + if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) + { + Fail("The producerItems string %s\n and the consumerItems string " + "%s\ndo not match. This could be a problem with the strncmp()" + " function\n FailingTest\nGetLastError() returned %d\n", + producerItems, consumerItems, GetLastError()); + } + + Trace ("producerItems and consumerItems arrays match. All %d\nitems " + "were produced and consumed in order.\nTest passed.\n", + PRODUCTION_TOTAL); + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CMakeLists.txt index b14284d08f..bd0a5a6e53 100644 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - CreateSemaphore.c + CreateSemaphore.cpp ) add_executable(paltest_createsemaphorew_releasesemaphore_test2 diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CreateSemaphore.c b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CreateSemaphore.c deleted file mode 100644 index 62532737ac..0000000000 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CreateSemaphore.c +++ /dev/null @@ -1,314 +0,0 @@ -// 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: CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.c -** -** Purpose: Test Semaphore operation using classic IPC problem: -** "Producer-Consumer Problem". -** -** Dependencies: CreateThread -** ReleaseSemaphore -** WaitForSingleObject -** Sleep -** fflush -** - -** -**=========================================================*/ - -#define UNICODE -#include - -#define PRODUCTION_TOTAL 26 - -#define _BUF_SIZE 10 - -DWORD dwThreadId; /* consumer thread identifier */ - -HANDLE hThread; /* handle to consumer thread */ - -HANDLE hSemaphoreM; /* handle to mutual exclusion semaphore */ - -HANDLE hSemaphoreE; /* handle to semaphore that counts empty buffer slots */ - -HANDLE hSemaphoreF; /* handle to semaphore that counts full buffer slots */ - -typedef struct Buffer -{ - short readIndex; - short writeIndex; - CHAR message[_BUF_SIZE]; - -} BufferStructure; - -CHAR producerItems[PRODUCTION_TOTAL + 1]; - -CHAR consumerItems[PRODUCTION_TOTAL + 1]; - -/* - * Read next message from the Buffer into provided pointer. - * Returns: 0 on failure, 1 on success. - */ -int -readBuf(BufferStructure *Buffer, char *c) -{ - if( Buffer -> writeIndex == Buffer -> readIndex ) - { - return 0; - } - *c = Buffer -> message[Buffer -> readIndex++]; - Buffer -> readIndex %= _BUF_SIZE; - return 1; -} - -/* - * Write message generated by the producer to Buffer. - * Returns: 0 on failure, 1 on success. - */ -int -writeBuf(BufferStructure *Buffer, CHAR c) -{ - if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == - (Buffer -> readIndex) ) - { - return 0; - } - Buffer -> message[Buffer -> writeIndex++] = c; - Buffer -> writeIndex %= _BUF_SIZE; - return 1; -} - -/* - * Atomic decrement of semaphore value. - */ -VOID -down(HANDLE hSemaphore) -{ - switch ( (WaitForSingleObject ( - hSemaphore, - 10000))) - { - case WAIT_OBJECT_0: /* - * Semaphore was signaled. OK to access semaphore. - */ - break; - case WAIT_ABANDONED: /* - * Object was mutex object whose owning - * thread has terminated. Shouldn't occur. - */ - Fail("WaitForSingleObject call returned 'WAIT_ABANDONED'.\n" - "Failing Test.\n"); - break; - case WAIT_FAILED: /* WaitForSingleObject function failed */ - Fail("WaitForSingleObject call returned 'WAIT_FAILED'.\n" - "GetLastError returned %d\nFailing Test.\n",GetLastError()); - break; - default: - Fail("WaitForSingleObject call returned an unexpected value.\n" - "Failing Test.\n"); - break; - } - -} - -/* - * Atomic increment of semaphore value. - */ -VOID -up(HANDLE hSemaphore) -{ - if (!ReleaseSemaphore ( - hSemaphore, - 1, - NULL) - ) - { - Fail("ReleaseSemaphore call failed. GetLastError returned %d\n", - GetLastError()); - } -} - -/* - * Sleep 10 milleseconds. - */ -VOID -consumerSleep(VOID) -{ - Sleep(10); -} - -/* - * Sleep 500 milleseconds. - */ -VOID -producerSleep(VOID) -{ - Sleep(500); -} - -/* - * Produce a message and write the message to Buffer. - */ -VOID -producer(BufferStructure *Buffer) -{ - - int n = 0; - char c; - - while (n < PRODUCTION_TOTAL) - { - c = 'A' + n ; /* Produce Item */ - - down(hSemaphoreE); - down(hSemaphoreM); - - if (writeBuf(Buffer, c)) - { - Trace("Producer produces %c.\n", c); - fflush(stdout); - producerItems[n++] = c; - } - - up(hSemaphoreM); - up(hSemaphoreF); - - producerSleep(); - } - return; -} - -/* - * Read and "Consume" the messages in Buffer. - */ -DWORD -PALAPI -consumer( LPVOID lpParam ) -{ - int n = 0; - char c; - - consumerSleep(); - - while (n < PRODUCTION_TOTAL) - { - - down(hSemaphoreF); - down(hSemaphoreM); - - if (readBuf((BufferStructure*)lpParam, &c)) - { - Trace("\tConsumer consumes %c.\n", c); - fflush(stdout); - consumerItems[n++] = c; - } - - up(hSemaphoreM); - up(hSemaphoreE); - - consumerSleep(); - } - return 0; -} - -int __cdecl main (int argc, char **argv) -{ - - BufferStructure Buffer, *pBuffer; - - pBuffer = &Buffer; - - if(0 != (PAL_Initialize(argc, argv))) - { - return (FAIL); - } - - /* - * Create Semaphores - */ - hSemaphoreM = CreateSemaphoreW ( - NULL, - 1, - 1, - NULL); - - if ( NULL == hSemaphoreM ) - { - Fail ( "hSemaphoreM = CreateSemaphoreW () - returned NULL\n" - "Failing Test.\n"); - } - - hSemaphoreE = CreateSemaphoreW ( - NULL, - _BUF_SIZE , - _BUF_SIZE , - NULL); - - if ( NULL == hSemaphoreE ) - { - Fail ( "hSemaphoreE = CreateSemaphoreW () - returned NULL\n" - "Failing Test.\n"); - } - - hSemaphoreF = CreateSemaphoreW ( - NULL, - 0, - _BUF_SIZE , - NULL); - - if ( NULL == hSemaphoreF ) - { - Fail ( "hSemaphoreF = CreateSemaphoreW () - returned NULL\n" - "Failing Test.\n"); - } - - /* - * Initialize Buffer - */ - pBuffer->writeIndex = pBuffer->readIndex = 0; - - /* - * Create Consumer - */ - hThread = CreateThread( - NULL, - 0, - consumer, - &Buffer, - 0, - &dwThreadId); - - if ( NULL == hThread ) - { - Fail ( "CreateThread() returned NULL. Failing test.\n"); - } - - /* - * Start producing - */ - producer(pBuffer); - - /* - * Wait for consumer to complete - */ - WaitForSingleObject (hThread, INFINITE); - - if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) - { - Fail("The producerItems string %s\n and the consumerItems string " - "%s\ndo not match. This could be a problem with the strncmp()" - " function\n FailingTest\nGetLastError() returned %d\n", - producerItems, consumerItems, GetLastError()); - } - - Trace ("producerItems and consumerItems arrays match. All %d\nitems " - "were produced and consumed in order.\nTest passed.\n", - PRODUCTION_TOTAL); - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CreateSemaphore.cpp b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CreateSemaphore.cpp new file mode 100644 index 0000000000..62532737ac --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test2/CreateSemaphore.cpp @@ -0,0 +1,314 @@ +// 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: CreateSemaphoreW_ReleaseSemaphore/test1/CreateSemaphore.c +** +** Purpose: Test Semaphore operation using classic IPC problem: +** "Producer-Consumer Problem". +** +** Dependencies: CreateThread +** ReleaseSemaphore +** WaitForSingleObject +** Sleep +** fflush +** + +** +**=========================================================*/ + +#define UNICODE +#include + +#define PRODUCTION_TOTAL 26 + +#define _BUF_SIZE 10 + +DWORD dwThreadId; /* consumer thread identifier */ + +HANDLE hThread; /* handle to consumer thread */ + +HANDLE hSemaphoreM; /* handle to mutual exclusion semaphore */ + +HANDLE hSemaphoreE; /* handle to semaphore that counts empty buffer slots */ + +HANDLE hSemaphoreF; /* handle to semaphore that counts full buffer slots */ + +typedef struct Buffer +{ + short readIndex; + short writeIndex; + CHAR message[_BUF_SIZE]; + +} BufferStructure; + +CHAR producerItems[PRODUCTION_TOTAL + 1]; + +CHAR consumerItems[PRODUCTION_TOTAL + 1]; + +/* + * Read next message from the Buffer into provided pointer. + * Returns: 0 on failure, 1 on success. + */ +int +readBuf(BufferStructure *Buffer, char *c) +{ + if( Buffer -> writeIndex == Buffer -> readIndex ) + { + return 0; + } + *c = Buffer -> message[Buffer -> readIndex++]; + Buffer -> readIndex %= _BUF_SIZE; + return 1; +} + +/* + * Write message generated by the producer to Buffer. + * Returns: 0 on failure, 1 on success. + */ +int +writeBuf(BufferStructure *Buffer, CHAR c) +{ + if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == + (Buffer -> readIndex) ) + { + return 0; + } + Buffer -> message[Buffer -> writeIndex++] = c; + Buffer -> writeIndex %= _BUF_SIZE; + return 1; +} + +/* + * Atomic decrement of semaphore value. + */ +VOID +down(HANDLE hSemaphore) +{ + switch ( (WaitForSingleObject ( + hSemaphore, + 10000))) + { + case WAIT_OBJECT_0: /* + * Semaphore was signaled. OK to access semaphore. + */ + break; + case WAIT_ABANDONED: /* + * Object was mutex object whose owning + * thread has terminated. Shouldn't occur. + */ + Fail("WaitForSingleObject call returned 'WAIT_ABANDONED'.\n" + "Failing Test.\n"); + break; + case WAIT_FAILED: /* WaitForSingleObject function failed */ + Fail("WaitForSingleObject call returned 'WAIT_FAILED'.\n" + "GetLastError returned %d\nFailing Test.\n",GetLastError()); + break; + default: + Fail("WaitForSingleObject call returned an unexpected value.\n" + "Failing Test.\n"); + break; + } + +} + +/* + * Atomic increment of semaphore value. + */ +VOID +up(HANDLE hSemaphore) +{ + if (!ReleaseSemaphore ( + hSemaphore, + 1, + NULL) + ) + { + Fail("ReleaseSemaphore call failed. GetLastError returned %d\n", + GetLastError()); + } +} + +/* + * Sleep 10 milleseconds. + */ +VOID +consumerSleep(VOID) +{ + Sleep(10); +} + +/* + * Sleep 500 milleseconds. + */ +VOID +producerSleep(VOID) +{ + Sleep(500); +} + +/* + * Produce a message and write the message to Buffer. + */ +VOID +producer(BufferStructure *Buffer) +{ + + int n = 0; + char c; + + while (n < PRODUCTION_TOTAL) + { + c = 'A' + n ; /* Produce Item */ + + down(hSemaphoreE); + down(hSemaphoreM); + + if (writeBuf(Buffer, c)) + { + Trace("Producer produces %c.\n", c); + fflush(stdout); + producerItems[n++] = c; + } + + up(hSemaphoreM); + up(hSemaphoreF); + + producerSleep(); + } + return; +} + +/* + * Read and "Consume" the messages in Buffer. + */ +DWORD +PALAPI +consumer( LPVOID lpParam ) +{ + int n = 0; + char c; + + consumerSleep(); + + while (n < PRODUCTION_TOTAL) + { + + down(hSemaphoreF); + down(hSemaphoreM); + + if (readBuf((BufferStructure*)lpParam, &c)) + { + Trace("\tConsumer consumes %c.\n", c); + fflush(stdout); + consumerItems[n++] = c; + } + + up(hSemaphoreM); + up(hSemaphoreE); + + consumerSleep(); + } + return 0; +} + +int __cdecl main (int argc, char **argv) +{ + + BufferStructure Buffer, *pBuffer; + + pBuffer = &Buffer; + + if(0 != (PAL_Initialize(argc, argv))) + { + return (FAIL); + } + + /* + * Create Semaphores + */ + hSemaphoreM = CreateSemaphoreW ( + NULL, + 1, + 1, + NULL); + + if ( NULL == hSemaphoreM ) + { + Fail ( "hSemaphoreM = CreateSemaphoreW () - returned NULL\n" + "Failing Test.\n"); + } + + hSemaphoreE = CreateSemaphoreW ( + NULL, + _BUF_SIZE , + _BUF_SIZE , + NULL); + + if ( NULL == hSemaphoreE ) + { + Fail ( "hSemaphoreE = CreateSemaphoreW () - returned NULL\n" + "Failing Test.\n"); + } + + hSemaphoreF = CreateSemaphoreW ( + NULL, + 0, + _BUF_SIZE , + NULL); + + if ( NULL == hSemaphoreF ) + { + Fail ( "hSemaphoreF = CreateSemaphoreW () - returned NULL\n" + "Failing Test.\n"); + } + + /* + * Initialize Buffer + */ + pBuffer->writeIndex = pBuffer->readIndex = 0; + + /* + * Create Consumer + */ + hThread = CreateThread( + NULL, + 0, + consumer, + &Buffer, + 0, + &dwThreadId); + + if ( NULL == hThread ) + { + Fail ( "CreateThread() returned NULL. Failing test.\n"); + } + + /* + * Start producing + */ + producer(pBuffer); + + /* + * Wait for consumer to complete + */ + WaitForSingleObject (hThread, INFINITE); + + if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) + { + Fail("The producerItems string %s\n and the consumerItems string " + "%s\ndo not match. This could be a problem with the strncmp()" + " function\n FailingTest\nGetLastError() returned %d\n", + producerItems, consumerItems, GetLastError()); + } + + Trace ("producerItems and consumerItems arrays match. All %d\nitems " + "were produced and consumed in order.\nTest passed.\n", + PRODUCTION_TOTAL); + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/CMakeLists.txt index f7f0905761..d0340c64cb 100644 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - createsemaphore.c + createsemaphore.cpp ) add_executable(paltest_createsemaphorew_releasesemaphore_test3 diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/createsemaphore.c b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/createsemaphore.c deleted file mode 100644 index ea0a5e0846..0000000000 --- a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/createsemaphore.c +++ /dev/null @@ -1,201 +0,0 @@ -// 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: createsemaphorew_releasesemaphore/test3/createsemaphore.c -** -** Purpose: Test attributes of CreateSemaphoreW and ReleaseSemaphore. -** Insure for CreateSemaphore that lInitialCount and lMaximumCount -** constraints are respected. Validate that CreateSemaphore rejects -** conditions where initial count and / or maximum count are negative -** and conditions where the initial count is greater than the maximum -** count. For ReleaseSemaphore validate that lpPreviousCount gets set -** to the previous semaphore count and lpPreviousCount can be NULL. -** Also establish ReleaseSemaphore fails when called in a semaphore -** with count equal to lMaximumCount. -** -** -**==========================================================================*/ - -#include - -struct testcase -{ - LPSECURITY_ATTRIBUTES lpSemaphoreAttributes; - LONG lInitialCount; - LONG lMaximumCount; - LPCWSTR lpName; - BOOL bNegativeTest; -}; - -struct testcase testCases[] = -{ - {NULL, -1, 1, NULL, TRUE}, - {NULL, 1, -1, NULL, TRUE}, - {NULL, -1, -1, NULL, TRUE}, - {NULL, 2, 1, NULL, TRUE}, - {NULL, 1, 2, NULL, FALSE}, - {NULL, 0, 10, NULL, FALSE}, - {NULL, INT_MAX - 1, INT_MAX, NULL, FALSE}, - {NULL, INT_MAX, INT_MAX, NULL, FALSE} -}; - -HANDLE hSemaphore[sizeof(testCases)/sizeof(struct testcase)]; - -BOOL cleanup(int index) -{ - int i; - BOOL bRet = TRUE; - for (i = 0; i < index; i++) - { - if (!CloseHandle(hSemaphore[i])) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CloseHandle(%p) call failed for index %d\n", - hSemaphore[i], i); - } - } - return(bRet); -} - -int __cdecl main (int argc, char **argv) -{ - int i; - int j; - - if(0 != (PAL_Initialize(argc, argv))) - { - return (FAIL); - } - /* create semaphores */ - for (i = 0; i < sizeof(testCases)/sizeof(struct testcase); i++) - { - hSemaphore[i] = CreateSemaphoreW (testCases[i].lpSemaphoreAttributes, - testCases[i].lInitialCount, - testCases[i].lMaximumCount, - testCases[i].lpName); - - if (NULL == hSemaphore[i]) - { - if (!testCases[i].bNegativeTest) - { - Trace("PALSUITE ERROR: CreateSemaphoreW('%p' '%ld' '%ld' " - "'%p') returned NULL at index %d.\nGetLastError " - "returned %d.\n", testCases[i].lpSemaphoreAttributes, - testCases[i].lInitialCount, testCases[i].lMaximumCount, - testCases[i].lpName, i, GetLastError()); - if (i > 0) - { - cleanup(i - 1); - } - Fail(""); - } - else - { - continue; - } - } - - /* increment semaphore count to lMaximumCount */ - for (j = testCases[i].lInitialCount; (ULONG)j <= (ULONG)testCases[i].lMaximumCount; - j++) - { - if (testCases[i].lMaximumCount == j) - { - /* Call ReleaseSemaphore once more to ensure ReleaseSemaphore - fails */ - if(ReleaseSemaphore(hSemaphore[i], 1, NULL)) - { - Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " - "call returned %d\nwhen it should have returned " - "%d.\nThe semaphore's count was %d.\nGetLastError " - "returned %d.\n", hSemaphore[i], 1, NULL, TRUE, - FALSE, j, GetLastError()); - cleanup(i); - Fail(""); - } - } - else - { - int previous; - BOOL bRet = ReleaseSemaphore(hSemaphore[i], 1, &previous); - DWORD dwError = GetLastError(); - - if(!bRet) - { - Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " - "call returned %d\nwhen it should have returned " - "%d.\nThe semaphore count was %d and it's " - "lMaxCount was %d.\nGetLastError returned %d.\n", - hSemaphore[i], 1, &previous, bRet, TRUE, j, - testCases[i].lMaximumCount, dwError); - cleanup(i); - Fail(""); - } - if (previous != j) - { - Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " - "call set %p to %d instead of %d.\n The semaphore " - "count was %d and GetLastError returned %d.\n", - hSemaphore[i], 1, &previous, &previous, previous, - j, j, dwError); - cleanup(i); - Fail(""); - } - } - } - - // Skip exhaustive decrement tests for too large an initial count - if(testCases[i].lInitialCount >= INT_MAX - 1) - { - continue; - } - - /* decrement semaphore count to 0 */ - for (j = testCases[i].lMaximumCount; j >= 0; j--) - { - DWORD dwRet = WaitForSingleObject(hSemaphore[i], 0); - DWORD dwError = GetLastError(); - - if (0 == j) - { - /* WaitForSingleObject should report that the - semaphore is nonsignaled */ - if (WAIT_TIMEOUT != dwRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject('%p' '%u') " - "call returned %d\nwhen it should have returned " - "%d.\nThe semaphore's count was %d.\nGetLastError " - "returned %d.\n", hSemaphore[i], 0, dwRet, - WAIT_TIMEOUT, j, dwError); - cleanup(i); - Fail(""); - } - } - else - { - /* WaitForSingleObject should report that the - semaphore is signaled */ - if (WAIT_OBJECT_0 != dwRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject('%p' '%u') " - "call returned %d\nwhen it should have returned " - "%d.\nThe semaphore's count was %d.\nGetLastError " - "returned %d.\n", hSemaphore[i], 0, dwRet, - WAIT_OBJECT_0, j, dwError); - cleanup(i); - Fail(""); - } - } - } - } - PAL_Terminate(); - return (PASS); -} - - - - - diff --git a/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/createsemaphore.cpp b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/createsemaphore.cpp new file mode 100644 index 0000000000..ea0a5e0846 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateSemaphoreW_ReleaseSemaphore/test3/createsemaphore.cpp @@ -0,0 +1,201 @@ +// 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: createsemaphorew_releasesemaphore/test3/createsemaphore.c +** +** Purpose: Test attributes of CreateSemaphoreW and ReleaseSemaphore. +** Insure for CreateSemaphore that lInitialCount and lMaximumCount +** constraints are respected. Validate that CreateSemaphore rejects +** conditions where initial count and / or maximum count are negative +** and conditions where the initial count is greater than the maximum +** count. For ReleaseSemaphore validate that lpPreviousCount gets set +** to the previous semaphore count and lpPreviousCount can be NULL. +** Also establish ReleaseSemaphore fails when called in a semaphore +** with count equal to lMaximumCount. +** +** +**==========================================================================*/ + +#include + +struct testcase +{ + LPSECURITY_ATTRIBUTES lpSemaphoreAttributes; + LONG lInitialCount; + LONG lMaximumCount; + LPCWSTR lpName; + BOOL bNegativeTest; +}; + +struct testcase testCases[] = +{ + {NULL, -1, 1, NULL, TRUE}, + {NULL, 1, -1, NULL, TRUE}, + {NULL, -1, -1, NULL, TRUE}, + {NULL, 2, 1, NULL, TRUE}, + {NULL, 1, 2, NULL, FALSE}, + {NULL, 0, 10, NULL, FALSE}, + {NULL, INT_MAX - 1, INT_MAX, NULL, FALSE}, + {NULL, INT_MAX, INT_MAX, NULL, FALSE} +}; + +HANDLE hSemaphore[sizeof(testCases)/sizeof(struct testcase)]; + +BOOL cleanup(int index) +{ + int i; + BOOL bRet = TRUE; + for (i = 0; i < index; i++) + { + if (!CloseHandle(hSemaphore[i])) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CloseHandle(%p) call failed for index %d\n", + hSemaphore[i], i); + } + } + return(bRet); +} + +int __cdecl main (int argc, char **argv) +{ + int i; + int j; + + if(0 != (PAL_Initialize(argc, argv))) + { + return (FAIL); + } + /* create semaphores */ + for (i = 0; i < sizeof(testCases)/sizeof(struct testcase); i++) + { + hSemaphore[i] = CreateSemaphoreW (testCases[i].lpSemaphoreAttributes, + testCases[i].lInitialCount, + testCases[i].lMaximumCount, + testCases[i].lpName); + + if (NULL == hSemaphore[i]) + { + if (!testCases[i].bNegativeTest) + { + Trace("PALSUITE ERROR: CreateSemaphoreW('%p' '%ld' '%ld' " + "'%p') returned NULL at index %d.\nGetLastError " + "returned %d.\n", testCases[i].lpSemaphoreAttributes, + testCases[i].lInitialCount, testCases[i].lMaximumCount, + testCases[i].lpName, i, GetLastError()); + if (i > 0) + { + cleanup(i - 1); + } + Fail(""); + } + else + { + continue; + } + } + + /* increment semaphore count to lMaximumCount */ + for (j = testCases[i].lInitialCount; (ULONG)j <= (ULONG)testCases[i].lMaximumCount; + j++) + { + if (testCases[i].lMaximumCount == j) + { + /* Call ReleaseSemaphore once more to ensure ReleaseSemaphore + fails */ + if(ReleaseSemaphore(hSemaphore[i], 1, NULL)) + { + Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " + "call returned %d\nwhen it should have returned " + "%d.\nThe semaphore's count was %d.\nGetLastError " + "returned %d.\n", hSemaphore[i], 1, NULL, TRUE, + FALSE, j, GetLastError()); + cleanup(i); + Fail(""); + } + } + else + { + int previous; + BOOL bRet = ReleaseSemaphore(hSemaphore[i], 1, &previous); + DWORD dwError = GetLastError(); + + if(!bRet) + { + Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " + "call returned %d\nwhen it should have returned " + "%d.\nThe semaphore count was %d and it's " + "lMaxCount was %d.\nGetLastError returned %d.\n", + hSemaphore[i], 1, &previous, bRet, TRUE, j, + testCases[i].lMaximumCount, dwError); + cleanup(i); + Fail(""); + } + if (previous != j) + { + Trace("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " + "call set %p to %d instead of %d.\n The semaphore " + "count was %d and GetLastError returned %d.\n", + hSemaphore[i], 1, &previous, &previous, previous, + j, j, dwError); + cleanup(i); + Fail(""); + } + } + } + + // Skip exhaustive decrement tests for too large an initial count + if(testCases[i].lInitialCount >= INT_MAX - 1) + { + continue; + } + + /* decrement semaphore count to 0 */ + for (j = testCases[i].lMaximumCount; j >= 0; j--) + { + DWORD dwRet = WaitForSingleObject(hSemaphore[i], 0); + DWORD dwError = GetLastError(); + + if (0 == j) + { + /* WaitForSingleObject should report that the + semaphore is nonsignaled */ + if (WAIT_TIMEOUT != dwRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject('%p' '%u') " + "call returned %d\nwhen it should have returned " + "%d.\nThe semaphore's count was %d.\nGetLastError " + "returned %d.\n", hSemaphore[i], 0, dwRet, + WAIT_TIMEOUT, j, dwError); + cleanup(i); + Fail(""); + } + } + else + { + /* WaitForSingleObject should report that the + semaphore is signaled */ + if (WAIT_OBJECT_0 != dwRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject('%p' '%u') " + "call returned %d\nwhen it should have returned " + "%d.\nThe semaphore's count was %d.\nGetLastError " + "returned %d.\n", hSemaphore[i], 0, dwRet, + WAIT_OBJECT_0, j, dwError); + cleanup(i); + Fail(""); + } + } + } + } + PAL_Terminate(); + return (PASS); +} + + + + + diff --git a/src/pal/tests/palsuite/threading/CreateThread/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateThread/test1/CMakeLists.txt index d3921c4409..b47afe498a 100644 --- a/src/pal/tests/palsuite/threading/CreateThread/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateThread/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_createthread_test1 diff --git a/src/pal/tests/palsuite/threading/CreateThread/test1/test1.c b/src/pal/tests/palsuite/threading/CreateThread/test1/test1.c deleted file mode 100644 index 2dd2f6acb6..0000000000 --- a/src/pal/tests/palsuite/threading/CreateThread/test1/test1.c +++ /dev/null @@ -1,119 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for CreateThread. Call CreateThread and ensure -** that it succeeds. Also check to ensure the paramater is passed -** properly. -** -** -**=========================================================*/ - -#include - -#ifndef PLATFORM_UNIX -#define LLFORMAT "%I64u" -#else -#define LLFORMAT "%llu" -#endif - -ULONGLONG dwCreateThreadTestParameter = 0; - -DWORD PALAPI CreateThreadTestThread( LPVOID lpParameter) -{ - DWORD dwRet = 0; - - /* save parameter for test */ - dwCreateThreadTestParameter = (ULONGLONG)lpParameter; - - return dwRet; -} - -BOOL CreateThreadTest() -{ - BOOL bRet = FALSE; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL; - DWORD dwStackSize = 0; - LPTHREAD_START_ROUTINE lpStartAddress = &CreateThreadTestThread; - LPVOID lpParameter = lpStartAddress; - DWORD dwCreationFlags = 0; /* run immediately */ - DWORD dwThreadId = 0; - - HANDLE hThread = 0; - - dwCreateThreadTestParameter = 0; - - /* Create a thread, passing the appropriate paramaters as declared - above. - */ - - hThread = CreateThread( lpThreadAttributes, - dwStackSize, - lpStartAddress, - lpParameter, - dwCreationFlags, - &dwThreadId ); - - /* Ensure that the HANDLE is not invalid! */ - if (hThread != INVALID_HANDLE_VALUE) - { - dwRet = WaitForSingleObject(hThread,INFINITE); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("CreateThreadTest:WaitForSingleObject " - "failed (%x)\n",GetLastError()); - } - else - { - /* Check to ensure that the parameter passed to the thread - function is the same in the function as what we passed. - */ - - if (dwCreateThreadTestParameter != (ULONGLONG)lpParameter) - { - Trace("CreateThreadTest:parameter error. The " - "parameter passed should have been " LLFORMAT " but when " - "passed to the Thread function it was " LLFORMAT " . GetLastError[%x]\n", - dwCreateThreadTestParameter,lpParameter, GetLastError()); - } - else - { - bRet = TRUE; - } - - } - CloseHandle(hThread); - } - else - { - Trace("CreateThreadTest:CreateThread failed (%x)\n",GetLastError()); - } - - return bRet; -} - - -int __cdecl main(int argc, char **argv) -{ - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!CreateThreadTest()) - { - Fail ("Test failed\n"); - } - - Trace("Test Passed\n"); - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/CreateThread/test1/test1.cpp b/src/pal/tests/palsuite/threading/CreateThread/test1/test1.cpp new file mode 100644 index 0000000000..dda25f1f4b --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateThread/test1/test1.cpp @@ -0,0 +1,119 @@ +// 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: test1.c +** +** Purpose: Test for CreateThread. Call CreateThread and ensure +** that it succeeds. Also check to ensure the paramater is passed +** properly. +** +** +**=========================================================*/ + +#include + +#ifndef PLATFORM_UNIX +#define LLFORMAT "%I64u" +#else +#define LLFORMAT "%llu" +#endif + +ULONGLONG dwCreateThreadTestParameter = 0; + +DWORD PALAPI CreateThreadTestThread( LPVOID lpParameter) +{ + DWORD dwRet = 0; + + /* save parameter for test */ + dwCreateThreadTestParameter = (ULONGLONG)lpParameter; + + return dwRet; +} + +BOOL CreateThreadTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL; + DWORD dwStackSize = 0; + LPTHREAD_START_ROUTINE lpStartAddress = &CreateThreadTestThread; + LPVOID lpParameter = (LPVOID)lpStartAddress; + DWORD dwCreationFlags = 0; /* run immediately */ + DWORD dwThreadId = 0; + + HANDLE hThread = 0; + + dwCreateThreadTestParameter = 0; + + /* Create a thread, passing the appropriate paramaters as declared + above. + */ + + hThread = CreateThread( lpThreadAttributes, + dwStackSize, + lpStartAddress, + lpParameter, + dwCreationFlags, + &dwThreadId ); + + /* Ensure that the HANDLE is not invalid! */ + if (hThread != INVALID_HANDLE_VALUE) + { + dwRet = WaitForSingleObject(hThread,INFINITE); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("CreateThreadTest:WaitForSingleObject " + "failed (%x)\n",GetLastError()); + } + else + { + /* Check to ensure that the parameter passed to the thread + function is the same in the function as what we passed. + */ + + if (dwCreateThreadTestParameter != (ULONGLONG)lpParameter) + { + Trace("CreateThreadTest:parameter error. The " + "parameter passed should have been " LLFORMAT " but when " + "passed to the Thread function it was " LLFORMAT " . GetLastError[%x]\n", + dwCreateThreadTestParameter,lpParameter, GetLastError()); + } + else + { + bRet = TRUE; + } + + } + CloseHandle(hThread); + } + else + { + Trace("CreateThreadTest:CreateThread failed (%x)\n",GetLastError()); + } + + return bRet; +} + + +int __cdecl main(int argc, char **argv) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!CreateThreadTest()) + { + Fail ("Test failed\n"); + } + + Trace("Test Passed\n"); + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateThread/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateThread/test2/CMakeLists.txt index 350cf66e9b..47877607b9 100644 --- a/src/pal/tests/palsuite/threading/CreateThread/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateThread/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_createthread_test2 diff --git a/src/pal/tests/palsuite/threading/CreateThread/test2/test2.c b/src/pal/tests/palsuite/threading/CreateThread/test2/test2.c deleted file mode 100644 index f64c32ea87..0000000000 --- a/src/pal/tests/palsuite/threading/CreateThread/test2/test2.c +++ /dev/null @@ -1,184 +0,0 @@ -// 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: test2.c -** -** Purpose: Test that lpThreadId is assigned the correct -** threadId value and that lpThreadId can be NULL. -** -** -**=========================================================*/ - -#include - -#define NUM_TESTS 3 - -HANDLE hThread[NUM_TESTS]; -DWORD dwThreadId[NUM_TESTS]; -volatile BOOL bResult[NUM_TESTS]; -volatile DWORD dwThreadId1[NUM_TESTS]; - -DWORD PALAPI Thread( LPVOID lpParameter) -{ - dwThreadId1[(DWORD) lpParameter] = GetCurrentThreadId(); - bResult[(DWORD) lpParameter] = TRUE; - return (DWORD) lpParameter; -} - -struct testCase -{ - LPSECURITY_ATTRIBUTES lpThreadAttributes; - DWORD dwStackSize; - LPTHREAD_START_ROUTINE lpStartAddress; - DWORD dwCreationFlags; - LPVOID lpThreadId; -}; - -struct testCase testCases[]= -{ - {NULL, 0, &Thread, 0, NULL}, - {NULL, 0, &Thread, CREATE_SUSPENDED, NULL}, - {NULL, 0, &Thread, 0, (LPVOID) 1} -}; - -/* - * close handles - */ -BOOL cleanup(int index) -{ - int i; - BOOL bRet = TRUE; - - for (i = 0; i < index; i++) - { - if (!CloseHandle(hThread[i])) - { - bRet = FALSE; - Trace("PALSUITE ERROR: CloseHandle(%p) call failed for index %d\n", - hThread[i], i); - } - } - - return(bRet); -} - -int __cdecl main(int argc, char **argv) -{ - SIZE_T i; - DWORD dwRetWFSO; - DWORD dwRetRT; - BOOL bRet = TRUE; - - if(0 != (PAL_Initialize(argc, argv))) - { - return (FAIL); - } - - /* set results array to FALSE */ - for (i = 0; i < NUM_TESTS; i++) - { - bResult[i]=FALSE; - dwThreadId[i]=0; - } - - for (i = 0; i < NUM_TESTS; i++) - { - if (NULL != testCases[i].lpThreadId) - { - testCases[i].lpThreadId = &dwThreadId[i]; - } - /* pass the index as the thread argument */ - hThread[i] = CreateThread( testCases[i].lpThreadAttributes, - testCases[i].dwStackSize, - testCases[i].lpStartAddress, - (LPVOID) i, - testCases[i].dwCreationFlags, - testCases[i].lpThreadId); - if (hThread[i] == NULL) - { - Trace("PALSUITE ERROR: CreateThread('%p' '%d' '%p' '%p' '%d' " - "'%p') call failed.\nGetLastError returned '%u'.\n", - testCases[i].lpThreadAttributes, testCases[i].dwStackSize, - testCases[i].lpStartAddress, (LPVOID) i, - testCases[i].dwCreationFlags, - testCases[i].lpThreadId, GetLastError()); - cleanup(i - 1); - Fail(""); - } - - /* Resume suspended threads */ - if (testCases[i].dwCreationFlags == CREATE_SUSPENDED) - { - dwRetRT = ResumeThread (hThread[i]); - if (dwRetRT != 1) - { - Trace ("PALSUITE ERROR: ResumeThread(%p) " - "call returned %d it should have returned %d.\n" - "GetLastError returned %u.\n", hThread[i], dwRetRT, - 1, GetLastError()); - cleanup(i); - Fail(""); - } - } - } - - /* cleanup */ - for (i = 0; i < NUM_TESTS; i++) - { - dwRetWFSO = WaitForSingleObject(hThread[i], 10000); - if (dwRetWFSO != WAIT_OBJECT_0) - { - Trace ("PALSUITE ERROR: WaitForSingleObject('%p' '%d') " - "call returned %d instead of WAIT_OBJECT_0 ('%d').\n" - "GetLastError returned %u.\n", hThread[i], 10000, - dwRetWFSO, WAIT_OBJECT_0, GetLastError()); - cleanup(i); - Fail(""); - } - } - if(!cleanup(NUM_TESTS)) - { - Fail(""); - } - - for (i = 0; i < NUM_TESTS; i++) - { - /* - * check to see that all threads were created and were passed - * the array index as an argument. - */ - if (FALSE == bResult[i]) - { - bRet = FALSE; - Trace("PALSUITE ERROR: result[%d]=%d. It should be %d\n", i, - FALSE, TRUE); - } - /* - * check to see that lpThreadId received the correct value. - */ - if (0 != dwThreadId[i]) - { - if (dwThreadId[i] != dwThreadId1[i]) - { - bRet = FALSE; - Trace("PALSUITE ERROR: dwThreadId[%d]=%p and dwThreadId1[%d]" - "=%p\nThese values should be identical.\n", i, - dwThreadId[i], i, dwThreadId1[i]); - } - } - } - if (!bRet) - { - cleanup(NUM_TESTS); - Fail(""); - } - - PAL_Terminate(); - return (PASS); -} - - - diff --git a/src/pal/tests/palsuite/threading/CreateThread/test2/test2.cpp b/src/pal/tests/palsuite/threading/CreateThread/test2/test2.cpp new file mode 100644 index 0000000000..1ee410a6c5 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateThread/test2/test2.cpp @@ -0,0 +1,184 @@ +// 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: test2.c +** +** Purpose: Test that lpThreadId is assigned the correct +** threadId value and that lpThreadId can be NULL. +** +** +**=========================================================*/ + +#include + +#define NUM_TESTS 3 + +HANDLE hThread[NUM_TESTS]; +DWORD dwThreadId[NUM_TESTS]; +volatile BOOL bResult[NUM_TESTS]; +volatile DWORD dwThreadId1[NUM_TESTS]; + +DWORD PALAPI Thread( LPVOID lpParameter) +{ + dwThreadId1[(DWORD) lpParameter] = GetCurrentThreadId(); + bResult[(DWORD) lpParameter] = TRUE; + return (DWORD) lpParameter; +} + +struct testCase +{ + LPSECURITY_ATTRIBUTES lpThreadAttributes; + DWORD dwStackSize; + LPTHREAD_START_ROUTINE lpStartAddress; + DWORD dwCreationFlags; + LPDWORD lpThreadId; +}; + +struct testCase testCases[]= +{ + {NULL, 0, &Thread, 0, NULL}, + {NULL, 0, &Thread, CREATE_SUSPENDED, NULL}, + {NULL, 0, &Thread, 0, (LPDWORD) 1} +}; + +/* + * close handles + */ +BOOL cleanup(int index) +{ + int i; + BOOL bRet = TRUE; + + for (i = 0; i < index; i++) + { + if (!CloseHandle(hThread[i])) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CloseHandle(%p) call failed for index %d\n", + hThread[i], i); + } + } + + return(bRet); +} + +int __cdecl main(int argc, char **argv) +{ + SIZE_T i; + DWORD dwRetWFSO; + DWORD dwRetRT; + BOOL bRet = TRUE; + + if(0 != (PAL_Initialize(argc, argv))) + { + return (FAIL); + } + + /* set results array to FALSE */ + for (i = 0; i < NUM_TESTS; i++) + { + bResult[i]=FALSE; + dwThreadId[i]=0; + } + + for (i = 0; i < NUM_TESTS; i++) + { + if (NULL != testCases[i].lpThreadId) + { + testCases[i].lpThreadId = &dwThreadId[i]; + } + /* pass the index as the thread argument */ + hThread[i] = CreateThread( testCases[i].lpThreadAttributes, + testCases[i].dwStackSize, + testCases[i].lpStartAddress, + (LPVOID)i, + testCases[i].dwCreationFlags, + testCases[i].lpThreadId); + if (hThread[i] == NULL) + { + Trace("PALSUITE ERROR: CreateThread('%p' '%d' '%p' '%p' '%d' " + "'%p') call failed.\nGetLastError returned '%u'.\n", + testCases[i].lpThreadAttributes, testCases[i].dwStackSize, + testCases[i].lpStartAddress, (LPVOID)i, + testCases[i].dwCreationFlags, + testCases[i].lpThreadId, GetLastError()); + cleanup(i - 1); + Fail(""); + } + + /* Resume suspended threads */ + if (testCases[i].dwCreationFlags == CREATE_SUSPENDED) + { + dwRetRT = ResumeThread (hThread[i]); + if (dwRetRT != 1) + { + Trace ("PALSUITE ERROR: ResumeThread(%p) " + "call returned %d it should have returned %d.\n" + "GetLastError returned %u.\n", hThread[i], dwRetRT, + 1, GetLastError()); + cleanup(i); + Fail(""); + } + } + } + + /* cleanup */ + for (i = 0; i < NUM_TESTS; i++) + { + dwRetWFSO = WaitForSingleObject(hThread[i], 10000); + if (dwRetWFSO != WAIT_OBJECT_0) + { + Trace ("PALSUITE ERROR: WaitForSingleObject('%p' '%d') " + "call returned %d instead of WAIT_OBJECT_0 ('%d').\n" + "GetLastError returned %u.\n", hThread[i], 10000, + dwRetWFSO, WAIT_OBJECT_0, GetLastError()); + cleanup(i); + Fail(""); + } + } + if(!cleanup(NUM_TESTS)) + { + Fail(""); + } + + for (i = 0; i < NUM_TESTS; i++) + { + /* + * check to see that all threads were created and were passed + * the array index as an argument. + */ + if (FALSE == bResult[i]) + { + bRet = FALSE; + Trace("PALSUITE ERROR: result[%d]=%d. It should be %d\n", i, + FALSE, TRUE); + } + /* + * check to see that lpThreadId received the correct value. + */ + if (0 != dwThreadId[i]) + { + if (dwThreadId[i] != dwThreadId1[i]) + { + bRet = FALSE; + Trace("PALSUITE ERROR: dwThreadId[%d]=%p and dwThreadId1[%d]" + "=%p\nThese values should be identical.\n", i, + dwThreadId[i], i, dwThreadId1[i]); + } + } + } + if (!bRet) + { + cleanup(NUM_TESTS); + Fail(""); + } + + PAL_Terminate(); + return (PASS); +} + + + diff --git a/src/pal/tests/palsuite/threading/CreateThread/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateThread/test3/CMakeLists.txt index 923d7a72ab..d454992e59 100644 --- a/src/pal/tests/palsuite/threading/CreateThread/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CreateThread/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_createthread_test3 diff --git a/src/pal/tests/palsuite/threading/CreateThread/test3/test3.c b/src/pal/tests/palsuite/threading/CreateThread/test3/test3.c deleted file mode 100644 index 0c44d1fdd0..0000000000 --- a/src/pal/tests/palsuite/threading/CreateThread/test3/test3.c +++ /dev/null @@ -1,101 +0,0 @@ -// 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: test3.c -** -** Purpose: Check to see that the handle CreateThread returns -** can be closed while the thread is still running. -** -** -**=========================================================*/ - -#include - -HANDLE hThread; -HANDLE hEvent; - -DWORD PALAPI Thread( LPVOID lpParameter) -{ - DWORD dwRet; - dwRet = WaitForSingleObject(hEvent, INFINITE); - /* if this thread continues beyond here, fail */ - Fail(""); - - return 0; -} - -int __cdecl main(int argc, char **argv) -{ - DWORD dwThreadId; - DWORD dwRet; - - if(0 != (PAL_Initialize(argc, argv))) - { - return (FAIL); - } - - hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - - if (hEvent == NULL) - { - Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " - "returned %u.\n", GetLastError()); - } - - /* pass the index as the thread argument */ - hThread = CreateThread( NULL, - 0, - &Thread, - (LPVOID) 0, - 0, - &dwThreadId); - if (hThread == NULL) - { - Trace("PALSUITE ERROR: CreateThread('%p' '%d' '%p' '%p' '%d' '%p') " - "call failed.\nGetLastError returned '%u'.\n", NULL, - 0, &Thread, (LPVOID) 0, 0, &dwThreadId, GetLastError()); - if (0 == CloseHandle(hEvent)) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hEvent); - } - Fail(""); - } - - dwRet = WaitForSingleObject(hThread, 10000); - if (dwRet != WAIT_TIMEOUT) - { - Trace ("PALSUITE ERROR: WaitForSingleObject('%p' '%d') " - "call returned %d instead of WAIT_TIMEOUT ('%d').\n" - "GetLastError returned '%u'.\n", hThread, 10000, - dwRet, WAIT_TIMEOUT, GetLastError()); - Fail(""); - } - - if (0 == CloseHandle(hThread)) - { - Trace("PALSUITE ERROR: Unable to CloseHandle(%p) on a running thread." - "\nGetLastError returned '%u'.\n", hThread, GetLastError()); - if (0 == CloseHandle(hEvent)) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "cleanup.\nGetLastError returned '%u'.\n", hEvent, - GetLastError()); - } - Fail(""); - } - if (0 == CloseHandle(hEvent)) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "cleanup.\nGetLastError returned '%u'.\n", hEvent, - GetLastError()); - Fail(""); - } - - PAL_Terminate(); - return (PASS); -} - diff --git a/src/pal/tests/palsuite/threading/CreateThread/test3/test3.cpp b/src/pal/tests/palsuite/threading/CreateThread/test3/test3.cpp new file mode 100644 index 0000000000..0c44d1fdd0 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateThread/test3/test3.cpp @@ -0,0 +1,101 @@ +// 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: test3.c +** +** Purpose: Check to see that the handle CreateThread returns +** can be closed while the thread is still running. +** +** +**=========================================================*/ + +#include + +HANDLE hThread; +HANDLE hEvent; + +DWORD PALAPI Thread( LPVOID lpParameter) +{ + DWORD dwRet; + dwRet = WaitForSingleObject(hEvent, INFINITE); + /* if this thread continues beyond here, fail */ + Fail(""); + + return 0; +} + +int __cdecl main(int argc, char **argv) +{ + DWORD dwThreadId; + DWORD dwRet; + + if(0 != (PAL_Initialize(argc, argv))) + { + return (FAIL); + } + + hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (hEvent == NULL) + { + Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " + "returned %u.\n", GetLastError()); + } + + /* pass the index as the thread argument */ + hThread = CreateThread( NULL, + 0, + &Thread, + (LPVOID) 0, + 0, + &dwThreadId); + if (hThread == NULL) + { + Trace("PALSUITE ERROR: CreateThread('%p' '%d' '%p' '%p' '%d' '%p') " + "call failed.\nGetLastError returned '%u'.\n", NULL, + 0, &Thread, (LPVOID) 0, 0, &dwThreadId, GetLastError()); + if (0 == CloseHandle(hEvent)) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hEvent); + } + Fail(""); + } + + dwRet = WaitForSingleObject(hThread, 10000); + if (dwRet != WAIT_TIMEOUT) + { + Trace ("PALSUITE ERROR: WaitForSingleObject('%p' '%d') " + "call returned %d instead of WAIT_TIMEOUT ('%d').\n" + "GetLastError returned '%u'.\n", hThread, 10000, + dwRet, WAIT_TIMEOUT, GetLastError()); + Fail(""); + } + + if (0 == CloseHandle(hThread)) + { + Trace("PALSUITE ERROR: Unable to CloseHandle(%p) on a running thread." + "\nGetLastError returned '%u'.\n", hThread, GetLastError()); + if (0 == CloseHandle(hEvent)) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "cleanup.\nGetLastError returned '%u'.\n", hEvent, + GetLastError()); + } + Fail(""); + } + if (0 == CloseHandle(hEvent)) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "cleanup.\nGetLastError returned '%u'.\n", hEvent, + GetLastError()); + Fail(""); + } + + PAL_Terminate(); + return (PASS); +} + diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/CMakeLists.txt index 5ba04fd801..8d2c1441c4 100644 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - InitializeCriticalSection.c + InitializeCriticalSection.cpp ) add_executable(paltest_criticalsectionfunctions_test1 diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/InitializeCriticalSection.c b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/InitializeCriticalSection.c deleted file mode 100644 index f294cea472..0000000000 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/InitializeCriticalSection.c +++ /dev/null @@ -1,235 +0,0 @@ -// 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: criticalsectionfunctions/test1/initializecriticalsection.c -** -** Purpose: Test Semaphore operation using classic IPC problem: -** "Producer-Consumer Problem". -** -** Dependencies: CreateThread -** InitializeCriticalSection -** EnterCriticalSection -** LeaveCriticalSection -** DeleteCriticalSection -** WaitForSingleObject -** Sleep -** - -** -**=========================================================*/ - -#include - -#define PRODUCTION_TOTAL 26 - -#define _BUF_SIZE 10 - -DWORD dwThreadId; /* consumer thread identifier */ - -HANDLE hThread; /* handle to consumer thread */ - -CRITICAL_SECTION CriticalSectionM; /* Critical Section Object (used as mutex) */ - -typedef struct Buffer -{ - short readIndex; - short writeIndex; - CHAR message[_BUF_SIZE]; - -} BufferStructure; - -CHAR producerItems[PRODUCTION_TOTAL + 1]; - -CHAR consumerItems[PRODUCTION_TOTAL + 1]; - -/* - * Read next message from the Buffer into provided pointer. - * Returns: 0 on failure, 1 on success. - */ -int -readBuf(BufferStructure *Buffer, char *c) -{ - if( Buffer -> writeIndex == Buffer -> readIndex ) - { - return 0; - } - *c = Buffer -> message[Buffer -> readIndex++]; - Buffer -> readIndex %= _BUF_SIZE; - return 1; -} - -/* - * Write message generated by the producer to Buffer. - * Returns: 0 on failure, 1 on success. - */ -int -writeBuf(BufferStructure *Buffer, CHAR c) -{ - if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == - (Buffer -> readIndex) ) - { - return 0; - } - Buffer -> message[Buffer -> writeIndex++] = c; - Buffer -> writeIndex %= _BUF_SIZE; - return 1; -} - -/* - * Sleep 500 milleseconds. - */ -VOID -consumerSleep(VOID) -{ - Sleep(500); -} - -/* - * Sleep between 10 milleseconds. - */ -VOID -producerSleep(VOID) -{ - Sleep(10); -} - -/* - * Produce a message and write the message to Buffer. - */ -VOID -producer(BufferStructure *Buffer) -{ - - int n = 0; - char c; - - while (n < PRODUCTION_TOTAL) - { - c = 'A' + n ; /* Produce Item */ - - EnterCriticalSection(&CriticalSectionM); - - if (writeBuf(Buffer, c)) - { - printf("Producer produces %c.\n", c); - producerItems[n++] = c; - } - - LeaveCriticalSection(&CriticalSectionM); - - producerSleep(); - } - - return; -} - -/* - * Read and "Consume" the messages in Buffer. - */ -DWORD -PALAPI -consumer( LPVOID lpParam ) -{ - int n = 0; - char c; - - consumerSleep(); - - while (n < PRODUCTION_TOTAL) - { - - EnterCriticalSection(&CriticalSectionM); - - if (readBuf((BufferStructure*)lpParam, &c)) - { - printf("\tConsumer consumes %c.\n", c); - consumerItems[n++] = c; - } - - LeaveCriticalSection(&CriticalSectionM); - - consumerSleep(); - } - - return 0; -} - -int __cdecl main (int argc, char **argv) -{ - - BufferStructure Buffer, *pBuffer; - - pBuffer = &Buffer; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* - * Create mutual exclusion mechanisms - */ - - InitializeCriticalSection ( &CriticalSectionM ); - - /* - * Initialize Buffer - */ - pBuffer->writeIndex = pBuffer->readIndex = 0; - - - - /* - * Create Consumer - */ - hThread = CreateThread( - NULL, - 0, - consumer, - &Buffer, - 0, - &dwThreadId); - - if ( NULL == hThread ) - { - Fail ( "CreateThread() returned NULL. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - /* - * Start producing - */ - producer(pBuffer); - - /* - * Wait for consumer to complete - */ - WaitForSingleObject (hThread, INFINITE); - - /* - * Compare items produced vs. items consumed - */ - if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) - { - Fail("The producerItems string %s\n and the consumerItems string " - "%s\ndo not match. This could be a problem with the strncmp()" - " function\n FailingTest\nGetLastError() returned %d\n", - producerItems, consumerItems, GetLastError()); - } - - /* - * Clean up Critical Section object - */ - DeleteCriticalSection(&CriticalSectionM); - - Trace("producerItems and consumerItems arrays match. All %d\nitems " - "were produced and consumed in order.\nTest passed.\n", - PRODUCTION_TOTAL); - - PAL_Terminate(); - return (PASS); - -} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/InitializeCriticalSection.cpp b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/InitializeCriticalSection.cpp new file mode 100644 index 0000000000..f294cea472 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test1/InitializeCriticalSection.cpp @@ -0,0 +1,235 @@ +// 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: criticalsectionfunctions/test1/initializecriticalsection.c +** +** Purpose: Test Semaphore operation using classic IPC problem: +** "Producer-Consumer Problem". +** +** Dependencies: CreateThread +** InitializeCriticalSection +** EnterCriticalSection +** LeaveCriticalSection +** DeleteCriticalSection +** WaitForSingleObject +** Sleep +** + +** +**=========================================================*/ + +#include + +#define PRODUCTION_TOTAL 26 + +#define _BUF_SIZE 10 + +DWORD dwThreadId; /* consumer thread identifier */ + +HANDLE hThread; /* handle to consumer thread */ + +CRITICAL_SECTION CriticalSectionM; /* Critical Section Object (used as mutex) */ + +typedef struct Buffer +{ + short readIndex; + short writeIndex; + CHAR message[_BUF_SIZE]; + +} BufferStructure; + +CHAR producerItems[PRODUCTION_TOTAL + 1]; + +CHAR consumerItems[PRODUCTION_TOTAL + 1]; + +/* + * Read next message from the Buffer into provided pointer. + * Returns: 0 on failure, 1 on success. + */ +int +readBuf(BufferStructure *Buffer, char *c) +{ + if( Buffer -> writeIndex == Buffer -> readIndex ) + { + return 0; + } + *c = Buffer -> message[Buffer -> readIndex++]; + Buffer -> readIndex %= _BUF_SIZE; + return 1; +} + +/* + * Write message generated by the producer to Buffer. + * Returns: 0 on failure, 1 on success. + */ +int +writeBuf(BufferStructure *Buffer, CHAR c) +{ + if( ( ((Buffer -> writeIndex) + 1) % _BUF_SIZE) == + (Buffer -> readIndex) ) + { + return 0; + } + Buffer -> message[Buffer -> writeIndex++] = c; + Buffer -> writeIndex %= _BUF_SIZE; + return 1; +} + +/* + * Sleep 500 milleseconds. + */ +VOID +consumerSleep(VOID) +{ + Sleep(500); +} + +/* + * Sleep between 10 milleseconds. + */ +VOID +producerSleep(VOID) +{ + Sleep(10); +} + +/* + * Produce a message and write the message to Buffer. + */ +VOID +producer(BufferStructure *Buffer) +{ + + int n = 0; + char c; + + while (n < PRODUCTION_TOTAL) + { + c = 'A' + n ; /* Produce Item */ + + EnterCriticalSection(&CriticalSectionM); + + if (writeBuf(Buffer, c)) + { + printf("Producer produces %c.\n", c); + producerItems[n++] = c; + } + + LeaveCriticalSection(&CriticalSectionM); + + producerSleep(); + } + + return; +} + +/* + * Read and "Consume" the messages in Buffer. + */ +DWORD +PALAPI +consumer( LPVOID lpParam ) +{ + int n = 0; + char c; + + consumerSleep(); + + while (n < PRODUCTION_TOTAL) + { + + EnterCriticalSection(&CriticalSectionM); + + if (readBuf((BufferStructure*)lpParam, &c)) + { + printf("\tConsumer consumes %c.\n", c); + consumerItems[n++] = c; + } + + LeaveCriticalSection(&CriticalSectionM); + + consumerSleep(); + } + + return 0; +} + +int __cdecl main (int argc, char **argv) +{ + + BufferStructure Buffer, *pBuffer; + + pBuffer = &Buffer; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* + * Create mutual exclusion mechanisms + */ + + InitializeCriticalSection ( &CriticalSectionM ); + + /* + * Initialize Buffer + */ + pBuffer->writeIndex = pBuffer->readIndex = 0; + + + + /* + * Create Consumer + */ + hThread = CreateThread( + NULL, + 0, + consumer, + &Buffer, + 0, + &dwThreadId); + + if ( NULL == hThread ) + { + Fail ( "CreateThread() returned NULL. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + /* + * Start producing + */ + producer(pBuffer); + + /* + * Wait for consumer to complete + */ + WaitForSingleObject (hThread, INFINITE); + + /* + * Compare items produced vs. items consumed + */ + if ( 0 != strncmp (producerItems, consumerItems, PRODUCTION_TOTAL) ) + { + Fail("The producerItems string %s\n and the consumerItems string " + "%s\ndo not match. This could be a problem with the strncmp()" + " function\n FailingTest\nGetLastError() returned %d\n", + producerItems, consumerItems, GetLastError()); + } + + /* + * Clean up Critical Section object + */ + DeleteCriticalSection(&CriticalSectionM); + + Trace("producerItems and consumerItems arrays match. All %d\nitems " + "were produced and consumed in order.\nTest passed.\n", + PRODUCTION_TOTAL); + + PAL_Terminate(); + return (PASS); + +} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/CMakeLists.txt index d26658cf5d..e0f59f4207 100644 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_criticalsectionfunctions_test2 diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/test2.c b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/test2.c deleted file mode 100644 index 47659a1c18..0000000000 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/test2.c +++ /dev/null @@ -1,226 +0,0 @@ -// 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: CriticalSectionFunctions/test2/test2.c -** -** Purpose: Test that we are able to nest critical section calls. -** The initial thread makes a call to EnterCriticalSection once, -** blocking on a CRITICAL_SECTION object and creates a new thread. -** The newly created thread blocks on the same CRITICAL_SECTION object. -** The first thread now makes a call to LeaveCriticalSection. -** Test to see that the new thread doesn't get unblocked. -** -** Dependencies: CreateThread -** InitializeCriticalSection -** EnterCriticalSection -** LeaveCriticalSection -** DeleteCriticalSection -** WaitForSingleObject -** - -** -**=========================================================*/ - -#include - -CRITICAL_SECTION CriticalSection; - -volatile BOOL t0_tflag = FAIL; /* thread 0 timeout flag */ -volatile BOOL t1_aflag = FAIL; /* thread 1 access flag */ -volatile BOOL t1_cflag = FAIL; /* thread 1 critical section flag */ -volatile BOOL bTestResult = FAIL; - -DWORD PALAPI Thread(LPVOID lpParam) -{ - t1_aflag = PASS; - EnterCriticalSection(&CriticalSection); - t1_cflag = PASS; - LeaveCriticalSection(&CriticalSection); - return 0; -} - -int __cdecl main (int argc, char **argv) -{ - HANDLE hThread; - DWORD dwThreadId; - DWORD dwRet; - - if(0 != (PAL_Initialize(argc, argv))) - { - return (bTestResult); - } - - /* - * Create critical section object and enter it - */ - InitializeCriticalSection ( &CriticalSection ); - EnterCriticalSection(&CriticalSection); - - /* - * Create a suspended thread - */ - hThread = CreateThread(NULL, - 0, - &Thread, - (LPVOID) NULL, - CREATE_SUSPENDED, - &dwThreadId); - - if (hThread == NULL) - { - Trace("PALSUITE ERROR: CreateThread call failed. GetLastError " - "returned %d.\n", GetLastError()); - LeaveCriticalSection(&CriticalSection); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - EnterCriticalSection(&CriticalSection); - /* - * Set priority of the thread to greater than that of the currently - * running thread so it is guaranteed to run. - */ - dwRet = (DWORD) SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL); - - if (0 == dwRet) - { - Trace("PALSUITE ERROR: SetThreadPriority (%p, %d) call failed.\n" - "GetLastError returned %d.\n", hThread, - THREAD_PRIORITY_NORMAL, GetLastError()); - LeaveCriticalSection(&CriticalSection); - CloseHandle(hThread); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - dwRet = ResumeThread(hThread); - - if (-1 == dwRet) - { - Trace("PALSUITE ERROR: ResumeThread(%p) call failed.\nGetLastError " - "returned %d.\n", hThread, GetLastError()); - LeaveCriticalSection(&CriticalSection); - CloseHandle(hThread); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - /* - * Sleep until we know the thread has been invoked. This sleep in - * combination with the higher priority of the other thread should - * guarantee both threads block on the critical section. - */ - while (t1_aflag == FAIL) - { - Sleep(1); - } - - LeaveCriticalSection(&CriticalSection); - - switch ((WaitForSingleObject( - hThread, - 10000))) /* Wait 10 seconds */ - { - case WAIT_OBJECT_0: - /* Object (thread) is signaled */ - LeaveCriticalSection(&CriticalSection); - CloseHandle(hThread); - DeleteCriticalSection(&CriticalSection); - Fail("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_TIMEOUT ('%d'), instead it returned " - "WAIT_OBJECT_0 ('%d').\nA nested LeaveCriticalSection(%p) " - "call released both threads that were waiting on it!\n", - hThread, 10000, WAIT_TIMEOUT, WAIT_OBJECT_0, &CriticalSection); - break; - case WAIT_ABANDONED: - /* - * Object was mutex object whose owning - * thread has terminated. Shouldn't occur. - */ - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_TIMEOUT ('%d'), instead it returned " - "WAIT_ABANDONED ('%d').\nGetLastError returned '%d'\n", - hThread, 10000, WAIT_TIMEOUT, WAIT_ABANDONED, GetLastError()); - LeaveCriticalSection(&CriticalSection); - CloseHandle(hThread); - DeleteCriticalSection(&CriticalSection); - Fail(""); - break; - case WAIT_FAILED: /* WaitForSingleObject function failed */ - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_TIMEOUT ('%d'), instead it returned " - "WAIT_FAILED ('%d').\nGetLastError returned '%d'\n", - hThread, 10000, WAIT_TIMEOUT, WAIT_FAILED, GetLastError()); - LeaveCriticalSection(&CriticalSection); - CloseHandle(hThread); - DeleteCriticalSection(&CriticalSection); - Fail(""); - break; - case WAIT_TIMEOUT: - /* - * We expect this thread to timeout waiting for the - * critical section object to become available. - */ - t0_tflag = PASS; - break; - } - - LeaveCriticalSection(&CriticalSection); - - if (WAIT_OBJECT_0 != WaitForSingleObject (hThread, 10000)) - { - if (0 == CloseHandle(hThread)) - { - Trace("PALSUITE ERROR: CloseHandle(%p) call failed.\n" - "WaitForSingleObject(%p,%d) should have returned " - "WAIT_OBJECT_0 ('%d').\nBoth calls failed. " - "Deleted CRITICAL_SECTION object which likely means\n" - "thread %p is now in an undefined state. GetLastError " - "returned '%d'.\n", hThread, hThread, 10000, WAIT_OBJECT_0, - hThread, GetLastError()); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - else - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned WAIT_OBJECT_0 ('%d').\n GetLastError returned " - "'%d'.\n", hThread, hThread, 10000, WAIT_OBJECT_0, - hThread, GetLastError()); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - } - - if (0 == CloseHandle(hThread)) - { - Trace("PALSUITE ERROR: CloseHandle(%p) call failed.\n" - "Deleted CRITICAL_SECTION object which likely means\n" - "thread %p is now in an undefined state. GetLastError " - "returned '%d'.\n", hThread, hThread, GetLastError()); - DeleteCriticalSection(&CriticalSection); - Fail(""); - - } - DeleteCriticalSection(&CriticalSection); - /* - * Ensure both thread 0 experienced a wait timeout and thread 1 - * accessed the critical section or fail the test, otherwise pass it. - */ - if ((t0_tflag == FAIL) || (t1_cflag == FAIL)) - { - Trace("PALSUITE ERROR: Thread 0 returned %d when %d was expected.\n" - "Thread 1 returned %d when %d was expected.\n", t0_tflag, - PASS, t1_cflag, PASS); - bTestResult=FAIL; - } - else - { - bTestResult=PASS; - } - - PAL_TerminateEx(bTestResult); - return (bTestResult); -} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/test2.cpp b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/test2.cpp new file mode 100644 index 0000000000..47659a1c18 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test2/test2.cpp @@ -0,0 +1,226 @@ +// 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: CriticalSectionFunctions/test2/test2.c +** +** Purpose: Test that we are able to nest critical section calls. +** The initial thread makes a call to EnterCriticalSection once, +** blocking on a CRITICAL_SECTION object and creates a new thread. +** The newly created thread blocks on the same CRITICAL_SECTION object. +** The first thread now makes a call to LeaveCriticalSection. +** Test to see that the new thread doesn't get unblocked. +** +** Dependencies: CreateThread +** InitializeCriticalSection +** EnterCriticalSection +** LeaveCriticalSection +** DeleteCriticalSection +** WaitForSingleObject +** + +** +**=========================================================*/ + +#include + +CRITICAL_SECTION CriticalSection; + +volatile BOOL t0_tflag = FAIL; /* thread 0 timeout flag */ +volatile BOOL t1_aflag = FAIL; /* thread 1 access flag */ +volatile BOOL t1_cflag = FAIL; /* thread 1 critical section flag */ +volatile BOOL bTestResult = FAIL; + +DWORD PALAPI Thread(LPVOID lpParam) +{ + t1_aflag = PASS; + EnterCriticalSection(&CriticalSection); + t1_cflag = PASS; + LeaveCriticalSection(&CriticalSection); + return 0; +} + +int __cdecl main (int argc, char **argv) +{ + HANDLE hThread; + DWORD dwThreadId; + DWORD dwRet; + + if(0 != (PAL_Initialize(argc, argv))) + { + return (bTestResult); + } + + /* + * Create critical section object and enter it + */ + InitializeCriticalSection ( &CriticalSection ); + EnterCriticalSection(&CriticalSection); + + /* + * Create a suspended thread + */ + hThread = CreateThread(NULL, + 0, + &Thread, + (LPVOID) NULL, + CREATE_SUSPENDED, + &dwThreadId); + + if (hThread == NULL) + { + Trace("PALSUITE ERROR: CreateThread call failed. GetLastError " + "returned %d.\n", GetLastError()); + LeaveCriticalSection(&CriticalSection); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + EnterCriticalSection(&CriticalSection); + /* + * Set priority of the thread to greater than that of the currently + * running thread so it is guaranteed to run. + */ + dwRet = (DWORD) SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL); + + if (0 == dwRet) + { + Trace("PALSUITE ERROR: SetThreadPriority (%p, %d) call failed.\n" + "GetLastError returned %d.\n", hThread, + THREAD_PRIORITY_NORMAL, GetLastError()); + LeaveCriticalSection(&CriticalSection); + CloseHandle(hThread); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + dwRet = ResumeThread(hThread); + + if (-1 == dwRet) + { + Trace("PALSUITE ERROR: ResumeThread(%p) call failed.\nGetLastError " + "returned %d.\n", hThread, GetLastError()); + LeaveCriticalSection(&CriticalSection); + CloseHandle(hThread); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + /* + * Sleep until we know the thread has been invoked. This sleep in + * combination with the higher priority of the other thread should + * guarantee both threads block on the critical section. + */ + while (t1_aflag == FAIL) + { + Sleep(1); + } + + LeaveCriticalSection(&CriticalSection); + + switch ((WaitForSingleObject( + hThread, + 10000))) /* Wait 10 seconds */ + { + case WAIT_OBJECT_0: + /* Object (thread) is signaled */ + LeaveCriticalSection(&CriticalSection); + CloseHandle(hThread); + DeleteCriticalSection(&CriticalSection); + Fail("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_TIMEOUT ('%d'), instead it returned " + "WAIT_OBJECT_0 ('%d').\nA nested LeaveCriticalSection(%p) " + "call released both threads that were waiting on it!\n", + hThread, 10000, WAIT_TIMEOUT, WAIT_OBJECT_0, &CriticalSection); + break; + case WAIT_ABANDONED: + /* + * Object was mutex object whose owning + * thread has terminated. Shouldn't occur. + */ + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_TIMEOUT ('%d'), instead it returned " + "WAIT_ABANDONED ('%d').\nGetLastError returned '%d'\n", + hThread, 10000, WAIT_TIMEOUT, WAIT_ABANDONED, GetLastError()); + LeaveCriticalSection(&CriticalSection); + CloseHandle(hThread); + DeleteCriticalSection(&CriticalSection); + Fail(""); + break; + case WAIT_FAILED: /* WaitForSingleObject function failed */ + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_TIMEOUT ('%d'), instead it returned " + "WAIT_FAILED ('%d').\nGetLastError returned '%d'\n", + hThread, 10000, WAIT_TIMEOUT, WAIT_FAILED, GetLastError()); + LeaveCriticalSection(&CriticalSection); + CloseHandle(hThread); + DeleteCriticalSection(&CriticalSection); + Fail(""); + break; + case WAIT_TIMEOUT: + /* + * We expect this thread to timeout waiting for the + * critical section object to become available. + */ + t0_tflag = PASS; + break; + } + + LeaveCriticalSection(&CriticalSection); + + if (WAIT_OBJECT_0 != WaitForSingleObject (hThread, 10000)) + { + if (0 == CloseHandle(hThread)) + { + Trace("PALSUITE ERROR: CloseHandle(%p) call failed.\n" + "WaitForSingleObject(%p,%d) should have returned " + "WAIT_OBJECT_0 ('%d').\nBoth calls failed. " + "Deleted CRITICAL_SECTION object which likely means\n" + "thread %p is now in an undefined state. GetLastError " + "returned '%d'.\n", hThread, hThread, 10000, WAIT_OBJECT_0, + hThread, GetLastError()); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + else + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned WAIT_OBJECT_0 ('%d').\n GetLastError returned " + "'%d'.\n", hThread, hThread, 10000, WAIT_OBJECT_0, + hThread, GetLastError()); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + } + + if (0 == CloseHandle(hThread)) + { + Trace("PALSUITE ERROR: CloseHandle(%p) call failed.\n" + "Deleted CRITICAL_SECTION object which likely means\n" + "thread %p is now in an undefined state. GetLastError " + "returned '%d'.\n", hThread, hThread, GetLastError()); + DeleteCriticalSection(&CriticalSection); + Fail(""); + + } + DeleteCriticalSection(&CriticalSection); + /* + * Ensure both thread 0 experienced a wait timeout and thread 1 + * accessed the critical section or fail the test, otherwise pass it. + */ + if ((t0_tflag == FAIL) || (t1_cflag == FAIL)) + { + Trace("PALSUITE ERROR: Thread 0 returned %d when %d was expected.\n" + "Thread 1 returned %d when %d was expected.\n", t0_tflag, + PASS, t1_cflag, PASS); + bTestResult=FAIL; + } + else + { + bTestResult=PASS; + } + + PAL_TerminateEx(bTestResult); + return (bTestResult); +} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/CMakeLists.txt index 8bd2a72878..11555ec484 100644 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_criticalsectionfunctions_test3 diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/test3.c b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/test3.c deleted file mode 100644 index d5911267b2..0000000000 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/test3.c +++ /dev/null @@ -1,376 +0,0 @@ -// 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: CriticalSectionFunctions/test3/test3.c -** -** Purpose: Create two threads to exercise TryEnterCriticalSection -** and EnterCriticalSection. TryEnterCriticalSection acquires -** and holds a CRITICAL_SECTION object. Another call to -** TryEnterCriticalSection is made from a different thread, at -** this time, to establish a call to TryEnterCriticalSection -** will return immediatly and to establish -** TryEnterCriticalSection returns the proper value when it -** attempts to lock a CRITICAL_SECTION that is already owned -** by another thread. The CRITICAL_SECTION object is then -** released and held by a call to EnterCriticalSection. A new -** thread is invoked and attempts to acquire the held -** CRITICAL_SECTION with a call to TryEnterCriticalSection. -** TryEnterCriticalSection returns immediatly and returns -** with the value that states the CRITICAL_SECTION object is -** held by another thread. This establishes -** TryEnterCriticalSection behaves the same way with -** CriticalSections locked by TryEnterCriticalSection and -** EnterCriticalSection. -** -** -**===================================================================*/ -#include - -#define NUM_THREADS 2 - -HANDLE hThread[NUM_THREADS]; -HANDLE hEvent[NUM_THREADS]; -CRITICAL_SECTION CriticalSection; -BOOL bRet = FAIL; - -DWORD PALAPI Thread(LPVOID lpParam) -{ - DWORD dwRet; - - if (0 == TryEnterCriticalSection(&CriticalSection)) - { - dwRet = WaitForMultipleObjects(NUM_THREADS, hEvent, TRUE, 10000); - if ((WAIT_OBJECT_0 > dwRet) || - ((WAIT_OBJECT_0 + NUM_THREADS - 1) < dwRet)) - { -#if 0 - if (0 == CloseHandle(hThread[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " - "during clean up.\nGetLastError returned '%d'.\n", - hThread[1], GetLastError()); - } -#endif - Trace("PALSUITE ERROR: WaitForMultipleObjects(%d, %p, %d, %d) call" - "returned an unexpected value, '%d'.\nGetLastError returned " - "%d.\n", NUM_THREADS, hEvent, TRUE, 10000, dwRet, - GetLastError()); - } - else - { - bRet = PASS; - } - } - else - { - /* signal thread 0 */ - if (0 == SetEvent(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[0], - GetLastError()); - LeaveCriticalSection(&CriticalSection); - if (0 == CloseHandle(hThread[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " - "during clean up\nGetLastError returned '%d'.\n", - hThread[0], GetLastError()); - } - if (0 == CloseHandle(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " - "during clean up\nGetLastError returned '%d'.\n", - hEvent[0], GetLastError()); - } - if (0 == CloseHandle(hEvent[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " - "during clean up\nGetLastError returned '%d'.\n", - hEvent[1], GetLastError()); - } - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - /* wait to be signaled */ - dwRet = WaitForSingleObject(hEvent[1], 10000); - if (WAIT_OBJECT_0 != dwRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " - "('%d').\nGetLastError returned '%d'.\n", - hEvent[0], 10000, WAIT_OBJECT_0, dwRet, GetLastError()); - if (0 == CloseHandle(hThread[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " - "during clean up.\nGetLastError returned '%d'.\n", - hThread[0], GetLastError()); - } - if (0 == CloseHandle(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " - "during clean up.\nGetLastError returned '%d'.\n", - hEvent[0], GetLastError()); - } - if (0 == CloseHandle(hEvent[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " - "during clean up.\nGetLastError returned '%d.'\n", - hEvent[1], GetLastError()); - } - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - LeaveCriticalSection(&CriticalSection); - } - return FAIL; -} - -int __cdecl main(int argc, char **argv) -{ - HANDLE hThread[NUM_THREADS]; - DWORD dwThreadId[NUM_THREADS]; - DWORD dwRet; - - if ((PAL_Initialize(argc,argv)) != 0) - { - return(bRet); - } - - /* thread 0 event */ - hEvent[0] = CreateEvent(NULL, TRUE, FALSE, NULL); - - if (hEvent[0] == NULL) - { - Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " - "returned %d.\n", GetLastError()); - } - - /* thread 1 event */ - hEvent[1] = CreateEvent(NULL, TRUE, FALSE, NULL); - - if (hEvent[1] == NULL) - { - Trace("PALSUITE ERROR: CreateEvent call #1 failed. GetLastError " - "returned %d.\n", GetLastError()); - if (0 == CloseHandle(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[0]); - } - Fail(""); - } - - InitializeCriticalSection ( &CriticalSection ); - - hThread[0] = CreateThread(NULL, - 0, - &Thread, - (LPVOID) NULL, - 0, - &dwThreadId[0]); - - if (hThread[0] == NULL) - { - Trace("PALSUITE ERROR: CreateThread call #0 failed. GetLastError " - "returned %d.\n", GetLastError()); - if (0 == CloseHandle(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[1], - GetLastError()); - } - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - - /* wait for thread 0 to be signaled */ - dwRet = WaitForSingleObject(hEvent[0], 10000); - if (WAIT_OBJECT_0 != dwRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " - "('%d').\nGetLastError returned '%d'.\n", hEvent[0], 10000, - WAIT_OBJECT_0, dwRet, GetLastError()); - if (0 == CloseHandle(hThread[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hThread[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[1], - GetLastError()); - } - Fail(""); - } - - /* - * Attempting to enter CRITICAL_SECTION object owned by the - * created thread and locked with TryEnterCriticalSection - */ - if (0 == TryEnterCriticalSection(&CriticalSection)) - { - /* signal thread 1 */ - if (0 == SetEvent(hEvent[1])) - { - Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) call.\n" - "GetLastError returned '%d'.\n", hEvent[1], - GetLastError()); - goto done; - } - } - else - { - Trace("PALSUITE_ERROR: TryEnterCriticalSection was able to grab a" - " CRITICAL_SECTION object\nwhich was already owned.\n"); - LeaveCriticalSection(&CriticalSection); - if (0 == CloseHandle(hThread[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hThread[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[1], - GetLastError()); - } - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - /* - * Enter the CRITICAL_SECTION and launch another thread to attempt - * to access the CRITICAL_SECTION with a call to TryEnterCriticalSection. - */ - EnterCriticalSection(&CriticalSection); - - hThread[1] = CreateThread(NULL, - 0, - &Thread, - (LPVOID) NULL, - 0, - &dwThreadId[1]); - - if (hThread[1] == NULL) - { - Trace("PALSUITE ERROR: CreateThread call #1 failed. GetLastError " - "returned %d.\n", GetLastError()); - LeaveCriticalSection(&CriticalSection); - if (0 == CloseHandle(hThread[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hThread[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[1], - GetLastError()); - } - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - dwRet = WaitForMultipleObjects(NUM_THREADS, hThread, TRUE, 10000); - if ((WAIT_OBJECT_0 > dwRet) || - ((WAIT_OBJECT_0 + NUM_THREADS - 1) < dwRet)) - { - Trace("PALSUITE ERROR: WaitForMultipleObjects(%d, %p, %d, %d) call " - "returned an unexpected value, '%d'.\nGetLastError returned " - "%d.\n", NUM_THREADS, hThread, TRUE, 10000, dwRet, - GetLastError()); - LeaveCriticalSection(&CriticalSection); - if (0 == CloseHandle(hThread[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hThread[0], - GetLastError()); - } - if (0 == CloseHandle(hThread[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hThread[1], - GetLastError()); - } - if (0 == CloseHandle(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[1], - GetLastError()); - } - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - LeaveCriticalSection(&CriticalSection); - if (0 == CloseHandle(hThread[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hThread[1], - GetLastError()); - } -done: - if (0 == CloseHandle(hThread[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hThread[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[0])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[0], - GetLastError()); - } - if (0 == CloseHandle(hEvent[1])) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%d'.\n", hEvent[1], - GetLastError()); - } - DeleteCriticalSection(&CriticalSection); - - PAL_TerminateEx(bRet); - - return (bRet); -} - diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/test3.cpp b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/test3.cpp new file mode 100644 index 0000000000..d5911267b2 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test3/test3.cpp @@ -0,0 +1,376 @@ +// 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: CriticalSectionFunctions/test3/test3.c +** +** Purpose: Create two threads to exercise TryEnterCriticalSection +** and EnterCriticalSection. TryEnterCriticalSection acquires +** and holds a CRITICAL_SECTION object. Another call to +** TryEnterCriticalSection is made from a different thread, at +** this time, to establish a call to TryEnterCriticalSection +** will return immediatly and to establish +** TryEnterCriticalSection returns the proper value when it +** attempts to lock a CRITICAL_SECTION that is already owned +** by another thread. The CRITICAL_SECTION object is then +** released and held by a call to EnterCriticalSection. A new +** thread is invoked and attempts to acquire the held +** CRITICAL_SECTION with a call to TryEnterCriticalSection. +** TryEnterCriticalSection returns immediatly and returns +** with the value that states the CRITICAL_SECTION object is +** held by another thread. This establishes +** TryEnterCriticalSection behaves the same way with +** CriticalSections locked by TryEnterCriticalSection and +** EnterCriticalSection. +** +** +**===================================================================*/ +#include + +#define NUM_THREADS 2 + +HANDLE hThread[NUM_THREADS]; +HANDLE hEvent[NUM_THREADS]; +CRITICAL_SECTION CriticalSection; +BOOL bRet = FAIL; + +DWORD PALAPI Thread(LPVOID lpParam) +{ + DWORD dwRet; + + if (0 == TryEnterCriticalSection(&CriticalSection)) + { + dwRet = WaitForMultipleObjects(NUM_THREADS, hEvent, TRUE, 10000); + if ((WAIT_OBJECT_0 > dwRet) || + ((WAIT_OBJECT_0 + NUM_THREADS - 1) < dwRet)) + { +#if 0 + if (0 == CloseHandle(hThread[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " + "during clean up.\nGetLastError returned '%d'.\n", + hThread[1], GetLastError()); + } +#endif + Trace("PALSUITE ERROR: WaitForMultipleObjects(%d, %p, %d, %d) call" + "returned an unexpected value, '%d'.\nGetLastError returned " + "%d.\n", NUM_THREADS, hEvent, TRUE, 10000, dwRet, + GetLastError()); + } + else + { + bRet = PASS; + } + } + else + { + /* signal thread 0 */ + if (0 == SetEvent(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[0], + GetLastError()); + LeaveCriticalSection(&CriticalSection); + if (0 == CloseHandle(hThread[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " + "during clean up\nGetLastError returned '%d'.\n", + hThread[0], GetLastError()); + } + if (0 == CloseHandle(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " + "during clean up\nGetLastError returned '%d'.\n", + hEvent[0], GetLastError()); + } + if (0 == CloseHandle(hEvent[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " + "during clean up\nGetLastError returned '%d'.\n", + hEvent[1], GetLastError()); + } + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + /* wait to be signaled */ + dwRet = WaitForSingleObject(hEvent[1], 10000); + if (WAIT_OBJECT_0 != dwRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " + "('%d').\nGetLastError returned '%d'.\n", + hEvent[0], 10000, WAIT_OBJECT_0, dwRet, GetLastError()); + if (0 == CloseHandle(hThread[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " + "during clean up.\nGetLastError returned '%d'.\n", + hThread[0], GetLastError()); + } + if (0 == CloseHandle(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " + "during clean up.\nGetLastError returned '%d'.\n", + hEvent[0], GetLastError()); + } + if (0 == CloseHandle(hEvent[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) " + "during clean up.\nGetLastError returned '%d.'\n", + hEvent[1], GetLastError()); + } + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + LeaveCriticalSection(&CriticalSection); + } + return FAIL; +} + +int __cdecl main(int argc, char **argv) +{ + HANDLE hThread[NUM_THREADS]; + DWORD dwThreadId[NUM_THREADS]; + DWORD dwRet; + + if ((PAL_Initialize(argc,argv)) != 0) + { + return(bRet); + } + + /* thread 0 event */ + hEvent[0] = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (hEvent[0] == NULL) + { + Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " + "returned %d.\n", GetLastError()); + } + + /* thread 1 event */ + hEvent[1] = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (hEvent[1] == NULL) + { + Trace("PALSUITE ERROR: CreateEvent call #1 failed. GetLastError " + "returned %d.\n", GetLastError()); + if (0 == CloseHandle(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[0]); + } + Fail(""); + } + + InitializeCriticalSection ( &CriticalSection ); + + hThread[0] = CreateThread(NULL, + 0, + &Thread, + (LPVOID) NULL, + 0, + &dwThreadId[0]); + + if (hThread[0] == NULL) + { + Trace("PALSUITE ERROR: CreateThread call #0 failed. GetLastError " + "returned %d.\n", GetLastError()); + if (0 == CloseHandle(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[1], + GetLastError()); + } + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + + /* wait for thread 0 to be signaled */ + dwRet = WaitForSingleObject(hEvent[0], 10000); + if (WAIT_OBJECT_0 != dwRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " + "('%d').\nGetLastError returned '%d'.\n", hEvent[0], 10000, + WAIT_OBJECT_0, dwRet, GetLastError()); + if (0 == CloseHandle(hThread[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hThread[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[1], + GetLastError()); + } + Fail(""); + } + + /* + * Attempting to enter CRITICAL_SECTION object owned by the + * created thread and locked with TryEnterCriticalSection + */ + if (0 == TryEnterCriticalSection(&CriticalSection)) + { + /* signal thread 1 */ + if (0 == SetEvent(hEvent[1])) + { + Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) call.\n" + "GetLastError returned '%d'.\n", hEvent[1], + GetLastError()); + goto done; + } + } + else + { + Trace("PALSUITE_ERROR: TryEnterCriticalSection was able to grab a" + " CRITICAL_SECTION object\nwhich was already owned.\n"); + LeaveCriticalSection(&CriticalSection); + if (0 == CloseHandle(hThread[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hThread[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[1], + GetLastError()); + } + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + /* + * Enter the CRITICAL_SECTION and launch another thread to attempt + * to access the CRITICAL_SECTION with a call to TryEnterCriticalSection. + */ + EnterCriticalSection(&CriticalSection); + + hThread[1] = CreateThread(NULL, + 0, + &Thread, + (LPVOID) NULL, + 0, + &dwThreadId[1]); + + if (hThread[1] == NULL) + { + Trace("PALSUITE ERROR: CreateThread call #1 failed. GetLastError " + "returned %d.\n", GetLastError()); + LeaveCriticalSection(&CriticalSection); + if (0 == CloseHandle(hThread[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hThread[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[1], + GetLastError()); + } + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + dwRet = WaitForMultipleObjects(NUM_THREADS, hThread, TRUE, 10000); + if ((WAIT_OBJECT_0 > dwRet) || + ((WAIT_OBJECT_0 + NUM_THREADS - 1) < dwRet)) + { + Trace("PALSUITE ERROR: WaitForMultipleObjects(%d, %p, %d, %d) call " + "returned an unexpected value, '%d'.\nGetLastError returned " + "%d.\n", NUM_THREADS, hThread, TRUE, 10000, dwRet, + GetLastError()); + LeaveCriticalSection(&CriticalSection); + if (0 == CloseHandle(hThread[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hThread[0], + GetLastError()); + } + if (0 == CloseHandle(hThread[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hThread[1], + GetLastError()); + } + if (0 == CloseHandle(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[1], + GetLastError()); + } + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + LeaveCriticalSection(&CriticalSection); + if (0 == CloseHandle(hThread[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hThread[1], + GetLastError()); + } +done: + if (0 == CloseHandle(hThread[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hThread[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[0])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[0], + GetLastError()); + } + if (0 == CloseHandle(hEvent[1])) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%d'.\n", hEvent[1], + GetLastError()); + } + DeleteCriticalSection(&CriticalSection); + + PAL_TerminateEx(bRet); + + return (bRet); +} + diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/CMakeLists.txt index 0626631640..8aa18854b3 100644 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_criticalsectionfunctions_test4 diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/test4.c b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/test4.c deleted file mode 100644 index 8a245a4776..0000000000 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/test4.c +++ /dev/null @@ -1,241 +0,0 @@ -// 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: criticalsectionfunctions/test4/test4.c -** -** Purpose: Test to see if threads blocked on a CRITICAL_SECTION object will -** be released in an orderly manner. This case looks at the following -** scenario. If one thread owns a CRITICAL_SECTION object and two threads -** block in EnterCriticalSection, trying to hold the already owned -** CRITICAL_SECTION object, when the first thread releases the CRITICAL_SECTION -** object, will one and only one of the waiters get unblocked? -** -** Dependencies: CreateThread -** InitializeCriticalSection -** EnterCriticalSection -** LeaveCriticalSection -** DeleteCriticalSection -** Sleep -** WaitForSingleObject -** - -** -**=========================================================*/ - -#include - -#define NUM_BLOCKING_THREADS 2 - -BOOL bTestResult; -CRITICAL_SECTION CriticalSection; -HANDLE hThread[NUM_BLOCKING_THREADS]; -HANDLE hEvent; -DWORD dwThreadId[NUM_BLOCKING_THREADS]; -volatile int flags[NUM_BLOCKING_THREADS] = {0,0}; - -DWORD PALAPI ThreadTest1(LPVOID lpParam) -{ - - EnterCriticalSection ( &CriticalSection ); - - flags[0] = 1; - - return 0; - -} - -DWORD PALAPI ThreadTest2(LPVOID lpParam) -{ - - EnterCriticalSection ( &CriticalSection ); - - flags[1] = 1; - - return 0; - -} - -int __cdecl main(int argc, char **argv) -{ - - DWORD dwRet; - DWORD dwRet1; - bTestResult = FAIL; - - if ((PAL_Initialize(argc,argv)) != 0) - { - return(bTestResult); - } - - /* - * Create Critical Section Object - */ - InitializeCriticalSection ( &CriticalSection ); - - EnterCriticalSection ( &CriticalSection ); - - hThread[0] = CreateThread(NULL, - 0, - &ThreadTest1, - (LPVOID) 0, - CREATE_SUSPENDED, - &dwThreadId[0]); - if (hThread[0] == NULL) - { - Trace("PALSUITE ERROR: CreateThread(%p, %d, %p, %p, %d, %p) call " - "failed.\nGetLastError returned %d.\n", NULL, 0, &ThreadTest1, - (LPVOID) 0, CREATE_SUSPENDED, &dwThreadId[0], GetLastError()); - LeaveCriticalSection(&CriticalSection); - DeleteCriticalSection ( &CriticalSection ); - Fail(""); - } - - hThread[1] = CreateThread(NULL, - 0, - &ThreadTest2, - (LPVOID) 0, - CREATE_SUSPENDED, - &dwThreadId[1]); - if (hThread[1] == NULL) - { - Trace("PALSUITE ERROR: CreateThread(%p, %d, %p, %p, %d, %p) call " - "failed.\nGetLastError returned %d.\n", NULL, 0, &ThreadTest2, - (LPVOID) 0, CREATE_SUSPENDED, &dwThreadId[1], GetLastError()); - LeaveCriticalSection(&CriticalSection); - - dwRet = ResumeThread(hThread[0]); - if (-1 == dwRet) - { - Trace("PALSUITE ERROR: ResumeThread(%p) call failed.\n" - "GetLastError returned '%d'.\n", hThread[0], - GetLastError()); - } - - dwRet = WaitForSingleObject(hThread[0], 10000); - if (WAIT_OBJECT_0 == dwRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call " - "failed. '%d' was returned instead of the expected '%d'.\n" - "GetLastError returned '%d'.\n", hThread[0], 10000, dwRet, - WAIT_OBJECT_0, GetLastError()); - } - - if (0 == CloseHandle(hThread[0])) - { - Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n" - "GetLastError returned %d. Not failing tests.\n", - hThread[0], GetLastError()); - } - - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - /* - * Set other thread priorities to be higher than ours & Sleep to ensure - * we give up the processor. - */ - dwRet = (DWORD) SetThreadPriority(hThread[0], - THREAD_PRIORITY_ABOVE_NORMAL); - if (0 == dwRet) - { - Trace("PALSUITE ERROR: SetThreadPriority(%p, %d) call failed.\n" - "GetLastError returned %d", hThread[0], - THREAD_PRIORITY_ABOVE_NORMAL, GetLastError()); - } - - dwRet = (DWORD) SetThreadPriority(hThread[1], - THREAD_PRIORITY_ABOVE_NORMAL); - if (0 == dwRet) - { - Trace("PALSUITE ERROR: SetThreadPriority(%p, %d) call failed.\n" - "GetLastError returned %d", hThread[1], - THREAD_PRIORITY_ABOVE_NORMAL, GetLastError()); - } - - dwRet = ResumeThread(hThread[0]); - if (-1 == dwRet) - { - Trace("PALSUITE ERROR: ResumeThread(%p, %d) call failed.\n" - "GetLastError returned %d", hThread[0], - GetLastError() ); - } - - dwRet = ResumeThread(hThread[1]); - if (-1 == dwRet) - { - Trace("PALSUITE ERROR: ResumeThread(%p, %d) call failed.\n" - "GetLastError returned %d", hThread[0], - GetLastError()); - } - - Sleep (0); - - LeaveCriticalSection (&CriticalSection); - - dwRet = WaitForSingleObject(hThread[0], 10000); - dwRet1 = WaitForSingleObject(hThread[1], 10000); - - if ((WAIT_OBJECT_0 == dwRet) || - (WAIT_OBJECT_0 == dwRet1)) - { - if ((1 == flags[0] && 0 == flags[1]) || - (0 == flags[0] && 1 == flags[1])) - { - bTestResult = PASS; - } - else - { - bTestResult = FAIL; - Trace ("PALSUITE ERROR: flags[%d] = {%d,%d}. These values are" - "inconsistent.\nCriticalSection test failed.\n", - NUM_BLOCKING_THREADS, flags[0], flags[1]); - } - - /* Fail the test if both threads returned WAIT_OBJECT_0 */ - if ((WAIT_OBJECT_0 == dwRet) && (WAIT_OBJECT_0 == dwRet1)) - { - bTestResult = FAIL; - Trace ("PALSUITE ERROR: WaitForSingleObject(%p, %d) and " - "WaitForSingleObject(%p, %d)\nboth returned dwRet = '%d'\n" - "One should have returned WAIT_TIMEOUT ('%d').\n", - hThread[0], 10000, hThread[1], 10000, dwRet, WAIT_TIMEOUT); - } - } - else - { - bTestResult = FAIL; - Trace ("PALSUITE ERROR: WaitForSingleObject(%p, %d) and " - "WaitForSingleObject(%p, %d)\nReturned dwRet = '%d' and\n" - "dwRet1 = '%d' respectively.\n", hThread[0], 10000, hThread[1], - 10000, dwRet, dwRet1); - } - - if (WAIT_OBJECT_0 == dwRet) - { - if (0 == CloseHandle(hThread[0])) - { - Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n" - "GetLastError returned %d. Not failing tests.\n", - hThread[0], GetLastError()); - } - } - if (WAIT_OBJECT_0 == dwRet1) - { - if (0 == CloseHandle(hThread[1])) - { - Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n" - "GetLastError returned %d. Not failing tests.\n", - hThread[1], GetLastError()); - } - } - - /* Leaking the CS on purpose, since there is still a thread - waiting on it */ - - PAL_TerminateEx(bTestResult); - return (bTestResult); -} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/test4.cpp b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/test4.cpp new file mode 100644 index 0000000000..8a245a4776 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test4/test4.cpp @@ -0,0 +1,241 @@ +// 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: criticalsectionfunctions/test4/test4.c +** +** Purpose: Test to see if threads blocked on a CRITICAL_SECTION object will +** be released in an orderly manner. This case looks at the following +** scenario. If one thread owns a CRITICAL_SECTION object and two threads +** block in EnterCriticalSection, trying to hold the already owned +** CRITICAL_SECTION object, when the first thread releases the CRITICAL_SECTION +** object, will one and only one of the waiters get unblocked? +** +** Dependencies: CreateThread +** InitializeCriticalSection +** EnterCriticalSection +** LeaveCriticalSection +** DeleteCriticalSection +** Sleep +** WaitForSingleObject +** + +** +**=========================================================*/ + +#include + +#define NUM_BLOCKING_THREADS 2 + +BOOL bTestResult; +CRITICAL_SECTION CriticalSection; +HANDLE hThread[NUM_BLOCKING_THREADS]; +HANDLE hEvent; +DWORD dwThreadId[NUM_BLOCKING_THREADS]; +volatile int flags[NUM_BLOCKING_THREADS] = {0,0}; + +DWORD PALAPI ThreadTest1(LPVOID lpParam) +{ + + EnterCriticalSection ( &CriticalSection ); + + flags[0] = 1; + + return 0; + +} + +DWORD PALAPI ThreadTest2(LPVOID lpParam) +{ + + EnterCriticalSection ( &CriticalSection ); + + flags[1] = 1; + + return 0; + +} + +int __cdecl main(int argc, char **argv) +{ + + DWORD dwRet; + DWORD dwRet1; + bTestResult = FAIL; + + if ((PAL_Initialize(argc,argv)) != 0) + { + return(bTestResult); + } + + /* + * Create Critical Section Object + */ + InitializeCriticalSection ( &CriticalSection ); + + EnterCriticalSection ( &CriticalSection ); + + hThread[0] = CreateThread(NULL, + 0, + &ThreadTest1, + (LPVOID) 0, + CREATE_SUSPENDED, + &dwThreadId[0]); + if (hThread[0] == NULL) + { + Trace("PALSUITE ERROR: CreateThread(%p, %d, %p, %p, %d, %p) call " + "failed.\nGetLastError returned %d.\n", NULL, 0, &ThreadTest1, + (LPVOID) 0, CREATE_SUSPENDED, &dwThreadId[0], GetLastError()); + LeaveCriticalSection(&CriticalSection); + DeleteCriticalSection ( &CriticalSection ); + Fail(""); + } + + hThread[1] = CreateThread(NULL, + 0, + &ThreadTest2, + (LPVOID) 0, + CREATE_SUSPENDED, + &dwThreadId[1]); + if (hThread[1] == NULL) + { + Trace("PALSUITE ERROR: CreateThread(%p, %d, %p, %p, %d, %p) call " + "failed.\nGetLastError returned %d.\n", NULL, 0, &ThreadTest2, + (LPVOID) 0, CREATE_SUSPENDED, &dwThreadId[1], GetLastError()); + LeaveCriticalSection(&CriticalSection); + + dwRet = ResumeThread(hThread[0]); + if (-1 == dwRet) + { + Trace("PALSUITE ERROR: ResumeThread(%p) call failed.\n" + "GetLastError returned '%d'.\n", hThread[0], + GetLastError()); + } + + dwRet = WaitForSingleObject(hThread[0], 10000); + if (WAIT_OBJECT_0 == dwRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call " + "failed. '%d' was returned instead of the expected '%d'.\n" + "GetLastError returned '%d'.\n", hThread[0], 10000, dwRet, + WAIT_OBJECT_0, GetLastError()); + } + + if (0 == CloseHandle(hThread[0])) + { + Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n" + "GetLastError returned %d. Not failing tests.\n", + hThread[0], GetLastError()); + } + + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + /* + * Set other thread priorities to be higher than ours & Sleep to ensure + * we give up the processor. + */ + dwRet = (DWORD) SetThreadPriority(hThread[0], + THREAD_PRIORITY_ABOVE_NORMAL); + if (0 == dwRet) + { + Trace("PALSUITE ERROR: SetThreadPriority(%p, %d) call failed.\n" + "GetLastError returned %d", hThread[0], + THREAD_PRIORITY_ABOVE_NORMAL, GetLastError()); + } + + dwRet = (DWORD) SetThreadPriority(hThread[1], + THREAD_PRIORITY_ABOVE_NORMAL); + if (0 == dwRet) + { + Trace("PALSUITE ERROR: SetThreadPriority(%p, %d) call failed.\n" + "GetLastError returned %d", hThread[1], + THREAD_PRIORITY_ABOVE_NORMAL, GetLastError()); + } + + dwRet = ResumeThread(hThread[0]); + if (-1 == dwRet) + { + Trace("PALSUITE ERROR: ResumeThread(%p, %d) call failed.\n" + "GetLastError returned %d", hThread[0], + GetLastError() ); + } + + dwRet = ResumeThread(hThread[1]); + if (-1 == dwRet) + { + Trace("PALSUITE ERROR: ResumeThread(%p, %d) call failed.\n" + "GetLastError returned %d", hThread[0], + GetLastError()); + } + + Sleep (0); + + LeaveCriticalSection (&CriticalSection); + + dwRet = WaitForSingleObject(hThread[0], 10000); + dwRet1 = WaitForSingleObject(hThread[1], 10000); + + if ((WAIT_OBJECT_0 == dwRet) || + (WAIT_OBJECT_0 == dwRet1)) + { + if ((1 == flags[0] && 0 == flags[1]) || + (0 == flags[0] && 1 == flags[1])) + { + bTestResult = PASS; + } + else + { + bTestResult = FAIL; + Trace ("PALSUITE ERROR: flags[%d] = {%d,%d}. These values are" + "inconsistent.\nCriticalSection test failed.\n", + NUM_BLOCKING_THREADS, flags[0], flags[1]); + } + + /* Fail the test if both threads returned WAIT_OBJECT_0 */ + if ((WAIT_OBJECT_0 == dwRet) && (WAIT_OBJECT_0 == dwRet1)) + { + bTestResult = FAIL; + Trace ("PALSUITE ERROR: WaitForSingleObject(%p, %d) and " + "WaitForSingleObject(%p, %d)\nboth returned dwRet = '%d'\n" + "One should have returned WAIT_TIMEOUT ('%d').\n", + hThread[0], 10000, hThread[1], 10000, dwRet, WAIT_TIMEOUT); + } + } + else + { + bTestResult = FAIL; + Trace ("PALSUITE ERROR: WaitForSingleObject(%p, %d) and " + "WaitForSingleObject(%p, %d)\nReturned dwRet = '%d' and\n" + "dwRet1 = '%d' respectively.\n", hThread[0], 10000, hThread[1], + 10000, dwRet, dwRet1); + } + + if (WAIT_OBJECT_0 == dwRet) + { + if (0 == CloseHandle(hThread[0])) + { + Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n" + "GetLastError returned %d. Not failing tests.\n", + hThread[0], GetLastError()); + } + } + if (WAIT_OBJECT_0 == dwRet1) + { + if (0 == CloseHandle(hThread[1])) + { + Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n" + "GetLastError returned %d. Not failing tests.\n", + hThread[1], GetLastError()); + } + } + + /* Leaking the CS on purpose, since there is still a thread + waiting on it */ + + PAL_TerminateEx(bTestResult); + return (bTestResult); +} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/CMakeLists.txt b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/CMakeLists.txt index 37d709f121..9474bcc6c9 100644 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_criticalsectionfunctions_test5 diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/test5.c b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/test5.c deleted file mode 100644 index 8dfa4f5f3d..0000000000 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/test5.c +++ /dev/null @@ -1,187 +0,0 @@ -// 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: CriticalSectionFunctions/test5/test5.c -** -** Purpose: Attempt to delete a critical section owned by another -** thread. -** -** -**===================================================================*/ -#include - -/* - * Tokens 0 and 1 are events. Token 2 is the thread. - */ -#define NUM_TOKENS 3 - -HANDLE hToken[NUM_TOKENS]; -CRITICAL_SECTION CriticalSection; - -BOOL CleanupHelper (HANDLE *hArray, DWORD dwIndex) -{ - BOOL bCHRet; - - bCHRet = CloseHandle(hArray[dwIndex]); - if (!bCHRet) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], - GetLastError()); - } - - return (bCHRet); -} - -BOOL Cleanup(HANDLE *hArray, DWORD dwIndex) -{ - BOOL bCRet; - BOOL bCHRet = FALSE; - - while (--dwIndex > 0) - { - bCHRet = CleanupHelper(&hArray[0], dwIndex); - } - - bCRet = CloseHandle(hArray[0]); - if (!bCRet) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], - GetLastError()); - } - - return (bCRet&&bCHRet); -} - -DWORD PALAPI Thread(LPVOID lpParam) -{ - DWORD dwTRet; - - EnterCriticalSection(&CriticalSection); - - /* signal thread 0 */ - if (0 == SetEvent(hToken[0])) - { - Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hToken[0], - GetLastError()); - LeaveCriticalSection(&CriticalSection); - Cleanup (&hToken[0], NUM_TOKENS); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - /* wait to be signaled */ - dwTRet = WaitForSingleObject(hToken[1], 10000); - if (WAIT_OBJECT_0 != dwTRet) - - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " - "('%d').\nGetLastError returned '%u'.\n", - hToken[1], 10000, WAIT_OBJECT_0, dwTRet, GetLastError()); - LeaveCriticalSection(&CriticalSection); - Cleanup (&hToken[0], NUM_TOKENS); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - LeaveCriticalSection(&CriticalSection); - return 0; -} - -int __cdecl main(int argc, char **argv) -{ - DWORD dwThreadId; - DWORD dwMRet; - - if ((PAL_Initialize(argc,argv)) != 0) - { - return(FAIL); - } - - /* thread 0 event */ - hToken[0] = CreateEvent(NULL, TRUE, FALSE, NULL); - if (NULL == hToken[0]) - { - Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " - "returned %u.\n", GetLastError()); - } - - /* thread 1 event */ - hToken[1] = CreateEvent(NULL, TRUE, FALSE, NULL); - if (NULL == hToken[1]) - { - Trace("PALSUITE ERROR: CreateEvent call #1 failed. GetLastError " - "returned %u.\n", GetLastError()); - Cleanup(&hToken[0], (NUM_TOKENS - 2)); - Fail(""); - } - - InitializeCriticalSection(&CriticalSection); - - hToken[2] = CreateThread(NULL, - 0, - &Thread, - (LPVOID) NULL, - 0, - &dwThreadId); - if (hToken[2] == NULL) - { - Trace("PALSUITE ERROR: CreateThread call #0 failed. GetLastError " - "returned %u.\n", GetLastError()); - Cleanup(&hToken[0], (NUM_TOKENS - 1)); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - /* wait for thread 0 to be signaled */ - dwMRet = WaitForSingleObject(hToken[0], 10000); - if (WAIT_OBJECT_0 != dwMRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " - "('%d').\nGetLastError returned '%u'.\n", hToken[0], 10000, - WAIT_OBJECT_0, dwMRet, GetLastError()); - Cleanup(&hToken[0], NUM_TOKENS); - Fail(""); - } - - /* - * Attempt to do delete CriticalSection object owned by other thread - */ - DeleteCriticalSection(&CriticalSection); - - /* signal thread 1 */ - if (0 == SetEvent(hToken[1])) - { - Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) call.\n" - "GetLastError returned '%u'.\n", hToken[1], - GetLastError()); - Cleanup(&hToken[0], NUM_TOKENS); - Fail(""); - } - - dwMRet = WaitForSingleObject(hToken[2], 10000); - if (WAIT_OBJECT_0 != dwMRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call " - "returned an unexpected value '%d'.\nGetLastError returned " - "%u.\n", hToken[2], 10000, dwMRet, GetLastError()); - Cleanup(&hToken[0], NUM_TOKENS); - Fail(""); - } - - if (!Cleanup(&hToken[0], NUM_TOKENS)) - { - Fail(""); - } - - PAL_Terminate(); - - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/test5.cpp b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/test5.cpp new file mode 100644 index 0000000000..8dfa4f5f3d --- /dev/null +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test5/test5.cpp @@ -0,0 +1,187 @@ +// 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: CriticalSectionFunctions/test5/test5.c +** +** Purpose: Attempt to delete a critical section owned by another +** thread. +** +** +**===================================================================*/ +#include + +/* + * Tokens 0 and 1 are events. Token 2 is the thread. + */ +#define NUM_TOKENS 3 + +HANDLE hToken[NUM_TOKENS]; +CRITICAL_SECTION CriticalSection; + +BOOL CleanupHelper (HANDLE *hArray, DWORD dwIndex) +{ + BOOL bCHRet; + + bCHRet = CloseHandle(hArray[dwIndex]); + if (!bCHRet) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], + GetLastError()); + } + + return (bCHRet); +} + +BOOL Cleanup(HANDLE *hArray, DWORD dwIndex) +{ + BOOL bCRet; + BOOL bCHRet = FALSE; + + while (--dwIndex > 0) + { + bCHRet = CleanupHelper(&hArray[0], dwIndex); + } + + bCRet = CloseHandle(hArray[0]); + if (!bCRet) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], + GetLastError()); + } + + return (bCRet&&bCHRet); +} + +DWORD PALAPI Thread(LPVOID lpParam) +{ + DWORD dwTRet; + + EnterCriticalSection(&CriticalSection); + + /* signal thread 0 */ + if (0 == SetEvent(hToken[0])) + { + Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hToken[0], + GetLastError()); + LeaveCriticalSection(&CriticalSection); + Cleanup (&hToken[0], NUM_TOKENS); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + /* wait to be signaled */ + dwTRet = WaitForSingleObject(hToken[1], 10000); + if (WAIT_OBJECT_0 != dwTRet) + + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " + "('%d').\nGetLastError returned '%u'.\n", + hToken[1], 10000, WAIT_OBJECT_0, dwTRet, GetLastError()); + LeaveCriticalSection(&CriticalSection); + Cleanup (&hToken[0], NUM_TOKENS); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + LeaveCriticalSection(&CriticalSection); + return 0; +} + +int __cdecl main(int argc, char **argv) +{ + DWORD dwThreadId; + DWORD dwMRet; + + if ((PAL_Initialize(argc,argv)) != 0) + { + return(FAIL); + } + + /* thread 0 event */ + hToken[0] = CreateEvent(NULL, TRUE, FALSE, NULL); + if (NULL == hToken[0]) + { + Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " + "returned %u.\n", GetLastError()); + } + + /* thread 1 event */ + hToken[1] = CreateEvent(NULL, TRUE, FALSE, NULL); + if (NULL == hToken[1]) + { + Trace("PALSUITE ERROR: CreateEvent call #1 failed. GetLastError " + "returned %u.\n", GetLastError()); + Cleanup(&hToken[0], (NUM_TOKENS - 2)); + Fail(""); + } + + InitializeCriticalSection(&CriticalSection); + + hToken[2] = CreateThread(NULL, + 0, + &Thread, + (LPVOID) NULL, + 0, + &dwThreadId); + if (hToken[2] == NULL) + { + Trace("PALSUITE ERROR: CreateThread call #0 failed. GetLastError " + "returned %u.\n", GetLastError()); + Cleanup(&hToken[0], (NUM_TOKENS - 1)); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + /* wait for thread 0 to be signaled */ + dwMRet = WaitForSingleObject(hToken[0], 10000); + if (WAIT_OBJECT_0 != dwMRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " + "('%d').\nGetLastError returned '%u'.\n", hToken[0], 10000, + WAIT_OBJECT_0, dwMRet, GetLastError()); + Cleanup(&hToken[0], NUM_TOKENS); + Fail(""); + } + + /* + * Attempt to do delete CriticalSection object owned by other thread + */ + DeleteCriticalSection(&CriticalSection); + + /* signal thread 1 */ + if (0 == SetEvent(hToken[1])) + { + Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) call.\n" + "GetLastError returned '%u'.\n", hToken[1], + GetLastError()); + Cleanup(&hToken[0], NUM_TOKENS); + Fail(""); + } + + dwMRet = WaitForSingleObject(hToken[2], 10000); + if (WAIT_OBJECT_0 != dwMRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call " + "returned an unexpected value '%d'.\nGetLastError returned " + "%u.\n", hToken[2], 10000, dwMRet, GetLastError()); + Cleanup(&hToken[0], NUM_TOKENS); + Fail(""); + } + + if (!Cleanup(&hToken[0], NUM_TOKENS)) + { + Fail(""); + } + + PAL_Terminate(); + + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/CMakeLists.txt b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/CMakeLists.txt index c580fdbd6b..f4887ad67d 100644 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_criticalsectionfunctions_test6 diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/test6.c b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/test6.c deleted file mode 100644 index c27db86e5b..0000000000 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/test6.c +++ /dev/null @@ -1,190 +0,0 @@ -// 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: CriticalSectionFunctions/test6/test6.c -** -** Purpose: Attempt to leave a critical section which is owned by -** another thread. -** -** -**===================================================================*/ -#include - -/* - * Tokens 0 and 1 are events. Token 2 is the thread. - */ -#define NUM_TOKENS 3 - -HANDLE hToken[NUM_TOKENS]; -CRITICAL_SECTION CriticalSection; - -BOOL CleanupHelper (HANDLE *hArray, DWORD dwIndex) -{ - BOOL bCHRet; - - bCHRet = CloseHandle(hArray[dwIndex]); - if (!bCHRet) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], - GetLastError()); - } - - return (bCHRet); -} - -BOOL Cleanup(HANDLE *hArray, DWORD dwIndex) -{ - BOOL bCRet; - BOOL bCHRet; - - while (--dwIndex > 0) - { - bCHRet = CleanupHelper(&hArray[0], dwIndex); - } - - bCRet = CloseHandle(hArray[0]); - if (!bCRet) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], - GetLastError()); - } - - return (bCRet&&bCHRet); -} - -DWORD PALAPI Thread(LPVOID lpParam) -{ - DWORD dwTRet; - - EnterCriticalSection(&CriticalSection); - - /* signal thread 0 */ - if (0 == SetEvent(hToken[0])) - { - Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hToken[0], - GetLastError()); - LeaveCriticalSection(&CriticalSection); - Cleanup (&hToken[0], NUM_TOKENS); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - /* wait to be signaled */ - dwTRet = WaitForSingleObject(hToken[1], 10000); - if (WAIT_OBJECT_0 != dwTRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " - "('%d').\nGetLastError returned '%u'.\n", - hToken[1], 10000, WAIT_OBJECT_0, dwTRet, GetLastError()); - LeaveCriticalSection(&CriticalSection); - Cleanup (&hToken[0], NUM_TOKENS); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - LeaveCriticalSection(&CriticalSection); - - return 0; -} - -int __cdecl main(int argc, char **argv) -{ - DWORD dwThreadId; - DWORD dwMRet; - - if ((PAL_Initialize(argc,argv)) != 0) - { - return(FAIL); - } - - /* thread 0 event */ - hToken[0] = CreateEvent(NULL, TRUE, FALSE, NULL); - - if (hToken[0] == NULL) - { - Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " - "returned %u.\n", GetLastError()); - } - - /* thread 1 event */ - hToken[1] = CreateEvent(NULL, TRUE, FALSE, NULL); - - if (hToken[1] == NULL) - { - Trace("PALSUITE ERROR: CreateEvent call #1 failed. GetLastError " - "returned %u.\n", GetLastError()); - Cleanup(&hToken[0], (NUM_TOKENS - 2)); - Fail(""); - } - - InitializeCriticalSection(&CriticalSection); - - hToken[2] = CreateThread(NULL, - 0, - &Thread, - (LPVOID) NULL, - 0, - &dwThreadId); - - if (hToken[2] == NULL) - { - Trace("PALSUITE ERROR: CreateThread call #0 failed. GetLastError " - "returned %u.\n", GetLastError()); - Cleanup(&hToken[0], (NUM_TOKENS - 1)); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - /* wait for thread 0 to be signaled */ - dwMRet = WaitForSingleObject(hToken[0], 10000); - if (WAIT_OBJECT_0 != dwMRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " - "('%d').\nGetLastError returned '%u'.\n", hToken[0], 10000, - WAIT_OBJECT_0, dwMRet, GetLastError()); - Cleanup(&hToken[0], NUM_TOKENS); - Fail(""); - } - - /* - * Attempt to leave critical section which is owned by the other thread. - */ - LeaveCriticalSection(&CriticalSection); - - /* signal thread 1 */ - if (0 == SetEvent(hToken[1])) - { - Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) call.\n" - "GetLastError returned '%u'.\n", hToken[1], - GetLastError()); - Cleanup(&hToken[0], NUM_TOKENS); - Fail(""); - } - - dwMRet = WaitForSingleObject(hToken[2], 10000); - if (WAIT_OBJECT_0 != dwMRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call " - "returned an unexpected value '%d'.\nGetLastError returned " - "%u.\n", hToken[2], 10000, dwMRet, GetLastError()); - Cleanup(&hToken[0], NUM_TOKENS); - Fail(""); - } - - if (!Cleanup(&hToken[0], NUM_TOKENS)) - { - Fail(""); - } - - PAL_Terminate(); - - return(PASS); -} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/test6.cpp b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/test6.cpp new file mode 100644 index 0000000000..c27db86e5b --- /dev/null +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test6/test6.cpp @@ -0,0 +1,190 @@ +// 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: CriticalSectionFunctions/test6/test6.c +** +** Purpose: Attempt to leave a critical section which is owned by +** another thread. +** +** +**===================================================================*/ +#include + +/* + * Tokens 0 and 1 are events. Token 2 is the thread. + */ +#define NUM_TOKENS 3 + +HANDLE hToken[NUM_TOKENS]; +CRITICAL_SECTION CriticalSection; + +BOOL CleanupHelper (HANDLE *hArray, DWORD dwIndex) +{ + BOOL bCHRet; + + bCHRet = CloseHandle(hArray[dwIndex]); + if (!bCHRet) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], + GetLastError()); + } + + return (bCHRet); +} + +BOOL Cleanup(HANDLE *hArray, DWORD dwIndex) +{ + BOOL bCRet; + BOOL bCHRet; + + while (--dwIndex > 0) + { + bCHRet = CleanupHelper(&hArray[0], dwIndex); + } + + bCRet = CloseHandle(hArray[0]); + if (!bCRet) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], + GetLastError()); + } + + return (bCRet&&bCHRet); +} + +DWORD PALAPI Thread(LPVOID lpParam) +{ + DWORD dwTRet; + + EnterCriticalSection(&CriticalSection); + + /* signal thread 0 */ + if (0 == SetEvent(hToken[0])) + { + Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hToken[0], + GetLastError()); + LeaveCriticalSection(&CriticalSection); + Cleanup (&hToken[0], NUM_TOKENS); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + /* wait to be signaled */ + dwTRet = WaitForSingleObject(hToken[1], 10000); + if (WAIT_OBJECT_0 != dwTRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " + "('%d').\nGetLastError returned '%u'.\n", + hToken[1], 10000, WAIT_OBJECT_0, dwTRet, GetLastError()); + LeaveCriticalSection(&CriticalSection); + Cleanup (&hToken[0], NUM_TOKENS); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + LeaveCriticalSection(&CriticalSection); + + return 0; +} + +int __cdecl main(int argc, char **argv) +{ + DWORD dwThreadId; + DWORD dwMRet; + + if ((PAL_Initialize(argc,argv)) != 0) + { + return(FAIL); + } + + /* thread 0 event */ + hToken[0] = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (hToken[0] == NULL) + { + Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " + "returned %u.\n", GetLastError()); + } + + /* thread 1 event */ + hToken[1] = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (hToken[1] == NULL) + { + Trace("PALSUITE ERROR: CreateEvent call #1 failed. GetLastError " + "returned %u.\n", GetLastError()); + Cleanup(&hToken[0], (NUM_TOKENS - 2)); + Fail(""); + } + + InitializeCriticalSection(&CriticalSection); + + hToken[2] = CreateThread(NULL, + 0, + &Thread, + (LPVOID) NULL, + 0, + &dwThreadId); + + if (hToken[2] == NULL) + { + Trace("PALSUITE ERROR: CreateThread call #0 failed. GetLastError " + "returned %u.\n", GetLastError()); + Cleanup(&hToken[0], (NUM_TOKENS - 1)); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + /* wait for thread 0 to be signaled */ + dwMRet = WaitForSingleObject(hToken[0], 10000); + if (WAIT_OBJECT_0 != dwMRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " + "('%d').\nGetLastError returned '%u'.\n", hToken[0], 10000, + WAIT_OBJECT_0, dwMRet, GetLastError()); + Cleanup(&hToken[0], NUM_TOKENS); + Fail(""); + } + + /* + * Attempt to leave critical section which is owned by the other thread. + */ + LeaveCriticalSection(&CriticalSection); + + /* signal thread 1 */ + if (0 == SetEvent(hToken[1])) + { + Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) call.\n" + "GetLastError returned '%u'.\n", hToken[1], + GetLastError()); + Cleanup(&hToken[0], NUM_TOKENS); + Fail(""); + } + + dwMRet = WaitForSingleObject(hToken[2], 10000); + if (WAIT_OBJECT_0 != dwMRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call " + "returned an unexpected value '%d'.\nGetLastError returned " + "%u.\n", hToken[2], 10000, dwMRet, GetLastError()); + Cleanup(&hToken[0], NUM_TOKENS); + Fail(""); + } + + if (!Cleanup(&hToken[0], NUM_TOKENS)) + { + Fail(""); + } + + PAL_Terminate(); + + return(PASS); +} diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/CMakeLists.txt b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/CMakeLists.txt index 0a12bfe3ef..ceb78a0512 100644 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_criticalsectionfunctions_test7 diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/test7.c b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/test7.c deleted file mode 100644 index 1c030d3c03..0000000000 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/test7.c +++ /dev/null @@ -1,188 +0,0 @@ -// 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: CriticalSectionFunctions/test7/test7.c -** -** Purpose: Attempt to delete a critical section owned by the current -** thread. -** -** -**===================================================================*/ -#include - -/* - * Tokens 0 and 1 are events. Token 2 is the thread. - */ -#define NUM_TOKENS 3 - -HANDLE hToken[NUM_TOKENS]; -CRITICAL_SECTION CriticalSection; - -BOOL CleanupHelper (HANDLE *hArray, DWORD dwIndex) -{ - BOOL bCHRet; - - bCHRet = CloseHandle(hArray[dwIndex]); - if (!bCHRet) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], - GetLastError()); - } - - return (bCHRet); -} - -BOOL Cleanup(HANDLE *hArray, DWORD dwIndex) -{ - BOOL bCRet; - BOOL bCHRet = 0; - - while (--dwIndex > 0) - { - bCHRet = CleanupHelper(&hArray[0], dwIndex); - } - - bCRet = CloseHandle(hArray[0]); - if (!bCRet) - { - Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], - GetLastError()); - } - - return (bCRet&&bCHRet); -} - -DWORD PALAPI Thread(LPVOID lpParam) -{ - DWORD dwTRet; - - EnterCriticalSection(&CriticalSection); - - /* signal thread 0 */ - if (0 == SetEvent(hToken[0])) - { - Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) during " - "clean up.\nGetLastError returned '%u'.\n", hToken[0], - GetLastError()); - LeaveCriticalSection(&CriticalSection); - Cleanup (&hToken[0], NUM_TOKENS); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - /* wait to be signaled */ - dwTRet = WaitForSingleObject(hToken[1], 10000); - if (WAIT_OBJECT_0 != dwTRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " - "('%d').\nGetLastError returned '%u'.\n", - hToken[0], 10000, WAIT_OBJECT_0, dwTRet, GetLastError()); - LeaveCriticalSection(&CriticalSection); - Cleanup (&hToken[0], NUM_TOKENS); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - DeleteCriticalSection(&CriticalSection); - - return 0; -} - -int __cdecl main(int argc, char **argv) -{ - DWORD dwThreadId; - DWORD dwMRet; - - if ((PAL_Initialize(argc,argv)) != 0) - { - return(FAIL); - } - - /* thread 0 event */ - hToken[0] = CreateEvent(NULL, TRUE, FALSE, NULL); - - if (hToken[0] == NULL) - { - Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " - "returned %u.\n", GetLastError()); - } - - /* thread 1 event */ - hToken[1] = CreateEvent(NULL, TRUE, FALSE, NULL); - - if (hToken[1] == NULL) - { - Trace("PALSUITE ERROR: CreateEvent call #1 failed. GetLastError " - "returned %u.\n", GetLastError()); - Cleanup (&hToken[0], (NUM_TOKENS - 2)); - Fail(""); - } - - InitializeCriticalSection(&CriticalSection); - - hToken[2] = CreateThread(NULL, - 0, - &Thread, - (LPVOID) NULL, - 0, - &dwThreadId); - - if (hToken[2] == NULL) - { - Trace("PALSUITE ERROR: CreateThread call #0 failed. GetLastError " - "returned %u.\n", GetLastError()); - Cleanup (&hToken[0], (NUM_TOKENS - 1)); - DeleteCriticalSection(&CriticalSection); - Fail(""); - } - - /* wait for thread 0 to be signaled */ - dwMRet = WaitForSingleObject(hToken[0], 10000); - if (WAIT_OBJECT_0 != dwMRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " - "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " - "('%d').\nGetLastError returned '%u'.\n", hToken[0], 10000, - WAIT_OBJECT_0, dwMRet, GetLastError()); - Cleanup (&hToken[0], NUM_TOKENS); - Fail(""); - } - - /* signal thread 1 */ - if (0 == SetEvent(hToken[1])) - { - Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) call.\n" - "GetLastError returned '%u'.\n", hToken[1], - GetLastError()); - Cleanup (&hToken[0], NUM_TOKENS); - Fail(""); - } - - dwMRet = WaitForSingleObject(hToken[2], 10000); - if (WAIT_OBJECT_0 != dwMRet) - { - Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call " - "returned an unexpected value '%d'.\nGetLastError returned " - "%u.\n", hToken[2], 10000, dwMRet, GetLastError()); - Cleanup (&hToken[0], NUM_TOKENS); - Fail(""); - } - - if (!Cleanup(&hToken[0], NUM_TOKENS)) - { - Fail(""); - } - - PAL_Terminate(); - - return (PASS); -} - - - diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/test7.cpp b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/test7.cpp new file mode 100644 index 0000000000..1c030d3c03 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test7/test7.cpp @@ -0,0 +1,188 @@ +// 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: CriticalSectionFunctions/test7/test7.c +** +** Purpose: Attempt to delete a critical section owned by the current +** thread. +** +** +**===================================================================*/ +#include + +/* + * Tokens 0 and 1 are events. Token 2 is the thread. + */ +#define NUM_TOKENS 3 + +HANDLE hToken[NUM_TOKENS]; +CRITICAL_SECTION CriticalSection; + +BOOL CleanupHelper (HANDLE *hArray, DWORD dwIndex) +{ + BOOL bCHRet; + + bCHRet = CloseHandle(hArray[dwIndex]); + if (!bCHRet) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], + GetLastError()); + } + + return (bCHRet); +} + +BOOL Cleanup(HANDLE *hArray, DWORD dwIndex) +{ + BOOL bCRet; + BOOL bCHRet = 0; + + while (--dwIndex > 0) + { + bCHRet = CleanupHelper(&hArray[0], dwIndex); + } + + bCRet = CloseHandle(hArray[0]); + if (!bCRet) + { + Trace("PALSUITE ERROR: Unable to execute CloseHandle(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hArray[dwIndex], + GetLastError()); + } + + return (bCRet&&bCHRet); +} + +DWORD PALAPI Thread(LPVOID lpParam) +{ + DWORD dwTRet; + + EnterCriticalSection(&CriticalSection); + + /* signal thread 0 */ + if (0 == SetEvent(hToken[0])) + { + Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) during " + "clean up.\nGetLastError returned '%u'.\n", hToken[0], + GetLastError()); + LeaveCriticalSection(&CriticalSection); + Cleanup (&hToken[0], NUM_TOKENS); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + /* wait to be signaled */ + dwTRet = WaitForSingleObject(hToken[1], 10000); + if (WAIT_OBJECT_0 != dwTRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " + "('%d').\nGetLastError returned '%u'.\n", + hToken[0], 10000, WAIT_OBJECT_0, dwTRet, GetLastError()); + LeaveCriticalSection(&CriticalSection); + Cleanup (&hToken[0], NUM_TOKENS); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + DeleteCriticalSection(&CriticalSection); + + return 0; +} + +int __cdecl main(int argc, char **argv) +{ + DWORD dwThreadId; + DWORD dwMRet; + + if ((PAL_Initialize(argc,argv)) != 0) + { + return(FAIL); + } + + /* thread 0 event */ + hToken[0] = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (hToken[0] == NULL) + { + Fail("PALSUITE ERROR: CreateEvent call #0 failed. GetLastError " + "returned %u.\n", GetLastError()); + } + + /* thread 1 event */ + hToken[1] = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (hToken[1] == NULL) + { + Trace("PALSUITE ERROR: CreateEvent call #1 failed. GetLastError " + "returned %u.\n", GetLastError()); + Cleanup (&hToken[0], (NUM_TOKENS - 2)); + Fail(""); + } + + InitializeCriticalSection(&CriticalSection); + + hToken[2] = CreateThread(NULL, + 0, + &Thread, + (LPVOID) NULL, + 0, + &dwThreadId); + + if (hToken[2] == NULL) + { + Trace("PALSUITE ERROR: CreateThread call #0 failed. GetLastError " + "returned %u.\n", GetLastError()); + Cleanup (&hToken[0], (NUM_TOKENS - 1)); + DeleteCriticalSection(&CriticalSection); + Fail(""); + } + + /* wait for thread 0 to be signaled */ + dwMRet = WaitForSingleObject(hToken[0], 10000); + if (WAIT_OBJECT_0 != dwMRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have " + "returned\nWAIT_OBJECT_0 ('%d'), instead it returned " + "('%d').\nGetLastError returned '%u'.\n", hToken[0], 10000, + WAIT_OBJECT_0, dwMRet, GetLastError()); + Cleanup (&hToken[0], NUM_TOKENS); + Fail(""); + } + + /* signal thread 1 */ + if (0 == SetEvent(hToken[1])) + { + Trace("PALSUITE ERROR: Unable to execute SetEvent(%p) call.\n" + "GetLastError returned '%u'.\n", hToken[1], + GetLastError()); + Cleanup (&hToken[0], NUM_TOKENS); + Fail(""); + } + + dwMRet = WaitForSingleObject(hToken[2], 10000); + if (WAIT_OBJECT_0 != dwMRet) + { + Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call " + "returned an unexpected value '%d'.\nGetLastError returned " + "%u.\n", hToken[2], 10000, dwMRet, GetLastError()); + Cleanup (&hToken[0], NUM_TOKENS); + Fail(""); + } + + if (!Cleanup(&hToken[0], NUM_TOKENS)) + { + Fail(""); + } + + PAL_Terminate(); + + return (PASS); +} + + + diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test8/CMakeLists.txt b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test8/CMakeLists.txt index 0d95a95410..d3f271d677 100644 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_criticalsectionfunctions_test8 diff --git a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test8/test8.c b/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test8/test8.c deleted file mode 100644 index 7f0c58cd26..0000000000 --- a/src/pal/tests/palsuite/threading/CriticalSectionFunctions/test8/test8.c +++ /dev/null @@ -1,217 +0,0 @@ -// 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: CriticalSectionFunctions/test8/test8.c -** -** Pyrpose: Ensure critical section functionality is working by -** having multiple threads racing on a CS under different -** scenarios -** -** -**===================================================================*/ -#include - -#define MAX_THREAD_COUNT 128 -#define DEFAULT_THREAD_COUNT 10 -#define DEFAULT_LOOP_COUNT 1000 - -#ifndef MIN -#define MIN(a,b) (((a)<(b)) ? (a) : (b)) -#endif - -int g_iThreadCount = DEFAULT_THREAD_COUNT; -int g_iLoopCount = DEFAULT_LOOP_COUNT; -volatile LONG g_lCriticalCount = 0; -HANDLE g_hEvStart = NULL; - -CRITICAL_SECTION g_cs; -DWORD PALAPI Thread(LPVOID lpParam) -{ - int i, j, iLpCnt; - DWORD dwRet = 0; - DWORD dwTid = GetCurrentThreadId(); - LONG lRet; - BOOL bSleepInside; - BOOL bSleepOutside; - - Trace("[tid=%u] Thread starting\n", dwTid); - - dwRet = WaitForSingleObject(g_hEvStart, INFINITE); - if (WAIT_OBJECT_0 != dwRet) - { - Fail("WaitForSingleObject returned unexpected %u [GetLastError()=%u]\n", - dwRet, GetLastError()); - } - - for (j=0;j<8;j++) - { - bSleepInside = 2 & j; - bSleepOutside = 4 & j; - - iLpCnt = g_iLoopCount; - if (bSleepInside || bSleepOutside) - { - iLpCnt /= 10; - } - - for (i=0;i= iVal) - { - g_iThreadCount = iVal; - } - } - break; - default: - break; - } - } - } - - Trace ("Iterations:\t%d\n", g_iLoopCount); - Trace ("Threads:\t%d\n", g_iThreadCount); - - g_hEvStart = CreateEvent(NULL, TRUE, FALSE, NULL); - - if (g_hEvStart == NULL) - { - Fail("CreateEvent call failed. GetLastError " - "returned %u.\n", GetLastError()); - } - - InitializeCriticalSection(&g_cs); - - for (i=0;i iThreadCount) - { - Fail("Failed to create minimum number if threads, i.e. 2\n"); - } - - if (!SetEvent(g_hEvStart)) - { - Fail("SetEvent failed [GetLastError()=%u]\n", GetLastError()); - } - - for (i=0; i + +#define MAX_THREAD_COUNT 128 +#define DEFAULT_THREAD_COUNT 10 +#define DEFAULT_LOOP_COUNT 1000 + +#ifndef MIN +#define MIN(a,b) (((a)<(b)) ? (a) : (b)) +#endif + +int g_iThreadCount = DEFAULT_THREAD_COUNT; +int g_iLoopCount = DEFAULT_LOOP_COUNT; +volatile LONG g_lCriticalCount = 0; +HANDLE g_hEvStart = NULL; + +CRITICAL_SECTION g_cs; +DWORD PALAPI Thread(LPVOID lpParam) +{ + int i, j, iLpCnt; + DWORD dwRet = 0; + DWORD dwTid = GetCurrentThreadId(); + LONG lRet; + BOOL bSleepInside; + BOOL bSleepOutside; + + Trace("[tid=%u] Thread starting\n", dwTid); + + dwRet = WaitForSingleObject(g_hEvStart, INFINITE); + if (WAIT_OBJECT_0 != dwRet) + { + Fail("WaitForSingleObject returned unexpected %u [GetLastError()=%u]\n", + dwRet, GetLastError()); + } + + for (j=0;j<8;j++) + { + bSleepInside = 2 & j; + bSleepOutside = 4 & j; + + iLpCnt = g_iLoopCount; + if (bSleepInside || bSleepOutside) + { + iLpCnt /= 10; + } + + for (i=0;i= iVal) + { + g_iThreadCount = iVal; + } + } + break; + default: + break; + } + } + } + + Trace ("Iterations:\t%d\n", g_iLoopCount); + Trace ("Threads:\t%d\n", g_iThreadCount); + + g_hEvStart = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (g_hEvStart == NULL) + { + Fail("CreateEvent call failed. GetLastError " + "returned %u.\n", GetLastError()); + } + + InitializeCriticalSection(&g_cs); + + for (i=0;i iThreadCount) + { + Fail("Failed to create minimum number if threads, i.e. 2\n"); + } + + if (!SetEvent(g_hEvStart)) + { + Fail("SetEvent failed [GetLastError()=%u]\n", GetLastError()); + } + + for (i=0; i - - -/* SHLEXT is defined only for Unix variants */ - -#if defined(SHLEXT) -#define LibName "testlib"SHLEXT -#define GETCALLCOUNT "GetCallCount" -#else -#define LibName "testlib" -#define GETCALLCOUNT "_GetCallCount@0" -#endif - -DWORD __stdcall ThreadFunc(LPVOID lpParam); -int RunTest(int DisableThreadCalls); - -int __cdecl main(int argc, char **argv) -{ - int ret; - - if ((PAL_Initialize(argc,argv)) != 0) - { - return (FAIL); - } - - - /* - * Although MSDN says that DisableThreadLibraryCalls will fail if passed - * an invalid handle, it actually returns success! - */ - ret = DisableThreadLibraryCalls(NULL); - if (!ret) - { - Fail("DisableThreadLibraryCalls failed on an invalid module " - "handle (it actually should pass)!\n"); - } - - - /* - * Test once without calling DisableThreadLibraryCalls and make sure we - * get expected results. - */ - ret = RunTest(0); - if (ret != 2) - { - Fail("Expected to get 2 thread library calls, got %d!\n", ret); - } - - - /* - * Test again, this time calling DisableThreadLibraryCalls. - */ - ret = RunTest(1); - if (ret != 0) - { - Fail("Expected to get 0 thread library calls, got %d!\n", ret); - } - - PAL_Terminate(); - return PASS; -} - -/* - * Thread entry point. Doesn't do anything. - */ -DWORD __stdcall ThreadFunc(LPVOID lpParam) -{ - return 0; -} - - -int RunTest(int DisableThreadCalls) -{ - HMODULE LibMod; - HANDLE hThread; - DWORD threadID; - DWORD WaitRet; - int (*GetCallCount)(); - int count; - - LibMod = LoadLibrary(LibName); - if (LibMod == NULL) - { - Fail("Unable to load test library!\nGetLastError returned %d\n", - GetLastError()); - } - - GetCallCount = (int(*)())GetProcAddress(LibMod, GETCALLCOUNT); - if (GetCallCount == NULL) - { - Fail("Unable to get function GetCallCount from library!\n" - "GetLastError returned %d\n", GetLastError()); - } - - if (DisableThreadCalls) - { - if (!DisableThreadLibraryCalls(LibMod)) - { - Fail("DisabledThreadLibraryCalls failed!\n" - "GetLastError returned %d!\n", GetLastError()); - } - } - - hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ThreadFunc, - NULL, 0, &threadID); - - if (hThread == NULL) - { - Fail("Unable to create a thread!\n"); - } - - WaitRet = WaitForSingleObject(hThread, INFINITE); - if (WaitRet == WAIT_FAILED) - { - Fail("Unable to wait on thread!\nGetLastError returned %d\n", - GetLastError()); - } - - count = GetCallCount(); - - CloseHandle(hThread); - - if (!FreeLibrary(LibMod)) - { - Fail("Failed freeing library!\nGetLastError returned %d\n", - GetLastError()); - } - - return count; -} diff --git a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/test1.cpp b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/test1.cpp new file mode 100644 index 0000000000..b64fd0c7d2 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/test1.cpp @@ -0,0 +1,145 @@ +// 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: test1.c +** +** Purpose: Tests that DisableThreadLibraryCalls actually stops thread +** attach/detach notifications to a library. Also tests how it +** handles an invalid module handle. +** +** +**===================================================================*/ + +#include + + +/* SHLEXT is defined only for Unix variants */ + +#if defined(SHLEXT) +#define LibName "testlib"SHLEXT +#define GETCALLCOUNT "GetCallCount" +#else +#define LibName "testlib" +#define GETCALLCOUNT "_GetCallCount@0" +#endif + +DWORD __stdcall ThreadFunc(LPVOID lpParam); +int RunTest(int DisableThreadCalls); + +int __cdecl main(int argc, char **argv) +{ + int ret; + + if ((PAL_Initialize(argc,argv)) != 0) + { + return (FAIL); + } + + + /* + * Although MSDN says that DisableThreadLibraryCalls will fail if passed + * an invalid handle, it actually returns success! + */ + ret = DisableThreadLibraryCalls(NULL); + if (!ret) + { + Fail("DisableThreadLibraryCalls failed on an invalid module " + "handle (it actually should pass)!\n"); + } + + + /* + * Test once without calling DisableThreadLibraryCalls and make sure we + * get expected results. + */ + ret = RunTest(0); + if (ret != 2) + { + Fail("Expected to get 2 thread library calls, got %d!\n", ret); + } + + + /* + * Test again, this time calling DisableThreadLibraryCalls. + */ + ret = RunTest(1); + if (ret != 0) + { + Fail("Expected to get 0 thread library calls, got %d!\n", ret); + } + + PAL_Terminate(); + return PASS; +} + +/* + * Thread entry point. Doesn't do anything. + */ +DWORD __stdcall ThreadFunc(LPVOID lpParam) +{ + return 0; +} + + +int RunTest(int DisableThreadCalls) +{ + HMODULE LibMod; + HANDLE hThread; + DWORD threadID; + DWORD WaitRet; + int (*GetCallCount)(); + int count; + + LibMod = LoadLibrary(LibName); + if (LibMod == NULL) + { + Fail("Unable to load test library!\nGetLastError returned %d\n", + GetLastError()); + } + + GetCallCount = (int(*)())GetProcAddress(LibMod, GETCALLCOUNT); + if (GetCallCount == NULL) + { + Fail("Unable to get function GetCallCount from library!\n" + "GetLastError returned %d\n", GetLastError()); + } + + if (DisableThreadCalls) + { + if (!DisableThreadLibraryCalls(LibMod)) + { + Fail("DisabledThreadLibraryCalls failed!\n" + "GetLastError returned %d!\n", GetLastError()); + } + } + + hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ThreadFunc, + NULL, 0, &threadID); + + if (hThread == NULL) + { + Fail("Unable to create a thread!\n"); + } + + WaitRet = WaitForSingleObject(hThread, INFINITE); + if (WaitRet == WAIT_FAILED) + { + Fail("Unable to wait on thread!\nGetLastError returned %d\n", + GetLastError()); + } + + count = GetCallCount(); + + CloseHandle(hThread); + + if (!FreeLibrary(LibMod)) + { + Fail("Failed freeing library!\nGetLastError returned %d\n", + GetLastError()); + } + + return count; +} diff --git a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/testlib.c b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/testlib.c deleted file mode 100644 index 53b66d1357..0000000000 --- a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/testlib.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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: testlib.c -** -** Purpose: Simple library that counts thread attach/detach notifications -** -** -**===================================================================*/ - -#include - -static int Count; - -BOOL __stdcall DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - - if (fdwReason == DLL_PROCESS_ATTACH) - { - Count = 0; - } - else if (fdwReason == DLL_THREAD_ATTACH || - fdwReason == DLL_THREAD_DETACH) - { - Count++; - } - - return TRUE; -} - -#ifdef WIN32 -BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - return DllMain(hinstDLL, fdwReason, lpvReserved); -} -#endif - -#ifdef WIN32 -__declspec(dllexport) -#endif -int __stdcall GetCallCount() -{ - return Count; -} diff --git a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/testlib.cpp b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/testlib.cpp new file mode 100644 index 0000000000..53b66d1357 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test1/testlib.cpp @@ -0,0 +1,47 @@ +// 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: testlib.c +** +** Purpose: Simple library that counts thread attach/detach notifications +** +** +**===================================================================*/ + +#include + +static int Count; + +BOOL __stdcall DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + + if (fdwReason == DLL_PROCESS_ATTACH) + { + Count = 0; + } + else if (fdwReason == DLL_THREAD_ATTACH || + fdwReason == DLL_THREAD_DETACH) + { + Count++; + } + + return TRUE; +} + +#ifdef WIN32 +BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + return DllMain(hinstDLL, fdwReason, lpvReserved); +} +#endif + +#ifdef WIN32 +__declspec(dllexport) +#endif +int __stdcall GetCallCount() +{ + return Count; +} diff --git a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain1.c b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain1.c deleted file mode 100644 index 5010a27665..0000000000 --- a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain1.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: dllmain1.c -** -** Purpose: Test to ensure DllMain() is called with THREAD_ATTACH -** when a thread in the application is started. -** -** Dependencies: none -** -** -**===========================================================================*/ - -#include - -/* count of the number of times DllMain() was called with THREAD_DETACH */ -static int g_attachCount = 0; - - -/* standard DllMain() */ -BOOL PALAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) -{ - BOOL bResult = TRUE; - - switch( reason ) - { - case DLL_PROCESS_ATTACH: - { - break; - } - - case DLL_PROCESS_DETACH: - { - break; - } - - case DLL_THREAD_ATTACH: - /* increment g_attachCount */ - g_attachCount++; - break; - - case DLL_THREAD_DETACH: - break; - } - return bResult; -} - - -#ifdef WIN32 -BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - return DllMain(hinstDLL, fdwReason, lpvReserved); -} -#endif - -/* function to return the current attach count */ -#ifdef WIN32 -__declspec(dllexport) -#endif -int PALAPI GetAttachCount( void ) -{ - return g_attachCount; -} diff --git a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain1.cpp b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain1.cpp new file mode 100644 index 0000000000..5010a27665 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain1.cpp @@ -0,0 +1,66 @@ +// 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: dllmain1.c +** +** Purpose: Test to ensure DllMain() is called with THREAD_ATTACH +** when a thread in the application is started. +** +** Dependencies: none +** +** +**===========================================================================*/ + +#include + +/* count of the number of times DllMain() was called with THREAD_DETACH */ +static int g_attachCount = 0; + + +/* standard DllMain() */ +BOOL PALAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) +{ + BOOL bResult = TRUE; + + switch( reason ) + { + case DLL_PROCESS_ATTACH: + { + break; + } + + case DLL_PROCESS_DETACH: + { + break; + } + + case DLL_THREAD_ATTACH: + /* increment g_attachCount */ + g_attachCount++; + break; + + case DLL_THREAD_DETACH: + break; + } + return bResult; +} + + +#ifdef WIN32 +BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + return DllMain(hinstDLL, fdwReason, lpvReserved); +} +#endif + +/* function to return the current attach count */ +#ifdef WIN32 +__declspec(dllexport) +#endif +int PALAPI GetAttachCount( void ) +{ + return g_attachCount; +} diff --git a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain2.c b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain2.c deleted file mode 100644 index 4e3f8862a4..0000000000 --- a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain2.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: dllmain2.c -** -** Purpose: Test to ensure DllMain() is called with THREAD_ATTACH -** when a thread in the application is started. -** -** Dependencies: none -** -** -**===========================================================================*/ - -#include - -/* count of the number of times DllMain() was called with THREAD_DETACH */ -static int g_attachCount = 0; - - -/* standard DllMain() */ -BOOL PALAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) -{ - BOOL bResult = TRUE; - - switch( reason ) - { - case DLL_PROCESS_ATTACH: - { - break; - } - - case DLL_PROCESS_DETACH: - { - break; - } - - case DLL_THREAD_ATTACH: - /* increment g_attachCount */ - g_attachCount++; - break; - - case DLL_THREAD_DETACH: - break; - } - return bResult; -} - - -#ifdef WIN32 -BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - return DllMain(hinstDLL, fdwReason, lpvReserved); -} -#endif - -/* function to return the current attach count */ -#ifdef WIN32 -__declspec(dllexport) -#endif -int PALAPI GetAttachCount( void ) -{ - return g_attachCount; -} diff --git a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain2.cpp b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain2.cpp new file mode 100644 index 0000000000..4e3f8862a4 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/dllmain2.cpp @@ -0,0 +1,66 @@ +// 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: dllmain2.c +** +** Purpose: Test to ensure DllMain() is called with THREAD_ATTACH +** when a thread in the application is started. +** +** Dependencies: none +** +** +**===========================================================================*/ + +#include + +/* count of the number of times DllMain() was called with THREAD_DETACH */ +static int g_attachCount = 0; + + +/* standard DllMain() */ +BOOL PALAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) +{ + BOOL bResult = TRUE; + + switch( reason ) + { + case DLL_PROCESS_ATTACH: + { + break; + } + + case DLL_PROCESS_DETACH: + { + break; + } + + case DLL_THREAD_ATTACH: + /* increment g_attachCount */ + g_attachCount++; + break; + + case DLL_THREAD_DETACH: + break; + } + return bResult; +} + + +#ifdef WIN32 +BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + return DllMain(hinstDLL, fdwReason, lpvReserved); +} +#endif + +/* function to return the current attach count */ +#ifdef WIN32 +__declspec(dllexport) +#endif +int PALAPI GetAttachCount( void ) +{ + return g_attachCount; +} diff --git a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/test2.c b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/test2.c deleted file mode 100644 index 5fb694ea14..0000000000 --- a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/test2.c +++ /dev/null @@ -1,237 +0,0 @@ -// 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: test2.c -** -** Purpose: Test to ensure DisableThreadLibraryCalls() called for one -** library will not disrupt THREAD_ATTACH notifications etc. by -** other loaded modules. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** CreateThread -** ResumeThread -** LoadLibrary -** FreeLibrary -** GetProcAddress -** WaitForSingleObject -** GetLastError -** -** -**===========================================================================*/ -#include - -/* SHLEXT is defined only for Unix variants */ - -#if defined(SHLEXT) -#define rgchLibraryFile1 "dllmain1"SHLEXT -#define rgchLibraryFile2 "dllmain2"SHLEXT -#define szFunction "GetAttachCount" -#else -#define rgchLibraryFile1 "dllmain1" -#define rgchLibraryFile2 "dllmain2" -#define szFunction "_GetAttachCount@0" -#endif - -/* define our test function type */ -typedef int ( PALAPI *LPTESTFUNC )( void ); - - - -/** - * ThreadFunc - * - * Dummy thread function for causing DLL thread notifications. - */ -DWORD PALAPI ThreadFunc( LPVOID param ) -{ - /* simulate some brief "work" */ - int i; - for( i=0; i<100000; i++ ) - { - } - - return 0; -} - - -/* main program entry point */ -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - - HANDLE hLib1 = NULL; - HANDLE hLib2 = NULL; - LPTESTFUNC pFunc1; - LPTESTFUNC pFunc2; - int attachCount1a = 0; - int attachCount1b = 0; - int attachCount2a = 0; - int attachCount2b = 0; - - HANDLE hThread = NULL; - DWORD IDThread; - DWORD dwRet; - - BOOL bResult = FAIL; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* Load the first test library */ - hLib1 = LoadLibrary( rgchLibraryFile1 ); - if(hLib1 == NULL) - { - Fail( "ERROR:%lu:LoadLibrary() call failed for %s\n", - GetLastError(), - rgchLibraryFile1 ); - } - - /* Load the second test library */ - hLib2 = LoadLibrary( rgchLibraryFile2 ); - if(hLib2 == NULL) - { - Trace( "ERROR:%lu:LoadLibrary() call failed for %s\n", - GetLastError(), - rgchLibraryFile2 ); - if( ! FreeLibrary( hLib1 ) ) - { - Trace( "ERROR:%lu:FreeLibrary() call failed\n", GetLastError() ); - } - Fail( "test failed\n" ); - } - - - /* Get the addresses of our test functions in the dlls */ - pFunc1 = (LPTESTFUNC)GetProcAddress( hLib1, szFunction ); - if( pFunc1 == NULL ) - { - Trace( "ERROR:%lu%:Unable to find \"%s\" in library \"%s\"\n", - GetLastError(), - szFunction, - rgchLibraryFile1 ); - goto cleanup; - } - - pFunc2 = (LPTESTFUNC)GetProcAddress( hLib2, szFunction ); - if( pFunc1 == NULL ) - { - Trace( "ERROR:%lu%:Unable to find \"%s\" in library \"%s\"\n", - GetLastError(), - szFunction, - rgchLibraryFile2 ); - goto cleanup; - } - - /* disable thread library calls for the first library */ - if( ! DisableThreadLibraryCalls( (HMODULE)hLib1 ) ) - { - Trace( "ERROR:%lu:DisableThreadLibraryCalls() call failed\n", - GetLastError() ); - goto cleanup; - } - - /* Execute the test function to get the attach count */ - attachCount1a = pFunc1(); - attachCount2a = pFunc2(); - - /* run another dummy thread to cause notification of the libraries */ - hThread = CreateThread( NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ - (LPVOID) NULL, /* pass thread index as */ - /* function argument */ - CREATE_SUSPENDED, /* create suspended */ - &IDThread ); /* returns thread id */ - - /* Check the return value for success. */ - if( hThread == NULL ) - { - /* error creating thread */ - Trace( "ERROR:%lu:CreateThread() call failed\n", - GetLastError() ); - goto cleanup; - } - - /* Resume the suspended thread */ - if( ResumeThread( hThread ) == -1 ) - { - Trace( "ERROR:%lu:ResumeThread() call failed\n", GetLastError() ); - goto cleanup; - } - - - /* wait for the thread to complete */ - dwRet = WaitForSingleObject( hThread, INFINITE ); - if( dwRet != WAIT_OBJECT_0 ) - { - Trace( "ERROR: WaitForSingleObject returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - goto cleanup; - } - - - /* Execute the test function to get the new detach count */ - attachCount1b = pFunc1(); - attachCount2b = pFunc2(); - - /* validate the result */ - if( attachCount1b != attachCount1a ) - { - Trace( "FAIL: unexpected DLL attach count %d, expected %d\n", - attachCount1b, - attachCount1a ); - goto cleanup; - } - - /* validate the result */ - if( attachCount2b != (attachCount2a + 1) ) - { - Trace( "FAIL: unexpected DLL attach count %d, expected %d\n", - attachCount2b, - (attachCount2a + 1) ); - goto cleanup; - } - - bResult = PASS; - -cleanup: - /* Unload the test libraries */ - if( !FreeLibrary( hLib1 ) ) - { - Trace( "ERROR:%u:FreeLibrary() failed on library \"%s\"\n", - GetLastError(), - rgchLibraryFile1 ); - bResult = FAIL; - } - - if( !FreeLibrary( hLib2 ) ) - { - Trace( "ERROR:%u:FreeLibrary() failed on library \"%s\"\n", - GetLastError(), - rgchLibraryFile2 ); - bResult = FAIL; - } - - /* check for failure */ - if( bResult == FAIL ) - { - Fail( "test failed\n" ); - } - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return PASS; -} - diff --git a/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/test2.cpp b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/test2.cpp new file mode 100644 index 0000000000..5fb694ea14 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DisableThreadLibraryCalls/test2/test2.cpp @@ -0,0 +1,237 @@ +// 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: test2.c +** +** Purpose: Test to ensure DisableThreadLibraryCalls() called for one +** library will not disrupt THREAD_ATTACH notifications etc. by +** other loaded modules. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** CreateThread +** ResumeThread +** LoadLibrary +** FreeLibrary +** GetProcAddress +** WaitForSingleObject +** GetLastError +** +** +**===========================================================================*/ +#include + +/* SHLEXT is defined only for Unix variants */ + +#if defined(SHLEXT) +#define rgchLibraryFile1 "dllmain1"SHLEXT +#define rgchLibraryFile2 "dllmain2"SHLEXT +#define szFunction "GetAttachCount" +#else +#define rgchLibraryFile1 "dllmain1" +#define rgchLibraryFile2 "dllmain2" +#define szFunction "_GetAttachCount@0" +#endif + +/* define our test function type */ +typedef int ( PALAPI *LPTESTFUNC )( void ); + + + +/** + * ThreadFunc + * + * Dummy thread function for causing DLL thread notifications. + */ +DWORD PALAPI ThreadFunc( LPVOID param ) +{ + /* simulate some brief "work" */ + int i; + for( i=0; i<100000; i++ ) + { + } + + return 0; +} + + +/* main program entry point */ +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + + HANDLE hLib1 = NULL; + HANDLE hLib2 = NULL; + LPTESTFUNC pFunc1; + LPTESTFUNC pFunc2; + int attachCount1a = 0; + int attachCount1b = 0; + int attachCount2a = 0; + int attachCount2b = 0; + + HANDLE hThread = NULL; + DWORD IDThread; + DWORD dwRet; + + BOOL bResult = FAIL; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* Load the first test library */ + hLib1 = LoadLibrary( rgchLibraryFile1 ); + if(hLib1 == NULL) + { + Fail( "ERROR:%lu:LoadLibrary() call failed for %s\n", + GetLastError(), + rgchLibraryFile1 ); + } + + /* Load the second test library */ + hLib2 = LoadLibrary( rgchLibraryFile2 ); + if(hLib2 == NULL) + { + Trace( "ERROR:%lu:LoadLibrary() call failed for %s\n", + GetLastError(), + rgchLibraryFile2 ); + if( ! FreeLibrary( hLib1 ) ) + { + Trace( "ERROR:%lu:FreeLibrary() call failed\n", GetLastError() ); + } + Fail( "test failed\n" ); + } + + + /* Get the addresses of our test functions in the dlls */ + pFunc1 = (LPTESTFUNC)GetProcAddress( hLib1, szFunction ); + if( pFunc1 == NULL ) + { + Trace( "ERROR:%lu%:Unable to find \"%s\" in library \"%s\"\n", + GetLastError(), + szFunction, + rgchLibraryFile1 ); + goto cleanup; + } + + pFunc2 = (LPTESTFUNC)GetProcAddress( hLib2, szFunction ); + if( pFunc1 == NULL ) + { + Trace( "ERROR:%lu%:Unable to find \"%s\" in library \"%s\"\n", + GetLastError(), + szFunction, + rgchLibraryFile2 ); + goto cleanup; + } + + /* disable thread library calls for the first library */ + if( ! DisableThreadLibraryCalls( (HMODULE)hLib1 ) ) + { + Trace( "ERROR:%lu:DisableThreadLibraryCalls() call failed\n", + GetLastError() ); + goto cleanup; + } + + /* Execute the test function to get the attach count */ + attachCount1a = pFunc1(); + attachCount2a = pFunc2(); + + /* run another dummy thread to cause notification of the libraries */ + hThread = CreateThread( NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ + (LPVOID) NULL, /* pass thread index as */ + /* function argument */ + CREATE_SUSPENDED, /* create suspended */ + &IDThread ); /* returns thread id */ + + /* Check the return value for success. */ + if( hThread == NULL ) + { + /* error creating thread */ + Trace( "ERROR:%lu:CreateThread() call failed\n", + GetLastError() ); + goto cleanup; + } + + /* Resume the suspended thread */ + if( ResumeThread( hThread ) == -1 ) + { + Trace( "ERROR:%lu:ResumeThread() call failed\n", GetLastError() ); + goto cleanup; + } + + + /* wait for the thread to complete */ + dwRet = WaitForSingleObject( hThread, INFINITE ); + if( dwRet != WAIT_OBJECT_0 ) + { + Trace( "ERROR: WaitForSingleObject returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + goto cleanup; + } + + + /* Execute the test function to get the new detach count */ + attachCount1b = pFunc1(); + attachCount2b = pFunc2(); + + /* validate the result */ + if( attachCount1b != attachCount1a ) + { + Trace( "FAIL: unexpected DLL attach count %d, expected %d\n", + attachCount1b, + attachCount1a ); + goto cleanup; + } + + /* validate the result */ + if( attachCount2b != (attachCount2a + 1) ) + { + Trace( "FAIL: unexpected DLL attach count %d, expected %d\n", + attachCount2b, + (attachCount2a + 1) ); + goto cleanup; + } + + bResult = PASS; + +cleanup: + /* Unload the test libraries */ + if( !FreeLibrary( hLib1 ) ) + { + Trace( "ERROR:%u:FreeLibrary() failed on library \"%s\"\n", + GetLastError(), + rgchLibraryFile1 ); + bResult = FAIL; + } + + if( !FreeLibrary( hLib2 ) ) + { + Trace( "ERROR:%u:FreeLibrary() failed on library \"%s\"\n", + GetLastError(), + rgchLibraryFile2 ); + bResult = FAIL; + } + + /* check for failure */ + if( bResult == FAIL ) + { + Fail( "test failed\n" ); + } + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return PASS; +} + diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/CMakeLists.txt index b908c1246b..9d5fc53a2d 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/CMakeLists.txt @@ -11,5 +11,4 @@ add_subdirectory(test5) add_subdirectory(test6) add_subdirectory(test7) add_subdirectory(test8) -add_subdirectory(test9) diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test1/CMakeLists.txt index 04588b75fe..18b1927a4e 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_duplicatehandle_test1 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test1/test1.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test1/test1.c deleted file mode 100644 index e080e98ae8..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test1/test1.c +++ /dev/null @@ -1,152 +0,0 @@ -// 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: test1.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function. -** This test will create two handles to file, one to write and -** one to read what was written. Test on a closed handle and a -** NULL handle, both should fail. -** -** -**===================================================================*/ -#include - -int __cdecl main(int argc, char **argv) -{ - HANDLE hFile; - HANDLE hDupFile; - char buf[256]; - char teststr[] = "A uNiQuE tEsT sTrInG"; - char lpFileName[] = "testfile.txt"; - DWORD dwBytesWritten; - DWORD dwBytesRead; - BOOL bRetVal; - - /*Initalize the PAL*/ - if ((PAL_Initialize(argc,argv)) != 0) - { - return (FAIL); - } - - /*Create a file handle with CreateFile*/ - hFile = CreateFile(lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_WRITE|FILE_SHARE_READ, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /*Write test string to the file.*/ - bRetVal = WriteFile(hFile, // handle to file - teststr, // data buffer - strlen(teststr), // number of bytes to write - &dwBytesWritten, // number of bytes written - NULL); // overlapped buffer - - if (bRetVal == FALSE) - { - Trace("ERROR: %u : unable to write to file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - CloseHandle(hFile); - Fail(""); - } - - /*Create a duplicate handle with DuplicateHandle.*/ - if (!(DuplicateHandle( - GetCurrentProcess(), - hFile, - GetCurrentProcess(), - &hDupFile, - GENERIC_READ|GENERIC_WRITE, - FALSE, - DUPLICATE_SAME_ACCESS))) - { - Trace("ERROR: %u : Fail to create the duplicate handle" - " to hFile=0x%lx\n", - GetLastError(), - hFile); - CloseHandle(hFile); - Fail(""); - } - - memset(buf, 0, 256); - - /*Read from the Duplicated handle.*/ - bRetVal = ReadFile(hDupFile, - buf, - 256, - &dwBytesRead, - NULL); - if (bRetVal == FALSE) - { - Trace("ERROR: %u :unable to read from file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - CloseHandle(hFile); - CloseHandle(hDupFile); - Fail(""); - } - - /*Compare what was written to what was read.*/ - if (memcmp(teststr, buf, dwBytesRead) != 0) - { - Trace("ERROR: expected %s, got %s\n", teststr, buf); - CloseHandle(hFile); - CloseHandle(hDupFile); - Fail(""); - } - - /*Close the handles*/ - CloseHandle(hFile); - CloseHandle(hDupFile); - - /*Failure test: Create DuplicateHandle to a closed handle*/ - if ((DuplicateHandle( - GetCurrentProcess(), - hFile, - GetCurrentProcess(), - &hDupFile, - GENERIC_READ|GENERIC_WRITE, - FALSE, - DUPLICATE_SAME_ACCESS))) - { - Fail("ERROR: %u :Created a duplicate handle to" - " a closed handle hFile=0x%lx\n", - GetLastError(), - hFile); - } - - /*Failure test: Create DuplicateHandle to a NULL handle*/ - hFile = NULL; - if ((DuplicateHandle( - GetCurrentProcess(), - hFile, - GetCurrentProcess(), - &hDupFile, - GENERIC_READ|GENERIC_WRITE, - FALSE, - DUPLICATE_SAME_ACCESS))) - { - Fail("ERROR: %u :Created a duplicate handle to " - " a NULL handle hFile=0x%lx\n", - GetLastError(), - hFile); - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test1/test1.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test1/test1.cpp new file mode 100644 index 0000000000..e080e98ae8 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test1/test1.cpp @@ -0,0 +1,152 @@ +// 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: test1.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function. +** This test will create two handles to file, one to write and +** one to read what was written. Test on a closed handle and a +** NULL handle, both should fail. +** +** +**===================================================================*/ +#include + +int __cdecl main(int argc, char **argv) +{ + HANDLE hFile; + HANDLE hDupFile; + char buf[256]; + char teststr[] = "A uNiQuE tEsT sTrInG"; + char lpFileName[] = "testfile.txt"; + DWORD dwBytesWritten; + DWORD dwBytesRead; + BOOL bRetVal; + + /*Initalize the PAL*/ + if ((PAL_Initialize(argc,argv)) != 0) + { + return (FAIL); + } + + /*Create a file handle with CreateFile*/ + hFile = CreateFile(lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_WRITE|FILE_SHARE_READ, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /*Write test string to the file.*/ + bRetVal = WriteFile(hFile, // handle to file + teststr, // data buffer + strlen(teststr), // number of bytes to write + &dwBytesWritten, // number of bytes written + NULL); // overlapped buffer + + if (bRetVal == FALSE) + { + Trace("ERROR: %u : unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + CloseHandle(hFile); + Fail(""); + } + + /*Create a duplicate handle with DuplicateHandle.*/ + if (!(DuplicateHandle( + GetCurrentProcess(), + hFile, + GetCurrentProcess(), + &hDupFile, + GENERIC_READ|GENERIC_WRITE, + FALSE, + DUPLICATE_SAME_ACCESS))) + { + Trace("ERROR: %u : Fail to create the duplicate handle" + " to hFile=0x%lx\n", + GetLastError(), + hFile); + CloseHandle(hFile); + Fail(""); + } + + memset(buf, 0, 256); + + /*Read from the Duplicated handle.*/ + bRetVal = ReadFile(hDupFile, + buf, + 256, + &dwBytesRead, + NULL); + if (bRetVal == FALSE) + { + Trace("ERROR: %u :unable to read from file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + CloseHandle(hFile); + CloseHandle(hDupFile); + Fail(""); + } + + /*Compare what was written to what was read.*/ + if (memcmp(teststr, buf, dwBytesRead) != 0) + { + Trace("ERROR: expected %s, got %s\n", teststr, buf); + CloseHandle(hFile); + CloseHandle(hDupFile); + Fail(""); + } + + /*Close the handles*/ + CloseHandle(hFile); + CloseHandle(hDupFile); + + /*Failure test: Create DuplicateHandle to a closed handle*/ + if ((DuplicateHandle( + GetCurrentProcess(), + hFile, + GetCurrentProcess(), + &hDupFile, + GENERIC_READ|GENERIC_WRITE, + FALSE, + DUPLICATE_SAME_ACCESS))) + { + Fail("ERROR: %u :Created a duplicate handle to" + " a closed handle hFile=0x%lx\n", + GetLastError(), + hFile); + } + + /*Failure test: Create DuplicateHandle to a NULL handle*/ + hFile = NULL; + if ((DuplicateHandle( + GetCurrentProcess(), + hFile, + GetCurrentProcess(), + &hDupFile, + GENERIC_READ|GENERIC_WRITE, + FALSE, + DUPLICATE_SAME_ACCESS))) + { + Fail("ERROR: %u :Created a duplicate handle to " + " a NULL handle hFile=0x%lx\n", + GetLastError(), + hFile); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test10/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test10/CMakeLists.txt index ba16252cb4..98c7a273dc 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test10/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test10/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test10.c + test10.cpp ) add_executable(paltest_duplicatehandle_test10 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test10/test10.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test10/test10.c deleted file mode 100644 index 108d748de6..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test10/test10.c +++ /dev/null @@ -1,239 +0,0 @@ -// 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: test10.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function. -** This tests the operation of a duplicated Semaphore handle -** -** -**===================================================================*/ - -#include - -enum wait_results -{ - WR_WAITING, - WR_GOT_MUTEX, - WR_TIMED_OUT, - WR_RELEASED -}; - - -volatile int t1_result=WR_WAITING; -volatile int t2_result=WR_WAITING; - - -DWORD PALAPI ThreadTest1(LPVOID lpParam) -{ - DWORD dwWait; - - dwWait = WaitForSingleObject((HANDLE)lpParam, 0); - if (dwWait == WAIT_OBJECT_0) - { - /* tell the main thread we got the mutex */ - t1_result=WR_GOT_MUTEX; - - /* wait for main thread to tell us to release the mutex */ - while(WR_GOT_MUTEX == t1_result) - Sleep(1); - ReleaseSemaphore((HANDLE)lpParam, 1, NULL); - - /* tell the main thread we released the mutex */ - t1_result = WR_RELEASED; - } - else - { - t1_result = WR_TIMED_OUT; - } - return 0; -} - -DWORD PALAPI ThreadTest2(LPVOID lpParam) -{ - DWORD dwWait; - - dwWait = WaitForSingleObject((HANDLE)lpParam, 0 ); - if (dwWait == WAIT_OBJECT_0) - { - ReleaseSemaphore((HANDLE)lpParam, 1, NULL); - t2_result = WR_GOT_MUTEX; - } - else - { - t2_result = WR_TIMED_OUT; - } - - return 0; -} - - -int __cdecl main(int argc, char **argv) -{ - - HANDLE hDupSemaphore; - HANDLE hSemaphore; - HANDLE hThread; - HANDLE hThread2; - BOOL bDupHandle=FALSE; - DWORD dwThreadId = 0; - - if ((PAL_Initialize(argc,argv)) != 0) - { - return(FAIL); - } - - hSemaphore = CreateSemaphoreW( NULL, - 1, - 1, - NULL); - if (hSemaphore == NULL) - { - Fail("PALSUITE ERROR:%u: Unable to create mutex\n", - GetLastError()); - } - - /*Create Duplicate of the Semaphore above*/ - bDupHandle = DuplicateHandle(GetCurrentProcess(), - hSemaphore, - GetCurrentProcess(), - &hDupSemaphore, - GENERIC_READ|GENERIC_WRITE, - FALSE, - DUPLICATE_SAME_ACCESS); - if (!bDupHandle) - { - Trace("PALSUITE ERROR:%u: Created the duplicate handle to " - "closed event handle hSemaphore=0x%lx\n", - GetLastError(), - hSemaphore); - CloseHandle(hSemaphore); - Fail(""); - } - - /*Create a thread to test the Semaphore*/ - hThread = CreateThread(NULL, - 0, - &ThreadTest1, - hSemaphore, - 0, - &dwThreadId); - if (hThread == NULL) - { - Trace("PALSUITE ERROR:%u: unable to create thread\n", - GetLastError()); - CloseHandle(hSemaphore); - CloseHandle(hDupSemaphore); - Fail(""); - } - - /* wait until thread has taken the mutex */ - while (WR_WAITING == t1_result) - Sleep(1); - - if(WR_TIMED_OUT == t1_result) - { - Trace("PALSUITE ERROR: %u: thread couldn't acquire the semaphore\n", - GetLastError()); - CloseHandle(hSemaphore); - CloseHandle(hDupSemaphore); - CloseHandle(hThread); - Fail(""); - } - - /*Create a second thread to use the Semaphore's duplicate handle*/ - /*This thread should block since the Semaphore is owned by another - thread*/ - hThread2 = CreateThread(NULL, - 0, - &ThreadTest2, - hDupSemaphore, - 0, - &dwThreadId); - - if (hThread2 == NULL) - { - Trace("PALSUITE ERROR:%u: unable to create thread\n", - GetLastError()); - CloseHandle(hSemaphore); - CloseHandle(hDupSemaphore); - CloseHandle(hThread); - Fail(""); - } - - /* wait until thread has tried to take the mutex */ - while (WR_WAITING == t2_result) - Sleep(1); - - if (WR_TIMED_OUT != t2_result ) - { - Trace("PALSUITE ERROR:%u: Able to take mutex %#x while its " - "duplicate %#x is held\n", GetLastError(), hDupSemaphore, - hSemaphore); - CloseHandle(hSemaphore); - CloseHandle(hDupSemaphore); - CloseHandle(hThread); - CloseHandle(hThread2); - Fail(""); - } - - /* reset second thread status */ - t2_result = WR_WAITING; - - /* tell thread 1 to release the mutex */ - t1_result = WR_WAITING; - - /* wait for thread 1 to release the mutex */ - while (WR_WAITING == t1_result) - Sleep(1); - - CloseHandle(hThread2); - - /*Re-Create the second thread to reuse the duplicated Semaphore*/ - /*Since the Semaphore has since been released, the thread should - put WR_GOT_MUTEX into t2_result */ - hThread2 = CreateThread(NULL, - 0, - &ThreadTest2, - hDupSemaphore, - 0, - &dwThreadId); - - if (hThread2 == NULL) - { - Trace("PALSUITE ERROR:%u: unable to create thread\n", - GetLastError()); - CloseHandle(hSemaphore); - CloseHandle(hDupSemaphore); - CloseHandle(hThread); - Fail(""); - } - - /* wait until thread has taken the semaphore */ - while (WR_WAITING == t2_result) - Sleep(1); - - if (WR_GOT_MUTEX != t2_result ) - { - Trace("PALSUITE ERROR:%u: Unable to take semaphore %#x after its" - " duplicate %#x was released\n", GetLastError(), hDupSemaphore, - hSemaphore); - CloseHandle(hSemaphore); - CloseHandle(hDupSemaphore); - CloseHandle(hThread); - CloseHandle(hThread2); - Fail(""); - } - - /*Cleanup.*/ - CloseHandle(hSemaphore); - CloseHandle(hDupSemaphore); - CloseHandle(hThread); - CloseHandle(hThread2); - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test10/test10.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test10/test10.cpp new file mode 100644 index 0000000000..108d748de6 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test10/test10.cpp @@ -0,0 +1,239 @@ +// 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: test10.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function. +** This tests the operation of a duplicated Semaphore handle +** +** +**===================================================================*/ + +#include + +enum wait_results +{ + WR_WAITING, + WR_GOT_MUTEX, + WR_TIMED_OUT, + WR_RELEASED +}; + + +volatile int t1_result=WR_WAITING; +volatile int t2_result=WR_WAITING; + + +DWORD PALAPI ThreadTest1(LPVOID lpParam) +{ + DWORD dwWait; + + dwWait = WaitForSingleObject((HANDLE)lpParam, 0); + if (dwWait == WAIT_OBJECT_0) + { + /* tell the main thread we got the mutex */ + t1_result=WR_GOT_MUTEX; + + /* wait for main thread to tell us to release the mutex */ + while(WR_GOT_MUTEX == t1_result) + Sleep(1); + ReleaseSemaphore((HANDLE)lpParam, 1, NULL); + + /* tell the main thread we released the mutex */ + t1_result = WR_RELEASED; + } + else + { + t1_result = WR_TIMED_OUT; + } + return 0; +} + +DWORD PALAPI ThreadTest2(LPVOID lpParam) +{ + DWORD dwWait; + + dwWait = WaitForSingleObject((HANDLE)lpParam, 0 ); + if (dwWait == WAIT_OBJECT_0) + { + ReleaseSemaphore((HANDLE)lpParam, 1, NULL); + t2_result = WR_GOT_MUTEX; + } + else + { + t2_result = WR_TIMED_OUT; + } + + return 0; +} + + +int __cdecl main(int argc, char **argv) +{ + + HANDLE hDupSemaphore; + HANDLE hSemaphore; + HANDLE hThread; + HANDLE hThread2; + BOOL bDupHandle=FALSE; + DWORD dwThreadId = 0; + + if ((PAL_Initialize(argc,argv)) != 0) + { + return(FAIL); + } + + hSemaphore = CreateSemaphoreW( NULL, + 1, + 1, + NULL); + if (hSemaphore == NULL) + { + Fail("PALSUITE ERROR:%u: Unable to create mutex\n", + GetLastError()); + } + + /*Create Duplicate of the Semaphore above*/ + bDupHandle = DuplicateHandle(GetCurrentProcess(), + hSemaphore, + GetCurrentProcess(), + &hDupSemaphore, + GENERIC_READ|GENERIC_WRITE, + FALSE, + DUPLICATE_SAME_ACCESS); + if (!bDupHandle) + { + Trace("PALSUITE ERROR:%u: Created the duplicate handle to " + "closed event handle hSemaphore=0x%lx\n", + GetLastError(), + hSemaphore); + CloseHandle(hSemaphore); + Fail(""); + } + + /*Create a thread to test the Semaphore*/ + hThread = CreateThread(NULL, + 0, + &ThreadTest1, + hSemaphore, + 0, + &dwThreadId); + if (hThread == NULL) + { + Trace("PALSUITE ERROR:%u: unable to create thread\n", + GetLastError()); + CloseHandle(hSemaphore); + CloseHandle(hDupSemaphore); + Fail(""); + } + + /* wait until thread has taken the mutex */ + while (WR_WAITING == t1_result) + Sleep(1); + + if(WR_TIMED_OUT == t1_result) + { + Trace("PALSUITE ERROR: %u: thread couldn't acquire the semaphore\n", + GetLastError()); + CloseHandle(hSemaphore); + CloseHandle(hDupSemaphore); + CloseHandle(hThread); + Fail(""); + } + + /*Create a second thread to use the Semaphore's duplicate handle*/ + /*This thread should block since the Semaphore is owned by another + thread*/ + hThread2 = CreateThread(NULL, + 0, + &ThreadTest2, + hDupSemaphore, + 0, + &dwThreadId); + + if (hThread2 == NULL) + { + Trace("PALSUITE ERROR:%u: unable to create thread\n", + GetLastError()); + CloseHandle(hSemaphore); + CloseHandle(hDupSemaphore); + CloseHandle(hThread); + Fail(""); + } + + /* wait until thread has tried to take the mutex */ + while (WR_WAITING == t2_result) + Sleep(1); + + if (WR_TIMED_OUT != t2_result ) + { + Trace("PALSUITE ERROR:%u: Able to take mutex %#x while its " + "duplicate %#x is held\n", GetLastError(), hDupSemaphore, + hSemaphore); + CloseHandle(hSemaphore); + CloseHandle(hDupSemaphore); + CloseHandle(hThread); + CloseHandle(hThread2); + Fail(""); + } + + /* reset second thread status */ + t2_result = WR_WAITING; + + /* tell thread 1 to release the mutex */ + t1_result = WR_WAITING; + + /* wait for thread 1 to release the mutex */ + while (WR_WAITING == t1_result) + Sleep(1); + + CloseHandle(hThread2); + + /*Re-Create the second thread to reuse the duplicated Semaphore*/ + /*Since the Semaphore has since been released, the thread should + put WR_GOT_MUTEX into t2_result */ + hThread2 = CreateThread(NULL, + 0, + &ThreadTest2, + hDupSemaphore, + 0, + &dwThreadId); + + if (hThread2 == NULL) + { + Trace("PALSUITE ERROR:%u: unable to create thread\n", + GetLastError()); + CloseHandle(hSemaphore); + CloseHandle(hDupSemaphore); + CloseHandle(hThread); + Fail(""); + } + + /* wait until thread has taken the semaphore */ + while (WR_WAITING == t2_result) + Sleep(1); + + if (WR_GOT_MUTEX != t2_result ) + { + Trace("PALSUITE ERROR:%u: Unable to take semaphore %#x after its" + " duplicate %#x was released\n", GetLastError(), hDupSemaphore, + hSemaphore); + CloseHandle(hSemaphore); + CloseHandle(hDupSemaphore); + CloseHandle(hThread); + CloseHandle(hThread2); + Fail(""); + } + + /*Cleanup.*/ + CloseHandle(hSemaphore); + CloseHandle(hDupSemaphore); + CloseHandle(hThread); + CloseHandle(hThread2); + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test11/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test11/CMakeLists.txt index 68ce7b23fb..f47f9bc350 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test11/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test11/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test11.c + test11.cpp ) add_executable(paltest_duplicatehandle_test11 @@ -20,7 +20,7 @@ target_link_libraries(paltest_duplicatehandle_test11 set(HELPERSOURCES - childprocess.c + childprocess.cpp ) add_executable(paltest_duplicatehandle_test11_child diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test11/childprocess.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test11/childprocess.c deleted file mode 100644 index d5b310e46c..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test11/childprocess.c +++ /dev/null @@ -1,74 +0,0 @@ -// 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: childprocess.c -** -** Purpose: Test to ensure DuplicateHandle works properly. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateMutexW -** WaitForSingleObject -** CloseHandle -** -** -**=========================================================*/ - -#include -#include "myexitcode.h" - - -int __cdecl main( int argc, char **argv ) -{ - HANDLE hMutex; - WCHAR wszMutexName[] = { 'T','E','S','T','1','1','\0' }; - DWORD dwRet; - int i; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* open a mutex to synchronize with the parent process */ - hMutex = CreateMutexW( NULL, FALSE, wszMutexName ); - if( hMutex == NULL ) - { - Fail( "ERROR:%lu:CreateMutex() call failed\r\n", GetLastError() ); - } - - /* acquire the mutex lock */ - dwRet = WaitForSingleObject( hMutex, 10000 ); - if( dwRet != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0", - dwRet ); - if( ! CloseHandle( hMutex ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "test failed\n" ); - } - - - /* simulate some activity */ - for( i=0; i<50000; i++ ) - ; - - /* close our mutex handle */ - if( ! CloseHandle( hMutex ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - - /* terminate the PAL */ - PAL_Terminate(); - - /* return the predefined exit code */ - return TEST_EXIT_CODE; -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test11/childprocess.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test11/childprocess.cpp new file mode 100644 index 0000000000..d5b310e46c --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test11/childprocess.cpp @@ -0,0 +1,74 @@ +// 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: childprocess.c +** +** Purpose: Test to ensure DuplicateHandle works properly. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateMutexW +** WaitForSingleObject +** CloseHandle +** +** +**=========================================================*/ + +#include +#include "myexitcode.h" + + +int __cdecl main( int argc, char **argv ) +{ + HANDLE hMutex; + WCHAR wszMutexName[] = { 'T','E','S','T','1','1','\0' }; + DWORD dwRet; + int i; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* open a mutex to synchronize with the parent process */ + hMutex = CreateMutexW( NULL, FALSE, wszMutexName ); + if( hMutex == NULL ) + { + Fail( "ERROR:%lu:CreateMutex() call failed\r\n", GetLastError() ); + } + + /* acquire the mutex lock */ + dwRet = WaitForSingleObject( hMutex, 10000 ); + if( dwRet != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0", + dwRet ); + if( ! CloseHandle( hMutex ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "test failed\n" ); + } + + + /* simulate some activity */ + for( i=0; i<50000; i++ ) + ; + + /* close our mutex handle */ + if( ! CloseHandle( hMutex ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + /* terminate the PAL */ + PAL_Terminate(); + + /* return the predefined exit code */ + return TEST_EXIT_CODE; +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test11/test11.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test11/test11.c deleted file mode 100644 index b05244c4b8..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test11/test11.c +++ /dev/null @@ -1,364 +0,0 @@ -// 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: test11.c -** -** Purpose: -** -** Test to ensure proper operation of the DuplicateHandle API. -** The test launches a trivial child process, then opens -** a handle to it using OpenProcess. It then duplicates that -** handle and uses it to wait for the child process to terminate, -** and then checks the exit code of the child process in order to -** verify that it was in fact a handle to the correct -** process. The test tries to duplicate the handle again after -** the process has been closed, to verify that failure ensues. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** ZeroMemory -** GetCurrentDirectoryW -** CreateProcessW -** WaitForSingleObject -** CreateMutexW -** ReleaseMutex -** CloseHandle -** GetLastError -** strlen -** strncpy -** -** -**===========================================================================*/ -#include -#include "myexitcode.h" - - -static const char* rgchPathDelim = "\\"; - - -int -mkAbsoluteFilename( LPSTR dirName, - DWORD dwDirLength, - LPCSTR fileName, - DWORD dwFileLength, - LPSTR absPathName ) -{ - DWORD sizeDN, sizeFN, sizeAPN; - - sizeDN = strlen( dirName ); - sizeFN = strlen( fileName ); - sizeAPN = (sizeDN + 1 + sizeFN + 1); - - /* ensure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ - if( sizeAPN > _MAX_PATH ) - { - return ( 0 ); - } - - strncpy( absPathName, dirName, dwDirLength +1 ); - strncpy( absPathName, rgchPathDelim, 2 ); - strncpy( absPathName, fileName, dwFileLength +1 ); - - return (sizeAPN); - -} - - -int __cdecl main( int argc, char **argv ) - -{ - const char* rgchChildFile = "childprocess"; - - STARTUPINFO si; - PROCESS_INFORMATION pi; - - DWORD dwError; - DWORD dwExitCode; - DWORD dwFileLength; - DWORD dwDirLength; - DWORD dwSize; - DWORD dwRet; - - HANDLE hMutex; - HANDLE hChildProcess; - HANDLE hDupChildProcess; - - char rgchDirName[_MAX_DIR]; - char absPathBuf[_MAX_PATH]; - char* rgchAbsPathName; - - BOOL ret = FAIL; - BOOL bChildDone = FALSE; - WCHAR wszMutexName[] = { 'T','E','S','T','1','1','\0' }; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* create a mutex to synchronize with the child process */ - hMutex = CreateMutexW( NULL, TRUE, wszMutexName ); - if( hMutex == NULL ) - { - Fail( "ERROR:%lu:CreateMutex() call failed\r\n", GetLastError() ); - } - - /* zero our process and startup info structures */ - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof( si ); - ZeroMemory( &pi, sizeof(pi) ); - - /* build the absolute path to the child process */ - rgchAbsPathName = &absPathBuf[0]; - dwFileLength = strlen( rgchChildFile ); - - dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName ); - if( dwDirLength == 0 ) - { - dwError = GetLastError(); - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - } - if( CloseHandle( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "GetCurrentDirectory call failed with error code %d\n", - dwError ); - } - - dwSize = mkAbsoluteFilename( rgchDirName, - dwDirLength, - rgchChildFile, - dwFileLength, - rgchAbsPathName ); - if( dwSize == 0 ) - { - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - } - if( CloseHandle( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ", - "not build absolute path name to file\n. Exiting.\n" ); - } - - /* launch the child process */ - if( !CreateProcess( NULL, /* module name to execute */ - rgchAbsPathName, /* command line */ - NULL, /* process handle not */ - /* inheritable */ - NULL, /* thread handle not */ - /*inheritable */ - FALSE, /* handle inheritance */ - CREATE_NEW_CONSOLE, /* dwCreationFlags */ - NULL, /* use parent's environment */ - NULL, /* use parent's starting */ - /* directory */ - &si, /* startup info struct */ - &pi ) /* process info struct */ - ) - { - dwError = GetLastError(); - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - } - if( CloseHandle( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "CreateProcess call failed with error code %d\n", - dwError ); - } - - /* open another handle to the child process */ - hChildProcess = OpenProcess( PROCESS_ALL_ACCESS, /* access */ - FALSE, /* inheritable */ - pi.dwProcessId /* process id */ - ); - if( hChildProcess == NULL ) - { - dwError = GetLastError(); - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - } - Trace( "ERROR:%lu:OpenProcess call failed\n", dwError ); - goto cleanup3; - } - - /* duplicate the child process handle */ - if( ! DuplicateHandle( GetCurrentProcess(), - hChildProcess, - GetCurrentProcess(), - &hDupChildProcess, - GENERIC_READ|GENERIC_WRITE, - FALSE, - DUPLICATE_SAME_ACCESS) ) - { - Trace( "ERROR:%lu:DuplicateHandle() call failed\n", GetLastError() ); - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - } - goto cleanup2; - } - - /* release the mutex so the child can proceed */ - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - goto cleanup1; - } - - /* wait for the child process to complete, using the new handle */ - dwRet = WaitForSingleObject( hDupChildProcess, 10000 ); - if( dwRet != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject call returned %lu, " - "expected WAIT_OBJECT_0", - dwRet ); - goto cleanup1; - } - - /* remember that we waited until the child was finished */ - bChildDone = TRUE; - - /* check the exit code from the process -- this is a bit of an */ - /* extra verification that we opened the correct process handle */ - if( ! GetExitCodeProcess( hDupChildProcess, &dwExitCode ) ) - { - Trace( "ERROR:%lu:GetExitCodeProcess call failed\n", GetLastError() ); - goto cleanup1; - } - - /* verification */ - if( (dwExitCode & 0xFF) != (TEST_EXIT_CODE & 0xFF) ) - { - Trace( "GetExitCodeProcess returned an incorrect exit code %d, " - "expected value is %d\n", - (dwExitCode & 0xFF), - (TEST_EXIT_CODE & 0xFF)); - goto cleanup1; - } - - /* close the duplicate handle */ - if( ! CloseHandle( hDupChildProcess ) ) - { - Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); - goto cleanup2; - } - - /* close the child process handle */ - if( ! CloseHandle ( hChildProcess ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - goto cleanup3; - } - - /* try to call duplicate handle on the closed child process handle */ - if( DuplicateHandle( GetCurrentProcess(), - hChildProcess, - GetCurrentProcess(), - &hDupChildProcess, - GENERIC_READ|GENERIC_WRITE, - FALSE, - DUPLICATE_SAME_ACCESS) ) - { - Trace( "ERROR:%lu:DuplicateHandle call succeeded on " - "a closed process handle, expected ERROR_INVALID_HANDLE\n" ); - if( ! CloseHandle( hDupChildProcess ) ) - { - Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); - } - goto cleanup3; - } - - /* verify that the last error was ERROR_INVALID_HANDLE */ - dwRet = GetLastError(); - if( dwRet != ERROR_INVALID_HANDLE ) - { - Trace( "ERROR:DuplicateHandle returned %lu, " - "expected ERROR_INVALID_HANDLE\n", - dwRet ); - goto cleanup3; - } - - - /* success if we get here */ - ret = PASS; - - /* skip the cleanup stuff that's already done */ - goto cleanup3; - - -cleanup1: - /* close our duplicate handle */ - if( ! CloseHandle( hDupChildProcess ) ) - { - Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); - ret = FAIL; - } - -cleanup2: - /* wait on the child process to complete if necessary */ - if( ! bChildDone ) - { - dwRet = WaitForSingleObject( hChildProcess, 10000 ); - if( dwRet != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject call returned %lu, " - "expected WAIT_OBJECT_0", - dwRet ); - ret = FAIL; - } - } - - /* close our child process handle */ - if( CloseHandle ( hChildProcess ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - ret = FAIL; - } - -cleanup3: - /* close all our other handles */ - if( CloseHandle ( pi.hProcess ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - ret = FAIL; - } - if( CloseHandle ( pi.hThread ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - ret = FAIL; - } - if( CloseHandle( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - ret = FAIL; - } - - if( ret == FAIL ) - { - Fail( "test failed\n" ); - } - - - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test11/test11.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test11/test11.cpp new file mode 100644 index 0000000000..b05244c4b8 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test11/test11.cpp @@ -0,0 +1,364 @@ +// 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: test11.c +** +** Purpose: +** +** Test to ensure proper operation of the DuplicateHandle API. +** The test launches a trivial child process, then opens +** a handle to it using OpenProcess. It then duplicates that +** handle and uses it to wait for the child process to terminate, +** and then checks the exit code of the child process in order to +** verify that it was in fact a handle to the correct +** process. The test tries to duplicate the handle again after +** the process has been closed, to verify that failure ensues. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** ZeroMemory +** GetCurrentDirectoryW +** CreateProcessW +** WaitForSingleObject +** CreateMutexW +** ReleaseMutex +** CloseHandle +** GetLastError +** strlen +** strncpy +** +** +**===========================================================================*/ +#include +#include "myexitcode.h" + + +static const char* rgchPathDelim = "\\"; + + +int +mkAbsoluteFilename( LPSTR dirName, + DWORD dwDirLength, + LPCSTR fileName, + DWORD dwFileLength, + LPSTR absPathName ) +{ + DWORD sizeDN, sizeFN, sizeAPN; + + sizeDN = strlen( dirName ); + sizeFN = strlen( fileName ); + sizeAPN = (sizeDN + 1 + sizeFN + 1); + + /* ensure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ + if( sizeAPN > _MAX_PATH ) + { + return ( 0 ); + } + + strncpy( absPathName, dirName, dwDirLength +1 ); + strncpy( absPathName, rgchPathDelim, 2 ); + strncpy( absPathName, fileName, dwFileLength +1 ); + + return (sizeAPN); + +} + + +int __cdecl main( int argc, char **argv ) + +{ + const char* rgchChildFile = "childprocess"; + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + DWORD dwError; + DWORD dwExitCode; + DWORD dwFileLength; + DWORD dwDirLength; + DWORD dwSize; + DWORD dwRet; + + HANDLE hMutex; + HANDLE hChildProcess; + HANDLE hDupChildProcess; + + char rgchDirName[_MAX_DIR]; + char absPathBuf[_MAX_PATH]; + char* rgchAbsPathName; + + BOOL ret = FAIL; + BOOL bChildDone = FALSE; + WCHAR wszMutexName[] = { 'T','E','S','T','1','1','\0' }; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* create a mutex to synchronize with the child process */ + hMutex = CreateMutexW( NULL, TRUE, wszMutexName ); + if( hMutex == NULL ) + { + Fail( "ERROR:%lu:CreateMutex() call failed\r\n", GetLastError() ); + } + + /* zero our process and startup info structures */ + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof( si ); + ZeroMemory( &pi, sizeof(pi) ); + + /* build the absolute path to the child process */ + rgchAbsPathName = &absPathBuf[0]; + dwFileLength = strlen( rgchChildFile ); + + dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName ); + if( dwDirLength == 0 ) + { + dwError = GetLastError(); + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + } + if( CloseHandle( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "GetCurrentDirectory call failed with error code %d\n", + dwError ); + } + + dwSize = mkAbsoluteFilename( rgchDirName, + dwDirLength, + rgchChildFile, + dwFileLength, + rgchAbsPathName ); + if( dwSize == 0 ) + { + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + } + if( CloseHandle( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ", + "not build absolute path name to file\n. Exiting.\n" ); + } + + /* launch the child process */ + if( !CreateProcess( NULL, /* module name to execute */ + rgchAbsPathName, /* command line */ + NULL, /* process handle not */ + /* inheritable */ + NULL, /* thread handle not */ + /*inheritable */ + FALSE, /* handle inheritance */ + CREATE_NEW_CONSOLE, /* dwCreationFlags */ + NULL, /* use parent's environment */ + NULL, /* use parent's starting */ + /* directory */ + &si, /* startup info struct */ + &pi ) /* process info struct */ + ) + { + dwError = GetLastError(); + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + } + if( CloseHandle( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "CreateProcess call failed with error code %d\n", + dwError ); + } + + /* open another handle to the child process */ + hChildProcess = OpenProcess( PROCESS_ALL_ACCESS, /* access */ + FALSE, /* inheritable */ + pi.dwProcessId /* process id */ + ); + if( hChildProcess == NULL ) + { + dwError = GetLastError(); + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + } + Trace( "ERROR:%lu:OpenProcess call failed\n", dwError ); + goto cleanup3; + } + + /* duplicate the child process handle */ + if( ! DuplicateHandle( GetCurrentProcess(), + hChildProcess, + GetCurrentProcess(), + &hDupChildProcess, + GENERIC_READ|GENERIC_WRITE, + FALSE, + DUPLICATE_SAME_ACCESS) ) + { + Trace( "ERROR:%lu:DuplicateHandle() call failed\n", GetLastError() ); + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + } + goto cleanup2; + } + + /* release the mutex so the child can proceed */ + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + goto cleanup1; + } + + /* wait for the child process to complete, using the new handle */ + dwRet = WaitForSingleObject( hDupChildProcess, 10000 ); + if( dwRet != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject call returned %lu, " + "expected WAIT_OBJECT_0", + dwRet ); + goto cleanup1; + } + + /* remember that we waited until the child was finished */ + bChildDone = TRUE; + + /* check the exit code from the process -- this is a bit of an */ + /* extra verification that we opened the correct process handle */ + if( ! GetExitCodeProcess( hDupChildProcess, &dwExitCode ) ) + { + Trace( "ERROR:%lu:GetExitCodeProcess call failed\n", GetLastError() ); + goto cleanup1; + } + + /* verification */ + if( (dwExitCode & 0xFF) != (TEST_EXIT_CODE & 0xFF) ) + { + Trace( "GetExitCodeProcess returned an incorrect exit code %d, " + "expected value is %d\n", + (dwExitCode & 0xFF), + (TEST_EXIT_CODE & 0xFF)); + goto cleanup1; + } + + /* close the duplicate handle */ + if( ! CloseHandle( hDupChildProcess ) ) + { + Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); + goto cleanup2; + } + + /* close the child process handle */ + if( ! CloseHandle ( hChildProcess ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + goto cleanup3; + } + + /* try to call duplicate handle on the closed child process handle */ + if( DuplicateHandle( GetCurrentProcess(), + hChildProcess, + GetCurrentProcess(), + &hDupChildProcess, + GENERIC_READ|GENERIC_WRITE, + FALSE, + DUPLICATE_SAME_ACCESS) ) + { + Trace( "ERROR:%lu:DuplicateHandle call succeeded on " + "a closed process handle, expected ERROR_INVALID_HANDLE\n" ); + if( ! CloseHandle( hDupChildProcess ) ) + { + Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); + } + goto cleanup3; + } + + /* verify that the last error was ERROR_INVALID_HANDLE */ + dwRet = GetLastError(); + if( dwRet != ERROR_INVALID_HANDLE ) + { + Trace( "ERROR:DuplicateHandle returned %lu, " + "expected ERROR_INVALID_HANDLE\n", + dwRet ); + goto cleanup3; + } + + + /* success if we get here */ + ret = PASS; + + /* skip the cleanup stuff that's already done */ + goto cleanup3; + + +cleanup1: + /* close our duplicate handle */ + if( ! CloseHandle( hDupChildProcess ) ) + { + Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); + ret = FAIL; + } + +cleanup2: + /* wait on the child process to complete if necessary */ + if( ! bChildDone ) + { + dwRet = WaitForSingleObject( hChildProcess, 10000 ); + if( dwRet != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject call returned %lu, " + "expected WAIT_OBJECT_0", + dwRet ); + ret = FAIL; + } + } + + /* close our child process handle */ + if( CloseHandle ( hChildProcess ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + ret = FAIL; + } + +cleanup3: + /* close all our other handles */ + if( CloseHandle ( pi.hProcess ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + ret = FAIL; + } + if( CloseHandle ( pi.hThread ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + ret = FAIL; + } + if( CloseHandle( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + ret = FAIL; + } + + if( ret == FAIL ) + { + Fail( "test failed\n" ); + } + + + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test12/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test12/CMakeLists.txt index 961a9c64e6..6a50a13265 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test12/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test12/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test12.c + test12.cpp ) add_executable(paltest_duplicatehandle_test12 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test12/test12.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test12/test12.c deleted file mode 100644 index 519194bc3a..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test12/test12.c +++ /dev/null @@ -1,129 +0,0 @@ -// 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: test12.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function. -** This test will create handle to file (to write) and close it, -** then call duplicate handle to read what was written. -** -** -**===================================================================*/ -#include - -int __cdecl main(int argc, char **argv) -{ - HANDLE hFile; - HANDLE hDupFile; - char buf[256]; - char teststr[] = "A uNiQuE tEsT sTrInG"; - char lpFileName[] = "testfile.txt"; - DWORD dwBytesWritten; - DWORD dwBytesRead; - BOOL bRetVal; - - /*Initalize the PAL*/ - if ((PAL_Initialize(argc,argv)) != 0) - { - return (FAIL); - } - - /*Create a file handle with CreateFile*/ - hFile = CreateFile(lpFileName, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_WRITE|FILE_SHARE_READ, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - Fail("ERROR: %u :unable to create file \"%s\".\n", - GetLastError(), - lpFileName); - } - - /*Write test string to the file.*/ - bRetVal = WriteFile(hFile, // handle to file - teststr, // data buffer - strlen(teststr), // number of bytes to write - &dwBytesWritten, // number of bytes written - NULL); // overlapped buffer - - if (bRetVal == FALSE) - { - Trace("ERROR: %u : unable to write to file handle " - "hFile=0x%lx\n", - GetLastError(), - hFile); - CloseHandle(hFile); - Fail(""); - } - - /*Create a duplicate handle with DuplicateHandle.*/ - if (!(DuplicateHandle( - GetCurrentProcess(), - hFile, - GetCurrentProcess(), - &hDupFile, - GENERIC_READ|GENERIC_WRITE, - FALSE, - DUPLICATE_SAME_ACCESS))) - { - Trace("ERROR: %u : Fail to create the duplicate handle" - " to hFile=0x%lx\n", - GetLastError(), - hFile); - CloseHandle(hFile); - Fail(""); - } - - if( !CloseHandle(hFile) ) - { - Fail("Duplicate Handle:Unable to close original file: Error[%u]\n", GetLastError()); - } - - memset(buf, 0, 256); - - /*Read from the Duplicated handle.*/ - bRetVal = ReadFile(hDupFile, - buf, - 256, - &dwBytesRead, - NULL); - if (bRetVal == FALSE) - { - Trace("ERROR: %u :unable to read from file handle " - "hFile=0x%lx\n", - GetLastError(), - hDupFile); - CloseHandle(hDupFile); - Fail(""); - } - - /*Compare what was written to what was read.*/ - if (memcmp(teststr, buf, dwBytesRead) != 0) - { - Trace("ERROR: expected %s, got %s\n", teststr, buf); - CloseHandle(hDupFile); - Fail(""); - } - - /*Close the handles*/ - CloseHandle(hDupFile); - - bRetVal = DeleteFileA(lpFileName); - if (bRetVal != TRUE) - { - Trace("Error:%u: DuplicateHandle, DeleteFileA: Couldn't delete DeleteFileA's" - " %s\n", GetLastError(), lpFileName); - Fail(""); - } - - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test12/test12.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test12/test12.cpp new file mode 100644 index 0000000000..519194bc3a --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test12/test12.cpp @@ -0,0 +1,129 @@ +// 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: test12.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function. +** This test will create handle to file (to write) and close it, +** then call duplicate handle to read what was written. +** +** +**===================================================================*/ +#include + +int __cdecl main(int argc, char **argv) +{ + HANDLE hFile; + HANDLE hDupFile; + char buf[256]; + char teststr[] = "A uNiQuE tEsT sTrInG"; + char lpFileName[] = "testfile.txt"; + DWORD dwBytesWritten; + DWORD dwBytesRead; + BOOL bRetVal; + + /*Initalize the PAL*/ + if ((PAL_Initialize(argc,argv)) != 0) + { + return (FAIL); + } + + /*Create a file handle with CreateFile*/ + hFile = CreateFile(lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_WRITE|FILE_SHARE_READ, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /*Write test string to the file.*/ + bRetVal = WriteFile(hFile, // handle to file + teststr, // data buffer + strlen(teststr), // number of bytes to write + &dwBytesWritten, // number of bytes written + NULL); // overlapped buffer + + if (bRetVal == FALSE) + { + Trace("ERROR: %u : unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + CloseHandle(hFile); + Fail(""); + } + + /*Create a duplicate handle with DuplicateHandle.*/ + if (!(DuplicateHandle( + GetCurrentProcess(), + hFile, + GetCurrentProcess(), + &hDupFile, + GENERIC_READ|GENERIC_WRITE, + FALSE, + DUPLICATE_SAME_ACCESS))) + { + Trace("ERROR: %u : Fail to create the duplicate handle" + " to hFile=0x%lx\n", + GetLastError(), + hFile); + CloseHandle(hFile); + Fail(""); + } + + if( !CloseHandle(hFile) ) + { + Fail("Duplicate Handle:Unable to close original file: Error[%u]\n", GetLastError()); + } + + memset(buf, 0, 256); + + /*Read from the Duplicated handle.*/ + bRetVal = ReadFile(hDupFile, + buf, + 256, + &dwBytesRead, + NULL); + if (bRetVal == FALSE) + { + Trace("ERROR: %u :unable to read from file handle " + "hFile=0x%lx\n", + GetLastError(), + hDupFile); + CloseHandle(hDupFile); + Fail(""); + } + + /*Compare what was written to what was read.*/ + if (memcmp(teststr, buf, dwBytesRead) != 0) + { + Trace("ERROR: expected %s, got %s\n", teststr, buf); + CloseHandle(hDupFile); + Fail(""); + } + + /*Close the handles*/ + CloseHandle(hDupFile); + + bRetVal = DeleteFileA(lpFileName); + if (bRetVal != TRUE) + { + Trace("Error:%u: DuplicateHandle, DeleteFileA: Couldn't delete DeleteFileA's" + " %s\n", GetLastError(), lpFileName); + Fail(""); + } + + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test2/CMakeLists.txt index 06529a6204..9faa58a271 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_duplicatehandle_test2 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test2/test2.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test2/test2.c deleted file mode 100644 index d1411e62d9..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test2/test2.c +++ /dev/null @@ -1,96 +0,0 @@ -// 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: test2.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function. -** This will test duplication of an CreateEvent handle. Test an -** event in a signaled state to wait, and then set the duplicate -** to nonsignaled state and perform the wait again. The wait on -** the event should fail. Test the duplication of closed and NULL -** events, these should fail. -** -** -**===================================================================*/ -#include - -int __cdecl main(int argc, char **argv) -{ - HANDLE hEvent; - HANDLE hDupEvent; - - /*Initalize the PAL.*/ - if ((PAL_Initialize(argc,argv)) != 0) - { - return (FAIL); - } - - /*Create an Event, and set it in the signaled state.*/ - hEvent = CreateEvent(0, TRUE, TRUE, 0); - if (hEvent == NULL) - { - Fail("ERROR: %u :unable to create event\n", - GetLastError()); - } - - /*Create a duplicate Event handle.*/ - if (!(DuplicateHandle(GetCurrentProcess(), - hEvent,GetCurrentProcess(), - &hDupEvent, - GENERIC_READ|GENERIC_WRITE, - FALSE, DUPLICATE_SAME_ACCESS))) - { - Trace("ERROR: %u :Fail to create the duplicate handle" - " to hEvent=0x%lx\n", - GetLastError(), - hEvent); - CloseHandle(hEvent); - Fail(""); - } - - /*Perform wait on Event that is in signaled state.*/ - if ((WaitForSingleObject(hEvent, 1000)) != WAIT_OBJECT_0) - { - Trace("ERROR: %u :WaitForSignalObject on Event=0x%lx set to " - " signaled state failed", - GetLastError(), - hEvent); - CloseHandle(hEvent); - CloseHandle(hDupEvent); - Fail(""); - } - - /*Set the Duplicate Event handle to nonsignaled state.*/ - if ((ResetEvent(hDupEvent)) == 0) - { - Trace("ERROR: %u :unable to reset dup event\n", - GetLastError()); - CloseHandle(hEvent); - CloseHandle(hDupEvent); - Fail(""); - } - - /*Perform wait on Event that is in signaled state.*/ - if ((WaitForSingleObject(hEvent, 1000)) == WAIT_OBJECT_0) - { - Trace("ERROR: %u: WaitForSignalObject succeeded on Event=0x%lx " - " when Duplicate Event=0x%lx set to nonsignaled state" - " succeeded\n", - GetLastError(), - hEvent, - hDupEvent); - CloseHandle(hEvent); - CloseHandle(hDupEvent); - Fail(""); - } - - /*Close handles to events.*/ - CloseHandle(hEvent); - CloseHandle(hDupEvent); - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test2/test2.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test2/test2.cpp new file mode 100644 index 0000000000..d1411e62d9 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test2/test2.cpp @@ -0,0 +1,96 @@ +// 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: test2.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function. +** This will test duplication of an CreateEvent handle. Test an +** event in a signaled state to wait, and then set the duplicate +** to nonsignaled state and perform the wait again. The wait on +** the event should fail. Test the duplication of closed and NULL +** events, these should fail. +** +** +**===================================================================*/ +#include + +int __cdecl main(int argc, char **argv) +{ + HANDLE hEvent; + HANDLE hDupEvent; + + /*Initalize the PAL.*/ + if ((PAL_Initialize(argc,argv)) != 0) + { + return (FAIL); + } + + /*Create an Event, and set it in the signaled state.*/ + hEvent = CreateEvent(0, TRUE, TRUE, 0); + if (hEvent == NULL) + { + Fail("ERROR: %u :unable to create event\n", + GetLastError()); + } + + /*Create a duplicate Event handle.*/ + if (!(DuplicateHandle(GetCurrentProcess(), + hEvent,GetCurrentProcess(), + &hDupEvent, + GENERIC_READ|GENERIC_WRITE, + FALSE, DUPLICATE_SAME_ACCESS))) + { + Trace("ERROR: %u :Fail to create the duplicate handle" + " to hEvent=0x%lx\n", + GetLastError(), + hEvent); + CloseHandle(hEvent); + Fail(""); + } + + /*Perform wait on Event that is in signaled state.*/ + if ((WaitForSingleObject(hEvent, 1000)) != WAIT_OBJECT_0) + { + Trace("ERROR: %u :WaitForSignalObject on Event=0x%lx set to " + " signaled state failed", + GetLastError(), + hEvent); + CloseHandle(hEvent); + CloseHandle(hDupEvent); + Fail(""); + } + + /*Set the Duplicate Event handle to nonsignaled state.*/ + if ((ResetEvent(hDupEvent)) == 0) + { + Trace("ERROR: %u :unable to reset dup event\n", + GetLastError()); + CloseHandle(hEvent); + CloseHandle(hDupEvent); + Fail(""); + } + + /*Perform wait on Event that is in signaled state.*/ + if ((WaitForSingleObject(hEvent, 1000)) == WAIT_OBJECT_0) + { + Trace("ERROR: %u: WaitForSignalObject succeeded on Event=0x%lx " + " when Duplicate Event=0x%lx set to nonsignaled state" + " succeeded\n", + GetLastError(), + hEvent, + hDupEvent); + CloseHandle(hEvent); + CloseHandle(hDupEvent); + Fail(""); + } + + /*Close handles to events.*/ + CloseHandle(hEvent); + CloseHandle(hDupEvent); + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test3/CMakeLists.txt index 7f961c2213..b161b928d3 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_duplicatehandle_test3 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test3/test3.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test3/test3.c deleted file mode 100644 index fc91b5ec22..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test3/test3.c +++ /dev/null @@ -1,123 +0,0 @@ -// 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: test3.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function. -** This will test duplication of an OpenEvent handle. Test an -** event in a signaled state to wait, and then set the duplicate -** to nonsignaled state and perform the wait again. The wait on -** the event should fail. Test the duplication of closed and NULL -** events, these should fail. -** -** -**===================================================================*/ -#include - -int __cdecl main(int argc, char **argv) -{ - HANDLE hCreateEvent; - HANDLE hOpenEvent; - HANDLE hDupEvent; - WCHAR lpEventName[]={'E','v','e','n','t','\0'}; - - /*Initialize the PAL.*/ - if ((PAL_Initialize(argc,argv)) != 0) - { - return (FAIL); - } - - /*Create an Event, and set it in the signaled state.*/ - hCreateEvent = CreateEventW(0, - TRUE, - TRUE, - lpEventName); - if (hCreateEvent == NULL) - { - Fail("ERROR: %u :unable to create event %s\n", - GetLastError(), - lpEventName); - } - - /*Open another handle to hCreateHandle with OpenEvent*/ - hOpenEvent = OpenEventW(EVENT_ALL_ACCESS, - TRUE, - lpEventName); - if (hOpenEvent == NULL) - { - Trace("ERROR: %u :unable to create handle with OpenEvent to %s\n", - GetLastError(), - lpEventName); - CloseHandle(hCreateEvent); - Fail(""); - } - - /*Create a duplicate Event handle*/ - if (!(DuplicateHandle(GetCurrentProcess(), - hOpenEvent, - GetCurrentProcess(), - &hDupEvent, - GENERIC_READ|GENERIC_WRITE, - FALSE, - DUPLICATE_SAME_ACCESS))) - { - Trace("ERROR: %u :Fail to create the duplicate handle" - " to hCreateEvent=0x%lx\n", - GetLastError(), - hCreateEvent); - CloseHandle(hCreateEvent); - CloseHandle(hOpenEvent); - Fail(""); - } - - /*Perform wait on Event that is in signaled state*/ - if ((WaitForSingleObject(hOpenEvent, 1000)) != WAIT_OBJECT_0) - { - Trace("ERROR: %u :WaitForSignalObject on hOpenEvent=0x%lx set to " - " signaled state failed\n", - GetLastError(), - hOpenEvent); - CloseHandle(hCreateEvent); - CloseHandle(hOpenEvent); - CloseHandle(hDupEvent); - Fail(""); - } - - /*Set the Duplicate Event handle to nonsignaled state*/ - if ((ResetEvent(hDupEvent)) == 0) - { - Trace("ERROR: %u: unable to reset hDupEvent=0x%lx\n", - GetLastError(), - hDupEvent); - CloseHandle(hCreateEvent); - CloseHandle(hOpenEvent); - CloseHandle(hDupEvent); - Fail(""); - } - - /*Perform wait on Event that is in signaled state*/ - if ((WaitForSingleObject(hOpenEvent, 1000)) == WAIT_OBJECT_0) - { - Trace("ERROR: %u :WaitForSignalObject succeeded on hOpenEvent=0x%lx " - " when Duplicate hDupEvent=0x%lx set to nonsignaled state" - " succeeded\n", - GetLastError(), - hOpenEvent, - hDupEvent); - CloseHandle(hCreateEvent); - CloseHandle(hOpenEvent); - CloseHandle(hDupEvent); - Fail(""); - } - - /*Close handles the events*/ - CloseHandle(hCreateEvent); - CloseHandle(hOpenEvent); - CloseHandle(hDupEvent); - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test3/test3.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test3/test3.cpp new file mode 100644 index 0000000000..fc91b5ec22 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test3/test3.cpp @@ -0,0 +1,123 @@ +// 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: test3.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function. +** This will test duplication of an OpenEvent handle. Test an +** event in a signaled state to wait, and then set the duplicate +** to nonsignaled state and perform the wait again. The wait on +** the event should fail. Test the duplication of closed and NULL +** events, these should fail. +** +** +**===================================================================*/ +#include + +int __cdecl main(int argc, char **argv) +{ + HANDLE hCreateEvent; + HANDLE hOpenEvent; + HANDLE hDupEvent; + WCHAR lpEventName[]={'E','v','e','n','t','\0'}; + + /*Initialize the PAL.*/ + if ((PAL_Initialize(argc,argv)) != 0) + { + return (FAIL); + } + + /*Create an Event, and set it in the signaled state.*/ + hCreateEvent = CreateEventW(0, + TRUE, + TRUE, + lpEventName); + if (hCreateEvent == NULL) + { + Fail("ERROR: %u :unable to create event %s\n", + GetLastError(), + lpEventName); + } + + /*Open another handle to hCreateHandle with OpenEvent*/ + hOpenEvent = OpenEventW(EVENT_ALL_ACCESS, + TRUE, + lpEventName); + if (hOpenEvent == NULL) + { + Trace("ERROR: %u :unable to create handle with OpenEvent to %s\n", + GetLastError(), + lpEventName); + CloseHandle(hCreateEvent); + Fail(""); + } + + /*Create a duplicate Event handle*/ + if (!(DuplicateHandle(GetCurrentProcess(), + hOpenEvent, + GetCurrentProcess(), + &hDupEvent, + GENERIC_READ|GENERIC_WRITE, + FALSE, + DUPLICATE_SAME_ACCESS))) + { + Trace("ERROR: %u :Fail to create the duplicate handle" + " to hCreateEvent=0x%lx\n", + GetLastError(), + hCreateEvent); + CloseHandle(hCreateEvent); + CloseHandle(hOpenEvent); + Fail(""); + } + + /*Perform wait on Event that is in signaled state*/ + if ((WaitForSingleObject(hOpenEvent, 1000)) != WAIT_OBJECT_0) + { + Trace("ERROR: %u :WaitForSignalObject on hOpenEvent=0x%lx set to " + " signaled state failed\n", + GetLastError(), + hOpenEvent); + CloseHandle(hCreateEvent); + CloseHandle(hOpenEvent); + CloseHandle(hDupEvent); + Fail(""); + } + + /*Set the Duplicate Event handle to nonsignaled state*/ + if ((ResetEvent(hDupEvent)) == 0) + { + Trace("ERROR: %u: unable to reset hDupEvent=0x%lx\n", + GetLastError(), + hDupEvent); + CloseHandle(hCreateEvent); + CloseHandle(hOpenEvent); + CloseHandle(hDupEvent); + Fail(""); + } + + /*Perform wait on Event that is in signaled state*/ + if ((WaitForSingleObject(hOpenEvent, 1000)) == WAIT_OBJECT_0) + { + Trace("ERROR: %u :WaitForSignalObject succeeded on hOpenEvent=0x%lx " + " when Duplicate hDupEvent=0x%lx set to nonsignaled state" + " succeeded\n", + GetLastError(), + hOpenEvent, + hDupEvent); + CloseHandle(hCreateEvent); + CloseHandle(hOpenEvent); + CloseHandle(hDupEvent); + Fail(""); + } + + /*Close handles the events*/ + CloseHandle(hCreateEvent); + CloseHandle(hOpenEvent); + CloseHandle(hDupEvent); + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test4/CMakeLists.txt index c3040d09ec..901151f4eb 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_duplicatehandle_test4 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test4/test4.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test4/test4.c deleted file mode 100644 index 14a72db461..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test4/test4.c +++ /dev/null @@ -1,239 +0,0 @@ -// 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: test4.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function. -** This test duplication of a Mutex handle. The test will comprise -** of creating a Mutex and its duplicate and create a thread that -** will get ownership. Another thread will be create that will -** attempt to get ownership of the duplicate Mutex, this will -** fail, since the Mutex is owned by another thread. The Mutex -** will be released and then the thread will attempt to get -** ownership of the duplicate Mutex, this will succeed. -** -** -**===================================================================*/ -#include - -enum wait_results -{ - WR_WAITING, - WR_GOT_MUTEX, - WR_TIMED_OUT, - WR_RELEASED -}; - - -volatile int t1_result=WR_WAITING; -volatile int t2_result=WR_WAITING; - - -DWORD PALAPI ThreadTest1(LPVOID lpParam) -{ - DWORD dwWait; - - dwWait = WaitForSingleObject((HANDLE)lpParam, 0); - if (dwWait == WAIT_OBJECT_0) - { - /* tell the main thread we got the mutex */ - t1_result=WR_GOT_MUTEX; - - /* wait for main thread to tell us to release the mutex */ - while(WR_GOT_MUTEX == t1_result) - Sleep(1); - ReleaseMutex((HANDLE)lpParam); - - /* tell the main thread we released the mutex */ - t1_result = WR_RELEASED; - } - else - { - t1_result = WR_TIMED_OUT; - } - return 0; -} - -DWORD PALAPI ThreadTest2(LPVOID lpParam) -{ - DWORD dwWait; - - dwWait = WaitForSingleObject((HANDLE)lpParam, 0 ); - if (dwWait == WAIT_OBJECT_0) - { - ReleaseMutex((HANDLE)lpParam); - t2_result = WR_GOT_MUTEX; - } - else - { - t2_result = WR_TIMED_OUT; - } - - return 0; -} - - -int __cdecl main(int argc, char **argv) -{ - - HANDLE hDupMutex; - HANDLE hMutex; - HANDLE hThread; - HANDLE hThread2; - BOOL bDupHandle=FALSE; - DWORD dwThreadId = 0; - - if ((PAL_Initialize(argc,argv)) != 0) - { - return(FAIL); - } - - /*Create Mutex without ownership*/ - hMutex = CreateMutexW(NULL, // no security attributes - FALSE, // initially not owned - NULL); // name of mutex - if (hMutex == NULL) - { - Fail("ERROR:%u: Unable to create mutex\n", - GetLastError()); - } - - /*Create Duplicate of the Mutex above*/ - bDupHandle = DuplicateHandle(GetCurrentProcess(), - hMutex, - GetCurrentProcess(), - &hDupMutex, - GENERIC_READ|GENERIC_WRITE, - FALSE, - DUPLICATE_SAME_ACCESS); - if (!bDupHandle) - { - Trace("ERROR:%u: Created the duplicate handle to " - "closed event handle hMutex=0x%lx\n", - GetLastError(), - hMutex); - CloseHandle(hMutex); - Fail(""); - } - - /*Create a thread to test the Mutex*/ - hThread = CreateThread(NULL, - 0, - &ThreadTest1, - hMutex, - 0, - &dwThreadId); - if (hThread == NULL) - { - Trace("ERROR:%u: unable to create thread\n", - GetLastError()); - CloseHandle(hMutex); - CloseHandle(hDupMutex); - Fail(""); - } - - /* wait until thread has taken the mutex */ - while (WR_WAITING == t1_result) - Sleep(1); - - if(WR_TIMED_OUT == t1_result) - { - Trace("ERROR: %u: thread 1 couldn't acquire the mutex\n"); - CloseHandle(hMutex); - CloseHandle(hDupMutex); - CloseHandle(hThread); - Fail(""); - } - - /*Create a second thread to use the duplicate Mutex*/ - /*This should fail since the Mutex is owned hThread*/ - hThread2 = CreateThread(NULL, - 0, - &ThreadTest2, - hDupMutex, - 0, - &dwThreadId); - - if (hThread2 == NULL) - { - Trace("ERROR:%u: unable to create thread\n", - GetLastError()); - CloseHandle(hMutex); - CloseHandle(hDupMutex); - CloseHandle(hThread); - Fail(""); - } - - /* wait until thread has tried to take the mutex */ - while (WR_WAITING == t2_result) - Sleep(1); - - if (WR_TIMED_OUT != t2_result ) - { - Trace("ERROR:%u: Able to take mutex %#x while its duplicate %#x is " - "held\n", hDupMutex, hMutex); - CloseHandle(hMutex); - CloseHandle(hDupMutex); - CloseHandle(hThread); - CloseHandle(hThread2); - Fail(""); - } - - /* reset second thread status */ - t2_result = WR_WAITING; - - /* tell thread 1 to release the mutex */ - t1_result = WR_WAITING; - - /* wait for thread 1 to release the mutex */ - while (WR_WAITING == t1_result) - Sleep(1); - - CloseHandle(hThread2); - - /*Re-Create the second thread to reuse the duplicated Mutex*/ - /*This test should pass, the Mutex has since been released*/ - hThread2 = CreateThread(NULL, - 0, - &ThreadTest2, - hDupMutex, - 0, - &dwThreadId); - - if (hThread2 == NULL) - { - Trace("ERROR:%u: unable to create thread\n", - GetLastError()); - CloseHandle(hMutex); - CloseHandle(hDupMutex); - CloseHandle(hThread); - Fail(""); - } - - /* wait until thread has taken the mutex */ - while (WR_WAITING == t2_result) - Sleep(1); - - if (WR_GOT_MUTEX != t2_result ) - { - Trace("ERROR:%u: Unable to take mutex %#x after its duplicate %#x was " - "released\n", hDupMutex, hMutex); - CloseHandle(hMutex); - CloseHandle(hDupMutex); - CloseHandle(hThread); - CloseHandle(hThread2); - Fail(""); - } - - /*Cleanup.*/ - CloseHandle(hMutex); - CloseHandle(hDupMutex); - CloseHandle(hThread); - CloseHandle(hThread2); - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test4/test4.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test4/test4.cpp new file mode 100644 index 0000000000..14a72db461 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test4/test4.cpp @@ -0,0 +1,239 @@ +// 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: test4.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function. +** This test duplication of a Mutex handle. The test will comprise +** of creating a Mutex and its duplicate and create a thread that +** will get ownership. Another thread will be create that will +** attempt to get ownership of the duplicate Mutex, this will +** fail, since the Mutex is owned by another thread. The Mutex +** will be released and then the thread will attempt to get +** ownership of the duplicate Mutex, this will succeed. +** +** +**===================================================================*/ +#include + +enum wait_results +{ + WR_WAITING, + WR_GOT_MUTEX, + WR_TIMED_OUT, + WR_RELEASED +}; + + +volatile int t1_result=WR_WAITING; +volatile int t2_result=WR_WAITING; + + +DWORD PALAPI ThreadTest1(LPVOID lpParam) +{ + DWORD dwWait; + + dwWait = WaitForSingleObject((HANDLE)lpParam, 0); + if (dwWait == WAIT_OBJECT_0) + { + /* tell the main thread we got the mutex */ + t1_result=WR_GOT_MUTEX; + + /* wait for main thread to tell us to release the mutex */ + while(WR_GOT_MUTEX == t1_result) + Sleep(1); + ReleaseMutex((HANDLE)lpParam); + + /* tell the main thread we released the mutex */ + t1_result = WR_RELEASED; + } + else + { + t1_result = WR_TIMED_OUT; + } + return 0; +} + +DWORD PALAPI ThreadTest2(LPVOID lpParam) +{ + DWORD dwWait; + + dwWait = WaitForSingleObject((HANDLE)lpParam, 0 ); + if (dwWait == WAIT_OBJECT_0) + { + ReleaseMutex((HANDLE)lpParam); + t2_result = WR_GOT_MUTEX; + } + else + { + t2_result = WR_TIMED_OUT; + } + + return 0; +} + + +int __cdecl main(int argc, char **argv) +{ + + HANDLE hDupMutex; + HANDLE hMutex; + HANDLE hThread; + HANDLE hThread2; + BOOL bDupHandle=FALSE; + DWORD dwThreadId = 0; + + if ((PAL_Initialize(argc,argv)) != 0) + { + return(FAIL); + } + + /*Create Mutex without ownership*/ + hMutex = CreateMutexW(NULL, // no security attributes + FALSE, // initially not owned + NULL); // name of mutex + if (hMutex == NULL) + { + Fail("ERROR:%u: Unable to create mutex\n", + GetLastError()); + } + + /*Create Duplicate of the Mutex above*/ + bDupHandle = DuplicateHandle(GetCurrentProcess(), + hMutex, + GetCurrentProcess(), + &hDupMutex, + GENERIC_READ|GENERIC_WRITE, + FALSE, + DUPLICATE_SAME_ACCESS); + if (!bDupHandle) + { + Trace("ERROR:%u: Created the duplicate handle to " + "closed event handle hMutex=0x%lx\n", + GetLastError(), + hMutex); + CloseHandle(hMutex); + Fail(""); + } + + /*Create a thread to test the Mutex*/ + hThread = CreateThread(NULL, + 0, + &ThreadTest1, + hMutex, + 0, + &dwThreadId); + if (hThread == NULL) + { + Trace("ERROR:%u: unable to create thread\n", + GetLastError()); + CloseHandle(hMutex); + CloseHandle(hDupMutex); + Fail(""); + } + + /* wait until thread has taken the mutex */ + while (WR_WAITING == t1_result) + Sleep(1); + + if(WR_TIMED_OUT == t1_result) + { + Trace("ERROR: %u: thread 1 couldn't acquire the mutex\n"); + CloseHandle(hMutex); + CloseHandle(hDupMutex); + CloseHandle(hThread); + Fail(""); + } + + /*Create a second thread to use the duplicate Mutex*/ + /*This should fail since the Mutex is owned hThread*/ + hThread2 = CreateThread(NULL, + 0, + &ThreadTest2, + hDupMutex, + 0, + &dwThreadId); + + if (hThread2 == NULL) + { + Trace("ERROR:%u: unable to create thread\n", + GetLastError()); + CloseHandle(hMutex); + CloseHandle(hDupMutex); + CloseHandle(hThread); + Fail(""); + } + + /* wait until thread has tried to take the mutex */ + while (WR_WAITING == t2_result) + Sleep(1); + + if (WR_TIMED_OUT != t2_result ) + { + Trace("ERROR:%u: Able to take mutex %#x while its duplicate %#x is " + "held\n", hDupMutex, hMutex); + CloseHandle(hMutex); + CloseHandle(hDupMutex); + CloseHandle(hThread); + CloseHandle(hThread2); + Fail(""); + } + + /* reset second thread status */ + t2_result = WR_WAITING; + + /* tell thread 1 to release the mutex */ + t1_result = WR_WAITING; + + /* wait for thread 1 to release the mutex */ + while (WR_WAITING == t1_result) + Sleep(1); + + CloseHandle(hThread2); + + /*Re-Create the second thread to reuse the duplicated Mutex*/ + /*This test should pass, the Mutex has since been released*/ + hThread2 = CreateThread(NULL, + 0, + &ThreadTest2, + hDupMutex, + 0, + &dwThreadId); + + if (hThread2 == NULL) + { + Trace("ERROR:%u: unable to create thread\n", + GetLastError()); + CloseHandle(hMutex); + CloseHandle(hDupMutex); + CloseHandle(hThread); + Fail(""); + } + + /* wait until thread has taken the mutex */ + while (WR_WAITING == t2_result) + Sleep(1); + + if (WR_GOT_MUTEX != t2_result ) + { + Trace("ERROR:%u: Unable to take mutex %#x after its duplicate %#x was " + "released\n", hDupMutex, hMutex); + CloseHandle(hMutex); + CloseHandle(hDupMutex); + CloseHandle(hThread); + CloseHandle(hThread2); + Fail(""); + } + + /*Cleanup.*/ + CloseHandle(hMutex); + CloseHandle(hDupMutex); + CloseHandle(hThread); + CloseHandle(hThread2); + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test5/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test5/CMakeLists.txt index bc468a4a75..94cd07f96f 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_duplicatehandle_test5 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test5/test5.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test5/test5.c deleted file mode 100644 index a588928f00..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test5/test5.c +++ /dev/null @@ -1,145 +0,0 @@ -// 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: test5.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function, -** with CreatePipe. This test will create a pipe and write to it, -** the duplicate the read handle and read what was written. -** -** Depends: WriteFile -** ReadFile -** memcmp -** CloseHandle -** -** -**===================================================================*/ - -#include - -const char* cTestString = "one fish, two fish, red fish, blue fish."; - -int __cdecl main(int argc, char **argv) -{ - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - HANDLE hDupPipe = NULL; - BOOL bRetVal = FALSE; - DWORD dwBytesWritten; - DWORD dwBytesRead; - char buffer[256]; - - SECURITY_ATTRIBUTES lpPipeAttributes; - - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /*Create a Pipe*/ - bRetVal = CreatePipe(&hReadPipe, /* read handle*/ - &hWritePipe, /* write handle */ - &lpPipeAttributes,/* security attributes*/ - 0); /* pipe size*/ - if (bRetVal == FALSE) - { - Fail("ERROR:%u:Unable to create pipe\n", GetLastError()); - } - - /*Write to the write pipe handle*/ - bRetVal = WriteFile(hWritePipe, /* handle to write pipe*/ - cTestString, /* buffer to write*/ - strlen(cTestString),/* number of bytes to write*/ - &dwBytesWritten, /* number of bytes written*/ - NULL); /* overlapped buffer*/ - if (bRetVal == FALSE) - { - Trace("ERROR:%u:unable to write to write pipe handle " - "hWritePipe=0x%lx\n", GetLastError(), hWritePipe); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - Fail(""); - } - - /*Duplicate the pipe handle*/ - if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ - hReadPipe, /* handle to duplicate*/ - GetCurrentProcess(), /* target process handle*/ - &hDupPipe, /* duplicate handle*/ - GENERIC_READ|GENERIC_WRITE,/* requested access*/ - FALSE, /* handle inheritance*/ - DUPLICATE_SAME_ACCESS))) /* optional actions*/ - { - Trace("ERROR:%u:Fail to create the duplicate handle" - " to hReadPipe=0x%lx", - GetLastError(), - hReadPipe); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - Fail(""); - } - - /*Read from the duplicated handle, 256 bytes, more bytes - than actually written. This will allow us to use the - value that ReadFile returns for comparision.*/ - bRetVal = ReadFile(hDupPipe, /* handle to read pipe*/ - buffer, /* buffer to write to*/ - 256, /* number of bytes to read*/ - &dwBytesRead, /* number of bytes read*/ - NULL); /* overlapped buffer*/ - if (bRetVal == FALSE) - { - Trace("ERROR:%u:unable read from the duplicated pipe " - "hDupPipe=0x%lx\n", - GetLastError(), - hDupPipe); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - CloseHandle(hDupPipe); - Fail(""); - } - - /*Compare what was read with what was written.*/ - if ((memcmp(cTestString, buffer, dwBytesRead)) != 0) - { - Trace("ERROR:%u: read \"%s\" expected \"%s\" \n", - GetLastError(), - buffer, - cTestString); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - CloseHandle(hDupPipe); - Fail(""); - } - - /*Compare values returned from WriteFile and ReadFile.*/ - if (dwBytesWritten != dwBytesRead) - { - Trace("ERROR:%u: WriteFile wrote \"%s\", but ReadFile read \"%s\"," - " these should be the same\n", - GetLastError(), - buffer, - cTestString); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - CloseHandle(hDupPipe); - Fail(""); - } - - /*Cleanup.*/ - CloseHandle(hWritePipe); - CloseHandle(hReadPipe); - CloseHandle(hDupPipe); - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test5/test5.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test5/test5.cpp new file mode 100644 index 0000000000..a588928f00 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test5/test5.cpp @@ -0,0 +1,145 @@ +// 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: test5.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function, +** with CreatePipe. This test will create a pipe and write to it, +** the duplicate the read handle and read what was written. +** +** Depends: WriteFile +** ReadFile +** memcmp +** CloseHandle +** +** +**===================================================================*/ + +#include + +const char* cTestString = "one fish, two fish, red fish, blue fish."; + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + HANDLE hDupPipe = NULL; + BOOL bRetVal = FALSE; + DWORD dwBytesWritten; + DWORD dwBytesRead; + char buffer[256]; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, /* read handle*/ + &hWritePipe, /* write handle */ + &lpPipeAttributes,/* security attributes*/ + 0); /* pipe size*/ + if (bRetVal == FALSE) + { + Fail("ERROR:%u:Unable to create pipe\n", GetLastError()); + } + + /*Write to the write pipe handle*/ + bRetVal = WriteFile(hWritePipe, /* handle to write pipe*/ + cTestString, /* buffer to write*/ + strlen(cTestString),/* number of bytes to write*/ + &dwBytesWritten, /* number of bytes written*/ + NULL); /* overlapped buffer*/ + if (bRetVal == FALSE) + { + Trace("ERROR:%u:unable to write to write pipe handle " + "hWritePipe=0x%lx\n", GetLastError(), hWritePipe); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + Fail(""); + } + + /*Duplicate the pipe handle*/ + if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ + hReadPipe, /* handle to duplicate*/ + GetCurrentProcess(), /* target process handle*/ + &hDupPipe, /* duplicate handle*/ + GENERIC_READ|GENERIC_WRITE,/* requested access*/ + FALSE, /* handle inheritance*/ + DUPLICATE_SAME_ACCESS))) /* optional actions*/ + { + Trace("ERROR:%u:Fail to create the duplicate handle" + " to hReadPipe=0x%lx", + GetLastError(), + hReadPipe); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + Fail(""); + } + + /*Read from the duplicated handle, 256 bytes, more bytes + than actually written. This will allow us to use the + value that ReadFile returns for comparision.*/ + bRetVal = ReadFile(hDupPipe, /* handle to read pipe*/ + buffer, /* buffer to write to*/ + 256, /* number of bytes to read*/ + &dwBytesRead, /* number of bytes read*/ + NULL); /* overlapped buffer*/ + if (bRetVal == FALSE) + { + Trace("ERROR:%u:unable read from the duplicated pipe " + "hDupPipe=0x%lx\n", + GetLastError(), + hDupPipe); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + CloseHandle(hDupPipe); + Fail(""); + } + + /*Compare what was read with what was written.*/ + if ((memcmp(cTestString, buffer, dwBytesRead)) != 0) + { + Trace("ERROR:%u: read \"%s\" expected \"%s\" \n", + GetLastError(), + buffer, + cTestString); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + CloseHandle(hDupPipe); + Fail(""); + } + + /*Compare values returned from WriteFile and ReadFile.*/ + if (dwBytesWritten != dwBytesRead) + { + Trace("ERROR:%u: WriteFile wrote \"%s\", but ReadFile read \"%s\"," + " these should be the same\n", + GetLastError(), + buffer, + cTestString); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + CloseHandle(hDupPipe); + Fail(""); + } + + /*Cleanup.*/ + CloseHandle(hWritePipe); + CloseHandle(hReadPipe); + CloseHandle(hDupPipe); + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test6/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test6/CMakeLists.txt index 20f7822b1e..a0dcae843c 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_duplicatehandle_test6 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test6/test6.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test6/test6.c deleted file mode 100644 index 026f315a44..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test6/test6.c +++ /dev/null @@ -1,146 +0,0 @@ -// 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: test6.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function, -** with CreatePipe. This test will create a pipe, then duplicate -** the write handle, write to the handle, and use the read to -** verify. -** -** Depends: WriteFile -** ReadFile -** memcmp -** CloseHandle -** -** -**===================================================================*/ - -#include - -const char* cTestString = "one fish, two fish, red fish, blue fish."; - -int __cdecl main(int argc, char **argv) -{ - HANDLE hReadPipe = NULL; - HANDLE hWritePipe = NULL; - HANDLE hDupPipe = NULL; - BOOL bRetVal = FALSE; - DWORD dwBytesWritten; - DWORD dwBytesRead; - char buffer[256]; - - SECURITY_ATTRIBUTES lpPipeAttributes; - - /*Initialize the PAL*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ - lpPipeAttributes.nLength = sizeof(lpPipeAttributes); - lpPipeAttributes.lpSecurityDescriptor = NULL; - lpPipeAttributes.bInheritHandle = TRUE; - - /*Create a Pipe*/ - bRetVal = CreatePipe(&hReadPipe, /* read handle*/ - &hWritePipe, /* write handle */ - &lpPipeAttributes,/* security attributes*/ - 0); /* pipe size*/ - if (bRetVal == FALSE) - { - Fail("ERROR: %ld :Unable to create pipe\n", GetLastError()); - } - - /*Duplicate the pipe handle*/ - if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ - hWritePipe, /* handle to duplicate*/ - GetCurrentProcess(), /* target process handle*/ - &hDupPipe, /* duplicate handle*/ - GENERIC_READ|GENERIC_WRITE,/* requested access*/ - FALSE, /* handle inheritance*/ - DUPLICATE_SAME_ACCESS))) /* optional actions*/ - { - Trace("ERROR: %ld :Fail to create the duplicate handle" - " to hWritePipe=0x%lx", - GetLastError(), - hWritePipe); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - Fail(""); - } - - /*Write to the duplicate write pipe handle*/ - bRetVal = WriteFile(hDupPipe, /* handle to write pipe*/ - cTestString, /* buffer to write*/ - strlen(cTestString),/* number of bytes to write*/ - &dwBytesWritten, /* number of bytes written*/ - NULL); /* overlapped buffer*/ - if (bRetVal == FALSE) - { - Trace("ERROR: %ld :unable to write to duplicate write pipe handle " - "hDupPipe=0x%lx\n", - GetLastError(), - hDupPipe); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - CloseHandle(hDupPipe); - Fail(""); - } - - /*Read from the read handle, 256 bytes, more bytes - then actually written. This will give allow us to use - the value that ReadFile returns for comparision.*/ - bRetVal = ReadFile(hReadPipe, /* handle to read pipe*/ - buffer, /* buffer to write to*/ - 256, /* number of bytes to read*/ - &dwBytesRead, /* number of bytes read*/ - NULL); /* overlapped buffer*/ - if (bRetVal == FALSE) - { - Trace("ERROR: %ld : unable read hReadPipe=0x%lx\n", - GetLastError(), hReadPipe); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - CloseHandle(hDupPipe); - Fail(""); - } - - /*Compare what was read with what was written.*/ - if ((memcmp(cTestString, buffer, dwBytesRead)) != 0) - { - Trace("ERROR: read \"%s\" expected \"%s\" \n", - buffer, - cTestString); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - CloseHandle(hDupPipe); - Fail(""); - } - - /*Compare values returned from WriteFile and ReadFile.*/ - if (dwBytesWritten != dwBytesRead) - { - Trace("ERROR: WriteFile wrote \"%s\", but ReadFile read \"%s\"," - " these should be the same\n", - buffer, - cTestString); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - CloseHandle(hDupPipe); - Fail(""); - } - - /*Cleanup.*/ - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - CloseHandle(hDupPipe); - - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test6/test6.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test6/test6.cpp new file mode 100644 index 0000000000..026f315a44 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test6/test6.cpp @@ -0,0 +1,146 @@ +// 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: test6.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function, +** with CreatePipe. This test will create a pipe, then duplicate +** the write handle, write to the handle, and use the read to +** verify. +** +** Depends: WriteFile +** ReadFile +** memcmp +** CloseHandle +** +** +**===================================================================*/ + +#include + +const char* cTestString = "one fish, two fish, red fish, blue fish."; + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + HANDLE hDupPipe = NULL; + BOOL bRetVal = FALSE; + DWORD dwBytesWritten; + DWORD dwBytesRead; + char buffer[256]; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, /* read handle*/ + &hWritePipe, /* write handle */ + &lpPipeAttributes,/* security attributes*/ + 0); /* pipe size*/ + if (bRetVal == FALSE) + { + Fail("ERROR: %ld :Unable to create pipe\n", GetLastError()); + } + + /*Duplicate the pipe handle*/ + if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ + hWritePipe, /* handle to duplicate*/ + GetCurrentProcess(), /* target process handle*/ + &hDupPipe, /* duplicate handle*/ + GENERIC_READ|GENERIC_WRITE,/* requested access*/ + FALSE, /* handle inheritance*/ + DUPLICATE_SAME_ACCESS))) /* optional actions*/ + { + Trace("ERROR: %ld :Fail to create the duplicate handle" + " to hWritePipe=0x%lx", + GetLastError(), + hWritePipe); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + Fail(""); + } + + /*Write to the duplicate write pipe handle*/ + bRetVal = WriteFile(hDupPipe, /* handle to write pipe*/ + cTestString, /* buffer to write*/ + strlen(cTestString),/* number of bytes to write*/ + &dwBytesWritten, /* number of bytes written*/ + NULL); /* overlapped buffer*/ + if (bRetVal == FALSE) + { + Trace("ERROR: %ld :unable to write to duplicate write pipe handle " + "hDupPipe=0x%lx\n", + GetLastError(), + hDupPipe); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + CloseHandle(hDupPipe); + Fail(""); + } + + /*Read from the read handle, 256 bytes, more bytes + then actually written. This will give allow us to use + the value that ReadFile returns for comparision.*/ + bRetVal = ReadFile(hReadPipe, /* handle to read pipe*/ + buffer, /* buffer to write to*/ + 256, /* number of bytes to read*/ + &dwBytesRead, /* number of bytes read*/ + NULL); /* overlapped buffer*/ + if (bRetVal == FALSE) + { + Trace("ERROR: %ld : unable read hReadPipe=0x%lx\n", + GetLastError(), hReadPipe); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + CloseHandle(hDupPipe); + Fail(""); + } + + /*Compare what was read with what was written.*/ + if ((memcmp(cTestString, buffer, dwBytesRead)) != 0) + { + Trace("ERROR: read \"%s\" expected \"%s\" \n", + buffer, + cTestString); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + CloseHandle(hDupPipe); + Fail(""); + } + + /*Compare values returned from WriteFile and ReadFile.*/ + if (dwBytesWritten != dwBytesRead) + { + Trace("ERROR: WriteFile wrote \"%s\", but ReadFile read \"%s\"," + " these should be the same\n", + buffer, + cTestString); + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + CloseHandle(hDupPipe); + Fail(""); + } + + /*Cleanup.*/ + CloseHandle(hReadPipe); + CloseHandle(hWritePipe); + CloseHandle(hDupPipe); + + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test7/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test7/CMakeLists.txt index df3fdf9ae0..a222331fe7 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_duplicatehandle_test7 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.c deleted file mode 100644 index 0477291922..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.c +++ /dev/null @@ -1,149 +0,0 @@ -// 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: test7.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function, -** with a handle from CreateThread. The test will create a thread -** handle and its duplicate. Then get the priorities of the threads, -** set the priority of one and the change should be seen in the -** other. -** -** -**===================================================================*/ - -#include - -DWORD PALAPI CreateTestThread(LPVOID lpParam); - -int __cdecl main(int argc, char* argv[]) -{ - HANDLE hThread; - HANDLE hDupThread; - DWORD dwThreadId = 0; - LPTHREAD_START_ROUTINE lpStartAddress = &CreateTestThread; - - int threadPriority; - int duplicatePriority; - int finalPriority; - - /* Initialize the PAL.*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - - /* Create a thread.*/ - hThread = CreateThread(NULL, /* SD*/ - (DWORD)0, /* initial stack size*/ - lpStartAddress, /* thread function*/ - NULL, /* thread argument*/ - (DWORD)0, /* creation option*/ - &dwThreadId); /* thread identifier*/ - if (hThread == NULL) - { - Fail("ERROR:%u: Unable to create thread.\n", - GetLastError()); - } - - /* Duplicate the thread handle.*/ - if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ - hThread, /* handle to duplicate*/ - GetCurrentProcess(), /* target process handle*/ - &hDupThread, /* duplicate handle*/ - (DWORD)0, /* requested access*/ - FALSE, /* handle inheritance*/ - DUPLICATE_SAME_ACCESS))) /* optional actions*/ - { - Trace("ERROR: %ld :Fail to create the duplicate handle" - " to hThread=0x%lx", - GetLastError(), - hThread); - CloseHandle(hThread); - Fail(""); - } - - /* Get the priority of the thread.*/ - threadPriority = GetThreadPriority(hThread); - if(threadPriority != 0) - { - Trace("ERROR: Thread priority of hThread=0x%lx should be " - "set to normal THREAD_PRIORITY_NORMAL=%d\n", - hThread, - THREAD_PRIORITY_NORMAL); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Get the priority of the duplicated handle, and compare it to - * the priority of the original thread. Should be the same.*/ - duplicatePriority = GetThreadPriority(hThread); - if(duplicatePriority != threadPriority) - { - Trace("ERROR: Expected priority of hThread=0x%lx and hDupThread=0x%lx" - " to be the same. Priorities:hThread=\"%d\":hDupThread=\"%d\"\n", - hThread, - hDupThread, - threadPriority, - duplicatePriority); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Set the priority of the duplicate thread.*/ - if(!SetThreadPriority (hDupThread,THREAD_PRIORITY_HIGHEST)) - { - Trace("ERROR:%u: SetThreadPriority failed on hThread=0x%lx\n", - GetLastError(), - hDupThread); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Get the priority of the origianl thread, and - * compare it to what the duplicate was set to.*/ - finalPriority = GetThreadPriority(hThread); - if (finalPriority != THREAD_PRIORITY_HIGHEST) - { - Trace("ERROR: Expected priority of hThread=0x%lw and " - "hDupThread=0x%lw to be set the same. Priorities:" - "hThread=\"%d\":hDupThread=\"%d\".\n", - hThread, - hDupThread, - threadPriority, - duplicatePriority); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Wait on the original thread.*/ - if((WaitForSingleObject(hThread, 100)) != WAIT_OBJECT_0) - { - Trace("ERROR:%u: hThread=0x%lx is in a non-signalled " - "mode, yet created signalled.\n", - GetLastError(), - hThread); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Clean-up thread and Terminate the PAL.*/ - CloseHandle(hThread); - CloseHandle(hDupThread); - PAL_Terminate(); - return PASS; -} - -/*Thread testing function, only return '0'*/ -DWORD PALAPI CreateTestThread(LPVOID lpParam) -{ - return (DWORD)0; -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.cpp new file mode 100644 index 0000000000..0477291922 --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.cpp @@ -0,0 +1,149 @@ +// 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: test7.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function, +** with a handle from CreateThread. The test will create a thread +** handle and its duplicate. Then get the priorities of the threads, +** set the priority of one and the change should be seen in the +** other. +** +** +**===================================================================*/ + +#include + +DWORD PALAPI CreateTestThread(LPVOID lpParam); + +int __cdecl main(int argc, char* argv[]) +{ + HANDLE hThread; + HANDLE hDupThread; + DWORD dwThreadId = 0; + LPTHREAD_START_ROUTINE lpStartAddress = &CreateTestThread; + + int threadPriority; + int duplicatePriority; + int finalPriority; + + /* Initialize the PAL.*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /* Create a thread.*/ + hThread = CreateThread(NULL, /* SD*/ + (DWORD)0, /* initial stack size*/ + lpStartAddress, /* thread function*/ + NULL, /* thread argument*/ + (DWORD)0, /* creation option*/ + &dwThreadId); /* thread identifier*/ + if (hThread == NULL) + { + Fail("ERROR:%u: Unable to create thread.\n", + GetLastError()); + } + + /* Duplicate the thread handle.*/ + if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ + hThread, /* handle to duplicate*/ + GetCurrentProcess(), /* target process handle*/ + &hDupThread, /* duplicate handle*/ + (DWORD)0, /* requested access*/ + FALSE, /* handle inheritance*/ + DUPLICATE_SAME_ACCESS))) /* optional actions*/ + { + Trace("ERROR: %ld :Fail to create the duplicate handle" + " to hThread=0x%lx", + GetLastError(), + hThread); + CloseHandle(hThread); + Fail(""); + } + + /* Get the priority of the thread.*/ + threadPriority = GetThreadPriority(hThread); + if(threadPriority != 0) + { + Trace("ERROR: Thread priority of hThread=0x%lx should be " + "set to normal THREAD_PRIORITY_NORMAL=%d\n", + hThread, + THREAD_PRIORITY_NORMAL); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Get the priority of the duplicated handle, and compare it to + * the priority of the original thread. Should be the same.*/ + duplicatePriority = GetThreadPriority(hThread); + if(duplicatePriority != threadPriority) + { + Trace("ERROR: Expected priority of hThread=0x%lx and hDupThread=0x%lx" + " to be the same. Priorities:hThread=\"%d\":hDupThread=\"%d\"\n", + hThread, + hDupThread, + threadPriority, + duplicatePriority); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Set the priority of the duplicate thread.*/ + if(!SetThreadPriority (hDupThread,THREAD_PRIORITY_HIGHEST)) + { + Trace("ERROR:%u: SetThreadPriority failed on hThread=0x%lx\n", + GetLastError(), + hDupThread); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Get the priority of the origianl thread, and + * compare it to what the duplicate was set to.*/ + finalPriority = GetThreadPriority(hThread); + if (finalPriority != THREAD_PRIORITY_HIGHEST) + { + Trace("ERROR: Expected priority of hThread=0x%lw and " + "hDupThread=0x%lw to be set the same. Priorities:" + "hThread=\"%d\":hDupThread=\"%d\".\n", + hThread, + hDupThread, + threadPriority, + duplicatePriority); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Wait on the original thread.*/ + if((WaitForSingleObject(hThread, 100)) != WAIT_OBJECT_0) + { + Trace("ERROR:%u: hThread=0x%lx is in a non-signalled " + "mode, yet created signalled.\n", + GetLastError(), + hThread); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Clean-up thread and Terminate the PAL.*/ + CloseHandle(hThread); + CloseHandle(hDupThread); + PAL_Terminate(); + return PASS; +} + +/*Thread testing function, only return '0'*/ +DWORD PALAPI CreateTestThread(LPVOID lpParam) +{ + return (DWORD)0; +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test8/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test8/CMakeLists.txt index 15ec23d272..18ed969cb7 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test8/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test8/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test8.c + test8.cpp ) add_executable(paltest_duplicatehandle_test8 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test8/test8.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test8/test8.c deleted file mode 100644 index 6748c5dffd..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test8/test8.c +++ /dev/null @@ -1,164 +0,0 @@ -// 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: test8.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function, -** with a handle from GetCurrentThread. The test will create a thread -** handle, get the current thread and its duplicate. Then get the -** priorities of the threads, set the priority of one and the change -** should be seen in the other. -** -** -**===================================================================*/ - -#include - -DWORD PALAPI CreateTestThread(LPVOID lpParam); - -int __cdecl main(int argc, char* argv[]) -{ - HANDLE hThread; - HANDLE hCurrentThread; - HANDLE hDupThread; - DWORD dwThreadId = 0; - LPTHREAD_START_ROUTINE lpStartAddress = &CreateTestThread; - - int threadPriority; - int duplicatePriority; - int finalPriority; - - /* Initialize the PAL.*/ - if ((PAL_Initialize(argc, argv)) != 0) - { - return (FAIL); - } - -#if !HAVE_SCHED_OTHER_ASSIGNABLE - /* Defining thread priority for SCHED_OTHER is implementation defined. - Some platforms like NetBSD cannot reassign it as they are dynamic. - */ - printf("paltest_duplicatehandle_test8 has been disabled on this platform\n"); -#else - - /* Create a thread.*/ - hThread = CreateThread(NULL, /* SD*/ - (DWORD)0, /* initial stack size*/ - lpStartAddress, /* thread function*/ - NULL, /* thread argument*/ - (DWORD)0, /* creation option*/ - &dwThreadId); /* thread identifier*/ - if (hThread == NULL) - { - Fail("ERROR:%u: Unable to create thread.\n", - GetLastError()); - } - - /*Get a psuedo handle to the current thread.*/ - hCurrentThread = GetCurrentThread(); - - /* Duplicate the psuedo thread handle.*/ - if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ - hCurrentThread, /* handle to duplicate*/ - GetCurrentProcess(), /* target process handle*/ - &hDupThread, /* duplicate handle*/ - (DWORD)0, /* requested access*/ - FALSE, /* handle inheritance*/ - DUPLICATE_SAME_ACCESS))) /* optional actions*/ - { - Trace("ERROR: %ld :Fail to create the duplicate handle" - " to hThread=0x%lx", - GetLastError(), - hThread); - CloseHandle(hThread); - Fail(""); - } - - /* Get the priority of the thread.*/ - threadPriority = GetThreadPriority(hCurrentThread); - if(threadPriority != 0) - { - Trace("ERROR: Thread priority of hCurrentThread=0x%lx should be " - "set to normal THREAD_PRIORITY_NORMAL=%d\n", - hCurrentThread, - THREAD_PRIORITY_NORMAL); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Get the priority of the duplicated handle, and compare it to - * the priority of the original thread. Should be the same.*/ - duplicatePriority = GetThreadPriority(hCurrentThread); - if(duplicatePriority != threadPriority) - { - Trace("ERROR: Expected priority of hCurrentThread=0x%lx and " - "hDupThread=0x%lx to be the same. Priorities:hThread=" - "\"%d\":hDupThread=\"%d\"\n", - hCurrentThread, - hDupThread, - threadPriority, - duplicatePriority); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Set the priority of the original thread.*/ - if(!SetThreadPriority (hCurrentThread,THREAD_PRIORITY_HIGHEST)) - { - Trace("ERROR:%u: SetThreadPriority failed on hCurrentThread=0x%lx\n", - GetLastError(), - hCurrentThread); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Get the priority of the duplicate thread, and - * compare it to what the original was set to.*/ - finalPriority = GetThreadPriority(hDupThread); - if (finalPriority != THREAD_PRIORITY_HIGHEST) - { - Trace("ERROR: Expected priority of hCurrentThread=0x%lw and " - "hDupThread=0x%lw to be set the same. Priorities:" - "hCurrentThread=\"%d\":hDupThread=\"%d\".\n", - hCurrentThread, - hDupThread, - threadPriority, - duplicatePriority); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Wait on the original thread.*/ - if((WaitForSingleObject(hThread, 100)) != WAIT_OBJECT_0) - { - Trace("ERROR:%u: hCurrentThread=0x%lx is in a non-signalled " - "mode, yet created signalled.\n", - GetLastError(), - hThread); - CloseHandle(hThread); - CloseHandle(hDupThread); - Fail(""); - } - - /* Clean-up thread and Terminate the PAL.*/ - CloseHandle(hThread); - CloseHandle(hDupThread); - -#endif - - PAL_Terminate(); - return PASS; -} - -/*Thread testing function, only return '0'*/ -DWORD PALAPI CreateTestThread(LPVOID lpParam) -{ - return (DWORD)0; -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test8/test8.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test8/test8.cpp new file mode 100644 index 0000000000..6748c5dffd --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test8/test8.cpp @@ -0,0 +1,164 @@ +// 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: test8.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function, +** with a handle from GetCurrentThread. The test will create a thread +** handle, get the current thread and its duplicate. Then get the +** priorities of the threads, set the priority of one and the change +** should be seen in the other. +** +** +**===================================================================*/ + +#include + +DWORD PALAPI CreateTestThread(LPVOID lpParam); + +int __cdecl main(int argc, char* argv[]) +{ + HANDLE hThread; + HANDLE hCurrentThread; + HANDLE hDupThread; + DWORD dwThreadId = 0; + LPTHREAD_START_ROUTINE lpStartAddress = &CreateTestThread; + + int threadPriority; + int duplicatePriority; + int finalPriority; + + /* Initialize the PAL.*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + +#if !HAVE_SCHED_OTHER_ASSIGNABLE + /* Defining thread priority for SCHED_OTHER is implementation defined. + Some platforms like NetBSD cannot reassign it as they are dynamic. + */ + printf("paltest_duplicatehandle_test8 has been disabled on this platform\n"); +#else + + /* Create a thread.*/ + hThread = CreateThread(NULL, /* SD*/ + (DWORD)0, /* initial stack size*/ + lpStartAddress, /* thread function*/ + NULL, /* thread argument*/ + (DWORD)0, /* creation option*/ + &dwThreadId); /* thread identifier*/ + if (hThread == NULL) + { + Fail("ERROR:%u: Unable to create thread.\n", + GetLastError()); + } + + /*Get a psuedo handle to the current thread.*/ + hCurrentThread = GetCurrentThread(); + + /* Duplicate the psuedo thread handle.*/ + if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ + hCurrentThread, /* handle to duplicate*/ + GetCurrentProcess(), /* target process handle*/ + &hDupThread, /* duplicate handle*/ + (DWORD)0, /* requested access*/ + FALSE, /* handle inheritance*/ + DUPLICATE_SAME_ACCESS))) /* optional actions*/ + { + Trace("ERROR: %ld :Fail to create the duplicate handle" + " to hThread=0x%lx", + GetLastError(), + hThread); + CloseHandle(hThread); + Fail(""); + } + + /* Get the priority of the thread.*/ + threadPriority = GetThreadPriority(hCurrentThread); + if(threadPriority != 0) + { + Trace("ERROR: Thread priority of hCurrentThread=0x%lx should be " + "set to normal THREAD_PRIORITY_NORMAL=%d\n", + hCurrentThread, + THREAD_PRIORITY_NORMAL); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Get the priority of the duplicated handle, and compare it to + * the priority of the original thread. Should be the same.*/ + duplicatePriority = GetThreadPriority(hCurrentThread); + if(duplicatePriority != threadPriority) + { + Trace("ERROR: Expected priority of hCurrentThread=0x%lx and " + "hDupThread=0x%lx to be the same. Priorities:hThread=" + "\"%d\":hDupThread=\"%d\"\n", + hCurrentThread, + hDupThread, + threadPriority, + duplicatePriority); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Set the priority of the original thread.*/ + if(!SetThreadPriority (hCurrentThread,THREAD_PRIORITY_HIGHEST)) + { + Trace("ERROR:%u: SetThreadPriority failed on hCurrentThread=0x%lx\n", + GetLastError(), + hCurrentThread); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Get the priority of the duplicate thread, and + * compare it to what the original was set to.*/ + finalPriority = GetThreadPriority(hDupThread); + if (finalPriority != THREAD_PRIORITY_HIGHEST) + { + Trace("ERROR: Expected priority of hCurrentThread=0x%lw and " + "hDupThread=0x%lw to be set the same. Priorities:" + "hCurrentThread=\"%d\":hDupThread=\"%d\".\n", + hCurrentThread, + hDupThread, + threadPriority, + duplicatePriority); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Wait on the original thread.*/ + if((WaitForSingleObject(hThread, 100)) != WAIT_OBJECT_0) + { + Trace("ERROR:%u: hCurrentThread=0x%lx is in a non-signalled " + "mode, yet created signalled.\n", + GetLastError(), + hThread); + CloseHandle(hThread); + CloseHandle(hDupThread); + Fail(""); + } + + /* Clean-up thread and Terminate the PAL.*/ + CloseHandle(hThread); + CloseHandle(hDupThread); + +#endif + + PAL_Terminate(); + return PASS; +} + +/*Thread testing function, only return '0'*/ +DWORD PALAPI CreateTestThread(LPVOID lpParam) +{ + return (DWORD)0; +} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test9/CMakeLists.txt b/src/pal/tests/palsuite/threading/DuplicateHandle/test9/CMakeLists.txt index e4442e327c..0383a010ac 100644 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test9/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test9/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test9.c + test9.cpp ) add_executable(paltest_duplicatehandle_test9 diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test9/test9.c b/src/pal/tests/palsuite/threading/DuplicateHandle/test9/test9.c deleted file mode 100644 index f15871c57d..0000000000 --- a/src/pal/tests/palsuite/threading/DuplicateHandle/test9/test9.c +++ /dev/null @@ -1,127 +0,0 @@ -// 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: test9.c (DuplicateHandle) -** -** Purpose: Tests the PAL implementation of the DuplicateHandle function, -** with a handle from GetCurrentProcess. The test will create a -** process, duplicate it, then using ReadProcessMemory will -** read from the memory location of the CreateProcess process -** memory and the DuplicateHandle process memory. If the -** duplication is correct the memory will be the same for both. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char* argv[]) -{ - HANDLE hProcess; - HANDLE hDupProcess; - char lpBuffer[64]; - char lpDupBuffer[64]; - SIZE_T lpNumberOfBytesRead; - SIZE_T lpDupNumberOfBytesRead; - char lpTestBuffer[] = "abcdefghijklmnopqrstuvwxyz"; - - /* Initalize the PAL. - */ - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Initalize the buffers. - */ - ZeroMemory( &lpBuffer, sizeof(lpBuffer) ); - ZeroMemory( &lpDupBuffer, sizeof(lpDupBuffer) ); - - /* Get current proces, this will be duplicated. - */ - hProcess = GetCurrentProcess(); - if(hProcess == NULL) - { - Fail("ERROR: Unable to get the current process\n"); - } - - /* Duplicate the current process handle. - */ - if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ - hProcess, /* handle to duplicate*/ - GetCurrentProcess(), /* target process handle*/ - &hDupProcess, /* duplicate handle*/ - (DWORD)0, /* requested access*/ - FALSE, /* handle inheritance*/ - DUPLICATE_SAME_ACCESS))) /* optional actions*/ - { - Trace("ERROR:%u: Failed to create the duplicate handle" - " to hProcess=0x%lx", - GetLastError(), - hProcess); - CloseHandle(hProcess); - Fail(""); - } - - /* Get memory read of the current process. - */ - if ((ReadProcessMemory(hDupProcess, &lpTestBuffer, - lpDupBuffer, sizeof(lpDupBuffer), &lpDupNumberOfBytesRead)) == 0) - { - Trace("ERROR:%u: Unable to read the process memory of " - "hDupProcess=0x%lx.\n", - GetLastError(), - hDupProcess); - CloseHandle(hProcess); - CloseHandle(hDupProcess); - Fail(""); - } - - /* Get read memory of the created process. - */ - if ((ReadProcessMemory(hProcess, &lpTestBuffer, - lpBuffer, sizeof(lpBuffer), &lpNumberOfBytesRead)) == 0) - { - Trace("ERROR:%u: Unable to read the process memory of " - "hProcess=0x%lx.\n", - GetLastError(), - hProcess); - CloseHandle(hProcess); - CloseHandle(hDupProcess); - Fail(""); - } - - /* Compare the number of bytes that were read by each - * ReadProcessMemory.*/ - if (lpDupNumberOfBytesRead != lpNumberOfBytesRead) - { - Trace("ERROR: ReadProcessMemory read different numbers of bytes " - "from duplicate process handles.\n"); - CloseHandle(hProcess); - CloseHandle(hDupProcess); - Fail(""); - } - - /* Compare the two buffers to make sure they are equal. - */ - if ((strcmp(lpBuffer, lpDupBuffer)) != 0) - { - Trace("ERROR: ReadProcessMemory read different numbers of bytes " - "from duplicate process handles. hProcess read \"%s\" and " - "hDupProcess read \"%s\"\n", - lpBuffer, - lpDupBuffer); - CloseHandle(hProcess); - CloseHandle(hDupProcess); - Fail(""); - } - - /* Clean-up thread and Terminate the PAL.*/ - CloseHandle(hProcess); - CloseHandle(hDupProcess); - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test9/test9.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test9/test9.cpp new file mode 100644 index 0000000000..f15871c57d --- /dev/null +++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test9/test9.cpp @@ -0,0 +1,127 @@ +// 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: test9.c (DuplicateHandle) +** +** Purpose: Tests the PAL implementation of the DuplicateHandle function, +** with a handle from GetCurrentProcess. The test will create a +** process, duplicate it, then using ReadProcessMemory will +** read from the memory location of the CreateProcess process +** memory and the DuplicateHandle process memory. If the +** duplication is correct the memory will be the same for both. +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char* argv[]) +{ + HANDLE hProcess; + HANDLE hDupProcess; + char lpBuffer[64]; + char lpDupBuffer[64]; + SIZE_T lpNumberOfBytesRead; + SIZE_T lpDupNumberOfBytesRead; + char lpTestBuffer[] = "abcdefghijklmnopqrstuvwxyz"; + + /* Initalize the PAL. + */ + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Initalize the buffers. + */ + ZeroMemory( &lpBuffer, sizeof(lpBuffer) ); + ZeroMemory( &lpDupBuffer, sizeof(lpDupBuffer) ); + + /* Get current proces, this will be duplicated. + */ + hProcess = GetCurrentProcess(); + if(hProcess == NULL) + { + Fail("ERROR: Unable to get the current process\n"); + } + + /* Duplicate the current process handle. + */ + if (!(DuplicateHandle(GetCurrentProcess(), /* source handle process*/ + hProcess, /* handle to duplicate*/ + GetCurrentProcess(), /* target process handle*/ + &hDupProcess, /* duplicate handle*/ + (DWORD)0, /* requested access*/ + FALSE, /* handle inheritance*/ + DUPLICATE_SAME_ACCESS))) /* optional actions*/ + { + Trace("ERROR:%u: Failed to create the duplicate handle" + " to hProcess=0x%lx", + GetLastError(), + hProcess); + CloseHandle(hProcess); + Fail(""); + } + + /* Get memory read of the current process. + */ + if ((ReadProcessMemory(hDupProcess, &lpTestBuffer, + lpDupBuffer, sizeof(lpDupBuffer), &lpDupNumberOfBytesRead)) == 0) + { + Trace("ERROR:%u: Unable to read the process memory of " + "hDupProcess=0x%lx.\n", + GetLastError(), + hDupProcess); + CloseHandle(hProcess); + CloseHandle(hDupProcess); + Fail(""); + } + + /* Get read memory of the created process. + */ + if ((ReadProcessMemory(hProcess, &lpTestBuffer, + lpBuffer, sizeof(lpBuffer), &lpNumberOfBytesRead)) == 0) + { + Trace("ERROR:%u: Unable to read the process memory of " + "hProcess=0x%lx.\n", + GetLastError(), + hProcess); + CloseHandle(hProcess); + CloseHandle(hDupProcess); + Fail(""); + } + + /* Compare the number of bytes that were read by each + * ReadProcessMemory.*/ + if (lpDupNumberOfBytesRead != lpNumberOfBytesRead) + { + Trace("ERROR: ReadProcessMemory read different numbers of bytes " + "from duplicate process handles.\n"); + CloseHandle(hProcess); + CloseHandle(hDupProcess); + Fail(""); + } + + /* Compare the two buffers to make sure they are equal. + */ + if ((strcmp(lpBuffer, lpDupBuffer)) != 0) + { + Trace("ERROR: ReadProcessMemory read different numbers of bytes " + "from duplicate process handles. hProcess read \"%s\" and " + "hDupProcess read \"%s\"\n", + lpBuffer, + lpDupBuffer); + CloseHandle(hProcess); + CloseHandle(hDupProcess); + Fail(""); + } + + /* Clean-up thread and Terminate the PAL.*/ + CloseHandle(hProcess); + CloseHandle(hDupProcess); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/ExitProcess/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/ExitProcess/test1/CMakeLists.txt index decddb8512..f2d28e06ca 100644 --- a/src/pal/tests/palsuite/threading/ExitProcess/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ExitProcess/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - ExitProcess.c + ExitProcess.cpp ) add_executable(paltest_exitprocess_test1 diff --git a/src/pal/tests/palsuite/threading/ExitProcess/test1/ExitProcess.c b/src/pal/tests/palsuite/threading/ExitProcess/test1/ExitProcess.c deleted file mode 100644 index 2b089a0b83..0000000000 --- a/src/pal/tests/palsuite/threading/ExitProcess/test1/ExitProcess.c +++ /dev/null @@ -1,32 +0,0 @@ -// 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: exitprocess/test1/exitprocess.c -** -** Purpose: Test to ensure ExitProcess returns the argument given -** to it. -** -** -**=========================================================*/ - -#include - -int __cdecl main( int argc, char **argv ) - -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - ExitProcess(PASS); - - Fail ("ExitProcess(0) failed to exit.\n Test Failed.\n"); - - return ( FAIL); - -} diff --git a/src/pal/tests/palsuite/threading/ExitProcess/test1/ExitProcess.cpp b/src/pal/tests/palsuite/threading/ExitProcess/test1/ExitProcess.cpp new file mode 100644 index 0000000000..2b089a0b83 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ExitProcess/test1/ExitProcess.cpp @@ -0,0 +1,32 @@ +// 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: exitprocess/test1/exitprocess.c +** +** Purpose: Test to ensure ExitProcess returns the argument given +** to it. +** +** +**=========================================================*/ + +#include + +int __cdecl main( int argc, char **argv ) + +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + ExitProcess(PASS); + + Fail ("ExitProcess(0) failed to exit.\n Test Failed.\n"); + + return ( FAIL); + +} diff --git a/src/pal/tests/palsuite/threading/ExitProcess/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/ExitProcess/test2/CMakeLists.txt index 881c7d0eee..5281a02aa4 100644 --- a/src/pal/tests/palsuite/threading/ExitProcess/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ExitProcess/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_exitprocess_test2 diff --git a/src/pal/tests/palsuite/threading/ExitProcess/test2/test2.c b/src/pal/tests/palsuite/threading/ExitProcess/test2/test2.c deleted file mode 100644 index 8023ad7bab..0000000000 --- a/src/pal/tests/palsuite/threading/ExitProcess/test2/test2.c +++ /dev/null @@ -1,30 +0,0 @@ -// 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: test2.c -** -** Purpose: Positive test for ExitProcess. -** -** Dependencies: none -** - -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* call ExitProcess() -- should work without PAL_Initialize() */ - ExitProcess(PASS); - - - /* return failure if we reach here -- note no attempt at */ - /* meaningful output because we never called PAL_Initialize(). */ - return FAIL; -} diff --git a/src/pal/tests/palsuite/threading/ExitProcess/test2/test2.cpp b/src/pal/tests/palsuite/threading/ExitProcess/test2/test2.cpp new file mode 100644 index 0000000000..8023ad7bab --- /dev/null +++ b/src/pal/tests/palsuite/threading/ExitProcess/test2/test2.cpp @@ -0,0 +1,30 @@ +// 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: test2.c +** +** Purpose: Positive test for ExitProcess. +** +** Dependencies: none +** + +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* call ExitProcess() -- should work without PAL_Initialize() */ + ExitProcess(PASS); + + + /* return failure if we reach here -- note no attempt at */ + /* meaningful output because we never called PAL_Initialize(). */ + return FAIL; +} diff --git a/src/pal/tests/palsuite/threading/ExitProcess/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/ExitProcess/test3/CMakeLists.txt index 638408e986..3fca087d05 100644 --- a/src/pal/tests/palsuite/threading/ExitProcess/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ExitProcess/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_exitprocess_test3 diff --git a/src/pal/tests/palsuite/threading/ExitProcess/test3/test3.c b/src/pal/tests/palsuite/threading/ExitProcess/test3/test3.c deleted file mode 100644 index aea485e5e3..0000000000 --- a/src/pal/tests/palsuite/threading/ExitProcess/test3/test3.c +++ /dev/null @@ -1,40 +0,0 @@ -// 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: test3.c -** -** Purpose: Positive test for ExitProcess. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** - -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* terminate the PAL */ - PAL_Terminate(); - - /* call ExitProcess() -- should work after PAL_Terminate() */ - ExitProcess( PASS ); - - - /* return failure if we reach here -- note no attempt at */ - /* meaningful output because we've called PAL_Terminte(). */ - return FAIL; -} diff --git a/src/pal/tests/palsuite/threading/ExitProcess/test3/test3.cpp b/src/pal/tests/palsuite/threading/ExitProcess/test3/test3.cpp new file mode 100644 index 0000000000..aea485e5e3 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ExitProcess/test3/test3.cpp @@ -0,0 +1,40 @@ +// 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: test3.c +** +** Purpose: Positive test for ExitProcess. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** + +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* terminate the PAL */ + PAL_Terminate(); + + /* call ExitProcess() -- should work after PAL_Terminate() */ + ExitProcess( PASS ); + + + /* return failure if we reach here -- note no attempt at */ + /* meaningful output because we've called PAL_Terminte(). */ + return FAIL; +} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/ExitThread/test1/CMakeLists.txt index 15e0c1b62d..c34b5257ab 100644 --- a/src/pal/tests/palsuite/threading/ExitThread/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ExitThread/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_exitthread_test1 diff --git a/src/pal/tests/palsuite/threading/ExitThread/test1/test1.c b/src/pal/tests/palsuite/threading/ExitThread/test1/test1.c deleted file mode 100644 index 2963745bef..0000000000 --- a/src/pal/tests/palsuite/threading/ExitThread/test1/test1.c +++ /dev/null @@ -1,114 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for ExitThread. Create a thread and then call -** exit thread within the threading function. Ensure that it exits -** immediatly. -** -** -**=========================================================*/ - -#include - -DWORD dwExitThreadTestParameter = 0; - -DWORD PALAPI ExitThreadTestThread( LPVOID lpParameter) -{ - DWORD dwRet = 0; - - /* Save parameter for test */ - dwExitThreadTestParameter = (DWORD)lpParameter; - - /* Call the ExitThread function */ - ExitThread(dwRet); - - /* If we didn't exit, get caught in this loop. But, the - program will exit. - */ - while (!dwRet) - { - Fail("ERROR: Entered an infinite loop because ExitThread " - "failed to exit from the thread. Forcing exit from " - "the test now."); - } - - return dwRet; -} - -BOOL ExitThreadTest() -{ - BOOL bRet = FALSE; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL; - DWORD dwStackSize = 0; - LPTHREAD_START_ROUTINE lpStartAddress = &ExitThreadTestThread; - LPVOID lpParameter = lpStartAddress; - DWORD dwCreationFlags = 0; //run immediately - DWORD dwThreadId = 0; - - HANDLE hThread = 0; - - dwExitThreadTestParameter = 0; - - /* Create a Thread. We'll need this to test that we're able - to exit the thread. - */ - hThread = CreateThread( lpThreadAttributes, - dwStackSize, lpStartAddress, lpParameter, - dwCreationFlags, &dwThreadId ); - - if (hThread != INVALID_HANDLE_VALUE) - { - dwRet = WaitForSingleObject(hThread,INFINITE); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("ExitThreadTest:WaitForSingleObject failed " - "(%x)\n",GetLastError()); - } - else - { - /* Check to ensure that the parameter set in the Thread - function is correct. - */ - if (dwExitThreadTestParameter != (DWORD)lpParameter) - { - Trace("ERROR: The paramater passed should have been " - "%d but turned up as %d.", - dwExitThreadTestParameter, lpParameter); - } - else - { - bRet = TRUE; - } - } - } - else - { - Trace("ExitThreadTest:CreateThread failed (%x)\n",GetLastError()); - } - - return bRet; -} - -int __cdecl main(int argc, char **argv) -{ - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!ExitThreadTest()) - { - Fail ("Test failed\n"); - } - - PAL_Terminate(); - return ( PASS ); -} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test1/test1.cpp b/src/pal/tests/palsuite/threading/ExitThread/test1/test1.cpp new file mode 100644 index 0000000000..caf1409406 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ExitThread/test1/test1.cpp @@ -0,0 +1,114 @@ +// 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: test1.c +** +** Purpose: Test for ExitThread. Create a thread and then call +** exit thread within the threading function. Ensure that it exits +** immediatly. +** +** +**=========================================================*/ + +#include + +DWORD dwExitThreadTestParameter = 0; + +DWORD PALAPI ExitThreadTestThread( LPVOID lpParameter) +{ + DWORD dwRet = 0; + + /* Save parameter for test */ + dwExitThreadTestParameter = (DWORD)lpParameter; + + /* Call the ExitThread function */ + ExitThread(dwRet); + + /* If we didn't exit, get caught in this loop. But, the + program will exit. + */ + while (!dwRet) + { + Fail("ERROR: Entered an infinite loop because ExitThread " + "failed to exit from the thread. Forcing exit from " + "the test now."); + } + + return dwRet; +} + +BOOL ExitThreadTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL; + DWORD dwStackSize = 0; + LPTHREAD_START_ROUTINE lpStartAddress = &ExitThreadTestThread; + LPVOID lpParameter = (LPVOID)lpStartAddress; + DWORD dwCreationFlags = 0; //run immediately + DWORD dwThreadId = 0; + + HANDLE hThread = 0; + + dwExitThreadTestParameter = 0; + + /* Create a Thread. We'll need this to test that we're able + to exit the thread. + */ + hThread = CreateThread( lpThreadAttributes, + dwStackSize, lpStartAddress, lpParameter, + dwCreationFlags, &dwThreadId ); + + if (hThread != INVALID_HANDLE_VALUE) + { + dwRet = WaitForSingleObject(hThread,INFINITE); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("ExitThreadTest:WaitForSingleObject failed " + "(%x)\n",GetLastError()); + } + else + { + /* Check to ensure that the parameter set in the Thread + function is correct. + */ + if (dwExitThreadTestParameter != (DWORD)lpParameter) + { + Trace("ERROR: The paramater passed should have been " + "%d but turned up as %d.", + dwExitThreadTestParameter, lpParameter); + } + else + { + bRet = TRUE; + } + } + } + else + { + Trace("ExitThreadTest:CreateThread failed (%x)\n",GetLastError()); + } + + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!ExitThreadTest()) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); +} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/ExitThread/test2/CMakeLists.txt index aa05382feb..5e16d36082 100644 --- a/src/pal/tests/palsuite/threading/ExitThread/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ExitThread/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test2.c + test2.cpp ) add_executable(paltest_exitthread_test2 @@ -20,7 +20,7 @@ target_link_libraries(paltest_exitthread_test2 set(HELPERSOURCES - childprocess.c + childprocess.cpp ) add_executable(paltest_exitthread_test2_child diff --git a/src/pal/tests/palsuite/threading/ExitThread/test2/childprocess.c b/src/pal/tests/palsuite/threading/ExitThread/test2/childprocess.c deleted file mode 100644 index 7fbe208f91..0000000000 --- a/src/pal/tests/palsuite/threading/ExitThread/test2/childprocess.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: childprocess.c -** -** Purpose: Test to ensure ExitThread returns the right -** value when shutting down the last thread of a process. -** All this program does is call ExitThread() with a predefined -** value. -** -** Dependencies: none -** - -** -**=========================================================*/ - -#include -#include "myexitcode.h" - -int __cdecl main( int argc, char **argv ) -{ - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* exit the current thread with a magic test value -- it should */ - /* terminate the process and return that test value from this */ - /* program. */ - ExitThread( TEST_EXIT_CODE ); - - /* technically we should never get here */ - PAL_Terminate(); - - /* return failure */ - return FAIL; -} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test2/childprocess.cpp b/src/pal/tests/palsuite/threading/ExitThread/test2/childprocess.cpp new file mode 100644 index 0000000000..7fbe208f91 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ExitThread/test2/childprocess.cpp @@ -0,0 +1,41 @@ +// 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: childprocess.c +** +** Purpose: Test to ensure ExitThread returns the right +** value when shutting down the last thread of a process. +** All this program does is call ExitThread() with a predefined +** value. +** +** Dependencies: none +** + +** +**=========================================================*/ + +#include +#include "myexitcode.h" + +int __cdecl main( int argc, char **argv ) +{ + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* exit the current thread with a magic test value -- it should */ + /* terminate the process and return that test value from this */ + /* program. */ + ExitThread( TEST_EXIT_CODE ); + + /* technically we should never get here */ + PAL_Terminate(); + + /* return failure */ + return FAIL; +} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test2/test2.c b/src/pal/tests/palsuite/threading/ExitThread/test2/test2.c deleted file mode 100644 index c31af8a079..0000000000 --- a/src/pal/tests/palsuite/threading/ExitThread/test2/test2.c +++ /dev/null @@ -1,168 +0,0 @@ -// 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: test2.c -** -** Purpose: Test to ensure ExitThread() called from the last thread of -** a process shuts down that process and returns the proper -** exit code as specified in the ExitThread() call. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** ZeroMemory -** GetCurrentDirectoryW -** CreateProcessW -** WaitForSingleObject -** GetLastError -** strlen -** strncpy -** - -** -**===========================================================================*/ -#include -#include "myexitcode.h" - - -static const char* rgchPathDelim = "\\"; - - -int -mkAbsoluteFilename( LPSTR dirName, - DWORD dwDirLength, - LPCSTR fileName, - DWORD dwFileLength, - LPSTR absPathName ) -{ - DWORD sizeDN, sizeFN, sizeAPN; - - sizeDN = strlen( dirName ); - sizeFN = strlen( fileName ); - sizeAPN = (sizeDN + 1 + sizeFN + 1); - - /* ensure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ - if( sizeAPN > _MAX_PATH ) - { - return ( 0 ); - } - - strncpy( absPathName, dirName, dwDirLength +1 ); - strncpy( absPathName, rgchPathDelim, 2 ); - strncpy( absPathName, fileName, dwFileLength +1 ); - - return (sizeAPN); - -} - - -int __cdecl main( int argc, char **argv ) - -{ - const char* rgchChildFile = "childprocess"; - - STARTUPINFO si; - PROCESS_INFORMATION pi; - - DWORD dwError; - DWORD dwExitCode; - DWORD dwFileLength; - DWORD dwDirLength; - DWORD dwSize; - DWORD dwExpected = TEST_EXIT_CODE; - - char rgchDirName[_MAX_DIR]; - char absPathBuf[_MAX_PATH]; - char* rgchAbsPathName; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* zero our process and startup info structures */ - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof( si ); - ZeroMemory( &pi, sizeof(pi) ); - - /* build the absolute path to the child process */ - rgchAbsPathName = &absPathBuf[0]; - dwFileLength = strlen( rgchChildFile ); - - dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName ); - if( dwDirLength == 0 ) - { - dwError = GetLastError(); - Fail( "GetCurrentDirectory call failed with error code %d\n", - dwError ); - } - - dwSize = mkAbsoluteFilename( rgchDirName, - dwDirLength, - rgchChildFile, - dwFileLength, - rgchAbsPathName ); - if( dwSize == 0 ) - { - Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ", - "not build absolute path name to file\n. Exiting.\n" ); - } - - /* launch the child process */ - if( !CreateProcess( NULL, /* module name to execute */ - rgchAbsPathName, /* command line */ - NULL, /* process handle not */ - /* inheritable */ - NULL, /* thread handle not */ - /* inheritable */ - FALSE, /* handle inheritance */ - CREATE_NEW_CONSOLE, /* dwCreationFlags */ - NULL, /* use parent's environment */ - NULL, /* use parent's starting */ - /* directory */ - &si, /* startup info struct */ - &pi ) /* process info struct */ - ) - { - dwError = GetLastError(); - Fail( "CreateProcess call failed with error code %d\n", - dwError ); - } - - /* wait for the child process to complete */ - WaitForSingleObject ( pi.hProcess, INFINITE ); - - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) - { - dwError = GetLastError(); - CloseHandle ( pi.hProcess ); - CloseHandle ( pi.hThread ); - Fail( "GetExitCodeProcess call failed with error code %d\n", - dwError ); - } - - /* close process and thread handle */ - CloseHandle ( pi.hProcess ); - CloseHandle ( pi.hThread ); - - /* check for the expected exit code */ - /* exit code for some systems is as small as a char, so that's all */ - /* we'll compare for checking success */ - if( LOBYTE(LOWORD(dwExitCode)) != LOBYTE(LOWORD(dwExpected)) ) - { - Fail( "GetExitCodeProcess returned an incorrect exit code %d, " - "expected value is %d\n", - LOWORD(dwExitCode), dwExpected ); - } - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test2/test2.cpp b/src/pal/tests/palsuite/threading/ExitThread/test2/test2.cpp new file mode 100644 index 0000000000..c31af8a079 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ExitThread/test2/test2.cpp @@ -0,0 +1,168 @@ +// 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: test2.c +** +** Purpose: Test to ensure ExitThread() called from the last thread of +** a process shuts down that process and returns the proper +** exit code as specified in the ExitThread() call. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** ZeroMemory +** GetCurrentDirectoryW +** CreateProcessW +** WaitForSingleObject +** GetLastError +** strlen +** strncpy +** + +** +**===========================================================================*/ +#include +#include "myexitcode.h" + + +static const char* rgchPathDelim = "\\"; + + +int +mkAbsoluteFilename( LPSTR dirName, + DWORD dwDirLength, + LPCSTR fileName, + DWORD dwFileLength, + LPSTR absPathName ) +{ + DWORD sizeDN, sizeFN, sizeAPN; + + sizeDN = strlen( dirName ); + sizeFN = strlen( fileName ); + sizeAPN = (sizeDN + 1 + sizeFN + 1); + + /* ensure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ + if( sizeAPN > _MAX_PATH ) + { + return ( 0 ); + } + + strncpy( absPathName, dirName, dwDirLength +1 ); + strncpy( absPathName, rgchPathDelim, 2 ); + strncpy( absPathName, fileName, dwFileLength +1 ); + + return (sizeAPN); + +} + + +int __cdecl main( int argc, char **argv ) + +{ + const char* rgchChildFile = "childprocess"; + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + DWORD dwError; + DWORD dwExitCode; + DWORD dwFileLength; + DWORD dwDirLength; + DWORD dwSize; + DWORD dwExpected = TEST_EXIT_CODE; + + char rgchDirName[_MAX_DIR]; + char absPathBuf[_MAX_PATH]; + char* rgchAbsPathName; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* zero our process and startup info structures */ + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof( si ); + ZeroMemory( &pi, sizeof(pi) ); + + /* build the absolute path to the child process */ + rgchAbsPathName = &absPathBuf[0]; + dwFileLength = strlen( rgchChildFile ); + + dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName ); + if( dwDirLength == 0 ) + { + dwError = GetLastError(); + Fail( "GetCurrentDirectory call failed with error code %d\n", + dwError ); + } + + dwSize = mkAbsoluteFilename( rgchDirName, + dwDirLength, + rgchChildFile, + dwFileLength, + rgchAbsPathName ); + if( dwSize == 0 ) + { + Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ", + "not build absolute path name to file\n. Exiting.\n" ); + } + + /* launch the child process */ + if( !CreateProcess( NULL, /* module name to execute */ + rgchAbsPathName, /* command line */ + NULL, /* process handle not */ + /* inheritable */ + NULL, /* thread handle not */ + /* inheritable */ + FALSE, /* handle inheritance */ + CREATE_NEW_CONSOLE, /* dwCreationFlags */ + NULL, /* use parent's environment */ + NULL, /* use parent's starting */ + /* directory */ + &si, /* startup info struct */ + &pi ) /* process info struct */ + ) + { + dwError = GetLastError(); + Fail( "CreateProcess call failed with error code %d\n", + dwError ); + } + + /* wait for the child process to complete */ + WaitForSingleObject ( pi.hProcess, INFINITE ); + + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) + { + dwError = GetLastError(); + CloseHandle ( pi.hProcess ); + CloseHandle ( pi.hThread ); + Fail( "GetExitCodeProcess call failed with error code %d\n", + dwError ); + } + + /* close process and thread handle */ + CloseHandle ( pi.hProcess ); + CloseHandle ( pi.hThread ); + + /* check for the expected exit code */ + /* exit code for some systems is as small as a char, so that's all */ + /* we'll compare for checking success */ + if( LOBYTE(LOWORD(dwExitCode)) != LOBYTE(LOWORD(dwExpected)) ) + { + Fail( "GetExitCodeProcess returned an incorrect exit code %d, " + "expected value is %d\n", + LOWORD(dwExitCode), dwExpected ); + } + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test3/dllmain.c b/src/pal/tests/palsuite/threading/ExitThread/test3/dllmain.c deleted file mode 100644 index 923650d1d3..0000000000 --- a/src/pal/tests/palsuite/threading/ExitThread/test3/dllmain.c +++ /dev/null @@ -1,65 +0,0 @@ -// 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: dllmain.c -** -** Purpose: Test to ensure DllMain() is called with THREAD_DETACH -** when a thread in the application calls ExitThread(). -** -** Dependencies: none -** - -** -**===========================================================================*/ - -#include - -/* count of the number of times DllMain() was called with THREAD_DETACH */ -static int g_detachCount = 0; - - -/* standard DllMain() */ -BOOL PALAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) -{ - switch( reason ) - { - case DLL_PROCESS_ATTACH: - { - break; - } - - case DLL_PROCESS_DETACH: - { - break; - } - - case DLL_THREAD_ATTACH: - break; - - case DLL_THREAD_DETACH: - /* increment g_detachCount */ - g_detachCount++; - break; - } - return TRUE; -} - -#ifdef WIN32 -BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - return DllMain(hinstDLL, fdwReason, lpvReserved); -} -#endif - - -/* function to return the current detach count */ -#ifdef WIN32 -__declspec(dllexport) -#endif -int PALAPI GetDetachCount( void ) -{ - return g_detachCount; -} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test3/dllmain.cpp b/src/pal/tests/palsuite/threading/ExitThread/test3/dllmain.cpp new file mode 100644 index 0000000000..923650d1d3 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ExitThread/test3/dllmain.cpp @@ -0,0 +1,65 @@ +// 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: dllmain.c +** +** Purpose: Test to ensure DllMain() is called with THREAD_DETACH +** when a thread in the application calls ExitThread(). +** +** Dependencies: none +** + +** +**===========================================================================*/ + +#include + +/* count of the number of times DllMain() was called with THREAD_DETACH */ +static int g_detachCount = 0; + + +/* standard DllMain() */ +BOOL PALAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID lpvReserved) +{ + switch( reason ) + { + case DLL_PROCESS_ATTACH: + { + break; + } + + case DLL_PROCESS_DETACH: + { + break; + } + + case DLL_THREAD_ATTACH: + break; + + case DLL_THREAD_DETACH: + /* increment g_detachCount */ + g_detachCount++; + break; + } + return TRUE; +} + +#ifdef WIN32 +BOOL __stdcall _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + return DllMain(hinstDLL, fdwReason, lpvReserved); +} +#endif + + +/* function to return the current detach count */ +#ifdef WIN32 +__declspec(dllexport) +#endif +int PALAPI GetDetachCount( void ) +{ + return g_detachCount; +} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test3/test3.c b/src/pal/tests/palsuite/threading/ExitThread/test3/test3.c deleted file mode 100644 index 8a71c7cc99..0000000000 --- a/src/pal/tests/palsuite/threading/ExitThread/test3/test3.c +++ /dev/null @@ -1,162 +0,0 @@ -// 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: test3.c -** -** Purpose: Test to ensure ExitThread() results in any loaded dynamic -** libraries having their entry point called with a THREAD_DETACH -** notification. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** GetCurrentDirectoryW -** CreateThread -** ResumeThread -** LoadLibrary -** FreeLibrary -** GetProcAddress -** WaitForSingleObject -** GetLastError -** strlen -** strncpy -** - -** -**===========================================================================*/ -#include - -/* SHLEXT is defined only for Unix variants */ - -#if defined(SHLEXT) -#define rgchLibraryFile "dllmain"SHLEXT -#define szFunction "GetDetachCount" -#else -#define rgchLibraryFile "dllmain" -#define szFunction "_GetDetachCount@0" -#endif - -/* define our test function type */ -typedef int ( PALAPI *LPTESTFUNC )( void ); - - -/** - * ThreadFunc - * - * Dummy thread function for causing DLL thread notifications. - */ -DWORD PALAPI ThreadFunc( LPVOID param ) -{ - /* simulate some brief "work" */ - int i; - for( i=0; i<100000; i++ ) - ; - - ExitThread( 0 ); - return (0); -} - - -/* main program entry point */ -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - - HANDLE hLib = NULL; - LPTESTFUNC pFunc; - int detachCount1 = 0; - int detachCount2 = 0; - - HANDLE hThread = NULL; - DWORD IDThread; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* Load the test library */ - hLib = LoadLibrary( rgchLibraryFile ); - if(hLib == NULL) - { - Fail("ERROR: Unable to load library %s\n", rgchLibraryFile ); - } - - - /* Get the address of our test function in the dll */ - pFunc = (LPTESTFUNC)GetProcAddress( hLib, szFunction ); - if( pFunc == NULL ) - { - Trace( "ERROR:%lu%:Unable to load function \"%s\" library \"%s\"\n", - GetLastError(), - szFunction, - rgchLibraryFile ); - if( ! FreeLibrary( hLib ) ) { - Trace( "FreeLibrary() failed with error code %lu\n", - GetLastError() ); - } - Fail( "Exiting\n" ); - } - - /* Execute the test function to get the detach count */ - detachCount1 = pFunc(); - - /* run another dummy thread to cause notification of the library */ - hThread = CreateThread( NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ - (LPVOID) NULL, /* pass thread index as */ - /* function argument */ - CREATE_SUSPENDED, /* create suspended */ - &IDThread ); /* returns thread id */ - - /* Check the return value for success. */ - if( hThread == NULL ) - { - /* error creating thread */ - Trace( "Unexpected CreateThread error %d\n", - GetLastError() ); - if( ! FreeLibrary( hLib ) ) { - Trace( "FreeLibrary() failed with error code %lu\n", - GetLastError() ); - } - Fail( "Exiting\n" ); - } - - /* Resume the suspended thread */ - ResumeThread( hThread ); - - /* wait for the thread to complete */ - WaitForSingleObject( hThread, INFINITE ); - - /* Execute the test function to get the new detach count */ - detachCount2 = pFunc(); - - /* Unload the test library */ - if( !FreeLibrary( hLib ) ) - { - Fail( "ERROR:%u: Unable to free library \"%s\"\n", - GetLastError(), - rgchLibraryFile ); - } - - /* validate the result */ - if( detachCount2 != (detachCount1 + 1) ) - { - Fail( "FAIL: unexpected DLL detach count %d, expected %d\n", - detachCount2, - (detachCount1 + 1) ); - } - - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/ExitThread/test3/test3.cpp b/src/pal/tests/palsuite/threading/ExitThread/test3/test3.cpp new file mode 100644 index 0000000000..8a71c7cc99 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ExitThread/test3/test3.cpp @@ -0,0 +1,162 @@ +// 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: test3.c +** +** Purpose: Test to ensure ExitThread() results in any loaded dynamic +** libraries having their entry point called with a THREAD_DETACH +** notification. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** GetCurrentDirectoryW +** CreateThread +** ResumeThread +** LoadLibrary +** FreeLibrary +** GetProcAddress +** WaitForSingleObject +** GetLastError +** strlen +** strncpy +** + +** +**===========================================================================*/ +#include + +/* SHLEXT is defined only for Unix variants */ + +#if defined(SHLEXT) +#define rgchLibraryFile "dllmain"SHLEXT +#define szFunction "GetDetachCount" +#else +#define rgchLibraryFile "dllmain" +#define szFunction "_GetDetachCount@0" +#endif + +/* define our test function type */ +typedef int ( PALAPI *LPTESTFUNC )( void ); + + +/** + * ThreadFunc + * + * Dummy thread function for causing DLL thread notifications. + */ +DWORD PALAPI ThreadFunc( LPVOID param ) +{ + /* simulate some brief "work" */ + int i; + for( i=0; i<100000; i++ ) + ; + + ExitThread( 0 ); + return (0); +} + + +/* main program entry point */ +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + + HANDLE hLib = NULL; + LPTESTFUNC pFunc; + int detachCount1 = 0; + int detachCount2 = 0; + + HANDLE hThread = NULL; + DWORD IDThread; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* Load the test library */ + hLib = LoadLibrary( rgchLibraryFile ); + if(hLib == NULL) + { + Fail("ERROR: Unable to load library %s\n", rgchLibraryFile ); + } + + + /* Get the address of our test function in the dll */ + pFunc = (LPTESTFUNC)GetProcAddress( hLib, szFunction ); + if( pFunc == NULL ) + { + Trace( "ERROR:%lu%:Unable to load function \"%s\" library \"%s\"\n", + GetLastError(), + szFunction, + rgchLibraryFile ); + if( ! FreeLibrary( hLib ) ) { + Trace( "FreeLibrary() failed with error code %lu\n", + GetLastError() ); + } + Fail( "Exiting\n" ); + } + + /* Execute the test function to get the detach count */ + detachCount1 = pFunc(); + + /* run another dummy thread to cause notification of the library */ + hThread = CreateThread( NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ + (LPVOID) NULL, /* pass thread index as */ + /* function argument */ + CREATE_SUSPENDED, /* create suspended */ + &IDThread ); /* returns thread id */ + + /* Check the return value for success. */ + if( hThread == NULL ) + { + /* error creating thread */ + Trace( "Unexpected CreateThread error %d\n", + GetLastError() ); + if( ! FreeLibrary( hLib ) ) { + Trace( "FreeLibrary() failed with error code %lu\n", + GetLastError() ); + } + Fail( "Exiting\n" ); + } + + /* Resume the suspended thread */ + ResumeThread( hThread ); + + /* wait for the thread to complete */ + WaitForSingleObject( hThread, INFINITE ); + + /* Execute the test function to get the new detach count */ + detachCount2 = pFunc(); + + /* Unload the test library */ + if( !FreeLibrary( hLib ) ) + { + Fail( "ERROR:%u: Unable to free library \"%s\"\n", + GetLastError(), + rgchLibraryFile ); + } + + /* validate the result */ + if( detachCount2 != (detachCount1 + 1) ) + { + Fail( "FAIL: unexpected DLL detach count %d, expected %d\n", + detachCount2, + (detachCount1 + 1) ); + } + + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/CMakeLists.txt index 44105348be..af4746bcb4 100644 --- a/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - process.c + process.cpp ) add_executable(paltest_getcurrentprocess_test1 diff --git a/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/process.c b/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/process.c deleted file mode 100644 index 17d9af6282..0000000000 --- a/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/process.c +++ /dev/null @@ -1,40 +0,0 @@ -// 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: GetCurrentProcess/test1/process.c -** -** Purpose: Test for to see if the process GetCurrentProcess -** returns a handle to the current process or not. -** -** Dependencies: TerminateProcess -** -** -**=========================================================*/ - -#include - -INT __cdecl main( int argc, char **argv ) -{ - - HANDLE hProcess; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - hProcess = GetCurrentProcess(); - Trace ("Testing the handle returned by GetCurrentProcess\n"); - if ( 0 == ( TerminateProcess ( hProcess, PASS ) ) ) - { - Fail ("Testing GetCurrentProcess, the TerminateProcess function " - "failed.\n"); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/process.cpp b/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/process.cpp new file mode 100644 index 0000000000..17d9af6282 --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetCurrentProcess/test1/process.cpp @@ -0,0 +1,40 @@ +// 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: GetCurrentProcess/test1/process.c +** +** Purpose: Test for to see if the process GetCurrentProcess +** returns a handle to the current process or not. +** +** Dependencies: TerminateProcess +** +** +**=========================================================*/ + +#include + +INT __cdecl main( int argc, char **argv ) +{ + + HANDLE hProcess; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + hProcess = GetCurrentProcess(); + Trace ("Testing the handle returned by GetCurrentProcess\n"); + if ( 0 == ( TerminateProcess ( hProcess, PASS ) ) ) + { + Fail ("Testing GetCurrentProcess, the TerminateProcess function " + "failed.\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/CMakeLists.txt index e5c31e6af2..523320a53c 100644 --- a/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - processId.c + processId.cpp ) add_executable(paltest_getcurrentprocessid_test1 diff --git a/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/processId.c b/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/processId.c deleted file mode 100644 index cc689b3f8b..0000000000 --- a/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/processId.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: getcurrentprocessid/test1/processid.c -** -** Purpose: Test to ensure GetCurrentProcessId returns the current -** process id number. This test compares the result of -** GetCurrentProcessId to getpid. -** -** -**=========================================================*/ - -#include - -INT __cdecl main( int argc, char **argv ) -{ - - DWORD dwProcessId; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - dwProcessId = GetCurrentProcessId(); - - if ( 0 >= dwProcessId ) - { - Fail ("%s has dwProcessId has id value %d\n", argv[0], - dwProcessId ); - } - Trace ("%s has dwProcessId %d\nPassing test as dwProcessId is > 0\n" - , argv[0], dwProcessId); - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/processId.cpp b/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/processId.cpp new file mode 100644 index 0000000000..cc689b3f8b --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetCurrentProcessId/test1/processId.cpp @@ -0,0 +1,41 @@ +// 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: getcurrentprocessid/test1/processid.c +** +** Purpose: Test to ensure GetCurrentProcessId returns the current +** process id number. This test compares the result of +** GetCurrentProcessId to getpid. +** +** +**=========================================================*/ + +#include + +INT __cdecl main( int argc, char **argv ) +{ + + DWORD dwProcessId; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + dwProcessId = GetCurrentProcessId(); + + if ( 0 >= dwProcessId ) + { + Fail ("%s has dwProcessId has id value %d\n", argv[0], + dwProcessId ); + } + Trace ("%s has dwProcessId %d\nPassing test as dwProcessId is > 0\n" + , argv[0], dwProcessId); + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/CMakeLists.txt index 84cbccbca0..23af2edbca 100644 --- a/src/pal/tests/palsuite/threading/GetCurrentThread/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - thread.c + thread.cpp ) add_executable(paltest_getcurrentthread_test1 diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.c b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.c deleted file mode 100644 index b2bb97fd67..0000000000 --- a/src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.c +++ /dev/null @@ -1,93 +0,0 @@ -// 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: GetCurrentThread/test1/thread.c -** -** Purpose: Test to ensure GetCurrentThread returns a handle to -** the current thread. -** -** Dependencies: GetThreadPriority -** SetThreadPriority -** Fail -** Trace -** - -** -**=========================================================*/ - -#include - -int __cdecl main( int argc, char **argv ) -{ - - HANDLE hThread; - int nPriority; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - -#if !HAVE_SCHED_OTHER_ASSIGNABLE - /* Defining thread priority for SCHED_OTHER is implementation defined. - Some platforms like NetBSD cannot reassign it as they are dynamic. - */ - printf("paltest_getcurrentthread_test1 has been disabled on this platform\n"); -#else - hThread = GetCurrentThread(); - - nPriority = GetThreadPriority(hThread); - - if ( THREAD_PRIORITY_NORMAL != nPriority ) - { - if ( THREAD_PRIORITY_ERROR_RETURN == nPriority ) - { - Fail ("GetThreadPriority function call failed for %s\n" - "GetLastError returned %d\n", argv[0], GetLastError()); - } - else - { - Fail ("GetThreadPriority function call failed for %s\n" - "The priority returned was %d\n", argv[0], nPriority); - } - } - else - { - nPriority = 0; - - if (0 == SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST)) - { - Fail ("Unable to set thread priority. Either handle doesn't" - " point to current thread \nor SetThreadPriority " - "function failed. Failing test.\n"); - } - - nPriority = GetThreadPriority(hThread); - - if ( THREAD_PRIORITY_ERROR_RETURN == nPriority ) - { - Fail ("GetThreadPriority function call failed for %s\n" - "GetLastError returned %d\n", argv[0], GetLastError()); - } - else if ( THREAD_PRIORITY_HIGHEST == nPriority ) - { - Trace ("GetCurrentThread returns handle to the current " - "thread.\n"); - exit ( PASS ); - } - else - { - Fail ("Unable to set thread priority. Either handle doesn't" - " point to current thread \nor SetThreadPriority " - "function failed. Failing test.\n"); - } - } -#endif - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.cpp b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.cpp new file mode 100644 index 0000000000..b2bb97fd67 --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.cpp @@ -0,0 +1,93 @@ +// 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: GetCurrentThread/test1/thread.c +** +** Purpose: Test to ensure GetCurrentThread returns a handle to +** the current thread. +** +** Dependencies: GetThreadPriority +** SetThreadPriority +** Fail +** Trace +** + +** +**=========================================================*/ + +#include + +int __cdecl main( int argc, char **argv ) +{ + + HANDLE hThread; + int nPriority; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + +#if !HAVE_SCHED_OTHER_ASSIGNABLE + /* Defining thread priority for SCHED_OTHER is implementation defined. + Some platforms like NetBSD cannot reassign it as they are dynamic. + */ + printf("paltest_getcurrentthread_test1 has been disabled on this platform\n"); +#else + hThread = GetCurrentThread(); + + nPriority = GetThreadPriority(hThread); + + if ( THREAD_PRIORITY_NORMAL != nPriority ) + { + if ( THREAD_PRIORITY_ERROR_RETURN == nPriority ) + { + Fail ("GetThreadPriority function call failed for %s\n" + "GetLastError returned %d\n", argv[0], GetLastError()); + } + else + { + Fail ("GetThreadPriority function call failed for %s\n" + "The priority returned was %d\n", argv[0], nPriority); + } + } + else + { + nPriority = 0; + + if (0 == SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST)) + { + Fail ("Unable to set thread priority. Either handle doesn't" + " point to current thread \nor SetThreadPriority " + "function failed. Failing test.\n"); + } + + nPriority = GetThreadPriority(hThread); + + if ( THREAD_PRIORITY_ERROR_RETURN == nPriority ) + { + Fail ("GetThreadPriority function call failed for %s\n" + "GetLastError returned %d\n", argv[0], GetLastError()); + } + else if ( THREAD_PRIORITY_HIGHEST == nPriority ) + { + Trace ("GetCurrentThread returns handle to the current " + "thread.\n"); + exit ( PASS ); + } + else + { + Fail ("Unable to set thread priority. Either handle doesn't" + " point to current thread \nor SetThreadPriority " + "function failed. Failing test.\n"); + } + } +#endif + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/CMakeLists.txt index 3fc3c3e7c6..9da2d075b2 100644 --- a/src/pal/tests/palsuite/threading/GetCurrentThread/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_getcurrentthread_test2 diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.c b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.c deleted file mode 100644 index beeb5ec241..0000000000 --- a/src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.c +++ /dev/null @@ -1,144 +0,0 @@ -// 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: test2.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** CreateThread -** SetThreadPriority -** GetThreadPriority -** ResumeThread -** WaitForSingleObject -** GetLastError -** -** Purpose: -** -** Test to ensure proper operation of the GetCurrentThread() -** API. The test launches a thread in suspended mode, and sets -** its priority to a non-default value using the handle returned -** by CreateThread(). The new thread calls GetCurrentThred() to -** retrieve a handle to itself, and calls GetThreadPriority() -** to verify that its priority matches what it was set to on -** the main execution thread. -** - -** -**===========================================================================*/ -#include - - -/* we store the return code from the child thread here because */ -/* we're missing the GetExitCodeThread() API */ - -static int g_priority = 0; - -/** - * ThreadFunc - * - * Thread function that calls GetCurrentThread() to get a pseudo-handle - * to itself, then checks its priority and exits with that value. - */ -DWORD PALAPI ThreadFunc( LPVOID param ) -{ - int priority; - HANDLE hThread; - - /* call GetCurrentThread() to get a pseudo-handle to */ - /* the current thread */ - hThread = GetCurrentThread(); - if( hThread == NULL ) - { - Fail( "GetCurrentThread() call failed\n" ); - } - - - /* get the current thread priority */ - priority = GetThreadPriority( hThread ); - if( priority == THREAD_PRIORITY_ERROR_RETURN ) - { - /* GetThreadPriority call failed */ - Fail( "ERROR:%lu:GetThreadPriority() call failed\n", GetLastError() ); - } - - /* store this globally because we don't have GetExitCodeThread() */ - g_priority = priority; - return (DWORD)priority; -} - - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - HANDLE hThread = NULL; - DWORD IDThread; - DWORD dwRet; - - SIZE_T i = 0; - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - -#if !HAVE_SCHED_OTHER_ASSIGNABLE - /* Defining thread priority for SCHED_OTHER is implementation defined. - Some platforms like NetBSD cannot reassign it as they are dynamic. - */ - printf("paltest_getcurrentthread_test2 has been disabled on this platform\n"); -#else - /* Create multiple threads. */ - hThread = CreateThread( NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ - (LPVOID) i, /* pass thread index as */ - /* function argument */ - CREATE_SUSPENDED, /* create suspended */ - &IDThread ); /* returns thread identifier */ - - /* Check the return value for success. */ - if( hThread == NULL ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateThread failed\n", GetLastError() ); - } - - /* set the thread priority of the new thread to the highest value */ - if( ! SetThreadPriority( hThread, THREAD_PRIORITY_TIME_CRITICAL) ) - { - Fail( "ERROR:%lu:SetThreadPriority() call failed\n", GetLastError() ); - } - - /* let the child thread run now */ - ResumeThread( hThread ); - - - /* wait for the thread to finish */ - dwRet = WaitForSingleObject( hThread, INFINITE ); - if( dwRet == WAIT_FAILED ) - { - /* ERROR */ - Fail( "ERROR:%lu:WaitForSingleObject call failed\n", GetLastError() ); - } - - /* validate the thread's exit code */ - if( g_priority != THREAD_PRIORITY_TIME_CRITICAL ) - { - /* ERROR */ - Fail( "FAIL:Unexpected thread priority %d returned, expected %d\n", - g_priority, THREAD_PRIORITY_TIME_CRITICAL ); - } -#endif - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.cpp b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.cpp new file mode 100644 index 0000000000..beeb5ec241 --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.cpp @@ -0,0 +1,144 @@ +// 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: test2.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** CreateThread +** SetThreadPriority +** GetThreadPriority +** ResumeThread +** WaitForSingleObject +** GetLastError +** +** Purpose: +** +** Test to ensure proper operation of the GetCurrentThread() +** API. The test launches a thread in suspended mode, and sets +** its priority to a non-default value using the handle returned +** by CreateThread(). The new thread calls GetCurrentThred() to +** retrieve a handle to itself, and calls GetThreadPriority() +** to verify that its priority matches what it was set to on +** the main execution thread. +** + +** +**===========================================================================*/ +#include + + +/* we store the return code from the child thread here because */ +/* we're missing the GetExitCodeThread() API */ + +static int g_priority = 0; + +/** + * ThreadFunc + * + * Thread function that calls GetCurrentThread() to get a pseudo-handle + * to itself, then checks its priority and exits with that value. + */ +DWORD PALAPI ThreadFunc( LPVOID param ) +{ + int priority; + HANDLE hThread; + + /* call GetCurrentThread() to get a pseudo-handle to */ + /* the current thread */ + hThread = GetCurrentThread(); + if( hThread == NULL ) + { + Fail( "GetCurrentThread() call failed\n" ); + } + + + /* get the current thread priority */ + priority = GetThreadPriority( hThread ); + if( priority == THREAD_PRIORITY_ERROR_RETURN ) + { + /* GetThreadPriority call failed */ + Fail( "ERROR:%lu:GetThreadPriority() call failed\n", GetLastError() ); + } + + /* store this globally because we don't have GetExitCodeThread() */ + g_priority = priority; + return (DWORD)priority; +} + + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + HANDLE hThread = NULL; + DWORD IDThread; + DWORD dwRet; + + SIZE_T i = 0; + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + +#if !HAVE_SCHED_OTHER_ASSIGNABLE + /* Defining thread priority for SCHED_OTHER is implementation defined. + Some platforms like NetBSD cannot reassign it as they are dynamic. + */ + printf("paltest_getcurrentthread_test2 has been disabled on this platform\n"); +#else + /* Create multiple threads. */ + hThread = CreateThread( NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ + (LPVOID) i, /* pass thread index as */ + /* function argument */ + CREATE_SUSPENDED, /* create suspended */ + &IDThread ); /* returns thread identifier */ + + /* Check the return value for success. */ + if( hThread == NULL ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateThread failed\n", GetLastError() ); + } + + /* set the thread priority of the new thread to the highest value */ + if( ! SetThreadPriority( hThread, THREAD_PRIORITY_TIME_CRITICAL) ) + { + Fail( "ERROR:%lu:SetThreadPriority() call failed\n", GetLastError() ); + } + + /* let the child thread run now */ + ResumeThread( hThread ); + + + /* wait for the thread to finish */ + dwRet = WaitForSingleObject( hThread, INFINITE ); + if( dwRet == WAIT_FAILED ) + { + /* ERROR */ + Fail( "ERROR:%lu:WaitForSingleObject call failed\n", GetLastError() ); + } + + /* validate the thread's exit code */ + if( g_priority != THREAD_PRIORITY_TIME_CRITICAL ) + { + /* ERROR */ + Fail( "FAIL:Unexpected thread priority %d returned, expected %d\n", + g_priority, THREAD_PRIORITY_TIME_CRITICAL ); + } +#endif + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/CMakeLists.txt index 490bff8f5f..a0824ab9a2 100644 --- a/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - threadId.c + threadId.cpp ) add_executable(paltest_getcurrentthreadid_test1 diff --git a/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.c b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.c deleted file mode 100644 index acbb1ff373..0000000000 --- a/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.c +++ /dev/null @@ -1,82 +0,0 @@ -// 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: getcurrentthreadid/test1/threadid.c -** -** Purpose: Test to ensure GetCurrentThreadId returns the threadId of the -** current thread. -** -** Dependencies: CloseHandle -** WaitForSingleObject -** CreateThread -** - -** -**=========================================================*/ - - -#include - -DWORD dwThreadIdTF; - -DWORD PALAPI ThreadFunction ( LPVOID lpParam ) -{ - Trace ("thread code executed\n"); - dwThreadIdTF = GetCurrentThreadId(); - return 0; -} - -int __cdecl main( int argc, char **argv ) -{ - extern DWORD dwThreadIdTF; - DWORD dwThreadIdCT; - HANDLE hThread; - DWORD dwThreadParam = 1; - DWORD dwThreadWait; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - hThread = CreateThread( - NULL, - 0, - ThreadFunction, - &dwThreadParam, - 0, - &dwThreadIdCT); - - if ( NULL == hThread ) - { - Fail ( "CreateThread() call failed - returned NULL"); - } - else - { - dwThreadWait = WaitForSingleObject( hThread, INFINITE ); - - Trace ("dwThreadWait returned %d\n", dwThreadWait ); - - if ( dwThreadIdCT == dwThreadIdTF ) - { - Trace ( "ThreadId numbers match - GetCurrentThreadId" - " works. dwThreadIdCT == dwThreadIdTF == %d\n", - dwThreadIdTF ); - PAL_Terminate(); - return ( PASS ); - } - else - { - Fail ( "ThreadId numbers don't match - " - "GetCurrentThreadId fails dwThreadIdCT = %d " - "and dwThreadIdTF = %d\n", dwThreadIdCT, dwThreadIdTF); - } - } - - PAL_TerminateEx(FAIL); - return (FAIL); - -} diff --git a/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.cpp b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.cpp new file mode 100644 index 0000000000..acbb1ff373 --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.cpp @@ -0,0 +1,82 @@ +// 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: getcurrentthreadid/test1/threadid.c +** +** Purpose: Test to ensure GetCurrentThreadId returns the threadId of the +** current thread. +** +** Dependencies: CloseHandle +** WaitForSingleObject +** CreateThread +** + +** +**=========================================================*/ + + +#include + +DWORD dwThreadIdTF; + +DWORD PALAPI ThreadFunction ( LPVOID lpParam ) +{ + Trace ("thread code executed\n"); + dwThreadIdTF = GetCurrentThreadId(); + return 0; +} + +int __cdecl main( int argc, char **argv ) +{ + extern DWORD dwThreadIdTF; + DWORD dwThreadIdCT; + HANDLE hThread; + DWORD dwThreadParam = 1; + DWORD dwThreadWait; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + hThread = CreateThread( + NULL, + 0, + ThreadFunction, + &dwThreadParam, + 0, + &dwThreadIdCT); + + if ( NULL == hThread ) + { + Fail ( "CreateThread() call failed - returned NULL"); + } + else + { + dwThreadWait = WaitForSingleObject( hThread, INFINITE ); + + Trace ("dwThreadWait returned %d\n", dwThreadWait ); + + if ( dwThreadIdCT == dwThreadIdTF ) + { + Trace ( "ThreadId numbers match - GetCurrentThreadId" + " works. dwThreadIdCT == dwThreadIdTF == %d\n", + dwThreadIdTF ); + PAL_Terminate(); + return ( PASS ); + } + else + { + Fail ( "ThreadId numbers don't match - " + "GetCurrentThreadId fails dwThreadIdCT = %d " + "and dwThreadIdTF = %d\n", dwThreadIdCT, dwThreadIdTF); + } + } + + PAL_TerminateEx(FAIL); + return (FAIL); + +} diff --git a/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/CMakeLists.txt index adddd97e6d..1ef9db2299 100644 --- a/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test1.c + test1.cpp ) add_executable(paltest_getexitcodeprocess_test1 @@ -20,7 +20,7 @@ target_link_libraries(paltest_getexitcodeprocess_test1 set(HELPERSOURCES - childProcess.c + childProcess.cpp ) add_executable(paltest_getexitcodeprocess_test1_child diff --git a/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/childProcess.c b/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/childProcess.c deleted file mode 100644 index fe1b38fb31..0000000000 --- a/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/childProcess.c +++ /dev/null @@ -1,31 +0,0 @@ -// 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: childprocess.c -** -** Purpose: Test to ensure GetExitCodeProcess returns the right -** value. All this program does is return a predefined value. -** -** Dependencies: none -** - -** -**=========================================================*/ - -#include -#include "myexitcode.h" - -int __cdecl main( int argc, char **argv ) -{ - int i; - - // simulate some activity - for( i=0; i<10000; i++ ) - ; - - // return the predefined exit code - return TEST_EXIT_CODE; -} diff --git a/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/childProcess.cpp b/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/childProcess.cpp new file mode 100644 index 0000000000..fe1b38fb31 --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/childProcess.cpp @@ -0,0 +1,31 @@ +// 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: childprocess.c +** +** Purpose: Test to ensure GetExitCodeProcess returns the right +** value. All this program does is return a predefined value. +** +** Dependencies: none +** + +** +**=========================================================*/ + +#include +#include "myexitcode.h" + +int __cdecl main( int argc, char **argv ) +{ + int i; + + // simulate some activity + for( i=0; i<10000; i++ ) + ; + + // return the predefined exit code + return TEST_EXIT_CODE; +} diff --git a/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/test1.c b/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/test1.c deleted file mode 100644 index 0f98cf8f57..0000000000 --- a/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/test1.c +++ /dev/null @@ -1,163 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure GetExitCodeProcess works properly. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** ZeroMemory -** GetCurrentDirectoryW -** CreateProcessW -** WaitForSingleObject -** GetLastError -** strlen -** strncpy -** - -** -**===========================================================================*/ -#include -#include "myexitcode.h" - - -static const char* rgchPathDelim = "\\"; - - -int -mkAbsoluteFilename( LPSTR dirName, - DWORD dwDirLength, - LPCSTR fileName, - DWORD dwFileLength, - LPSTR absPathName ) -{ - DWORD sizeDN, sizeFN, sizeAPN; - - sizeDN = strlen( dirName ); - sizeFN = strlen( fileName ); - sizeAPN = (sizeDN + 1 + sizeFN + 1); - - /* ensure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ - if( sizeAPN > _MAX_PATH ) - { - return ( 0 ); - } - - strncpy( absPathName, dirName, dwDirLength +1 ); - strncpy( absPathName, rgchPathDelim, 2 ); - strncpy( absPathName, fileName, dwFileLength +1 ); - - return (sizeAPN); - -} - - -int __cdecl main( int argc, char **argv ) - -{ - const char* rgchChildFile = "childprocess"; - - STARTUPINFO si; - PROCESS_INFORMATION pi; - - DWORD dwError; - DWORD dwExitCode; - DWORD dwFileLength; - DWORD dwDirLength; - DWORD dwSize; - - char rgchDirName[_MAX_DIR]; - char absPathBuf[_MAX_PATH]; - char* rgchAbsPathName; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* zero our process and startup info structures */ - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof( si ); - ZeroMemory( &pi, sizeof(pi) ); - - /* build the absolute path to the child process */ - rgchAbsPathName = &absPathBuf[0]; - dwFileLength = strlen( rgchChildFile ); - - dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName ); - if( dwDirLength == 0 ) - { - dwError = GetLastError(); - Fail( "GetCurrentDirectory call failed with error code %d\n", - dwError ); - } - - dwSize = mkAbsoluteFilename( rgchDirName, - dwDirLength, - rgchChildFile, - dwFileLength, - rgchAbsPathName ); - if( dwSize == 0 ) - { - Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ", - "not build absolute path name to file\n. Exiting.\n" ); - } - - /* launch the child process */ - if( !CreateProcess( NULL, /* module name to execute */ - rgchAbsPathName, /* command line */ - NULL, /* process handle not */ - /* inheritable */ - NULL, /* thread handle not */ - /* inheritable */ - FALSE, /* handle inheritance */ - CREATE_NEW_CONSOLE, /* dwCreationFlags */ - NULL, /* use parent's environment */ - NULL, /* use parent's starting */ - /* directory */ - &si, /* startup info struct */ - &pi ) /* process info struct */ - ) - { - dwError = GetLastError(); - Fail( "CreateProcess call failed with error code %d\n", - dwError ); - } - - /* wait for the child process to complete */ - WaitForSingleObject ( pi.hProcess, INFINITE ); - - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) - { - dwError = GetLastError(); - CloseHandle ( pi.hProcess ); - CloseHandle ( pi.hThread ); - Fail( "GetExitCodeProcess call failed with error code %d\n", - dwError ); - } - - /* close process and thread handle */ - CloseHandle ( pi.hProcess ); - CloseHandle ( pi.hThread ); - - /* check for the expected exit code */ - if( dwExitCode != TEST_EXIT_CODE ) - { - Fail( "GetExitCodeProcess returned an incorrect exit code %d, " - "expected value is %d\n", - dwExitCode, TEST_EXIT_CODE ); - } - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/test1.cpp b/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/test1.cpp new file mode 100644 index 0000000000..0f98cf8f57 --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetExitCodeProcess/test1/test1.cpp @@ -0,0 +1,163 @@ +// 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: test1.c +** +** Purpose: Test to ensure GetExitCodeProcess works properly. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** ZeroMemory +** GetCurrentDirectoryW +** CreateProcessW +** WaitForSingleObject +** GetLastError +** strlen +** strncpy +** + +** +**===========================================================================*/ +#include +#include "myexitcode.h" + + +static const char* rgchPathDelim = "\\"; + + +int +mkAbsoluteFilename( LPSTR dirName, + DWORD dwDirLength, + LPCSTR fileName, + DWORD dwFileLength, + LPSTR absPathName ) +{ + DWORD sizeDN, sizeFN, sizeAPN; + + sizeDN = strlen( dirName ); + sizeFN = strlen( fileName ); + sizeAPN = (sizeDN + 1 + sizeFN + 1); + + /* ensure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ + if( sizeAPN > _MAX_PATH ) + { + return ( 0 ); + } + + strncpy( absPathName, dirName, dwDirLength +1 ); + strncpy( absPathName, rgchPathDelim, 2 ); + strncpy( absPathName, fileName, dwFileLength +1 ); + + return (sizeAPN); + +} + + +int __cdecl main( int argc, char **argv ) + +{ + const char* rgchChildFile = "childprocess"; + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + DWORD dwError; + DWORD dwExitCode; + DWORD dwFileLength; + DWORD dwDirLength; + DWORD dwSize; + + char rgchDirName[_MAX_DIR]; + char absPathBuf[_MAX_PATH]; + char* rgchAbsPathName; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* zero our process and startup info structures */ + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof( si ); + ZeroMemory( &pi, sizeof(pi) ); + + /* build the absolute path to the child process */ + rgchAbsPathName = &absPathBuf[0]; + dwFileLength = strlen( rgchChildFile ); + + dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName ); + if( dwDirLength == 0 ) + { + dwError = GetLastError(); + Fail( "GetCurrentDirectory call failed with error code %d\n", + dwError ); + } + + dwSize = mkAbsoluteFilename( rgchDirName, + dwDirLength, + rgchChildFile, + dwFileLength, + rgchAbsPathName ); + if( dwSize == 0 ) + { + Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ", + "not build absolute path name to file\n. Exiting.\n" ); + } + + /* launch the child process */ + if( !CreateProcess( NULL, /* module name to execute */ + rgchAbsPathName, /* command line */ + NULL, /* process handle not */ + /* inheritable */ + NULL, /* thread handle not */ + /* inheritable */ + FALSE, /* handle inheritance */ + CREATE_NEW_CONSOLE, /* dwCreationFlags */ + NULL, /* use parent's environment */ + NULL, /* use parent's starting */ + /* directory */ + &si, /* startup info struct */ + &pi ) /* process info struct */ + ) + { + dwError = GetLastError(); + Fail( "CreateProcess call failed with error code %d\n", + dwError ); + } + + /* wait for the child process to complete */ + WaitForSingleObject ( pi.hProcess, INFINITE ); + + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) + { + dwError = GetLastError(); + CloseHandle ( pi.hProcess ); + CloseHandle ( pi.hThread ); + Fail( "GetExitCodeProcess call failed with error code %d\n", + dwError ); + } + + /* close process and thread handle */ + CloseHandle ( pi.hProcess ); + CloseHandle ( pi.hThread ); + + /* check for the expected exit code */ + if( dwExitCode != TEST_EXIT_CODE ) + { + Fail( "GetExitCodeProcess returned an incorrect exit code %d, " + "expected value is %d\n", + dwExitCode, TEST_EXIT_CODE ); + } + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/GetProcessTimes/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetProcessTimes/test2/CMakeLists.txt index 0ef7260204..8e905873e9 100644 --- a/src/pal/tests/palsuite/threading/GetProcessTimes/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/GetProcessTimes/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_getprocesstimes_test2 diff --git a/src/pal/tests/palsuite/threading/GetProcessTimes/test2/test2.c b/src/pal/tests/palsuite/threading/GetProcessTimes/test2/test2.c deleted file mode 100644 index 687facc584..0000000000 --- a/src/pal/tests/palsuite/threading/GetProcessTimes/test2/test2.c +++ /dev/null @@ -1,122 +0,0 @@ -// 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: test2.c -** -** Purpose: Test to ensure GetProcessTimes works properly. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** ZeroMemory -** CompareFileTime -** GetLastError -** - -** -**===========================================================================*/ -#include - - -int __cdecl main( int argc, char **argv ) - -{ - int i, j, k; - int *total; - - HANDLE hProcess; - FILETIME createTime; - FILETIME exitTime; - FILETIME kernelTime1; - FILETIME userTime1; - FILETIME kernelTime2; - FILETIME userTime2; - - DWORD dwError; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* get our own process handle */ - hProcess = GetCurrentProcess(); - if( hProcess == NULL ) - { - Fail( "GetCurrentProcess() returned a NULL handle.\n" ); - } - - /* zero our time structures */ - ZeroMemory( &createTime, sizeof(createTime) ); - ZeroMemory( &exitTime, sizeof(exitTime) ); - ZeroMemory( &kernelTime1, sizeof(kernelTime1) ); - ZeroMemory( &userTime1, sizeof(userTime1) ); - ZeroMemory( &kernelTime2, sizeof(kernelTime2) ); - ZeroMemory( &userTime2, sizeof(userTime2) ); - - /* check the process times for the child process */ - if( ! GetProcessTimes( hProcess, - &createTime, - &exitTime, - &kernelTime1, - &userTime1 ) ) - { - dwError = GetLastError(); - Fail( "GetProcessTimes() call failed with error code %d\n", - dwError ); - } - - - /* simulate some activity */ - for( i=0; i<1000; i++ ) - { - for( j=0; j<1000; j++ ) - { - /* do kernel work to increase system usage counters */ - total = malloc(1024 * 1024); - - *total = j * i; - for( k=0; k<1000; k++ ) - { - *total += k + i; - } - - free(total); - } - } - - /* check the process times for the child process */ - if( ! GetProcessTimes( hProcess, - &createTime, - &exitTime, - &kernelTime2, - &userTime2 ) ) - { - dwError = GetLastError(); - Fail( "GetProcessTimes() call failed with error code %d\n", - dwError ); - } - - - /* very simple logical checking of the results */ - if( CompareFileTime( &kernelTime1, &kernelTime2 ) > 0 ) - { - Fail( "Unexpected kernel time value reported.\n" ); - } - - if( CompareFileTime( &userTime1, &userTime2 ) > 0 ) - { - Fail( "Unexpected user time value reported.\n" ); - } - - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/GetProcessTimes/test2/test2.cpp b/src/pal/tests/palsuite/threading/GetProcessTimes/test2/test2.cpp new file mode 100644 index 0000000000..cc39de609b --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetProcessTimes/test2/test2.cpp @@ -0,0 +1,122 @@ +// 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: test2.c +** +** Purpose: Test to ensure GetProcessTimes works properly. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** ZeroMemory +** CompareFileTime +** GetLastError +** + +** +**===========================================================================*/ +#include + + +int __cdecl main( int argc, char **argv ) + +{ + int i, j, k; + int *total; + + HANDLE hProcess; + FILETIME createTime; + FILETIME exitTime; + FILETIME kernelTime1; + FILETIME userTime1; + FILETIME kernelTime2; + FILETIME userTime2; + + DWORD dwError; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* get our own process handle */ + hProcess = GetCurrentProcess(); + if( hProcess == NULL ) + { + Fail( "GetCurrentProcess() returned a NULL handle.\n" ); + } + + /* zero our time structures */ + ZeroMemory( &createTime, sizeof(createTime) ); + ZeroMemory( &exitTime, sizeof(exitTime) ); + ZeroMemory( &kernelTime1, sizeof(kernelTime1) ); + ZeroMemory( &userTime1, sizeof(userTime1) ); + ZeroMemory( &kernelTime2, sizeof(kernelTime2) ); + ZeroMemory( &userTime2, sizeof(userTime2) ); + + /* check the process times for the child process */ + if( ! GetProcessTimes( hProcess, + &createTime, + &exitTime, + &kernelTime1, + &userTime1 ) ) + { + dwError = GetLastError(); + Fail( "GetProcessTimes() call failed with error code %d\n", + dwError ); + } + + + /* simulate some activity */ + for( i=0; i<1000; i++ ) + { + for( j=0; j<1000; j++ ) + { + /* do kernel work to increase system usage counters */ + total = (int*)malloc(1024 * 1024); + + *total = j * i; + for( k=0; k<1000; k++ ) + { + *total += k + i; + } + + free(total); + } + } + + /* check the process times for the child process */ + if( ! GetProcessTimes( hProcess, + &createTime, + &exitTime, + &kernelTime2, + &userTime2 ) ) + { + dwError = GetLastError(); + Fail( "GetProcessTimes() call failed with error code %d\n", + dwError ); + } + + + /* very simple logical checking of the results */ + if( CompareFileTime( &kernelTime1, &kernelTime2 ) > 0 ) + { + Fail( "Unexpected kernel time value reported.\n" ); + } + + if( CompareFileTime( &userTime1, &userTime2 ) > 0 ) + { + Fail( "Unexpected user time value reported.\n" ); + } + + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/GetThreadTimes/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetThreadTimes/test1/CMakeLists.txt index d7e2eb2a88..aa4dad11ce 100644 --- a/src/pal/tests/palsuite/threading/GetThreadTimes/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/GetThreadTimes/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_getthreadtimes_test1 diff --git a/src/pal/tests/palsuite/threading/GetThreadTimes/test1/test1.c b/src/pal/tests/palsuite/threading/GetThreadTimes/test1/test1.c deleted file mode 100644 index 6b62c05ec7..0000000000 --- a/src/pal/tests/palsuite/threading/GetThreadTimes/test1/test1.c +++ /dev/null @@ -1,102 +0,0 @@ -// 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: -** -** Source : test1.c -** -** Purpose: Test for GetThreadTimes() function -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) { - int ret = FAIL; - - //Test is failing unreliably, so for now we always return pass. - if (TRUE){ - ret = PASS; - goto EXIT; - } - - FILETIME kernelTime1, userTime1, kernelTime2, userTime2; - /* Delta = .01 sec */ - LONG64 Actual, Expected, Delta = 850000000; - Actual = 0; - Expected = 0; - const ULONG64 MSEC_TO_NSEC = 1000000; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - HANDLE cThread = GetCurrentThread(); - - int i; - /* Take 2000 tiny measurements */ - for (i = 0; i < 2000; i++){ - ULONG64 Time1, Time2; - - Sleep(1); - - /* Grab a FirstCount, then loop for a bit to make the clock increase */ - if (!GetThreadTimes(cThread, NULL, NULL, &kernelTime1, &userTime1)) - { - Fail("ERROR: GetThreadTimes returned failure.\n"); - } - LONG64 x, Init; - /* Init is in milliseconds, so we will convert later */ - Init = (ULONG64)GetTickCount(); - /* Spin for < 1 Quantum so we don't get interrupted */ - x = Init + 3; - volatile int counter; - do { - for (counter = 0; counter < 100000; counter++) - { - // spin to consume CPU time - } - - } while (x > GetTickCount()); - Expected += (GetTickCount() - Init) * MSEC_TO_NSEC; - /* Get a second count */ - if (!GetThreadTimes(cThread, NULL, NULL, &kernelTime2, &userTime2)) - { - Fail("ERROR: GetThreadTimes returned failure.\n"); - } - - Time1 = ((ULONG64)kernelTime1.dwHighDateTime << 32); - Time1 += (ULONG64)kernelTime1.dwLowDateTime; - Time1 += ((ULONG64)userTime1.dwHighDateTime << 32); - Time1 += (ULONG64)userTime1.dwLowDateTime; - - Time2 = ((ULONG64)kernelTime2.dwHighDateTime << 32); - Time2 += (ULONG64)kernelTime2.dwLowDateTime; - Time2 += ((ULONG64)userTime2.dwHighDateTime << 32); - Time2 += (ULONG64)userTime2.dwLowDateTime; - - Actual += (Time2 - Time1) * 100; - } - - if(labs(Expected - Actual) > Delta) - { - Fail("ERROR: The measured time (%llu millisecs) was not within Delta %llu " - "of the expected time (%llu millisecs).\n", - (Actual / MSEC_TO_NSEC), (Delta / MSEC_TO_NSEC), (Expected / MSEC_TO_NSEC)); - } - //printf("%llu, %llu\n", Expected, Actual); - PAL_Terminate(); - ret = PASS; - -EXIT: - return ret; -} diff --git a/src/pal/tests/palsuite/threading/GetThreadTimes/test1/test1.cpp b/src/pal/tests/palsuite/threading/GetThreadTimes/test1/test1.cpp new file mode 100644 index 0000000000..e57a7d08ba --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetThreadTimes/test1/test1.cpp @@ -0,0 +1,102 @@ +// 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: +** +** Source : test1.c +** +** Purpose: Test for GetThreadTimes() function +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) { + int ret = FAIL; + + //Test is failing unreliably, so for now we always return pass. + if (TRUE){ + ret = PASS; + goto EXIT; + } + { + FILETIME kernelTime1, userTime1, kernelTime2, userTime2; + /* Delta = .01 sec */ + LONG64 Actual, Expected, Delta = 850000000; + Actual = 0; + Expected = 0; + const ULONG64 MSEC_TO_NSEC = 1000000; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + HANDLE cThread = GetCurrentThread(); + + int i; + /* Take 2000 tiny measurements */ + for (i = 0; i < 2000; i++){ + ULONG64 Time1, Time2; + + Sleep(1); + + /* Grab a FirstCount, then loop for a bit to make the clock increase */ + if (!GetThreadTimes(cThread, NULL, NULL, &kernelTime1, &userTime1)) + { + Fail("ERROR: GetThreadTimes returned failure.\n"); + } + LONG64 x, Init; + /* Init is in milliseconds, so we will convert later */ + Init = (ULONG64)GetTickCount(); + /* Spin for < 1 Quantum so we don't get interrupted */ + x = Init + 3; + volatile int counter; + do { + for (counter = 0; counter < 100000; counter++) + { + // spin to consume CPU time + } + + } while (x > GetTickCount()); + Expected += (GetTickCount() - Init) * MSEC_TO_NSEC; + /* Get a second count */ + if (!GetThreadTimes(cThread, NULL, NULL, &kernelTime2, &userTime2)) + { + Fail("ERROR: GetThreadTimes returned failure.\n"); + } + + Time1 = ((ULONG64)kernelTime1.dwHighDateTime << 32); + Time1 += (ULONG64)kernelTime1.dwLowDateTime; + Time1 += ((ULONG64)userTime1.dwHighDateTime << 32); + Time1 += (ULONG64)userTime1.dwLowDateTime; + + Time2 = ((ULONG64)kernelTime2.dwHighDateTime << 32); + Time2 += (ULONG64)kernelTime2.dwLowDateTime; + Time2 += ((ULONG64)userTime2.dwHighDateTime << 32); + Time2 += (ULONG64)userTime2.dwLowDateTime; + + Actual += (Time2 - Time1) * 100; + } + + if(labs(Expected - Actual) > Delta) + { + Fail("ERROR: The measured time (%llu millisecs) was not within Delta %llu " + "of the expected time (%llu millisecs).\n", + (Actual / MSEC_TO_NSEC), (Delta / MSEC_TO_NSEC), (Expected / MSEC_TO_NSEC)); + } + //printf("%llu, %llu\n", Expected, Actual); + PAL_Terminate(); + ret = PASS; + } +EXIT: + return ret; +} diff --git a/src/pal/tests/palsuite/threading/NamedMutex/test1/namedmutex.cpp b/src/pal/tests/palsuite/threading/NamedMutex/test1/namedmutex.cpp index 3726214701..a9d46b3d73 100644 --- a/src/pal/tests/palsuite/threading/NamedMutex/test1/namedmutex.cpp +++ b/src/pal/tests/palsuite/threading/NamedMutex/test1/namedmutex.cpp @@ -520,7 +520,7 @@ bool MutualExclusionTests_Parent() return true; } -DWORD MutualExclusionTests_Child(void *arg = nullptr) +DWORD PALAPI MutualExclusionTests_Child(void *arg = nullptr) { const char *testName = "MutualExclusionTests"; @@ -626,7 +626,7 @@ bool LifetimeTests_Parent() return true; } -DWORD LifetimeTests_Child(void *arg = nullptr) +DWORD PALAPI LifetimeTests_Child(void *arg = nullptr) { const char *testName = "LifetimeTests"; @@ -682,7 +682,7 @@ bool LifetimeTests() return true; } -DWORD AbandonTests_Child_TryLock(void *arg = nullptr); +DWORD PALAPI AbandonTests_Child_TryLock(void *arg = nullptr); bool AbandonTests_Parent() { @@ -751,7 +751,7 @@ bool AbandonTests_Parent() return true; } -DWORD AbandonTests_Child_GracefulExit_Close(void *arg = nullptr) +DWORD PALAPI AbandonTests_Child_GracefulExit_Close(void *arg = nullptr) { const char *testName = "AbandonTests"; @@ -837,7 +837,7 @@ DWORD AbandonTests_Child_AbruptExit(void *arg = nullptr) return 0; } -DWORD AbandonTests_Child_TryLock(void *arg) +DWORD PALAPI AbandonTests_Child_TryLock(void *arg) { const char *testName = "AbandonTests"; @@ -910,7 +910,7 @@ DWORD g_stressDurationMilliseconds = 0; LONG g_stressTestCounts[_countof(TestList)] = {0}; LONG g_stressResult = true; -DWORD StressTest(void *arg) +DWORD PALAPI StressTest(void *arg) { // Run the specified test continuously for the stress duration SIZE_T testIndex = reinterpret_cast(arg); diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/OpenEventW/test1/CMakeLists.txt index 2bb61e3044..2d5698b153 100644 --- a/src/pal/tests/palsuite/threading/OpenEventW/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/OpenEventW/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_openeventw_test1 diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test1/test1.c b/src/pal/tests/palsuite/threading/OpenEventW/test1/test1.c deleted file mode 100644 index 9dcb3a4a68..0000000000 --- a/src/pal/tests/palsuite/threading/OpenEventW/test1/test1.c +++ /dev/null @@ -1,134 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for OpenEventW. This test creates an event, -** opens a handle to the same event, then waits on both handles -** in both a signalled and non-signalled state to verify they're. -** pointing to the same event object. -** -** -**==========================================================================*/ -#include - -int __cdecl main(int argc, char **argv) -{ - BOOL bRet = FAIL; - DWORD dwRet; - HANDLE hEvent; - HANDLE hOpenEvent; - WCHAR theName[] = {'E','v','e','n','t','\0'}; - LPCWSTR lpName = theName; - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - /* Create an event (with a 0 intial state!) and ensure that the - HANDLE is valid - */ - hEvent = CreateEventW( NULL, TRUE, FALSE, lpName ); - if( hEvent == NULL ) - { - Fail( "ERROR:%lu:CreateEvent call failed\n", GetLastError() ); - } - - - /* Call OpenEventW to get another HANDLE on - this event. Ensure the HANDLE is valid. - */ - hOpenEvent = OpenEventW( EVENT_ALL_ACCESS, TRUE, lpName ); - if( hOpenEvent == NULL ) - { - Trace( "ERROR:%lu:OpenEventW call failed\n", GetLastError() ); - goto cleanup2; - } - - /* wait on the original event to verify that it's not signalled */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - Trace( "ERROR:WaitForSingleObject returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - /* wait on the opened event to verify that it's not signalled either */ - dwRet = WaitForSingleObject( hOpenEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - Trace( "ERROR:WaitForSingleObject returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - - /* Set this opened HANDLE */ - if( ! SetEvent( hOpenEvent ) ) - { - Trace( "ERROR:%lu:SetEvent call failed\n", GetLastError() ); - goto cleanup; - } - - /* wait on the original event to verify that it's signalled */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - goto cleanup; - } - - /* wait on the opened event to verify that it's signalled too */ - dwRet = WaitForSingleObject( hOpenEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - goto cleanup; - } - - /* success if we get here */ - bRet = PASS; - -cleanup: - /* close the opened handle */ - if( ! CloseHandle( hOpenEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); - bRet = FAIL; - } - -cleanup2: - /* close the original event handle */ - if( ! CloseHandle( hEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); - bRet = FAIL; - } - - /* check for failure */ - if( bRet == FAIL ) - { - Fail( "test failed\n" ); - } - - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return ( PASS ); - -} - diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test1/test1.cpp b/src/pal/tests/palsuite/threading/OpenEventW/test1/test1.cpp new file mode 100644 index 0000000000..9dcb3a4a68 --- /dev/null +++ b/src/pal/tests/palsuite/threading/OpenEventW/test1/test1.cpp @@ -0,0 +1,134 @@ +// 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: test1.c +** +** Purpose: Test for OpenEventW. This test creates an event, +** opens a handle to the same event, then waits on both handles +** in both a signalled and non-signalled state to verify they're. +** pointing to the same event object. +** +** +**==========================================================================*/ +#include + +int __cdecl main(int argc, char **argv) +{ + BOOL bRet = FAIL; + DWORD dwRet; + HANDLE hEvent; + HANDLE hOpenEvent; + WCHAR theName[] = {'E','v','e','n','t','\0'}; + LPCWSTR lpName = theName; + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + /* Create an event (with a 0 intial state!) and ensure that the + HANDLE is valid + */ + hEvent = CreateEventW( NULL, TRUE, FALSE, lpName ); + if( hEvent == NULL ) + { + Fail( "ERROR:%lu:CreateEvent call failed\n", GetLastError() ); + } + + + /* Call OpenEventW to get another HANDLE on + this event. Ensure the HANDLE is valid. + */ + hOpenEvent = OpenEventW( EVENT_ALL_ACCESS, TRUE, lpName ); + if( hOpenEvent == NULL ) + { + Trace( "ERROR:%lu:OpenEventW call failed\n", GetLastError() ); + goto cleanup2; + } + + /* wait on the original event to verify that it's not signalled */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + Trace( "ERROR:WaitForSingleObject returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + /* wait on the opened event to verify that it's not signalled either */ + dwRet = WaitForSingleObject( hOpenEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + Trace( "ERROR:WaitForSingleObject returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + + /* Set this opened HANDLE */ + if( ! SetEvent( hOpenEvent ) ) + { + Trace( "ERROR:%lu:SetEvent call failed\n", GetLastError() ); + goto cleanup; + } + + /* wait on the original event to verify that it's signalled */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + goto cleanup; + } + + /* wait on the opened event to verify that it's signalled too */ + dwRet = WaitForSingleObject( hOpenEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + goto cleanup; + } + + /* success if we get here */ + bRet = PASS; + +cleanup: + /* close the opened handle */ + if( ! CloseHandle( hOpenEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); + bRet = FAIL; + } + +cleanup2: + /* close the original event handle */ + if( ! CloseHandle( hEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle call failed\n", GetLastError() ); + bRet = FAIL; + } + + /* check for failure */ + if( bRet == FAIL ) + { + Fail( "test failed\n" ); + } + + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return ( PASS ); + +} + diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/OpenEventW/test2/CMakeLists.txt index 48fa1f2c4b..bedf83b487 100644 --- a/src/pal/tests/palsuite/threading/OpenEventW/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/OpenEventW/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_openeventw_test2 diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test2/test2.c b/src/pal/tests/palsuite/threading/OpenEventW/test2/test2.c deleted file mode 100644 index 9cbf872b95..0000000000 --- a/src/pal/tests/palsuite/threading/OpenEventW/test2/test2.c +++ /dev/null @@ -1,194 +0,0 @@ -// 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: test2.c -** -** Purpose: Positive test for OpenEventW. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** CloseHandle -** WaitForSingleObject -** -** Purpose: -** -** Test to ensure proper operation of the OpenEventW() -** API by creating a new named event and verifying that -** it can be used interchangeably by setting the event -** with the original handle and waiting on it with the -** new one, then resetting it with the new one and waiting -** on it with the original one. -** -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - BOOL ret = FAIL; - DWORD dwRet = 0; - HANDLE hEvent = NULL; - HANDLE hTestEvent = NULL; - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - WCHAR wcName[] = {'W','o','o','B','a','b','y','\0'}; - LPWSTR lpName = wcName; - - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - - /* create an event which we can use with SetEvent */ - hEvent = CreateEventW( lpEventAttributes, - bManualReset, - bInitialState, - lpName ); - - if( hEvent == NULL ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* open a new handle to our event */ - hTestEvent = OpenEventW(EVENT_ALL_ACCESS, /* we want all rights */ - FALSE, /* no inherit */ - lpName ); - - if( hTestEvent == NULL ) - { - /* ERROR */ - Trace( "ERROR:%lu:OpenEventW() call failed\n", GetLastError() ); - goto cleanup; - } - - /* verify that the event isn't signalled yet by waiting on both */ - /* handles to the event object */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - dwRet = WaitForSingleObject( hTestEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - - /* set the event using the original handle */ - if( ! SetEvent( hEvent ) ) - { - /* ERROR */ - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - /* verify that the event is signalled by waiting on both handles */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - goto cleanup; - } - - dwRet = WaitForSingleObject( hTestEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - goto cleanup; - } - - /* reset the event using the new handle */ - if( ! ResetEvent( hTestEvent ) ) - { - /* ERROR */ - Trace( "ERROR:%lu:ResetEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - /* verify that the event isn't signalled by waiting on both handles */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - dwRet = WaitForSingleObject( hTestEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - - /* test was successful */ - ret = PASS; - - -cleanup: - /* close the new event handle */ - if( hTestEvent != NULL ) - { - if( ! CloseHandle( hTestEvent ) ) - { - ret = FAIL; - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - } - - /* close the original event handle */ - if( ! CloseHandle( hEvent ) ) - { - ret = FAIL; - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - - /* failure message */ - if( ret != PASS ) - { - Fail( "Test failed\n" ); - } - - - /* PAL termination */ - PAL_Terminate(); - - /* return success or failure */ - return ret; -} diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test2/test2.cpp b/src/pal/tests/palsuite/threading/OpenEventW/test2/test2.cpp new file mode 100644 index 0000000000..9cbf872b95 --- /dev/null +++ b/src/pal/tests/palsuite/threading/OpenEventW/test2/test2.cpp @@ -0,0 +1,194 @@ +// 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: test2.c +** +** Purpose: Positive test for OpenEventW. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** WaitForSingleObject +** +** Purpose: +** +** Test to ensure proper operation of the OpenEventW() +** API by creating a new named event and verifying that +** it can be used interchangeably by setting the event +** with the original handle and waiting on it with the +** new one, then resetting it with the new one and waiting +** on it with the original one. +** +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + BOOL ret = FAIL; + DWORD dwRet = 0; + HANDLE hEvent = NULL; + HANDLE hTestEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + WCHAR wcName[] = {'W','o','o','B','a','b','y','\0'}; + LPWSTR lpName = wcName; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with SetEvent */ + hEvent = CreateEventW( lpEventAttributes, + bManualReset, + bInitialState, + lpName ); + + if( hEvent == NULL ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* open a new handle to our event */ + hTestEvent = OpenEventW(EVENT_ALL_ACCESS, /* we want all rights */ + FALSE, /* no inherit */ + lpName ); + + if( hTestEvent == NULL ) + { + /* ERROR */ + Trace( "ERROR:%lu:OpenEventW() call failed\n", GetLastError() ); + goto cleanup; + } + + /* verify that the event isn't signalled yet by waiting on both */ + /* handles to the event object */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + dwRet = WaitForSingleObject( hTestEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + + /* set the event using the original handle */ + if( ! SetEvent( hEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + /* verify that the event is signalled by waiting on both handles */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + goto cleanup; + } + + dwRet = WaitForSingleObject( hTestEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + goto cleanup; + } + + /* reset the event using the new handle */ + if( ! ResetEvent( hTestEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:ResetEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + /* verify that the event isn't signalled by waiting on both handles */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + dwRet = WaitForSingleObject( hTestEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + + /* test was successful */ + ret = PASS; + + +cleanup: + /* close the new event handle */ + if( hTestEvent != NULL ) + { + if( ! CloseHandle( hTestEvent ) ) + { + ret = FAIL; + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + } + + /* close the original event handle */ + if( ! CloseHandle( hEvent ) ) + { + ret = FAIL; + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + /* failure message */ + if( ret != PASS ) + { + Fail( "Test failed\n" ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success or failure */ + return ret; +} diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/OpenEventW/test3/CMakeLists.txt index 433a3a255c..7f7622dca0 100644 --- a/src/pal/tests/palsuite/threading/OpenEventW/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/OpenEventW/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test3.c + test3.cpp ) add_executable(paltest_openeventw_test3 @@ -20,7 +20,7 @@ target_link_libraries(paltest_openeventw_test3 set(HELPERSOURCES - childprocess.c + childprocess.cpp ) add_executable(paltest_openeventw_test3_child diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test3/childprocess.c b/src/pal/tests/palsuite/threading/OpenEventW/test3/childprocess.c deleted file mode 100644 index b5149e006f..0000000000 --- a/src/pal/tests/palsuite/threading/OpenEventW/test3/childprocess.c +++ /dev/null @@ -1,81 +0,0 @@ -// 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: childprocess.c -** -** Purpose: Test to ensure that OpenEventW() works when -** opening an event created by another process. The test -** program launches this program as a child, which creates -** a named, initially-unset event. The child waits up to -** 10 seconds for the parent process to open that event -** and set it, and returns PASS if the event was set or FAIL -** otherwise. The parent process checks the return value -** from the child to verify that the opened event was -** properly used across processes. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEventW -** WaitForSingleObject -** CloseHandle -** -** -**=========================================================*/ - -#include - -int __cdecl main( int argc, char **argv ) -{ - /* local variables */ - HANDLE hEvent = NULL; - WCHAR wcName[] = {'P','A','L','R','o','c','k','s','\0'}; - LPWSTR lpName = wcName; - - int result = PASS; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - - /* open a handle to the event created in the child process */ - hEvent = OpenEventW( EVENT_ALL_ACCESS, /* we want all rights */ - FALSE, /* no inherit */ - lpName ); - - if( hEvent == NULL ) - { - /* ERROR */ - Trace( "ERROR:%lu:OpenEventW() call failed\n", GetLastError() ); - result = FAIL; - goto parentwait; - } - - /* set the event -- should take effect in the child process */ - if( ! SetEvent( hEvent ) ) - { - /* ERROR */ - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - result = FAIL; - } - -parentwait: - /* close the event handle */ - if( ! CloseHandle( hEvent ) ) - { - /* ERROR */ - Fail( "ERROR:%lu:CloseHandle() call failed in child\n", - GetLastError()); - } - - /* terminate the PAL */ - PAL_TerminateEx(result); - - /* return success or failure */ - return result; -} diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test3/childprocess.cpp b/src/pal/tests/palsuite/threading/OpenEventW/test3/childprocess.cpp new file mode 100644 index 0000000000..b5149e006f --- /dev/null +++ b/src/pal/tests/palsuite/threading/OpenEventW/test3/childprocess.cpp @@ -0,0 +1,81 @@ +// 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: childprocess.c +** +** Purpose: Test to ensure that OpenEventW() works when +** opening an event created by another process. The test +** program launches this program as a child, which creates +** a named, initially-unset event. The child waits up to +** 10 seconds for the parent process to open that event +** and set it, and returns PASS if the event was set or FAIL +** otherwise. The parent process checks the return value +** from the child to verify that the opened event was +** properly used across processes. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEventW +** WaitForSingleObject +** CloseHandle +** +** +**=========================================================*/ + +#include + +int __cdecl main( int argc, char **argv ) +{ + /* local variables */ + HANDLE hEvent = NULL; + WCHAR wcName[] = {'P','A','L','R','o','c','k','s','\0'}; + LPWSTR lpName = wcName; + + int result = PASS; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + + /* open a handle to the event created in the child process */ + hEvent = OpenEventW( EVENT_ALL_ACCESS, /* we want all rights */ + FALSE, /* no inherit */ + lpName ); + + if( hEvent == NULL ) + { + /* ERROR */ + Trace( "ERROR:%lu:OpenEventW() call failed\n", GetLastError() ); + result = FAIL; + goto parentwait; + } + + /* set the event -- should take effect in the child process */ + if( ! SetEvent( hEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + result = FAIL; + } + +parentwait: + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + /* ERROR */ + Fail( "ERROR:%lu:CloseHandle() call failed in child\n", + GetLastError()); + } + + /* terminate the PAL */ + PAL_TerminateEx(result); + + /* return success or failure */ + return result; +} diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test3/test3.c b/src/pal/tests/palsuite/threading/OpenEventW/test3/test3.c deleted file mode 100644 index 10a678a107..0000000000 --- a/src/pal/tests/palsuite/threading/OpenEventW/test3/test3.c +++ /dev/null @@ -1,187 +0,0 @@ -// 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: test3.c -** -** Purpose: Test to ensure that OpenEventW() works when -** opening an event created by another process. This test -** program launches a child process which creates a -** named, initially-unset event. The child waits up to -** 10 seconds for the parent process to open that event -** and set it, and returns PASS if the event was set or FAIL -** otherwise. The parent process checks the return value -** from the child to verify that the opened event was -** properly used across processes. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** ZeroMemory -** GetCurrentDirectoryW -** CreateProcessW -** WaitForSingleObject -** GetExitCodeProcess -** GetLastError -** strlen -** strncpy -** -** -**===========================================================================*/ -#include - -#define TIMEOUT 60000 - -int __cdecl main( int argc, char **argv ) -{ - BOOL ret = FAIL; - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - - STARTUPINFO si; - PROCESS_INFORMATION pi; - - DWORD dwExitCode; - - DWORD dwRet = 0; - HANDLE hEvent = NULL; - WCHAR wcName[] = {'P','A','L','R','o','c','k','s','\0'}; - LPWSTR lpName = wcName; - char lpCommandLine[MAX_PATH] = ""; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* zero our process and startup info structures */ - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof( si ); - ZeroMemory( &pi, sizeof(pi) ); - - /* create an event which we can use with SetEvent */ - hEvent = CreateEventW( lpEventAttributes, - TRUE, /* manual reset */ - FALSE, /* unsignalled */ - lpName ); - - if( hEvent == NULL ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateEventW() call failed in child\n", - GetLastError()); - } - - ZeroMemory( lpCommandLine, MAX_PATH ); - if ( _snprintf( lpCommandLine, MAX_PATH-1, "childprocess ") < 0 ) - { - Fail ("Error: Insufficient lpCommandline for\n"); - } - - /* launch the child process */ - if( !CreateProcess( NULL, /* module name to execute */ - lpCommandLine, /* command line */ - NULL, /* process handle not */ - /* inheritable */ - NULL, /* thread handle not */ - /* inheritable */ - FALSE, /* handle inheritance */ - CREATE_NEW_CONSOLE, /* dwCreationFlags */ - NULL, /* use parent's environment */ - NULL, /* use parent's starting */ - /* directory */ - &si, /* startup info struct */ - &pi ) /* process info struct */ - ) - { - Fail( "ERROR:%lu:CreateProcess call failed\n", - GetLastError() ); - } - - /* verify that the event is signalled by the child process */ - dwRet = WaitForSingleObject( hEvent, TIMEOUT ); - if( dwRet != WAIT_OBJECT_0 ) - { - ret = FAIL; - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - "expected WAIT_OBJECT_0\n", - dwRet ); - - goto cleanup; - - if( !CloseHandle( hEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed in child\n", - GetLastError()); - } - goto cleanup; - } - - /* wait for the child process to complete */ - dwRet = WaitForSingleObject ( pi.hProcess, TIMEOUT ); - if( dwRet != WAIT_OBJECT_0 ) - { - ret = FAIL; - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected %lu\n", - dwRet, - WAIT_OBJECT_0 ); - goto cleanup; - } - - /* check the exit code from the process */ - if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) - { - ret = FAIL; - Trace( "ERROR:%lu:GetExitCodeProcess call failed\n", - GetLastError() ); - goto cleanup; - } - - /* check for success */ - ret = (dwExitCode == PASS) ? PASS : FAIL; - -cleanup: - if( hEvent != NULL ) - { - if( ! CloseHandle ( hEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle call failed on event handle\n", - GetLastError() ); - ret = FAIL; - } - } - - - /* close process and thread handle */ - if( ! CloseHandle ( pi.hProcess ) ) - { - Trace( "ERROR:%lu:CloseHandle call failed on process handle\n", - GetLastError() ); - ret = FAIL; - } - - if( ! CloseHandle ( pi.hThread ) ) - { - Trace( "ERROR:%lu:CloseHandle call failed on thread handle\n", - GetLastError() ); - ret = FAIL; - } - - /* output a convenient error message and exit if we failed */ - if( ret == FAIL ) - { - Fail( "test failed\n" ); - } - - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return ret; -} diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test3/test3.cpp b/src/pal/tests/palsuite/threading/OpenEventW/test3/test3.cpp new file mode 100644 index 0000000000..c4edf22a76 --- /dev/null +++ b/src/pal/tests/palsuite/threading/OpenEventW/test3/test3.cpp @@ -0,0 +1,187 @@ +// 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: test3.c +** +** Purpose: Test to ensure that OpenEventW() works when +** opening an event created by another process. This test +** program launches a child process which creates a +** named, initially-unset event. The child waits up to +** 10 seconds for the parent process to open that event +** and set it, and returns PASS if the event was set or FAIL +** otherwise. The parent process checks the return value +** from the child to verify that the opened event was +** properly used across processes. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** ZeroMemory +** GetCurrentDirectoryW +** CreateProcessW +** WaitForSingleObject +** GetExitCodeProcess +** GetLastError +** strlen +** strncpy +** +** +**===========================================================================*/ +#include + +#define TIMEOUT 60000 + +int __cdecl main( int argc, char **argv ) +{ + BOOL ret = FAIL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + DWORD dwExitCode; + + DWORD dwRet = 0; + HANDLE hEvent = NULL; + WCHAR wcName[] = {'P','A','L','R','o','c','k','s','\0'}; + LPWSTR lpName = wcName; + char lpCommandLine[MAX_PATH] = ""; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* zero our process and startup info structures */ + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof( si ); + ZeroMemory( &pi, sizeof(pi) ); + + /* create an event which we can use with SetEvent */ + hEvent = CreateEventW( lpEventAttributes, + TRUE, /* manual reset */ + FALSE, /* unsignalled */ + lpName ); + + if( hEvent == NULL ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEventW() call failed in child\n", + GetLastError()); + } + + ZeroMemory( lpCommandLine, MAX_PATH ); + if ( sprintf_s( lpCommandLine, MAX_PATH-1, "childprocess ") < 0 ) + { + Fail ("Error: Insufficient lpCommandline for\n"); + } + + /* launch the child process */ + if( !CreateProcess( NULL, /* module name to execute */ + lpCommandLine, /* command line */ + NULL, /* process handle not */ + /* inheritable */ + NULL, /* thread handle not */ + /* inheritable */ + FALSE, /* handle inheritance */ + CREATE_NEW_CONSOLE, /* dwCreationFlags */ + NULL, /* use parent's environment */ + NULL, /* use parent's starting */ + /* directory */ + &si, /* startup info struct */ + &pi ) /* process info struct */ + ) + { + Fail( "ERROR:%lu:CreateProcess call failed\n", + GetLastError() ); + } + + /* verify that the event is signalled by the child process */ + dwRet = WaitForSingleObject( hEvent, TIMEOUT ); + if( dwRet != WAIT_OBJECT_0 ) + { + ret = FAIL; + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + "expected WAIT_OBJECT_0\n", + dwRet ); + + goto cleanup; + + if( !CloseHandle( hEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed in child\n", + GetLastError()); + } + goto cleanup; + } + + /* wait for the child process to complete */ + dwRet = WaitForSingleObject ( pi.hProcess, TIMEOUT ); + if( dwRet != WAIT_OBJECT_0 ) + { + ret = FAIL; + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected %lu\n", + dwRet, + WAIT_OBJECT_0 ); + goto cleanup; + } + + /* check the exit code from the process */ + if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) + { + ret = FAIL; + Trace( "ERROR:%lu:GetExitCodeProcess call failed\n", + GetLastError() ); + goto cleanup; + } + + /* check for success */ + ret = (dwExitCode == PASS) ? PASS : FAIL; + +cleanup: + if( hEvent != NULL ) + { + if( ! CloseHandle ( hEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle call failed on event handle\n", + GetLastError() ); + ret = FAIL; + } + } + + + /* close process and thread handle */ + if( ! CloseHandle ( pi.hProcess ) ) + { + Trace( "ERROR:%lu:CloseHandle call failed on process handle\n", + GetLastError() ); + ret = FAIL; + } + + if( ! CloseHandle ( pi.hThread ) ) + { + Trace( "ERROR:%lu:CloseHandle call failed on thread handle\n", + GetLastError() ); + ret = FAIL; + } + + /* output a convenient error message and exit if we failed */ + if( ret == FAIL ) + { + Fail( "test failed\n" ); + } + + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return ret; +} diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/OpenEventW/test4/CMakeLists.txt index ff17fea23b..73b8904993 100644 --- a/src/pal/tests/palsuite/threading/OpenEventW/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/OpenEventW/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_openeventw_test4 diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test4/test4.c b/src/pal/tests/palsuite/threading/OpenEventW/test4/test4.c deleted file mode 100644 index ae657a0511..0000000000 --- a/src/pal/tests/palsuite/threading/OpenEventW/test4/test4.c +++ /dev/null @@ -1,112 +0,0 @@ -// 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: test4.c -** -** Purpose: Positive test for OpenEventW. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** CloseHandle -** WaitForSingleObject -** -** Purpose: -** -** Test to ensure proper operation of the OpenEventW() -** API by trying to open an event with a name that is -** already taken by a non-event object. -** -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - BOOL bRet = PASS; - DWORD dwLastError = 0; - HANDLE hMutex = NULL; - HANDLE hTestEvent = NULL; - LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL; - BOOL bInitialState = TRUE; - WCHAR wcName[] = {'I','m','A','M','u','t','e','x','\0'}; - LPWSTR lpName = wcName; - - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - /* create a mutex object */ - hMutex = CreateMutexW( lpSecurityAttributes, - bInitialState, - lpName ); - - if( hMutex == NULL ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateMutexW() call failed\n", GetLastError() ); - } - - /* open a new handle to our event */ - hTestEvent = OpenEventW(EVENT_ALL_ACCESS, /* we want all rights */ - FALSE, /* no inherit */ - lpName ); - - if( hTestEvent != NULL ) - { - /* ERROR */ - Trace( "ERROR:OpenEventW() call succeeded against a named " - "mutex, should have returned NULL\n" ); - if( ! CloseHandle( hTestEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed \n", GetLastError() ); - } - bRet = FAIL; - } - else - { - dwLastError = GetLastError(); - if( dwLastError != ERROR_INVALID_HANDLE ) - { - /* ERROR */ - Trace( "ERROR:OpenEventW() call failed against a named " - "mutex, but returned an unexpected result: %lu\n", - dwLastError ); - bRet = FAIL; - } - } - - - /* close the mutex handle */ - if( ! CloseHandle( hMutex ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed \n", GetLastError() ); - bRet = FAIL; - } - - - /* fail here if we weren't successful */ - if( bRet == FAIL ) - { - Fail( "" ); - } - - - /* PAL termination */ - PAL_Terminate(); - - /* return success or failure */ - return PASS; -} - - diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test4/test4.cpp b/src/pal/tests/palsuite/threading/OpenEventW/test4/test4.cpp new file mode 100644 index 0000000000..ae657a0511 --- /dev/null +++ b/src/pal/tests/palsuite/threading/OpenEventW/test4/test4.cpp @@ -0,0 +1,112 @@ +// 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: test4.c +** +** Purpose: Positive test for OpenEventW. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** WaitForSingleObject +** +** Purpose: +** +** Test to ensure proper operation of the OpenEventW() +** API by trying to open an event with a name that is +** already taken by a non-event object. +** +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + BOOL bRet = PASS; + DWORD dwLastError = 0; + HANDLE hMutex = NULL; + HANDLE hTestEvent = NULL; + LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL; + BOOL bInitialState = TRUE; + WCHAR wcName[] = {'I','m','A','M','u','t','e','x','\0'}; + LPWSTR lpName = wcName; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + /* create a mutex object */ + hMutex = CreateMutexW( lpSecurityAttributes, + bInitialState, + lpName ); + + if( hMutex == NULL ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateMutexW() call failed\n", GetLastError() ); + } + + /* open a new handle to our event */ + hTestEvent = OpenEventW(EVENT_ALL_ACCESS, /* we want all rights */ + FALSE, /* no inherit */ + lpName ); + + if( hTestEvent != NULL ) + { + /* ERROR */ + Trace( "ERROR:OpenEventW() call succeeded against a named " + "mutex, should have returned NULL\n" ); + if( ! CloseHandle( hTestEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed \n", GetLastError() ); + } + bRet = FAIL; + } + else + { + dwLastError = GetLastError(); + if( dwLastError != ERROR_INVALID_HANDLE ) + { + /* ERROR */ + Trace( "ERROR:OpenEventW() call failed against a named " + "mutex, but returned an unexpected result: %lu\n", + dwLastError ); + bRet = FAIL; + } + } + + + /* close the mutex handle */ + if( ! CloseHandle( hMutex ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed \n", GetLastError() ); + bRet = FAIL; + } + + + /* fail here if we weren't successful */ + if( bRet == FAIL ) + { + Fail( "" ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success or failure */ + return PASS; +} + + diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test5/CMakeLists.txt b/src/pal/tests/palsuite/threading/OpenEventW/test5/CMakeLists.txt index b78d7fbfc0..3bad4d9cc5 100644 --- a/src/pal/tests/palsuite/threading/OpenEventW/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/OpenEventW/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_openeventw_test5 diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test5/test5.c b/src/pal/tests/palsuite/threading/OpenEventW/test5/test5.c deleted file mode 100644 index 43b585765c..0000000000 --- a/src/pal/tests/palsuite/threading/OpenEventW/test5/test5.c +++ /dev/null @@ -1,197 +0,0 @@ -// 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: test5.c -** -** Purpose: Positive test for OpenEventW. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** CloseHandle -** WaitForSingleObject -** -** Purpose: -** -** Test to ensure proper operation of the OpenEventW() -** API by creating a new named event with CreateEventA() -** and verifying that it can be opened with OpenEventW(). -** It should be possible to use the event handles -** interchangeably, we test by setting the event with the -** original handle and waiting on it with the new one, -** then resetting it with the new one and waiting -** on it with the original one. -** -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - BOOL ret = FAIL; - DWORD dwRet = 0; - HANDLE hEvent = NULL; - HANDLE hTestEvent = NULL; - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - LPSTR lpNameA = "ShakeIt"; - WCHAR wcName[] = {'S','h','a','k','e','I','t','\0'}; - LPWSTR lpNameW = wcName; - - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - - /* create an event which we can use with SetEvent */ - hEvent = CreateEventA( lpEventAttributes, - bManualReset, - bInitialState, - lpNameA ); - - if( hEvent == NULL ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* open a new handle to our event */ - hTestEvent = OpenEventW(EVENT_ALL_ACCESS, /* we want all rights */ - FALSE, /* no inherit */ - lpNameW ); - - if( hTestEvent == NULL ) - { - /* ERROR */ - Trace( "ERROR:%lu:OpenEventW() call failed\n", GetLastError() ); - goto cleanup; - } - - /* verify that the event isn't signalled yet by waiting on both */ - /* handles to the event object */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - dwRet = WaitForSingleObject( hTestEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - - /* set the event using the original handle */ - if( ! SetEvent( hEvent ) ) - { - /* ERROR */ - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - /* verify that the event is signalled by waiting on both handles */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - goto cleanup; - } - - dwRet = WaitForSingleObject( hTestEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - goto cleanup; - } - - /* reset the event using the new handle */ - if( ! ResetEvent( hTestEvent ) ) - { - /* ERROR */ - Trace( "ERROR:%lu:ResetEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - /* verify that the event isn't signalled by waiting on both handles */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - dwRet = WaitForSingleObject( hTestEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - goto cleanup; - } - - - /* test was successful */ - ret = PASS; - - -cleanup: - /* close the new event handle */ - if( hTestEvent != NULL ) - { - if( ! CloseHandle( hTestEvent ) ) - { - ret = FAIL; - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - } - - /* close the original event handle */ - if( ! CloseHandle( hEvent ) ) - { - ret = FAIL; - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - - /* failure message */ - if( ret != PASS ) - { - Fail( "Test failed\n" ); - } - - - /* PAL termination */ - PAL_Terminate(); - - /* return success or failure */ - return ret; -} diff --git a/src/pal/tests/palsuite/threading/OpenEventW/test5/test5.cpp b/src/pal/tests/palsuite/threading/OpenEventW/test5/test5.cpp new file mode 100644 index 0000000000..43b585765c --- /dev/null +++ b/src/pal/tests/palsuite/threading/OpenEventW/test5/test5.cpp @@ -0,0 +1,197 @@ +// 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: test5.c +** +** Purpose: Positive test for OpenEventW. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** WaitForSingleObject +** +** Purpose: +** +** Test to ensure proper operation of the OpenEventW() +** API by creating a new named event with CreateEventA() +** and verifying that it can be opened with OpenEventW(). +** It should be possible to use the event handles +** interchangeably, we test by setting the event with the +** original handle and waiting on it with the new one, +** then resetting it with the new one and waiting +** on it with the original one. +** +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + BOOL ret = FAIL; + DWORD dwRet = 0; + HANDLE hEvent = NULL; + HANDLE hTestEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + LPSTR lpNameA = "ShakeIt"; + WCHAR wcName[] = {'S','h','a','k','e','I','t','\0'}; + LPWSTR lpNameW = wcName; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with SetEvent */ + hEvent = CreateEventA( lpEventAttributes, + bManualReset, + bInitialState, + lpNameA ); + + if( hEvent == NULL ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* open a new handle to our event */ + hTestEvent = OpenEventW(EVENT_ALL_ACCESS, /* we want all rights */ + FALSE, /* no inherit */ + lpNameW ); + + if( hTestEvent == NULL ) + { + /* ERROR */ + Trace( "ERROR:%lu:OpenEventW() call failed\n", GetLastError() ); + goto cleanup; + } + + /* verify that the event isn't signalled yet by waiting on both */ + /* handles to the event object */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + dwRet = WaitForSingleObject( hTestEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + + /* set the event using the original handle */ + if( ! SetEvent( hEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + /* verify that the event is signalled by waiting on both handles */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + goto cleanup; + } + + dwRet = WaitForSingleObject( hTestEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + goto cleanup; + } + + /* reset the event using the new handle */ + if( ! ResetEvent( hTestEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:ResetEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + /* verify that the event isn't signalled by waiting on both handles */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + dwRet = WaitForSingleObject( hTestEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + goto cleanup; + } + + + /* test was successful */ + ret = PASS; + + +cleanup: + /* close the new event handle */ + if( hTestEvent != NULL ) + { + if( ! CloseHandle( hTestEvent ) ) + { + ret = FAIL; + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + } + + /* close the original event handle */ + if( ! CloseHandle( hEvent ) ) + { + ret = FAIL; + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + /* failure message */ + if( ret != PASS ) + { + Fail( "Test failed\n" ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success or failure */ + return ret; +} diff --git a/src/pal/tests/palsuite/threading/OpenProcess/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/OpenProcess/test1/CMakeLists.txt index 26d30547a9..dd2e30516c 100644 --- a/src/pal/tests/palsuite/threading/OpenProcess/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/OpenProcess/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test1.c + test1.cpp ) add_executable(paltest_openprocess_test1 @@ -20,7 +20,7 @@ target_link_libraries(paltest_openprocess_test1 set(HELPERSOURCES - childProcess.c + childProcess.cpp ) add_executable(paltest_openprocess_test1_child diff --git a/src/pal/tests/palsuite/threading/OpenProcess/test1/childProcess.c b/src/pal/tests/palsuite/threading/OpenProcess/test1/childProcess.c deleted file mode 100644 index 9ef07433fd..0000000000 --- a/src/pal/tests/palsuite/threading/OpenProcess/test1/childProcess.c +++ /dev/null @@ -1,75 +0,0 @@ -// 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: childprocess.c -** -** Purpose: Test to ensure OpenProcess works properly. -** All this program does is return a predefined value. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateMutexW -** WaitForSingleObject -** CloseHandle -** -** -**=========================================================*/ - -#include -#include "myexitcode.h" - - -int __cdecl main( int argc, char **argv ) -{ - HANDLE hMutex; - WCHAR wszMutexName[] = { 'T','E','S','T','1','\0' }; - DWORD dwRet; - int i; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* open a mutex to synchronize with the parent process */ - hMutex = CreateMutexW( NULL, FALSE, wszMutexName ); - if( hMutex == NULL ) - { - Fail( "ERROR:%lu:CreateMutex() call failed\r\n", GetLastError() ); - } - - /* acquire the mutex lock */ - dwRet = WaitForSingleObject( hMutex, 10000 ); - if( dwRet != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0", - dwRet ); - if( ! CloseHandle( hMutex ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "test failed\n" ); - } - - - /* simulate some activity */ - for( i=0; i<50000; i++ ) - ; - - /* close our mutex handle */ - if( ! CloseHandle( hMutex ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - - /* terminate the PAL */ - PAL_Terminate(); - - /* return the predefined exit code */ - return TEST_EXIT_CODE; -} diff --git a/src/pal/tests/palsuite/threading/OpenProcess/test1/childProcess.cpp b/src/pal/tests/palsuite/threading/OpenProcess/test1/childProcess.cpp new file mode 100644 index 0000000000..9ef07433fd --- /dev/null +++ b/src/pal/tests/palsuite/threading/OpenProcess/test1/childProcess.cpp @@ -0,0 +1,75 @@ +// 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: childprocess.c +** +** Purpose: Test to ensure OpenProcess works properly. +** All this program does is return a predefined value. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateMutexW +** WaitForSingleObject +** CloseHandle +** +** +**=========================================================*/ + +#include +#include "myexitcode.h" + + +int __cdecl main( int argc, char **argv ) +{ + HANDLE hMutex; + WCHAR wszMutexName[] = { 'T','E','S','T','1','\0' }; + DWORD dwRet; + int i; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* open a mutex to synchronize with the parent process */ + hMutex = CreateMutexW( NULL, FALSE, wszMutexName ); + if( hMutex == NULL ) + { + Fail( "ERROR:%lu:CreateMutex() call failed\r\n", GetLastError() ); + } + + /* acquire the mutex lock */ + dwRet = WaitForSingleObject( hMutex, 10000 ); + if( dwRet != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0", + dwRet ); + if( ! CloseHandle( hMutex ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "test failed\n" ); + } + + + /* simulate some activity */ + for( i=0; i<50000; i++ ) + ; + + /* close our mutex handle */ + if( ! CloseHandle( hMutex ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + /* terminate the PAL */ + PAL_Terminate(); + + /* return the predefined exit code */ + return TEST_EXIT_CODE; +} diff --git a/src/pal/tests/palsuite/threading/OpenProcess/test1/test1.c b/src/pal/tests/palsuite/threading/OpenProcess/test1/test1.c deleted file mode 100644 index d0f9019646..0000000000 --- a/src/pal/tests/palsuite/threading/OpenProcess/test1/test1.c +++ /dev/null @@ -1,282 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure OpenProcess works properly. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** ZeroMemory -** GetCurrentDirectoryW -** CreateProcessW -** WaitForSingleObject -** CreateMutexW -** ReleaseMutex -** CloseHandle -** GetLastError -** strlen -** strncpy -** -** -**===========================================================================*/ -#include -#include "myexitcode.h" - - -static const char* rgchPathDelim = "\\"; - - -int -mkAbsoluteFilename( LPSTR dirName, - DWORD dwDirLength, - LPCSTR fileName, - DWORD dwFileLength, - LPSTR absPathName ) -{ - DWORD sizeDN, sizeFN, sizeAPN; - - sizeDN = strlen( dirName ); - sizeFN = strlen( fileName ); - sizeAPN = (sizeDN + 1 + sizeFN + 1); - - /* ensure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ - if( sizeAPN > _MAX_PATH ) - { - return ( 0 ); - } - - strncpy( absPathName, dirName, dwDirLength +1 ); - strncpy( absPathName, rgchPathDelim, 2 ); - strncpy( absPathName, fileName, dwFileLength +1 ); - - return (sizeAPN); - -} - - -int __cdecl main( int argc, char **argv ) - -{ - const char* rgchChildFile = "childprocess"; - - STARTUPINFO si; - PROCESS_INFORMATION pi; - - DWORD dwError; - DWORD dwExitCode; - DWORD dwFileLength; - DWORD dwDirLength; - DWORD dwSize; - DWORD dwRet; - - HANDLE hMutex; - HANDLE hChildProcess; - - char rgchDirName[_MAX_DIR]; - char absPathBuf[_MAX_PATH]; - char* rgchAbsPathName; - - BOOL ret = FAIL; - BOOL bChildDone = FALSE; - WCHAR wszMutexName[] = { 'T','E','S','T','1','\0' }; - - /* initialize the PAL */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return( FAIL ); - } - - /* create a mutex to synchronize with the child process */ - hMutex = CreateMutexW( NULL, TRUE, wszMutexName ); - if( hMutex == NULL ) - { - Fail( "ERROR:%lu:CreateMutex() call failed\r\n", GetLastError() ); - } - - /* zero our process and startup info structures */ - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof( si ); - ZeroMemory( &pi, sizeof(pi) ); - - /* build the absolute path to the child process */ - rgchAbsPathName = &absPathBuf[0]; - dwFileLength = strlen( rgchChildFile ); - - dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName ); - if( dwDirLength == 0 ) - { - dwError = GetLastError(); - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - } - if( CloseHandle( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "GetCurrentDirectory call failed with error code %d\n", - dwError ); - } - - dwSize = mkAbsoluteFilename( rgchDirName, - dwDirLength, - rgchChildFile, - dwFileLength, - rgchAbsPathName ); - if( dwSize == 0 ) - { - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - } - if( CloseHandle( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ", - "not build absolute path name to file\n. Exiting.\n" ); - } - - /* launch the child process */ - if( !CreateProcess( NULL, /* module name to execute */ - rgchAbsPathName, /* command line */ - NULL, /* process handle not */ - /* inheritable */ - NULL, /* thread handle not */ - /*inheritable */ - FALSE, /* handle inheritance */ - CREATE_NEW_CONSOLE, /* dwCreationFlags */ - NULL, /* use parent's environment */ - NULL, /* use parent's starting */ - /* directory */ - &si, /* startup info struct */ - &pi ) /* process info struct */ - ) - { - dwError = GetLastError(); - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - } - if( CloseHandle( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "CreateProcess call failed with error code %d\n", - dwError ); - } - - /* open another handle to the child process */ - hChildProcess = OpenProcess( PROCESS_ALL_ACCESS, /* access */ - FALSE, /* inheritable */ - pi.dwProcessId /* process id */ - ); - if( hChildProcess == NULL ) - { - dwError = GetLastError(); - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - } - Trace( "ERROR:%lu:OpenProcess call failed\n", dwError ); - goto cleanup2; - } - - /* release the mutex so the child can proceed */ - if( ReleaseMutex( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); - goto cleanup; - } - - /* wait for the child process to complete, using the new handle */ - dwRet = WaitForSingleObject( hChildProcess, 10000 ); - if( dwRet != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject call returned %lu, " - "expected WAIT_OBJECT_0", - dwRet ); - goto cleanup; - } - - /* remember that we waited until the child was finished */ - bChildDone = TRUE; - - /* check the exit code from the process -- this is a bit of an */ - /* extra verification that we opened the correct process handle */ - if( ! GetExitCodeProcess( hChildProcess, &dwExitCode ) ) - { - Trace( "ERROR:%lu:GetExitCodeProcess call failed\n", GetLastError() ); - goto cleanup; - } - - /* verification */ - if( (dwExitCode & 0xFF) != (TEST_EXIT_CODE & 0xFF) ) - { - Trace( "GetExitCodeProcess returned an incorrect exit code %d, " - "expected value is %d\n", - (dwExitCode & 0xFF), - (TEST_EXIT_CODE & 0xFF)); - goto cleanup; - } - - /* success if we get here */ - ret = PASS; - - -cleanup: - /* wait on the child process to complete if necessary */ - if( ! bChildDone ) - { - dwRet = WaitForSingleObject( hChildProcess, 10000 ); - if( dwRet != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject call returned %lu, " - "expected WAIT_OBJECT_0", - dwRet ); - ret = FAIL; - } - } - - /* close all our handles */ - if( CloseHandle ( hChildProcess ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - ret = FAIL; - } - -cleanup2: - if( CloseHandle ( pi.hProcess ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - ret = FAIL; - } - if( CloseHandle ( pi.hThread ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - ret = FAIL; - } - if( CloseHandle( hMutex ) == 0 ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - ret = FAIL; - } - - if( ret == FAIL ) - { - Fail( "test failed\n" ); - } - - - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/OpenProcess/test1/test1.cpp b/src/pal/tests/palsuite/threading/OpenProcess/test1/test1.cpp new file mode 100644 index 0000000000..d0f9019646 --- /dev/null +++ b/src/pal/tests/palsuite/threading/OpenProcess/test1/test1.cpp @@ -0,0 +1,282 @@ +// 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: test1.c +** +** Purpose: Test to ensure OpenProcess works properly. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** ZeroMemory +** GetCurrentDirectoryW +** CreateProcessW +** WaitForSingleObject +** CreateMutexW +** ReleaseMutex +** CloseHandle +** GetLastError +** strlen +** strncpy +** +** +**===========================================================================*/ +#include +#include "myexitcode.h" + + +static const char* rgchPathDelim = "\\"; + + +int +mkAbsoluteFilename( LPSTR dirName, + DWORD dwDirLength, + LPCSTR fileName, + DWORD dwFileLength, + LPSTR absPathName ) +{ + DWORD sizeDN, sizeFN, sizeAPN; + + sizeDN = strlen( dirName ); + sizeFN = strlen( fileName ); + sizeAPN = (sizeDN + 1 + sizeFN + 1); + + /* ensure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */ + if( sizeAPN > _MAX_PATH ) + { + return ( 0 ); + } + + strncpy( absPathName, dirName, dwDirLength +1 ); + strncpy( absPathName, rgchPathDelim, 2 ); + strncpy( absPathName, fileName, dwFileLength +1 ); + + return (sizeAPN); + +} + + +int __cdecl main( int argc, char **argv ) + +{ + const char* rgchChildFile = "childprocess"; + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + DWORD dwError; + DWORD dwExitCode; + DWORD dwFileLength; + DWORD dwDirLength; + DWORD dwSize; + DWORD dwRet; + + HANDLE hMutex; + HANDLE hChildProcess; + + char rgchDirName[_MAX_DIR]; + char absPathBuf[_MAX_PATH]; + char* rgchAbsPathName; + + BOOL ret = FAIL; + BOOL bChildDone = FALSE; + WCHAR wszMutexName[] = { 'T','E','S','T','1','\0' }; + + /* initialize the PAL */ + if( PAL_Initialize(argc, argv) != 0 ) + { + return( FAIL ); + } + + /* create a mutex to synchronize with the child process */ + hMutex = CreateMutexW( NULL, TRUE, wszMutexName ); + if( hMutex == NULL ) + { + Fail( "ERROR:%lu:CreateMutex() call failed\r\n", GetLastError() ); + } + + /* zero our process and startup info structures */ + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof( si ); + ZeroMemory( &pi, sizeof(pi) ); + + /* build the absolute path to the child process */ + rgchAbsPathName = &absPathBuf[0]; + dwFileLength = strlen( rgchChildFile ); + + dwDirLength = GetCurrentDirectory( _MAX_PATH, rgchDirName ); + if( dwDirLength == 0 ) + { + dwError = GetLastError(); + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + } + if( CloseHandle( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "GetCurrentDirectory call failed with error code %d\n", + dwError ); + } + + dwSize = mkAbsoluteFilename( rgchDirName, + dwDirLength, + rgchChildFile, + dwFileLength, + rgchAbsPathName ); + if( dwSize == 0 ) + { + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + } + if( CloseHandle( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "Palsuite Code: mkAbsoluteFilename() call failed. Could ", + "not build absolute path name to file\n. Exiting.\n" ); + } + + /* launch the child process */ + if( !CreateProcess( NULL, /* module name to execute */ + rgchAbsPathName, /* command line */ + NULL, /* process handle not */ + /* inheritable */ + NULL, /* thread handle not */ + /*inheritable */ + FALSE, /* handle inheritance */ + CREATE_NEW_CONSOLE, /* dwCreationFlags */ + NULL, /* use parent's environment */ + NULL, /* use parent's starting */ + /* directory */ + &si, /* startup info struct */ + &pi ) /* process info struct */ + ) + { + dwError = GetLastError(); + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + } + if( CloseHandle( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "CreateProcess call failed with error code %d\n", + dwError ); + } + + /* open another handle to the child process */ + hChildProcess = OpenProcess( PROCESS_ALL_ACCESS, /* access */ + FALSE, /* inheritable */ + pi.dwProcessId /* process id */ + ); + if( hChildProcess == NULL ) + { + dwError = GetLastError(); + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + } + Trace( "ERROR:%lu:OpenProcess call failed\n", dwError ); + goto cleanup2; + } + + /* release the mutex so the child can proceed */ + if( ReleaseMutex( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:ReleaseMutex() call failed\n", GetLastError() ); + goto cleanup; + } + + /* wait for the child process to complete, using the new handle */ + dwRet = WaitForSingleObject( hChildProcess, 10000 ); + if( dwRet != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject call returned %lu, " + "expected WAIT_OBJECT_0", + dwRet ); + goto cleanup; + } + + /* remember that we waited until the child was finished */ + bChildDone = TRUE; + + /* check the exit code from the process -- this is a bit of an */ + /* extra verification that we opened the correct process handle */ + if( ! GetExitCodeProcess( hChildProcess, &dwExitCode ) ) + { + Trace( "ERROR:%lu:GetExitCodeProcess call failed\n", GetLastError() ); + goto cleanup; + } + + /* verification */ + if( (dwExitCode & 0xFF) != (TEST_EXIT_CODE & 0xFF) ) + { + Trace( "GetExitCodeProcess returned an incorrect exit code %d, " + "expected value is %d\n", + (dwExitCode & 0xFF), + (TEST_EXIT_CODE & 0xFF)); + goto cleanup; + } + + /* success if we get here */ + ret = PASS; + + +cleanup: + /* wait on the child process to complete if necessary */ + if( ! bChildDone ) + { + dwRet = WaitForSingleObject( hChildProcess, 10000 ); + if( dwRet != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject call returned %lu, " + "expected WAIT_OBJECT_0", + dwRet ); + ret = FAIL; + } + } + + /* close all our handles */ + if( CloseHandle ( hChildProcess ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + ret = FAIL; + } + +cleanup2: + if( CloseHandle ( pi.hProcess ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + ret = FAIL; + } + if( CloseHandle ( pi.hThread ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + ret = FAIL; + } + if( CloseHandle( hMutex ) == 0 ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + ret = FAIL; + } + + if( ret == FAIL ) + { + Fail( "test failed\n" ); + } + + + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/CMakeLists.txt index ad3eec1a45..9a54ad15b6 100644 --- a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_querythreadcycletime_test1 diff --git a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.c b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.c deleted file mode 100644 index 54f0116bd0..0000000000 --- a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.c +++ /dev/null @@ -1,98 +0,0 @@ -// 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: -** -** Source : test1.c -** -** Purpose: Test for QueryThreadCycleTime() function -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) { - int ret = FAIL; - - //Test is failing unreliably, so for now we always return pass. - if (TRUE){ - ret = PASS; - goto EXIT; - } - - LONG64 Actual, Expected, Delta = 850000000; - Actual = 0; - Expected = 0; - const LONG64 MSEC_TO_NSEC = 1000000; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - HANDLE cThread = GetCurrentThread(); - - int i; - /* Take 2000 tiny measurements */ - for (i = 0; i < 2000; i++){ - ULONG64 FirstCount, SecondCount; - LONG64 Init; - - Sleep(1); - - /* Grab a FirstCount, then loop for a bit to make the clock increase */ - if (!QueryThreadCycleTime(cThread, (PULONG64)&FirstCount)) - { - Fail("ERROR: QueryThreadCycleTime returned failure.\n"); - } - - LONG64 x; - /* Init is in milliseconds, so we will convert later */ - Init = (LONG64)GetTickCount(); - x = Init + 3; - volatile int counter; - do { - for (counter = 0; counter < 100000; counter++) - { - // spin to consume CPU time - } - - } while (x > GetTickCount()); - Expected += (GetTickCount() - Init) * MSEC_TO_NSEC; - /* Get a second count */ - if (!QueryThreadCycleTime(cThread, (PULONG64)&SecondCount)) - { - Fail("ERROR: QueryThreadCycleTime returned failure.\n"); - } - - LONG64 trial = (LONG64)SecondCount - (LONG64)FirstCount; - if (trial < 0){ - printf("Negative value %llu measured", trial); - } - Actual += (trial); - - } - - - - if(labs(Expected - Actual) > Delta) - { - Fail("ERROR: The measured time (%llu millisecs) was not within Delta %llu " - "of the expected time (%llu millisecs).\n", - (Actual / MSEC_TO_NSEC), (Delta / MSEC_TO_NSEC), (Expected / MSEC_TO_NSEC)); - } - //printf("%llu, %llu\n", Expected, Actual); - PAL_Terminate(); - ret = PASS; - -EXIT: - return ret; -} diff --git a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.cpp b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.cpp new file mode 100644 index 0000000000..026243c81a --- /dev/null +++ b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.cpp @@ -0,0 +1,98 @@ +// 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: +** +** Source : test1.c +** +** Purpose: Test for QueryThreadCycleTime() function +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) { + int ret = FAIL; + + //Test is failing unreliably, so for now we always return pass. + if (TRUE){ + ret = PASS; + goto EXIT; + } + { + LONG64 Actual, Expected, Delta = 850000000; + Actual = 0; + Expected = 0; + const LONG64 MSEC_TO_NSEC = 1000000; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + HANDLE cThread = GetCurrentThread(); + + int i; + /* Take 2000 tiny measurements */ + for (i = 0; i < 2000; i++){ + ULONG64 FirstCount, SecondCount; + LONG64 Init; + + Sleep(1); + + /* Grab a FirstCount, then loop for a bit to make the clock increase */ + if (!QueryThreadCycleTime(cThread, (PULONG64)&FirstCount)) + { + Fail("ERROR: QueryThreadCycleTime returned failure.\n"); + } + + LONG64 x; + /* Init is in milliseconds, so we will convert later */ + Init = (LONG64)GetTickCount(); + x = Init + 3; + volatile int counter; + do { + for (counter = 0; counter < 100000; counter++) + { + // spin to consume CPU time + } + + } while (x > GetTickCount()); + Expected += (GetTickCount() - Init) * MSEC_TO_NSEC; + /* Get a second count */ + if (!QueryThreadCycleTime(cThread, (PULONG64)&SecondCount)) + { + Fail("ERROR: QueryThreadCycleTime returned failure.\n"); + } + + LONG64 trial = (LONG64)SecondCount - (LONG64)FirstCount; + if (trial < 0){ + printf("Negative value %llu measured", trial); + } + Actual += (trial); + + } + + + + if(labs(Expected - Actual) > Delta) + { + Fail("ERROR: The measured time (%llu millisecs) was not within Delta %llu " + "of the expected time (%llu millisecs).\n", + (Actual / MSEC_TO_NSEC), (Delta / MSEC_TO_NSEC), (Expected / MSEC_TO_NSEC)); + } + //printf("%llu, %llu\n", Expected, Actual); + PAL_Terminate(); + ret = PASS; + } +EXIT: + return ret; +} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/QueueUserAPC/test1/CMakeLists.txt index 54a4d03719..a99b0a69cc 100644 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_queueuserapc_test1 diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test1/test1.c b/src/pal/tests/palsuite/threading/QueueUserAPC/test1/test1.c deleted file mode 100644 index 3637897ba7..0000000000 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test1/test1.c +++ /dev/null @@ -1,313 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that APCs sent to a thread in an alertable state via -** QueueUserAPC are executed in FIFO order. Also tests that the APC -** function is executed within the context of the correct thread and -** that the dwData parameter gets sent correctly. -** -** -**===================================================================*/ - -#include - -const int ChildThreadSleepTime = 2000; -const int InterruptTime = 1000; - -VOID PALAPI APCFuncA(ULONG_PTR dwParam); -VOID PALAPI APCFuncB(ULONG_PTR dwParam); -VOID PALAPI APCFuncC(ULONG_PTR dwParam); -VOID PALAPI APCFuncD(ULONG_PTR dwParam); -DWORD PALAPI SleeperProc(LPVOID lpParameter); - -const char *ExpectedResults = "A0B0C0D0A1B1C1D1A2B2C2D2A3B3C3D3"; -char ResultBuffer[256]; -char *ResultPtr; -DWORD ChildThread; - -/* synchronization events */ -static HANDLE hSyncEvent1 = NULL; -static HANDLE hSyncEvent2 = NULL; - -/* thread result because we have no GetExitCodeThread() API */ -BOOL bThreadResult = FAIL; - -int __cdecl main (int argc, char **argv) -{ - HANDLE hThread = NULL; - int ret; - int i,j; - BOOL bResult = FAIL; - - PAPCFUNC APCFuncs[] = - { - APCFuncA, - APCFuncB, - APCFuncC, - APCFuncD, - }; - - /* initialize the PAL */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ResultPtr = ResultBuffer; - - /* create a pair of synchronization events to coordinate our threads */ - hSyncEvent1 = CreateEvent( NULL, FALSE, FALSE, NULL ); - if( hSyncEvent1 == NULL ) - { - Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - hSyncEvent2 = CreateEvent( NULL, FALSE, FALSE, NULL ); - if( hSyncEvent2 == NULL ) - { - Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - /* create a child thread which will call SleepEx */ - hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)SleeperProc, - 0, - 0, - &ChildThread); - - if( hThread == NULL ) - { - Trace( "ERROR:%lu:CreateThread() call failed\n", - GetLastError()); - goto cleanup; - } - - - /* wait on our synchronization event to ensure the thread is running */ - ret = WaitForSingleObject( hSyncEvent1, 20000 ); - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - goto cleanup; - } - - - /* queue our user APC functions on the thread */ - for (i=0; i<4; i++) - { - for (j=0; j + +const int ChildThreadSleepTime = 2000; +const int InterruptTime = 1000; + +VOID PALAPI APCFuncA(ULONG_PTR dwParam); +VOID PALAPI APCFuncB(ULONG_PTR dwParam); +VOID PALAPI APCFuncC(ULONG_PTR dwParam); +VOID PALAPI APCFuncD(ULONG_PTR dwParam); +DWORD PALAPI SleeperProc(LPVOID lpParameter); + +const char *ExpectedResults = "A0B0C0D0A1B1C1D1A2B2C2D2A3B3C3D3"; +char ResultBuffer[256]; +char *ResultPtr; +DWORD ChildThread; + +/* synchronization events */ +static HANDLE hSyncEvent1 = NULL; +static HANDLE hSyncEvent2 = NULL; + +/* thread result because we have no GetExitCodeThread() API */ +BOOL bThreadResult = FAIL; + +int __cdecl main (int argc, char **argv) +{ + HANDLE hThread = NULL; + int ret; + int i,j; + BOOL bResult = FAIL; + + PAPCFUNC APCFuncs[] = + { + APCFuncA, + APCFuncB, + APCFuncC, + APCFuncD, + }; + + /* initialize the PAL */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ResultPtr = ResultBuffer; + + /* create a pair of synchronization events to coordinate our threads */ + hSyncEvent1 = CreateEvent( NULL, FALSE, FALSE, NULL ); + if( hSyncEvent1 == NULL ) + { + Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + hSyncEvent2 = CreateEvent( NULL, FALSE, FALSE, NULL ); + if( hSyncEvent2 == NULL ) + { + Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + /* create a child thread which will call SleepEx */ + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)SleeperProc, + 0, + 0, + &ChildThread); + + if( hThread == NULL ) + { + Trace( "ERROR:%lu:CreateThread() call failed\n", + GetLastError()); + goto cleanup; + } + + + /* wait on our synchronization event to ensure the thread is running */ + ret = WaitForSingleObject( hSyncEvent1, 20000 ); + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + goto cleanup; + } + + + /* queue our user APC functions on the thread */ + for (i=0; i<4; i++) + { + for (j=0; j - -const int ChildThreadSleepTime = 2000; -const int InterruptTime = 1000; - -DWORD ChildThread; -BOOL InAPC; - -/* synchronization events */ -static HANDLE hSyncEvent1 = NULL; -static HANDLE hSyncEvent2 = NULL; - -/* thread result because we have no GetExitCodeThread() API */ -static BOOL bThreadResult = FAIL; - - -VOID PALAPI APCFunc(ULONG_PTR dwParam) -{ - InAPC = TRUE; -} - -DWORD PALAPI SleeperProc(LPVOID lpParameter) -{ - DWORD ret; - - /* signal the main thread that we're ready to proceed */ - if( ! SetEvent( hSyncEvent1 ) ) - { - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - bThreadResult = FAIL; - goto done; - } - - /* wait for notification from the main thread */ - ret = WaitForSingleObject( hSyncEvent2, 20000 ); - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - bThreadResult = FAIL; - goto done; - } - - /* call our sleep function */ - Sleep( ChildThreadSleepTime ); - - /* success if we reach here */ - bThreadResult = PASS; - - -done: - - /* signal the main thread that we're finished */ - if( ! SetEvent( hSyncEvent1 ) ) - { - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - bThreadResult = FAIL; - } - - /* return success or failure */ - return bThreadResult; -} - - -int __cdecl main (int argc, char **argv) -{ - /* local variables */ - HANDLE hThread = 0; - int ret; - BOOL bResult = FAIL; - - /* initialize the PAL */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - InAPC = FALSE; - - /* create a pair of synchronization events to coordinate our threads */ - hSyncEvent1 = CreateEvent( NULL, FALSE, FALSE, NULL ); - if( hSyncEvent1 == NULL ) - { - Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - hSyncEvent2 = CreateEvent( NULL, FALSE, FALSE, NULL ); - if( hSyncEvent2 == NULL ) - { - Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - /* create a child thread */ - hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)SleeperProc, - 0, - 0, - &ChildThread); - - if (hThread == NULL) - { - Trace( "ERROR:%lu:CreateThread() call failed\n", - GetLastError()); - goto cleanup; - } - - - /* wait on our synchronization event to ensure the thread is running */ - ret = WaitForSingleObject( hSyncEvent1, 20000 ); - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - goto cleanup; - } - - /* queue a user APC on the child thread */ - ret = QueueUserAPC(APCFunc, hThread, 0); - if (ret == 0) - { - Trace( "ERROR:%lu:QueueUserAPC() call failed\n", - GetLastError()); - goto cleanup; - } - - /* signal the child thread to continue */ - if( ! SetEvent( hSyncEvent2 ) ) - { - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - /* wait on our synchronization event to ensure the other thread is done */ - ret = WaitForSingleObject( hSyncEvent1, 20000 ); - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - goto cleanup; - } - - /* check that the thread executed successfully */ - if( bThreadResult == FAIL ) - { - goto cleanup; - } - - - /* check whether the APC function was executed */ - if( InAPC ) - { - Trace( "FAIL:APC function was executed but shouldn't have been\n" ); - goto cleanup; - } - - /* success if we reach here */ - bResult = PASS; - - -cleanup: - /* wait for the other thread to finish */ - if( hThread != NULL ) - { - ret = WaitForSingleObject( hThread, INFINITE ); - if (ret == WAIT_FAILED) - { - Trace( "ERROR:%lu:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - bResult = FAIL; - } - } - - /* close our synchronization handles */ - if( hSyncEvent1 != NULL ) - { - if( ! CloseHandle( hSyncEvent1 ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - bResult = FAIL; - } - } - - if( hSyncEvent2 != NULL ) - { - if( ! CloseHandle( hSyncEvent2 ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - bResult = FAIL; - } - } - - if( bResult == FAIL ) - { - Fail( "test failed\n" ); - } - - - /* terminate the PAL */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test2/test2.cpp b/src/pal/tests/palsuite/threading/QueueUserAPC/test2/test2.cpp new file mode 100644 index 0000000000..dc2bfdb173 --- /dev/null +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test2/test2.cpp @@ -0,0 +1,224 @@ +// 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: test2.c +** +** Purpose: Tests that APCs are not executed if a thread never enters an +** alertable state after they are queued. +** +** +**===================================================================*/ + +#include + +const int ChildThreadSleepTime = 2000; +const int InterruptTime = 1000; + +DWORD ChildThread; +BOOL InAPC; + +/* synchronization events */ +static HANDLE hSyncEvent1 = NULL; +static HANDLE hSyncEvent2 = NULL; + +/* thread result because we have no GetExitCodeThread() API */ +static BOOL bThreadResult = FAIL; + + +VOID PALAPI APCFunc(ULONG_PTR dwParam) +{ + InAPC = TRUE; +} + +DWORD PALAPI SleeperProc(LPVOID lpParameter) +{ + DWORD ret; + + /* signal the main thread that we're ready to proceed */ + if( ! SetEvent( hSyncEvent1 ) ) + { + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + bThreadResult = FAIL; + goto done; + } + + /* wait for notification from the main thread */ + ret = WaitForSingleObject( hSyncEvent2, 20000 ); + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + bThreadResult = FAIL; + goto done; + } + + /* call our sleep function */ + Sleep( ChildThreadSleepTime ); + + /* success if we reach here */ + bThreadResult = PASS; + + +done: + + /* signal the main thread that we're finished */ + if( ! SetEvent( hSyncEvent1 ) ) + { + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + bThreadResult = FAIL; + } + + /* return success or failure */ + return bThreadResult; +} + + +int __cdecl main (int argc, char **argv) +{ + /* local variables */ + HANDLE hThread = 0; + int ret; + BOOL bResult = FAIL; + + /* initialize the PAL */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + InAPC = FALSE; + + /* create a pair of synchronization events to coordinate our threads */ + hSyncEvent1 = CreateEvent( NULL, FALSE, FALSE, NULL ); + if( hSyncEvent1 == NULL ) + { + Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + hSyncEvent2 = CreateEvent( NULL, FALSE, FALSE, NULL ); + if( hSyncEvent2 == NULL ) + { + Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + /* create a child thread */ + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)SleeperProc, + 0, + 0, + &ChildThread); + + if (hThread == NULL) + { + Trace( "ERROR:%lu:CreateThread() call failed\n", + GetLastError()); + goto cleanup; + } + + + /* wait on our synchronization event to ensure the thread is running */ + ret = WaitForSingleObject( hSyncEvent1, 20000 ); + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + goto cleanup; + } + + /* queue a user APC on the child thread */ + ret = QueueUserAPC(APCFunc, hThread, 0); + if (ret == 0) + { + Trace( "ERROR:%lu:QueueUserAPC() call failed\n", + GetLastError()); + goto cleanup; + } + + /* signal the child thread to continue */ + if( ! SetEvent( hSyncEvent2 ) ) + { + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + /* wait on our synchronization event to ensure the other thread is done */ + ret = WaitForSingleObject( hSyncEvent1, 20000 ); + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + goto cleanup; + } + + /* check that the thread executed successfully */ + if( bThreadResult == FAIL ) + { + goto cleanup; + } + + + /* check whether the APC function was executed */ + if( InAPC ) + { + Trace( "FAIL:APC function was executed but shouldn't have been\n" ); + goto cleanup; + } + + /* success if we reach here */ + bResult = PASS; + + +cleanup: + /* wait for the other thread to finish */ + if( hThread != NULL ) + { + ret = WaitForSingleObject( hThread, INFINITE ); + if (ret == WAIT_FAILED) + { + Trace( "ERROR:%lu:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + bResult = FAIL; + } + } + + /* close our synchronization handles */ + if( hSyncEvent1 != NULL ) + { + if( ! CloseHandle( hSyncEvent1 ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + bResult = FAIL; + } + } + + if( hSyncEvent2 != NULL ) + { + if( ! CloseHandle( hSyncEvent2 ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + bResult = FAIL; + } + } + + if( bResult == FAIL ) + { + Fail( "test failed\n" ); + } + + + /* terminate the PAL */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/QueueUserAPC/test3/CMakeLists.txt index 8475dcb03e..e07ab67070 100644 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_queueuserapc_test3 diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test3/test3.c b/src/pal/tests/palsuite/threading/QueueUserAPC/test3/test3.c deleted file mode 100644 index 933f41a5b4..0000000000 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test3/test3.c +++ /dev/null @@ -1,33 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests how QueueUserAPC handles an invalid thread. -** -** -**===================================================================*/ - -#include - -int __cdecl main (int argc, char **argv) -{ - int ret; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - ret = QueueUserAPC(NULL, NULL, 0); - if (ret != 0) - { - Fail("QueueUserAPC passed with an invalid thread!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test3/test3.cpp b/src/pal/tests/palsuite/threading/QueueUserAPC/test3/test3.cpp new file mode 100644 index 0000000000..933f41a5b4 --- /dev/null +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test3/test3.cpp @@ -0,0 +1,33 @@ +// 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: test3.c +** +** Purpose: Tests how QueueUserAPC handles an invalid thread. +** +** +**===================================================================*/ + +#include + +int __cdecl main (int argc, char **argv) +{ + int ret; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ret = QueueUserAPC(NULL, NULL, 0); + if (ret != 0) + { + Fail("QueueUserAPC passed with an invalid thread!\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/QueueUserAPC/test4/CMakeLists.txt index 2552738b50..08a5cc763b 100644 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_queueuserapc_test4 diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test4/test4.c b/src/pal/tests/palsuite/threading/QueueUserAPC/test4/test4.c deleted file mode 100644 index c28709db81..0000000000 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test4/test4.c +++ /dev/null @@ -1,72 +0,0 @@ -// 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: test4.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** GetCurrentThread -** SleepEx -** -** Purpose: -** -** Test to ensure proper operation of the QueueUserAPC() -** API by trying to queue APC functions on the current -** thread. -** -** -**===========================================================================*/ -#include - - -static BOOL bAPCExecuted = FALSE; - -VOID PALAPI APCFunc( ULONG_PTR dwParam ) -{ - bAPCExecuted = TRUE; -} - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - HANDLE hThread = NULL; - DWORD ret; - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - /* get the current thread */ - hThread = GetCurrentThread(); - ret = QueueUserAPC( APCFunc, hThread, 0 ); - if( ret == 0 ) - { - Fail( "ERROR:%lu:QueueUserAPC call failed\n", GetLastError() ); - } - - /* call SleepEx() to put the thread in an alertable state */ - ret = SleepEx( 2000, TRUE ); - if( ret != WAIT_IO_COMPLETION ) - { - Fail( "ERROR:Expected sleep to return WAIT_IO_COMPLETION, got %lu\n", - ret ); - } - - /* check that the APC function was executed */ - if( bAPCExecuted == FALSE ) - { - Fail( "ERROR:APC function was not executed\n" ); - } - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test4/test4.cpp b/src/pal/tests/palsuite/threading/QueueUserAPC/test4/test4.cpp new file mode 100644 index 0000000000..c28709db81 --- /dev/null +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test4/test4.cpp @@ -0,0 +1,72 @@ +// 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: test4.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** GetCurrentThread +** SleepEx +** +** Purpose: +** +** Test to ensure proper operation of the QueueUserAPC() +** API by trying to queue APC functions on the current +** thread. +** +** +**===========================================================================*/ +#include + + +static BOOL bAPCExecuted = FALSE; + +VOID PALAPI APCFunc( ULONG_PTR dwParam ) +{ + bAPCExecuted = TRUE; +} + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + HANDLE hThread = NULL; + DWORD ret; + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + /* get the current thread */ + hThread = GetCurrentThread(); + ret = QueueUserAPC( APCFunc, hThread, 0 ); + if( ret == 0 ) + { + Fail( "ERROR:%lu:QueueUserAPC call failed\n", GetLastError() ); + } + + /* call SleepEx() to put the thread in an alertable state */ + ret = SleepEx( 2000, TRUE ); + if( ret != WAIT_IO_COMPLETION ) + { + Fail( "ERROR:Expected sleep to return WAIT_IO_COMPLETION, got %lu\n", + ret ); + } + + /* check that the APC function was executed */ + if( bAPCExecuted == FALSE ) + { + Fail( "ERROR:APC function was not executed\n" ); + } + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test5/CMakeLists.txt b/src/pal/tests/palsuite/threading/QueueUserAPC/test5/CMakeLists.txt index c2fa10de12..0ef65ce583 100644 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_queueuserapc_test5 diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test5/test5.c b/src/pal/tests/palsuite/threading/QueueUserAPC/test5/test5.c deleted file mode 100644 index 3d26a55f59..0000000000 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test5/test5.c +++ /dev/null @@ -1,200 +0,0 @@ -// 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: test5.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** SetEvent -** CreateThread -** ResumeThread -** WaitForSingleObject -** CloseHandle -** -** Purpose: -** -** Test to ensure proper operation of the QueueUserAPC() -** API by trying to queue and activate APC functions on -** a thread that was created suspended, prior to resuming -** it. We're verifying the following behavior: -** -** "If an application queues an APC before the thread begins -** running, the thread begins by calling the APC function. -** After the thread calls an APC function, it calls the APC -** functions for all APCs in its APC queue." -** -** -**===========================================================================*/ -#include - - -static HANDLE hEvent = NULL; -static BOOL bAPCExecuted = FALSE; - -VOID PALAPI APCFunc( ULONG_PTR dwParam ) -{ - bAPCExecuted = TRUE; -} - -/** - * ThreadFunc - * - * Dummy thread function for APC queuing. - */ -DWORD PALAPI ThreadFunc( LPVOID param ) -{ - DWORD ret = 0; - - /* alertable wait until the global event is signalled */ - ret = WaitForSingleObject( hEvent, INFINITE ); - if( ret != WAIT_OBJECT_0 ) - { - Fail( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - } - - return 0; -} - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - HANDLE hThread = NULL; - DWORD IDThread; - DWORD ret; - BOOL bResult = FALSE; - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - /* create an event for the other thread to wait on */ - hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); - if( hEvent == NULL ) - { - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* run another dummy thread to cause notification of the library */ - hThread = CreateThread( NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ - (LPVOID) NULL, /* pass thread index as */ - /* function argument */ - CREATE_SUSPENDED, /* create suspended */ - &IDThread ); /* returns thread id */ - - /* Check the return value for success. */ - if( hThread == NULL ) - { - /* error creating thread */ - Trace( "ERROR:%lu:CreateThread call failed\n", GetLastError() ); - if( ! CloseHandle( hEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "test failed\n" ); - } - - /* queue our APC on the suspended thread */ - ret = QueueUserAPC( APCFunc, hThread, 0 ); - if( ret == 0 ) - { - Fail( "ERROR:%lu:QueueUserAPC call failed\n", GetLastError() ); - } - - /* wait on the suspended thread */ - ret = WaitForSingleObject( hThread, 2000 ); - if( ret != WAIT_TIMEOUT ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_TIMEOUT\n", - ret ); - goto cleanup; - } - - /* verify that the APC function was not executed */ - if( bAPCExecuted == TRUE ) - { - Trace( "ERROR:APC function was executed for a suspended thread\n" ); - goto cleanup; - } - - /* Resume the suspended thread */ - ResumeThread( hThread ); - - /* do another wait on the resumed thread */ - ret = WaitForSingleObject( hThread, 2000 ); - - /* verify that we got a WAIT_TIMEOUT result */ - if( ret != WAIT_TIMEOUT ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_TIMEOUT\n", - ret ); - goto cleanup; - } - - /* check that the APC function was actually executed */ - if( bAPCExecuted == FALSE ) - { - Trace( "ERROR:APC function was not executed\n" ); - goto cleanup; - } - - /* set the success flag */ - bResult = PASS; - -cleanup: - /* signal the event so the other thread will exit */ - if( ! SetEvent( hEvent ) ) - { - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - bResult = FAIL; - } - - /* close the global event handle */ - if( ! CloseHandle( hEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - bResult = FAIL; - } - - /* wait on the other thread to complete */ - ret = WaitForSingleObject( hThread, 2000 ); - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - bResult = FAIL; - } - - /* close the thread handle */ - if( ! CloseHandle( hThread ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - bResult = FAIL; - } - - /* output final failure result for failure case */ - if( bResult == FAIL ) - { - Fail( "test failed\n" ); - } - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test5/test5.cpp b/src/pal/tests/palsuite/threading/QueueUserAPC/test5/test5.cpp new file mode 100644 index 0000000000..3d26a55f59 --- /dev/null +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test5/test5.cpp @@ -0,0 +1,200 @@ +// 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: test5.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** SetEvent +** CreateThread +** ResumeThread +** WaitForSingleObject +** CloseHandle +** +** Purpose: +** +** Test to ensure proper operation of the QueueUserAPC() +** API by trying to queue and activate APC functions on +** a thread that was created suspended, prior to resuming +** it. We're verifying the following behavior: +** +** "If an application queues an APC before the thread begins +** running, the thread begins by calling the APC function. +** After the thread calls an APC function, it calls the APC +** functions for all APCs in its APC queue." +** +** +**===========================================================================*/ +#include + + +static HANDLE hEvent = NULL; +static BOOL bAPCExecuted = FALSE; + +VOID PALAPI APCFunc( ULONG_PTR dwParam ) +{ + bAPCExecuted = TRUE; +} + +/** + * ThreadFunc + * + * Dummy thread function for APC queuing. + */ +DWORD PALAPI ThreadFunc( LPVOID param ) +{ + DWORD ret = 0; + + /* alertable wait until the global event is signalled */ + ret = WaitForSingleObject( hEvent, INFINITE ); + if( ret != WAIT_OBJECT_0 ) + { + Fail( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + } + + return 0; +} + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + HANDLE hThread = NULL; + DWORD IDThread; + DWORD ret; + BOOL bResult = FALSE; + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + /* create an event for the other thread to wait on */ + hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); + if( hEvent == NULL ) + { + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* run another dummy thread to cause notification of the library */ + hThread = CreateThread( NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ + (LPVOID) NULL, /* pass thread index as */ + /* function argument */ + CREATE_SUSPENDED, /* create suspended */ + &IDThread ); /* returns thread id */ + + /* Check the return value for success. */ + if( hThread == NULL ) + { + /* error creating thread */ + Trace( "ERROR:%lu:CreateThread call failed\n", GetLastError() ); + if( ! CloseHandle( hEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "test failed\n" ); + } + + /* queue our APC on the suspended thread */ + ret = QueueUserAPC( APCFunc, hThread, 0 ); + if( ret == 0 ) + { + Fail( "ERROR:%lu:QueueUserAPC call failed\n", GetLastError() ); + } + + /* wait on the suspended thread */ + ret = WaitForSingleObject( hThread, 2000 ); + if( ret != WAIT_TIMEOUT ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_TIMEOUT\n", + ret ); + goto cleanup; + } + + /* verify that the APC function was not executed */ + if( bAPCExecuted == TRUE ) + { + Trace( "ERROR:APC function was executed for a suspended thread\n" ); + goto cleanup; + } + + /* Resume the suspended thread */ + ResumeThread( hThread ); + + /* do another wait on the resumed thread */ + ret = WaitForSingleObject( hThread, 2000 ); + + /* verify that we got a WAIT_TIMEOUT result */ + if( ret != WAIT_TIMEOUT ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_TIMEOUT\n", + ret ); + goto cleanup; + } + + /* check that the APC function was actually executed */ + if( bAPCExecuted == FALSE ) + { + Trace( "ERROR:APC function was not executed\n" ); + goto cleanup; + } + + /* set the success flag */ + bResult = PASS; + +cleanup: + /* signal the event so the other thread will exit */ + if( ! SetEvent( hEvent ) ) + { + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + bResult = FAIL; + } + + /* close the global event handle */ + if( ! CloseHandle( hEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + bResult = FAIL; + } + + /* wait on the other thread to complete */ + ret = WaitForSingleObject( hThread, 2000 ); + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + bResult = FAIL; + } + + /* close the thread handle */ + if( ! CloseHandle( hThread ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + bResult = FAIL; + } + + /* output final failure result for failure case */ + if( bResult == FAIL ) + { + Fail( "test failed\n" ); + } + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test6/CMakeLists.txt b/src/pal/tests/palsuite/threading/QueueUserAPC/test6/CMakeLists.txt index 3fd1b1a08e..2e7198358c 100644 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test6.c + test6.cpp ) add_executable(paltest_queueuserapc_test6 diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test6/test6.c b/src/pal/tests/palsuite/threading/QueueUserAPC/test6/test6.c deleted file mode 100644 index e2e2464726..0000000000 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test6/test6.c +++ /dev/null @@ -1,129 +0,0 @@ -// 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: test6.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** SetEvent -** CreateThread -** ResumeThread -** WaitForMultipleObjectsEx -** CloseHandle -** -** Purpose: -** -** Test to ensure proper operation of the QueueUserAPC() -** API by trying to queue APC functions on a thread that -** has already terminated. -** -** -**===========================================================================*/ -#include - - -static BOOL bAPCExecuted = FALSE; - -VOID PALAPI APCFunc( ULONG_PTR dwParam ) -{ - bAPCExecuted = TRUE; -} - -/** - * ThreadFunc - * - * Dummy thread function for APC queuing. - */ -DWORD PALAPI ThreadFunc( LPVOID param ) -{ - int i; - - /* simulate some activity */ - for( i=0; i<250000; i++ ) - ; - - return 0; -} - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - HANDLE hThread = NULL; - DWORD IDThread; - DWORD ret; - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - /* run another dummy thread to cause notification of the library */ - hThread = CreateThread( NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ - (LPVOID) NULL, /* pass thread index as */ - /* function argument */ - CREATE_SUSPENDED, /* create suspended */ - &IDThread ); /* returns thread id */ - - /* Check the return value for success. */ - if( hThread == NULL ) - { - /* error creating thread */ - Fail( "ERROR:%lu:CreateThread call failed\n", GetLastError() ); - } - - /* Resume the suspended thread */ - ResumeThread( hThread ); - - /* wait on the other thread to complete */ - ret = WaitForSingleObject( hThread, INFINITE ); - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - if( ! CloseHandle( hThread ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "test failed\n" ); - } - - /* queue our APC on the finished thread */ - ret = QueueUserAPC( APCFunc, hThread, 0 ); - if( ret != 0 ) - { - Trace( "ERROR:QueueUserAPC call succeeded on a terminated thread\n" ); - if( ! CloseHandle( hThread ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "test failed\n" ); - } - - if( ! CloseHandle( hThread ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - - /* dummy check that the APC function wasn't actually executed */ - if( bAPCExecuted != FALSE ) - { - Fail( "ERROR:APC function was executed\n" ); - } - - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test6/test6.cpp b/src/pal/tests/palsuite/threading/QueueUserAPC/test6/test6.cpp new file mode 100644 index 0000000000..e2e2464726 --- /dev/null +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test6/test6.cpp @@ -0,0 +1,129 @@ +// 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: test6.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** SetEvent +** CreateThread +** ResumeThread +** WaitForMultipleObjectsEx +** CloseHandle +** +** Purpose: +** +** Test to ensure proper operation of the QueueUserAPC() +** API by trying to queue APC functions on a thread that +** has already terminated. +** +** +**===========================================================================*/ +#include + + +static BOOL bAPCExecuted = FALSE; + +VOID PALAPI APCFunc( ULONG_PTR dwParam ) +{ + bAPCExecuted = TRUE; +} + +/** + * ThreadFunc + * + * Dummy thread function for APC queuing. + */ +DWORD PALAPI ThreadFunc( LPVOID param ) +{ + int i; + + /* simulate some activity */ + for( i=0; i<250000; i++ ) + ; + + return 0; +} + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + HANDLE hThread = NULL; + DWORD IDThread; + DWORD ret; + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + /* run another dummy thread to cause notification of the library */ + hThread = CreateThread( NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ + (LPVOID) NULL, /* pass thread index as */ + /* function argument */ + CREATE_SUSPENDED, /* create suspended */ + &IDThread ); /* returns thread id */ + + /* Check the return value for success. */ + if( hThread == NULL ) + { + /* error creating thread */ + Fail( "ERROR:%lu:CreateThread call failed\n", GetLastError() ); + } + + /* Resume the suspended thread */ + ResumeThread( hThread ); + + /* wait on the other thread to complete */ + ret = WaitForSingleObject( hThread, INFINITE ); + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + if( ! CloseHandle( hThread ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "test failed\n" ); + } + + /* queue our APC on the finished thread */ + ret = QueueUserAPC( APCFunc, hThread, 0 ); + if( ret != 0 ) + { + Trace( "ERROR:QueueUserAPC call succeeded on a terminated thread\n" ); + if( ! CloseHandle( hThread ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "test failed\n" ); + } + + if( ! CloseHandle( hThread ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + /* dummy check that the APC function wasn't actually executed */ + if( bAPCExecuted != FALSE ) + { + Fail( "ERROR:APC function was executed\n" ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test7/CMakeLists.txt b/src/pal/tests/palsuite/threading/QueueUserAPC/test7/CMakeLists.txt index 751f3894f4..c27cd7e67c 100644 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test7/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test7/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test7.c + test7.cpp ) add_executable(paltest_queueuserapc_test7 diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test7/test7.c b/src/pal/tests/palsuite/threading/QueueUserAPC/test7/test7.c deleted file mode 100644 index 54a63982fe..0000000000 --- a/src/pal/tests/palsuite/threading/QueueUserAPC/test7/test7.c +++ /dev/null @@ -1,253 +0,0 @@ -// 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: test7.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** SetEvent -** CreateThread -** ResumeThread -** WaitForMultipleObjectsEx -** CloseHandle -** -** Purpose: -** -** Test to ensure proper operation of the QueueUserAPC() -** API by trying to queue an APC function on a thread and -** activating it with WaitForMultipleObjectsEx. -** -** -**===========================================================================*/ -#include - - -static HANDLE hSyncEvent = NULL; -static HANDLE hTestEvent = NULL; -static int nAPCExecuted = 0; -static BOOL bThreadResult = FALSE; - -VOID PALAPI APCFunc( ULONG_PTR dwParam ) -{ - ++nAPCExecuted; -} - -/** - * ThreadFunc - * - * Dummy thread function for APC queuing. - */ -DWORD PALAPI ThreadFunc( LPVOID param ) -{ - DWORD ret = 0; - - /* pessimism */ - bThreadResult = FALSE; - - /* set the sync event to notify the main thread */ - if( ! SetEvent( hSyncEvent ) ) - { - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - goto done; - } - - /* wait until the test event is signalled */ - ret = WaitForSingleObject( hTestEvent, INFINITE ); - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - goto done; - } - - /* now do an alertable wait on the same event, which is now - in an unsignalled state */ - ret = WaitForMultipleObjectsEx( 1, &hTestEvent, TRUE, 2000, TRUE ); - - /* verify that we got a WAIT_IO_COMPLETION result */ - if( ret != WAIT_IO_COMPLETION ) - { - Trace( "ERROR:WaitForMultipleObjectsEx returned %lu, " - "expected WAIT_IO_COMPLETION\n", - ret ); - goto done; - } - - /* set the event again */ - if( ! SetEvent( hTestEvent ) ) - { - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - goto done; - } - - /* do a non-alertable wait on the same event */ - ret = WaitForMultipleObjectsEx( 1, &hTestEvent, TRUE, INFINITE, FALSE ); - - /* verify that we got a WAIT_OBJECT_0 result */ - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForMultipleObjectsEx returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - goto done; - } - - /* success at this point */ - bThreadResult = TRUE; - - -done: - return bThreadResult; -} - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - HANDLE hThread = NULL; - DWORD IDThread; - DWORD ret; - BOOL bResult = FALSE; - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - /* create an auto-reset event for the other thread to wait on */ - hTestEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); - if( hTestEvent == NULL ) - { - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* create an auto-reset event for synchronization */ - hSyncEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); - if( hSyncEvent == NULL ) - { - Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - if( ! CloseHandle( hTestEvent ) ) - { - Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - Fail( "test failed\n" ); - } - - /* run another dummy thread to cause notification of the library */ - hThread = CreateThread( NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ - (LPVOID) NULL, /* pass thread index as */ - /* function argument */ - CREATE_SUSPENDED, /* create suspended */ - &IDThread ); /* returns thread id */ - - /* Check the return value for success. */ - if( hThread == NULL ) - { - /* error creating thread */ - Trace( "ERROR:%lu:CreateThread call failed\n", GetLastError() ); - if( ! CloseHandle( hTestEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - Fail( "test failed\n" ); - } - - /* Resume the suspended thread */ - ResumeThread( hThread ); - - /* wait until the other thread is ready to proceed */ - ret = WaitForSingleObject( hSyncEvent, 10000 ); - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - goto cleanup; - } - - - /* now queue our APC on the test thread */ - ret = QueueUserAPC( APCFunc, hThread, 0 ); - if( ret == 0 ) - { - Trace( "ERROR:%lu:QueueUserAPC call failed\n", GetLastError() ); - goto cleanup; - } - - /* signal the test event so the other thread will proceed */ - if( ! SetEvent( hTestEvent ) ) - { - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - goto cleanup; - } - - /* wait on the other thread to complete */ - ret = WaitForSingleObject( hThread, INFINITE ); - if( ret != WAIT_OBJECT_0 ) - { - Trace( "ERROR:WaitForSingleObject() returned %lu, " - "expected WAIT_OBJECT_0\n", - ret ); - goto cleanup; - } - - /* check the result of the other thread */ - if( bThreadResult == FALSE ) - { - goto cleanup; - } - - /* check that the APC function was actually executed exactly one time */ - if( nAPCExecuted != 1 ) - { - Trace( "ERROR:APC function was executed %d times, " - "expected once\n", nAPCExecuted ); - goto cleanup; - } - - /* set the success flag */ - bResult = PASS; - - -cleanup: - /* close the global event handles */ - if( ! CloseHandle( hTestEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - bResult = FAIL; - } - - if( ! CloseHandle( hSyncEvent ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - bResult = FAIL; - } - - /* close the thread handle */ - if( ! CloseHandle( hThread ) ) - { - Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - bResult = FAIL; - } - - /* output final failure result for failure case */ - if( bResult == FAIL ) - { - Fail( "test failed\n" ); - } - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/QueueUserAPC/test7/test7.cpp b/src/pal/tests/palsuite/threading/QueueUserAPC/test7/test7.cpp new file mode 100644 index 0000000000..54a63982fe --- /dev/null +++ b/src/pal/tests/palsuite/threading/QueueUserAPC/test7/test7.cpp @@ -0,0 +1,253 @@ +// 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: test7.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** SetEvent +** CreateThread +** ResumeThread +** WaitForMultipleObjectsEx +** CloseHandle +** +** Purpose: +** +** Test to ensure proper operation of the QueueUserAPC() +** API by trying to queue an APC function on a thread and +** activating it with WaitForMultipleObjectsEx. +** +** +**===========================================================================*/ +#include + + +static HANDLE hSyncEvent = NULL; +static HANDLE hTestEvent = NULL; +static int nAPCExecuted = 0; +static BOOL bThreadResult = FALSE; + +VOID PALAPI APCFunc( ULONG_PTR dwParam ) +{ + ++nAPCExecuted; +} + +/** + * ThreadFunc + * + * Dummy thread function for APC queuing. + */ +DWORD PALAPI ThreadFunc( LPVOID param ) +{ + DWORD ret = 0; + + /* pessimism */ + bThreadResult = FALSE; + + /* set the sync event to notify the main thread */ + if( ! SetEvent( hSyncEvent ) ) + { + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + goto done; + } + + /* wait until the test event is signalled */ + ret = WaitForSingleObject( hTestEvent, INFINITE ); + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + goto done; + } + + /* now do an alertable wait on the same event, which is now + in an unsignalled state */ + ret = WaitForMultipleObjectsEx( 1, &hTestEvent, TRUE, 2000, TRUE ); + + /* verify that we got a WAIT_IO_COMPLETION result */ + if( ret != WAIT_IO_COMPLETION ) + { + Trace( "ERROR:WaitForMultipleObjectsEx returned %lu, " + "expected WAIT_IO_COMPLETION\n", + ret ); + goto done; + } + + /* set the event again */ + if( ! SetEvent( hTestEvent ) ) + { + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + goto done; + } + + /* do a non-alertable wait on the same event */ + ret = WaitForMultipleObjectsEx( 1, &hTestEvent, TRUE, INFINITE, FALSE ); + + /* verify that we got a WAIT_OBJECT_0 result */ + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForMultipleObjectsEx returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + goto done; + } + + /* success at this point */ + bThreadResult = TRUE; + + +done: + return bThreadResult; +} + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + HANDLE hThread = NULL; + DWORD IDThread; + DWORD ret; + BOOL bResult = FALSE; + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + /* create an auto-reset event for the other thread to wait on */ + hTestEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); + if( hTestEvent == NULL ) + { + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* create an auto-reset event for synchronization */ + hSyncEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); + if( hSyncEvent == NULL ) + { + Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + if( ! CloseHandle( hTestEvent ) ) + { + Trace( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + Fail( "test failed\n" ); + } + + /* run another dummy thread to cause notification of the library */ + hThread = CreateThread( NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ + (LPVOID) NULL, /* pass thread index as */ + /* function argument */ + CREATE_SUSPENDED, /* create suspended */ + &IDThread ); /* returns thread id */ + + /* Check the return value for success. */ + if( hThread == NULL ) + { + /* error creating thread */ + Trace( "ERROR:%lu:CreateThread call failed\n", GetLastError() ); + if( ! CloseHandle( hTestEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + Fail( "test failed\n" ); + } + + /* Resume the suspended thread */ + ResumeThread( hThread ); + + /* wait until the other thread is ready to proceed */ + ret = WaitForSingleObject( hSyncEvent, 10000 ); + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + goto cleanup; + } + + + /* now queue our APC on the test thread */ + ret = QueueUserAPC( APCFunc, hThread, 0 ); + if( ret == 0 ) + { + Trace( "ERROR:%lu:QueueUserAPC call failed\n", GetLastError() ); + goto cleanup; + } + + /* signal the test event so the other thread will proceed */ + if( ! SetEvent( hTestEvent ) ) + { + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + goto cleanup; + } + + /* wait on the other thread to complete */ + ret = WaitForSingleObject( hThread, INFINITE ); + if( ret != WAIT_OBJECT_0 ) + { + Trace( "ERROR:WaitForSingleObject() returned %lu, " + "expected WAIT_OBJECT_0\n", + ret ); + goto cleanup; + } + + /* check the result of the other thread */ + if( bThreadResult == FALSE ) + { + goto cleanup; + } + + /* check that the APC function was actually executed exactly one time */ + if( nAPCExecuted != 1 ) + { + Trace( "ERROR:APC function was executed %d times, " + "expected once\n", nAPCExecuted ); + goto cleanup; + } + + /* set the success flag */ + bResult = PASS; + + +cleanup: + /* close the global event handles */ + if( ! CloseHandle( hTestEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + bResult = FAIL; + } + + if( ! CloseHandle( hSyncEvent ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + bResult = FAIL; + } + + /* close the thread handle */ + if( ! CloseHandle( hThread ) ) + { + Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + bResult = FAIL; + } + + /* output final failure result for failure case */ + if( bResult == FAIL ) + { + Fail( "test failed\n" ); + } + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/ReleaseMutex/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/ReleaseMutex/test3/CMakeLists.txt index 8e64c28242..6bb3a79db4 100644 --- a/src/pal/tests/palsuite/threading/ReleaseMutex/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ReleaseMutex/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - ReleaseMutex.c + ReleaseMutex.cpp ) add_executable(paltest_releasemutex_test3 diff --git a/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.c b/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.c deleted file mode 100644 index 5f6adb0419..0000000000 --- a/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.c +++ /dev/null @@ -1,103 +0,0 @@ -// 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: ReleaseMutex/test3/ReleaseMutex.c -** -** Purpose: Test failure code for ReleaseMutex. -** -** Dependencies: CreateMutex -** ReleaseMutex -** CreateThread -** - -** -**=========================================================*/ - -#include - -DWORD dwTestResult; /* global for test result */ - -DWORD dwThreadId; /* consumer thread identifier */ - -HANDLE hMutex; /* handle to mutex */ - -HANDLE hThread; /* handle to thread */ - -/* - * Thread function. - */ -DWORD -PALAPI -ThreadFunction( LPVOID lpNoArg ) -{ - - dwTestResult = ReleaseMutex(hMutex); - - return 0; -} - -int __cdecl main (int argc, char **argv) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return (FAIL); - } - - /* - * set dwTestResult so test fails even if ReleaseMutex is not called - */ - dwTestResult = 1; - - /* - * Create mutex - */ - hMutex = CreateMutexW ( - NULL, - TRUE, - NULL); - - if ( NULL == hMutex ) - { - Fail ( "hMutex = CreateMutex () - returned NULL\n" - "Failing Test.\nGetLastError returned %d\n", GetLastError()); - } - - /* - * Create ThreadFunction - */ - hThread = CreateThread( - NULL, - 0, - ThreadFunction, - NULL, - 0, - &dwThreadId); - - if ( NULL == hThread ) - { - - Fail ( "CreateThread() returned NULL. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - /* - * Wait for ThreadFunction to complete - */ - WaitForSingleObject (hThread, INFINITE); - - if (dwTestResult) - { - Fail ("ReleaseMutex() test was expected to return 0.\n" - "It returned %d. Failing test.\n", dwTestResult ); - } - - Trace ("ReleaseMutex() test returned 0.\nTest passed.\n"); - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp b/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp new file mode 100644 index 0000000000..5f6adb0419 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp @@ -0,0 +1,103 @@ +// 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: ReleaseMutex/test3/ReleaseMutex.c +** +** Purpose: Test failure code for ReleaseMutex. +** +** Dependencies: CreateMutex +** ReleaseMutex +** CreateThread +** + +** +**=========================================================*/ + +#include + +DWORD dwTestResult; /* global for test result */ + +DWORD dwThreadId; /* consumer thread identifier */ + +HANDLE hMutex; /* handle to mutex */ + +HANDLE hThread; /* handle to thread */ + +/* + * Thread function. + */ +DWORD +PALAPI +ThreadFunction( LPVOID lpNoArg ) +{ + + dwTestResult = ReleaseMutex(hMutex); + + return 0; +} + +int __cdecl main (int argc, char **argv) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return (FAIL); + } + + /* + * set dwTestResult so test fails even if ReleaseMutex is not called + */ + dwTestResult = 1; + + /* + * Create mutex + */ + hMutex = CreateMutexW ( + NULL, + TRUE, + NULL); + + if ( NULL == hMutex ) + { + Fail ( "hMutex = CreateMutex () - returned NULL\n" + "Failing Test.\nGetLastError returned %d\n", GetLastError()); + } + + /* + * Create ThreadFunction + */ + hThread = CreateThread( + NULL, + 0, + ThreadFunction, + NULL, + 0, + &dwThreadId); + + if ( NULL == hThread ) + { + + Fail ( "CreateThread() returned NULL. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + /* + * Wait for ThreadFunction to complete + */ + WaitForSingleObject (hThread, INFINITE); + + if (dwTestResult) + { + Fail ("ReleaseMutex() test was expected to return 0.\n" + "It returned %d. Failing test.\n", dwTestResult ); + } + + Trace ("ReleaseMutex() test returned 0.\nTest passed.\n"); + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResetEvent/test1/CMakeLists.txt index 78e84da2b9..12c83119d8 100644 --- a/src/pal/tests/palsuite/threading/ResetEvent/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ResetEvent/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_resetevent_test1 diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test1/test1.c b/src/pal/tests/palsuite/threading/ResetEvent/test1/test1.c deleted file mode 100644 index 20a0d5dffa..0000000000 --- a/src/pal/tests/palsuite/threading/ResetEvent/test1/test1.c +++ /dev/null @@ -1,99 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for ResetEvent. Create an event with an intial -** state signaled. Then reset that signal, and check to see that -** the event is now not signaled. -** -** -**=========================================================*/ - -#include - -BOOL ResetEventTest() -{ - BOOL bRet = FALSE; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpEventAttributes = 0; - BOOL bManualReset = TRUE; - BOOL bInitialState = TRUE; - - /* Create an Event, ensure it is valid */ - HANDLE hEvent = CreateEvent( lpEventAttributes, - bManualReset, bInitialState, NULL); - - if (hEvent != INVALID_HANDLE_VALUE) - { - /* Check that WaitFor returns WAIT_OBJECT_0, indicating that - the event is signaled. - */ - - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_OBJECT_0) - { - Fail("ResetEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); - } - else - { - /* Call ResetEvent, which will reset the signal */ - bRet = ResetEvent(hEvent); - - if (!bRet) - { - Fail("ResetEventTest:ResetEvent failed (%x)\n", GetLastError()); - } - else - { - /* Call WaitFor again, and since it has been reset, - the return value should now be WAIT_TIMEOUT - */ - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_TIMEOUT) - { - Fail("ResetEventTest:WaitForSingleObject %s failed (%x)\n", GetLastError()); - } - else - { - bRet = CloseHandle(hEvent); - - if (!bRet) - { - Fail("ResetEventTest:CloseHandle failed (%x)\n", GetLastError()); - } - } - } - } - } - else - { - Fail("ResetEventTest:CreateEvent failed (%x)\n", GetLastError()); - } - - return bRet; -} - -int __cdecl main(int argc, char **argv) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!ResetEventTest()) - { - Fail ("Test failed\n"); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test1/test1.cpp b/src/pal/tests/palsuite/threading/ResetEvent/test1/test1.cpp new file mode 100644 index 0000000000..20a0d5dffa --- /dev/null +++ b/src/pal/tests/palsuite/threading/ResetEvent/test1/test1.cpp @@ -0,0 +1,99 @@ +// 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: test1.c +** +** Purpose: Test for ResetEvent. Create an event with an intial +** state signaled. Then reset that signal, and check to see that +** the event is now not signaled. +** +** +**=========================================================*/ + +#include + +BOOL ResetEventTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = 0; + BOOL bManualReset = TRUE; + BOOL bInitialState = TRUE; + + /* Create an Event, ensure it is valid */ + HANDLE hEvent = CreateEvent( lpEventAttributes, + bManualReset, bInitialState, NULL); + + if (hEvent != INVALID_HANDLE_VALUE) + { + /* Check that WaitFor returns WAIT_OBJECT_0, indicating that + the event is signaled. + */ + + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_OBJECT_0) + { + Fail("ResetEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + /* Call ResetEvent, which will reset the signal */ + bRet = ResetEvent(hEvent); + + if (!bRet) + { + Fail("ResetEventTest:ResetEvent failed (%x)\n", GetLastError()); + } + else + { + /* Call WaitFor again, and since it has been reset, + the return value should now be WAIT_TIMEOUT + */ + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_TIMEOUT) + { + Fail("ResetEventTest:WaitForSingleObject %s failed (%x)\n", GetLastError()); + } + else + { + bRet = CloseHandle(hEvent); + + if (!bRet) + { + Fail("ResetEventTest:CloseHandle failed (%x)\n", GetLastError()); + } + } + } + } + } + else + { + Fail("ResetEventTest:CreateEvent failed (%x)\n", GetLastError()); + } + + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!ResetEventTest()) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResetEvent/test2/CMakeLists.txt index ad0fe9b4a1..1f67b5d884 100644 --- a/src/pal/tests/palsuite/threading/ResetEvent/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ResetEvent/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_resetevent_test2 diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test2/test2.c b/src/pal/tests/palsuite/threading/ResetEvent/test2/test2.c deleted file mode 100644 index 8117f44353..0000000000 --- a/src/pal/tests/palsuite/threading/ResetEvent/test2/test2.c +++ /dev/null @@ -1,89 +0,0 @@ -// 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: test2.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** CloseHandle -** WaitForSingleObject -** -** Purpose: Test to ensure proper operation of the ResetEvent() -** API by calling it on an event handle that's already -** unsignalled. -** - -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - DWORD dwRet = 0; - HANDLE hEvent = NULL; - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - - /* create an unsignalled event which we can use with ResetEvent */ - hEvent = CreateEvent( lpEventAttributes, - bManualReset, - bInitialState, - NULL ); - - if( hEvent == INVALID_HANDLE_VALUE ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* verify that the event isn't signalled yet */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - /* try to reset the event */ - if( ! ResetEvent( hEvent ) ) - { - /* ERROR */ - Trace( "FAIL:%lu:ResetEvent() call failed\n", GetLastError() ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - /* close the event handle */ - if( ! CloseHandle( hEvent ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test2/test2.cpp b/src/pal/tests/palsuite/threading/ResetEvent/test2/test2.cpp new file mode 100644 index 0000000000..8117f44353 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ResetEvent/test2/test2.cpp @@ -0,0 +1,89 @@ +// 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: test2.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** WaitForSingleObject +** +** Purpose: Test to ensure proper operation of the ResetEvent() +** API by calling it on an event handle that's already +** unsignalled. +** + +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + DWORD dwRet = 0; + HANDLE hEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an unsignalled event which we can use with ResetEvent */ + hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL ); + + if( hEvent == INVALID_HANDLE_VALUE ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* verify that the event isn't signalled yet */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* try to reset the event */ + if( ! ResetEvent( hEvent ) ) + { + /* ERROR */ + Trace( "FAIL:%lu:ResetEvent() call failed\n", GetLastError() ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResetEvent/test3/CMakeLists.txt index 3c4ea1f249..fd0d6e8b16 100644 --- a/src/pal/tests/palsuite/threading/ResetEvent/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ResetEvent/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_resetevent_test3 diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test3/test3.c b/src/pal/tests/palsuite/threading/ResetEvent/test3/test3.c deleted file mode 100644 index 9bc068ea72..0000000000 --- a/src/pal/tests/palsuite/threading/ResetEvent/test3/test3.c +++ /dev/null @@ -1,86 +0,0 @@ -// 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: test3.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** CloseHandle -** -** Purpose: -** -** Test to ensure proper operation of the ResetEvent() -** API by calling it on an event handle that's been -** closed. We expect it to return an appropriate error -** result. -** -** - -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - HANDLE hEvent = NULL; - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - - /* create an event which we can use with ResetEvent */ - hEvent = CreateEvent( lpEventAttributes, - bManualReset, - bInitialState, - NULL ); - - if( hEvent == INVALID_HANDLE_VALUE ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* close the event handle */ - if( ! CloseHandle( hEvent ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - - /* try to reset the event */ - if( ResetEvent( hEvent ) ) - { - /* ERROR */ - Fail( "FAIL:ResetEvent() call succeeded on a closed event handle\n" ); - } - - /* verify the result of GetLastError() */ - if( GetLastError() != ERROR_INVALID_HANDLE ) - { - /* ERROR */ - Fail( "FAIL:ResetEvent() call failed on a closed event handle " - "but returned an unexpected error result %lu\n" ); - } - - - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test3/test3.cpp b/src/pal/tests/palsuite/threading/ResetEvent/test3/test3.cpp new file mode 100644 index 0000000000..9bc068ea72 --- /dev/null +++ b/src/pal/tests/palsuite/threading/ResetEvent/test3/test3.cpp @@ -0,0 +1,86 @@ +// 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: test3.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** +** Purpose: +** +** Test to ensure proper operation of the ResetEvent() +** API by calling it on an event handle that's been +** closed. We expect it to return an appropriate error +** result. +** +** + +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + HANDLE hEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with ResetEvent */ + hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL ); + + if( hEvent == INVALID_HANDLE_VALUE ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + /* try to reset the event */ + if( ResetEvent( hEvent ) ) + { + /* ERROR */ + Fail( "FAIL:ResetEvent() call succeeded on a closed event handle\n" ); + } + + /* verify the result of GetLastError() */ + if( GetLastError() != ERROR_INVALID_HANDLE ) + { + /* ERROR */ + Fail( "FAIL:ResetEvent() call failed on a closed event handle " + "but returned an unexpected error result %lu\n" ); + } + + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResetEvent/test4/CMakeLists.txt index 68ee20bc95..ca2a918775 100644 --- a/src/pal/tests/palsuite/threading/ResetEvent/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ResetEvent/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_resetevent_test4 diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test4/test4.c b/src/pal/tests/palsuite/threading/ResetEvent/test4/test4.c deleted file mode 100644 index 0cc68fd9aa..0000000000 --- a/src/pal/tests/palsuite/threading/ResetEvent/test4/test4.c +++ /dev/null @@ -1,161 +0,0 @@ -// 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: test4.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** CloseHandle -** WaitForSingleObject -** DuplicateHandle -** GetCurrentProcess -** -** Purpose: -** -** Test to ensure proper operation of the ResetEvent() -** API by calling it on an event handle that's the -** result of a DuplicateHandle() call on another event -** handle. -** - -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - DWORD dwRet = 0; - HANDLE hEvent = NULL; - HANDLE hDupEvent = NULL; - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = TRUE; - - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - - /* create an event which we can use with ResetEvent */ - hEvent = CreateEvent( lpEventAttributes, - bManualReset, - bInitialState, - NULL ); - - if( hEvent == INVALID_HANDLE_VALUE ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* verify that the event is signalled already */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - - /* duplicate the event handle */ - if( ! (DuplicateHandle( - GetCurrentProcess(), - hEvent, - GetCurrentProcess(), - &hDupEvent, - GENERIC_READ|GENERIC_WRITE, /* ignored in PAL */ - FALSE, - DUPLICATE_SAME_ACCESS ) ) ) - { - Trace("ERROR:%u:DuplicateHandle() call failed\n", - GetLastError() ); - CloseHandle( hEvent ); - Fail("Test failed\n"); - } - - /* verify that the event is signalled with the duplicate handle */ - dwRet = WaitForSingleObject( hDupEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - CloseHandle( hEvent ); - CloseHandle( hDupEvent ); - Fail( "Test failed\n" ); - } - - - /* reset the event using the duplicate handle */ - if( ! ResetEvent( hDupEvent ) ) - { - /* ERROR */ - Trace( "ERROR:%lu:ResetEvent() call failed\n", GetLastError() ); - CloseHandle( hEvent ); - CloseHandle( hDupEvent ); - Fail( "Test failed\n" ); - } - - /* verify that the event isn't signalled using the duplicate handle*/ - dwRet = WaitForSingleObject( hDupEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - /* check that the event isn't signalled using the original event handle */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - - /* close the duplicate event handle */ - if( ! CloseHandle( hDupEvent ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed for duplicate handle\n", - GetLastError() ); - } - - - /* close the event handle */ - if( ! CloseHandle( hEvent ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed for original handle\n", - GetLastError() ); - } - - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test4/test4.cpp b/src/pal/tests/palsuite/threading/ResetEvent/test4/test4.cpp new file mode 100644 index 0000000000..0cc68fd9aa --- /dev/null +++ b/src/pal/tests/palsuite/threading/ResetEvent/test4/test4.cpp @@ -0,0 +1,161 @@ +// 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: test4.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** WaitForSingleObject +** DuplicateHandle +** GetCurrentProcess +** +** Purpose: +** +** Test to ensure proper operation of the ResetEvent() +** API by calling it on an event handle that's the +** result of a DuplicateHandle() call on another event +** handle. +** + +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + DWORD dwRet = 0; + HANDLE hEvent = NULL; + HANDLE hDupEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = TRUE; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with ResetEvent */ + hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL ); + + if( hEvent == INVALID_HANDLE_VALUE ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* verify that the event is signalled already */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + + /* duplicate the event handle */ + if( ! (DuplicateHandle( + GetCurrentProcess(), + hEvent, + GetCurrentProcess(), + &hDupEvent, + GENERIC_READ|GENERIC_WRITE, /* ignored in PAL */ + FALSE, + DUPLICATE_SAME_ACCESS ) ) ) + { + Trace("ERROR:%u:DuplicateHandle() call failed\n", + GetLastError() ); + CloseHandle( hEvent ); + Fail("Test failed\n"); + } + + /* verify that the event is signalled with the duplicate handle */ + dwRet = WaitForSingleObject( hDupEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + CloseHandle( hDupEvent ); + Fail( "Test failed\n" ); + } + + + /* reset the event using the duplicate handle */ + if( ! ResetEvent( hDupEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:ResetEvent() call failed\n", GetLastError() ); + CloseHandle( hEvent ); + CloseHandle( hDupEvent ); + Fail( "Test failed\n" ); + } + + /* verify that the event isn't signalled using the duplicate handle*/ + dwRet = WaitForSingleObject( hDupEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* check that the event isn't signalled using the original event handle */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + + /* close the duplicate event handle */ + if( ! CloseHandle( hDupEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed for duplicate handle\n", + GetLastError() ); + } + + + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed for original handle\n", + GetLastError() ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/ResumeThread/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResumeThread/test1/CMakeLists.txt index 2c83dfd3d5..96d7edcbba 100644 --- a/src/pal/tests/palsuite/threading/ResumeThread/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ResumeThread/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_resumethread_test1 diff --git a/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.c b/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.c deleted file mode 100644 index 037f79f7a3..0000000000 --- a/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.c +++ /dev/null @@ -1,141 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for ResumeThread. Create a suspended Thread. -** First, ensure that it is indeed suspended. Then call resumethread -** and check to ensure that the function has now run. -** -** -**=========================================================*/ - -#include - -DWORD dwResumeThreadTestParameter = 0; - -DWORD PALAPI ResumeThreadTestThread( LPVOID lpParameter) -{ - DWORD dwRet = 0; - - /* Save parameter so we can check and ensure this function ran - properly. - */ - - dwResumeThreadTestParameter = (DWORD)lpParameter; - - return dwRet; -} - -BOOL ResumeThreadTest() -{ - BOOL bRet = FALSE; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL; - DWORD dwStackSize = 0; - LPTHREAD_START_ROUTINE lpStartAddress = &ResumeThreadTestThread; - LPVOID lpParameter = lpStartAddress; - DWORD dwCreationFlags = CREATE_SUSPENDED; - DWORD dwThreadId = 0; - - HANDLE hThread = 0; - - dwResumeThreadTestParameter = 0; - - /* Create a thread, with CREATE_SUSPENDED, so we can resume it! */ - - hThread = CreateThread( lpThreadAttributes, - dwStackSize, lpStartAddress, lpParameter, - dwCreationFlags, &dwThreadId ); - - if (hThread != INVALID_HANDLE_VALUE) - { - /* Wait for one second. This should return WAIT_TIMEOUT */ - dwRet = WaitForSingleObject(hThread,1000); - - if (dwRet != WAIT_TIMEOUT) - { - Trace("ResumeThreadTest:WaitForSingleObject " - "failed (%x)\n",GetLastError()); - } - else - { - /* Check to ensure the parameter hasn't changed. The - function shouldn't have occurred yet. - */ - if (dwResumeThreadTestParameter != 0) - { - Trace("ResumeThreadTest:parameter error\n"); - } - else - { - /* Call ResumeThread and ensure the return value is - correct. - */ - - dwRet = ResumeThread(hThread); - - if (dwRet != 1) - { - Trace("ResumeThreadTest:ResumeThread " - "failed (%x)\n",GetLastError()); - } - else - { - /* Wait again, now that the thread has been - resumed, and the return should be WAIT_OBJECT_0 - */ - dwRet = WaitForSingleObject(hThread,INFINITE); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("ResumeThreadTest:WaitForSingleObject " - "failed (%x)\n",GetLastError()); - } - else - { - /* Check the param now and it should have been - set. - */ - if (dwResumeThreadTestParameter != (DWORD)lpParameter) - { - Trace("ResumeThreadTest:parameter error\n"); - } - else - { - bRet = TRUE; - } - } - } - } - } - } - else - { - Trace("ResumeThreadTest:CreateThread failed (%x)\n",GetLastError()); - } - - return bRet; -} - -int __cdecl main(int argc, char **argv) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!ResumeThreadTest()) - { - Fail("Test Failed\n"); - } - - PAL_Terminate(); - return (PASS); - -} diff --git a/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.cpp b/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.cpp new file mode 100644 index 0000000000..d2be262e4d --- /dev/null +++ b/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.cpp @@ -0,0 +1,141 @@ +// 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: test1.c +** +** Purpose: Test for ResumeThread. Create a suspended Thread. +** First, ensure that it is indeed suspended. Then call resumethread +** and check to ensure that the function has now run. +** +** +**=========================================================*/ + +#include + +DWORD dwResumeThreadTestParameter = 0; + +DWORD PALAPI ResumeThreadTestThread( LPVOID lpParameter) +{ + DWORD dwRet = 0; + + /* Save parameter so we can check and ensure this function ran + properly. + */ + + dwResumeThreadTestParameter = (DWORD)lpParameter; + + return dwRet; +} + +BOOL ResumeThreadTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL; + DWORD dwStackSize = 0; + LPTHREAD_START_ROUTINE lpStartAddress = &ResumeThreadTestThread; + LPVOID lpParameter = (LPVOID)lpStartAddress; + DWORD dwCreationFlags = CREATE_SUSPENDED; + DWORD dwThreadId = 0; + + HANDLE hThread = 0; + + dwResumeThreadTestParameter = 0; + + /* Create a thread, with CREATE_SUSPENDED, so we can resume it! */ + + hThread = CreateThread( lpThreadAttributes, + dwStackSize, lpStartAddress, lpParameter, + dwCreationFlags, &dwThreadId ); + + if (hThread != INVALID_HANDLE_VALUE) + { + /* Wait for one second. This should return WAIT_TIMEOUT */ + dwRet = WaitForSingleObject(hThread,1000); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("ResumeThreadTest:WaitForSingleObject " + "failed (%x)\n",GetLastError()); + } + else + { + /* Check to ensure the parameter hasn't changed. The + function shouldn't have occurred yet. + */ + if (dwResumeThreadTestParameter != 0) + { + Trace("ResumeThreadTest:parameter error\n"); + } + else + { + /* Call ResumeThread and ensure the return value is + correct. + */ + + dwRet = ResumeThread(hThread); + + if (dwRet != 1) + { + Trace("ResumeThreadTest:ResumeThread " + "failed (%x)\n",GetLastError()); + } + else + { + /* Wait again, now that the thread has been + resumed, and the return should be WAIT_OBJECT_0 + */ + dwRet = WaitForSingleObject(hThread,INFINITE); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("ResumeThreadTest:WaitForSingleObject " + "failed (%x)\n",GetLastError()); + } + else + { + /* Check the param now and it should have been + set. + */ + if (dwResumeThreadTestParameter != (DWORD)lpParameter) + { + Trace("ResumeThreadTest:parameter error\n"); + } + else + { + bRet = TRUE; + } + } + } + } + } + } + else + { + Trace("ResumeThreadTest:CreateThread failed (%x)\n",GetLastError()); + } + + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!ResumeThreadTest()) + { + Fail("Test Failed\n"); + } + + PAL_Terminate(); + return (PASS); + +} diff --git a/src/pal/tests/palsuite/threading/SetErrorMode/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetErrorMode/test1/CMakeLists.txt index cfdeb31950..7c145a8528 100644 --- a/src/pal/tests/palsuite/threading/SetErrorMode/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/SetErrorMode/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_seterrormode_test1 diff --git a/src/pal/tests/palsuite/threading/SetErrorMode/test1/test1.c b/src/pal/tests/palsuite/threading/SetErrorMode/test1/test1.c deleted file mode 100644 index 238cec4421..0000000000 --- a/src/pal/tests/palsuite/threading/SetErrorMode/test1/test1.c +++ /dev/null @@ -1,50 +0,0 @@ -// 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: test1.c (SetErrorMode) -** -** Purpose: Tests the PAL implementation of the SetErrorMode function. -** This test will set the error mode and then read the error -** set with GetLastError(). -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - DWORD dErrorReturn; - UINT dErrorModes[] = {SEM_NOOPENFILEERRORBOX, SEM_FAILCRITICALERRORS, 0}; - int i; - - /* - * Initialize the Pal - */ - if ((PAL_Initialize(argc,argv)) != 0) - { - return (FAIL); - } - - /* - * Loop through the supported Error Modes and verify - * that GetLastError() returns the correct Error Mode - */ - for (i=0; i < (sizeof(dErrorModes) / sizeof(UINT)); i++) - { - SetLastError(dErrorModes[i]); - if ((dErrorReturn = GetLastError()) != dErrorModes[i]) - { - Fail("ERROR: SetLastError was set to 0x%4.4x but," - " GetLastError returned 0x%4.4x\n", - dErrorModes[i], - dErrorReturn); - } - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/SetErrorMode/test1/test1.cpp b/src/pal/tests/palsuite/threading/SetErrorMode/test1/test1.cpp new file mode 100644 index 0000000000..238cec4421 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetErrorMode/test1/test1.cpp @@ -0,0 +1,50 @@ +// 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: test1.c (SetErrorMode) +** +** Purpose: Tests the PAL implementation of the SetErrorMode function. +** This test will set the error mode and then read the error +** set with GetLastError(). +** +** +**===================================================================*/ + +#include + +int __cdecl main(int argc, char **argv) +{ + DWORD dErrorReturn; + UINT dErrorModes[] = {SEM_NOOPENFILEERRORBOX, SEM_FAILCRITICALERRORS, 0}; + int i; + + /* + * Initialize the Pal + */ + if ((PAL_Initialize(argc,argv)) != 0) + { + return (FAIL); + } + + /* + * Loop through the supported Error Modes and verify + * that GetLastError() returns the correct Error Mode + */ + for (i=0; i < (sizeof(dErrorModes) / sizeof(UINT)); i++) + { + SetLastError(dErrorModes[i]); + if ((dErrorReturn = GetLastError()) != dErrorModes[i]) + { + Fail("ERROR: SetLastError was set to 0x%4.4x but," + " GetLastError returned 0x%4.4x\n", + dErrorModes[i], + dErrorReturn); + } + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetEvent/test1/CMakeLists.txt index 9be8d5a421..8d9d729554 100644 --- a/src/pal/tests/palsuite/threading/SetEvent/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/SetEvent/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_setevent_test1 diff --git a/src/pal/tests/palsuite/threading/SetEvent/test1/test1.c b/src/pal/tests/palsuite/threading/SetEvent/test1/test1.c deleted file mode 100644 index d5a29ce3f3..0000000000 --- a/src/pal/tests/palsuite/threading/SetEvent/test1/test1.c +++ /dev/null @@ -1,94 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for SetEvent. Create an Event and then set -** this event, checking the return value. Ensure that it returns -** positive. -** -** -**=========================================================*/ - -#include - -BOOL SetEventTest() -{ - int bRet = 0; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpEventAttributes = 0; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - - /* Create an event which we can use with SetEvent */ - HANDLE hEvent = CreateEvent( lpEventAttributes, - bManualReset, bInitialState, NULL); - - if (hEvent != INVALID_HANDLE_VALUE) - { - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_TIMEOUT) - { - Trace("SetEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); - } - else - { - /* Set the event to the previously created event and check - the return value. - */ - bRet = SetEvent(hEvent); - - if (!bRet) - { - Trace("SetEventTest:SetEvent failed (%x)\n", GetLastError()); - } - else - { - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("SetEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); - } - else - { - dwRet = CloseHandle(hEvent); - - if (!dwRet) - { - Trace("SetEventTest:CloseHandle failed (%x)\n", GetLastError()); - } - } - } - } - } - else - { - Trace("SetEventTest:CreateEvent failed (%x)\n", GetLastError()); - } - - return bRet; -} - - -int __cdecl main(int argc, char **argv) -{ - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(SetEventTest() == 0) - { - Fail ("Test failed\n"); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test1/test1.cpp b/src/pal/tests/palsuite/threading/SetEvent/test1/test1.cpp new file mode 100644 index 0000000000..d5a29ce3f3 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test1/test1.cpp @@ -0,0 +1,94 @@ +// 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: test1.c +** +** Purpose: Test for SetEvent. Create an Event and then set +** this event, checking the return value. Ensure that it returns +** positive. +** +** +**=========================================================*/ + +#include + +BOOL SetEventTest() +{ + int bRet = 0; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = 0; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + /* Create an event which we can use with SetEvent */ + HANDLE hEvent = CreateEvent( lpEventAttributes, + bManualReset, bInitialState, NULL); + + if (hEvent != INVALID_HANDLE_VALUE) + { + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("SetEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + /* Set the event to the previously created event and check + the return value. + */ + bRet = SetEvent(hEvent); + + if (!bRet) + { + Trace("SetEventTest:SetEvent failed (%x)\n", GetLastError()); + } + else + { + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("SetEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + dwRet = CloseHandle(hEvent); + + if (!dwRet) + { + Trace("SetEventTest:CloseHandle failed (%x)\n", GetLastError()); + } + } + } + } + } + else + { + Trace("SetEventTest:CreateEvent failed (%x)\n", GetLastError()); + } + + return bRet; +} + + +int __cdecl main(int argc, char **argv) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(SetEventTest() == 0) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetEvent/test2/CMakeLists.txt index 87522b3ffc..7d33b56058 100644 --- a/src/pal/tests/palsuite/threading/SetEvent/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/SetEvent/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_setevent_test2 diff --git a/src/pal/tests/palsuite/threading/SetEvent/test2/test2.c b/src/pal/tests/palsuite/threading/SetEvent/test2/test2.c deleted file mode 100644 index 5fd2833957..0000000000 --- a/src/pal/tests/palsuite/threading/SetEvent/test2/test2.c +++ /dev/null @@ -1,125 +0,0 @@ -// 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: test2.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** CloseHandle -** WaitForSingleObject -** -** Purpose: -** -** Test to ensure proper operation of the SetEvent() -** API by calling it on an event handle that's already set. -** - -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - DWORD dwRet = 0; - HANDLE hEvent = NULL; - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - - /* create an event which we can use with SetEvent */ - hEvent = CreateEvent( lpEventAttributes, - bManualReset, - bInitialState, - NULL ); - - if( hEvent == INVALID_HANDLE_VALUE ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* verify that the event isn't signalled yet */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - /* set the event */ - if( ! SetEvent( hEvent ) ) - { - /* ERROR */ - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - /* verify that the event is signalled */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - /* try to set the event again */ - if( ! SetEvent( hEvent ) ) - { - /* ERROR */ - Trace( "FAIL:%lu:SetEvent() call failed on signalled event\n", - GetLastError() ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - /* verify that the event is still signalled */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - - /* close the event handle */ - if( ! CloseHandle( hEvent ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test2/test2.cpp b/src/pal/tests/palsuite/threading/SetEvent/test2/test2.cpp new file mode 100644 index 0000000000..5fd2833957 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test2/test2.cpp @@ -0,0 +1,125 @@ +// 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: test2.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** WaitForSingleObject +** +** Purpose: +** +** Test to ensure proper operation of the SetEvent() +** API by calling it on an event handle that's already set. +** + +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + DWORD dwRet = 0; + HANDLE hEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with SetEvent */ + hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL ); + + if( hEvent == INVALID_HANDLE_VALUE ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* verify that the event isn't signalled yet */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* set the event */ + if( ! SetEvent( hEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* verify that the event is signalled */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* try to set the event again */ + if( ! SetEvent( hEvent ) ) + { + /* ERROR */ + Trace( "FAIL:%lu:SetEvent() call failed on signalled event\n", + GetLastError() ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* verify that the event is still signalled */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetEvent/test3/CMakeLists.txt index d09239b3e4..1c66460ea0 100644 --- a/src/pal/tests/palsuite/threading/SetEvent/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/SetEvent/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_setevent_test3 diff --git a/src/pal/tests/palsuite/threading/SetEvent/test3/test3.c b/src/pal/tests/palsuite/threading/SetEvent/test3/test3.c deleted file mode 100644 index 21601f00b8..0000000000 --- a/src/pal/tests/palsuite/threading/SetEvent/test3/test3.c +++ /dev/null @@ -1,85 +0,0 @@ -// 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: test3.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** CloseHandle -** -** Purpose: -** -** Test to ensure proper operation of the SetEvent() -** API by calling it on an event handle that's been -** closed. We expect it to return an appropriate error -** result. -** - -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - HANDLE hEvent = NULL; - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - - /* create an event which we can use with SetEvent */ - hEvent = CreateEvent( lpEventAttributes, - bManualReset, - bInitialState, - NULL ); - - if( hEvent == INVALID_HANDLE_VALUE ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* close the event handle */ - if( ! CloseHandle( hEvent ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); - } - - /* try to set the event */ - if( SetEvent( hEvent ) ) - { - /* ERROR */ - Fail( "FAIL:SetEvent() call succeeded on a closed event handle\n" ); - } - - /* verify the result of GetLastError() */ - if( GetLastError() != ERROR_INVALID_HANDLE ) - { - /* ERROR */ - Fail( "FAIL:SetEvent() call failed on a closed event handle" - "but returned an unexpected error result %lu\n" ); - } - - - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test3/test3.cpp b/src/pal/tests/palsuite/threading/SetEvent/test3/test3.cpp new file mode 100644 index 0000000000..21601f00b8 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test3/test3.cpp @@ -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: test3.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** +** Purpose: +** +** Test to ensure proper operation of the SetEvent() +** API by calling it on an event handle that's been +** closed. We expect it to return an appropriate error +** result. +** + +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + HANDLE hEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with SetEvent */ + hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL ); + + if( hEvent == INVALID_HANDLE_VALUE ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + /* try to set the event */ + if( SetEvent( hEvent ) ) + { + /* ERROR */ + Fail( "FAIL:SetEvent() call succeeded on a closed event handle\n" ); + } + + /* verify the result of GetLastError() */ + if( GetLastError() != ERROR_INVALID_HANDLE ) + { + /* ERROR */ + Fail( "FAIL:SetEvent() call failed on a closed event handle" + "but returned an unexpected error result %lu\n" ); + } + + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetEvent/test4/CMakeLists.txt index 3f1d344292..04f1815259 100644 --- a/src/pal/tests/palsuite/threading/SetEvent/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/SetEvent/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_setevent_test4 diff --git a/src/pal/tests/palsuite/threading/SetEvent/test4/test4.c b/src/pal/tests/palsuite/threading/SetEvent/test4/test4.c deleted file mode 100644 index 7a79a9d708..0000000000 --- a/src/pal/tests/palsuite/threading/SetEvent/test4/test4.c +++ /dev/null @@ -1,161 +0,0 @@ -// 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: test4.c -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** CreateEvent -** CloseHandle -** WaitForSingleObject -** DuplicateHandle -** GetCurrentProcess -** -** Purpose: -** -** Test to ensure proper operation of the SetEvent() -** API by calling it on an event handle that's the -** result of a DuplicateHandle() call on another event -** handle. -** - -** -**===========================================================================*/ -#include - - - -int __cdecl main( int argc, char **argv ) - -{ - /* local variables */ - DWORD dwRet = 0; - HANDLE hEvent = NULL; - HANDLE hDupEvent = NULL; - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = FALSE; - - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - - /* create an event which we can use with SetEvent */ - hEvent = CreateEvent( lpEventAttributes, - bManualReset, - bInitialState, - NULL ); - - if( hEvent == INVALID_HANDLE_VALUE ) - { - /* ERROR */ - Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); - } - - /* verify that the event isn't signalled yet */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - - /* duplicate the event handle */ - if( ! (DuplicateHandle( - GetCurrentProcess(), - hEvent, - GetCurrentProcess(), - &hDupEvent, - GENERIC_READ|GENERIC_WRITE, /* ignored in PAL */ - FALSE, - DUPLICATE_SAME_ACCESS ) ) ) - { - Trace("ERROR:%u:DuplicateHandle() call failed\n", - GetLastError() ); - CloseHandle( hEvent ); - Fail("Test failed\n"); - } - - /* verify that the event isn't signalled yet with the duplicate handle */ - dwRet = WaitForSingleObject( hDupEvent, 0 ); - if( dwRet != WAIT_TIMEOUT ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_TIMEOUT\n", - dwRet ); - CloseHandle( hEvent ); - CloseHandle( hDupEvent ); - Fail( "Test failed\n" ); - } - - - /* set the event using the duplicate handle */ - if( ! SetEvent( hDupEvent ) ) - { - /* ERROR */ - Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); - CloseHandle( hEvent ); - CloseHandle( hDupEvent ); - Fail( "Test failed\n" ); - } - - /* verify that the event is signalled using the duplicate handle*/ - dwRet = WaitForSingleObject( hDupEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - /* verify that the event is signalled using the original event handle */ - dwRet = WaitForSingleObject( hEvent, 0 ); - if( dwRet != WAIT_OBJECT_0 ) - { - /* ERROR */ - Trace( "ERROR:WaitForSingleObject() call returned %lu, " - "expected WAIT_OBJECT_0\n", - dwRet ); - CloseHandle( hEvent ); - Fail( "Test failed\n" ); - } - - - /* close the duplicate event handle */ - if( ! CloseHandle( hDupEvent ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed for duplicate handle\n", - GetLastError() ); - } - - - /* close the event handle */ - if( ! CloseHandle( hEvent ) ) - { - Fail( "ERROR:%lu:CloseHandle() call failed for original handle\n", - GetLastError() ); - } - - - /* PAL termination */ - PAL_Terminate(); - - /* return success */ - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test4/test4.cpp b/src/pal/tests/palsuite/threading/SetEvent/test4/test4.cpp new file mode 100644 index 0000000000..7a79a9d708 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test4/test4.cpp @@ -0,0 +1,161 @@ +// 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: test4.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** WaitForSingleObject +** DuplicateHandle +** GetCurrentProcess +** +** Purpose: +** +** Test to ensure proper operation of the SetEvent() +** API by calling it on an event handle that's the +** result of a DuplicateHandle() call on another event +** handle. +** + +** +**===========================================================================*/ +#include + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + DWORD dwRet = 0; + HANDLE hEvent = NULL; + HANDLE hDupEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with SetEvent */ + hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL ); + + if( hEvent == INVALID_HANDLE_VALUE ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* verify that the event isn't signalled yet */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + + /* duplicate the event handle */ + if( ! (DuplicateHandle( + GetCurrentProcess(), + hEvent, + GetCurrentProcess(), + &hDupEvent, + GENERIC_READ|GENERIC_WRITE, /* ignored in PAL */ + FALSE, + DUPLICATE_SAME_ACCESS ) ) ) + { + Trace("ERROR:%u:DuplicateHandle() call failed\n", + GetLastError() ); + CloseHandle( hEvent ); + Fail("Test failed\n"); + } + + /* verify that the event isn't signalled yet with the duplicate handle */ + dwRet = WaitForSingleObject( hDupEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + CloseHandle( hEvent ); + CloseHandle( hDupEvent ); + Fail( "Test failed\n" ); + } + + + /* set the event using the duplicate handle */ + if( ! SetEvent( hDupEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + CloseHandle( hEvent ); + CloseHandle( hDupEvent ); + Fail( "Test failed\n" ); + } + + /* verify that the event is signalled using the duplicate handle*/ + dwRet = WaitForSingleObject( hDupEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* verify that the event is signalled using the original event handle */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + + /* close the duplicate event handle */ + if( ! CloseHandle( hDupEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed for duplicate handle\n", + GetLastError() ); + } + + + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed for original handle\n", + GetLastError() ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/Sleep/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/Sleep/test1/CMakeLists.txt index b0d8db28a2..601789600b 100644 --- a/src/pal/tests/palsuite/threading/Sleep/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/Sleep/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - Sleep.c + Sleep.cpp ) add_executable(paltest_sleep_test1 diff --git a/src/pal/tests/palsuite/threading/Sleep/test1/Sleep.c b/src/pal/tests/palsuite/threading/Sleep/test1/Sleep.c deleted file mode 100644 index f7f7c91730..0000000000 --- a/src/pal/tests/palsuite/threading/Sleep/test1/Sleep.c +++ /dev/null @@ -1,80 +0,0 @@ -// 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: Sleep.c -** -** Purpose: Test to establish whether the Sleep function stops the thread from -** executing for the specified times. -** -** Dependencies: GetSystemTime -** Fail -** Trace -** - -** -**=========================================================*/ - -#include - -DWORD SleepTimes[] = -{ - 0, - 50, - 100, - 500, - 2000 -}; - -/* Milliseconds of error which are acceptable Function execution time, etc. */ -DWORD AcceptableTimeError = 150; - -int __cdecl main( int argc, char **argv ) -{ - UINT64 OldTimeStamp; - UINT64 NewTimeStamp; - DWORD MaxDelta; - DWORD TimeDelta; - DWORD i; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - LARGE_INTEGER performanceFrequency; - if (!QueryPerformanceFrequency(&performanceFrequency)) - { - return FAIL; - } - - for( i = 0; i < sizeof(SleepTimes) / sizeof(DWORD); i++) - { - OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - Sleep(SleepTimes[i]); - NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - TimeDelta = NewTimeStamp - OldTimeStamp; - - /* For longer intervals use a 10 percent tolerance */ - if ((SleepTimes[i] * 0.1) > AcceptableTimeError) - { - MaxDelta = SleepTimes[i] + (DWORD)(SleepTimes[i] * 0.1); - } - else - { - MaxDelta = SleepTimes[i] + AcceptableTimeError; - } - - if ( TimeDeltaMaxDelta ) - { - Fail("The sleep function slept for %d ms when it should have " - "slept for %d ms\n", TimeDelta, SleepTimes[i]); - } - } - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/Sleep/test1/Sleep.cpp b/src/pal/tests/palsuite/threading/Sleep/test1/Sleep.cpp new file mode 100644 index 0000000000..f7f7c91730 --- /dev/null +++ b/src/pal/tests/palsuite/threading/Sleep/test1/Sleep.cpp @@ -0,0 +1,80 @@ +// 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: Sleep.c +** +** Purpose: Test to establish whether the Sleep function stops the thread from +** executing for the specified times. +** +** Dependencies: GetSystemTime +** Fail +** Trace +** + +** +**=========================================================*/ + +#include + +DWORD SleepTimes[] = +{ + 0, + 50, + 100, + 500, + 2000 +}; + +/* Milliseconds of error which are acceptable Function execution time, etc. */ +DWORD AcceptableTimeError = 150; + +int __cdecl main( int argc, char **argv ) +{ + UINT64 OldTimeStamp; + UINT64 NewTimeStamp; + DWORD MaxDelta; + DWORD TimeDelta; + DWORD i; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + LARGE_INTEGER performanceFrequency; + if (!QueryPerformanceFrequency(&performanceFrequency)) + { + return FAIL; + } + + for( i = 0; i < sizeof(SleepTimes) / sizeof(DWORD); i++) + { + OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + Sleep(SleepTimes[i]); + NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + TimeDelta = NewTimeStamp - OldTimeStamp; + + /* For longer intervals use a 10 percent tolerance */ + if ((SleepTimes[i] * 0.1) > AcceptableTimeError) + { + MaxDelta = SleepTimes[i] + (DWORD)(SleepTimes[i] * 0.1); + } + else + { + MaxDelta = SleepTimes[i] + AcceptableTimeError; + } + + if ( TimeDeltaMaxDelta ) + { + Fail("The sleep function slept for %d ms when it should have " + "slept for %d ms\n", TimeDelta, SleepTimes[i]); + } + } + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/Sleep/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/Sleep/test2/CMakeLists.txt index 832e8ab42d..b8bc3ed7d7 100644 --- a/src/pal/tests/palsuite/threading/Sleep/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/Sleep/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - sleep.c + sleep.cpp ) add_executable(paltest_sleep_test2 diff --git a/src/pal/tests/palsuite/threading/Sleep/test2/sleep.c b/src/pal/tests/palsuite/threading/Sleep/test2/sleep.c deleted file mode 100644 index eb30e34f2f..0000000000 --- a/src/pal/tests/palsuite/threading/Sleep/test2/sleep.c +++ /dev/null @@ -1,73 +0,0 @@ -// 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: Sleep.c -** -** Purpose: Test to establish whether the Sleep function stops the thread from -** executing for the specified times. -** -** Dependencies: GetTickCount -** - -** -**=========================================================*/ - -#include - -/* - * times in 10^(-3) seconds - */ - -DWORD SleepTimes[] = -{ - 60000, - 300000, - 1800000, - 3200000 -}; - -/* Milliseconds of error which are acceptable Function execution time, etc. */ -DWORD AcceptableTimeError = 150; - -int __cdecl main( int argc, char **argv ) -{ - UINT64 OldTimeStamp; - UINT64 NewTimeStamp; - DWORD MaxDelta; - DWORD TimeDelta; - DWORD i; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - LARGE_INTEGER performanceFrequency; - if (!QueryPerformanceFrequency(&performanceFrequency)) - { - return FAIL; - } - - for( i = 0; i < sizeof(SleepTimes) / sizeof(DWORD); i++) - { - OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - Sleep(SleepTimes[i]); - NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - TimeDelta = NewTimeStamp - OldTimeStamp; - - MaxDelta = SleepTimes[i] + AcceptableTimeError; - - if ( TimeDeltaMaxDelta ) - { - Fail("The sleep function slept for %u ms when it should have " - "slept for %u ms\n", TimeDelta, SleepTimes[i]); - } - } - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/Sleep/test2/sleep.cpp b/src/pal/tests/palsuite/threading/Sleep/test2/sleep.cpp new file mode 100644 index 0000000000..eb30e34f2f --- /dev/null +++ b/src/pal/tests/palsuite/threading/Sleep/test2/sleep.cpp @@ -0,0 +1,73 @@ +// 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: Sleep.c +** +** Purpose: Test to establish whether the Sleep function stops the thread from +** executing for the specified times. +** +** Dependencies: GetTickCount +** + +** +**=========================================================*/ + +#include + +/* + * times in 10^(-3) seconds + */ + +DWORD SleepTimes[] = +{ + 60000, + 300000, + 1800000, + 3200000 +}; + +/* Milliseconds of error which are acceptable Function execution time, etc. */ +DWORD AcceptableTimeError = 150; + +int __cdecl main( int argc, char **argv ) +{ + UINT64 OldTimeStamp; + UINT64 NewTimeStamp; + DWORD MaxDelta; + DWORD TimeDelta; + DWORD i; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + LARGE_INTEGER performanceFrequency; + if (!QueryPerformanceFrequency(&performanceFrequency)) + { + return FAIL; + } + + for( i = 0; i < sizeof(SleepTimes) / sizeof(DWORD); i++) + { + OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + Sleep(SleepTimes[i]); + NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + TimeDelta = NewTimeStamp - OldTimeStamp; + + MaxDelta = SleepTimes[i] + AcceptableTimeError; + + if ( TimeDeltaMaxDelta ) + { + Fail("The sleep function slept for %u ms when it should have " + "slept for %u ms\n", TimeDelta, SleepTimes[i]); + } + } + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/SleepEx/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/SleepEx/test1/CMakeLists.txt index de562755fc..b2aed8333b 100644 --- a/src/pal/tests/palsuite/threading/SleepEx/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/SleepEx/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_sleepex_test1 diff --git a/src/pal/tests/palsuite/threading/SleepEx/test1/test1.c b/src/pal/tests/palsuite/threading/SleepEx/test1/test1.c deleted file mode 100644 index 7ccfe0ce87..0000000000 --- a/src/pal/tests/palsuite/threading/SleepEx/test1/test1.c +++ /dev/null @@ -1,89 +0,0 @@ -// 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: test1.c -** -** Purpose: Tests that SleepEx correctly sleeps for a given amount of time, -** regardless of the alertable flag. -** -** -**===================================================================*/ - -#include - -typedef struct -{ - DWORD SleepTime; - BOOL Alertable; -} testCase; - -testCase testCases[] = -{ - {0, FALSE}, - {50, FALSE}, - {100, FALSE}, - {500, FALSE}, - {2000, FALSE}, - - {0, TRUE}, - {50, TRUE}, - {100, TRUE}, - {500, TRUE}, - {2000, TRUE}, -}; - -/* Milliseconds of error which are acceptable Function execution time, etc. */ -DWORD AcceptableTimeError = 150; - -int __cdecl main( int argc, char **argv ) -{ - UINT64 OldTimeStamp; - UINT64 NewTimeStamp; - DWORD MaxDelta; - DWORD TimeDelta; - DWORD i; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - LARGE_INTEGER performanceFrequency; - if (!QueryPerformanceFrequency(&performanceFrequency)) - { - return FAIL; - } - - for (i = 0; i AcceptableTimeError) - { - MaxDelta = testCases[i].SleepTime + (DWORD)(testCases[i].SleepTime * 0.1); - } - else - { - MaxDelta = testCases[i].SleepTime + AcceptableTimeError; - } - - if (TimeDelta < testCases[i].SleepTime || TimeDelta > MaxDelta) - { - Fail("The sleep function slept for %d ms when it should have " - "slept for %d ms\n", TimeDelta, testCases[i].SleepTime); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/SleepEx/test1/test1.cpp b/src/pal/tests/palsuite/threading/SleepEx/test1/test1.cpp new file mode 100644 index 0000000000..7ccfe0ce87 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SleepEx/test1/test1.cpp @@ -0,0 +1,89 @@ +// 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: test1.c +** +** Purpose: Tests that SleepEx correctly sleeps for a given amount of time, +** regardless of the alertable flag. +** +** +**===================================================================*/ + +#include + +typedef struct +{ + DWORD SleepTime; + BOOL Alertable; +} testCase; + +testCase testCases[] = +{ + {0, FALSE}, + {50, FALSE}, + {100, FALSE}, + {500, FALSE}, + {2000, FALSE}, + + {0, TRUE}, + {50, TRUE}, + {100, TRUE}, + {500, TRUE}, + {2000, TRUE}, +}; + +/* Milliseconds of error which are acceptable Function execution time, etc. */ +DWORD AcceptableTimeError = 150; + +int __cdecl main( int argc, char **argv ) +{ + UINT64 OldTimeStamp; + UINT64 NewTimeStamp; + DWORD MaxDelta; + DWORD TimeDelta; + DWORD i; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + LARGE_INTEGER performanceFrequency; + if (!QueryPerformanceFrequency(&performanceFrequency)) + { + return FAIL; + } + + for (i = 0; i AcceptableTimeError) + { + MaxDelta = testCases[i].SleepTime + (DWORD)(testCases[i].SleepTime * 0.1); + } + else + { + MaxDelta = testCases[i].SleepTime + AcceptableTimeError; + } + + if (TimeDelta < testCases[i].SleepTime || TimeDelta > MaxDelta) + { + Fail("The sleep function slept for %d ms when it should have " + "slept for %d ms\n", TimeDelta, testCases[i].SleepTime); + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/SleepEx/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/SleepEx/test2/CMakeLists.txt index 0ea4a44449..991e9b40e2 100644 --- a/src/pal/tests/palsuite/threading/SleepEx/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/SleepEx/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_sleepex_test2 diff --git a/src/pal/tests/palsuite/threading/SleepEx/test2/test2.c b/src/pal/tests/palsuite/threading/SleepEx/test2/test2.c deleted file mode 100644 index c2ba4e704d..0000000000 --- a/src/pal/tests/palsuite/threading/SleepEx/test2/test2.c +++ /dev/null @@ -1,183 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests that a child thread in the middle of a SleepEx call will be -** interrupted by QueueUserAPC if the alert flag was set. -** -** -**===================================================================*/ - -#include - -const int ChildThreadSleepTime = 2000; -const int InterruptTime = 1000; -/* We need to keep in mind that BSD has a timer resolution of 10ms, so - we need to adjust our delta to keep that in mind. Besides we need some - tolerance to account for different scheduling strategies, heavy load - scenarios, etc. - - Real-world data also tells us we can expect a big difference between - values when run on real iron vs run in a hypervisor. - - Thread-interruption times when run on bare metal will typically yield - around 0ms on Linux and between 0 and 16ms on FreeBSD. However, when run - in a hypervisor (like VMWare ESXi) we may get values around an order of - magnitude higher, up to 110 ms for some tests. -*/ -const DWORD AcceptableDelta = 150; - -const int Iterations = 5; - -void RunTest(BOOL AlertThread); -VOID PALAPI APCFunc(ULONG_PTR dwParam); -DWORD PALAPI SleeperProc(LPVOID lpParameter); - -DWORD ThreadSleepDelta; - -int __cdecl main( int argc, char **argv ) -{ - int i; - DWORD dwAvgDelta; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* - On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects - (such as conditions) involves some pthread internal initialization that - can make the first wait slighty longer, potentially going above the - acceptable delta for this test. Let's add a dummy wait to preinitialize - internal structures - */ - Sleep(100); - - /* - * Check that Queueing an APC in the middle of a sleep does interrupt - * it, if it's in an alertable state. - */ - dwAvgDelta = 0; - for (i=0;i AcceptableDelta) - { - Fail("Expected thread to sleep for %d ms (and get interrupted).\n" - "Average delta: %u ms, acceptable delta: %u\n", - InterruptTime, dwAvgDelta, AcceptableDelta); - } - - /* - * Check that Queueing an APC in the middle of a sleep does NOT interrupt - * it, if it is not in an alertable state. - */ - dwAvgDelta = 0; - for (i=0;i AcceptableDelta) - { - Fail("Expected thread to sleep for %d ms (and not be interrupted).\n" - "Average delta: %u ms, acceptable delta: %u\n", - ChildThreadSleepTime, dwAvgDelta, AcceptableDelta); - } - - PAL_Terminate(); - return PASS; -} - -void RunTest(BOOL AlertThread) -{ - HANDLE hThread = 0; - DWORD dwThreadId = 0; - int ret; - - hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)SleeperProc, - (LPVOID) AlertThread, - 0, - &dwThreadId); - - if (hThread == NULL) - { - Fail("ERROR: Was not able to create the thread to test SleepEx!\n" - "GetLastError returned %d\n", GetLastError()); - } - - if (SleepEx(InterruptTime, FALSE) != 0) - { - Fail("The creating thread did not sleep!\n"); - } - - ret = QueueUserAPC(APCFunc, hThread, 0); - if (ret == 0) - { - Fail("QueueUserAPC failed! GetLastError returned %d\n", GetLastError()); - } - - ret = WaitForSingleObject(hThread, INFINITE); - if (ret == WAIT_FAILED) - { - Fail("Unable to wait on child thread!\nGetLastError returned %d.", - GetLastError()); - } -} - -/* Function doesn't do anything, just needed to interrupt SleepEx */ -VOID PALAPI APCFunc(ULONG_PTR dwParam) -{ - -} - -/* Entry Point for child thread. */ -DWORD PALAPI SleeperProc(LPVOID lpParameter) -{ - UINT64 OldTimeStamp; - UINT64 NewTimeStamp; - BOOL Alertable; - DWORD ret; - - Alertable = (BOOL) lpParameter; - - LARGE_INTEGER performanceFrequency; - if (!QueryPerformanceFrequency(&performanceFrequency)) - { - return FAIL; - } - - OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - ret = SleepEx(ChildThreadSleepTime, Alertable); - - NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - if (Alertable && ret != WAIT_IO_COMPLETION) - { - Fail("Expected the interrupted sleep to return WAIT_IO_COMPLETION.\n" - "Got %d\n", ret); - } - else if (!Alertable && ret != 0) - { - Fail("Sleep did not timeout. Expected return of 0, got %d.\n", ret); - } - - - ThreadSleepDelta = NewTimeStamp - OldTimeStamp; - - return 0; -} diff --git a/src/pal/tests/palsuite/threading/SleepEx/test2/test2.cpp b/src/pal/tests/palsuite/threading/SleepEx/test2/test2.cpp new file mode 100644 index 0000000000..c2ba4e704d --- /dev/null +++ b/src/pal/tests/palsuite/threading/SleepEx/test2/test2.cpp @@ -0,0 +1,183 @@ +// 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: test2.c +** +** Purpose: Tests that a child thread in the middle of a SleepEx call will be +** interrupted by QueueUserAPC if the alert flag was set. +** +** +**===================================================================*/ + +#include + +const int ChildThreadSleepTime = 2000; +const int InterruptTime = 1000; +/* We need to keep in mind that BSD has a timer resolution of 10ms, so + we need to adjust our delta to keep that in mind. Besides we need some + tolerance to account for different scheduling strategies, heavy load + scenarios, etc. + + Real-world data also tells us we can expect a big difference between + values when run on real iron vs run in a hypervisor. + + Thread-interruption times when run on bare metal will typically yield + around 0ms on Linux and between 0 and 16ms on FreeBSD. However, when run + in a hypervisor (like VMWare ESXi) we may get values around an order of + magnitude higher, up to 110 ms for some tests. +*/ +const DWORD AcceptableDelta = 150; + +const int Iterations = 5; + +void RunTest(BOOL AlertThread); +VOID PALAPI APCFunc(ULONG_PTR dwParam); +DWORD PALAPI SleeperProc(LPVOID lpParameter); + +DWORD ThreadSleepDelta; + +int __cdecl main( int argc, char **argv ) +{ + int i; + DWORD dwAvgDelta; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* + On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects + (such as conditions) involves some pthread internal initialization that + can make the first wait slighty longer, potentially going above the + acceptable delta for this test. Let's add a dummy wait to preinitialize + internal structures + */ + Sleep(100); + + /* + * Check that Queueing an APC in the middle of a sleep does interrupt + * it, if it's in an alertable state. + */ + dwAvgDelta = 0; + for (i=0;i AcceptableDelta) + { + Fail("Expected thread to sleep for %d ms (and get interrupted).\n" + "Average delta: %u ms, acceptable delta: %u\n", + InterruptTime, dwAvgDelta, AcceptableDelta); + } + + /* + * Check that Queueing an APC in the middle of a sleep does NOT interrupt + * it, if it is not in an alertable state. + */ + dwAvgDelta = 0; + for (i=0;i AcceptableDelta) + { + Fail("Expected thread to sleep for %d ms (and not be interrupted).\n" + "Average delta: %u ms, acceptable delta: %u\n", + ChildThreadSleepTime, dwAvgDelta, AcceptableDelta); + } + + PAL_Terminate(); + return PASS; +} + +void RunTest(BOOL AlertThread) +{ + HANDLE hThread = 0; + DWORD dwThreadId = 0; + int ret; + + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)SleeperProc, + (LPVOID) AlertThread, + 0, + &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: Was not able to create the thread to test SleepEx!\n" + "GetLastError returned %d\n", GetLastError()); + } + + if (SleepEx(InterruptTime, FALSE) != 0) + { + Fail("The creating thread did not sleep!\n"); + } + + ret = QueueUserAPC(APCFunc, hThread, 0); + if (ret == 0) + { + Fail("QueueUserAPC failed! GetLastError returned %d\n", GetLastError()); + } + + ret = WaitForSingleObject(hThread, INFINITE); + if (ret == WAIT_FAILED) + { + Fail("Unable to wait on child thread!\nGetLastError returned %d.", + GetLastError()); + } +} + +/* Function doesn't do anything, just needed to interrupt SleepEx */ +VOID PALAPI APCFunc(ULONG_PTR dwParam) +{ + +} + +/* Entry Point for child thread. */ +DWORD PALAPI SleeperProc(LPVOID lpParameter) +{ + UINT64 OldTimeStamp; + UINT64 NewTimeStamp; + BOOL Alertable; + DWORD ret; + + Alertable = (BOOL) lpParameter; + + LARGE_INTEGER performanceFrequency; + if (!QueryPerformanceFrequency(&performanceFrequency)) + { + return FAIL; + } + + OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + ret = SleepEx(ChildThreadSleepTime, Alertable); + + NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + if (Alertable && ret != WAIT_IO_COMPLETION) + { + Fail("Expected the interrupted sleep to return WAIT_IO_COMPLETION.\n" + "Got %d\n", ret); + } + else if (!Alertable && ret != 0) + { + Fail("Sleep did not timeout. Expected return of 0, got %d.\n", ret); + } + + + ThreadSleepDelta = NewTimeStamp - OldTimeStamp; + + return 0; +} diff --git a/src/pal/tests/palsuite/threading/SwitchToThread/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/SwitchToThread/test1/CMakeLists.txt index 40ecc910b0..b9008c486f 100644 --- a/src/pal/tests/palsuite/threading/SwitchToThread/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/SwitchToThread/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_switchtothread_test1 diff --git a/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.c b/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.c deleted file mode 100644 index 76ecdd3572..0000000000 --- a/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.c +++ /dev/null @@ -1,97 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure SwitchToThread works, without -** causing test to hang -** -** Dependencies: PAL_Initialize -** Fail -** SwitchToThread -** WaitForMultipleObject -** CreateThread -** GetLastError -** - -** -**===========================================================================*/ - - -#include -#define THREAD_COUNT 10 -#define REPEAT_COUNT 1000 -#define TIMEOUT 60000 -void PALAPI Run_Thread(LPVOID lpParam); - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - DWORD dwParam; - HANDLE hThread[THREAD_COUNT]; - DWORD threadId[THREAD_COUNT]; - - int i = 0; - int returnCode = 0; - - /*PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return FAIL; - } - - - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for iteration %d GetLastError value is %d\n", i, GetLastError()); - } - - } - - - returnCode = WaitForMultipleObjects(THREAD_COUNT, hThread, TRUE, TIMEOUT); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) returned %d, expected value is %d, and GetLastError value is %d\n", returnCode, WAIT_OBJECT_0, GetLastError()); - } - - PAL_Terminate(); - return PASS; - -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - int i = 0; - int Id=(int)lpParam; - - for(i=0; i < REPEAT_COUNT; i++ ) - { - // No Last Error is set.. - if(!SwitchToThread()) - { - Trace( "The operating system did not switch execution to another thread," - "for thread id[%d], iteration [%d]\n", Id, i ); - } - } -} diff --git a/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.cpp b/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.cpp new file mode 100644 index 0000000000..76ecdd3572 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.cpp @@ -0,0 +1,97 @@ +// 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: test1.c +** +** Purpose: Test to ensure SwitchToThread works, without +** causing test to hang +** +** Dependencies: PAL_Initialize +** Fail +** SwitchToThread +** WaitForMultipleObject +** CreateThread +** GetLastError +** + +** +**===========================================================================*/ + + +#include +#define THREAD_COUNT 10 +#define REPEAT_COUNT 1000 +#define TIMEOUT 60000 +void PALAPI Run_Thread(LPVOID lpParam); + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + DWORD dwParam; + HANDLE hThread[THREAD_COUNT]; + DWORD threadId[THREAD_COUNT]; + + int i = 0; + int returnCode = 0; + + /*PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return FAIL; + } + + + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for iteration %d GetLastError value is %d\n", i, GetLastError()); + } + + } + + + returnCode = WaitForMultipleObjects(THREAD_COUNT, hThread, TRUE, TIMEOUT); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) returned %d, expected value is %d, and GetLastError value is %d\n", returnCode, WAIT_OBJECT_0, GetLastError()); + } + + PAL_Terminate(); + return PASS; + +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + int i = 0; + int Id=(int)lpParam; + + for(i=0; i < REPEAT_COUNT; i++ ) + { + // No Last Error is set.. + if(!SwitchToThread()) + { + Trace( "The operating system did not switch execution to another thread," + "for thread id[%d], iteration [%d]\n", Id, i ); + } + } +} diff --git a/src/pal/tests/palsuite/threading/TLS/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/TLS/test1/CMakeLists.txt index ff1a866eb9..fef741272f 100644 --- a/src/pal/tests/palsuite/threading/TLS/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/TLS/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - TLS.c + TLS.cpp ) add_executable(paltest_tls_test1 diff --git a/src/pal/tests/palsuite/threading/TLS/test1/TLS.c b/src/pal/tests/palsuite/threading/TLS/test1/TLS.c deleted file mode 100644 index 4300c3f98b..0000000000 --- a/src/pal/tests/palsuite/threading/TLS/test1/TLS.c +++ /dev/null @@ -1,182 +0,0 @@ -// 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: tls.c -** -** Purpose: Test to ensure TlsAlloc, TlsGetValue, TlsSetValue -** and TlsFree are working properly together. -** -** Dependencies: PAL_Initialize -** Fail -** Sleep -** LocalAlloc -** LocalFree -** WaitForSingleObject -** CreateThread -** GetLastError -** - -** -**===========================================================================*/ -#include - -#define NUM_OF_THREADS 10 - -DWORD dwTlsIndex; /* TLS index */ - -/** - * CommonFunction - * - * Helper function that calls TlsGetValue - */ -VOID CommonFunction(VOID) -{ - LPVOID lpvData; - DWORD dwError; - - /* Retrieve a data pointer for the current thread. */ - lpvData = TlsGetValue(dwTlsIndex); - - if ( (lpvData == 0) && - ((dwError = GetLastError()) != NO_ERROR) ) - {/*ERROR */ - Fail("TlsGetValue(%d) returned 0 with error %d\n", - dwTlsIndex, - dwError); - } - - Sleep(5000); -} - -/** - * ThreadFunc - * - * Thread function that stores a value in the thread's tls slot - * for the predefined tls index - */ -DWORD PALAPI ThreadFunc(LPVOID lpThreadParameter) -{ - LPVOID lpvData; - DWORD dwError; - - /* Initialize the TLS index for this thread.*/ - lpvData = (LPVOID) LocalAlloc(0, 256); - - if( lpvData == NULL ) - {/*ERROR */ - dwError = GetLastError(); - Fail("Unexpected LocalAlloc(0, 256) failure with error %d\n", - dwError); - } - - - if ( TlsSetValue(dwTlsIndex, lpvData) == 0 ) - {/*ERROR */ - dwError = GetLastError(); - Fail("TlsSetValue(%d, %x) returned 0 with error %d\n", - dwTlsIndex, - lpvData, - dwError); - } - - CommonFunction(); - - /* Release the dynamic memory. */ - lpvData = TlsGetValue(dwTlsIndex); - - if ( (lpvData == 0) && - ((dwError = GetLastError()) != NO_ERROR) ) - {/*ERROR */ - Fail("TlsGetValue(%d) returned 0 with error %d\n", - dwTlsIndex, - dwError); - } - else - { - if( LocalFree((HLOCAL) lpvData) != NULL ) - { - dwError = GetLastError(); - Fail("Unexpected LocalFree(%x) failure with error %d\n", - lpvData, - dwError); - } - } - - return PASS; -} - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - DWORD IDThread; - HANDLE hThread[NUM_OF_THREADS]; - int i; - - /*PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return FAIL; - } - - /*Allocate a TLS index. */ - if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) - {/*RROR*/ - DWORD dwError = GetLastError(); - Fail("TlsAlloc() returned error %d\n", - dwError); - } - - /*Create multiple threads.*/ - - for (i = 0; i < NUM_OF_THREADS; i++) - { - hThread[i] = CreateThread(NULL, /* no security attributes*/ - 0, /* use default stack size */ - ThreadFunc, /* thread function */ - NULL, /* no thread function argument */ - 0, /* use default creation flags */ - &IDThread); /* returns thread identifier */ - - /* Check the return value for success. */ - if (hThread[i] == NULL) - {/* ERROR */ - DWORD dwError = GetLastError(); - Fail("Unexpected CreateThread error %d\n", - dwError); - } - } - - /* Wait for all threads to finish */ - for (i = 0; i < NUM_OF_THREADS; i++) - { - DWORD dwRet; - - dwRet = WaitForSingleObject(hThread[i], INFINITE); - - if( dwRet == WAIT_FAILED ) - {/* ERROR */ - DWORD dwError = GetLastError(); - Fail("Unexpected WaitForSingleObject error %d\n", - dwError); - } - } - - /* Release the TLS index */ - if( TlsFree( dwTlsIndex ) == 0 ) - {/* ERROR */ - DWORD dwError = GetLastError(); - Fail("TlsFree() returned 0 with error %d\n", - dwError); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/threading/TLS/test1/TLS.cpp b/src/pal/tests/palsuite/threading/TLS/test1/TLS.cpp new file mode 100644 index 0000000000..4300c3f98b --- /dev/null +++ b/src/pal/tests/palsuite/threading/TLS/test1/TLS.cpp @@ -0,0 +1,182 @@ +// 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: tls.c +** +** Purpose: Test to ensure TlsAlloc, TlsGetValue, TlsSetValue +** and TlsFree are working properly together. +** +** Dependencies: PAL_Initialize +** Fail +** Sleep +** LocalAlloc +** LocalFree +** WaitForSingleObject +** CreateThread +** GetLastError +** + +** +**===========================================================================*/ +#include + +#define NUM_OF_THREADS 10 + +DWORD dwTlsIndex; /* TLS index */ + +/** + * CommonFunction + * + * Helper function that calls TlsGetValue + */ +VOID CommonFunction(VOID) +{ + LPVOID lpvData; + DWORD dwError; + + /* Retrieve a data pointer for the current thread. */ + lpvData = TlsGetValue(dwTlsIndex); + + if ( (lpvData == 0) && + ((dwError = GetLastError()) != NO_ERROR) ) + {/*ERROR */ + Fail("TlsGetValue(%d) returned 0 with error %d\n", + dwTlsIndex, + dwError); + } + + Sleep(5000); +} + +/** + * ThreadFunc + * + * Thread function that stores a value in the thread's tls slot + * for the predefined tls index + */ +DWORD PALAPI ThreadFunc(LPVOID lpThreadParameter) +{ + LPVOID lpvData; + DWORD dwError; + + /* Initialize the TLS index for this thread.*/ + lpvData = (LPVOID) LocalAlloc(0, 256); + + if( lpvData == NULL ) + {/*ERROR */ + dwError = GetLastError(); + Fail("Unexpected LocalAlloc(0, 256) failure with error %d\n", + dwError); + } + + + if ( TlsSetValue(dwTlsIndex, lpvData) == 0 ) + {/*ERROR */ + dwError = GetLastError(); + Fail("TlsSetValue(%d, %x) returned 0 with error %d\n", + dwTlsIndex, + lpvData, + dwError); + } + + CommonFunction(); + + /* Release the dynamic memory. */ + lpvData = TlsGetValue(dwTlsIndex); + + if ( (lpvData == 0) && + ((dwError = GetLastError()) != NO_ERROR) ) + {/*ERROR */ + Fail("TlsGetValue(%d) returned 0 with error %d\n", + dwTlsIndex, + dwError); + } + else + { + if( LocalFree((HLOCAL) lpvData) != NULL ) + { + dwError = GetLastError(); + Fail("Unexpected LocalFree(%x) failure with error %d\n", + lpvData, + dwError); + } + } + + return PASS; +} + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + DWORD IDThread; + HANDLE hThread[NUM_OF_THREADS]; + int i; + + /*PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return FAIL; + } + + /*Allocate a TLS index. */ + if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) + {/*RROR*/ + DWORD dwError = GetLastError(); + Fail("TlsAlloc() returned error %d\n", + dwError); + } + + /*Create multiple threads.*/ + + for (i = 0; i < NUM_OF_THREADS; i++) + { + hThread[i] = CreateThread(NULL, /* no security attributes*/ + 0, /* use default stack size */ + ThreadFunc, /* thread function */ + NULL, /* no thread function argument */ + 0, /* use default creation flags */ + &IDThread); /* returns thread identifier */ + + /* Check the return value for success. */ + if (hThread[i] == NULL) + {/* ERROR */ + DWORD dwError = GetLastError(); + Fail("Unexpected CreateThread error %d\n", + dwError); + } + } + + /* Wait for all threads to finish */ + for (i = 0; i < NUM_OF_THREADS; i++) + { + DWORD dwRet; + + dwRet = WaitForSingleObject(hThread[i], INFINITE); + + if( dwRet == WAIT_FAILED ) + {/* ERROR */ + DWORD dwError = GetLastError(); + Fail("Unexpected WaitForSingleObject error %d\n", + dwError); + } + } + + /* Release the TLS index */ + if( TlsFree( dwTlsIndex ) == 0 ) + {/* ERROR */ + DWORD dwError = GetLastError(); + Fail("TlsFree() returned 0 with error %d\n", + dwError); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/threading/TLS/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/TLS/test2/CMakeLists.txt index 5afe82b4a6..10c5034589 100644 --- a/src/pal/tests/palsuite/threading/TLS/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/TLS/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - TLS.c + TLS.cpp ) add_executable(paltest_tls_test2 diff --git a/src/pal/tests/palsuite/threading/TLS/test2/TLS.c b/src/pal/tests/palsuite/threading/TLS/test2/TLS.c deleted file mode 100644 index 96a6011f96..0000000000 --- a/src/pal/tests/palsuite/threading/TLS/test2/TLS.c +++ /dev/null @@ -1,66 +0,0 @@ -// 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: tls.c -** -** Purpose: Test to ensure TlsAlloc and TlsFree are working when we try -** to allocate the guaranted minimum number of indicies. -** - -** -**===========================================================================*/ -#include - -#define NUM_OF_INDEX 64 -/* Minimum guaranteed is at least 64 for all systems.*/ - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - DWORD dwIndexes[NUM_OF_INDEX]; - int i,j; - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return FAIL; - } - - /* Allocate a bunch of TLS indexes. */ - for( i = 0; i < NUM_OF_INDEX; i++ ) - { - if( (dwIndexes[i] = TlsAlloc()) == TLS_OUT_OF_INDEXES ) - {/*ERROR */ - DWORD dwError = GetLastError(); - Fail("TlsAlloc() returned -1 with error %d" - "when trying to allocate %d index\n", - dwError, - i); - } - } - - /* Free the TLS indexes.*/ - for( j = 0; j < NUM_OF_INDEX; j++ ) - { - if( TlsFree(dwIndexes[j]) == 0 ) - {/* ERROR */ - DWORD dwError = GetLastError(); - Fail("TlsFree() returned 0 with error %d" - "when trying to free %d index\n", - dwError, - i); - } - } - - PAL_Terminate(); - - return PASS; -} - diff --git a/src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp b/src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp new file mode 100644 index 0000000000..96a6011f96 --- /dev/null +++ b/src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp @@ -0,0 +1,66 @@ +// 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: tls.c +** +** Purpose: Test to ensure TlsAlloc and TlsFree are working when we try +** to allocate the guaranted minimum number of indicies. +** + +** +**===========================================================================*/ +#include + +#define NUM_OF_INDEX 64 +/* Minimum guaranteed is at least 64 for all systems.*/ + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + DWORD dwIndexes[NUM_OF_INDEX]; + int i,j; + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return FAIL; + } + + /* Allocate a bunch of TLS indexes. */ + for( i = 0; i < NUM_OF_INDEX; i++ ) + { + if( (dwIndexes[i] = TlsAlloc()) == TLS_OUT_OF_INDEXES ) + {/*ERROR */ + DWORD dwError = GetLastError(); + Fail("TlsAlloc() returned -1 with error %d" + "when trying to allocate %d index\n", + dwError, + i); + } + } + + /* Free the TLS indexes.*/ + for( j = 0; j < NUM_OF_INDEX; j++ ) + { + if( TlsFree(dwIndexes[j]) == 0 ) + {/* ERROR */ + DWORD dwError = GetLastError(); + Fail("TlsFree() returned 0 with error %d" + "when trying to free %d index\n", + dwError, + i); + } + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/threading/TLS/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/TLS/test3/CMakeLists.txt index 0964d33d2c..6bd76d3fdf 100644 --- a/src/pal/tests/palsuite/threading/TLS/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/TLS/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - TLS.c + TLS.cpp ) add_executable(paltest_tls_test3 diff --git a/src/pal/tests/palsuite/threading/TLS/test3/TLS.c b/src/pal/tests/palsuite/threading/TLS/test3/TLS.c deleted file mode 100644 index 4acaef5020..0000000000 --- a/src/pal/tests/palsuite/threading/TLS/test3/TLS.c +++ /dev/null @@ -1,90 +0,0 @@ -// 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: tls.c -** -** Purpose: Test to ensure TlsGetValue, TlsSetValue and TlsFree -** are not working with an invalid index -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** LocalAlloc -** LocalFree -** - -** -**===========================================================================*/ -#include - -DWORD dwTlsIndex; /* TLS index */ - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - CHAR lpstrData[256] = ""; - LPVOID lpvData = NULL; - BOOL bRet; - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return FAIL; - } - - /* Invalid TLS index */ - dwTlsIndex = -1; - - /* - * Set some data in the invalid TLS index - *Should return 0 and an error - */ - bRet = TlsSetValue(dwTlsIndex, (LPVOID)lpstrData); - - if ( bRet != 0) - {/*ERROR */ - Fail("TlsSetValue(%d, %x) returned %d " - "when it should have returned 0 and an error\n", - dwTlsIndex, - lpvData, - bRet); - } - - /* - * Get the data at the invalid index - * Should return 0 and an error - */ - lpvData = TlsGetValue(dwTlsIndex); - - if ( lpvData != 0 ) - {/* ERROR */ - Fail("TlsGetValue(%d) returned %d " - "when it should have returned 0 and an error\n", - dwTlsIndex, - lpvData); - } - - /* - * Release the invalid TLS index - * Should return 0 and an error - */ - bRet = TlsFree( dwTlsIndex ); - - if( bRet != 0 ) - {/* ERROR */ - Fail("TlsFree() returned %d " - "when it should have returned 0 and an error\n", - bRet); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/pal/tests/palsuite/threading/TLS/test3/TLS.cpp b/src/pal/tests/palsuite/threading/TLS/test3/TLS.cpp new file mode 100644 index 0000000000..4acaef5020 --- /dev/null +++ b/src/pal/tests/palsuite/threading/TLS/test3/TLS.cpp @@ -0,0 +1,90 @@ +// 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: tls.c +** +** Purpose: Test to ensure TlsGetValue, TlsSetValue and TlsFree +** are not working with an invalid index +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** LocalAlloc +** LocalFree +** + +** +**===========================================================================*/ +#include + +DWORD dwTlsIndex; /* TLS index */ + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + CHAR lpstrData[256] = ""; + LPVOID lpvData = NULL; + BOOL bRet; + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return FAIL; + } + + /* Invalid TLS index */ + dwTlsIndex = -1; + + /* + * Set some data in the invalid TLS index + *Should return 0 and an error + */ + bRet = TlsSetValue(dwTlsIndex, (LPVOID)lpstrData); + + if ( bRet != 0) + {/*ERROR */ + Fail("TlsSetValue(%d, %x) returned %d " + "when it should have returned 0 and an error\n", + dwTlsIndex, + lpvData, + bRet); + } + + /* + * Get the data at the invalid index + * Should return 0 and an error + */ + lpvData = TlsGetValue(dwTlsIndex); + + if ( lpvData != 0 ) + {/* ERROR */ + Fail("TlsGetValue(%d) returned %d " + "when it should have returned 0 and an error\n", + dwTlsIndex, + lpvData); + } + + /* + * Release the invalid TLS index + * Should return 0 and an error + */ + bRet = TlsFree( dwTlsIndex ); + + if( bRet != 0 ) + {/* ERROR */ + Fail("TlsFree() returned %d " + "when it should have returned 0 and an error\n", + bRet); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/threading/TLS/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/TLS/test4/CMakeLists.txt index 7e7b47786a..73ba496f1d 100644 --- a/src/pal/tests/palsuite/threading/TLS/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/TLS/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_tls_test4 diff --git a/src/pal/tests/palsuite/threading/TLS/test4/test4.c b/src/pal/tests/palsuite/threading/TLS/test4/test4.c deleted file mode 100644 index 8c3603cdb0..0000000000 --- a/src/pal/tests/palsuite/threading/TLS/test4/test4.c +++ /dev/null @@ -1,137 +0,0 @@ -// 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: test4.c (threading/tls) -** -** Purpose: Test to ensure that upon key creation, the value NULL -** is associated with the new key in all active threads. -** Upon thread creation, the value NULL is associated -** with all defined keys in the new thread. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** LocalAlloc -** LocalFree -** - -** -**===========================================================================*/ -#include - -#define NUM_OF_THREADS 10 - -DWORD dwTlsIndex; /* TLS index */ - -/** - * ThreadFunc - * - * Thread function that checks that NULL is associated with the tls index - */ -DWORD PALAPI ThreadFunc(VOID) -{ - LPVOID lpvData; - DWORD dwError; - - /* Retrieve a data pointer for the current thread. - The return value should be NULL since no data has been - set in the index */ - lpvData = TlsGetValue(dwTlsIndex); - - if ( (lpvData != NULL) && - ((dwError = GetLastError()) == NO_ERROR) ) - {/*ERROR */ - Fail("TlsGetValue(%d) returned data " - "even if no data was associated with the index\n", - dwTlsIndex); - } - - return PASS; -} - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - DWORD IDThread; - LPVOID lpvData; - DWORD dwError; - HANDLE hThread[NUM_OF_THREADS]; - int i; - - /*PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return FAIL; - } - - /*Allocate a TLS index. */ - if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) - {/*ERROR*/ - DWORD dwError = GetLastError(); - Fail("TlsAlloc() returned error %d\n", - dwError); - } - - /*Check that the value associated with the tls index is NULL*/ - lpvData = TlsGetValue(dwTlsIndex); - - if ( (lpvData != NULL) && - ((dwError = GetLastError()) == NO_ERROR) ) - {/*ERROR */ - Fail("TlsGetValue(%d) returned non-null data " - "even if no data was associated with the index\n", - dwTlsIndex); - } - - /*Create multiple threads.*/ - for (i = 0; i < NUM_OF_THREADS; i++) - { - hThread[i] = CreateThread(NULL, /* no security attributes*/ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ - NULL, /* no thread function argument */ - 0, /* use default creation flags */ - &IDThread); /* returns thread identifier */ - - /* Check the return value for success. */ - if (hThread[i] == NULL) - {/* ERROR */ - DWORD dwError = GetLastError(); - Fail("Unexpected CreateThread error %d\n", - dwError); - } - } - - /* Wait for all threads to finish */ - for (i = 0; i < NUM_OF_THREADS; i++) - { - DWORD dwRet; - - dwRet = WaitForSingleObject(hThread[i], INFINITE); - - if( dwRet == WAIT_FAILED ) - {/* ERROR */ - DWORD dwError = GetLastError(); - Fail("Unexpected WaitForSingleObject error %d\n", - dwError); - } - } - - /* Release the TLS index */ - if( TlsFree( dwTlsIndex ) == 0 ) - {/* ERROR */ - DWORD dwError = GetLastError(); - Fail("TlsFree() returned 0 with error %d\n", - dwError); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/threading/TLS/test4/test4.cpp b/src/pal/tests/palsuite/threading/TLS/test4/test4.cpp new file mode 100644 index 0000000000..8c3603cdb0 --- /dev/null +++ b/src/pal/tests/palsuite/threading/TLS/test4/test4.cpp @@ -0,0 +1,137 @@ +// 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: test4.c (threading/tls) +** +** Purpose: Test to ensure that upon key creation, the value NULL +** is associated with the new key in all active threads. +** Upon thread creation, the value NULL is associated +** with all defined keys in the new thread. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** LocalAlloc +** LocalFree +** + +** +**===========================================================================*/ +#include + +#define NUM_OF_THREADS 10 + +DWORD dwTlsIndex; /* TLS index */ + +/** + * ThreadFunc + * + * Thread function that checks that NULL is associated with the tls index + */ +DWORD PALAPI ThreadFunc(VOID) +{ + LPVOID lpvData; + DWORD dwError; + + /* Retrieve a data pointer for the current thread. + The return value should be NULL since no data has been + set in the index */ + lpvData = TlsGetValue(dwTlsIndex); + + if ( (lpvData != NULL) && + ((dwError = GetLastError()) == NO_ERROR) ) + {/*ERROR */ + Fail("TlsGetValue(%d) returned data " + "even if no data was associated with the index\n", + dwTlsIndex); + } + + return PASS; +} + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + DWORD IDThread; + LPVOID lpvData; + DWORD dwError; + HANDLE hThread[NUM_OF_THREADS]; + int i; + + /*PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return FAIL; + } + + /*Allocate a TLS index. */ + if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) + {/*ERROR*/ + DWORD dwError = GetLastError(); + Fail("TlsAlloc() returned error %d\n", + dwError); + } + + /*Check that the value associated with the tls index is NULL*/ + lpvData = TlsGetValue(dwTlsIndex); + + if ( (lpvData != NULL) && + ((dwError = GetLastError()) == NO_ERROR) ) + {/*ERROR */ + Fail("TlsGetValue(%d) returned non-null data " + "even if no data was associated with the index\n", + dwTlsIndex); + } + + /*Create multiple threads.*/ + for (i = 0; i < NUM_OF_THREADS; i++) + { + hThread[i] = CreateThread(NULL, /* no security attributes*/ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */ + NULL, /* no thread function argument */ + 0, /* use default creation flags */ + &IDThread); /* returns thread identifier */ + + /* Check the return value for success. */ + if (hThread[i] == NULL) + {/* ERROR */ + DWORD dwError = GetLastError(); + Fail("Unexpected CreateThread error %d\n", + dwError); + } + } + + /* Wait for all threads to finish */ + for (i = 0; i < NUM_OF_THREADS; i++) + { + DWORD dwRet; + + dwRet = WaitForSingleObject(hThread[i], INFINITE); + + if( dwRet == WAIT_FAILED ) + {/* ERROR */ + DWORD dwError = GetLastError(); + Fail("Unexpected WaitForSingleObject error %d\n", + dwError); + } + } + + /* Release the TLS index */ + if( TlsFree( dwTlsIndex ) == 0 ) + {/* ERROR */ + DWORD dwError = GetLastError(); + Fail("TlsFree() returned 0 with error %d\n", + dwError); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/threading/TLS/test5/CMakeLists.txt b/src/pal/tests/palsuite/threading/TLS/test5/CMakeLists.txt index 5fb5c9ddfd..e26fcfff26 100644 --- a/src/pal/tests/palsuite/threading/TLS/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/TLS/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test5.c + test5.cpp ) add_executable(paltest_tls_test5 diff --git a/src/pal/tests/palsuite/threading/TLS/test5/test5.c b/src/pal/tests/palsuite/threading/TLS/test5/test5.c deleted file mode 100644 index c1cd132937..0000000000 --- a/src/pal/tests/palsuite/threading/TLS/test5/test5.c +++ /dev/null @@ -1,108 +0,0 @@ -// 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: test5.c (threading/tls) -** -** Purpose: Test that creates a key, sets its value, deletes the key, -** creates a new key, and gets its value to make sure its NULL. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** LocalAlloc -** LocalFree -** - -** -**===========================================================================*/ -#include - -DWORD dwTlsIndex; /* TLS index */ - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - LPVOID lpvData; - DWORD dwError; - - /*PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return FAIL; - } - - /** - * create a key, set its value, delete the key - */ - - /*Allocate a TLS index. */ - if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) - {/*ERROR*/ - DWORD dwError = GetLastError(); - Fail("TlsAlloc() returned error %d\n", - dwError); - } - - /* Initialize the TLS index for this thread.*/ - lpvData = (LPVOID) LocalAlloc(0, 256); - - if( lpvData == NULL ) - {/*ERROR */ - dwError = GetLastError(); - Fail("Unexpected LocalAlloc(0, 256) failure with error %d\n", - dwError); - } - - if ( TlsSetValue(dwTlsIndex, lpvData) == 0 ) - {/*ERROR */ - dwError = GetLastError(); - Fail("TlsSetValue(%d, %x) returned 0 with error %d\n", - dwTlsIndex, - lpvData, - dwError); - } - - /* Release the TLS index */ - if( TlsFree( dwTlsIndex ) == 0 ) - {/* ERROR */ - DWORD dwError = GetLastError(); - Fail("TlsFree() returned 0 with error %d\n", - dwError); - } - - - /** - * create a new key, and get its value - */ - - /*Allocate a TLS index. */ - if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) - {/*ERROR*/ - DWORD dwError = GetLastError(); - Fail("TlsAlloc() returned error %d\n", - dwError); - } - - /* Retrieve a data pointer for the current thread. - The return value should be NULL since no data has been - set in the index */ - lpvData = TlsGetValue(dwTlsIndex); - - if ( (lpvData != NULL) && - ((dwError = GetLastError()) == NO_ERROR) ) - {/*ERROR */ - Fail("TlsGetValue(%d) returned data " - "even if no data was associated with the index\n", - dwTlsIndex); - } - - PAL_Terminate(); - return PASS; -} - diff --git a/src/pal/tests/palsuite/threading/TLS/test5/test5.cpp b/src/pal/tests/palsuite/threading/TLS/test5/test5.cpp new file mode 100644 index 0000000000..c1cd132937 --- /dev/null +++ b/src/pal/tests/palsuite/threading/TLS/test5/test5.cpp @@ -0,0 +1,108 @@ +// 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: test5.c (threading/tls) +** +** Purpose: Test that creates a key, sets its value, deletes the key, +** creates a new key, and gets its value to make sure its NULL. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** LocalAlloc +** LocalFree +** + +** +**===========================================================================*/ +#include + +DWORD dwTlsIndex; /* TLS index */ + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + LPVOID lpvData; + DWORD dwError; + + /*PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return FAIL; + } + + /** + * create a key, set its value, delete the key + */ + + /*Allocate a TLS index. */ + if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) + {/*ERROR*/ + DWORD dwError = GetLastError(); + Fail("TlsAlloc() returned error %d\n", + dwError); + } + + /* Initialize the TLS index for this thread.*/ + lpvData = (LPVOID) LocalAlloc(0, 256); + + if( lpvData == NULL ) + {/*ERROR */ + dwError = GetLastError(); + Fail("Unexpected LocalAlloc(0, 256) failure with error %d\n", + dwError); + } + + if ( TlsSetValue(dwTlsIndex, lpvData) == 0 ) + {/*ERROR */ + dwError = GetLastError(); + Fail("TlsSetValue(%d, %x) returned 0 with error %d\n", + dwTlsIndex, + lpvData, + dwError); + } + + /* Release the TLS index */ + if( TlsFree( dwTlsIndex ) == 0 ) + {/* ERROR */ + DWORD dwError = GetLastError(); + Fail("TlsFree() returned 0 with error %d\n", + dwError); + } + + + /** + * create a new key, and get its value + */ + + /*Allocate a TLS index. */ + if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) + {/*ERROR*/ + DWORD dwError = GetLastError(); + Fail("TlsAlloc() returned error %d\n", + dwError); + } + + /* Retrieve a data pointer for the current thread. + The return value should be NULL since no data has been + set in the index */ + lpvData = TlsGetValue(dwTlsIndex); + + if ( (lpvData != NULL) && + ((dwError = GetLastError()) == NO_ERROR) ) + {/*ERROR */ + Fail("TlsGetValue(%d) returned data " + "even if no data was associated with the index\n", + dwTlsIndex); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/CMakeLists.txt b/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/CMakeLists.txt index 8b3a4ed64a..bfc7b75e0b 100644 --- a/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_tls_test6_optimizedtls diff --git a/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/test.c b/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/test.c deleted file mode 100644 index 02419dc90c..0000000000 --- a/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/test.c +++ /dev/null @@ -1,190 +0,0 @@ -// 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 to ensure TlsAlloc, PAL_MakeOptimizedTlsGetter, -** PAL_FreeOptimizedTlsGetter and TlsFree are working properly -** on supported platforms -** -** Dependencies: PAL_Initialize -** Fail -** Sleep -** LocalAlloc -** LocalFree -** WaitForSingleObject -** CreateThread -** GetLastError -** - -** -**===========================================================================*/ - - -#include -#define THREAD_COUNT 5 -DWORD dwTlsIndex; /* TLS index */ - -void PALAPI Run_Thread(LPVOID lpParam); - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - DWORD dwParam; - DWORD dwError; - HANDLE hThread[THREAD_COUNT]; - DWORD threadId[THREAD_COUNT]; - - int i = 0; - int returnCode = 0; - - /*PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return FAIL; - } - - /*Allocate a TLS index. */ - if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) - { - /*ERROR*/ - dwError = GetLastError(); - Fail("TlsAlloc() returned error %d\n", - dwError); - } - - - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for iteration %d GetLastError value is %d\n", i, GetLastError()); - } - - } - - - returnCode = WaitForMultipleObjects(THREAD_COUNT, hThread, TRUE, INFINITE); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) returned %d, expected value is %d, and GetLastError value is %d\n", returnCode, WAIT_OBJECT_0, GetLastError()); - } - - /* Release the TLS index */ - if( TlsFree( dwTlsIndex ) == 0 ) - { - /* ERROR */ - dwError = GetLastError(); - Fail("TlsFree() returned 0 with error %d\n", - dwError); - } - - PAL_Terminate(); - return PASS; - -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - unsigned int i = 0; - - LPVOID lpvData; - DWORD dwError; - PAL_POPTIMIZEDTLSGETTER ptrOptimizedTlsGetter; - - int Id=(int)lpParam; - - - lpvData = TlsGetValue(dwTlsIndex); - if ( (lpvData != NULL) && - ((dwError = GetLastError()) == NO_ERROR) ) - { - /*ERROR */ - Fail("Error:%d:TlsGetValue(%d) returned data " - "even if data was not associated with the index, for thread id [%d]\n", - dwError, dwTlsIndex, Id); - } - - - /* Initialize the TLS index for this thread.*/ - lpvData = (LPVOID) LocalAlloc(0, 256); - - if( lpvData == NULL ) - { - /*ERROR */ - dwError = GetLastError(); - Fail("Unexpected LocalAlloc(0, 256) failure with error %d\n", - dwError); - } - - if ( TlsSetValue(dwTlsIndex, lpvData) == 0 ) - { - /*ERROR */ - dwError = GetLastError(); - Fail("TlsSetValue(%d, %x) returned 0 with error %d\n", - dwTlsIndex, - lpvData, - dwError); - } - - ptrOptimizedTlsGetter = PAL_MakeOptimizedTlsGetter(dwTlsIndex); - if( ptrOptimizedTlsGetter == NULL ) - { - /* Retrieve a data pointer for the current thread. - The return value should be NULL since no data has been - set in the index */ - lpvData = TlsGetValue(dwTlsIndex); - Trace("Not Inside the optimizer loop for thread [%d]\n", Id); - - if ( (lpvData == NULL) && - ((dwError = GetLastError()) == NO_ERROR) ) - { - /*ERROR */ - Fail("Error:%d:TlsGetValue(%d) returned data " - "as NULL even if data was associated with the index, for thread id [%d]\n", - dwError, dwTlsIndex, Id); - } - } - else - { - /* Retrieve a data pointer for the current thread. - The return value should be NULL since no data has been - set in the index */ - lpvData = ptrOptimizedTlsGetter(); - - if ( (lpvData == NULL) && - ((dwError = GetLastError()) == NO_ERROR) ) - { - /*ERROR */ - Fail(" Error:%d: MakeOptimizedTlsGetter for dwTlsIndex (%d) returned data " - "as NULL even if no data was associated with the index, for thread id [%d]\n", - dwError, dwTlsIndex, Id); - } - - Trace("Inside the optimizer loop for thread [%d]\n", Id); - PAL_FreeOptimizedTlsGetter(ptrOptimizedTlsGetter); - } - - - - -} - diff --git a/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/test.cpp b/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/test.cpp new file mode 100644 index 0000000000..02419dc90c --- /dev/null +++ b/src/pal/tests/palsuite/threading/TLS/test6_optimizedtls/test.cpp @@ -0,0 +1,190 @@ +// 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 to ensure TlsAlloc, PAL_MakeOptimizedTlsGetter, +** PAL_FreeOptimizedTlsGetter and TlsFree are working properly +** on supported platforms +** +** Dependencies: PAL_Initialize +** Fail +** Sleep +** LocalAlloc +** LocalFree +** WaitForSingleObject +** CreateThread +** GetLastError +** + +** +**===========================================================================*/ + + +#include +#define THREAD_COUNT 5 +DWORD dwTlsIndex; /* TLS index */ + +void PALAPI Run_Thread(LPVOID lpParam); + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + DWORD dwParam; + DWORD dwError; + HANDLE hThread[THREAD_COUNT]; + DWORD threadId[THREAD_COUNT]; + + int i = 0; + int returnCode = 0; + + /*PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return FAIL; + } + + /*Allocate a TLS index. */ + if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) + { + /*ERROR*/ + dwError = GetLastError(); + Fail("TlsAlloc() returned error %d\n", + dwError); + } + + + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for iteration %d GetLastError value is %d\n", i, GetLastError()); + } + + } + + + returnCode = WaitForMultipleObjects(THREAD_COUNT, hThread, TRUE, INFINITE); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) returned %d, expected value is %d, and GetLastError value is %d\n", returnCode, WAIT_OBJECT_0, GetLastError()); + } + + /* Release the TLS index */ + if( TlsFree( dwTlsIndex ) == 0 ) + { + /* ERROR */ + dwError = GetLastError(); + Fail("TlsFree() returned 0 with error %d\n", + dwError); + } + + PAL_Terminate(); + return PASS; + +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + unsigned int i = 0; + + LPVOID lpvData; + DWORD dwError; + PAL_POPTIMIZEDTLSGETTER ptrOptimizedTlsGetter; + + int Id=(int)lpParam; + + + lpvData = TlsGetValue(dwTlsIndex); + if ( (lpvData != NULL) && + ((dwError = GetLastError()) == NO_ERROR) ) + { + /*ERROR */ + Fail("Error:%d:TlsGetValue(%d) returned data " + "even if data was not associated with the index, for thread id [%d]\n", + dwError, dwTlsIndex, Id); + } + + + /* Initialize the TLS index for this thread.*/ + lpvData = (LPVOID) LocalAlloc(0, 256); + + if( lpvData == NULL ) + { + /*ERROR */ + dwError = GetLastError(); + Fail("Unexpected LocalAlloc(0, 256) failure with error %d\n", + dwError); + } + + if ( TlsSetValue(dwTlsIndex, lpvData) == 0 ) + { + /*ERROR */ + dwError = GetLastError(); + Fail("TlsSetValue(%d, %x) returned 0 with error %d\n", + dwTlsIndex, + lpvData, + dwError); + } + + ptrOptimizedTlsGetter = PAL_MakeOptimizedTlsGetter(dwTlsIndex); + if( ptrOptimizedTlsGetter == NULL ) + { + /* Retrieve a data pointer for the current thread. + The return value should be NULL since no data has been + set in the index */ + lpvData = TlsGetValue(dwTlsIndex); + Trace("Not Inside the optimizer loop for thread [%d]\n", Id); + + if ( (lpvData == NULL) && + ((dwError = GetLastError()) == NO_ERROR) ) + { + /*ERROR */ + Fail("Error:%d:TlsGetValue(%d) returned data " + "as NULL even if data was associated with the index, for thread id [%d]\n", + dwError, dwTlsIndex, Id); + } + } + else + { + /* Retrieve a data pointer for the current thread. + The return value should be NULL since no data has been + set in the index */ + lpvData = ptrOptimizedTlsGetter(); + + if ( (lpvData == NULL) && + ((dwError = GetLastError()) == NO_ERROR) ) + { + /*ERROR */ + Fail(" Error:%d: MakeOptimizedTlsGetter for dwTlsIndex (%d) returned data " + "as NULL even if no data was associated with the index, for thread id [%d]\n", + dwError, dwTlsIndex, Id); + } + + Trace("Inside the optimizer loop for thread [%d]\n", Id); + PAL_FreeOptimizedTlsGetter(ptrOptimizedTlsGetter); + } + + + + +} + diff --git a/src/pal/tests/palsuite/threading/TerminateProcess/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/TerminateProcess/test1/CMakeLists.txt index 37d575952f..382e801e29 100644 --- a/src/pal/tests/palsuite/threading/TerminateProcess/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/TerminateProcess/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - TerminateProcess.c + TerminateProcess.cpp ) add_executable(paltest_terminateprocess_test1 diff --git a/src/pal/tests/palsuite/threading/TerminateProcess/test1/TerminateProcess.c b/src/pal/tests/palsuite/threading/TerminateProcess/test1/TerminateProcess.c deleted file mode 100644 index 6feedfce76..0000000000 --- a/src/pal/tests/palsuite/threading/TerminateProcess/test1/TerminateProcess.c +++ /dev/null @@ -1,41 +0,0 @@ -// 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: terminateprocess/test1/terminateprocess.c -** -** Purpose: Test to see if TerminateProcess will -** terminate the current process. -** -** Dependencies: GetCurrentProcess -** -** -**=========================================================*/ - -#include - -INT __cdecl main( int argc, char **argv ) -{ - - HANDLE hProcess; - - if(0 != (PAL_Initialize(argc, argv))) - { - return (FAIL); - } - - hProcess = GetCurrentProcess(); - - Trace ("Testing TerminateProcess function.\n"); - - if ( 0 == ( TerminateProcess ( hProcess, PASS ) ) ) - { - Fail ("TerminateProcess failed.\n"); - } - - PAL_TerminateEx(FAIL); - return (FAIL); - -} diff --git a/src/pal/tests/palsuite/threading/TerminateProcess/test1/TerminateProcess.cpp b/src/pal/tests/palsuite/threading/TerminateProcess/test1/TerminateProcess.cpp new file mode 100644 index 0000000000..6feedfce76 --- /dev/null +++ b/src/pal/tests/palsuite/threading/TerminateProcess/test1/TerminateProcess.cpp @@ -0,0 +1,41 @@ +// 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: terminateprocess/test1/terminateprocess.c +** +** Purpose: Test to see if TerminateProcess will +** terminate the current process. +** +** Dependencies: GetCurrentProcess +** +** +**=========================================================*/ + +#include + +INT __cdecl main( int argc, char **argv ) +{ + + HANDLE hProcess; + + if(0 != (PAL_Initialize(argc, argv))) + { + return (FAIL); + } + + hProcess = GetCurrentProcess(); + + Trace ("Testing TerminateProcess function.\n"); + + if ( 0 == ( TerminateProcess ( hProcess, PASS ) ) ) + { + Fail ("TerminateProcess failed.\n"); + } + + PAL_TerminateEx(FAIL); + return (FAIL); + +} diff --git a/src/pal/tests/palsuite/threading/ThreadPriority/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/ThreadPriority/test1/CMakeLists.txt index e341ca7435..026f4ed043 100644 --- a/src/pal/tests/palsuite/threading/ThreadPriority/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/ThreadPriority/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - ThreadPriority.c + ThreadPriority.cpp ) add_executable(paltest_threadpriority_test1 diff --git a/src/pal/tests/palsuite/threading/ThreadPriority/test1/ThreadPriority.c b/src/pal/tests/palsuite/threading/ThreadPriority/test1/ThreadPriority.c deleted file mode 100644 index 95bcdac52a..0000000000 --- a/src/pal/tests/palsuite/threading/ThreadPriority/test1/ThreadPriority.c +++ /dev/null @@ -1,83 +0,0 @@ -// 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: threadpriority.c -** -** Purpose: Test to ensure GetThreadPriority works properly. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** CreateThread -** WaitForSingleObject -** GetLastError -** time() -** - -** -**===========================================================================*/ -#include - -/** - * CheckThreadPriority - * - * Helper function that checks the current thread priority - * against an expected value. - */ -static VOID CheckThreadPriority( HANDLE hThread, int expectedPriority ) -{ - int priority; - DWORD dwError = 0; - - /* get the current thread priority */ - priority = GetThreadPriority( hThread ); - if( priority == THREAD_PRIORITY_ERROR_RETURN ) - { - /* GetThreadPriority call failed */ - dwError = GetLastError(); - Fail( "Unexpected GetThreadPriority() failure " - "with error %d\n", dwError ); - } - else if( priority != expectedPriority ) - { - /* unexpected thread priority detected */ - Fail( "Unexpected initial thread priority value %d reported\n", - priority ); - } -} - - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - - /* PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return( FAIL ); - } - - /* set the thread priority of the main to the highest possible value - this will give the chance to the main thread to create all the - other threads */ - if(!SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL)) - { - DWORD dwError; - - dwError = GetLastError(); - Fail( "Unexpected SetThreadPriority() failure with error %d\n", - dwError ); - } - - CheckThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL ); - //Add verification of timing out here.. - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/ThreadPriority/test1/ThreadPriority.cpp b/src/pal/tests/palsuite/threading/ThreadPriority/test1/ThreadPriority.cpp new file mode 100644 index 0000000000..95bcdac52a --- /dev/null +++ b/src/pal/tests/palsuite/threading/ThreadPriority/test1/ThreadPriority.cpp @@ -0,0 +1,83 @@ +// 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: threadpriority.c +** +** Purpose: Test to ensure GetThreadPriority works properly. +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** CreateThread +** WaitForSingleObject +** GetLastError +** time() +** + +** +**===========================================================================*/ +#include + +/** + * CheckThreadPriority + * + * Helper function that checks the current thread priority + * against an expected value. + */ +static VOID CheckThreadPriority( HANDLE hThread, int expectedPriority ) +{ + int priority; + DWORD dwError = 0; + + /* get the current thread priority */ + priority = GetThreadPriority( hThread ); + if( priority == THREAD_PRIORITY_ERROR_RETURN ) + { + /* GetThreadPriority call failed */ + dwError = GetLastError(); + Fail( "Unexpected GetThreadPriority() failure " + "with error %d\n", dwError ); + } + else if( priority != expectedPriority ) + { + /* unexpected thread priority detected */ + Fail( "Unexpected initial thread priority value %d reported\n", + priority ); + } +} + + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + /* set the thread priority of the main to the highest possible value + this will give the chance to the main thread to create all the + other threads */ + if(!SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL)) + { + DWORD dwError; + + dwError = GetLastError(); + Fail( "Unexpected SetThreadPriority() failure with error %d\n", + dwError ); + } + + CheckThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL ); + //Add verification of timing out here.. + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/CMakeLists.txt index 2b1f946b26..ea13c7de4c 100644 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_waitformultipleobjects_test1 diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/test1.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/test1.c deleted file mode 100644 index 8249c38d9d..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/test1.c +++ /dev/null @@ -1,224 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for WaitForMultipleObjects. Call the function -** on an array of 4 events, and ensure that it returns correct -** results when we do so. -** -** -**=========================================================*/ - -#include - -/* Number of events in array */ -#define MAX_EVENTS 4 - -BOOL WaitForMultipleObjectsTest() -{ - BOOL bRet = TRUE; - DWORD dwRet = 0; - - DWORD i = 0, j = 0; - - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = TRUE; - - HANDLE hEvent[MAX_EVENTS]; - - /* Run through this for loop and create 4 events */ - for (i = 0; i < MAX_EVENTS; i++) - { - hEvent[i] = CreateEvent( lpEventAttributes, - bManualReset, bInitialState, NULL); - - if (hEvent[i] == INVALID_HANDLE_VALUE) - { - Trace("WaitForMultipleObjectsTest:CreateEvent %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - - /* Set the current event */ - bRet = SetEvent(hEvent[i]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsTest:SetEvent %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - - /* Ensure that this returns the correct value */ - dwRet = WaitForSingleObject(hEvent[i],0); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("WaitForMultipleObjectsTest:WaitForSingleObject %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - - /* Reset the event, and again ensure that the return value of - WaitForSingle is correct. - */ - bRet = ResetEvent(hEvent[i]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsTest:ResetEvent %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - - dwRet = WaitForSingleObject(hEvent[i],0); - - if (dwRet != WAIT_TIMEOUT) - { - Trace("WaitForMultipleObjectsTest:WaitForSingleObject %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - } - - /* - * If the first section of the test passed, move on to the - * second. - */ - - if (bRet) - { - BOOL bWaitAll = TRUE; - DWORD nCount = MAX_EVENTS; - CONST HANDLE *lpHandles = &hEvent[0]; - - /* Call WaitForMultipleOjbects on all the events, the return - should be WAIT_TIMEOUT - */ - dwRet = WaitForMultipleObjects( nCount, - lpHandles, - bWaitAll, - 0); - - if (dwRet != WAIT_TIMEOUT) - { - Trace("WaitForMultipleObjectsTest:WaitForMultipleObjects failed (%x)\n", GetLastError()); - } - else - { - /* Step through each event and one at a time, set the - currect test, while reseting all the other tests - */ - - for (i = 0; i < MAX_EVENTS; i++) - { - for (j = 0; j < MAX_EVENTS; j++) - { - if (j == i) - { - - bRet = SetEvent(hEvent[j]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsTest:SetEvent %u failed (%x)\n", j, GetLastError()); - break; - } - } - else - { - bRet = ResetEvent(hEvent[j]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsTest:ResetEvent %u failed (%x)\n", j, GetLastError()); - } - } - } - - bWaitAll = FALSE; - - /* Check that WaitFor returns WAIT_OBJECT + i */ - dwRet = WaitForMultipleObjects( nCount, - lpHandles, bWaitAll, 0); - - if (dwRet != WAIT_OBJECT_0+i) - { - Trace("WaitForMultipleObjectsTest:WaitForMultipleObjects failed (%x)\n", GetLastError()); - bRet = FALSE; - break; - } - } - } - - for (i = 0; i < MAX_EVENTS; i++) - { - bRet = CloseHandle(hEvent[i]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsTest:CloseHandle %u failed (%x)\n", i, GetLastError()); - } - } - } - - return bRet; -} - -BOOL WaitMultipleDuplicateHandleTest() -{ - BOOL testResult = TRUE; - const HANDLE eventHandle = CreateEvent(NULL, TRUE, TRUE, NULL); - HANDLE eventHandles[] = {eventHandle, eventHandle}; - - // WaitAny - Wait for any of the events (no error expected) - DWORD result = WaitForMultipleObjects(sizeof(eventHandles) / sizeof(eventHandles[0]), eventHandles, FALSE, 0); - if (result != WAIT_OBJECT_0) - { - Trace("WaitMultipleDuplicateHandleTest:WaitAny failed (%x)\n", GetLastError()); - testResult = FALSE; - } - - // WaitAll - Wait for all of the events (error expected) - result = WaitForMultipleObjects(sizeof(eventHandles) / sizeof(eventHandles[0]), eventHandles, TRUE, 0); - if (result != WAIT_FAILED) - { - Trace("WaitMultipleDuplicateHandleTest:WaitAll failed: call unexpectedly succeeded\n"); - testResult = FALSE; - } - else if (GetLastError() != ERROR_INVALID_PARAMETER) - { - Trace("WaitMultipleDuplicateHandleTest:WaitAll failed: unexpected last error (%x)\n"); - testResult = FALSE; - } - - return testResult; -} - -int __cdecl main(int argc, char **argv) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!WaitForMultipleObjectsTest()) - { - Fail ("Test failed\n"); - } - - if (!WaitMultipleDuplicateHandleTest()) - { - Fail("Test failed\n"); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/test1.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/test1.cpp new file mode 100644 index 0000000000..8249c38d9d --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjects/test1/test1.cpp @@ -0,0 +1,224 @@ +// 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: test1.c +** +** Purpose: Test for WaitForMultipleObjects. Call the function +** on an array of 4 events, and ensure that it returns correct +** results when we do so. +** +** +**=========================================================*/ + +#include + +/* Number of events in array */ +#define MAX_EVENTS 4 + +BOOL WaitForMultipleObjectsTest() +{ + BOOL bRet = TRUE; + DWORD dwRet = 0; + + DWORD i = 0, j = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = TRUE; + + HANDLE hEvent[MAX_EVENTS]; + + /* Run through this for loop and create 4 events */ + for (i = 0; i < MAX_EVENTS; i++) + { + hEvent[i] = CreateEvent( lpEventAttributes, + bManualReset, bInitialState, NULL); + + if (hEvent[i] == INVALID_HANDLE_VALUE) + { + Trace("WaitForMultipleObjectsTest:CreateEvent %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + + /* Set the current event */ + bRet = SetEvent(hEvent[i]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsTest:SetEvent %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + + /* Ensure that this returns the correct value */ + dwRet = WaitForSingleObject(hEvent[i],0); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("WaitForMultipleObjectsTest:WaitForSingleObject %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + + /* Reset the event, and again ensure that the return value of + WaitForSingle is correct. + */ + bRet = ResetEvent(hEvent[i]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsTest:ResetEvent %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + + dwRet = WaitForSingleObject(hEvent[i],0); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("WaitForMultipleObjectsTest:WaitForSingleObject %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + } + + /* + * If the first section of the test passed, move on to the + * second. + */ + + if (bRet) + { + BOOL bWaitAll = TRUE; + DWORD nCount = MAX_EVENTS; + CONST HANDLE *lpHandles = &hEvent[0]; + + /* Call WaitForMultipleOjbects on all the events, the return + should be WAIT_TIMEOUT + */ + dwRet = WaitForMultipleObjects( nCount, + lpHandles, + bWaitAll, + 0); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("WaitForMultipleObjectsTest:WaitForMultipleObjects failed (%x)\n", GetLastError()); + } + else + { + /* Step through each event and one at a time, set the + currect test, while reseting all the other tests + */ + + for (i = 0; i < MAX_EVENTS; i++) + { + for (j = 0; j < MAX_EVENTS; j++) + { + if (j == i) + { + + bRet = SetEvent(hEvent[j]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsTest:SetEvent %u failed (%x)\n", j, GetLastError()); + break; + } + } + else + { + bRet = ResetEvent(hEvent[j]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsTest:ResetEvent %u failed (%x)\n", j, GetLastError()); + } + } + } + + bWaitAll = FALSE; + + /* Check that WaitFor returns WAIT_OBJECT + i */ + dwRet = WaitForMultipleObjects( nCount, + lpHandles, bWaitAll, 0); + + if (dwRet != WAIT_OBJECT_0+i) + { + Trace("WaitForMultipleObjectsTest:WaitForMultipleObjects failed (%x)\n", GetLastError()); + bRet = FALSE; + break; + } + } + } + + for (i = 0; i < MAX_EVENTS; i++) + { + bRet = CloseHandle(hEvent[i]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsTest:CloseHandle %u failed (%x)\n", i, GetLastError()); + } + } + } + + return bRet; +} + +BOOL WaitMultipleDuplicateHandleTest() +{ + BOOL testResult = TRUE; + const HANDLE eventHandle = CreateEvent(NULL, TRUE, TRUE, NULL); + HANDLE eventHandles[] = {eventHandle, eventHandle}; + + // WaitAny - Wait for any of the events (no error expected) + DWORD result = WaitForMultipleObjects(sizeof(eventHandles) / sizeof(eventHandles[0]), eventHandles, FALSE, 0); + if (result != WAIT_OBJECT_0) + { + Trace("WaitMultipleDuplicateHandleTest:WaitAny failed (%x)\n", GetLastError()); + testResult = FALSE; + } + + // WaitAll - Wait for all of the events (error expected) + result = WaitForMultipleObjects(sizeof(eventHandles) / sizeof(eventHandles[0]), eventHandles, TRUE, 0); + if (result != WAIT_FAILED) + { + Trace("WaitMultipleDuplicateHandleTest:WaitAll failed: call unexpectedly succeeded\n"); + testResult = FALSE; + } + else if (GetLastError() != ERROR_INVALID_PARAMETER) + { + Trace("WaitMultipleDuplicateHandleTest:WaitAll failed: unexpected last error (%x)\n"); + testResult = FALSE; + } + + return testResult; +} + +int __cdecl main(int argc, char **argv) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!WaitForMultipleObjectsTest()) + { + Fail ("Test failed\n"); + } + + if (!WaitMultipleDuplicateHandleTest()) + { + Fail("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/CMakeLists.txt index d035021bb9..59d4cd8cd4 100644 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_waitformultipleobjectsex_test1 diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/test1.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/test1.c deleted file mode 100644 index df3233fa50..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/test1.c +++ /dev/null @@ -1,226 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for WaitForMultipleObjectsEx. Call the function -** on an array of 4 events, and ensure that it returns correct -** results when we do so. -** -** -**=========================================================*/ - -#include - -/* Originally written as WaitForMultipleObjects/test1 */ - - -/* Number of events in array */ -#define MAX_EVENTS 4 - -BOOL WaitForMultipleObjectsExTest() -{ - BOOL bRet = TRUE; - DWORD dwRet = 0; - DWORD i = 0, j = 0; - - LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; - BOOL bManualReset = TRUE; - BOOL bInitialState = TRUE; - - HANDLE hEvent[MAX_EVENTS]; - - /* Run through this for loop and create 4 events */ - for (i = 0; i < MAX_EVENTS; i++) - { - hEvent[i] = CreateEvent( lpEventAttributes, - bManualReset, bInitialState, NULL); - - if (hEvent[i] == INVALID_HANDLE_VALUE) - { - Trace("WaitForMultipleObjectsExTest:CreateEvent %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - - /* Set the current event */ - bRet = SetEvent(hEvent[i]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsExTest:SetEvent %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - - /* Ensure that this returns the correct value */ - dwRet = WaitForSingleObject(hEvent[i],0); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("WaitForMultipleObjectsExTest:WaitForSingleObject %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - - /* Reset the event, and again ensure that the return value of - WaitForSingle is correct. - */ - bRet = ResetEvent(hEvent[i]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsExTest:ResetEvent %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - - dwRet = WaitForSingleObject(hEvent[i],0); - - if (dwRet != WAIT_TIMEOUT) - { - Trace("WaitForMultipleObjectsExTest:WaitForSingleObject %u failed (%x)\n", i, GetLastError()); - bRet = FALSE; - break; - } - } - - /* - * If the first section of the test passed, move on to the - * second. - */ - - if (bRet) - { - BOOL bWaitAll = TRUE; - DWORD nCount = MAX_EVENTS; - CONST HANDLE *lpHandles = &hEvent[0]; - - /* Call WaitForMultipleObjectsEx on all the events, the return - should be WAIT_TIMEOUT - */ - dwRet = WaitForMultipleObjectsEx(nCount, - lpHandles, - bWaitAll, - 0, - FALSE); - - if (dwRet != WAIT_TIMEOUT) - { - Trace("WaitForMultipleObjectsExTest: WaitForMultipleObjectsEx failed (%x)\n", GetLastError()); - } - else - { - /* Step through each event and one at a time, set the - currect test, while reseting all the other tests - */ - - for (i = 0; i < MAX_EVENTS; i++) - { - for (j = 0; j < MAX_EVENTS; j++) - { - if (j == i) - { - - bRet = SetEvent(hEvent[j]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsExTest:SetEvent %j failed (%x)\n", j, GetLastError()); - break; - } - } - else - { - bRet = ResetEvent(hEvent[j]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsExTest:ResetEvent %u failed (%x)\n", j, GetLastError()); - } - } - } - - bWaitAll = FALSE; - - /* Check that WaitFor returns WAIT_OBJECT + i */ - dwRet = WaitForMultipleObjectsEx( nCount, - lpHandles, bWaitAll, 0, FALSE); - - if (dwRet != WAIT_OBJECT_0+i) - { - Trace("WaitForMultipleObjectsExTest: WaitForMultipleObjectsEx failed (%x)\n", GetLastError()); - bRet = FALSE; - break; - } - } - } - - for (i = 0; i < MAX_EVENTS; i++) - { - bRet = CloseHandle(hEvent[i]); - - if (!bRet) - { - Trace("WaitForMultipleObjectsExTest:CloseHandle %u failed (%x)\n", i, GetLastError()); - } - } - } - - return bRet; -} - -BOOL WaitMultipleDuplicateHandleTest() -{ - BOOL testResult = TRUE; - const HANDLE eventHandle = CreateEvent(NULL, TRUE, TRUE, NULL); - HANDLE eventHandles[] = {eventHandle, eventHandle}; - - // WaitAny - Wait for any of the events (no error expected) - DWORD result = WaitForMultipleObjects(sizeof(eventHandles) / sizeof(eventHandles[0]), eventHandles, FALSE, 0); - if (result != WAIT_OBJECT_0) - { - Trace("WaitMultipleDuplicateHandleTest:WaitAny failed (%x)\n", GetLastError()); - testResult = FALSE; - } - - // WaitAll - Wait for all of the events (error expected) - result = WaitForMultipleObjects(sizeof(eventHandles) / sizeof(eventHandles[0]), eventHandles, TRUE, 0); - if (result != WAIT_FAILED) - { - Trace("WaitMultipleDuplicateHandleTest:WaitAll failed: call unexpectedly succeeded\n"); - testResult = FALSE; - } - else if (GetLastError() != ERROR_INVALID_PARAMETER) - { - Trace("WaitMultipleDuplicateHandleTest:WaitAll failed: unexpected last error (%x)\n"); - testResult = FALSE; - } - - return testResult; -} - -int __cdecl main(int argc, char **argv) -{ - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!WaitForMultipleObjectsExTest()) - { - Fail ("Test failed\n"); - } - - if (!WaitMultipleDuplicateHandleTest()) - { - Fail("Test failed\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/test1.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/test1.cpp new file mode 100644 index 0000000000..df3233fa50 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/test1.cpp @@ -0,0 +1,226 @@ +// 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: test1.c +** +** Purpose: Test for WaitForMultipleObjectsEx. Call the function +** on an array of 4 events, and ensure that it returns correct +** results when we do so. +** +** +**=========================================================*/ + +#include + +/* Originally written as WaitForMultipleObjects/test1 */ + + +/* Number of events in array */ +#define MAX_EVENTS 4 + +BOOL WaitForMultipleObjectsExTest() +{ + BOOL bRet = TRUE; + DWORD dwRet = 0; + DWORD i = 0, j = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = TRUE; + + HANDLE hEvent[MAX_EVENTS]; + + /* Run through this for loop and create 4 events */ + for (i = 0; i < MAX_EVENTS; i++) + { + hEvent[i] = CreateEvent( lpEventAttributes, + bManualReset, bInitialState, NULL); + + if (hEvent[i] == INVALID_HANDLE_VALUE) + { + Trace("WaitForMultipleObjectsExTest:CreateEvent %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + + /* Set the current event */ + bRet = SetEvent(hEvent[i]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsExTest:SetEvent %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + + /* Ensure that this returns the correct value */ + dwRet = WaitForSingleObject(hEvent[i],0); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("WaitForMultipleObjectsExTest:WaitForSingleObject %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + + /* Reset the event, and again ensure that the return value of + WaitForSingle is correct. + */ + bRet = ResetEvent(hEvent[i]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsExTest:ResetEvent %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + + dwRet = WaitForSingleObject(hEvent[i],0); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("WaitForMultipleObjectsExTest:WaitForSingleObject %u failed (%x)\n", i, GetLastError()); + bRet = FALSE; + break; + } + } + + /* + * If the first section of the test passed, move on to the + * second. + */ + + if (bRet) + { + BOOL bWaitAll = TRUE; + DWORD nCount = MAX_EVENTS; + CONST HANDLE *lpHandles = &hEvent[0]; + + /* Call WaitForMultipleObjectsEx on all the events, the return + should be WAIT_TIMEOUT + */ + dwRet = WaitForMultipleObjectsEx(nCount, + lpHandles, + bWaitAll, + 0, + FALSE); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("WaitForMultipleObjectsExTest: WaitForMultipleObjectsEx failed (%x)\n", GetLastError()); + } + else + { + /* Step through each event and one at a time, set the + currect test, while reseting all the other tests + */ + + for (i = 0; i < MAX_EVENTS; i++) + { + for (j = 0; j < MAX_EVENTS; j++) + { + if (j == i) + { + + bRet = SetEvent(hEvent[j]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsExTest:SetEvent %j failed (%x)\n", j, GetLastError()); + break; + } + } + else + { + bRet = ResetEvent(hEvent[j]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsExTest:ResetEvent %u failed (%x)\n", j, GetLastError()); + } + } + } + + bWaitAll = FALSE; + + /* Check that WaitFor returns WAIT_OBJECT + i */ + dwRet = WaitForMultipleObjectsEx( nCount, + lpHandles, bWaitAll, 0, FALSE); + + if (dwRet != WAIT_OBJECT_0+i) + { + Trace("WaitForMultipleObjectsExTest: WaitForMultipleObjectsEx failed (%x)\n", GetLastError()); + bRet = FALSE; + break; + } + } + } + + for (i = 0; i < MAX_EVENTS; i++) + { + bRet = CloseHandle(hEvent[i]); + + if (!bRet) + { + Trace("WaitForMultipleObjectsExTest:CloseHandle %u failed (%x)\n", i, GetLastError()); + } + } + } + + return bRet; +} + +BOOL WaitMultipleDuplicateHandleTest() +{ + BOOL testResult = TRUE; + const HANDLE eventHandle = CreateEvent(NULL, TRUE, TRUE, NULL); + HANDLE eventHandles[] = {eventHandle, eventHandle}; + + // WaitAny - Wait for any of the events (no error expected) + DWORD result = WaitForMultipleObjects(sizeof(eventHandles) / sizeof(eventHandles[0]), eventHandles, FALSE, 0); + if (result != WAIT_OBJECT_0) + { + Trace("WaitMultipleDuplicateHandleTest:WaitAny failed (%x)\n", GetLastError()); + testResult = FALSE; + } + + // WaitAll - Wait for all of the events (error expected) + result = WaitForMultipleObjects(sizeof(eventHandles) / sizeof(eventHandles[0]), eventHandles, TRUE, 0); + if (result != WAIT_FAILED) + { + Trace("WaitMultipleDuplicateHandleTest:WaitAll failed: call unexpectedly succeeded\n"); + testResult = FALSE; + } + else if (GetLastError() != ERROR_INVALID_PARAMETER) + { + Trace("WaitMultipleDuplicateHandleTest:WaitAll failed: unexpected last error (%x)\n"); + testResult = FALSE; + } + + return testResult; +} + +int __cdecl main(int argc, char **argv) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!WaitForMultipleObjectsExTest()) + { + Fail ("Test failed\n"); + } + + if (!WaitMultipleDuplicateHandleTest()) + { + Fail("Test failed\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/CMakeLists.txt index ab47c6f2e7..e970ec526e 100644 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test2.cpp ) add_executable(paltest_waitformultipleobjectsex_test2 diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.c deleted file mode 100644 index b2bc301128..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.c +++ /dev/null @@ -1,188 +0,0 @@ -// 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: test2.c -** -** Purpose: Tests that a child thread in the middle of a -** WaitForMultipleObjectsEx call will be interrupted by QueueUserAPC -** if the alert flag was set. -** -** -**===================================================================*/ - -#include - -/* Based on SleepEx/test2 */ - -const unsigned int ChildThreadWaitTime = 1000; -const unsigned int InterruptTime = 500; - -#define TOLERANCE 10 - -void RunTest(BOOL AlertThread); -VOID PALAPI APCFunc(ULONG_PTR dwParam); -DWORD PALAPI WaiterProc(LPVOID lpParameter); - -DWORD ThreadWaitDelta; - -int __cdecl main( int argc, char **argv ) -{ - - DWORD delta = 0; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* - On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects - (such as conditions) involves some pthread internal initialization that - can make the first wait slighty longer, potentially going above the - acceptable delta for this test. Let's add a dummy wait to preinitialize - internal structures - */ - Sleep(100); - - - /* - * Check that Queueing an APC in the middle of a wait does interrupt - * it, if it's in an alertable state. - */ - RunTest(TRUE); - // Make sure that the wait returns in time greater than interrupt and less than - // wait timeout - if ( - ((ThreadWaitDelta >= ChildThreadWaitTime) && (ThreadWaitDelta - ChildThreadWaitTime) > TOLERANCE) - || (( ThreadWaitDelta < InterruptTime) && (ThreadWaitDelta - InterruptTime) > TOLERANCE) - ) - { - Fail("Expected thread to wait for %d ms (and get interrupted).\n" - "Interrupt Time: %d ms, ThreadWaitDelta %u\n", - ChildThreadWaitTime, InterruptTime, ThreadWaitDelta); - } - - /* - * Check that Queueing an APC in the middle of a wait does NOT interrupt - * it, if it is not in an alertable state. - */ - RunTest(FALSE); - - // Make sure that time taken for thread to return from wait is more than interrupt - // and also not less than the complete child thread wait time - - delta = ThreadWaitDelta - ChildThreadWaitTime; - if( (ThreadWaitDelta < ChildThreadWaitTime) && ( delta > TOLERANCE) ) - { - Fail("Expected thread to wait for %d ms (and not get interrupted).\n" - "Interrupt Time: %d ms, ThreadWaitDelta %u\n", - ChildThreadWaitTime, InterruptTime, ThreadWaitDelta); - } - - - PAL_Terminate(); - return PASS; -} - -void RunTest(BOOL AlertThread) -{ - HANDLE hThread = 0; - DWORD dwThreadId = 0; - int ret; - - hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)WaiterProc, - (LPVOID) AlertThread, - 0, - &dwThreadId); - - if (hThread == NULL) - { - Fail("ERROR: Was not able to create the thread to test!\n" - "GetLastError returned %d\n", GetLastError()); - } - - Sleep(InterruptTime); - - ret = QueueUserAPC(APCFunc, hThread, 0); - if (ret == 0) - { - Fail("QueueUserAPC failed! GetLastError returned %d\n", - GetLastError()); - } - - ret = WaitForSingleObject(hThread, INFINITE); - if (ret == WAIT_FAILED) - { - Fail("Unable to wait on child thread!\nGetLastError returned %d.\n", - GetLastError()); - } -} - -/* Function doesn't do anything, just needed to interrupt the wait*/ -VOID PALAPI APCFunc(ULONG_PTR dwParam) -{ -} - -/* Entry Point for child thread. */ -DWORD PALAPI WaiterProc(LPVOID lpParameter) -{ - HANDLE Semaphore; - UINT64 OldTimeStamp; - UINT64 NewTimeStamp; - BOOL Alertable; - DWORD ret; - - /* Create a semaphore that is not in the signalled state */ - Semaphore = CreateSemaphoreW(NULL, 0, 1, NULL); - - if (Semaphore == NULL) - { - Fail("Failed to create semaphore! GetLastError returned %d.\n", - GetLastError()); - } - - Alertable = (BOOL) lpParameter; - - LARGE_INTEGER performanceFrequency; - if (!QueryPerformanceFrequency(&performanceFrequency)) - { - Fail("Failed to query performance frequency!"); - } - - OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - ret = WaitForMultipleObjectsEx(1, &Semaphore, FALSE, ChildThreadWaitTime, - Alertable); - - NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - - if (Alertable && ret != WAIT_IO_COMPLETION) - { - Fail("Expected the interrupted wait to return WAIT_IO_COMPLETION.\n" - "Got %d\n", ret); - } - else if (!Alertable && ret != WAIT_TIMEOUT) - { - Fail("WaitForMultipleObjectsEx did not timeout.\n" - "Expected return of WAIT_TIMEOUT, got %d.\n", ret); - } - - ThreadWaitDelta = NewTimeStamp - OldTimeStamp; - - ret = CloseHandle(Semaphore); - if (!ret) - { - Fail("Unable to close handle to semaphore!\n" - "GetLastError returned %d\n", GetLastError()); - } - - return 0; -} - - diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.cpp new file mode 100644 index 0000000000..b2bc301128 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.cpp @@ -0,0 +1,188 @@ +// 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: test2.c +** +** Purpose: Tests that a child thread in the middle of a +** WaitForMultipleObjectsEx call will be interrupted by QueueUserAPC +** if the alert flag was set. +** +** +**===================================================================*/ + +#include + +/* Based on SleepEx/test2 */ + +const unsigned int ChildThreadWaitTime = 1000; +const unsigned int InterruptTime = 500; + +#define TOLERANCE 10 + +void RunTest(BOOL AlertThread); +VOID PALAPI APCFunc(ULONG_PTR dwParam); +DWORD PALAPI WaiterProc(LPVOID lpParameter); + +DWORD ThreadWaitDelta; + +int __cdecl main( int argc, char **argv ) +{ + + DWORD delta = 0; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* + On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects + (such as conditions) involves some pthread internal initialization that + can make the first wait slighty longer, potentially going above the + acceptable delta for this test. Let's add a dummy wait to preinitialize + internal structures + */ + Sleep(100); + + + /* + * Check that Queueing an APC in the middle of a wait does interrupt + * it, if it's in an alertable state. + */ + RunTest(TRUE); + // Make sure that the wait returns in time greater than interrupt and less than + // wait timeout + if ( + ((ThreadWaitDelta >= ChildThreadWaitTime) && (ThreadWaitDelta - ChildThreadWaitTime) > TOLERANCE) + || (( ThreadWaitDelta < InterruptTime) && (ThreadWaitDelta - InterruptTime) > TOLERANCE) + ) + { + Fail("Expected thread to wait for %d ms (and get interrupted).\n" + "Interrupt Time: %d ms, ThreadWaitDelta %u\n", + ChildThreadWaitTime, InterruptTime, ThreadWaitDelta); + } + + /* + * Check that Queueing an APC in the middle of a wait does NOT interrupt + * it, if it is not in an alertable state. + */ + RunTest(FALSE); + + // Make sure that time taken for thread to return from wait is more than interrupt + // and also not less than the complete child thread wait time + + delta = ThreadWaitDelta - ChildThreadWaitTime; + if( (ThreadWaitDelta < ChildThreadWaitTime) && ( delta > TOLERANCE) ) + { + Fail("Expected thread to wait for %d ms (and not get interrupted).\n" + "Interrupt Time: %d ms, ThreadWaitDelta %u\n", + ChildThreadWaitTime, InterruptTime, ThreadWaitDelta); + } + + + PAL_Terminate(); + return PASS; +} + +void RunTest(BOOL AlertThread) +{ + HANDLE hThread = 0; + DWORD dwThreadId = 0; + int ret; + + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)WaiterProc, + (LPVOID) AlertThread, + 0, + &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: Was not able to create the thread to test!\n" + "GetLastError returned %d\n", GetLastError()); + } + + Sleep(InterruptTime); + + ret = QueueUserAPC(APCFunc, hThread, 0); + if (ret == 0) + { + Fail("QueueUserAPC failed! GetLastError returned %d\n", + GetLastError()); + } + + ret = WaitForSingleObject(hThread, INFINITE); + if (ret == WAIT_FAILED) + { + Fail("Unable to wait on child thread!\nGetLastError returned %d.\n", + GetLastError()); + } +} + +/* Function doesn't do anything, just needed to interrupt the wait*/ +VOID PALAPI APCFunc(ULONG_PTR dwParam) +{ +} + +/* Entry Point for child thread. */ +DWORD PALAPI WaiterProc(LPVOID lpParameter) +{ + HANDLE Semaphore; + UINT64 OldTimeStamp; + UINT64 NewTimeStamp; + BOOL Alertable; + DWORD ret; + + /* Create a semaphore that is not in the signalled state */ + Semaphore = CreateSemaphoreW(NULL, 0, 1, NULL); + + if (Semaphore == NULL) + { + Fail("Failed to create semaphore! GetLastError returned %d.\n", + GetLastError()); + } + + Alertable = (BOOL) lpParameter; + + LARGE_INTEGER performanceFrequency; + if (!QueryPerformanceFrequency(&performanceFrequency)) + { + Fail("Failed to query performance frequency!"); + } + + OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + ret = WaitForMultipleObjectsEx(1, &Semaphore, FALSE, ChildThreadWaitTime, + Alertable); + + NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + + if (Alertable && ret != WAIT_IO_COMPLETION) + { + Fail("Expected the interrupted wait to return WAIT_IO_COMPLETION.\n" + "Got %d\n", ret); + } + else if (!Alertable && ret != WAIT_TIMEOUT) + { + Fail("WaitForMultipleObjectsEx did not timeout.\n" + "Expected return of WAIT_TIMEOUT, got %d.\n", ret); + } + + ThreadWaitDelta = NewTimeStamp - OldTimeStamp; + + ret = CloseHandle(Semaphore); + if (!ret) + { + Fail("Unable to close handle to semaphore!\n" + "GetLastError returned %d\n", GetLastError()); + } + + return 0; +} + + diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/CMakeLists.txt index 645b86719d..f1b76fb819 100644 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test3.cpp ) add_executable(paltest_waitformultipleobjectsex_test3 diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/test3.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/test3.c deleted file mode 100644 index b78b0540dc..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/test3.c +++ /dev/null @@ -1,106 +0,0 @@ -// 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: test3.c -** -** Purpose: Tests that waiting on an open mutex will a return -** WAIT_OBJECT_0. Does this by creating a child thread that -** acquires the mutex, releases it, and exits. -** -** -**===================================================================*/ - -#include - - -const int ChildThreadWaitTime = 1000; -const int ParentDelayTime = 2000; - -DWORD PALAPI AcquiringProc(LPVOID lpParameter); - -int __cdecl main( int argc, char **argv) -{ - HANDLE Mutex; - HANDLE hThread = 0; - DWORD dwThreadId = 0; - int ret; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - Mutex = CreateMutexW(NULL, FALSE, NULL); - if (Mutex == NULL) - { - Fail("Unable to create the mutex. GetLastError returned %d\n", - GetLastError()); - } - - hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)AcquiringProc, - (LPVOID) Mutex, - 0, - &dwThreadId); - - if (hThread == NULL) - { - Fail("ERROR: Was not able to create the thread to test!\n" - "GetLastError returned %d\n", GetLastError()); - } - - Sleep(ParentDelayTime); - - ret = WaitForMultipleObjectsEx(1, &Mutex, FALSE, INFINITE, FALSE); - if (ret != WAIT_OBJECT_0) - { - Fail("Expected WaitForMultipleObjectsEx to return WAIT_OBJECT_0\n" - "Got %d\n", ret); - } - - if (!CloseHandle(Mutex)) - { - Fail("CloseHandle on the mutex failed!\n"); - } - - if (!CloseHandle(hThread)) - { - Fail("CloseHandle on the thread failed!\n"); - } - - PAL_Terminate(); - return PASS; -} - -/* - * Entry Point for child thread. Acquries a mutex, releases it, and exits. - */ -DWORD PALAPI AcquiringProc(LPVOID lpParameter) -{ - HANDLE Mutex; - DWORD ret; - - Mutex = (HANDLE) lpParameter; - - Sleep(ChildThreadWaitTime); - - ret = WaitForSingleObject(Mutex, 0); - if (ret != WAIT_OBJECT_0) - { - Fail("Expected the WaitForSingleObject call on the mutex to succeed\n" - "Expected return of WAIT_OBJECT_0, got %d\n", ret); - } - - ret = ReleaseMutex(Mutex); - if (!ret) - { - Fail("Unable to release mutex! GetLastError returned %d\n", - GetLastError()); - } - - return 0; -} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/test3.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/test3.cpp new file mode 100644 index 0000000000..b78b0540dc --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test3/test3.cpp @@ -0,0 +1,106 @@ +// 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: test3.c +** +** Purpose: Tests that waiting on an open mutex will a return +** WAIT_OBJECT_0. Does this by creating a child thread that +** acquires the mutex, releases it, and exits. +** +** +**===================================================================*/ + +#include + + +const int ChildThreadWaitTime = 1000; +const int ParentDelayTime = 2000; + +DWORD PALAPI AcquiringProc(LPVOID lpParameter); + +int __cdecl main( int argc, char **argv) +{ + HANDLE Mutex; + HANDLE hThread = 0; + DWORD dwThreadId = 0; + int ret; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + Mutex = CreateMutexW(NULL, FALSE, NULL); + if (Mutex == NULL) + { + Fail("Unable to create the mutex. GetLastError returned %d\n", + GetLastError()); + } + + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)AcquiringProc, + (LPVOID) Mutex, + 0, + &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: Was not able to create the thread to test!\n" + "GetLastError returned %d\n", GetLastError()); + } + + Sleep(ParentDelayTime); + + ret = WaitForMultipleObjectsEx(1, &Mutex, FALSE, INFINITE, FALSE); + if (ret != WAIT_OBJECT_0) + { + Fail("Expected WaitForMultipleObjectsEx to return WAIT_OBJECT_0\n" + "Got %d\n", ret); + } + + if (!CloseHandle(Mutex)) + { + Fail("CloseHandle on the mutex failed!\n"); + } + + if (!CloseHandle(hThread)) + { + Fail("CloseHandle on the thread failed!\n"); + } + + PAL_Terminate(); + return PASS; +} + +/* + * Entry Point for child thread. Acquries a mutex, releases it, and exits. + */ +DWORD PALAPI AcquiringProc(LPVOID lpParameter) +{ + HANDLE Mutex; + DWORD ret; + + Mutex = (HANDLE) lpParameter; + + Sleep(ChildThreadWaitTime); + + ret = WaitForSingleObject(Mutex, 0); + if (ret != WAIT_OBJECT_0) + { + Fail("Expected the WaitForSingleObject call on the mutex to succeed\n" + "Expected return of WAIT_OBJECT_0, got %d\n", ret); + } + + ret = ReleaseMutex(Mutex); + if (!ret) + { + Fail("Unable to release mutex! GetLastError returned %d\n", + GetLastError()); + } + + return 0; +} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/CMakeLists.txt index 3cd7f72b98..815b2b069c 100644 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test4.c + test4.cpp ) add_executable(paltest_waitformultipleobjectsex_test4 diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c deleted file mode 100644 index 15d0a386d1..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c +++ /dev/null @@ -1,101 +0,0 @@ -// 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: test4.c -** -** Purpose: Tests that waiting on an abandonded mutex will a return -** WAIT_ABANDONED_0. Does this by creating a child thread that -** acquires the mutex and exits. -** -** -**===================================================================*/ - -#include - - -const int ChildThreadWaitTime = 1000; -const int ParentDelayTime = 2000; - -DWORD PALAPI AbandoningProc(LPVOID lpParameter); - -int __cdecl main( int argc, char **argv ) -{ - HANDLE Mutex; - HANDLE hThread = 0; - DWORD dwThreadId = 0; - int ret; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - Mutex = CreateMutexW(NULL, FALSE, NULL); - if (Mutex == NULL) - { - Fail("Unable to create the mutex. GetLastError returned %d\n", - GetLastError()); - } - - hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)AbandoningProc, - (LPVOID) Mutex, - 0, - &dwThreadId); - - if (hThread == NULL) - { - Fail("ERROR: Was not able to create the thread to test!\n" - "GetLastError returned %d\n", GetLastError()); - } - - Sleep(ParentDelayTime); - - ret = WaitForMultipleObjectsEx(1, &Mutex, FALSE, INFINITE, FALSE); - if (ret != WAIT_ABANDONED_0) - { - Fail("Expected WaitForMultipleObjectsEx to return WAIT_ABANDONED_0\n" - "Got %d\n", ret); - } - - ReleaseMutex(Mutex); - if (!CloseHandle(Mutex)) - { - Fail("CloseHandle on the mutex failed!\n"); - } - - if (!CloseHandle(hThread)) - { - Fail("CloseHandle on the thread failed!\n"); - } - - PAL_Terminate(); - return PASS; -} - -/* - * Entry Point for child thread. Acquries a mutex and exit's without - * releasing it. - */ -DWORD PALAPI AbandoningProc(LPVOID lpParameter) -{ - HANDLE Mutex; - DWORD ret; - - Mutex = (HANDLE) lpParameter; - - Sleep(ChildThreadWaitTime); - - ret = WaitForSingleObject(Mutex, 0); - if (ret != WAIT_OBJECT_0) - { - Fail("Expected the WaitForSingleObject call on the mutex to succeed\n" - "Expected return of WAIT_OBJECT_0, got %d\n", ret); - } - - return 0; -} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.cpp new file mode 100644 index 0000000000..15d0a386d1 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.cpp @@ -0,0 +1,101 @@ +// 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: test4.c +** +** Purpose: Tests that waiting on an abandonded mutex will a return +** WAIT_ABANDONED_0. Does this by creating a child thread that +** acquires the mutex and exits. +** +** +**===================================================================*/ + +#include + + +const int ChildThreadWaitTime = 1000; +const int ParentDelayTime = 2000; + +DWORD PALAPI AbandoningProc(LPVOID lpParameter); + +int __cdecl main( int argc, char **argv ) +{ + HANDLE Mutex; + HANDLE hThread = 0; + DWORD dwThreadId = 0; + int ret; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + Mutex = CreateMutexW(NULL, FALSE, NULL); + if (Mutex == NULL) + { + Fail("Unable to create the mutex. GetLastError returned %d\n", + GetLastError()); + } + + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)AbandoningProc, + (LPVOID) Mutex, + 0, + &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: Was not able to create the thread to test!\n" + "GetLastError returned %d\n", GetLastError()); + } + + Sleep(ParentDelayTime); + + ret = WaitForMultipleObjectsEx(1, &Mutex, FALSE, INFINITE, FALSE); + if (ret != WAIT_ABANDONED_0) + { + Fail("Expected WaitForMultipleObjectsEx to return WAIT_ABANDONED_0\n" + "Got %d\n", ret); + } + + ReleaseMutex(Mutex); + if (!CloseHandle(Mutex)) + { + Fail("CloseHandle on the mutex failed!\n"); + } + + if (!CloseHandle(hThread)) + { + Fail("CloseHandle on the thread failed!\n"); + } + + PAL_Terminate(); + return PASS; +} + +/* + * Entry Point for child thread. Acquries a mutex and exit's without + * releasing it. + */ +DWORD PALAPI AbandoningProc(LPVOID lpParameter) +{ + HANDLE Mutex; + DWORD ret; + + Mutex = (HANDLE) lpParameter; + + Sleep(ChildThreadWaitTime); + + ret = WaitForSingleObject(Mutex, 0); + if (ret != WAIT_OBJECT_0) + { + Fail("Expected the WaitForSingleObject call on the mutex to succeed\n" + "Expected return of WAIT_OBJECT_0, got %d\n", ret); + } + + return 0; +} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/CMakeLists.txt index 50147e9bf3..730ec60649 100644 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test5.c + test5.cpp ) add_executable(paltest_waitformultipleobjectsex_test5 @@ -20,7 +20,7 @@ target_link_libraries(paltest_waitformultipleobjectsex_test5 set(HELPERSOURCES - helper.c + helper.cpp ) add_executable(paltest_waitformultipleobjectsex_test5_helper diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/helper.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/helper.c deleted file mode 100644 index 274780a216..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/helper.c +++ /dev/null @@ -1,122 +0,0 @@ -// 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: helper.c -** -** Purpose: This helper process sets up signals to communicate -** with the test thread in the parent process, and let the test -** thread signal this process when to exit. -** -** -**============================================================*/ - -#include "commonconsts.h" - -#include - -HANDLE hProcessStartEvent; -HANDLE hProcessReadyEvent; -HANDLE hProcessFinishEvent; -HANDLE hProcessCleanupEvent; - - -int __cdecl main(int argc, char *argv[]) -{ - - BOOL success = TRUE; /* assume success */ - DWORD dwRet; - DWORD dwProcessId; - char szEventName[MAX_LONGPATH]; - PWCHAR uniString; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* Open the event to let test thread tell us to get started. */ - uniString = convert(szcHelperProcessStartEvName); - hProcessStartEvent = OpenEventW(EVENT_ALL_ACCESS, 0, uniString); - free(uniString); - if (!hProcessStartEvent) - { - Fail("helper.main: OpenEvent of '%S' failed (%u). " - "(the event should already exist!)\n", - szcHelperProcessStartEvName, GetLastError()); - } - - /* Wait for signal from test thread. */ - dwRet = WaitForSingleObject(hProcessStartEvent, TIMEOUT); - if (dwRet != WAIT_OBJECT_0) - { - Fail("helper.main: WaitForSingleObject '%s' failed\n" - "LastError:(%u)\n", szcHelperProcessStartEvName, GetLastError()); - } - - dwProcessId = GetCurrentProcessId(); - - if ( 0 >= dwProcessId ) - { - Fail ("helper.main: %s has invalid pid %d\n", argv[0], dwProcessId ); - } - - /* Open the event to tell test thread we are ready. */ - if (_snprintf(szEventName, MAX_LONGPATH-1, "%s%d", szcHelperProcessReadyEvName, dwProcessId) < 0) - { - Fail ("helper.main: Insufficient event name string length for pid=%d\n", dwProcessId); - } - - uniString = convert(szEventName); - - hProcessReadyEvent = OpenEventW(EVENT_ALL_ACCESS, 0, uniString); - free(uniString); - if (!hProcessReadyEvent) - { - Fail("helper.main: OpenEvent of '%s' failed (%u). " - "(the event should already exist!)\n", - szEventName, GetLastError()); - } - - /* Open the event to let test thread tell us to exit. */ - if (_snprintf(szEventName, MAX_LONGPATH-1, "%s%d", szcHelperProcessFinishEvName, dwProcessId) < 0) - { - Fail ("helper.main: Insufficient event name string length for pid=%d\n", dwProcessId); - } - - uniString = convert(szEventName); - - hProcessFinishEvent = OpenEventW(EVENT_ALL_ACCESS, 0, uniString); - free(uniString); - if (!hProcessFinishEvent) - { - Fail("helper.main: OpenEvent of '%s' failed LastError:(%u).\n", - szEventName, GetLastError()); - } - - /* Tell the test thread we are ready. */ - if (!SetEvent(hProcessReadyEvent)) - { - Fail("helper.main: SetEvent '%s' failed LastError:(%u)\n", - hProcessReadyEvent, GetLastError()); - } - - /* Wait for signal from test thread before exit. */ - dwRet = WaitForSingleObject(hProcessFinishEvent, TIMEOUT); - if (WAIT_OBJECT_0 != dwRet) - { - Fail("helper.main: WaitForSingleObject '%s' failed pid=%d\n" - "LastError:(%u)\n", - szcHelperProcessFinishEvName, dwProcessId, GetLastError()); - } - - PEDANTIC(CloseHandle, (hProcessStartEvent)); - PEDANTIC(CloseHandle, (hProcessReadyEvent)); - PEDANTIC(CloseHandle, (hProcessFinishEvent)); - - PAL_Terminate(); - - return success ? PASS : FAIL; -} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/helper.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/helper.cpp new file mode 100644 index 0000000000..caa0206a11 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/helper.cpp @@ -0,0 +1,122 @@ +// 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: helper.c +** +** Purpose: This helper process sets up signals to communicate +** with the test thread in the parent process, and let the test +** thread signal this process when to exit. +** +** +**============================================================*/ + +#include "commonconsts.h" + +#include + +HANDLE hProcessStartEvent; +HANDLE hProcessReadyEvent; +HANDLE hProcessFinishEvent; +HANDLE hProcessCleanupEvent; + + +int __cdecl main(int argc, char *argv[]) +{ + + BOOL success = TRUE; /* assume success */ + DWORD dwRet; + DWORD dwProcessId; + char szEventName[MAX_LONGPATH]; + PWCHAR uniString; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Open the event to let test thread tell us to get started. */ + uniString = convert(szcHelperProcessStartEvName); + hProcessStartEvent = OpenEventW(EVENT_ALL_ACCESS, 0, uniString); + free(uniString); + if (!hProcessStartEvent) + { + Fail("helper.main: OpenEvent of '%S' failed (%u). " + "(the event should already exist!)\n", + szcHelperProcessStartEvName, GetLastError()); + } + + /* Wait for signal from test thread. */ + dwRet = WaitForSingleObject(hProcessStartEvent, TIMEOUT); + if (dwRet != WAIT_OBJECT_0) + { + Fail("helper.main: WaitForSingleObject '%s' failed\n" + "LastError:(%u)\n", szcHelperProcessStartEvName, GetLastError()); + } + + dwProcessId = GetCurrentProcessId(); + + if ( 0 >= dwProcessId ) + { + Fail ("helper.main: %s has invalid pid %d\n", argv[0], dwProcessId ); + } + + /* Open the event to tell test thread we are ready. */ + if (sprintf_s(szEventName, MAX_LONGPATH-1, "%s%d", szcHelperProcessReadyEvName, dwProcessId) < 0) + { + Fail ("helper.main: Insufficient event name string length for pid=%d\n", dwProcessId); + } + + uniString = convert(szEventName); + + hProcessReadyEvent = OpenEventW(EVENT_ALL_ACCESS, 0, uniString); + free(uniString); + if (!hProcessReadyEvent) + { + Fail("helper.main: OpenEvent of '%s' failed (%u). " + "(the event should already exist!)\n", + szEventName, GetLastError()); + } + + /* Open the event to let test thread tell us to exit. */ + if (sprintf_s(szEventName, MAX_LONGPATH-1, "%s%d", szcHelperProcessFinishEvName, dwProcessId) < 0) + { + Fail ("helper.main: Insufficient event name string length for pid=%d\n", dwProcessId); + } + + uniString = convert(szEventName); + + hProcessFinishEvent = OpenEventW(EVENT_ALL_ACCESS, 0, uniString); + free(uniString); + if (!hProcessFinishEvent) + { + Fail("helper.main: OpenEvent of '%s' failed LastError:(%u).\n", + szEventName, GetLastError()); + } + + /* Tell the test thread we are ready. */ + if (!SetEvent(hProcessReadyEvent)) + { + Fail("helper.main: SetEvent '%s' failed LastError:(%u)\n", + hProcessReadyEvent, GetLastError()); + } + + /* Wait for signal from test thread before exit. */ + dwRet = WaitForSingleObject(hProcessFinishEvent, TIMEOUT); + if (WAIT_OBJECT_0 != dwRet) + { + Fail("helper.main: WaitForSingleObject '%s' failed pid=%d\n" + "LastError:(%u)\n", + szcHelperProcessFinishEvName, dwProcessId, GetLastError()); + } + + PEDANTIC(CloseHandle, (hProcessStartEvent)); + PEDANTIC(CloseHandle, (hProcessReadyEvent)); + PEDANTIC(CloseHandle, (hProcessFinishEvent)); + + PAL_Terminate(); + + return success ? PASS : FAIL; +} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.c deleted file mode 100644 index d19978c103..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.c +++ /dev/null @@ -1,506 +0,0 @@ -// 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: test5.c -** -** Purpose: Test the functionality of simultaneously waiting -** on multiple processes. Create the same number of helper -** processes and helper threads. -** Helper threads wait on helper processes to finish. -** Helper processes wait on the event signal from test -** thread before exit. -** The test thread can wake up one helper -** thread at a time by signaling the corresponding helper -** process to finish. -** The test thread can also wake up all helper threads at once -** by signaling help process 0 to exit. -** -** -**============================================================*/ - -#define UNICODE - -#include "commonconsts.h" - -#include - -/* The maximum number of objects a thread can wait is MAXIMUM_WAIT_OBJECTS. - The last helper thread in this test case will wait on all helper processes - plus a thread finish event so the maximum number of helper processes - can be created in this test case is (MAXIMUM_WAIT_OBJECTS-1). */ -#define MAX_HELPER_PROCESS (MAXIMUM_WAIT_OBJECTS-1) - -int MaxNumHelperProcess = MAX_HELPER_PROCESS; - -/* indicate how the test thread wake up helper thread. */ -typedef enum _TestCaseType { - WakeUpOneThread, /* wake up one helper thread at a time. */ - WakeUpAllThread /* wake up all helper threads at once */ -} TestCaseType; - -TestCaseType TestCase = WakeUpOneThread; - -/* When the test thread wakes up one thread at a time, - ThreadIndexOfThreadFinishEvent specifies the index of the thread that - should be waked up using hThreadFinishEvent instead of helper process. */ -DWORD ThreadIndexOfThreadFinishEvent = 0; - -struct helper_process_t -{ - PROCESS_INFORMATION pi; - HANDLE hProcessReadyEvent; - HANDLE hProcessFinishEvent; -} helper_process[MAX_HELPER_PROCESS]; - -HANDLE hProcessStartEvent; - -struct helper_thread_t -{ - HANDLE hThread; - DWORD dwThreadId; - HANDLE hThreadReadyEvent; - HANDLE hThreadFinishEvent; -} helper_thread[MAX_HELPER_PROCESS]; - -/* - * Entry Point for helper thread. - */ -DWORD PALAPI WaitForProcess(LPVOID lpParameter) -{ - DWORD index, i; - DWORD dwRet; - HANDLE handles[MAX_HELPER_PROCESS+1]; - - index = (DWORD) lpParameter; - - /* The helper thread 0 will wait for helper process 0, helper thread 1 will - wait for helper process 0 and 1, helper thread 2 will wait for helper - process 0, 1, and 2, and so on ..., and the last helper thread will wait - on all helper processes. - Each helper thread also waits on hThreadFinishEvent so that - it can exit without waiting on any process to finish. */ - - for (i = 0; i <= index; i++) - { - handles[i] = helper_process[i].pi.hProcess; - } - - handles[index+1] = helper_thread[index].hThreadFinishEvent; - - if(!SetEvent(helper_thread[index].hThreadReadyEvent)) - { - Fail("test5.WaitProcess: SetEvent of hThreadReadyEvent failed for thread %d. " - "GetLastError() returned %d.\n", index, - GetLastError()); - } - - dwRet = WaitForMultipleObjectsEx(index+2, &handles[0], FALSE, TIMEOUT, TRUE); - if (WakeUpAllThread == TestCase) - { - /* If the test thread signals helper process 0 to exit, all threads will be waked up, - and the return value must be (WAIT_OBJECT_0+0) because the handle of helper process 0 - is in handle[0]. */ - if (dwRet != (WAIT_OBJECT_0+0)) - { - Fail("test5.WaitForProcess: invalid return value %d for WakupAllThread from WaitForMultipleObjectsEx for thread %d\n" - "LastError:(%u)\n", - dwRet, index, - GetLastError()); - } - } - else if (WakeUpOneThread == TestCase) - { - /* If the test thread wakes up one helper thread at a time, - the return value must be either (WAIT_OBJECT_0+index) if the helper thread - wakes up because the corresponding help process exits, - or (index+1) if the helper thread wakes up because of hThreadReadyEvent. */ - if ((index != ThreadIndexOfThreadFinishEvent && dwRet != (WAIT_OBJECT_0+index)) || - (index == ThreadIndexOfThreadFinishEvent && dwRet != (index+1))) - { - Fail("test5.WaitForProcess: invalid return value %d for WakupOneThread from WaitForMultipleObjectsEx for thread %d\n" - "LastError:(%u)\n", - dwRet, index, - GetLastError()); - } - } - else - { - Fail("Unknown TestCase %d\n", TestCase); - } - return 0; -} - -/* - * Setup the helper processes and helper threads. - */ -void -Setup() -{ - - STARTUPINFO si; - DWORD dwRet; - int i; - - char szEventName[MAX_PATH]; - PWCHAR uniStringHelper; - PWCHAR uniString; - - /* Create the event to start helper process after it was created. */ - uniString = convert(szcHelperProcessStartEvName); - hProcessStartEvent = CreateEvent(NULL, TRUE, FALSE, uniString); - free(uniString); - if (!hProcessStartEvent) - { - Fail("test5.Setup: CreateEvent of '%s' failed. " - "GetLastError() returned %d.\n", szcHelperProcessStartEvName, - GetLastError()); - } - - /* Create the helper processes. */ - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - uniStringHelper = convert("helper"); - for (i = 0; i < MaxNumHelperProcess; i++) - { - ZeroMemory( &helper_process[i].pi, sizeof(PROCESS_INFORMATION)); - - if(!CreateProcess( NULL, uniStringHelper, NULL, NULL, - FALSE, 0, NULL, NULL, &si, &helper_process[i].pi)) - { - Fail("test5.Setup: CreateProcess failed to load executable for helper process %d. " - "GetLastError() returned %u.\n", - i, GetLastError()); - } - - /* Create the event to let helper process tell us it is ready. */ - if (_snprintf(szEventName, MAX_PATH-1, "%s%d", - szcHelperProcessReadyEvName, helper_process[i].pi.dwProcessId) < 0) - { - Fail ("test5.Setup: Insufficient event name string length for %s\n", szcHelperProcessReadyEvName); - } - - uniString = convert(szEventName); - - helper_process[i].hProcessReadyEvent = CreateEvent(NULL, FALSE, FALSE, uniString); - free(uniString); - if (!helper_process[i].hProcessReadyEvent) - { - Fail("test5.Setup: CreateEvent of '%s' failed. " - "GetLastError() returned %d.\n", szEventName, - GetLastError()); - } - - /* Create the event to tell helper process to exit. */ - if (_snprintf(szEventName, MAX_PATH-1, "%s%d", - szcHelperProcessFinishEvName, helper_process[i].pi.dwProcessId) < 0) - { - Fail ("test5.Setup: Insufficient event name string length for %s\n", szcHelperProcessFinishEvName); - } - - uniString = convert(szEventName); - - helper_process[i].hProcessFinishEvent = CreateEvent(NULL, TRUE, FALSE, uniString); - free(uniString); - if (!helper_process[i].hProcessFinishEvent) - { - Fail("test5.Setup: CreateEvent of '%s' failed. " - "GetLastError() returned %d.\n", szEventName, - GetLastError()); - } - - } - free(uniStringHelper); - - /* Signal all helper processes to start. */ - if (!SetEvent(hProcessStartEvent)) - { - Fail("test5.Setup: SetEvent '%s' failed\n", - "LastError:(%u)\n", - szcHelperProcessStartEvName, GetLastError()); - } - - /* Wait for ready signals from all helper processes. */ - for (i = 0; i < MaxNumHelperProcess; i++) - { - dwRet = WaitForSingleObject(helper_process[i].hProcessReadyEvent, TIMEOUT); - if (dwRet != WAIT_OBJECT_0) - { - Fail("test5.Setup: WaitForSingleObject %s failed for helper process %d\n" - "LastError:(%u)\n", - szcHelperProcessReadyEvName, i, GetLastError()); - } - } - - /* Create the same number of helper threads as helper processes. */ - for (i = 0; i < MaxNumHelperProcess; i++) - { - /* Create the event to let helper thread tell us it is ready. */ - helper_thread[i].hThreadReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - if (!helper_thread[i].hThreadReadyEvent) - { - Fail("test5.Setup: CreateEvent of hThreadReadyEvent failed for thread %d\n" - "LastError:(%u)\n", i, GetLastError()); - } - - /* Create the event to tell helper thread to exit without waiting for helper process. */ - helper_thread[i].hThreadFinishEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - if (!helper_thread[i].hThreadFinishEvent) - { - Fail("test5.Setup: CreateEvent of hThreadFinishEvent failed for thread %d\n" - "LastError:(%u)\n", i, GetLastError()); - } - - /* Create the helper thread. */ - helper_thread[i].hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)WaitForProcess, - (LPVOID)i, - 0, - &helper_thread[i].dwThreadId); - if (NULL == helper_thread[i].hThread) - { - Fail("test5.Setup: Unable to create the helper thread %d\n" - "LastError:(%u)\n", i, GetLastError()); - } - } - - /* Wait for ready signals from all helper threads. */ - for (i = 0; i < MaxNumHelperProcess; i++) - { - dwRet = WaitForSingleObject(helper_thread[i].hThreadReadyEvent, TIMEOUT); - if (dwRet != WAIT_OBJECT_0) - { - Fail("test5.Setup: WaitForSingleObject hThreadReadyEvent for thread %d\n" - "LastError:(%u)\n", i, GetLastError()); - } - } -} - -/* - * Cleanup the helper processes and helper threads. - */ -DWORD -Cleanup() -{ - DWORD dwExitCode; - DWORD dwRet; - int i; - - /* Wait for all helper process to finish and close their handles - and associated events. */ - for (i = 0; i < MaxNumHelperProcess; i++) - { - - /* wait for the child process to complete */ - dwRet = WaitForSingleObject ( helper_process[i].pi.hProcess, TIMEOUT ); - if (WAIT_OBJECT_0 != dwRet) - { - Fail("test5.Cleanup: WaitForSingleObject hThreadReadyEvent failed for thread %d\n" - "LastError:(%u)\n", i, GetLastError()); - } - - /* check the exit code from the process */ - if (!GetExitCodeProcess(helper_process[i].pi.hProcess, &dwExitCode)) - { - Trace( "test5.Cleanup: GetExitCodeProcess %d call failed LastError:(%u)\n", - i, GetLastError()); - dwExitCode = FAIL; - } - PEDANTIC(CloseHandle, (helper_process[i].pi.hThread)); - PEDANTIC(CloseHandle, (helper_process[i].pi.hProcess)); - PEDANTIC(CloseHandle, (helper_process[i].hProcessReadyEvent)); - PEDANTIC(CloseHandle, (helper_process[i].hProcessFinishEvent)); - } - - /* Close all helper threads' handles */ - for (i = 0; i < MaxNumHelperProcess; i++) - { - PEDANTIC(CloseHandle, (helper_thread[i].hThread)); - PEDANTIC(CloseHandle, (helper_thread[i].hThreadReadyEvent)); - PEDANTIC(CloseHandle, (helper_thread[i].hThreadFinishEvent)); - } - - /* Close all process start event. */ - PEDANTIC(CloseHandle, (hProcessStartEvent)); - - return dwExitCode; -} - -/* - * In this test case, the test thread will signal one helper - * process to exit at a time starting from the last helper - * process and then wait for the corresponding helper thread to exit. - * The ThreadIndexOfThreadFinishEvent specifies the index of the thread that - * should be waked up using hThreadFinishEvent instead of helper process. - */ -void -TestWakeupOneThread() -{ - DWORD dwRet; - int i; - - TestCase = WakeUpOneThread; - - if (((LONG)ThreadIndexOfThreadFinishEvent) < 0 || - ThreadIndexOfThreadFinishEvent >= MAX_HELPER_PROCESS) - Fail("test5.TestWaitOnOneThread: Invalid ThreadIndexOfThreadFinishEvent %d\n", ThreadIndexOfThreadFinishEvent); - - /* Since helper thread 0 waits on helper process 0, - thread 1 waits on on process 0, and 1, - thread 2 waits on process 0, 1, and 2, and so on ..., - and the last helper thread will wait on all helper processes, - the helper thread can be waked up one at a time by - waking up the help process one at a time starting from the - last helper process. */ - for (i = MaxNumHelperProcess-1; i >= 0; i--) - { - /* make sure the helper thread has not exited yet. */ - dwRet = WaitForSingleObject(helper_thread[i].hThread, 0); - if (WAIT_TIMEOUT != dwRet) - { - Fail("test5.TestWaitOnOneThread: helper thread %d already exited %d\n", i); - } - - /* Decide how to wakeup the helper thread: - using event or using helper process. */ - if (i == ThreadIndexOfThreadFinishEvent) - { - if (!SetEvent(helper_thread[i].hThreadFinishEvent)) - { - Fail("test5.TestWaitOnOneThread: SetEvent hThreadFinishEvent failed for thread %d\n", - "LastError:(%u)\n", i, GetLastError()); - } - } - else - { - if (!SetEvent(helper_process[i].hProcessFinishEvent)) - { - Fail("test5.TestWaitOnOneThread: SetEvent %s%d failed for helper process %d\n", - "LastError:(%u)\n", - szcHelperProcessFinishEvName, helper_process[i].pi.dwProcessId, i, - GetLastError()); - } - } - - dwRet = WaitForSingleObject(helper_thread[i].hThread, TIMEOUT); - if (WAIT_OBJECT_0 != dwRet) - { - Fail("test5.TestWaitOnOneThread: WaitForSingleObject helper thread %d" - "LastError:(%u)\n", - i, GetLastError()); - } - } - - /* Finally, need to wake up the helper process which the test thread - skips waking up in the last loop. */ - if (!SetEvent(helper_process[ThreadIndexOfThreadFinishEvent].hProcessFinishEvent)) - { - Fail("test5.TestWaitOnOneThread: SetEvent %s%d failed\n", - "LastError:(%u)\n", - szcHelperProcessFinishEvName, helper_process[ThreadIndexOfThreadFinishEvent].pi.dwProcessId, - GetLastError()); - } -} - -/* - * In this test case, the test thread will signal the helper - * process 0 to exit. Since all helper threads wait on process 0, - * all helper threads will wake up and exit, and the test thread - * will wait for all of them to exit. - */ -void -TestWakeupAllThread() -{ - DWORD dwRet; - int i; - - TestCase = WakeUpAllThread; - - /* make sure none of the helper thread exits. */ - for (i = 0; i < MaxNumHelperProcess; i++) - { - dwRet = WaitForSingleObject(helper_thread[i].hThread, 0); - if (WAIT_TIMEOUT != dwRet) - { - Fail("test5.TestWaitOnAllThread: helper thread %d already exited %d\n", i); - } - } - - /* Signal helper process 0 to exit. */ - if (!SetEvent(helper_process[0].hProcessFinishEvent)) - { - Fail("test5.TestWaitOnAllThread: SetEvent %s%d failed\n", - "LastError:(%u)\n", - szcHelperProcessFinishEvName, helper_process[0].pi.dwProcessId, - GetLastError()); - } - - /* Wait for all helper threads to exit. */ - for (i = 0; i < MaxNumHelperProcess; i++) - { - - dwRet = WaitForSingleObject(helper_thread[i].hThread, TIMEOUT); - if (WAIT_OBJECT_0 != dwRet) - { - Fail("test5.TestWaitOnAllThread: WaitForSingleObject failed for helper thread %d\n" - "LastError:(%u)\n", - i, GetLastError()); - } - } - - /* Signal the rest of helper processes to exit. */ - for (i = 1; i < MaxNumHelperProcess; i++) - { - if (!SetEvent(helper_process[i].hProcessFinishEvent)) - { - Fail("test5.TestWaitOnAllThread: SetEvent %s%d failed\n", - "LastError:(%u)\n", - szcHelperProcessFinishEvName, helper_process[i].pi.dwProcessId, - GetLastError()); - } - } -} - -int __cdecl main(int argc, char *argv[]) -{ - DWORD dwExitCode; - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - switch (argc) - { - case 1: - MaxNumHelperProcess = MAX_HELPER_PROCESS; - break; - case 2: - MaxNumHelperProcess = atol(argv[1]); - break; - default: - Fail("Invalid number of arguments\n"); - } - - if (MaxNumHelperProcess < 1 || - MaxNumHelperProcess > MAX_HELPER_PROCESS) - Fail("test5.main: Invalid MaxNumHelperProcess %d\n", MaxNumHelperProcess); - - Setup(); - ThreadIndexOfThreadFinishEvent = 3; - TestWakeupOneThread(); - dwExitCode = Cleanup(); - - if (PASS == dwExitCode) - { - Setup(); - TestWakeupAllThread(); - dwExitCode = Cleanup(); - } - - PAL_TerminateEx(dwExitCode); - return dwExitCode; -} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.cpp new file mode 100644 index 0000000000..a0216494ba --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.cpp @@ -0,0 +1,506 @@ +// 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: test5.c +** +** Purpose: Test the functionality of simultaneously waiting +** on multiple processes. Create the same number of helper +** processes and helper threads. +** Helper threads wait on helper processes to finish. +** Helper processes wait on the event signal from test +** thread before exit. +** The test thread can wake up one helper +** thread at a time by signaling the corresponding helper +** process to finish. +** The test thread can also wake up all helper threads at once +** by signaling help process 0 to exit. +** +** +**============================================================*/ + +#define UNICODE + +#include "commonconsts.h" + +#include + +/* The maximum number of objects a thread can wait is MAXIMUM_WAIT_OBJECTS. + The last helper thread in this test case will wait on all helper processes + plus a thread finish event so the maximum number of helper processes + can be created in this test case is (MAXIMUM_WAIT_OBJECTS-1). */ +#define MAX_HELPER_PROCESS (MAXIMUM_WAIT_OBJECTS-1) + +int MaxNumHelperProcess = MAX_HELPER_PROCESS; + +/* indicate how the test thread wake up helper thread. */ +typedef enum _TestCaseType { + WakeUpOneThread, /* wake up one helper thread at a time. */ + WakeUpAllThread /* wake up all helper threads at once */ +} TestCaseType; + +TestCaseType TestCase = WakeUpOneThread; + +/* When the test thread wakes up one thread at a time, + ThreadIndexOfThreadFinishEvent specifies the index of the thread that + should be waked up using hThreadFinishEvent instead of helper process. */ +DWORD ThreadIndexOfThreadFinishEvent = 0; + +struct helper_process_t +{ + PROCESS_INFORMATION pi; + HANDLE hProcessReadyEvent; + HANDLE hProcessFinishEvent; +} helper_process[MAX_HELPER_PROCESS]; + +HANDLE hProcessStartEvent; + +struct helper_thread_t +{ + HANDLE hThread; + DWORD dwThreadId; + HANDLE hThreadReadyEvent; + HANDLE hThreadFinishEvent; +} helper_thread[MAX_HELPER_PROCESS]; + +/* + * Entry Point for helper thread. + */ +DWORD PALAPI WaitForProcess(LPVOID lpParameter) +{ + DWORD index, i; + DWORD dwRet; + HANDLE handles[MAX_HELPER_PROCESS+1]; + + index = (DWORD) lpParameter; + + /* The helper thread 0 will wait for helper process 0, helper thread 1 will + wait for helper process 0 and 1, helper thread 2 will wait for helper + process 0, 1, and 2, and so on ..., and the last helper thread will wait + on all helper processes. + Each helper thread also waits on hThreadFinishEvent so that + it can exit without waiting on any process to finish. */ + + for (i = 0; i <= index; i++) + { + handles[i] = helper_process[i].pi.hProcess; + } + + handles[index+1] = helper_thread[index].hThreadFinishEvent; + + if(!SetEvent(helper_thread[index].hThreadReadyEvent)) + { + Fail("test5.WaitProcess: SetEvent of hThreadReadyEvent failed for thread %d. " + "GetLastError() returned %d.\n", index, + GetLastError()); + } + + dwRet = WaitForMultipleObjectsEx(index+2, &handles[0], FALSE, TIMEOUT, TRUE); + if (WakeUpAllThread == TestCase) + { + /* If the test thread signals helper process 0 to exit, all threads will be waked up, + and the return value must be (WAIT_OBJECT_0+0) because the handle of helper process 0 + is in handle[0]. */ + if (dwRet != (WAIT_OBJECT_0+0)) + { + Fail("test5.WaitForProcess: invalid return value %d for WakupAllThread from WaitForMultipleObjectsEx for thread %d\n" + "LastError:(%u)\n", + dwRet, index, + GetLastError()); + } + } + else if (WakeUpOneThread == TestCase) + { + /* If the test thread wakes up one helper thread at a time, + the return value must be either (WAIT_OBJECT_0+index) if the helper thread + wakes up because the corresponding help process exits, + or (index+1) if the helper thread wakes up because of hThreadReadyEvent. */ + if ((index != ThreadIndexOfThreadFinishEvent && dwRet != (WAIT_OBJECT_0+index)) || + (index == ThreadIndexOfThreadFinishEvent && dwRet != (index+1))) + { + Fail("test5.WaitForProcess: invalid return value %d for WakupOneThread from WaitForMultipleObjectsEx for thread %d\n" + "LastError:(%u)\n", + dwRet, index, + GetLastError()); + } + } + else + { + Fail("Unknown TestCase %d\n", TestCase); + } + return 0; +} + +/* + * Setup the helper processes and helper threads. + */ +void +Setup() +{ + + STARTUPINFO si; + DWORD dwRet; + int i; + + char szEventName[MAX_PATH]; + PWCHAR uniStringHelper; + PWCHAR uniString; + + /* Create the event to start helper process after it was created. */ + uniString = convert(szcHelperProcessStartEvName); + hProcessStartEvent = CreateEvent(NULL, TRUE, FALSE, uniString); + free(uniString); + if (!hProcessStartEvent) + { + Fail("test5.Setup: CreateEvent of '%s' failed. " + "GetLastError() returned %d.\n", szcHelperProcessStartEvName, + GetLastError()); + } + + /* Create the helper processes. */ + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + uniStringHelper = convert("helper"); + for (i = 0; i < MaxNumHelperProcess; i++) + { + ZeroMemory( &helper_process[i].pi, sizeof(PROCESS_INFORMATION)); + + if(!CreateProcess( NULL, uniStringHelper, NULL, NULL, + FALSE, 0, NULL, NULL, &si, &helper_process[i].pi)) + { + Fail("test5.Setup: CreateProcess failed to load executable for helper process %d. " + "GetLastError() returned %u.\n", + i, GetLastError()); + } + + /* Create the event to let helper process tell us it is ready. */ + if (sprintf_s(szEventName, MAX_PATH-1, "%s%d", + szcHelperProcessReadyEvName, helper_process[i].pi.dwProcessId) < 0) + { + Fail ("test5.Setup: Insufficient event name string length for %s\n", szcHelperProcessReadyEvName); + } + + uniString = convert(szEventName); + + helper_process[i].hProcessReadyEvent = CreateEvent(NULL, FALSE, FALSE, uniString); + free(uniString); + if (!helper_process[i].hProcessReadyEvent) + { + Fail("test5.Setup: CreateEvent of '%s' failed. " + "GetLastError() returned %d.\n", szEventName, + GetLastError()); + } + + /* Create the event to tell helper process to exit. */ + if (sprintf_s(szEventName, MAX_PATH-1, "%s%d", + szcHelperProcessFinishEvName, helper_process[i].pi.dwProcessId) < 0) + { + Fail ("test5.Setup: Insufficient event name string length for %s\n", szcHelperProcessFinishEvName); + } + + uniString = convert(szEventName); + + helper_process[i].hProcessFinishEvent = CreateEvent(NULL, TRUE, FALSE, uniString); + free(uniString); + if (!helper_process[i].hProcessFinishEvent) + { + Fail("test5.Setup: CreateEvent of '%s' failed. " + "GetLastError() returned %d.\n", szEventName, + GetLastError()); + } + + } + free(uniStringHelper); + + /* Signal all helper processes to start. */ + if (!SetEvent(hProcessStartEvent)) + { + Fail("test5.Setup: SetEvent '%s' failed\n", + "LastError:(%u)\n", + szcHelperProcessStartEvName, GetLastError()); + } + + /* Wait for ready signals from all helper processes. */ + for (i = 0; i < MaxNumHelperProcess; i++) + { + dwRet = WaitForSingleObject(helper_process[i].hProcessReadyEvent, TIMEOUT); + if (dwRet != WAIT_OBJECT_0) + { + Fail("test5.Setup: WaitForSingleObject %s failed for helper process %d\n" + "LastError:(%u)\n", + szcHelperProcessReadyEvName, i, GetLastError()); + } + } + + /* Create the same number of helper threads as helper processes. */ + for (i = 0; i < MaxNumHelperProcess; i++) + { + /* Create the event to let helper thread tell us it is ready. */ + helper_thread[i].hThreadReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if (!helper_thread[i].hThreadReadyEvent) + { + Fail("test5.Setup: CreateEvent of hThreadReadyEvent failed for thread %d\n" + "LastError:(%u)\n", i, GetLastError()); + } + + /* Create the event to tell helper thread to exit without waiting for helper process. */ + helper_thread[i].hThreadFinishEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if (!helper_thread[i].hThreadFinishEvent) + { + Fail("test5.Setup: CreateEvent of hThreadFinishEvent failed for thread %d\n" + "LastError:(%u)\n", i, GetLastError()); + } + + /* Create the helper thread. */ + helper_thread[i].hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)WaitForProcess, + (LPVOID)i, + 0, + &helper_thread[i].dwThreadId); + if (NULL == helper_thread[i].hThread) + { + Fail("test5.Setup: Unable to create the helper thread %d\n" + "LastError:(%u)\n", i, GetLastError()); + } + } + + /* Wait for ready signals from all helper threads. */ + for (i = 0; i < MaxNumHelperProcess; i++) + { + dwRet = WaitForSingleObject(helper_thread[i].hThreadReadyEvent, TIMEOUT); + if (dwRet != WAIT_OBJECT_0) + { + Fail("test5.Setup: WaitForSingleObject hThreadReadyEvent for thread %d\n" + "LastError:(%u)\n", i, GetLastError()); + } + } +} + +/* + * Cleanup the helper processes and helper threads. + */ +DWORD +Cleanup() +{ + DWORD dwExitCode; + DWORD dwRet; + int i; + + /* Wait for all helper process to finish and close their handles + and associated events. */ + for (i = 0; i < MaxNumHelperProcess; i++) + { + + /* wait for the child process to complete */ + dwRet = WaitForSingleObject ( helper_process[i].pi.hProcess, TIMEOUT ); + if (WAIT_OBJECT_0 != dwRet) + { + Fail("test5.Cleanup: WaitForSingleObject hThreadReadyEvent failed for thread %d\n" + "LastError:(%u)\n", i, GetLastError()); + } + + /* check the exit code from the process */ + if (!GetExitCodeProcess(helper_process[i].pi.hProcess, &dwExitCode)) + { + Trace( "test5.Cleanup: GetExitCodeProcess %d call failed LastError:(%u)\n", + i, GetLastError()); + dwExitCode = FAIL; + } + PEDANTIC(CloseHandle, (helper_process[i].pi.hThread)); + PEDANTIC(CloseHandle, (helper_process[i].pi.hProcess)); + PEDANTIC(CloseHandle, (helper_process[i].hProcessReadyEvent)); + PEDANTIC(CloseHandle, (helper_process[i].hProcessFinishEvent)); + } + + /* Close all helper threads' handles */ + for (i = 0; i < MaxNumHelperProcess; i++) + { + PEDANTIC(CloseHandle, (helper_thread[i].hThread)); + PEDANTIC(CloseHandle, (helper_thread[i].hThreadReadyEvent)); + PEDANTIC(CloseHandle, (helper_thread[i].hThreadFinishEvent)); + } + + /* Close all process start event. */ + PEDANTIC(CloseHandle, (hProcessStartEvent)); + + return dwExitCode; +} + +/* + * In this test case, the test thread will signal one helper + * process to exit at a time starting from the last helper + * process and then wait for the corresponding helper thread to exit. + * The ThreadIndexOfThreadFinishEvent specifies the index of the thread that + * should be waked up using hThreadFinishEvent instead of helper process. + */ +void +TestWakeupOneThread() +{ + DWORD dwRet; + int i; + + TestCase = WakeUpOneThread; + + if (((LONG)ThreadIndexOfThreadFinishEvent) < 0 || + ThreadIndexOfThreadFinishEvent >= MAX_HELPER_PROCESS) + Fail("test5.TestWaitOnOneThread: Invalid ThreadIndexOfThreadFinishEvent %d\n", ThreadIndexOfThreadFinishEvent); + + /* Since helper thread 0 waits on helper process 0, + thread 1 waits on on process 0, and 1, + thread 2 waits on process 0, 1, and 2, and so on ..., + and the last helper thread will wait on all helper processes, + the helper thread can be waked up one at a time by + waking up the help process one at a time starting from the + last helper process. */ + for (i = MaxNumHelperProcess-1; i >= 0; i--) + { + /* make sure the helper thread has not exited yet. */ + dwRet = WaitForSingleObject(helper_thread[i].hThread, 0); + if (WAIT_TIMEOUT != dwRet) + { + Fail("test5.TestWaitOnOneThread: helper thread %d already exited %d\n", i); + } + + /* Decide how to wakeup the helper thread: + using event or using helper process. */ + if (i == ThreadIndexOfThreadFinishEvent) + { + if (!SetEvent(helper_thread[i].hThreadFinishEvent)) + { + Fail("test5.TestWaitOnOneThread: SetEvent hThreadFinishEvent failed for thread %d\n", + "LastError:(%u)\n", i, GetLastError()); + } + } + else + { + if (!SetEvent(helper_process[i].hProcessFinishEvent)) + { + Fail("test5.TestWaitOnOneThread: SetEvent %s%d failed for helper process %d\n", + "LastError:(%u)\n", + szcHelperProcessFinishEvName, helper_process[i].pi.dwProcessId, i, + GetLastError()); + } + } + + dwRet = WaitForSingleObject(helper_thread[i].hThread, TIMEOUT); + if (WAIT_OBJECT_0 != dwRet) + { + Fail("test5.TestWaitOnOneThread: WaitForSingleObject helper thread %d" + "LastError:(%u)\n", + i, GetLastError()); + } + } + + /* Finally, need to wake up the helper process which the test thread + skips waking up in the last loop. */ + if (!SetEvent(helper_process[ThreadIndexOfThreadFinishEvent].hProcessFinishEvent)) + { + Fail("test5.TestWaitOnOneThread: SetEvent %s%d failed\n", + "LastError:(%u)\n", + szcHelperProcessFinishEvName, helper_process[ThreadIndexOfThreadFinishEvent].pi.dwProcessId, + GetLastError()); + } +} + +/* + * In this test case, the test thread will signal the helper + * process 0 to exit. Since all helper threads wait on process 0, + * all helper threads will wake up and exit, and the test thread + * will wait for all of them to exit. + */ +void +TestWakeupAllThread() +{ + DWORD dwRet; + int i; + + TestCase = WakeUpAllThread; + + /* make sure none of the helper thread exits. */ + for (i = 0; i < MaxNumHelperProcess; i++) + { + dwRet = WaitForSingleObject(helper_thread[i].hThread, 0); + if (WAIT_TIMEOUT != dwRet) + { + Fail("test5.TestWaitOnAllThread: helper thread %d already exited %d\n", i); + } + } + + /* Signal helper process 0 to exit. */ + if (!SetEvent(helper_process[0].hProcessFinishEvent)) + { + Fail("test5.TestWaitOnAllThread: SetEvent %s%d failed\n", + "LastError:(%u)\n", + szcHelperProcessFinishEvName, helper_process[0].pi.dwProcessId, + GetLastError()); + } + + /* Wait for all helper threads to exit. */ + for (i = 0; i < MaxNumHelperProcess; i++) + { + + dwRet = WaitForSingleObject(helper_thread[i].hThread, TIMEOUT); + if (WAIT_OBJECT_0 != dwRet) + { + Fail("test5.TestWaitOnAllThread: WaitForSingleObject failed for helper thread %d\n" + "LastError:(%u)\n", + i, GetLastError()); + } + } + + /* Signal the rest of helper processes to exit. */ + for (i = 1; i < MaxNumHelperProcess; i++) + { + if (!SetEvent(helper_process[i].hProcessFinishEvent)) + { + Fail("test5.TestWaitOnAllThread: SetEvent %s%d failed\n", + "LastError:(%u)\n", + szcHelperProcessFinishEvName, helper_process[i].pi.dwProcessId, + GetLastError()); + } + } +} + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwExitCode; + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + switch (argc) + { + case 1: + MaxNumHelperProcess = MAX_HELPER_PROCESS; + break; + case 2: + MaxNumHelperProcess = atol(argv[1]); + break; + default: + Fail("Invalid number of arguments\n"); + } + + if (MaxNumHelperProcess < 1 || + MaxNumHelperProcess > MAX_HELPER_PROCESS) + Fail("test5.main: Invalid MaxNumHelperProcess %d\n", MaxNumHelperProcess); + + Setup(); + ThreadIndexOfThreadFinishEvent = 3; + TestWakeupOneThread(); + dwExitCode = Cleanup(); + + if (PASS == dwExitCode) + { + Setup(); + TestWakeupAllThread(); + dwExitCode = Cleanup(); + } + + PAL_TerminateEx(dwExitCode); + return dwExitCode; +} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/CMakeLists.txt index ce75cadbff..01331821a8 100644 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(TESTSOURCES - test6.c + test6.cpp ) add_executable(paltest_waitformultipleobjectsex_test6 @@ -20,7 +20,7 @@ target_link_libraries(paltest_waitformultipleobjectsex_test6 set(HELPERSOURCES - child6.c + child6.cpp ) add_executable(paltest_waitformultipleobjectsex_test6_child diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/child6.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/child6.c deleted file mode 100644 index 1a95815ddf..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/child6.c +++ /dev/null @@ -1,211 +0,0 @@ -// 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: child6.c -** -** Purpose: Test for WaitForMultipleObjectsEx in multiple -** scenarios - child process -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - int i, iRet; - BOOL bRet; - BOOL bNamedEvent = 0; - BOOL bMutex = 0; - BOOL bMutexAndNamedEvent = 0; - BOOL bSemaphore = 0; - DWORD dwRet; - HANDLE hNamedEvent; - HANDLE hMutex; - char szTestName[256]; - WCHAR wszTestName[256] = { 0 }; - char szEventName[128] = { 0 }; - char szMutexName[128] = { 0 }; - char szSemName[128] = { 0 }; - WCHAR wszEventName[128]; - WCHAR wszMutexName[128]; - WCHAR wszSemName[128]; - DWORD iExitCode = 0; - HANDLE hSemaphore; - - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - Trace("[child] Starting\n"); - - for (i=1; i + +int __cdecl main(int argc, char **argv) +{ + int i, iRet; + BOOL bRet; + BOOL bNamedEvent = 0; + BOOL bMutex = 0; + BOOL bMutexAndNamedEvent = 0; + BOOL bSemaphore = 0; + DWORD dwRet; + HANDLE hNamedEvent; + HANDLE hMutex; + char szTestName[256]; + WCHAR wszTestName[256] = { 0 }; + char szEventName[128] = { 0 }; + char szMutexName[128] = { 0 }; + char szSemName[128] = { 0 }; + WCHAR wszEventName[128]; + WCHAR wszMutexName[128]; + WCHAR wszSemName[128]; + DWORD iExitCode = 0; + HANDLE hSemaphore; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + Trace("[child] Starting\n"); + + for (i=1; i - -#define MAX_COUNT 10000 -#define MAX_THREADS 256 - -BOOL g_bMutex = 0; -BOOL g_bEvent = 0; -BOOL g_bNamedEvent = 0; -BOOL g_bSemaphore = 0; -BOOL g_bProcess = 0; -BOOL g_bLocalWaitAll = 0; -BOOL g_bRemoteWaitAll = 0; -BOOL g_bRandom = 0; - -int iCount = 1; -int iThreads = 1; -HANDLE hThreads[MAX_THREADS]; - -#ifndef MIN -#define MIN(a,b) (((a)<(b)) ? (a) : (b)) -#endif - -DWORD PALAPI EventTestThread(PVOID pArg) -{ - BOOL bRet; - DWORD dwRet; - HANDLE hEvent[2]; - HANDLE (*prgHandles)[] = (HANDLE (*)[])pArg; - - Trace("[EventTestThread] Starting\n"); - - bRet = DuplicateHandle(GetCurrentProcess(), (*prgHandles)[0], GetCurrentProcess(), - &hEvent[0], 0, FALSE, DUPLICATE_SAME_ACCESS); - bRet &= DuplicateHandle(GetCurrentProcess(), (*prgHandles)[1], GetCurrentProcess(), - &hEvent[1], 0, FALSE, DUPLICATE_SAME_ACCESS); - if (FALSE == bRet) - { - Fail("[EventTestThread] Failed to duplicate handles\n"); - } - - Sleep(1000); - bRet = SetEvent(hEvent[1]); - if (FALSE == bRet) - { - Fail("SetEvent failed\n"); - Fail("[EventTestThread] SetEvent failed [GetLastError()=%u]\n", - GetLastError()); - } - - dwRet = WaitForSingleObject(hEvent[1], INFINITE); - if (WAIT_FAILED == dwRet) - { - Fail("[EventTestThread] WaitForMultipleObjects failed [GetLastError()=%u]\n", - GetLastError()); - } - - Sleep(1000); - bRet = SetEvent(hEvent[0]); - if (FALSE == bRet) - { - Fail("[EventTestThread] SetEvent failed [GetLastError()=%u]\n", - GetLastError()); - } - - Sleep(1000); - bRet = SetEvent(hEvent[1]); - if (FALSE == bRet) - { - Fail("[EventTestThread] SetEvent failed [GetLastError()=%u]\n", - GetLastError()); - } - - CloseHandle(hEvent[0]); - CloseHandle(hEvent[1]); - - Trace("[EventTestThread] Done\n"); - return 0; -} - -DWORD PALAPI MutexTestThread(PVOID pArg) -{ - BOOL bRet; - DWORD dwRet; - HANDLE hMutex; - - Trace("[MutexTestThread] Starting\n"); - - bRet = DuplicateHandle(GetCurrentProcess(), (HANDLE)pArg, GetCurrentProcess(), &hMutex, - 0, FALSE, DUPLICATE_SAME_ACCESS); - if (FALSE == bRet) - { - Fail("[EventTestThread] DuplicateHandle failed [GetLastError()=%u]\n", - GetLastError()); - } - - dwRet = WaitForSingleObject(hMutex, INFINITE); - if (WAIT_FAILED == dwRet) - { - Fail("[EventTestThread] WaitForMultipleObjects failed [GetLastError()=%u]\n", - GetLastError()); - } - - Sleep(1000); - CloseHandle(hMutex); - - Trace("[MutexTestThread] Done\n"); - - return 0; -} - -DWORD PALAPI TestThread(PVOID pArg) -{ - BOOL bRet; - DWORD dwRet; - PROCESS_INFORMATION pi; - STARTUPINFO si; - HANDLE hNamedEvent; - HANDLE hEvent[2] = { 0, 0 }; - HANDLE hMutex = 0; - HANDLE hSemaphore = 0; - HANDLE hObjs[2]; - DWORD dwThreadNum; - DWORD dwSlaveThreadTid = 0; - HANDLE hThread; - int i, iCnt, iRet; - char szTestName[128]; - char szCmd[128]; - char szEventName[128] = { 0 }; - char szMutexName[128] = { 0 }; - char szSemName[128] = { 0 }; - WCHAR wszEventName[128] = { 0 }; - WCHAR wszMutexName[128] = { 0 }; - WCHAR wszSemName[128] = { 0 }; - BOOL bMutex = g_bMutex; - BOOL bEvent = g_bEvent; - BOOL bNamedEvent = g_bNamedEvent; - BOOL bSemaphore = g_bSemaphore; - BOOL bProcess = g_bProcess; - BOOL bLocalWaitAll = g_bLocalWaitAll; - BOOL bRemoteWaitAll = g_bRemoteWaitAll; - int iDesiredExitCode; - - dwThreadNum = (DWORD)pArg; - - _snprintf (szTestName, 128, "Test6_%u", dwThreadNum); - szTestName[127] = 0; - - _snprintf(szEventName, 128, "%s_Event", szTestName); - szEventName[127] = 0; - _snprintf(szMutexName, 128, "%s_Mutex", szTestName); - szMutexName[127] = 0; - _snprintf(szSemName, 128, "%s_Semaphore", szTestName); - szSemName[127] = 0; - - iRet = MultiByteToWideChar(CP_ACP, 0, szEventName, strlen(szEventName)+1, wszEventName, 128); - iRet &= MultiByteToWideChar(CP_ACP, 0, szMutexName, strlen(szMutexName)+1, wszMutexName, 128); - iRet &= MultiByteToWideChar(CP_ACP, 0, szSemName, strlen(szSemName)+1, wszSemName, 128); - - if (0 == iRet) - { - Fail("[TestThread] Failed to convert strings\n"); - } - - Trace("[TestThread] TestName=%s Event: %S, Mutex: %S, Semaphore = %S\n", - szTestName, wszEventName, wszMutexName, wszSemName); - - hEvent[0] = CreateEventA(NULL, FALSE, FALSE, NULL); - hEvent[1] = CreateEventA(NULL, FALSE, FALSE, NULL); - - hNamedEvent = CreateEventW(NULL, FALSE, FALSE, wszEventName); - hMutex = CreateMutexW(NULL, FALSE, wszMutexName); - hSemaphore = CreateSemaphoreW(NULL, 0, 256, wszSemName); - - if (NULL == hEvent[0] || NULL == hEvent[1] || NULL == hMutex || - NULL == hNamedEvent || NULL == hSemaphore) - { - Fail("[TestThread] Failed to create objects " - "[hNamedEvent=%p hMutex=%p hSemaphore=%p]\n", - (VOID*)hNamedEvent, (VOID*)hMutex, (VOID*)hSemaphore); - } - - for (iCnt=0; iCnt i+1)) - { - i++; - iCnt = atoi(argv[i]); - if (iCnt > 0 && iCnt < MAX_COUNT) - { - iCount = iCnt; - } - } - else if ((0 == strcmp(argv[i], "-threads")) && (argc > i+1)) - { - i++; - iCnt = atoi(argv[i]); - if (iCnt > 0 && iCnt <= MAX_THREADS) - { - iThreads = iCnt; - } - } - else - { - Trace("Unknown option %s ignored\n", argv[i]); - } - } - } - - - iCnt = 0; - for (i=0;i + +#define MAX_COUNT 10000 +#define MAX_THREADS 256 + +BOOL g_bMutex = 0; +BOOL g_bEvent = 0; +BOOL g_bNamedEvent = 0; +BOOL g_bSemaphore = 0; +BOOL g_bProcess = 0; +BOOL g_bLocalWaitAll = 0; +BOOL g_bRemoteWaitAll = 0; +BOOL g_bRandom = 0; + +int iCount = 1; +int iThreads = 1; +HANDLE hThreads[MAX_THREADS]; + +#ifndef MIN +#define MIN(a,b) (((a)<(b)) ? (a) : (b)) +#endif + +DWORD PALAPI EventTestThread(PVOID pArg) +{ + BOOL bRet; + DWORD dwRet; + HANDLE hEvent[2]; + HANDLE (*prgHandles)[] = (HANDLE (*)[])pArg; + + Trace("[EventTestThread] Starting\n"); + + bRet = DuplicateHandle(GetCurrentProcess(), (*prgHandles)[0], GetCurrentProcess(), + &hEvent[0], 0, FALSE, DUPLICATE_SAME_ACCESS); + bRet &= DuplicateHandle(GetCurrentProcess(), (*prgHandles)[1], GetCurrentProcess(), + &hEvent[1], 0, FALSE, DUPLICATE_SAME_ACCESS); + if (FALSE == bRet) + { + Fail("[EventTestThread] Failed to duplicate handles\n"); + } + + Sleep(1000); + bRet = SetEvent(hEvent[1]); + if (FALSE == bRet) + { + Fail("SetEvent failed\n"); + Fail("[EventTestThread] SetEvent failed [GetLastError()=%u]\n", + GetLastError()); + } + + dwRet = WaitForSingleObject(hEvent[1], INFINITE); + if (WAIT_FAILED == dwRet) + { + Fail("[EventTestThread] WaitForMultipleObjects failed [GetLastError()=%u]\n", + GetLastError()); + } + + Sleep(1000); + bRet = SetEvent(hEvent[0]); + if (FALSE == bRet) + { + Fail("[EventTestThread] SetEvent failed [GetLastError()=%u]\n", + GetLastError()); + } + + Sleep(1000); + bRet = SetEvent(hEvent[1]); + if (FALSE == bRet) + { + Fail("[EventTestThread] SetEvent failed [GetLastError()=%u]\n", + GetLastError()); + } + + CloseHandle(hEvent[0]); + CloseHandle(hEvent[1]); + + Trace("[EventTestThread] Done\n"); + return 0; +} + +DWORD PALAPI MutexTestThread(PVOID pArg) +{ + BOOL bRet; + DWORD dwRet; + HANDLE hMutex; + + Trace("[MutexTestThread] Starting\n"); + + bRet = DuplicateHandle(GetCurrentProcess(), (HANDLE)pArg, GetCurrentProcess(), &hMutex, + 0, FALSE, DUPLICATE_SAME_ACCESS); + if (FALSE == bRet) + { + Fail("[EventTestThread] DuplicateHandle failed [GetLastError()=%u]\n", + GetLastError()); + } + + dwRet = WaitForSingleObject(hMutex, INFINITE); + if (WAIT_FAILED == dwRet) + { + Fail("[EventTestThread] WaitForMultipleObjects failed [GetLastError()=%u]\n", + GetLastError()); + } + + Sleep(1000); + CloseHandle(hMutex); + + Trace("[MutexTestThread] Done\n"); + + return 0; +} + +DWORD PALAPI TestThread(PVOID pArg) +{ + BOOL bRet; + DWORD dwRet; + PROCESS_INFORMATION pi; + STARTUPINFO si; + HANDLE hNamedEvent; + HANDLE hEvent[2] = { 0, 0 }; + HANDLE hMutex = 0; + HANDLE hSemaphore = 0; + HANDLE hObjs[2]; + DWORD dwThreadNum; + DWORD dwSlaveThreadTid = 0; + HANDLE hThread; + int i, iCnt, iRet; + char szTestName[128]; + char szCmd[128]; + char szEventName[128] = { 0 }; + char szMutexName[128] = { 0 }; + char szSemName[128] = { 0 }; + WCHAR wszEventName[128] = { 0 }; + WCHAR wszMutexName[128] = { 0 }; + WCHAR wszSemName[128] = { 0 }; + BOOL bMutex = g_bMutex; + BOOL bEvent = g_bEvent; + BOOL bNamedEvent = g_bNamedEvent; + BOOL bSemaphore = g_bSemaphore; + BOOL bProcess = g_bProcess; + BOOL bLocalWaitAll = g_bLocalWaitAll; + BOOL bRemoteWaitAll = g_bRemoteWaitAll; + int iDesiredExitCode; + + dwThreadNum = (DWORD)pArg; + + sprintf_s (szTestName, 128, "Test6_%u", dwThreadNum); + szTestName[127] = 0; + + sprintf_s(szEventName, 128, "%s_Event", szTestName); + szEventName[127] = 0; + sprintf_s(szMutexName, 128, "%s_Mutex", szTestName); + szMutexName[127] = 0; + sprintf_s(szSemName, 128, "%s_Semaphore", szTestName); + szSemName[127] = 0; + + iRet = MultiByteToWideChar(CP_ACP, 0, szEventName, strlen(szEventName)+1, wszEventName, 128); + iRet &= MultiByteToWideChar(CP_ACP, 0, szMutexName, strlen(szMutexName)+1, wszMutexName, 128); + iRet &= MultiByteToWideChar(CP_ACP, 0, szSemName, strlen(szSemName)+1, wszSemName, 128); + + if (0 == iRet) + { + Fail("[TestThread] Failed to convert strings\n"); + } + + Trace("[TestThread] TestName=%s Event: %S, Mutex: %S, Semaphore = %S\n", + szTestName, wszEventName, wszMutexName, wszSemName); + + hEvent[0] = CreateEventA(NULL, FALSE, FALSE, NULL); + hEvent[1] = CreateEventA(NULL, FALSE, FALSE, NULL); + + hNamedEvent = CreateEventW(NULL, FALSE, FALSE, wszEventName); + hMutex = CreateMutexW(NULL, FALSE, wszMutexName); + hSemaphore = CreateSemaphoreW(NULL, 0, 256, wszSemName); + + if (NULL == hEvent[0] || NULL == hEvent[1] || NULL == hMutex || + NULL == hNamedEvent || NULL == hSemaphore) + { + Fail("[TestThread] Failed to create objects " + "[hNamedEvent=%p hMutex=%p hSemaphore=%p]\n", + (VOID*)hNamedEvent, (VOID*)hMutex, (VOID*)hSemaphore); + } + + for (iCnt=0; iCnt i+1)) + { + i++; + iCnt = atoi(argv[i]); + if (iCnt > 0 && iCnt < MAX_COUNT) + { + iCount = iCnt; + } + } + else if ((0 == strcmp(argv[i], "-threads")) && (argc > i+1)) + { + i++; + iCnt = atoi(argv[i]); + if (iCnt > 0 && iCnt <= MAX_THREADS) + { + iThreads = iCnt; + } + } + else + { + Trace("Unknown option %s ignored\n", argv[i]); + } + } + } + + + iCnt = 0; + for (i=0;i - -/*Based on SleepEx/test2 */ - -const int ChildThreadWaitTime = 4000; -const int InterruptTime = 2000; -const DWORD AcceptableDelta = 300; - -void RunTest(BOOL AlertThread); -VOID PALAPI APCFunc(ULONG_PTR dwParam); -DWORD PALAPI WaiterProc(LPVOID lpParameter); - -DWORD ThreadWaitDelta; -HANDLE hMutex; - - - -int __cdecl main( int argc, char **argv ) -{ - int ret=0; - - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* - On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects - (such as conditions) involves some pthread internal initialization that - can make the first wait slighty longer, potentially going above the - acceptable delta for this test. Let's add a dummy wait to preinitialize - internal structures - */ - Sleep(100); - - /* - The state of a mutex object is signaled when it is not owned by any thread. - The creating thread can use the bInitialOwner flag to request immediate ownership - of the mutex. Otherwise, a thread must use one of the wait functions to request - ownership. When the mutex's state is signaled, one waiting thread is granted - ownership, the mutex's state changes to nonsignaled, and the wait function returns. - Only one thread can own a mutex at any given time. The owning thread uses the - ReleaseMutex function to release its ownership. - */ - - /* Create a mutex that is not in the signalled state */ - hMutex = CreateMutex(NULL, //No security attributes - TRUE, //Iniitally owned - NULL); //Name of mutex - - if (hMutex == NULL) - { - Fail("Failed to create mutex! GetLastError returned %d.\n", - GetLastError()); - } - /* - * Check that Queueing an APC in the middle of a wait does interrupt - * it, if it's in an alertable state. - */ - - RunTest(TRUE); - if ((ThreadWaitDelta - InterruptTime) > AcceptableDelta) - { - Fail("Expected thread to wait for %d ms (and get interrupted).\n" - "Thread waited for %d ms! (Acceptable delta: %d)\n", - InterruptTime, ThreadWaitDelta, AcceptableDelta); - } - - - /* - * Check that Queueing an APC in the middle of a wait does NOT interrupt - * it, if it is not in an alertable state. - */ - RunTest(FALSE); - if ((ThreadWaitDelta - ChildThreadWaitTime) > AcceptableDelta) - { - Fail("Expected thread to wait for %d ms (and not be interrupted).\n" - "Thread waited for %d ms! (Acceptable delta: %d)\n", - ChildThreadWaitTime, ThreadWaitDelta, AcceptableDelta); - } - - - - //Release Mutex - ret = ReleaseMutex(hMutex); - if (0==ret) - { - Fail("Unable to Release Mutex!\n" - "GetLastError returned %d\n", GetLastError()); - } - - //Close Mutex Handle - ret = CloseHandle(hMutex); - if (!ret) - { - Fail("Unable to close handle to Mutex!\n" - "GetLastError returned %d\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} - -void RunTest(BOOL AlertThread) -{ - - HANDLE hThread = 0; - DWORD dwThreadId = 0; - - int ret=0; - - hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)WaiterProc, - (LPVOID) AlertThread, - 0, - &dwThreadId); - - if (hThread == NULL) - { - Fail("ERROR: Was not able to create the thread to test!\n" - "GetLastError returned %d\n", GetLastError()); - } - - - - Sleep(InterruptTime); - - ret = QueueUserAPC(APCFunc, hThread, 0); - - if (ret == 0) - { - Fail("QueueUserAPC failed! GetLastError returned %d\n", - GetLastError()); - } - - ret = WaitForSingleObject(hThread, INFINITE); - - if (ret == WAIT_FAILED) - { - Fail("Unable to wait on child thread!\nGetLastError returned %d.\n", - GetLastError()); - } - - - if (0==CloseHandle(hThread)) - { - Trace("Could not close Thread handle\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } -} - -/* Function doesn't do anything, just needed to interrupt the wait*/ -VOID PALAPI APCFunc(ULONG_PTR dwParam) -{ -} - -/* Entry Point for child thread. */ -DWORD PALAPI WaiterProc(LPVOID lpParameter) -{ - UINT64 OldTimeStamp; - UINT64 NewTimeStamp; - BOOL Alertable; - DWORD ret; - - Alertable = (BOOL) lpParameter; - - LARGE_INTEGER performanceFrequency; - if (!QueryPerformanceFrequency(&performanceFrequency)) - { - Fail("Failed to query performance frequency!"); - } - - OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - ret = WaitForSingleObjectEx( hMutex, - ChildThreadWaitTime, - Alertable); - - NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - if (Alertable && ret != WAIT_IO_COMPLETION) - { - Fail("Expected the interrupted wait to return WAIT_IO_COMPLETION.\n" - "Got %d\n", ret); - } - else if (!Alertable && ret != WAIT_TIMEOUT) - { - Fail("WaitForSingleObjectEx did not timeout.\n" - "Expected return of WAIT_TIMEOUT, got %d.\n", ret); - } - - ThreadWaitDelta = NewTimeStamp - OldTimeStamp; - - return 0; -} - - - diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.cpp new file mode 100644 index 0000000000..3737f9cc10 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.cpp @@ -0,0 +1,214 @@ +// 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: WFSOExMutex.c +** +** Purpose: Tests a child thread in the middle of a +** WaitForSingleObjectEx call will be interrupted by QueueUserAPC +** if the alert flag was set. +** +** +**===================================================================*/ + +#include + +/*Based on SleepEx/test2 */ + +const int ChildThreadWaitTime = 4000; +const int InterruptTime = 2000; +const DWORD AcceptableDelta = 300; + +void RunTest(BOOL AlertThread); +VOID PALAPI APCFunc(ULONG_PTR dwParam); +DWORD PALAPI WaiterProc(LPVOID lpParameter); + +DWORD ThreadWaitDelta; +HANDLE hMutex; + + + +int __cdecl main( int argc, char **argv ) +{ + int ret=0; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* + On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects + (such as conditions) involves some pthread internal initialization that + can make the first wait slighty longer, potentially going above the + acceptable delta for this test. Let's add a dummy wait to preinitialize + internal structures + */ + Sleep(100); + + /* + The state of a mutex object is signaled when it is not owned by any thread. + The creating thread can use the bInitialOwner flag to request immediate ownership + of the mutex. Otherwise, a thread must use one of the wait functions to request + ownership. When the mutex's state is signaled, one waiting thread is granted + ownership, the mutex's state changes to nonsignaled, and the wait function returns. + Only one thread can own a mutex at any given time. The owning thread uses the + ReleaseMutex function to release its ownership. + */ + + /* Create a mutex that is not in the signalled state */ + hMutex = CreateMutex(NULL, //No security attributes + TRUE, //Iniitally owned + NULL); //Name of mutex + + if (hMutex == NULL) + { + Fail("Failed to create mutex! GetLastError returned %d.\n", + GetLastError()); + } + /* + * Check that Queueing an APC in the middle of a wait does interrupt + * it, if it's in an alertable state. + */ + + RunTest(TRUE); + if ((ThreadWaitDelta - InterruptTime) > AcceptableDelta) + { + Fail("Expected thread to wait for %d ms (and get interrupted).\n" + "Thread waited for %d ms! (Acceptable delta: %d)\n", + InterruptTime, ThreadWaitDelta, AcceptableDelta); + } + + + /* + * Check that Queueing an APC in the middle of a wait does NOT interrupt + * it, if it is not in an alertable state. + */ + RunTest(FALSE); + if ((ThreadWaitDelta - ChildThreadWaitTime) > AcceptableDelta) + { + Fail("Expected thread to wait for %d ms (and not be interrupted).\n" + "Thread waited for %d ms! (Acceptable delta: %d)\n", + ChildThreadWaitTime, ThreadWaitDelta, AcceptableDelta); + } + + + + //Release Mutex + ret = ReleaseMutex(hMutex); + if (0==ret) + { + Fail("Unable to Release Mutex!\n" + "GetLastError returned %d\n", GetLastError()); + } + + //Close Mutex Handle + ret = CloseHandle(hMutex); + if (!ret) + { + Fail("Unable to close handle to Mutex!\n" + "GetLastError returned %d\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} + +void RunTest(BOOL AlertThread) +{ + + HANDLE hThread = 0; + DWORD dwThreadId = 0; + + int ret=0; + + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)WaiterProc, + (LPVOID) AlertThread, + 0, + &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: Was not able to create the thread to test!\n" + "GetLastError returned %d\n", GetLastError()); + } + + + + Sleep(InterruptTime); + + ret = QueueUserAPC(APCFunc, hThread, 0); + + if (ret == 0) + { + Fail("QueueUserAPC failed! GetLastError returned %d\n", + GetLastError()); + } + + ret = WaitForSingleObject(hThread, INFINITE); + + if (ret == WAIT_FAILED) + { + Fail("Unable to wait on child thread!\nGetLastError returned %d.\n", + GetLastError()); + } + + + if (0==CloseHandle(hThread)) + { + Trace("Could not close Thread handle\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } +} + +/* Function doesn't do anything, just needed to interrupt the wait*/ +VOID PALAPI APCFunc(ULONG_PTR dwParam) +{ +} + +/* Entry Point for child thread. */ +DWORD PALAPI WaiterProc(LPVOID lpParameter) +{ + UINT64 OldTimeStamp; + UINT64 NewTimeStamp; + BOOL Alertable; + DWORD ret; + + Alertable = (BOOL) lpParameter; + + LARGE_INTEGER performanceFrequency; + if (!QueryPerformanceFrequency(&performanceFrequency)) + { + Fail("Failed to query performance frequency!"); + } + + OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + ret = WaitForSingleObjectEx( hMutex, + ChildThreadWaitTime, + Alertable); + + NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + if (Alertable && ret != WAIT_IO_COMPLETION) + { + Fail("Expected the interrupted wait to return WAIT_IO_COMPLETION.\n" + "Got %d\n", ret); + } + else if (!Alertable && ret != WAIT_TIMEOUT) + { + Fail("WaitForSingleObjectEx did not timeout.\n" + "Expected return of WAIT_TIMEOUT, got %d.\n", ret); + } + + ThreadWaitDelta = NewTimeStamp - OldTimeStamp; + + return 0; +} + + + diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/CMakeLists.txt index 12517e31e0..2d12b25e69 100644 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - WFSOExSemaphoreTest.c + WFSOExSemaphoreTest.cpp ) add_executable(paltest_waitforsingleobject_wfsoexsemaphoretest diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.c b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.c deleted file mode 100644 index 793c50995c..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.c +++ /dev/null @@ -1,184 +0,0 @@ -// 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: WFSOExSemaphore.c -** -** Purpose: Tests a child thread in the middle of a -** WaitForSingleObjectEx call will be interrupted by QueueUserAPC -** if the alert flag was set. -** -** -**===================================================================*/ - -#include - -/*Based on SleepEx/test2 */ - -const int ChildThreadWaitTime = 4000; -const int InterruptTime = 2000; -const DWORD AcceptableDelta = 300; - -void RunTest(BOOL AlertThread); -VOID PALAPI APCFunc(ULONG_PTR dwParam); -DWORD PALAPI WaiterProc(LPVOID lpParameter); - -DWORD ThreadWaitDelta; - -int __cdecl main( int argc, char **argv ) -{ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* - On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects - (such as conditions) involves some pthread internal initialization that - can make the first wait slighty longer, potentially going above the - acceptable delta for this test. Let's add a dummy wait to preinitialize - internal structures - */ - Sleep(100); - - /* - * Check that Queueing an APC in the middle of a wait does interrupt - * it, if it's in an alertable state. - */ - - RunTest(TRUE); - if ((ThreadWaitDelta - InterruptTime) > AcceptableDelta) - { - Fail("Expected thread to wait for %d ms (and get interrupted).\n" - "Thread waited for %d ms! (Acceptable delta: %d)\n", - InterruptTime, ThreadWaitDelta, AcceptableDelta); - } - - - /* - * Check that Queueing an APC in the middle of a wait does NOT interrupt - * it, if it is not in an alertable state. - */ - RunTest(FALSE); - if ((ThreadWaitDelta - ChildThreadWaitTime) > AcceptableDelta) - { - Fail("Expected thread to wait for %d ms (and not be interrupted).\n" - "Thread waited for %d ms! (Acceptable delta: %d)\n", - ChildThreadWaitTime, ThreadWaitDelta, AcceptableDelta); - } - - - PAL_Terminate(); - return PASS; -} - -void RunTest(BOOL AlertThread) -{ - HANDLE hThread = 0; - DWORD dwThreadId = 0; - int ret; - - hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)WaiterProc, - (LPVOID) AlertThread, - 0, - &dwThreadId); - - if (hThread == NULL) - { - Fail("ERROR: Was not able to create the thread to test!\n" - "GetLastError returned %d\n", GetLastError()); - } - - Sleep(InterruptTime); - - ret = QueueUserAPC(APCFunc, hThread, 0); - if (ret == 0) - { - Fail("QueueUserAPC failed! GetLastError returned %d\n", - GetLastError()); - } - - ret = WaitForSingleObject(hThread, INFINITE); - if (ret == WAIT_FAILED) - { - Fail("Unable to wait on child thread!\nGetLastError returned %d.\n", - GetLastError()); - } - - if (0==CloseHandle(hThread)) - { - Trace("Could not close Thread handle\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } -} - -/* Function doesn't do anything, just needed to interrupt the wait*/ -VOID PALAPI APCFunc(ULONG_PTR dwParam) -{ -} - -/* Entry Point for child thread. */ -DWORD PALAPI WaiterProc(LPVOID lpParameter) -{ - HANDLE hSemaphore; - UINT64 OldTimeStamp; - UINT64 NewTimeStamp; - BOOL Alertable; - DWORD ret; - - LARGE_INTEGER performanceFrequency; - if (!QueryPerformanceFrequency(&performanceFrequency)) - { - Fail("Failed to query performance frequency!"); - } - - /* Create a semaphore that is not in the signalled state */ - hSemaphore = CreateSemaphoreW(NULL, 0, 1, NULL); - - if (hSemaphore == NULL) - { - Fail("Failed to create semaphore! GetLastError returned %d.\n", - GetLastError()); - } - - Alertable = (BOOL) lpParameter; - - OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - ret = WaitForSingleObjectEx( hSemaphore, - ChildThreadWaitTime, - Alertable); - - NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - - if (Alertable && ret != WAIT_IO_COMPLETION) - { - Fail("Expected the interrupted wait to return WAIT_IO_COMPLETION.\n" - "Got %d\n", ret); - } - else if (!Alertable && ret != WAIT_TIMEOUT) - { - Fail("WaitForSingleObjectEx did not timeout.\n" - "Expected return of WAIT_TIMEOUT, got %d.\n", ret); - } - - - ThreadWaitDelta = NewTimeStamp - OldTimeStamp; - - ret = CloseHandle(hSemaphore); - if (!ret) - { - Fail("Unable to close handle to semaphore!\n" - "GetLastError returned %d\n", GetLastError()); - } - - return 0; -} - - - diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp new file mode 100644 index 0000000000..793c50995c --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp @@ -0,0 +1,184 @@ +// 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: WFSOExSemaphore.c +** +** Purpose: Tests a child thread in the middle of a +** WaitForSingleObjectEx call will be interrupted by QueueUserAPC +** if the alert flag was set. +** +** +**===================================================================*/ + +#include + +/*Based on SleepEx/test2 */ + +const int ChildThreadWaitTime = 4000; +const int InterruptTime = 2000; +const DWORD AcceptableDelta = 300; + +void RunTest(BOOL AlertThread); +VOID PALAPI APCFunc(ULONG_PTR dwParam); +DWORD PALAPI WaiterProc(LPVOID lpParameter); + +DWORD ThreadWaitDelta; + +int __cdecl main( int argc, char **argv ) +{ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* + On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects + (such as conditions) involves some pthread internal initialization that + can make the first wait slighty longer, potentially going above the + acceptable delta for this test. Let's add a dummy wait to preinitialize + internal structures + */ + Sleep(100); + + /* + * Check that Queueing an APC in the middle of a wait does interrupt + * it, if it's in an alertable state. + */ + + RunTest(TRUE); + if ((ThreadWaitDelta - InterruptTime) > AcceptableDelta) + { + Fail("Expected thread to wait for %d ms (and get interrupted).\n" + "Thread waited for %d ms! (Acceptable delta: %d)\n", + InterruptTime, ThreadWaitDelta, AcceptableDelta); + } + + + /* + * Check that Queueing an APC in the middle of a wait does NOT interrupt + * it, if it is not in an alertable state. + */ + RunTest(FALSE); + if ((ThreadWaitDelta - ChildThreadWaitTime) > AcceptableDelta) + { + Fail("Expected thread to wait for %d ms (and not be interrupted).\n" + "Thread waited for %d ms! (Acceptable delta: %d)\n", + ChildThreadWaitTime, ThreadWaitDelta, AcceptableDelta); + } + + + PAL_Terminate(); + return PASS; +} + +void RunTest(BOOL AlertThread) +{ + HANDLE hThread = 0; + DWORD dwThreadId = 0; + int ret; + + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)WaiterProc, + (LPVOID) AlertThread, + 0, + &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: Was not able to create the thread to test!\n" + "GetLastError returned %d\n", GetLastError()); + } + + Sleep(InterruptTime); + + ret = QueueUserAPC(APCFunc, hThread, 0); + if (ret == 0) + { + Fail("QueueUserAPC failed! GetLastError returned %d\n", + GetLastError()); + } + + ret = WaitForSingleObject(hThread, INFINITE); + if (ret == WAIT_FAILED) + { + Fail("Unable to wait on child thread!\nGetLastError returned %d.\n", + GetLastError()); + } + + if (0==CloseHandle(hThread)) + { + Trace("Could not close Thread handle\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } +} + +/* Function doesn't do anything, just needed to interrupt the wait*/ +VOID PALAPI APCFunc(ULONG_PTR dwParam) +{ +} + +/* Entry Point for child thread. */ +DWORD PALAPI WaiterProc(LPVOID lpParameter) +{ + HANDLE hSemaphore; + UINT64 OldTimeStamp; + UINT64 NewTimeStamp; + BOOL Alertable; + DWORD ret; + + LARGE_INTEGER performanceFrequency; + if (!QueryPerformanceFrequency(&performanceFrequency)) + { + Fail("Failed to query performance frequency!"); + } + + /* Create a semaphore that is not in the signalled state */ + hSemaphore = CreateSemaphoreW(NULL, 0, 1, NULL); + + if (hSemaphore == NULL) + { + Fail("Failed to create semaphore! GetLastError returned %d.\n", + GetLastError()); + } + + Alertable = (BOOL) lpParameter; + + OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + ret = WaitForSingleObjectEx( hSemaphore, + ChildThreadWaitTime, + Alertable); + + NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + + if (Alertable && ret != WAIT_IO_COMPLETION) + { + Fail("Expected the interrupted wait to return WAIT_IO_COMPLETION.\n" + "Got %d\n", ret); + } + else if (!Alertable && ret != WAIT_TIMEOUT) + { + Fail("WaitForSingleObjectEx did not timeout.\n" + "Expected return of WAIT_TIMEOUT, got %d.\n", ret); + } + + + ThreadWaitDelta = NewTimeStamp - OldTimeStamp; + + ret = CloseHandle(hSemaphore); + if (!ret) + { + Fail("Unable to close handle to semaphore!\n" + "GetLastError returned %d\n", GetLastError()); + } + + return 0; +} + + + diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/CMakeLists.txt index f3d868f082..915ee94a62 100644 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - WFSOExThreadTest.c + WFSOExThreadTest.cpp ) add_executable(paltest_waitforsingleobject_wfsoexthreadtest diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.c b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.c deleted file mode 100644 index 894d2804aa..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.c +++ /dev/null @@ -1,204 +0,0 @@ -// 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: WFSOExThreadTest.c -** -** Purpose: Tests a child thread in the middle of a -** WaitForSingleObjectEx call will be interrupted by QueueUserAPC -** if the alert flag was set. -** -** -**===================================================================*/ - -#include - -/*Based on SleepEx/test2 */ - -const int ChildThreadWaitTime = 4000; -const int InterruptTime = 2000; -const DWORD AcceptableDelta = 300; - -void RunTest(BOOL AlertThread); -VOID PALAPI APCFunc(ULONG_PTR dwParam); -DWORD PALAPI WaiterProc(LPVOID lpParameter); -void WorkerThread(void); - -int ThreadWaitDelta; - -int __cdecl main( int argc, char **argv ) -{ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - /* - On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects - (such as conditions) involves some pthread internal initialization that - can make the first wait slighty longer, potentially going above the - acceptable delta for this test. Let's add a dummy wait to preinitialize - internal structures - */ - Sleep(100); - - /* - * Check that Queueing an APC in the middle of a wait does interrupt - * it, if it's in an alertable state. - */ - - RunTest(TRUE); - if (abs(ThreadWaitDelta - InterruptTime) > AcceptableDelta) - { - Fail("Expected thread to wait for %d ms (and get interrupted).\n" - "Thread waited for %d ms! (Acceptable delta: %d)\n", - InterruptTime, ThreadWaitDelta, AcceptableDelta); - } - - - /* - * Check that Queueing an APC in the middle of a wait does NOT interrupt - * it, if it is not in an alertable state. - */ - RunTest(FALSE); - if (abs(ThreadWaitDelta - ChildThreadWaitTime) > AcceptableDelta) - { - Fail("Expected thread to wait for %d ms (and not be interrupted).\n" - "Thread waited for %d ms! (Acceptable delta: %d)\n", - ChildThreadWaitTime, ThreadWaitDelta, AcceptableDelta); - } - - - PAL_Terminate(); - return PASS; -} - -void RunTest(BOOL AlertThread) -{ - HANDLE hThread = 0; - DWORD dwThreadId = 0; - int ret; - - //Create thread - hThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)WaiterProc, - (LPVOID) AlertThread, - 0, - &dwThreadId); - - if (hThread == NULL) - { - Fail("ERROR: Was not able to create the thread to test!\n" - "GetLastError returned %d\n", GetLastError()); - } - - Sleep(InterruptTime); - - ret = QueueUserAPC(APCFunc, hThread, 0); - if (ret == 0) - { - Fail("QueueUserAPC failed! GetLastError returned %d\n", - GetLastError()); - } - - - ret = WaitForSingleObject(hThread, INFINITE); - if (ret == WAIT_FAILED) - { - Fail("Unable to wait on child thread!\nGetLastError returned %d.\n", - GetLastError()); - } - - if (0==CloseHandle(hThread)) - { - Trace("Could not close Thread handle\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } -} - -/* Function doesn't do anything, just needed to interrupt the wait*/ -VOID PALAPI APCFunc(ULONG_PTR dwParam) -{ -} - -/* Entry Point for child thread. */ -DWORD PALAPI WaiterProc(LPVOID lpParameter) -{ - HANDLE hWaitThread; - UINT64 OldTimeStamp; - UINT64 NewTimeStamp; - BOOL Alertable; - DWORD ret; - DWORD dwThreadId = 0; - -/* -When a thread terminates, the thread object attains a signaled state, -satisfying any threads that were waiting on the object. -*/ - -/* Create a thread that does not return immediately to maintain a non signaled test*/ - hWaitThread = CreateThread( NULL, - 0, - (LPTHREAD_START_ROUTINE)WorkerThread, - NULL, - 0, - &dwThreadId); - - if (hWaitThread == NULL) - { - Fail("ERROR: Was not able to create worker thread to wait on!\n" - "GetLastError returned %d\n", GetLastError()); - } - - Alertable = (BOOL) lpParameter; - - LARGE_INTEGER performanceFrequency; - if (!QueryPerformanceFrequency(&performanceFrequency)) - { - Fail("Failed to query performance frequency!"); - } - - OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - ret = WaitForSingleObjectEx( hWaitThread, - ChildThreadWaitTime, - Alertable); - - NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); - - - if (Alertable && ret != WAIT_IO_COMPLETION) - { - Fail("Expected the interrupted wait to return WAIT_IO_COMPLETION.\n" - "Got %d\n", ret); - } - else if (!Alertable && ret != WAIT_TIMEOUT) - { - Fail("WaitForSingleObjectEx did not timeout.\n" - "Expected return of WAIT_TIMEOUT, got %d.\n", ret); - } - - ThreadWaitDelta = NewTimeStamp - OldTimeStamp; - - ret = CloseHandle(hWaitThread); - if (!ret) - { - Fail("Unable to close handle to Thread!\n" - "GetLastError returned %d\n", GetLastError()); - } - - return 0; -} - - -void WorkerThread(void) -{ - - //Make the worker thread sleep to test WFSOEx Functionality - - Sleep(2*ChildThreadWaitTime); -} - diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.cpp new file mode 100644 index 0000000000..894d2804aa --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.cpp @@ -0,0 +1,204 @@ +// 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: WFSOExThreadTest.c +** +** Purpose: Tests a child thread in the middle of a +** WaitForSingleObjectEx call will be interrupted by QueueUserAPC +** if the alert flag was set. +** +** +**===================================================================*/ + +#include + +/*Based on SleepEx/test2 */ + +const int ChildThreadWaitTime = 4000; +const int InterruptTime = 2000; +const DWORD AcceptableDelta = 300; + +void RunTest(BOOL AlertThread); +VOID PALAPI APCFunc(ULONG_PTR dwParam); +DWORD PALAPI WaiterProc(LPVOID lpParameter); +void WorkerThread(void); + +int ThreadWaitDelta; + +int __cdecl main( int argc, char **argv ) +{ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* + On some platforms (e.g. FreeBSD 4.9) the first call to some synch objects + (such as conditions) involves some pthread internal initialization that + can make the first wait slighty longer, potentially going above the + acceptable delta for this test. Let's add a dummy wait to preinitialize + internal structures + */ + Sleep(100); + + /* + * Check that Queueing an APC in the middle of a wait does interrupt + * it, if it's in an alertable state. + */ + + RunTest(TRUE); + if (abs(ThreadWaitDelta - InterruptTime) > AcceptableDelta) + { + Fail("Expected thread to wait for %d ms (and get interrupted).\n" + "Thread waited for %d ms! (Acceptable delta: %d)\n", + InterruptTime, ThreadWaitDelta, AcceptableDelta); + } + + + /* + * Check that Queueing an APC in the middle of a wait does NOT interrupt + * it, if it is not in an alertable state. + */ + RunTest(FALSE); + if (abs(ThreadWaitDelta - ChildThreadWaitTime) > AcceptableDelta) + { + Fail("Expected thread to wait for %d ms (and not be interrupted).\n" + "Thread waited for %d ms! (Acceptable delta: %d)\n", + ChildThreadWaitTime, ThreadWaitDelta, AcceptableDelta); + } + + + PAL_Terminate(); + return PASS; +} + +void RunTest(BOOL AlertThread) +{ + HANDLE hThread = 0; + DWORD dwThreadId = 0; + int ret; + + //Create thread + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)WaiterProc, + (LPVOID) AlertThread, + 0, + &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: Was not able to create the thread to test!\n" + "GetLastError returned %d\n", GetLastError()); + } + + Sleep(InterruptTime); + + ret = QueueUserAPC(APCFunc, hThread, 0); + if (ret == 0) + { + Fail("QueueUserAPC failed! GetLastError returned %d\n", + GetLastError()); + } + + + ret = WaitForSingleObject(hThread, INFINITE); + if (ret == WAIT_FAILED) + { + Fail("Unable to wait on child thread!\nGetLastError returned %d.\n", + GetLastError()); + } + + if (0==CloseHandle(hThread)) + { + Trace("Could not close Thread handle\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } +} + +/* Function doesn't do anything, just needed to interrupt the wait*/ +VOID PALAPI APCFunc(ULONG_PTR dwParam) +{ +} + +/* Entry Point for child thread. */ +DWORD PALAPI WaiterProc(LPVOID lpParameter) +{ + HANDLE hWaitThread; + UINT64 OldTimeStamp; + UINT64 NewTimeStamp; + BOOL Alertable; + DWORD ret; + DWORD dwThreadId = 0; + +/* +When a thread terminates, the thread object attains a signaled state, +satisfying any threads that were waiting on the object. +*/ + +/* Create a thread that does not return immediately to maintain a non signaled test*/ + hWaitThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)WorkerThread, + NULL, + 0, + &dwThreadId); + + if (hWaitThread == NULL) + { + Fail("ERROR: Was not able to create worker thread to wait on!\n" + "GetLastError returned %d\n", GetLastError()); + } + + Alertable = (BOOL) lpParameter; + + LARGE_INTEGER performanceFrequency; + if (!QueryPerformanceFrequency(&performanceFrequency)) + { + Fail("Failed to query performance frequency!"); + } + + OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + ret = WaitForSingleObjectEx( hWaitThread, + ChildThreadWaitTime, + Alertable); + + NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); + + + if (Alertable && ret != WAIT_IO_COMPLETION) + { + Fail("Expected the interrupted wait to return WAIT_IO_COMPLETION.\n" + "Got %d\n", ret); + } + else if (!Alertable && ret != WAIT_TIMEOUT) + { + Fail("WaitForSingleObjectEx did not timeout.\n" + "Expected return of WAIT_TIMEOUT, got %d.\n", ret); + } + + ThreadWaitDelta = NewTimeStamp - OldTimeStamp; + + ret = CloseHandle(hWaitThread); + if (!ret) + { + Fail("Unable to close handle to Thread!\n" + "GetLastError returned %d\n", GetLastError()); + } + + return 0; +} + + +void WorkerThread(void) +{ + + //Make the worker thread sleep to test WFSOEx Functionality + + Sleep(2*ChildThreadWaitTime); +} + diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOMutexTest/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOMutexTest/CMakeLists.txt index 374880e90f..b96324d654 100644 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOMutexTest/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOMutexTest/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - WFSOMutexTest.c + WFSOMutexTest.cpp ) add_executable(paltest_waitforsingleobject_wfsomutextest diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOMutexTest/WFSOMutexTest.c b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOMutexTest/WFSOMutexTest.c deleted file mode 100644 index 5ecf517c2a..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOMutexTest/WFSOMutexTest.c +++ /dev/null @@ -1,184 +0,0 @@ -// 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: WFSOMutexTest.c -** -** Purpose: Test for WaitForSingleObjectTest. -** Create Mutex Object -** Create Two Threads, Each Threads does WFSO for the Mutex Object -** Increments Counter -** Releases Mutex -** Test Passes if the above operations are successful -** -** -** -**=========================================================*/ - - - -#include - - -#define NUMBER_OF_WORKER_THREADS 2 - -//Declaring Variables -HANDLE hMutex = NULL; -unsigned int globalcounter =0; -int testReturnCode = PASS; - -//Declaring Function Prototypes -DWORD WFSOMutexTest(LPVOID params); -void incrementCounter(void); - - - -int __cdecl main(int argc, char **argv) -{ - - //Declare local variables - int i =0; - - // 2 dimensional array to hold thread handles for each worker thread - HANDLE hThread[NUMBER_OF_WORKER_THREADS]; - DWORD dwThreadId=0; - int returnCode = 0; - - //Initialize PAL - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - //Create Mutex - hMutex = CreateMutex(NULL, // no security attributes - FALSE, // initially not owned - NULL); // name of mutex - - //Check for Mutex Creation - - if (hMutex == NULL) - { - Fail("Create Mutex Failed, GetLastError: %d\n", GetLastError()); - } - - - //Spawn 2 worker threads - for (i=0;i + + +#define NUMBER_OF_WORKER_THREADS 2 + +//Declaring Variables +HANDLE hMutex = NULL; +unsigned int globalcounter =0; +int testReturnCode = PASS; + +//Declaring Function Prototypes +DWORD PALAPI WFSOMutexTest(LPVOID params); +void incrementCounter(void); + + + +int __cdecl main(int argc, char **argv) +{ + + //Declare local variables + int i =0; + + // 2 dimensional array to hold thread handles for each worker thread + HANDLE hThread[NUMBER_OF_WORKER_THREADS]; + DWORD dwThreadId=0; + int returnCode = 0; + + //Initialize PAL + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + //Create Mutex + hMutex = CreateMutex(NULL, // no security attributes + FALSE, // initially not owned + NULL); // name of mutex + + //Check for Mutex Creation + + if (hMutex == NULL) + { + Fail("Create Mutex Failed, GetLastError: %d\n", GetLastError()); + } + + + //Spawn 2 worker threads + for (i=0;i - -int __cdecl main(int argc, char **argv) -{ - -//Declare local variables -int i =0; - - - -//Initialize PAL -if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - -//Do some work -for (i=0; i<100000; i++); - -Trace("Counter Value was incremented to %d \n ",i); - -PAL_Terminate(); -return ( PASS ); - -} - - - - - - - - diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/ChildProcess.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/ChildProcess.cpp new file mode 100644 index 0000000000..91c24d87bb --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/ChildProcess.cpp @@ -0,0 +1,50 @@ +// 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: ChildProcess.c +** +** Purpose: Dummy Process which does some work on which the Main Test case waits +** +** + +** +**=========================================================*/ + + + +#include + +int __cdecl main(int argc, char **argv) +{ + +//Declare local variables +int i =0; + + + +//Initialize PAL +if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + +//Do some work +for (i=0; i<100000; i++); + +Trace("Counter Value was incremented to %d \n ",i); + +PAL_Terminate(); +return ( PASS ); + +} + + + + + + + + diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/WFSOProcessTest.c b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/WFSOProcessTest.c deleted file mode 100644 index 2711e26c29..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/WFSOProcessTest.c +++ /dev/null @@ -1,119 +0,0 @@ -// 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: WFSOProcessTest.c -** -** Purpose: Test for WaitForSingleObjectTest. -** Create One Process and do some work -** Use WFSO For the Process to finish -** -** Test Passes if the above operations are successful -** -** -** -**=========================================================*/ - - - -#include - -int __cdecl main(int argc, char **argv) -{ - -//Declare local variables -STARTUPINFO si; -PROCESS_INFORMATION pi; - -DWORD dwWaitResult=0; - -//Initialize PAL -if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - -ZeroMemory( &si, sizeof(si) ); -si.cb = sizeof(si); -ZeroMemory( &pi, sizeof(pi) ); - -// Start the child process. -if( !CreateProcess( NULL, // No module name (use command line). - "childprocess", // Command line. - NULL, // Process handle not inheritable. - NULL, // Thread handle not inheritable. - FALSE, // Set handle inheritance to FALSE. - 0, // No creation flags. - NULL, // Use parent's environment block. - NULL, // Use parent's starting directory. - &si, // Pointer to STARTUPINFO structure. - &pi ) // Pointer to PROCESS_INFORMATION structure. -) - -{ -Fail ( "Create Process Failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); -} - -// Wait until child process exits. - dwWaitResult = WaitForSingleObject( pi.hProcess, INFINITE ); -switch (dwWaitResult) - { - // The Process wait was successful - case WAIT_OBJECT_0: - { - - Trace("Wait for Process was successful\n"); - break; - } - - // Time-out. - case WAIT_TIMEOUT: - { - Fail ( "Time -out. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - return FALSE; - } - - // Got ownership of the abandoned process object. - case WAIT_ABANDONED: - { - Fail ( "Got ownership of the abandoned Process object. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - return FALSE; - } - - //Error condition - case WAIT_FAILED: - { - Fail ( "Wait for Process Failed. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - return FALSE; - } - -} - - - -// Close process handle -if (0==CloseHandle(pi.hProcess)) - { - Trace("Could not close process handle\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - - -PAL_Terminate(); -return ( PASS ); - -} - - - - - - - diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/WFSOProcessTest.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/WFSOProcessTest.cpp new file mode 100644 index 0000000000..2711e26c29 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOProcessTest/WFSOProcessTest.cpp @@ -0,0 +1,119 @@ +// 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: WFSOProcessTest.c +** +** Purpose: Test for WaitForSingleObjectTest. +** Create One Process and do some work +** Use WFSO For the Process to finish +** +** Test Passes if the above operations are successful +** +** +** +**=========================================================*/ + + + +#include + +int __cdecl main(int argc, char **argv) +{ + +//Declare local variables +STARTUPINFO si; +PROCESS_INFORMATION pi; + +DWORD dwWaitResult=0; + +//Initialize PAL +if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + +ZeroMemory( &si, sizeof(si) ); +si.cb = sizeof(si); +ZeroMemory( &pi, sizeof(pi) ); + +// Start the child process. +if( !CreateProcess( NULL, // No module name (use command line). + "childprocess", // Command line. + NULL, // Process handle not inheritable. + NULL, // Thread handle not inheritable. + FALSE, // Set handle inheritance to FALSE. + 0, // No creation flags. + NULL, // Use parent's environment block. + NULL, // Use parent's starting directory. + &si, // Pointer to STARTUPINFO structure. + &pi ) // Pointer to PROCESS_INFORMATION structure. +) + +{ +Fail ( "Create Process Failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); +} + +// Wait until child process exits. + dwWaitResult = WaitForSingleObject( pi.hProcess, INFINITE ); +switch (dwWaitResult) + { + // The Process wait was successful + case WAIT_OBJECT_0: + { + + Trace("Wait for Process was successful\n"); + break; + } + + // Time-out. + case WAIT_TIMEOUT: + { + Fail ( "Time -out. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + return FALSE; + } + + // Got ownership of the abandoned process object. + case WAIT_ABANDONED: + { + Fail ( "Got ownership of the abandoned Process object. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + return FALSE; + } + + //Error condition + case WAIT_FAILED: + { + Fail ( "Wait for Process Failed. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + return FALSE; + } + +} + + + +// Close process handle +if (0==CloseHandle(pi.hProcess)) + { + Trace("Could not close process handle\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + + +PAL_Terminate(); +return ( PASS ); + +} + + + + + + + diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOSemaphoreTest/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOSemaphoreTest/CMakeLists.txt index 171e0583e5..d17f8da8e5 100644 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOSemaphoreTest/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOSemaphoreTest/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - WFSOSemaphoreTest.c + WFSOSemaphoreTest.cpp ) add_executable(paltest_waitforsingleobject_wfsosemaphoretest diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOSemaphoreTest/WFSOSemaphoreTest.c b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOSemaphoreTest/WFSOSemaphoreTest.c deleted file mode 100644 index 9902d448cd..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOSemaphoreTest/WFSOSemaphoreTest.c +++ /dev/null @@ -1,183 +0,0 @@ -// 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: WFSOMutexTest.c -** -** Purpose: Test for WaitForSingleObjectTest. -** Create Semaphore Object -** Create Two Threads, Each Threads does WFSO for the Semaphore Object -** Increments Counter -** Releases Semaphore -** Test Passes if the above operations are successful -** -** -** -**=========================================================*/ - - - -#include - - -#define NUMBER_OF_WORKER_THREADS 2 - - -//Declaring Variables -HANDLE hSemaphore = NULL; -unsigned int globalcounter =0; -int testReturnCode = PASS; - -//Declaring Function Prototypes -DWORD WFSOSemaphoreTest(LPVOID params); -void incrementCounter(void); - -int __cdecl main(int argc, char **argv) -{ - - //Declare local variables - int i =0; - int cMax = 2; - - int returnCode = 0; - - // 2 dimensional array to hold thread handles for each worker thread - HANDLE hThread[NUMBER_OF_WORKER_THREADS]; - DWORD dwThreadId=0; - - //Initialize PAL - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - //Create Semaphore - hSemaphore = CreateSemaphore( - NULL, // no security attributes - cMax, // initial count - cMax, // maximum count - NULL); // unnamed semaphore - - if (hSemaphore == NULL) - { - // Check for error. - Fail("Create Semaphore Failed, GetLastError: %d\n", GetLastError()); - } - - - - //Spawn 2 worker threads - for (i=0;i + + +#define NUMBER_OF_WORKER_THREADS 2 + + +//Declaring Variables +HANDLE hSemaphore = NULL; +unsigned int globalcounter =0; +int testReturnCode = PASS; + +//Declaring Function Prototypes +DWORD PALAPI WFSOSemaphoreTest(LPVOID params); +void incrementCounter(void); + +int __cdecl main(int argc, char **argv) +{ + + //Declare local variables + int i =0; + int cMax = 2; + + int returnCode = 0; + + // 2 dimensional array to hold thread handles for each worker thread + HANDLE hThread[NUMBER_OF_WORKER_THREADS]; + DWORD dwThreadId=0; + + //Initialize PAL + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + //Create Semaphore + hSemaphore = CreateSemaphore( + NULL, // no security attributes + cMax, // initial count + cMax, // maximum count + NULL); // unnamed semaphore + + if (hSemaphore == NULL) + { + // Check for error. + Fail("Create Semaphore Failed, GetLastError: %d\n", GetLastError()); + } + + + + //Spawn 2 worker threads + for (i=0;i - - -//Declaring Variables -HANDLE hThread = NULL; -HANDLE hEvent = NULL; - -unsigned int globalcounter =0; - -//Declaring Function Prototypes -DWORD incrementCounter(LPVOID params); - -int __cdecl main(int argc, char **argv) -{ - - //Declare local variables - DWORD dwThreadId=0; - DWORD dwWaitResult=0; - - //Initialize PAL - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - - //Create Event - hEvent = CreateEvent(NULL,TRUE,FALSE, NULL); - if(hEvent == NULL) - { - Fail("Create Event Failed\n" - "GetLastError returned %d\n", GetLastError()); - } - - - //Create Thread - hThread = CreateThread( - NULL, - 0, - incrementCounter, - NULL, - 0, - &dwThreadId); - - if ( NULL == hThread ) - { - Fail ( "CreateThread() returned NULL. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - - //Wait For Thread to signal start - dwWaitResult = WaitForSingleObject(hEvent,INFINITE); - - switch (dwWaitResult) - { - // The thread wait was successful - case WAIT_OBJECT_0: - { - - Trace ("Wait for Single Object (hEvent) was successful.\n"); - break; - } - - // Time-out. - case WAIT_TIMEOUT: - { - Fail ( "Time -out. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - return FALSE; - } - - // Got ownership of the abandoned event object. - case WAIT_ABANDONED: - { - Fail ( "Got ownership of the abandoned event object. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - return FALSE; - } - - } - - - //Wait for Thread to finish - dwWaitResult = WaitForSingleObject( - hThread, //handle to thread - 5000L); //Wait Indefinitely - - - switch (dwWaitResult) - { - // The thread wait was successful - case WAIT_OBJECT_0: - { - - Trace("Wait for thread was successful\n"); - - break; - } - - // Time-out. - case WAIT_TIMEOUT: - { - Fail ( "Time -out. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - return FALSE; - } - - // Got ownership of the abandoned thread object. - case WAIT_ABANDONED: - { - Fail ( "Got ownership of the abandoned thread object. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - return FALSE; - } - - } - - -//Close Handles -if (0==CloseHandle(hEvent)) - { - Trace("Could not Close event handle\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } -if (0==CloseHandle(hThread)) - { - Trace("Could not Close thread handle\n"); - Fail ( "GetLastError returned %d\n", GetLastError()); - } - -PAL_Terminate(); -return ( PASS ); - -} - -DWORD incrementCounter(LPVOID params) -{ - - //Signal Event so that main thread can start to wait for thread object - if (0==SetEvent(hEvent)) - { - Fail ( "SetEvent returned Zero. Failing test.\n" - "GetLastError returned %d\n", GetLastError()); - } - - for (globalcounter=0;globalcounter<100000;globalcounter++); - - //Sleep(5000); - - Trace("Global Counter Value: %d \n", globalcounter); - return 0; -} - - - - - - diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOThreadTest/WFSOThreadTest.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOThreadTest/WFSOThreadTest.cpp new file mode 100644 index 0000000000..e3c3fe22b7 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOThreadTest/WFSOThreadTest.cpp @@ -0,0 +1,179 @@ +// 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: WFSOThreadTest.c +** +** Purpose: Test for WaitForSingleObjectTest. +** Create One Thread and do some work +** Use WFSO For the Thread to finish +** +** Test Passes if the above operations are successful +** +** +** +**=========================================================*/ + + + +#include + + +//Declaring Variables +HANDLE hThread = NULL; +HANDLE hEvent = NULL; + +unsigned int globalcounter =0; + +//Declaring Function Prototypes +DWORD PALAPI incrementCounter(LPVOID params); + +int __cdecl main(int argc, char **argv) +{ + + //Declare local variables + DWORD dwThreadId=0; + DWORD dwWaitResult=0; + + //Initialize PAL + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + + //Create Event + hEvent = CreateEvent(NULL,TRUE,FALSE, NULL); + if(hEvent == NULL) + { + Fail("Create Event Failed\n" + "GetLastError returned %d\n", GetLastError()); + } + + + //Create Thread + hThread = CreateThread( + NULL, + 0, + incrementCounter, + NULL, + 0, + &dwThreadId); + + if ( NULL == hThread ) + { + Fail ( "CreateThread() returned NULL. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + + //Wait For Thread to signal start + dwWaitResult = WaitForSingleObject(hEvent,INFINITE); + + switch (dwWaitResult) + { + // The thread wait was successful + case WAIT_OBJECT_0: + { + + Trace ("Wait for Single Object (hEvent) was successful.\n"); + break; + } + + // Time-out. + case WAIT_TIMEOUT: + { + Fail ( "Time -out. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + return FALSE; + } + + // Got ownership of the abandoned event object. + case WAIT_ABANDONED: + { + Fail ( "Got ownership of the abandoned event object. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + return FALSE; + } + + } + + + //Wait for Thread to finish + dwWaitResult = WaitForSingleObject( + hThread, //handle to thread + 5000L); //Wait Indefinitely + + + switch (dwWaitResult) + { + // The thread wait was successful + case WAIT_OBJECT_0: + { + + Trace("Wait for thread was successful\n"); + + break; + } + + // Time-out. + case WAIT_TIMEOUT: + { + Fail ( "Time -out. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + return FALSE; + } + + // Got ownership of the abandoned thread object. + case WAIT_ABANDONED: + { + Fail ( "Got ownership of the abandoned thread object. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + return FALSE; + } + + } + + +//Close Handles +if (0==CloseHandle(hEvent)) + { + Trace("Could not Close event handle\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } +if (0==CloseHandle(hThread)) + { + Trace("Could not Close thread handle\n"); + Fail ( "GetLastError returned %d\n", GetLastError()); + } + +PAL_Terminate(); +return ( PASS ); + +} + +DWORD PALAPI incrementCounter(LPVOID params) +{ + + //Signal Event so that main thread can start to wait for thread object + if (0==SetEvent(hEvent)) + { + Fail ( "SetEvent returned Zero. Failing test.\n" + "GetLastError returned %d\n", GetLastError()); + } + + for (globalcounter=0;globalcounter<100000;globalcounter++); + + //Sleep(5000); + + Trace("Global Counter Value: %d \n", globalcounter); + return 0; +} + + + + + + diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/CMakeLists.txt index 0a71330ba1..25f3739492 100644 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_waitforsingleobject_test1 diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/test1.c b/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/test1.c deleted file mode 100644 index 2af80df677..0000000000 --- a/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/test1.c +++ /dev/null @@ -1,121 +0,0 @@ -// 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: test1.c -** -** Purpose: Test for WaitForSingleObjectTest. Create two events, one -** with a TRUE and one with FALSE intial state. Ensure that WaitForSingle -** returns correct values for each of these. -** -** -**=========================================================*/ - -#include - -BOOL WaitForSingleObjectTest() -{ - - BOOL bRet = FALSE; - DWORD dwRet = 0; - - LPSECURITY_ATTRIBUTES lpEventAttributes = 0; - BOOL bManualReset = TRUE; - BOOL bInitialState = TRUE; - - HANDLE hEvent; - - /* Create an event, and ensure the HANDLE is valid */ - hEvent = CreateEvent(lpEventAttributes, bManualReset, - bInitialState, NULL); - - if (hEvent != INVALID_HANDLE_VALUE) - { - - /* Call WaitForSingleObject with 0 time on the event. It - should return WAIT_OBJECT_0 - */ - - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_OBJECT_0) - { - Trace("WaitForSingleObjectTest:WaitForSingleObject failed (%x)\n", GetLastError()); - } - else - { - bRet = CloseHandle(hEvent); - - if (!bRet) - { - Trace("WaitForSingleObjectTest:CloseHandle failed (%x)\n", GetLastError()); - } - } - } - else - { - Trace("WaitForSingleObjectTest:CreateEvent failed (%x)\n", GetLastError()); - } - - /* If the first section passed, Create another event, with the - intial state being FALSE this time. - */ - - if (bRet) - { - bRet = FALSE; - - bInitialState = FALSE; - - hEvent = CreateEvent( lpEventAttributes, - bManualReset, bInitialState, NULL); - - if (hEvent != INVALID_HANDLE_VALUE) - { - - /* Test WaitForSingleObject and ensure that it returns - WAIT_TIMEOUT in this case. - */ - - dwRet = WaitForSingleObject(hEvent,0); - - if (dwRet != WAIT_TIMEOUT) - { - Trace("WaitForSingleObjectTest:WaitForSingleObject failed (%x)\n", GetLastError()); - } - else - { - bRet = CloseHandle(hEvent); - - if (!bRet) - { - Trace("WaitForSingleObjectTest:CloseHandle failed (%x)\n", GetLastError()); - } - } - } - else - { - Trace("WaitForSingleObjectTest::CreateEvent failed (%x)\n", GetLastError()); - } - } - return bRet; -} - -int __cdecl main(int argc, char **argv) -{ - if(0 != (PAL_Initialize(argc, argv))) - { - return ( FAIL ); - } - - if(!WaitForSingleObjectTest()) - { - Fail ("Test failed\n"); - } - - PAL_Terminate(); - return ( PASS ); - -} diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/test1.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/test1.cpp new file mode 100644 index 0000000000..2af80df677 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/test1/test1.cpp @@ -0,0 +1,121 @@ +// 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: test1.c +** +** Purpose: Test for WaitForSingleObjectTest. Create two events, one +** with a TRUE and one with FALSE intial state. Ensure that WaitForSingle +** returns correct values for each of these. +** +** +**=========================================================*/ + +#include + +BOOL WaitForSingleObjectTest() +{ + + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = 0; + BOOL bManualReset = TRUE; + BOOL bInitialState = TRUE; + + HANDLE hEvent; + + /* Create an event, and ensure the HANDLE is valid */ + hEvent = CreateEvent(lpEventAttributes, bManualReset, + bInitialState, NULL); + + if (hEvent != INVALID_HANDLE_VALUE) + { + + /* Call WaitForSingleObject with 0 time on the event. It + should return WAIT_OBJECT_0 + */ + + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("WaitForSingleObjectTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + bRet = CloseHandle(hEvent); + + if (!bRet) + { + Trace("WaitForSingleObjectTest:CloseHandle failed (%x)\n", GetLastError()); + } + } + } + else + { + Trace("WaitForSingleObjectTest:CreateEvent failed (%x)\n", GetLastError()); + } + + /* If the first section passed, Create another event, with the + intial state being FALSE this time. + */ + + if (bRet) + { + bRet = FALSE; + + bInitialState = FALSE; + + hEvent = CreateEvent( lpEventAttributes, + bManualReset, bInitialState, NULL); + + if (hEvent != INVALID_HANDLE_VALUE) + { + + /* Test WaitForSingleObject and ensure that it returns + WAIT_TIMEOUT in this case. + */ + + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("WaitForSingleObjectTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + bRet = CloseHandle(hEvent); + + if (!bRet) + { + Trace("WaitForSingleObjectTest:CloseHandle failed (%x)\n", GetLastError()); + } + } + } + else + { + Trace("WaitForSingleObjectTest::CreateEvent failed (%x)\n", GetLastError()); + } + } + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!WaitForSingleObjectTest()) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/YieldProcessor/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/YieldProcessor/test1/CMakeLists.txt index 5002bf763d..1c600bd81c 100644 --- a/src/pal/tests/palsuite/threading/YieldProcessor/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/YieldProcessor/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_yieldprocessor_test1 diff --git a/src/pal/tests/palsuite/threading/YieldProcessor/test1/test1.c b/src/pal/tests/palsuite/threading/YieldProcessor/test1/test1.c deleted file mode 100644 index 6adbe989c2..0000000000 --- a/src/pal/tests/palsuite/threading/YieldProcessor/test1/test1.c +++ /dev/null @@ -1,92 +0,0 @@ -// 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: test1.c -** -** Purpose: Test to ensure YieldProcessor works, without -** causing test to hang -** -** Dependencies: PAL_Initialize -** Fail -** YieldProcessor -** WaitForMultipleObject -** CreateThread -** GetLastError -** - -** -**===========================================================================*/ - - -#include -#define THREAD_COUNT 10 -#define REPEAT_COUNT 1000 -#define TIMEOUT 60000 -void PALAPI Run_Thread(LPVOID lpParam); - -/** - * main - * - * executable entry point - */ -INT __cdecl main( INT argc, CHAR **argv ) -{ - DWORD dwParam; - HANDLE hThread[THREAD_COUNT]; - DWORD threadId[THREAD_COUNT]; - - int i = 0; - int returnCode = 0; - - /*PAL initialization */ - if( (PAL_Initialize(argc, argv)) != 0 ) - { - return FAIL; - } - - - for( i = 0; i < THREAD_COUNT; i++ ) - { - dwParam = (int) i; - //Create thread - hThread[i] = CreateThread( - NULL, /* no security attributes */ - 0, /* use default stack size */ - (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ - (LPVOID)dwParam, /* argument to thread function */ - 0, /* use default creation flags */ - &threadId[i] /* returns the thread identifier*/ - ); - - if(hThread[i] == NULL) - { - Fail("Create Thread failed for iteration %d GetLastError value is %d\n", i, GetLastError()); - } - - } - - - returnCode = WaitForMultipleObjects(THREAD_COUNT, hThread, TRUE, TIMEOUT); - if( WAIT_OBJECT_0 != returnCode ) - { - Trace("Wait for Object(s) returned %d, expected value is %d, and GetLastError value is %d\n", returnCode, WAIT_OBJECT_0, GetLastError()); - } - - PAL_Terminate(); - return PASS; - -} - -void PALAPI Run_Thread (LPVOID lpParam) -{ - int i = 0; - - for(i=0; i < REPEAT_COUNT; i++ ) - { - // No error code set nor does it have any return code - YieldProcessor(); - } -} diff --git a/src/pal/tests/palsuite/threading/YieldProcessor/test1/test1.cpp b/src/pal/tests/palsuite/threading/YieldProcessor/test1/test1.cpp new file mode 100644 index 0000000000..6adbe989c2 --- /dev/null +++ b/src/pal/tests/palsuite/threading/YieldProcessor/test1/test1.cpp @@ -0,0 +1,92 @@ +// 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: test1.c +** +** Purpose: Test to ensure YieldProcessor works, without +** causing test to hang +** +** Dependencies: PAL_Initialize +** Fail +** YieldProcessor +** WaitForMultipleObject +** CreateThread +** GetLastError +** + +** +**===========================================================================*/ + + +#include +#define THREAD_COUNT 10 +#define REPEAT_COUNT 1000 +#define TIMEOUT 60000 +void PALAPI Run_Thread(LPVOID lpParam); + +/** + * main + * + * executable entry point + */ +INT __cdecl main( INT argc, CHAR **argv ) +{ + DWORD dwParam; + HANDLE hThread[THREAD_COUNT]; + DWORD threadId[THREAD_COUNT]; + + int i = 0; + int returnCode = 0; + + /*PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return FAIL; + } + + + for( i = 0; i < THREAD_COUNT; i++ ) + { + dwParam = (int) i; + //Create thread + hThread[i] = CreateThread( + NULL, /* no security attributes */ + 0, /* use default stack size */ + (LPTHREAD_START_ROUTINE)Run_Thread,/* thread function */ + (LPVOID)dwParam, /* argument to thread function */ + 0, /* use default creation flags */ + &threadId[i] /* returns the thread identifier*/ + ); + + if(hThread[i] == NULL) + { + Fail("Create Thread failed for iteration %d GetLastError value is %d\n", i, GetLastError()); + } + + } + + + returnCode = WaitForMultipleObjects(THREAD_COUNT, hThread, TRUE, TIMEOUT); + if( WAIT_OBJECT_0 != returnCode ) + { + Trace("Wait for Object(s) returned %d, expected value is %d, and GetLastError value is %d\n", returnCode, WAIT_OBJECT_0, GetLastError()); + } + + PAL_Terminate(); + return PASS; + +} + +void PALAPI Run_Thread (LPVOID lpParam) +{ + int i = 0; + + for(i=0; i < REPEAT_COUNT; i++ ) + { + // No error code set nor does it have any return code + YieldProcessor(); + } +} diff --git a/src/pal/tests/palsuite/threading/releasesemaphore/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/releasesemaphore/test1/CMakeLists.txt index e415f91fb2..4f6947476d 100644 --- a/src/pal/tests/palsuite/threading/releasesemaphore/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/releasesemaphore/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test.c + test.cpp ) add_executable(paltest_releasesemaphore_test1 diff --git a/src/pal/tests/palsuite/threading/releasesemaphore/test1/test.c b/src/pal/tests/palsuite/threading/releasesemaphore/test1/test.c deleted file mode 100644 index 4d736b7d9a..0000000000 --- a/src/pal/tests/palsuite/threading/releasesemaphore/test1/test.c +++ /dev/null @@ -1,68 +0,0 @@ -// 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: releasesemaphore/test1/createsemaphore.c -** -** Purpose: Check that ReleaseSemaphore fails when using a semaphore handle -** which has been closed by a call to CloseHandle. Check that -** ReleaseSemaphore fails when using a ReleaseCount of zero or less than -** zero. -** -** -**==========================================================================*/ - -#include - -HANDLE hSemaphore; - -int __cdecl main (int argc, char **argv) -{ - if(0 != (PAL_Initialize(argc, argv))) - { - return (FAIL); - } - hSemaphore = CreateSemaphoreA (NULL, 1, 2, NULL); - - if (NULL == hSemaphore) - { - Fail("PALSUITE ERROR: CreateSemaphoreA ('%p' '%ld' '%ld' " - "'%p') returned NULL.\nGetLastError returned %d.\n", - NULL, 1, 2, NULL, GetLastError()); - } - - if(ReleaseSemaphore(hSemaphore, 0, NULL)) - { - Fail("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " - "call returned %d\nwhen it should have returned " - "%d.\nGetLastError returned %d.\n", - hSemaphore, 0, NULL, FALSE, TRUE, GetLastError()); - } - - if(ReleaseSemaphore(hSemaphore, -1, NULL)) - { - Fail("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " - "call returned %d\nwhen it should have returned " - "%d.\nGetLastError returned %d.\n", - hSemaphore, -1, NULL, TRUE, FALSE, GetLastError()); - } - - if(!CloseHandle(hSemaphore)) - { - Fail("PALSUITE ERROR: CloseHandle(%p) call failed. GetLastError " - "returned %d.\n", hSemaphore, GetLastError()); - } - - if(ReleaseSemaphore(hSemaphore, 1, NULL)) - { - Fail("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " - "call incremented semaphore %p count\nafter the handle " - "was closed by a call to CloseHandle.\n GetLastError returned " - "%d.\n", hSemaphore, -1, NULL, hSemaphore, GetLastError()); - } - - PAL_Terminate(); - return (PASS); -} diff --git a/src/pal/tests/palsuite/threading/releasesemaphore/test1/test.cpp b/src/pal/tests/palsuite/threading/releasesemaphore/test1/test.cpp new file mode 100644 index 0000000000..4d736b7d9a --- /dev/null +++ b/src/pal/tests/palsuite/threading/releasesemaphore/test1/test.cpp @@ -0,0 +1,68 @@ +// 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: releasesemaphore/test1/createsemaphore.c +** +** Purpose: Check that ReleaseSemaphore fails when using a semaphore handle +** which has been closed by a call to CloseHandle. Check that +** ReleaseSemaphore fails when using a ReleaseCount of zero or less than +** zero. +** +** +**==========================================================================*/ + +#include + +HANDLE hSemaphore; + +int __cdecl main (int argc, char **argv) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return (FAIL); + } + hSemaphore = CreateSemaphoreA (NULL, 1, 2, NULL); + + if (NULL == hSemaphore) + { + Fail("PALSUITE ERROR: CreateSemaphoreA ('%p' '%ld' '%ld' " + "'%p') returned NULL.\nGetLastError returned %d.\n", + NULL, 1, 2, NULL, GetLastError()); + } + + if(ReleaseSemaphore(hSemaphore, 0, NULL)) + { + Fail("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " + "call returned %d\nwhen it should have returned " + "%d.\nGetLastError returned %d.\n", + hSemaphore, 0, NULL, FALSE, TRUE, GetLastError()); + } + + if(ReleaseSemaphore(hSemaphore, -1, NULL)) + { + Fail("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " + "call returned %d\nwhen it should have returned " + "%d.\nGetLastError returned %d.\n", + hSemaphore, -1, NULL, TRUE, FALSE, GetLastError()); + } + + if(!CloseHandle(hSemaphore)) + { + Fail("PALSUITE ERROR: CloseHandle(%p) call failed. GetLastError " + "returned %d.\n", hSemaphore, GetLastError()); + } + + if(ReleaseSemaphore(hSemaphore, 1, NULL)) + { + Fail("PALSUITE ERROR: ReleaseSemaphore('%p' '%ld' '%p') " + "call incremented semaphore %p count\nafter the handle " + "was closed by a call to CloseHandle.\n GetLastError returned " + "%d.\n", hSemaphore, -1, NULL, hSemaphore, GetLastError()); + } + + PAL_Terminate(); + return (PASS); +} -- cgit v1.2.3