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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/IBBoard.Ini.Tests.mdp	Mon Jan 12 20:41:45 2009 +0000
     1.3 @@ -0,0 +1,30 @@
     1.4 +<Project name="IBBoard.Ini.Tests" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
     1.5 +  <Configurations active="Debug">
     1.6 +    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
     1.7 +      <Output directory="bin/Debug" assembly="IBBoard.Ini.Tests" />
     1.8 +      <Build debugmode="True" target="Library" />
     1.9 +      <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
    1.10 +      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
    1.11 +    </Configuration>
    1.12 +    <Configuration name="Release" ctype="DotNetProjectConfiguration">
    1.13 +      <Output directory="bin/Release" assembly="IBBoard.Ini.Tests" />
    1.14 +      <Build debugmode="False" target="Library" />
    1.15 +      <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
    1.16 +      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
    1.17 +    </Configuration>
    1.18 +  </Configurations>
    1.19 +  <Contents>
    1.20 +    <File name="IniLineParserTest.cs" subtype="Code" buildaction="Compile" />
    1.21 +    <File name="IniFileReaderTest.cs" subtype="Code" buildaction="Compile" />
    1.22 +    <File name="TestData" subtype="Directory" buildaction="Compile" />
    1.23 +    <File name="TestData/EmptyFile.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
    1.24 +    <File name="TestData/SingleSectionSingleLine.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
    1.25 +    <File name="TestData/SingleSectionWithContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
    1.26 +    <File name="TestData/DoubleSectionWithContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
    1.27 +  </Contents>
    1.28 +  <References>
    1.29 +    <ProjectReference type="Project" localcopy="True" refto="IBBoard.Ini" />
    1.30 +    <ProjectReference type="Gac" localcopy="True" refto="nunit.framework, Version=2.2.9.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
    1.31 +  </References>
    1.32 +  <GtkDesignInfo />
    1.33 +</Project>
    1.34 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/IniFileReaderTest.cs	Mon Jan 12 20:41:45 2009 +0000
     2.3 @@ -0,0 +1,96 @@
     2.4 +// This file (IniFileReaderTest.cs) is a part of the IBBoard.Ini.Tests library and is copyright 2009 IBBoard.
     2.5 +//
     2.6 +// 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.
     2.7 +
     2.8 +using System;
     2.9 +using System.IO;
    2.10 +using NUnit.Framework;
    2.11 +
    2.12 +namespace IBBoard.Ini
    2.13 +{
    2.14 +	[TestFixture()]
    2.15 +	public class IniFileReaderTest
    2.16 +	{
    2.17 +		[Test()]
    2.18 +		public void TestIniFileReaderReturnsEmptyObjectForEmptyIniText()
    2.19 +		{
    2.20 +			IniFile file = IniFileReader.ReadFile("");
    2.21 +			Assert.AreEqual(0, file.Sections.Length);
    2.22 +		}
    2.23 +
    2.24 +		
    2.25 +		[Test()]
    2.26 +		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniText()
    2.27 +		{
    2.28 +			IniFile file = IniFileReader.ReadFile("[ASection]");
    2.29 +			Assert.AreEqual(1, file.Sections.Length);
    2.30 +			Assert.IsTrue(file.HasSection("ASection"));
    2.31 +			Assert.IsNotNull(file["ASection"]);
    2.32 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
    2.33 +		}
    2.34 +		
    2.35 +		[Test()]
    2.36 +		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniTextWithContent()
    2.37 +		{
    2.38 +			IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble");
    2.39 +			Assert.AreEqual(1, file.Sections.Length);
    2.40 +			Assert.IsTrue(file.HasSection("ASection"));
    2.41 +			Assert.IsNotNull(file["ASection"]);
    2.42 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
    2.43 +		}
    2.44 +		
    2.45 +		[Test()]
    2.46 +		public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniTextWithContent()
    2.47 +		{
    2.48 +			IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble\n[BSection]\nsomethingElse=fibble");
    2.49 +			Assert.AreEqual(2, file.Sections.Length);
    2.50 +			Assert.IsTrue(file.HasSection("ASection"));
    2.51 +			Assert.IsNotNull(file["ASection"]);
    2.52 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
    2.53 +			Assert.IsTrue(file.HasSection("BSection"));
    2.54 +			Assert.IsNotNull(file["BSection"]);
    2.55 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]);
    2.56 +		}
    2.57 +		
    2.58 +		[Test()]
    2.59 +		public void TestIniFileReaderReturnsEmptyObjectForEmptyIniFile()
    2.60 +		{
    2.61 +			IniFile file = IniFileReader.ReadFile(new FileInfo("EmptyFile.ini"));
    2.62 +			Assert.AreEqual(0, file.Sections.Length);
    2.63 +		}
    2.64 +
    2.65 +		
    2.66 +		[Test()]
    2.67 +		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFile()
    2.68 +		{
    2.69 +			IniFile file = IniFileReader.ReadFile(new FileInfo("SingleSectionSingleLine.ini"));
    2.70 +			Assert.AreEqual(1, file.Sections.Length);
    2.71 +			Assert.IsTrue(file.HasSection("ASection"));
    2.72 +			Assert.IsNotNull(file["ASection"]);
    2.73 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
    2.74 +		}
    2.75 +		
    2.76 +		[Test()]
    2.77 +		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFileWithContent()
    2.78 +		{
    2.79 +			IniFile file = IniFileReader.ReadFile(new FileInfo("SingleSectionWithContent.ini"));
    2.80 +			Assert.AreEqual(1, file.Sections.Length);
    2.81 +			Assert.IsTrue(file.HasSection("ASection"));
    2.82 +			Assert.IsNotNull(file["ASection"]);
    2.83 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
    2.84 +		}
    2.85 +		
    2.86 +		[Test()]
    2.87 +		public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniFileWithContent()
    2.88 +		{
    2.89 +			IniFile file = IniFileReader.ReadFile(new FileInfo("DoubleSectionWithContent.ini"));
    2.90 +			Assert.AreEqual(2, file.Sections.Length);
    2.91 +			Assert.IsTrue(file.HasSection("ASection"));
    2.92 +			Assert.IsNotNull(file["ASection"]);
    2.93 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
    2.94 +			Assert.IsTrue(file.HasSection("BSection"));
    2.95 +			Assert.IsNotNull(file["BSection"]);
    2.96 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]);
    2.97 +		}
    2.98 +	}
    2.99 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/IniLineParserTest.cs	Mon Jan 12 20:41:45 2009 +0000
     3.3 @@ -0,0 +1,41 @@
     3.4 +// This file (IniLineParserTest.cs) is a part of the IBBoard.Ini.Tests library and is copyright 2009 IBBoard.
     3.5 +//
     3.6 +// 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.
     3.7 +
     3.8 +using System;
     3.9 +using NUnit.Framework;
    3.10 +
    3.11 +namespace IBBoard.Ini
    3.12 +{
    3.13 +	[TestFixture()]
    3.14 +	public class IniLineParserTest
    3.15 +	{
    3.16 +		[Test()]
    3.17 +		public void TestIniLineParserReturnsExceptedKeyValuePairForValidProperty()
    3.18 +		{
    3.19 +			IIniLine iniLine = IniLineParser.ParseIniLine("some_key=some_value");
    3.20 +			Assert.IsInstanceOfType(typeof(IniKeyValuePairLine), iniLine);
    3.21 +			IniKeyValuePairLine keyValuePair = (IniKeyValuePairLine)iniLine;
    3.22 +			Assert.AreEqual("some_key", keyValuePair.Key);
    3.23 +			Assert.AreEqual("some_value", keyValuePair.Value);
    3.24 +		}
    3.25 +		
    3.26 +		[Test()]
    3.27 +		public void TestIniLineParserReturnsCommentLineForNonProperty()
    3.28 +		{
    3.29 +			IIniLine iniLine = IniLineParser.ParseIniLine("something that isn't a property");
    3.30 +			Assert.IsInstanceOfType(typeof(IniCommentLine), iniLine);
    3.31 +			IniCommentLine commentLine = (IniCommentLine)iniLine;
    3.32 +			Assert.AreEqual("something that isn't a property", commentLine.Comment);
    3.33 +		}
    3.34 +		
    3.35 +		[Test()]
    3.36 +		public void TestIniLineParserReturnsCommentForComment()
    3.37 +		{
    3.38 +			IIniLine iniLine = IniLineParser.ParseIniLine("; something that looks like a comment");
    3.39 +			Assert.IsInstanceOfType(typeof(IniCommentLine), iniLine);
    3.40 +			IniCommentLine commentLine = (IniCommentLine)iniLine;
    3.41 +			Assert.AreEqual(" something that looks like a comment", commentLine.Comment);
    3.42 +		}
    3.43 +	}
    3.44 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/TestData/DoubleSectionWithContent.ini	Mon Jan 12 20:41:45 2009 +0000
     4.3 @@ -0,0 +1,4 @@
     4.4 +[ASection]
     4.5 +something=fibble
     4.6 +[BSection]
     4.7 +somethingElse=fibble
     4.8 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/TestData/SingleSectionSingleLine.ini	Mon Jan 12 20:41:45 2009 +0000
     5.3 @@ -0,0 +1,1 @@
     5.4 +[ASection]
     5.5 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/TestData/SingleSectionWithContent.ini	Mon Jan 12 20:41:45 2009 +0000
     6.3 @@ -0,0 +1,2 @@
     6.4 +[ASection]
     6.5 +something=fibble
     6.6 \ No newline at end of file