@@ -9,6 +9,7 @@ import com.looker.sync.fdroid.common.Izzy
9
9
import com.looker.sync.fdroid.common.JsonParser
10
10
import com.looker.sync.fdroid.common.downloadIndex
11
11
import com.looker.sync.fdroid.common.memory
12
+ import com.looker.sync.fdroid.common.toV2
12
13
import com.looker.sync.fdroid.v1.V1Parser
13
14
import com.looker.sync.fdroid.v1.V1Syncable
14
15
import com.looker.sync.fdroid.v1.model.IndexV1
@@ -22,12 +23,12 @@ import kotlinx.coroutines.test.StandardTestDispatcher
22
23
import kotlinx.coroutines.test.runTest
23
24
import org.junit.Before
24
25
import org.junit.runner.RunWith
26
+ import kotlin.math.exp
25
27
import kotlin.system.measureTimeMillis
26
28
import kotlin.test.Test
27
29
import kotlin.test.assertContentEquals
28
30
import kotlin.test.assertEquals
29
31
import kotlin.test.assertNotNull
30
- import kotlin.test.assertTrue
31
32
32
33
@RunWith(AndroidJUnit4 ::class )
33
34
class V1SyncableTest {
@@ -82,9 +83,24 @@ class V1SyncableTest {
82
83
83
84
@Test
84
85
fun v1tov2 () = runTest(dispatcher) {
85
- val fileV2 = FakeDownloader .downloadIndex(context, repo, " data" , " index-v2-updated.json" )
86
- val (fingerV1, foundIndex) = syncable.sync(repo)
86
+ testIndexConversion(" index-v1.jar" , " index-v2-updated.json" )
87
+ }
88
+
89
+ @Test
90
+ fun v1tov2FDroidRepo () = runTest(dispatcher) {
91
+ testIndexConversion(" fdroid-index-v1.json" , " fdroid-index-v2.json" , " com.looker.droidify" )
92
+ }
93
+
94
+ private suspend fun testIndexConversion (
95
+ v1 : String ,
96
+ v2 : String ,
97
+ targeted : String? = null,
98
+ ) {
99
+ val fileV1 = FakeDownloader .downloadIndex(context, repo, " data-v1" , v1)
100
+ val fileV2 = FakeDownloader .downloadIndex(context, repo, " data-v2" , v2)
101
+ val (fingerV1, foundIndexV1) = parser.parse(fileV1, repo)
87
102
val (fingerV2, expectedIndex) = v2Parser.parse(fileV2, repo)
103
+ val foundIndex = foundIndexV1.toV2()
88
104
assertEquals(fingerV2, fingerV1)
89
105
assertNotNull(foundIndex)
90
106
assertNotNull(expectedIndex)
@@ -94,13 +110,31 @@ class V1SyncableTest {
94
110
expectedIndex.packages.keys.sorted(),
95
111
foundIndex.packages.keys.sorted(),
96
112
)
97
- val expectedPackage = expectedIndex.packages[" com.looker.droidify" ]
98
- val foundPackage = foundIndex.packages[" com.looker.droidify" ]
113
+ if (targeted == null ) {
114
+ expectedIndex.packages.keys.forEach { key ->
115
+ val expectedPackage = expectedIndex.packages[key]
116
+ val foundPackage = foundIndex.packages[key]
117
+
118
+ println (" **" .repeat(25 ))
119
+ println (" Testing: ${expectedPackage?.metadata?.name?.get(" en-US" )} <$key >" )
120
+
121
+ assertNotNull(expectedPackage)
122
+ assertNotNull(foundPackage)
123
+ assertMetadata(expectedPackage.metadata, foundPackage.metadata)
124
+ assertVersion(expectedPackage.versions, foundPackage.versions)
125
+ }
126
+ } else {
127
+ val expectedPackage = expectedIndex.packages[targeted]
128
+ val foundPackage = foundIndex.packages[targeted]
99
129
100
- assertNotNull(expectedPackage)
101
- assertNotNull(foundPackage)
102
- assertMetadata(expectedPackage.metadata, foundPackage.metadata)
103
- assertVersion(expectedPackage.versions, foundPackage.versions)
130
+ println (" **" .repeat(25 ))
131
+ println (" Testing: ${expectedPackage?.metadata?.name?.get(" en-US" )} <$targeted >" )
132
+
133
+ assertNotNull(expectedPackage)
134
+ assertNotNull(foundPackage)
135
+ assertMetadata(expectedPackage.metadata, foundPackage.metadata)
136
+ assertVersion(expectedPackage.versions, foundPackage.versions)
137
+ }
104
138
}
105
139
}
106
140
@@ -168,28 +202,32 @@ private fun assertVersion(
168
202
) {
169
203
assertEquals(expected.keys.size, found.keys.size)
170
204
assertContentEquals(expected.keys.sorted(), found.keys.sorted().asIterable())
171
- expected.keys.forEach {
172
- val expected = expected[it ]
173
- val found = found[it ]
174
- assertNotNull(expected )
175
- assertNotNull(found )
176
-
177
- assertEquals(expected .added, found .added)
178
- assertEquals(expected .file.name, found .file.name)
179
- assertEquals(expected .src?.name, found .src?.name)
180
- // We are knowingly adding same whats new to all versions
205
+ expected.keys.forEach { versionHash ->
206
+ val expectedVersion = expected[versionHash ]
207
+ val foundVersion = found[versionHash ]
208
+ assertNotNull(expectedVersion )
209
+ assertNotNull(foundVersion )
210
+
211
+ assertEquals(expectedVersion .added, foundVersion .added)
212
+ assertEquals(expectedVersion .file.name, foundVersion .file.name)
213
+ assertEquals(expectedVersion .src?.name, foundVersion .src?.name)
214
+ // We are knowingly adding same whats new to all versions
181
215
// assertLocalizedString(expected.whatsNew, found.whatsNew)
182
- assertLocalized(
183
- expected.antiFeatures,
184
- found.antiFeatures
185
- ) { antiFeatureExpected, antiFeatureFound ->
186
- assertLocalizedString(antiFeatureExpected, antiFeatureFound)
187
- }
216
+
217
+ // We cannot assure this too, since they started adding version specific anti-features
218
+ // assertLocalized(
219
+ // expected.antiFeatures,
220
+ // found.antiFeatures
221
+ // ) { antiFeatureExpected, antiFeatureFound ->
222
+ // println(antiFeatureExpected)
223
+ // println(antiFeatureFound)
224
+ // assertLocalizedString(antiFeatureExpected, antiFeatureFound)
225
+ // }
188
226
// TODO: fix
189
227
// assertContentEquals(expected.signer?.sha256, found.signer?.sha256)
190
228
191
- val expectedMan = expected .manifest
192
- val foundMan = found .manifest
229
+ val expectedMan = expectedVersion .manifest
230
+ val foundMan = foundVersion .manifest
193
231
194
232
assertEquals(expectedMan.versionCode, foundMan.versionCode)
195
233
assertEquals(expectedMan.versionName, foundMan.versionName)
@@ -221,14 +259,16 @@ private fun <T> assertLocalized(
221
259
found : Map <String , T >? ,
222
260
block : (expected: T , found: T ) -> Unit ,
223
261
) {
224
- if (expected == null && found == null ) return
262
+ if (expected == null || found == null ) {
263
+ assertEquals(expected, found)
264
+ return
265
+ }
225
266
assertNotNull(expected)
226
267
assertNotNull(found)
227
268
assertEquals(expected.size, found.size)
228
269
assertContentEquals(expected.keys.sorted(), found.keys.sorted().asIterable())
229
270
expected.keys.forEach {
230
- assertTrue { expected[it] != null && found[it] != null }
231
- block(expected[it]!! , found[it]!! )
271
+ if (expected[it] != null && found[it] != null ) block(expected[it]!! , found[it]!! )
232
272
}
233
273
}
234
274
0 commit comments