OSDN Git Service

Fix TestCases
authorjruesga <jorge@ruesga.com>
Fri, 12 Oct 2012 11:00:38 +0000 (13:00 +0200)
committerjruesga <jorge@ruesga.com>
Fri, 12 Oct 2012 11:00:38 +0000 (13:00 +0200)
Still fails ExecCommandTest because we need a command to write content
in a file (the test script to execute). Now, we haven't permissions to
write to /data with standard java routines

27 files changed:
tests/src/com/cyanogenmod/explorer/commands/shell/AbstractConsoleTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/ChangeCurrentDirCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/ChangeOwnerCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/ChangePermissionsCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/CopyCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/CreateDirCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/CreateFileCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/CurrentDirCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/DeleteDirCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/DeleteFileCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/DiskUsageCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/EchoCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/ExecCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/FindCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/FolderUsageCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/GroupsCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/IdentityCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/LinkCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/ListCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/MountCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/MountPointInfoCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/MoveCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/ParentDirCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/ProcessIdCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/QuickFolderSearchCommandTest.java
tests/src/com/cyanogenmod/explorer/commands/shell/ResolveLinkCommandTest.java
tests/src/com/cyanogenmod/explorer/console/ConsoleBuilderTest.java

index 723d846..2157509 100644 (file)
@@ -19,13 +19,14 @@ package com.cyanogenmod.explorer.commands.shell;
 import com.cyanogenmod.explorer.console.Console;
 import com.cyanogenmod.explorer.console.ConsoleBuilder;
 import com.cyanogenmod.explorer.console.shell.ShellConsole;
+import com.cyanogenmod.explorer.util.FileHelper;
 
 /**
  * An abstract class that manages tests that needs a console.
  */
 public abstract class AbstractConsoleTest extends android.test.AndroidTestCase {
 
-    private static final String INITIAL_DIR = "/";  //$NON-NLS-1$
+    private static final String INITIAL_DIR = FileHelper.ROOT_DIRECTORY;
 
     private Console mConsole;
 
index c52dffd..99e3afa 100644 (file)
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.console.NoSuchFileOrDirectory;
 import com.cyanogenmod.explorer.util.CommandHelper;
+import com.cyanogenmod.explorer.util.FileHelper;
 
 /**
  * A class for testing the {@link ChangeCurrentDirCommand} command.
@@ -26,8 +29,8 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class ChangeCurrentDirCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_OK = "/"; //$NON-NLS-1$
-    private static final String PATH_ERROR = "/mnt/sdcard121212"; //$NON-NLS-1$
+    private static final String PATH_OK = FileHelper.ROOT_DIRECTORY;
+    private static final String PATH_ERROR = "/foo/foo121212"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
@@ -42,6 +45,7 @@ public class ChangeCurrentDirCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testChangeDirOk() throws Exception {
         boolean ret = CommandHelper.changeCurrentDir(getContext(), PATH_OK, getConsole());
         assertTrue("response==false", ret); //$NON-NLS-1$
@@ -58,6 +62,7 @@ public class ChangeCurrentDirCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testChangeDirFail() throws Exception {
         String oldPwd = CommandHelper.getCurrentDir(getContext(), getConsole());
         try {
index eb94b80..ecab562 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.model.FileSystemObject;
 import com.cyanogenmod.explorer.model.Group;
 import com.cyanogenmod.explorer.model.User;
@@ -28,7 +31,8 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class ChangeOwnerCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_FILE = "/data/chowntest.txt"; //$NON-NLS-1$
+    private static final String PATH_FILE =
+            Environment.getDataDirectory().getAbsolutePath() + "/chowntest.txt"; //$NON-NLS-1$
     private static final String NEW_GROUP = "graphics"; //$NON-NLS-1$
 
     /**
@@ -44,6 +48,7 @@ public class ChangeOwnerCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testChangeOwnerOk() throws Exception {
         try {
             //Create and list the file
index c9dfe43..b2af590 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.model.FileSystemObject;
 import com.cyanogenmod.explorer.model.Permissions;
 import com.cyanogenmod.explorer.util.CommandHelper;
@@ -27,7 +30,8 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class ChangePermissionsCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_FILE = "/data/chmodtest.txt"; //$NON-NLS-1$
+    private static final String PATH_FILE =
+            Environment.getDataDirectory().getAbsolutePath() + "/chmodtest.txt"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
@@ -42,6 +46,7 @@ public class ChangePermissionsCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testChangePermissionsOk() throws Exception {
         try {
             //Create and list the file
index 8aa4464..ede0b3e 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.util.CommandHelper;
 
 /**
@@ -25,15 +28,17 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class CopyCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_FILE_SRC = "/mnt/sdcard/copytest.txt"; //$NON-NLS-1$
-    private static final String PATH_FILE_DST = "/mnt/sdcard/copytest2.txt"; //$NON-NLS-1$
+    private static final String PATH_FILE_SRC =
+            Environment.getDataDirectory().getAbsolutePath() + "/copytest.txt"; //$NON-NLS-1$
+    private static final String PATH_FILE_DST =
+            Environment.getDataDirectory().getAbsolutePath() + "/copytest2.txt"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -41,6 +46,7 @@ public class CopyCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testCopyOk() throws Exception {
         try {
             CommandHelper.createFile(getContext(), PATH_FILE_SRC, getConsole());
index bea0438..00e9abe 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.console.NoSuchFileOrDirectory;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
@@ -26,15 +29,16 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class CreateDirCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_NEWDIR_OK = "/mnt/sdcard/newtestdir"; //$NON-NLS-1$
-    private static final String PATH_NEWDIR_ERROR = "/mnt/sdcard121212/newtestdir"; //$NON-NLS-1$
+    private static final String PATH_NEWDIR_OK =
+            Environment.getDataDirectory().getAbsolutePath() + "/newtestdir"; //$NON-NLS-1$
+    private static final String PATH_NEWDIR_ERROR = "/foo/foo121212/newtestdir"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -42,6 +46,7 @@ public class CreateDirCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testCreateDirOk() throws Exception {
         try {
             boolean ret = CommandHelper.createDirectory(getContext(), PATH_NEWDIR_OK, getConsole());
@@ -50,9 +55,7 @@ public class CreateDirCommandTest extends AbstractConsoleTest {
         } finally {
             try {
                 CommandHelper.deleteDirectory(getContext(), PATH_NEWDIR_OK, getConsole());
-            } catch (Throwable ex) {
-                /**NON BLOCK**/
-            }
+            } catch (Throwable ex) {/**NON BLOCK**/}
         }
     }
 
