public void Constructor4_Message_Empty()
        {
            BadImageFormatException bif = null;

            bif = new BadImageFormatException(string.Empty, "file.txt");

#if NET_2_0
            Assert.IsNotNull(bif.Data, "#1");
#endif
            Assert.IsNotNull(bif.FileName, "#2");
            Assert.AreEqual("file.txt", bif.FileName, "#3");
            Assert.IsNull(bif.InnerException, "#4");
            Assert.IsNotNull(bif.Message, "#5");
            Assert.AreEqual(string.Empty, bif.Message, "#6");
            Assert.IsNull(bif.FusionLog, "#7");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName
                                                    + ": " + Environment.NewLine), "#8");
#if NET_2_0
            Assert.IsTrue(bif.ToString().IndexOf("'file.txt'") != -1, "#9");
            Assert.IsFalse(bif.ToString().IndexOf("\"file.txt\"") != -1, "#10");
#else
            Assert.IsFalse(bif.ToString().IndexOf("'file.txt'") != -1, "#9");
            Assert.IsTrue(bif.ToString().IndexOf("\"file.txt\"") != -1, "#10");
#endif
        }
        public void Constructor4_Message_Null()
        {
            BadImageFormatException bif = null;

            bif = new BadImageFormatException((string)null, "file.txt");

            Assert.IsNotNull(bif.Data, "#A1");
            Assert.IsNotNull(bif.FileName, "#A2");
            Assert.AreEqual("file.txt", bif.FileName, "#A3");
            Assert.IsNull(bif.InnerException, "#A4");
            Assert.IsNotNull(bif.Message, "#A5");
            Assert.IsNull(bif.FusionLog, "#A6");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName
                                                    + ": "), "#A7");
            Assert.IsTrue(bif.ToString().IndexOf(Environment.NewLine) != -1, "#A8");
            Assert.IsTrue(bif.ToString().IndexOf("'file.txt'") != -1, "#A9");

            bif = new BadImageFormatException((string)null, string.Empty);

            Assert.IsNotNull(bif.Data, "#B1");
            Assert.IsNotNull(bif.FileName, "#B2");
            Assert.AreEqual(string.Empty, bif.FileName, "#B3");
            Assert.IsNull(bif.InnerException, "#B4");
            // .NET 1.1: The format of the file 'file.txt' is invalid
            // .NET 2.0: Could not load file or assembly 'file.txt' or one of its ...
            Assert.IsNotNull(bif.Message, "#B5");
            Assert.IsNull(bif.FusionLog, "#B6");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName
                                                    + ": "), "#B7");
            Assert.IsFalse(bif.ToString().IndexOf(Environment.NewLine) != -1, "#B8");
            Assert.IsTrue(bif.ToString().IndexOf("''") != -1, "#B9");
        }
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call ToString on an empty exception class");

        try
        {
            BadImageFormatException ex = new BadImageFormatException();
            string expected = "System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.";
            string actual = ex.ToString();

            if (ex.ToString() == null)
            {
                TestLibrary.TestFramework.LogError("001.1", "ToString returns unexpected value");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] expected = " + expected + ", actual = " + actual);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call ToString on an empty exception class");

        try
        {
            BadImageFormatException ex = new BadImageFormatException();
            string expected            = "System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.";
            string actual = ex.ToString();

            if (ex.ToString() == null)
            {
                TestLibrary.TestFramework.LogError("001.1", "ToString returns unexpected value");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] expected = " + expected + ", actual = " + actual);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
        public void Constructor3_Message_Null()
        {
            ArithmeticException     ame = new ArithmeticException("something");
            BadImageFormatException bif = new BadImageFormatException((string)null, ame);

#if NET_2_0
            Assert.IsNotNull(bif.Data, "#1");
#endif
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNotNull(bif.InnerException, "#3");
            Assert.AreSame(ame, bif.InnerException, "#4");
#if NET_2_0
            Assert.IsNotNull(bif.Message, "#5"); // Could not load file or assembly '' ...
            Assert.IsTrue(bif.Message.IndexOf("''") != -1, "#6");
#else
            Assert.IsNotNull(bif.Message, "#5"); // Format of the executable (.exe) or library ...
            Assert.IsFalse(bif.Message.IndexOf("''") != -1, "#6");
#endif
            Assert.IsNull(bif.FusionLog, "#7");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName), "#8");
            Assert.IsTrue(bif.ToString().IndexOf("---> " + ame.GetType().FullName) != -1, "#9");
