From 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 23 Nov 2016 19:09:09 +0900 Subject: Imported Upstream version 1.1.0 --- .../palsuite/c_runtime/wprintf/CMakeLists.txt | 5 + .../c_runtime/wprintf/test1/CMakeLists.txt | 19 +++ .../tests/palsuite/c_runtime/wprintf/test1/test1.c | 47 ++++++ .../palsuite/c_runtime/wprintf/test1/testinfo.dat | 12 ++ .../c_runtime/wprintf/test2/CMakeLists.txt | 19 +++ .../tests/palsuite/c_runtime/wprintf/test2/test2.c | 45 ++++++ .../palsuite/c_runtime/wprintf/test2/testinfo.dat | 12 ++ src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h | 171 +++++++++++++++++++++ 8 files changed, 330 insertions(+) create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test2/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.c create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/test2/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h (limited to 'src/pal/tests/palsuite/c_runtime/wprintf') diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wprintf/CMakeLists.txt new file mode 100644 index 0000000000..ef14ea5352 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) + diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wprintf/test1/CMakeLists.txt new file mode 100644 index 0000000000..701bbe4160 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/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_wprintf_test1 + ${SOURCES} +) + +add_dependencies(paltest_wprintf_test1 coreclrpal) + +target_link_libraries(paltest_wprintf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.c new file mode 100644 index 0000000000..d99dc8cf93 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/test1/test1.c @@ -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/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/wprintf/test1/testinfo.dat new file mode 100644 index 0000000000..02946361b0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/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 = wprintf +Name = Positive Test for wprintf +TYPE = DEFAULT +EXE1 = test1 +Description += General test to see if wprintf works correctly diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/wprintf/test2/CMakeLists.txt new file mode 100644 index 0000000000..55c3d11913 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.c +) + +add_executable(paltest_wprintf_test2 + ${SOURCES} +) + +add_dependencies(paltest_wprintf_test2 coreclrpal) + +target_link_libraries(paltest_wprintf_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.c b/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.c new file mode 100644 index 0000000000..254e98a394 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.c @@ -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/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/wprintf/test2/testinfo.dat new file mode 100644 index 0000000000..7808c069dd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/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 = wprintf +Name = Positive Test for wprintf +TYPE = DEFAULT +EXE1 = test2 +Description += Tests wprintf with strings diff --git a/src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h b/src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h new file mode 100644 index 0000000000..7d3caf1b02 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/wprintf/wprintf.h @@ -0,0 +1,171 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: wprintf.h +** +** Purpose: Containts common testing functions for wprintf +** +** +**==========================================================================*/ + +#ifndef __wprintf_H__ +#define __wprintf_H__ + +void DoStrTest(WCHAR *formatstr, WCHAR* param, WCHAR *checkstr) +{ + int ret; + + ret = wprintf(formatstr, param); + if (ret != wcslen(checkstr)) + { + Fail("DoStrTest:Expected wprintf to return %d, got %d.\n", + wcslen(checkstr), ret); + } +} + + +void DoPointerTest(WCHAR *formatstr, void* param, WCHAR* paramstr, + WCHAR *checkstr1) +{ + int ret; + + ret = wprintf(formatstr, param); + if (ret != wcslen(checkstr1)) + { + Fail("DoPointerTest:Expected wprintf to return %d, got %d.\n", + wcslen(checkstr1), ret); + } +} + +void DoCountTest(WCHAR *formatstr, int param, WCHAR *checkstr) +{ + int ret; + int n = -1; + + ret = wprintf(formatstr, &n); + + if (n != param) + { + Fail("DoCountTest:Expected count parameter to resolve to %d, got %d\n", param, n); + } + + if (ret != wcslen(checkstr)) + { + Fail("DoCountTest:Expected wprintf to return %d, got %d.\n", + wcslen(checkstr), ret); + } +} + +void DoShortCountTest(WCHAR *formatstr, int param, WCHAR *checkstr) +{ + int ret; + short int n = -1; + + ret = wprintf(formatstr, &n); + + if (n != param) + { + Fail("DoShortCountTest:Expected count parameter to resolve to %d, got %d\n", param, n); + } + + if (ret != wcslen(checkstr)) + { + Fail("DoShortCountTest:Expected wprintf to return %d, got %d.\n", + wcslen(checkstr), ret); + } +} + + +void DoCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) +{ + int ret; + + ret = wprintf(formatstr, param); + if (ret != wcslen(checkstr)) + { + Fail("DoCharTest:Expected wprintf to return %d, got %d.\n", + wcslen(checkstr), ret); + } +} + +void DoWCharTest(WCHAR *formatstr, WCHAR param, WCHAR *checkstr) +{ + int ret; + + ret = wprintf(formatstr, param); + if (ret != wcslen(checkstr)) + { + Fail("DoWCharTest:Expected wprintf to return %d, got %d.\n", + wcslen(checkstr), ret); + } +} + +void DoNumTest(WCHAR *formatstr, int param, WCHAR *checkstr) +{ + int ret; + + ret = wprintf(formatstr, param); + if (ret != wcslen(checkstr)) + { + Fail("DoNumTest:Expected wprintf to return %d, got %d.\n", + wcslen(checkstr), ret); + } +} + +void DoI64Test(WCHAR *formatstr, INT64 param, WCHAR *valuestr, + WCHAR *checkstr1) +{ + int ret; + + ret = wprintf(formatstr, param); + if (ret != wcslen(checkstr1)) + { + Fail("DoI64Test:Expected wprintf to return %d, got %d.\n", + wcslen(checkstr1), ret); + } +} + +void DoDoubleTest(WCHAR *formatstr, double param, + WCHAR *checkstr1, WCHAR *checkstr2) +{ + int ret; + + ret = wprintf(formatstr, param); + if (ret != wcslen(checkstr1) && ret != wcslen(checkstr2)) + { + Fail("DoDoubleTest:Expected wprintf to return %d or %d, got %d.\n", + wcslen(checkstr1), wcslen(checkstr2), ret); + } +} + +void DoArgumentPrecTest(WCHAR *formatstr, int precision, void *param, + WCHAR *paramstr, WCHAR *checkstr1, WCHAR *checkstr2) +{ + int ret; + + ret = wprintf(formatstr, precision, param); + if (ret != wcslen(checkstr1) && ret != wcslen(checkstr2)) + { + Fail("DoArgumentPrecTest:Expected wprintf to return %d or %d, got %d.\n", + wcslen(checkstr1), wcslen(checkstr2), ret); + } +} + +void DoArgumentPrecDoubleTest(WCHAR *formatstr, int precision, double param, + WCHAR *checkstr1, WCHAR *checkstr2) +{ + int ret; + + ret = wprintf(formatstr, precision, param); + if (ret != wcslen(checkstr1) && ret != wcslen(checkstr2)) + { + Fail("DoArgumentPrecDoubleTest:Expected wprintf to return %d or %d, got %d.\n", + wcslen(checkstr1), wcslen(checkstr2), ret); + } +} + +#endif + -- cgit v1.2.3