diff --git a/CHANGES b/CHANGES index 2244fafd0b..0e9c0fd06a 100644 --- a/CHANGES +++ b/CHANGES @@ -8,7 +8,7 @@ Changes for 1.11.0: * Matcher に StrEq,StrNe,StrCaseEq,StrCaseNe,HasSubstr を追加 * Matcher に FloatEq,DoubleEq,NanSensitiveFloatEq,NanSensitiveDoubleEq を追加 * コンテナMatcher に Each,ElementsAre,ElementsAreArray を追加 -* メンバーMatcher に Key,Pair,Field を追加 +* メンバーMatcher に Key,Pair,Field,Property を追加 ** 修正 * IUTEST_*_FLOAT_EQ,DOUBLE_EQ で NAN の比較が真を返す不具合を修正 diff --git a/doc/Doxyfile b/doc/Doxyfile index 57d54f73fd..1daf3deaa1 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = iutest # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.10.99.15 +PROJECT_NUMBER = 1.10.99.16 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/doc/cover.html b/doc/cover.html index 7707424487..8c8529a5e6 100644 --- a/doc/cover.html +++ b/doc/cover.html @@ -52,7 +52,7 @@

IUTEST

-Iris Unit Test Framework : 2014 / 08 / 23
+Iris Unit Test Framework : 2014 / 10 / 03

͂߂

