Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
2010-01-14 Marek Habersack <mhabersack@novell.com>
* NunitWebTest.cs: added new overload of GetControlFromPageHtml
which takes begin and end markers as parameters.
2008-01-07 Dean Brettle <dean@brettle.com>
* HtmlAgilityPack/AssemblyInfo.cs: made assembly delay signed so that
tests can access System.Web internals now that System.Web is
InternalsVisibleTo this assembly.
2007-03-06 Vladimir Krasniv <vladimirk@mainsoft.com>
* reference20: added reference test for PageDirectories tests
2007-03-05 Vladimir Krasniv <vladimirk@mainsoft.com>
* reference20: added reference tests for PageDirectories tests
2007-02-27 Vladimir Krasniv <vladimirk@mainsoft.com>
* almost_config.xml, test_catalog.xml, WebTest.cs: fixed not working
tests for asp 2.0
2006-12-07 Igor Zelmanovich <igorz@mainsoft.com>
* XmlComparer.cs:
* NunitWebTest.cs: fixed HtmlComparer
2006-10-30 Andrew Skiba <andrews@mainsoft.com>
* NunitWebTest.cs: fallback for HtmlCompare to the text diff
2006-09-28 Vladimir Krasniv <vladimirk@mainsoft.com>
* added SystemWebTest20.csproj, SystemWebTest20.vmwcsproj for VS2005
2006-09-12 Vladimir Krasniv <vladimirk@mainsoft.com>
* WebTest.cs: fixed test case find in response of net2.0
* added reference20, reference response from net2.0
2006-07-26 Vladimir Krasnov <vladimirk@mainsfot.com>
* NunitWebTest.cs: fixed HtmltoXml, removes spaces and crlf before
converting
2006-07-26 Andrew Skiba <andrews@mainsoft.com>
* XmlComparer.cs: make expected and actual arguments look like in NUnit.
2006-07-16 Vladimir Krasnov <vladimirk@mainsfot.com>
* NunitWebTest.cs: fixed AssertAreEqual, order of actual and expected
2006-06-28 Vladimir Krasnov <vladimirk@mainsfot.com>
* nunitweb_config.xml: filtered onclick for input tags
2006-05-21 Yoni Klain <yonik@mainsoft.com>
* XmlComparer.cs: add 2 variable for test fail asserting information
2006-05-21 Yoni Klain <yonik@mainsoft.com>
* NunitWebTest.cs: add method for Nunit tests asserting fails
2006-05-17 Andrew Skiba <andrews@mainsoft.com>
* nunitweb_config.xml: similar to almost_config.xml but ignores more stuff
* NunitWebTest.cs: use nunit_config.xml and fallback on XmlException
2006-05-17 Andrew Skiba <andrews@mainsoft.com>
* nunitweb_config.xml: similar to almost_config.xml but ignores more stuff
* NunitWebTest.cs: use nunit_config.xml and fallback on XmlException
2006-03-27 Vladimir Krasnov <vladimirk@mainsoft.com>
* test_catalog.xml: fixed not working tests
* almost_config.xml: fixed almost for not a bug
* reference/HyperLinkColumn_DataTextField.aspx.xml,
reference/HyperLinkColumn_DataNavigateUrlField.aspx.xml: removed refs
of removed tests
* reference/WebControl_CopyBaseAttributes_W.aspx.xml: same
2006-02-23 Vladimir Krasnov <vladimirk@mainsoft.com>
* test_catalog.xml: fixed not working tests
2006-02-23 Vladimir Krasnov <vladimirk@mainsoft.com>
* added SystemWebTest.vmwcsproj, GH project file
2006-02-20 Vladimir Krasnov <vladimirk@mainsoft.com>
* XmlComparer.cs: fixed AreEqualAttribs, to make attributes
compare case insensitive

View File

