aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorjruesga <jorge@ruesga.com>2012-10-13 23:13:02 +0200
committerjruesga <jorge@ruesga.com>2012-10-13 23:13:02 +0200
commit2d7b380448e3843a3949b6f08fba06bb0a4b86a7 (patch)
tree1967f6e106ed198a5b35afcbbc2adaed65966f8d /tests/src
parentdc925f72d8829093e9c0f93721b9f07a3e9d7ce9 (diff)
downloadandroid_packages_apps_CMFileManager-2d7b380448e3843a3949b6f08fba06bb0a4b86a7.tar.gz
android_packages_apps_CMFileManager-2d7b380448e3843a3949b6f08fba06bb0a4b86a7.tar.bz2
android_packages_apps_CMFileManager-2d7b380448e3843a3949b6f08fba06bb0a4b86a7.zip
Various: new commands and buffer management
* Change default buffer to 4096 * New commands: Read, send signal, terminate and write * Background console now change to privileged when foreground console is or change to privileged * Fix cancel asynchronous programs launched on privileged consoles (non-privileged background console is not able to kill or signal) * Fix root directory default * Allow send signal and terminate, in addition to cancel, for AsyncResultExecutable programs * Passing console trace status to commands (allow programs to use user preference) * Allow to programs to access the stdout to respond to programs (xe: write to stdin of dd). * Fix ResolveLinkCommand when src is the root directory * Remove check of error code in checkStdErr of the shell. Determine the errors based on the returned text. Error code is not necessary because the check is over stderr, not stdin. * Create separate methods for create privileged console (one with no check and other for check and change to non-privileged on error) * Fix detection of start of program on Shell * No send string controls to asynchronous programs on parsePartial method (cut buffers prior to invoke) * Create static method on Permissions to load from raw and octals strings. * Fix disk usage and mount point info when no background console is available * Fix test app name. Changed to CMExplorerTest * Fix exec test, once there are a write command. Now write the shell program and execute to check results.
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/AbstractConsoleTest.java2
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/ExecCommandTest.java25
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/FindCommandTest.java4
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/FolderUsageCommandTest.java4
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/ReadCommandTest.java102
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/SendSignalCommandTest.java34
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/WriteCommandTest.java120
7 files changed, 280 insertions, 11 deletions
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/AbstractConsoleTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/AbstractConsoleTest.java
index 21575091..d5ead37e 100644
--- a/tests/src/com/cyanogenmod/explorer/commands/shell/AbstractConsoleTest.java
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/AbstractConsoleTest.java
@@ -16,6 +16,7 @@
package com.cyanogenmod.explorer.commands.shell;
+import com.cyanogenmod.explorer.ExplorerApplication;
import com.cyanogenmod.explorer.console.Console;
import com.cyanogenmod.explorer.console.ConsoleBuilder;
import com.cyanogenmod.explorer.console.shell.ShellConsole;
@@ -44,6 +45,7 @@ public abstract class AbstractConsoleTest extends android.test.AndroidTestCase {
protected void setUp() throws Exception {
//Setup the console
if (isRootConsoleNeeded()) {
+ ExplorerApplication.changeBackgroundConsoleToPriviligedConsole();
this.mConsole = ConsoleBuilder.createPrivilegedConsole(getContext(), INITIAL_DIR);
} else {
this.mConsole = ConsoleBuilder.createNonPrivilegedConsole(getContext(), INITIAL_DIR);
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/ExecCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/ExecCommandTest.java
index d6754236..580288f4 100644
--- a/tests/src/com/cyanogenmod/explorer/commands/shell/ExecCommandTest.java
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/ExecCommandTest.java
@@ -16,13 +16,14 @@
package com.cyanogenmod.explorer.commands.shell;
-import java.io.File;
-import java.io.FileWriter;
+import java.io.OutputStream;
import android.os.Environment;
import android.test.suitebuilder.annotation.MediumTest;
import com.cyanogenmod.explorer.commands.AsyncResultListener;
+import com.cyanogenmod.explorer.commands.WriteExecutable;
+import com.cyanogenmod.explorer.model.Permissions;
import com.cyanogenmod.explorer.util.CommandHelper;
/**
@@ -36,6 +37,7 @@ public class ExecCommandTest extends AbstractConsoleTest {
Environment.getDataDirectory().getAbsolutePath() + "/source.sh"; //$NON-NLS-1$
private static final String EXEC_PROGRAM =
"#!/system/bin/sh\necho \"List of files:\"\nls -la\n"; //$NON-NLS-1$
+ private static final String EXEC_CMD_PERMISSIONS = "0755"; //$NON-NLS-1$
/**
* @hide
@@ -63,9 +65,18 @@ public class ExecCommandTest extends AbstractConsoleTest {
public void testExecWithPartialResult() throws Exception {
try {
// Create the test program
- FileWriter fw = new FileWriter(new File(EXEC_CMD));
- fw.write(EXEC_PROGRAM);
- fw.close();
+ WriteExecutable writeCmd =
+ CommandHelper.write(getContext(), EXEC_CMD, null, getConsole());
+ OutputStream os = writeCmd.createOutputStream();
+ os.write(EXEC_PROGRAM.getBytes());
+ writeCmd.end();
+
+ // Enable execute permission
+ CommandHelper.changePermissions(
+ getContext(),
+ EXEC_CMD,
+ Permissions.fromOctalString(EXEC_CMD_PERMISSIONS),
+ getConsole());
// Execute the test program
this.mNewPartialData = false;
@@ -75,11 +86,11 @@ public class ExecCommandTest extends AbstractConsoleTest {
}
public void onAsyncEnd(boolean canceled) {
synchronized (ExecCommandTest.this.mSync) {
- ExecCommandTest.this.mSync.notifyAll();
+ ExecCommandTest.this.mSync.notify();
}
}
public void onException(Exception cause) {
- fail(cause.toString());
+ fail(String.valueOf(cause));
}
public void onPartialResult(Object results) {
ExecCommandTest.this.mNewPartialData = true;
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/FindCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/FindCommandTest.java
index 978772c6..ec24076f 100644
--- a/tests/src/com/cyanogenmod/explorer/commands/shell/FindCommandTest.java
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/FindCommandTest.java
@@ -79,11 +79,11 @@ public class FindCommandTest extends AbstractConsoleTest {
public void onAsyncEnd(boolean canceled) {
synchronized (FindCommandTest.this.mSync) {
FindCommandTest.this.mNormalEnd = true;
- FindCommandTest.this.mSync.notifyAll();
+ FindCommandTest.this.mSync.notify();
}
}
public void onException(Exception cause) {
- fail(cause.toString());
+ fail(String.valueOf(cause));
}
@SuppressWarnings("unchecked")
public void onPartialResult(Object results) {
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/FolderUsageCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/FolderUsageCommandTest.java
index c028aac8..018fa537 100644
--- a/tests/src/com/cyanogenmod/explorer/commands/shell/FolderUsageCommandTest.java
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/FolderUsageCommandTest.java
@@ -81,11 +81,11 @@ public class FolderUsageCommandTest extends AbstractConsoleTest {
public void onAsyncEnd(boolean canceled) {
synchronized (FolderUsageCommandTest.this.mSync) {
FolderUsageCommandTest.this.mNormalEnd = true;
- FolderUsageCommandTest.this.mSync.notifyAll();
+ FolderUsageCommandTest.this.mSync.notify();
}
}
public void onException(Exception cause) {
- fail(cause.toString());
+ fail(String.valueOf(cause));
}
public void onPartialResult(Object result) {
FolderUsageCommandTest.this.mNewPartialData = true;
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/ReadCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/ReadCommandTest.java
new file mode 100644
index 00000000..bb54aa0f
--- /dev/null
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/ReadCommandTest.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.explorer.commands.shell;
+
+import android.test.suitebuilder.annotation.MediumTest;
+import android.util.Log;
+
+import com.cyanogenmod.explorer.commands.AsyncResultExecutable;
+import com.cyanogenmod.explorer.commands.AsyncResultListener;
+import com.cyanogenmod.explorer.util.CommandHelper;
+
+/**
+ * A class for testing read command.
+ *
+ * @see ReadCommand
+ */
+public class ReadCommandTest extends AbstractConsoleTest {
+
+ private static final String TAG = "ReadCommandTest"; //$NON-NLS-1$
+
+ private static final String READ_FILE = "/boot.txt"; //$NON-NLS-1$
+
+ /**
+ * @hide
+ */
+ final Object mSync = new Object();
+ /**
+ * @hide
+ */
+ boolean mNewPartialData;
+ /**
+ * @hide
+ */
+ boolean mNormalEnd;
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isRootConsoleNeeded() {
+ return true;
+ }
+
+ /**
+ * Method that performs a read of a file
+ *
+ * @throws Exception If an exception occurs while executing the test
+ */
+ @MediumTest
+ public void testReadWithPartialResult() throws Exception {
+ this.mNewPartialData = false;
+ this.mNormalEnd = false;
+ final StringBuffer sb = new StringBuffer();
+ AsyncResultExecutable cmd =
+ CommandHelper.read(getContext(), READ_FILE, new AsyncResultListener() {
+ public void onAsyncStart() {
+ /**NON BLOCK**/
+ }
+ public void onAsyncEnd(boolean canceled) {
+ synchronized (ReadCommandTest.this.mSync) {
+ ReadCommandTest.this.mNormalEnd = true;
+ ReadCommandTest.this.mSync.notify();
+ }
+ }
+ public void onException(Exception cause) {
+ fail(String.valueOf(cause));
+ }
+ public void onPartialResult(Object results) {
+ ReadCommandTest.this.mNewPartialData = true;
+ sb.append(new String((byte[])results));
+ }
+ }, getConsole());
+ synchronized (ReadCommandTest.this.mSync) {
+ ReadCommandTest.this.mSync.wait(15000L);
+ }
+ try {
+ if (!this.mNormalEnd && cmd != null && cmd.isCancelable() && !cmd.isCanceled()) {
+ cmd.cancel();
+ }
+ } catch (Exception e) {/**NON BLOCK**/}
+ assertTrue("no new partial data", this.mNewPartialData); //$NON-NLS-1$
+ assertNotNull("sb==null", sb); //$NON-NLS-1$
+ Log.v(TAG, String.format("read data: %s", sb.toString())); //$NON-NLS-1$
+ assertTrue("read.size > 0", sb.length() > 0); //$NON-NLS-1$
+ }
+
+}
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/SendSignalCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/SendSignalCommandTest.java
new file mode 100644
index 00000000..83a8ccfc
--- /dev/null
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/SendSignalCommandTest.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.explorer.commands.shell;
+/**
+ * A class for testing the {@link SendSignalCommand} command.
+ *
+ * @see SendSignalCommand
+ */
+public class SendSignalCommandTest extends AbstractConsoleTest {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isRootConsoleNeeded() {
+ return false;
+ }
+
+ // Can't perform any test, because a running program in a shell is needed.
+}
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/WriteCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/WriteCommandTest.java
new file mode 100644
index 00000000..a0626ab9
--- /dev/null
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/WriteCommandTest.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.explorer.commands.shell;
+
+import java.io.OutputStream;
+import java.util.Random;
+
+import android.os.Environment;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.cyanogenmod.explorer.commands.AsyncResultListener;
+import com.cyanogenmod.explorer.commands.WriteExecutable;
+import com.cyanogenmod.explorer.util.CommandHelper;
+
+/**
+ * A class for testing write command.
+ *
+ * @see WriteCommand
+ */
+public class WriteCommandTest extends AbstractConsoleTest {
+
+ private static final String WRITE_FILE_SMALL =
+ Environment.getDataDirectory().getAbsolutePath() + "/write-test-s.txt"; //$NON-NLS-1$
+ private static final String WRITE_FILE_LARGE =
+ Environment.getDataDirectory().getAbsolutePath() + "/write-test-l.txt"; //$NON-NLS-1$
+ private static final byte[] TEST_DATA = new byte[]{(byte)33, (byte)36, '\n'};
+
+ private static final int DATA_SIZE = 4096;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isRootConsoleNeeded() {
+ return true;
+ }
+
+ /**
+ * Method that performs a small write test.
+ *
+ * @throws Exception If an exception occurs while executing the test
+ */
+ @SmallTest
+ public void testSmallWriteWithPartialResult() throws Exception {
+ try {
+ WriteExecutable cmd =
+ CommandHelper.write(getContext(),
+ WRITE_FILE_SMALL, new AsyncResultListener() {
+ public void onAsyncStart() {/**NON BLOCK**/}
+ public void onAsyncEnd(boolean canceled) {/**NON BLOCK**/}
+ public void onException(Exception cause) {
+ fail(String.valueOf(cause));
+ }
+ public void onPartialResult(Object results) {/**NON BLOCK**/}
+ }, getConsole());
+ OutputStream os = cmd.createOutputStream();
+ os.write(TEST_DATA, 0, TEST_DATA.length);
+ cmd.end();
+
+ // Wait for allow close all instrumentation data
+ Thread.sleep(2500L);
+ } finally {
+ try {
+ CommandHelper.deleteFile(getContext(), WRITE_FILE_SMALL, getConsole());
+ } catch (Exception e) {/**NON BLOCK**/}
+ }
+ }
+
+ /**
+ * Method that performs a large write test.
+ *
+ * @throws Exception If an exception occurs while executing the test
+ */
+ @LargeTest
+ public void testLargeWriteWithPartialResult() throws Exception {
+ try {
+ WriteExecutable cmd =
+ CommandHelper.write(getContext(),
+ WRITE_FILE_LARGE, new AsyncResultListener() {
+ public void onAsyncStart() {/**NON BLOCK**/}
+ public void onAsyncEnd(boolean canceled) {/**NON BLOCK**/}
+ public void onException(Exception cause) {
+ fail(String.valueOf(cause));
+ }
+ public void onPartialResult(Object results) {/**NON BLOCK**/}
+ }, getConsole());
+ OutputStream os = cmd.createOutputStream();
+ Random random = new Random();
+ for (int i = 0; i < 50; i++) {
+ byte[] data = new byte[DATA_SIZE];
+ random.nextBytes(data);
+ os.write(data, 0, data.length);
+ }
+ cmd.end();
+
+ // Wait for allow close all instrumentation data
+ Thread.sleep(2500L);
+ } finally {
+ try {
+ CommandHelper.deleteFile(getContext(), WRITE_FILE_LARGE, getConsole());
+ } catch (Exception e) {/**NON BLOCK**/}
+ }
+ }
+
+}