3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
33 * Tests for help topic management and help topic formatting.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36 * \ingroup module_onlinehelp
38 #include "gromacs/onlinehelp/helpmanager.h"
42 #include <gmock/gmock.h>
43 #include <gtest/gtest.h>
45 #include "gromacs/onlinehelp/helptopic.h"
46 #include "gromacs/onlinehelp/helpwritercontext.h"
47 #include "gromacs/utility/exceptions.h"
48 #include "gromacs/utility/file.h"
50 #include "testutils/mock_helptopic.h"
51 #include "testutils/stringtest.h"
52 #include "testutils/testfilemanager.h"
57 using gmx::test::MockHelpTopic;
59 class HelpTestBase : public gmx::test::StringTestBase
64 gmx::test::TestFileManager tempFiles_;
65 MockHelpTopic rootTopic_;
66 std::string filename_;
68 gmx::HelpWriterContext context_;
69 gmx::HelpManager manager_;
72 HelpTestBase::HelpTestBase()
73 : rootTopic_("", NULL, "Root topic text"),
74 filename_(tempFiles_.getTemporaryFilePath("helptext.txt")),
75 helpFile_(filename_, "w"),
76 context_(&helpFile_, gmx::eHelpOutputFormat_Console),
77 manager_(rootTopic_, context_)
81 /********************************************************************
82 * Tests for HelpManager
85 //! Test fixture for gmx::HelpManager.
86 typedef HelpTestBase HelpManagerTest;
88 TEST_F(HelpManagerTest, HandlesRootTopic)
91 EXPECT_CALL(rootTopic_, writeHelp(_));
92 manager_.writeCurrentTopic();
95 TEST_F(HelpManagerTest, HandlesSubTopics)
97 MockHelpTopic &first =
98 rootTopic_.addSubTopic("first", "First topic", "First topic text");
99 MockHelpTopic &firstSub =
100 first.addSubTopic("firstsub", "First subtopic", "First subtopic text");
101 rootTopic_.addSubTopic("second", "Second topic", "Second topic text");
104 EXPECT_CALL(firstSub, writeHelp(_));
105 ASSERT_NO_THROW(manager_.enterTopic("first"));
106 ASSERT_NO_THROW(manager_.enterTopic("firstsub"));
107 manager_.writeCurrentTopic();
110 TEST_F(HelpManagerTest, HandlesInvalidTopics)
112 MockHelpTopic &first =
113 rootTopic_.addSubTopic("first", "First topic", "First topic text");
114 first.addSubTopic("firstsub", "First subtopic", "First subtopic text");
115 rootTopic_.addSubTopic("second", "Second topic", "Second topic text");
117 ASSERT_THROW(manager_.enterTopic("unknown"), gmx::InvalidInputError);
118 ASSERT_NO_THROW(manager_.enterTopic("first"));
119 ASSERT_THROW(manager_.enterTopic("unknown"), gmx::InvalidInputError);
120 ASSERT_THROW(manager_.enterTopic("second"), gmx::InvalidInputError);
121 ASSERT_NO_THROW(manager_.enterTopic("firstsub"));
124 /********************************************************************
125 * Tests for help topic formatting
130 static const char name[];
131 static const char title[];
132 static const char *const text[];
135 const char TestHelpText::name[] = "testtopic";
136 const char TestHelpText::title[] = "Topic title";
137 const char *const TestHelpText::text[] = {
138 "Test topic text.[PAR]",
139 "Another paragraph of text."
142 class HelpTopicFormattingTest : public HelpTestBase
145 void checkHelpFormatting();
148 void HelpTopicFormattingTest::checkHelpFormatting()
150 ASSERT_NO_THROW(manager_.enterTopic("testtopic"));
151 ASSERT_NO_THROW(manager_.writeCurrentTopic());
154 checkFileContents(filename_, "HelpText");
157 TEST_F(HelpTopicFormattingTest, FormatsSimpleTopic)
159 rootTopic_.addSubTopic(gmx::HelpTopicPointer(
160 new gmx::SimpleHelpTopic<TestHelpText>));
161 checkHelpFormatting();
164 TEST_F(HelpTopicFormattingTest, FormatsCompositeTopicWithSubTopics)
166 gmx::CompositeHelpTopicPointer topic(new gmx::CompositeHelpTopic<TestHelpText>);
167 MockHelpTopic::addSubTopic(topic.get(), "subtopic", "First subtopic", "Text");
168 MockHelpTopic::addSubTopic(topic.get(), "other", "Second subtopic", "Text");
169 rootTopic_.addSubTopic(move(topic));
170 checkHelpFormatting();