aboutsummaryrefslogtreecommitdiff
path: root/tests/common/src/com/android/tv/testing
diff options
context:
space:
mode:
Diffstat (limited to 'tests/common/src/com/android/tv/testing')
-rw-r--r--tests/common/src/com/android/tv/testing/ChannelUtils.java5
-rw-r--r--tests/common/src/com/android/tv/testing/FakeClock.java106
-rw-r--r--tests/common/src/com/android/tv/testing/ProgramUtils.java3
-rw-r--r--tests/common/src/com/android/tv/testing/Utils.java3
-rw-r--r--tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java34
5 files changed, 147 insertions, 4 deletions
diff --git a/tests/common/src/com/android/tv/testing/ChannelUtils.java b/tests/common/src/com/android/tv/testing/ChannelUtils.java
index 8d96cbed..00881c86 100644
--- a/tests/common/src/com/android/tv/testing/ChannelUtils.java
+++ b/tests/common/src/com/android/tv/testing/ChannelUtils.java
@@ -41,6 +41,7 @@ import java.util.Map;
*/
public class ChannelUtils {
private static final String TAG = "ChannelUtils";
+ private static final boolean DEBUG = false;
/**
* Query and return the map of (channel_id, ChannelInfo).
@@ -115,10 +116,10 @@ public class ChannelUtils {
Long rowId = existingChannelsMap.get(channel.originalNetworkId);
Uri uri;
if (rowId == null) {
- Log.v(TAG, "Inserting "+ channel);
+ if (DEBUG) Log.d(TAG, "Inserting "+ channel);
uri = resolver.insert(TvContract.Channels.CONTENT_URI, values);
} else {
- Log.v(TAG, "Updating "+ channel);
+ if (DEBUG) Log.d(TAG, "Updating "+ channel);
uri = TvContract.buildChannelUri(rowId);
resolver.update(uri, values, null, null);
existingChannelsMap.remove(channel.originalNetworkId);
diff --git a/tests/common/src/com/android/tv/testing/FakeClock.java b/tests/common/src/com/android/tv/testing/FakeClock.java
new file mode 100644
index 00000000..372a7569
--- /dev/null
+++ b/tests/common/src/com/android/tv/testing/FakeClock.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2015 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.tv.testing;
+
+import com.android.tv.util.Clock;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Fake implementation of Clock suitable for testing.
+ *
+ * <p>The current time only changes if {@link #setCurrentTimeMillis(long)}, {@link #increment} or
+ * {@link #sleep(long)} is called.
+ */
+public class FakeClock implements Clock {
+ /**
+ * Creates a fake clock with the time set to now and the boot time set to now - 100,000.
+ */
+ public static FakeClock createWithCurrentTime() {
+ long now = System.currentTimeMillis();
+ return new FakeClock(now, now - 100_000);
+ }
+
+ /**
+ * Creates a fake clock with the time set to zero.
+ */
+ public static FakeClock createWithTimeOne() {
+ return new FakeClock(1L, 0L);
+ }
+
+
+ private long mCurrentTimeMillis;
+
+ private long mBootTimeMillis;
+
+ private FakeClock(long currentTimeMillis, long bootTimeMillis) {
+ mCurrentTimeMillis = currentTimeMillis;
+ mBootTimeMillis = bootTimeMillis;
+ }
+
+ public void setCurrentTimeMillis(long ms) {
+ if (ms < mBootTimeMillis) {
+ throw new IllegalStateException("current time can not be before boot time");
+ }
+ mCurrentTimeMillis = ms;
+ }
+
+ public void setBootTimeMillis(long ms) {
+ if (ms > mCurrentTimeMillis) {
+ throw new IllegalStateException("boot time can not be after current time");
+ }
+ mBootTimeMillis = ms;
+ }
+
+ /**
+ * Increment the current time by one unit of time.
+ *
+ * @param unit The time unit to increment by.
+ */
+ public void increment(TimeUnit unit) {
+ increment(unit, 1);
+ }
+
+ /**
+ * Increment the current time by {@code amount} unit of time.
+ *
+ * @param unit The time unit to increment by.
+ * @param amount The amount of time units to increment by.
+ */
+ private void increment(TimeUnit unit, long amount) {
+ mCurrentTimeMillis += unit.toMillis(amount);
+ }
+
+ @Override
+ public long currentTimeMillis() {
+ return mCurrentTimeMillis;
+ }
+
+ @Override
+ public long elapsedRealtime() {
+ return mCurrentTimeMillis - mBootTimeMillis;
+ }
+
+ /**
+ * Sleep does not block it just updates the current time.
+ */
+ @Override
+ public void sleep(long ms) {
+ // TODO: implement blocking if needed.
+ mCurrentTimeMillis += ms;
+ }
+}
diff --git a/tests/common/src/com/android/tv/testing/ProgramUtils.java b/tests/common/src/com/android/tv/testing/ProgramUtils.java
index 92fe9c82..493891b6 100644
--- a/tests/common/src/com/android/tv/testing/ProgramUtils.java
+++ b/tests/common/src/com/android/tv/testing/ProgramUtils.java
@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
public class ProgramUtils {
private static final String TAG = "ProgramUtils";
+ private static final boolean DEBUG = false;
// Populate program data for a week.
private static final long PROGRAM_INSERT_DURATION_MS = TimeUnit.DAYS.toMillis(7);
@@ -77,7 +78,7 @@ public class ProgramUtils {
|| timeMs >= targetEndTimeMs) {
context.getContentResolver().bulkInsert(Programs.CONTENT_URI,
list.toArray(new ContentValues[list.size()]));
- Log.v(TAG, "Inserted " + list.size() + " programs for " + channelUri);
+ if (DEBUG) Log.d(TAG, "Inserted " + list.size() + " programs for " + channelUri);
list.clear();
}
}
diff --git a/tests/common/src/com/android/tv/testing/Utils.java b/tests/common/src/com/android/tv/testing/Utils.java
index c1a7506f..9e1bd3e9 100644
--- a/tests/common/src/com/android/tv/testing/Utils.java
+++ b/tests/common/src/com/android/tv/testing/Utils.java
@@ -29,6 +29,7 @@ import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
+import com.android.tv.common.TvCommonUtils;
import com.android.tv.util.MainThreadExecutor;
import java.io.IOException;
@@ -46,7 +47,7 @@ import java.util.concurrent.Future;
*
* <p>This class is also used to check whether TV app is running in tests or not.
*
- * @see com.android.tv.util.Utils#isRunningInTest
+ * @see TvCommonUtils#isRunningInTest
*/
public final class Utils {
private static final String TAG ="Utils";
diff --git a/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java b/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java
new file mode 100644
index 00000000..30e21e2e
--- /dev/null
+++ b/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2015 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.tv.testing.dvr;
+
+import com.android.tv.data.Channel;
+import com.android.tv.dvr.Recording;
+
+import java.util.Collections;
+
+/**
+ * Static utils for using {@link Recording} in tests.
+ */
+public class RecordingTestUtils {
+ public static Recording createTestRecordingWithPeriod(long id, long startTime, long endTime) {
+ return Recording.builder(new Channel.Builder().build(), startTime, endTime)
+ .setId(id)
+ .setPrograms(Collections.EMPTY_LIST)
+ .build();
+ }
+}