summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/t_launchTest.cpp
blob: 4ec0d08364eb377515b0b7646a81345b18d9b8e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
// Contact: http://www.qt-project.org/legal
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
//

// INCLUDE FILES
#include <t_launchTest.h>

void DoTestsL()
    {
    CLog* loger; 
    RTest test(_L("T_LaunchTest"));
    TInt blankLoc;
    TBuf<100> appName( 0 );
    TBuf<200> parameters( 0 );
    TBuf<200> tempStr( 0 );
    RFile fileread;
    TFileText tf;
    RFs fsSession;
    TUidType uidtype( KNullUid );
    _LIT(KFileNameRead, "C:\\data\\cm_all_tests.bat");
    _LIT(KLogFileName,"t_launchTest.log");
    
    // New loger    
    loger = CLog::NewL( test, KLogFileName );
    CleanupStack::PushL( loger );

    // New process control
    RProcess* process = new RProcess();
    CleanupStack::PushL( process );
    loger->LogLine(
        _L("Run auto testing for contacts model.[cm_all_tests.bat]") );

    // Open cm_all_tests.bat
    User::LeaveIfError( fsSession.Connect() );
    CleanupClosePushL( fsSession );
    User::LeaveIfError( fileread.Open( fsSession, KFileNameRead, EFileStream
        | EFileRead ) );
    CleanupClosePushL( fileread );
    tf.Set( fileread );
    loger->LogLine( _L("Runing:") );

    // Read the testing cases from cm_all_tests.bat and run it.
    for (; KErrNone == tf.Read( tempStr ); )
        {
        if ( tempStr.Length() <= 0 )
            {
            loger->LogLine( _L("Blank line: No Program ") );
            continue;
            }
        // Analyze the command format   
        appName.Copy( _L("z:\\sys\\bin\\") );
        tempStr.TrimAll();
        blankLoc = tempStr.Locate( ' ' );
        if ( 0 > blankLoc )
            {
            // No parameters.
            appName.Append( tempStr );
            parameters = _L( "" );
            }
        else
            {
            // Store parameters.
            appName.Append( tempStr.Left( blankLoc ) );
            parameters = tempStr.Mid( blankLoc + 1 );
            }
        appName.Append( _L(".exe") );
        loger->LogLine( tempStr );

        // Run the command.
        TInt err = process->Create( appName, parameters, uidtype );
        if ( KErrNone != err )
            {
            tempStr.Format( _L("Not Found %S "), &appName );
            loger->LogLine( tempStr );
            continue;
            }
        TRequestStatus status( KRequestPending );
        process->Rendezvous( status );
        process->Resume();
        User::WaitForRequest( status );
        TExitType type = process->ExitType();
        TBuf<200> buf = process->ExitCategory();
        buf.AppendFormat( _L(": process->ExitType %d "), type );
        loger->LogLine( buf );
        process->Close();
        User::After( 1000000 );
        }
    fileread.Close();
    fsSession.Close();
    loger->LogLine( _L("Print any key to exit:"));
    test.Close();
    CleanupStack::PopAndDestroy( 4 ); // fileread, process, fsSession, loger
    }
    


int main( void )
    {
    __UHEAP_MARK;
    TRAPD(err,DoTestsL());
    __UHEAP_MARKEND;
    return KErrNone;
    }