summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Burrows <Daniel Burrows Daniel_Burrows@alumni.brown.edu>2010-06-07 21:20:46 -0700
committerDaniel Burrows <Daniel Burrows Daniel_Burrows@alumni.brown.edu>2010-06-07 21:20:46 -0700
commitc58a4b52ccfb68fcd26a72b61a5a97407c25e0db (patch)
tree41212bd799aa5204834dd87e38f0f715924ba2e6 /tests
parent8f22bc8461dcc510004449f83a2ba468a7e8198c (diff)
downloadaptitude-c58a4b52ccfb68fcd26a72b61a5a97407c25e0db.tar.gz
Write tests of the transient-message class.
One of the tests fails, and it appears to be a legitimate failure.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/SConscript2
-rw-r--r--tests/test_transient_message.cc210
3 files changed, 214 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 39032716..e0c8b74c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -66,4 +66,5 @@ gtest_test_SOURCES = \
gtest_test_main.cc \
test_logging.cc \
test_teletype_mock.cc \
- test_terminal_mock.cc
+ test_terminal_mock.cc \
+ test_transient_message.cc
diff --git a/tests/SConscript b/tests/SConscript
index 840659e3..3a596bc5 100644
--- a/tests/SConscript
+++ b/tests/SConscript
@@ -114,12 +114,14 @@ gtest_test_sources = [
'test_logging.cc',
'test_teletype_mock.cc',
'test_terminal_mock.cc',
+ 'test_transient_message.o',
]
gtest_test_extra_deps = [
'../src/cmdline/mocks/teletype.o',
'../src/cmdline/mocks/terminal.o',
'../src/cmdline/terminal.o',
+ '../src/cmdline/transient_message.o',
'../src/generic/util/logging.o',
]
diff --git a/tests/test_transient_message.cc b/tests/test_transient_message.cc
new file mode 100644
index 00000000..d76f002c
--- /dev/null
+++ b/tests/test_transient_message.cc
@@ -0,0 +1,210 @@
+/** \file test_transient_message.cc */
+
+
+// Copyright (C) 2010 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 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
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+// Local includes:
+#include <cmdline/mocks/teletype.h>
+#include <cmdline/mocks/terminal.h>
+#include <cmdline/terminal.h>
+#include <cmdline/transient_message.h>
+
+// Global includes:
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+namespace mocks = aptitude::cmdline::mocks;
+
+using aptitude::cmdline::create_transient_message;
+using aptitude::cmdline::mocks::StrTrimmedRightEq;
+using aptitude::cmdline::transient_message;
+using boost::shared_ptr;
+using testing::InSequence;
+using testing::Return;
+using testing::Test;
+using testing::_;
+
+namespace
+{
+ // We'll pretend that '=' is two columns wide.
+ const wchar_t two_column_char = L'=';
+
+ struct TransientMessage : public Test
+ {
+ shared_ptr<mocks::terminal> term;
+ shared_ptr<mocks::terminal_locale> term_locale;
+ shared_ptr<mocks::teletype> teletype;
+ shared_ptr<transient_message> message;
+ std::wstring widechar;
+
+ TransientMessage()
+ : term(mocks::create_combining_terminal()),
+ term_locale(mocks::terminal_locale::create()),
+ teletype(mocks::create_teletype(term, term_locale)),
+ message(create_transient_message(term, term_locale)),
+ widechar(1, two_column_char)
+ {
+ EXPECT_CALL(*term, get_screen_width())
+ .WillRepeatedly(Return(80));
+
+ EXPECT_CALL(*term_locale, wcwidth(two_column_char))
+ .WillRepeatedly(Return(2));
+
+ // The tests should never scroll past the first line (that's the
+ // whole point of the transient message object, after all).
+ EXPECT_CALL(*teletype, newline())
+ .Times(0);
+ }
+ };
+}
+
+TEST_F(TransientMessage, SetText)
+{
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"abc")));
+
+ message->set_text(L"abc");
+}
+
+TEST_F(TransientMessage, ClearText)
+{
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq("abc")));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq("")));
+
+ message->set_text(L"abc");
+ message->set_text(L"");
+}
+
+TEST_F(TransientMessage, ReplaceTextWithShorter)
+{
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"abc")));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"a")));
+
+ message->set_text(L"abc");
+ message->set_text(L"a");
+}
+
+TEST_F(TransientMessage, ReplaceTextWithSameLength)
+{
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"abc")));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"xyz")));
+
+ message->set_text(L"abc");
+ message->set_text(L"xyz");
+}
+
+TEST_F(TransientMessage, ReplaceTextWithLonger)
+{
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"abc")));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"xyzw")));
+
+ message->set_text(L"abc");
+ message->set_text(L"xyzw");
+}
+
+TEST_F(TransientMessage, ReplaceWideCharTextWithShorter)
+{
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(widechar + widechar + widechar)));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"xyz")));
+
+ message->set_text(widechar + widechar + widechar);
+ message->set_text(L"xyz");
+}
+
+TEST_F(TransientMessage, ReplaceWideCharTextWithSameLength)
+{
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(widechar + widechar)));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"abcd")));
+
+ message->set_text(widechar + widechar);
+ message->set_text(L"abcd");
+}
+
+TEST_F(TransientMessage, ReplaceWideCharTextWithLonger)
+{
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(widechar)));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"abc")));
+
+ message->set_text(widechar);
+ message->set_text(L"abc");
+}
+
+TEST_F(TransientMessage, TruncateLongLine)
+{
+ EXPECT_CALL(*term, get_screen_width())
+ .WillRepeatedly(Return(4));
+
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq("abcd")));
+
+ message->set_text(L"abcdefghijklmnopqrstuvwxyz");
+}
+
+TEST_F(TransientMessage, ReplaceTruncatedLongLineWithNonTruncated)
+{
+ EXPECT_CALL(*term, get_screen_width())
+ .WillRepeatedly(Return(4));
+
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq("abcd")));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq("xyz")));
+
+ message->set_text(L"abcdefghijklmnopqrstuvwxyz");
+ message->set_text(L"xyz");
+}
+
+TEST_F(TransientMessage, ReplaceTruncatedLongLineWithTruncated)
+{
+ EXPECT_CALL(*term, get_screen_width())
+ .WillRepeatedly(Return(4));
+
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq("abcd")));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq("zyxw")));
+
+ message->set_text(L"abcdefghijklmnopqrstuvwxyz");
+ message->set_text(L"zyxwvuts");
+}
+
+TEST_F(TransientMessage, TruncateWideCharLine)
+{
+ EXPECT_CALL(*term, get_screen_width())
+ .WillRepeatedly(Return(4));
+
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"ab" + widechar)));
+
+ message->set_text(L"ab" + widechar + L"cdef");
+}
+
+TEST_F(TransientMessage, TruncateWideCharLineWithSplit)
+{
+ EXPECT_CALL(*term, get_screen_width())
+ .WillRepeatedly(Return(4));
+
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"abc")));
+
+ message->set_text(L"abc" + widechar + L"def");
+}
+
+TEST_F(TransientMessage, ReplaceTruncatedWideCharLine)
+{
+ EXPECT_CALL(*term, get_screen_width())
+ .WillRepeatedly(Return(4));
+
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(widechar + widechar)));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"z")));
+
+ message->set_text(widechar + widechar + L"abcdef");
+ message->set_text(L"z");
+}