This is an automated email from the git hooks/post-receive script. plessy pushed a commit to branch debian/unstable in repository libgtextutils.
commit 187e4f2457eab40ea1658ea777616b5fe71953a4 Author: A. Gordon <[email protected]> Date: Wed Mar 25 19:56:34 2009 -0400 Added tests to TextLineReader and InputStreamWrapper. --- tests/Makefile.am | 11 ++++- tests/test_input_stream_wrapper.cpp | 49 +++++++++++++++++++++ tests/test_text_reader.cpp | 73 ++++++++++++++++++++++++++++++ tests/test_text_reader_unget.cpp | 88 +++++++++++++++++++++++++++++++++++++ 4 files changed, 220 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 61876a5..7e31520 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -9,9 +9,14 @@ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +noinst_DATA = test.txt + check_PROGRAMS = test_container_join \ - test_natural_sort + test_natural_sort \ + test_input_stream_wrapper \ + test_text_reader \ + test_text_reader_unget TESTS = $(check_PROGRAMS) @@ -20,3 +25,7 @@ INCLUDES = -I$(top_srcdir)/src test_container_join_SOURCES = test_container_join.cpp test_natural_sort_SOURCES = test_natural_sort.cpp +test_input_stream_wrapper_SOURCES = test_input_stream_wrapper.cpp +test_text_reader_SOURCES = test_text_reader.cpp +test_text_reader_unget_SOURCES = test_text_reader_unget.cpp + diff --git a/tests/test_input_stream_wrapper.cpp b/tests/test_input_stream_wrapper.cpp new file mode 100644 index 0000000..72dc6ba --- /dev/null +++ b/tests/test_input_stream_wrapper.cpp @@ -0,0 +1,49 @@ +/* + Gordon's Text-Utilities Library + Copyright (C) 2009 Assaf Gordon ([email protected]) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/> +*/ +#include <err.h> +#include <iostream> +#include <string> +#include <gtextutils/stream_wrapper.h> +#include "tests_assertion.h" + +/* + * Simple unit test - InputStreamWrapper + * + * Read the first word out of a test file (whose content we know), + */ + +using namespace std; + +int main() +{ + //The object will create a 'ifstream' file with this file, + //or exit if there was an error + InputStreamWrapper input("test.txt"); + + // InputStreamWrapper can be used as 'istream&' + // with it's conversion operator + istream& is ( input ) ; + + std::string s; + + is >> s ; + + ASSERT ( s == "first" ) ; + + return 0; +} diff --git a/tests/test_text_reader.cpp b/tests/test_text_reader.cpp new file mode 100644 index 0000000..f40a44b --- /dev/null +++ b/tests/test_text_reader.cpp @@ -0,0 +1,73 @@ +/* + Gordon's Text-Utilities Library + Copyright (C) 2009 Assaf Gordon ([email protected]) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/> +*/ +#include <err.h> +#include <iostream> +#include <string> + +#include <gtextutils/stream_wrapper.h> +#include <gtextutils/text_line_reader.h> + +#include "tests_assertion.h" + +/* + * Testing the TextLineReader class + * + * Read four lines from a known file, + * using different methods + */ + +using namespace std; + +int main() +{ + InputStreamWrapper input("test.txt"); + TextLineReader reader ( input.stream() ); + + string line ; + + ASSERT ( reader.next_line() ); + line = reader.line_string() ; //first line - with explicit method to get the string + ASSERT( line == "first line" ) ; + + ASSERT ( reader.next_line() ); + line = reader ; //second line - with implicit conversion to std::string + ASSERT( line == "second line" ) ; + + ASSERT ( reader.next_line() ); + istream &is1 ( reader.line_stream() ); //third line - with explicit method to get the istream + is1 >> line ; // read each word from the line + ASSERT( line == "third" ) ; + is1 >> line ; + ASSERT ( line == "line" ) ; + is1 >> line ; // read past the end of the line - this should fail (and not read the next word from the next line, as it would have happened with a normal istream; + ASSERT ( ! is1 ) ; + + ASSERT ( reader.next_line() ); + istream &is2 ( reader ) ; // fourth line - with implicit conversion to std::istream + is2 >> line ; + ASSERT( line == "fourth" ) ; + is2 >> line ; + ASSERT( line == "line" ) ; + is1 >> line ; // read past the end of the line - this should fail (and not read the next word from the next line + ASSERT ( !is2 ) ; + + + //read past the end of the file - make sure it fails. + ASSERT ( !reader.next_line() ) ; + return 0; +} diff --git a/tests/test_text_reader_unget.cpp b/tests/test_text_reader_unget.cpp new file mode 100644 index 0000000..a23f8a8 --- /dev/null +++ b/tests/test_text_reader_unget.cpp @@ -0,0 +1,88 @@ +/* + Gordon's Text-Utilities Library + Copyright (C) 2009 Assaf Gordon ([email protected]) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/> +*/ +#include <err.h> +#include <iostream> +#include <string> + +#include <gtextutils/stream_wrapper.h> +#include <gtextutils/text_line_reader.h> + +#include "tests_assertion.h" + +using namespace std; + +int main() +{ + InputStreamWrapper input("test.txt"); + TextLineReader reader ( input.stream() ); + + string line ; + + //Read first line + ASSERT ( reader.next_line() ); + line = reader; + ASSERT( line == "first line" ) ; + + //Unget the current line - + //The next call to 'reader.next_line' should return this SAME line + //instead of actually reading the next line from the file. + reader.unget_current_line(); + + //Read the next line - + //but because of the 'unget' it should still return the first line + ASSERT ( reader.next_line() ) ; + line = reader ; + ASSERT( line == "first line" ) ; + ASSERT ( reader.line_number() == 1 ) ; //we should still be on line 1 + + + //Read the next line - + //This should be the real second line from the file. + ASSERT ( reader.next_line() ) ; + line = reader; + ASSERT ( line == "second line" ); + ASSERT ( reader.line_number() == 2 ) ; + + //Test multiple consecutive ungets + for ( int i=0 ; i < 10; ++i ) { + reader.unget_current_line(); + + ASSERT ( reader.next_line() ) ; + line = reader; + ASSERT ( line == "second line" ); + ASSERT ( reader.line_number() == 2 ) ; + } + + //Read the next line - + //This should be the real third line from the file. + ASSERT ( reader.next_line() ) ; + line = reader; + ASSERT ( line == "third line" ); + ASSERT ( reader.line_number() == 3 ) ; + + //Unget a custom line string + reader.unget_line("hello world"); + + + //Read the next line - this should return the ungot text ("hello world") + ASSERT ( reader.next_line() ) ; + line = reader; + ASSERT ( line == "hello world" ); + + return 0; +} -- Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/libgtextutils.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
