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 string formatting functions and classes.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36 * \ingroup module_onlinehelp
38 #include <gtest/gtest.h>
40 #include "gromacs/onlinehelp/helpformat.h"
42 #include "testutils/stringtest.h"
47 const char g_wrapText[] = "A quick brown fox jumps over the lazy dog";
48 const char g_wrapText2[] = "A quick brown fox jumps\nover the lazy dog";
50 /********************************************************************
51 * Tests for TextTableFormatter
54 class TextTableFormatterTest : public gmx::test::StringTestBase
57 void setupStandardColumns();
59 gmx::TextTableFormatter formatter_;
62 void TextTableFormatterTest::setupStandardColumns()
64 formatter_.addColumn("Col1", 4, false);
65 formatter_.addColumn("Col2", 4, false);
66 formatter_.addColumn("Col3Wrap", 14, true);
67 formatter_.addColumn("Col4Wrap", 14, true);
70 TEST_F(TextTableFormatterTest, HandlesBasicCase)
72 setupStandardColumns();
74 formatter_.addColumnLine(0, "foo");
75 formatter_.addColumnLine(1, "bar");
76 formatter_.addColumnLine(2, g_wrapText);
77 formatter_.addColumnLine(3, g_wrapText2);
78 checkText(formatter_.formatRow(), "FormattedTable");
81 TEST_F(TextTableFormatterTest, HandlesEmptyColumnTitles)
83 formatter_.addColumn(NULL, 4, false);
84 formatter_.addColumn("", 4, false);
85 formatter_.addColumn(NULL, 14, true);
86 formatter_.addColumn("", 14, true);
89 formatter_.addColumnLine(0, "foo");
90 formatter_.addColumnLine(1, "bar");
91 formatter_.addColumnLine(2, g_wrapText);
92 formatter_.addColumnLine(3, g_wrapText2);
93 checkText(formatter_.formatRow(), "FormattedTable");
96 TEST_F(TextTableFormatterTest, HandlesIndentation)
98 setupStandardColumns();
99 formatter_.setFirstColumnIndent(4);
101 formatter_.addColumnLine(0, "foo");
102 formatter_.addColumnLine(1, "bar");
103 formatter_.addColumnLine(2, g_wrapText);
104 formatter_.addColumnLine(3, g_wrapText2);
105 checkText(formatter_.formatRow(), "FormattedTable");
108 TEST_F(TextTableFormatterTest, HandlesOverflowingLines)
110 setupStandardColumns();
112 formatter_.addColumnLine(0, "foobar");
113 formatter_.addColumnLine(1, "barfoo");
114 formatter_.addColumnLine(2, g_wrapText);
115 formatter_.addColumnLine(3, g_wrapText2);
116 checkText(formatter_.formatRow(), "FormattedTable");
118 formatter_.addColumnLine(0, "foobar");
119 formatter_.addColumnLine(1, "barfoo");
120 formatter_.setColumnFirstLineOffset(1, 1);
121 formatter_.addColumnLine(2, g_wrapText);
122 formatter_.addColumnLine(3, g_wrapText2);
123 checkText(formatter_.formatRow(), "FormattedRow2");
125 formatter_.addColumnLine(0, "foobar");
126 formatter_.addColumnLine(1, "barfoo");
127 formatter_.setColumnFirstLineOffset(1, 1);
128 formatter_.addColumnLine(2, g_wrapText);
129 formatter_.setColumnFirstLineOffset(2, 2);
130 formatter_.addColumnLine(3, g_wrapText2);
131 checkText(formatter_.formatRow(), "FormattedRow3");
134 TEST_F(TextTableFormatterTest, HandlesEmptyColumns)
136 setupStandardColumns();
138 formatter_.addColumnLine(0, "foo");
139 formatter_.addColumnLine(1, "bar");
140 formatter_.addColumnLine(3, "Text");
141 checkText(formatter_.formatRow(), "FormattedTable");
143 formatter_.addColumnLine(0, "foo");
144 formatter_.addColumnLine(1, "bar");
145 formatter_.setColumnFirstLineOffset(2, 1);
146 formatter_.addColumnLine(3, "Text");
147 checkText(formatter_.formatRow(), "FormattedRow2");
149 formatter_.addColumnLine(0, "foo");
150 formatter_.addColumnLine(1, "bar");
151 formatter_.addColumnLine(2, "");
152 formatter_.setColumnFirstLineOffset(2, 1);
153 formatter_.addColumnLine(3, "Text");
154 checkText(formatter_.formatRow(), "FormattedRow3");