summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
commit4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch)
tree98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c
parentfa45f57ed55137c75ac870356a1b8f76c84b229c (diff)
downloadcoreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c')
-rw-r--r--src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c b/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c
new file mode 100644
index 0000000000..51ec1f099c
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fprintf/test4/test4.c
@@ -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 <palsuite.h>
+#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;
+}