Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ad781c0 authored by Roozbeh Pournader's avatar Roozbeh Pournader
Browse files

Fix failing unit tests for android.text.format.Formatter

An update was needed for I34ae16bb68a28e60b09a7c17ac3b1d5ab9ddbeea,
but was forgotten. The updated tests assume standardized SI rounding,
using powers of 1000 instead of the previous powers of 1024.

Bug: 27672362
Bug: 29871955
Change-Id: Ib42124e9ec24bcb1309c3c940c1d830a18c4802f
parent c05bf612
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -68,23 +68,26 @@ public class FormatterTest extends AndroidTestCase {
        checkFormatBytes(123, true, "123", 123);
        checkFormatBytes(123, false, "123", 123);

        checkFormatBytes(812, true, "812", 812);
        checkFormatBytes(812, false, "812", 812);
        checkFormatBytes(900, true, "900", 900);
        checkFormatBytes(900, false, "900", 900);

        checkFormatBytes(912, true, "0.89", 911);
        checkFormatBytes(912, false, "0.89", 911);
        checkFormatBytes(901, true, "0.90", 900);
        checkFormatBytes(901, false, "0.90", 900);

        checkFormatBytes(9123, true, "8.9", 9113);
        checkFormatBytes(9123, false, "8.91", 9123);
        checkFormatBytes(912, true, "0.91", 910);
        checkFormatBytes(912, false, "0.91", 910);

        checkFormatBytes(9123000, true, "8.7", 9122611);
        checkFormatBytes(9123000, false, "8.70", 9122611);
        checkFormatBytes(9123, true, "9.1", 9100);
        checkFormatBytes(9123, false, "9.12", 9120);

        checkFormatBytes(9123456, true, "9.1", 9100000);
        checkFormatBytes(9123456, false, "9.12", 9120000);

        checkFormatBytes(-1, true, "-1", -1);
        checkFormatBytes(-1, false, "-1", -1);

        checkFormatBytes(-912, true, "-0.89", -911);
        checkFormatBytes(-912, false, "-0.89", -911);
        checkFormatBytes(-914, true, "-0.91", -910);
        checkFormatBytes(-914, false, "-0.91", -910);

        // Missing FLAG_CALCULATE_ROUNDED case.
        BytesResult r = Formatter.formatBytes(getContext().getResources(), 1, 0);
@@ -93,7 +96,7 @@ public class FormatterTest extends AndroidTestCase {

        // Make sure it works on different locales.
        setLocale(new Locale("es", "ES"));
        checkFormatBytes(9123000, false, "8,70", 9122611);
        checkFormatBytes(9123000, false, "9,12", 9120000);
    }

    private void checkFormatBytes(long bytes, boolean useShort,