2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Tests for help topic management and help topic formatting.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_onlinehelp
44 #include "gromacs/onlinehelp/helpmanager.h"
48 #include <gmock/gmock.h>
49 #include <gtest/gtest.h>
51 #include "gromacs/onlinehelp/helptopic.h"
52 #include "gromacs/onlinehelp/helpwritercontext.h"
53 #include "gromacs/utility/exceptions.h"
54 #include "gromacs/utility/stringstream.h"
56 #include "gromacs/onlinehelp/tests/mock_helptopic.h"
57 #include "testutils/stringtest.h"
58 #include "testutils/testasserts.h"
63 using gmx::test::MockHelpTopic;
65 class HelpTestBase : public gmx::test::StringTestBase
70 MockHelpTopic rootTopic_;
71 gmx::StringOutputStream helpFile_;
72 gmx::HelpWriterContext context_;
73 gmx::HelpManager manager_;
76 HelpTestBase::HelpTestBase()
77 : rootTopic_("", NULL, "Root topic text"),
78 context_(&helpFile_, gmx::eHelpOutputFormat_Console),
79 manager_(rootTopic_, context_)
83 /********************************************************************
84 * Tests for HelpManager
87 //! Test fixture for gmx::HelpManager.
88 typedef HelpTestBase HelpManagerTest;
90 TEST_F(HelpManagerTest, HandlesRootTopic)
93 EXPECT_CALL(rootTopic_, writeHelp(_));
94 manager_.writeCurrentTopic();
97 TEST_F(HelpManagerTest, HandlesSubTopics)
99 MockHelpTopic &first =
100 rootTopic_.addSubTopic("first", "First topic", NULL);
101 MockHelpTopic &firstSub =
102 first.addSubTopic("firstsub", "First subtopic", NULL);
103 rootTopic_.addSubTopic("second", "Second topic", NULL);
106 EXPECT_CALL(firstSub, writeHelp(_));
107 ASSERT_NO_THROW_GMX(manager_.enterTopic("first"));
108 ASSERT_NO_THROW_GMX(manager_.enterTopic("firstsub"));
109 manager_.writeCurrentTopic();
112 TEST_F(HelpManagerTest, HandlesInvalidTopics)
114 MockHelpTopic &first =
115 rootTopic_.addSubTopic("first", "First topic", NULL);
116 first.addSubTopic("firstsub", "First subtopic", NULL);
117 rootTopic_.addSubTopic("second", "Second topic", NULL);
119 ASSERT_THROW_GMX(manager_.enterTopic("unknown"), gmx::InvalidInputError);
120 ASSERT_NO_THROW_GMX(manager_.enterTopic("first"));
121 ASSERT_THROW_GMX(manager_.enterTopic("unknown"), gmx::InvalidInputError);
122 ASSERT_THROW_GMX(manager_.enterTopic("second"), gmx::InvalidInputError);
123 ASSERT_NO_THROW_GMX(manager_.enterTopic("firstsub"));
126 /********************************************************************
127 * Tests for help topic formatting
132 static const char name[];
133 static const char title[];
134 static const char *const text[];
137 const char TestHelpText::name[] = "testtopic";
138 const char TestHelpText::title[] = "Topic title";
139 const char *const TestHelpText::text[] = {
140 "Test topic text.[PAR]",
141 "Another paragraph of text."
144 class HelpTopicFormattingTest : public HelpTestBase
147 void checkHelpFormatting();
150 void HelpTopicFormattingTest::checkHelpFormatting()
152 ASSERT_NO_THROW_GMX(manager_.enterTopic("testtopic"));
153 ASSERT_NO_THROW_GMX(manager_.writeCurrentTopic());
156 checkText(helpFile_.toString(), "HelpText");
159 TEST_F(HelpTopicFormattingTest, FormatsSimpleTopic)
161 rootTopic_.addSubTopic(gmx::HelpTopicPointer(
162 new gmx::SimpleHelpTopic<TestHelpText>));
163 checkHelpFormatting();
166 TEST_F(HelpTopicFormattingTest, FormatsCompositeTopicWithSubTopics)
168 gmx::CompositeHelpTopicPointer topic(new gmx::CompositeHelpTopic<TestHelpText>);
169 MockHelpTopic::addSubTopic(topic.get(), "subtopic", "First subtopic", "Text");
170 MockHelpTopic::addSubTopic(topic.get(), "other", "Second subtopic", "Text");
171 rootTopic_.addSubTopic(move(topic));
172 checkHelpFormatting();