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
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");
138 // Test a case where a column value overflows even the next column.
139 formatter_.addColumnLine(0, "foobarfoobar");
140 formatter_.addColumnLine(1, "barfoobarfoo");
141 formatter_.addColumnLine(2, g_wrapText);
142 formatter_.addColumnLine(3, g_wrapText2);
143 checkText(formatter_.formatRow(), "FormattedRow4");
146 TEST_F(TextTableFormatterTest, HandlesLastColumnFolding)
148 setupStandardColumns();
149 formatter_.setFoldLastColumnToNextLine(4);
151 formatter_.addColumnLine(0, "foo");
152 formatter_.addColumnLine(1, "bar");
153 formatter_.addColumnLine(2, "text");
154 formatter_.addColumnLine(3, g_wrapText);
155 checkText(formatter_.formatRow(), "FormattedTable");
157 formatter_.addColumnLine(0, "foo");
158 formatter_.addColumnLine(1, "bar");
159 formatter_.addColumnLine(2, "text");
160 formatter_.addColumnLine(3, g_wrapText2);
161 checkText(formatter_.formatRow(), "FormattedRow2");
163 formatter_.addColumnLine(0, "foo");
164 formatter_.addColumnLine(1, "bar");
165 formatter_.addColumnLine(2, "text");
166 formatter_.addColumnLine(3, "A quick brown fox jumps");
167 checkText(formatter_.formatRow(), "FormattedRow3");
170 TEST_F(TextTableFormatterTest, HandlesEmptyColumns)
172 setupStandardColumns();
174 formatter_.addColumnLine(0, "foo");
175 formatter_.addColumnLine(1, "bar");
176 formatter_.addColumnLine(3, "Text");
177 checkText(formatter_.formatRow(), "FormattedTable");
179 formatter_.addColumnLine(0, "foo");
180 formatter_.addColumnLine(1, "bar");
181 formatter_.setColumnFirstLineOffset(2, 1);
182 formatter_.addColumnLine(3, "Text");
183 checkText(formatter_.formatRow(), "FormattedRow2");
185 formatter_.addColumnLine(0, "foo");
186 formatter_.addColumnLine(1, "bar");
187 formatter_.addColumnLine(2, "");
188 formatter_.setColumnFirstLineOffset(2, 1);
189 formatter_.addColumnLine(3, "Text");
190 checkText(formatter_.formatRow(), "FormattedRow3");