123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /*
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * Copyright (C) 2019 Tobias Kaminsky
- * Copyright (C) 2019 Nextcloud GmbH
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * 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.nextcloud.client.utils
- import com.owncloud.android.utils.FileStorageUtils
- import org.junit.Assert.assertEquals
- import org.junit.Test
- import java.io.File
- import java.util.Locale
- class FileStorageUtilsTest {
- @Test
- fun testInstantUploadPathSubfolder() {
- val file = File("/sdcard/DCIM/subfolder/file.jpg")
- val syncedFolderLocalPath = "/sdcard/DCIM"
- val syncedFolderRemotePath = "/Camera"
- val subFolderByDate = false
- val dateTaken = 123123123L
- val result = FileStorageUtils.getInstantUploadFilePath(file,
- Locale.ROOT,
- syncedFolderRemotePath,
- syncedFolderLocalPath,
- dateTaken,
- subFolderByDate)
- val expected = "/Camera/subfolder/file.jpg"
- assertEquals(expected, result)
- }
- @Test
- fun testInstantUploadPathNoSubfolder() {
- val file = File("/sdcard/DCIM/file.jpg")
- val syncedFolderLocalPath = "/sdcard/DCIM"
- val syncedFolderRemotePath = "/Camera"
- val subFolderByDate = false
- val dateTaken = 123123123L
- val result = FileStorageUtils.getInstantUploadFilePath(file,
- Locale.ROOT,
- syncedFolderRemotePath,
- syncedFolderLocalPath,
- dateTaken,
- subFolderByDate)
- val expected = "/Camera/file.jpg"
- assertEquals(expected, result)
- }
- @Test
- fun testInstantUploadPathEmptyDateZero() {
- val file = File("/sdcard/DCIM/file.jpg")
- val syncedFolderLocalPath = "/sdcard/DCIM"
- val syncedFolderRemotePath = "/Camera"
- val subFolderByDate = true
- val dateTaken = 0L
- val result = FileStorageUtils.getInstantUploadFilePath(file,
- Locale.ROOT,
- syncedFolderRemotePath,
- syncedFolderLocalPath,
- dateTaken,
- subFolderByDate)
- val expected = "/Camera/file.jpg"
- assertEquals(expected, result)
- }
- @Test
- fun testInstantUploadPath() {
- val file = File("/sdcard/DCIM/file.jpg")
- val syncedFolderLocalPath = "/sdcard/DCIM"
- val syncedFolderRemotePath = "/Camera"
- val subFolderByDate = false
- val dateTaken = 123123123L
- val result = FileStorageUtils.getInstantUploadFilePath(file,
- Locale.ROOT,
- syncedFolderRemotePath,
- syncedFolderLocalPath,
- dateTaken,
- subFolderByDate)
- val expected = "/Camera/file.jpg"
- assertEquals(expected, result)
- }
- @Test
- fun testInstantUploadPathWithSubfolderByDate() {
- val file = File("/sdcard/DCIM/file.jpg")
- val syncedFolderLocalPath = "/sdcard/DCIM"
- val syncedFolderRemotePath = "/Camera"
- val subFolderByDate = true
- val dateTaken = 1569918628000L
- val result = FileStorageUtils.getInstantUploadFilePath(file,
- Locale.ROOT,
- syncedFolderRemotePath,
- syncedFolderLocalPath,
- dateTaken,
- subFolderByDate)
- val expected = "/Camera/2019/10/file.jpg"
- assertEquals(expected, result)
- }
- @Test
- fun testInstantUploadPathWithSubfolderFile() {
- val file = File("/sdcard/DCIM/subfolder/file.jpg")
- val syncedFolderLocalPath = "/sdcard/DCIM"
- val syncedFolderRemotePath = "/Camera"
- val subFolderByDate = false
- val dateTaken = 123123123L
- val result = FileStorageUtils.getInstantUploadFilePath(file,
- Locale.ROOT,
- syncedFolderRemotePath,
- syncedFolderLocalPath,
- dateTaken,
- subFolderByDate)
- val expected = "/Camera/subfolder/file.jpg"
- assertEquals(expected, result)
- }
- @Test
- fun testInstantUploadPathWithSubfolderByDateWithSubfolderFile() {
- val file = File("/sdcard/DCIM/subfolder/file.jpg")
- val syncedFolderLocalPath = "/sdcard/DCIM"
- val syncedFolderRemotePath = "/Camera"
- val subFolderByDate = true
- val dateTaken = 1569918628000L
- val result = FileStorageUtils.getInstantUploadFilePath(file,
- Locale.ROOT,
- syncedFolderRemotePath,
- syncedFolderLocalPath,
- dateTaken,
- subFolderByDate)
- val expected = "/Camera/2019/10/subfolder/file.jpg"
- assertEquals(expected, result)
- }
- }
|