瀏覽代碼

OC-1869: Create Unit test project

masensio 11 年之前
父節點
當前提交
780d91da3b
共有 32 個文件被更改,包括 397 次插入0 次删除
  1. 10 0
      oc_framework-test-project/.classpath
  2. 33 0
      oc_framework-test-project/.project
  3. 4 0
      oc_framework-test-project/.settings/org.eclipse.jdt.core.prefs
  4. 30 0
      oc_framework-test-project/AndroidManifest.xml
  5. 二進制
      oc_framework-test-project/ic_launcher-web.png
  6. 二進制
      oc_framework-test-project/libs/android-support-v4.jar
  7. 10 0
      oc_framework-test-project/oc_framework-test-test/.classpath
  8. 34 0
      oc_framework-test-project/oc_framework-test-test/.project
  9. 4 0
      oc_framework-test-project/oc_framework-test-test/.settings/org.eclipse.jdt.core.prefs
  10. 17 0
      oc_framework-test-project/oc_framework-test-test/AndroidManifest.xml
  11. 14 0
      oc_framework-test-project/oc_framework-test-test/project.properties
  12. 二進制
      oc_framework-test-project/oc_framework-test-test/res/drawable-hdpi/ic_launcher.png
  13. 二進制
      oc_framework-test-project/oc_framework-test-test/res/drawable-ldpi/ic_launcher.png
  14. 二進制
      oc_framework-test-project/oc_framework-test-test/res/drawable-mdpi/ic_launcher.png
  15. 二進制
      oc_framework-test-project/oc_framework-test-test/res/drawable-xhdpi/ic_launcher.png
  16. 6 0
      oc_framework-test-project/oc_framework-test-test/res/values/strings.xml
  17. 45 0
      oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java
  18. 15 0
      oc_framework-test-project/project.properties
  19. 二進制
      oc_framework-test-project/res/drawable-hdpi/ic_launcher.png
  20. 二進制
      oc_framework-test-project/res/drawable-mdpi/ic_launcher.png
  21. 二進制
      oc_framework-test-project/res/drawable-xhdpi/ic_launcher.png
  22. 二進制
      oc_framework-test-project/res/drawable-xxhdpi/ic_launcher.png
  23. 16 0
      oc_framework-test-project/res/layout/activity_test.xml
  24. 9 0
      oc_framework-test-project/res/menu/test.xml
  25. 8 0
      oc_framework-test-project/res/values-sw600dp/dimens.xml
  26. 9 0
      oc_framework-test-project/res/values-sw720dp-land/dimens.xml
  27. 11 0
      oc_framework-test-project/res/values-v11/styles.xml
  28. 12 0
      oc_framework-test-project/res/values-v14/styles.xml
  29. 7 0
      oc_framework-test-project/res/values/dimens.xml
  30. 8 0
      oc_framework-test-project/res/values/strings.xml
  31. 20 0
      oc_framework-test-project/res/values/styles.xml
  32. 75 0
      oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java

+ 10 - 0
oc_framework-test-project/.classpath

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
+	<classpathentry 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 exported="true" kind="lib" path="/oc_framework/bin/oc_framework.jar"/>
+	<classpathentry kind="output" path="bin/classes"/>
+</classpath>

+ 33 - 0
oc_framework-test-project/.project

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>oc_framework-test-project</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>

+ 4 - 0
oc_framework-test-project/.settings/org.eclipse.jdt.core.prefs

@@ -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

+ 30 - 0
oc_framework-test-project/AndroidManifest.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.owncloud.android.oc_framework_test_project"
+    android:versionCode="1"
+    android:versionName="1.0" >
+    
+    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
+    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
+    
+    <uses-sdk
+        android:minSdkVersion="8"
+        android:targetSdkVersion="18" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name="com.owncloud.android.oc_framework_test_project.TestActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>

二進制
oc_framework-test-project/ic_launcher-web.png


二進制
oc_framework-test-project/libs/android-support-v4.jar


+ 10 - 0
oc_framework-test-project/oc_framework-test-test/.classpath

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
+	<classpathentry combineaccessrules="false" exported="true" kind="src" path="/oc_framework-test-project"/>
+	<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 kind="output" path="bin/classes"/>
+</classpath>

+ 34 - 0
oc_framework-test-project/oc_framework-test-test/.project

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>oc_framework-test</name>
+	<comment></comment>
+	<projects>
+		<project>oc_framework-test-project</project>
+	</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>

+ 4 - 0
oc_framework-test-project/oc_framework-test-test/.settings/org.eclipse.jdt.core.prefs

@@ -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

+ 17 - 0
oc_framework-test-project/oc_framework-test-test/AndroidManifest.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.owncloud.android.oc_framework_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.oc_framework_test_project"
+        android:targetPackage="com.owncloud.android.oc_framework_test_project" />
+
+</manifest>

+ 14 - 0
oc_framework-test-project/oc_framework-test-test/project.properties

@@ -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

二進制
oc_framework-test-project/oc_framework-test-test/res/drawable-hdpi/ic_launcher.png


二進制
oc_framework-test-project/oc_framework-test-test/res/drawable-ldpi/ic_launcher.png


二進制
oc_framework-test-project/oc_framework-test-test/res/drawable-mdpi/ic_launcher.png


二進制
oc_framework-test-project/oc_framework-test-test/res/drawable-xhdpi/ic_launcher.png


+ 6 - 0
oc_framework-test-project/oc_framework-test-test/res/values/strings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">Oc_framework-testTest</string>
+
+</resources>

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

@@ -0,0 +1,45 @@
+package com.owncloud.android.oc_framework_test_project.test;
+
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework_test_project.TestActivity;
+
+import android.test.ActivityInstrumentationTestCase2;
+import android.util.Log;
+
+public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
+
+	private TestActivity mActivity;
+	
+	public CreateFolderTest() {
+	    super(TestActivity.class);
+	   
+	}
+	
+	@Override
+	  protected void setUp() throws Exception {
+	    super.setUp();
+	    setActivityInitialTouchMode(false);
+	    mActivity = getActivity();
+	}
+	
+	public void testCreateFolder() {
+		
+		String remotePath = "beta.owncloud.com/owncloud/testCreateFolder";
+		boolean createFullPath = true;
+		
+		RemoteOperationResult result =  mActivity.createFolder(remotePath, createFullPath);
+		Log.d("test CreateFolder", "-----------------------" + result.getCode().name());
+		Log.d("test CreateFolder", "-----------------------" + result.getLogMessage());
+		assertTrue(result.isSuccess());
+	}
+	
+	public void testCreateFolderSpecialCharacters() {
+		String remotePath = "beta.owncloud.com/owncloud/test^^SpecialCharacters";
+		boolean createFullPath = true;
+		
+		RemoteOperationResult result =  mActivity.createFolder(remotePath, createFullPath);
+		assertTrue(result.isSuccess());
+	}
+
+
+}

+ 15 - 0
oc_framework-test-project/project.properties

@@ -0,0 +1,15 @@
+# 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
+android.library.reference.1=../oc_framework

二進制
oc_framework-test-project/res/drawable-hdpi/ic_launcher.png


二進制
oc_framework-test-project/res/drawable-mdpi/ic_launcher.png


二進制
oc_framework-test-project/res/drawable-xhdpi/ic_launcher.png


二進制
oc_framework-test-project/res/drawable-xxhdpi/ic_launcher.png


+ 16 - 0
oc_framework-test-project/res/layout/activity_test.xml

@@ -0,0 +1,16 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    tools:context=".TestActivity" >
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/hello_world" />
+
+</RelativeLayout>

+ 9 - 0
oc_framework-test-project/res/menu/test.xml

@@ -0,0 +1,9 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+    <item
+        android:id="@+id/action_settings"
+        android:orderInCategory="100"
+        android:showAsAction="never"
+        android:title="@string/action_settings"/>
+
+</menu>

+ 8 - 0
oc_framework-test-project/res/values-sw600dp/dimens.xml

@@ -0,0 +1,8 @@
+<resources>
+
+    <!--
+         Customize dimensions originally defined in res/values/dimens.xml (such as
+         screen margins) for sw600dp devices (e.g. 7" tablets) here.
+    -->
+
+</resources>

+ 9 - 0
oc_framework-test-project/res/values-sw720dp-land/dimens.xml

@@ -0,0 +1,9 @@
+<resources>
+
+    <!--
+         Customize dimensions originally defined in res/values/dimens.xml (such as
+         screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
+    -->
+    <dimen name="activity_horizontal_margin">128dp</dimen>
+
+</resources>

+ 11 - 0
oc_framework-test-project/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
oc_framework-test-project/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 7 - 0
oc_framework-test-project/res/values/dimens.xml

@@ -0,0 +1,7 @@
+<resources>
+
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">16dp</dimen>
+
+</resources>

+ 8 - 0
oc_framework-test-project/res/values/strings.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">oc_framework-test-project</string>
+    <string name="action_settings">Settings</string>
+    <string name="hello_world">Hello world!</string>
+
+</resources>

+ 20 - 0
oc_framework-test-project/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

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

@@ -0,0 +1,75 @@
+package com.owncloud.android.oc_framework_test_project;
+
+import java.io.IOException;
+import com.owncloud.android.oc_framework.authentication.AccountUtils.AccountNotFoundException;
+import com.owncloud.android.oc_framework.network.OwnCloudClientUtils;
+import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
+
+import android.os.Bundle;
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.AuthenticatorException;
+import android.accounts.OperationCanceledException;
+import android.app.Activity;
+import android.util.Log;
+import android.view.Menu;
+
+public class TestActivity extends Activity {
+	
+	private static final String TAG = "TestActivity";
+	
+	private Account mAccount;
+	private WebdavClient mClient;
+	
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_test);
+
+		String accountName = "admin@beta.owncloud.com";
+		String accountHost = "beta.owncloud.com";
+		String accountUser = "admin";
+		String accountPass = "owncloud42";
+		String accountType = "owncloud";	
+		String accountTypePass = "owncloud.password";
+		String authorities = "org.owncloud";
+
+		mAccount = new Account(accountName, accountType);
+		AccountManager am = AccountManager.get(this);
+		am.addAccountExplicitly(mAccount, accountPass, null);
+		
+
+		try {
+			mClient = OwnCloudClientUtils.createOwnCloudClient(mAccount, this.getApplicationContext(), authorities);
+		} catch (OperationCanceledException e) {
+			Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
+			e.printStackTrace();
+		} catch (AuthenticatorException e) {
+			Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
+			e.printStackTrace();
+		} catch (AccountNotFoundException e) {
+			Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
+			e.printStackTrace();
+		} catch (IOException e) {
+			Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
+			e.printStackTrace();
+		}
+	}
+
+	@Override
+	public boolean onCreateOptionsMenu(Menu menu) {
+		// Inflate the menu; this adds items to the action bar if it is present.
+		getMenuInflater().inflate(R.menu.test, menu);
+		return true;
+	}
+
+	public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
+		
+		CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath);
+		RemoteOperationResult result =  createOperation.execute(mClient);
+		
+		return result;
+	}
+}