gcc/linux compile/tests

This commit is contained in:
Aleksandar Fabijanic 2012-09-30 13:10:51 +00:00
parent f70ac1ca07
commit 8f747fabdc
5 changed files with 80 additions and 60 deletions

View File

@ -158,10 +158,15 @@ protected:
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
void fail(const std::string&message = "", void fail(const std::string& message = "",
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER, long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME); const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
void warn(const std::string& message = "",
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
private: private:
const std::string _name; const std::string _name;
}; };

View File

@ -11,6 +11,7 @@
#include "CppUnit/TestResult.h" #include "CppUnit/TestResult.h"
#include "CppUnit/estring.h" #include "CppUnit/estring.h"
#include <typeinfo> #include <typeinfo>
#include <iostream>
using namespace std; using namespace std;
@ -94,12 +95,18 @@ void TestCase::assertNull(const void* pointer, const std::string& pointerExpress
} }
void TestCase::fail (const std::string& message, long lineNumber, const std::string& fileName) void TestCase::fail(const std::string& message, long lineNumber, const std::string& fileName)
{ {
throw CppUnitException(std::string("fail: ") + message, lineNumber, fileName); throw CppUnitException(std::string("fail: ") + message, lineNumber, fileName);
} }
void TestCase::warn(const std::string& message, long lineNumber, const std::string& fileName)
{
std::cout << "Warning [" << fileName << ':' << lineNumber << "]: " << message << std::endl;
}
// Run the test and catch any exceptions that are triggered by it // Run the test and catch any exceptions that are triggered by it
void TestCase::run(TestResult *result) void TestCase::run(TestResult *result)
{ {

View File

@ -50,11 +50,36 @@
#endif #endif
#include <limits> #include <limits>
#include <cmath> #include <cmath>
#include <locale>
namespace Poco { namespace Poco {
inline char decimalSeparator()
/// Returns decimal separator from global locale or
/// default '.' for platforms where locale is unavailable.
{
#if !defined(POCO_NO_LOCALE)
return std::use_facet<std::numpunct<char> >(std::locale()).decimal_point();
#else
return '.';
#endif
}
inline char thousandSeparator()
/// Returns thousand separator from global locale or
/// default ',' for platforms where locale is unavailable.
{
#if !defined(POCO_NO_LOCALE)
return std::use_facet<std::numpunct<char> >(std::locale()).thousands_sep();
#else
return ',';
#endif
}
template <typename I> template <typename I>
bool strToInt(const char* pStr, I& result, short base = -1) bool strToInt(const char* pStr, I& result, short base = -1)
/// Converts zero-terminated array to integer number; /// Converts zero-terminated array to integer number;
@ -199,30 +224,6 @@ bool strToInt(const std::string& str, I& result, short base = -1)
} }
inline char decimalSeparator()
/// Returns decimal separator from global locale or
/// default '.' for platforms where locale is unavailable.
{
#if !defined(POCO_NO_LOCALE)
return std::use_facet<std::numpunct<char> >(std::locale()).decimal_point();
#else
return '.';
#endif
}
inline char thousandSeparator()
/// Returns thousand separator from global locale or
/// default ',' for platforms where locale is unavailable.
{
#if !defined(POCO_NO_LOCALE)
return std::use_facet<std::numpunct<char> >(std::locale()).thousands_sep();
#else
return ',';
#endif
}
#ifndef POCO_NO_FPENVIRONMENT #ifndef POCO_NO_FPENVIRONMENT
namespace { namespace {

View File

@ -41,6 +41,7 @@
#include "Poco/Stopwatch.h" #include "Poco/Stopwatch.h"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <cstdio>
using Poco::NumberParser; using Poco::NumberParser;

View File

@ -39,6 +39,7 @@
#include "Poco/Stopwatch.h" #include "Poco/Stopwatch.h"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <cstdio>
using Poco::trimLeft; using Poco::trimLeft;
@ -527,10 +528,12 @@ void StringTest::testStringToFloatError()
void StringTest::testNumericLocale() void StringTest::testNumericLocale()
{ {
#if !defined(POCO_NO_LOCALE) #if !defined(POCO_NO_LOCALE)
try
{
char dp = decimalSeparator(); char dp = decimalSeparator();
char ts = thousandSeparator(); char ts = thousandSeparator();
std::locale loc; std::locale loc;
std::cout << "Original locale: '" << loc.c_str() << '\'' << std::endl; std::cout << "Original locale: '" << loc.name() << '\'' << std::endl;
std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl; std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
std::cout << "Thousand separator: '" << ts << '\'' << std::endl; std::cout << "Thousand separator: '" << ts << '\'' << std::endl;
@ -538,7 +541,7 @@ void StringTest::testNumericLocale()
std::locale locGerman; std::locale locGerman;
assert (',' == decimalSeparator()); assert (',' == decimalSeparator());
assert ('.' == thousandSeparator()); assert ('.' == thousandSeparator());
std::cout << "New locale: '" << locGerman.c_str() << '\'' << std::endl; std::cout << "New locale: '" << locGerman.name() << '\'' << std::endl;
std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl; std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl; std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl;
@ -546,20 +549,23 @@ void StringTest::testNumericLocale()
std::locale locUS; std::locale locUS;
assert ('.' == decimalSeparator()); assert ('.' == decimalSeparator());
assert (',' == thousandSeparator()); assert (',' == thousandSeparator());
std::cout << "New locale: '" << locUS.c_str() << '\'' << std::endl; std::cout << "New locale: '" << locUS.name() << '\'' << std::endl;
std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl; std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl; std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl;
std::locale::global(loc); std::locale::global(loc);
dp = decimalSeparator(); dp = decimalSeparator();
ts = thousandSeparator(); ts = thousandSeparator();
std::cout << "Final locale: '" << loc.c_str() << '\'' << std::endl; std::cout << "Final locale: '" << loc.name() << '\'' << std::endl;
std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl; std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl; std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl;
assert (dp == decimalSeparator()); assert (dp == decimalSeparator());
assert (ts == thousandSeparator()); assert (ts == thousandSeparator());
#else } catch (std::runtime_error& ex)
std::cout << "No locale available, skipping." << std::endl; {
std::cout << ex.what() << std::endl;
warn ("Locale not found, skipping test");
}
#endif #endif
} }