summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/ctime
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/ctime
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/ctime')
-rw-r--r--src/pal/tests/palsuite/c_runtime/ctime/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/c_runtime/ctime/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/ctime/test1/test1.c154
-rw-r--r--src/pal/tests/palsuite/c_runtime/ctime/test1/testinfo.dat15
4 files changed, 192 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/ctime/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ctime/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/ctime/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/ctime/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ctime/test1/CMakeLists.txt
new file mode 100644
index 0000000000..aa64a71d1e
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/ctime/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_ctime_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_ctime_test1 coreclrpal)
+
+target_link_libraries(paltest_ctime_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/ctime/test1/test1.c b/src/pal/tests/palsuite/c_runtime/ctime/test1/test1.c
new file mode 100644
index 0000000000..5d5e22ce89
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/ctime/test1/test1.c
@@ -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 <palsuite.h>
+
+/*
+ * 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( &LTime );
+
+ /* 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( &LTime );
+
+ /* 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( &LTime );
+
+ /* 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/testinfo.dat b/src/pal/tests/palsuite/c_runtime/ctime/test1/testinfo.dat
new file mode 100644
index 0000000000..c5aa3df65e
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/ctime/test1/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 = ctime
+Name = Positive Test for ctime
+TYPE = DEFAULT
+EXE1 = test1
+Description
+= Call ctime with a valid number of second in it's t_time parameter
+= and expect a non-null char* as a return value.
+= Call ctime with a invalid number of second (-1) and expect
+= a null char* as a return value.