Просмотр исходного кода

* ConfigurationErrorsExceptionTest.cs: Added tests for ctors and
GetFilename/GetLineNumber overloads.
* System.Configuration_test.dll.sources: added
ConfigurationErrorsExceptionTest.cs.
* System.Configuration.dll.sources: added ConfigXmlTextReader.cs.
* ConfigurationElement.cs: Use ConfigurationErrorsException instead of
ConfigurationException, and pass reader to ConfigurationErrorsException
ctor to allow for file/linenumber info in exception message.
* ConfigurationErrorsException.cs: Removed local bareMessage field, and
use base.BareMessage field instead. Fixed Message property to only add
filename if not null or zero-length string, and only add line if not
zero. In GetFilename/GetLineNumber overloads, only try to get info if
node/reader implements IConfigErrorInfo.
* ConfigurationSection.cs: Use ConfigXmlTextReader instead of
XmlTextReader to allow for file/linenumber info in exception messages.
* ConfigXmlTextReader.cs: Added XmlTextReader that implements
IConfigErrorInfo.
* ConfigurationLocation.cs: Use ConfigXmlTextReader instead of
XmlTextReader to allow for file/linenumber info in exception messages.
* ClientConfigurationSystem.cs: Perform lazy initialization and
wrap exceptions in ConfigurationErrorsException. Fixes standalone test
t28.
* Configuration.cs: Use ConfigXmlTextReader instead of XmlTextReader
to allow for file/linenumber info in exception messages.
* ConfigInfo.cs: Fixed ThrowException to use file/number info available
in XmlTextReader for exception message.
* AppSettingsSection.cs: Use ConfigXmlTextReader instead of
XmlTextReader to allow for file/linenumber info in exception messages.
* Assert.cs: added.
* Makefile: added Assert.cs, and explicitly specify output file.
* t28.cs: Improved test.

svn path=/trunk/mcs/; revision=106626

Gert Driesen 17 лет назад
Родитель
Сommit
590868c044
20 измененных файлов с 1055 добавлено и 79 удалено
  1. 6 0
      mcs/class/System.Configuration/ChangeLog
  2. 2 1
      mcs/class/System.Configuration/System.Configuration.dll.sources
  3. 1 1
      mcs/class/System.Configuration/System.Configuration/AppSettingsSection.cs
  4. 26 0
      mcs/class/System.Configuration/System.Configuration/ChangeLog
  5. 26 15
      mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs
  6. 1 1
      mcs/class/System.Configuration/System.Configuration/ConfigInfo.cs
  7. 68 0
      mcs/class/System.Configuration/System.Configuration/ConfigXmlTextReader.cs
  8. 7 13
      mcs/class/System.Configuration/System.Configuration/Configuration.cs
  9. 4 4
      mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs
  10. 32 31
      mcs/class/System.Configuration/System.Configuration/ConfigurationErrorsException.cs
  11. 1 1
      mcs/class/System.Configuration/System.Configuration/ConfigurationLocation.cs
  12. 6 4
      mcs/class/System.Configuration/System.Configuration/ConfigurationSection.cs
  13. 1 0
      mcs/class/System.Configuration/System.Configuration_test.dll.sources
  14. 5 0
      mcs/class/System.Configuration/Test/System.Configuration/ChangeLog
  15. 755 0
      mcs/class/System.Configuration/Test/System.Configuration/ConfigurationErrorsExceptionTest.cs
  16. 86 0
      mcs/class/System.Configuration/Test/standalone/Assert.cs
  17. 6 0
      mcs/class/System.Configuration/Test/standalone/ChangeLog
  18. 1 1
      mcs/class/System.Configuration/Test/standalone/Makefile
  19. 21 7
      mcs/class/System.Configuration/Test/standalone/t28.cs
  20. 0 0
      mcs/class/System.Configuration/Test/standalone/t42.cs

+ 6 - 0
mcs/class/System.Configuration/ChangeLog

@@ -1,3 +1,9 @@
+2008-06-26  Gert Driesen  <[email protected]>
+
+	* System.Configuration_test.dll.sources: added
+	ConfigurationErrorsExceptionTest.cs
+	* System.Configuration.dll.sources: added ConfigXmlTextReader.cs.
+
 2007-08-31  Gert Driesen  <[email protected]>
 
 	* System.Configuration_test.dll.sources: added ProviderBaseTest.cs.

+ 2 - 1
mcs/class/System.Configuration/System.Configuration.dll.sources

@@ -57,6 +57,7 @@ System.Configuration/ConfigurationSectionGroupCollection.cs
 System.Configuration/ConfigurationUserLevel.cs
 System.Configuration/ConfigurationValidatorAttribute.cs
 System.Configuration/ConfigurationValidatorBase.cs
+System.Configuration/ConfigXmlTextReader.cs
 System.Configuration/ConnectionStringsSection.cs
 System.Configuration/ConnectionStringSettingsCollection.cs
 System.Configuration/ConnectionStringSettings.cs
@@ -115,4 +116,4 @@ System.Configuration/TimeSpanValidator.cs
 System.Configuration/TimeSpanValidatorAttribute.cs
 System.Configuration/TypeNameConverter.cs
 System.Configuration/ValidatorCallback.cs
-System.Configuration/WhiteSpaceTrimStringConverter.cs
+System.Configuration/WhiteSpaceTrimStringConverter.cs

+ 1 - 1
mcs/class/System.Configuration/System.Configuration/AppSettingsSection.cs

