UtilsTests.java revision 75f53668f94c3ced9d3cc8583d7e45ce725ff9de
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.calendar; 18 19import com.android.calendar.CalendarUtils.TimeZoneUtils; 20 21import android.content.res.Configuration; 22import android.database.MatrixCursor; 23import android.provider.CalendarContract.CalendarCache; 24import android.test.mock.MockResources; 25import android.test.suitebuilder.annotation.SmallTest; 26import android.test.suitebuilder.annotation.Smoke; 27import android.text.format.Time; 28 29import java.util.HashMap; 30import java.util.Locale; 31 32import junit.framework.TestCase; 33 34/** 35 * Test class for verifying helper functions in Calendar's Utils 36 * 37 * You can run these tests with the following command: 38 * "adb shell am instrument -w -e class com.android.calendar.UtilsTests 39 * com.android.calendar.tests/android.test.InstrumentationTestRunner" 40 */ 41public class UtilsTests extends TestCase { 42 HashMap<String, Boolean> mIsDuplicateName; 43 HashMap<String, Boolean> mIsDuplicateNameExpected; 44 MatrixCursor mDuplicateNameCursor; 45 private DbTestUtils dbUtils; 46 private final TimeZoneUtils timezoneUtils = new TimeZoneUtils(Utils.SHARED_PREFS_NAME); 47 48 private static final int NAME_COLUMN = 0; 49 private static final String[] DUPLICATE_NAME_COLUMNS = new String[] { "name" }; 50 private static final String[][] DUPLICATE_NAMES = new String[][] { 51 {"Pepper Pots"}, 52 {"Green Goblin"}, 53 {"Pepper Pots"}, 54 {"Peter Parker"}, 55 {"Silver Surfer"}, 56 {"John Jameson"}, 57 {"John Jameson"}, 58 {"Pepper Pots"} 59 }; 60 // First date is Thursday, Jan 1st, 1970. 61 private static final int[] JULIAN_DAYS = {2440588, 2440589, 2440590, 2440591, 2440592, 2440593, 62 2440594, 2440595, 2440596, 2440597, 2440598, 2440599, 2440600, 2440601 63 }; 64 private static final int[] EXPECTED_WEEK_MONDAY_START = { 65 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2 }; 66 private static final int[] EXPECTED_WEEK_SUNDAY_START = { 67 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2 }; 68 private static final int[] EXPECTED_WEEK_SATURDAY_START = { 69 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 }; 70 private static final int[] WEEKS_FOR_JULIAN_MONDAYS = {1, 2}; 71 private static final int[] EXPECTED_JULIAN_MONDAYS = {2440592, 2440599}; 72 73 private static final int NOW_MONTH = 3; // April 74 private static final int NOW_DAY = 10; 75 private static final int NOW_YEAR = 2012; 76 private static final long NOW_TIME = createTimeInMillis(5, 5, 5, NOW_DAY, NOW_MONTH, NOW_YEAR); 77 private static final String DEFAULT_TIMEZONE = Time.getCurrentTimezone(); 78 79 /** 80 * Mock resources. Add translation strings for test here. 81 */ 82 private static class ResourcesForTest extends MockResources { 83 @Override 84 public String getString(int id) { 85 if (id == R.string.today) { 86 return "Today"; 87 } 88 if (id == R.string.tomorrow) { 89 return "Tomorrow"; 90 } 91 throw new IllegalArgumentException("unexpected resource ID: " + id); 92 } 93 94 @Override 95 public Configuration getConfiguration() { 96 Configuration config = new Configuration(); 97 config.locale = Locale.getDefault(); 98 return config; 99 } 100 } 101 102 private static long createTimeInMillis(int second, int minute, int hour, int monthDay, 103 int month, int year) { 104 return createTimeInMillis(second, minute, hour, monthDay, month, year, 105 Time.getCurrentTimezone()); 106 } 107 108 private static long createTimeInMillis(int second, int minute, int hour, int monthDay, 109 int month, int year, String timezone) { 110 Time t = new Time(timezone); 111 t.set(second, minute, hour, monthDay, month, year); 112 t.normalize(false); 113 return t.toMillis(false); 114 } 115 116 private void setTimezone(String tz) { 117 timezoneUtils.setTimeZone(dbUtils.getContext(), tz); 118 } 119 120 @Override 121 public void setUp() { 122 mIsDuplicateName = new HashMap<String, Boolean> (); 123 mDuplicateNameCursor = new MatrixCursor(DUPLICATE_NAME_COLUMNS); 124 for (int i = 0; i < DUPLICATE_NAMES.length; i++) { 125 mDuplicateNameCursor.addRow(DUPLICATE_NAMES[i]); 126 } 127 128 mIsDuplicateNameExpected = new HashMap<String, Boolean> (); 129 mIsDuplicateNameExpected.put("Pepper Pots", true); 130 mIsDuplicateNameExpected.put("Green Goblin", false); 131 mIsDuplicateNameExpected.put("Peter Parker", false); 132 mIsDuplicateNameExpected.put("Silver Surfer", false); 133 mIsDuplicateNameExpected.put("John Jameson", true); 134 135 // Set up fake db. 136 dbUtils = new DbTestUtils(new ResourcesForTest()); 137 dbUtils.getContentResolver().addProvider("settings", dbUtils.getContentProvider()); 138 dbUtils.getContentResolver().addProvider(CalendarCache.URI.getAuthority(), 139 dbUtils.getContentProvider()); 140 setTimezone(DEFAULT_TIMEZONE); 141 } 142 143 @Override 144 public void tearDown() { 145 mDuplicateNameCursor.close(); 146 147 // Must reset the timezone here, because even though the fake provider will be 148 // recreated/cleared, TimeZoneUtils statically holds on to a cached value. 149 setTimezone(Time.getCurrentTimezone()); 150 } 151 152 @Smoke 153 @SmallTest 154 public void testCheckForDuplicateNames() { 155 Utils.checkForDuplicateNames(mIsDuplicateName, mDuplicateNameCursor, NAME_COLUMN); 156 assertEquals(mIsDuplicateName, mIsDuplicateNameExpected); 157 } 158 159 @Smoke 160 @SmallTest 161 public void testGetWeeksSinceEpochFromJulianDay() { 162 for (int i = 0; i < JULIAN_DAYS.length; i++) { 163 assertEquals(EXPECTED_WEEK_MONDAY_START[i], 164 Utils.getWeeksSinceEpochFromJulianDay(JULIAN_DAYS[i], Time.MONDAY)); 165 assertEquals(EXPECTED_WEEK_SUNDAY_START[i], 166 Utils.getWeeksSinceEpochFromJulianDay(JULIAN_DAYS[i], Time.SUNDAY)); 167 assertEquals(EXPECTED_WEEK_SATURDAY_START[i], 168 Utils.getWeeksSinceEpochFromJulianDay(JULIAN_DAYS[i], Time.SATURDAY)); 169 } 170 } 171 172 @Smoke 173 @SmallTest 174 public void testGetJulianMondayFromWeeksSinceEpoch() { 175 for (int i = 0; i < WEEKS_FOR_JULIAN_MONDAYS.length; i++) { 176 assertEquals(EXPECTED_JULIAN_MONDAYS[i], 177 Utils.getJulianMondayFromWeeksSinceEpoch(WEEKS_FOR_JULIAN_MONDAYS[i])); 178 } 179 } 180 181 @Smoke 182 @SmallTest 183 public void testEquals() { 184 assertTrue(Utils.equals(null, null)); 185 assertFalse(Utils.equals("", null)); 186 assertFalse(Utils.equals(null, "")); 187 assertTrue(Utils.equals("","")); 188 189 Integer int1 = new Integer(1); 190 Integer int2 = new Integer(1); 191 assertTrue(Utils.equals(int1, int2)); 192 } 193 194 195 // Helper function to create test events for BusyBits testing 196 Event buildTestEvent(int startTime, int endTime, boolean allDay, int startDay, int endDay) { 197 Event e = new Event(); 198 e.startTime = startTime; 199 e.endTime = endTime; 200 e.allDay = allDay; 201 e.startDay = startDay; 202 e.endDay = endDay; 203 e.startMillis = e.startDay * 1000L * 3600L * 24L + e.startTime * 60L * 1000L; 204 e.endMillis = e.endDay * 1000L * 3600L * 24L + e.endTime * 60L * 1000L; 205 return e; 206 } 207 208 @Smoke 209 @SmallTest 210 public void testCreateBusyBitSegments() { 211 212 /* ArrayList<Event> events = new ArrayList<Event>(); 213 214 // Test cases that should return null 215 // Empty events list 216 assertEquals(null, Utils.createBusyBitSegments(10, 30, 100, 200, 0, events)); 217 // No events list 218 assertEquals(null, Utils.createBusyBitSegments(10, 30, 100, 200, 0, null)); 219 220 events.add(buildTestEvent(100, 130, false, 1, 1)); 221 events.add(buildTestEvent(1000, 1030, false, 1, 1)); 222 // Illegal pixel positions 223 assertEquals(null, Utils.createBusyBitSegments(30, 10, 100, 200, 1, events)); 224 // Illegal start and end times 225 assertEquals(null, Utils.createBusyBitSegments(10, 30, 200, 100, 1, events)); 226 assertEquals(null, Utils.createBusyBitSegments(10, 30, -10, 100, 1, events)); 227 assertEquals(null, Utils.createBusyBitSegments(10, 30, 24 * 60 + 100, 24 * 60 + 200, 1, 228 events)); 229 assertEquals(null, Utils.createBusyBitSegments(10, 30, 200, 24 * 60 + 100, 1, events)); 230 assertEquals(null, Utils.createBusyBitSegments(10, 30, 200, -100, 1, events)); 231 // No Events in time frame 232 assertEquals(null, Utils.createBusyBitSegments(10, 30, 500, 900, 1, events)); 233 234 // Test event that spans over the day 235 events.clear(); 236 events.add(buildTestEvent(100, 300, false, 1, 5)); 237 ArrayList<BusyBitsSegment> segments = new ArrayList<BusyBitsSegment>(); 238 assertEquals(null, Utils.createBusyBitSegments(0, 250, 200, 1200, 3, events)); 239 240 // test zero times events, events that are partially in the time span 241 // and all day events 242 events.clear(); 243 events.add(buildTestEvent(100, 300, false, 1, 1)); 244 events.add(buildTestEvent(1100, 1300, false, 1, 1)); 245 events.add(buildTestEvent(500, 600, true, 1, 1)); 246 events.add(buildTestEvent(700, 700, false, 1, 1)); 247 segments.clear(); 248 segments.add(new BusyBitsSegment(0, 10, false)); 249 segments.add(new BusyBitsSegment(90, 100, false)); 250 assertEquals(segments, Utils.createBusyBitSegments(0, 100, 200, 1200, 1, events)); 251 252 // Test event that spans over 2 days but start and end time do not 253 // overlap fully with tested time span 254 255 events.clear(); 256 events.add(buildTestEvent(23 * 60, 120, false, 1, 2)); 257 segments.clear(); 258 segments.add(new BusyBitsSegment(0, 120, false)); 259 assertEquals(segments, Utils.createBusyBitSegments(0, 240, 60, 180, 2, events)); 260 261 // Test overlapped events (two draw sizes) 262 events.clear(); 263 events.add(buildTestEvent(10, 200, false, 1, 1)); 264 events.add(buildTestEvent(150, 250, false, 1, 1)); 265 events.add(buildTestEvent(150, 250, false, 1, 1)); 266 events.add(buildTestEvent(200, 400, false, 1, 1)); 267 events.add(buildTestEvent(500, 700, false, 1, 1)); 268 events.add(buildTestEvent(550, 600, false, 1, 1)); 269 events.add(buildTestEvent(550, 580, false, 1, 1)); 270 events.add(buildTestEvent(560, 570, false, 1, 1)); 271 events.add(buildTestEvent(600, 700, false, 1, 1)); 272 events.add(buildTestEvent(620, 700, false, 1, 1)); 273 events.add(buildTestEvent(650, 700, false, 1, 1)); 274 events.add(buildTestEvent(800, 900, false, 1, 1)); 275 events.add(buildTestEvent(800, 900, false, 1, 1)); 276 events.add(buildTestEvent(800, 850, false, 1, 1)); 277 events.add(buildTestEvent(1000, 1200, false, 1, 1)); 278 events.add(buildTestEvent(1000, 1200, false, 1, 1)); 279 segments.clear(); 280 segments.add(new BusyBitsSegment(100, 149, false)); 281 segments.add(new BusyBitsSegment(150, 250, true)); 282 segments.add(new BusyBitsSegment(251, 400, false)); 283 segments.add(new BusyBitsSegment(500, 549, false)); 284 segments.add(new BusyBitsSegment(550, 700, true)); 285 segments.add(new BusyBitsSegment(800, 900, true)); 286 segments.add(new BusyBitsSegment(1000, 1100, true)); 287 assertEquals(segments, Utils.createBusyBitSegments(100, 1100, 100, 1100, 1, events)); 288 segments.clear(); 289 segments.add(new BusyBitsSegment(100, 111, false)); 290 segments.add(new BusyBitsSegment(112, 137, true)); 291 segments.add(new BusyBitsSegment(138, 175, false)); 292 segments.add(new BusyBitsSegment(200, 211, false)); 293 segments.add(new BusyBitsSegment(212, 250, true)); 294 segments.add(new BusyBitsSegment(275, 300, true)); 295 segments.add(new BusyBitsSegment(325, 350, true)); 296 assertEquals(segments, Utils.createBusyBitSegments(100, 350, 100, 1100, 1, events)); 297*/ 298 } 299 300 /** 301 * Tests the findNanpPhoneNumbers function. 302 */ 303 @SmallTest 304 public void testFindNanpPhoneNumber() { 305 final String[] NO_NUMBERS = new String[] {}; 306 307 findPhoneNumber("", NO_NUMBERS); 308 findPhoneNumber(" ", NO_NUMBERS); 309 findPhoneNumber("123", NO_NUMBERS); 310 findPhoneNumber("how much wood", NO_NUMBERS); 311 findPhoneNumber("abc1-650-555-1212", NO_NUMBERS); 312 findPhoneNumber("abc 5551212 def", new String[] { "5551212" }); 313 findPhoneNumber("1234567", NO_NUMBERS); 314 findPhoneNumber(" 2345678 ", new String[] { "2345678" }); 315 findPhoneNumber("1234567890", NO_NUMBERS); 316 findPhoneNumber("12345678901", new String[] { "12345678901" }); 317 findPhoneNumber("123456789012", NO_NUMBERS); 318 findPhoneNumber("+1-555-1212", NO_NUMBERS); 319 findPhoneNumber("+1 (650) 555-1212", new String[] { "+1 (650) 555-1212" }); 320 findPhoneNumber("(650) 555-1212, (650) 555-1213", 321 new String[] { "(650) 555-1212", "(650) 555-1213" }); 322 findPhoneNumber("Call 555-1212, 555-1213 and also 555-1214.", 323 new String[] { "555-1212", "555-1213", "555-1214." }); 324 findPhoneNumber("555-1212,555-1213,555-1214", new String[] { "555-1212" }); 325 findPhoneNumber("123 (650) 555-1212", new String[] { "(650) 555-1212" }); 326 findPhoneNumber("1-650-555-1212", new String[] { "1-650-555-1212" }); 327 findPhoneNumber("1650-555-1212", new String[] { "1650-555-1212" }); 328 findPhoneNumber("1650 555-1212", new String[] { "1650 555-1212" }); 329 findPhoneNumber("1650/555-1212", NO_NUMBERS); 330 findPhoneNumber("1650-555 1212", NO_NUMBERS); 331 findPhoneNumber("8-650-555-1212", NO_NUMBERS); 332 findPhoneNumber("8 650-555-1212", new String[] { "650-555-1212" }); 333 findPhoneNumber("650.555.1212", new String[] { "650.555.1212" }); 334 findPhoneNumber(" *#650.555.1212#*!", new String[] { "*#650.555.1212#*" }); 335 findPhoneNumber("555.1212", new String[] { "555.1212" }); 336 findPhoneNumber("6505551212 x123, 555-1212", new String[] { "6505551212", "555-1212" }); 337 findPhoneNumber("6505551212x123", new String[] { "6505551212" }); 338 findPhoneNumber("http://example.com/6505551212/", NO_NUMBERS); 339 findPhoneNumber("Mountain View, CA 94043 (650) 555-1212", new String[]{ "(650) 555-1212" }); 340 findPhoneNumber("New York, NY 10001-0001", NO_NUMBERS); 341 } 342 343 /** 344 * Finds the numbers in a block of text, and checks to see if the positions of the numbers 345 * match the expected values. 346 * 347 * @param text The text to search. 348 * @param matches Pairs of start/end positions. 349 */ 350 private static void findPhoneNumber(String text, String[] matches) { 351 int[] results = EventInfoFragment.findNanpPhoneNumbers(text); 352 353 assertEquals(results.length % 2, 0); 354 355 if (results.length / 2 != matches.length) { 356 fail("Text '" + text + "': expected " + matches.length 357 + " matches, found " + results.length / 2); 358 } 359 360 for (int i = 0; i < results.length / 2; i++) { 361 CharSequence seq = text.subSequence(results[i*2], results[i*2 + 1]); 362 assertEquals(matches[i], seq); 363 } 364 } 365 366 @SmallTest 367 public void testGetDisplayedDatetime_differentYear() { 368 // 4/12/2000 5pm - 4/12/2000 6pm 369 long start = createTimeInMillis(0, 0, 17, 12, 3, 2000); 370 long end = createTimeInMillis(0, 0, 18, 12, 3, 2000); 371 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 372 DEFAULT_TIMEZONE, false, dbUtils.getContext()); 373 assertEquals("Wednesday, April 12, 2000, 5:00pm \u2013 6:00pm", result); 374 375 // 12/31/2012 5pm - 1/1/2013 6pm 376 start = createTimeInMillis(0, 0, 17, 31, 11, 2012); 377 end = createTimeInMillis(0, 0, 18, 1, 0, 2013); 378 result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 379 DEFAULT_TIMEZONE, false, dbUtils.getContext()); 380 assertEquals("Mon, Dec 31, 2012, 5:00pm – Tue, Jan 1, 2013, 6:00pm", result); 381 } 382 383 @SmallTest 384 public void testGetDisplayedDatetime_sameYear() { 385 // 4/12/2012 5pm - 4/12/2012 6pm 386 long start = createTimeInMillis(0, 0, 17, 12, 3, 2012); 387 long end = createTimeInMillis(0, 0, 18, 12, 3, 2012); 388 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 389 DEFAULT_TIMEZONE, false, dbUtils.getContext()); 390 assertEquals("Thursday, April 12, 5:00pm \u2013 6:00pm", result); 391 } 392 393 @SmallTest 394 public void testGetDisplayedDatetime_today() { 395 // 4/10/2012 5pm - 4/10/2012 6pm 396 long start = createTimeInMillis(0, 0, 17, NOW_DAY, NOW_MONTH, NOW_YEAR); 397 long end = createTimeInMillis(0, 0, 18, NOW_DAY, NOW_MONTH, NOW_YEAR); 398 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 399 DEFAULT_TIMEZONE, false, dbUtils.getContext()); 400 assertEquals("Today, 5:00pm \u2013 6:00pm", result); 401 } 402 403 @SmallTest 404 public void testGetDisplayedDatetime_todayMidnight() { 405 // 4/10/2012 5pm - 4/11/2012 12am 406 long start = createTimeInMillis(0, 0, 17, NOW_DAY, NOW_MONTH, NOW_YEAR); 407 long end = createTimeInMillis(0, 0, 0, NOW_DAY + 1, NOW_MONTH, NOW_YEAR); 408 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 409 DEFAULT_TIMEZONE, false, dbUtils.getContext()); 410 assertEquals("Today, 5:00pm \u2013 midnight", result); 411 } 412 413 @SmallTest 414 public void testGetDisplayedDatetime_tomorrow() { 415 // 4/11/2012 12:01am - 4/11/2012 11:59pm 416 long start = createTimeInMillis(0, 1, 0, NOW_DAY + 1, NOW_MONTH, NOW_YEAR); 417 long end = createTimeInMillis(0, 59, 23, NOW_DAY + 1, NOW_MONTH, NOW_YEAR); 418 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 419 DEFAULT_TIMEZONE, false, dbUtils.getContext()); 420 assertEquals("Tomorrow, 12:01am \u2013 11:59pm", result); 421 } 422 423 @SmallTest 424 public void testGetDisplayedDatetime_yesterday() { 425 // 4/9/2012 5pm - 4/9/2012 6pm 426 long start = createTimeInMillis(0, 0, 17, 9, 3, 2012); 427 long end = createTimeInMillis(0, 0, 18, 9, 3, 2012); 428 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 429 DEFAULT_TIMEZONE, false, dbUtils.getContext()); 430 assertEquals("Monday, April 9, 5:00pm \u2013 6:00pm", result); 431 } 432 433 @SmallTest 434 public void testGetDisplayedDatetime_multiDay() { 435 // 4/10/2012 12:01am - 4/11/2012 12:01am 436 long start = createTimeInMillis(0, 1, 0, NOW_DAY, NOW_MONTH, NOW_YEAR); 437 long end = createTimeInMillis(0, 1, 0, NOW_DAY + 1, NOW_MONTH, NOW_YEAR); 438 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 439 DEFAULT_TIMEZONE, false, dbUtils.getContext()); 440 assertEquals("Tue, Apr 10, 12:01am \u2013 Wed, Apr 11, 12:01am", result); 441 } 442 443 @SmallTest 444 public void testGetDisplayedDatetime_allDay() { 445 // 4/2/2012 12:00am - 4/3/2012 12:00am 446 long start = createTimeInMillis(0, 0, 0, 2, 3, NOW_YEAR, Time.TIMEZONE_UTC); 447 long end = createTimeInMillis(0, 0, 0, 3, 3, NOW_YEAR, Time.TIMEZONE_UTC); 448 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 449 DEFAULT_TIMEZONE, true, dbUtils.getContext()); 450 assertEquals("Monday, April 2", result); 451 } 452 453 @SmallTest 454 public void testGetDisplayedDatetime_allDayToday() { 455 // 4/10/2012 12:00am - 4/11/2012 12:00am 456 long start = createTimeInMillis(0, 0, 0, NOW_DAY, NOW_MONTH, NOW_YEAR, Time.TIMEZONE_UTC); 457 long end = createTimeInMillis(0, 0, 0, NOW_DAY + 1, NOW_MONTH, NOW_YEAR, Time.TIMEZONE_UTC); 458 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE, 459 DEFAULT_TIMEZONE, true, dbUtils.getContext()); 460 assertEquals("Today", result); 461 } 462 463 @SmallTest 464 public void testGetDisplayedDatetime_differentTimezone() { 465 String localTz = "America/New_York"; 466 String eventTz = "America/Los_Angeles"; 467 setTimezone(localTz); 468 469 // 4/12/2012 5pm - 4/12/2012 6pm (Pacific) 470 long start = createTimeInMillis(0, 0, 17, 12, 3, 2012, eventTz); 471 long end = createTimeInMillis(0, 0, 18, 12, 3, 2012, eventTz); 472 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, localTz, eventTz, false, 473 dbUtils.getContext()); 474 assertEquals("Thursday, April 12, 8:00pm \u2013 9:00pm (EDT)", result); 475 } 476 477 @SmallTest 478 public void testGetDisplayedDatetime_allDayDiffTimezone() { 479 String localTz = "America/New_York"; 480 setTimezone(localTz); 481 482 // 4/2/2012 12:00am - 4/3/2012 12:00am 483 long start = createTimeInMillis(0, 0, 0, 2, 3, NOW_YEAR, Time.TIMEZONE_UTC); 484 long end = createTimeInMillis(0, 0, 0, 3, 3, NOW_YEAR, Time.TIMEZONE_UTC); 485 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, localTz, 486 Time.TIMEZONE_UTC, true, dbUtils.getContext()); 487 assertEquals("Monday, April 2", result); 488 } 489 490 @SmallTest 491 public void testGetDisplayedDatetime_allDayTomorrowDiffTimezone() { 492 String localTz = "America/New_York"; 493 setTimezone(localTz); 494 495 // 4/2/2012 12:00am - 4/3/2012 12:00am 496 long start = createTimeInMillis(0, 0, 0, NOW_DAY + 1, NOW_MONTH, NOW_YEAR, 497 Time.TIMEZONE_UTC); 498 long end = createTimeInMillis(0, 0, 0, NOW_DAY + 2, NOW_MONTH, NOW_YEAR, 499 Time.TIMEZONE_UTC); 500 String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, localTz, 501 Time.TIMEZONE_UTC, true, dbUtils.getContext()); 502 assertEquals("Tomorrow", result); 503 } 504} 505