#if !TARGET_JVM // ToString always has a stack trace under TARGET_JVM
            Assert.IsFalse(bif.ToString().IndexOf(Environment.NewLine) != -1, "#10");
#endif // TARGET_JVM
        }
        public void Constructor2_Message_Null()
        {
            BadImageFormatException bif = new BadImageFormatException((string)null);

            Assert.IsNotNull(bif.Data, "#1");
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNull(bif.InnerException, "#3");
            Assert.IsNotNull(bif.Message, "#4");              // Could not load file or assembly '' ...
            Assert.IsTrue(bif.Message.IndexOf("''") != -1, "#5");
            Assert.IsNull(bif.FusionLog, "#5");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName), "#6");
            Assert.IsTrue(bif.ToString().IndexOf("''") != -1, "#7");
        }
Exemplo n.º 7
0
        public void Constructor4_FileNameAndMessage_Null()
        {
            BadImageFormatException bif = new BadImageFormatException((string)null,
                                                                      (string)null);

            Assert.IsNotNull(bif.Data, "#1");
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNull(bif.InnerException, "#3");
            Assert.IsNotNull(bif.Message, "#4");
            Assert.IsNull(bif.FusionLog, "#5");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName
                                                    + ": "), "#6");
            Assert.IsFalse(bif.ToString().IndexOf(Environment.NewLine) != -1, "#7");
        }
Exemplo n.º 8
0
        public void Constructor3_Message_Null()
        {
            ArithmeticException     ame = new ArithmeticException("something");
            BadImageFormatException bif = new BadImageFormatException((string)null, ame);

            Assert.IsNotNull(bif.Data, "#1");
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNotNull(bif.InnerException, "#3");
            Assert.AreSame(ame, bif.InnerException, "#4");
            Assert.IsNotNull(bif.Message, "#5");
            Assert.IsNull(bif.FusionLog, "#7");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName), "#8");
            Assert.IsTrue(bif.ToString().IndexOf("---> " + ame.GetType().FullName) != -1, "#9");
            Assert.IsFalse(bif.ToString().IndexOf(Environment.NewLine) != -1, "#10");
        }
        public void Constructor4_FileName_Null()
        {
            BadImageFormatException bif = new BadImageFormatException("message",
                                                                      (string)null);

            Assert.IsNotNull(bif.Data, "#A1");
            Assert.IsNull(bif.FileName, "#A2");
            Assert.IsNull(bif.InnerException, "#A3");
            Assert.IsNotNull(bif.Message, "#A4");
            Assert.AreEqual("message", bif.Message, "#A5");
            Assert.IsNull(bif.FusionLog, "#A6");
            Assert.AreEqual(bif.GetType().FullName + ": message",
                            bif.ToString(), "#A7");

            bif = new BadImageFormatException(string.Empty, (string)null);

            Assert.IsNotNull(bif.Data, "#B1");
            Assert.IsNull(bif.FileName, "#B2");
            Assert.IsNull(bif.InnerException, "#B3");
            Assert.IsNotNull(bif.Message, "#B4");
            Assert.AreEqual(string.Empty, bif.Message, "#B5");
            Assert.IsNull(bif.FusionLog, "#B6");
            Assert.AreEqual(bif.GetType().FullName + ": ",
                            bif.ToString(), "#B7");
        }
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Call ToString on an exception class with message is set");

        try
        {
            string message = TestLibrary.Generator.GetString(-55, false, 1, 50);
            BadImageFormatException ex = new BadImageFormatException(message);
            string expected = "System.BadImageFormatException: " + message;
            string actual = ex.ToString();

            if (expected != actual)
            {
                TestLibrary.TestFramework.LogError("002.1", "ToString returns unexpected value");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] expected = " + expected + ", actual = " + actual);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: Call ToString on an exception class with message and inner is set");

        try
        {
            string    message          = TestLibrary.Generator.GetString(-55, false, 1, 50);
            Exception inner            = new Exception();
            BadImageFormatException ex = new BadImageFormatException(message, inner);
            string expected            = "System.BadImageFormatException: " + message + " ---> " + inner.ToString();
            string actual = ex.ToString();

            if (expected != actual)
            {
                TestLibrary.TestFramework.LogError("003.1", "ToString returns unexpected value");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] expected = " + expected + ", actual = " + actual);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
        public void Constructor2_Message_Empty()
        {
            BadImageFormatException bif = new BadImageFormatException(string.Empty);

#if NET_2_0
            Assert.IsNotNull(bif.Data, "#1");
#endif
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNull(bif.InnerException, "#3");
            Assert.IsNotNull(bif.Message, "#4");
            Assert.AreEqual(string.Empty, bif.Message, "#5");
            Assert.IsNull(bif.FusionLog, "#6");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName + ": "), "#7");
