2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012, by the GROMACS development team, led by
5 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 * others, as listed in the AUTHORS file in the top-level source
7 * 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 string formatting functions and classes.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_onlinehelp
42 #include <gtest/gtest.h>
44 #include "gromacs/onlinehelp/helpformat.h"
46 #include "testutils/stringtest.h"
51 //! Simple test string for wrapping.
52 const char g_wrapText[] = "A quick brown fox jumps over the lazy dog";
53 //! Test string for wrapping with embedded line breaks.
54 const char g_wrapText2[] = "A quick brown fox jumps\nover the lazy dog";
56 /********************************************************************
57 * Tests for TextTableFormatter
60 class TextTableFormatterTest : public gmx::test::StringTestBase
63 void setupStandardColumns();
65 gmx::TextTableFormatter formatter_;
68 void TextTableFormatterTest::setupStandardColumns()
70 formatter_.addColumn("Col1", 4, false);
71 formatter_.addColumn("Col2", 4, false);
72 formatter_.addColumn("Col3Wrap", 14, true);
73 formatter_.addColumn("Col4Wrap", 14, true);
76 TEST_F(TextTableFormatterTest, HandlesBasicCase)
78 setupStandardColumns();
80 formatter_.addColumnLine(0, "foo");
81 formatter_.addColumnLine(1, "bar");
82 formatter_.addColumnLine(2, g_wrapText);
83 formatter_.addColumnLine(3, g_wrapText2);
84 checkText(formatter_.formatRow(), "FormattedTable");
87 TEST_F(TextTableFormatterTest, HandlesEmptyColumnTitles)
89 formatter_.addColumn(NULL, 4, false);
90 formatter_.addColumn("", 4, false);
91 formatter_.addColumn(NULL, 14, true);
92 formatter_.addColumn("", 14, true);
95 formatter_.addColumnLine(0, "foo");
96 formatter_.addColumnLine(1, "bar");
97 formatter_.addColumnLine(2, g_wrapText);
98 formatter_.addColumnLine(3, g_wrapText2);
99 checkText(formatter_.formatRow(), "FormattedTable");
102 TEST_F(TextTableFormatterTest, HandlesIndentation)
104 setupStandardColumns();
105 formatter_.setFirstColumnIndent(4);
107 formatter_.addColumnLine(0, "foo");
108 formatter_.addColumnLine(1, "bar");
109 formatter_.addColumnLine(2, g_wrapText);
110 formatter_.addColumnLine(3, g_wrapText2);
111 checkText(formatter_.formatRow(), "FormattedTable");
114 TEST_F(TextTableFormatterTest, HandlesOverflowingLines)
116 setupStandardColumns();
118 formatter_.addColumnLine(0, "foobar");
119 formatter_.addColumnLine(1, "barfoo");
120 formatter_.addColumnLine(2, g_wrapText);
121 formatter_.addColumnLine(3, g_wrapText2);
122 checkText(formatter_.formatRow(), "FormattedTable");
124 formatter_.addColumnLine(0, "foobar");
125 formatter_.addColumnLine(1, "barfoo");
126 formatter_.setColumnFirstLineOffset(1, 1);
127 formatter_.addColumnLine(2, g_wrapText);
128 formatter_.addColumnLine(3, g_wrapText2);
129 checkText(formatter_.formatRow(), "FormattedRow2");
131 formatter_.addColumnLine(0, "foobar");
132 formatter_.addColumnLine(1, "barfoo");
133 formatter_.setColumnFirstLineOffset(1, 1);
134 formatter_.addColumnLine(2, g_wrapText);
135 formatter_.setColumnFirstLineOffset(2, 2);
136 formatter_.addColumnLine(3, g_wrapText2);
137 checkText(formatter_.formatRow(), "FormattedRow3");
140 TEST_F(TextTableFormatterTest, HandlesEmptyColumns)
142 setupStandardColumns();
144 formatter_.addColumnLine(0, "foo");
145 formatter_.addColumnLine(1, "bar");
146 formatter_.addColumnLine(3, "Text");
147 checkText(formatter_.formatRow(), "FormattedTable");
149 formatter_.addColumnLine(0, "foo");
150 formatter_.addColumnLine(1, "bar");
151 formatter_.setColumnFirstLineOffset(2, 1);
152 formatter_.addColumnLine(3, "Text");
153 checkText(formatter_.formatRow(), "FormattedRow2");
155 formatter_.addColumnLine(0, "foo");
156 formatter_.addColumnLine(1, "bar");
157 formatter_.addColumnLine(2, "");
158 formatter_.setColumnFirstLineOffset(2, 1);
159 formatter_.addColumnLine(3, "Text");
160 checkText(formatter_.formatRow(), "FormattedRow3");