[Libreoffice-commits] .: svl/qa
Kohei Yoshida
kohei at kemper.freedesktop.org
Wed Feb 23 16:28:35 PST 2011
svl/qa/unit/svl.cxx | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 134 insertions(+), 1 deletion(-)
New commits:
commit 28370475daecb60a545aeba4d93a4bbd0ca532db
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Feb 23 19:26:13 2011 -0500
Unit test for default number format codes for US English.
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 390d3a5..4647959 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -131,7 +131,140 @@ Test::~Test()
void Test::testNumberFormat()
{
- SvNumberFormatter aFormatter(LANGUAGE_ENGLISH_US);
+ LanguageType eLang = LANGUAGE_ENGLISH_US;
+
+ const char* pNumber[] = {
+ "General",
+ "0",
+ "0.00",
+ "#,##0",
+ "#,##0.00",
+ "#,###.00",
+ 0
+ };
+
+ const char* pScientific[] = {
+ "0.00E+000",
+ "0.00E+00",
+ 0
+ };
+
+ const char* pPercent[] = {
+ "0%",
+ "0.00%",
+ 0
+ };
+
+ const char* pFraction[] = {
+ "# \?/\?",
+ "# \?\?/\?\?",
+ "# \?/4",
+ "# \?\?/100",
+ 0
+ };
+
+ const char* pCurrency[] = {
+ "$#,##0;[RED]-$#,##0",
+ "$#,##0.00;[RED]-$#,##0.00",
+ "#,##0.00 CCC",
+ "$#,##0.--;[RED]-$#,##0.--",
+ "$#,##0;-$#,##0",
+ "$#,##0;-$#,##0",
+ 0
+ };
+
+ const char* pDate[] = {
+ "MM/DD/YY",
+ "MM/DD/YYYY",
+ "MMM D, YY",
+ "MMM D, YYYY",
+ "D. MMM. YYYY",
+ "MMMM D, YYYY",
+ "D. MMMM YYYY",
+ "NN, MMM D, YY",
+ "NN DD/MMM YY",
+ "NN, MMMM D, YYYY",
+ "NNNNMMMM D, YYYY",
+ "MM-DD",
+ "YY-MM-DD",
+ "YYYY-MM-DD",
+ "MM/YY",
+ "MMM DD",
+ "MMMM",
+ "QQ YY",
+ "WW",
+ "MM/DD/YY",
+ "WW",
+ 0
+ };
+
+ const char* pTime[] = {
+ "HH:MM AM/PM",
+ "HH:MM:SS AM/PM",
+ "[HH]:MM:SS",
+ "MM:SS.00",
+ "[HH]:MM:SS.00",
+ "HH:MM:SS AM/PM",
+ "HH:MM:SS AM/PM",
+ 0
+ };
+
+ const char* pDateTime[] = {
+ "MM/DD/YY HH:MM AM/PM",
+ "MM/DD/YY HH:MM AM/PM",
+ 0
+ };
+
+ const char* pBoolean[] = {
+ "BOOLEAN",
+ 0
+ };
+
+ const char* pText[] = {
+ "@",
+ 0
+ };
+
+ struct {
+ NfIndexTableOffset eStart;
+ NfIndexTableOffset eEnd;
+ size_t nSize;
+ const char** pCodes;
+ } aTests[] = {
+ { NF_NUMBER_START, NF_NUMBER_END, 6, pNumber },
+ { NF_SCIENTIFIC_START, NF_SCIENTIFIC_END, 2, pScientific },
+ { NF_PERCENT_START, NF_PERCENT_END, 2, pPercent },
+ { NF_FRACTION_START, NF_FRACTION_END, 4, pFraction },
+ { NF_CURRENCY_START, NF_CURRENCY_END, 6, pCurrency },
+ { NF_DATE_START, NF_DATE_END, 21, pDate },
+ { NF_TIME_START, NF_TIME_END, 7, pTime },
+ { NF_DATETIME_START, NF_DATETIME_END, 2, pDateTime },
+ { NF_BOOLEAN, NF_BOOLEAN, 1, pBoolean },
+ { NF_TEXT, NF_TEXT, 1, pText }
+ };
+
+ SvNumberFormatter aFormatter(eLang);
+
+ for (size_t i = 0; i < SAL_N_ELEMENTS(aTests); ++i)
+ {
+ size_t nStart = aTests[i].eStart;
+ size_t nEnd = aTests[i].eEnd;
+
+ CPPUNIT_ASSERT_MESSAGE("Unexpected number of formats for this category.",
+ (nEnd - nStart + 1) == aTests[i].nSize);
+
+ for (size_t j = nStart; j <= nEnd; ++j)
+ {
+ sal_uInt32 nIndex =
+ aFormatter.GetFormatIndex(static_cast<NfIndexTableOffset>(j));
+ const SvNumberformat* p = aFormatter.GetEntry(nIndex);
+
+ CPPUNIT_ASSERT_MESSAGE("Number format entry is expected, but doesn't exist.", p);
+ OUString aCode = p->GetFormatstring();
+ bool bEqual = aCode.equalsAscii(aTests[i].pCodes[j-nStart]);
+ CPPUNIT_ASSERT_MESSAGE("Unexpected number format code.", bEqual);
+ }
+ }
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
More information about the Libreoffice-commits
mailing list