| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- //
- // FileNotFoundExceptionTest.cs - Unit tests for
- // System.IO.FileNotFoundException
- //
- // Author:
- // Gert Driesen <[email protected]>
- //
- // Copyright (C) 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.
- //
- using System;
- using System.IO;
- using NUnit.Framework;
- namespace MonoTests.System.IO {
- [TestFixture]
- public class FileNotFoundExceptionTest {
- [Test]
- public void Constructor1 ()
- {
- FileNotFoundException fnf = new FileNotFoundException ();
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNull (fnf.FileName, "#2");
- Assert.IsNull (fnf.InnerException, "#3");
- Assert.IsNotNull (fnf.Message, "#4"); // Unable to find the specified file
- Assert.IsNull (fnf.FusionLog, "#5");
- Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType().FullName), "#6");
- }
- [Test]
- public void Constructor2 ()
- {
- FileNotFoundException fnf = new FileNotFoundException ("message");
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNull (fnf.FileName, "#2");
- Assert.IsNull (fnf.InnerException, "#3");
- Assert.IsNotNull (fnf.Message, "#4");
- Assert.AreEqual ("message", fnf.Message, "#5");
- Assert.IsNull (fnf.FusionLog, "#6");
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"),"#7");
- #else
- Assert.AreEqual (fnf.GetType ().FullName + ": message",
- fnf.ToString (), "#7");
- #endif
- }
- [Test]
- public void Constructor2_Message_Empty ()
- {
- FileNotFoundException fnf = new FileNotFoundException (string.Empty);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNull (fnf.FileName, "#2");
- Assert.IsNull (fnf.InnerException, "#3");
- Assert.IsNotNull (fnf.Message, "#4");
- Assert.AreEqual (string.Empty, fnf.Message, "#5");
- Assert.IsNull (fnf.FusionLog, "#6");
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": "), "#7");
- #else
- Assert.AreEqual (fnf.GetType ().FullName + ": ",
- fnf.ToString (), "#7");
- #endif
- }
- [Test]
- public void Constructor2_Message_Null ()
- {
- FileNotFoundException fnf = new FileNotFoundException ((string) null);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNull (fnf.FileName, "#2");
- Assert.IsNull (fnf.InnerException, "#3");
- #if NET_2_0
- Assert.IsNull (fnf.Message, "#4");
- #else
- Assert.IsNotNull (fnf.Message, "#4"); // File or assembly name (null), or ...
- #endif
- Assert.IsNull (fnf.FusionLog, "#5");
- #if NET_2_0 && !TARGET_JVM
- Assert.AreEqual (fnf.GetType ().FullName + ": ",
- fnf.ToString (), "#6");
- #else
- Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName), "#6");
- #endif
- }
- [Test]
- public void Constructor3 ()
- {
- ArithmeticException ame = new ArithmeticException ("something");
- FileNotFoundException fnf = new FileNotFoundException ("message",
- ame);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNull (fnf.FileName, "#2");
- Assert.IsNotNull (fnf.InnerException, "#3");
- Assert.AreSame (ame, fnf.InnerException, "#4");
- Assert.IsNotNull (fnf.Message, "#5");
- Assert.AreEqual ("message", fnf.Message, "#6");
- Assert.IsNull (fnf.FusionLog, "#7");
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message ---> "
- + ame.GetType().FullName + ": something"), "#8");
- #else
- Assert.AreEqual (fnf.GetType ().FullName + ": message ---> "
- + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
- #endif
- }
- [Test]
- public void Constructor3_Message_Empty ()
- {
- ArithmeticException ame = new ArithmeticException ("something");
- FileNotFoundException fnf = new FileNotFoundException (string.Empty, ame);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNull (fnf.FileName, "#2");
- Assert.IsNotNull (fnf.InnerException, "#3");
- Assert.AreSame (ame, fnf.InnerException, "#4");
- Assert.IsNotNull (fnf.Message, "#5");
- Assert.AreEqual (string.Empty, fnf.Message, "#6");
- Assert.IsNull (fnf.FusionLog, "#7");
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": ---> "
- + ame.GetType().FullName + ": something"), "#8");
- #else
- Assert.AreEqual (fnf.GetType ().FullName + ": ---> "
- + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
- #endif
- }
- [Test]
- public void Constructor3_Message_Null ()
- {
- ArithmeticException ame = new ArithmeticException ("something");
- FileNotFoundException fnf = new FileNotFoundException ((string) null, ame);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNull (fnf.FileName, "#2");
- Assert.IsNotNull (fnf.InnerException, "#3");
- Assert.AreSame (ame, fnf.InnerException, "#4");
- #if NET_2_0
- Assert.IsNull (fnf.Message, "#5");
- #else
- Assert.IsNotNull (fnf.Message, "#5"); // File or assembly name (null), or ...
- #endif
- Assert.IsNull (fnf.FusionLog, "#6");
- #if NET_2_0
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": ---> "
- + ame.GetType().FullName + ": something"), "#7");
- #else
- Assert.AreEqual (fnf.GetType ().FullName + ": ---> "
- + ame.GetType ().FullName + ": something", fnf.ToString (), "#7");
- #endif
- #else
- Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName), "#7");
- Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#9");
- #endif
- }
- [Test]
- public void Constructor3_InnerException_Null ()
- {
- FileNotFoundException fnf = new FileNotFoundException ("message",
- (Exception) null);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNull (fnf.FileName, "#2");
- Assert.IsNull (fnf.InnerException, "#3");
- Assert.IsNotNull (fnf.Message, "#4");
- Assert.AreEqual ("message", fnf.Message, "#5");
- Assert.IsNull (fnf.FusionLog, "#6");
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"), "#7");
- #else
- Assert.AreEqual (fnf.GetType ().FullName + ": message",
- fnf.ToString (), "#7");
- #endif
- }
- [Test]
- public void Constructor4 ()
- {
- FileNotFoundException fnf = new FileNotFoundException ("message",
- "file.txt");
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNotNull (fnf.FileName, "#2");
- Assert.AreEqual ("file.txt", fnf.FileName, "#3");
- Assert.IsNull (fnf.InnerException, "#4");
- Assert.IsNotNull (fnf.Message, "#5");
- Assert.AreEqual ("message", fnf.Message, "#6");
- Assert.IsNull (fnf.FusionLog, "#7");
- Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
- + ": message" + Environment.NewLine), "#8");
- #if NET_2_0
- Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
- Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
- #else
- Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
- Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
- #endif
- }
- [Test]
- public void Constructor4_FileName_Empty ()
- {
- FileNotFoundException fnf = new FileNotFoundException ("message",
- string.Empty);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNotNull (fnf.FileName, "#2");
- Assert.AreEqual (string.Empty, fnf.FileName, "#3");
- Assert.IsNull (fnf.InnerException, "#4");
- Assert.IsNotNull (fnf.Message, "#5");
- Assert.AreEqual ("message", fnf.Message, "#6");
- Assert.IsNull (fnf.FusionLog, "#7");
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"), "#8");
- #else
- Assert.AreEqual (fnf.GetType ().FullName + ": message",
- fnf.ToString (), "#8");
- #endif
- }
- [Test]
- public void Constructor4_FileName_Null ()
- {
- FileNotFoundException fnf = new FileNotFoundException ("message",
- (string) null);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#A1");
- #endif
- Assert.IsNull (fnf.FileName, "#A2");
- Assert.IsNull (fnf.InnerException, "#A3");
- Assert.IsNotNull (fnf.Message, "#A4");
- Assert.AreEqual ("message", fnf.Message, "#A5");
- Assert.IsNull (fnf.FusionLog, "#A6");
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"), "#A7");
- #else
-
- Assert.AreEqual (fnf.GetType ().FullName + ": message",
- fnf.ToString (), "#A7");
- #endif
- fnf = new FileNotFoundException (string.Empty, (string) null);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#B1");
- #endif
- Assert.IsNull (fnf.FileName, "#B2");
- Assert.IsNull (fnf.InnerException, "#B3");
- Assert.IsNotNull (fnf.Message, "#B4");
- Assert.AreEqual (string.Empty, fnf.Message, "#B5");
- Assert.IsNull (fnf.FusionLog, "#B6");
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": "), "#B7");
- #else
- Assert.AreEqual (fnf.GetType ().FullName + ": ",
- fnf.ToString (), "#B7");
- #endif
- }
- [Test]
- public void Constructor4_FileNameAndMessage_Empty ()
- {
- FileNotFoundException fnf = new FileNotFoundException (string.Empty,
- string.Empty);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNotNull (fnf.FileName, "#2");
- Assert.AreEqual (string.Empty, fnf.FileName, "#3");
- Assert.IsNull (fnf.InnerException, "#4");
- Assert.IsNotNull (fnf.Message, "#5");
- Assert.AreEqual (string.Empty, fnf.Message, "#6");
- Assert.IsNull (fnf.FusionLog, "#7");
- #if TARGET_JVM
- Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": "), "#8");
- #else
- Assert.AreEqual (fnf.GetType ().FullName + ": ", fnf.ToString (), "#8");
- #endif
- }
- [Test]
- public void Constructor4_FileNameAndMessage_Null ()
- {
- FileNotFoundException fnf = new FileNotFoundException ((string) null,
- (string) null);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNull (fnf.FileName, "#2");
- Assert.IsNull (fnf.InnerException, "#3");
- #if NET_2_0
- Assert.IsNull (fnf.Message, "#4");
- #else
- Assert.IsNotNull (fnf.Message, "#4");
- #endif
- Assert.IsNull (fnf.FusionLog, "#5");
- Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
- + ": "), "#6");
- #if !TARGET_JVM
- Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
- #endif
- Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#8");
- }
- [Test]
- public void Constructor4_Message_Empty ()
- {
- FileNotFoundException fnf = null;
-
- fnf = new FileNotFoundException (string.Empty, "file.txt");
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#1");
- #endif
- Assert.IsNotNull (fnf.FileName, "#2");
- Assert.AreEqual ("file.txt", fnf.FileName, "#3");
- Assert.IsNull (fnf.InnerException, "#4");
- Assert.IsNotNull (fnf.Message, "#5");
- Assert.AreEqual (string.Empty, fnf.Message, "#6");
- Assert.IsNull (fnf.FusionLog, "#7");
- Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
- + ": " + Environment.NewLine), "#8");
- #if NET_2_0
- Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
- Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
- #else
- Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
- Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
- #endif
- }
- [Test]
- public void Constructor4_Message_Null ()
- {
- FileNotFoundException fnf = null;
-
- fnf = new FileNotFoundException ((string) null, "file.txt");
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#A1");
- #endif
- Assert.IsNotNull (fnf.FileName, "#A2");
- Assert.AreEqual ("file.txt", fnf.FileName, "#A3");
- Assert.IsNull (fnf.InnerException, "#A4");
- Assert.IsNotNull (fnf.Message, "#A5");
- Assert.IsNull (fnf.FusionLog, "#A6");
- Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
- + ": "), "#A7");
- Assert.IsTrue (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
- #if NET_2_0
- Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
- Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
- #else
- Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
- Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
- #endif
- fnf = new FileNotFoundException ((string) null, string.Empty);
- #if NET_2_0
- Assert.IsNotNull (fnf.Data, "#B1");
- #endif
- Assert.IsNotNull (fnf.FileName, "#B2");
- Assert.AreEqual (string.Empty, fnf.FileName, "#B3");
- Assert.IsNull (fnf.InnerException, "#B4");
- // .NET 1.1: File or assembly name , or one of its dependencies ...
- // .NET 2.0: Could not load file or assembly '' or one of its ...
- Assert.IsNotNull (fnf.Message, "#B5");
- Assert.IsNull (fnf.FusionLog, "#B6");
- Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
- + ": "), "#B7");
- #if !TARGET_JVM
- Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
- #endif
- #if NET_2_0
- Assert.IsTrue (fnf.ToString ().IndexOf ("''") != -1, "#B9");
- #else
- Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#B9");
- Assert.IsFalse (fnf.ToString ().IndexOf ("\"\"") != -1, "#B10");
- #endif
- }
- }
- }
|