@@ -61,12 +64,17 @@ public class CreateDirCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testCreateDirFail() throws Exception {
         try {
             CommandHelper.createDirectory(getContext(), PATH_NEWDIR_ERROR, getConsole());
             assertTrue("exit code==0", false); //$NON-NLS-1$
         } catch (NoSuchFileOrDirectory error) {
           //This command must failed. exit code !=0
+        } finally {
+            try {
+                CommandHelper.deleteDirectory(getContext(), PATH_NEWDIR_ERROR, getConsole());
+            } catch (Throwable ex) {/**NON BLOCK**/}
         }
     }
 
index 1da9e18..192a40d 100644 (file)
 
 package com.cyanogenmod.explorer.commands.shell;
 
-import com.cyanogenmod.explorer.console.ExecutionException;
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.cyanogenmod.explorer.console.NoSuchFileOrDirectory;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
 /**
@@ -26,15 +29,16 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class CreateFileCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_NEWFILE_OK = "/mnt/sdcard/newtest.txt"; //$NON-NLS-1$
-    private static final String PATH_NEWFILE_ERROR = "/mnt/sdcard121212/newtest.txt"; //$NON-NLS-1$
+    private static final String PATH_NEWFILE_OK =
+            Environment.getDataDirectory().getAbsolutePath() + "/newtest.txt"; //$NON-NLS-1$
+    private static final String PATH_NEWFILE_ERROR = "/foo/foo121212/newtest.txt"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -42,6 +46,7 @@ public class CreateFileCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testCreateFileOk() throws Exception {
         try {
             boolean ret = CommandHelper.createFile(getContext(), PATH_NEWFILE_OK, getConsole());
@@ -60,12 +65,19 @@ public class CreateFileCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testCreateFileFail() throws Exception {
         try {
             CommandHelper.createFile(getContext(), PATH_NEWFILE_ERROR, getConsole());
             assertTrue("exit code==0", false); //$NON-NLS-1$
-        } catch (ExecutionException error) {
+        } catch (NoSuchFileOrDirectory error) {
           //This command must failed. exit code !=0
+        } finally {
+            try {
+                CommandHelper.deleteFile(getContext(), PATH_NEWFILE_ERROR, getConsole());
+            } catch (Throwable ex) {
+                /**NON BLOCK**/
+            }
         }
     }
 
