|
@@ -5,7 +5,6 @@
|
|
|
* @author Tobias Kaminsky
|
|
|
* Copyright (C) 2020 Tobias Kaminsky
|
|
|
* Copyright (C) 2020 Nextcloud GmbH
|
|
|
- * Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
|
|
|
*
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
@@ -20,54 +19,21 @@
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
-package com.owncloud.android.ui.fragment
|
|
|
+package com.owncloud.android.utils
|
|
|
|
|
|
import android.content.Context
|
|
|
import androidx.test.core.app.ApplicationProvider
|
|
|
-import androidx.test.espresso.intent.rule.IntentsTestRule
|
|
|
-import com.nextcloud.client.GrantStoragePermissionRule
|
|
|
-import com.nextcloud.client.device.BatteryStatus
|
|
|
-import com.nextcloud.client.device.PowerManagementService
|
|
|
-import com.nextcloud.client.network.Connectivity
|
|
|
-import com.nextcloud.client.network.ConnectivityService
|
|
|
-import com.owncloud.android.AbstractOnServerIT
|
|
|
+import com.owncloud.android.AbstractIT
|
|
|
import com.owncloud.android.datamodel.OCFile
|
|
|
-import com.owncloud.android.ui.activity.FileDisplayActivity
|
|
|
+import com.owncloud.android.utils.FileStorageUtils.checkIfEnoughSpace
|
|
|
+import com.owncloud.android.utils.FileStorageUtils.pathToUserFriendlyDisplay
|
|
|
+import org.junit.Assert.assertEquals
|
|
|
import org.junit.Assert.assertFalse
|
|
|
import org.junit.Assert.assertTrue
|
|
|
-import org.junit.Rule
|
|
|
import org.junit.Test
|
|
|
-import org.junit.rules.TestRule
|
|
|
import java.io.File
|
|
|
|
|
|
-class OCFileListFragmentIT : AbstractOnServerIT() {
|
|
|
- @get:Rule
|
|
|
- val activityRule = IntentsTestRule(FileDisplayActivity::class.java, true, false)
|
|
|
-
|
|
|
- @get:Rule
|
|
|
- val permissionRule: TestRule = GrantStoragePermissionRule.grant()
|
|
|
-
|
|
|
- private val connectivityServiceMock: ConnectivityService = object : ConnectivityService {
|
|
|
- override fun isInternetWalled(): Boolean {
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- override fun getConnectivity(): Connectivity {
|
|
|
- return Connectivity.CONNECTED_WIFI
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private val powerManagementServiceMock: PowerManagementService = object : PowerManagementService {
|
|
|
- override val isPowerSavingEnabled: Boolean
|
|
|
- get() = false
|
|
|
-
|
|
|
- override val isPowerSavingExclusionAvailable: Boolean
|
|
|
- get() = false
|
|
|
-
|
|
|
- override val battery: BatteryStatus
|
|
|
- get() = BatteryStatus()
|
|
|
- }
|
|
|
-
|
|
|
+class FileStorageUtilsIT : AbstractIT() {
|
|
|
private fun openFile(name: String): File {
|
|
|
val ctx: Context = ApplicationProvider.getApplicationContext()
|
|
|
val externalFilesDir = ctx.getExternalFilesDir(null)
|
|
@@ -77,7 +43,6 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
|
|
|
@Test
|
|
|
@SuppressWarnings("MagicNumber")
|
|
|
fun testEnoughSpaceWithoutLocalFile() {
|
|
|
- val sut = OCFileListFragment()
|
|
|
val ocFile = OCFile("/test.txt")
|
|
|
val file = openFile("test.txt")
|
|
|
file.createNewFile()
|
|
@@ -85,22 +50,21 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
|
|
|
ocFile.storagePath = file.absolutePath
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(200L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 0
|
|
|
- assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(200L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertFalse(sut.checkIfEnoughSpace(50L, ocFile))
|
|
|
+ assertFalse(checkIfEnoughSpace(50L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertFalse(sut.checkIfEnoughSpace(100L, ocFile))
|
|
|
+ assertFalse(checkIfEnoughSpace(100L, ocFile))
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@SuppressWarnings("MagicNumber")
|
|
|
fun testEnoughSpaceWithLocalFile() {
|
|
|
- val sut = OCFileListFragment()
|
|
|
val ocFile = OCFile("/test.txt")
|
|
|
val file = openFile("test.txt")
|
|
|
file.writeText("123123")
|
|
@@ -108,22 +72,21 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
|
|
|
ocFile.storagePath = file.absolutePath
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(200L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 0
|
|
|
- assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(200L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertFalse(sut.checkIfEnoughSpace(50L, ocFile))
|
|
|
+ assertFalse(checkIfEnoughSpace(50L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertFalse(sut.checkIfEnoughSpace(100L, ocFile))
|
|
|
+ assertFalse(checkIfEnoughSpace(100L, ocFile))
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@SuppressWarnings("MagicNumber")
|
|
|
fun testEnoughSpaceWithoutLocalFolder() {
|
|
|
- val sut = OCFileListFragment()
|
|
|
val ocFile = OCFile("/test/")
|
|
|
val file = openFile("test")
|
|
|
File(file, "1.txt").writeText("123123")
|
|
@@ -131,22 +94,21 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
|
|
|
ocFile.storagePath = file.absolutePath
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(200L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 0
|
|
|
- assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(200L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertFalse(sut.checkIfEnoughSpace(50L, ocFile))
|
|
|
+ assertFalse(checkIfEnoughSpace(50L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertFalse(sut.checkIfEnoughSpace(100L, ocFile))
|
|
|
+ assertFalse(checkIfEnoughSpace(100L, ocFile))
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@SuppressWarnings("MagicNumber")
|
|
|
fun testEnoughSpaceWithLocalFolder() {
|
|
|
- val sut = OCFileListFragment()
|
|
|
val ocFile = OCFile("/test/")
|
|
|
val folder = openFile("test")
|
|
|
folder.mkdirs()
|
|
@@ -158,30 +120,42 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
|
|
|
ocFile.mimeType = "DIR"
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(200L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 0
|
|
|
- assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(200L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertFalse(sut.checkIfEnoughSpace(50L, ocFile))
|
|
|
+ assertFalse(checkIfEnoughSpace(50L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 44
|
|
|
- assertTrue(sut.checkIfEnoughSpace(50L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(50L, ocFile))
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertTrue(sut.checkIfEnoughSpace(100L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(100L, ocFile))
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@SuppressWarnings("MagicNumber")
|
|
|
fun testEnoughSpaceWithNoLocalFolder() {
|
|
|
- val sut = OCFileListFragment()
|
|
|
val ocFile = OCFile("/test/")
|
|
|
|
|
|
ocFile.mimeType = "DIR"
|
|
|
|
|
|
ocFile.fileLength = 100
|
|
|
- assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
|
|
+ assertTrue(checkIfEnoughSpace(200L, ocFile))
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ fun testPathToUserFriendlyDisplay() {
|
|
|
+ assertEquals("/", pathToUserFriendlyDisplay("/"))
|
|
|
+ assertEquals("/sdcard/", pathToUserFriendlyDisplay("/sdcard/"))
|
|
|
+ assertEquals("/sdcard/test/1/", pathToUserFriendlyDisplay("/sdcard/test/1/"))
|
|
|
+ assertEquals("Internal storage/Movies/", pathToUserFriendlyDisplay("/storage/emulated/0/Movies/"))
|
|
|
+ assertEquals("Internal storage/", pathToUserFriendlyDisplay("/storage/emulated/0/"))
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun pathToUserFriendlyDisplay(path: String): String {
|
|
|
+ return pathToUserFriendlyDisplay(path, targetContext, targetContext.resources)
|
|
|
}
|
|
|
}
|