1//
2// HelpFormatterTest.cpp
3//
4// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
5// and Contributors.
6//
7// SPDX-License-Identifier: BSL-1.0
8//
9
10
11#include "HelpFormatterTest.h"
12#include "Poco/CppUnit/TestCaller.h"
13#include "Poco/CppUnit/TestSuite.h"
14#include "Poco/Util/Option.h"
15#include "Poco/Util/OptionSet.h"
16#include "Poco/Util/HelpFormatter.h"
17#include <iostream>
18
19
20using Poco::Util::Option;
21using Poco::Util::OptionSet;
22using Poco::Util::HelpFormatter;
23
24
25HelpFormatterTest::HelpFormatterTest(const std::string& name): CppUnit::TestCase(name)
26{
27}
28
29
30HelpFormatterTest::~HelpFormatterTest()
31{
32}
33
34
35void HelpFormatterTest::testHelpFormatter()
36{
37 OptionSet set;
38 set.addOption(
39 Option("include-dir", "I", "specify a search path for locating header files")
40 .required(false)
41 .repeatable(true)
42 .argument("path"));
43
44 set.addOption(
45 Option("library-dir", "L", "specify a search path for locating library files (this option has a very long description)")
46 .required(false)
47 .repeatable(true)
48 .argument("path"));
49
50 set.addOption(
51 Option("output", "o", "specify the output file", true)
52 .argument("file", true));
53
54 set.addOption(
55 Option("verbose", "v")
56 .description("enable verbose mode")
57 .required(false)
58 .repeatable(false));
59
60 set.addOption(
61 Option("optimize", "O")
62 .description("enable optimization")
63 .required(false)
64 .repeatable(false)
65 .argument("level", false));
66
67 HelpFormatter formatter(set);
68 formatter.format(std::cout);
69
70 formatter.setCommand("cc");
71 formatter.format(std::cout);
72
73 formatter.setUsage("OPTIONS FILES");
74 formatter.setHeader("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
75 "Vivamus volutpat imperdiet massa. Nulla at ipsum vitae risus facilisis posuere. "
76 "Cras convallis, lacus ac vulputate convallis, metus nisl euismod ligula, "
77 "ac euismod diam wisi in dolor.\nMauris vitae leo.");
78 formatter.setFooter("Cras semper mollis tellus. Mauris eleifend mauris et lorem. "
79 "Etiam odio dolor, fermentum quis, mollis nec, sodales sed, tellus. "
80 "Quisque consequat orci eu augue. Aliquam ac nibh ac neque hendrerit iaculis.");
81 formatter.format(std::cout);
82
83 formatter.setUnixStyle(false);
84 formatter.format(std::cout);
85
86 formatter.setHeader("");
87 formatter.setFooter("tab: a\tb\tcde\tf\n\ta\n\t\tb");
88 formatter.format(std::cout);
89}
90
91
92void HelpFormatterTest::setUp()
93{
94}
95
96
97void HelpFormatterTest::tearDown()
98{
99}
100
101
102CppUnit::Test* HelpFormatterTest::suite()
103{
104 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HelpFormatterTest");
105
106 CppUnit_addTest(pSuite, HelpFormatterTest, testHelpFormatter);
107
108 return pSuite;
109}
110