index fe802c5..1e20199 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.util.CommandHelper;
 
 /**
@@ -25,7 +28,8 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class CurrentDirCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH = "/mnt/sdcard"; //$NON-NLS-1$
+    private static final String PATH =
+            Environment.getExternalStorageDirectory().getAbsolutePath();
 
     /**
      * {@inheritDoc}
@@ -40,6 +44,7 @@ public class CurrentDirCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testCurrentDir() throws Exception {
         CommandHelper.changeCurrentDir(getContext(), PATH, getConsole());
         String curDir = CommandHelper.getCurrentDir(getContext(), getConsole());
index ae0c3c9..816b4e1 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.console.NoSuchFileOrDirectory;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
@@ -26,15 +29,16 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class DeleteDirCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_DELDIR_OK = "/mnt/sdcard/deltestfolder"; //$NON-NLS-1$
-    private static final String PATH_DELDIR_ERROR = "/mnt/sdcard121212/deltestfolder"; //$NON-NLS-1$
+    private static final String PATH_DELDIR_OK =
+            Environment.getDataDirectory().getAbsolutePath() + "/deltestfolder"; //$NON-NLS-1$
+    private static final String PATH_DELDIR_ERROR = "/foo/foo121212/deltestfolder"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -42,10 +46,14 @@ public class DeleteDirCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testDeleteDirOk() throws Exception {
-        CommandHelper.createDirectory(getContext(), PATH_DELDIR_OK, getConsole());
-        boolean ret = CommandHelper.deleteDirectory(getContext(), PATH_DELDIR_OK, getConsole());
-        assertTrue("response==false", ret); //$NON-NLS-1$
+        try {
+            CommandHelper.createDirectory(getContext(), PATH_DELDIR_OK, getConsole());
+        } finally {
+            boolean ret = CommandHelper.deleteDirectory(getContext(), PATH_DELDIR_OK, getConsole());
+            assertTrue("response==false", ret); //$NON-NLS-1$
+        }
     }
 
     /**
@@ -53,6 +61,7 @@ public class DeleteDirCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testDeleteDirFail() throws Exception {
         try {
             CommandHelper.deleteDirectory(getContext(), PATH_DELDIR_ERROR, getConsole());
index 40081c3..2783fd8 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.console.NoSuchFileOrDirectory;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
@@ -26,15 +29,16 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class DeleteFileCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_DELFILE_OK = "/mnt/sdcard/deltest.txt"; //$NON-NLS-1$
-    private static final String PATH_DELFILE_ERROR = "/mnt/sdcard121212/deltest.txt"; //$NON-NLS-1$
+    private static final String PATH_DELFILE_OK =
+            Environment.getDataDirectory().getAbsolutePath() + "/deltest.txt"; //$NON-NLS-1$
+    private static final String PATH_DELFILE_ERROR = "/foo/foo121212/deltest.txt"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -42,6 +46,7 @@ public class DeleteFileCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testDeleteFileOk() throws Exception {
         CommandHelper.createFile(getContext(), PATH_DELFILE_OK, getConsole());
         boolean ret = CommandHelper.deleteFile(getContext(), PATH_DELFILE_OK, getConsole());
@@ -53,6 +58,7 @@ public class DeleteFileCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testDeleteFileFail() throws Exception {
         try {
             CommandHelper.deleteFile(getContext(), PATH_DELFILE_ERROR, getConsole());
index 95d710a..db4b5d4 100644 (file)
@@ -18,6 +18,8 @@ package com.cyanogenmod.explorer.commands.shell;
 
 import java.util.List;
 
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.model.DiskUsage;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
@@ -41,6 +43,7 @@ public class DiskUsageCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testDiskUsage() throws Exception {
         List<DiskUsage> du = CommandHelper.getDiskUsage(getContext(), getConsole());
         assertNotNull("diskusage==null", du); //$NON-NLS-1$
@@ -54,6 +57,7 @@ public class DiskUsageCommandTest extends AbstractConsoleTest {
      * {@link ListCommand#parse(String, String)}
      */
     @SuppressWarnings("static-method")
