015565c6e5e12ffafdecacfa5bb9cb6e0efe51e1
[pub/Android/ownCloud.git] /
1 package com.owncloud.android.oc_framework_test_project.test;
2
3 import java.io.File;
4
5 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
6 import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
7 import com.owncloud.android.oc_framework.utils.FileUtils;
8 import com.owncloud.android.oc_framework_test_project.TestActivity;
9
10 import android.test.ActivityInstrumentationTestCase2;
11
12 public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
13
14 /* Folder data to rename. This folder must exist on the account */
15 private final String mOldFolderName = "folderToRename";
16 private final String mOldFolderPath = "/folderToRename/";
17 private final String mNewFolderName = "renamedFolder";
18 private final String mNewFolderPath = "/renameFolder";
19
20 /* File data to rename. This file must exist on the account */
21 private final String mOldFileName = "fileToRename.png";
22 private final String mOldFilePath = "/fileToRename.png";
23 private final String mNewFileName = "renamedFile";
24 private final String mNewFilePath = "/renamedFile";
25 private final String mFileExtension = ".png";
26
27
28 private TestActivity mActivity;
29
30 public RenameFileTest() {
31 super(TestActivity.class);
32
33 }
34
35 @Override
36 protected void setUp() throws Exception {
37 super.setUp();
38 setActivityInitialTouchMode(false);
39 mActivity = getActivity();
40 }
41
42 /**
43 * Test Rename Folder
44 */
45 public void testRenameFolder() {
46
47 RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
48 mNewFolderName, mNewFolderPath + FileUtils.PATH_SEPARATOR);
49 assertTrue(result.isSuccess());
50 }
51
52 /**
53 * Test Rename Folder with forbidden characters : / \ < > : " | ? *
54 */
55 public void testRenameFolderForbiddenChars() {
56
57 RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
58 mNewFolderName + "//", mNewFolderPath + "//" + FileUtils.PATH_SEPARATOR);
59 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
60
61 result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
62 mNewFolderName + "\\", mNewFolderPath + "\\" + FileUtils.PATH_SEPARATOR);
63 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
64
65 result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
66 mNewFolderName + "<", mNewFolderPath + "<" + FileUtils.PATH_SEPARATOR);
67 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
68
69 result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
70 mNewFolderName + ">", mNewFolderPath + ">" + FileUtils.PATH_SEPARATOR);
71 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
72
73 result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
74 mNewFolderName + ":", mNewFolderPath + ":" + FileUtils.PATH_SEPARATOR);
75 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
76
77 result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
78 mNewFolderName + "\"", mNewFolderPath + "\"" + FileUtils.PATH_SEPARATOR);
79 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
80
81 result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
82 mNewFolderName + "|", mNewFolderPath + "|" + FileUtils.PATH_SEPARATOR);
83 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
84
85 result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
86 mNewFolderName + "?", mNewFolderPath + "?" + FileUtils.PATH_SEPARATOR);
87 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
88
89 result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
90 mNewFolderName + "*", mNewFolderPath + "*" + FileUtils.PATH_SEPARATOR);
91 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
92 }
93
94 /**
95 * Test Rename File
96 */
97 public void testRenameFile() {
98 RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
99 mNewFileName + mFileExtension, mNewFilePath + mFileExtension);
100 assertTrue(result.isSuccess());
101 }
102
103
104 /**
105 * Test Rename Folder with forbidden characters: / \ < > : " | ? *
106 */
107 public void testRenameFileForbiddenChars() {
108 RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
109 mNewFileName + "//" + mFileExtension, mNewFilePath + "//" + mFileExtension);
110 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
111
112 result = mActivity.renameFile(mOldFileName, mOldFilePath,
113 mNewFileName + "\\" + mFileExtension, mNewFilePath + "\\" + mFileExtension);
114 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
115
116 result = mActivity.renameFile(mOldFileName, mOldFilePath,
117 mNewFileName + "<" + mFileExtension, mNewFilePath + "<" + mFileExtension);
118 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
119
120 result = mActivity.renameFile(mOldFileName, mOldFilePath,
121 mNewFileName + ">" + mFileExtension, mNewFilePath + ">" + mFileExtension);
122 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
123
124 result = mActivity.renameFile(mOldFileName, mOldFilePath,
125 mNewFileName + ":" + mFileExtension, mNewFilePath + ":" + mFileExtension);
126 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
127
128 result = mActivity.renameFile(mOldFileName, mOldFilePath,
129 mNewFileName + "\"" + mFileExtension, mNewFilePath + "\"" + mFileExtension);
130 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
131
132 result = mActivity.renameFile(mOldFileName, mOldFilePath,
133 mNewFileName + "|" + mFileExtension, mNewFilePath + "|" + mFileExtension);
134 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
135
136 result = mActivity.renameFile(mOldFileName, mOldFilePath,
137 mNewFileName + "?" + mFileExtension, mNewFilePath + "?" + mFileExtension);
138 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
139
140 result = mActivity.renameFile(mOldFileName, mOldFilePath,
141 mNewFileName + "*" + mFileExtension, mNewFilePath + "*" + mFileExtension);
142 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
143
144 }
145
146
147 /**
148 * Restore initial conditions
149 */
150 public void testRestoreInitialConditions() {
151 RemoteOperationResult result = mActivity.renameFile(mNewFolderName, mNewFolderPath, mOldFolderName, mOldFolderPath);
152 assertTrue(result.isSuccess());
153
154 result = mActivity.renameFile(mNewFileName, mNewFilePath, mOldFileName, mOldFilePath);
155 assertTrue(result.isSuccess());
156 }
157
158 }