summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/_gcvt
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/_gcvt')
-rw-r--r--src/pal/tests/palsuite/c_runtime/_gcvt/CMakeLists.txt5
-rw-r--r--src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c58
-rw-r--r--src/pal/tests/palsuite/c_runtime/_gcvt/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c83
-rw-r--r--src/pal/tests/palsuite/c_runtime/_gcvt/test2/testinfo.dat15
7 files changed, 212 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_gcvt/CMakeLists.txt
new file mode 100644
index 0000000000..ef14ea5352
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_gcvt/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/_gcvt/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt
new file mode 100644
index 0000000000..33eb5cf19c
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ _gcvt.c
+)
+
+add_executable(paltest_gcvt_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_gcvt_test1 coreclrpal)
+
+target_link_libraries(paltest_gcvt_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c
new file mode 100644
index 0000000000..ccfc286898
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c
@@ -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 <palsuite.h>
+
+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/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/testinfo.dat
new file mode 100644
index 0000000000..d527418108
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_gcvt/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 = _gcvt
+Name = Positive test for _gcvt API to convert a floatable value to a string
+TYPE = DEFAULT
+EXE1 = _gcvt
+Description
+=Test the _gcvt to convert a floatable value to a string
+=with specified sigficant digits stored
diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt
new file mode 100644
index 0000000000..05641b9b78
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_gcvt/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_gcvt_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_gcvt_test2 coreclrpal)
+
+target_link_libraries(paltest_gcvt_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c
new file mode 100644
index 0000000000..7ac9a4fcf0
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c
@@ -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 <palsuite.h>
+
+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/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/testinfo.dat
new file mode 100644
index 0000000000..e9e192849a
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/testinfo.dat
@@ -0,0 +1,15 @@
+# Licensed to the .NET Foundation under one or more agreements.
+# The .NET Foundation licenses this file to you under the MIT license.
+# See the LICENSE file in the project root for more information.
+
+Version = 1.0
+Section = C Runtime
+Function = _gcvt
+Name = Call _gcvt on normal values, negatives, exponents and hex digits.
+TYPE = DEFAULT
+EXE1 = test2
+Description
+= 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)