Ejemplo n.º 1
0
        public void Test_enumFiles()
        {
            string tmp_path, a, b;

            if (NWEnviroment.osVersionStr() == "Unix")
            {
                tmp_path = "/hoge/fuga/nyaa";
                a        = "/a.txt";
                b        = "/b.txt";
            }
            else
            {
                tmp_path = "\\hoge\\fuga\\nyaa";
                a        = "\\a.txt";
                b        = "\\b.txt";
            }
            string tmp = System.IO.Path.GetTempPath() + tmp_path;

            runner.Run(com.WriteIL(
                           "DIR=「" + tmp + "」\n" +
                           "DIRにフォルダ作成。\n" +
                           "F=DIR&「" + a + "」;Fに「abc」を保存。\n" +
                           "F=DIR&「" + b + "」;Fに「abc」を保存。\n" +
                           "DIRのファイル列挙して「/」で配列結合して表示。"));
            Assert.AreEqual("a.txt/b.txt", runner.PrintLog);
        }
Ejemplo n.º 2
0
 private int __total() //MB単位
 {
     if (NWEnviroment.isWindows())
     {
         float                      total = 0;
         ManagementClass            mc    = new ManagementClass("Win32_OperatingSystem");
         ManagementObjectCollection moc   = mc.GetInstances();
         foreach (ManagementObject mo in moc)
         {
             total = (int.Parse(mo["TotalVisibleMemorySize"].ToString()) + int.Parse(mo["TotalVirtualMemorySize"].ToString())) / 1000;
         }
         moc.Dispose();
         mc.Dispose();
         return((int)total);
     }
     else
     {
         string free = LinuxCommand.execute("free -m");
         using (StringReader sr = new StringReader(free)){
             string line = "";
             while ((line = sr.ReadLine()) != null)
             {
                 if (line.Contains("-/+"))
                 {
                     string[] parts = Regex.Split(line, @"\s+");
                     int      total = int.Parse(parts[parts.Length - 1]) + int.Parse(parts[parts.Length - 2]);
                     sr.Close();
                     sr.Dispose();
                     return(total);
                 }
             }
         }
     }
     return(0);//TODO: Exception?
 }
Ejemplo n.º 3
0
        private int __available() //MB単位
        {
            if (NWEnviroment.isWindows())
            {
                string mem      = "Memory";
                string countMem = "Available Mbytes";
                System.Diagnostics.PerformanceCounter pcMem = new System.Diagnostics.PerformanceCounter(mem, countMem);
                float available = pcMem.NextValue();
                pcMem.Close();
                pcMem.Dispose();
                return((int)available);
            }
            else
            {
                string free = LinuxCommand.execute("free -m");
                using (StringReader sr = new StringReader(free)){
                    string line = "";
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.Contains("-/+"))
                        {
                            string[] parts     = Regex.Split(line, @"\s+");
                            int      available = int.Parse(parts[parts.Length - 1]);
                            sr.Close();
                            sr.Dispose();
                            return(available);
//                            Console.WriteLine("rate:{0}",(int)(100*int.Parse(parts[2])/(int.Parse(parts[3])+int.Parse(parts[2]))));
                        }
                    }
                }
            }
            return(0);//TODO: Exception?
        }
Ejemplo n.º 4
0
        private object _toKana(INakoFuncCallInfo info)
        {
            string s = info.StackPopAsString();

            if (NWEnviroment.isWindows())
            {
                return(Strings.StrConv(s, VbStrConv.Hiragana, 0));
            }
            else
            {
                return(LinuxCommand.execute("echo '" + s + "' | nkf --hiragana").Replace("\n", ""));
            }
        }
Ejemplo n.º 5
0
 public void TestEnumWindows()
 {
     if (NWEnviroment.isWindows())
     {
         runner.Run(com.WriteIL(
                        "窓列挙して表示。\n"));
         Assert.AreNotEqual("", runner.PrintLog);
     }
     else
     {
         Assert.Pass("Windows環境でないのでスキップ");
     }
 }
