view IniFileReaderTest.cs @ 12:0be17f8102ed

* Fix unit test paths
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Nov 2012 20:22:20 +0000
parents 4f281289bcdd
children
line source
1 // This file (IniFileReaderTest.cs) is a part of the IBBoard.Ini.Tests library and is copyright 2009 IBBoard.
2 //
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
4 using System;
5 using System.IO;
6 using NUnit.Framework;
8 namespace IBBoard.Ini
9 {
10 [TestFixture()]
11 public class IniFileReaderTest
12 {
13 [Test()]
14 public void TestIniFileReaderReturnsEmptyObjectForEmptyIniText()
15 {
16 IniFile file = IniFileReader.ReadFile("");
17 Assert.AreEqual(0, file.Sections.Length);
18 }
20 [Test()]
21 public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniText()
22 {
23 IniFile file = IniFileReader.ReadFile("[ASection]");
24 Assert.AreEqual(1, file.Sections.Length);
25 Assert.IsTrue(file.HasSection("ASection"));
26 Assert.IsNotNull(file["ASection"]);
27 Assert.AreEqual(0, file["ASection"].Keys.Length);
28 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
29 }
31 [Test()]
32 public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniTextWithContent()
33 {
34 IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble");
35 Assert.AreEqual(1, file.Sections.Length);
36 Assert.IsTrue(file.HasSection("ASection"));
37 Assert.IsNotNull(file["ASection"]);
38 Assert.AreEqual(1, file["ASection"].Keys.Length);
39 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
40 }
42 [Test()]
43 public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniTextWithMultiLineContent()
44 {
45 IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble\nfobble_key=foo\nabcde=fghij\nfoo9=bar2");
46 Assert.AreEqual(1, file.Sections.Length);
47 Assert.IsTrue(file.HasSection("ASection"));
48 IniSection section = file["ASection"];
49 Assert.IsNotNull(section);
50 Assert.AreEqual(4, section.Keys.Length);
51 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
53 string[] keys = new string[]{"something", "fobble_key", "abcde", "foo9"};
55 foreach (string key in keys)
56 {
57 bool found = false;
59 foreach (string sectionKey in section.Keys)
60 {
61 if (key == sectionKey)
62 {
63 found = true;
64 break;
65 }
66 }
68 Assert.IsTrue(found, "Did not find " + key);
69 }
70 }
72 [Test()]
73 public void TestIniFileReaderContainsExpectedSectionsForTwoSectionIniTextWithContent()
74 {
75 IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble\n[BSection]\nsomethingElse=fibble");
76 Assert.AreEqual(2, file.Sections.Length);
77 Assert.IsTrue(file.HasSection("ASection"));
78 Assert.IsNotNull(file["ASection"]);
79 Assert.AreEqual(1, file["ASection"].Keys.Length);
80 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
81 Assert.IsTrue(file.HasSection("BSection"));
82 Assert.IsNotNull(file["BSection"]);
83 Assert.AreEqual(1, file["BSection"].Keys.Length);
84 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]);
85 }
87 [Test()]
88 public void TestIniFileReaderContainsExpectedSectionsForTwoConsecutiveSectionSectionsInText()
89 {
90 IniFile file = IniFileReader.ReadFile("[SectionA]\n[SectionB]");
91 Assert.AreEqual(2, file.Sections.Length);
92 Assert.IsTrue(file.HasSection("SectionA"));
93 Assert.IsNotNull(file["SectionA"]);
94 Assert.AreEqual(0, file["SectionA"].Keys.Length);
95 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionA"]);
96 Assert.IsTrue(file.HasSection("SectionB"));
97 Assert.IsNotNull(file["SectionB"]);
98 Assert.AreEqual(0, file["SectionB"].Keys.Length);
99 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionB"]);
100 }
102 [Test()]
103 public void TestIniFileReaderContainsExpectedSectionWhenTextPaddedAtStart()
104 {
105 IniFile file = IniFileReader.ReadFile("\nnon-blank\n[ASection]\nsomething=fibble");
106 Assert.AreEqual(1, file.Sections.Length);
107 Assert.IsTrue(file.HasSection("ASection"));
108 Assert.IsNotNull(file["ASection"]);
109 Assert.AreEqual(1, file["ASection"].Keys.Length);
110 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
111 }
113 [Test()]
114 public void TestIniFileReaderReturnsEmptyObjectForEmptyIniFile()
115 {
116 IniFile file = IniFileReader.ReadFile(new FileInfo("TestData/EmptyFile.ini"));
117 Assert.AreEqual(0, file.Sections.Length);
118 }
120 [Test()]
121 public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFile()
122 {
123 IniFile file = IniFileReader.ReadFile(new FileInfo("TestData/SingleSectionSingleLine.ini"));
124 Assert.AreEqual(1, file.Sections.Length);
125 Assert.IsTrue(file.HasSection("ASection"));
126 Assert.IsNotNull(file["ASection"]);
127 Assert.AreEqual(0, file["ASection"].Keys.Length);
128 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
129 }
131 [Test()]
132 public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFileWithContent()
133 {
134 IniFile file = IniFileReader.ReadFile(new FileInfo("TestData/SingleSectionWithContent.ini"));
135 Assert.AreEqual(1, file.Sections.Length);
136 Assert.IsTrue(file.HasSection("ASection"));
137 Assert.IsNotNull(file["ASection"]);
138 Assert.AreEqual(1, file["ASection"].Keys.Length);
139 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
140 }
142 [Test()]
143 public void TestIniFileReaderContainsExpectedSectionsForTwoSectionIniFileWithContent()
144 {
145 IniFile file = IniFileReader.ReadFile(new FileInfo("TestData/DoubleSectionWithContent.ini"));
146 Assert.AreEqual(2, file.Sections.Length);
147 Assert.IsTrue(file.HasSection("ASection"));
148 Assert.IsNotNull(file["ASection"]);
149 Assert.AreEqual(1, file["ASection"].Keys.Length);
150 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
151 Assert.IsTrue(file.HasSection("BSection"));
152 Assert.IsNotNull(file["BSection"]);
153 Assert.AreEqual(1, file["BSection"].Keys.Length);
154 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]);
155 }
157 [Test()]
158 public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFileWithMultiLineContent()
159 {
160 IniFile file = IniFileReader.ReadFile(new FileInfo("TestData/SingleSectionWithMultiLineContent.ini"));
161 Assert.AreEqual(1, file.Sections.Length);
162 Assert.IsTrue(file.HasSection("ASection"));
163 IniSection section = file["ASection"];
164 Assert.IsNotNull(section);
165 Assert.AreEqual(4, section.Keys.Length);
166 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
168 string[] keys = new string[]{"something", "fobble_key", "abcde", "foo9"};
170 foreach (string key in keys)
171 {
172 bool found = false;
174 foreach (string sectionKey in section.Keys)
175 {
176 if (key == sectionKey)
177 {
178 found = true;
179 break;
180 }
181 }
183 Assert.IsTrue(found, "Did not find " + key);
184 }
185 }
187 [Test()]
188 public void TestIniFileReaderContainsExpectedSectionWhenFilePaddedAtStart()
189 {
190 IniFile file = IniFileReader.ReadFile(new FileInfo("TestData/StartPadded.ini"));
191 Assert.AreEqual(1, file.Sections.Length);
192 Assert.IsTrue(file.HasSection("ASection"));
193 Assert.IsNotNull(file["ASection"]);
194 Assert.AreEqual(1, file["ASection"].Keys.Length);
195 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
196 }
198 [Test()]
199 public void TestIniFileReaderContainsExpectedSectionsForTwoConsecutiveSectionSectionsInFile()
200 {
201 IniFile file = IniFileReader.ReadFile(new FileInfo("TestData/ConsecutiveSection.ini"));
202 Assert.AreEqual(2, file.Sections.Length);
203 Assert.IsTrue(file.HasSection("SectionA"));
204 Assert.IsNotNull(file["SectionA"]);
205 Assert.AreEqual(0, file["SectionA"].Keys.Length);
206 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionA"]);
207 Assert.IsTrue(file.HasSection("SectionB"));
208 Assert.IsNotNull(file["SectionB"]);
209 Assert.AreEqual(0, file["SectionB"].Keys.Length);
210 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionB"]);
211 }
212 }
213 }