main branch updated
This commit is contained in:
parent
3d33d3fe49
commit
9a05dc1657
353 changed files with 16802 additions and 2995 deletions
|
|
@ -119,7 +119,8 @@ class SyncedFoldersActivityIT : AbstractIT() {
|
|||
onIdleSync {
|
||||
EspressoIdlingResource.increment()
|
||||
val dialog = sut.buildPowerCheckDialog()
|
||||
dialog.show()
|
||||
sut.showPowerCheckDialog()
|
||||
|
||||
EspressoIdlingResource.decrement()
|
||||
|
||||
val screenShotName = createName(testClassName + "_" + "showPowerCheckDialog", "")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
package com.nextcloud.client.assistant
|
||||
|
||||
import com.nextcloud.client.assistant.repository.AssistantRepository
|
||||
import com.nextcloud.client.assistant.repository.remote.AssistantRemoteRepositoryImpl
|
||||
import com.owncloud.android.AbstractOnServerIT
|
||||
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
|
||||
import com.owncloud.android.lib.resources.status.NextcloudVersion
|
||||
|
|
@ -18,11 +18,11 @@ import org.junit.Test
|
|||
@Suppress("MagicNumber")
|
||||
class AssistantRepositoryTests : AbstractOnServerIT() {
|
||||
|
||||
private var sut: AssistantRepository? = null
|
||||
private var sut: AssistantRemoteRepositoryImpl? = null
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
sut = AssistantRepository(nextcloudClient, capability)
|
||||
sut = AssistantRemoteRepositoryImpl(nextcloudClient, capability)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class TransferManagerConnectionTest {
|
|||
connection.onServiceConnected(componentName, binder)
|
||||
|
||||
// WHEN
|
||||
// is runnign flag accessed
|
||||
// is running flag accessed
|
||||
val isRunning = connection.isRunning
|
||||
|
||||
// THEN
|
||||
|
|
|
|||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.nextcloud.extensions
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.nextcloud.utils.decodeSampledBitmapFromFile
|
||||
import com.nextcloud.utils.extensions.toFile
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.io.OutputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.io.path.deleteRecursively
|
||||
import kotlin.io.path.exists
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
class BitmapDecodeTests {
|
||||
|
||||
private lateinit var tempDir: Path
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
tempDir = Files.createTempDirectory("auto_upload_test_")
|
||||
assertTrue("Temp directory should exist", tempDir.exists())
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
@After
|
||||
fun cleanup() {
|
||||
if (tempDir.exists()) {
|
||||
tempDir.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createTempImageFile(width: Int = 100, height: Int = 100): Path {
|
||||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val imagePath = tempDir.resolve("test_${System.currentTimeMillis()}.jpg")
|
||||
|
||||
Files.newOutputStream(imagePath).use { out: OutputStream ->
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out)
|
||||
}
|
||||
|
||||
assertTrue(imagePath.exists())
|
||||
return imagePath
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToFileWhenPathIsValidShouldReturnExistingFile() {
|
||||
val path = createTempImageFile()
|
||||
val result = path.absolutePathString().toFile()
|
||||
assertNotNull(result)
|
||||
assertTrue(result!!.exists())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToFileWhenPathIsEmptyShouldReturnNull() {
|
||||
val result = "".toFile()
|
||||
assertNull(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToFileWhenFileDoesNotExistShouldReturnNull() {
|
||||
val nonExistentPath = tempDir.resolve("does_not_exist.jpg")
|
||||
val result = nonExistentPath.absolutePathString().toFile()
|
||||
assertNull(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDecodeSampledBitmapFromFileWhenValidPathShouldReturnBitmap() {
|
||||
val path = createTempImageFile(400, 400)
|
||||
val bitmap = decodeSampledBitmapFromFile(path.absolutePathString(), 100, 100)
|
||||
assertNotNull(bitmap)
|
||||
assertTrue(bitmap!!.width <= 400)
|
||||
assertTrue(bitmap.height <= 400)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDecodeSampledBitmapFromFileWhenInvalidPathShouldReturnNull() {
|
||||
val invalidPath = tempDir.resolve("invalid_path.jpg").absolutePathString()
|
||||
val bitmap = decodeSampledBitmapFromFile(invalidPath, 100, 100)
|
||||
assertNull(bitmap)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDecodeSampledBitmapFromFileWhenImageIsLargeShouldDownsampleBitmap() {
|
||||
val path = createTempImageFile(2000, 2000)
|
||||
val bitmap = decodeSampledBitmapFromFile(path.absolutePathString(), 100, 100)
|
||||
assertNotNull(bitmap)
|
||||
assertTrue("Bitmap should be smaller than original", bitmap!!.width < 2000 && bitmap.height < 2000)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDecodeSampledBitmapFromFileWhenImageIsSmallerThanRequestedShouldKeepOriginalSize() {
|
||||
val path = createTempImageFile(100, 100)
|
||||
val bitmap = decodeSampledBitmapFromFile(path.absolutePathString(), 200, 200)
|
||||
assertNotNull(bitmap)
|
||||
assertEquals(100, bitmap!!.width)
|
||||
assertEquals(100, bitmap.height)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.nextcloud.extensions
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.nextcloud.utils.rotateBitmapViaExif
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class BitmapRotationTests {
|
||||
|
||||
private fun createTestBitmap(): Bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888).apply {
|
||||
setPixel(0, 0, Color.RED)
|
||||
setPixel(1, 0, Color.GREEN)
|
||||
setPixel(0, 1, Color.BLUE)
|
||||
setPixel(1, 1, Color.YELLOW)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateBitmapViaExifWhenGivenNullBitmapShouldReturnNull() {
|
||||
val rotated = null.rotateBitmapViaExif(ExifInterface.ORIENTATION_ROTATE_90)
|
||||
assertEquals(null, rotated)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateBitmapViaExifWhenGivenNormalOrientationShouldReturnSameBitmap() {
|
||||
val bmp = createTestBitmap()
|
||||
val rotated = bmp.rotateBitmapViaExif(ExifInterface.ORIENTATION_NORMAL)
|
||||
assertEquals(bmp, rotated)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateBitmapViaExifWhenGivenRotate90ShouldReturnRotatedBitmap() {
|
||||
val bmp = createTestBitmap()
|
||||
val rotated = bmp.rotateBitmapViaExif(ExifInterface.ORIENTATION_ROTATE_90)!!
|
||||
assertEquals(bmp.width, rotated.height)
|
||||
assertEquals(bmp.height, rotated.width)
|
||||
|
||||
assertEquals(Color.BLUE, rotated.getPixel(0, 0))
|
||||
assertEquals(Color.RED, rotated.getPixel(1, 0))
|
||||
assertEquals(Color.YELLOW, rotated.getPixel(0, 1))
|
||||
assertEquals(Color.GREEN, rotated.getPixel(1, 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateBitmapViaExifWhenGivenRotate180ShouldReturnRotatedBitmap() {
|
||||
val bmp = createTestBitmap()
|
||||
val rotated = bmp.rotateBitmapViaExif(ExifInterface.ORIENTATION_ROTATE_180)!!
|
||||
assertEquals(bmp.width, rotated.width)
|
||||
assertEquals(bmp.height, rotated.height)
|
||||
|
||||
assertEquals(Color.YELLOW, rotated.getPixel(0, 0))
|
||||
assertEquals(Color.BLUE, rotated.getPixel(1, 0))
|
||||
assertEquals(Color.GREEN, rotated.getPixel(0, 1))
|
||||
assertEquals(Color.RED, rotated.getPixel(1, 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateBitmapViaExifWhenGivenFlipHorizontalShouldReturnFlippedBitmap() {
|
||||
val bmp = createTestBitmap()
|
||||
val rotated = bmp.rotateBitmapViaExif(ExifInterface.ORIENTATION_FLIP_HORIZONTAL)!!
|
||||
assertEquals(bmp.width, rotated.width)
|
||||
assertEquals(bmp.height, rotated.height)
|
||||
|
||||
assertEquals(Color.GREEN, rotated.getPixel(0, 0))
|
||||
assertEquals(Color.RED, rotated.getPixel(1, 0))
|
||||
assertEquals(Color.YELLOW, rotated.getPixel(0, 1))
|
||||
assertEquals(Color.BLUE, rotated.getPixel(1, 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateBitmapViaExifWhenGivenFlipVerticalShouldReturnFlippedBitmap() {
|
||||
val bmp = createTestBitmap()
|
||||
val rotated = bmp.rotateBitmapViaExif(ExifInterface.ORIENTATION_FLIP_VERTICAL)!!
|
||||
assertEquals(bmp.width, rotated.width)
|
||||
assertEquals(bmp.height, rotated.height)
|
||||
|
||||
assertEquals(Color.BLUE, rotated.getPixel(0, 0))
|
||||
assertEquals(Color.YELLOW, rotated.getPixel(1, 0))
|
||||
assertEquals(Color.RED, rotated.getPixel(0, 1))
|
||||
assertEquals(Color.GREEN, rotated.getPixel(1, 1))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.nextcloud.extensions
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.nextcloud.utils.extensions.getExifOrientation
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import org.junit.After
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
class GetExifOrientationTests {
|
||||
|
||||
private val tempFiles = mutableListOf<File>()
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
private fun createTempImageFile(): File {
|
||||
val file = File.createTempFile("test_image", ".jpg")
|
||||
tempFiles.add(file)
|
||||
|
||||
val bmp = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888).apply {
|
||||
setPixel(0, 0, Color.RED)
|
||||
setPixel(1, 0, Color.GREEN)
|
||||
setPixel(0, 1, Color.BLUE)
|
||||
setPixel(1, 1, Color.YELLOW)
|
||||
}
|
||||
|
||||
file.outputStream().use { out ->
|
||||
bmp.compress(Bitmap.CompressFormat.JPEG, 100, out)
|
||||
}
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
@After
|
||||
fun cleanup() {
|
||||
tempFiles.forEach { it.delete() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetExifOrientationWhenExifIsRotate90ShouldReturnRotate90() {
|
||||
val file = createTempImageFile()
|
||||
|
||||
val exif = ExifInterface(file.absolutePath)
|
||||
exif.setAttribute(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_ROTATE_90.toString())
|
||||
exif.saveAttributes()
|
||||
|
||||
val orientation = getExifOrientation(file.absolutePath)
|
||||
|
||||
assertEquals(ExifInterface.ORIENTATION_ROTATE_90, orientation)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetExifOrientationWhenExifIsRotate180ShouldReturnRotate180() {
|
||||
val file = createTempImageFile()
|
||||
|
||||
val exif = ExifInterface(file.absolutePath)
|
||||
exif.setAttribute(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_ROTATE_180.toString())
|
||||
exif.saveAttributes()
|
||||
|
||||
val orientation = getExifOrientation(file.absolutePath)
|
||||
assertEquals(ExifInterface.ORIENTATION_ROTATE_180, orientation)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetExifOrientationWhenExifIsUndefinedShouldReturnUndefined() {
|
||||
val file = createTempImageFile()
|
||||
|
||||
val orientation = getExifOrientation(file.absolutePath)
|
||||
assertEquals(ExifInterface.ORIENTATION_UNDEFINED, orientation)
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ package com.nextcloud.utils
|
|||
import com.nextcloud.utils.autoRename.AutoRename
|
||||
import com.owncloud.android.AbstractOnServerIT
|
||||
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFile
|
||||
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
|
||||
import com.owncloud.android.lib.resources.status.NextcloudVersion
|
||||
import com.owncloud.android.lib.resources.status.OCCapability
|
||||
import org.junit.Before
|
||||
|
|
@ -27,6 +28,7 @@ class AutoRenameTests : AbstractOnServerIT() {
|
|||
testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
||||
|
||||
capability = capability.apply {
|
||||
isWCFEnabled = CapabilityBooleanType.TRUE
|
||||
forbiddenFilenameExtensionJson = listOf(
|
||||
"""[" ",".",".part",".part"]""",
|
||||
"""[".",".part",".part"," "]""",
|
||||
|
|
@ -238,4 +240,14 @@ class AutoRenameTests : AbstractOnServerIT() {
|
|||
val expectedFilename = "Foo.Bar.Baz"
|
||||
assert(result == expectedFilename) { "Expected $expectedFilename but got $result" }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skipAutoRenameWhenWCFDisabled() {
|
||||
capability = capability.apply {
|
||||
isWCFEnabled = CapabilityBooleanType.FALSE
|
||||
}
|
||||
val filename = " readme.txt "
|
||||
val result = AutoRename.rename(filename, capability, isFolderPath = true)
|
||||
assert(result == filename) { "Expected $filename but got $result" }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.nextcloud.utils
|
||||
|
||||
import com.nextcloud.utils.extensions.checkWCFRestrictions
|
||||
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
|
||||
import com.owncloud.android.lib.resources.status.NextcloudVersion
|
||||
import com.owncloud.android.lib.resources.status.OCCapability
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
class CheckWCFRestrictionsTests {
|
||||
|
||||
private fun createCapability(
|
||||
version: NextcloudVersion,
|
||||
isWCFEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN
|
||||
): OCCapability = OCCapability().apply {
|
||||
this.versionMayor = version.majorVersionNumber
|
||||
this.isWCFEnabled = isWCFEnabled
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReturnsFalseForVersionsOlderThan30() {
|
||||
val capability = createCapability(NextcloudVersion.nextcloud_29)
|
||||
assertFalse(capability.checkWCFRestrictions())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReturnsTrueForVersion30WhenWCFAlwaysEnabled() {
|
||||
val capability = createCapability(NextcloudVersion.nextcloud_30)
|
||||
assertTrue(capability.checkWCFRestrictions())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReturnsTrueForVersion31WhenWCFAlwaysEnabled() {
|
||||
val capability = createCapability(NextcloudVersion.nextcloud_31)
|
||||
assertTrue(capability.checkWCFRestrictions())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReturnsTrueForVersion32WhenWCFEnabled() {
|
||||
val capability = createCapability(NextcloudVersion.nextcloud_32, CapabilityBooleanType.TRUE)
|
||||
assertTrue(capability.checkWCFRestrictions())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReturnsFalseForVersion32WhenWCFDisabled() {
|
||||
val capability = createCapability(NextcloudVersion.nextcloud_32, CapabilityBooleanType.FALSE)
|
||||
assertFalse(capability.checkWCFRestrictions())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReturnsFalseForVersion32WhenWCFIsUnknown() {
|
||||
val capability = createCapability(NextcloudVersion.nextcloud_32)
|
||||
assertFalse(capability.checkWCFRestrictions())
|
||||
}
|
||||
}
|
||||
204
app/src/androidTest/java/com/nextcloud/utils/FileHelperTest.kt
Normal file
204
app/src/androidTest/java/com/nextcloud/utils/FileHelperTest.kt
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.nextcloud.utils
|
||||
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
class FileHelperTest {
|
||||
|
||||
private lateinit var testDirectory: File
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
testDirectory = Files.createTempDirectory("test").toFile()
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
testDirectory.deleteRecursively()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenGivenNullDirectoryShouldReturnEmptyList() {
|
||||
val result = FileHelper.listDirectoryEntries(null, 0, 10, false)
|
||||
assertTrue(result.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenGivenNonExistentDirectoryShouldReturnEmptyList() {
|
||||
val nonExistent = File(testDirectory, "does_not_exist")
|
||||
val result = FileHelper.listDirectoryEntries(nonExistent, 0, 10, false)
|
||||
assertTrue(result.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenGivenFileInsteadOfDirectoryShouldReturnEmptyList() {
|
||||
val file = File(testDirectory, "test.txt")
|
||||
file.createNewFile()
|
||||
val result = FileHelper.listDirectoryEntries(file, 0, 10, false)
|
||||
assertTrue(result.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenGivenEmptyDirectoryShouldReturnEmptyList() {
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 0, 10, false)
|
||||
assertTrue(result.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenFetchingFoldersShouldReturnOnlyFolders() {
|
||||
File(testDirectory, "folder1").mkdir()
|
||||
File(testDirectory, "folder2").mkdir()
|
||||
File(testDirectory, "file1.txt").createNewFile()
|
||||
File(testDirectory, "file2.txt").createNewFile()
|
||||
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 0, 10, true)
|
||||
|
||||
assertEquals(2, result.size)
|
||||
assertTrue(result.all { it.isDirectory })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenFetchingFilesShouldReturnOnlyFiles() {
|
||||
File(testDirectory, "folder1").mkdir()
|
||||
File(testDirectory, "folder2").mkdir()
|
||||
File(testDirectory, "file1.txt").createNewFile()
|
||||
File(testDirectory, "file2.txt").createNewFile()
|
||||
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 0, 10, false)
|
||||
|
||||
assertEquals(2, result.size)
|
||||
assertTrue(result.all { it.isFile })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenStartIndexProvidedShouldSkipCorrectNumberOfItems() {
|
||||
for (i in 1..5) File(testDirectory, "file$i.txt").createNewFile()
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 2, 10, false)
|
||||
assertEquals(3, result.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenMaxItemsProvidedShouldLimitResults() {
|
||||
for (i in 1..10) File(testDirectory, "file$i.txt").createNewFile()
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 0, 5, false)
|
||||
assertEquals(5, result.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenGivenStartIndexAndMaxItemsShouldReturnCorrectSubset() {
|
||||
for (i in 1..10) File(testDirectory, "file$i.txt").createNewFile()
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 3, 4, false)
|
||||
assertEquals(4, result.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenStartIndexBeyondAvailableShouldReturnEmptyList() {
|
||||
for (i in 1..3) File(testDirectory, "file$i.txt").createNewFile()
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 10, 5, false)
|
||||
assertTrue(result.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenMaxItemsBeyondAvailableShouldReturnAllItems() {
|
||||
for (i in 1..3) File(testDirectory, "file$i.txt").createNewFile()
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 0, 100, false)
|
||||
assertEquals(3, result.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenFetchingFoldersWithOffsetShouldSkipCorrectly() {
|
||||
for (i in 1..5) File(testDirectory, "folder$i").mkdir()
|
||||
for (i in 1..3) File(testDirectory, "file$i.txt").createNewFile()
|
||||
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 2, 10, true)
|
||||
|
||||
assertEquals(3, result.size)
|
||||
assertTrue(result.all { it.isDirectory })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenFetchingFilesWithOffsetShouldSkipCorrectly() {
|
||||
for (i in 1..3) File(testDirectory, "folder$i").mkdir()
|
||||
for (i in 1..5) File(testDirectory, "file$i.txt").createNewFile()
|
||||
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 2, 10, false)
|
||||
|
||||
assertEquals(3, result.size)
|
||||
assertTrue(result.all { it.isFile })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenGivenOnlyFoldersAndFetchingFilesShouldReturnEmptyList() {
|
||||
for (i in 1..5) File(testDirectory, "folder$i").mkdir()
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 0, 10, false)
|
||||
assertTrue(result.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenGivenOnlyFilesAndFetchingFoldersShouldReturnEmptyList() {
|
||||
for (i in 1..5) File(testDirectory, "file$i.txt").createNewFile()
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 0, 10, true)
|
||||
assertTrue(result.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenMaxItemsIsZeroShouldReturnEmptyList() {
|
||||
for (i in 1..5) File(testDirectory, "file$i.txt").createNewFile()
|
||||
val result = FileHelper.listDirectoryEntries(testDirectory, 0, 0, false)
|
||||
assertTrue(result.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenGivenMixedContentShouldFilterCorrectly() {
|
||||
for (i in 1..3) File(testDirectory, "folder$i").mkdir()
|
||||
for (i in 1..7) File(testDirectory, "file$i.txt").createNewFile()
|
||||
|
||||
val folders = FileHelper.listDirectoryEntries(testDirectory, 0, 10, true)
|
||||
val files = FileHelper.listDirectoryEntries(testDirectory, 0, 10, false)
|
||||
|
||||
assertEquals(3, folders.size)
|
||||
assertEquals(7, files.size)
|
||||
assertTrue(folders.all { it.isDirectory })
|
||||
assertTrue(files.all { it.isFile })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenPaginatingFoldersShouldWorkCorrectly() {
|
||||
for (i in 1..10) File(testDirectory, "folder$i").mkdir()
|
||||
|
||||
val page1 = FileHelper.listDirectoryEntries(testDirectory, 0, 3, true)
|
||||
val page2 = FileHelper.listDirectoryEntries(testDirectory, 3, 3, true)
|
||||
val page3 = FileHelper.listDirectoryEntries(testDirectory, 6, 3, true)
|
||||
val page4 = FileHelper.listDirectoryEntries(testDirectory, 9, 3, true)
|
||||
|
||||
assertEquals(3, page1.size)
|
||||
assertEquals(3, page2.size)
|
||||
assertEquals(3, page3.size)
|
||||
assertEquals(1, page4.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListDirectoryEntriesWhenPaginatingFilesShouldWorkCorrectly() {
|
||||
for (i in 1..10) File(testDirectory, "file$i.txt").createNewFile()
|
||||
|
||||
val page1 = FileHelper.listDirectoryEntries(testDirectory, 0, 4, false)
|
||||
val page2 = FileHelper.listDirectoryEntries(testDirectory, 4, 4, false)
|
||||
val page3 = FileHelper.listDirectoryEntries(testDirectory, 8, 4, false)
|
||||
|
||||
assertEquals(4, page1.size)
|
||||
assertEquals(4, page2.size)
|
||||
assertEquals(2, page3.size)
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ package com.nextcloud.utils
|
|||
import com.nextcloud.utils.fileNameValidator.FileNameValidator
|
||||
import com.owncloud.android.AbstractOnServerIT
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
|
||||
import com.owncloud.android.lib.resources.status.NextcloudVersion
|
||||
import com.owncloud.android.lib.resources.status.OCCapability
|
||||
import org.junit.Assert.assertEquals
|
||||
|
|
@ -27,6 +28,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
|
|||
@Before
|
||||
fun setup() {
|
||||
capability = capability.apply {
|
||||
isWCFEnabled = CapabilityBooleanType.TRUE
|
||||
forbiddenFilenamesJson = """[".htaccess",".htaccess"]"""
|
||||
forbiddenFilenameBaseNamesJson = """
|
||||
["con", "prn", "aux", "nul", "com0", "com1", "com2", "com3", "com4",
|
||||
|
|
@ -228,4 +230,14 @@ class FileNameValidatorTests : AbstractOnServerIT() {
|
|||
val result = FileNameValidator.checkFolderAndFilePaths(folderPath, listOf(), capability, targetContext)
|
||||
assertFalse(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skipValidationWhenWCFDisabled() {
|
||||
capability = capability.apply {
|
||||
isWCFEnabled = CapabilityBooleanType.FALSE
|
||||
}
|
||||
val filename = "abc.txt"
|
||||
val result = FileNameValidator.checkFileName(filename, capability, targetContext)
|
||||
assertNull(result)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -400,11 +400,6 @@ public abstract class AbstractIT {
|
|||
public boolean isPowerSavingEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowerSavingExclusionAvailable() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
|
||||
|
|
|
|||
|
|
@ -216,11 +216,6 @@ public abstract class AbstractOnServerIT extends AbstractIT {
|
|||
public boolean isPowerSavingEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowerSavingExclusionAvailable() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
|
||||
|
|
|
|||
|
|
@ -82,12 +82,6 @@ public class UploadIT extends AbstractOnServerIT {
|
|||
public boolean isPowerSavingEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowerSavingExclusionAvailable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public BatteryStatus getBattery() {
|
||||
|
|
@ -237,11 +231,6 @@ public class UploadIT extends AbstractOnServerIT {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowerSavingExclusionAvailable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public BatteryStatus getBattery() {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.nextcloud.client.account.CurrentAccountProvider;
|
|||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.nextcloud.client.database.entity.UploadEntityKt;
|
||||
import com.nextcloud.test.RandomStringGenerator;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.MainApp;
|
||||
|
|
@ -108,7 +109,7 @@ public class UploadStorageManagerTest extends AbstractIT {
|
|||
OCUpload upload = createUpload(account);
|
||||
|
||||
uploads.add(upload);
|
||||
uploadsStorageManager.storeUpload(upload);
|
||||
uploadsStorageManager.uploadDao.insertOrReplace(UploadEntityKt.toUploadEntity(upload));
|
||||
}
|
||||
|
||||
OCUpload[] storedUploads = uploadsStorageManager.getAllStoredUploads();
|
||||
|
|
@ -151,17 +152,14 @@ public class UploadStorageManagerTest extends AbstractIT {
|
|||
account.name);
|
||||
|
||||
corruptUpload.setLocalPath(null);
|
||||
|
||||
uploadsStorageManager.storeUpload(corruptUpload);
|
||||
|
||||
uploadsStorageManager.uploadDao.insertOrReplace(UploadEntityKt.toUploadEntity(corruptUpload));
|
||||
uploadsStorageManager.getAllStoredUploads();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getById() {
|
||||
OCUpload upload = createUpload(account);
|
||||
long id = uploadsStorageManager.storeUpload(upload);
|
||||
|
||||
long id = uploadsStorageManager.uploadDao.insertOrReplace(UploadEntityKt.toUploadEntity(upload));
|
||||
OCUpload newUpload = uploadsStorageManager.getUploadById(id);
|
||||
|
||||
assertNotNull(newUpload);
|
||||
|
|
@ -178,7 +176,7 @@ public class UploadStorageManagerTest extends AbstractIT {
|
|||
|
||||
private void insertUploads(Account account, int rowsToInsert) {
|
||||
for (int i = 0; i < rowsToInsert; i++) {
|
||||
uploadsStorageManager.storeUpload(createUpload(account));
|
||||
uploadsStorageManager.uploadDao.insertOrReplace(UploadEntityKt.toUploadEntity(createUpload(account)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,9 +46,6 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
|
|||
override val isPowerSavingEnabled: Boolean
|
||||
get() = false
|
||||
|
||||
override val isPowerSavingExclusionAvailable: Boolean
|
||||
get() = false
|
||||
|
||||
override val battery: BatteryStatus
|
||||
get() = BatteryStatus()
|
||||
}
|
||||
|
|
@ -327,7 +324,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
|
|||
user,
|
||||
null,
|
||||
ocUpload2,
|
||||
NameCollisionPolicy.CANCEL,
|
||||
NameCollisionPolicy.SKIP,
|
||||
FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
|
|
@ -376,7 +373,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
|
|||
user,
|
||||
arrayOf(ocFile2),
|
||||
FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
|
||||
NameCollisionPolicy.CANCEL
|
||||
NameCollisionPolicy.SKIP
|
||||
)
|
||||
|
||||
shortSleep()
|
||||
|
|
@ -403,7 +400,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
|
|||
user,
|
||||
null,
|
||||
ocUpload,
|
||||
NameCollisionPolicy.CANCEL,
|
||||
NameCollisionPolicy.SKIP,
|
||||
FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
|
|
@ -429,7 +426,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
|
|||
user,
|
||||
null,
|
||||
ocUpload2,
|
||||
NameCollisionPolicy.CANCEL,
|
||||
NameCollisionPolicy.SKIP,
|
||||
FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
|
|
@ -480,7 +477,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
|
|||
user,
|
||||
arrayOf(ocFile2),
|
||||
FileUploadWorker.LOCAL_BEHAVIOUR_COPY,
|
||||
NameCollisionPolicy.CANCEL
|
||||
NameCollisionPolicy.SKIP
|
||||
)
|
||||
|
||||
shortSleep()
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ public class FileDisplayActivityTest extends AbstractIT {
|
|||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
Activity activity =
|
||||
ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED).iterator().next();
|
||||
if (activity instanceof WhatsNewActivity) {
|
||||
activity.onBackPressed();
|
||||
if (activity instanceof WhatsNewActivity whatsNewActivity) {
|
||||
whatsNewActivity.getOnBackPressedDispatcher().onBackPressed();
|
||||
}
|
||||
});
|
||||
scenario.recreate();
|
||||
|
|
|
|||
|
|
@ -822,7 +822,7 @@ class FileDetailSharingFragmentIT : AbstractIT() {
|
|||
val processFragment =
|
||||
activity.supportFragmentManager.findFragmentByTag(FileDetailsSharingProcessFragment.TAG) as
|
||||
FileDetailsSharingProcessFragment
|
||||
processFragment.onBackPressed()
|
||||
processFragment.activity?.onBackPressedDispatcher?.onBackPressed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class UnifiedSearchFragmentIT : AbstractIT() {
|
|||
scenario.onActivity { activity ->
|
||||
onIdleSync {
|
||||
EspressoIdlingResource.increment()
|
||||
val sut = UnifiedSearchFragment.newInstance(null, null)
|
||||
val sut = UnifiedSearchFragment.newInstance(null, null, "/")
|
||||
activity.addFragment(sut)
|
||||
|
||||
sut.onSearchResultChanged(
|
||||
|
|
@ -83,7 +83,7 @@ class UnifiedSearchFragmentIT : AbstractIT() {
|
|||
onIdleSync {
|
||||
EspressoIdlingResource.increment()
|
||||
|
||||
val sut = UnifiedSearchFragment.newInstance(null, null)
|
||||
val sut = UnifiedSearchFragment.newInstance(null, null, "/")
|
||||
val testViewModel = UnifiedSearchViewModel(activity.application)
|
||||
testViewModel.setConnectivityService(activity.connectivityServiceMock)
|
||||
val localRepository = UnifiedSearchFakeRepository()
|
||||
|
|
|
|||
|
|
@ -32,6 +32,14 @@ class CapabilityUtilsIT : AbstractIT() {
|
|||
assertTrue(test(OwnCloudVersion.nextcloud_20))
|
||||
}
|
||||
|
||||
private fun test(version: OwnCloudVersion): Boolean =
|
||||
CapabilityUtils.checkOutdatedWarning(targetContext.resources, version, false)
|
||||
@Test
|
||||
fun checkOutdatedWarningWithSubscription() {
|
||||
assertFalse(test(NextcloudVersion.nextcloud_31))
|
||||
assertFalse(test(NextcloudVersion.nextcloud_30))
|
||||
|
||||
assertFalse(test(OwnCloudVersion.nextcloud_20, true))
|
||||
}
|
||||
|
||||
private fun test(version: OwnCloudVersion, hasValidSubscription: Boolean = false): Boolean =
|
||||
CapabilityUtils.checkOutdatedWarning(targetContext.resources, version, false, hasValidSubscription)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue