summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel_Burrows@alumni.brown.edu <Daniel_Burrows@alumni.brown.edu>2010-06-30 18:45:32 -0700
committerDaniel Burrows <Daniel Burrows Daniel_Burrows@alumni.brown.edu>2010-06-30 21:31:26 -0700
commit4f75af1c96d21f0a7be0d6fc346ba8aa80c35dff (patch)
tree48dc8a976637d8b8496ae431410204b6ec1523f8 /tests
parentd3e3fd8731a86e4e27541dcbbba2149b9934e267 (diff)
downloadaptitude-4f75af1c96d21f0a7be0d6fc346ba8aa80c35dff.tar.gz
Add a view interface for displaying the download progress and an implementation for showing the download progress at the command line and a stub implementation.
This is mostly just a streamlining of the apt interface, but putting the code behind a clean view will also make it much more testable.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/SConscript1
-rw-r--r--tests/test_cmdline_download_progress_display.cc106
3 files changed, 109 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5cca3a79..12a7ecb9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,6 +18,7 @@ $(top_builddir)/src/generic/problemresolver/libgeneric-problemresolver.a \
$(top_builddir)/src/cmdline/mocks/libcmdline-mocks.a \
$(top_builddir)/src/cmdline/libcmdline.a \
$(top_builddir)/src/generic/util/libgeneric-util.a \
+$(top_builddir)/src/generic/views/libgeneric-views.a \
-lcppunit \
$(BOOST_TEST_LDFLAGS) $(GMOCK_LDFLAGS)
@@ -68,6 +69,7 @@ boost_test_SOURCES = \
gtest_test_SOURCES = \
gtest_test_main.cc \
+ test_cmdline_download_progress_display.cc \
test_cmdline_progress_display.cc \
test_cmdline_search_progress.cc \
test_logging.cc \
diff --git a/tests/SConscript b/tests/SConscript
index 86b8ba35..13614953 100644
--- a/tests/SConscript
+++ b/tests/SConscript
@@ -92,6 +92,7 @@ boost_test_extra_deps = [
gtest_test_sources = [
'gtest_test_main.cc',
+ 'test_cmdline_download_progress_display.cc',
'test_cmdline_progress_display.cc',
'test_cmdline_search_progress.cc',
'test_logging.cc',
diff --git a/tests/test_cmdline_download_progress_display.cc b/tests/test_cmdline_download_progress_display.cc
new file mode 100644
index 00000000..06b6c9e1
--- /dev/null
+++ b/tests/test_cmdline_download_progress_display.cc
@@ -0,0 +1,106 @@
+/** \file test_cmdline_download_progress_display.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/cmdline_download_progress_display.h>
+#include <cmdline/mocks/terminal.h>
+#include <cmdline/mocks/transient_message.h>
+
+// System includes:
+#include <boost/make_shared.hpp>
+#include <boost/shared_ptr.hpp>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using aptitude::cmdline::create_download_progress_display;
+using aptitude::views::download_progress;
+using boost::make_shared;
+using boost::shared_ptr;
+using testing::Return;
+using testing::Test;
+using testing::_;
+
+namespace mocks = aptitude::cmdline::mocks;
+
+namespace
+{
+ // We pretend this character occupies two cells and all the rest
+ // occupy only one.
+ const wchar_t two_column_char = L'-';
+
+ struct CmdlineDownloadProgressDisplayTest : public Test
+ {
+ shared_ptr<mocks::transient_message> msg;
+ shared_ptr<mocks::terminal> term;
+ shared_ptr<mocks::terminal_locale> term_locale;
+
+ shared_ptr<download_progress> progress;
+
+ CmdlineDownloadProgressDisplayTest()
+ : msg(make_shared<mocks::transient_message>()),
+ term(mocks::terminal::create()),
+ term_locale(mocks::terminal_locale::create()),
+ progress(create_download_progress_display(msg, term, term_locale))
+ {
+ // Expect no occurrences of the terminal routines other than
+ // get_screen_width() (normally they would be invoked by the
+ // message, but that's a mock in this case).
+
+ // TODO: is there a way to ask the mock to always reject
+ // unexpected calls?
+ EXPECT_CALL(*term, output_is_a_terminal())
+ .Times(0);
+
+ EXPECT_CALL(*term, write_text(_))
+ .Times(0);
+
+ EXPECT_CALL(*term, move_to_beginning_of_line())
+ .Times(0);
+
+ EXPECT_CALL(*term, flush())
+ .Times(0);
+
+ EXPECT_CALL(*term, prompt_for_input(_))
+ .Times(0);
+
+ EXPECT_CALL(*term, output(_))
+ .Times(0);
+
+ // Make the terminal 20 characters wide by default (the progress
+ // display always outputs messages that are as wide as the
+ // terminal, so too wide a value would be a pain).
+ EXPECT_CALL(*term, get_screen_width())
+ .WillRepeatedly(Return(80));
+
+
+ // Set up the locale to claim that the two-column character
+ // occupies two columns.
+ EXPECT_CALL(*term_locale, wcwidth(two_column_char))
+ .WillRepeatedly(Return(2));
+ }
+ };
+}
+
+// Test that there are no unexpected calls just from creating the
+// download progress display.
+TEST_F(CmdlineDownloadProgressDisplayTest, CreateDoesNothing)
+{
+}