susumu.yata
null+****@clear*****
Tue Mar 12 12:24:52 JST 2013
susumu.yata 2013-03-12 12:24:52 +0900 (Tue, 12 Mar 2013) New Revision: bee35dfafe5b6e09494fac14b9e61451fde97f2a https://github.com/groonga/grnxx/commit/bee35dfafe5b6e09494fac14b9e61451fde97f2a Message: Add tests for grnxx::Charset. Added files: test/test_charset.cpp Modified files: .gitignore test/Makefile.am Modified: .gitignore (+1 -0) =================================================================== --- .gitignore 2013-03-12 12:24:32 +0900 (55613a9) +++ .gitignore 2013-03-12 12:24:52 +0900 (07d1a0f) @@ -30,6 +30,7 @@ temp/ test/test_alpha_double_array test/test_backtrace test/test_broken_down_time +test/test_charset test/test_db_blob_vector test/test_db_vector test/test_duration Modified: test/Makefile.am (+4 -0) =================================================================== --- test/Makefile.am 2013-03-12 12:24:32 +0900 (3009c43) +++ test/Makefile.am 2013-03-12 12:24:52 +0900 (023c9ad) @@ -4,6 +4,7 @@ TESTS = \ test_alpha_double_array \ test_backtrace \ test_broken_down_time \ + test_charset \ test_db_blob_vector \ test_db_vector \ test_duration \ @@ -45,6 +46,9 @@ test_backtrace_LDADD = ../lib/libgrnxx.la test_broken_down_time_SOURCES = test_broken_down_time.cpp test_broken_down_time_LDADD = ../lib/libgrnxx.la +test_charset_SOURCES = test_charset.cpp +test_charset_LDADD = ../lib/libgrnxx.la + test_db_blob_vector_SOURCES = test_db_blob_vector.cpp test_db_blob_vector_LDADD = ../lib/libgrnxx.la Added: test/test_charset.cpp (+99 -0) 100644 =================================================================== --- /dev/null +++ test/test_charset.cpp 2013-03-12 12:24:52 +0900 (b852869) @@ -0,0 +1,99 @@ +/* + 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 "logger.hpp" +#include "charset.hpp" + +void test_ascii() { + const grnxx::Slice query = "Hello, world!"; + + const grnxx::Charset *charset = grnxx::Charset::open(grnxx::CHARSET_EUC_JP); + grnxx::Slice query_left = query; + while (query_left) { + const grnxx::Slice next = charset->get_char(query); + assert(next.size() == 1); + query_left.remove_prefix(next.size()); + } + + charset = grnxx::Charset::open(grnxx::CHARSET_SHIFT_JIS); + query_left = query; + while (query_left) { + const grnxx::Slice next = charset->get_char(query); + assert(next.size() == 1); + query_left.remove_prefix(next.size()); + } + + charset = grnxx::Charset::open(grnxx::CHARSET_UTF_8); + query_left = query; + while (query_left) { + const grnxx::Slice next = charset->get_char(query); + assert(next.size() == 1); + query_left.remove_prefix(next.size()); + } +} + +void test_euc_jp() { + const grnxx::Slice query = "\xCA\xB8\xBB\xFA\xCE\xF3"; + + const grnxx::Charset *charset = grnxx::Charset::open(grnxx::CHARSET_EUC_JP); + grnxx::Slice query_left = query; + while (query_left) { + const grnxx::Slice next = charset->get_char(query); + assert(next.size() == 2); + query_left.remove_prefix(next.size()); + } +} + +void test_shift_jis() { + const grnxx::Slice query = "\x95\xB6\x8E\x9A\x97\xF1"; + + const grnxx::Charset *charset = + grnxx::Charset::open(grnxx::CHARSET_SHIFT_JIS); + grnxx::Slice query_left = query; + while (query_left) { + const grnxx::Slice next = charset->get_char(query); + assert(next.size() == 2); + query_left.remove_prefix(next.size()); + } +} + +void test_utf_8() { + const grnxx::Slice query = "\xE6\x96\x87\xE5\xAD\x97\xE5\x88\x97"; + + const grnxx::Charset *charset = grnxx::Charset::open(grnxx::CHARSET_UTF_8); + grnxx::Slice query_left = query; + while (query_left) { + const grnxx::Slice next = charset->get_char(query); + assert(next.size() == 3); + query_left.remove_prefix(next.size()); + } +} + +int main() { + grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL | + grnxx::LOGGER_ENABLE_COUT); + grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER); + + test_ascii(); + test_euc_jp(); + test_shift_jis(); + test_utf_8(); + + return 0; +} -------------- next part -------------- HTML����������������������������...Download