mirror of
https://github.com/reactos/wine.git
synced 2024-11-29 14:40:56 +00:00
dceae02d73
structure. Instead return error when it is given an unormalized date. - Use better algorithms for RtlTimeToTimeFields and RtlTimeFieldsToTime. RtlTimeToTimeFields is about 3 times faster. - Add tests for RtlTimeFieldsToTime. - SystemTimeToFileTime must fail if RtlTimeFieldsToTime fails. Users of SystemTimeToFileTime must do likewise. - Remove a todo_wine from SystemTimeToFileTime tests. - Since msvcrt.mktime must accept unnormalized dates, it cannot use SystemTimeToFileTime and do the calculations itself. - Add some tests for mktime accepting unnormalized dates.
110 lines
4.5 KiB
C
110 lines
4.5 KiB
C
/*
|
|
* Unit test suite for ntdll time functions
|
|
*
|
|
* Copyright 2004 Rein Klazes
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include "ntdll_test.h"
|
|
|
|
#ifdef __WINE_WINTERNL_H
|
|
|
|
#define TICKSPERSEC 10000000
|
|
#define TICKSPERMSEC 10000
|
|
#define SECSPERDAY 86400
|
|
|
|
static VOID (WINAPI *pRtlTimeToTimeFields)( const LARGE_INTEGER *liTime, PTIME_FIELDS TimeFields) ;
|
|
static VOID (WINAPI *pRtlTimeFieldsToTime)( PTIME_FIELDS TimeFields, PLARGE_INTEGER Time) ;
|
|
|
|
static const int MonthLengths[2][12] =
|
|
{
|
|
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
|
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
|
};
|
|
|
|
static inline int IsLeapYear(int Year)
|
|
{
|
|
return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
|
|
}
|
|
|
|
/* start time of the tests */
|
|
TIME_FIELDS tftest = {1889,12,31,23,59,59,0,0};
|
|
|
|
static void test_pRtlTimeToTimeFields()
|
|
{
|
|
LARGE_INTEGER litime , liresult;
|
|
TIME_FIELDS tfresult;
|
|
int i=0;
|
|
litime.QuadPart = ((ULONGLONG)0x0144017a << 32) | 0xf0b0a980;
|
|
while( tftest.Year < 2110 ) {
|
|
/* test at the last second of the month */
|
|
pRtlTimeToTimeFields( &litime, &tfresult);
|
|
ok( tfresult.Year == tftest.Year && tfresult.Month == tftest.Month &&
|
|
tfresult.Day == tftest.Day && tfresult.Hour == tftest.Hour &&
|
|
tfresult.Minute == tftest.Minute && tfresult.Second == tftest.Second,
|
|
"#%d expected: %d-%d-%d %d:%d:%d got: %d-%d-%d %d:%d:%d\n", ++i,
|
|
tftest.Year, tftest.Month, tftest.Day,
|
|
tftest.Hour, tftest.Minute,tftest.Second,
|
|
tfresult.Year, tfresult.Month, tfresult.Day,
|
|
tfresult.Hour, tfresult.Minute, tfresult.Second);
|
|
/* test the inverse */
|
|
pRtlTimeFieldsToTime( &tfresult, &liresult);
|
|
ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
|
|
tfresult.Year, tfresult.Month, tfresult.Day,
|
|
tfresult.Hour, tfresult.Minute, tfresult.Second,
|
|
(int) (liresult.QuadPart - litime.QuadPart) );
|
|
/* one second later is beginning of next month */
|
|
litime.QuadPart += TICKSPERSEC ;
|
|
pRtlTimeToTimeFields( &litime, &tfresult);
|
|
ok( tfresult.Year == tftest.Year + (tftest.Month ==12) &&
|
|
tfresult.Month == tftest.Month % 12 + 1 &&
|
|
tfresult.Day == 1 && tfresult.Hour == 0 &&
|
|
tfresult.Minute == 0 && tfresult.Second == 0,
|
|
"#%d expected: %d-%d-%d %d:%d:%d got: %d-%d-%d %d:%d:%d\n", ++i,
|
|
tftest.Year + (tftest.Month ==12),
|
|
tftest.Month % 12 + 1, 1, 0, 0, 0,
|
|
tfresult.Year, tfresult.Month, tfresult.Day,
|
|
tfresult.Hour, tfresult.Minute, tfresult.Second);
|
|
/* test the inverse */
|
|
pRtlTimeFieldsToTime( &tfresult, &liresult);
|
|
ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
|
|
tfresult.Year, tfresult.Month, tfresult.Day,
|
|
tfresult.Hour, tfresult.Minute, tfresult.Second,
|
|
(int) (liresult.QuadPart - litime.QuadPart) );
|
|
/* advance to the end of the month */
|
|
litime.QuadPart -= TICKSPERSEC ;
|
|
if( tftest.Month == 12) {
|
|
tftest.Month = 1;
|
|
tftest.Year += 1;
|
|
} else
|
|
tftest.Month += 1;
|
|
tftest.Day = MonthLengths[IsLeapYear(tftest.Year)][tftest.Month - 1];
|
|
litime.QuadPart += (LONGLONG) tftest.Day * TICKSPERSEC * SECSPERDAY;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
START_TEST(time)
|
|
{
|
|
#ifdef __WINE_WINTERNL_H
|
|
HMODULE mod = GetModuleHandleA("ntdll.dll");
|
|
pRtlTimeToTimeFields = (void *)GetProcAddress(mod,"RtlTimeToTimeFields");
|
|
pRtlTimeFieldsToTime = (void *)GetProcAddress(mod,"RtlTimeFieldsToTime");
|
|
if (pRtlTimeToTimeFields && pRtlTimeFieldsToTime)
|
|
test_pRtlTimeToTimeFields();
|
|
#endif
|
|
}
|