changeset 0:ada654b0648c

Re #7 - add IBBoard.Ini test\n * Add initial tests
author IBBoard <dev@ibboard.co.uk>
date Mon, 12 Jan 2009 20:41:45 +0000
parents
children c2a0d074b3b5
files IBBoard.Ini.Tests.mdp IniFileReaderTest.cs IniLineParserTest.cs TestData/DoubleSectionWithContent.ini TestData/EmptyFile.ini TestData/SingleSectionSingleLine.ini TestData/SingleSectionWithContent.ini
diffstat 6 files changed, 174 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IBBoard.Ini.Tests.mdp	Mon Jan 12 20:41:45 2009 +0000
@@ -0,0 +1,30 @@
+<Project name="IBBoard.Ini.Tests" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
+  <Configurations active="Debug">
+    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+      <Output directory="bin/Debug" assembly="IBBoard.Ini.Tests" />
+      <Build debugmode="True" target="Library" />
+      <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+    </Configuration>
+    <Configuration name="Release" ctype="DotNetProjectConfiguration">
+      <Output directory="bin/Release" assembly="IBBoard.Ini.Tests" />
+      <Build debugmode="False" target="Library" />
+      <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+    </Configuration>
+  </Configurations>
+  <Contents>
+    <File name="IniLineParserTest.cs" subtype="Code" buildaction="Compile" />
+    <File name="IniFileReaderTest.cs" subtype="Code" buildaction="Compile" />
+    <File name="TestData" subtype="Directory" buildaction="Compile" />
+    <File name="TestData/EmptyFile.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
+    <File name="TestData/SingleSectionSingleLine.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
+    <File name="TestData/SingleSectionWithContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
+    <File name="TestData/DoubleSectionWithContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
+  </Contents>
+  <References>
+    <ProjectReference type="Project" localcopy="True" refto="IBBoard.Ini" />
+    <ProjectReference type="Gac" localcopy="True" refto="nunit.framework, Version=2.2.9.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
+  </References>
+  <GtkDesignInfo />
+</Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IniFileReaderTest.cs	Mon Jan 12 20:41:45 2009 +0000
@@ -0,0 +1,96 @@
+// This file (IniFileReaderTest.cs) is a part of the IBBoard.Ini.Tests library and is copyright 2009 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU LGPL license. Please see COPYING.LGPL for more information and the full license.
+
+using System;
+using System.IO;
+using NUnit.Framework;
+
+namespace IBBoard.Ini
+{
+	[TestFixture()]
+	public class IniFileReaderTest
+	{
+		[Test()]
+		public void TestIniFileReaderReturnsEmptyObjectForEmptyIniText()
+		{
+			IniFile file = IniFileReader.ReadFile("");
+			Assert.AreEqual(0, file.Sections.Length);
+		}
+
+		
+		[Test()]
+		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniText()
+		{
+			IniFile file = IniFileReader.ReadFile("[ASection]");
+			Assert.AreEqual(1, file.Sections.Length);
+			Assert.IsTrue(file.HasSection("ASection"));
+			Assert.IsNotNull(file["ASection"]);
+			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
+		}
+		
+		[Test()]
+		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniTextWithContent()
+		{
+			IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble");
+			Assert.AreEqual(1, file.Sections.Length);
+			Assert.IsTrue(file.HasSection("ASection"));
+			Assert.IsNotNull(file["ASection"]);
+			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
+		}
+		
+		[Test()]
+		public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniTextWithContent()
+		{
+			IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble\n[BSection]\nsomethingElse=fibble");
+			Assert.AreEqual(2, file.Sections.Length);
+			Assert.IsTrue(file.HasSection("ASection"));
+			Assert.IsNotNull(file["ASection"]);
+			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
+			Assert.IsTrue(file.HasSection("BSection"));
+			Assert.IsNotNull(file["BSection"]);
+			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]);
+		}
+		
+		[Test()]
+		public void TestIniFileReaderReturnsEmptyObjectForEmptyIniFile()
+		{
+			IniFile file = IniFileReader.ReadFile(new FileInfo("EmptyFile.ini"));
+			Assert.AreEqual(0, file.Sections.Length);
+		}
+
+		
+		[Test()]
+		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFile()
+		{
+			IniFile file = IniFileReader.ReadFile(new FileInfo("SingleSectionSingleLine.ini"));
+			Assert.AreEqual(1, file.Sections.Length);
+			Assert.IsTrue(file.HasSection("ASection"));
+			Assert.IsNotNull(file["ASection"]);
+			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
+		}
+		
+		[Test()]
+		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFileWithContent()
+		{
+			IniFile file = IniFileReader.ReadFile(new FileInfo("SingleSectionWithContent.ini"));
+			Assert.AreEqual(1, file.Sections.Length);
+			Assert.IsTrue(file.HasSection("ASection"));
+			Assert.IsNotNull(file["ASection"]);
+			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
+		}
+		
+		[Test()]
+		public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniFileWithContent()
+		{
+			IniFile file = IniFileReader.ReadFile(new FileInfo("DoubleSectionWithContent.ini"));
+			Assert.AreEqual(2, file.Sections.Length);
+			Assert.IsTrue(file.HasSection("ASection"));
+			Assert.IsNotNull(file["ASection"]);
+			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
+			Assert.IsTrue(file.HasSection("BSection"));
+			Assert.IsNotNull(file["BSection"]);
+			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]);
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IniLineParserTest.cs	Mon Jan 12 20:41:45 2009 +0000
@@ -0,0 +1,41 @@
+// This file (IniLineParserTest.cs) is a part of the IBBoard.Ini.Tests library and is copyright 2009 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU LGPL license. Please see COPYING.LGPL for more information and the full license.
+
+using System;
+using NUnit.Framework;
+
+namespace IBBoard.Ini
+{
+	[TestFixture()]
+	public class IniLineParserTest
+	{
+		[Test()]
+		public void TestIniLineParserReturnsExceptedKeyValuePairForValidProperty()
+		{
+			IIniLine iniLine = IniLineParser.ParseIniLine("some_key=some_value");
+			Assert.IsInstanceOfType(typeof(IniKeyValuePairLine), iniLine);
+			IniKeyValuePairLine keyValuePair = (IniKeyValuePairLine)iniLine;
+			Assert.AreEqual("some_key", keyValuePair.Key);
+			Assert.AreEqual("some_value", keyValuePair.Value);
+		}
+		
+		[Test()]
+		public void TestIniLineParserReturnsCommentLineForNonProperty()
+		{
+			IIniLine iniLine = IniLineParser.ParseIniLine("something that isn't a property");
+			Assert.IsInstanceOfType(typeof(IniCommentLine), iniLine);
+			IniCommentLine commentLine = (IniCommentLine)iniLine;
+			Assert.AreEqual("something that isn't a property", commentLine.Comment);
+		}
+		
+		[Test()]
+		public void TestIniLineParserReturnsCommentForComment()
+		{
+			IIniLine iniLine = IniLineParser.ParseIniLine("; something that looks like a comment");
+			Assert.IsInstanceOfType(typeof(IniCommentLine), iniLine);
+			IniCommentLine commentLine = (IniCommentLine)iniLine;
+			Assert.AreEqual(" something that looks like a comment", commentLine.Comment);
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TestData/DoubleSectionWithContent.ini	Mon Jan 12 20:41:45 2009 +0000
@@ -0,0 +1,4 @@
+[ASection]
+something=fibble
+[BSection]
+somethingElse=fibble
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TestData/SingleSectionSingleLine.ini	Mon Jan 12 20:41:45 2009 +0000
@@ -0,0 +1,1 @@
+[ASection]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TestData/SingleSectionWithContent.ini	Mon Jan 12 20:41:45 2009 +0000
@@ -0,0 +1,2 @@
+[ASection]
+something=fibble
\ No newline at end of file