1 /*
<lambda>null2 * Copyright 2024 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 androidx.compose.foundation.content
18
19 import android.content.ClipData
20 import android.os.Build
21 import com.google.common.truth.FailureMetadata
22 import com.google.common.truth.Subject
23 import com.google.common.truth.Truth
24
25 /** Truth extension for ClipData. */
26 internal class ClipDataSubject
27 private constructor(failureMetadata: FailureMetadata?, private val subject: ClipData?) :
28 Subject(failureMetadata, subject) {
29
30 companion object {
31 internal val SUBJECT_FACTORY: Factory<ClipDataSubject?, ClipData?> =
32 Factory { failureMetadata, subject ->
33 ClipDataSubject(failureMetadata, subject)
34 }
35 }
36
37 /**
38 * Checks the equality of two [ClipData]s.
39 *
40 * @param clipData the [ClipData] to be matched.
41 */
42 fun isEqualToClipData(clipData: ClipData, ignoreClipDescription: Boolean = false) {
43 if (subject === clipData) return
44 check("isNotNull()").that(subject).isNotNull()
45 check("getItemCount()").that(subject!!.itemCount).isEqualTo(clipData.itemCount)
46 for (i in 0 until subject.itemCount) {
47 check("getItemAt($i).getUri()")
48 .that(subject.getItemAt(i).uri)
49 .isEqualTo(clipData.getItemAt(i).uri)
50 check("getItemAt($i).getText()")
51 .that(subject.getItemAt(i).text)
52 .isEqualTo(clipData.getItemAt(i).text)
53 check("getItemAt($i).getHtmlText()")
54 .that(subject.getItemAt(i).htmlText)
55 .isEqualTo(clipData.getItemAt(i).htmlText)
56 check("getItemAt($i).getIntent()")
57 .that(subject.getItemAt(i).intent)
58 .isEqualTo(clipData.getItemAt(i).intent)
59 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
60 check("getItemAt($i).getTextLinks()")
61 .that(subject.getItemAt(i).textLinks)
62 .isEqualTo(clipData.getItemAt(i).textLinks)
63 }
64 }
65 if (!ignoreClipDescription) {
66 assertClipDescription(subject.description)
67 .isEqualToClipDescription(clipData.description)
68 }
69 }
70 }
71
assertClipDatanull72 internal fun assertClipData(clipData: ClipData): ClipDataSubject {
73 return Truth.assertAbout(ClipDataSubject.SUBJECT_FACTORY).that(clipData)!!
74 }
75