Changeset 303 in pacpusframework for trunk


Ignore:
Timestamp:
04/08/14 11:22:06 (10 years ago)
Author:
Marek Kurdej
Message:

TestFileLib added

Location:
trunk/src
Files:
4 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}
  • trunk/src/PacpusLib/ColorSeverityFormatter.hpp

    r301 r303  
    1818#if defined(PACPUS_LOG_COLORED_OUTPUT)
    1919
     20#include <Pacpus/predef/os.h>
     21
    2022#include <boost/assert.hpp>
    2123#include <boost/log/attributes/attribute_name.hpp>
     
    2830#include <string>
    2931
    30 // could use Boost.Predef with Boost >= 1.55
    31 #if defined(WIN32) || defined(_WINDOWS)
    32 #   define PACPUS_OS_WINDOWS 1
    33 #elif defined(__unix) || defined(__unix__)
    34 #   define PACPUS_OS_UNIX 1
    35 #   if defined(__linux) || defined(__linux__)
    36 #       define PACPUS_OS_LINUX 1
    37 #   endif
    38 #elif defined(__APPLE__) || defined(__MACH__) || defined(Macintosh) || defined(macintosh)
    39 #   define PACPUS_OS_MACOS 1
    40 #else
    41 //  unknown system
    42 #endif
    43 
    44 #if defined(PACPUS_OS_WINDOWS)
     32#if PACPUS_OS_WINDOWS
    4533#   include <Windows.h>
    4634#endif
     
    7361}
    7462
    75 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     63#if PACPUS_OS_WINDOWS
    7664
    7765// Returns the character attribute for the given color.
     
    134122}
    135123
    136 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     124#endif // PACPUS_OS_WINDOWS
    137125
    138126bool shouldUseColor(bool stdoutIsTty)
    139127{
    140 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     128#if PACPUS_OS_WINDOWS // && !PACPUS_OS_WINDOWS_MOBILE
    141129    return true;
    142130#else
     
    150138            || (term == "cygwin");
    151139    return stdoutIsTty && termSupportsColor;
    152 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     140#endif // PACPUS_OS_WINDOWS
    153141}
    154142
     
    157145{
    158146    ColorFormatter()
    159 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     147#if PACPUS_OS_WINDOWS
    160148        : mStreamHandle(GetStdHandle(STD_OUTPUT_HANDLE))
    161 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     149#endif // PACPUS_OS_WINDOWS
    162150    {
    163151        mShouldUseColor = shouldUseColor(/*stdoutIsTty*/ true);
     
    169157            return;
    170158        }
    171 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     159#if PACPUS_OS_WINDOWS
    172160        // Gets the current text color.
    173161        CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
     
    182170#else
    183171        strm << getAnsiColorCode(getColor(sev)).c_str();
    184 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     172#endif // PACPUS_OS_WINDOWS
    185173    }
    186174
    187175    bool mShouldUseColor;
    188 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     176#if PACPUS_OS_WINDOWS
    189177    const HANDLE mStreamHandle;
    190178    WORD mSavedConsoleBufferInfo;
    191 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     179#endif // PACPUS_OS_WINDOWS
    192180};
    193181
     
    196184{
    197185    DefaultFormatter()
    198 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     186#if PACPUS_OS_WINDOWS
    199187    //DefaultFormatter(WORD savedConsoleBufferInfo)
    200188        : mStreamHandle(GetStdHandle(STD_OUTPUT_HANDLE))
    201189        //, mSavedConsoleBufferInfo(savedConsoleBufferInfo)
    202190        , mSavedConsoleBufferInfo(getColorAttribute(COLOR_WHITE)) // FIXME: restore old value, not just reset
    203 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     191#endif // PACPUS_OS_WINDOWS
    204192    {
    205193        mShouldUseColor = shouldUseColor(/*stdoutIsTty*/ true);
     
    211199            return;
    212200        }
    213 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     201#if PACPUS_OS_WINDOWS
    214202        fflush(stdout);
    215203        // Restores the text color.
     
    217205#else
    218206        strm << getAnsiColorCodeRestoreDefault().c_str();
    219 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     207#endif // PACPUS_OS_WINDOWS
    220208    }
    221209
    222210    bool mShouldUseColor;
    223 #if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     211#if PACPUS_OS_WINDOWS
    224212    const HANDLE mStreamHandle;
    225213    WORD mSavedConsoleBufferInfo;
    226 #endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     214#endif // PACPUS_OS_WINDOWS
    227215};
    228216
     
    273261    {
    274262        if (restoreDefault) {
    275 //#if defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     263//#if PACPUS_OS_WINDOWS
    276264//            m_formatter = formatter_function_type(DefaultFormatter<char_type>());
    277 //#else // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     265//#else // PACPUS_OS_WINDOWS
    278266            m_formatter = formatter_function_type(DefaultFormatter<char_type>());
    279 //#endif // defined(PACPUS_OS_WINDOWS) && !defined(PACPUS_OS_WINDOWS_MOBILE)
     267//#endif // PACPUS_OS_WINDOWS
    280268        } else {
    281269            m_formatter = formatter_function_type(ColorFormatter<char_type>());
  • trunk/src/PacpusTools/src/SharedMemory.cpp

    r300 r303  
    1717#endif
    1818
    19 DECLARE_STATIC_LOGGER("pacpus.framwork.SharedMemory");
     19DECLARE_STATIC_LOGGER("pacpus.framwork.SharedMemory")
    2020
    2121using namespace pacpus;
Note: See TracChangeset for help on using the changeset viewer.