~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/ntdll/tests/time.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Unit test suite for ntdll time functions
  3  *
  4  * Copyright 2004 Rein Klazes
  5  *
  6  * This library is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU Lesser General Public
  8  * License as published by the Free Software Foundation; either
  9  * version 2.1 of the License, or (at your option) any later version.
 10  *
 11  * This library is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  * Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public
 17  * License along with this library; if not, write to the Free Software
 18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include "ntdll_test.h"
 22 
 23 #ifdef __WINE_WINTERNL_H
 24 
 25 #define TICKSPERSEC        10000000
 26 #define TICKSPERMSEC       10000
 27 #define SECSPERDAY         86400
 28 
 29 static VOID (WINAPI *pRtlTimeToTimeFields)( const LARGE_INTEGER *liTime, PTIME_FIELDS TimeFields) ;
 30 static VOID (WINAPI *pRtlTimeFieldsToTime)(  PTIME_FIELDS TimeFields,  PLARGE_INTEGER Time) ;
 31 
 32 static const int MonthLengths[2][12] =
 33 {
 34         { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
 35         { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
 36 };
 37 
 38 static inline int IsLeapYear(int Year)
 39 {
 40         return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
 41 }
 42 
 43 /* start time of the tests */
 44 TIME_FIELDS tftest = {1889,12,31,23,59,59,0,0};
 45 
 46 static void test_pRtlTimeToTimeFields(void)
 47 {
 48     LARGE_INTEGER litime , liresult;
 49     TIME_FIELDS tfresult;
 50     int i=0;
 51     litime.QuadPart = ((ULONGLONG)0x0144017a << 32) | 0xf0b0a980;
 52     while( tftest.Year < 2110 ) {
 53         /* test at the last second of the month */
 54         pRtlTimeToTimeFields( &litime, &tfresult);
 55         ok( tfresult.Year == tftest.Year && tfresult.Month == tftest.Month &&
 56             tfresult.Day == tftest.Day && tfresult.Hour == tftest.Hour && 
 57             tfresult.Minute == tftest.Minute && tfresult.Second == tftest.Second,
 58             "#%d expected: %d-%d-%d %d:%d:%d  got:  %d-%d-%d %d:%d:%d\n", ++i,
 59             tftest.Year, tftest.Month, tftest.Day,
 60             tftest.Hour, tftest.Minute,tftest.Second,
 61             tfresult.Year, tfresult.Month, tfresult.Day,
 62             tfresult.Hour, tfresult.Minute, tfresult.Second);
 63         /* test the inverse */
 64         pRtlTimeFieldsToTime( &tfresult, &liresult);
 65         ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
 66             tfresult.Year, tfresult.Month, tfresult.Day,
 67             tfresult.Hour, tfresult.Minute, tfresult.Second,
 68             (int) (liresult.QuadPart - litime.QuadPart) );
 69         /*  one second later is beginning of next month */
 70         litime.QuadPart +=  TICKSPERSEC ;
 71         pRtlTimeToTimeFields( &litime, &tfresult);
 72         ok( tfresult.Year == tftest.Year + (tftest.Month ==12) &&
 73             tfresult.Month == tftest.Month % 12 + 1 &&
 74             tfresult.Day == 1 && tfresult.Hour == 0 && 
 75             tfresult.Minute == 0 && tfresult.Second == 0,
 76             "#%d expected: %d-%d-%d %d:%d:%d  got:  %d-%d-%d %d:%d:%d\n", ++i,
 77             tftest.Year + (tftest.Month ==12),
 78             tftest.Month % 12 + 1, 1, 0, 0, 0,
 79             tfresult.Year, tfresult.Month, tfresult.Day,
 80             tfresult.Hour, tfresult.Minute, tfresult.Second);
 81         /* test the inverse */
 82         pRtlTimeFieldsToTime( &tfresult, &liresult);
 83         ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
 84             tfresult.Year, tfresult.Month, tfresult.Day,
 85             tfresult.Hour, tfresult.Minute, tfresult.Second,
 86             (int) (liresult.QuadPart - litime.QuadPart) );
 87         /* advance to the end of the month */
 88         litime.QuadPart -=  TICKSPERSEC ;
 89         if( tftest.Month == 12) {
 90             tftest.Month = 1;
 91             tftest.Year += 1;
 92         } else 
 93             tftest.Month += 1;
 94         tftest.Day = MonthLengths[IsLeapYear(tftest.Year)][tftest.Month - 1];
 95         litime.QuadPart +=  (LONGLONG) tftest.Day * TICKSPERSEC * SECSPERDAY;
 96     }
 97 }
 98 #endif
 99 
100 START_TEST(time)
101 {
102 #ifdef __WINE_WINTERNL_H
103     HMODULE mod = GetModuleHandleA("ntdll.dll");
104     pRtlTimeToTimeFields = (void *)GetProcAddress(mod,"RtlTimeToTimeFields");
105     pRtlTimeFieldsToTime = (void *)GetProcAddress(mod,"RtlTimeFieldsToTime");
106     if (pRtlTimeToTimeFields && pRtlTimeFieldsToTime)
107         test_pRtlTimeToTimeFields();
108 #endif
109 }
110 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.