#else
            Assert.AreEqual(bif.GetType().FullName + ": ",
                            bif.ToString(), "#7");
#endif // TARGET_JVM
        }
Exemplo n.º 13
0
        public void NoRestriction()
        {
            BadImageFormatException fle = new BadImageFormatException("message", "filename",
                                                                      new BadImageFormatException("inner message", "inner filename"));

            Assert.AreEqual("message", fle.Message, "Message");
            Assert.AreEqual("filename", fle.FileName, "FileName");
            Assert.IsNull(fle.FusionLog, "FusionLog");
            Assert.IsNotNull(fle.ToString(), "ToString");
        }
Exemplo n.º 14
0
        public static void ToStringTest()
        {
            string message = "this is not the file you're looking for";
            string fileName = "file.txt";
            var innerException = new Exception("Inner exception");
            var exception = new BadImageFormatException(message, fileName, innerException);

            var toString = exception.ToString();
            Assert.Contains(": " + message, toString);
            Assert.Contains(": '" + fileName + "'", toString);
            Assert.Contains("---> " + innerException.ToString(), toString);

            // set the stack trace
            try { throw exception; }
            catch
            {
                Assert.False(string.IsNullOrEmpty(exception.StackTrace));
                Assert.Contains(exception.StackTrace, exception.ToString());
            }
        }
Exemplo n.º 15
0
        public void Constructor2_Message_Null()
        {
            BadImageFormatException bif = new BadImageFormatException((string)null);

            Assert.IsNotNull(bif.Data, "#1");
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNull(bif.InnerException, "#3");
            Assert.IsNotNull(bif.Message, "#4");
            Assert.IsNull(bif.FusionLog, "#5");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName), "#6");
        }
        public void Constructor1()
        {
            BadImageFormatException bif = new BadImageFormatException();

            Assert.IsNotNull(bif.Data, "#1");
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNull(bif.InnerException, "#3");
            Assert.IsNotNull(bif.Message, "#4");              // Format of the executable (.exe) or library (.dll) is invalid
            Assert.IsNull(bif.FusionLog, "#5");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName), "#6");
        }
Exemplo n.º 17
0
        public void FullRestriction()
        {
            BadImageFormatException fle = new BadImageFormatException("message", "filename",
                                                                      new BadImageFormatException("inner message", "inner filename"));

            Assert.AreEqual("message", fle.Message, "Message");
            Assert.AreEqual("filename", fle.FileName, "FileName");
            Assert.IsNull(fle.FusionLog, "FusionLog");
            // ToString doesn't work in this case and strangely throws a BadImageFormatException
            Assert.IsNotNull(fle.ToString(), "ToString");
        }
        public void Constructor3_Message_Empty()
        {
            ArithmeticException     ame = new ArithmeticException("something");
            BadImageFormatException bif = new BadImageFormatException(string.Empty, ame);

#if NET_2_0
            Assert.IsNotNull(bif.Data, "#1");
#endif
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNotNull(bif.InnerException, "#3");
            Assert.AreSame(ame, bif.InnerException, "#4");
            Assert.IsNotNull(bif.Message, "#5");
            Assert.AreEqual(string.Empty, bif.Message, "#6");
            Assert.IsNull(bif.FusionLog, "#7");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
            Assert.IsTrue(bif.ToString().IndexOf(ame.GetType().FullName + ": something") != -1, "#8");
#else
            Assert.AreEqual(bif.GetType().FullName + ":  ---> "
                            + ame.GetType().FullName + ": something", bif.ToString(), "#8");
#endif // TARGET_JVM
        }
        public static void ToStringTest()
        {
            string message        = "this is not the file you're looking for";
            string fileName       = "file.txt";
            var    innerException = new Exception("Inner exception");
            var    exception      = new BadImageFormatException(message, fileName, innerException);

            var toString = exception.ToString();

            Assert.Contains(": " + message, toString);
            Assert.Contains(": '" + fileName + "'", toString);
            Assert.Contains("---> " + innerException.ToString(), toString);

            // set the stack trace
            try { throw exception; }
            catch
            {
                Assert.False(string.IsNullOrEmpty(exception.StackTrace));
                Assert.Contains(exception.StackTrace, exception.ToString());
            }
        }
