filehandling/htmltorichtextconverter/tsrc/loadconvertertest.cpp
changeset 0 2e3d3ce01487
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/filehandling/htmltorichtextconverter/tsrc/loadconvertertest.cpp	Tue Feb 02 10:12:00 2010 +0200
@@ -0,0 +1,137 @@
+// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// 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:
+// CHtmlToCrtConverter loading test code
+// 
+//
+
+#include <e32std.h>
+#include <e32test.h>
+#include <f32file.h>
+#include <e32math.h>
+
+#include <e32cons.h>
+
+#include <ecom/ecom.h>
+
+#include <confndr.h>
+#include <conlist.h>
+#include <concnf.h>
+#include "CHtmlToCrtConverter.h"
+
+_LIT(KTestName,"CHtmlToCrtConverter");
+_LIT(KTest1,"@SYMTestCaseID PIM-LOADCONVERTERTEST-0001 CHtmlToCrtConverter test");
+
+LOCAL_D RTest test(KTestName);
+
+//================================================================================
+//getPathL
+//================================================================================
+TBool getPathL(TDes& aPath, RFs& aFs)
+	{
+	// Generate the folder spec to search in
+	TFileName searchSpec;
+	TChar driveLetter = 'C';
+	searchSpec.Append(driveLetter);
+	searchSpec.Append(aPath);
+
+	CDir* entryList = NULL;
+	TFindFile finder(aFs);
+	TInt ret = finder.FindWildByPath(searchSpec, NULL, entryList);
+	if(ret<KErrNone)
+		{
+		//try z drive
+		driveLetter = 'Z';
+		searchSpec.Zero();
+		searchSpec.Append(driveLetter);
+		searchSpec.Append(aPath);
+		delete entryList;
+		entryList = NULL;
+
+		ret = finder.FindWildByPath(searchSpec, NULL, entryList);
+		if	(ret < KErrNone)
+			{
+			//path not found
+			delete entryList;
+			test.Printf(_L("files not found\n"));
+			return EFalse;
+			}
+		}
+
+	//set path
+	delete entryList;
+	aPath.Copy(searchSpec);
+	return ETrue;
+	}
+//==========================================================================
+//loadConverterL
+//==========================================================================
+void loadConverterL(TDesC& aSourceFile, TDesC& aTargetFile)
+	{
+	//get converter
+	CCnaConverterList* convList=CCnaConverterList::NewLC();
+	const TUid KUidCHtmlToCrtConverter = {0x1000a90e};
+	CConverterBase* conv = NULL;
+	conv = convList->NewConverterL(KUidCHtmlToCrtConverter);
+
+	if (conv)
+		{
+		CleanupStack::PushL(conv);
+		//do conversion
+		conv->ConvertL(aSourceFile, aTargetFile);	
+		CleanupStack::PopAndDestroy(); //conv
+		//output result
+		_LIT(KString,"%S");
+		test.Printf(KString,&(aSourceFile));
+		test.Printf(_L(" converted\n"));
+		}
+	CleanupStack::PopAndDestroy(convList);
+	}
+//==========================================================================
+
+/**
+@SYMTestCaseID PIM-LOADCONVERTERTEST-0001
+*/	
+void doMainL()
+	{
+	test.Start(KTest1);
+
+	RFs		fs;
+	fs.Connect();
+
+	TBufC<11> targetFile = (_L("target file"));
+	TBuf<100> sourceFile(_L(":\\testHtml\\LoadConverterTest.txt"));
+
+	if(getPathL(sourceFile, fs))
+		{
+		loadConverterL(sourceFile, targetFile);
+		}
+
+	REComSession::FinalClose(); //needed, otherwise you will get a memory leak
+	
+	test.End();
+	test.Close();
+	}
+
+GLDEF_C TInt E32Main()
+	{	
+	__UHEAP_MARK;
+
+	CTrapCleanup* theCleanup=CTrapCleanup::New();
+	TRAPD(ret,doMainL());	
+	test(ret==KErrNone);
+	delete theCleanup;	
+
+	__UHEAP_MARKEND;
+	return(KErrNone);
+	}