From 8f747fabdcadeb94e243b07064bca953f7bf73e0 Mon Sep 17 00:00:00 2001
From: Aleksandar Fabijanic <alex@pocoproject.org>
Date: Sun, 30 Sep 2012 13:10:51 +0000
Subject: [PATCH] gcc/linux compile/tests

---
 CppUnit/include/CppUnit/TestCase.h            |  9 ++-
 CppUnit/src/TestCase.cpp                      |  9 ++-
 Foundation/include/Poco/NumericString.h       | 55 ++++++++--------
 Foundation/testsuite/src/NumberParserTest.cpp |  1 +
 Foundation/testsuite/src/StringTest.cpp       | 66 ++++++++++---------
 5 files changed, 80 insertions(+), 60 deletions(-)

diff --git a/CppUnit/include/CppUnit/TestCase.h b/CppUnit/include/CppUnit/TestCase.h
index d7ad8538e..cd843f45b 100644
--- a/CppUnit/include/CppUnit/TestCase.h
+++ b/CppUnit/include/CppUnit/TestCase.h
@@ -103,7 +103,7 @@ public:
 protected:
 	virtual void runTest();
 	TestResult* defaultResult();
-	
+
 	void assertImplementation(bool condition,
 	                          const std::string& conditionExpression = "",
 	                          long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
@@ -158,10 +158,15 @@ protected:
 	                long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
 	                const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
 
-	void fail(const std::string&message = "",
+	void fail(const std::string& message = "",
 	          long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
 	          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:
 	const std::string _name;
 };
diff --git a/CppUnit/src/TestCase.cpp b/CppUnit/src/TestCase.cpp
index 95e9c34e5..0e8669d97 100644
--- a/CppUnit/src/TestCase.cpp
+++ b/CppUnit/src/TestCase.cpp
@@ -11,6 +11,7 @@
 #include "CppUnit/TestResult.h"
 #include "CppUnit/estring.h"
 #include <typeinfo>
+#include <iostream>
 
 
 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);
 }
 
 
+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
 void TestCase::run(TestResult *result)
 {
diff --git a/Foundation/include/Poco/NumericString.h b/Foundation/include/Poco/NumericString.h
index 30267c2ae..bb340ddd9 100644
--- a/Foundation/include/Poco/NumericString.h
+++ b/Foundation/include/Poco/NumericString.h
@@ -50,11 +50,36 @@
 #endif
 #include <limits>
 #include <cmath>
+#include <locale>
 
 
 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>
 bool strToInt(const char* pStr, I& result, short base = -1)
 	/// Converts zero-terminated array to integer number;
@@ -71,7 +96,7 @@ bool strToInt(const char* pStr, I& result, short base = -1)
 	if (!pStr || (pStr && *pStr == '\0')) return false;
 	while ((*pStr != '\0') && (*pStr == ' ')) ++pStr;
 	if (*pStr == '\0') return false;
-	
+
 	char sign = 1;
 
 	if (*pStr == '-')
@@ -92,7 +117,7 @@ bool strToInt(const char* pStr, I& result, short base = -1)
 			result = 0;
 			return true;
 		}
-		
+
 		if ((*pStr == 'x') || (*pStr == 'X'))
 		{
 			base = 0x10;
@@ -129,7 +154,7 @@ bool strToInt(const char* pStr, I& result, short base = -1)
 			}
 			else return false;
 			break;
-		
+
 		case '8': case '9':
 			if (allowDigits && (base == 10 || base == 16))
 			{
@@ -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
 
 namespace {
diff --git a/Foundation/testsuite/src/NumberParserTest.cpp b/Foundation/testsuite/src/NumberParserTest.cpp
index 58b3f171d..0e6936d80 100644
--- a/Foundation/testsuite/src/NumberParserTest.cpp
+++ b/Foundation/testsuite/src/NumberParserTest.cpp
@@ -41,6 +41,7 @@
 #include "Poco/Stopwatch.h"
 #include <iostream>
 #include <iomanip>
+#include <cstdio>
 
 
 using Poco::NumberParser;
diff --git a/Foundation/testsuite/src/StringTest.cpp b/Foundation/testsuite/src/StringTest.cpp
index 5fcdc012a..0bff4ec4a 100644
--- a/Foundation/testsuite/src/StringTest.cpp
+++ b/Foundation/testsuite/src/StringTest.cpp
@@ -39,6 +39,7 @@
 #include "Poco/Stopwatch.h"
 #include <iostream>
 #include <iomanip>
+#include <cstdio>
 
 
 using Poco::trimLeft;
@@ -527,39 +528,44 @@ void StringTest::testStringToFloatError()
 void StringTest::testNumericLocale()
 {
 #if !defined(POCO_NO_LOCALE)
-	char dp = decimalSeparator();
-	char ts = thousandSeparator();
-	std::locale loc;
-	std::cout << "Original locale: '" << loc.c_str() << '\'' << std::endl;
-	std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
-	std::cout << "Thousand separator: '" << ts << '\'' << std::endl;
+	try
+	{
+		char dp = decimalSeparator();
+		char ts = thousandSeparator();
+		std::locale loc;
+		std::cout << "Original locale: '" << loc.name() << '\'' << std::endl;
+		std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
+		std::cout << "Thousand separator: '" << ts << '\'' << std::endl;
 
-	std::locale::global(std::locale("German"));
-	std::locale locGerman;
-	assert (',' == decimalSeparator());
-	assert ('.' == thousandSeparator());
-	std::cout << "New locale: '" << locGerman.c_str() << '\'' << std::endl;
-	std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
-	std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl;
+		std::locale::global(std::locale("German"));
+		std::locale locGerman;
+		assert (',' == decimalSeparator());
+		assert ('.' == thousandSeparator());
+		std::cout << "New locale: '" << locGerman.name() << '\'' << std::endl;
+		std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
+		std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl;
 
-	std::locale::global(std::locale("US"));
-	std::locale locUS;
-	assert ('.' == decimalSeparator());
-	assert (',' == thousandSeparator());
-	std::cout << "New locale: '" << locUS.c_str() << '\'' << std::endl;
-	std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
-	std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl;
+		std::locale::global(std::locale("US"));
+		std::locale locUS;
+		assert ('.' == decimalSeparator());
+		assert (',' == thousandSeparator());
+		std::cout << "New locale: '" << locUS.name() << '\'' << std::endl;
+		std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
+		std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl;
 
-	std::locale::global(loc);
-	dp = decimalSeparator();
-	ts = thousandSeparator();
-	std::cout << "Final locale: '" << loc.c_str() << '\'' << std::endl;
-	std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
-	std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl;
-	assert (dp == decimalSeparator());
-	assert (ts == thousandSeparator());
-#else
-	std::cout << "No locale available, skipping." << std::endl;
+		std::locale::global(loc);
+		dp = decimalSeparator();
+		ts = thousandSeparator();
+		std::cout << "Final locale: '" << loc.name() << '\'' << std::endl;
+		std::cout << "Decimal point: '" << decimalSeparator() << '\'' << std::endl;
+		std::cout << "Thousand separator: '" << thousandSeparator() << '\'' << std::endl;
+		assert (dp == decimalSeparator());
+		assert (ts == thousandSeparator());
+	} catch (std::runtime_error& ex)
+	{
+		std::cout << ex.what() << std::endl;
+		warn ("Locale not found, skipping test");
+	}
 #endif
 }