Exemplo n.º 20
0
        public void Constructor4_FileNameAndMessage_Null()
        {
            BadImageFormatException bif = new BadImageFormatException((string)null,
                                                                      (string)null);

#if NET_2_0
            Assert.IsNotNull(bif.Data, "#1");
#endif
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNull(bif.InnerException, "#3");
#if NET_2_0
            Assert.IsNotNull(bif.Message, "#4");              // Could not load file or assembly '' ...
            Assert.IsTrue(bif.Message.IndexOf("''") != -1, "#5");
#else
            Assert.IsNotNull(bif.Message, "#4");              // Format of the executable (.exe) or library ...
            Assert.IsFalse(bif.Message.IndexOf("''") != -1, "#5");
#endif
            Assert.IsNull(bif.FusionLog, "#5");
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName
                                                    + ": "), "#6");
            Assert.IsFalse(bif.ToString().IndexOf(Environment.NewLine) != -1, "#7");
        }
        public void Constructor2_Message_Empty()
        {
            BadImageFormatException bif = new BadImageFormatException(string.Empty);

            Assert.IsNotNull(bif.Data, "#1");
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNull(bif.InnerException, "#3");
            Assert.IsNotNull(bif.Message, "#4");
            Assert.AreEqual(string.Empty, bif.Message, "#5");
            Assert.IsNull(bif.FusionLog, "#6");
            Assert.AreEqual(bif.GetType().FullName + ": ",
                            bif.ToString(), "#7");
        }
        public void Constructor3_InnerException_Null()
        {
            BadImageFormatException bif = new BadImageFormatException("message",
                                                                      (Exception)null);

            Assert.IsNotNull(bif.Data, "#1");
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNull(bif.InnerException, "#3");
            Assert.IsNotNull(bif.Message, "#4");
            Assert.AreEqual("message", bif.Message, "#5");
            Assert.IsNull(bif.FusionLog, "#6");
            Assert.AreEqual(bif.GetType().FullName + ": message",
                            bif.ToString(), "#7");
        }
        public void Constructor4_FileName_Null()
        {
            BadImageFormatException bif = new BadImageFormatException("message",
                                                                      (string)null);

#if NET_2_0
            Assert.IsNotNull(bif.Data, "#A1");
#endif
            Assert.IsNull(bif.FileName, "#A2");
            Assert.IsNull(bif.InnerException, "#A3");
            Assert.IsNotNull(bif.Message, "#A4");
            Assert.AreEqual("message", bif.Message, "#A5");
            Assert.IsNull(bif.FusionLog, "#A6");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName + ": message"), "#A7");
#else
            Assert.AreEqual(bif.GetType().FullName + ": message",
                            bif.ToString(), "#A7");
#endif // TARGET_JVM

            bif = new BadImageFormatException(string.Empty, (string)null);

#if NET_2_0
            Assert.IsNotNull(bif.Data, "#B1");
#endif
            Assert.IsNull(bif.FileName, "#B2");
            Assert.IsNull(bif.InnerException, "#B3");
            Assert.IsNotNull(bif.Message, "#B4");
            Assert.AreEqual(string.Empty, bif.Message, "#B5");
            Assert.IsNull(bif.FusionLog, "#B6");
#if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
            Assert.IsTrue(bif.ToString().StartsWith(bif.GetType().FullName + ": "), "#B7");
#else
            Assert.AreEqual(bif.GetType().FullName + ": ",
                            bif.ToString(), "#B7");
#endif // TARGET_JVM
        }
        public void Constructor3_Message_Empty()
        {
            ArithmeticException     ame = new ArithmeticException("something");
            BadImageFormatException bif = new BadImageFormatException(string.Empty, ame);

            Assert.IsNotNull(bif.Data, "#1");
            Assert.IsNull(bif.FileName, "#2");
            Assert.IsNotNull(bif.InnerException, "#3");
            Assert.AreSame(ame, bif.InnerException, "#4");
            Assert.IsNotNull(bif.Message, "#5");
            Assert.AreEqual(string.Empty, bif.Message, "#6");
            Assert.IsNull(bif.FusionLog, "#7");
            Assert.AreEqual(bif.GetType().FullName + ":  ---> "
                            + ame.GetType().FullName + ": something", bif.ToString(), "#8");
        }