亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > cppUnit
測試驅動開發入門-CppUnit
作者:網絡轉載 發布時間:[ 2012/11/29 15:11:55 ] 推薦標簽:

下面給出完整的程序:

// UnitTest.cpp : Defines the entry point for the console application.
//

#include "CppUnit/TestCase.h"
#include "CppUnit/TestResult.h"
#include "CppUnit/TextOutputter.h"
#include "CppUnit/TestResultCollector.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/extensions/HelperMacros.h"

#include
#include
#include
#include

class FileStatusError
{};

class FileStatus
{
public:
    FileStatus(const std::string& fileName)
    {}
    DWORD getFileSize() const
    {
        return 0;
    }
    bool fileExist() const
    {
        return false;
    }
    void setFileModifyDate( const FILETIME* )
    {
    }
    FILETIME getFileModifyDate() const
    {
        return FILETIME();
    }
    std::string getFileName() const
    {
        return "";
    }
};

class MyTestCase:public CPPUNIT_NS::TestFixture
{
    std::string mFileNameExist;
    std::string mFileNameNotExist;
    std::string mTestFolder;
    enum DUMMY
    {
        FILE_SIZE = 1011
    };
public:
    virtual void setUp()
    {
        mTestFolder = "c:justfortest";
        mFileNameExist = mTestFolder + "exist.dat";
        mFileNameNotExist = mTestFolder + "notexist.dat";
        if( GetFileAttributes( mTestFolder.c_str() ) != INVALID_FILE_ATTRIBUTES )
            throw std::exception( "test folder already exists" );
        if( ! CreateDirectory( mTestFolder.c_str() ,NULL ) )

            throw std::exception( "cannot create folder" );
        HANDLE file = CreateFile( mFileNameExist.c_str(), GENERIC_READ | GENERIC_WRITE,
            0, NULL, CREATE_NEW, 0, NULL );
        if( file == INVALID_HANDLE_VALUE )
            throw std::exception( "cannot create file" );
        char buffer[FILE_SIZE];
        DWORD bytesWritten;
        if( !WriteFile( file, buffer, FILE_SIZE, &bytesWritten, NULL ) ||
            bytesWritten != FILE_SIZE )
        {
            CloseHandle( file );
            throw std::exception( "cannot write file" );
        }
        CloseHandle( file );
    }
    virtual void tearDown()
    {
        if( ! DeleteFile( mFileNameExist.c_str() ) )
            throw std::exception( "cannot delete file" );
        if( ! RemoveDirectory( mTestFolder.c_str() ) )
            throw std::exception( "cannot remove folder" );
    }
    void testCtorAndGetName()
    {
        FileStatus status( mFileNameExist );
        CPPUNIT_ASSERT_EQUAL( status.getFileName(), mFileNameExist );
    }
    void testGetFileSize()
    {
        FileStatus exist( mFileNameExist );
        CPPUNIT_ASSERT_EQUAL( exist.getFileSize(), (DWORD)FILE_SIZE );
        FileStatus notExist( mFileNameNotExist );
        CPPUNIT_ASSERT_THROW( notExist.getFileSize(), FileStatusError );
    }
    void testFileExist()
    {
        FileStatus exist( mFileNameExist );
        CPPUNIT_ASSERT( exist.fileExist() );
        FileStatus notExist( mFileNameNotExist );
        CPPUNIT_ASSERT( ! notExist.fileExist() );
    }
    void testFileModifyDateBasic()
    {
        FILETIME fileTime;
        GetSystemTimeAsFileTime( &fileTime );
        FileStatus exist( mFileNameExist );
        CPPUNIT_ASSERT_NO_THROW( exist.getFileModifyDate() );
        CPPUNIT_ASSERT_NO_THROW( exist.setFileModifyDate( &fileTime ) );
        FileStatus notExist( mFileNameNotExist );
        CPPUNIT_ASSERT_THROW( notExist.getFileModifyDate(), FileStatusError );
        CPPUNIT_ASSERT_THROW( notExist.setFileModifyDate( &fileTime ), FileStatusError );
    }
    void testFileModifyDateEqual()
    {
        FILETIME fileTime;
        GetSystemTimeAsFileTime( &fileTime );
        FileStatus exist( mFileNameExist );
        CPPUNIT_ASSERT_NO_THROW( exist.setFileModifyDate( &fileTime ) );
        FILETIME get = exist.getFileModifyDate();
        CPPUNIT_ASSERT( CompareFileTime( &get, &fileTime ) == 0 );
    }
};

int main()
{
    CPPUNIT_NS::TestResult r;
    CPPUNIT_NS::TestResultCollector result;
    r.addListener( &result );
    CPPUNIT_NS::TestCaller testCase1( "testCtorAndGetName", MyTestCase::testCtorAndGetName );
    CPPUNIT_NS::TestCaller testCase2( "testGetFileSize", MyTestCase::testGetFileSize );
    CPPUNIT_NS::TestCaller testCase3( "testFileExist", MyTestCase::testFileExist );
    CPPUNIT_NS::TestCaller testCase4( "testFileModifyDateBasic", MyTestCase::testFileModifyDateBasic );
    CPPUNIT_NS::TestCaller testCase5( "testFileModifyDateEqual", MyTestCase::testFileModifyDateEqual );
    testCase1.run( &r );
    testCase2.run( &r );
    testCase3.run( &r );
    testCase4.run( &r );
    testCase5.run( &r );
    CPPUNIT_NS::TextOutputter out( &result, std::cout );
    out.write();
    return 0;
}

上一頁12345下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 日本福利写真福利视频 | 日韩三级大片 | 欧美高清国产在线观看 | 美女网站全黄 | 成人9久久国产精品品 | 中国一级特黄aa毛片大片 | 欧洲乱码专区一区二区三区四区 | 一级黄色免费 | 成年人网站在线 | 欧美高清一区二区三 | 日本中文字幕二区三区 | 亚洲伦理在线 | 日韩精品一区二区三区在线观看l | 人人欧美| 不卡国产 | 欧美性bbbb| 女黄人东京手机福利视频 | 国产91精品一区二区麻豆网站 | 日韩高清一区二区三区五区七区 | 国产一区二区三区在线视频 | 亚洲国产日韩欧美在线a乱码 | www深夜视频在线观看高清 | 亚洲天堂成人在线观看 | 日本精品一区二区三区在线观看 | 欧美怀孕色xxxxx | 夜天干天干啦天干天天爽 | 在线观看国产区 | 国产免费不卡 | 成人免费公开视频 | 77788色淫网站女女免费视频 | 天天看天天色 | 在线欧美一区 | 天天干天天操天天舔 | 日批视频在线播放 | 黄色网点 | 亚洲精品亚洲人成在线观看麻豆 | 国产精品欧美亚洲 | 久久窝窝国产精品午夜看15 | 成人一级免费视频 | 国产一区二区在线播放 | 欧美成人精品不卡视频在线观看 |