genericopenlibs/posixrealtimeextensions/test/testcapclock/src/tcapclockblocks.cpp
changeset 31 ce057bb09d0b
parent 0 e4d67989cc36
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 
       
     2 // Copyright (c) 2008-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 "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 // Name        : tcapclockblocks.cpp
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "tcapclock.h"
       
    20 
       
    21 // -----------------------------------------------------------------------------
       
    22 // CTesttrapsignal::Testcapclocksettime1()
       
    23 // 
       
    24 // API tested: clock_settime()
       
    25 // Description: Capability test for clock_settime()
       
    26 // -----------------------------------------------------------------------------
       
    27 
       
    28 TInt Ctestcapclock::Testcapclocksettime1()
       
    29 	{
       
    30 	int ret, ret1 = KErrGeneral;
       
    31 	clockid_t clockid;
       
    32 	struct timespec stmspec, gtmspec;
       
    33 	ret = clock_getcpuclockid(0,&clockid);
       
    34 	if (ret != 0)
       
    35 		{
       
    36 	 	ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
       
    37 	 	goto close;	
       
    38 		}
       
    39 	stmspec.tv_sec = 2;
       
    40 	stmspec.tv_nsec = 100000;
       
    41 	ret = clock_settime(clockid,&stmspec);
       
    42 	if (ret != 0)
       
    43 		{
       
    44 	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
       
    45 	 	return errno;	
       
    46 		}	
       
    47 	INFO_PRINTF1(_L("clock_settime() successfully able to set the time") );
       
    48 	ret = clock_gettime(clockid,&gtmspec);
       
    49 	if (ret != 0)
       
    50 		{
       
    51 	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
       
    52 	 	goto close;	
       
    53 		}
       
    54 	if (gtmspec.tv_sec < stmspec.tv_sec)
       
    55 		{
       
    56 	 	ERR_PRINTF2(_L("Failed to retrieve resolution of the clock id specified and errno is %d"),errno);
       
    57 	 	goto close;			
       
    58 		}
       
    59 	INFO_PRINTF1(_L("clock_gettime() successfully able to get the time") );
       
    60 	ret1 = KErrNone;
       
    61 	
       
    62 	close:
       
    63 	return ret1;	
       
    64 	}
       
    65 
       
    66 //End of file