• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 package android.media.tv.cts;
18 
19 import static com.google.common.truth.Truth.assertAbout;
20 
21 import android.annotation.Nullable;
22 import android.media.tv.TvTrackInfo;
23 import android.os.Build;
24 import android.os.Bundle;
25 import android.os.Parcelable;
26 
27 import androidx.annotation.RequiresApi;
28 import androidx.test.ext.truth.os.BundleSubject;
29 import androidx.test.ext.truth.os.ParcelableSubject;
30 
31 import com.google.common.truth.FailureMetadata;
32 import com.google.common.truth.SimpleSubjectBuilder;
33 import com.google.common.truth.Subject;
34 
35 /** Test {@link Subject} for {@link TvTrackInfo}. */
36 public final class TvTrackInfoSubject extends Subject {
37     // TODO(b/153190774): Move to androidx.test.ext.truth
38 
39     @Nullable
40     private final TvTrackInfo actual;
41 
TvTrackInfoSubject(FailureMetadata metadata, @Nullable TvTrackInfo actual)42     private TvTrackInfoSubject(FailureMetadata metadata, @Nullable TvTrackInfo actual) {
43         super(metadata, actual);
44         this.actual = actual;
45     }
46 
assertThat(@ullable TvTrackInfo actual)47     public static TvTrackInfoSubject assertThat(@Nullable TvTrackInfo actual) {
48         return assertAbout(tvTrackInfos()).that(actual);
49     }
50 
tvTrackInfos()51     public static Factory<TvTrackInfoSubject, TvTrackInfo> tvTrackInfos() {
52         return TvTrackInfoSubject::new;
53     }
54 
hasAudioChannelCount(int id)55     public void hasAudioChannelCount(int id) {
56         check("getAudioChannelCount()").that(actual.getAudioChannelCount()).isEqualTo(id);
57     }
58 
hasAudioSampleRate(int rate)59     public void hasAudioSampleRate(int rate) {
60         check("getAudioSampleRate()").that(actual.getAudioSampleRate()).isEqualTo(rate);
61     }
62 
hasContentDescription(int content)63     public void hasContentDescription(int content) {
64         check("describeContents()").that(actual.describeContents()).isEqualTo(content);
65     }
66 
67     @RequiresApi(Build.VERSION_CODES.R)
hasEncoding(String encoding)68     public void hasEncoding(String encoding) {
69         check("getEncoding()").that(actual.getEncoding()).isEqualTo(encoding);
70     }
71 
hasId(String id)72     public void hasId(String id) {
73         check("getId()").that(actual.getId()).isEqualTo(id);
74     }
75 
hasLanguage(String language)76     public void hasLanguage(String language) {
77         check("getLanguage()").that(actual.getLanguage()).isEqualTo(language);
78     }
79 
hasType(int type)80     public void hasType(int type) {
81         check("getType()").that(actual.getType()).isEqualTo(type);
82     }
83 
hasVideoActiveFormatDescription(byte format)84     public void hasVideoActiveFormatDescription(byte format) {
85         check("getVideoActiveFormatDescription()").that(
86                 actual.getVideoActiveFormatDescription()).isEqualTo(format);
87     }
hasVideoHeight(int height)88     public void hasVideoHeight(int height) {
89         check("getVideoHeight()").that(actual.getVideoHeight()).isEqualTo(height);
90     }
91 
hasVideoFrameRate(float rate)92     public void hasVideoFrameRate(float rate) {
93         check("getVideoFrameRate()").that(actual.getVideoFrameRate()).isEqualTo(rate);
94     }
95 
hasVideoPixelAspectRatio(float ratio)96     public void hasVideoPixelAspectRatio(float ratio) {
97         check("getVideoPixelAspectRatio()").that(actual.getVideoPixelAspectRatio()).isEqualTo(
98                 ratio);
99     }
100 
hasVideoWidth(int width)101     public void hasVideoWidth(int width) {
102         check("getVideoWidth()").that(actual.getVideoWidth()).isEqualTo(width);
103     }
104 
105     @RequiresApi(Build.VERSION_CODES.R)
isAudioDescription(boolean enabled)106     public void isAudioDescription(boolean enabled) {
107         check("isAudioDescription()").that(actual.isAudioDescription()).isEqualTo(enabled);
108     }
109 
110     @RequiresApi(Build.VERSION_CODES.R)
isEncrypted(boolean enabled)111     public void isEncrypted(boolean enabled) {
112         check("isEncrypted()").that(actual.isEncrypted()).isEqualTo(enabled);
113     }
114 
115     @RequiresApi(Build.VERSION_CODES.R)
isHardOfHearing(boolean enabled)116     public void isHardOfHearing(boolean enabled) {
117         check("isHardOfHearing()").that(actual.isHardOfHearing()).isEqualTo(enabled);
118     }
119 
120     @RequiresApi(Build.VERSION_CODES.R)
isSpokenSubtitle(boolean enabled)121     public void isSpokenSubtitle(boolean enabled) {
122         check("isSpokenSubtitle()").that(actual.isSpokenSubtitle()).isEqualTo(enabled);
123     }
124 
extra()125     public BundleSubject extra() {
126         SimpleSubjectBuilder<? extends BundleSubject, Bundle> bundleSubjectBuilder = check(
127                 "getExtra()").about(BundleSubject.bundles());
128         return bundleSubjectBuilder.that(actual.getExtra());
129     }
130 
recreatesEqual(Parcelable.Creator<TvTrackInfo> creator)131     public void recreatesEqual(Parcelable.Creator<TvTrackInfo> creator) {
132         SimpleSubjectBuilder<? extends ParcelableSubject, Parcelable> parcelableSubjectBuilder =
133                 check("recreatesEqual()").about(ParcelableSubject.parcelables());
134         parcelableSubjectBuilder.that(actual).recreatesEqual(creator);
135     }
136 }
137