예제 #1
0
inline bool
equal_and_continue_impl( Left const& left_, Right const& right_,
                         wrap_stringstream& message_, const_string file_name_, std::size_t line_num_,
                         unit_test::log_level log_level_ = unit_test::log_all_errors,
                         std::size_t pos                 = (std::size_t)-1 )
{
    extended_predicate_value predicate( left_ == right_ );

    if( !predicate ) {
        wrap_stringstream error_message;
        error_message.ref() << "test " << message_ << " failed";

        if( pos != (std::size_t)-1 )
            error_message.ref() <<  " in a position " << pos;

        error_message.ref() << " [" 
                            << print_helper<Left>( left_ )   << " != " 
                            << print_helper<Right>( right_ ) << "]";

        return test_and_continue_impl( predicate, error_message, file_name_, line_num_, false, log_level_ );
    }

    return test_and_continue_impl( predicate, wrap_stringstream().ref() << message_, file_name_, line_num_, true, log_level_ );
    //----------------------------------------------^ this is added to prevent message_ corruption when reused by collection comparison
}
예제 #2
0
inline bool
compare_and_continue_impl( FPT left_, FPT right_, PersentType tolerance_,
                           const_string left_text_, const_string right_text_,
                           const_string file_name_, std::size_t line_num_,
                           unit_test::log_level log_level_ = unit_test::log_all_errors )
{
    extended_predicate_value predicate( check_is_close( left_, right_, tolerance_ ) );

    if( !predicate ) {
        return test_and_continue_impl( predicate,
            wrap_stringstream().ref() << "difference between " << left_text_ << "{" << print_helper<FPT>( left_ ) << "}" 
                                      << " and " << right_text_ << "{" << print_helper<FPT>( right_ ) << "}" 
                                      << " exceeds " << print_helper<PersentType>( tolerance_ ) << "%",
            file_name_, line_num_, false, log_level_ );
    }

    return test_and_continue_impl( predicate, 
        wrap_stringstream().ref() << "difference between " << left_text_ << "{" << print_helper<FPT>( left_ ) << "}" 
                                  << " and " << right_text_ << "{" << print_helper<FPT>( right_ ) << "}" 
                                  << " does not exceeds " << print_helper<PersentType>( tolerance_ ) << "%",
        file_name_, line_num_, true, log_level_ );
}
예제 #3
0
inline void
bitwise_equal_and_continue_impl( Left const& left_, Right const& right_,
                                 wrap_stringstream& message_, const_string file_name_, std::size_t line_num_,
                                 unit_test::log_level log_level_ = unit_test::log_all_errors )
{
    std::size_t left_bit_size  = sizeof(Left)*CHAR_BIT;
    std::size_t right_bit_size = sizeof(Right)*CHAR_BIT;

    static Left const L1( 1 );
    static Right const R1( 1 );

    if( left_bit_size != right_bit_size )
        warn_and_continue_impl( false, wrap_stringstream().ref() << message_ << ": operands bit sizes does not coinside", 
                                file_name_, line_num_, false );

    std::size_t total_bits = left_bit_size < right_bit_size ? left_bit_size : right_bit_size;

    for( std::size_t counter = 0; counter < total_bits; ++counter ) {
        bool predicate = ( left_ & ( L1 << counter ) ) == ( right_ & ( R1 << counter ) );

        test_and_continue_impl( predicate, wrap_stringstream().ref() << message_.str() << " in the position " << counter,
                                file_name_, line_num_, true, log_level_ );
    }
}
예제 #4
0
inline bool
test_and_continue_impl( Predicate const& pred_, ArgType const& arg_,
                        wrap_stringstream& message_,
                        const_string file_name_, std::size_t line_num_,
                        unit_test::log_level log_level_ = unit_test::log_all_errors )
{
    extended_predicate_value predicate( pred_( arg_ ) );

    if( !predicate ) {
        return test_and_continue_impl( predicate,
                                       wrap_stringstream().ref() << "test " << message_ << " failed for " 
                                                                 << print_helper<ArgType>( arg_ ),
                                       file_name_, line_num_, false, log_level_ );
    }

    return test_and_continue_impl( predicate, message_, file_name_, line_num_, true, log_level_ );
}
예제 #5
0
inline bool
test_and_continue_impl( Predicate const& pred_, First const& first_, Second const& second_,
                        wrap_stringstream& message_,
                        const_string file_name_, std::size_t line_num_,
                        unit_test::log_level log_level_ = unit_test::log_all_errors )
{
    extended_predicate_value predicate( pred_( first_, second_ ) );

    if( !predicate ) {
        return test_and_continue_impl( predicate,
            wrap_stringstream().ref() << "test " << message_ 
                                      << " failed for (" << print_helper<First>( first_ ) << ", " 
                                                         << print_helper<Second>( second_ ) << ")",
            file_name_, line_num_, false, log_level_ );
    }

    return test_and_continue_impl( predicate, message_, file_name_, line_num_, true, log_level_ );
}
예제 #6
0
bool
equal_and_continue_impl( c_string_literal left, c_string_literal right, wrap_stringstream& message,
                         c_string_literal file_name, int line_num,
                         unit_test_framework::log_level loglevel )
{
    bool predicate = (left && right) ? std::strcmp( left, right ) == 0 : (left == right);

    left  = left  ? left  : "null string";
    right = right ? right : "null string";

    if( !predicate ) {
        return test_and_continue_impl( false,
            wrap_stringstream().ref() << "test " << message.str() << " failed [" << left << " != " << right << "]",
            file_name, line_num, false, loglevel );
    }

    return test_and_continue_impl( true, message, file_name, line_num, true, loglevel );
}