Changeset 303 in pacpusframework for trunk/src/FileLib


Ignore:
Timestamp:
Apr 8, 2014, 11:22:06 AM (11 years ago)
Author:
Marek Kurdej
Message:

TestFileLib added

Location:
trunk/src/FileLib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/FileLib/src/DbiteFile.cpp

    r292 r303  
    3838typedef int8_t VariableDataSizeT;
    3939
    40 DECLARE_STATIC_LOGGER("pacpus.core.DbiteFile");
     40DECLARE_STATIC_LOGGER("pacpus.core.DbiteFile")
    4141
    4242namespace pacpus
    4343{
    44   VariableDataSizeTag VariableDataSize;
    45   ReadModeTag ReadMode;
    46   WriteModeTag WriteMode;
    47   DiagnoseModeTag DiagnoseMode;
     44    VariableDataSizeTag VariableDataSize;
     45    ReadModeTag ReadMode;
     46    WriteModeTag WriteMode;
     47    DiagnoseModeTag DiagnoseMode;
    4848}
    4949
     
    115115        LOG_ERROR("Dbite exception: " << e.what());
    116116        close();
    117         BOOST_THROW_EXCEPTION(DbiteException("cannot open file for reading")
     117        BOOST_THROW_EXCEPTION(e
     118            //<< "cannot open file for reading"
    118119            << errinfo_file_name(mPath)
    119120            << errinfo_ios_base_open_mode(openmode)
     
    128129        // TODO: readAndDiagnoseHeader();
    129130        close();
    130         BOOST_THROW_EXCEPTION(DbiteException("cannot read header")
     131        BOOST_THROW_EXCEPTION(e
     132            //<< "cannot read header"
    131133            << errinfo_nested_exception(copy_exception(e))
    132134        );
     
    194196            // TODO: readAndDiagnoseHeader();
    195197            close();
    196             BOOST_THROW_EXCEPTION(DbiteException("cannot read header"));
     198            //BOOST_THROW_EXCEPTION(DbiteException("cannot read header"));
     199            throw;
    197200        }
    198201    } else {
     
    343346    checkFileOpen();
    344347    read((char *)(&mHeader), sizeof(mHeader));
     348    // FIXME: header has good format
    345349    LOG_DEBUG("file: " << getPath());
    346350    LOG_TRACE("header read:\n" << string(*this));
     
    824828        string errorMessage = "file is not open";
    825829        LOG_WARN(errorMessage);
    826         BOOST_THROW_EXCEPTION(DbiteException(errorMessage.c_str())
     830        BOOST_THROW_EXCEPTION(DbiteException(errorMessage)
    827831            << errinfo_file_name(mPath)
     832            << errinfo_api_function("open")
    828833        );
    829834    }
  • trunk/src/FileLib/test/TestFileLib.cpp

    r301 r303  
    2121#include <Pacpus/kernel/Log.h>
    2222
     23#include <boost/exception/diagnostic_information.hpp>
     24#include <boost/exception/errinfo_api_function.hpp>
     25#include <boost/exception/get_error_info.hpp>
    2326#include <boost/noncopyable.hpp>
    2427#include <cstdio>
    2528
    26 DECLARE_STATIC_LOGGER("pacpus.framework.test.FileLib");
     29DECLARE_STATIC_LOGGER("pacpus.framework.test.FileLib")
    2730
    2831using namespace boost;
     
    3134
    3235struct HasExceptionMessage
    33         : noncopyable
     36    : noncopyable
    3437{
    3538    HasExceptionMessage(const string expectedMessage)
     
    4851};
    4952
     53template <
     54    typename ErrorInfo,
     55    typename E = typename ErrorInfo::error_info::value_type
     56>
     57struct HasErrorInfo
     58    : noncopyable
     59{
     60    HasErrorInfo(E const& expectedValue)
     61        : mExpectedValue(expectedValue)
     62    {
     63    }
     64
     65    bool operator()(DbiteException const& ex)
     66    {
     67        LOG_INFO("diagnostic_information: " << diagnostic_information(ex));
     68        E const* value = get_error_info<ErrorInfo>(ex);
     69        if (!value) {
     70            return false;
     71        }
     72        return mExpectedValue == *value;
     73    }
     74
     75private:
     76    E const mExpectedValue;
     77};
     78
    5079BOOST_AUTO_TEST_SUITE(suiteBasic)
    5180
     
    150179        (df.open("data/bad-empty-file.dbt", ReadMode))
    151180        , DbiteException
    152         , HasExceptionMessage("cannot read header")
     181//        , HasExceptionMessage("cannot read data") // FIXME: cannot read header
     182        , HasErrorInfo<errinfo_api_function>("open")
    153183    );
    154184}
     
    164194        (df.open("data/bad-incomplete-header.dbt", ReadMode))
    165195        , DbiteException
    166         , HasExceptionMessage("cannot read header")
     196        , HasExceptionMessage("cannot read data") // FIXME: cannot read header
    167197    );
    168198}
Note: See TracChangeset for help on using the changeset viewer.