@@ -73,7 +73,7 @@ namespace System.Configuration {
 			if (File != "") {
 				try {
 					Stream s = System.IO.File.OpenRead (File);
-					XmlReader subreader = new XmlTextReader (s);
+					XmlReader subreader = new ConfigXmlTextReader (s, File);
 					base.DeserializeElement (subreader, serializeCollectionKey);
 					s.Close ();
 				}

+ 26 - 0
mcs/class/System.Configuration/System.Configuration/ChangeLog

@@ -1,3 +1,29 @@
+2008-06-26  Gert Driesen  <[email protected]>
+
+	* ConfigurationElement.cs: Use ConfigurationErrorsException instead of
+	ConfigurationException, and pass reader to ConfigurationErrorsException
+	ctor to allow for file/linenumber info in exception message.
+	* ConfigurationErrorsException.cs: Removed local bareMessage field, and
+	use base.BareMessage field instead. Fixed Message property to only add
+	filename if not null or zero-length string, and only add line if not
+	zero. In GetFilename/GetLineNumber overloads, only try to get info if
+	node/reader implements IConfigErrorInfo.
+	* ConfigurationSection.cs: Use ConfigXmlTextReader instead of
+	XmlTextReader to allow for file/linenumber info in exception messages.
+	* ConfigXmlTextReader.cs: Added XmlTextReader that implements
+	IConfigErrorInfo.
+	* ConfigurationLocation.cs: Use ConfigXmlTextReader instead of
+	XmlTextReader to allow for file/linenumber info in exception messages.
+	* ClientConfigurationSystem.cs: Perform lazy initialization and
+	wrap exceptions in ConfigurationErrorsException. Fixes standalone test
+	t28.
+	* Configuration.cs: Use ConfigXmlTextReader instead of XmlTextReader
+	to allow for file/linenumber info in exception messages.
+	* ConfigInfo.cs: Fixed ThrowException to use file/number info available
+	in XmlTextReader for exception message.
+	* AppSettingsSection.cs: Use ConfigXmlTextReader instead of
+	XmlTextReader to allow for file/linenumber info in exception messages.
+
 2008-06-19  Jb Evain  <[email protected]>
 
 	* ConfigurationPermissionAttribute.cs (CreatePermission): implement.

+ 26 - 15
mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs

@@ -32,28 +32,39 @@ using System;
 using System.Reflection;
 using System.Configuration.Internal;
 
-namespace System.Configuration {
-
+namespace System.Configuration
+{
 	internal class ClientConfigurationSystem : IInternalConfigSystem
 	{
-		readonly Configuration cfg;
+		Configuration cfg;
 
-		public ClientConfigurationSystem () {
-			Assembly a = Assembly.GetEntryAssembly();
-			string exePath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
-            
-			if (a == null && exePath == null)
-				exePath = "";
-            
-			cfg = ConfigurationManager.OpenExeConfigurationInternal (ConfigurationUserLevel.None, a, exePath);
+		public ClientConfigurationSystem ()
+		{
+		}
+
+		private Configuration Configuration {
+			get {
+				if (cfg == null) {
+					Assembly a = Assembly.GetEntryAssembly();
+					string exePath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
+
+					if (a == null && exePath == null)
+						exePath = string.Empty;
+
+					try {
+						cfg = ConfigurationManager.OpenExeConfigurationInternal (
+							ConfigurationUserLevel.None, a, exePath);
+					} catch (Exception ex) {
+						throw new ConfigurationErrorsException ("Error Initializing the configuration system.", ex);
+					}
+				}
+				return cfg;
+			}
 		}
 
 		object IInternalConfigSystem.GetSection (string configKey)
 		{
-			if (cfg == null)
-				return null;
-
-			ConfigurationSection s = cfg.GetSection (configKey);
+			ConfigurationSection s = Configuration.GetSection (configKey);
 			return s != null ? s.GetRuntimeObject () : null;
 		}
 

+ 1 - 1
mcs/class/System.Configuration/System.Configuration/ConfigInfo.cs

@@ -73,7 +73,7 @@ namespace System.Configuration {
 		
 		protected void ThrowException (string text, XmlTextReader reader)
 		{
-			throw new ConfigurationErrorsException (text, StreamName, reader.LineNumber);
+			throw new ConfigurationErrorsException (text, reader);
 		}
 		
 		public abstract void ReadConfig (Configuration cfg, string streamName, XmlTextReader reader);

+ 68 - 0
mcs/class/System.Configuration/System.Configuration/ConfigXmlTextReader.cs

@@ -0,0 +1,68 @@
+//
+// System.Configuration.ConfigXmlTextReader.cs
+//
+// Authors:
+//	Gert Driesen  <[email protected]>
+//
+// Copyright (C) 2008 Gert Driesen
+//
+// 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.
+//
+
+#if NET_2_0
+
+using System;
+using System.Configuration.Internal;
+using System.IO;
+using System.Xml;
+
+internal class ConfigXmlTextReader : XmlTextReader, IConfigErrorInfo
+{
+	private readonly string fileName;
+
+	public ConfigXmlTextReader (Stream s, string fileName) : base (s)
+	{
+		if (fileName == null)
+			throw new ArgumentNullException ("fileName");
+
+		this.fileName = fileName;
+	}
+
+	public ConfigXmlTextReader (TextReader input, string fileName)
+		: base (input)
+	{
+		if (fileName == null)
+			throw new ArgumentNullException ("fileName");
+
+		this.fileName = fileName;
+	}
+
+	public string Filename {
+		get { return fileName; }
+	}
+
+	public int LineNumber {
+		get {
+			return base.LineNumber;
+		}
+	}
+}
+
+#endif

+ 7 - 13
mcs/class/System.Configuration/System.Configuration/Configuration.cs

@@ -216,11 +216,11 @@ namespace System.Configuration {
 					rootSectionGroup.Initialize (this, rootGroup);
 				}
 				return rootSectionGroup;
-			}                        
+			}
 		}
 
 		public ConfigurationSectionGroupCollection SectionGroups {
-			get { return RootSectionGroup.SectionGroups; }                        
+			get { return RootSectionGroup.SectionGroups; }
 		}
 
 		public ConfigurationSectionCollection Sections {
@@ -281,7 +281,7 @@ namespace System.Configuration {
 			sec.Reset (parentSection);
 
 			if (xml != null && xml == data) {
-				XmlTextReader r = new XmlTextReader (new StringReader (xml));
+				XmlTextReader r = new ConfigXmlTextReader (new StringReader (xml), FilePath);
 				sec.DeserializeSection (r);
 				r.Close ();
 
@@ -327,10 +327,10 @@ namespace System.Configuration {
 				object ctx = sec.SectionInformation.AllowExeDefinition != ConfigurationAllowExeDefinition.MachineToApplication ? (object) sec.SectionInformation.AllowExeDefinition : (object) sec.SectionInformation.AllowDefinition;
 				throw new ConfigurationErrorsException ("The section <" + name + "> can't be defined in this configuration file (the allowed definition context is '" + ctx + "').");
 			}
-						
+
 			if (sec.SectionInformation.Type == null)
 				sec.SectionInformation.Type = system.Host.GetConfigTypeName (sec.GetType ());
-			
+
 			SectionInfo section = new SectionInfo (name, sec.SectionInformation);
 			section.StreamName = streamName;
 			section.ConfigHost = system.Host;
@@ -449,7 +449,6 @@ namespace System.Configuration {
 			if (String.IsNullOrEmpty (streamName))
 				return true;
 
-			XmlTextReader reader = null;
 			Stream stream = null;
 			
 			// FIXME: we should remove this kind of hack that
@@ -460,17 +459,12 @@ namespace System.Configuration {
 				return false;
 			}
 
-			try {
-				reader = new XmlTextReader (stream);
+			using (XmlTextReader reader = new ConfigXmlTextReader (stream, streamName)) {
 				ReadConfigFile (reader, streamName);
-			} finally {
-				if (reader != null)
-					reader.Close();
 			}
 			return true;
 		}
 
-
 		void ReadConfigFile (XmlTextReader reader, string fileName)
 		{
 			reader.MoveToContent ();
@@ -507,7 +501,7 @@ namespace System.Configuration {
 			
 			rootGroup.ReadRootData (reader, this, true);
 		}
-		
+
 		internal void ReadData (XmlTextReader reader, bool allowOverride)
 		{
 			rootGroup.ReadData (this, reader, allowOverride);

+ 4 - 4
mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs

@@ -322,13 +322,13 @@ namespace System.Configuration
 					} else if (this is ConfigurationSection && reader.LocalName == "configSource") {
 						/* ignore */
 					} else if (!OnDeserializeUnrecognizedAttribute (reader.LocalName, reader.Value))
-						throw new ConfigurationException ("Unrecognized attribute '" + reader.LocalName + "'.");
+						throw new ConfigurationErrorsException ("Unrecognized attribute '" + reader.LocalName + "'.", reader);
 
 					continue;
 				}
 				
 				if (readProps.ContainsKey (prop))
-					throw new ConfigurationException ("The attribute '" + prop.Name + "' may only appear once in this element.");
+					throw new ConfigurationErrorsException ("The attribute '" + prop.Name + "' may only appear once in this element.", reader);
 
 				string value = null;
 				try {
@@ -369,7 +369,7 @@ namespace System.Configuration
 								if (c != null && c.OnDeserializeUnrecognizedElement (reader.LocalName, reader))
 									continue;
 							}
-							throw new ConfigurationException ("Unrecognized element '" + reader.LocalName + "'.");
+							throw new ConfigurationErrorsException ("Unrecognized element '" + reader.LocalName + "'.", reader);
 						}
 						continue;
 					}
@@ -378,7 +378,7 @@ namespace System.Configuration
 						throw new ConfigurationException ("Property '" + prop.Name + "' is not a ConfigurationElement.");
 					
 					if (readProps.Contains (prop))
-						throw new ConfigurationException ("The element <" + prop.Name + "> may only appear once in this section.");
+						throw new ConfigurationErrorsException ("The element <" + prop.Name + "> may only appear once in this section.", reader);
 					
 					ConfigurationElement val = (ConfigurationElement) prop.Value;
 					val.DeserializeElement (reader, serializeCollectionKey);

+ 32 - 31
mcs/class/System.Configuration/System.Configuration/ConfigurationErrorsException.cs

@@ -32,6 +32,7 @@
 #if NET_2_0
 
 using System;
+using System.Configuration.Internal;
 using System.Globalization;
 using System.Runtime.Serialization;
 using System.Collections;
@@ -55,7 +56,6 @@ namespace System.Configuration
 		public ConfigurationErrorsException (string message)
 			: base (message)
 		{
-			bareMessage = message;
 		}
 
 		protected ConfigurationErrorsException (SerializationInfo info, StreamingContext context)
@@ -98,7 +98,6 @@ namespace System.Configuration
 		public ConfigurationErrorsException (string message, Exception inner, string filename, int line)
 			: base (message, inner)
 		{
-			bareMessage = message;
 			this.filename = filename;
 			this.line = line;
 		}
@@ -106,34 +105,37 @@ namespace System.Configuration
 		//
 		// Properties
 		//
-		public override string BareMessage
-		{
-			get  { return bareMessage; }
+		public override string BareMessage {
+			get  { return base.BareMessage; }
 		}
 
-		public ICollection Errors
-		{
+		public ICollection Errors {
 			get { throw new NotImplementedException (); }
 		}
 
-		public override string Filename
-		{
+		public override string Filename {
 			get { return filename; }
 		}
 		
-		public override int Line
-		{
+		public override int Line {
 			get { return line; }
 		}
 
-		public override string Message
-		{
+		public override string Message {
 			get {
-				string baseMsg = base.Message;
-				string f = (filename == null) ? String.Empty : filename;
-				string l = (line == 0) ? String.Empty : (" line " + line);
-
-				return baseMsg + " (" + f + l + ")";
+				string msg;
+				if (!String.IsNullOrEmpty (filename)) {
+					if (line != 0)
+						msg = BareMessage + " (" + filename + " line " + line + ")";
+					else
+						msg = BareMessage + " (" + filename + ")";
+				} else {
+					if (line != 0)
+						msg = BareMessage + " (line " + line + ")";
+					else
+						msg = BareMessage;
+				}
+				return msg;
 			}
 		}
 		//
@@ -141,34 +143,34 @@ namespace System.Configuration
 		//
 		public static string GetFilename (XmlReader reader)
 		{
-			if (reader is XmlTextReader)
-				return ((XmlTextReader)reader).BaseURI;
+			if (reader is IConfigErrorInfo)
+				return ((IConfigErrorInfo) reader).Filename;
 			else
-				return String.Empty;
+				return null;
 		}
 
 		public static int GetLineNumber (XmlReader reader)
 		{
-			if (reader is XmlTextReader)
-				return ((XmlTextReader)reader).LineNumber;
+			if (reader is IConfigErrorInfo)
+				return ((IConfigErrorInfo) reader).LineNumber;
 			else
 				return 0;
 		}
 
 		public static string GetFilename (XmlNode node)
 		{
-			if (!(node is IConfigXmlNode))
-				return String.Empty;
+			if (!(node is IConfigErrorInfo))
+				return null;
 
-			return ((IConfigXmlNode) node).Filename;
+			return ((IConfigErrorInfo) node).Filename;
 		}
 
 		public static int GetLineNumber (XmlNode node)
 		{
-			if (!(node is IConfigXmlNode))
+			if (!(node is IConfigErrorInfo))
 				return 0;
 
-			return ((IConfigXmlNode) node).LineNumber;
+			return ((IConfigErrorInfo) node).LineNumber;
 		}
 		
 		public override void GetObjectData (SerializationInfo info, StreamingContext context)
@@ -178,9 +180,8 @@ namespace System.Configuration
 			info.AddValue ("ConfigurationErrors_Line", line);
 		}
 
-		string bareMessage = "";
-		string filename = "";
-		int line = 0;
+		readonly string filename;
+		readonly int line;
 	}
 #pragma warning restore
 }

+ 1 - 1
mcs/class/System.Configuration/System.Configuration/ConfigurationLocation.cs

@@ -83,7 +83,7 @@ namespace System.Configuration {
 				}
 				
 				configuration = new Configuration (parent, path);
-				using (XmlTextReader tr = new XmlTextReader (new StringReader (xmlContent)))
+				using (XmlTextReader tr = new ConfigXmlTextReader (new StringReader (xmlContent), path))
 					configuration.ReadData (tr, allowOverride);
 
 				xmlContent = null;

+ 6 - 4
mcs/class/System.Configuration/System.Configuration/ConfigurationSection.cs

@@ -88,9 +88,11 @@ namespace System.Configuration
 				
 				try {
 					// This code requires some re-thinking...
-					XmlReader reader = new XmlTextReader (new StringReader (RawXml));
+					XmlReader reader = new ConfigXmlTextReader (
+						new StringReader (RawXml),
+						Configuration.FilePath);
 
-					DoDeserializeSection (reader);				
+					DoDeserializeSection (reader);
 					
 					if (!String.IsNullOrEmpty (SectionInformation.ConfigSource)) {
 						string fileDir = SectionInformation.ConfigFilePath;
@@ -146,7 +148,7 @@ namespace System.Configuration
 			string localName;
 			
 			while (reader.MoveToNextAttribute ()) {
-				localName = reader.LocalName;				
+				localName = reader.LocalName;
 				if (localName == "configProtectionProvider")
 					protection_provider = reader.Value;
 				else if (localName == "configSource")
@@ -208,7 +210,7 @@ namespace System.Configuration
 			
 			RawXml = File.ReadAllText (path);
 			SectionInformation.SetRawXml (RawXml);
-			DeserializeElement (new XmlTextReader (new StringReader (RawXml)), false);
+			DeserializeElement (new ConfigXmlTextReader (new StringReader (RawXml), path), false);
 		}
 		
 		protected internal virtual string SerializeSection (ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)

+ 1 - 0
mcs/class/System.Configuration/System.Configuration_test.dll.sources

@@ -2,6 +2,7 @@ System.Configuration/CallbackValidatorTest.cs
 System.Configuration/CommaDelimitedStringCollectionConverterTest.cs
 System.Configuration/CommaDelimitedStringCollectionTest.cs
 System.Configuration/ConfigurationElementTest.cs
+System.Configuration/ConfigurationErrorsExceptionTest.cs
 System.Configuration/ConfigurationLockCollectionTest.cs
 System.Configuration/ConfigurationPermissionTest.cs
 System.Configuration/ConfigurationPropertyTest.cs

+ 5 - 0
mcs/class/System.Configuration/Test/System.Configuration/ChangeLog

@@ -1,3 +1,8 @@
+2008-06-26  Gert Driesen  <[email protected]>
+
+	* ConfigurationErrorsExceptionTest.cs: Added tests for ctors and
+	GetFilename/GetLineNumber overloads.
+
 2007-08-31  Gert Driesen  <[email protected]>
 
 	* GenericEnumConverterTest.cs: Remove unused variable.

+ 755 - 0
mcs/class/System.Configuration/Test/System.Configuration/ConfigurationErrorsExceptionTest.cs

@@ -0,0 +1,755 @@
+//
+// ConfigurationErrorsExceptionTest.cs
+//
+// Author:
+//	Gert Driesen  <[email protected]>
+//
+// Copyright (C) 2008 Gert Driesen
+//
+// 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.
+//
+
+#if NET_2_0
+
+using System;
+using System.Configuration;
+using System.Configuration.Internal;
+using System.IO;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Configuration
+{
+	[TestFixture]
+	public class ConfigurationErrorsExceptionTest
+	{
+		private string foldername;
+
+		[SetUp]
+		public void SetUp ()
+		{
+			foldername = Path.Combine (Path.GetTempPath (),
+				this.GetType ().FullName);
+			if (!Directory.Exists (foldername))
+				Directory.CreateDirectory (foldername);
+		}
+
+		[TearDown]
+		public void TearDown ()
+		{
+			if (Directory.Exists (foldername))
+				Directory.Delete (foldername, true);
+		}
+
+		[Test] // ctor ()
+		public void Constructor1 ()
+		{
+			ConfigurationErrorsException cee = new ConfigurationErrorsException ();
+			Assert.IsNotNull (cee.BareMessage, "#1");
+			Assert.IsTrue (cee.BareMessage.IndexOf ("'" + typeof (ConfigurationErrorsException).FullName + "'") != -1, "#2:" + cee.BareMessage);
+			Assert.IsNotNull (cee.Data, "#3");
+			Assert.AreEqual (0, cee.Data.Count, "#4");
+			Assert.IsNull (cee.Filename, "#5");
+			Assert.IsNull (cee.InnerException, "#6");
+			Assert.AreEqual (0, cee.Line, "#7");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#8");
+		}
+
+		[Test] // ctor (String)
+		public void Constructor2 ()
+		{
+			string msg;
+			ConfigurationErrorsException cee;
+
+			msg = "MSG";
+			cee = new ConfigurationErrorsException (msg);
+			Assert.AreSame (msg, cee.BareMessage, "#A1");
+			Assert.IsNotNull (cee.Data, "#A2");
+			Assert.AreEqual (0, cee.Data.Count, "#A3");
+			Assert.IsNull (cee.Filename, "#A4");
+			Assert.IsNull (cee.InnerException, "#A5");
+			Assert.AreEqual (0, cee.Line, "#A6");
+			Assert.AreSame (msg, cee.Message, "#A7");
+
+			msg = null;
+			cee = new ConfigurationErrorsException (msg);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#B1");
+			Assert.IsNotNull (cee.Data, "#B2");
+			Assert.AreEqual (0, cee.Data.Count, "#B3");
+			Assert.IsNull (cee.Filename, "#B4");
+			Assert.IsNull (cee.InnerException, "#B5");
+			Assert.AreEqual (0, cee.Line, "#B6");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#B7");
+		}
+
+		[Test] // ctor (String, Exception)
+		public void Constructor3 ()
+		{
+			string msg;
+			Exception inner;
+			ConfigurationErrorsException cee;
+
+			msg = "MSG";
+			inner = new Exception ();
+			cee = new ConfigurationErrorsException (msg, inner);
+			Assert.AreSame (msg, cee.BareMessage, "#A1");
+			Assert.IsNotNull (cee.Data, "#A2");
+			Assert.AreEqual (0, cee.Data.Count, "#A3");
+			Assert.IsNull (cee.Filename, "#A4");
+			Assert.AreSame (inner, cee.InnerException, "#A5");
+			Assert.AreEqual (0, cee.Line, "#A6");
+			Assert.AreSame (msg, cee.Message, "#A7");
+
+			msg = null;
+			inner = null;
+			cee = new ConfigurationErrorsException (msg, inner);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#B1");
+			Assert.IsNotNull (cee.Data, "#B2");
+			Assert.AreEqual (0, cee.Data.Count, "#B3");
+			Assert.IsNull (cee.Filename, "#B4");
+			Assert.AreSame (inner, cee.InnerException, "#B5");
+			Assert.AreEqual (0, cee.Line, "#B6");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#B7");
+		}
+
+		[Test] // ctor (String, XmlNode)
+		public void Constructor4 ()
+		{
+			string msg;
+			XmlNode node;
+			ConfigurationErrorsException cee;
+
+			string xmlfile = Path.Combine (foldername, "test.xml");
+			XmlDocument doc = new XmlDocument ();
+			doc.AppendChild (doc.CreateElement ("test"));
+			doc.Save (xmlfile);
+
+			msg = "MSG";
+			node = new XmlDocument ();
+			cee = new ConfigurationErrorsException (msg, node);
+			Assert.AreSame (msg, cee.BareMessage, "#A1");
+			Assert.IsNotNull (cee.Data, "#A2");
+			Assert.AreEqual (0, cee.Data.Count, "#A3");
+			Assert.IsNull (cee.Filename, "#A4");
+			Assert.IsNull (cee.InnerException, "#A5");
+			Assert.AreEqual (0, cee.Line, "#A6");
+			Assert.AreSame (msg, cee.Message, "#A7");
+
+			doc = new XmlDocument ();
+			doc.Load (xmlfile);
+
+			msg = "MSG";
+			node = doc.DocumentElement;
+			cee = new ConfigurationErrorsException (msg, node);
+			Assert.AreSame (msg, cee.BareMessage, "#B1");
+			Assert.IsNotNull (cee.Data, "#B2");
+			Assert.AreEqual (0, cee.Data.Count, "#B3");
+			Assert.IsNull (cee.Filename, "#B4");
+			Assert.IsNull (cee.InnerException, "#B5");
+			Assert.AreEqual (0, cee.Line, "#B6");
+			Assert.AreSame (msg, cee.Message, "#B7");
+
+			doc = new ConfigXmlDocument ();
+			doc.Load (xmlfile);
+
+			msg = "MSG";
+			node = doc.DocumentElement;
+			cee = new ConfigurationErrorsException (msg, node);
+			Assert.AreSame (msg, cee.BareMessage, "#C1");
+			Assert.IsNotNull (cee.Data, "#C2");
+			Assert.AreEqual (0, cee.Data.Count, "#C3");
+			Assert.AreEqual (xmlfile, cee.Filename, "#C4");
+			Assert.IsNull (cee.InnerException, "#C5");
+			Assert.AreEqual (1, cee.Line, "#C6");
+			Assert.AreEqual (msg + " (" + xmlfile + " line 1)", cee.Message, "#C7");
+
+			msg = null;
+			node = null;
+			cee = new ConfigurationErrorsException (msg, node);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#D1");
+			Assert.IsNotNull (cee.Data, "#D2");
+			Assert.AreEqual (0, cee.Data.Count, "#D3");
+			Assert.IsNull (cee.Filename, "#D4");
+			Assert.IsNull (cee.InnerException, "#D5");
+			Assert.AreEqual (0, cee.Line, "#D6");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#D7");
+		}
+
+		[Test] // ctor (String, XmlReader)
+		public void Constructor5 ()
+		{
+			string msg;
+			XmlReader reader;
+			ConfigurationErrorsException cee;
+
+			string xmlfile = Path.Combine (foldername, "test.xml");
+
+			XmlDocument doc = new XmlDocument ();
+			doc.AppendChild (doc.CreateElement ("test"));
+			doc.Save (xmlfile);
+
+			using (reader = new XmlTextReader (xmlfile)) {
+				msg = "MSG";
+				cee = new ConfigurationErrorsException (msg, reader);
+				Assert.AreSame (msg, cee.BareMessage, "#A1");
+				Assert.IsNotNull (cee.Data, "#A2");
+				Assert.AreEqual (0, cee.Data.Count, "#A3");
+				Assert.IsNull (cee.Filename, "#A4");
+				Assert.IsNull (cee.InnerException, "#A5");
+				Assert.AreEqual (0, cee.Line, "#A6");
+				Assert.AreSame (msg, cee.Message, "#A7");
+			}
+
+			using (reader = new XmlErrorReader (xmlfile)) {
+				msg = "MSG";
+				cee = new ConfigurationErrorsException (msg, reader);
+				Assert.AreSame (msg, cee.BareMessage, "#B1");
+				Assert.IsNotNull (cee.Data, "#B2");
+				Assert.AreEqual (0, cee.Data.Count, "#B3");
+				Assert.AreEqual ("FILE", cee.Filename, "#B4");
+				Assert.IsNull (cee.InnerException, "#B5");
+				Assert.AreEqual (666, cee.Line, "#B6");
+				Assert.AreEqual (msg + " (FILE line 666)", cee.Message, "#B7");
+			}
+
+			msg = null;
+			reader = null;
+			cee = new ConfigurationErrorsException (msg, reader);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#C1");
+			Assert.IsNotNull (cee.Data, "#C2");
+			Assert.AreEqual (0, cee.Data.Count, "#C3");
+			Assert.IsNull (cee.Filename, "#C4");
+			Assert.IsNull (cee.InnerException, "#C5");
+			Assert.AreEqual (0, cee.Line, "#C6");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#C7");
+		}
+
+		[Test] // ctor (String, Exception, XmlNode)
+		public void Constructor6 ()
+		{
+			string msg;
+			Exception inner;
+			XmlNode node;
+			ConfigurationErrorsException cee;
+
+			string xmlfile = Path.Combine (foldername, "test.xml");
+			XmlDocument doc = new XmlDocument ();
+			doc.AppendChild (doc.CreateElement ("test"));
+			doc.Save (xmlfile);
+
+			msg = "MSG";
+			inner = new Exception ();
+			node = new XmlDocument ();
+			cee = new ConfigurationErrorsException (msg, inner, node);
+			Assert.AreSame (msg, cee.BareMessage, "#A1");
+			Assert.IsNotNull (cee.Data, "#A2");
+			Assert.AreEqual (0, cee.Data.Count, "#A3");
+			Assert.IsNull (cee.Filename, "#A4");
+			Assert.AreSame (inner, cee.InnerException, "#A5");
+			Assert.AreEqual (0, cee.Line, "#A6");
+			Assert.AreSame (msg, cee.Message, "#A7");
+
+			doc = new XmlDocument ();
+			doc.Load (xmlfile);
+
+			msg = null;
+			inner = null;
+			node = doc.DocumentElement;
+			cee = new ConfigurationErrorsException (msg, inner, node);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#B1");
+			Assert.IsNotNull (cee.Data, "#B2");
+			Assert.AreEqual (0, cee.Data.Count, "#B3");
+			Assert.IsNull (cee.Filename, "#B4");
+			Assert.AreSame (inner, cee.InnerException, "#B5");
+			Assert.AreEqual (0, cee.Line, "#B6");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#B7");
+
+			doc = new ConfigXmlDocument ();
+			doc.Load (xmlfile);
+
+			msg = null;
+			inner = null;
+			node = doc.DocumentElement;
+			cee = new ConfigurationErrorsException (msg, inner, node);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#C1");
+			Assert.IsNotNull (cee.Data, "#C2");
+			Assert.AreEqual (0, cee.Data.Count, "#C3");
+			Assert.AreEqual (xmlfile, cee.Filename, "#C4");
+			Assert.AreSame (inner, cee.InnerException, "#C5");
+			Assert.AreEqual (1, cee.Line, "#C6");
+			Assert.AreEqual (cee.BareMessage + " (" + xmlfile + " line 1)", cee.Message, "#C7");
+
+			msg = null;
+			inner = null;
+			node = null;
+			cee = new ConfigurationErrorsException (msg, inner, node);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#D1");
+			Assert.IsNotNull (cee.Data, "#D2");
+			Assert.AreEqual (0, cee.Data.Count, "#D3");
+			Assert.IsNull (cee.Filename, "#D4");
+			Assert.AreSame (inner, cee.InnerException, "#D5");
+			Assert.AreEqual (0, cee.Line, "#D6");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#D7");
+		}
+
+		[Test] // ctor (String, Exception, XmlReader)
+		public void Constructor7 ()
+		{
+			string msg;
+			Exception inner;
+			XmlReader reader;
+			ConfigurationErrorsException cee;
+
+			string xmlfile = Path.Combine (foldername, "test.xml");
+
+			XmlDocument doc = new XmlDocument ();
+			doc.AppendChild (doc.CreateElement ("test"));
+			doc.Save (xmlfile);
+
+			using (reader = new XmlTextReader (xmlfile)) {
+				msg = "MSG";
+				inner = new Exception ();
+				cee = new ConfigurationErrorsException (msg, inner, reader);
+				Assert.AreSame (msg, cee.BareMessage, "#A1");
+				Assert.IsNotNull (cee.Data, "#A2");
+				Assert.AreEqual (0, cee.Data.Count, "#A3");
+				Assert.IsNull (cee.Filename, "#A4");
+				Assert.AreSame (inner, cee.InnerException, "#A5");
+				Assert.AreEqual (0, cee.Line, "#A6");
+				Assert.AreEqual (msg, cee.Message, "#A7");
+			}
+
+			using (reader = new XmlErrorReader (xmlfile)) {
+				msg = "MSG";
+				inner = new Exception ();
+				cee = new ConfigurationErrorsException (msg, inner, reader);
+				Assert.AreSame (msg, cee.BareMessage, "#B1");
+				Assert.IsNotNull (cee.Data, "#B2");
+				Assert.AreEqual (0, cee.Data.Count, "#B3");
+				Assert.AreEqual ("FILE", cee.Filename, "#B4");
+				Assert.AreSame (inner, cee.InnerException, "#B5");
+				Assert.AreEqual (666, cee.Line, "#B6");
+				Assert.AreEqual (msg + " (FILE line 666)", cee.Message, "#B7");
+			}
+
+			msg = null;
+			inner = null;
+			reader = null;
+			cee = new ConfigurationErrorsException (msg, inner, reader);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#C1");
+			Assert.IsNotNull (cee.Data, "#C2");
+			Assert.AreEqual (0, cee.Data.Count, "#C3");
+			Assert.IsNull (cee.Filename, "#C4");
+			Assert.AreSame (inner, cee.InnerException, "#C5");
+			Assert.AreEqual (0, cee.Line, "#C6");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#C7");
+		}
+
+		[Test] // ctor (String, String, Int32)
+		public void Constructor8 ()
+		{
+			string msg;
+			string filename;
+			int line;
+			ConfigurationErrorsException cee;
+
+			msg = "MSG";
+			filename = "abc.txt";
+			line = 7;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#A1");
+			Assert.IsNotNull (cee.Data, "#A2");
+			Assert.AreEqual (0, cee.Data.Count, "#A3");
+			Assert.AreSame (filename, cee.Filename, "#A4");
+			Assert.IsNull (cee.InnerException, "#A5");
+			Assert.AreEqual (line, cee.Line, "#A6");
+			Assert.AreEqual ("MSG (abc.txt line 7)", cee.Message, "#A7");
+
+			msg = null;
+			filename = null;
+			line = 0;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#B1");
+			Assert.IsNotNull (cee.Data, "#B3");
+			Assert.AreEqual (0, cee.Data.Count, "#B4");
+			Assert.AreSame (filename, cee.Filename, "#B5");
+			Assert.IsNull (cee.InnerException, "#B6");
+			Assert.AreEqual (0, cee.Line, "#B7");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#B8");
+
+			msg = null;
+			filename = "abc.txt";
+			line = 5;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#B1");
+			Assert.IsNotNull (cee.Data, "#C2");
+			Assert.AreEqual (0, cee.Data.Count, "#C3");
+			Assert.AreSame (filename, cee.Filename, "#C4");
+			Assert.IsNull (cee.InnerException, "#C5");
+			Assert.AreEqual (5, cee.Line, "#C6");
+			Assert.AreEqual (cee.BareMessage + " (abc.txt line 5)", cee.Message, "#C7");
+
+			msg = "MSG";
+			filename = null;
+			line = 5;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#D1");
+			Assert.IsNotNull (cee.Data, "#D2");
+			Assert.AreEqual (0, cee.Data.Count, "#D3");
+			Assert.AreSame (filename, cee.Filename, "#D4");
+			Assert.IsNull (cee.InnerException, "#D5");
+			Assert.AreEqual (5, cee.Line, "#D6");
+			Assert.AreEqual (msg + " (line 5)", cee.Message, "#D7");
+
+			msg = "MSG";
+			filename = "abc.txt";
+			line = 0;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#E1");
+			Assert.IsNotNull (cee.Data, "#E2");
+			Assert.AreEqual (0, cee.Data.Count, "#E3");
+			Assert.AreSame (filename, cee.Filename, "#E4");
+			Assert.IsNull (cee.InnerException, "#E5");
+			Assert.AreEqual (0, cee.Line, "#E6");
+			Assert.AreEqual (msg + " (abc.txt)", cee.Message, "#E7");
+
+			msg = null;
+			filename = null;
+			line = 4;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#F1");
+			Assert.IsNotNull (cee.Data, "#F2");
+			Assert.AreEqual (0, cee.Data.Count, "#F3");
+			Assert.AreSame (filename, cee.Filename, "#F4");
+			Assert.IsNull (cee.InnerException, "#F5");
+			Assert.AreEqual (4, cee.Line, "#F6");
+			Assert.AreEqual (cee.BareMessage + " (line 4)", cee.Message, "#F7");
+
+			msg = string.Empty;
+			filename = string.Empty;
+			line = 0;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#G1");
+			Assert.IsNotNull (cee.Data, "#G2");
+			Assert.AreEqual (0, cee.Data.Count, "#G3");
+			Assert.AreSame (filename, cee.Filename, "#G4");
+			Assert.IsNull (cee.InnerException, "#G5");
+			Assert.AreEqual (0, cee.Line, "#G6");
+			Assert.AreSame (msg, cee.Message, "#G7");
+
+			msg = string.Empty;
+			filename = "abc.txt";
+			line = 6;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#H1");
+			Assert.IsNotNull (cee.Data, "#H2");
+			Assert.AreEqual (0, cee.Data.Count, "#H3");
+			Assert.AreSame (filename, cee.Filename, "#H4");
+			Assert.IsNull (cee.InnerException, "#H5");
+			Assert.AreEqual (6, cee.Line, "#H6");
+			Assert.AreEqual (msg + " (abc.txt line 6)", cee.Message, "#H7");
+
+			msg = "MSG";
+			filename = string.Empty;
+			line = 6;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#I1");
+			Assert.IsNotNull (cee.Data, "#I2");
+			Assert.AreEqual (0, cee.Data.Count, "#I3");
+			Assert.AreSame (filename, cee.Filename, "#I4");
+			Assert.IsNull (cee.InnerException, "#I5");
+			Assert.AreEqual (6, cee.Line, "#I6");
+			Assert.AreEqual (msg + " (line 6)", cee.Message, "#I7");
+
+			msg = string.Empty;
+			filename = string.Empty;
+			line = 4;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#J1");
+			Assert.IsNotNull (cee.Data, "#J2");
+			Assert.AreEqual (0, cee.Data.Count, "#J3");
+			Assert.AreSame (filename, cee.Filename, "#J4");
+			Assert.IsNull (cee.InnerException, "#J5");
+			Assert.AreEqual (4, cee.Line, "#J6");
+			Assert.AreEqual (msg + " (line 4)", cee.Message, "#J7");
+
+			msg = "MSG";
+			filename = string.Empty;
+			line = 0;
+			cee = new ConfigurationErrorsException (msg, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#K1");
+			Assert.IsNotNull (cee.Data, "#K2");
+			Assert.AreEqual (0, cee.Data.Count, "#K3");
+			Assert.AreSame (filename, cee.Filename, "#K4");
+			Assert.IsNull (cee.InnerException, "#K5");
+			Assert.AreEqual (0, cee.Line, "#K6");
+			Assert.AreEqual (msg, cee.Message, "#K7");
+		}
+
+		[Test] // ctor (String, Exception, String, Int32)
+		public void Constructor9 ()
+		{
+			string msg;
+			Exception inner;
+			string filename;
+			int line;
+			ConfigurationErrorsException cee;
+
+			msg = "MSG";
+			inner = new Exception ();
+			filename = "abc.txt";
+			line = 7;
+			cee = new ConfigurationErrorsException (msg, inner, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#A1");
+			Assert.IsNotNull (cee.Data, "#A2");
+			Assert.AreEqual (0, cee.Data.Count, "#A3");
+			Assert.AreSame (filename, cee.Filename, "#A4");
+			Assert.AreSame (inner, cee.InnerException, "#A5");
+			Assert.AreEqual (line, cee.Line, "#A6");
+			Assert.AreEqual (msg + " (abc.txt line 7)", cee.Message, "#A7");
+
+			msg = null;
+			inner = null;
+			filename = null;
+			line = 0;
+			cee = new ConfigurationErrorsException (msg, inner, filename, line);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#B1");
+			Assert.IsNotNull (cee.Data, "#B2");
+			Assert.AreEqual (0, cee.Data.Count, "#B3");
+			Assert.AreSame (filename, cee.Filename, "#B4");
+			Assert.AreSame (inner, cee.InnerException, "#B5");
+			Assert.AreEqual (0, cee.Line, "#B6");
+			Assert.AreEqual (cee.BareMessage, cee.Message, "#B7");
+
+			msg = null;
+			inner = new Exception ();
+			filename = null;
+			line = 7;
+			cee = new ConfigurationErrorsException (msg, inner, filename, line);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#C1");
+			Assert.IsNotNull (cee.Data, "#C2");
+			Assert.AreEqual (0, cee.Data.Count, "#C3");
+			Assert.AreSame (filename, cee.Filename, "#C4");
+			Assert.AreSame (inner, cee.InnerException, "#C5");
+			Assert.AreEqual (line, cee.Line, "#C6");
+			Assert.AreEqual (cee.BareMessage + " (line 7)", cee.Message, "#C7");
+
+			msg = string.Empty;
+			inner = new Exception ();
+			filename = string.Empty;
+			line = 7;
+			cee = new ConfigurationErrorsException (msg, inner, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#D1");
+			Assert.IsNotNull (cee.Data, "#D2");
+			Assert.AreEqual (0, cee.Data.Count, "#D3");
+			Assert.AreSame (filename, cee.Filename, "#D4");
+			Assert.AreSame (inner, cee.InnerException, "#D5");
+			Assert.AreEqual (line, cee.Line, "#D6");
+			Assert.AreEqual (" (line 7)", cee.Message, "#D7");
+
+			msg = string.Empty;
+			inner = new Exception ();
+			filename = "abc.txt";
+			line = 7;
+			cee = new ConfigurationErrorsException (msg, inner, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#E1");
+			Assert.IsNotNull (cee.Data, "#E2");
+			Assert.AreEqual (0, cee.Data.Count, "#E3");
+			Assert.AreSame (filename, cee.Filename, "#E4");
+			Assert.AreSame (inner, cee.InnerException, "#E5");
+			Assert.AreEqual (line, cee.Line, "#E6");
+			Assert.AreEqual (" (abc.txt line 7)", cee.Message, "#E7");
+
+			msg = "MSG";
+			inner = new Exception ();
+			filename = null;
+			line = 7;
+			cee = new ConfigurationErrorsException (msg, inner, filename, line);
+			Assert.AreSame (msg, cee.BareMessage, "#F1");
+			Assert.IsNotNull (cee.Data, "#F2");
+			Assert.AreEqual (0, cee.Data.Count, "#F3");
+			Assert.AreSame (filename, cee.Filename, "#F4");
+			Assert.AreSame (inner, cee.InnerException, "#F5");
+			Assert.AreEqual (line, cee.Line, "#F6");
+			Assert.AreEqual (cee.BareMessage + " (line 7)", cee.Message, "#F7");
+
+			msg = null;
+			inner = new Exception ();
+			filename = "abc.txt";
+			line = 7;
+			cee = new ConfigurationErrorsException (msg, inner, filename, line);
+			Assert.AreEqual (new ConfigurationErrorsException ().Message, cee.BareMessage, "#G1");
+			Assert.IsNotNull (cee.Data, "#G2");
+			Assert.AreEqual (0, cee.Data.Count, "#G3");
+			Assert.AreSame (filename, cee.Filename, "#G4");
+			Assert.AreSame (inner, cee.InnerException, "#G5");
+			Assert.AreEqual (line, cee.Line, "#G6");
+			Assert.AreEqual (cee.BareMessage + " (abc.txt line 7)", cee.Message, "#G7");
+		}
+
+		[Test] // GetFilename (XmlReader)
+		public void GetFilename1 ()
+		{
+			string xmlfile = Path.Combine (foldername, "test.xml");
+			XmlDocument doc = new XmlDocument ();
+			doc.AppendChild (doc.CreateElement ("test"));
+			doc.Save (xmlfile);
+
+			using (XmlReader reader = new XmlTextReader (xmlfile)) {
+				string filename = ConfigurationErrorsException.GetFilename (reader);
+				Assert.IsNull (filename, "#1");
+			}
+
+			using (XmlErrorReader reader = new XmlErrorReader (xmlfile)) {
+				string filename = ConfigurationErrorsException.GetFilename (reader);
+				Assert.AreEqual ("FILE", filename, "#2");
+			}
+		}
+
+		[Test] // GetFilename (XmlReader)
+		public void GetFilename1_Reader_Null ()
+		{
+			XmlReader reader = null;
+			string filename = ConfigurationErrorsException.GetFilename (reader);
+			Assert.IsNull (filename);
+		}
+
+		[Test] // GetFilename (XmlNode)
+		public void GetFilename2 ()
+		{
+			XmlNode node;
+			string filename;
+
+			string xmlfile = Path.Combine (foldername, "test.xml");
+			XmlDocument doc = new XmlDocument ();
+			doc.AppendChild (doc.CreateElement ("test"));
+			doc.Save (xmlfile);
+
+			node = new XmlDocument ();
+			filename = ConfigurationErrorsException.GetFilename (node);
+			Assert.IsNull (filename, "#1");
+
+			doc = new XmlDocument ();
+			doc.Load (xmlfile);
+
+			node = doc.DocumentElement;
+			filename = ConfigurationErrorsException.GetFilename (node);
+			Assert.IsNull (filename, "#2");
+
+			doc = new ConfigXmlDocument ();
+			doc.Load (xmlfile);
+
+			node = doc.DocumentElement;
+			filename = ConfigurationErrorsException.GetFilename (node);
+			Assert.AreEqual (xmlfile, filename, "#3");
+		}
+
+		[Test] // GetFilename (XmlNode)
+		public void GetFilename2_Node_Null ()
+		{
+			XmlNode node = null;
+			string filename = ConfigurationErrorsException.GetFilename (node);
+			Assert.IsNull (filename);
+		}
+
+		[Test] // GetLineNumber (XmlReader)
+		public void GetLineNumber1 ()
+		{
+			string xmlfile = Path.Combine (foldername, "test.xml");
+			XmlDocument doc = new XmlDocument ();
+			doc.AppendChild (doc.CreateElement ("test"));
+			doc.Save (xmlfile);
+
+			using (XmlReader reader = new XmlTextReader (xmlfile)) {
+				int line = ConfigurationErrorsException.GetLineNumber (reader);
+				Assert.AreEqual (0, line, "#1");
+			}
+
+			using (XmlErrorReader reader = new XmlErrorReader (xmlfile)) {
+				int line = ConfigurationErrorsException.GetLineNumber (reader);
+				Assert.AreEqual (666, line, "#1");
+			}
+		}
+
+		[Test] // GetLineNumber (XmlReader)
+		public void GetLineNumber1_Reader_Null ()
+		{
+			XmlReader reader = null;
+			int line = ConfigurationErrorsException.GetLineNumber (reader);
+			Assert.AreEqual (0, line);
+		}
+
+		[Test] // GetLineNumber (XmlNode)
+		public void GetLineNumber2 ()
+		{
+			XmlNode node;
+			int line;
+
+			string xmlfile = Path.Combine (foldername, "test.xml");
+			XmlDocument doc = new XmlDocument ();
+			doc.AppendChild (doc.CreateElement ("test"));
+			doc.Save (xmlfile);
+
+			node = new XmlDocument ();
+			line = ConfigurationErrorsException.GetLineNumber (node);
+			Assert.AreEqual (0, line, "#1");
+
+			doc = new XmlDocument ();
+			doc.Load (xmlfile);
+
+			node = doc.DocumentElement;
+			line = ConfigurationErrorsException.GetLineNumber (node);
+			Assert.AreEqual (0, line, "#2");
+
+			doc = new ConfigXmlDocument ();
+			doc.Load (xmlfile);
+
+			node = doc.DocumentElement;
+			line = ConfigurationErrorsException.GetLineNumber (node);
+			Assert.AreEqual (1, line, "#3");
+		}
+
+		[Test] // GetLineNumber (XmlNode)
+		public void GetLineNumber2_Node_Null ()
+		{
+			XmlNode node = null;
+			int line = ConfigurationErrorsException.GetLineNumber (node);
+			Assert.AreEqual (0, line);
+		}
+
+		class XmlErrorReader : XmlTextReader, IConfigErrorInfo
+		{
+			public XmlErrorReader (string filename) : base (filename)
+			{
+			}
+
+			string IConfigErrorInfo.Filename {
+				get { return "FILE"; }
+			}
+
+			int IConfigErrorInfo.LineNumber {
+				get { return 666; }
+			}
+		}
+	}
+}
+
+#endif

+ 86 - 0
mcs/class/System.Configuration/Test/standalone/Assert.cs

@@ -0,0 +1,86 @@
+using System;
+using System.Globalization;
+
+class Assert
+{
+	public static void AreEqual (string x, string y, string msg)
+	{
+		if (x == null && y == null)
+			return;
+		if ((x == null || y == null) || !x.Equals (y))
+			throw new Exception (string.Format (CultureInfo.InvariantCulture,
+				"Expected: {0}, but was: {1}. {2}",
+				x == null ? "<null>" : x, y == null ? "<null>" : y, msg));
+	}
+
+	public static void AreEqual (object x, object y, string msg)
+	{
+		if (x == null && y == null)
+			return;
+		if ((x == null || y == null))
+			throw new Exception (string.Format (CultureInfo.InvariantCulture,
+				"Expected: {0}, but was: {1}. {2}",
+				x == null ? "<null>" : x, y == null ? "<null>" : y, msg));
+
+		bool isArrayX = x.GetType ().IsArray;
+		bool isArrayY = y.GetType ().IsArray;
+
+		if (isArrayX && isArrayY) {
+			Array arrayX = (Array) x;
+			Array arrayY = (Array) y;
+
+			if (arrayX.Length != arrayY.Length)
+				throw new Exception (string.Format (CultureInfo.InvariantCulture,
+					"Length of arrays differs. Expected: {0}, but was: {1}. {2}",
+					arrayX.Length, arrayY.Length, msg));
+
+			for (int i = 0; i < arrayX.Length; i++) {
+				object itemX = arrayX.GetValue (i);
+				object itemY = arrayY.GetValue (i);
+				if (!itemX.Equals (itemY))
+					throw new Exception (string.Format (CultureInfo.InvariantCulture,
+						"Arrays differ at position {0}. Expected: {1}, but was: {2}. {3}",
+						i, itemX, itemY, msg));
+			}
+		} else if (!x.Equals (y)) {
+			throw new Exception (string.Format (CultureInfo.InvariantCulture,
+				"Expected: {0}, but was: {1}. {2}",
+				x, y, msg));
+		}
+	}
+
+	public static void Fail (string msg)
+	{
+		throw new Exception (msg);
+	}
+
+	public static void IsFalse (bool value, string msg)
+	{
+		if (value)
+			throw new Exception (msg);
+	}
+
+	public static void IsTrue (bool value, string msg)
+	{
+		if (!value)
+			throw new Exception (msg);
+	}
+
+	public static void IsNotNull (object value, string msg)
+	{
+		if (value == null)
+			throw new Exception (msg);
+	}
+
+	public static void IsNull (object value, string msg)
+	{
+		if (value != null)
+			throw new Exception (msg);
+	}
+
+	public static void AreSame (object x, object y, string msg)
+	{
+		if (!object.ReferenceEquals (x, y))
+			throw new Exception (msg);
+	}
+}

+ 6 - 0
mcs/class/System.Configuration/Test/standalone/ChangeLog

@@ -1,3 +1,9 @@
+2008-06-26  Gert Driesen  <[email protected]>
+
+	* Assert.cs: added.
+	* Makefile: added Assert.cs, and explicitly specify output file.
+	* t28.cs: Improved test.
+
 2007-11-15  Atsushi Enomoto  <[email protected]>
 
 	* Makefile : added -r:System.Data.

+ 1 - 1
mcs/class/System.Configuration/Test/standalone/Makefile

@@ -23,4 +23,4 @@ t36.exe : t36.cs t36-lib.cs
 	gmcs /debug -r:System.Configuration.dll -r:t36-lib.dll t36.cs
 
 %.exe: %.cs
-	gmcs /debug $< -r:System.Configuration.dll -r:System.Web.dll -r:System.Data.dll
+	gmcs /debug /out:$@ Assert.cs $< -r:System.Configuration.dll -r:System.Web.dll -r:System.Data.dll

+ 21 - 7
mcs/class/System.Configuration/Test/standalone/t28.cs

@@ -9,14 +9,28 @@ class T1
 {
 	static void Main(string[] args)
 	{
-		try
-		{
+		try {
 			NameValueCollection AppSettings = ConfigurationManager.AppSettings;
+			Assert.Fail ("#1:" + AppSettings);
+		} catch (ConfigurationErrorsException ex) {
+			// Configuration system failed to initialize
+			Assert.AreEqual (typeof (ConfigurationErrorsException), ex.GetType (), "#2");
+			Assert.IsNull (ex.Filename, "#3");
+			Assert.IsNotNull (ex.InnerException, "#6");
+			Assert.AreEqual (0, ex.Line, "#7");
+			Assert.IsNotNull (ex.Message, "#8");
+
+			// <location> sections are allowed only within <configuration> sections
+			ConfigurationErrorsException inner = ex.InnerException as ConfigurationErrorsException;
+			Assert.AreEqual (typeof (ConfigurationErrorsException), inner.GetType (), "#9");
+			Assert.AreEqual (AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, inner.Filename, "#10");
+			Assert.IsNull (inner.InnerException, "#11");
+			Assert.AreEqual (3, inner.Line, "#12");
+			Assert.IsNotNull (inner.Message, "#13");
+			Assert.IsTrue (inner.Message.IndexOf ("<location>") != -1, "#14:" + inner.Message);
+			Assert.IsTrue (inner.Message.IndexOf ("<configuration>") != -1, "#15:" + inner.Message);
+
+			Console.WriteLine ("configuration exception thrown.");
 		}
-		catch (ConfigurationErrorsException e) {
-			Console.WriteLine ("configuration exception thrown.");
-			return;
-		}
-		Console.WriteLine ("configuration exception not thrown.");
 	}
 }

+ 0 - 0
mcs/class/System.Configuration/Test/standalone/t42.cs