0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

[test/misc] Misc test code additions/changes:

expr.cpp -- test Macro::BooleanExpression
macro.cpp -- test Macro parsing and representation
uniter.cpp -- test Unicode::UTF8Iterator
format.cpp -- test minor changes to printfmt()
unused/comment_out.hpp -- unused code that comments
                          out a multiline string.
This commit is contained in:
James Yonan 2015-10-01 17:27:05 -07:00 committed by Frank Lichtenheld
parent 319250f33e
commit 56cdfe6b00

View File

@ -37,23 +37,28 @@ void test()
const double pi = 3.14159265;
const int three = 3;
const std::string weather = "partly cloudy";
char *nc = const_cast<char *>("non const");
std::cout << to_string(seven) << std::endl;
std::cout << to_string(foo) << std::endl;
std::cout << to_string(bar) << std::endl;
std::cout << to_string(pi) << std::endl;
std::cout << to_string(three) << std::endl;
std::cout << to_string(true) << std::endl;
std::cout << to_string(false) << std::endl;
std::cout << prints("pi", "is", std::string("not"), 3, "nor is it", seven, ';', "it", "is", pi, "...") << std::endl;
std::cout << printfmt("pi is %r %s nor is it %s ; it is %s... (and has %s%% less %s!)", "not", 3, seven, pi, 99, std::string("fat")) << std::endl;
std::cout << printfmt("the year is %s and the weather is %r", 2015, weather) << std::endl;
std::cout << printfmt("the year is %s and the weather is %R", 2015, weather) << std::endl;
std::cout << printfmt("where am %s? is it still %s?", 'I', 2015) << std::endl;
std::cout << printfmt("no, it's %s... bring out yer dedd%s", 1666) << std::endl;
std::cout << printfmt("save 20%%!") << std::endl;
std::cout << printfmt("no wait... save%s 99.9999%%!") << std::endl;
std::cout << printfmt("extra argument is here", 1) << std::endl;
std::cout << printfmt("is the question %s or %s?", true, false) << std::endl;
std::cout << printfmt("more extra arguments are here", 1, 2, 3, 4) << std::endl;
std::cout << printfmt("null string '%s'", static_cast<char *>(nullptr)) << std::endl;
std::cout << printfmt("null string '%s'", static_cast<const char *>(nullptr)) << std::endl;
std::cout << printfmt("nullptr '%s'", nullptr) << std::endl;
std::cout << printfmt("%s=%s %s", foo, bar, nc) << std::endl;
try {
const std::string exstr = "bad foo";
throw Exception(exstr);
@ -71,20 +76,32 @@ void test()
}
}
template<typename... Args>
inline std::string pfmt(const std::string& fmt, Args... args)
{
#if 1
PrintFormatted<std::string> pf(fmt, 256);
#else
PrintFormatted<std::ostringstream> pf(fmt, 256);
#endif
pf.process(args...);
return pf.str();
}
void perf()
{
const MyObj seven(7);
const double pi = 3.14159265;
//const double pi = 3.14159265;
long count = 0;
const std::string weather = "partly cloudy";
for (long i = 0; i < 1000000; ++i)
{
const std::string str = printfmt("the year is %s and the weather is %r", 2015, weather);
//const std::string str = printfmt("this program is brought to you by the number %s", seven);
//const std::string str = printfmt("foo %s", 69);
//const std::string str = printfmt("foo");
//const std::string str = printfmt("foo %s %s", 69, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
//const std::string str = printfmt("pi is %s %s nor is it %s ; it is %s... (and has %s%% less %s!)", "not", 3, seven, pi, 99, std::string("fat"));
const std::string str = pfmt("the year is %s and the weather is %r", 2015, weather);
//const std::string str = pfmt("this program is brought to you by the number %s", seven);
//const std::string str = pfmt("foo %s", 69);
//const std::string str = pfmt("foo");
//const std::string str = pfmt("foo %s %s", 69, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
//const std::string str = pfmt("pi is %s %s nor is it %s ; it is %s... (and has %s%% less %s!)", "not", 3, seven, pi, 99, std::string("fat"));
count += str.length();
}
std::cout << count << std::endl;