+void IntlTestDecimalFormatAPI::verifyString(const UnicodeString& message, const UnicodeString& got, UnicodeString& expected){
+ logln((UnicodeString)message + got + (UnicodeString)" Expected : " + expected);
+ if(got != expected ) {
+ errln((UnicodeString)"ERROR: " + message + got + (UnicodeString)" Expected : " + expected);
+ }
+}
+
+void IntlTestDecimalFormatAPI::testRoundingInc(/*char *par*/)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ DecimalFormat pat(UnicodeString("#,##0.00"),status);
+ if(U_FAILURE(status)) {
+ errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s", u_errorName(status));
+ return;
+ }
+
+ // get default rounding increment
+ double roundingInc = pat.getRoundingIncrement();
+ if (roundingInc != 0.0) {
+ errln((UnicodeString)"ERROR: Rounding increment not zero");
+ return;
+ }
+
+ // With rounding now being handled by decNumber, we no longer
+ // set a rounding increment to enable non-default mode rounding,
+ // checking of which was the original point of this test.
+
+ // set rounding mode with zero increment. Rounding
+ // increment should not be set by this operation
+ pat.setRoundingMode((DecimalFormat::ERoundingMode)0);
+ roundingInc = pat.getRoundingIncrement();
+ if (roundingInc != 0.0) {
+ errln((UnicodeString)"ERROR: Rounding increment not zero after setRoundingMode");
+ return;
+ }
+}
+
+void IntlTestDecimalFormatAPI::TestScale()
+{
+ typedef struct TestData {
+ double inputValue;
+ int inputScale;
+ char *expectedOutput;
+ } TestData;
+
+ static TestData testData[] = {
+ { 100.0, 3, "100,000" },
+ { 10034.0, -2, "100.34" },
+ { 0.86, -3, "0.0009" },
+ { -0.000455, 1, "-0%" },
+ { -0.000555, 1, "-1%" },
+ { 0.000455, 1, "0%" },
+ { 0.000555, 1, "1%" },
+ };
+
+ UErrorCode status = U_ZERO_ERROR;
+ DecimalFormat pat(status);
+ if(U_FAILURE(status)) {
+ errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s", u_errorName(status));
+ return;
+ }
+
+ UnicodeString message;
+ UnicodeString resultStr;
+ UnicodeString exp;
+ UnicodeString percentPattern("#,##0%");
+ pat.setMaximumFractionDigits(4);
+
+ for(int32_t i=0;i < sizeof(testData)/sizeof(testData[0]);i++) {
+ if ( i > 2 ) {
+ pat.applyPattern(percentPattern,status);
+ }
+ pat.setAttribute(UNUM_SCALE,testData[i].inputScale,status);
+ pat.format(testData[i].inputValue, resultStr);
+ message = UnicodeString("Unexpected output for ") + testData[i].inputValue + UnicodeString(" and scale ") + testData[i].inputScale + UnicodeString(". Got: ");
+ exp = testData[i].expectedOutput;
+ verifyString(message, resultStr, exp);
+ message.remove();
+ resultStr.remove();
+ exp.remove();
+ }
+}