messagingappbase/smilparser/SMILdtd/tsrc/t_SmilDom.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2001-2009 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 // Name of test harness: T_SMIL_DOM
       
    15 // Input file required to run test harness:
       
    16 // \epoc32\wins\c\MsgTest\SMIL_DOM\script.txt
       
    17 // Output file produced by running test harness:
       
    18 // \epoc32\wins\c\MsgTest\SMIL_DOM\SmilDomLog.txt
       
    19 // This script driven test harness tests the SMIL DOM classes. Tree navigation, and attribute
       
    20 // getting and setting methods can be exercised by means of script commands. The test harness
       
    21 // uses the concepts of the current element in a DOM tree, and the numeric position of a
       
    22 // child element, in its child list. It logs results (including errors) for verification.
       
    23 // The test harness may be used to perform the following tests:
       
    24 // Exercise of each of the element creation and navigation routines. Each routine may be
       
    25 // exercised in a valid way and also, where applicable, in invalid ways (for example, inserting
       
    26 // before non-existent elements in a list).
       
    27 // Simple attributes (e.g. id) can be used to check position during navigation. Elements should
       
    28 // have their ids set when they are created, and various navigational paths taken to elements
       
    29 // with known ids.
       
    30 // Note that the harness is allowed to fail, if it is given a script containing errors; so not
       
    31 // a lot of work has gone into handling errors.
       
    32 // 
       
    33 //
       
    34 
       
    35 
       
    36 #include "t_TestScript.h"
       
    37 #include "t_ScriptRunner.h"
       
    38 #include <e32test.h>
       
    39 #include <e32std.h>
       
    40 #include <f32file.h>
       
    41 
       
    42 
       
    43 // This is used if we can't find MsgLogs anywhere
       
    44 _LIT(KMsvTestFileDefaultOutputBase, "C:\\MsgLogs\\");
       
    45 _LIT(KMsvPathSep, "\\");
       
    46 _LIT(KMsvTestFileInputBase, "MsgTest");
       
    47 _LIT(KMsvTestFileOutputBase, "MsgLogs");
       
    48 
       
    49 
       
    50 TInt ResolveFile(RFs& aFs, const TDesC& aComponent, const TDesC& aFileName, TParse& aParseOut)
       
    51 	{
       
    52 	TFileName* savedPath = new TFileName;
       
    53 	TFileName* fileName = new TFileName;
       
    54 
       
    55 	if ((savedPath == NULL) || (fileName == NULL))
       
    56 		{
       
    57 		return KErrNoMemory;
       
    58 		}
       
    59 
       
    60 	fileName->Append(KMsvPathSep);
       
    61 	fileName->Append(KMsvTestFileInputBase);
       
    62 	fileName->Append(KMsvPathSep);
       
    63 	fileName->Append(aComponent);
       
    64 	fileName->Append(KMsvPathSep);
       
    65 	fileName->Append(aFileName);
       
    66 
       
    67 	// File finder will look in the session drive first, then Y->A,Z
       
    68 	// so set session drive to Y (save old, and restore it afterwards).
       
    69 	aFs.SessionPath(*savedPath);
       
    70 	_LIT(KTopDrive, "Y:\\");
       
    71 	aFs.SetSessionPath(KTopDrive);
       
    72 	TFindFile file_finder(aFs);
       
    73 	TInt err = file_finder.FindByDir(*fileName, KNullDesC);
       
    74 
       
    75 	if (err == KErrNone)
       
    76 		{
       
    77 		aParseOut.Set(file_finder.File(), NULL, NULL);
       
    78 		}
       
    79 
       
    80 	aFs.SetSessionPath(*savedPath);
       
    81 	delete savedPath;
       
    82 	delete fileName;
       
    83 	return (err);
       
    84 	}
       
    85 
       
    86 
       
    87 //
       
    88 //
       
    89 // Main Test Harness
       
    90 //
       
    91 
       
    92 LOCAL_D CTrapCleanup* theCleanup;
       
    93 
       
    94 
       
    95 void doMainL()
       
    96 	{
       
    97 	RTest test(_L("SMIL DOM tests"));
       
    98 	RFs fs;
       
    99 	fs.Connect();
       
   100 
       
   101 	CTestScript* script = CTestScript::NewL(fs);
       
   102 	CleanupStack::PushL(script);
       
   103 	TParse scriptFileName;
       
   104 
       
   105 	TInt err = ResolveFile(fs, _L("SMIL_DOM"), _L("script.txt"), scriptFileName);
       
   106 
       
   107 	if (err != KErrNone)
       
   108 		{
       
   109 		// This should report unable to load file
       
   110 		}
       
   111 
       
   112 	script->LoadFileL(scriptFileName.FullName());
       
   113 
       
   114 	CScriptRunner* scriptRunner = CScriptRunner::NewL();
       
   115 	CleanupStack::PushL(scriptRunner);
       
   116 
       
   117 	TBuf8<128> line;
       
   118 	TBuf<128> uniLine;
       
   119 	while (script->GetLineL(line))
       
   120 		{
       
   121 		uniLine.Copy(line);
       
   122 		scriptRunner->ParseL(uniLine);
       
   123 		}
       
   124 
       
   125 	CleanupStack::PopAndDestroy(scriptRunner);
       
   126 	CleanupStack::PopAndDestroy(script);
       
   127 
       
   128 	fs.Close();
       
   129 	test.Close();
       
   130 	}
       
   131 
       
   132 
       
   133 GLDEF_C TInt E32Main()
       
   134 	{
       
   135 	__UHEAP_MARK;
       
   136 	theCleanup = CTrapCleanup::New();
       
   137 
       
   138 	TRAPD(ret, doMainL());
       
   139 
       
   140 	delete theCleanup;
       
   141 	__UHEAP_MARKEND;
       
   142 	User::Heap().Check();
       
   143 	return (KErrNone);
       
   144 	}
       
   145