1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-20 12:52:53 +00:00

Initial commit of ownCloud Android library

This commit is contained in:
David A. Velasco
2014-01-20 13:51:09 +01:00
commit 1f3123b1b7
104 changed files with 7694 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry combineaccessrules="false" kind="src" path="/ownCloud Android Library Test Project"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
+33
View File
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ownCloud Android Library Tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6
+41
View File
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.owncloud.android.lib.test_project.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application>
<uses-library android:name="android.test.runner" />
</application>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Tests for com.owncloud.android.lib.test_project"
android:targetPackage="com.owncloud.android.lib.test_project" />
</manifest>
+14
View File
@@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-19
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

+30
View File
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<resources>
<string name="app_name">Oc_framework-testTest</string>
</resources>
@@ -0,0 +1,119 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Create Folder Operation
* @author masensio
*
*/
public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
private TestActivity mActivity;
private String mCurrentDate;
public CreateFolderTest() {
super(TestActivity.class);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
mCurrentDate = sdf.format(new Date());
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Create Folder
*/
public void testCreateFolder() {
String remotePath = "/testCreateFolder" + mCurrentDate;
boolean createFullPath = true;
RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
// Create Subfolder
remotePath = "/testCreateFolder" + mCurrentDate + "/" + "testCreateFolder" + mCurrentDate;
createFullPath = true;
result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
}
/**
* Test to Create Folder with special characters: / \ < > : " | ? *
*/
public void testCreateFolderSpecialCharacters() {
boolean createFullPath = true;
String remotePath = "/testSpecialCharacters_\\" + mCurrentDate;
RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = "/testSpecialCharacters_<" + mCurrentDate;
result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = "/testSpecialCharacters_>" + mCurrentDate;
result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = "/testSpecialCharacters_:" + mCurrentDate;
result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = "/testSpecialCharacters_\"" + mCurrentDate;
result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = "/testSpecialCharacters_|" + mCurrentDate;
result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = "/testSpecialCharacters_?" + mCurrentDate;
result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = "/testSpecialCharacters_*" + mCurrentDate;
result = mActivity.createFolder(remotePath, createFullPath);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
}
@@ -0,0 +1,87 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Delete a File Operation
* @author masensio
*
*/
public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
/* Folder data to delete. */
private final String mFolderPath = "/folderToDelete";
/* File to delete. */
private final String mFilePath = "fileToDelete.png";
private TestActivity mActivity;
public DeleteFileTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Remove Folder
*/
public void testRemoveFolder() {
RemoteOperationResult result = mActivity.removeFile(mFolderPath);
assertTrue(result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND);
}
/**
* Test Remove File
*/
public void testRemoveFile() {
RemoteOperationResult result = mActivity.removeFile(mFilePath);
assertTrue(result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND);
}
/**
* Restore initial conditions
*/
public void testRestoreInitialConditions() {
RemoteOperationResult result = mActivity.createFolder(mFolderPath, true);
assertTrue(result.isSuccess());
}
}
@@ -0,0 +1,130 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.owncloud.android.lib.operations.common.RemoteFile;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Download File Operation
* @author masensio
*
*/
public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
/* Files to download. These files must exist on the account */
private final String mRemoteFilePng = "/fileToDownload.png";
private final String mRemoteFileChunks = "/fileToDownload.mp4";
private final String mRemoteFileSpecialChars = "/@file@download.png";
private final String mRemoteFileSpecialCharsChunks = "/@file@download.mp4";
private final String mRemoteFileNotFound = "/fileNotFound.png"; /* This file mustn't exist on the account */
private String mCurrentDate;
private TestActivity mActivity;
public DownloadFileTest() {
super(TestActivity.class);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
mCurrentDate = sdf.format(new Date());
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Download a File
*/
public void testDownloadFile() {
String temporalFolder = "/download" + mCurrentDate;
RemoteFile remoteFile= new RemoteFile(mRemoteFilePng);
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
assertTrue(result.isSuccess());
}
/**
* Test Download a File with chunks
*/
public void testDownloadFileChunks() {
String temporalFolder = "/download" + mCurrentDate;
RemoteFile remoteFile= new RemoteFile(mRemoteFileChunks);
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
assertTrue(result.isSuccess());
}
/**
* Test Download a File with special chars
*/
public void testDownloadFileSpecialChars() {
String temporalFolder = "/download" + mCurrentDate;
RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialChars);
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
assertTrue(result.isSuccess());
}
/**
* Test Download a File with special chars and chunks
*/
public void testDownloadFileSpecialCharsChunks() {
String temporalFolder = "/download" + mCurrentDate;
RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialCharsChunks);
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
assertTrue(result.isSuccess());
}
/**
* Test Download a Not Found File
*/
public void testDownloadFileNotFound() {
String temporalFolder = "/download" + mCurrentDate;
RemoteFile remoteFile = new RemoteFile(mRemoteFileNotFound);
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
assertFalse(result.isSuccess());
}
}
@@ -0,0 +1,67 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Read File Operation
* @author masensio
*
*/
public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
/* File data to read. This file must exist on the account */
private final String mRemoteFolderPath = "/fileToRead.txt";
private TestActivity mActivity;
public ReadFileTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Read File
*/
public void testReadFile() {
RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath);
assertTrue(result.getData().size() == 1);
assertTrue(result.isSuccess());
}
}
@@ -0,0 +1,69 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Read Folder Operation
* @author masensio
*
*/
public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
/* Folder data to read. This folder must exist on the account */
private final String mRemoteFolderPath = "/folderToRead";
private TestActivity mActivity;
public ReadFolderTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Read Folder
*/
public void testReadFolder() {
RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath);
assertTrue(result.getData().size() > 1);
assertTrue(result.getData().size() == 4);
assertTrue(result.isSuccess());
}
}
@@ -0,0 +1,177 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Rename File Operation
* @author masensio
*
*/
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
/* Folder data to rename. This folder must exist on the account */
private final String mOldFolderName = "folderToRename";
private final String mOldFolderPath = "/folderToRename";
private final String mNewFolderName = "renamedFolder";
private final String mNewFolderPath = "/renamedFolder";
/* 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";
private final String mFileExtension = ".png";
private final String mNewFilePath ="/renamedFile.png";
private TestActivity mActivity;
public RenameFileTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Rename Folder
*/
public void testRenameFolder() {
RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
mNewFolderName, true);
assertTrue(result.isSuccess());
}
/**
* Test Rename Folder with forbidden characters : \ < > : " | ? *
*/
public void testRenameFolderForbiddenChars() {
RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
mNewFolderName + "\\", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
mNewFolderName + "<", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
mNewFolderName + ">", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
mNewFolderName + ":", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
mNewFolderName + "\"", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
mNewFolderName + "|", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
mNewFolderName + "?", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
mNewFolderName + "*", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
/**
* Test Rename File
*/
public void testRenameFile() {
RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
mNewFileName + mFileExtension, false);
assertTrue(result.isSuccess());
}
/**
* Test Rename Folder with forbidden characters: \ < > : " | ? *
*/
public void testRenameFileForbiddenChars() {
RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
mNewFileName + "\\" + mFileExtension, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
mNewFileName + "<" + mFileExtension, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
mNewFileName + ">" + mFileExtension, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
mNewFileName + ":" + mFileExtension, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
mNewFileName + "\"" + mFileExtension, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
mNewFileName + "|" + mFileExtension, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
mNewFileName + "?" + mFileExtension, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
mNewFileName + "*" + mFileExtension, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
/**
* Restore initial conditions
*/
public void testRestoreInitialConditions() {
RemoteOperationResult result = mActivity.renameFile(mNewFolderName, mNewFolderPath, mOldFolderName, true);
assertTrue(result.isSuccess());
result = mActivity.renameFile(mNewFileName + mFileExtension, mNewFilePath, mOldFileName, false);
assertTrue(result.isSuccess());
}
}
@@ -0,0 +1,168 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.content.res.AssetManager;
import android.os.Environment;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Update File Operation
* @author masensio
*
*/
public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
/* Files to upload. These files must exists on the device */
private final String mFileToUpload = "fileToUpload.png";
private final String mMimeType = "image/png";
private final String mFileToUploadWithChunks = "fileToUploadChunks.MP4";
private final String mMimeTypeWithChunks = "video/mp4";
private final String mFileNotFound = "fileNotFound.png";
private final String mStoragePath = "/owncloud/tmp/uploadTest";
private String mPath;
private String mCurrentDate;
private TestActivity mActivity;
public UploadFileTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
mCurrentDate = sdf.format(new Date());
File sdCard = Environment.getExternalStorageDirectory();
mPath = sdCard.getAbsolutePath() + "/" + mStoragePath + mCurrentDate;
//mActivity.createFolder(mPath, true);
copyAssets();
}
/**
* Copy Files to ulpload to SdCard
*/
private void copyAssets() {
AssetManager assetManager = getActivity().getAssets();
String[] files = { mFileToUpload, mFileToUploadWithChunks };
// Folder with contents
File folder = new File(mPath);
folder.mkdirs();
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(filename);
File outFile = new File(folder, filename);
out = new FileOutputStream(outFile);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(IOException e) {
Log.e("tag", "Failed to copy asset file: " + filename, e);
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
/**
* Test Upload File without chunks
*/
public void testUploadFile() {
String storagePath = mPath + "/" + mFileToUpload;
//String remotePath = "/uploadTest" + mCurrentDate + "/" + mFileToUpload;
String remotePath = "/" + mFileToUpload;
RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeType);
assertTrue(result.isSuccess());
}
/**
* Test Upload File with chunks
*/
public void testUploadFileWithChunks() {
String storagePath = mPath + "/" + mFileToUploadWithChunks;
//String remotePath = "/uploadTest" + mCurrentDate + "/" +mFileToUploadWithChunks;
String remotePath = "/" + mFileToUploadWithChunks;
RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeTypeWithChunks);
assertTrue(result.isSuccess());
}
/**
* Test Upload Not Found File
*/
public void testUploadFileNotFound() {
String storagePath = mPath + "/" + mFileNotFound;
//String remotePath = "/uploadTest" + mCurrentDate + "/" + mFileToUpload;
String remotePath = "/" + mFileNotFound;
RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeType);
assertFalse(result.isSuccess());
}
}