1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/test/test-automate/test-automate.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,146 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +#include <e32base.h>
1.21 +#include <e32cmn.h>
1.22 +#include <f32file.h>
1.23 +
1.24 +#include <stdio.h>
1.25 +
1.26 +#ifndef __EPOC32__
1.27 +_LIT(KConfigPath,"c:\\System\\Data\\stdcpp_runtest.ini");
1.28 +#else
1.29 +_LIT(KConfigPath,"z:\\System\\Data\\stdcpp_runtest.ini");
1.30 +#endif // __EPOC32__
1.31 +
1.32 +TInt ReadConfig(TLex8& aTlex);
1.33 +TInt RunProcess(TDesC8& achild, TDesC16& aParam, TInt aTimer);
1.34 +
1.35 +
1.36 +TInt E32Main()
1.37 +{
1.38 + TLex8 aTLex;
1.39 + TInt ret;
1.40 + TBuf8<50> child;
1.41 + ret = ReadConfig(aTLex);
1.42 + if(ret)
1.43 + {
1.44 + printf("Failed to Read with Error value %d\n", ret);
1.45 + return -1;
1.46 + }
1.47 + return 0;
1.48 +}
1.49 +
1.50 +
1.51 +TInt ReadConfig(TLex8& aTLex)
1.52 +{
1.53 +
1.54 + TBuf8<5400> data;
1.55 + TInt ret = 0;
1.56 + RFs aRfs;
1.57 + RFile aRfile;
1.58 + TInt asize;
1.59 + TInt tmp, iGiveAwaySum;
1.60 +
1.61 + ret = aRfs.Connect();
1.62 +
1.63 + if(KErrNone != ret )
1.64 + {
1.65 + printf("Failure to connect to the file server\n");
1.66 + return ret;
1.67 + }
1.68 + ret = aRfile.Open(aRfs,KConfigPath,EFileRead);
1.69 +
1.70 + if(KErrNone != ret )
1.71 + {
1.72 + printf("Failure to open the file\n");
1.73 + return ret;
1.74 + }
1.75 + ret = aRfile.Size(asize);
1.76 +
1.77 + if(ret != KErrNone)
1.78 + {
1.79 + printf("File with no size\n");
1.80 + return ret;
1.81 + }
1.82 +
1.83 + if(0 == asize )
1.84 + {
1.85 + printf("File with no size\n");
1.86 + return ret;
1.87 + }
1.88 +
1.89 + ret = aRfile.Read(data, asize);
1.90 + if(ret != KErrNone)
1.91 + {
1.92 + printf("Cannot read the complete file\n");
1.93 + return ret;
1.94 + }
1.95 + aTLex.Assign(data);
1.96 + TChar chr;
1.97 + TBuf8<50> copybuf;
1.98 + TBuf16<50> copybuf1;
1.99 + while (!aTLex.Eos())
1.100 + {
1.101 + TPtrC8 nexttoken = aTLex.NextToken();
1.102 + copybuf.Copy(nexttoken);
1.103 + TPtrC8 adata = aTLex.NextToken();
1.104 + TLex8 numLexer(adata);
1.105 + if (numLexer.Val(tmp) == KErrNone)
1.106 + {
1.107 + iGiveAwaySum = tmp;
1.108 + }
1.109 + else
1.110 + {
1.111 + //nada
1.112 + }
1.113 + TPtrC8 nexttoken1 = aTLex.NextToken();
1.114 + copybuf1.Copy(nexttoken1);
1.115 + RunProcess(copybuf, copybuf1, tmp);
1.116 + }
1.117 + return ret;
1.118 +}
1.119 +
1.120 +
1.121 +TInt RunProcess(TDesC8& achild, TDesC16& aparam, TInt atimer)
1.122 +{
1.123 + TFileName childpath;
1.124 + childpath.Copy(achild);
1.125 + TInt ret = 0;
1.126 + RProcess process;
1.127 + TRequestStatus processstatus, timerstatus;
1.128 + ret = process.Create(childpath, aparam);
1.129 + process.Resume();
1.130 + process.Logon(processstatus);
1.131 + RTimer timeout;
1.132 + timeout.CreateLocal();
1.133 + timeout.After(timerstatus, atimer*1000000);
1.134 + User::WaitForRequest(processstatus, timerstatus);
1.135 + if (processstatus == KRequestPending)
1.136 + {
1.137 + process.LogonCancel(processstatus);
1.138 + process.Kill(KErrTimedOut);
1.139 + }
1.140 + else
1.141 + {
1.142 + timeout.Cancel();
1.143 + }
1.144 + process.Close();
1.145 + timeout.Close();
1.146 + return 0;
1.147 +
1.148 +}
1.149 +