persistentstorage/sqlite3api/TEST/t_sqlitetclstarter.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
child 25 047f208ea78f
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <e32uid.h>
       
    18 #include <f32file.h>
       
    19 #include <bautils.h>
       
    20 
       
    21 
       
    22 ///////////////////////////////////////////////////////////////////////////////////////
       
    23 
       
    24 RTest TheTest(_L("t_sqlitetclstarter"));
       
    25 
       
    26 _LIT(KTclExecutableName,"tclsqlite3.exe");
       
    27 _LIT(KTclScriptName,"all.test");
       
    28 
       
    29 _LIT(KStdioConfigFilePath,	"C:\\system\\data\\");
       
    30 _LIT(KStdioConfigFile,	"C:\\system\\data\\config.ini");
       
    31 
       
    32 _LIT(KLogsFilePath, "C:\\logs\\testexecute\\");
       
    33 
       
    34 RFs theFs;
       
    35 
       
    36 ///////////////////////////////////////////////////////////////////////////////////////
       
    37 
       
    38 //
       
    39 // Creates the appropriate stdio ini file to redirect stdio output to a file 
       
    40 //
       
    41 
       
    42 void CreateIniFileForStdoutRedirection(void)
       
    43 	{
       
    44 	TInt err(KErrNone);
       
    45 
       
    46 	// check path exists otherwise create
       
    47 	if (!BaflUtils::FolderExists(theFs, KStdioConfigFilePath))
       
    48 		{
       
    49 		err = theFs.MkDirAll(KStdioConfigFilePath);
       
    50 		TheTest(err == KErrNone, __LINE__);
       
    51 		}
       
    52 
       
    53 	
       
    54 	// create file
       
    55 	RFile file;
       
    56 	err = file.Create(theFs, KStdioConfigFile, EFileRead | EFileWrite);	
       
    57 	TheTest(err == KErrNone, __LINE__);
       
    58 
       
    59 	TheTest(KErrNone == file.Write(_L8("[STDIO]\r\n")), __LINE__);
       
    60 	TheTest(KErrNone == file.Write(_L8("STDIN = MEDIA1\r\n")), __LINE__);
       
    61 	TheTest(KErrNone == file.Write(_L8("STDOUT = MEDIA2\r\n")), __LINE__);
       
    62 	TheTest(KErrNone == file.Write(_L8("[MEDIA1]\r\n")), __LINE__);
       
    63 	TheTest(KErrNone == file.Write(_L8("type = console\r\n")), __LINE__);
       
    64 	TheTest(KErrNone == file.Write(_L8("width = -1\r\n")), __LINE__);
       
    65 	TheTest(KErrNone == file.Write(_L8("height = -1\r\n")), __LINE__);
       
    66 	TheTest(KErrNone == file.Write(_L8("[MEDIA2]\r\n")), __LINE__);
       
    67 	TheTest(KErrNone == file.Write(_L8("type = file\r\n")), __LINE__);
       
    68 	TheTest(KErrNone == file.Write(_L8("path = C:\\logs\\testexecute\\t_sqlitetclstarter.htm\r\n")), __LINE__);
       
    69 	TheTest(KErrNone == file.Flush(),__LINE__);
       
    70 
       
    71 	file.Close();
       
    72 
       
    73 	}
       
    74 
       
    75 ///////////////////////////////////////////////////////////////////////////////////////
       
    76 
       
    77 //
       
    78 // Deletes the stdio ini file
       
    79 //
       
    80 
       
    81 void DeleteIniFileForStdoutRedirection(void)
       
    82 	{
       
    83 	TInt err = theFs.Delete(KStdioConfigFile);
       
    84 	TheTest(err == KErrNone || err==KErrNotFound || err==KErrPathNotFound, __LINE__);
       
    85 	}
       
    86 
       
    87 ///////////////////////////////////////////////////////////////////////////////////////
       
    88 
       
    89 //
       
    90 // Ensure the directory for the Logs file exists
       
    91 //
       
    92 
       
    93 void EnsureLogsDirectoryExists(void)
       
    94 	{
       
    95 	TInt err(KErrNone);
       
    96 
       
    97 	// check path exists otherwise create
       
    98 	if (!BaflUtils::FolderExists(theFs, KLogsFilePath))
       
    99 		{
       
   100 		err = theFs.MkDirAll(KLogsFilePath);
       
   101 		TheTest(err == KErrNone, __LINE__);
       
   102 		}
       
   103 	}
       
   104 
       
   105 ///////////////////////////////////////////////////////////////////////////////////////
       
   106 
       
   107 //
       
   108 // Start the tcl process with a script
       
   109 //
       
   110 
       
   111 void StartTclProcess(void)
       
   112 	{
       
   113 	RProcess process;
       
   114 	TInt err = process.Create(KTclExecutableName,KTclScriptName);
       
   115 	TheTest(err==KErrNone, __LINE__);
       
   116 	
       
   117 	TRequestStatus processStatus;
       
   118 	process.Logon(processStatus);
       
   119 
       
   120 	process.Resume();
       
   121 
       
   122 	TheTest.Printf(_L("Wait for TCL tests to finish\r\n"));
       
   123 
       
   124 	User::WaitForRequest(processStatus);
       
   125 
       
   126 	TheTest.Printf(_L("TCL tests finished %d\r\n"),processStatus.Int());
       
   127 
       
   128 	TheTest(processStatus.Int() == KErrNone, __LINE__);
       
   129 	}
       
   130 
       
   131 ///////////////////////////////////////////////////////////////////////////////////////
       
   132 
       
   133 TInt E32Main()
       
   134 	{
       
   135 	TheTest.Title();
       
   136 	TheTest.Start(_L("TCL tests"));
       
   137 
       
   138 	CTrapCleanup* tc = CTrapCleanup::New();
       
   139 	
       
   140 	__UHEAP_MARK;
       
   141 	
       
   142 	TInt err = theFs.Connect();
       
   143 	TheTest(err == KErrNone, __LINE__);
       
   144 
       
   145 	DeleteIniFileForStdoutRedirection();
       
   146 
       
   147 	CreateIniFileForStdoutRedirection();
       
   148 
       
   149 	EnsureLogsDirectoryExists();
       
   150 
       
   151 	StartTclProcess();
       
   152 
       
   153 	DeleteIniFileForStdoutRedirection();
       
   154 
       
   155 	theFs.Close();
       
   156 
       
   157 	__UHEAP_MARKEND;
       
   158 	
       
   159 	TheTest.End();
       
   160 	TheTest.Close();
       
   161 	
       
   162 	delete tc;
       
   163 	
       
   164 	User::Heap().Check();
       
   165 	return KErrNone;
       
   166 	}