mmappcomponents/asxparser/test/test.cpp
changeset 0 a2952bb97e68
child 2 7a9a8e73f54b
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Simple v2/v3 ASX-fileparser
       
    15  *
       
    16 */
       
    17 
       
    18 // Version : %version: 5 %
       
    19 
       
    20 
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32cons.h>
       
    24 #include <AsxParser.h>
       
    25 
       
    26 #include <e32svr.h>
       
    27 #include <e32def.h>
       
    28 #include <flogger.h>
       
    29 
       
    30 #include <utf.h>
       
    31 
       
    32 void PrintUrl( TPtrC8 aUrl )
       
    33 {
       
    34     HBufC16* urlBuffer = HBufC16::NewL(100);
       
    35     TPtr16   url = urlBuffer->Des();
       
    36 
       
    37     CnvUtfConverter::ConvertToUnicodeFromUtf8(url,aUrl);
       
    38     RDebug::Print(_L("#MP# TestAsx url=%S"),&url);
       
    39 
       
    40     delete urlBuffer;
       
    41 }
       
    42 
       
    43 
       
    44 void DoTest( CConsoleBase* /*aConsole*/ )
       
    45 {
       
    46     CAsxParser* parser;
       
    47 
       
    48     RDebug::Print(_L("#MP# TestAsx Test 1"));
       
    49     {
       
    50         _LIT(KFile,"c:\\test.asx");
       
    51         parser = CAsxParser::NewL(KFile);
       
    52         TUint i = 0;
       
    53         parser->GetUrlCount(i);
       
    54         __ASSERT_DEBUG(i == 2,1);
       
    55         TPtrC8 url;
       
    56         parser->GetUrl(1,url);
       
    57         PrintUrl(url);
       
    58         parser->GetUrl(2,url);
       
    59         PrintUrl(url);
       
    60         delete parser;
       
    61     }
       
    62 
       
    63     RDebug::Print(_L("#MP# TestAsx Test 2"));
       
    64     {
       
    65         _LIT(KFile,"c:\\test2.asx");
       
    66         parser = CAsxParser::NewL(KFile);
       
    67         TUint i = 0;
       
    68         parser->GetUrlCount(i);
       
    69         __ASSERT_DEBUG(i == 2,1);
       
    70         TPtrC8 url;
       
    71         TPtrC16 url2;
       
    72         parser->GetUrl(1,url);
       
    73         PrintUrl(url);
       
    74         parser->GetUrl(2,url);
       
    75         PrintUrl(url);
       
    76         delete parser;
       
    77     }
       
    78 
       
    79     RDebug::Print(_L("#MP# TestAsx Test 3"));
       
    80     {
       
    81         _LIT(KFile,"c:\\Corrupttest.asx");
       
    82         parser = CAsxParser::NewL(KFile);
       
    83         TUint i = 0;
       
    84         parser->GetUrlCount(i);
       
    85         __ASSERT_DEBUG(i == 0,1);
       
    86         TPtrC8 url;
       
    87         TPtrC16 url2;
       
    88         parser->GetUrl(1,url);
       
    89         PrintUrl(url);
       
    90         delete parser;
       
    91     }
       
    92 
       
    93     RDebug::Print(_L("#MP# TestAsx Test 4"));
       
    94     {
       
    95         _LIT(KFile,"c:\\Corrupttest2.asx");
       
    96         parser = CAsxParser::NewL(KFile);
       
    97         TUint i = 0;
       
    98         parser->GetUrlCount(i);
       
    99         __ASSERT_DEBUG(i == 1,1);
       
   100         TPtrC8 url;
       
   101         TPtrC16 url2;
       
   102         parser->GetUrl(1,url);
       
   103         PrintUrl(url);
       
   104         delete parser;
       
   105     }
       
   106 }
       
   107 
       
   108 void DoExampleL()
       
   109 {
       
   110     CConsoleBase* console;
       
   111 
       
   112     //
       
   113     //  Make the console and push it on the cleanup stack.
       
   114     //
       
   115     console = Console::NewL(_L("Console"), TSize( KConsFullScreen, KConsFullScreen));
       
   116     CleanupStack::PushL(console);
       
   117     DoTest(console);
       
   118     CleanupStack::PopAndDestroy(console);
       
   119 }
       
   120 
       
   121 TInt E32Main()
       
   122 {
       
   123     __UHEAP_MARK;
       
   124     //Create a cleanup stack
       
   125     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   126     //Call some Leaving methods inside TRAP
       
   127     TRAPD(error, DoExampleL());
       
   128     __ASSERT_ALWAYS(!error, User::Panic(_L("Hello"), error));
       
   129     //Destroy cleanup stack
       
   130     delete cleanup;
       
   131     __UHEAP_MARKEND;
       
   132     return 0;
       
   133 }