忍者ブログ
[199] [198] [197] [196] [195] [194] [193] [192] [191] [190] [189]

DATE : 2024/04/16 (Tue)
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。


DATE : 2006/11/03 (Fri)

前回の記事

テスト用アプリケーションの記述

ユニットテストを実行するアプリケーションを記述します。

テスト用のアプリケーションは、Brew Unit Test に付属するサンプルコードを流用すると、簡単に記述できます。

サンプルコードは、「src\platforms\brew」にある brewunit.cpp です。

以下に、 brewunit.cpp の一部を転載します。(インデントなどは、記事に合わせて変更してあります)

#include "stdafx.h"

// include base files for BrewTestUnit library
#include "UnitTestCase.h"
#include "UnitTestResult.h"
#include "UnitTestSuite.h"

// add brew-specific listeners support
#include "stdlistener.h"
#include "filelistener.h"


#include "cppunit.bid"        // applet class ID

// add multiplatform examples
#include "../examples/testcase1.h"
#include "../examples/testcase2.h"

static bool CppUnit_HandleEvent(IApplet * pi, AEEEvent eCode, 
                                      uint16 wParam, uint32 dwParam);

int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,
                            IModule * po,void ** ppObj)
{
    *ppObj = NULL;
    if(ClsId == AEECLSID_CPPUNIT)
    {        
        if(AEEApplet_New(sizeof(AEEApplet), ClsId, pIShell,
                po,(IApplet**)ppObj,
                (AEEHANDLER)CppUnit_HandleEvent,NULL)
            == TRUE)
        {            
            return AEE_SUCCESS;
        }
    }
    return EFAILED;
}

static bool CppUnit_HandleEvent(IApplet * pi, AEEEvent eCode,
                                uint16 wParam, uint32 dwParam)
{      
    AEEApplet * pMe = (AEEApplet*)pi;    

    switch (eCode) 
    {
    case EVT_APP_START:
        AECHAR * forDraw;
        {
            CppUnit::TestResult tr; // accumulate test's statistics

            // create and register some listeners
            StandardListener stdListener;
            FileListener fileListener;
            tr.addListener(stdListener);
            tr.addListener(fileListener);

            // create main test suite with some test cases
            // (or test suites) and run its
            MyTestCase1 tc1(_T("check account"));
            MyTestCase2 tc2(_T("security test"));
            CppUnit::TestSuite ts;
            ts.addTestCase(tc1);
            ts.addTestCase(tc2);
            ts.run(tr);    

            // we can use TestResult in direct way
            // (instead of use listeners)
            if (tr.failureCount() == 0)
                forDraw = L"Tests OK";
            else
                forDraw = L"Tests FAILED";
        }    

        // Display result string on screen
        IDISPLAY_DrawText(pMe->m_pIDisplay, AEE_FONT_BOLD, forDraw, -1,
                        0, 0, 0, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
        
        IDISPLAY_Update (pMe->m_pIDisplay);
        return true;
    case EVT_APP_STOP:
        return true;
    default:
        break;
    }

    return false;
}

まず次の部分をテスト用アプリケーションのために生成した bid ファイルに変更します。

#include "cppunit.bid"        // applet class ID

続いて以下の部分を、作成したテストケースのヘッダファイルを取り込むように変更します。

// add multiplatform examples
#include "../examples/testcase1.h"
#include "../examples/testcase2.h"

最後に、テストケースを生成してテストスイートに登録します。変更する部分は、次の通りです。

            // create main test suite with some test cases
            // (or test suites) and run its
            MyTestCase1 tc1(_T("check account"));
            MyTestCase2 tc2(_T("security test"));
            CppUnit::TestSuite ts;
            ts.addTestCase(tc1);
            ts.addTestCase(tc2);
            ts.run(tr);

例えば、「SampleTest」(SampleTest.h)というテストケースを登録する場合は、次のようになります。

#include "SampleTest.h"
            // create main test suite with some test cases
            // (or test suites) and run its
            SampleTest sampleTest;
            CppUnit::TestSuite ts;
            ts.addTestCase(sampleTest);
            ts.run(tr);

テストケースの分だけ、テストケースの取り込み、テストケースの生成、テストスイートに登録という作業を繰り返すことになります。

以上で、ユニットテストを実行するアプリケーションができました。あとは、このアプリケーションをビルドして BREW シミュレータで実行するだけです。

なお、シミュレータの「BREW 出力ウィンドウ」とファイルにテストの結果が出力されます。

(了)

PR
●この記事にコメントする
お名前
タイトル
文字色
メールアドレス
URL
コメント
パスワード
●この記事へのトラックバック
この記事にトラックバックする:
忍者ブログ [PR]
ブログ内検索
最近の状況
リンク
カレンダー
03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
使用許諾
最新コメント
(08/15)
(05/04)
(03/06)
(03/04)
(09/25)
最新トラックバック
ブログ内検索
最近の状況
リンク
カレンダー
03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
使用許諾
最新コメント
(08/15)
(05/04)
(03/06)
(03/04)
(09/25)
最新トラックバック