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 //! Simple test string for wrapping.
48 const char g_wrapText[] = "A quick brown fox jumps over the lazy dog";
49 //! Test string for wrapping with embedded line breaks.
50 const char g_wrapText2[] = "A quick brown fox jumps\nover the lazy dog";
52 /********************************************************************
53 * Tests for TextTableFormatter
56 class TextTableFormatterTest : public gmx::test::StringTestBase
59 void setupStandardColumns();
61 gmx::TextTableFormatter formatter_;
64 void TextTableFormatterTest::setupStandardColumns()
66 formatter_.addColumn("Col1", 4, false);
67 formatter_.addColumn("Col2", 4, false);
68 formatter_.addColumn("Col3Wrap", 14, true);
69 formatter_.addColumn("Col4Wrap", 14, true);
72 TEST_F(TextTableFormatterTest, HandlesBasicCase)
74 setupStandardColumns();
76 formatter_.addColumnLine(0, "foo");
77 formatter_.addColumnLine(1, "bar");
78 formatter_.addColumnLine(2, g_wrapText);
79 formatter_.addColumnLine(3, g_wrapText2);
80 checkText(formatter_.formatRow(), "FormattedTable");
83 TEST_F(TextTableFormatterTest, HandlesEmptyColumnTitles)
85 formatter_.addColumn(NULL, 4, false);
86 formatter_.addColumn("", 4, false);
87 formatter_.addColumn(NULL, 14, true);
88 formatter_.addColumn("", 14, true);
91 formatter_.addColumnLine(0, "foo");
92 formatter_.addColumnLine(1, "bar");
93 formatter_.addColumnLine(2, g_wrapText);
94 formatter_.addColumnLine(3, g_wrapText2);
95 checkText(formatter_.formatRow(), "FormattedTable");
98 TEST_F(TextTableFormatterTest, HandlesIndentation)
100 setupStandardColumns();
101 formatter_.setFirstColumnIndent(4);
103 formatter_.addColumnLine(0, "foo");
104 formatter_.addColumnLine(1, "bar");
105 formatter_.addColumnLine(2, g_wrapText);
106 formatter_.addColumnLine(3, g_wrapText2);
107 checkText(formatter_.formatRow(), "FormattedTable");
110 TEST_F(TextTableFormatterTest, HandlesOverflowingLines)
112 setupStandardColumns();
114 formatter_.addColumnLine(0, "foobar");
115 formatter_.addColumnLine(1, "barfoo");
116 formatter_.addColumnLine(2, g_wrapText);
117 formatter_.addColumnLine(3, g_wrapText2);
118 checkText(formatter_.formatRow(), "FormattedTable");
120 formatter_.addColumnLine(0, "foobar");
121 formatter_.addColumnLine(1, "barfoo");
122 formatter_.setColumnFirstLineOffset(1, 1);
123 formatter_.addColumnLine(2, g_wrapText);
124 formatter_.addColumnLine(3, g_wrapText2);
125 checkText(formatter_.formatRow(), "FormattedRow2");
127 formatter_.addColumnLine(0, "foobar");
128 formatter_.addColumnLine(1, "barfoo");
129 formatter_.setColumnFirstLineOffset(1, 1);
130 formatter_.addColumnLine(2, g_wrapText);
131 formatter_.setColumnFirstLineOffset(2, 2);
132 formatter_.addColumnLine(3, g_wrapText2);
133 checkText(formatter_.formatRow(), "FormattedRow3");
136 TEST_F(TextTableFormatterTest, HandlesEmptyColumns)
138 setupStandardColumns();
140 formatter_.addColumnLine(0, "foo");
141 formatter_.addColumnLine(1, "bar");
142 formatter_.addColumnLine(3, "Text");
143 checkText(formatter_.formatRow(), "FormattedTable");
145 formatter_.addColumnLine(0, "foo");
146 formatter_.addColumnLine(1, "bar");
147 formatter_.setColumnFirstLineOffset(2, 1);
148 formatter_.addColumnLine(3, "Text");
149 checkText(formatter_.formatRow(), "FormattedRow2");
151 formatter_.addColumnLine(0, "foo");
152 formatter_.addColumnLine(1, "bar");
153 formatter_.addColumnLine(2, "");
154 formatter_.setColumnFirstLineOffset(2, 1);
155 formatter_.addColumnLine(3, "Text");
156 checkText(formatter_.formatRow(), "FormattedRow3");