+    @SmallTest
     public void testParse() throws Exception {
         DiskUsageCommand cmd = new DiskUsageCommand();
         String in = "Filesystem             Size   Used   Free   Blksize\n" + //$NON-NLS-1$
index 6f1629a..cf3f118 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.util.CommandHelper;
 
 /**
@@ -42,6 +44,7 @@ public class EchoCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testEchoOk() throws Exception {
         String echo = CommandHelper.getVariable(getContext(), ECHO_MSG, getConsole());
         assertNotNull("echo==null", echo); //$NON-NLS-1$
@@ -53,6 +56,7 @@ public class EchoCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testEchoVoid() throws Exception {
         String echo = CommandHelper.getVariable(getContext(), ECHO_MSG_VOID, getConsole());
         assertNotNull("exitCode==null", echo); //$NON-NLS-1$
index 5a9d629..d675423 100644 (file)
@@ -19,6 +19,9 @@ package com.cyanogenmod.explorer.commands.shell;
 import java.io.File;
 import java.io.FileWriter;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.MediumTest;
+
 import com.cyanogenmod.explorer.commands.AsyncResultListener;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
@@ -29,7 +32,8 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class ExecCommandTest extends AbstractConsoleTest {
 
-    private static final String EXEC_CMD = "/sdcard/source.sh"; //$NON-NLS-1$
+    private static final String EXEC_CMD =
+            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$
 
@@ -55,6 +59,7 @@ public class ExecCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @MediumTest
     public void testExecWithPartialResult() throws Exception {
         try {
             // Create the test program
@@ -68,7 +73,7 @@ public class ExecCommandTest extends AbstractConsoleTest {
                 public void onAsyncStart() {
                     /**NON BLOCK**/
                 }
