diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2011-02-23 19:26:13 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2011-02-23 19:26:13 -0500 |
commit | 635171fadb485979f386a19853d26b2d32d03cbf (patch) | |
tree | 1ea9cc32c34909858e069248d6b37bd6ced8698b /svl/qa/unit | |
parent | 0f3b0b411ba97d07e5dcb0d0bcdcbf1a094d14bb (diff) |
Unit test for default number format codes for US English.
Diffstat (limited to 'svl/qa/unit')
-rw-r--r-- | svl/qa/unit/svl.cxx | 135 |
1 files changed, 134 insertions, 1 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index 390d3a5d2e8b..464795940375 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); |