os/ossrv/genericopenlibs/cppstdlib/test/test-automate/test-automate.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
#include <e32base.h>
sl@0
    18
#include <e32cmn.h>
sl@0
    19
#include <f32file.h>
sl@0
    20
sl@0
    21
#include <stdio.h>
sl@0
    22
sl@0
    23
#ifndef __EPOC32__
sl@0
    24
_LIT(KConfigPath,"c:\\System\\Data\\stdcpp_runtest.ini");
sl@0
    25
#else
sl@0
    26
_LIT(KConfigPath,"z:\\System\\Data\\stdcpp_runtest.ini");
sl@0
    27
#endif // __EPOC32__
sl@0
    28
sl@0
    29
TInt ReadConfig(TLex8& aTlex);
sl@0
    30
TInt RunProcess(TDesC8& achild, TDesC16& aParam, TInt aTimer);
sl@0
    31
sl@0
    32
sl@0
    33
TInt E32Main()
sl@0
    34
{
sl@0
    35
	TLex8 aTLex;
sl@0
    36
	TInt ret;
sl@0
    37
	TBuf8<50> child;
sl@0
    38
	ret = ReadConfig(aTLex);
sl@0
    39
	if(ret)
sl@0
    40
	{
sl@0
    41
		printf("Failed to Read with Error value %d\n", ret);
sl@0
    42
		return -1;
sl@0
    43
	}
sl@0
    44
	return 0;	
sl@0
    45
}
sl@0
    46
sl@0
    47
sl@0
    48
TInt ReadConfig(TLex8& aTLex)
sl@0
    49
{
sl@0
    50
	
sl@0
    51
	TBuf8<5400> data;
sl@0
    52
	TInt 	ret = 0;
sl@0
    53
	RFs 	aRfs;
sl@0
    54
	RFile 	aRfile;
sl@0
    55
	TInt 	asize;
sl@0
    56
	TInt tmp, iGiveAwaySum;
sl@0
    57
	
sl@0
    58
	ret = aRfs.Connect();
sl@0
    59
	
sl@0
    60
	if(KErrNone != ret )
sl@0
    61
	{
sl@0
    62
		printf("Failure to connect to the file server\n");
sl@0
    63
		return ret;
sl@0
    64
	}
sl@0
    65
	ret = aRfile.Open(aRfs,KConfigPath,EFileRead);
sl@0
    66
	
sl@0
    67
	if(KErrNone != ret )
sl@0
    68
	{
sl@0
    69
		printf("Failure to open the file\n");
sl@0
    70
		return ret;
sl@0
    71
	}
sl@0
    72
	ret = aRfile.Size(asize);
sl@0
    73
	
sl@0
    74
	if(ret != KErrNone)
sl@0
    75
	{
sl@0
    76
		printf("File with no size\n");
sl@0
    77
		return ret;
sl@0
    78
	}
sl@0
    79
	
sl@0
    80
	if(0 == asize )
sl@0
    81
	{
sl@0
    82
		printf("File with no size\n");
sl@0
    83
		return ret;
sl@0
    84
	}
sl@0
    85
	
sl@0
    86
	ret = aRfile.Read(data, asize);
sl@0
    87
	if(ret != KErrNone)
sl@0
    88
		{
sl@0
    89
		printf("Cannot read the complete file\n");
sl@0
    90
		return ret;
sl@0
    91
		}
sl@0
    92
		aTLex.Assign(data);
sl@0
    93
		TChar chr;
sl@0
    94
		TBuf8<50> copybuf;
sl@0
    95
		TBuf16<50> copybuf1;
sl@0
    96
		while (!aTLex.Eos())
sl@0
    97
			{
sl@0
    98
			TPtrC8 nexttoken = aTLex.NextToken();
sl@0
    99
			copybuf.Copy(nexttoken);
sl@0
   100
			TPtrC8 adata = aTLex.NextToken();
sl@0
   101
			TLex8 numLexer(adata);			
sl@0
   102
			if (numLexer.Val(tmp) == KErrNone)
sl@0
   103
				{
sl@0
   104
				iGiveAwaySum = tmp;
sl@0
   105
				}
sl@0
   106
			else 
sl@0
   107
				{
sl@0
   108
				//nada		
sl@0
   109
				}
sl@0
   110
			TPtrC8 nexttoken1 = aTLex.NextToken();
sl@0
   111
			copybuf1.Copy(nexttoken1);
sl@0
   112
			RunProcess(copybuf, copybuf1, tmp);				
sl@0
   113
			}
sl@0
   114
	return ret;	
sl@0
   115
}
sl@0
   116
sl@0
   117
sl@0
   118
TInt RunProcess(TDesC8& achild, TDesC16& aparam, TInt atimer)
sl@0
   119
{
sl@0
   120
	TFileName childpath;
sl@0
   121
	childpath.Copy(achild);
sl@0
   122
	TInt ret = 0;
sl@0
   123
	RProcess process;
sl@0
   124
	TRequestStatus processstatus, timerstatus;
sl@0
   125
	ret = process.Create(childpath, aparam);
sl@0
   126
	process.Resume();
sl@0
   127
	process.Logon(processstatus);
sl@0
   128
	RTimer timeout;
sl@0
   129
	timeout.CreateLocal();
sl@0
   130
	timeout.After(timerstatus, atimer*1000000);
sl@0
   131
	User::WaitForRequest(processstatus, timerstatus);
sl@0
   132
	if (processstatus == KRequestPending)
sl@0
   133
		{
sl@0
   134
		process.LogonCancel(processstatus);
sl@0
   135
		process.Kill(KErrTimedOut);
sl@0
   136
		}
sl@0
   137
	else
sl@0
   138
		{
sl@0
   139
		timeout.Cancel();
sl@0
   140
		}
sl@0
   141
	process.Close();
sl@0
   142
	timeout.Close();
sl@0
   143
	return 0;
sl@0
   144
	
sl@0
   145
}
sl@0
   146