diff --git a/doc/primer.html b/doc/primer.html index bb19d574b4..dbc9dc9d2e 100644 --- a/doc/primer.html +++ b/doc/primer.html @@ -3,6 +3,7 @@ + iutest - iutest - primer @@ -105,6 +111,23 @@
  • Google Test [h
  • +
  • Matcher + +
  • @@ -502,6 +525,7 @@ +

    iutest / Google Test ؂ւ

    @@ -525,6 +549,27 @@
    +
    +

    Matcher

    +
    +

    Matcher ̊Tv

    +

    iutest ł Matcher 񋟂Ă܂Biutest Matcher Google Mock ̂Ƃقړg܂B
    +AGoogle Mock Ƃ̌݊Ή͂Ă܂̂łӂB +

    +

    AT[V

    +

    +Matcher IUTEST_*_THAT AT[Vŗp܂B + + +
    IUTEST_*_THAT(expression, m)expression ̒l Mathcer m Ƀ}b`邩؂܂
    +

    + +

    Matcher ̎

    +Matcher ̎ނɂ‚Ă Doxygen ̃hLgmFĂB + +
    +
    Copyright (c) 2011-2014, Takazumi-Shirayanagi, All rights reserved.
    diff --git a/doc/sidebar.html b/doc/sidebar.html index a3a3c2c5d9..847ea51322 100644 --- a/doc/sidebar.html +++ b/doc/sidebar.html @@ -39,6 +39,7 @@ diff --git a/doc/wandbox.html b/doc/wandbox.html new file mode 100644 index 0000000000..664af4c932 --- /dev/null +++ b/doc/wandbox.html @@ -0,0 +1,127 @@ + + + + + + iutest - Wandbox + + + + + + +
    +

    Wandbox ̗p

    + +
    +

    iuwandbox

    +
    +Wandbox iutest geXgR[h悤ɑΉ܂B
    +lXȃRpC[Eo[WŃrhEeXgł邽߁AȂ̃vÕRpC[Ή܂B
    +
    +
    + +
    +

    g

    +
    +tools/wandbox/iuwandbox.py gp܂B
    +iuwandbox python ŏĂ܂̂ŁApython p”\Ȋ‹ŎsĂB
    +s͊ȒPłBrhEs\[XR[ht@CɓnłB
    +
    + +j
    +
    +iuwandbox.py sample.cpp
    +
    + +\[XR[hɓʂȋLq͕Kv܂B
    +dvȂ̂ iutest.hpp include 邱ƂłB̂ƂAiutest.hpp ɃpXʂĂȂĂ肠܂B
    +
    +#include "../../include/iutest.hpp"
    +#include 
    +
    +int main(int argc, char** argv)
    +{
    +    int x = 0;
    +    std::cout << "hoge" << std::endl;
    +    
    +    IUTEST_INIT(&argc, argv);
    +    return IUTEST_RUN_ALL_TESTS();
    +}
    +
    +IUTEST(Foo, Bar)
    +{
    +    IUTEST_ASSERT_EQ(1, abs(-1));
    +}
    +
    + +Tv̎sʂ͂ɂȂ܂B
    +
    +RpC[̑IȂǂ͌q̃R}hCIvV̍B
    +
    + +

    R}hCIvV

    +
    + + + + + + + + + + + + + + +
    -c,--compiler COMPILER RpC[I܂BIłRpC[ Wandbox mF邩A--list_compiler IvVŊmFĂB
    -x,--options OPTIONS IvVI܂BIłRpC[ Wandbox mF邩A--list_options IvVŊmFĂB
    -f,--compiler_options_raw OPTIONSRpC[̃IvV𒼐ڎw肵܂B̃IvVw肷ꍇ́A[ -f"-Dx=hogefuga\n-O3" ] Ƃ邩A[ -f"-Dx=hogefuga" -f"-O3" ] ̂悤ɕIvVLqĂB
    -r,--runtime_options_raw OPTIONSrhst@C̃R}hCIvVw肵܂B̃IvVw肷ꍇ́A[ -r"--iutest_shuffle\n--iutest_random_seed=1" ] Ƃ邩A[ -r"--iutest_shuffle" -r"--iutest_random_seed=1" ] ̂悤ɕIvVLqĂB
    --list_compilerp”\ȃRpC[񋓂܂B
    --list_options COMPILERCOMPILER ŗp”\ȃIvV񋓂܂B
    --stdin s stdin ̓ew肵܂B
    --encoding ENCODING̓\[XR[ht@C̃GR[hw肵܂B
    -s, --save permarnent link 𐶐܂B
    --permlink ID ID permarnent link ̏擾܂B--output IvVw肷ƁA\[XR[ht@Cɏo܂B
    -o, --output FILE--permlink w肵ۂɎ擾\[XR[h FILE ɏo܂B
    -v,--version o[W\܂
    -h,--help wv\܂
    +
    + +
    + +
    +
    Copyright (c) 2011-2014, Takazumi-Shirayanagi, All rights reserved.
    + + + diff --git a/include/iutest_matcher.hpp b/include/iutest_matcher.hpp index 0fdf530359..3a0661b04b 100644 --- a/include/iutest_matcher.hpp +++ b/include/iutest_matcher.hpp @@ -879,6 +879,51 @@ class FieldMatcher : public IMatcher const T& m_expected; }; +/** + * @brief Property matcher +*/ +template +class PropertyMatcher : public IMatcher +{ +public: + PropertyMatcher(const F& prop, const T& expected) : m_property(prop), m_expected(expected) {} + +public: + template + AssertionResult operator ()(const U& actual) const + { + if( Check(actual) ) return AssertionSuccess(); + return AssertionFailure() << WitchIs(); + } + +public: + ::std::string WitchIs(void) const IUTEST_CXX_OVERRIDE + { + iu_global_format_stringstream strm; + strm << "Property: " << m_expected; + //strm << "Property: (" << detail::GetTypeName() << ") " << m_expected; + return strm.str(); + } +private: + template + bool Check(const U& actual + , typename detail::disable_if_t< detail::is_pointer >::type*& = detail::enabler::value) const + { + return static_cast(CastToMatcher(m_expected)((actual.*m_property)())); + } + template + bool Check(const U& actual + , typename detail::enable_if_t< detail::is_pointer >::type*& = detail::enabler::value) const + { + return static_cast(CastToMatcher(m_expected)((actual->*m_property)())); + } +private: + IUTEST_PP_DISALLOW_ASSIGN(PropertyMatcher); + + const F& m_property; + const T& m_expected; +}; + /** * @brief Key matcher */ @@ -1419,6 +1464,12 @@ detail::PairMatcher Pair(const T1& m1, const T2& m2) { return detail::Pa template detail::FieldMatcher Field(const F& field, const T& expected) { return detail::FieldMatcher(field, expected); } +/** + * @brief Make Field matcher +*/ +template +detail::PropertyMatcher Property(const P& prop, const T& expected) { return detail::PropertyMatcher(prop, expected); } + #if IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF diff --git a/include/iutest_ver.hpp b/include/iutest_ver.hpp index adc76cc87a..2650c15c62 100644 --- a/include/iutest_ver.hpp +++ b/include/iutest_ver.hpp @@ -17,11 +17,11 @@ //====================================================================== // define -#define IUTEST_VER 0x01109915u //!< iutest version 1.10.99.15 +#define IUTEST_VER 0x01109916u //!< iutest version 1.10.99.16 #define IUTEST_MAJORVER 0x01u //!< Major Version #define IUTEST_MINORVER 0x10u //!< Minor Version #define IUTEST_BUILD 0x99u //!< Build -#define IUTEST_REVISION 0x15u //!< Revision +#define IUTEST_REVISION 0x16u //!< Revision /** * @mainpage diff --git a/shippable.yml b/shippable.yml index c34873ca7c..a8ef30fa28 100644 --- a/shippable.yml +++ b/shippable.yml @@ -11,8 +11,8 @@ before_script: script: - cd tools/wandbox -# - python ./iuwandbox.py ../../test/iutest_syntax_tests.cpp -c ${WANDBOX_COMPILER} - - python ./iuwandbox.py sample.cpp -c ${WANDBOX_COMPILER} + - python ./iuwandbox.py ../../test/iutest_syntax_tests.cpp -c ${WANDBOX_COMPILER} --encoding utf-8-sig +# - python ./iuwandbox.py sample.cpp -c ${WANDBOX_COMPILER} env: - WANDBOX_COMPILER=gcc-head diff --git a/test/iutest_matcher_tests.cpp b/test/iutest_matcher_tests.cpp index 4cf12f9c42..9721def3de 100644 --- a/test/iutest_matcher_tests.cpp +++ b/test/iutest_matcher_tests.cpp @@ -39,7 +39,7 @@ void* p1 = NULL; void* p2 = &p1; float f0 = 0.0f; double d0 = 0.0; -struct X { int a, b; X(int _a, int _b) : a(_a), b(_b) {} int GetA() { return a; } }; +struct X { int a, b; X(int _a, int _b) : a(_a), b(_b) {} int GetA() const { return a; } }; X x(1,1); ::std::map mx; @@ -214,6 +214,13 @@ IUTEST(Matcher, Field) IUTEST_EXPECT_THAT(mx, Each(Pair(Le(10), Field(&X::b, Ge(0))))); } +IUTEST(Matcher, Propetry) +{ + IUTEST_EXPECT_THAT( x, Property(&X::GetA, 1)); + IUTEST_EXPECT_THAT(&x, Property(&X::GetA, 1)); + IUTEST_EXPECT_THAT(mx, Each(Pair(Le(10), Property(&X::GetA, Ge(0))))); +} + IUTEST(Matcher, ElementsAreArray) { IUTEST_EXPECT_THAT( a, ElementsAreArray(va)); @@ -370,6 +377,12 @@ IUTEST(MatcherFailure, Field) IUTEST_EXPECT_FATAL_FAILURE( IUTEST_ASSERT_THAT( x, Field(&X::a, Ne(1))), "Field: Ne: 1" ); } +IUTEST(MatcherFailure, Property) +{ + IUTEST_EXPECT_FATAL_FAILURE( IUTEST_ASSERT_THAT( x, Property(&X::GetA, 100)), "Property: 100" ); + IUTEST_EXPECT_FATAL_FAILURE( IUTEST_ASSERT_THAT( x, Property(&X::GetA, Ne(1))), "Property: Ne: 1" ); +} + IUTEST(MatcherFailure, ElementsAreArray) { IUTEST_EXPECT_FATAL_FAILURE( IUTEST_ASSERT_THAT(b, ElementsAreArray(c)), "ElementsAreArray: " ); diff --git a/tools/wandbox/iuwandbox.py b/tools/wandbox/iuwandbox.py index 39f5985a17..f9fbd48f8a 100644 --- a/tools/wandbox/iuwandbox.py +++ b/tools/wandbox/iuwandbox.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # # iuwandbox.py # @@ -25,7 +24,7 @@ def parse_command_line(): '-v' , '--version' , action='version' - , version=u'%(prog)s version 0.1' + , version=u'%(prog)s version 0.2' ) parser.add_argument( '--list_compiler' @@ -78,6 +77,10 @@ def parse_command_line(): , '--output' , help = 'Get permanent link code.' ) + parser.add_argument( + '--encoding' + , help = 'Set encoding.' + ) parser.add_argument( 'code' , metavar='CODE' @@ -92,9 +95,12 @@ def parse_command_line(): # # make code -def make_code(path): +def make_code(path, encoding): code = '' - file = open(path, 'r') + if encoding: + file = codecs.open(path, 'r', encoding) + else: + file = open(path, 'r') for line in file: m = IUTEST_INCLUDE_REGEX.match(line) if m: @@ -171,7 +177,7 @@ def run(options): filepath = options.code if not os.path.exists(filepath): sys.exit(1) - code = make_code(filepath) + code = make_code(filepath,options.encoding) r = run_wandbox(code, options) b = show_result(r) sys.exit(b) diff --git a/tools/wandbox/pywandbox.py b/tools/wandbox/pywandbox.py index 21539dfc97..a22101f3ad 100644 --- a/tools/wandbox/pywandbox.py +++ b/tools/wandbox/pywandbox.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # # pywandbox.py #