0c099b1517ae059fc7c234b8d1775af9a6c943b9
[pub/Android/ownCloud.git] /
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.oc_framework_test_project.test;
19
20 import java.text.SimpleDateFormat;
21 import java.util.Date;
22
23 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
24 import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
25 import com.owncloud.android.oc_framework_test_project.TestActivity;
26
27 import android.test.ActivityInstrumentationTestCase2;
28
29 /**
30 * Class to test Create Folder Operation
31 * @author masensio
32 *
33 */
34 public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
35
36 private TestActivity mActivity;
37 private String mCurrentDate;
38
39 public CreateFolderTest() {
40 super(TestActivity.class);
41
42 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
43 mCurrentDate = sdf.format(new Date());
44 }
45
46 @Override
47 protected void setUp() throws Exception {
48 super.setUp();
49 setActivityInitialTouchMode(false);
50 mActivity = getActivity();
51 }
52
53 /**
54 * Test Create Folder
55 */
56 public void testCreateFolder() {
57
58 String remotePath = "/testCreateFolder" + mCurrentDate;
59 boolean createFullPath = true;
60
61 RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
62 assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
63
64 // Create Subfolder
65 remotePath = "/testCreateFolder" + mCurrentDate + "/" + "testCreateFolder" + mCurrentDate;
66 createFullPath = true;
67
68 result = mActivity.createFolder(remotePath, createFullPath);
69 assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
70 }
71
72
73 /**
74 * Test to Create Folder with special characters: / \ < > : " | ? *
75 */
76 public void testCreateFolderSpecialCharacters() {
77 boolean createFullPath = true;
78
79 String remotePath = "/testSpecialCharacters_\\" + mCurrentDate;
80 RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
81 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
82
83 remotePath = "/testSpecialCharacters_<" + mCurrentDate;
84 result = mActivity.createFolder(remotePath, createFullPath);
85 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
86
87 remotePath = "/testSpecialCharacters_>" + mCurrentDate;
88 result = mActivity.createFolder(remotePath, createFullPath);
89 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
90
91 remotePath = "/testSpecialCharacters_:" + mCurrentDate;
92 result = mActivity.createFolder(remotePath, createFullPath);
93 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
94
95 remotePath = "/testSpecialCharacters_\"" + mCurrentDate;
96 result = mActivity.createFolder(remotePath, createFullPath);
97 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
98
99 remotePath = "/testSpecialCharacters_|" + mCurrentDate;
100 result = mActivity.createFolder(remotePath, createFullPath);
101 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
102
103 remotePath = "/testSpecialCharacters_?" + mCurrentDate;
104 result = mActivity.createFolder(remotePath, createFullPath);
105 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
106
107 remotePath = "/testSpecialCharacters_*" + mCurrentDate;
108 result = mActivity.createFolder(remotePath, createFullPath);
109 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
110 }
111
112
113 }