null+****@clear*****
null+****@clear*****
2011年 11月 9日 (水) 18:16:54 JST
Susumu Yata 2011-11-09 09:16:54 +0000 (Wed, 09 Nov 2011)
New Revision: 3881debb96db854c2783c51a65b60465143cf4f5
Log:
add a test of grn::dat::String.
Added files:
test/unit/core/dat/test-string.cpp
Modified files:
test/unit/core/dat/Makefile.am
Modified: test/unit/core/dat/Makefile.am (+2 -2)
===================================================================
--- test/unit/core/dat/Makefile.am 2011-11-09 08:46:09 +0000 (2817b8f)
+++ test/unit/core/dat/Makefile.am 2011-11-09 09:16:54 +0000 (eb162b7)
@@ -8,6 +8,7 @@ noinst_LTLIBRARIES = \
test-header.la \
test-key.la \
test-node.la \
+ test-string.la \
test-vector.la
# test-cursor-factory.la \
@@ -16,7 +17,6 @@ noinst_LTLIBRARIES = \
# test-key-cursor.la \
# test-predictive-cursor.la \
# test-prefix-cursor.la \
-# test-string.la \
# test-trie.la
endif
@@ -54,6 +54,6 @@ test_key_la_SOURCES = test-key.cpp
test_node_la_SOURCES = test-node.cpp
#test_predictive_cursor_la_SOURCES = test-predictive-cursor.cpp
#test_prefix_cursor_la_SOURCES = test-prefix-cursor.cpp
-#test_string_la_SOURCES = test-string.cpp
+test_string_la_SOURCES = test-string.cpp
#test_trie_la_SOURCES = test-trie.cpp
test_vector_la_SOURCES = test-vector.cpp
Added: test/unit/core/dat/test-string.cpp (+123 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-string.cpp 2011-11-09 09:16:54 +0000 (84b02df)
@@ -0,0 +1,123 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+ Copyright (C) 2011 Brazil
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License version 2.1 as published by the Free Software Foundation.
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/string.hpp>
+
+namespace test_dat_string
+{
+ void test_empty_string(void)
+ {
+ const grn::dat::String str;
+
+ cppcut_assert_equal(str.ptr(), static_cast<const void *>(NULL));
+ cppcut_assert_equal(str.length(), static_cast<grn::dat::UInt32>(0));
+ }
+
+ void test_constructor_with_length(void)
+ {
+ const char str_buf[] = "日本語";
+ const grn::dat::String str(str_buf, sizeof(str_buf) - 1);
+
+ cppcut_assert_equal(str.ptr(), static_cast<const void *>(str_buf));
+ cppcut_assert_equal(str.length(), static_cast<grn::dat::UInt32>(sizeof(str_buf) - 1));
+ }
+
+ void test_constructor_without_length(void)
+ {
+ const char str_buf[] = "日本語";
+ const grn::dat::String str(str_buf);
+
+ cppcut_assert_equal(str.ptr(), static_cast<const void *>(str_buf));
+ cppcut_assert_equal(str.length(), static_cast<grn::dat::UInt32>(sizeof(str_buf) - 1));
+ }
+
+ void test_copy_constructor(void)
+ {
+ const char str_buf[] = "日本語";
+ const grn::dat::String str_origin(str_buf);
+ const grn::dat::String str_copy(str_origin);
+
+ cppcut_assert_equal(str_origin.ptr(), str_copy.ptr());
+ cppcut_assert_equal(str_origin.length(), str_copy.length());
+ }
+
+ void test_index_access(void)
+ {
+ const char str_buf[] = "日本語";
+ const grn::dat::String str(str_buf);
+
+ for (grn::dat::UInt32 i = 0; i < str.length(); ++i) {
+ cppcut_assert_equal(str[i], static_cast<grn::dat::UInt8>(str_buf[i]));
+ }
+ }
+
+ void test_assign(void)
+ {
+ const char str_buf[] = "日本語";
+
+ grn::dat::String str;
+ str.assign(str_buf, sizeof(str_buf) - 1);
+
+ cppcut_assert_equal(str.ptr(), static_cast<const void *>(str_buf));
+ cppcut_assert_equal(str.length(), static_cast<grn::dat::UInt32>(sizeof(str_buf) - 1));
+ }
+
+ void test_substr(void)
+ {
+ const grn::dat::String str("apple");
+
+ cut_assert(str.substr(3) == grn::dat::String("le"));
+ cut_assert(str.substr(0, 3) == grn::dat::String("app"));
+ cut_assert(str.substr(1, 3) == grn::dat::String("ppl"));
+ }
+
+ void test_compare(void)
+ {
+ const grn::dat::String str("apple");
+
+ cppcut_assert_equal(str.compare(grn::dat::String("apple")), 0);
+ cut_assert(str.compare(grn::dat::String("appl")) > 0);
+ cut_assert(str.compare(grn::dat::String("appleX")) < 0);
+ cut_assert(str.compare(grn::dat::String("banana")) < 0);
+ cut_assert(str.compare(grn::dat::String("and")) > 0);
+ }
+
+ void test_starts_with(void)
+ {
+ const grn::dat::String str("apple");
+
+ cppcut_assert_equal(str.starts_with(grn::dat::String("")), true);
+ cppcut_assert_equal(str.starts_with(grn::dat::String("app")), true);
+ cppcut_assert_equal(str.starts_with(grn::dat::String("apple")), true);
+ cppcut_assert_equal(str.starts_with(grn::dat::String("X")), false);
+ }
+
+ void test_ends_with(void)
+ {
+ const grn::dat::String str("apple");
+
+ cppcut_assert_equal(str.ends_with(grn::dat::String("")), true);
+ cppcut_assert_equal(str.ends_with(grn::dat::String("ple")), true);
+ cppcut_assert_equal(str.ends_with(grn::dat::String("apple")), true);
+ cppcut_assert_equal(str.ends_with(grn::dat::String("X")), false);
+ }
+}