Merge remote-tracking branch 'origin/release-4-6' into HEAD
[alexxy/gromacs.git] / src / gromacs / onlinehelp / tests / helpformat.cpp
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
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.
13
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.
18  *
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.
25  *
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.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \internal \file
32  * \brief
33  * Tests for help string formatting functions and classes.
34  *
35  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36  * \ingroup module_onlinehelp
37  */
38 #include <gtest/gtest.h>
39
40 #include "gromacs/onlinehelp/helpformat.h"
41
42 #include "testutils/stringtest.h"
43
44 namespace
45 {
46
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";
49
50 /********************************************************************
51  * Tests for TextTableFormatter
52  */
53
54 class TextTableFormatterTest : public gmx::test::StringTestBase
55 {
56     public:
57         void setupStandardColumns();
58
59         gmx::TextTableFormatter formatter_;
60 };
61
62 void TextTableFormatterTest::setupStandardColumns()
63 {
64     formatter_.addColumn("Col1", 4, false);
65     formatter_.addColumn("Col2", 4, false);
66     formatter_.addColumn("Col3Wrap", 14, true);
67     formatter_.addColumn("Col4Wrap", 14, true);
68 }
69
70 TEST_F(TextTableFormatterTest, HandlesBasicCase)
71 {
72     setupStandardColumns();
73     formatter_.clear();
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");
79 }
80
81 TEST_F(TextTableFormatterTest, HandlesEmptyColumnTitles)
82 {
83     formatter_.addColumn(NULL, 4, false);
84     formatter_.addColumn("", 4, false);
85     formatter_.addColumn(NULL, 14, true);
86     formatter_.addColumn("", 14, true);
87
88     formatter_.clear();
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");
94 }
95
96 TEST_F(TextTableFormatterTest, HandlesIndentation)
97 {
98     setupStandardColumns();
99     formatter_.setFirstColumnIndent(4);
100     formatter_.clear();
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");
106 }
107
108 TEST_F(TextTableFormatterTest, HandlesOverflowingLines)
109 {
110     setupStandardColumns();
111     formatter_.clear();
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");
117     formatter_.clear();
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");
124     formatter_.clear();
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");
132 }
133
134 TEST_F(TextTableFormatterTest, HandlesEmptyColumns)
135 {
136     setupStandardColumns();
137     formatter_.clear();
138     formatter_.addColumnLine(0, "foo");
139     formatter_.addColumnLine(1, "bar");
140     formatter_.addColumnLine(3, "Text");
141     checkText(formatter_.formatRow(), "FormattedTable");
142     formatter_.clear();
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");
148     formatter_.clear();
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");
155 }
156
157 } // namespace