Ejemplo n.º 6
0
        public void Test_driveType()
        {
            string driveName = @"C:\";

            if (!NWEnviroment.isWindows())
            {
                driveName = @"/";
            }
            runner.Run(com.WriteIL(
                           "S=「" + driveName + "」のドライブ種類\n" +
                           "Sを継続表示\n" +
                           ""));
            Assert.AreEqual("Fixed", runner.PrintLog);
        }
Ejemplo n.º 7
0
 public void TestClipboad2()
 {
     if (NWEnviroment.isWindows())
     {
         runner.Run(com.WriteIL(
                        "10をコピー。\n" +
                        "クリップボードを表示。"));
         Assert.AreEqual("10", runner.PrintLog);
     }
     else
     {
         Assert.Pass("Windows環境でないのでスキップ");
     }
 }
Ejemplo n.º 8
0
        private object _alnumToEn(INakoFuncCallInfo info)
        {
            string s = info.StackPopAsString();

            return(Regex.Replace(s, @"[0-9A-Za-z:- ]+", delegate(Match m){
                if (NWEnviroment.isWindows())
                {
                    return Strings.StrConv(m.Value, VbStrConv.Narrow, 0);
                }
                else
                {
                    return LinuxCommand.execute("echo '" + m.Value + "' | nkf -Z3").Replace("\n", "");
                }
            }));
        }
Ejemplo n.º 9
0
        public Object _execCommandAndGetResult(INakoFuncCallInfo info)
        {
            string s   = info.StackPopAsString();
            string ret = "";

            if (NWEnviroment.isWindows())
            {
                ret = WindowsCommand.execute(s);
            }
            else
            {
                ret = LinuxCommand.execute(s);
            }
            return(ret);
        }
Ejemplo n.º 10
0
        public void Test_currentDir()
        {
            string currentDir = System.IO.Directory.GetCurrentDirectory();

            runner.Run(com.WriteIL(
                           "F=作業フォルダ取得\n" +
                           "Fを継続表示\n" +
                           ""));
            Assert.AreEqual(NWEnviroment.AppendLastPathFlag(currentDir), runner.PrintLog);
            currentDir = System.IO.Path.GetTempPath();
            runner.Run(com.WriteIL(
                           "「" + currentDir + "」に作業フォルダ変更\n" +
                           "F=作業フォルダ取得\n" +
                           "Fを継続表示\n" +
                           ""));
            Assert.AreEqual(NWEnviroment.AppendLastPathFlag(currentDir), runner.PrintLog);
        }
Ejemplo n.º 11
0
        public void Test_Path()
        {
            string desktop = NWEnviroment.AppendLastPathFlag(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop));

            runner.Run(com.WriteIL(
                           "デスクトップを表示。\n" +
                           ""));
            Assert.AreEqual(desktop, runner.PrintLog);
            string path = ConvertPath("/tmp/hoge/fuga/piyo.txt");

            runner.Run(com.WriteIL(
                           "「" + path + "」のパス抽出を表示。\n" +
                           ""));
            Assert.AreEqual(ConvertPath("/tmp/hoge/fuga"), runner.PrintLog);
            runner.Run(com.WriteIL(
                           "「" + path + "」の拡張子抽出を表示。\n" +
                           ""));
            Assert.AreEqual(ConvertPath(".txt"), runner.PrintLog);
            runner.Run(com.WriteIL(
                           "「" + path + "」のファイル名抽出を表示。\n" +
                           ""));
            Assert.AreEqual(ConvertPath("piyo.txt"), runner.PrintLog);
        }
Ejemplo n.º 12
0
 private string ConvertPath(string s)
 {
     return((NWEnviroment.osVersionStr().Contains("Windows"))? s.Replace("/", "\\") : s.Replace("\\", "/"));
 }
Ejemplo n.º 13
0
 public void TestPs()//TODO:Success test
 {
     runner.Run(com.WriteIL(
                    "プロセス列挙して表示。\n"));
     Assert.AreEqual(true, runner.PrintLog.Contains((NWEnviroment.isWindows())? "svchost" : "mono"));
 }
Ejemplo n.º 14
0
 private object _os(INakoFuncCallInfo info)
 {
     return(NWEnviroment.osVersionStr());
 }
Ejemplo n.º 15
0
 private string _path(string dir)
 {
     return(NWEnviroment.AppendLastPathFlag(dir));
 }