2010-10-19 05:50:07 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Xml.Linq;
|
2011-04-08 22:29:16 +02:00
|
|
|
|
using System.Runtime.Serialization;
|
2010-10-19 05:50:07 +02:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.Sputnik.Interop.ParserEngine
|
|
|
|
|
{
|
2011-04-08 22:29:16 +02:00
|
|
|
|
[DataContract]
|
2010-10-19 05:50:07 +02:00
|
|
|
|
public class SputnikTestScript
|
|
|
|
|
{
|
|
|
|
|
private string testScriptID = string.Empty;
|
|
|
|
|
private string testScriptSection = string.Empty;
|
|
|
|
|
private string testScriptDescription = string.Empty;
|
2011-04-08 22:29:16 +02:00
|
|
|
|
private string testScriptAssertion = string.Empty;
|
2010-10-19 05:50:07 +02:00
|
|
|
|
private string replicationCode = string.Empty;
|
|
|
|
|
private int actualFileConvertedCount = 0;
|
2011-04-19 19:15:02 +02:00
|
|
|
|
public bool negativeTest = false;
|
2010-10-19 05:50:07 +02:00
|
|
|
|
private bool strictModeNegativeTest = false;
|
|
|
|
|
private const string xmlNode = "format";
|
|
|
|
|
private const string xmlAttribute = "sequence";
|
|
|
|
|
private string[] checkSections;
|
|
|
|
|
private SortedDictionary<string, string> testScriptFormats = new SortedDictionary<string, string>();
|
|
|
|
|
|
|
|
|
|
public string Header = string.Empty;
|
|
|
|
|
public string Body = string.Empty;
|
2011-04-08 22:29:16 +02:00
|
|
|
|
public string InitialComment = string.Empty;
|
2011-04-19 19:15:02 +02:00
|
|
|
|
public string pathFromRoot = string.Empty;
|
2010-10-19 05:50:07 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the ID.
|
|
|
|
|
/// </summary>
|
2011-04-08 22:29:16 +02:00
|
|
|
|
/// <value>The ID.</value>
|
2011-04-20 20:17:38 +02:00
|
|
|
|
[DataMember]
|
|
|
|
|
public string id
|
2010-10-19 05:50:07 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return testScriptID;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != null)
|
|
|
|
|
testScriptID = value.Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public bool IsNegativeInStrictMode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return strictModeNegativeTest;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
strictModeNegativeTest = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the netative test flag.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>true if this is a @negative test</value>
|
|
|
|
|
public bool IsNegative
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return negativeTest;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
negativeTest=value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the testScriptSection
|
|
|
|
|
/// </summary>
|
2011-04-20 20:17:38 +02:00
|
|
|
|
[DataMember]
|
|
|
|
|
public string path
|
2010-10-19 05:50:07 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return testScriptSection;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if(value!=null)
|
|
|
|
|
testScriptSection = value.Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Actual number of input files which got converted
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int ConvertedFileCount
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return actualFileConvertedCount;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
actualFileConvertedCount = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-08 22:29:16 +02:00
|
|
|
|
|
|
|
|
|
|
2010-10-19 05:50:07 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the testScriptDescription
|
|
|
|
|
/// </summary>
|
2011-04-08 22:29:16 +02:00
|
|
|
|
[DataMember]
|
2011-04-20 20:17:38 +02:00
|
|
|
|
public string description
|
2010-10-19 05:50:07 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return testScriptDescription;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != null)
|
|
|
|
|
testScriptDescription = value.Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 22:29:16 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the testScriptAssersion
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataMember]
|
2011-04-20 20:17:38 +02:00
|
|
|
|
public string assertion
|
2011-04-08 22:29:16 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return testScriptAssertion;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != null)
|
|
|
|
|
testScriptAssertion = value.Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 05:50:07 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the value for checkSections
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string[] Checks
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return checkSections;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
checkSections = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the full path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The full path.</value>
|
|
|
|
|
public string FullPath { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the replication code.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The replication code.</value>
|
|
|
|
|
public string ReplicationCode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return replicationCode;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != null)
|
|
|
|
|
replicationCode = value.Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the possible checks count.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The possible checks count.</value>
|
|
|
|
|
public int PossibleChecksCount { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the pre condition code.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The pre condition code.</value>
|
|
|
|
|
public string PreConditionCode { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor which reads the regular expression formats from InputFormats.xml file
|
|
|
|
|
/// </summary>
|
|
|
|
|
public SputnikTestScript()
|
|
|
|
|
{
|
|
|
|
|
ReadInputXml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reads the regular expression formats from inputformats.xml file
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ReadInputXml()
|
|
|
|
|
{
|
|
|
|
|
string inputXmlPath = Path.GetFullPath(ConfigurationManager.AppSettings[ResourceClass.InputXMLPath].ToString());
|
|
|
|
|
XmlTextReader reader = new XmlTextReader(inputXmlPath);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(inputXmlPath))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
switch (reader.NodeType)
|
|
|
|
|
{
|
|
|
|
|
case XmlNodeType.Element:
|
|
|
|
|
if (!Convert.ToBoolean(string.Compare(reader.Name.ToLower(), xmlNode)))
|
|
|
|
|
{
|
|
|
|
|
testScriptFormats.Add(reader.GetAttribute(xmlAttribute), reader.ReadString());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (XmlException ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteToLog(string.Format(ResourceClass.XMLException_Log, ex.Message));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads the sputnik testscript file and extracts the required details from it
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filePath">Path to the source file</param>
|
2011-04-19 19:15:02 +02:00
|
|
|
|
public void Load(string filePath, string root)
|
2010-10-19 05:50:07 +02:00
|
|
|
|
{
|
|
|
|
|
string[] regexTrimDelimiter = { "\n","\r"};
|
|
|
|
|
String fullFile = string.Empty;
|
|
|
|
|
|
|
|
|
|
using (TextReader txtReader = new StreamReader(filePath))
|
|
|
|
|
{
|
|
|
|
|
fullFile = txtReader.ReadToEnd();
|
|
|
|
|
}
|
|
|
|
|
this.FullPath = filePath;
|
2011-04-19 19:15:02 +02:00
|
|
|
|
int indexOfRoot = this.FullPath.IndexOf(root, StringComparison.InvariantCulture) + root.Length + 1;
|
|
|
|
|
this.pathFromRoot = this.FullPath.Substring(indexOfRoot, this.FullPath.Length - indexOfRoot);
|
2010-10-19 05:50:07 +02:00
|
|
|
|
|
2011-04-21 01:52:14 +02:00
|
|
|
|
Regex regx = new Regex("\\\\S([0-9]+)_([^\\\\]+)\\.js$");
|
|
|
|
|
if (regx.IsMatch(this.pathFromRoot))
|
|
|
|
|
{
|
|
|
|
|
Match tempMatch = regx.Match(this.pathFromRoot);
|
|
|
|
|
String tempDir = "\\" + tempMatch.Groups[1].Value + ".0_Chapter";
|
|
|
|
|
this.pathFromRoot = regx.Replace(this.pathFromRoot, tempDir + "\\S$1.0_$2.js");
|
|
|
|
|
}
|
2011-04-19 19:15:02 +02:00
|
|
|
|
ReadSimpleTestCase(fullFile);
|
2010-10-19 05:50:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Read a basic sputnik test file and create an object for it. Assume just a header comment and a test body
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fullFile">Input file content</param>
|
|
|
|
|
private void ReadSimpleTestCase(string fullFile)
|
|
|
|
|
{
|
|
|
|
|
char[] delimiter = { ':' };
|
|
|
|
|
char[] trimDelimit = { ';' ,'\r','\n'};
|
|
|
|
|
string holdStr = string.Empty;
|
|
|
|
|
string[] arrComments;
|
|
|
|
|
|
|
|
|
|
Regex commentTailRegex = new Regex("\\s*\\*\\/\\s*");
|
|
|
|
|
Match matchCommentTail = commentTailRegex.Match(fullFile);
|
|
|
|
|
|
|
|
|
|
this.Header = fullFile.Substring(0,matchCommentTail.Index+matchCommentTail.Length);
|
2011-04-08 22:29:16 +02:00
|
|
|
|
|
|
|
|
|
Regex csharpCommentRegx = new Regex("\\/\\*");
|
|
|
|
|
Match matchCSharpCommentHead = csharpCommentRegx.Match(this.Header);
|
|
|
|
|
this.InitialComment = this.Header.Substring(0, matchCSharpCommentHead.Index);
|
|
|
|
|
|
2010-10-19 05:50:07 +02:00
|
|
|
|
this.Body = fullFile.Substring(matchCommentTail.Index+matchCommentTail.Length);
|
|
|
|
|
|
|
|
|
|
string commentFormat = "@[a-zA-Z0-9_]+(:\\s*[^\\r\\n]*)?;?\\s*(\\r|\\n)";
|
|
|
|
|
Regex regx = new Regex(commentFormat);
|
|
|
|
|
MatchCollection matchComments = regx.Matches(this.Header);
|
|
|
|
|
|
|
|
|
|
foreach (Match comment in matchComments)
|
|
|
|
|
{
|
|
|
|
|
holdStr = comment.Value;
|
|
|
|
|
arrComments = holdStr.Trim(trimDelimit).Trim().Split(delimiter,2);
|
|
|
|
|
|
|
|
|
|
string commentKey = arrComments[0].ToLower();
|
|
|
|
|
if (commentKey.Contains(ResourceClass.LookFor_Name))
|
|
|
|
|
{
|
2011-04-20 20:17:38 +02:00
|
|
|
|
this.id = this.pathFromRoot.Substring(this.pathFromRoot.LastIndexOf("\\") + 1);
|
2011-04-21 01:52:14 +02:00
|
|
|
|
this.id = this.id.Remove(this.id.Length - 3);
|
2010-10-19 05:50:07 +02:00
|
|
|
|
}
|
|
|
|
|
if (commentKey.Contains(ResourceClass.LookFor_Section))
|
|
|
|
|
{
|
2011-04-21 01:52:14 +02:00
|
|
|
|
this.path = this.pathFromRoot;
|
2011-04-08 22:29:16 +02:00
|
|
|
|
}
|
|
|
|
|
if (commentKey.Contains(ResourceClass.LookFor_Assertion))
|
|
|
|
|
{
|
2011-04-20 20:17:38 +02:00
|
|
|
|
this.assertion = arrComments[arrComments.Length - 1].Trim(trimDelimit);
|
2010-10-19 05:50:07 +02:00
|
|
|
|
}
|
|
|
|
|
if (commentKey.Contains(ResourceClass.LookFor_Description))
|
|
|
|
|
{
|
2011-04-20 20:17:38 +02:00
|
|
|
|
this.description = arrComments[arrComments.Length - 1].Trim(trimDelimit);
|
2010-10-19 05:50:07 +02:00
|
|
|
|
}
|
|
|
|
|
if (commentKey.Contains(ResourceClass.LookFor_NegativeStrictMode))
|
|
|
|
|
{
|
|
|
|
|
this.IsNegativeInStrictMode = true;
|
|
|
|
|
}
|
|
|
|
|
if (commentKey.Contains(ResourceClass.LookFor_Negative))
|
|
|
|
|
{
|
|
|
|
|
if (!arrComments[0].Contains(ResourceClass.LookFor_NegativeStrictMode)) this.IsNegative = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.PossibleChecksCount = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|