FileStorageUtilsTest.kt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Tobias Kaminsky
  5. * Copyright (C) 2019 Tobias Kaminsky
  6. * Copyright (C) 2019 Nextcloud GmbH
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. package com.nextcloud.client.utils
  22. import com.owncloud.android.utils.FileStorageUtils
  23. import org.junit.Assert.assertEquals
  24. import org.junit.Test
  25. import java.io.File
  26. import java.util.Locale
  27. class FileStorageUtilsTest {
  28. @Test
  29. fun testInstantUploadPathSubfolder() {
  30. val file = File("/sdcard/DCIM/subfolder/file.jpg")
  31. val syncedFolderLocalPath = "/sdcard/DCIM"
  32. val syncedFolderRemotePath = "/Camera"
  33. val subFolderByDate = false
  34. val dateTaken = 123123123L
  35. val result = FileStorageUtils.getInstantUploadFilePath(file,
  36. Locale.ROOT,
  37. syncedFolderRemotePath,
  38. syncedFolderLocalPath,
  39. dateTaken,
  40. subFolderByDate)
  41. val expected = "/Camera/subfolder/file.jpg"
  42. assertEquals(expected, result)
  43. }
  44. @Test
  45. fun testInstantUploadPathNoSubfolder() {
  46. val file = File("/sdcard/DCIM/file.jpg")
  47. val syncedFolderLocalPath = "/sdcard/DCIM"
  48. val syncedFolderRemotePath = "/Camera"
  49. val subFolderByDate = false
  50. val dateTaken = 123123123L
  51. val result = FileStorageUtils.getInstantUploadFilePath(file,
  52. Locale.ROOT,
  53. syncedFolderRemotePath,
  54. syncedFolderLocalPath,
  55. dateTaken,
  56. subFolderByDate)
  57. val expected = "/Camera/file.jpg"
  58. assertEquals(expected, result)
  59. }
  60. @Test
  61. fun testInstantUploadPathEmptyDateZero() {
  62. val file = File("/sdcard/DCIM/file.jpg")
  63. val syncedFolderLocalPath = "/sdcard/DCIM"
  64. val syncedFolderRemotePath = "/Camera"
  65. val subFolderByDate = true
  66. val dateTaken = 0L
  67. val result = FileStorageUtils.getInstantUploadFilePath(file,
  68. Locale.ROOT,
  69. syncedFolderRemotePath,
  70. syncedFolderLocalPath,
  71. dateTaken,
  72. subFolderByDate)
  73. val expected = "/Camera/file.jpg"
  74. assertEquals(expected, result)
  75. }
  76. @Test
  77. fun testInstantUploadPath() {
  78. val file = File("/sdcard/DCIM/file.jpg")
  79. val syncedFolderLocalPath = "/sdcard/DCIM"
  80. val syncedFolderRemotePath = "/Camera"
  81. val subFolderByDate = false
  82. val dateTaken = 123123123L
  83. val result = FileStorageUtils.getInstantUploadFilePath(file,
  84. Locale.ROOT,
  85. syncedFolderRemotePath,
  86. syncedFolderLocalPath,
  87. dateTaken,
  88. subFolderByDate)
  89. val expected = "/Camera/file.jpg"
  90. assertEquals(expected, result)
  91. }
  92. @Test
  93. fun testInstantUploadPathWithSubfolderByDate() {
  94. val file = File("/sdcard/DCIM/file.jpg")
  95. val syncedFolderLocalPath = "/sdcard/DCIM"
  96. val syncedFolderRemotePath = "/Camera"
  97. val subFolderByDate = true
  98. val dateTaken = 1569918628000L
  99. val result = FileStorageUtils.getInstantUploadFilePath(file,
  100. Locale.ROOT,
  101. syncedFolderRemotePath,
  102. syncedFolderLocalPath,
  103. dateTaken,
  104. subFolderByDate)
  105. val expected = "/Camera/2019/10/file.jpg"
  106. assertEquals(expected, result)
  107. }
  108. @Test
  109. fun testInstantUploadPathWithSubfolderFile() {
  110. val file = File("/sdcard/DCIM/subfolder/file.jpg")
  111. val syncedFolderLocalPath = "/sdcard/DCIM"
  112. val syncedFolderRemotePath = "/Camera"
  113. val subFolderByDate = false
  114. val dateTaken = 123123123L
  115. val result = FileStorageUtils.getInstantUploadFilePath(file,
  116. Locale.ROOT,
  117. syncedFolderRemotePath,
  118. syncedFolderLocalPath,
  119. dateTaken,
  120. subFolderByDate)
  121. val expected = "/Camera/subfolder/file.jpg"
  122. assertEquals(expected, result)
  123. }
  124. @Test
  125. fun testInstantUploadPathWithSubfolderByDateWithSubfolderFile() {
  126. val file = File("/sdcard/DCIM/subfolder/file.jpg")
  127. val syncedFolderLocalPath = "/sdcard/DCIM"
  128. val syncedFolderRemotePath = "/Camera"
  129. val subFolderByDate = true
  130. val dateTaken = 1569918628000L
  131. val result = FileStorageUtils.getInstantUploadFilePath(file,
  132. Locale.ROOT,
  133. syncedFolderRemotePath,
  134. syncedFolderLocalPath,
  135. dateTaken,
  136. subFolderByDate)
  137. val expected = "/Camera/2019/10/subfolder/file.jpg"
  138. assertEquals(expected, result)
  139. }
  140. }