summaryrefslogtreecommitdiffstats
path: root/tests/unit/src/com/android/bluetooth/mapclient/ObexTimeTest.java
diff options
context:
space:
mode:
authorKevin F. Haggerty <haggertk@lineageos.org>2020-06-01 20:43:45 -0600
committerKevin F. Haggerty <haggertk@lineageos.org>2020-06-01 20:43:45 -0600
commitcf38327eba534b6354b44e4d29a3fef8190b481e (patch)
tree84195c87dacf64c2d7df6be202f9f62a62258aba /tests/unit/src/com/android/bluetooth/mapclient/ObexTimeTest.java
parent837b47f2b5613cb2e6235229831f9c80ec28c741 (diff)
parent906df07061fcf46aac856894fb6d68b2ccccfa2c (diff)
downloadandroid_packages_apps_Bluetooth-cf38327eba534b6354b44e4d29a3fef8190b481e.tar.gz
android_packages_apps_Bluetooth-cf38327eba534b6354b44e4d29a3fef8190b481e.tar.bz2
android_packages_apps_Bluetooth-cf38327eba534b6354b44e4d29a3fef8190b481e.zip
Merge tag 'android-10.0.0_r37' into staging/lineage-17.1_merge-android-10.0.0_r37lineage-17.1
Android 10.0.0 Release 37 (QQ3A.200605.001) * tag 'android-10.0.0_r37': (37 commits) Import translations. DO NOT MERGE Revert "PBAP server, send favorite contacts" Import translations. DO NOT MERGE Delete call logs when calls are made without PBAP Set Browsing bit to 0 in PbapSupportedFeatures Prevent phone's bd_addr from appearing in Accounts Return an empty list when the requested node is not in the tree AvrcpController Test update AVRCP Controller Media Controller not ready Allow subsequent requests for media keys to replay the silent audio sample HFP Client call status update PBAP server, send favorite contacts AVRCP Controller Disable Automatic Focus Request A2DP Sink: Focus gain while transient loss AVRCP Controller State without Browsing Add bluetooth prefs for Android Automotive MAP Client disconnect state machine if MAS client disconnected MAP Client close connection on MNS disconnect MAP Client Only connect MNS in connected state MAP Client BMessage parser length ... Change-Id: I1398f4ffe79e4ac0a37765927e4afd2e05ee0908
Diffstat (limited to 'tests/unit/src/com/android/bluetooth/mapclient/ObexTimeTest.java')
-rw-r--r--tests/unit/src/com/android/bluetooth/mapclient/ObexTimeTest.java114
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/unit/src/com/android/bluetooth/mapclient/ObexTimeTest.java b/tests/unit/src/com/android/bluetooth/mapclient/ObexTimeTest.java
new file mode 100644
index 000000000..5ef2d455b
--- /dev/null
+++ b/tests/unit/src/com/android/bluetooth/mapclient/ObexTimeTest.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bluetooth.mapclient;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Date;
+import java.util.TimeZone;
+
+@RunWith(AndroidJUnit4.class)
+public class ObexTimeTest {
+ private static final String TAG = ObexTimeTest.class.getSimpleName();
+
+ private static final String VALID_TIME_STRING = "20190101T121314";
+ private static final String VALID_TIME_STRING_WITH_OFFSET_POS = "20190101T121314+0130";
+ private static final String VALID_TIME_STRING_WITH_OFFSET_NEG = "20190101T121314-0130";
+
+ private static final String INVALID_TIME_STRING_OFFSET_EXTRA_DIGITS = "20190101T121314-99999";
+ private static final String INVALID_TIME_STRING_BAD_DELIMITER = "20190101Q121314";
+
+ // MAP message listing times, per spec, use "local time basis" if UTC offset isn't given. The
+ // ObexTime class parses using the current default timezone (assumed to be the "local timezone")
+ // in the case that UTC isn't provided. However, the Date class assumes UTC ALWAYS when
+ // initializing off of a long value. We have to take that into account when determining our
+ // expected results for time strings that don't have an offset.
+ private static final long LOCAL_TIMEZONE_OFFSET = TimeZone.getDefault().getRawOffset();
+
+ // If you are a positive offset from GMT then GMT is in the "past" and you need to subtract that
+ // offset from the time. If you are negative then GMT is in the future and you need to add that
+ // offset to the time.
+ private static final long VALID_TS = 1546344794000L; // Jan 01, 2019 at 12:13:14 GMT
+ private static final long TS_OFFSET = 5400000L; // 1 Hour, 30 minutes -> milliseconds
+ private static final long VALID_TS_LOCAL_TZ = VALID_TS - LOCAL_TIMEZONE_OFFSET;
+ private static final long VALID_TS_OFFSET_POS = VALID_TS - TS_OFFSET;
+ private static final long VALID_TS_OFFSET_NEG = VALID_TS + TS_OFFSET;
+
+ private static final Date VALID_DATE_LOCAL_TZ = new Date(VALID_TS_LOCAL_TZ);
+ private static final Date VALID_DATE_WITH_OFFSET_POS = new Date(VALID_TS_OFFSET_POS);
+ private static final Date VALID_DATE_WITH_OFFSET_NEG = new Date(VALID_TS_OFFSET_NEG);
+
+ @Test
+ public void createWithValidDateTimeString_TimestampCorrect() {
+ ObexTime timestamp = new ObexTime(VALID_TIME_STRING);
+ Assert.assertEquals("Parsed timestamp must match expected", VALID_DATE_LOCAL_TZ,
+ timestamp.getTime());
+ }
+
+ @Test
+ public void createWithValidDateTimeStringWithPosOffset_TimestampCorrect() {
+ ObexTime timestamp = new ObexTime(VALID_TIME_STRING_WITH_OFFSET_POS);
+ Assert.assertEquals("Parsed timestamp must match expected", VALID_DATE_WITH_OFFSET_POS,
+ timestamp.getTime());
+ }
+
+ @Test
+ public void createWithValidDateTimeStringWithNegOffset_TimestampCorrect() {
+ ObexTime timestamp = new ObexTime(VALID_TIME_STRING_WITH_OFFSET_NEG);
+ Assert.assertEquals("Parsed timestamp must match expected", VALID_DATE_WITH_OFFSET_NEG,
+ timestamp.getTime());
+ }
+
+ @Test
+ public void createWithValidDate_TimestampCorrect() {
+ ObexTime timestamp = new ObexTime(VALID_DATE_LOCAL_TZ);
+ Assert.assertEquals("ObexTime created with a date must return the same date",
+ VALID_DATE_LOCAL_TZ, timestamp.getTime());
+ }
+
+ @Test
+ public void printValidTime_TimestampMatchesInput() {
+ ObexTime timestamp = new ObexTime(VALID_TIME_STRING);
+ Assert.assertEquals("Timestamp as a string must match the input string", VALID_TIME_STRING,
+ timestamp.toString());
+ }
+
+ @Test
+ public void createWithInvalidDelimiterString_TimestampIsNull() {
+ ObexTime timestamp = new ObexTime(INVALID_TIME_STRING_BAD_DELIMITER);
+ Assert.assertEquals("Parsed timestamp was invalid and must result in a null object", null,
+ timestamp.getTime());
+ }
+
+ @Test
+ public void createWithInvalidOffsetString_TimestampIsNull() {
+ ObexTime timestamp = new ObexTime(INVALID_TIME_STRING_OFFSET_EXTRA_DIGITS);
+ Assert.assertEquals("Parsed timestamp was invalid and must result in a null object", null,
+ timestamp.getTime());
+ }
+
+ @Test
+ public void printInvalidTime_ReturnsNull() {
+ ObexTime timestamp = new ObexTime(INVALID_TIME_STRING_BAD_DELIMITER);
+ Assert.assertEquals("Invalid timestamps must return null for toString()", null,
+ timestamp.toString());
+ }
+}