secureswitools/swisistools/source/sisxlibrary/sistime.cpp
changeset 0 ba25891c3a9e
child 26 04d4a7bbc3e0
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Note: This file may contain code to generate corrupt files for test purposes.
       
    16 * Such code is excluded from production builds by use of compiler defines;
       
    17 * it is recommended that such code should be removed if this code is ever published publicly.
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 /**
       
    23  @file 
       
    24  @internalComponent
       
    25  @released
       
    26 */
       
    27 
       
    28 
       
    29 #include "sistime.h"
       
    30 #include "exception.h"
       
    31 
       
    32 #include <time.h>
       
    33 
       
    34 CSISTime::CSISTime (const CSISTime& aInitialiser) :
       
    35 		CStructure <CSISFieldRoot::ESISTime> (aInitialiser),
       
    36 		iHours (aInitialiser.iHours),
       
    37 		iMinutes (aInitialiser.iMinutes),
       
    38 		iSeconds (aInitialiser.iSeconds)
       
    39 	{
       
    40 	InsertMembers (); 
       
    41 	}
       
    42 
       
    43 
       
    44 void CSISTime::InsertMembers ()
       
    45 	{
       
    46 	InsertMember (iHours);
       
    47 	InsertMember (iMinutes);
       
    48 	InsertMember (iSeconds);
       
    49 	}
       
    50 
       
    51 
       
    52 void CSISTime::Verify (const TUint32 aLanguages) const
       
    53 	{
       
    54 	CStructure <CSISFieldRoot::ESISTime>::Verify (aLanguages);
       
    55 	if (	(iHours > 23) ||
       
    56 			(iMinutes > 59) ||
       
    57 			(iSeconds > 61))
       
    58 		{
       
    59 		const int maxlen = 256;
       
    60 		char message [maxlen];
       
    61 		struct tm time;
       
    62 		memset (&time, 0, sizeof (struct tm));
       
    63 		time.tm_hour = iHours;
       
    64 		time.tm_min = iMinutes;
       
    65 		time.tm_sec = iSeconds;
       
    66 		::strftime (message, maxlen, "invalid time %c", &time);
       
    67 		throw CSISException (CSISException::EVerification, message);
       
    68 		}
       
    69 	}
       
    70 
       
    71 
       
    72 void CSISTime::Set (const TUint8 aHours, const TUint8 aMinutes, const TUint8 aSeconds)
       
    73 	{
       
    74 	iHours = aHours;
       
    75 	iMinutes = aMinutes;
       
    76 	iSeconds = aSeconds;
       
    77 	}
       
    78 
       
    79 void CSISTime::AddPackageEntry(std::wostream& aStream, bool aVerbose) const
       
    80 	{
       
    81 	aStream << static_cast<int>(iHours)		<< L":"; 
       
    82 	aStream << static_cast<int>(iMinutes)	<< L":";
       
    83 	aStream << static_cast<int>(iSeconds);
       
    84 	}
       
    85 
       
    86 
       
    87 #ifdef GENERATE_ERRORS
       
    88 void CSISTime::CreateDefects ()
       
    89 	{
       
    90 	if (CSISFieldRoot::IsBugToBeCreated (CSISFieldRoot::EBugInvalidValues))
       
    91 		{
       
    92 		iHours = rand ();
       
    93 		}
       
    94 	if (CSISFieldRoot::IsBugToBeCreated (CSISFieldRoot::EBugInvalidValues))
       
    95 		{
       
    96 		iMinutes = rand ();
       
    97 		}
       
    98 	if (CSISFieldRoot::IsBugToBeCreated (CSISFieldRoot::EBugInvalidValues))
       
    99 		{
       
   100 		iSeconds = rand ();
       
   101 		}
       
   102 	}
       
   103 #endif // GENERATE_ERRORS
       
   104