Separated string formatting used only for help.
[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         TextTableFormatterTest();
58
59         gmx::TextTableFormatter formatter_;
60 };
61
62 TextTableFormatterTest::TextTableFormatterTest()
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     formatter_.clear();
73     formatter_.addColumnLine(0, "foo");
74     formatter_.addColumnLine(1, "bar");
75     formatter_.addColumnLine(2, g_wrapText);
76     formatter_.addColumnLine(3, g_wrapText2);
77     checkText(formatter_.formatRow(), "FormattedTable");
78 }
79
80 TEST_F(TextTableFormatterTest, HandlesOverflowingLines)
81 {
82     formatter_.clear();
83     formatter_.addColumnLine(0, "foobar");
84     formatter_.addColumnLine(1, "barfoo");
85     formatter_.addColumnLine(2, g_wrapText);
86     formatter_.addColumnLine(3, g_wrapText2);
87     checkText(formatter_.formatRow(), "FormattedTable");
88     formatter_.clear();
89     formatter_.addColumnLine(0, "foobar");
90     formatter_.addColumnLine(1, "barfoo");
91     formatter_.setColumnFirstLineOffset(1, 1);
92     formatter_.addColumnLine(2, g_wrapText);
93     formatter_.addColumnLine(3, g_wrapText2);
94     checkText(formatter_.formatRow(), "FormattedRow2");
95     formatter_.clear();
96     formatter_.addColumnLine(0, "foobar");
97     formatter_.addColumnLine(1, "barfoo");
98     formatter_.setColumnFirstLineOffset(1, 1);
99     formatter_.addColumnLine(2, g_wrapText);
100     formatter_.setColumnFirstLineOffset(2, 2);
101     formatter_.addColumnLine(3, g_wrapText2);
102     checkText(formatter_.formatRow(), "FormattedRow3");
103 }
104
105 TEST_F(TextTableFormatterTest, HandlesEmptyColumns)
106 {
107     formatter_.clear();
108     formatter_.addColumnLine(0, "foo");
109     formatter_.addColumnLine(1, "bar");
110     formatter_.addColumnLine(3, "Text");
111     checkText(formatter_.formatRow(), "FormattedTable");
112     formatter_.clear();
113     formatter_.addColumnLine(0, "foo");
114     formatter_.addColumnLine(1, "bar");
115     formatter_.setColumnFirstLineOffset(2, 1);
116     formatter_.addColumnLine(3, "Text");
117     checkText(formatter_.formatRow(), "FormattedRow2");
118     formatter_.clear();
119     formatter_.addColumnLine(0, "foo");
120     formatter_.addColumnLine(1, "bar");
121     formatter_.addColumnLine(2, "");
122     formatter_.setColumnFirstLineOffset(2, 1);
123     formatter_.addColumnLine(3, "Text");
124     checkText(formatter_.formatRow(), "FormattedRow3");
125 }
126
127 } // namespace