Skip to content

Commit

Permalink
update r712
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix committed Oct 3, 2014
1 parent b338094 commit da89c38
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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 の比較が真を返す不具合を修正
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/cover.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div class="contents">
<h1>IUTEST</h1>
<div class="text_block">
Iris Unit Test Framework : 2014 / 08 / 23<br />
Iris Unit Test Framework : 2014 / 10 / 03<br />
<br />
</div>
<h2>はじめに</h2>
Expand Down
45 changes: 45 additions & 0 deletions doc/primer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<title>iutest - 入門</title>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
<meta http-equiv="content-style-type" content="text/css" />
<style type="text/css">
Expand Down Expand Up @@ -44,6 +45,11 @@
padding: 0.5em;
margin: 10px;
}
table.ruled {
border-top: solid 1px;
border-bottom: solid 1px;
width: 90%;
}
</style>
<title>iutest - primer</title>
</head>
Expand Down Expand Up @@ -105,6 +111,23 @@
<li><a href="#switch_gtest">Google Test モード</a></li>
</ul>
</li>
<li><a href="#matcher">Matcher</a>
<ul>
<li><a href="#matcher_summary">Mathcer の概要</a></li>
<li><a href="#matcher_assertion">アサーション</a></li>
<li><a href="#matcher_matchers">Matcher の種類</a>
<!--
<ul>
<li><a href="#matcher_gernal">一般的な比較</a></li>
<li><a href="#matcher_float">浮動小数点 Matcher</a></li>
<li><a href="#matcher_string">文字列 Matcher</a></li>
<li><a href="#matcher_container">コンテナ Matcher</a></li>
<li><a href="#matcher_member">メンバー Matcher</a></li>
</ul>
-->
</li>
</ul>
</li>
</ul>
</div> <!-- end of contents -->

Expand Down Expand Up @@ -502,6 +525,7 @@
</ul>
</div>
</div> <!-- end of contents -->

<div class="contents">
<h2><a name="switch" id="switch">iutest / Google Test 切り替え</a></h2>
<div class="text_block">
Expand All @@ -525,6 +549,27 @@
</div>
</div> <!-- end of contents -->

<div class="contents">
<h2><a name="matcher" id="matcher">Matcher</a></h2>
<div class="text_block">
<h3><a name="matcher_summary" id="matcher_summary">Matcher の概要</a></h3>
<p>iutest では Matcher を提供しています。iutest の Matcher は Google Mock のそれとほぼ同じ使い方をします。<br />
ただし、Google Mock との互換性対応はしていませんのでご注意ください。
</p>
<h3><a name="matcher_assertion" id="matcher_assertion">アサーション</a></h3>
<p>
Matcher は IUTEST_*_THAT アサーションで利用します。
<table class="ruled" >
<tr><td>IUTEST_*_THAT(expression, m)</td><td>expression の値が Mathcer m にマッチするか検証します</td></tr>
</table>
</p>

<h3><a name="matcher_matchers" id="matcher_matchers">Matcher の種類</a></h3>
Matcher の種類については Doxygen 生成のドキュメントを確認してください。

</div> <!-- end of text_block --
</div> <!-- end of contents -->

<br />
<div align="right">Copyright (c) 2011-2014, Takazumi-Shirayanagi, All rights reserved.</div>

Expand Down
1 change: 1 addition & 0 deletions doc/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<ul>
<li><a href="cover.html">はじめに</a></li>
<li><a href="primer.html">入門ドキュメント</a></li>
<li><a href="wandbox.html">Wandbox の利用</a></li>
<li><a href="html/index.html">Doxygen ドキュメント</a></li>
</ul>
</li>
Expand Down
127 changes: 127 additions & 0 deletions doc/wandbox.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="Shift_JIS"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<title>iutest - Wandbox</title>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
<meta http-equiv="content-style-type" content="text/css" />
<style type="text/css">
body {
font-family: Arial,'MS Pゴシック',sans-serif ;
background-color:#008080;
line-height:130%;
}
h1 {
padding:20px 10px;
background-color:#cccccc;
border-bottom: solid 1px #808080;
}
h2 {
padding:14px 10px;
background-color:#cccccc;
border-bottom: solid 1px #808080;
}
h3 {
padding:10px 10px;
background-color:#cccccc;
border-bottom: solid 1px #808080;
}
.contents {
padding:0px 0px 1em 0px;
background-color:#f8f8f8;
border-right: solid 5px #006400;
border-bottom: solid 10px #006400;
}
li {
padding-bottom:4px;
}
.text_block {
padding-left:1em;
}
.source {
border : solid 2px #006400;
background-color:#ffffff;
padding: 0.5em;
margin: 10px;
}
</style>
</head>
<body>

<div class="contents">
<h1>Wandbox の利用</h1>

<div class="contents">
<h2>iuwandbox</h2>
<div class="text_block">
<a href="">Wandbox</a> で iutest を使ったテストコードを書けるように対応しました。<br />
様々なコンパイラー・バージョンでビルド・テストができるため、あなたのプログラムのコンパイラー対応を助けます。<br />
</div>
</div> <!-- end of contents -->

