Commit fbd0a57e by Oliver Woodman

Push tests.

parent 462fea3e
Showing with 1983 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="src" path="java"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry combineaccessrules="false" kind="src" path="/ExoPlayerDemo"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ExoPlayerTests</name>
<comment></comment>
<projects>
<project>ExoPlayerLib</project>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>libs/dexmaker-1.2.jar</name>
<type>1</type>
<locationURI>$%7BPARENT-3-PROJECT_LOC%7D/third_party/dexmaker/dexmaker-1.2.jar</locationURI>
</link>
<link>
<name>libs/dexmaker-mockito-1.2.jar</name>
<type>1</type>
<locationURI>$%7BPARENT-3-PROJECT_LOC%7D/third_party/dexmaker/dexmaker-mockito-1.2.jar</locationURI>
</link>
<link>
<name>libs/mockito-all-1.9.5.jar</name>
<type>1</type>
<locationURI>$%7BPARENT-3-PROJECT_LOC%7D/third_party/mockito/mockito-all-1.9.5.jar</locationURI>
</link>
</linkedResources>
<filteredResources>
<filter>
<id>1425657306619</id>
<name></name>
<type>14</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-true-false-BUILD</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.exoplayer.tests">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21"/>
<application>
<uses-library android:name="android.test.runner"/>
</application>
<instrumentation
android:targetPackage="com.google.android.exoplayer.demo"
android:name="android.test.InstrumentationTestRunner"/>
</manifest>
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
availabilityStartTime="2014-06-19T23:07:42"
minBufferTime="PT1.500S"
minimumUpdatePeriod="PT5.000S"
profiles="urn:mpeg:dash:profile:isoff-main:2011"
timeShiftBufferDepth="PT129600.000S"
type="dynamic"
xmlns="urn:mpeg:DASH:schema:MPD:2011"
xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 DASH-MPD.xsd"
yt:earliestMediaSequence="1266404" >
<Period start="PT6462826.784S" >
<SegmentList
presentationTimeOffset="34740095"
startNumber="1292317"
timescale="1000" >
<SegmentTimeline>
<S d="4804" />
<S d="5338" />
<S d="4938" />
</SegmentTimeline>
</SegmentList>
<AdaptationSet
mimeType="audio/mp4"
subsegmentAlignment="true" >
<Role
schemeIdUri="urn:mpeg:DASH:role:2011"
value="main" />
<Representation
id="141"
audioSamplingRate="48000"
bandwidth="272000"
codecs="mp4a.40.2"
startWithSAP="1" >
<AudioChannelConfiguration
schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011"
value="2" />
<BaseURL>
http://www.test.com/141
</BaseURL>
<SegmentList>
<Initialization
range="0-591"
sourceURL="sq/0/clen/79480/lmt/1403219262956762/dur/4.805" />
<SegmentURL media="sq/1292317/clen/77447/lmt/1409671169987621/dur/4.805" />
<SegmentURL media="sq/1292318/clen/86958/lmt/1409671174832549/dur/5.339" />
<SegmentURL media="sq/1292319/clen/85018/lmt/1409671179719956/dur/4.938" />
</SegmentList>
</Representation>
</AdaptationSet>
<AdaptationSet
mimeType="video/mp4"
subsegmentAlignment="true" >
<Role
schemeIdUri="urn:mpeg:DASH:role:2011"
value="main" />
<Representation
id="135"
bandwidth="1116000"
codecs="avc1.42c01f"
height="480"
startWithSAP="1"
width="854" >
<BaseURL>
http://www.test.com/135
</BaseURL>
<SegmentList>
<Initialization
range="0-671"
sourceURL="sq/0/clen/1221137/lmt/1403219262956762/dur/4.805" />
<SegmentURL media="sq/1292317/clen/1279915/lmt/1409671169987621/dur/4.805" />
<SegmentURL media="sq/1292318/clen/1310650/lmt/1409671174832549/dur/5.339" />
<SegmentURL media="sq/1292319/clen/1486558/lmt/1409671179719956/dur/4.938" />
</SegmentList>
</Representation>
</AdaptationSet>
<AdaptationSet
lang="en"
mimeType="text/vtt" >
<Role
schemeIdUri="urn:mpeg:DASH:role:2011"
value="caption" />
<Representation
id="en"
bandwidth="0"
codecs="" >
<BaseURL>
http://www.test.com/vtt
</BaseURL>
<SegmentList>
<SegmentURL media="sq/1292317" />
<SegmentURL media="sq/1292318" />
<SegmentURL media="sq/1292319" />
</SegmentList>
</Representation>
</AdaptationSet>
</Period>
</MPD>
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00.000,MPEGTS:450000
00:00.000 --> 00:01.234
This is the first subtitle.
00:02.345 --> 00:03.456
This is the second subtitle.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00.000,MPEGTS:450000
1
00:00.000 --> 00:01.234
This is the first subtitle.
2
00:02.345 --> 00:03.456
This is the second subtitle.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00.000,MPEGTS:450000
00:00.000 --> 00:01.234
This is the <i>first</i> subtitle.
00:02.345 --> 00:03.456
This is the <b><i>second</b></i> subtitle.
00:04.000 --> 00:05.000
This is the <c.red.caps>third</c> subtitle.
00:06.000 --> 00:07.000
This is&nbsp;the &lt;fourth&gt; &amp;subtitle.
/*
* Copyright (C) 2014 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.google.android.exoplayer;
import com.google.android.exoplayer.util.Util;
import android.annotation.TargetApi;
import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.List;
/**
* Unit test for {@link MediaFormat}.
*/
public class MediaFormatTest extends TestCase {
public void testConversionToFrameworkFormat() {
if (Util.SDK_INT < 16) {
// Test doesn't apply.
return;
}
byte[] initData1 = new byte[] {1, 2, 3};
byte[] initData2 = new byte[] {4, 5, 6};
List<byte[]> initData = new ArrayList<byte[]>();
initData.add(initData1);
initData.add(initData2);
testConversionToFrameworkFormatV16(
MediaFormat.createVideoFormat("video/xyz", 102400, 1280, 720, 1.5f, initData));
testConversionToFrameworkFormatV16(
MediaFormat.createAudioFormat("audio/xyz", 102400, 5, 44100, initData));
}
@TargetApi(16)
private void testConversionToFrameworkFormatV16(MediaFormat format) {
// Convert to a framework MediaFormat and back again.
MediaFormat convertedFormat = MediaFormat.createFromFrameworkMediaFormatV16(
format.getFrameworkMediaFormatV16());
// Assert that we end up with an equivalent object to the one we started with.
assertEquals(format.hashCode(), convertedFormat.hashCode());
assertEquals(format, convertedFormat);
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.dash;
import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.chunk.Format;
import com.google.android.exoplayer.dash.mpd.Representation;
import com.google.android.exoplayer.dash.mpd.SegmentBase.SingleSegmentBase;
import junit.framework.TestCase;
/**
* Tests {@link DashChunkSource}.
*/
public class DashChunkSourceTest extends TestCase {
public void testMaxVideoDimensions() {
SingleSegmentBase segmentBase1 = new SingleSegmentBase("https://example.com/1.mp4");
Format format1 = new Format("1", "video/mp4", 100, 200, -1, -1, 1000);
Representation representation1 =
Representation.newInstance(0, 0, null, 0, format1, segmentBase1);
SingleSegmentBase segmentBase2 = new SingleSegmentBase("https://example.com/2.mp4");
Format format2 = new Format("2", "video/mp4", 400, 50, -1, -1, 1000);
Representation representation2 =
Representation.newInstance(0, 0, null, 0, format2, segmentBase2);
DashChunkSource chunkSource = new DashChunkSource(null, null, representation1, representation2);
MediaFormat out = MediaFormat.createVideoFormat("video/h264", 1, 1, 1, 1, null);
chunkSource.getMaxVideoDimensions(out);
assertEquals(400, out.getMaxVideoWidth());
assertEquals(200, out.getMaxVideoHeight());
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.dash.mpd;
import android.test.InstrumentationTestCase;
import java.io.IOException;
import java.io.InputStream;
/**
* Unit tests for {@link MediaPresentationDescriptionParser}.
*/
public class MediaPresentationDescriptionParserTest extends InstrumentationTestCase {
private static final String SAMPLE_MPD_1 = "dash/sample_mpd_1";
public void testParseMediaPresentationDescription() throws IOException {
MediaPresentationDescriptionParser parser = new MediaPresentationDescriptionParser();
InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets().open(SAMPLE_MPD_1);
// Simple test to ensure that the sample manifest parses without throwing any exceptions.
parser.parse("https://example.com/test.mpd", inputStream);
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.dash.mpd;
import junit.framework.TestCase;
/**
* Unit test for {@link RangedUri}.
*/
public class RangedUriTest extends TestCase {
private static final String FULL_URI = "http://www.test.com/path/file.ext";
public void testMerge() {
RangedUri rangeA = new RangedUri(null, FULL_URI, 0, 10);
RangedUri rangeB = new RangedUri(null, FULL_URI, 10, 10);
RangedUri expected = new RangedUri(null, FULL_URI, 0, 20);
assertMerge(rangeA, rangeB, expected);
}
public void testMergeUnbounded() {
RangedUri rangeA = new RangedUri(null, FULL_URI, 0, 10);
RangedUri rangeB = new RangedUri(null, FULL_URI, 10, -1);
RangedUri expected = new RangedUri(null, FULL_URI, 0, -1);
assertMerge(rangeA, rangeB, expected);
}
public void testNonMerge() {
// A and B do not overlap, so should not merge
RangedUri rangeA = new RangedUri(null, FULL_URI, 0, 10);
RangedUri rangeB = new RangedUri(null, FULL_URI, 11, 10);
assertNonMerge(rangeA, rangeB);
// A and B do not overlap, so should not merge
rangeA = new RangedUri(null, FULL_URI, 0, 10);
rangeB = new RangedUri(null, FULL_URI, 11, -1);
assertNonMerge(rangeA, rangeB);
// A and B are bounded but overlap, so should not merge
rangeA = new RangedUri(null, FULL_URI, 0, 11);
rangeB = new RangedUri(null, FULL_URI, 10, 10);
assertNonMerge(rangeA, rangeB);
// A and B overlap due to unboundedness, so should not merge
rangeA = new RangedUri(null, FULL_URI, 0, -1);
rangeB = new RangedUri(null, FULL_URI, 10, -1);
assertNonMerge(rangeA, rangeB);
}
private void assertMerge(RangedUri rangeA, RangedUri rangeB, RangedUri expected) {
RangedUri merged = rangeA.attemptMerge(rangeB);
assertEquals(expected, merged);
merged = rangeB.attemptMerge(rangeA);
assertEquals(expected, merged);
}
private void assertNonMerge(RangedUri rangeA, RangedUri rangeB) {
RangedUri merged = rangeA.attemptMerge(rangeB);
assertNull(merged);
merged = rangeB.attemptMerge(rangeA);
assertNull(merged);
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.dash.mpd;
import com.google.android.exoplayer.chunk.Format;
import com.google.android.exoplayer.dash.mpd.SegmentBase.SingleSegmentBase;
import com.google.android.exoplayer.util.MimeTypes;
import junit.framework.TestCase;
/**
* Unit test for {@link Representation}.
*/
public class RepresentationTest extends TestCase {
public void testGetCacheKey() {
String uri = "http://www.google.com";
SegmentBase base = new SingleSegmentBase(new RangedUri(uri, null, 0, 1), 1, 0, uri, 1, 1);
Format format = new Format("0", MimeTypes.VIDEO_MP4, 1920, 1080, 0, 0, 2500000);
Representation representation = Representation.newInstance(-1, -1, "test_stream_1", 3,
format, base);
assertEquals("test_stream_1.0.3", representation.getCacheKey());
format = new Format("150", MimeTypes.VIDEO_MP4, 1920, 1080, 0, 0, 2500000);
representation = Representation.newInstance(-1, -1, "test_stream_1", -1, format, base);
assertEquals("test_stream_1.150.-1", representation.getCacheKey());
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.dash.mpd;
import junit.framework.TestCase;
/**
* Unit test for {@link UrlTemplate}.
*/
public class UrlTemplateTest extends TestCase {
public void testRealExamples() {
String template = "QualityLevels($Bandwidth$)/Fragments(video=$Time$,format=mpd-time-csf)";
UrlTemplate urlTemplate = UrlTemplate.compile(template);
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("QualityLevels(650000)/Fragments(video=5000,format=mpd-time-csf)", url);
template = "$RepresentationID$/$Number$";
urlTemplate = UrlTemplate.compile(template);
url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("abc1/10", url);
template = "chunk_ctvideo_cfm4s_rid$RepresentationID$_cn$Number$_w2073857842_mpd.m4s";
urlTemplate = UrlTemplate.compile(template);
url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("chunk_ctvideo_cfm4s_ridabc1_cn10_w2073857842_mpd.m4s", url);
}
public void testFull() {
String template = "$Bandwidth$_a_$RepresentationID$_b_$Time$_c_$Number$";
UrlTemplate urlTemplate = UrlTemplate.compile(template);
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("650000_a_abc1_b_5000_c_10", url);
}
public void testFullWithDollarEscaping() {
String template = "$$$Bandwidth$$$_a$$_$RepresentationID$_b_$Time$_c_$Number$$$";
UrlTemplate urlTemplate = UrlTemplate.compile(template);
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
assertEquals("$650000$_a$_abc1_b_5000_c_10$", url);
}
public void testInvalidSubstitution() {
String template = "$IllegalId$";
try {
UrlTemplate.compile(template);
assertTrue(false);
} catch (IllegalArgumentException e) {
// Expected.
}
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.hls;
import com.google.android.exoplayer.C;
import junit.framework.TestCase;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
/**
* Test for {@link HlsMasterPlaylistParserTest}
*/
public class HlsMasterPlaylistParserTest extends TestCase {
public void testParseMasterPlaylist() {
String playlistUrl = "https://example.com/test.m3u8";
String playlistString = "#EXTM3U\n"
+ "\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=1280000,CODECS=\"mp4a.40.2,avc1.66.30\",RESOLUTION=304x128\n"
+ "http://example.com/low.m3u8\n"
+ "\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=1280000,CODECS=\"mp4a.40.2 , avc1.66.30 \"\n"
+ "http://example.com/spaces_in_codecs.m3u8\n"
+ "\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=2560000,RESOLUTION=384x160\n"
+ "http://example.com/mid.m3u8\n"
+ "\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=7680000\n"
+ "http://example.com/hi.m3u8\n"
+ "\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=65000,CODECS=\"mp4a.40.5\"\n"
+ "http://example.com/audio-only.m3u8";
ByteArrayInputStream inputStream = new ByteArrayInputStream(
playlistString.getBytes(Charset.forName(C.UTF8_NAME)));
try {
HlsPlaylist playlist = new HlsPlaylistParser().parse(playlistUrl, inputStream);
assertNotNull(playlist);
assertEquals(HlsPlaylist.TYPE_MASTER, playlist.type);
HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) playlist;
List<Variant> variants = masterPlaylist.variants;
assertNotNull(variants);
assertEquals(5, variants.size());
assertEquals(0, variants.get(0).index);
assertEquals(1280000, variants.get(0).bandwidth);
assertNotNull(variants.get(0).codecs);
assertEquals(2, variants.get(0).codecs.length);
assertEquals("mp4a.40.2", variants.get(0).codecs[0]);
assertEquals("avc1.66.30", variants.get(0).codecs[1]);
assertEquals(304, variants.get(0).width);
assertEquals(128, variants.get(0).height);
assertEquals("http://example.com/low.m3u8", variants.get(0).url);
assertEquals(1, variants.get(1).index);
assertEquals(1280000, variants.get(1).bandwidth);
assertNotNull(variants.get(1).codecs);
assertEquals(2, variants.get(1).codecs.length);
assertEquals("mp4a.40.2", variants.get(1).codecs[0]);
assertEquals("avc1.66.30", variants.get(1).codecs[1]);
assertEquals("http://example.com/spaces_in_codecs.m3u8", variants.get(1).url);
assertEquals(2, variants.get(2).index);
assertEquals(2560000, variants.get(2).bandwidth);
assertEquals(null, variants.get(2).codecs);
assertEquals(384, variants.get(2).width);
assertEquals(160, variants.get(2).height);
assertEquals("http://example.com/mid.m3u8", variants.get(2).url);
assertEquals(3, variants.get(3).index);
assertEquals(7680000, variants.get(3).bandwidth);
assertEquals(null, variants.get(3).codecs);
assertEquals(-1, variants.get(3).width);
assertEquals(-1, variants.get(3).height);
assertEquals("http://example.com/hi.m3u8", variants.get(3).url);
assertEquals(4, variants.get(4).index);
assertEquals(65000, variants.get(4).bandwidth);
assertNotNull(variants.get(4).codecs);
assertEquals(1, variants.get(4).codecs.length);
assertEquals("mp4a.40.5", variants.get(4).codecs[0]);
assertEquals(-1, variants.get(4).width);
assertEquals(-1, variants.get(4).height);
assertEquals("http://example.com/audio-only.m3u8", variants.get(4).url);
} catch (IOException exception) {
fail(exception.getMessage());
}
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.hls;
import com.google.android.exoplayer.C;
import junit.framework.TestCase;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Locale;
/**
* Test for {@link HlsMediaPlaylistParserTest}
*/
public class HlsMediaPlaylistParserTest extends TestCase {
public void testParseMediaPlaylist() {
String playlistUrl = "https://example.com/test.m3u8";
String playlistString = "#EXTM3U\n"
+ "#EXT-X-VERSION:3\n"
+ "#EXT-X-TARGETDURATION:8\n"
+ "#EXT-X-MEDIA-SEQUENCE:2679\n"
+ "#EXT-X-ALLOW-CACHE:YES\n"
+ "\n"
+ "#EXTINF:7.975,\n"
+ "#EXT-X-BYTERANGE:51370@0\n"
+ "https://priv.example.com/fileSequence2679.ts\n"
+ "\n"
+ "#EXT-X-KEY:METHOD=AES-128,URI=\"https://priv.example.com/key.php?r=2680\",IV=0x1566B\n"
+ "#EXTINF:7.975,\n"
+ "#EXT-X-BYTERANGE:51501@51370\n"
+ "https://priv.example.com/fileSequence2680.ts\n"
+ "\n"
+ "#EXT-X-KEY:METHOD=NONE\n"
+ "#EXTINF:7.941,\n"
+ "#EXT-X-BYTERANGE:51501\n" // @102871
+ "https://priv.example.com/fileSequence2681.ts\n"
+ "\n"
+ "#EXT-X-DISCONTINUITY\n"
+ "#EXT-X-KEY:METHOD=AES-128,URI=\"https://priv.example.com/key.php?r=2682\"\n"
+ "#EXTINF:7.975,\n"
+ "#EXT-X-BYTERANGE:51740\n" // @154372
+ "https://priv.example.com/fileSequence2682.ts\n"
+ "\n"
+ "#EXTINF:7.975,\n"
+ "https://priv.example.com/fileSequence2683.ts\n"
+ "#EXT-X-ENDLIST";
InputStream inputStream = new ByteArrayInputStream(
playlistString.getBytes(Charset.forName(C.UTF8_NAME)));
try {
HlsPlaylist playlist = new HlsPlaylistParser().parse(playlistUrl, inputStream);
assertNotNull(playlist);
assertEquals(HlsPlaylist.TYPE_MEDIA, playlist.type);
HlsMediaPlaylist mediaPlaylist = (HlsMediaPlaylist) playlist;
assertEquals(2679, mediaPlaylist.mediaSequence);
assertEquals(8, mediaPlaylist.targetDurationSecs);
assertEquals(3, mediaPlaylist.version);
assertEquals(false, mediaPlaylist.live);
List<HlsMediaPlaylist.Segment> segments = mediaPlaylist.segments;
assertNotNull(segments);
assertEquals(5, segments.size());
assertEquals(false, segments.get(0).discontinuity);
assertEquals(7.975, segments.get(0).durationSecs);
assertEquals(null, segments.get(0).encryptionMethod);
assertEquals(null, segments.get(0).encryptionKeyUri);
assertEquals(null, segments.get(0).encryptionIV);
assertEquals(51370, segments.get(0).byterangeLength);
assertEquals(0, segments.get(0).byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2679.ts", segments.get(0).url);
assertEquals(false, segments.get(1).discontinuity);
assertEquals(7.975, segments.get(1).durationSecs);
assertEquals("AES-128", segments.get(1).encryptionMethod);
assertEquals("https://priv.example.com/key.php?r=2680", segments.get(1).encryptionKeyUri);
assertEquals("0x1566B", segments.get(1).encryptionIV);
assertEquals(51501, segments.get(1).byterangeLength);
assertEquals(51370, segments.get(1).byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2680.ts", segments.get(1).url);
assertEquals(false, segments.get(2).discontinuity);
assertEquals(7.941, segments.get(2).durationSecs);
assertEquals(HlsMediaPlaylist.ENCRYPTION_METHOD_NONE, segments.get(2).encryptionMethod);
assertEquals(null, segments.get(2).encryptionKeyUri);
assertEquals(null, segments.get(2).encryptionIV);
assertEquals(51501, segments.get(2).byterangeLength);
assertEquals(102871, segments.get(2).byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2681.ts", segments.get(2).url);
assertEquals(true, segments.get(3).discontinuity);
assertEquals(7.975, segments.get(3).durationSecs);
assertEquals("AES-128", segments.get(3).encryptionMethod);
assertEquals("https://priv.example.com/key.php?r=2682", segments.get(3).encryptionKeyUri);
// 0xA7A == 2682.
assertNotNull(segments.get(3).encryptionIV);
assertEquals("A7A", segments.get(3).encryptionIV.toUpperCase(Locale.getDefault()));
assertEquals(51740, segments.get(3).byterangeLength);
assertEquals(154372, segments.get(3).byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2682.ts", segments.get(3).url);
assertEquals(false, segments.get(4).discontinuity);
assertEquals(7.975, segments.get(4).durationSecs);
assertEquals("AES-128", segments.get(4).encryptionMethod);
assertEquals("https://priv.example.com/key.php?r=2682", segments.get(4).encryptionKeyUri);
// 0xA7A == 2682.
assertNotNull(segments.get(4).encryptionIV);
assertEquals("A7A", segments.get(4).encryptionIV.toUpperCase(Locale.getDefault()));
assertEquals(C.LENGTH_UNBOUNDED, segments.get(4).byterangeLength);
assertEquals(0, segments.get(4).byterangeOffset);
assertEquals("https://priv.example.com/fileSequence2683.ts", segments.get(4).url);
} catch (IOException exception) {
fail(exception.getMessage());
}
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.metadata;
import junit.framework.TestCase;
import java.util.Map;
/**
* Test for {@link Id3Parser}
*/
public class Id3ParserTest extends TestCase {
public void testParseTxxxFrames() {
byte[] rawId3 = new byte[] { 73, 68, 51, 4, 0, 0, 0, 0, 0, 41, 84, 88, 88, 88, 0, 0, 0, 31,
0, 0, 3, 0, 109, 100, 105, 97, 108, 111, 103, 95, 86, 73, 78, 68, 73, 67, 79, 49, 53, 50,
55, 54, 54, 52, 95, 115, 116, 97, 114, 116, 0 };
Id3Parser parser = new Id3Parser();
try {
Map<String, Object> metadata = parser.parse(rawId3, rawId3.length);
assertNotNull(metadata);
assertEquals(1, metadata.size());
TxxxMetadata txxx = (TxxxMetadata) metadata.get(TxxxMetadata.TYPE);
assertNotNull(txxx);
assertEquals("", txxx.description);
assertEquals("mdialog_VINDICO1527664_start", txxx.value);
} catch (Exception exception) {
fail(exception.getMessage());
}
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.mp4;
import junit.framework.TestCase;
import java.util.Arrays;
/**
* Tests for {@link Mp4Util}.
*/
public class Mp4UtilTest extends TestCase {
private static final int TEST_PARTIAL_NAL_POSITION = 4;
private static final int TEST_NAL_POSITION = 10;
public void testFindNalUnit() {
byte[] data = buildTestData();
// Should find NAL unit.
int result = Mp4Util.findNalUnit(data, 0, data.length);
assertEquals(TEST_NAL_POSITION, result);
// Should find NAL unit whose prefix ends one byte before the limit.
result = Mp4Util.findNalUnit(data, 0, TEST_NAL_POSITION + 4);
assertEquals(TEST_NAL_POSITION, result);
// Shouldn't find NAL unit whose prefix ends at the limit (since the limit is exclusive).
result = Mp4Util.findNalUnit(data, 0, TEST_NAL_POSITION + 3);
assertEquals(TEST_NAL_POSITION + 3, result);
// Should find NAL unit whose prefix starts at the offset.
result = Mp4Util.findNalUnit(data, TEST_NAL_POSITION, data.length);
assertEquals(TEST_NAL_POSITION, result);
// Shouldn't find NAL unit whose prefix starts one byte past the offset.
result = Mp4Util.findNalUnit(data, TEST_NAL_POSITION + 1, data.length);
assertEquals(data.length, result);
}
public void testFindNalUnitWithPrefix() {
byte[] data = buildTestData();
// First byte of NAL unit in data1, rest in data2.
boolean[] prefixFlags = new boolean[3];
byte[] data1 = Arrays.copyOfRange(data, 0, TEST_NAL_POSITION + 1);
byte[] data2 = Arrays.copyOfRange(data, TEST_NAL_POSITION + 1, data.length);
int result = Mp4Util.findNalUnit(data1, 0, data1.length, prefixFlags);
assertEquals(data1.length, result);
result = Mp4Util.findNalUnit(data2, 0, data2.length, prefixFlags);
assertEquals(-1, result);
assertPrefixFlagsCleared(prefixFlags);
// First three bytes of NAL unit in data1, rest in data2.
prefixFlags = new boolean[3];
data1 = Arrays.copyOfRange(data, 0, TEST_NAL_POSITION + 3);
data2 = Arrays.copyOfRange(data, TEST_NAL_POSITION + 3, data.length);
result = Mp4Util.findNalUnit(data1, 0, data1.length, prefixFlags);
assertEquals(data1.length, result);
result = Mp4Util.findNalUnit(data2, 0, data2.length, prefixFlags);
assertEquals(-3, result);
assertPrefixFlagsCleared(prefixFlags);
// First byte of NAL unit in data1, second byte in data2, rest in data3.
prefixFlags = new boolean[3];
data1 = Arrays.copyOfRange(data, 0, TEST_NAL_POSITION + 1);
data2 = Arrays.copyOfRange(data, TEST_NAL_POSITION + 1, TEST_NAL_POSITION + 2);
byte[] data3 = Arrays.copyOfRange(data, TEST_NAL_POSITION + 2, data.length);
result = Mp4Util.findNalUnit(data1, 0, data1.length, prefixFlags);
assertEquals(data1.length, result);
result = Mp4Util.findNalUnit(data2, 0, data2.length, prefixFlags);
assertEquals(data2.length, result);
result = Mp4Util.findNalUnit(data3, 0, data3.length, prefixFlags);
assertEquals(-2, result);
assertPrefixFlagsCleared(prefixFlags);
// NAL unit split with one byte in four arrays.
prefixFlags = new boolean[3];
data1 = Arrays.copyOfRange(data, 0, TEST_NAL_POSITION + 1);
data2 = Arrays.copyOfRange(data, TEST_NAL_POSITION + 1, TEST_NAL_POSITION + 2);
data3 = Arrays.copyOfRange(data, TEST_NAL_POSITION + 2, TEST_NAL_POSITION + 3);
byte[] data4 = Arrays.copyOfRange(data, TEST_NAL_POSITION + 2, data.length);
result = Mp4Util.findNalUnit(data1, 0, data1.length, prefixFlags);
assertEquals(data1.length, result);
result = Mp4Util.findNalUnit(data2, 0, data2.length, prefixFlags);
assertEquals(data2.length, result);
result = Mp4Util.findNalUnit(data3, 0, data3.length, prefixFlags);
assertEquals(data3.length, result);
result = Mp4Util.findNalUnit(data4, 0, data4.length, prefixFlags);
assertEquals(-3, result);
assertPrefixFlagsCleared(prefixFlags);
// NAL unit entirely in data2. data1 ends with partial prefix.
prefixFlags = new boolean[3];
data1 = Arrays.copyOfRange(data, 0, TEST_PARTIAL_NAL_POSITION + 2);
data2 = Arrays.copyOfRange(data, TEST_PARTIAL_NAL_POSITION + 2, data.length);
result = Mp4Util.findNalUnit(data1, 0, data1.length, prefixFlags);
assertEquals(data1.length, result);
result = Mp4Util.findNalUnit(data2, 0, data2.length, prefixFlags);
assertEquals(4, result);
assertPrefixFlagsCleared(prefixFlags);
}
private static byte[] buildTestData() {
byte[] data = new byte[20];
for (int i = 0; i < data.length; i++) {
data[i] = (byte) 0xFF;
}
// Insert an incomplete NAL unit start code.
data[TEST_PARTIAL_NAL_POSITION] = 0;
data[TEST_PARTIAL_NAL_POSITION + 1] = 0;
// Insert a complete NAL unit start code.
data[TEST_NAL_POSITION] = 0;
data[TEST_NAL_POSITION + 1] = 0;
data[TEST_NAL_POSITION + 2] = 1;
data[TEST_NAL_POSITION + 3] = 5;
return data;
}
private static void assertPrefixFlagsCleared(boolean[] flags) {
assertEquals(false, flags[0] || flags[1] || flags[2]);
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.testutil;
import java.util.Random;
/**
* Utility methods for tests.
*/
public class Util {
private Util() {}
public static byte[] buildTestData(int length) {
return buildTestData(length, length);
}
public static byte[] buildTestData(int length, int seed) {
Random random = new Random(seed);
byte[] source = new byte[length];
random.nextBytes(source);
return source;
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.text.webvtt;
import com.google.android.exoplayer.C;
import android.test.InstrumentationTestCase;
import java.io.IOException;
import java.io.InputStream;
/**
* Unit test for {@link WebvttParser}.
*/
public class WebvttParserTest extends InstrumentationTestCase {
private static final String TYPICAL_WEBVTT_FILE = "webvtt/typical";
private static final String TYPICAL_WITH_IDS_WEBVTT_FILE = "webvtt/typical_with_identifiers";
private static final String TYPICAL_WITH_TAGS_WEBVTT_FILE = "webvtt/typical_with_tags";
private static final String EMPTY_WEBVTT_FILE = "webvtt/empty";
public void testParseNullWebvttFile() throws IOException {
WebvttParser parser = new WebvttParser();
InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets().open(EMPTY_WEBVTT_FILE);
try {
parser.parse(inputStream, C.UTF8_NAME, 0);
fail("Expected IOException");
} catch (IOException expected) {
// Do nothing.
}
}
public void testParseTypicalWebvttFile() throws IOException {
WebvttParser parser = new WebvttParser();
InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets().open(TYPICAL_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME, 0);
// test start time and event count
long startTimeUs = 5000000;
assertEquals(startTimeUs, subtitle.getStartTime());
assertEquals(4, subtitle.getEventTimeCount());
// test first cue
assertEquals(startTimeUs, subtitle.getEventTime(0));
assertEquals("This is the first subtitle.",
subtitle.getText(subtitle.getEventTime(0)));
assertEquals(startTimeUs + 1234000, subtitle.getEventTime(1));
// test second cue
assertEquals(startTimeUs + 2345000, subtitle.getEventTime(2));
assertEquals("This is the second subtitle.",
subtitle.getText(subtitle.getEventTime(2)));
assertEquals(startTimeUs + 3456000, subtitle.getEventTime(3));
}
public void testParseTypicalWithIdsWebvttFile() throws IOException {
WebvttParser parser = new WebvttParser();
InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets()
.open(TYPICAL_WITH_IDS_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME, 0);
// test start time and event count
long startTimeUs = 5000000;
assertEquals(startTimeUs, subtitle.getStartTime());
assertEquals(4, subtitle.getEventTimeCount());
// test first cue
assertEquals(startTimeUs, subtitle.getEventTime(0));
assertEquals("This is the first subtitle.",
subtitle.getText(subtitle.getEventTime(0)));
assertEquals(startTimeUs + 1234000, subtitle.getEventTime(1));
// test second cue
assertEquals(startTimeUs + 2345000, subtitle.getEventTime(2));
assertEquals("This is the second subtitle.",
subtitle.getText(subtitle.getEventTime(2)));
assertEquals(startTimeUs + 3456000, subtitle.getEventTime(3));
}
public void testParseTypicalWithTagsWebvttFile() throws IOException {
WebvttParser parser = new WebvttParser();
InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets()
.open(TYPICAL_WITH_TAGS_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME, 0);
// test start time and event count
long startTimeUs = 5000000;
assertEquals(startTimeUs, subtitle.getStartTime());
assertEquals(8, subtitle.getEventTimeCount());
// test first cue
assertEquals(startTimeUs, subtitle.getEventTime(0));
assertEquals("This is the first subtitle.",
subtitle.getText(subtitle.getEventTime(0)));
assertEquals(startTimeUs + 1234000, subtitle.getEventTime(1));
// test second cue
assertEquals(startTimeUs + 2345000, subtitle.getEventTime(2));
assertEquals("This is the second subtitle.",
subtitle.getText(subtitle.getEventTime(2)));
assertEquals(startTimeUs + 3456000, subtitle.getEventTime(3));
// test third cue
assertEquals(startTimeUs + 4000000, subtitle.getEventTime(4));
assertEquals("This is the third subtitle.",
subtitle.getText(subtitle.getEventTime(4)));
assertEquals(startTimeUs + 5000000, subtitle.getEventTime(5));
// test fourth cue
assertEquals(startTimeUs + 6000000, subtitle.getEventTime(6));
assertEquals("This is the <fourth> &subtitle.",
subtitle.getText(subtitle.getEventTime(6)));
assertEquals(startTimeUs + 7000000, subtitle.getEventTime(7));
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.text.webvtt;
import junit.framework.TestCase;
/**
* Unit test for {@link WebvttSubtitle}.
*/
public class WebvttSubtitleTest extends TestCase {
private static final String FIRST_SUBTITLE_STRING = "This is the first subtitle.";
private static final String SECOND_SUBTITLE_STRING = "This is the second subtitle.";
private static final String FIRST_AND_SECOND_SUBTITLE_STRING =
FIRST_SUBTITLE_STRING + SECOND_SUBTITLE_STRING;
private WebvttSubtitle emptySubtitle = new WebvttSubtitle(new String[] {}, 0, new long[] {});
private WebvttSubtitle simpleSubtitle = new WebvttSubtitle(
new String[] {FIRST_SUBTITLE_STRING, SECOND_SUBTITLE_STRING}, 0,
new long[] {1000000, 2000000, 3000000, 4000000});
private WebvttSubtitle overlappingSubtitle = new WebvttSubtitle(
new String[] {FIRST_SUBTITLE_STRING, SECOND_SUBTITLE_STRING}, 0,
new long[] {1000000, 3000000, 2000000, 4000000});
private WebvttSubtitle nestedSubtitle = new WebvttSubtitle(
new String[] {FIRST_SUBTITLE_STRING, SECOND_SUBTITLE_STRING}, 0,
new long[] {1000000, 4000000, 2000000, 3000000});
public void testEventCount() {
assertEquals(0, emptySubtitle.getEventTimeCount());
assertEquals(4, simpleSubtitle.getEventTimeCount());
assertEquals(4, overlappingSubtitle.getEventTimeCount());
assertEquals(4, nestedSubtitle.getEventTimeCount());
}
public void testStartTime() {
assertEquals(0, emptySubtitle.getStartTime());
assertEquals(0, simpleSubtitle.getStartTime());
assertEquals(0, overlappingSubtitle.getStartTime());
assertEquals(0, nestedSubtitle.getStartTime());
}
public void testLastEventTime() {
assertEquals(-1, emptySubtitle.getLastEventTime());
assertEquals(4000000, simpleSubtitle.getLastEventTime());
assertEquals(4000000, overlappingSubtitle.getLastEventTime());
assertEquals(4000000, nestedSubtitle.getLastEventTime());
}
public void testSimpleSubtitleEventTimes() {
testSubtitleEventTimesHelper(simpleSubtitle);
}
public void testSimpleSubtitleEventIndices() {
testSubtitleEventIndicesHelper(simpleSubtitle);
}
public void testSimpleSubtitleText() {
// Test before first subtitle
assertNull(simpleSubtitle.getText(0));
assertNull(simpleSubtitle.getText(500000));
assertNull(simpleSubtitle.getText(999999));
// Test first subtitle
assertEquals(FIRST_SUBTITLE_STRING, simpleSubtitle.getText(1000000));
assertEquals(FIRST_SUBTITLE_STRING, simpleSubtitle.getText(1500000));
assertEquals(FIRST_SUBTITLE_STRING, simpleSubtitle.getText(1999999));
// Test after first subtitle, before second subtitle
assertNull(simpleSubtitle.getText(2000000));
assertNull(simpleSubtitle.getText(2500000));
assertNull(simpleSubtitle.getText(2999999));
// Test second subtitle
assertEquals(SECOND_SUBTITLE_STRING, simpleSubtitle.getText(3000000));
assertEquals(SECOND_SUBTITLE_STRING, simpleSubtitle.getText(3500000));
assertEquals(SECOND_SUBTITLE_STRING, simpleSubtitle.getText(3999999));
// Test after second subtitle
assertNull(simpleSubtitle.getText(4000000));
assertNull(simpleSubtitle.getText(4500000));
assertNull(simpleSubtitle.getText(Long.MAX_VALUE));
}
public void testOverlappingSubtitleEventTimes() {
testSubtitleEventTimesHelper(overlappingSubtitle);
}
public void testOverlappingSubtitleEventIndices() {
testSubtitleEventIndicesHelper(overlappingSubtitle);
}
public void testOverlappingSubtitleText() {
// Test before first subtitle
assertNull(overlappingSubtitle.getText(0));
assertNull(overlappingSubtitle.getText(500000));
assertNull(overlappingSubtitle.getText(999999));
// Test first subtitle
assertEquals(FIRST_SUBTITLE_STRING, overlappingSubtitle.getText(1000000));
assertEquals(FIRST_SUBTITLE_STRING, overlappingSubtitle.getText(1500000));
assertEquals(FIRST_SUBTITLE_STRING, overlappingSubtitle.getText(1999999));
// Test after first and second subtitle
assertEquals(FIRST_AND_SECOND_SUBTITLE_STRING, overlappingSubtitle.getText(2000000));
assertEquals(FIRST_AND_SECOND_SUBTITLE_STRING, overlappingSubtitle.getText(2500000));
assertEquals(FIRST_AND_SECOND_SUBTITLE_STRING, overlappingSubtitle.getText(2999999));
// Test second subtitle
assertEquals(SECOND_SUBTITLE_STRING, overlappingSubtitle.getText(3000000));
assertEquals(SECOND_SUBTITLE_STRING, overlappingSubtitle.getText(3500000));
assertEquals(SECOND_SUBTITLE_STRING, overlappingSubtitle.getText(3999999));
// Test after second subtitle
assertNull(overlappingSubtitle.getText(4000000));
assertNull(overlappingSubtitle.getText(4500000));
assertNull(overlappingSubtitle.getText(Long.MAX_VALUE));
}
public void testNestedSubtitleEventTimes() {
testSubtitleEventTimesHelper(nestedSubtitle);
}
public void testNestedSubtitleEventIndices() {
testSubtitleEventIndicesHelper(nestedSubtitle);
}
public void testNestedSubtitleText() {
// Test before first subtitle
assertNull(nestedSubtitle.getText(0));
assertNull(nestedSubtitle.getText(500000));
assertNull(nestedSubtitle.getText(999999));
// Test first subtitle
assertEquals(FIRST_SUBTITLE_STRING, nestedSubtitle.getText(1000000));
assertEquals(FIRST_SUBTITLE_STRING, nestedSubtitle.getText(1500000));
assertEquals(FIRST_SUBTITLE_STRING, nestedSubtitle.getText(1999999));
// Test after first and second subtitle
assertEquals(FIRST_AND_SECOND_SUBTITLE_STRING, nestedSubtitle.getText(2000000));
assertEquals(FIRST_AND_SECOND_SUBTITLE_STRING, nestedSubtitle.getText(2500000));
assertEquals(FIRST_AND_SECOND_SUBTITLE_STRING, nestedSubtitle.getText(2999999));
// Test first subtitle
assertEquals(FIRST_SUBTITLE_STRING, nestedSubtitle.getText(3000000));
assertEquals(FIRST_SUBTITLE_STRING, nestedSubtitle.getText(3500000));
assertEquals(FIRST_SUBTITLE_STRING, nestedSubtitle.getText(3999999));
// Test after second subtitle
assertNull(nestedSubtitle.getText(4000000));
assertNull(nestedSubtitle.getText(4500000));
assertNull(nestedSubtitle.getText(Long.MAX_VALUE));
}
private void testSubtitleEventTimesHelper(WebvttSubtitle subtitle) {
assertEquals(1000000, subtitle.getEventTime(0));
assertEquals(2000000, subtitle.getEventTime(1));
assertEquals(3000000, subtitle.getEventTime(2));
assertEquals(4000000, subtitle.getEventTime(3));
}
private void testSubtitleEventIndicesHelper(WebvttSubtitle subtitle) {
// Test first event
assertEquals(0, subtitle.getNextEventTimeIndex(0));
assertEquals(0, subtitle.getNextEventTimeIndex(500000));
assertEquals(0, subtitle.getNextEventTimeIndex(999999));
// Test second event
assertEquals(1, subtitle.getNextEventTimeIndex(1000000));
assertEquals(1, subtitle.getNextEventTimeIndex(1500000));
assertEquals(1, subtitle.getNextEventTimeIndex(1999999));
// Test third event
assertEquals(2, subtitle.getNextEventTimeIndex(2000000));
assertEquals(2, subtitle.getNextEventTimeIndex(2500000));
assertEquals(2, subtitle.getNextEventTimeIndex(2999999));
// Test fourth event
assertEquals(3, subtitle.getNextEventTimeIndex(3000000));
assertEquals(3, subtitle.getNextEventTimeIndex(3500000));
assertEquals(3, subtitle.getNextEventTimeIndex(3999999));
// Test null event (i.e. look for events after the last event)
assertEquals(-1, subtitle.getNextEventTimeIndex(4000000));
assertEquals(-1, subtitle.getNextEventTimeIndex(4500000));
assertEquals(-1, subtitle.getNextEventTimeIndex(Long.MAX_VALUE));
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.upstream;
import com.google.android.exoplayer.C;
import junit.framework.TestCase;
import java.io.IOException;
/**
* Unit tests for {@link ByteArrayDataSource}.
*/
public class ByteArrayDataSourceTest extends TestCase {
private static final byte[] TEST_DATA = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
private static final byte[] TEST_DATA_ODD = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
public void testFullReadSingleBytes() {
readTestData(TEST_DATA, 0, C.LENGTH_UNBOUNDED, 1, 0, 1, false);
}
public void testFullReadAllBytes() {
readTestData(TEST_DATA, 0, C.LENGTH_UNBOUNDED, 100, 0, 100, false);
}
public void testLimitReadSingleBytes() {
// Limit set to the length of the data.
readTestData(TEST_DATA, 0, TEST_DATA.length, 1, 0, 1, false);
// And less.
readTestData(TEST_DATA, 0, 6, 1, 0, 1, false);
}
public void testFullReadTwoBytes() {
// Try with the total data length an exact multiple of the size of each individual read.
readTestData(TEST_DATA, 0, C.LENGTH_UNBOUNDED, 2, 0, 2, false);
// And not.
readTestData(TEST_DATA_ODD, 0, C.LENGTH_UNBOUNDED, 2, 0, 2, false);
}
public void testLimitReadTwoBytes() {
// Try with the limit an exact multiple of the size of each individual read.
readTestData(TEST_DATA, 0, 6, 2, 0, 2, false);
// And not.
readTestData(TEST_DATA, 0, 7, 2, 0, 2, false);
}
public void testReadFromValidOffsets() {
// Read from an offset without bound.
readTestData(TEST_DATA, 1, C.LENGTH_UNBOUNDED, 1, 0, 1, false);
// And with bound.
readTestData(TEST_DATA, 1, 6, 1, 0, 1, false);
// Read from the last possible offset without bound.
readTestData(TEST_DATA, TEST_DATA.length - 1, C.LENGTH_UNBOUNDED, 1, 0, 1, false);
// And with bound.
readTestData(TEST_DATA, TEST_DATA.length - 1, 1, 1, 0, 1, false);
}
public void testReadFromInvalidOffsets() {
// Read from first invalid offset and check failure without bound.
readTestData(TEST_DATA, TEST_DATA.length, C.LENGTH_UNBOUNDED, 1, 0, 1, true);
// And with bound.
readTestData(TEST_DATA, TEST_DATA.length, 1, 1, 0, 1, true);
}
public void testReadWithInvalidLength() {
// Read more data than is available.
readTestData(TEST_DATA, 0, TEST_DATA.length + 1, 1, 0, 1, true);
// And with bound.
readTestData(TEST_DATA, 1, TEST_DATA.length, 1, 0, 1, true);
}
/**
* Tests reading from a {@link ByteArrayDataSource} with various parameters.
*
* @param testData The data that the {@link ByteArrayDataSource} will wrap.
* @param dataOffset The offset from which to read data.
* @param dataLength The total length of data to read.
* @param outputBufferLength The length of the target buffer for each read.
* @param writeOffset The offset into {@code outputBufferLength} for each read.
* @param maxReadLength The maximum length of each read.
* @param expectFailOnOpen Whether it is expected that opening the source will fail.
*/
private void readTestData(byte[] testData, int dataOffset, int dataLength, int outputBufferLength,
int writeOffset, int maxReadLength, boolean expectFailOnOpen) {
int expectedFinalBytesRead =
dataLength == C.LENGTH_UNBOUNDED ? (testData.length - dataOffset) : dataLength;
ByteArrayDataSource dataSource = new ByteArrayDataSource(testData);
boolean opened = false;
try {
// Open the source.
long length = dataSource.open(new DataSpec(null, dataOffset, dataLength, null));
opened = true;
assertFalse(expectFailOnOpen);
// Verify the resolved length is as we expect.
assertEquals(expectedFinalBytesRead, length);
byte[] outputBuffer = new byte[outputBufferLength];
int accumulatedBytesRead = 0;
while (true) {
// Calculate a valid length for the next read, constraining by the specified output buffer
// length, write offset and maximum write length input parameters.
int requestedReadLength = Math.min(maxReadLength, outputBufferLength - writeOffset);
assertTrue(requestedReadLength > 0);
int bytesRead = dataSource.read(outputBuffer, writeOffset, requestedReadLength);
if (bytesRead != -1) {
assertTrue(bytesRead > 0);
assertTrue(bytesRead <= requestedReadLength);
// Check the data read was correct.
for (int i = 0; i < bytesRead; i++) {
assertEquals(testData[dataOffset + accumulatedBytesRead + i],
outputBuffer[writeOffset + i]);
}
// Check that we haven't read more data than we were expecting.
accumulatedBytesRead += bytesRead;
assertTrue(accumulatedBytesRead <= expectedFinalBytesRead);
// If we haven't read all of the bytes the request should have been satisfied in full.
assertTrue(accumulatedBytesRead == expectedFinalBytesRead
|| bytesRead == requestedReadLength);
} else {
// We're done. Check we read the expected number of bytes.
assertEquals(expectedFinalBytesRead, accumulatedBytesRead);
return;
}
}
} catch (IOException e) {
if (expectFailOnOpen && !opened) {
// Expected.
return;
}
// Unexpected failure.
fail();
}
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.upstream;
import com.google.android.exoplayer.testutil.Util;
import junit.framework.TestCase;
import java.io.IOException;
import java.util.Arrays;
/**
* Unit tests for {@link DataSourceStream}.
*/
public class DataSourceStreamTest extends TestCase {
private static final int DATA_LENGTH = 1024;
private static final int BUFFER_LENGTH = 128;
public void testGetLoadedData() throws IOException, InterruptedException {
byte[] testData = Util.buildTestData(DATA_LENGTH);
DataSource dataSource = new ByteArrayDataSource(testData);
DataSpec dataSpec = new DataSpec(null, 0, DATA_LENGTH, null);
DataSourceStream dataSourceStream = new DataSourceStream(dataSource, dataSpec,
new BufferPool(BUFFER_LENGTH));
dataSourceStream.load();
// Assert that the read and load positions are correct.
assertEquals(0, dataSourceStream.getReadPosition());
assertEquals(testData.length, dataSourceStream.getLoadPosition());
int halfTestDataLength = testData.length / 2;
byte[] readData = new byte[testData.length];
int bytesRead = dataSourceStream.read(readData, 0, halfTestDataLength);
// Assert that the read position is updated correctly.
assertEquals(halfTestDataLength, bytesRead);
assertEquals(halfTestDataLength, dataSourceStream.getReadPosition());
bytesRead += dataSourceStream.read(readData, bytesRead, testData.length - bytesRead);
// Assert that the read position was updated correctly.
assertEquals(testData.length, bytesRead);
assertEquals(testData.length, dataSourceStream.getReadPosition());
// Assert that the data read using the two read calls either side of getLoadedData is correct.
assertTrue(Arrays.equals(testData, readData));
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.util;
import junit.framework.TestCase;
import java.util.Arrays;
/**
* Tests for {@link ParsableByteArray}.
*/
public class ParsableByteArrayTest extends TestCase {
private static final byte[] ARRAY_ELEMENTS =
new byte[] {0x0F, (byte) 0xFF, (byte) 0x42, (byte) 0x0F, 0x00, 0x00, 0x00, 0x00};
private ParsableByteArray parsableByteArray;
@Override
public void setUp() {
parsableByteArray = new ParsableByteArray(ARRAY_ELEMENTS.length);
System.arraycopy(ARRAY_ELEMENTS, 0, parsableByteArray.data, 0, ARRAY_ELEMENTS.length);
}
public void testReadInt() {
// When reading a signed integer
int value = parsableByteArray.readInt();
// Then the read value is equal to the array elements interpreted as an int.
assertEquals((0xFF & ARRAY_ELEMENTS[0]) << 24 | (0xFF & ARRAY_ELEMENTS[1]) << 16
| (0xFF & ARRAY_ELEMENTS[2]) << 8 | (0xFF & ARRAY_ELEMENTS[3]), value);
}
public void testSkipBack() {
// When reading an unsigned integer
long value = parsableByteArray.readUnsignedInt();
// Then skipping back and reading gives the same value.
parsableByteArray.skip(-4);
assertEquals(value, parsableByteArray.readUnsignedInt());
}
public void testReadingMovesPosition() {
// Given an array at the start
assertEquals(0, parsableByteArray.getPosition());
// When reading an integer, the position advances
parsableByteArray.readUnsignedInt();
assertEquals(4, parsableByteArray.getPosition());
}
public void testOutOfBoundsThrows() {
// Given an array at the end
parsableByteArray.readUnsignedLongToLong();
assertEquals(ARRAY_ELEMENTS.length, parsableByteArray.getPosition());
// Then reading more data throws.
try {
parsableByteArray.readUnsignedInt();
fail();
} catch (Exception e) {
// Expected.
}
}
public void testModificationsAffectParsableArray() {
// When modifying the wrapped byte array
byte[] data = parsableByteArray.data;
long readValue = parsableByteArray.readUnsignedInt();
data[0] = (byte) (ARRAY_ELEMENTS[0] + 1);
parsableByteArray.setPosition(0);
// Then the parsed value changes.
assertFalse(parsableByteArray.readUnsignedInt() == readValue);
}
public void testReadingUnsignedLongWithMsbSetThrows() {
// Given an array with the most-significant bit set on the top byte
byte[] data = parsableByteArray.data;
data[0] = (byte) 0x80;
// Then reading an unsigned long throws.
try {
parsableByteArray.readUnsignedLongToLong();
fail();
} catch (Exception e) {
// Expected.
}
}
public void testReadUnsignedFixedPoint1616() {
// When reading the integer part of a 16.16 fixed point value
int value = parsableByteArray.readUnsignedFixedPoint1616();
// Then the read value is equal to the array elements interpreted as a short.
assertEquals((0xFF & ARRAY_ELEMENTS[0]) << 8 | (ARRAY_ELEMENTS[1] & 0xFF), value);
assertEquals(4, parsableByteArray.getPosition());
}
public void testReadingBytesReturnsCopy() {
// When reading all the bytes back
int length = parsableByteArray.limit();
assertEquals(ARRAY_ELEMENTS.length, length);
byte[] copy = new byte[length];
parsableByteArray.readBytes(copy, 0, length);
// Then the array elements are the same.
assertTrue(Arrays.equals(parsableByteArray.data, copy));
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.util;
import junit.framework.TestCase;
/**
* Unit tests for {@link UriUtil}.
*/
public class UriUtilTest extends TestCase {
/**
* Tests normal usage of {@link UriUtil#resolve(String, String)}.
* <p>
* The test cases are taken from RFC-3986 5.4.1.
*/
public void testResolveNormal() {
String base = "http://a/b/c/d;p?q";
assertEquals("g:h", UriUtil.resolve(base, "g:h"));
assertEquals("http://a/b/c/g", UriUtil.resolve(base, "g"));
assertEquals("http://a/b/c/g/", UriUtil.resolve(base, "g/"));
assertEquals("http://a/g", UriUtil.resolve(base, "/g"));
assertEquals("http://g", UriUtil.resolve(base, "//g"));
assertEquals("http://a/b/c/d;p?y", UriUtil.resolve(base, "?y"));
assertEquals("http://a/b/c/g?y", UriUtil.resolve(base, "g?y"));
assertEquals("http://a/b/c/d;p?q#s", UriUtil.resolve(base, "#s"));
assertEquals("http://a/b/c/g#s", UriUtil.resolve(base, "g#s"));
assertEquals("http://a/b/c/g?y#s", UriUtil.resolve(base, "g?y#s"));
assertEquals("http://a/b/c/;x", UriUtil.resolve(base, ";x"));
assertEquals("http://a/b/c/g;x", UriUtil.resolve(base, "g;x"));
assertEquals("http://a/b/c/g;x?y#s", UriUtil.resolve(base, "g;x?y#s"));
assertEquals("http://a/b/c/d;p?q", UriUtil.resolve(base, ""));
assertEquals("http://a/b/c/", UriUtil.resolve(base, "."));
assertEquals("http://a/b/c/", UriUtil.resolve(base, "./"));
assertEquals("http://a/b/", UriUtil.resolve(base, ".."));
assertEquals("http://a/b/", UriUtil.resolve(base, "../"));
assertEquals("http://a/b/g", UriUtil.resolve(base, "../g"));
assertEquals("http://a/", UriUtil.resolve(base, "../.."));
assertEquals("http://a/", UriUtil.resolve(base, "../../"));
assertEquals("http://a/g", UriUtil.resolve(base, "../../g"));
}
/**
* Tests abnormal usage of {@link UriUtil#resolve(String, String)}.
* <p>
* The test cases are taken from RFC-3986 5.4.2.
*/
public void testResolveAbnormal() {
String base = "http://a/b/c/d;p?q";
assertEquals("http://a/g", UriUtil.resolve(base, "../../../g"));
assertEquals("http://a/g", UriUtil.resolve(base, "../../../../g"));
assertEquals("http://a/g", UriUtil.resolve(base, "/./g"));
assertEquals("http://a/g", UriUtil.resolve(base, "/../g"));
assertEquals("http://a/b/c/g.", UriUtil.resolve(base, "g."));
assertEquals("http://a/b/c/.g", UriUtil.resolve(base, ".g"));
assertEquals("http://a/b/c/g..", UriUtil.resolve(base, "g.."));
assertEquals("http://a/b/c/..g", UriUtil.resolve(base, "..g"));
assertEquals("http://a/b/g", UriUtil.resolve(base, "./../g"));
assertEquals("http://a/b/c/g/", UriUtil.resolve(base, "./g/."));
assertEquals("http://a/b/c/g/h", UriUtil.resolve(base, "g/./h"));
assertEquals("http://a/b/c/h", UriUtil.resolve(base, "g/../h"));
assertEquals("http://a/b/c/g;x=1/y", UriUtil.resolve(base, "g;x=1/./y"));
assertEquals("http://a/b/c/y", UriUtil.resolve(base, "g;x=1/../y"));
assertEquals("http://a/b/c/g?y/./x", UriUtil.resolve(base, "g?y/./x"));
assertEquals("http://a/b/c/g?y/../x", UriUtil.resolve(base, "g?y/../x"));
assertEquals("http://a/b/c/g#s/./x", UriUtil.resolve(base, "g#s/./x"));
assertEquals("http://a/b/c/g#s/../x", UriUtil.resolve(base, "g#s/../x"));
assertEquals("http:g", UriUtil.resolve(base, "http:g"));
}
/**
* Tests additional abnormal usage of {@link UriUtil#resolve(String, String)}.
*/
public void testResolveAbnormalAdditional() {
assertEquals("c:e", UriUtil.resolve("http://a/b", "c:d/../e"));
assertEquals("a:c", UriUtil.resolve("a:b", "../c"));
}
}
/*
* Copyright (C) 2014 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.google.android.exoplayer.util;
import junit.framework.TestCase;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
/**
* Unit tests for {@link Util}.
*/
public class UtilTest extends TestCase {
public void testArrayBinarySearchFloor() {
long[] values = new long[0];
assertEquals(-1, Util.binarySearchFloor(values, 0, false, false));
assertEquals(0, Util.binarySearchFloor(values, 0, false, true));
values = new long[] {1, 3, 5};
assertEquals(-1, Util.binarySearchFloor(values, 0, false, false));
assertEquals(-1, Util.binarySearchFloor(values, 0, true, false));
assertEquals(0, Util.binarySearchFloor(values, 0, false, true));
assertEquals(0, Util.binarySearchFloor(values, 0, true, true));
assertEquals(-1, Util.binarySearchFloor(values, 1, false, false));
assertEquals(0, Util.binarySearchFloor(values, 1, true, false));
assertEquals(0, Util.binarySearchFloor(values, 1, false, true));
assertEquals(0, Util.binarySearchFloor(values, 1, true, true));
assertEquals(1, Util.binarySearchFloor(values, 4, false, false));
assertEquals(1, Util.binarySearchFloor(values, 4, true, false));
assertEquals(1, Util.binarySearchFloor(values, 5, false, false));
assertEquals(2, Util.binarySearchFloor(values, 5, true, false));
assertEquals(2, Util.binarySearchFloor(values, 6, false, false));
assertEquals(2, Util.binarySearchFloor(values, 6, true, false));
}
public void testListBinarySearchFloor() {
List<Integer> values = new ArrayList<Integer>();
assertEquals(-1, Util.binarySearchFloor(values, 0, false, false));
assertEquals(0, Util.binarySearchFloor(values, 0, false, true));
values.add(1);
values.add(3);
values.add(5);
assertEquals(-1, Util.binarySearchFloor(values, 0, false, false));
assertEquals(-1, Util.binarySearchFloor(values, 0, true, false));
assertEquals(0, Util.binarySearchFloor(values, 0, false, true));
assertEquals(0, Util.binarySearchFloor(values, 0, true, true));
assertEquals(-1, Util.binarySearchFloor(values, 1, false, false));
assertEquals(0, Util.binarySearchFloor(values, 1, true, false));
assertEquals(0, Util.binarySearchFloor(values, 1, false, true));
assertEquals(0, Util.binarySearchFloor(values, 1, true, true));
assertEquals(1, Util.binarySearchFloor(values, 4, false, false));
assertEquals(1, Util.binarySearchFloor(values, 4, true, false));
assertEquals(1, Util.binarySearchFloor(values, 5, false, false));
assertEquals(2, Util.binarySearchFloor(values, 5, true, false));
assertEquals(2, Util.binarySearchFloor(values, 6, false, false));
assertEquals(2, Util.binarySearchFloor(values, 6, true, false));
}
public void testArrayBinarySearchCeil() {
long[] values = new long[0];
assertEquals(0, Util.binarySearchCeil(values, 0, false, false));
assertEquals(-1, Util.binarySearchCeil(values, 0, false, true));
values = new long[] {1, 3, 5};
assertEquals(0, Util.binarySearchCeil(values, 0, false, false));
assertEquals(0, Util.binarySearchCeil(values, 0, true, false));
assertEquals(1, Util.binarySearchCeil(values, 1, false, false));
assertEquals(0, Util.binarySearchCeil(values, 1, true, false));
assertEquals(1, Util.binarySearchCeil(values, 2, false, false));
assertEquals(1, Util.binarySearchCeil(values, 2, true, false));
assertEquals(3, Util.binarySearchCeil(values, 5, false, false));
assertEquals(2, Util.binarySearchCeil(values, 5, true, false));
assertEquals(2, Util.binarySearchCeil(values, 5, false, true));
assertEquals(2, Util.binarySearchCeil(values, 5, true, true));
assertEquals(3, Util.binarySearchCeil(values, 6, false, false));
assertEquals(3, Util.binarySearchCeil(values, 6, true, false));
assertEquals(2, Util.binarySearchCeil(values, 6, false, true));
assertEquals(2, Util.binarySearchCeil(values, 6, true, true));
}
public void testListBinarySearchCeil() {
List<Integer> values = new ArrayList<Integer>();
assertEquals(0, Util.binarySearchCeil(values, 0, false, false));
assertEquals(-1, Util.binarySearchCeil(values, 0, false, true));
values.add(1);
values.add(3);
values.add(5);
assertEquals(0, Util.binarySearchCeil(values, 0, false, false));
assertEquals(0, Util.binarySearchCeil(values, 0, true, false));
assertEquals(1, Util.binarySearchCeil(values, 1, false, false));
assertEquals(0, Util.binarySearchCeil(values, 1, true, false));
assertEquals(1, Util.binarySearchCeil(values, 2, false, false));
assertEquals(1, Util.binarySearchCeil(values, 2, true, false));
assertEquals(3, Util.binarySearchCeil(values, 5, false, false));
assertEquals(2, Util.binarySearchCeil(values, 5, true, false));
assertEquals(2, Util.binarySearchCeil(values, 5, false, true));
assertEquals(2, Util.binarySearchCeil(values, 5, true, true));
assertEquals(3, Util.binarySearchCeil(values, 6, false, false));
assertEquals(3, Util.binarySearchCeil(values, 6, true, false));
assertEquals(2, Util.binarySearchCeil(values, 6, false, true));
assertEquals(2, Util.binarySearchCeil(values, 6, true, true));
}
public void testParseXsDuration() {
assertEquals(150279L, Util.parseXsDuration("PT150.279S"));
assertEquals(1500L, Util.parseXsDuration("PT1.500S"));
}
public void testParseXsDateTime() throws ParseException {
assertEquals(1403219262000L, Util.parseXsDateTime("2014-06-19T23:07:42"));
assertEquals(1407322800000L, Util.parseXsDateTime("2014-08-06T11:00:00Z"));
}
}
This file is needed to make sure the libs directory is present.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-21
This file is needed to make sure the res directory is present.
The file is ignored by the Android toolchain because its name starts with a dot.
No preview for this file type
The MIT License
Copyright (c) 2008-2010 Mockito contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment