| 
sl@0
 | 
     1  | 
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
  | 
| 
sl@0
 | 
     2  | 
// All rights reserved.
  | 
| 
sl@0
 | 
     3  | 
// This component and the accompanying materials are made available
  | 
| 
sl@0
 | 
     4  | 
// under the terms of "Eclipse Public License v1.0"
  | 
| 
sl@0
 | 
     5  | 
// which accompanies this distribution, and is available
  | 
| 
sl@0
 | 
     6  | 
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
  | 
| 
sl@0
 | 
     7  | 
//
  | 
| 
sl@0
 | 
     8  | 
// Initial Contributors:
  | 
| 
sl@0
 | 
     9  | 
// Nokia Corporation - initial contribution.
  | 
| 
sl@0
 | 
    10  | 
//
  | 
| 
sl@0
 | 
    11  | 
// Contributors:
  | 
| 
sl@0
 | 
    12  | 
//
  | 
| 
sl@0
 | 
    13  | 
// Description:
  | 
| 
sl@0
 | 
    14  | 
//
  | 
| 
sl@0
 | 
    15  | 
  | 
| 
sl@0
 | 
    16  | 
#define MY_STRINGPOOL pool
  | 
| 
sl@0
 | 
    17  | 
  | 
| 
sl@0
 | 
    18  | 
#include <e32std.h>
  | 
| 
sl@0
 | 
    19  | 
#include <e32test.h>
  | 
| 
sl@0
 | 
    20  | 
#include <f32file.h>
  | 
| 
sl@0
 | 
    21  | 
#include <WapTestUtils.h>
  | 
| 
sl@0
 | 
    22  | 
#include "http.h"
  | 
| 
sl@0
 | 
    23  | 
  | 
| 
sl@0
 | 
    24  | 
LOCAL_D CWapTestHarness* testHarness;
  | 
| 
sl@0
 | 
    25  | 
  | 
| 
sl@0
 | 
    26  | 
_LIT(KTitleStr, "HTTP String Pool Test Harness");
  | 
| 
sl@0
 | 
    27  | 
_LIT8(KHello, "hello");
  | 
| 
sl@0
 | 
    28  | 
_LIT8(KHello1, "hello");
  | 
| 
sl@0
 | 
    29  | 
_LIT8(KGoodbye, "goodbye");
  | 
| 
sl@0
 | 
    30  | 
const void* tableContent[] = { (const void*)&KHello,
 | 
| 
sl@0
 | 
    31  | 
											  (const void*)&KGoodbye};
  | 
| 
sl@0
 | 
    32  | 
  | 
| 
sl@0
 | 
    33  | 
const static TStringTable table = { 2,&tableContent[0]};
 | 
| 
sl@0
 | 
    34  | 
  | 
| 
sl@0
 | 
    35  | 
class CHTTPTest : public CBase
  | 
| 
sl@0
 | 
    36  | 
	{
 | 
| 
sl@0
 | 
    37  | 
public:
  | 
| 
sl@0
 | 
    38  | 
	static CHTTPTest* NewL();
  | 
| 
sl@0
 | 
    39  | 
	void DoTestsL();
  | 
| 
sl@0
 | 
    40  | 
	};
  | 
| 
sl@0
 | 
    41  | 
  | 
| 
sl@0
 | 
    42  | 
CHTTPTest* CHTTPTest::NewL()
  | 
| 
sl@0
 | 
    43  | 
	{
 | 
| 
sl@0
 | 
    44  | 
	return new (ELeave) CHTTPTest;
  | 
| 
sl@0
 | 
    45  | 
	}
  | 
| 
sl@0
 | 
    46  | 
  | 
| 
sl@0
 | 
    47  | 
void CHTTPTest::DoTestsL()
  | 
