[Ngms-svn] SVN-Commit: [104] [NMShell] add test suite for mkdir

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2010年 1月 28日 (木) 17:56:29 JST


Revision: 104
          http://sourceforge.jp/projects/ngms/svn/view?view=rev&revision=104
Author:   ikemoto
Date:     2010-01-28 17:56:29 +0900 (Thu, 28 Jan 2010)

Log Message:
-----------
[NMShell] add test suite for mkdir

Added Paths:
-----------
    trunk/source/NMShell/test/info/
    trunk/source/NMShell/test/info/ngms/
    trunk/source/NMShell/test/info/ngms/commands/
    trunk/source/NMShell/test/info/ngms/commands/MkdirTest.scala

Added: trunk/source/NMShell/test/info/ngms/commands/MkdirTest.scala
===================================================================
--- trunk/source/NMShell/test/info/ngms/commands/MkdirTest.scala	                        (rev 0)
+++ trunk/source/NMShell/test/info/ngms/commands/MkdirTest.scala	2010-01-28 08:56:29 UTC (rev 104)
@@ -0,0 +1,213 @@
+package info.ngms.commands
+
+import org.scalatest.FunSuite
+//import org.scalatest.BeforeAndAfterEach
+import java.io.ByteArrayInputStream
+import java.io.ByteArrayOutputStream
+import java.io.PrintStream
+import org.apache.commons.cli.CommandLine
+import info.ngms.nmshell.NMCommand
+import info.ngms.nmshell.NMCommandContext
+import info.ngms.nmshell.NMCommandThread
+import info.ngms.nmshell.NMShellEnvironment
+import info.ngms.nmshell.NMShellConfigFile
+import info.ngms.nmtree.NMFileSystemTree
+import info.ngms.nmtree.NMPath
+import info.ngms.nmtree.NMTree
+import info.ngms.nmtree.NMTreeImplementations
+
+/**
+ * <code>mkdir</code>のテストを行います。
+ *
+ * @version $Id$
+ * @auther ikemo****@itpl*****
+ */
+class MkdirTest extends FunSuite {
+
+    test("name") {
+        assert(new mkdir().name == "mkdir")
+    }
+
+    test("createCommandLine") {
+
+        var commandLine : CommandLine = null
+
+        commandLine = new mkdir().createCommandLine(
+            Array())
+        assert( ! commandLine.hasOption("m") )
+
+        commandLine = new mkdir().createCommandLine(
+            Array("-m", "-xw", "-v", "testdir"))
+        assert( commandLine.hasOption("m") )
+        assert( commandLine.hasOption("v") )
+        assert( ! commandLine.hasOption("p") )
+
+        commandLine = new mkdir().createCommandLine(
+            Array("-m", "-xw", "-p", "testdir"))
+        assert( commandLine.hasOption("m") )
+        assert( ! commandLine.hasOption("v") )
+        assert( commandLine.hasOption("p") )
+
+        commandLine = new mkdir().createCommandLine(
+            Array("--mode", "=xr", "--verbose", "--parents", "testdir/testdir"))
+        assert( commandLine.hasOption("m") )
+        assert( commandLine.hasOption("v") )
+        assert( commandLine.hasOption("p") )
+
+    }
+
+    test("main") {
+        val fileSystemTree : NMFileSystemTree = initializeEnvironment()
+        val context : NMCommandContext = new NMCommandContext(null)
+        val testBaseDir : String = "testdir"
+        val testDir1 : String = "testdir1"
+        val testDir2 : String = "testdir2"
+        val testDir3 : String = "testdir3"
+        val testDir4 : String = "testdir4"
+        val testDir5 : String = "testdir5"
+        val testDir6 : String = "testdir6"
+        val testDir7 : String = "testdir7"
+        val testDir8 : String = "testdir8"
+        val testDir9 : String = "testdir9"
+        val testDir0 : String = "testdir0"
+
+        NMShellEnvironment.currentPath = new NMPath(NMPath.root)
+        executeCommand(context, new mkdir(), Array("-v", testBaseDir))
+        assert( new NMPath(testBaseDir).exists )
+        assert( new NMPath(testBaseDir).isDir )
+        
+        NMShellEnvironment.currentPath = new NMPath(NMPath.root + "/" + testBaseDir)
+        executeCommand(context, new mkdir(), Array(
+            testDir1 + "/" + testDir2,
+            testDir3,
+            testDir3 + "/../" + testDir4,
+            "../" + testDir5,
+            "../" + testDir6 + "/" + testDir7,
+            "/" + testDir8,
+            "/" + testDir9 + "/" + testDir0
+            ))
+        assert( ! new NMPath(testBaseDir + "/" + testDir1).exists )
+        assert( new NMPath(testBaseDir + "/" + testDir3).exists )
+        assert( new NMPath(testBaseDir + "/" + testDir3).isDir )
+        assert( new NMPath(testBaseDir + "/" + testDir4).exists )
+        assert( new NMPath(testBaseDir + "/" + testDir4).isDir )
+        assert( new NMPath("/" + testDir5).exists )
+        assert( new NMPath("/" + testDir5).isDir )
+        assert( ! new NMPath("/" + testDir6).exists )
+        assert( new NMPath("/" + testDir8).exists )
+        assert( new NMPath("/" + testDir8).isDir )
+        assert( ! new NMPath("/" + testDir9).exists )
+
+        //tear down
+        delete(fileSystemTree, testBaseDir + "/" + testDir3, false)
+        delete(fileSystemTree, testBaseDir + "/" + testDir4, false)
+        delete(fileSystemTree, "/" + testDir5, false)
+        delete(fileSystemTree, "/" + testDir8, false)
+
+        executeCommand(context, new mkdir(), Array(
+            "-p",
+            testDir1 + "/" + testDir2,
+            testDir3,
+            testDir3 + "/../" + testDir4,
+            "../" + testDir5,
+            "../" + testDir6 + "/" + testDir7,
+            "/" + testDir8,
+            "/" + testDir9 + "/" + testDir0
+            ))
+        assert( new NMPath(testBaseDir + "/" + testDir1).exists )
+        assert( new NMPath(testBaseDir + "/" + testDir1).isDir )
+        assert( new NMPath(testBaseDir + "/" + testDir1 + "/" + testDir2).exists )
+        assert( new NMPath(testBaseDir + "/" + testDir1 + "/" + testDir2).isDir )
+        assert( new NMPath(testBaseDir + "/" + testDir3).exists )
+        assert( new NMPath(testBaseDir + "/" + testDir3).isDir )
+        assert( new NMPath(testBaseDir + "/" + testDir4).exists )
+        assert( new NMPath(testBaseDir + "/" + testDir4).isDir )
+        assert( new NMPath("/" + testDir5).exists )
+        assert( new NMPath("/" + testDir5).isDir )
+        assert( new NMPath("/" + testDir6).exists )
+        assert( new NMPath("/" + testDir6).isDir )
+        assert( new NMPath("/" + testDir6 + "/" + testDir7).exists )
+        assert( new NMPath("/" + testDir6 + "/" + testDir7).isDir )
+        assert( new NMPath("/" + testDir8).exists )
+        assert( new NMPath("/" + testDir8).isDir )
+        assert( new NMPath("/" + testDir9).exists )
+        assert( new NMPath("/" + testDir9).isDir )
+        assert( new NMPath("/" + testDir9 + "/" + testDir0).exists )
+        assert( new NMPath("/" + testDir9 + "/" + testDir0).isDir )
+
+        //tear down
+        delete(fileSystemTree, "/" + testDir5, true)
+        delete(fileSystemTree, "/" + testDir6, true)
+        delete(fileSystemTree, "/" + testDir8, true)
+        delete(fileSystemTree, "/" + testDir9, true)
+        delete(fileSystemTree, testBaseDir, true)
+
+    }
+
+    def initializeEnvironment() : NMFileSystemTree = {
+        NMTree.init( NMShellEnvironment )
+        val root = new NMPath(NMPath.root)
+        val config : NMShellConfigFile = new NMShellConfigFile(NMShellConfigFile.defaultPath)
+        config.rootType match {
+            case NMTreeImplementations.RowFileSystem => {
+                val fs = new NMFileSystemTree( config.rootPath, root )
+                NMTree.mount( root, fs )
+                return fs
+            }
+        }
+    }
+
+    def delete(fileSystemTree : NMFileSystemTree, pathName : String, recursive : Boolean) : Unit = {
+        fileSystemTree.TreeOperations.delete(new NMPath(pathName), recursive)
+    }
+
+    def executeCommand(context : NMCommandContext, command : NMCommand, args : Array[String]) {
+        command.parseOption(args)
+        command.doWork(context)
+    }
+
+//    val lineSeparator : String = "\n"
+//
+//    test("main") {
+//        val shell : TestShell = new TestShell()
+//        Main.main(Array[String]())
+//        shell.input("mkdir -v testdir8" + lineSeparator)
+//    }
+
+    class TestShell {
+
+        private[this] var outputByteArrayStream : ByteArrayOutputStream = null
+        private[this] var errorOutputByteArrayStream : ByteArrayOutputStream = null
+
+        def input(input : String) : Unit = {
+            outputByteArrayStream = new ByteArrayOutputStream()
+            errorOutputByteArrayStream  = new ByteArrayOutputStream()
+            val outputStream : PrintStream = new PrintStream(outputByteArrayStream)
+            val errorOutputStream : PrintStream = new PrintStream(errorOutputByteArrayStream)
+            System.setOut(outputStream)
+            System.setErr(errorOutputStream)
+            System.setIn(new ByteArrayInputStream(input.getBytes()))
+            val threadGroup = Thread.currentThread.getThreadGroup()
+            val threads : Array[Thread] = new Array[Thread](threadGroup.activeCount() * 2) 
+            val numberOfThreads : Int = threadGroup.enumerate(threads)
+            for (thread <- threads if thread != null) {
+                if (thread.isInstanceOf[NMCommandThread]) {
+                    thread.join()
+//System.err.println("Joined: " + thread)
+                }
+            }
+            outputStream.flush()
+            errorOutputStream.flush()
+        }
+
+        def output() : String = {
+            return outputByteArrayStream.toString()
+        }
+
+        def errorOutput() : String = {
+            return errorOutputByteArrayStream.toString()
+        }
+        
+    }
+
+}


Property changes on: trunk/source/NMShell/test/info/ngms/commands/MkdirTest.scala
___________________________________________________________________
Added: svn:keywords
   + Id




Ngms-svn メーリングリストの案内
Zurück zum Archiv-Index