Skip to content

Commit

Permalink
Start of multi-file testing
Browse files Browse the repository at this point in the history
Start of multi-file.
  • Loading branch information
wforums committed Jun 6, 2015
1 parent f1f7b08 commit e3df59e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 21 deletions.
51 changes: 35 additions & 16 deletions CCExtractorTester/Analyzers/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.Schema;

namespace CCExtractorTester
{
Expand Down Expand Up @@ -144,11 +145,20 @@ void loadAndParseXML (string xmlFileName)
XmlDocument doc = new XmlDocument ();
using(FileStream fs = new FileStream(xmlFileName,FileMode.Open)){
doc.Load (fs);
foreach (XmlNode node in doc.SelectNodes("//test")) {
XmlNode sampleFile = node.SelectSingleNode ("sample");
XmlNode command = node.SelectSingleNode ("cmd");
XmlNode resultFile = node.SelectSingleNode ("result");
Entries.Add(new TestEntry(ConvertFolderDelimiters(sampleFile.InnerText),command.InnerText,ConvertFolderDelimiters(resultFile.InnerText)));
XmlNodeList testNodes = doc.SelectNodes ("//test");
if (testNodes.Count > 0) {
foreach (XmlNode node in testNodes) {
XmlNode sampleFile = node.SelectSingleNode ("sample");
XmlNode command = node.SelectSingleNode ("cmd");
XmlNode resultFile = node.SelectSingleNode ("result");
Entries.Add (new TestEntry (ConvertFolderDelimiters (sampleFile.InnerText), command.InnerText, ConvertFolderDelimiters (resultFile.InnerText)));
}
} else {
// Dealing with multi file
foreach (XmlNode node in doc.SelectNodes ("//testfile")) {
String testFileLocation = ConvertFolderDelimiters(node.SelectSingleNode ("location").InnerText);
// TODO: add to separate list, which then will be parsed following the same pattern.
}
}
}
return;
Expand All @@ -162,14 +172,33 @@ void loadAndParseXML (string xmlFileName)
/// <param name="xmlFileName">The location of the XML file to validate.</param>
void ValidateXML (string xmlFileName)
{
try {
ValidateAgainstSchema (xmlFileName, Resources.tests);
} catch(XmlSchemaValidationException){
try {
ValidateAgainstSchema (xmlFileName, Resources.multitest);
} catch(XmlSchemaValidationException){
throw new InvalidDataException ("Given XML is neither a test XML file nor a multitest XML file.");
}
}
}

/// <summary>
/// Validates the XML against a given schema.
/// </summary>
/// <param name="xmlFileName">Xml file name.</param>
/// <param name="xmlSchema">Xml schema.</param>
private void ValidateAgainstSchema(string xmlFileName, string xmlSchema){
using (StringReader sr = new StringReader (Resources.tests)) {
XmlReader r = XmlReader.Create (sr);
XmlReaderSettings settings = new XmlReaderSettings ();
settings.Schemas.Add (null, r);
settings.ValidationType = ValidationType.Schema;
settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler (settings_ValidationEventHandler);
using (FileStream fs = new FileStream (xmlFileName, FileMode.Open)) {
var reader = XmlReader.Create (fs, settings);
while (reader.Read ()) {
// Nothing in here, just need to read out the entire file in a loop.
}
}
}
}
Expand All @@ -195,16 +224,6 @@ string ConvertFolderDelimiters (string path)
return path.Replace (env, Path.DirectorySeparatorChar);
}

/// <summary>
/// The validation event handler for the settings XSD scheme.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
void settings_ValidationEventHandler (object sender, System.Xml.Schema.ValidationEventArgs e)
{
throw new InvalidDataException ("XML File is not formatted correctly");
}

/// <summary>
/// Runs the tests.
/// </summary>
Expand Down
9 changes: 6 additions & 3 deletions CCExtractorTester/CCExtractorTester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<ConsolePause>false</ConsolePause>
<Commandlineparameters>-t "E:\CCExtractor repository\TestFiles\General\_General.xml"</Commandlineparameters>
<Commandlineparameters>-t xsd.xml</Commandlineparameters>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
Expand Down Expand Up @@ -74,8 +74,6 @@
<Compile Include="gtk-gui\generated.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="gtk-gui\CCExtractorTester.MainWindow.cs" />
<Compile Include="gtk-gui\CCExtractorTester.ConfigWindow.cs" />
<Compile Include="Resources.Designer.cs">
<DependentUpon>Resources.resx</DependentUpon>
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -116,6 +114,8 @@
<Compile Include="PerformanceLoggers\NullPerformanceLogger.cs" />
<Compile Include="NullProgressReporter.cs" />
<Compile Include="Comparers\Hasher.cs" />
<Compile Include="gtk-gui\CCExtractorTester.ConfigWindow.cs" />
<Compile Include="gtk-gui\CCExtractorTester.MainWindow.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand All @@ -124,6 +124,9 @@
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<None Include="multitest.xsd">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="tests.xml" />
Expand Down
26 changes: 24 additions & 2 deletions CCExtractorTester/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions CCExtractorTester/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="multitest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>multitest.xsd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="tests" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>tests.xsd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
Expand Down
15 changes: 15 additions & 0 deletions CCExtractorTester/multitest.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="multitest">
<xs:complexType>
<xs:sequence>
<xs:element name="testfile" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="location"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

0 comments on commit e3df59e

Please sign in to comment.