-                public void onAsyncEnd(boolean cancelled) {
+                public void onAsyncEnd(boolean canceled) {
                     synchronized (ExecCommandTest.this.mSync) {
                         ExecCommandTest.this.mSync.notifyAll();
                     }
index e382292..978772c 100644 (file)
@@ -19,6 +19,10 @@ package com.cyanogenmod.explorer.commands.shell;
 import java.util.ArrayList;
 import java.util.List;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import com.cyanogenmod.explorer.commands.AsyncResultExecutable;
 import com.cyanogenmod.explorer.commands.AsyncResultListener;
 import com.cyanogenmod.explorer.model.FileSystemObject;
 import com.cyanogenmod.explorer.model.Query;
@@ -31,8 +35,9 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class FindCommandTest extends AbstractConsoleTest {
 
-    private static final String FIND_PATH = "/"; //$NON-NLS-1$
-    private static final String FIND_TERM_PARTIAL = "xml"; //$NON-NLS-1$
+    private static final String FIND_PATH =
+            Environment.getDataDirectory().getAbsolutePath();
+    private static final String FIND_TERM_PARTIAL = "shared"; //$NON-NLS-1$
 
     /**
      * @hide
@@ -42,13 +47,17 @@ public class FindCommandTest extends AbstractConsoleTest {
      * @hide
      */
     boolean mNewPartialData;
+    /**
+     * @hide
+     */
+    boolean mNormalEnd;
 
     /**
      * {@inheritDoc}
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -56,16 +65,20 @@ public class FindCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @LargeTest
     public void testFindWithPartialResult() throws Exception {
         this.mNewPartialData = false;
+        this.mNormalEnd = false;
         Query query = new Query().setSlot(FIND_TERM_PARTIAL, 0);
         final List<FileSystemObject> files = new ArrayList<FileSystemObject>();
-        CommandHelper.findFiles(getContext(), FIND_PATH, query, new AsyncResultListener() {
+        AsyncResultExecutable cmd =
+                CommandHelper.findFiles(getContext(), FIND_PATH, query, new AsyncResultListener() {
                         public void onAsyncStart() {
                             /**NON BLOCK**/
                         }
-                        public void onAsyncEnd(boolean cancelled) {
+                        public void onAsyncEnd(boolean canceled) {
                             synchronized (FindCommandTest.this.mSync) {
+                                FindCommandTest.this.mNormalEnd = true;
                                 FindCommandTest.this.mSync.notifyAll();
                             }
                         }
@@ -81,6 +94,11 @@ public class FindCommandTest extends AbstractConsoleTest {
         synchronized (FindCommandTest.this.mSync) {
             FindCommandTest.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("files==null", files); //$NON-NLS-1$
         assertTrue("no objects returned", files.size() > 0); //$NON-NLS-1$
index a41617c..c028aac 100644 (file)
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.LargeTest;
 import android.util.Log;
 
+import com.cyanogenmod.explorer.commands.AsyncResultExecutable;
 import com.cyanogenmod.explorer.commands.AsyncResultListener;
 import com.cyanogenmod.explorer.model.FolderUsage;
 import com.cyanogenmod.explorer.util.CommandHelper;
@@ -26,13 +29,14 @@ import com.cyanogenmod.explorer.util.MimeTypeHelper.MimeTypeCategory;
 /**
  * A class for testing folder usage command.
  *
- * @see FindCommand
+ * @see FolderUsageCommand
  */
 public class FolderUsageCommandTest extends AbstractConsoleTest {
 
     private static final String TAG = "FolderUsageCommandTest"; //$NON-NLS-1$
 
-    private static final String PATH = "/system"; //$NON-NLS-1$
+    private static final String PATH =
+            Environment.getDataDirectory().getAbsolutePath() + "/app"; //$NON-NLS-1$
 
     /**
      * @hide
@@ -45,6 +49,10 @@ public class FolderUsageCommandTest extends AbstractConsoleTest {
     /**
      * @hide
      */
+    boolean mNormalEnd;
+    /**
+     * @hide
+     */
     FolderUsage mUsage;
 
     /**
@@ -52,7 +60,7 @@ public class FolderUsageCommandTest extends AbstractConsoleTest {
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -60,15 +68,19 @@ public class FolderUsageCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @LargeTest
     public void testFolderUsageWithPartialResult() throws Exception {
         this.mNewPartialData = false;
+        this.mNormalEnd = false;
         this.mUsage = null;
-        CommandHelper.getFolderUsage(getContext(), PATH, new AsyncResultListener() {
+        AsyncResultExecutable cmd =
+                CommandHelper.getFolderUsage(getContext(), PATH, new AsyncResultListener() {
                         public void onAsyncStart() {
                             /**NON BLOCK**/
                         }
-                        public void onAsyncEnd(boolean cancelled) {
+                        public void onAsyncEnd(boolean canceled) {
                             synchronized (FolderUsageCommandTest.this.mSync) {
+                                FolderUsageCommandTest.this.mNormalEnd = true;
                                 FolderUsageCommandTest.this.mSync.notifyAll();
                             }
                         }
@@ -85,15 +97,19 @@ public class FolderUsageCommandTest extends AbstractConsoleTest {
                         }
                    }, getConsole());
         synchronized (FolderUsageCommandTest.this.mSync) {
-            FolderUsageCommandTest.this.mSync.wait(25000L);
+            FolderUsageCommandTest.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("usage==null", this.mUsage); //$NON-NLS-1$
-        assertTrue("no folder returned", this.mUsage.getNumberOfFolders() > 0); //$NON-NLS-1$
         assertTrue("no files returned", this.mUsage.getNumberOfFiles() > 0); //$NON-NLS-1$
         assertTrue("no size returned", this.mUsage.getTotalSize() > 0); //$NON-NLS-1$
         assertTrue("no text category returned", //$NON-NLS-1$
-                this.mUsage.getStatisticsForCategory(MimeTypeCategory.TEXT) > 0);
+                this.mUsage.getStatisticsForCategory(MimeTypeCategory.APP) > 0);
     }
 
 }
index 52a176f..e5982ea 100644 (file)
@@ -18,6 +18,8 @@ package com.cyanogenmod.explorer.commands.shell;
 
 import java.util.List;
 
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.model.Group;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
@@ -41,6 +43,7 @@ public class GroupsCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testGroups() throws Exception {
         List<Group> groups = CommandHelper.getGroups(getContext(), getConsole());
         assertNotNull("groups==null", groups); //$NON-NLS-1$
@@ -54,6 +57,7 @@ public class GroupsCommandTest extends AbstractConsoleTest {
      * {@link GroupsCommand#parse(String, String)}
      */
     @SuppressWarnings("static-method")
+    @SmallTest
     public void testParse() throws Exception {
         GroupsCommand cmd = new GroupsCommand();
         String in =
index bc413ef..857fe9c 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.model.Identity;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
@@ -39,6 +41,7 @@ public class IdentityCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testId() throws Exception {
         Identity identity = CommandHelper.getIdentity(getContext(), getConsole());
         assertNotNull("identity==null", identity); //$NON-NLS-1$
@@ -55,6 +58,7 @@ public class IdentityCommandTest extends AbstractConsoleTest {
      * {@link IdentityCommand#parse(String, String)}
      */
     @SuppressWarnings("static-method")
+    @SmallTest
     public void testParse() throws Exception {
         IdentityCommand cmd = new IdentityCommand();
         String in = "uid=2000(shell) gid=2000(shell2) groups=1003(graphics)," //$NON-NLS-1$
index f8ef322..2e0281b 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.console.InsufficientPermissionsException;
 import com.cyanogenmod.explorer.model.FileSystemObject;
 import com.cyanogenmod.explorer.model.Symlink;
@@ -28,10 +31,16 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class LinkCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_SOURCE_OK = "/data/source.txt"; //$NON-NLS-1$
-    private static final String PATH_LINK_OK = "/data/source-link"; //$NON-NLS-1$
-    private static final String PATH_SOURCE_ERROR = "/sdcard/source.txt"; //$NON-NLS-1$
-    private static final String PATH_LINK_ERROR = "/sdcard/source-link"; //$NON-NLS-1$
+    private static final String PATH_SOURCE_OK =
+            Environment.getDataDirectory().getAbsolutePath() + "/source.txt"; //$NON-NLS-1$
+    private static final String PATH_LINK_OK =
+            Environment.getDataDirectory().getAbsolutePath() + "/source-link"; //$NON-NLS-1$
+    private static final String PATH_SOURCE_ERROR =
+            Environment.getExternalStorageDirectory().getAbsolutePath() +
+            "/source.txt"; //$NON-NLS-1$
+    private static final String PATH_LINK_ERROR =
+            Environment.getExternalStorageDirectory().getAbsolutePath() +
+            "/source-link"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
@@ -46,6 +55,7 @@ public class LinkCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testCreateSymlinkOk() throws Exception {
         try {
             CommandHelper.createFile(getContext(), PATH_SOURCE_OK, getConsole());
@@ -70,6 +80,7 @@ public class LinkCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testCreateSymlinkFail() throws Exception {
         try {
             CommandHelper.createFile(getContext(), PATH_SOURCE_ERROR, getConsole());
index 79b5aa1..891d817 100644 (file)
@@ -18,6 +18,9 @@ package com.cyanogenmod.explorer.commands.shell;
 
 import java.util.List;
 
+import android.test.suitebuilder.annotation.MediumTest;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.model.BlockDevice;
 import com.cyanogenmod.explorer.model.CharacterDevice;
 import com.cyanogenmod.explorer.model.Directory;
@@ -27,6 +30,7 @@ import com.cyanogenmod.explorer.model.NamedPipe;
 import com.cyanogenmod.explorer.model.RegularFile;
 import com.cyanogenmod.explorer.model.Symlink;
 import com.cyanogenmod.explorer.util.CommandHelper;
+import com.cyanogenmod.explorer.util.FileHelper;
 
 /**
  * A class for testing list command.
@@ -35,7 +39,7 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class ListCommandTest extends AbstractConsoleTest {
 
-    private static final String LS_PATH = "/"; //$NON-NLS-1$
+    private static final String LS_PATH = FileHelper.ROOT_DIRECTORY;
     private static final String LS_INFOFILE = "/boot.txt"; //$NON-NLS-1$
     private static final String LS_INFOFILE_NAME = "boot.txt"; //$NON-NLS-1$
 
@@ -53,6 +57,7 @@ public class ListCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @MediumTest
     public void testList() throws Exception {
         List<FileSystemObject> files = CommandHelper.listFiles(getContext(), LS_PATH, getConsole());
         assertNotNull("files==null", files); //$NON-NLS-1$
@@ -65,6 +70,7 @@ public class ListCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @MediumTest
     public void testListInfo() throws Exception {
         FileSystemObject file = CommandHelper.getFileInfo(getContext(), LS_INFOFILE, getConsole());
         assertNotNull("file==null", file); //$NON-NLS-1$
@@ -79,6 +85,7 @@ public class ListCommandTest extends AbstractConsoleTest {
      * @throws Exception If test failed
      * {@link ListCommand#parse(String, String)}
      */
+    @SmallTest
     public void testParse() throws Exception {
         ListCommand cmd = new ListCommand(LS_PATH, getConsole());
         String in =
index f3cbc7d..48465e0 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.test.suitebuilder.annotation.MediumTest;
+
 import com.cyanogenmod.explorer.model.MountPoint;
 import com.cyanogenmod.explorer.util.CommandHelper;
 import com.cyanogenmod.explorer.util.MountPointHelper;
@@ -42,6 +44,7 @@ public class MountCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @MediumTest
     public void testRemountOk() throws Exception {
         MountPoint mp = MountPointHelper.getMountPointFromDirectory(getConsole(), MOUNT_POINT_DIR);
         boolean rw = MountPointHelper.isReadWrite(mp);
index edf6f9a..674ad2a 100644 (file)
@@ -18,6 +18,8 @@ package com.cyanogenmod.explorer.commands.shell;
 
 import java.util.List;
 
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.model.MountPoint;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
@@ -41,6 +43,7 @@ public class MountPointInfoCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testMountPoint() throws Exception {
         List<MountPoint> mp = CommandHelper.getMountPoints(getContext(), getConsole());
         assertNotNull("mountpoints==null", mp); //$NON-NLS-1$
@@ -54,6 +57,7 @@ public class MountPointInfoCommandTest extends AbstractConsoleTest {
      * {@link ListCommand#parse(String, String)}
      */
     @SuppressWarnings("static-method")
+    @SmallTest
     public void testParse() throws Exception {
         MountPointInfoCommand cmd = new MountPointInfoCommand();
         String in = "rootfs / rootfs ro,relatime 0 0\n" + //$NON-NLS-1$
index 782e666..5bb5621 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.util.CommandHelper;
 
 /**
@@ -25,15 +28,17 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class MoveCommandTest extends AbstractConsoleTest {
 
-    private static final String PATH_FILE_SRC = "/mnt/sdcard/movetest.txt"; //$NON-NLS-1$
-    private static final String PATH_FILE_DST = "/mnt/sdcard/movetest2.txt"; //$NON-NLS-1$
+    private static final String PATH_FILE_SRC =
+            Environment.getDataDirectory().getAbsolutePath() + "/movetest.txt"; //$NON-NLS-1$
+    private static final String PATH_FILE_DST =
+            Environment.getDataDirectory().getAbsolutePath() + "/movetest2.txt"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -41,6 +46,7 @@ public class MoveCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testMoveOk() throws Exception {
         try {
             CommandHelper.createFile(getContext(), PATH_FILE_SRC, getConsole());
index f42a969..9717e7e 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.util.CommandHelper;
 
 /**
@@ -25,15 +28,16 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class ParentDirCommandTest extends AbstractConsoleTest {
 
-    private static final String FILE = "/mnt/sdcard/parentdirtest.txt"; //$NON-NLS-1$
-    private static final String PARENT = "/mnt/sdcard"; //$NON-NLS-1$
+    private static final String FILE =
+            Environment.getDataDirectory().getAbsolutePath() + "/parentdirtest.txt"; //$NON-NLS-1$
+    private static final String PARENT = Environment.getDataDirectory().getAbsolutePath();
 
     /**
      * {@inheritDoc}
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -41,6 +45,7 @@ public class ParentDirCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testParentDirOk() throws Exception {
         try {
             CommandHelper.createFile(getContext(), FILE, getConsole());
@@ -50,7 +55,11 @@ public class ParentDirCommandTest extends AbstractConsoleTest {
                     String.format(
                             "parent!=%s", PARENT), parent.compareTo(PARENT) == 0); //$NON-NLS-1$
         } finally {
-            CommandHelper.deleteFile(getContext(), FILE, getConsole());
+            try {
+                CommandHelper.deleteFile(getContext(), FILE, getConsole());
+            } catch (Throwable ex) {
+                /**NON BLOCK**/
+            }
         }
     }
 
index 6196690..0e4818b 100644 (file)
@@ -30,6 +30,6 @@ public class ProcessIdCommandTest extends AbstractConsoleTest {
         return false;
     }
 
-    // Can't perform any test, because a running program in a shell is needed, and PID of
-    // shell is not available for external use outside the console.
+    // Can't perform any test, because a running program in a shell is needed, and the PID of
+    // the shell is not available for external use outside the console.
 }
index 6009f1e..14e3f01 100644 (file)
@@ -18,6 +18,9 @@ package com.cyanogenmod.explorer.commands.shell;
 
 import java.util.List;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.LargeTest;
+
 import com.cyanogenmod.explorer.util.CommandHelper;
 
 /**
@@ -27,15 +30,17 @@ import com.cyanogenmod.explorer.util.CommandHelper;
  */
 public class QuickFolderSearchCommandTest extends AbstractConsoleTest {
 
-    private static final String SEARCH_EXPRESSION = "/mnt/sdcard/And"; //$NON-NLS-1$
-    private static final String SEARCH_FOLDER = "/mnt/sdcard/Android/"; //$NON-NLS-1$
+    private static final String SEARCH_EXPRESSION =
+            Environment.getDataDirectory().getAbsolutePath() + "/dal"; //$NON-NLS-1$
+    private static final String SEARCH_CONTAINS =
+            Environment.getDataDirectory().getAbsolutePath() + "/dalvik-cache/"; //$NON-NLS-1$
 
     /**
      * {@inheritDoc}
      */
     @Override
     public boolean isRootConsoleNeeded() {
-        return false;
+        return true;
     }
 
     /**
@@ -43,14 +48,15 @@ public class QuickFolderSearchCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @LargeTest
     public void testQuickFolderSearchOk() throws Exception {
         List<String> result =
                 CommandHelper.quickFolderSearch(getContext(), SEARCH_EXPRESSION, getConsole());
         assertNotNull("result==null", result); //$NON-NLS-1$
         assertTrue("result.size==0", result.size() != 0); //$NON-NLS-1$
         assertTrue(
-                String.format("result not contains %s", SEARCH_FOLDER), //$NON-NLS-1$
-                result.contains(SEARCH_FOLDER));
+                String.format("result not contains %s", SEARCH_CONTAINS), //$NON-NLS-1$
+                result.contains(SEARCH_CONTAINS));
     }
 
 }
index 2065065..e0685c8 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.cyanogenmod.explorer.commands.shell;
 
+import android.test.suitebuilder.annotation.SmallTest;
+
 import com.cyanogenmod.explorer.model.FileSystemObject;
 import com.cyanogenmod.explorer.util.CommandHelper;
 
@@ -42,6 +44,7 @@ public class ResolveLinkCommandTest extends AbstractConsoleTest {
      *
      * @throws Exception If test failed
      */
+    @SmallTest
     public void testReadLinkOk() throws Exception {
         FileSystemObject fso = CommandHelper.resolveSymlink(getContext(), LINK, getConsole());
         assertNotNull("fso==null)", fso); //$NON-NLS-1$
index dd9bcca..2b5d124 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.cyanogenmod.explorer.console;
 
+import android.os.Environment;
+import android.test.suitebuilder.annotation.SmallTest;
+
 
 /**
  * A class for testing list command.
@@ -24,7 +27,8 @@ package com.cyanogenmod.explorer.console;
  */
 public class ConsoleBuilderTest extends android.test.AndroidTestCase {
 
-    private static final String PATH = "/mnt/sdcard"; //$NON-NLS-1$
+    private static final String PATH =
+            Environment.getExternalStorageDirectory().getAbsolutePath();
 
     /**
      * {@inheritDoc}
@@ -48,6 +52,7 @@ public class ConsoleBuilderTest extends android.test.AndroidTestCase {
      * @throws Exception If test failed
      * @{link {@link ConsoleBuilder#createPrivilegedConsole(android.content.Context, String)}
      */
+    @SmallTest
     public void testCreatePrivilegedConsole() throws Exception {
         Console console = ConsoleBuilder.createPrivilegedConsole(getContext(), PATH);
         try {
@@ -67,6 +72,7 @@ public class ConsoleBuilderTest extends android.test.AndroidTestCase {
      * @throws Exception If test failed
      * @{link {@link ConsoleBuilder#createNonPrivilegedConsole(android.content.Context, String)}
      */
+    @SmallTest
     public void testCreateNonPrivilegedConsole() throws Exception {
         Console console = ConsoleBuilder.createNonPrivilegedConsole(getContext(), PATH);
         try {