[Groonga-commit] groonga/grnxx at 309dc57 [master] Add tests for grnxx::Traits.

Back to archive index

susumu.yata null+****@clear*****
Wed May 15 13:54:28 JST 2013


susumu.yata	2013-05-15 13:54:28 +0900 (Wed, 15 May 2013)

  New Revision: 309dc5767da1e2106e7a0451bb01eef46234d5d2
  https://github.com/groonga/grnxx/commit/309dc5767da1e2106e7a0451bb01eef46234d5d2

  Message:
    Add tests for grnxx::Traits.

  Added files:
    test/test_traits.cpp
  Modified files:
    .gitignore
    test/Makefile.am

  Modified: .gitignore (+1 -0)
===================================================================
--- .gitignore    2013-05-15 13:49:12 +0900 (c08c288)
+++ .gitignore    2013-05-15 13:54:28 +0900 (c51a8a3)
@@ -54,3 +54,4 @@ test/test_string_builder
 test/test_string_format
 test/test_thread
 test/test_time
+test/test_traits

  Modified: test/Makefile.am (+5 -1)
===================================================================
--- test/Makefile.am    2013-05-15 13:49:12 +0900 (b8192a0)
+++ test/Makefile.am    2013-05-15 13:54:28 +0900 (591af6b)
@@ -27,7 +27,8 @@ TESTS =					\
 	test_string_builder		\
 	test_string_format		\
 	test_thread			\
-	test_time
+	test_time			\
+	test_traits
 
 check_PROGRAMS = $(TESTS)
 
@@ -111,3 +112,6 @@ test_thread_LDADD = ../lib/grnxx/libgrnxx.la
 
 test_time_SOURCES = test_time.cpp
 test_time_LDADD = ../lib/grnxx/libgrnxx.la
+
+test_traits_SOURCES = test_traits.cpp
+test_traits_LDADD = ../lib/grnxx/libgrnxx.la

  Added: test/test_traits.cpp (+84 -0) 100644
===================================================================
--- /dev/null
+++ test/test_traits.cpp    2013-05-15 13:54:28 +0900 (c3ddbba)
@@ -0,0 +1,84 @@
+/*
+  Copyright (C) 2013  Brazil, Inc.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#include <cassert>
+
+#include "grnxx/logger.hpp"
+#include "grnxx/traits.hpp"
+
+namespace {
+
+// This type should use pass by reference.
+struct Point {
+  int x, y;
+};
+
+// This type has starts_with().
+struct Something {
+  bool starts_with(const Something &) const;
+};
+
+// An operator<() is declared for Something.
+bool operator<(const Something &, const Something &);
+
+// This type's starts_with() is invalid because it does not take Something2.
+// This type has operator<().
+struct Something2 {
+  bool starts_with(const Point &) const;
+  bool operator<(const Something2 &) const;
+};
+
+void test_type() {
+  assert((std::is_same<int, typename grnxx::Traits<int>::Type>::value));
+  assert((std::is_same<Point, typename grnxx::Traits<Point>::Type>::value));
+}
+
+void test_argument_type() {
+  assert((std::is_same<int,
+                       typename grnxx::Traits<int>::ArgumentType>::value));
+  assert((std::is_same<const Point &,
+                       typename grnxx::Traits<Point>::ArgumentType>::value));
+}
+
+void test_has_less() {
+  assert(grnxx::Traits<int>::has_less());
+  assert(!grnxx::Traits<Point>::has_less());
+  assert(grnxx::Traits<Something>::has_less());
+  assert(grnxx::Traits<Something2>::has_less());
+}
+
+void test_has_starts_with() {
+  assert(!grnxx::Traits<int>::has_starts_with());
+  assert(!grnxx::Traits<Point>::has_starts_with());
+  assert(grnxx::Traits<Something>::has_starts_with());
+  assert(!grnxx::Traits<Something2>::has_starts_with());
+}
+
+}  // namespace
+
+int main() {
+  grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL |
+                           grnxx::LOGGER_ENABLE_COUT);
+  grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER);
+
+  test_type();
+  test_argument_type();
+  test_has_less();
+  test_has_starts_with();
+
+  return 0;
+}
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index