OSDN Git Service

swappable のテストを追加
authorSubaruG <subaru_g@users.sourceforge.jp>
Sun, 7 Feb 2010 07:33:45 +0000 (16:33 +0900)
committerSubaruG <subaru_g@users.sourceforge.jp>
Sun, 7 Feb 2010 07:33:45 +0000 (16:33 +0900)
tests/swappable.cc [new file with mode: 0644]

diff --git a/tests/swappable.cc b/tests/swappable.cc
new file mode 100644 (file)
index 0000000..870ee2f
--- /dev/null
@@ -0,0 +1,39 @@
+#include "../gintenlib/swappable.hpp"
+
+// boost の単体テストフレームワーク
+#include <boost/test/minimal.hpp>
+
+// 使用例(名前空間に入れてみる)
+namespace ns
+{
+  struct hoge
+    : private gintenlib::swappable<hoge>
+  {
+    static bool swap_has_called;
+
+    void swap( hoge& )
+    {
+      swap_has_called = true;
+    }
+    
+  };
+  bool hoge::swap_has_called = false;
+  
+} // namespace ns
+
+#include <algorithm>  // for std::swap
+
+// テスト本体
+int test_main( int, char** )
+{
+  ns::hoge::swap_has_called = false;
+  
+  ns::hoge h1, h2;
+  using std::swap;
+  
+  BOOST_CHECK( !ns::hoge::swap_has_called );
+  swap( h1, h2 );
+  BOOST_CHECK(  ns::hoge::swap_has_called );
+  
+  return 0;
+}