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

Commit 059f02fa authored by Raman Tenneti's avatar Raman Tenneti Committed by Michael Bestas
Browse files

AOSP/Calendar - Minimal calendar app.

+ Calendar UI shows day/week/month calendars.
+ Calendar can be scrolled different days/weeks/months
+ Clicking on day icon shows the today.
+ New events can not be created.
+ Fixed the tests so that they pass.
+ Deleted src/com/android/calendar/AbstractCalendarActivity.java and tested
  everything.

Bug: 118760450
Bug: 118712914

Test: manual - Ran the following CTS tests on Pixel phone. Tested the calendar UI.
$ adb shell am instrument -w com.android.calendar.tests
  com.android.calendar.FormatDateRangeTest:.
  com.android.calendar.UtilsTests:..................
  com.android.calendar.WeekNumberTest:.
  com.android.calendar.widget.CalendarAppWidgetServiceTest:..
  Test results for InstrumentationTestRunner=......................
  Time: 0.315
  OK (22 tests)

+ android.provider.cts.CalendarTest:................................
  Time: 17.842
  OK (32 tests)
+ android.content.cts.AvailableIntentsTest:.................................
  Time: 0.441
  OK (33 tests)
+ com.android.cts.privilegedupdate.PrivilegedUpdateTest:...
  Time: 0.119
  OK (3 tests)
+ android.permission2.cts.ProtectedBroadcastsTest:..
  Time: 0.285
  OK (2 tests)

Change-Id: Ib6a3df46e46619248d2e45d71622109d3085eb64
parent 47e1a01d
Loading
Loading
Loading
Loading
+0 −661

File deleted.

Preview size limit exceeded, changes collapsed.

+4 −0
Original line number Diff line number Diff line
@@ -66,6 +66,10 @@ class DbTestUtils {
            return resources;
        }

        public int getUserId() {
            return 0;
        }

        public void setSharedPreferences(SharedPreferences sharedPreferences) {
            this.sharedPreferences = sharedPreferences;
        }
+19 −19
Original line number Diff line number Diff line
@@ -73,29 +73,29 @@ public class FormatDateRangeTest extends AndroidTestCase {

    DateTest[] tests = {
            new DateTest(0, 10, 9, 8, 0, 0, 10, 9, 11, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "8am \u2013 11am"),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "8 \u2013 11 AM"),
            new DateTest(0, 10, 9, 8, 0, 0, 10, 9, 11, 0,
                    DateUtils.FORMAT_SHOW_TIME, "8:00AM \u2013 11:00AM"),
                    DateUtils.FORMAT_SHOW_TIME, "8:00 \u2013 11:00 AM"),
            new DateTest(0, 10, 9, 8, 0, 0, 10, 9, 17, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR, "08:00 \u2013 17:00"),
            new DateTest(0, 10, 9, 8, 0, 0, 10, 9, 12, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "8am \u2013 noon"),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "8 AM \u2013 12 PM"),
            new DateTest(0, 10, 9, 8, 0, 0, 10, 9, 12, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_ABBREV_ALL,
                    "8am \u2013 12pm"),
                    "8 AM \u2013 12 PM"),
            new DateTest(0, 10, 9, 8, 0, 0, 10, 9, 12, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_CAP_NOON | DateUtils.FORMAT_ABBREV_ALL,
                    "8am \u2013 Noon"),
                    "8 AM \u2013 12 PM"),
            new DateTest(0, 10, 9, 10, 30, 0, 10, 9, 13, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "10:30AM \u2013 1pm"),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "10:30 AM \u2013 1:00 PM"),
            new DateTest(0, 10, 9, 13, 0, 0, 10, 9, 14, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "1pm \u2013 2pm"),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "1 \u2013 2 PM"),
            new DateTest(0, 10, 9, 0, 0, 0, 10, 9, 14, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "12am \u2013 2pm"),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "12 AM \u2013 2 PM"),
            new DateTest(0, 10, 9, 20, 0, 0, 10, 10, 0, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "8pm \u2013 midnight"),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "8 PM \u2013 12 AM"),
            new DateTest(0, 10, 10, 0, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "12am"),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "12 AM"),
            new DateTest(0, 10, 9, 20, 0, 0, 10, 10, 0, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR | DateUtils.FORMAT_ABBREV_ALL,
                    "20:00 \u2013 00:00"),