@@ -0,0 +1,68 @@
// HtmlAgilityPack V1.0 - Simon Mourier <simonm@microsoft.com>
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
#if DEBUG
[assembly: AssemblyTitle("Html Agility Pack - Debug")] //Description
#else // release
#if TRACE
[assembly: AssemblyTitle("Html Agility Pack - ReleaseTrace")] //Description
#else
[assembly: AssemblyTitle("Html Agility Pack - Release")] //Description
#endif
#endif
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Simon Mourier")]
[assembly: AssemblyProduct("Html Agility Pack")]
[assembly: AssemblyCopyright("Simon Mourier")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.1.1")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
#if !(TARGET_JVM || TARGET_DOTNET)
[assembly: AssemblyDelaySign (true)]
[assembly: AssemblyKeyFile ("../winfx.pub")]
#endif

View File

@@ -0,0 +1,111 @@
// HtmlAgilityPack V1.0 - Simon Mourier <simonm@microsoft.com>
using System;
using System.Collections;
namespace HtmlAgilityPack
{
internal class NameValuePair
{
internal readonly string Name;
internal string Value;
internal NameValuePair()
{
}
internal NameValuePair(string name):
this()
{
Name = name;
}
internal NameValuePair(string name, string value):
this(name)
{
Value = value;
}
}
internal class NameValuePairList
{
internal readonly string Text;
private ArrayList _allPairs;
private Hashtable _pairsWithName;
internal NameValuePairList():
this(null)
{
}
internal NameValuePairList(string text)
{
Text = text;
_allPairs = new ArrayList();
_pairsWithName = new Hashtable();
Parse(text);
}
internal string GetNameValuePairValue(string name)
{
if (name==null)
throw new ArgumentNullException();
ArrayList al = GetNameValuePairs(name);
if (al==null)
return null;
// return first item
NameValuePair nvp = al[0] as NameValuePair;
return nvp.Value;
}
internal ArrayList GetNameValuePairs(string name)
{
if (name==null)
return _allPairs;
return _pairsWithName[name] as ArrayList;
}
private void Parse(string text)
{
_allPairs.Clear();
_pairsWithName.Clear();
if (text==null)
return;
string[] p = text.Split(';');
if (p==null)
return;
foreach(string pv in p)
{
if (pv.Length==0)
continue;
string[] onep = pv.Split(new char[]{'='}, 2);
if (onep==null)
continue;
NameValuePair nvp = new NameValuePair(onep[0].Trim().ToLower());
if (onep.Length<2)
nvp.Value = "";
else
nvp.Value = onep[1];
_allPairs.Add(nvp);
// index by name
ArrayList al = _pairsWithName[nvp.Name] as ArrayList;
if (al==null)
{
al = new ArrayList();
_pairsWithName[nvp.Name] = al;
}
al.Add(nvp);
}
}
internal static string GetNameValuePairsValue(string text, string name)
{
NameValuePairList l = new NameValuePairList(text);
return l.GetNameValuePairValue(name);
}
}
}

View File

@@ -0,0 +1,468 @@
// HtmlAgilityPack V1.0 - Simon Mourier <simonm@microsoft.com>
using System;
using System.Collections;
namespace HtmlAgilityPack
{
/// <summary>
/// Represents an HTML attribute.
/// </summary>
public class HtmlAttribute: IComparable
{
internal int _line = 0;
internal int _lineposition = 0;
internal int _streamposition = 0;
internal int _namestartindex = 0;
internal int _namelength = 0;
internal int _valuestartindex = 0;
internal int _valuelength = 0;
internal HtmlDocument _ownerdocument; // attribute can exists without a node
internal HtmlNode _ownernode;
internal string _name;
internal string _value;
internal HtmlAttribute(HtmlDocument ownerdocument)
{
_ownerdocument = ownerdocument;
}
/// <summary>
/// Creates a duplicate of this attribute.
/// </summary>
/// <returns>The cloned attribute.</returns>
public HtmlAttribute Clone()
{
HtmlAttribute att = new HtmlAttribute(_ownerdocument);
att.Name = Name;
att.Value = Value;
return att;
}
/// <summary>
/// Compares the current instance with another attribute. Comparison is based on attributes' name.
/// </summary>
/// <param name="obj">An attribute to compare with this instance.</param>
/// <returns>A 32-bit signed integer that indicates the relative order of the names comparison.</returns>
public int CompareTo(object obj)
{
HtmlAttribute att = obj as HtmlAttribute;
if (att == null)
{
throw new ArgumentException("obj");
}
return Name.CompareTo(att.Name);
}
internal string XmlName
{
get
{
return HtmlDocument.GetXmlName(Name);
}
}
internal string XmlValue
{
get
{
return Value;
}
}
/// <summary>
/// Gets the qualified name of the attribute.
/// </summary>
public string Name
{
get
{
if (_name == null)
{
_name = _ownerdocument._text.Substring(_namestartindex, _namelength).ToLower();
}
return _name;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
_name = value.ToLower();
if (_ownernode != null)
{
_ownernode._innerchanged = true;
_ownernode._outerchanged = true;
}
}
}
/// <summary>
/// Gets or sets the value of the attribute.
/// </summary>
public string Value
{
get
{
if (_value == null)
{
_value = _ownerdocument._text.Substring(_valuestartindex, _valuelength);
}
return _value;
}
set
{
_value = value;
if (_ownernode != null)
{
_ownernode._innerchanged = true;
_ownernode._outerchanged = true;
}
}
}
/// <summary>
/// Gets the line number of this attribute in the document.
/// </summary>
public int Line
{
get
{
return _line;
}
}
/// <summary>
/// Gets the column number of this attribute in the document.
/// </summary>
public int LinePosition
{
get
{
return _lineposition;
}
}
/// <summary>
/// Gets the stream position of this attribute in the document, relative to the start of the document.
/// </summary>
public int StreamPosition
{
get
{
return _streamposition;
}
}
/// <summary>
/// Gets the HTML node to which this attribute belongs.
/// </summary>
public HtmlNode OwnerNode
{
get
{
return _ownernode;
}
}
/// <summary>
/// Gets the HTML document to which this attribute belongs.
/// </summary>
public HtmlDocument OwnerDocument
{
get
{
return _ownerdocument;
}
}
}
/// <summary>
/// Represents a combined list and collection of HTML nodes.
/// </summary>
public class HtmlAttributeCollection: IEnumerable
{
internal Hashtable _hashitems = new Hashtable();
private ArrayList _items = new ArrayList();
private HtmlNode _ownernode;
internal HtmlAttributeCollection(HtmlNode ownernode)
{
_ownernode = ownernode;
}
/// <summary>
/// Inserts the specified attribute as the last attribute in the collection.
/// </summary>
/// <param name="newAttribute">The attribute to insert. May not be null.</param>
/// <returns>The appended attribute.</returns>
public HtmlAttribute Append(HtmlAttribute newAttribute)
{
if (newAttribute == null)
{
throw new ArgumentNullException("newAttribute");
}
_hashitems[newAttribute.Name] = newAttribute;
newAttribute._ownernode = _ownernode;
_items.Add(newAttribute);
_ownernode._innerchanged = true;
_ownernode._outerchanged = true;
return newAttribute;
}
/// <summary>
/// Creates and inserts a new attribute as the last attribute in the collection.
/// </summary>
/// <param name="name">The name of the attribute to insert.</param>
/// <returns>The appended attribute.</returns>
public HtmlAttribute Append(string name)
{
HtmlAttribute att = _ownernode._ownerdocument.CreateAttribute(name);
return Append(att);
}
/// <summary>
/// Creates and inserts a new attribute as the last attribute in the collection.
/// </summary>
/// <param name="name">The name of the attribute to insert.</param>
/// <param name="value">The value of the attribute to insert.</param>
/// <returns>The appended attribute.</returns>
public HtmlAttribute Append(string name, string value)
{
HtmlAttribute att = _ownernode._ownerdocument.CreateAttribute(name, value);
return Append(att);
}
/// <summary>
/// Inserts the specified attribute as the first node in the collection.
/// </summary>
/// <param name="newAttribute">The attribute to insert. May not be null.</param>
/// <returns>The prepended attribute.</returns>
public HtmlAttribute Prepend(HtmlAttribute newAttribute)
{
if (newAttribute == null)
{
throw new ArgumentNullException("newAttribute");
}
_hashitems[newAttribute.Name] = newAttribute;
newAttribute._ownernode = _ownernode;
_items.Insert(0, newAttribute);
_ownernode._innerchanged = true;
_ownernode._outerchanged = true;
return newAttribute;
}
/// <summary>
/// Removes the attribute at the specified index.
/// </summary>
/// <param name="index">The index of the attribute to remove.</param>
public void RemoveAt(int index)
{
HtmlAttribute att = (HtmlAttribute)_items[index];
_hashitems.Remove(att.Name);
_items.RemoveAt(index);
_ownernode._innerchanged = true;
_ownernode._outerchanged = true;
}
/// <summary>
/// Removes a given attribute from the list.
/// </summary>
/// <param name="attribute">The attribute to remove. May not be null.</param>
public void Remove(HtmlAttribute attribute)
{
if (attribute == null)
{
throw new ArgumentNullException("attribute");
}
int index = GetAttributeIndex(attribute);
if (index == -1)
{
throw new IndexOutOfRangeException();
}
RemoveAt(index);
}
/// <summary>
/// Removes an attribute from the list, using its name. If there are more than one attributes with this name, they will all be removed.
/// </summary>
/// <param name="name">The attribute's name. May not be null.</param>
public void Remove(string name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
string lname = name.ToLower();
for(int i=0;i<_items.Count;i++)
{
HtmlAttribute att = (HtmlAttribute)_items[i];
if (att.Name == lname)
{
RemoveAt(i);
}
}
}
/// <summary>
/// Remove all attributes in the list.
/// </summary>
public void RemoveAll()
{
_hashitems.Clear();
_items.Clear();
_ownernode._innerchanged = true;
_ownernode._outerchanged = true;
}
/// <summary>
/// Gets the number of elements actually contained in the list.
/// </summary>
public int Count
{
get
{
return _items.Count;
}
}
internal int GetAttributeIndex(HtmlAttribute attribute)
{
if (attribute == null)
{
throw new ArgumentNullException("attribute");
}
for(int i=0;i<_items.Count;i++)
{
if (((HtmlAttribute)_items[i])==attribute)
return i;
}
return -1;
}
internal int GetAttributeIndex(string name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
string lname = name.ToLower();
for(int i=0;i<_items.Count;i++)
{
if (((HtmlAttribute)_items[i]).Name==lname)
return i;
}
return -1;
}
/// <summary>
/// Gets a given attribute from the list using its name.
/// </summary>
public HtmlAttribute this[string name]
{
get
{
if (name == null)
{
throw new ArgumentNullException("name");
}
return _hashitems[name.ToLower()] as HtmlAttribute;
}
}
/// <summary>
/// Gets the attribute at the specified index.
/// </summary>
public HtmlAttribute this[int index]
{
get
{
return _items[index] as HtmlAttribute;
}
}
internal void Clear()
{
_hashitems.Clear();
_items.Clear();
}
/// <summary>
/// Returns an enumerator that can iterate through the list.
/// </summary>
/// <returns>An IEnumerator for the entire list.</returns>
public HtmlAttributeEnumerator GetEnumerator()
{
return new HtmlAttributeEnumerator(_items);
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
/// <summary>
/// Represents an enumerator that can iterate through the list.
/// </summary>
public class HtmlAttributeEnumerator: IEnumerator
{
int _index;
ArrayList _items;
internal HtmlAttributeEnumerator(ArrayList items)
{
_items = items;
_index = -1;
}
/// <summary>
/// Sets the enumerator to its initial position, which is before the first element in the collection.
/// </summary>
public void Reset()
{
_index = -1;
}
/// <summary>
/// Advances the enumerator to the next element of the collection.
/// </summary>
/// <returns>true if the enumerator was successfully advanced to the next element, false if the enumerator has passed the end of the collection.</returns>
public bool MoveNext()
{
_index++;
return (_index<_items.Count);
}
/// <summary>
/// Gets the current element in the collection.
/// </summary>
public HtmlAttribute Current
{
get
{
return (HtmlAttribute)(_items[_index]);
}
}
/// <summary>
/// Gets the current element in the collection.
/// </summary>
object IEnumerator.Current
{
get
{
return (Current);
}
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,448 @@
// HtmlAgilityPack V1.3.1.0 - Simon Mourier <simonm@microsoft.com>
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace HtmlAgilityPack
{
/// <summary>
/// Represents a rewindable buffered TextReader specifically well suited for parsing operations.
/// </summary>
public class ParseReader: Stream
{
private StringBuilder _sb;
private int _baseReaderPosition;
private int _maxReaderPosition;
private int _position;
private TextReader _baseReader;
/// <summary>
/// Initializes an instance of the ParserReader class, based on an existing TextReader instance.
/// </summary>
/// <param name="baseReader">The TextReader to base parsing on. Must not be null.</param>
public ParseReader(TextReader baseReader)
{
if (baseReader == null)
throw new ArgumentNullException("baseReader");
_baseReader = baseReader;
_sb = new StringBuilder();
_position = 0;
_baseReaderPosition = 0;
_maxReaderPosition = int.MaxValue;
}
/// <summary>
/// Gets the length in bytes of the stream.
/// Always throws a NotSupportedException for the ParserReader class.
/// </summary>
public override long Length
{
get
{
throw new NotSupportedException();
}
}
/// <summary>
/// Gets or sets the position within the stream.
/// </summary>
public override long Position
{
get
{
return _position;
}
set
{
if (value < 0)
throw new ArgumentException("value is negative: " + value + ".");
if (value > int.MaxValue)
throw new ArgumentException("value must not be larger than int32 MaxValue.");
_position = (int)value;
}
}
/// <summary>
/// Checks the length of the underlying stream.
/// </summary>
/// <param name="length">The required length.</param>
/// <returns>true if the underlying stream's length is greater than the required length, false otherwise.</returns>
public bool CheckLength(int length)
{
if (length <= 0)
throw new ArgumentException("length must be greater than zero.");
if (BufferedTextLength >= length)
return true;
Seek(length, SeekOrigin.Begin);
return (BufferedTextLength >= length);
}
/// <summary>
/// Gets a value indicating whether the current stream supports seeking.
/// Always returns true for the ParserReader class.
/// </summary>
public override bool CanSeek
{
get
{
return true;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports reading.
/// Always returns true for the ParserReader class.
/// </summary>
public override bool CanRead
{
get
{
return true;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports writing.
/// Always returns false for the ParserReader class.
/// </summary>
public override bool CanWrite
{
get
{
return false;
}
}
/// <summary>
/// Sets the length of the current stream.
/// Always throws a NotSupportedException for the ParserReader class.
/// </summary>
/// <param name="value">The desired length of the current stream in bytes.</param>
public override void SetLength(long value)
{
throw new NotSupportedException();
}
/// <summary>
/// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
/// </summary>
public override void Flush()
{
// nothing to do
}
/// <summary>
/// Gets the position within the underlying stream.
/// </summary>
public int BaseReaderPosition
{
get
{
return _baseReaderPosition;
}
}
/// <summary>
/// Gets the maximum position within the underlying stream.
/// </summary>
public int MaxReaderPosition
{
get
{
return _maxReaderPosition;
}
}
private void CheckBaseReader()
{
if (_baseReader == null)
throw new InvalidOperationException("Cannot read from a closed ParseReader.");
}
/// <summary>
/// Closes the current underlying stream.
/// </summary>
public void CloseBaseReader()
{
if (_maxReaderPosition != int.MaxValue) // we have already closed it
return;
CheckBaseReader();
_baseReader.Close();
_baseReader = null;
}
private void InternalCloseBaseReader()
{
CloseBaseReader();
_maxReaderPosition = _position;
}
/// <summary>
/// Returns the next available character but does not consume it.
/// </summary>
/// <returns>The next character to be read, or -1 if no more characters are available.</returns>
public int Peek()
{
if (_position < _baseReaderPosition)
return Convert.ToInt32(this[_position]);
if (_position == _maxReaderPosition)
return -1;
CheckBaseReader();
int i = _baseReader.Peek();
if (i < 0)
{
InternalCloseBaseReader();
return i;
}
Debug.Assert(_position >= _baseReaderPosition);
if (_position == _baseReaderPosition)
{
if (_sb.Length < (_position + 1))
{
_sb.Append(Convert.ToChar(i));
}
}
return i;
}
/// <summary>
/// Reads the next character and advances the character position by one character.
/// </summary>
/// <returns>The next character represented as an Int32, or -1 if no more characters are available.</returns>
public int Read()
{
int i;
if (_position < _baseReaderPosition)
{
i = Convert.ToInt32(_sb[_position]);
_position++;
return i;
}
if (_position == _maxReaderPosition)
return -1;
CheckBaseReader();
i = _baseReader.Read();
if (i < 0)
{
InternalCloseBaseReader();
return i;
}
if (_position >= _baseReaderPosition)
{
if (_sb.Length < (_position + 1))
{
_sb.Append(Convert.ToChar(i));
}
}
_baseReaderPosition++;
_position++;
return i;
}
/// <summary>
/// Move the position starting from the current position.
/// </summary>
/// <param name="count">A character offset relative to the current position.</param>
/// <returns>The new position.</returns>
public int Seek(int count)
{
int i;
if (count < 0)
{
if ((_position + count ) < 0)
{
i = _position;
_position = 0;
return i;
}
else
{
_position += count;
return - count;
}
}
for(i=0;i<count;i++)
{
int c = Read();
if (c < 0)
{
break;
}
}
return i;
}
/// <summary>
/// Reads a string from the current position.
/// </summary>
/// <param name="count">The number of characters to read.</param>
/// <returns>The read string or null, if an error occurred.</returns>
public string ReadString(int count)
{
int first = (int)Position;
Seek(count);
int last = (int)Position;
if (first >= _sb.Length)
return null;
return _sb.ToString(first, last - first);
}
/// <summary>
/// Reads a string, represented as an array of System.Int32, from the current position.
/// </summary>
/// <param name="count">The number of characters to read.</param>
/// <returns>The read string or null, if an error occurred.</returns>
public int[] Read(int count)
{
string s = ReadString(count);
if (s == null)
return null;
char[] chars = s.ToCharArray();
int[] ints = new int[chars.Length];
chars.CopyTo(ints, 0);
return ints;
}
/// <summary>
/// reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
/// </summary>
/// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count- 1) replaced by the bytes read from the current source.</param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
/// <param name="count">The maximum number of bytes to be read from the current stream.</param>
/// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
public override int Read(byte[] buffer, int offset, int count)
{
if (buffer == null)
throw new ArgumentNullException("buffer");
// we don't really know how to read count bytes... so we read count chars
string s = ReadString(count);
if (s == null)
return 0;
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // probably around 2*count bytes
int read = 0;
for(int i=0;i<bytes.Length;i++)
{
buffer[offset + i] = bytes[i];
read++;
if (read == count) // enough?
break;
}
return read;
}
/// <summary>
/// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
/// Always throws a NotSupportedException for the ParserReader class.
/// </summary>
/// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
/// <param name="count">The number of bytes to be written to the current stream.</param>
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
/// <summary>
/// Sets the position within the current stream.
/// </summary>
/// <param name="offset">A byte offset relative to the origin parameter.</param>
/// <param name="origin">A value of type SeekOrigin indicating the reference point used to obtain the new position.</param>
/// <returns>The new position within the current stream.</returns>
public override long Seek(long offset, SeekOrigin origin)
{
if (offset > int.MaxValue)
throw new ArgumentException("offset must not be larger than int32 MaxValue.");
switch(origin)
{
case SeekOrigin.Begin:
_position = 0;
break;
case SeekOrigin.End:
Seek(int.MaxValue);
break;
case SeekOrigin.Current:
break;
}
return Seek((int)offset);
}
/// <summary>
/// Gets the character at the specified index or -1 if no more characters are available.
/// </summary>
public int this[int index]
{
get
{
if (index >= _baseReaderPosition)
{
int count = Seek(index - _baseReaderPosition);
if (count < (index - _baseReaderPosition))
return -1;
int i = Peek();
if (i < 0)
return -1;
}
return _sb[index];
}
}
/// <summary>
/// Gets the length of the currently buffered text.
/// </summary>
public int BufferedTextLength
{
get
{
return _sb.Length;
}
}
/// <summary>
/// Gets the currently buffered text.
/// </summary>
public string BufferedText
{
get
{
return _sb.ToString();
}
}
/// <summary>
/// Extracts a string out of the buffered text.
/// </summary>
/// <param name="offset">The zero-based byte offset in buffered text at which to begin extracting.</param>
/// <param name="length">The maximum number of bytes to be read from the buffered text.</param>
/// <returns></returns>
public string GetBufferedString(int offset, int length)
{
if (offset > BufferedTextLength)
{
return null;
}
if ((offset + length) > BufferedTextLength)
{
length -= (offset + length) - BufferedTextLength;
}
return BufferedText.Substring(offset, length);
}
}
}

View File

@@ -0,0 +1,140 @@
// HtmlAgilityPack V1.0 - Simon Mourier <simonm@microsoft.com>
using System;
using System.IO;
namespace HtmlAgilityPack
{
/// <summary>
/// A utility class to compute CRC32.
/// </summary>
public class Crc32
{
private uint _crc32 = 0;
static private uint[] crc_32_tab = // CRC polynomial 0xedb88320
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
static private uint UPDC32(byte octet, uint crc)
{
return (crc_32_tab[((crc)^((byte)octet)) & 0xff] ^ ((crc) >> 8));
}
internal uint CheckSum
{
get
{
return _crc32;
}
set
{
_crc32 = value;
}
}
internal uint AddToCRC32(int c)
{
return AddToCRC32((ushort)c);
}
internal uint AddToCRC32(ushort c)
{
byte lowByte, hiByte;
lowByte = (byte)(c & 0x00ff);
hiByte = (byte)(c >> 8);
_crc32 = UPDC32(hiByte, _crc32);
_crc32 = UPDC32(lowByte, _crc32);
return ~_crc32;
}
/// <summary>
/// Compute a checksum for a given string.
/// </summary>
/// <param name="text">The string to compute the checksum for.</param>
/// <returns>The computed checksum.</returns>
static public uint CRC32String(string text)
{
uint oldcrc32;
oldcrc32 = 0xFFFFFFFF;
int len = text.Length;
ushort uCharVal;
byte lowByte, hiByte;
for ( int i=0; len>0; i++)
{
--len;
uCharVal = text[len];
unchecked
{
lowByte = (byte)(uCharVal & 0x00ff);
hiByte = (byte)(uCharVal >> 8);
}
oldcrc32 = UPDC32(hiByte, oldcrc32);
oldcrc32 = UPDC32(lowByte, oldcrc32);
}
return ~oldcrc32;
}
/// <summary>
/// Compute a checksum for a given array of bytes.
/// </summary>
/// <param name="bytes">The array of bytes to compute the checksum for.</param>
/// <returns>The computed checksum.</returns>
static public uint CRC32Bytes(byte[] bytes)
{
uint oldcrc32;
oldcrc32 = 0xFFFFFFFF;
int len = bytes.Length;
for ( int i=0; len>0; i++)
{
--len;
oldcrc32 = UPDC32(bytes[len], oldcrc32);
}
return ~oldcrc32;
}
}
}

View File

@@ -0,0 +1,224 @@
// HtmlAgilityPack V1.0 - Simon Mourier <simonm@microsoft.com>
using System;
using System.Diagnostics;
using System.IO;
namespace HtmlAgilityPack
{
internal struct IOLibrary
{
internal static void MakeWritable(string path)
{
if (!File.Exists(path))
return;
File.SetAttributes(path, File.GetAttributes(path) & ~FileAttributes.ReadOnly);
}
internal static void CopyAlways(string source, string target)
{
if (!File.Exists(source))
return;
Directory.CreateDirectory(Path.GetDirectoryName(target));
MakeWritable(target);
File.Copy(source, target, true);
}
}
#if TARGET_JVM1
internal struct HtmlLibrary
{
[Conditional("DEBUG")]
internal static void GetVersion(out string version)
{
System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(1, true);
version = sf.GetMethod().DeclaringType.Assembly.GetName().Version.ToString();
}
[Conditional("DEBUG")]
[Conditional("TRACE")]
internal static void Trace(object Value)
{
// category is the method
string name = null;
GetCurrentMethodName(2, out name);
System.Diagnostics.Trace.WriteLine(Value, name);
}
[Conditional("DEBUG")]
[Conditional("TRACE")]
internal static void TraceStackFrame(int steps)
{
string name = null;
GetCurrentMethodName(2, out name);
string trace = "";
for(int i=1;i<steps;i++)
{
System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(i, true);
trace += sf.ToString();
}
System.Diagnostics.Trace.WriteLine(trace, name);
System.Diagnostics.Trace.WriteLine("");
}
[Conditional("DEBUG")]
internal static void GetCurrentMethodName(out string name)
{
name = null;
GetCurrentMethodName(2, out name);
}
[Conditional("DEBUG")]
internal static void GetCurrentMethodName(int skipframe, out string name)
{
StackFrame sf = new StackFrame(skipframe, true);
name = sf.GetMethod().DeclaringType.Name + "." + sf.GetMethod().Name;
}
}
#endif
internal class HtmlCmdLine
{
static internal bool Help;
static HtmlCmdLine()
{
Help = false;
ParseArgs();
}
internal static string GetOption(string name, string def)
{
string p = def;
string[] args = Environment.GetCommandLineArgs();
for (int i=1;i<args.Length;i++)
{
GetStringArg(args[i], name, ref p);
}
return p;
}
internal static string GetOption(int index, string def)
{
string p = def;
string[] args = Environment.GetCommandLineArgs();
int j = 0;
for (int i=1;i<args.Length;i++)
{
if (GetStringArg(args[i], ref p))
{
if (index==j)
return p;
else
p = def;
j++;
}
}
return p;
}
internal static bool GetOption(string name, bool def)
{
bool p = def;
string[] args = Environment.GetCommandLineArgs();
for (int i=1;i<args.Length;i++)
{
GetBoolArg(args[i], name, ref p);
}
return p;
}
internal static int GetOption(string name, int def)
{
int p = def;
string[] args = Environment.GetCommandLineArgs();
for (int i=1;i<args.Length;i++)
{
GetIntArg(args[i], name, ref p);
}
return p;
}
private static void ParseArgs()
{
string[] args = Environment.GetCommandLineArgs();
for (int i=1;i<args.Length;i++)
{
// help
GetBoolArg(args[i], "?", ref Help);
GetBoolArg(args[i], "h", ref Help);
GetBoolArg(args[i], "help", ref Help);
}
}
private static bool GetStringArg(string Arg, ref string ArgValue)
{
if (('/'==Arg[0]) || ('-'==Arg[0]))
return false;
ArgValue = Arg;
return true;
}
private static void GetStringArg(string Arg, string Name, ref string ArgValue)
{
if (Arg.Length<(Name.Length+3)) // -name:x is 3 more than name
return;
if (('/'!=Arg[0]) && ('-'!=Arg[0])) // not a param
return;
if (Arg.Substring(1, Name.Length).ToLower()==Name.ToLower())
ArgValue = Arg.Substring(Name.Length+2, Arg.Length-Name.Length-2);
}
private static void GetBoolArg(string Arg, string Name, ref bool ArgValue)
{
if (Arg.Length<(Name.Length+1)) // -name is 1 more than name
return;
if (('/'!=Arg[0]) && ('-'!=Arg[0])) // not a param
return;
if (Arg.Substring(1, Name.Length).ToLower()==Name.ToLower())
ArgValue = true;
}
private static void GetIntArg(string Arg, string Name, ref int ArgValue)
{
if (Arg.Length<(Name.Length+3)) // -name:12 is 3 more than name
return;
if (('/'!=Arg[0]) && ('-'!=Arg[0])) // not a param
return;
if (Arg.Substring(1, Name.Length).ToLower()==Name.ToLower())
{
try
{
ArgValue = Convert.ToInt32(Arg.Substring(Name.Length+2, Arg.Length-Name.Length-2));
}
catch
{
}
}
}
}
internal class HtmlConsoleListener: System.Diagnostics.TraceListener
{
public override void WriteLine(string Message)
{
Write(Message + "\n");
}
public override void Write(string Message)
{
Write(Message, "");
}
public override void Write(string Message, string Category)
{
Console.Write("T:" + Category + ": " + Message);
}
public override void WriteLine(string Message, string Category)
{
Write(Message + "\n", Category);
}
}
}

View File

@@ -0,0 +1,301 @@
//
// Authors:
// Rafael Mizrahi <rafim@mainsoft.com>
// Erez Lotan <erezl@mainsoft.com>
// Vladimir Krasnov <vladimirk@mainsoft.com>
//
//
// Copyright (c) 2002-2005 Mainsoft Corporation.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using System.Xml;
using System.Net;
using System.Text;
using System.Collections;
using System.Reflection;
using NUnit.Framework;
namespace MonoTests.stand_alone.WebHarness
{
public class HtmlDiff
{
public const string BEGIN_TAG = "begint";
public const string END_TAG = "endt";
private XmlDocument _xmlIgnoreList = null;
private string _compareStatus = "";
private static string _compareActual = "";
private static string _compareExpect = "";
private string _ignoreListFile = "";
public HtmlDiff()
{
}
public string IgnoreListFile
{
get {return _ignoreListFile;}
set {_ignoreListFile = value;}
}
public string CompareStatus
{
get {return _compareStatus.ToString();}
}
public static string GetControlFromPageHtml (string str)
{
return GetControlFromPageHtml (str, BEGIN_TAG, END_TAG);
}
public static string GetControlFromPageHtml (string str, string beginTag, string endTag)
{
if (str == null || str.Length == 0)
throw new ArgumentException ("internal error: str is null or empty");
if (beginTag == null || beginTag.Length == 0)
throw new ArgumentNullException ("beginTag");
if (endTag == null || endTag.Length == 0)
throw new ArgumentNullException ("endTag");
int beginPos = str.IndexOf (beginTag);
int endPos = str.IndexOf (endTag);
if (beginPos == -1)
throw new InvalidOperationException (String.Format ("internal error: begin tag ('{0}') is missing. Full source: {1}", beginTag, str));
if (endPos == -1)
throw new InvalidOperationException (String.Format ("internal error: end tag ('{0}') is missing. Full source: {1}", endTag, str));
StringBuilder sb = new StringBuilder ();
sb.Append (str.Substring (beginPos + beginTag.Length, endPos - beginPos - beginTag.Length));
return sb.ToString ();
}
public static void AssertAreEqual (string origin, string derived, string msg)
{
bool test = false;
try {
test = HtmlComparer (origin, derived);
}
catch (Exception e) {
//swallow e when there is XML error and fallback
//to the text comparison
Assert.AreEqual (origin, derived, msg);
}
if (!test) {
Assert.AreEqual (_compareExpect, _compareActual, msg);
}
}
private static bool HtmlComparer (string origin, string derived)
{
XmlDocument or = new XmlDocument ();
MonoTests.stand_alone.WebHarness.HtmlDiff helper = new MonoTests.stand_alone.WebHarness.HtmlDiff ();
or.LoadXml (helper.HtmltoXml (origin));
XmlDocument dr = new XmlDocument ();
dr.LoadXml (helper.HtmltoXml (derived));
return helper.XmlCompare (or, dr, false);
}
private bool XmlCompare(XmlDocument expected, XmlDocument actual, bool ignoreAlmost)
{
XmlComparer comparer = new XmlComparer();
if (ignoreAlmost == false)
{
DoAlmost(expected);
DoAlmost(actual);
}
bool c = comparer.AreEqual(expected, actual);
_compareStatus = comparer.LastCompare;
_compareActual = comparer.Actual;
_compareExpect = comparer.Expected;
return c;
}
public string HtmltoXml (string html) //throws XmlException
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument ();
doc.LoadHtml (html.Trim (new char[] { '\r', '\n', ' ' })); // bug in HtmlAgilityPack
StringBuilder fixedxml = new StringBuilder ();
StringWriter sw = new StringWriter (fixedxml);
StringBuilder tempxml = new StringBuilder ();
StringWriter tsw = new StringWriter (tempxml);
doc.OptionOutputAsXml = true;
doc.Save (tsw);
// fix style attribute
// the reason is that style attribute name-value pairs come in different order
// in .NET and GH
// Here I will sort the values of style attribute
XmlDocument tempDoc = new XmlDocument ();
tempDoc.LoadXml (tempxml.ToString ());
XmlNodeList allNodes = tempDoc.SelectNodes ("//*");
foreach (XmlNode n in allNodes) {
if (n.Attributes["style"] != null) {
string att = n.Attributes["style"].Value;
string[] style = att.Trim (new char[] { ' ', ';' }).Split (';');
for (int styleIndex = 0; styleIndex < style.Length; styleIndex++) {
style[styleIndex] = FixStyleNameValue (style[styleIndex]);
}
Array.Sort (style);
n.Attributes["style"].Value = string.Join (";", style);
}
}
tempDoc.Save (sw);
return fixedxml.ToString ();
}
private string FixStyleNameValue(string nameValue)
{
string [] nv = nameValue.Split(':');
// value may contain spaces in case of
// multiple values for one key
string [] nvalue = nv[1].Trim().Split(' ');
Array.Sort(nvalue);
nv[1] = string.Join(" ", nvalue);
return nv[0].Trim().ToLower() + ":" + nv[1].Trim().ToLower();
}
private void DoAlmost(XmlDocument xmlDocument)
{
XmlNode XmlIgnoreNode;
IEnumerator xmlIgnoreEnum;
if (_xmlIgnoreList == null)
{
_xmlIgnoreList = new XmlDocument();
string xml;
Stream source = Assembly.GetExecutingAssembly ()
.GetManifestResourceStream ("HtmlCompare.nunitweb_config.xml");
if (source == null) {
source = Assembly.GetExecutingAssembly ()
.GetManifestResourceStream ("nunitweb_config.xml");
}
try {
using (StreamReader sr = new StreamReader (source))
xml = sr.ReadToEnd ();
}
finally {
source.Close ();
}
_xmlIgnoreList.LoadXml (xml);
}
// Remove by Id or Name
// search by tag and if id or name match, remove all attributes
// must be the first almost since the following almost delete the id and name
xmlIgnoreEnum = _xmlIgnoreList.SelectSingleNode("Almost/RemoveById").GetEnumerator();
while (xmlIgnoreEnum.MoveNext())
{
XmlNodeList DocNodeList;
XmlIgnoreNode = (XmlNode)xmlIgnoreEnum.Current;
DocNodeList = xmlDocument.GetElementsByTagName("*");
if (DocNodeList != null)
{
foreach (XmlElement tmpXmlElement in DocNodeList)
{
foreach (XmlAttribute tmpIgnoreAttr in XmlIgnoreNode.Attributes)
{
if (tmpXmlElement.Name.ToLower() == XmlIgnoreNode.Name.ToLower())
{
if (tmpXmlElement.Attributes[tmpIgnoreAttr.Name] != null )
{
if (tmpXmlElement.Attributes[tmpIgnoreAttr.Name].Value.ToLower() == tmpIgnoreAttr.Value.ToLower())
{
tmpXmlElement.RemoveAllAttributes();
}
}
}
}
}
}
}
// remove ignored attributes
// search for tag and remove it's attributes
xmlIgnoreEnum = _xmlIgnoreList.SelectSingleNode("Almost/IgnoreList").GetEnumerator(); //FirstChild.GetEnumerator
while (xmlIgnoreEnum.MoveNext())
{
XmlIgnoreNode = (XmlNode)xmlIgnoreEnum.Current;
XmlNodeList DocNodeList;
//clean specific element
DocNodeList = xmlDocument.GetElementsByTagName("*");
if (DocNodeList != null)
{
foreach (XmlElement tmpXmlElement in DocNodeList)
{
if (tmpXmlElement.Name.ToLower() == XmlIgnoreNode.Name.ToLower())
{
foreach (XmlAttribute tmpIgnoreAttr in XmlIgnoreNode.Attributes)
{
tmpXmlElement.RemoveAttribute(tmpIgnoreAttr.Name);
}
}
}
}
}
// clean javascript attribute value
xmlIgnoreEnum = _xmlIgnoreList.SelectSingleNode("Almost/CleanJavaScriptValueList").GetEnumerator(); //FirstChild.GetEnumerator
while (xmlIgnoreEnum.MoveNext())
{
XmlIgnoreNode = (XmlNode)xmlIgnoreEnum.Current;
XmlNodeList DocNodeList;
//clean Java Script attribute values
DocNodeList = xmlDocument.GetElementsByTagName("*");
if (DocNodeList != null)
{
foreach (XmlElement tmpXmlElement in DocNodeList)
{
if (tmpXmlElement.Name.ToLower() == XmlIgnoreNode.Name.ToLower())
{
foreach (XmlAttribute tmpIgnoreAttr in XmlIgnoreNode.Attributes)
{
if (tmpXmlElement.Attributes[tmpIgnoreAttr.Name] != null )
{
if (tmpXmlElement.Attributes[tmpIgnoreAttr.Name].Value.ToLower().IndexOf("javascript") >= 0 )
{
tmpXmlElement.SetAttribute(tmpIgnoreAttr.Name, "");
}
}
}
}
}
}
}
}
}
}

View File

@@ -0,0 +1,133 @@
using System;
using System.Xml;
namespace MonoTests.stand_alone.WebHarness
{
/// <summary>
/// Summary description for XmlComparer.
/// </summary>
public class XmlComparer
{
[Flags]
public enum Flags {
IgnoreNone=0,
IgnoreAttribOrder=1,
}
Flags flags;
bool ignoreWS = true;
string lastCompare = "";
string _actual = "";
string _expected = "";
public XmlComparer (Flags flags, bool ignoreWS)
{
this.flags = flags;
this.ignoreWS = ignoreWS;
}
public XmlComparer (Flags flags) : this (flags, true)
{
}
public XmlComparer () : this (Flags.IgnoreAttribOrder)
{
}
public bool AreEqualAttribs (XmlAttributeCollection expected, XmlAttributeCollection actual)
{
if (expected.Count != actual.Count)
return false;
for (int i=0; i<expected.Count; i++) {
if ((flags & Flags.IgnoreAttribOrder) != 0) {
string ln = expected[i].LocalName;
string ns = expected[i].NamespaceURI;
string val = expected[i].Value;
_expected = ns+":"+ln+"="+val;
XmlAttribute atr2 = actual[ln, ns];
_actual = atr2 == null ? "<<missing>>" : ns + ":" + ln + "=" + atr2.Value;
if (atr2 == null || atr2.Value.Trim().ToLower() != val.Trim().ToLower())
return false;
} else {
if (expected [i].LocalName != actual [i].LocalName)
return false;
if (expected [i].NamespaceURI != actual [i].NamespaceURI)
return false;
if (expected [i].Value.Trim().ToLower() != actual [i].Value.Trim().ToLower())
return false;
}
}
return true;
}
public bool AreEqualNodeList (XmlNodeList expected, XmlNodeList actual)
{
if (expected.Count != actual.Count)
return false;
for (int i=0; i<expected.Count; i++) {
if (!AreEqual (expected[i], actual[i]))
return false;
}
return true;
}
public bool AreEqual (XmlNode expected, XmlNode actual)
{
lastCompare = expected.OuterXml + "\n" + actual.OuterXml;
_actual = actual.OuterXml;
_expected = expected.OuterXml;
// skip XmlDeclaration
if ((expected.NodeType == XmlNodeType.XmlDeclaration) &&
(actual.NodeType == XmlNodeType.XmlDeclaration))
return true;
if (expected.NodeType != actual.NodeType)
return false;
if (expected.LocalName != actual.LocalName)
return false;
if (expected.NamespaceURI != actual.NamespaceURI)
return false;
if (expected.Attributes != null && actual.Attributes != null) {
if (!AreEqualAttribs (expected.Attributes, actual.Attributes))
return false;
_actual = actual.OuterXml;
_expected = expected.OuterXml;
}
else //one of nodes has no attrs
if (expected.Attributes != null || actual.Attributes != null)
return false;//and another has some
if (!expected.HasChildNodes && !actual.HasChildNodes) {
string val1 = expected.Value;
string val2 = actual.Value;
if (ignoreWS) //ignore white spaces
{
if (val1 != null)
val1 = val1.Trim().Replace("\r\n", "\n");
if (val2 != null)
val2 = val2.Trim().Replace("\r\n", "\n");
}
return val1 == val2;
}
else {//one of nodes has some children
if (!expected.HasChildNodes || !actual.HasChildNodes)
return false;//and another has none
return AreEqualNodeList (expected.ChildNodes, actual.ChildNodes);
}
}
public string LastCompare
{
get {return lastCompare;}
}
public string Actual
{
get { return _actual; }
}
public string Expected
{
get { return _expected; }
}
}
}

View File

@@ -0,0 +1,41 @@
<Almost>
<IgnoreList>
<div id="" visible="" name=""/>
<span id="" visible="" name=""/>
<input id="" visible="" name="" __EVENTARGUMENT="" __EVENTTARGET="" __VIEWSTATE="" causesvalidation=""/>
<table id="" visible="" name=""/>
<td id="" visible="" name=""/>
<th id="" visible="" name=""/>
<tr id="" visible="" name=""/>
<table id="" visible="" name=""/>
<img id="" visible="" name="" disabled=""/>
<a id="" visible="" name=""/>
<select id="" visible="" name=""/>
<textarea id="" visible="" name=""/>
<button id="" visible="" name="" causesvalidation=""/>
<p visible=""/>
<form visible=""/>
<label for=""/>
<td colspan=""/>
<select language="" onchange=""/>
<input language="" onchange=""/>
<table bordercolor=""/>
</IgnoreList>
<!--delete Java Script attribute value-->
<CleanJavaScriptValueList>
<a href=""/>
<a onclick=""/>
<input onclick=""/>
</CleanJavaScriptValueList>
<!--remove tags by attribute Id or name-->
<RemoveById>
<input id="__VIEWSTATE" name="__VIEWSTATE"/>
</RemoveById>
<!--remove tags-->
<RemoveTags>
</RemoveTags>
</Almost>

View File

@@ -0,0 +1,38 @@
<Almost>
<IgnoreList>
<div id="" visible="" name="" onmouseover="" onmouseout="" style="" />"
<span id="" visible="" name="" src=""/>
<input id="" visible="" name="" __EVENTARGUMENT="" __EVENTTARGET="" __VIEWSTATE="" causesvalidation="" onclick=""/>
<table id="" visible="" name=""/>
<td id="" visible="" name=""/>
<th id="" visible="" name=""/>
<tr id="" visible="" name=""/>
<table id="" visible="" name=""/>
<img id="" visible="" name="" disabled="" src=""/>
<a id="" visible="" name="" href="" onclick=""/>
<select id="" visible="" name=""/>
<textarea id="" visible="" name=""/>
<button id="" visible="" name="" causesvalidation=""/>
<p visible=""/>
<form visible=""/>
<label for=""/>
<select language="" onchange=""/>
<input language="" onchange=""/>
<table bordercolor=""/>
<tr onmouseover="" onmouseout="" onkeyup="" id="" />
<td onmouseover="" onmouseout="" onkeyup="" id="" />
</IgnoreList>
<!--delete Java Script attribute value-->
<CleanJavaScriptValueList>
<a href=""/>
<a onclick=""/>
<area href=""/>
</CleanJavaScriptValueList>
<!--remove tags by attribute Id or name-->
<RemoveById>
<input id="__VIEWSTATE" name="__VIEWSTATE"/>
</RemoveById>
</Almost>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<testresults name="">
</testresults>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<testresults name="">
<div id="GHTSubTest1" style="height:296px;left:16px;position:absolute;top:15px;width:553px;z-index:100">
</div>
</testresults>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<testresults name="">
<div id="GHTSubTest1" style="height:296px;left:16px;position:absolute;top:15px;width:553px;z-index:100">
</div>
</testresults>

Some files were not shown because too many files have changed in this diff Show More