2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, 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 string formatting functions and classes.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_onlinehelp
44 #include "gromacs/onlinehelp/helpformat.h"
46 #include <gtest/gtest.h>
48 #include "testutils/stringtest.h"
53 //! Simple test string for wrapping.
54 const char g_wrapText[] = "A quick brown fox jumps over the lazy dog";
55 //! Test string for wrapping with embedded line breaks.
56 const char g_wrapText2[] = "A quick brown fox jumps\nover the lazy dog";
58 /********************************************************************
59 * Tests for TextTableFormatter
62 class TextTableFormatterTest : public gmx::test::StringTestBase
65 void setupStandardColumns();
67 gmx::TextTableFormatter formatter_;
70 void TextTableFormatterTest::setupStandardColumns()
72 formatter_.addColumn("Col1", 4, false);
73 formatter_.addColumn("Col2", 4, false);
74 formatter_.addColumn("Col3Wrap", 14, true);
75 formatter_.addColumn("Col4Wrap", 14, true);
78 TEST_F(TextTableFormatterTest, HandlesBasicCase)
80 setupStandardColumns();
82 formatter_.addColumnLine(0, "foo");
83 formatter_.addColumnLine(1, "bar");
84 formatter_.addColumnLine(2, g_wrapText);
85 formatter_.addColumnLine(3, g_wrapText2);
86 checkText(formatter_.formatRow(), "FormattedTable");
89 TEST_F(TextTableFormatterTest, HandlesEmptyColumnTitles)
91 formatter_.addColumn(NULL, 4, false);
92 formatter_.addColumn("", 4, false);
93 formatter_.addColumn(NULL, 14, true);
94 formatter_.addColumn("", 14, true);
97 formatter_.addColumnLine(0, "foo");
98 formatter_.addColumnLine(1, "bar");
99 formatter_.addColumnLine(2, g_wrapText);
100 formatter_.addColumnLine(3, g_wrapText2);
101 checkText(formatter_.formatRow(), "FormattedTable");
104 TEST_F(TextTableFormatterTest, HandlesIndentation)
106 setupStandardColumns();
107 formatter_.setFirstColumnIndent(4);
109 formatter_.addColumnLine(0, "foo");
110 formatter_.addColumnLine(1, "bar");
111 formatter_.addColumnLine(2, g_wrapText);
112 formatter_.addColumnLine(3, g_wrapText2);
113 checkText(formatter_.formatRow(), "FormattedTable");
116 TEST_F(TextTableFormatterTest, HandlesOverflowingLines)
118 setupStandardColumns();
120 formatter_.addColumnLine(0, "foobar");
121 formatter_.addColumnLine(1, "barfoo");
122 formatter_.addColumnLine(2, g_wrapText);
123 formatter_.addColumnLine(3, g_wrapText2);
124 checkText(formatter_.formatRow(), "FormattedTable");
126 formatter_.addColumnLine(0, "foobar");
127 formatter_.addColumnLine(1, "barfoo");
128 formatter_.setColumnFirstLineOffset(1, 1);
129 formatter_.addColumnLine(2, g_wrapText);
130 formatter_.addColumnLine(3, g_wrapText2);
131 checkText(formatter_.formatRow(), "FormattedRow2");
133 formatter_.addColumnLine(0, "foobar");
134 formatter_.addColumnLine(1, "barfoo");
135 formatter_.setColumnFirstLineOffset(1, 1);
136 formatter_.addColumnLine(2, g_wrapText);
137 formatter_.setColumnFirstLineOffset(2, 2);
138 formatter_.addColumnLine(3, g_wrapText2);
139 checkText(formatter_.formatRow(), "FormattedRow3");
140 // Test a case where a column value overflows even the next column.
141 formatter_.addColumnLine(0, "foobarfoobar");
142 formatter_.addColumnLine(1, "barfoobarfoo");
143 formatter_.addColumnLine(2, g_wrapText);
144 formatter_.addColumnLine(3, g_wrapText2);
145 checkText(formatter_.formatRow(), "FormattedRow4");
148 TEST_F(TextTableFormatterTest, HandlesLastColumnFolding)
150 setupStandardColumns();
151 formatter_.setFoldLastColumnToNextLine(4);
153 formatter_.addColumnLine(0, "foo");
154 formatter_.addColumnLine(1, "bar");
155 formatter_.addColumnLine(2, "text");
156 formatter_.addColumnLine(3, g_wrapText);
157 checkText(formatter_.formatRow(), "FormattedTable");
159 formatter_.addColumnLine(0, "foo");
160 formatter_.addColumnLine(1, "bar");
161 formatter_.addColumnLine(2, "text");
162 formatter_.addColumnLine(3, g_wrapText2);
163 checkText(formatter_.formatRow(), "FormattedRow2");
165 formatter_.addColumnLine(0, "foo");
166 formatter_.addColumnLine(1, "bar");
167 formatter_.addColumnLine(2, "text");
168 formatter_.addColumnLine(3, "A quick brown fox jumps");
169 checkText(formatter_.formatRow(), "FormattedRow3");
172 TEST_F(TextTableFormatterTest, HandlesEmptyColumns)
174 setupStandardColumns();
176 formatter_.addColumnLine(0, "foo");
177 formatter_.addColumnLine(1, "bar");
178 formatter_.addColumnLine(3, "Text");
179 checkText(formatter_.formatRow(), "FormattedTable");
181 formatter_.addColumnLine(0, "foo");
182 formatter_.addColumnLine(1, "bar");
183 formatter_.setColumnFirstLineOffset(2, 1);
184 formatter_.addColumnLine(3, "Text");
185 checkText(formatter_.formatRow(), "FormattedRow2");
187 formatter_.addColumnLine(0, "foo");
188 formatter_.addColumnLine(1, "bar");
189 formatter_.addColumnLine(2, "");
190 formatter_.setColumnFirstLineOffset(2, 1);
191 formatter_.addColumnLine(3, "Text");
192 checkText(formatter_.formatRow(), "FormattedRow3");