@@ -114,15 +114,15 @@ public class FormatDateRangeTest extends AndroidTestCase {
                    "Nov 10"),
            new DateTest(0, 10, 9, 20, 0, 0, 10, 10, 0, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL,
                    "8pm \u2013 12am"),
                    "8 PM \u2013 12 AM"),
            new DateTest(0, 10, 9, 20, 0, 0, 10, 10, 0, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_CAP_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL,
                    "8pm \u2013 Midnight"),
                    "8 PM \u2013 12 AM"),
            new DateTest(0, 10, 9, 0, 0, 0, 10, 10, 0, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "12am \u2013 midnight"),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, "Nov 9, 12 AM \u2013 Nov 10, 12 AM"),
            new DateTest(0, 10, 9, 0, 0, 0, 10, 10, 0, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR | DateUtils.FORMAT_ABBREV_ALL,
                    "00:00 \u2013 00:00"),
                    "Nov 9, 00:00 \u2013 Nov 10, 00:00"),
            new DateTest(0, 10, 9, 0, 0, 0, 10, 10, 0, 0,
                    DateUtils.FORMAT_UTC | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL, "Nov 9"),
            new DateTest(0, 10, 9, 0, 0, 0, 10, 10, 0, 0,
@@ -143,19 +143,19 @@ public class FormatDateRangeTest extends AndroidTestCase {
                    DateUtils.FORMAT_UTC | DateUtils.FORMAT_ABBREV_ALL, "Dec 29, 2007 \u2013 Jan 1, 2008"),
            new DateTest(2007, 11, 29, 8, 0, 2008, 0, 2, 17, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL,
                    "Dec 29, 2007, 8am \u2013 Jan 2, 2008, 5pm"),
                    "Dec 29, 2007, 8 AM \u2013 Jan 2, 2008, 5 PM"),
            new DateTest(0, 10, 9, 8, 0, 0, 10, 11, 17, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL,
                    "Nov 9, 8am \u2013 Nov 11, 5pm"),
                    "Nov 9, 8 AM \u2013 Nov 11, 5 PM"),
            new DateTest(2007, 10, 9, 8, 0, 2007, 10, 11, 17, 0,
                    DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_ALL,
                    "Fri, Nov 9, 2007 \u2013 Sun, Nov 11, 2007"),
                    "Fri, Nov 9 \u2013 Sun, Nov 11, 2007"),
            new DateTest(2007, 10, 9, 8, 0, 2007, 10, 11, 17, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_ALL,
                    "Fri, Nov 9, 2007, 8am \u2013 Sun, Nov 11, 2007, 5pm"),
                    "Fri, Nov 9, 2007, 8 AM \u2013 Sun, Nov 11, 2007, 5 PM"),
            new DateTest(2007, 11, 3, 13, 0, 2007, 11, 3, 14, 0,
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR,
                    "1:00PM \u2013 2:00PM, December 3, 2007"),
                    "December 3, 2007, 1:00 \u2013 2:00 PM"),
            // Tests that FORMAT_SHOW_YEAR takes precedence over FORMAT_NO_YEAR:
            new DateTest(2007, 11, 3, 13, 0, 2007, 11, 3, 13, 0,
                    DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_YEAR,
+10 −288
Original line number Diff line number Diff line
@@ -188,13 +188,6 @@ public class UtilsTests extends TestCase {
        setTimezone(Time.getCurrentTimezone());
    }

    @Smoke
    @SmallTest
    public void testCheckForDuplicateNames() {
        Utils.checkForDuplicateNames(mIsDuplicateName, mDuplicateNameCursor, NAME_COLUMN);
        assertEquals(mIsDuplicateNameExpected, mIsDuplicateName);
    }

    @Smoke
    @SmallTest
    public void testGetWeeksSinceEpochFromJulianDay() {
@@ -217,20 +210,6 @@ public class UtilsTests extends TestCase {
        }
    }

    @Smoke
    @SmallTest
    public void testEquals() {
        assertTrue(Utils.equals(null, null));
        assertFalse(Utils.equals("", null));
        assertFalse(Utils.equals(null, ""));
        assertTrue(Utils.equals("",""));

        Integer int1 = new Integer(1);
        Integer int2 = new Integer(1);
        assertTrue(Utils.equals(int1, int2));
    }


    // Helper function to create test events for BusyBits testing
    Event buildTestEvent(int startTime, int endTime, boolean allDay, int startDay, int endDay) {
        Event e = new Event();
@@ -244,263 +223,6 @@ public class UtilsTests extends TestCase {
        return e;
    }

    @Smoke
    @SmallTest
    public void testCreateBusyBitSegments() {

  /*      ArrayList<Event> events = new ArrayList<Event>();

        // Test cases that should return null
        // Empty events list
        assertEquals(null, Utils.createBusyBitSegments(10, 30, 100, 200, 0, events));
        // No events list
        assertEquals(null, Utils.createBusyBitSegments(10, 30, 100, 200, 0, null));

        events.add(buildTestEvent(100, 130, false, 1, 1));
        events.add(buildTestEvent(1000, 1030, false, 1, 1));
        // Illegal pixel positions
        assertEquals(null, Utils.createBusyBitSegments(30, 10, 100, 200, 1, events));
        // Illegal start and end times
        assertEquals(null, Utils.createBusyBitSegments(10, 30, 200, 100, 1, events));
        assertEquals(null, Utils.createBusyBitSegments(10, 30, -10, 100, 1, events));
        assertEquals(null, Utils.createBusyBitSegments(10, 30, 24 * 60 + 100, 24 * 60 + 200, 1,
                events));
        assertEquals(null, Utils.createBusyBitSegments(10, 30, 200, 24 * 60 + 100, 1, events));
        assertEquals(null, Utils.createBusyBitSegments(10, 30, 200, -100, 1, events));
        // No Events in time frame
        assertEquals(null, Utils.createBusyBitSegments(10, 30, 500, 900, 1, events));

        // Test event that spans over the day
        events.clear();
        events.add(buildTestEvent(100, 300, false, 1, 5));
        ArrayList<BusyBitsSegment> segments = new ArrayList<BusyBitsSegment>();
        assertEquals(null, Utils.createBusyBitSegments(0, 250, 200, 1200, 3, events));

        // test zero times events, events that are partially in the time span
        // and all day events
        events.clear();
        events.add(buildTestEvent(100, 300, false, 1, 1));
        events.add(buildTestEvent(1100, 1300, false, 1, 1));
        events.add(buildTestEvent(500, 600, true, 1, 1));
        events.add(buildTestEvent(700, 700, false, 1, 1));
        segments.clear();
        segments.add(new BusyBitsSegment(0, 10, false));
        segments.add(new BusyBitsSegment(90, 100, false));
        assertEquals(segments, Utils.createBusyBitSegments(0, 100, 200, 1200, 1, events));

        // Test event that spans over 2 days but start and end time do not
        // overlap fully with tested time span

        events.clear();
        events.add(buildTestEvent(23 * 60, 120, false, 1, 2));
        segments.clear();
        segments.add(new BusyBitsSegment(0, 120, false));
        assertEquals(segments, Utils.createBusyBitSegments(0, 240, 60, 180, 2, events));

        // Test overlapped events (two draw sizes)
        events.clear();
        events.add(buildTestEvent(10, 200, false, 1, 1));
        events.add(buildTestEvent(150, 250, false, 1, 1));
        events.add(buildTestEvent(150, 250, false, 1, 1));
        events.add(buildTestEvent(200, 400, false, 1, 1));
        events.add(buildTestEvent(500, 700, false, 1, 1));
        events.add(buildTestEvent(550, 600, false, 1, 1));
        events.add(buildTestEvent(550, 580, false, 1, 1));
        events.add(buildTestEvent(560, 570, false, 1, 1));
        events.add(buildTestEvent(600, 700, false, 1, 1));
        events.add(buildTestEvent(620, 700, false, 1, 1));
        events.add(buildTestEvent(650, 700, false, 1, 1));
        events.add(buildTestEvent(800, 900, false, 1, 1));
        events.add(buildTestEvent(800, 900, false, 1, 1));
        events.add(buildTestEvent(800, 850, false, 1, 1));
        events.add(buildTestEvent(1000, 1200, false, 1, 1));
        events.add(buildTestEvent(1000, 1200, false, 1, 1));
        segments.clear();
        segments.add(new BusyBitsSegment(100, 149, false));
        segments.add(new BusyBitsSegment(150, 250, true));
        segments.add(new BusyBitsSegment(251, 400, false));
        segments.add(new BusyBitsSegment(500, 549, false));
        segments.add(new BusyBitsSegment(550, 700, true));
        segments.add(new BusyBitsSegment(800, 900, true));
        segments.add(new BusyBitsSegment(1000, 1100, true));
        assertEquals(segments, Utils.createBusyBitSegments(100, 1100, 100, 1100, 1, events));
        segments.clear();
        segments.add(new BusyBitsSegment(100, 111, false));
        segments.add(new BusyBitsSegment(112, 137, true));
        segments.add(new BusyBitsSegment(138, 175, false));
        segments.add(new BusyBitsSegment(200, 211, false));
        segments.add(new BusyBitsSegment(212, 250, true));
        segments.add(new BusyBitsSegment(275, 300, true));
        segments.add(new BusyBitsSegment(325, 350, true));
        assertEquals(segments, Utils.createBusyBitSegments(100, 350, 100, 1100, 1, events));
*/
    }

    /**
     * Tests the findNanpPhoneNumbers function.
     */
    @SmallTest
    public void testFindNanpPhoneNumber() {
        final String[] NO_NUMBERS = new String[] {};

        findPhoneNumber("", NO_NUMBERS);
        findPhoneNumber("               ", NO_NUMBERS);
        findPhoneNumber("123", NO_NUMBERS);
        findPhoneNumber("how much wood", NO_NUMBERS);
        findPhoneNumber("abc1-650-555-1212", NO_NUMBERS);
        findPhoneNumber("abc 5551212 def", new String[] { "5551212" });
        findPhoneNumber("1234567", NO_NUMBERS);
        findPhoneNumber(" 2345678 ", new String[] { "2345678" });
        findPhoneNumber("1234567890", NO_NUMBERS);
        findPhoneNumber("12345678901", new String[] { "12345678901" });
        findPhoneNumber("123456789012", NO_NUMBERS);
        findPhoneNumber("+1-555-1212", NO_NUMBERS);
        findPhoneNumber("+1 (650) 555-1212", new String[] { "+1 (650) 555-1212" });
        findPhoneNumber("(650) 555-1212, (650) 555-1213",
                new String[] { "(650) 555-1212", "(650) 555-1213" });
        findPhoneNumber("Call 555-1212, 555-1213 and also 555-1214.",
                new String[] { "555-1212", "555-1213", "555-1214." });
        findPhoneNumber("555-1212,555-1213,555-1214", new String[] { "555-1212" });
        findPhoneNumber("123 (650) 555-1212", new String[] { "(650) 555-1212" });
        findPhoneNumber("1-650-555-1212", new String[] { "1-650-555-1212" });
        findPhoneNumber("1650-555-1212", new String[] { "1650-555-1212" });
        findPhoneNumber("1650 555-1212", new String[] { "1650 555-1212" });
        findPhoneNumber("1650/555-1212", NO_NUMBERS);
        findPhoneNumber("1650-555 1212", NO_NUMBERS);
        findPhoneNumber("8-650-555-1212", NO_NUMBERS);
        findPhoneNumber("8 650-555-1212", new String[] { "650-555-1212" });
        findPhoneNumber("650.555.1212", new String[] { "650.555.1212" });
        findPhoneNumber(" *#650.555.1212#*!", new String[] { "*#650.555.1212#*" });
        findPhoneNumber("555.1212", new String[] { "555.1212" });
        findPhoneNumber("6505551212 x123, 555-1212", new String[] { "6505551212", "555-1212" });
        findPhoneNumber("6505551212x123", new String[] { "6505551212" });
        findPhoneNumber("http://example.com/6505551212/", NO_NUMBERS);
        findPhoneNumber("Mountain View, CA 94043 (650) 555-1212", new String[]{ "(650) 555-1212" });
        findPhoneNumber("New York, NY 10001-0001", NO_NUMBERS);
    }

    /**
     * Finds the numbers in a block of text, and checks to see if the positions of the numbers
     * match the expected values.
     *
     * @param text The text to search.
     * @param matches Pairs of start/end positions.
     */
    private static void findPhoneNumber(String text, String[] matches) {
        int[] results = Utils.findNanpPhoneNumbers(text);

        assertEquals(0, results.length % 2);

        if (results.length / 2 != matches.length) {
            fail("Text '" + text + "': expected " + matches.length
                    + " matches, found " + results.length / 2);
        }

        for (int i = 0; i < results.length / 2; i++) {
            CharSequence seq = text.subSequence(results[i*2], results[i*2 + 1]);
            assertEquals(matches[i], seq);
        }
    }

    /**
     * Tests the linkify section of event locations.
     */
    @SmallTest
    public void testExtendedLinkify() {
        final URLSpan[] NO_LINKS = new URLSpan[] {};
        URLSpan span_tel01 = new URLSpan("tel:6505551234");
        URLSpan span_tel02 = new URLSpan("tel:5555678");
        URLSpan span_tel03 = new URLSpan("tel:+16505551234");
        URLSpan span_tel04 = new URLSpan("tel:16505551234");
        URLSpan span_web = new URLSpan("http://www.google.com");
        URLSpan span_geo01 =
                new URLSpan("geo:0,0?q=1600+Amphitheatre+Parkway%2C+Mountain+View+CA+94043");
        URLSpan span_geo02 =
                new URLSpan("geo:0,0?q=37.422081°, -122.084576°");
        URLSpan span_geo03 =
                new URLSpan("geo:0,0?q=37.422081,-122.084576");
        URLSpan span_geo04 =
                new URLSpan("geo:0,0?q=+37°25'19.49\", -122°5'4.47\"");
        URLSpan span_geo05 =
                new URLSpan("geo:0,0?q=37°25'19.49\"N, 122°5'4.47\"W");
        URLSpan span_geo06 =
                new URLSpan("geo:0,0?q=N 37° 25' 19.49\",  W 122° 5' 4.47\"");
        URLSpan span_geo07 = new URLSpan("geo:0,0?q=non-specified address");


        // First test without the last-ditch geo attempt.
        // Phone spans.
        findLinks("", NO_LINKS, false);
        findLinks("(650) 555-1234", new URLSpan[]{span_tel01}, false);
        findLinks("94043", NO_LINKS, false);
        findLinks("123456789012", NO_LINKS, false);
        findLinks("+1 (650) 555-1234", new URLSpan[]{span_tel03}, false);
        findLinks("(650) 555 1234", new URLSpan[]{span_tel01}, false);
        findLinks("1-650-555-1234", new URLSpan[]{span_tel04}, false);
        findLinks("*#650.555.1234#*!", new URLSpan[]{span_tel01}, false);
        findLinks("555.5678", new URLSpan[]{span_tel02}, false);

        // Web spans.
        findLinks("http://www.google.com", new URLSpan[]{span_web}, false);

        // Geo spans.
        findLinks("1600 Amphitheatre Parkway, Mountain View CA 94043",
                new URLSpan[]{span_geo01}, false);
        findLinks("37.422081°, -122.084576°", new URLSpan[]{span_geo02}, false);
        findLinks("37.422081,-122.084576", new URLSpan[]{span_geo03}, false);
        findLinks("+37°25'19.49\", -122°5'4.47\"", new URLSpan[]{span_geo04}, false);
        findLinks("37°25'19.49\"N, 122°5'4.47\"W", new URLSpan[]{span_geo05}, false);
        findLinks("N 37° 25' 19.49\",  W 122° 5' 4.47\"", new URLSpan[]{span_geo06}, false);

        // Multiple spans.
        findLinks("(650) 555-1234 1600 Amphitheatre Parkway, Mountain View CA 94043",
                new URLSpan[]{span_tel01, span_geo01}, false);
        findLinks("(650) 555-1234, 555-5678", new URLSpan[]{span_tel01, span_tel02}, false);


        // Now test using the last-ditch geo attempt.
        findLinks("", NO_LINKS, true);
        findLinks("(650) 555-1234", new URLSpan[]{span_tel01}, true);
        findLinks("http://www.google.com", new URLSpan[]{span_web}, true);
        findLinks("1600 Amphitheatre Parkway, Mountain View CA 94043",
                new URLSpan[]{span_geo01}, true);
        findLinks("37.422081°, -122.084576°", new URLSpan[]{span_geo02}, true);
        findLinks("37.422081,-122.084576", new URLSpan[]{span_geo03}, true);
        findLinks("+37°25'19.49\", -122°5'4.47\"", new URLSpan[]{span_geo04}, true);
        findLinks("37°25'19.49\"N, 122°5'4.47\"W", new URLSpan[]{span_geo05}, true);
        findLinks("N 37° 25' 19.49\",  W 122° 5' 4.47\"", new URLSpan[]{span_geo06}, true);
        findLinks("non-specified address", new URLSpan[]{span_geo07}, true);
    }

    private static void findLinks(String text, URLSpan[] matches, boolean lastDitchGeo) {
        Spannable spanText = Utils.extendedLinkify(text, lastDitchGeo);
        URLSpan[] spansFound = spanText.getSpans(0, spanText.length(), URLSpan.class);
        assertEquals(matches.length, spansFound.length);

        // Make sure the expected matches list of URLs is the same as that returned by linkify.
        ArrayList<URLSpan> matchesArrayList = new ArrayList<URLSpan>(Arrays.asList(matches));
        for (URLSpan spanFound : spansFound) {
            Iterator<URLSpan> matchesIt = matchesArrayList.iterator();
            boolean removed = false;
            while (matchesIt.hasNext()) {
                URLSpan match = matchesIt.next();
                if (match.getURL().equals(spanFound.getURL())) {
                    matchesIt.remove();
                    removed = true;
                    break;
                }
            }
            if (!removed) {
                // If a match was not found for the current spanFound, the lists aren't equal.
                fail("No match found for span: "+spanFound.getURL());
            }
        }

        // As a sanity check, ensure the matches list is empty, as each item should have been
        // removed by going through the spans returned by linkify.
        assertTrue(matchesArrayList.isEmpty());
    }

    @SmallTest
    public void testGetDisplayedDatetime_differentYear() {
        // 4/12/2000 5pm - 4/12/2000 6pm
@@ -508,7 +230,7 @@ public class UtilsTests extends TestCase {
        long end = createTimeInMillis(0, 0, 18, 12, 3, 2000);
        String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE,
                false, dbUtils.getContext());
        assertEquals("Wednesday, April 12, 2000, 5:00PM \u2013 6:00PM", result);
        assertEquals("Wednesday, April 12, 2000, 5:00 \u2013 6:00 PM", result);

        // 12/31/2012 5pm - 1/1/2013 6pm
        start = createTimeInMillis(0, 0, 17, 31, 11, 2012);
@@ -525,7 +247,7 @@ public class UtilsTests extends TestCase {
        long end = createTimeInMillis(0, 0, 18, 12, 3, 2012);
        String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE,
                false, dbUtils.getContext());
        assertEquals("Thursday, April 12, 2012, 5:00PM \u2013 6:00PM", result);
        assertEquals("Thursday, April 12, 2012, 5:00 \u2013 6:00 PM", result);
    }

    @SmallTest
@@ -535,7 +257,7 @@ public class UtilsTests extends TestCase {
        long end = createTimeInMillis(0, 0, 18, NOW_DAY, NOW_MONTH, NOW_YEAR);
        String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE,
                false, dbUtils.getContext());
        assertEquals("Today at 5:00PM \u2013 6:00PM", result);
        assertEquals("Today at 5:00 \u2013 6:00 PM", result);
    }

    @SmallTest
@@ -545,7 +267,7 @@ public class UtilsTests extends TestCase {
        long end = createTimeInMillis(0, 0, 0, NOW_DAY + 1, NOW_MONTH, NOW_YEAR);
        String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE,
                false, dbUtils.getContext());
        assertEquals("Today at 5:00PM \u2013 midnight", result);
        assertEquals("Today at 5:00 PM \u2013 12:00 AM", result);
    }

    @SmallTest