<div class="contents">
<h2>使い方</h2>
<div class="text_block">
tools/wandbox/iuwandbox.py を使用します。<br />
iuwandbox は python で書かれていますので、python が利用可能な環境で実行してください。<br />
実行は簡単です。ビルド・実行したいソースコードファイルを引数に渡すだけです。<br />
<br />

例)<br />
<pre>
iuwandbox.py sample.cpp
</pre>

ソースコードに特別な記述は必要ありません。<br />
重要なのは iutest.hpp を include することです。このとき、iutest.hpp にパスが通っていなくても問題ありません。<br />
<pre class="source">
#include "../../include/iutest.hpp"
#include <iostream>

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));
}
</pre>

サンプルの実行結果はこちらになります。<br />
<br />
コンパイラーの選択などは後述のコマンドラインオプションの項をご覧ください。<br />
</div>

<h2>コマンドラインオプション</h2>
<div class="text_block">
<table class="ruled" >
<tr><td>-c,--compiler COMPILER</td> <td>コンパイラーを選択します。選択できるコンパイラーは Wandbox を確認するか、--list_compiler オプションで確認してください。</td></tr>
<tr><td>-x,--options OPTIONS</td> <td>オプションを選択します。選択できるコンパイラーは Wandbox を確認するか、--list_options オプションで確認してください。</td></tr>
<tr><td>-f,--compiler_options_raw OPTIONS</td><td>コンパイラーのオプションを直接指定します。複数のオプションを指定する場合は、[ -f"-Dx=hogefuga\n-O3" ] とするか、[ -f"-Dx=hogefuga" -f"-O3" ] のように複数オプションを記述してください。 </td></tr>
<tr><td>-r,--runtime_options_raw OPTIONS</td><td>ビルドした実行ファイルのコマンドラインオプションを指定します。複数のオプションを指定する場合は、[ -r"--iutest_shuffle\n--iutest_random_seed=1" ] とするか、[ -r"--iutest_shuffle" -r"--iutest_random_seed=1" ] のように複数オプションを記述してください。 </td></tr>
<tr><td>--list_compiler</td><td>利用可能なコンパイラーを列挙します。</td></tr>
<tr><td>--list_options COMPILER</td><td>COMPILER で利用可能なオプションを列挙します。</td></tr>
<tr><td>--stdin</td> <td>実行時の stdin の内容を指定します。</td></tr>
<tr><td>--encoding ENCODING</td><td>入力ソースコードファイルのエンコードを指定します。</td></tr>
<tr><td>-s, --save</td> <td>permarnent link を生成します。</td></tr>
<tr><td>--permlink ID</td> <td>ID の permarnent link の情報を取得します。--output オプションを指定すると、ソースコードをファイルに書き出します。</td></tr>
<tr><td>-o, --output FILE</td><td>--permlink 指定した際に取得したソースコードを FILE に書き出します。</td></tr>
<tr><td>-v,--version</td> <td>バージョンを表示します</td></tr>
<tr><td width="200px">-h,--help</td> <td>ヘルプを表示します</td></tr>
</table>
</div>

</div> <!-- end of contents -->

<br />
<div align="right">Copyright (c) 2011-2014, Takazumi-Shirayanagi, All rights reserved.</div>

</body>
</html>
51 changes: 51 additions & 0 deletions include/iutest_matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,51 @@ class FieldMatcher : public IMatcher
const T& m_expected;
};

/**
* @brief Property matcher
*/
template<typename F, typename T>
class PropertyMatcher : public IMatcher
{
public:
PropertyMatcher(const F& prop, const T& expected) : m_property(prop), m_expected(expected) {}

public:
template<typename U>
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<F>() << ") " << m_expected;
return strm.str();
}
private:
template<typename U>
bool Check(const U& actual
, typename detail::disable_if_t< detail::is_pointer<U> >::type*& = detail::enabler::value) const
{
return static_cast<bool>(CastToMatcher(m_expected)((actual.*m_property)()));
}
template<typename U>
bool Check(const U& actual
, typename detail::enable_if_t< detail::is_pointer<U> >::type*& = detail::enabler::value) const
{
return static_cast<bool>(CastToMatcher(m_expected)((actual->*m_property)()));
}
private:
IUTEST_PP_DISALLOW_ASSIGN(PropertyMatcher);

const F& m_property;
const T& m_expected;
};

/**
* @brief Key matcher
*/
Expand Down Expand Up @@ -1419,6 +1464,12 @@ detail::PairMatcher<T1, T2> Pair(const T1& m1, const T2& m2) { return detail::Pa
template<typename F, typename T>
detail::FieldMatcher<F, T> Field(const F& field, const T& expected) { return detail::FieldMatcher<F, T>(field, expected); }

/**
* @brief Make Field matcher
*/
template<typename P, typename T>
detail::PropertyMatcher<P, T> Property(const P& prop, const T& expected) { return detail::PropertyMatcher<P, T>(prop, expected); }


#if IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF

Expand Down
4 changes: 2 additions & 2 deletions include/iutest_ver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions shippable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion test/iutest_matcher_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, X> mx;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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: " );
Expand Down

0 comments on commit da89c38

Please sign in to comment.