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

📄 testrunner.h

📁 symbian 3rd下的单元测试工具 里面包括一个框架 一个实例程序 还有使用手册 很好用的 我自己用过 有问题的可以交流奥
💻 H
字号:
#ifndef __CXXTEST_TESTRUNNER_H
#define __CXXTEST_TESTRUNNER_H

//
// TestRunner is the class that runs all the tests.
// To use it, create an object that implements the TestListener
// interface and call TestRunner::runAllTests( &myListener );
// 

//Changed by Penrillian Ltd 14 August 2002
//Arguments names cahnged to avoid compiler warnings 
//Use of _TS_TRY and _TS_CATCH changed to reflect implementation using leave
 
#include <cxxtest/Runnable.h>
#include <cxxtest/TestListenerProxy.h>
#include <cxxtest/Descriptions.h>
#include <cxxtest/TestSuite.h>
#include "Logger.h"

const TInt KRunAllSuites = -1;

namespace CxxTest 
{
    class TestRunner : public TestListenerProxy
    {
    public:
        TestRunner( TestListener *l, MUiUpdater * aUI ) : TestListenerProxy( l->listener(),aUI ) {}

        static void runAllTests( TestListener *alistener, WorldDescription & world, MUiUpdater * aUI, TInt aSuite  )
        {
            runWorld( alistener->listener(), world, aUI, aSuite );
        }

        static void runWorld( TestListener *alistener, const WorldDescription &world, MUiUpdater * aUI, TInt aSuite  )
        {
            TestRunner( alistener->listener(),aUI ).runWorld( world, aSuite );
        }
    
    private:
        
        void runWorld( const WorldDescription &wd, TInt aSuite )
        {
            enterWorld( wd, aSuite );
            wd.setUp( this );
			if(aSuite != KRunAllSuites && aSuite < wd.numSuites())
			{
				checkAndRunSuite(wd, aSuite);
			}
			else
			{
				for ( TInt i = 0; i < wd.numSuites(); ++ i )
				{
					checkAndRunSuite(wd, i);
				}
			}
            wd.tearDown( this );
            leaveWorld( wd, aSuite );
        }

		void checkAndRunSuite(const WorldDescription &wd, TInt aSuite)
		{
			if ( wd.suiteDescription(aSuite).suite )
                    runSuite( wd.suiteDescription(aSuite) );
		}
    
        void runSuite( const SuiteDescription &sd )
        {
            enterSuite( sd );
            sd.suite->setListener( this );
			iContinue = true;
            for ( unsigned i = 0; i < sd.numTests && iContinue; ++ i ) {
				TInt allocatedHeapCells = User::CountAllocCells();
				const char* testName = sd.tests[i].name;
				Logger::Log( "", testName );
				Logger::Log( "********** Test: %s **********", testName );
                sd.suite->setUp();
                runTest( sd.tests[i] );
                sd.suite->tearDown();	
				TInt lostCells = User::CountAllocCells() - allocatedHeapCells;
				if (lostCells != 0 && lostCells != sd.suite->iMemoryLeakCells )
				{
					failedTest(sd.tests[i].suite, testName, lostCells, "Memory Leak");
				}
				testCompleted();
            }
            leaveSuite( sd );
        }

        void runTest( const TestDescription &td )
        {
            enterTest( td );
			TRAPD(err, td.test->run());

			if (err == -1003)  // EPOC Exit application.
			{
				iContinue = false;
			}
			else if(err != 0)
			{ 
				TBuf8<30> result;
				result.Format( _L8( "Left with code %d" ), err );
				result.ZeroTerminate();
				failedTest(td.suite, td.name,td.line,(const char*)result.Ptr());
			} 

            leaveTest( td );
        }
		bool iContinue;
    };
}


#endif // __CXXTEST_TESTRUNNER_H

⌨️ 快捷键说明

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