You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2005/03/10 22:58:57 UTC
cvs commit: logging-log4cxx/tests/src/helpers datetimedateformattestcase.cpp
carnold 2005/03/10 13:58:57
Modified: include/log4cxx/helpers simpledateformat.h
src simpledateformat.cpp
tests/src/helpers datetimedateformattestcase.cpp
Log:
LOGCXX-11: Check locale aware date vs STL output not fixed strings, VC enhancements for SimpleDateFormat
Revision Changes Path
1.9 +2 -4 logging-log4cxx/include/log4cxx/helpers/simpledateformat.h
Index: simpledateformat.h
===================================================================
RCS file: /home/cvs/logging-log4cxx/include/log4cxx/helpers/simpledateformat.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- simpledateformat.h 15 Feb 2005 23:55:59 -0000 1.8
+++ simpledateformat.h 10 Mar 2005 21:58:57 -0000 1.9
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,13 +87,11 @@
const apr_time_exp_t& date,
log4cxx::helpers::Pool& p) const = 0;
- typedef std::time_put<wchar_t, std::ostreambuf_iterator<wchar_t> > TimePutFacet;
-
protected:
static void renderFacet(const std::locale& locale,
std::wostream& buffer,
const tm* time,
- const char spec);
+ const wchar_t spec);
private:
/**
1.14 +11 -11 logging-log4cxx/src/simpledateformat.cpp
Index: simpledateformat.cpp
===================================================================
RCS file: /home/cvs/logging-log4cxx/src/simpledateformat.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- simpledateformat.cpp 1 Mar 2005 23:30:44 -0000 1.13
+++ simpledateformat.cpp 10 Mar 2005 21:58:57 -0000 1.14
@@ -42,13 +42,13 @@
void SimpleDateFormat::PatternToken::renderFacet(const std::locale& locale,
std::basic_ostream<wchar_t>& buffer,
const tm* time,
- const char spec) {
-#if defined(_MSC_VER) && _MSC_VER < 1300
- _USE(locale, TimePutFacet).put(buffer,
- buffer, time, spec);
+ const wchar_t spec) {
+#if defined(_USEFAC)
+ _USEFAC(locale, std::time_put<wchar_t> )
+ .put(buffer, buffer, time, spec);
#else
- std::use_facet<TimePutFacet>(locale).put(buffer,
- buffer, buffer.fill(), time, spec);
+ std::use_facet<std::time_put<wchar_t> >(locale)
+ .put(buffer, buffer, buffer.fill(), time, spec);
#endif
}
@@ -131,7 +131,7 @@
size_t start = 0;
for (int imon = 0; imon < 12; imon++) {
time.tm_mon = imon;
- renderFacet(locale, buffer, &time, 'b');
+ renderFacet(locale, buffer, &time, L'b');
std::wstring monthnames(buffer.str());
names[imon] = monthnames.substr(start);
start = monthnames.length();
@@ -156,7 +156,7 @@
size_t start = 0;
for (int imon = 0; imon < 12; imon++) {
time.tm_mon = imon;
- renderFacet(locale, buffer, &time, 'B');
+ renderFacet(locale, buffer, &time, L'B');
std::wstring monthnames(buffer.str());
names[imon] = monthnames.substr(start);
start = monthnames.length();
@@ -233,7 +233,7 @@
size_t start = 0;
for (int iday = 0; iday < 7; iday++) {
time.tm_wday = iday;
- renderFacet(locale, buffer, &time, 'a');
+ renderFacet(locale, buffer, &time, L'a');
std::wstring daynames(buffer.str());
names[iday] = daynames.substr(start);
start = daynames.length();
@@ -258,7 +258,7 @@
size_t start = 0;
for (int iday = 0; iday < 7; iday++) {
time.tm_wday = iday;
- renderFacet(locale, buffer, &time, 'A');
+ renderFacet(locale, buffer, &time, L'A');
std::wstring daynames(buffer.str());
names[iday] = daynames.substr(start);
start = daynames.length();
@@ -341,7 +341,7 @@
size_t start = 0;
for (int i = 0; i < 2; i++) {
time.tm_hour = i * 12;
- renderFacet(locale, buffer, &time, 'p');
+ renderFacet(locale, buffer, &time, L'p');
std::wstring ampm = buffer.str();
names[i] = ampm.substr(start);
start = ampm.length();
1.10 +34 -20 logging-log4cxx/tests/src/helpers/datetimedateformattestcase.cpp
Index: datetimedateformattestcase.cpp
===================================================================
RCS file: /home/cvs/logging-log4cxx/tests/src/helpers/datetimedateformattestcase.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- datetimedateformattestcase.cpp 1 Mar 2005 23:30:45 -0000 1.9
+++ datetimedateformattestcase.cpp 10 Mar 2005 21:58:57 -0000 1.10
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#define __STDC_CONSTANT_MACROS
#include <log4cxx/helpers/datetimedateformat.h>
#include <cppunit/extensions/HelperMacros.h>
#include <log4cxx/helpers/pool.h>
@@ -22,9 +23,11 @@
#include <apr.h>
#include <apr_time.h>
#include "localechanger.h"
+#include <sstream>
using namespace log4cxx;
using namespace log4cxx::helpers;
+using namespace std;
#if defined(_WIN32)
#define LOCALE_US "English_us"
@@ -34,11 +37,6 @@
#define LOCALE_FR "fr_FR"
#endif
-//Define INT64_C for compilers that don't have it
-#if (!defined(INT64_C))
-#define INT64_C(value) value ## LL
-#endif
-
/**
Unit test {@link DateTimeDateFormat}.
@@ -54,9 +52,7 @@
CPPUNIT_TEST( test4 );
CPPUNIT_TEST( test5 );
CPPUNIT_TEST( test6 );
-#if !defined(__BORLANDC__)
CPPUNIT_TEST( test7 );
-#endif
CPPUNIT_TEST( test8 );
CPPUNIT_TEST_SUITE_END();
@@ -162,6 +158,20 @@
LOG4CXX_STR("03 Jul 2004 00:00:00,000"));
}
+ LogString formatDate(const std::locale& locale, const tm& date, const LogString& fmt) {
+ //
+ // output the using STL
+ //
+ std::basic_ostringstream<logchar> buffer;
+#if defined(_USEFAC)
+ _USEFAC(locale, std::time_put<logchar>)
+ .put(buffer, buffer, &date, fmt.c_str(), fmt.c_str() + fmt.length());
+#else
+ std::use_facet<std::time_put<logchar> >(locale)
+ .put(buffer, buffer, buffer.fill(), &date, fmt.c_str(), fmt.c_str() + fmt.length());
+#endif
+ return buffer.str();
+ }
/** Check that format is locale sensitive. */
void test7()
@@ -171,30 +181,34 @@
if (localeChange.isEffective()) {
LogString formatted;
Pool p;
- DateTimeDateFormat formatter;
- formatter.setTimeZone(TimeZone::getGMT());
+ SimpleDateFormat formatter(LOG4CXX_STR("MMM"));
formatter.format(formatted, avr11, p);
- //
- // abbreviation for Avril varies
- //
- if (formatted != LOG4CXX_STR("11 avr. 2004 00:00:00,000")) {
- CPPUNIT_ASSERT_EQUAL((LogString) LOG4CXX_STR("11 avr 2004 00:00:00,000"), formatted );
- }
+
+ std::locale localeFR(LOCALE_FR);
+ struct tm avr11tm = { 0, 0, 0, 11, 03, 104 };
+ LogString expected(formatDate(localeFR, avr11tm, LOG4CXX_STR("%b")));
+
+ CPPUNIT_ASSERT_EQUAL(expected, formatted);
}
}
/** Check that format is locale sensitive. */
void test8()
{
- apr_time_t march12 = MICROSECONDS_PER_DAY * 12519;
+ apr_time_t apr11 = MICROSECONDS_PER_DAY * 12519;
LocaleChanger localeChange(LOCALE_US);
if (localeChange.isEffective()) {
LogString formatted;
Pool p;
- DateTimeDateFormat formatter;
+ SimpleDateFormat formatter(LOG4CXX_STR("MMM"));
formatter.setTimeZone(TimeZone::getGMT());
- formatter.format(formatted, march12, p);
- CPPUNIT_ASSERT_EQUAL((LogString) LOG4CXX_STR("11 Apr 2004 00:00:00,000"), formatted );
+ formatter.format(formatted, apr11, p);
+
+ std::locale localeUS(LOCALE_US);
+ struct tm apr11tm = { 0, 0, 0, 11, 03, 104 };
+ LogString expected(formatDate(localeUS, apr11tm, LOG4CXX_STR("%b")));
+
+ CPPUNIT_ASSERT_EQUAL(expected, formatted);
}
}