1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/datetime/t_dparse.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,122 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\datetime\t_dparse.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +
1.23 +RTest test(_L("T_DPARSE"));
1.24 +TInt offset=0;
1.25 +
1.26 +LOCAL_C TInt DateTimeParse(TDateTime& aDateTime,const TDesC& aDes,TInt aCenturyOffset=0)
1.27 + {
1.28 + TTime time;
1.29 + TInt r=time.Parse(aDes,aCenturyOffset);
1.30 + if (r>=0)
1.31 + aDateTime=time.DateTime();
1.32 + return r;
1.33 + }
1.34 +
1.35 +LOCAL_D TInt ConvertDesToDateTimeInteractively()
1.36 + {
1.37 + TKeyCode code;
1.38 + TBuf<32> buf;
1.39 + buf.SetLength(0);
1.40 + FOREVER
1.41 + {
1.42 + code = test.Console()->Getch();
1.43 + if (code==EKeyEnter || code==EKeyLineFeed)
1.44 + break;
1.45 + if (code==EKeyEscape)
1.46 + return KErrGeneral;
1.47 + if ((code==EKeyDelete || code==EKeyBackspace) && buf.Length()>0)
1.48 + {
1.49 + TChar del(code);
1.50 + TBuf<1> delBuf;
1.51 + delBuf.Append(del);
1.52 + test.Printf(delBuf);
1.53 + buf.SetLength(buf.Length()-1);
1.54 + continue;
1.55 + }
1.56 + if (buf.Length()==0 && code==EKeyF1)
1.57 + {
1.58 + test.Printf(_L("Enter a two digit value. "));
1.59 + TKeyCode code1 = test.Console()->Getch();
1.60 + TKeyCode code2 = test.Console()->Getch();
1.61 + TChar ch1(code1);
1.62 + TChar ch2(code2);
1.63 + TBuf<2> centuryOffset;
1.64 + centuryOffset.Append(ch1);
1.65 + centuryOffset.Append(ch2);
1.66 + TLex lex(centuryOffset);
1.67 + if (lex.Val(offset)!=KErrNone)
1.68 + return KErrGeneral;
1.69 + test.Printf(_L("The century offset is set to %d\n"),offset);
1.70 + if (ConvertDesToDateTimeInteractively()==KErrGeneral)
1.71 + return KErrGeneral;
1.72 + }
1.73 + TChar ch(code);
1.74 + buf.Append(ch);
1.75 + TBuf<1> charBuf;
1.76 + charBuf.Append(ch);
1.77 + test.Printf(charBuf);
1.78 + }
1.79 + test.Printf(_L(" = "));
1.80 + TDateTime dateTime;
1.81 + TInt error = DateTimeParse(dateTime,buf,offset);
1.82 + TInt year = dateTime.Year();
1.83 + TInt month = dateTime.Month()+1;
1.84 + TInt day = dateTime.Day()+1;
1.85 + TInt hour = dateTime.Hour();
1.86 + TInt min = dateTime.Minute();
1.87 + TInt sec = dateTime.Second();
1.88 + TInt msec = dateTime.MicroSecond();
1.89 + switch(error)
1.90 + {
1.91 + case EParseTimePresent:
1.92 + test.Printf(_L("%d:%d:%d.%d "),hour,min,sec,msec);
1.93 + test.Printf(_L("Time\n"));
1.94 + break;
1.95 + case EParseDatePresent:
1.96 + test.Printf(_L("%d/%d/%d "),day,month,year);
1.97 + test.Printf(_L("Date\n"));
1.98 + break;
1.99 + case EParseTimePresent|EParseDatePresent:
1.100 + test.Printf(_L("%d:%d:%d.%d %d/%d/%d "),hour,min,sec,msec,day,month,year);
1.101 + test.Printf(_L("DateAndTime\n"));
1.102 + break;
1.103 + default:
1.104 + test.Printf(_L("error\n"));
1.105 + break;
1.106 + }
1.107 + if (ConvertDesToDateTimeInteractively()==KErrGeneral)
1.108 + return KErrGeneral;
1.109 + return KErrNone;
1.110 + }
1.111 +
1.112 +
1.113 +TInt E32Main()
1.114 + {
1.115 + test.Start(_L("Begin tests"));
1.116 + test.Console()->Printf(_L("Convert a Des To a DateTime.\n"));
1.117 + test.Printf(_L("Enter a Date, a Time or a Date & Time.\n"));
1.118 + test.Printf(_L("Press Escape to exit tests.\n"));
1.119 + test.Printf(_L("Press the F1 key to set the century offset.\n"));
1.120 + ConvertDesToDateTimeInteractively();
1.121 + test.End();
1.122 + return KErrNone;
1.123 + }
1.124 +
1.125 +