@@ -565,7 +287,7 @@ public class UtilsTests extends TestCase {
        long end = createTimeInMillis(0, 0, 18, 9, 3, 2012);
        String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE,
                false, dbUtils.getContext());
        assertEquals("Monday, April 9, 2012, 5:00PM \u2013 6:00PM", result);
        assertEquals("Monday, April 9, 2012, 5:00 \u2013 6:00 PM", result);
    }

    @SmallTest
@@ -605,7 +327,7 @@ public class UtilsTests extends TestCase {
        long end = createTimeInMillis(0, 0, 0, NOW_DAY + 3, NOW_MONTH, NOW_YEAR, Time.TIMEZONE_UTC);
        String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE,
                true, dbUtils.getContext());
        assertEquals("Tuesday, April 10, 2012 \u2013 Thursday, April 12, 2012", result);
        assertEquals("Tuesday, April 10 \u2013 Thursday, April 12, 2012", result);
    }

    @SmallTest
@@ -619,7 +341,7 @@ public class UtilsTests extends TestCase {
        long end = createTimeInMillis(0, 0, 18, 12, 3, 2012, eventTz);
        String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, localTz, false,
                dbUtils.getContext());
        assertEquals("Thursday, April 12, 2012, 8:00PM \u2013 9:00PM", result);
        assertEquals("Thursday, April 12, 2012, 8:00 \u2013 9:00 PM", result);
    }

    @SmallTest
+0 −319

File deleted.

Preview size limit exceeded, changes collapsed.

Loading