| 
sl@0
 | 
    48  | 
	{
 | 
| 
sl@0
 | 
    49  | 
  | 
| 
sl@0
 | 
    50  | 
	testHarness->StartTestL(_L("Creating the string pool"));
 | 
| 
sl@0
 | 
    51  | 
	RStringPool pool;
  | 
| 
sl@0
 | 
    52  | 
	pool.OpenL(table);
  | 
| 
sl@0
 | 
    53  | 
	testHarness->EndTest(0);
  | 
| 
sl@0
 | 
    54  | 
	testHarness->StartTestL(_L("Creating 'hello'"));
 | 
| 
sl@0
 | 
    55  | 
	STRDCI_L(hello, KHello);
  | 
| 
sl@0
 | 
    56  | 
	RStringF def;
  | 
| 
sl@0
 | 
    57  | 
	testHarness->EndTest(hello == def);
  | 
| 
sl@0
 | 
    58  | 
	testHarness->StartTestL(_L("Creating another 'hello'"));
 | 
| 
sl@0
 | 
    59  | 
	ASTRDCI_L(hello1, KHello1);
  | 
| 
sl@0
 | 
    60  | 
	testHarness->EndTest(!(hello == hello1.iObj));
  | 
| 
sl@0
 | 
    61  | 
	testHarness->StartTestL(_L("Testing !="));
 | 
| 
sl@0
 | 
    62  | 
	testHarness->EndTest(hello != hello1.iObj);
  | 
| 
sl@0
 | 
    63  | 
	testHarness->StartTestL(_L("Creating 'goodbye'"));
 | 
| 
sl@0
 | 
    64  | 
	STRDCI_L(goodbye, KGoodbye);
  | 
| 
sl@0
 | 
    65  | 
	testHarness->EndTest(hello == goodbye);
  | 
| 
sl@0
 | 
    66  | 
	testHarness->StartTestL(_L("Creating string tokens"));
 | 
| 
sl@0
 | 
    67  | 
	RStringTokenF h1, h2(hello), g;
  | 
| 
sl@0
 | 
    68  | 
	h1 = hello;
  | 
| 
sl@0
 | 
    69  | 
	testHarness->EndTest(h1 != h2);
  | 
| 
sl@0
 | 
    70  | 
	testHarness->StartTestL(_L("Testing == on string tokens"));
 | 
| 
sl@0
 | 
    71  | 
	testHarness->EndTest(!(h1 == h2));
  | 
| 
sl@0
 | 
    72  | 
	testHarness->StartTestL(_L("Making a string from a token"));
 | 
| 
sl@0
 | 
    73  | 
	hello1.iObj =  pool.StringF(h1);
  | 
| 
sl@0
 | 
    74  | 
	testHarness->EndTest(hello != hello1.iObj);
  | 
| 
sl@0
 | 
    75  | 
	testHarness->StartTestL(_L("Non-equal tokens"));
 | 
| 
sl@0
 | 
    76  | 
	g = goodbye;
  | 
| 
sl@0
 | 
    77  | 
	testHarness->EndTest(hello == goodbye);
  | 
| 
sl@0
 | 
    78  | 
	testHarness->StartTestL(_L("Operator != on non-equal tokens"));
 | 
| 
sl@0
 | 
    79  | 
	testHarness->EndTest(!(hello != goodbye));
  | 
| 
sl@0
 | 
    80  | 
	testHarness->StartTestL(_L("Copy function"));
 | 
| 
sl@0
 | 
    81  | 
	hello1.iObj = hello.Copy();
  | 
| 
sl@0
 | 
    82  | 
	testHarness->EndTest(hello != hello1.iObj);
  | 
| 
sl@0
 | 
    83  | 
	testHarness->StartTestL(_L("String extraction (same)"));
 | 
| 
sl@0
 | 
    84  | 
	testHarness->EndTest(static_cast<const TDesC8&>(hello).Compare(hello1.iObj));
  | 
| 
sl@0
 | 
    85  | 
	testHarness->StartTestL(_L("String extraction (different)"));
 | 
| 
sl@0
 | 
    86  | 
	testHarness->EndTest(!static_cast<const TDesC8&>(hello).Compare(goodbye));
  | 
| 
sl@0
 | 
    87  | 
	testHarness->StartTestL(_L("String extraction (original)"));
 | 
| 
sl@0
 | 
    88  | 
	testHarness->EndTest(static_cast<const TDesC8&>(hello).Compare(KHello));
  | 
| 
sl@0
 | 
    89  | 
	testHarness->StartTestL(_L("Closing pool"));
 | 
| 
sl@0
 | 
    90  | 
	hello.Copy();
  | 
| 
sl@0
 | 
    91  | 
	hello.Close();
  | 
| 
sl@0
 | 
    92  | 
	hello.Close();
  | 
| 
sl@0
 | 
    93  | 
	hello1.iObj.Close();
  | 
| 
sl@0
 | 
    94  | 
	// The copys here have got a bit confused
  | 
| 
sl@0
 | 
    95  | 
	hello1.iObj.Close();
  | 
| 
sl@0
 | 
    96  | 
	goodbye.Close();
  | 
| 
sl@0
 | 
    97  | 
	pool.CloseAll();
  | 
| 
sl@0
 | 
    98  | 
	testHarness->EndTest(0);	
  | 
| 
sl@0
 | 
    99  | 
	}
  | 
| 
sl@0
 | 
   100  | 
  | 
| 
sl@0
 | 
   101  | 
GLDEF_C void TestL()
  | 
| 
sl@0
 | 
   102  | 
	{
 | 
| 
sl@0
 | 
   103  | 
	testHarness = CWapTestHarness::NewLC(KTitleStr);
  | 
| 
sl@0
 | 
   104  | 
	// Set resource handle leak test
  | 
| 
sl@0
 | 
   105  | 
	testHarness->DoResourceLeakTest(ETrue);
  | 
| 
sl@0
 | 
   106  | 
	CHTTPTest* theTest = CHTTPTest::NewL();
  | 
| 
sl@0
 | 
   107  | 
	theTest->DoTestsL();
  | 
| 
sl@0
 | 
   108  | 
	delete theTest;
  | 
| 
sl@0
 | 
   109  | 
	CleanupStack::PopAndDestroy();	//	UrlTest, wapTest
  | 
| 
sl@0
 | 
   110  | 
	}
  | 
| 
sl@0
 | 
   111  | 
  | 
| 
sl@0
 | 
   112  | 
GLDEF_C TInt E32Main()
  | 
| 
sl@0
 | 
   113  | 
//
  | 
| 
sl@0
 | 
   114  | 
// Main function
  | 
| 
sl@0
 | 
   115  | 
	{
 | 
| 
sl@0
 | 
   116  | 
	__UHEAP_MARK;
  | 
| 
sl@0
 | 
   117  | 
	CTrapCleanup* tc=CTrapCleanup::New();
  | 
| 
sl@0
 | 
   118  | 
	TRAPD(err,TestL());
  | 
| 
sl@0
 | 
   119  | 
	if (err!=KErrNone)
  | 
| 
sl@0
 | 
   120  | 
		User::Panic(_L("TSTRING"),err);
 | 
| 
sl@0
 | 
   121  | 
	delete tc;
  | 
| 
sl@0
 | 
   122  | 
	__UHEAP_MARKEND;
  | 
| 
sl@0
 | 
   123  | 
	return KErrNone;
  | 
| 
sl@0
 | 
   124  | 
	}
  |