format() bool support

This commit is contained in:
Aleksandar Fabijanic 2008-01-15 02:43:04 +00:00
parent 9e8e627347
commit ae607d40e5
3 changed files with 40 additions and 0 deletions

View File

@ -160,6 +160,8 @@ namespace
str << AnyCast<Int64>(any);
else if (any.type() == typeid(UInt64))
str << AnyCast<UInt64>(any);
else if (any.type() == typeid(bool))
str << AnyCast<bool>(any);
}
@ -176,6 +178,9 @@ namespace
prepareFormat(str, type);
switch (type)
{
case 'b':
str << AnyCast<bool>(*itVal++);
break;
case 'c':
str << AnyCast<char>(*itVal++);
break;

View File

@ -46,6 +46,7 @@
#include "FormatTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Any.h"
#include "Poco/Format.h"
#include "Poco/Exception.h"
@ -211,12 +212,44 @@ void FormatTest::testInt()
}
void FormatTest::testBool()
{
bool b = true;
std::string s = format("%b", b);
assert (s == "1");
b = false;
s = format("%b", b);
assert (s == "0");
std::vector<Poco::Any> bv;
bv.push_back(false);
bv.push_back(true);
bv.push_back(false);
bv.push_back(true);
bv.push_back(false);
bv.push_back(true);
bv.push_back(false);
bv.push_back(true);
bv.push_back(false);
bv.push_back(true);
s.clear();
format(s, "%b%b%b%b%b%b%b%b%b%b", bv);
assert (s == "0101010101");
}
void FormatTest::testAnyInt()
{
char c = 42;
std::string s(format("%?i", c));
assert (s == "42");
bool b = true;
s = format("%?i", b);
assert (s == "1");
signed char sc = -42;
s = format("%?i", sc);
assert (s == "-42");
@ -361,6 +394,7 @@ CppUnit::Test* FormatTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FormatTest");
CppUnit_addTest(pSuite, FormatTest, testChar);
CppUnit_addTest(pSuite, FormatTest, testBool);
CppUnit_addTest(pSuite, FormatTest, testInt);
CppUnit_addTest(pSuite, FormatTest, testAnyInt);
CppUnit_addTest(pSuite, FormatTest, testFloatFix);

View File

@ -61,6 +61,7 @@ public:
void testChar();
void testInt();
void testBool();
void testAnyInt();
void testFloatFix();
void testFloatSci();