⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testurl.cpp

📁 Active Object实现动画
💻 CPP
字号:

#include <e32base.h>
#include <e32cons.h>

#include "AOExampleEngine.h"

class ConsoleForwarder : public CAOExampleEngine::MEngineObserver
    {
    public:

        ConsoleForwarder(CConsoleBase& aConsole) : iConsole(aConsole) {}

    public: // from CAOExampleEngine::MEngineObserver

        virtual void FileFetched(CBufBase* aContent);
        virtual void Cancelled(const TDesC& aReason);
        virtual void ToState(CAOExampleEngine::TStates aState);

    private:
        CConsoleBase& iConsole;
    };

void ConsoleForwarder::FileFetched(CBufBase* /*aContent*/)
    {
    }

void ConsoleForwarder::Cancelled(const TDesC& aReason)
    {
    iConsole.Printf( _L("\nCancelled: ") );
    iConsole.Printf( aReason );
    }

void ConsoleForwarder::ToState(CAOExampleEngine::TStates aState)
    {
    iConsole.Printf( _L("\nToState: %d"), aState );
    }

class TTestModel
    {
    public:
        TBool    iShouldFail;
        TUint16* iUrl;
        TUint16* iServer;
        TInt     iPort;
        TUint16* iDocument;
    };

static const TTestModel tests[]=
    {
        { 0, L"http://www.google.fi/", L"www.google.fi", 80, L"/" },
        { 0, L"http://www.server.com:88/docs", L"www.server.com", 88, L"/docs" },
        { 0, L"http://www.other.net:1522/ex/take.html", L"www.other.net", 1522, L"/ex/take.html" },
        { 0, L"http://130.234.22.232:43/", L"130.234.22.232", 43, L"/" },
        { 1, L"www.google.fi" },
        { 1, L"http://www.server.com" },
        { 1, L"http://www.server.com:88" },
        { 1, L"http://www.server.com:88s/" }, // this should fail but doesn't
    };

void doTestL(CConsoleBase& console)
    {
    ConsoleForwarder forw( console );
    TBuf<128> server;
    TInt port=0;
    TBuf<128> document;
    for(TInt i=0; i<sizeof(tests)/sizeof(TTestModel); i++ )
        {
        const TTestModel& tc = tests[i];
        TRAPD(error,
            CAOExampleEngine::ParseURLL( TPtrC(tc.iUrl), forw, server, port, document )
            );
        if( error )
            {
            if( !tc.iShouldFail )
                {
                console.Printf(_L("\nCase %d: failed but shouldn't"), i+1);
                User::Leave(1000);
                } // else ok
            }
        else // !error
            {
            if( tc.iShouldFail ) // case was expected to fail
                {
                console.Printf(_L("\nCase %d: expected to fail but didn't"), i+1);
                User::Leave(1000);
                }
            else // case was expected to run withouth problems
                {
                // compare that fields do match
                if( TPtrC(tc.iServer).Compare(server) != 0 )
                    {
                    console.Printf(_L("\nCase %d: server doesn't match"), i+1);
                    User::Leave(1000);
                    }
                if( tc.iPort != port )
                    {
                    console.Printf(_L("\nCase %d: port doesn't match"), i+1);
                    User::Leave(1000);
                    }
                if( TPtrC(tc.iDocument).Compare(document) != 0 )
                    {
                    console.Printf(_L("\nCase %d: document doesn't match"), i+1);
                    User::Leave(1000);
                    }
                }
            }
        }
    }

_LIT( KExeTest,"ExeText" );
LOCAL_C int callTest()
    {
    CConsoleBase* console = Console::NewL( KExeTest, TSize( KConsFullScreen, KConsFullScreen ) );
    CleanupStack::PushL(console);

    TRAPD(error, doTestL(*console) );
    if (error)
        {
        _LIT(KFormatFailed,"\nleave code: %d ");
        console->Printf(KFormatFailed, error);
        User::After(5 * 1000000);
        }
    CleanupStack::PopAndDestroy();
    return error;
    }

GLDEF_C TInt E32Main() // main function called by E32
    {
    __UHEAP_MARK;
    CTrapCleanup* cleanup=CTrapCleanup::New();
    TRAPD( error, callTest() );
    __ASSERT_ALWAYS( !error, User::Panic( KExeTest, error ) );
    delete cleanup;
    __UHEAP_MARKEND;
    return error; // and return
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -