Эх сурвалжийг харах

OC-1991: Add more cases in rename file / folder tests

masensio 11 жил өмнө
parent
commit
6e092bf235

+ 1 - 1
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java

@@ -56,7 +56,7 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
 	
 	
 	/**
-	 * Test to Create Folder with special characters
+	 * Test to Create Folder with special characters: /  \  < >  :  "  |  ?  *
 	 */
 	public void testCreateFolderSpecialCharacters() {		
 		boolean createFullPath = true;

+ 80 - 13
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/RenameFileTest.java

@@ -1,7 +1,10 @@
 package com.owncloud.android.oc_framework_test_project.test;
 
+import java.io.File;
+
 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
 import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.oc_framework.utils.FileUtils;
 import com.owncloud.android.oc_framework_test_project.TestActivity;
 
 import android.test.ActivityInstrumentationTestCase2;
@@ -12,17 +15,14 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
 	private final String mOldFolderName = "folderToRename";
 	private final String mOldFolderPath = "/folderToRename/";
 	private final String mNewFolderName = "renamedFolder"; 
-	private final String mNewFolderPath = "/renameFolder/";
-	private final String mNewFolderNameInvalidChars = "renamedFolder:";
-	private final String mNewFolderPathInvalidChars = "/renamedFolder:/";
+	private final String mNewFolderPath = "/renameFolder";
 	
 	/* File data to rename. This file must exist on the account */
 	private final String mOldFileName = "fileToRename.png";
 	private final String mOldFilePath = "/fileToRename.png";
-	private final String mNewFileName = "renamedFile.png";
-	private final String mNewFilePath = "/renamedFile.png";
-	private final String mNewFileNameInvalidChars = "renamedFile:.png";
-	private final String mNewFilePathInvalidChars = "/renamedFile:.png";
+	private final String mNewFileName = "renamedFile";
+	private final String mNewFilePath = "/renamedFile";
+	private final String mFileExtension = ".png";
 	
 	
 	private TestActivity mActivity;
@@ -44,17 +44,50 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
 	 */
 	public void testRenameFolder() {
 
-		RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath, mNewFolderName, mNewFolderPath);
+		RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
+				mNewFolderName, mNewFolderPath + FileUtils.PATH_SEPARATOR);
 		assertTrue(result.isSuccess());
 	}
 	
 	/**
-	 * Test Rename Folder with forbidden characters
+	 * Test Rename Folder with forbidden characters : /  \  < >  :  "  |  ?  *
 	 */
 	public void testRenameFolderForbiddenChars() {
 
 		RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
-				mNewFolderNameInvalidChars, mNewFolderPathInvalidChars);
+				mNewFolderName + "//", mNewFolderPath + "//" + FileUtils.PATH_SEPARATOR);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
+				mNewFolderName + "\\", mNewFolderPath + "\\" + FileUtils.PATH_SEPARATOR);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
+				mNewFolderName + "<", mNewFolderPath + "<" + FileUtils.PATH_SEPARATOR);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
+				mNewFolderName + ">", mNewFolderPath + ">" + FileUtils.PATH_SEPARATOR);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
+				mNewFolderName + ":", mNewFolderPath + ":" + FileUtils.PATH_SEPARATOR);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
+				mNewFolderName + "\"", mNewFolderPath + "\"" + FileUtils.PATH_SEPARATOR);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
+				mNewFolderName + "|", mNewFolderPath + "|" + FileUtils.PATH_SEPARATOR);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
+				mNewFolderName + "?", mNewFolderPath + "?" + FileUtils.PATH_SEPARATOR);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFolderName, mOldFolderPath, 
+				mNewFolderName + "*", mNewFolderPath + "*" + FileUtils.PATH_SEPARATOR);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 	}
 	
@@ -62,18 +95,52 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
 	 * Test Rename File
 	 */
 	public void testRenameFile() {
-		RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath, mNewFileName, mNewFilePath);
+		RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath, 
+				mNewFileName + mFileExtension, mNewFilePath + mFileExtension);
 		assertTrue(result.isSuccess());
 	}
 	
 	
 	/**
-	 * Test Rename Folder with forbidden characters
+	 * Test Rename Folder with forbidden characters: /  \  < >  :  "  |  ?  *
 	 */
 	public void testRenameFileForbiddenChars() {
 		RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath, 
-				mNewFileNameInvalidChars, mNewFilePathInvalidChars);
+				mNewFileName + "//" + mFileExtension, mNewFilePath + "//" + mFileExtension);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFileName, mOldFilePath, 
+				mNewFileName + "\\" + mFileExtension, mNewFilePath + "\\" + mFileExtension);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFileName, mOldFilePath, 
+				mNewFileName + "<" + mFileExtension, mNewFilePath + "<" + mFileExtension);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFileName, mOldFilePath, 
+				mNewFileName + ">" + mFileExtension, mNewFilePath + ">" + mFileExtension);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFileName, mOldFilePath, 
+				mNewFileName + ":" + mFileExtension, mNewFilePath + ":" + mFileExtension);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFileName, mOldFilePath, 
+				mNewFileName + "\"" + mFileExtension, mNewFilePath + "\"" + mFileExtension);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFileName, mOldFilePath, 
+				mNewFileName + "|" + mFileExtension, mNewFilePath + "|" + mFileExtension);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFileName, mOldFilePath, 
+				mNewFileName + "?" + mFileExtension, mNewFilePath + "?" + mFileExtension);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
+		result = mActivity.renameFile(mOldFileName, mOldFilePath, 
+				mNewFileName + "*" + mFileExtension, mNewFilePath + "*" + mFileExtension);
+		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+		
 	}
 	
 	

+ 2 - 2
oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java

@@ -58,8 +58,8 @@ public class TestActivity extends Activity {
 //	        am.setUserData(mAccount, "oc_version",    "5.0.14");
 //	        am.setUserData(mAccount, "oc_base_url",   "http://beta.owncloud.com/owncloud");
 //        } else {
-            Log.d(TAG, "oc_version --->"+ am.getUserData(mAccount, "oc_version") );
-            Log.d(TAG, "oc_base_url --->"+ am.getUserData(mAccount, "oc_base_url") );
+//            Log.d(TAG, "oc_version --->"+ am.getUserData(mAccount, "oc_version") );
+//            Log.d(TAG, "oc_base_url --->"+ am.getUserData(mAccount, "oc_base_url") );
 //        }
         	
         

+ 2 - 2
oc_framework/src/com/owncloud/android/oc_framework/network/webdav/OwnCloudClientFactory.java

@@ -78,8 +78,8 @@ public class OwnCloudClientFactory {
             
         } else {
             String username = account.name.substring(0, account.name.lastIndexOf('@'));
-            //String password = am.getPassword(account);
-            String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), false);
+            String password = am.getPassword(account);
+            //String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), false);
             client.setBasicCredentials(username, password);
         }