⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesystemtests.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 3 页
字号:
'' FileSystemTests.vb - NUnit Test Cases for Microsoft.VisualBasic.Information '' Guy Cohen (guyc@mainsoft.com)'' '' Copyright (C) 2002-2006 Mainsoft Corporation.' Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)'' Permission is hereby granted, free of charge, to any person obtaining' a copy of this software and associated documentation files (the' "Software"), to deal in the Software without restriction, including' without limitation the rights to use, copy, modify, merge, publish,' distribute, sublicense, and/or sell copies of the Software, and to' permit persons to whom the Software is furnished to do so, subject to' the following conditions:' ' The above copyright notice and this permission notice shall be' included in all copies or substantial portions of the Software.' ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE' LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION' OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.'Imports NUnit.FrameworkImports SystemImports System.IOImports System.TextImports System.CollectionsImports System.ThreadingImports Microsoft.VisualBasic<Category("Broken"), TestFixture(), Category("MayFailOnSharedDrived")> _Public Class FilesSystemTest    Public DATA_DIR As String    Public sep_ch As Char    <TestFixtureSetUp()> _    Public Sub GetReady()        DATA_DIR = Environment.GetEnvironmentVariable("DATA_DIR")        sep_ch = Path.DirectorySeparatorChar        If Not (DATA_DIR) Then            'System.Console.WriteLine("DATA_DIR environment variable not found, set default value")            DATA_DIR = (Directory.GetCurrentDirectory() + sep_ch + "data")        End If        If Not Directory.Exists(DATA_DIR) Then            Directory.CreateDirectory(DATA_DIR)        Else            Directory.Delete(DATA_DIR, True)            Directory.CreateDirectory(DATA_DIR)        End If    End Sub    <TestFixtureTearDown()> _    Public Sub Clean_All()    End Sub    <TearDown()> _    Public Sub Clean()    End Sub#Region "ChDir"    <Test()> _    Public Sub ChDir_1()        Dim test_dir As String = "chdir_test1"        Dim cur_dir, tmpStr As String        Dim last_ch As Integer        Directory.CreateDirectory(DATA_DIR + sep_ch + test_dir)        FileSystem.ChDir(DATA_DIR + sep_ch + test_dir)        tmpStr = Directory.GetCurrentDirectory()        last_ch = tmpStr.LastIndexOf(sep_ch)        cur_dir = tmpStr.Substring(last_ch + 1, (tmpStr.Length - last_ch) - 1)        Assert.AreEqual(cur_dir, test_dir)        FileSystem.ChDir("..")        Directory.Delete(DATA_DIR + sep_ch + test_dir)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub ChDir_2()        FileSystem.ChDir("")    End Sub#If NET_2_0 Then    <Test(), ExpectedException(GetType(DirectoryNotFoundException))> _    Public Sub ChDir_3()        Dim test_dir As String = "chdir_test3"        FileSystem.ChDir(test_dir)    End Sub#Else        <Test(), ExpectedException(GetType(FileNotFoundException))> _        Public Sub ChDir_3()            Dim test_dir As String = "chdir_test3"            FileSystem.ChDir(test_dir)        End Sub#End If#End Region#Region "CurDir"    <Test()> _    Public Sub CurDir_1()        Dim cur_dir, test_dir As String        Dim bRes As Boolean = True        FileSystem.ChDir(DATA_DIR)        cur_dir = Directory.GetCurrentDirectory()        test_dir = FileSystem.CurDir()        Assert.AreEqual(cur_dir, test_dir)        Directory.CreateDirectory("CurDir_1")        FileSystem.ChDir(DATA_DIR + sep_ch + "CurDir_1")        test_dir = FileSystem.CurDir()        If (cur_dir = test_dir) Then bRes = False        Assert.AreEqual(True, bRes)        FileSystem.ChDir("..")        Directory.Delete(DATA_DIR + sep_ch + "CurDir_1")    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub CurDir_2()        FileSystem.CurDir("2")    End Sub    <Test(), ExpectedException(GetType(IOException))> _    Public Sub CurDir_3()        '' hopefully J won`t exist on this computer        Dim test_drive As Char = "J"c        FileSystem.CurDir(test_drive)    End Sub#End Region#Region "ChDrive"    <Test()> _    Public Sub ChDrive_1()        Dim test_drive As Char = "C"c        Dim cur_drive As Char        Dim tmpStr As String        FileSystem.ChDrive(test_drive)        tmpStr = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory())        cur_drive = tmpStr.Substring(0, 1)        Assert.AreEqual(cur_drive, test_drive)    End Sub    <Test()> _    Public Sub ChDrive_2()        Dim test_drive As String = ""        Dim cur_drive, last_drive As Char        Dim tmpStr As String        tmpStr = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory())        last_drive = tmpStr.Substring(0, 1)        FileSystem.ChDrive(test_drive)        tmpStr = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory())        cur_drive = tmpStr.Substring(0, 1)        Assert.AreEqual(cur_drive, last_drive)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub ChDrive_3()        FileSystem.ChDrive("2")    End Sub    <Test(), ExpectedException(GetType(IOException))> _    Public Sub ChDrive_4()        FileSystem.ChDrive("TR:\")    End Sub#End Region#Region "FileCopy"    <Test()> _    Public Sub FileCopy_1()        Dim dest_dir As String = "temp_dir1"        Dim src_file As String = "FileCopy_1.txt"        Dim fs As FileStream        If File.Exists(DATA_DIR + sep_ch + src_file) Then File.Delete(DATA_DIR + sep_ch + src_file)        fs = File.Create(DATA_DIR + sep_ch + src_file)        fs.Close()        If Directory.Exists(CStr(DATA_DIR + sep_ch + dest_dir)) Then Directory.Delete(CStr(DATA_DIR + sep_ch + dest_dir))        Directory.CreateDirectory(CStr(DATA_DIR + sep_ch + dest_dir))        FileSystem.FileCopy(DATA_DIR + sep_ch + src_file, DATA_DIR + sep_ch + dest_dir + sep_ch + src_file)        ' wait a while till the copy ends        Thread.Sleep(100)        Assert.AreEqual(True, File.Exists(DATA_DIR + sep_ch + dest_dir + sep_ch + src_file))        File.Delete(DATA_DIR + sep_ch + dest_dir + sep_ch + src_file)        Directory.Delete(DATA_DIR + sep_ch + dest_dir, True)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub FileCopy_2()        Dim dest_dir As String = "temp_dir2"        Dim src_file As String = "FileCopy_2.txt"        If File.Exists(DATA_DIR + sep_ch + src_file) Then File.Delete(DATA_DIR + sep_ch + src_file)        File.CreateText(DATA_DIR + sep_ch + src_file)        If Directory.Exists(CStr(DATA_DIR + sep_ch + dest_dir)) Then Directory.Delete(CStr(DATA_DIR + sep_ch + dest_dir))        Directory.CreateDirectory(CStr(DATA_DIR + sep_ch + dest_dir))        '' pass null src        FileSystem.FileCopy("", DATA_DIR + sep_ch + dest_dir)    End Sub    <Test(), ExpectedException(GetType(IOException))> _    Public Sub FileCopy_3()        Dim dest_dir As String = "temp_dir3"        Dim src_file As String = "FileCopy_3.txt"        If File.Exists(DATA_DIR + sep_ch + src_file) Then File.Delete(DATA_DIR + sep_ch + src_file)        File.CreateText(DATA_DIR + sep_ch + src_file)        If Directory.Exists(CStr(DATA_DIR + sep_ch + dest_dir)) Then Directory.Delete(CStr(DATA_DIR + sep_ch + dest_dir))        Directory.CreateDirectory(CStr(DATA_DIR + sep_ch + dest_dir))        '' pass existing directory name to copy        FileSystem.FileCopy(DATA_DIR + sep_ch + src_file, DATA_DIR + sep_ch + dest_dir)        File.Delete(DATA_DIR + sep_ch + src_file)        File.Delete(DATA_DIR + sep_ch + dest_dir)        File.Delete(DATA_DIR + sep_ch + dest_dir + sep_ch + src_file)        Directory.Delete(DATA_DIR + sep_ch + dest_dir)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub FileCopy_4()        Dim dest_dir As String = "temp_dir4"        Dim src_file As String = "FileCopy_4.txt"        If File.Exists(DATA_DIR + sep_ch + src_file) Then File.Delete(DATA_DIR + sep_ch + src_file)        File.CreateText(DATA_DIR + sep_ch + src_file)        If Directory.Exists(CStr(DATA_DIR + sep_ch + dest_dir)) Then Directory.Delete(CStr(DATA_DIR + sep_ch + dest_dir))        Directory.CreateDirectory(CStr(DATA_DIR + sep_ch + dest_dir))        '' pass null destination        FileSystem.FileCopy(DATA_DIR + sep_ch + dest_dir, "")    End Sub    <Test(), ExpectedException(GetType(FileNotFoundException))> _     Public Sub FileCopy_5()        Dim dest_dir As String = "temp_dir5"        Dim src_file As String = "FileCopy_5.txt"        If File.Exists(DATA_DIR + sep_ch + src_file) Then File.Delete(DATA_DIR + sep_ch + src_file)        If Directory.Exists(CStr(DATA_DIR + sep_ch + dest_dir)) Then Directory.Delete(CStr(DATA_DIR + sep_ch + dest_dir))        Directory.CreateDirectory(CStr(DATA_DIR + sep_ch + dest_dir))        '' pass missing src file        FileSystem.FileCopy(DATA_DIR + sep_ch + src_file, DATA_DIR + sep_ch + dest_dir + sep_ch + src_file)    End Sub    <Test(), ExpectedException(GetType(DirectoryNotFoundException))> _    Public Sub FileCopy_6()        Dim dest_dir As String = "temp_dir6"        Dim src_file As String = "FileCopy_6.txt"        If File.Exists(DATA_DIR + sep_ch + src_file) Then File.Delete(DATA_DIR + sep_ch + src_file)        File.CreateText(DATA_DIR + sep_ch + src_file)        If Directory.Exists(CStr(DATA_DIR + sep_ch + dest_dir)) Then Directory.Delete(CStr(DATA_DIR + sep_ch + dest_dir))        '' pass missing directory to destination        FileSystem.FileCopy(DATA_DIR + sep_ch + src_file, DATA_DIR + sep_ch + dest_dir + sep_ch + src_file)    End Sub#End Region#Region "FileDateTime"    'TargetJvmNotSupported - File metadata/attributes feature is not supported #If Not TARGET_JVM Then    <Test(), Category("TargetJvmNotSupported")> _    Public Sub FileDateTime_1()        Dim test_file As String = "FileDateTime_test1.dat"        Dim create_time, test_time As Date        Dim fs As FileStream        fs = File.Create(DATA_DIR + sep_ch + test_file)        create_time = File.GetCreationTime(DATA_DIR + sep_ch + test_file)        test_time = FileSystem.FileDateTime(DATA_DIR + sep_ch + test_file)        Assert.AreEqual(create_time, test_time, "Creation Time should be the same")        fs.Close()        Thread.Sleep(600)        File.Delete(DATA_DIR + sep_ch + test_file)    End Sub#End If#If Not TARGET_JVM Then    'TargetJvmNotSupported - File metadata/attributes feature is not supported     <Test(), Category("TargetJvmNotSupported")> _    Public Sub FileDateTime_2()        Dim test_file As String = "FileDateTime_test1.dat"        Dim modify_time, test_time As Date        Dim fs As FileStream

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -