Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@435 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
38 changed files with 705 additions and 338 deletions
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Xml; |
||||
using XmlEditor.Tests.Utils; |
||||
using XmlEditor.Tests.Schema; |
||||
|
||||
namespace XmlEditor.Tests.Schema.Includes |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that schemas referenced via xs:include elements are used when
|
||||
/// generating completion data.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AttributeGroupRefSchemaIncludeTestFixture : AttributeGroupRefTestFixture |
||||
{ |
||||
[TestFixtureTearDown] |
||||
public void FixtureTearDown() |
||||
{ |
||||
SchemaIncludeTestFixtureHelper.FixtureTearDown(); |
||||
} |
||||
|
||||
protected override XmlSchemaCompletionData CreateSchemaCompletionDataObject() |
||||
{ |
||||
return SchemaIncludeTestFixtureHelper.CreateSchemaCompletionDataObject(GetMainSchema(), GetSchema()); |
||||
} |
||||
|
||||
string GetMainSchema() |
||||
{ |
||||
return "<xs:schema \r\n" + |
||||
"targetNamespace=\"http://www.w3schools.com\" \r\n" + |
||||
"xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" \r\n" + |
||||
"elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:include schemaLocation=\"include.xsd\"/>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Xml; |
||||
using XmlEditor.Tests.Utils; |
||||
using XmlEditor.Tests.Schema; |
||||
|
||||
namespace XmlEditor.Tests.Schema.Includes |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that schemas referenced via xs:include elements are used when
|
||||
/// generating completion data.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class TwoElementSchemaIncludeTestFixture : TwoElementSchemaTestFixture |
||||
{ |
||||
[TestFixtureTearDown] |
||||
public void FixtureTearDown() |
||||
{ |
||||
SchemaIncludeTestFixtureHelper.FixtureTearDown(); |
||||
} |
||||
|
||||
protected override XmlSchemaCompletionData CreateSchemaCompletionDataObject() |
||||
{ |
||||
return SchemaIncludeTestFixtureHelper.CreateSchemaCompletionDataObject(GetMainSchema(), GetSchema()); |
||||
} |
||||
|
||||
string GetMainSchema() |
||||
{ |
||||
return "<xs:schema \r\n" + |
||||
"targetNamespace=\"http://www.w3schools.com\" \r\n" + |
||||
"xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" \r\n" + |
||||
"elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:include schemaLocation=\"include.xsd\"/>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Xml; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Schema.Uri |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the <see cref="XmlSchemaCompletionData.GetUri"/> method.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class GetUriTestFixture |
||||
{ |
||||
[Test] |
||||
public void SimpleFileName() |
||||
{ |
||||
string fileName = @"C:\temp\foo.xml"; |
||||
string expectedUri = "file:///C:/temp/foo.xml"; |
||||
|
||||
Assert.AreEqual(expectedUri, XmlSchemaCompletionData.GetUri(fileName)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullFileName() |
||||
{ |
||||
Assert.AreEqual(String.Empty, XmlSchemaCompletionData.GetUri(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void EmptyString() |
||||
{ |
||||
Assert.AreEqual(String.Empty, XmlSchemaCompletionData.GetUri(String.Empty)); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,137 @@
@@ -0,0 +1,137 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 318 $</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests elements that are abstract and require substitution groups.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AbstractElementTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
ICompletionData[] itemsElementChildren; |
||||
ICompletionData[] fileElementAttributes; |
||||
ICompletionData[] fileElementChildren; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
|
||||
path.Elements.Add(new QualifiedName("project", "http://foo")); |
||||
path.Elements.Add(new QualifiedName("items", "http://foo")); |
||||
|
||||
itemsElementChildren = SchemaCompletionData.GetChildElementCompletionData(path); |
||||
|
||||
path.Elements.Add(new QualifiedName("file", "http://foo")); |
||||
|
||||
fileElementAttributes = SchemaCompletionData.GetAttributeCompletionData(path); |
||||
fileElementChildren = SchemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void ItemsElementHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, itemsElementChildren.Length, |
||||
"Should be 2 child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReferenceElementIsChildOfItemsElement() |
||||
{ |
||||
Assert.IsTrue(SchemaTestFixtureBase.Contains(itemsElementChildren, "reference")); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileElementIsChildOfItemsElement() |
||||
{ |
||||
Assert.IsTrue(SchemaTestFixtureBase.Contains(itemsElementChildren, "file")); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileElementHasAttributeNamedType() |
||||
{ |
||||
Assert.IsTrue(SchemaTestFixtureBase.Contains(fileElementAttributes, "type")); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileElementHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, fileElementChildren.Length, "Should be 2 child elements."); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema targetNamespace=\"http://foo\" xmlns:foo=\"http://foo\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">\r\n" + |
||||
" <xs:element name=\"project\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:group ref=\"foo:projectItems\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:group name=\"projectItems\">\r\n" + |
||||
" <xs:choice>\r\n" + |
||||
" <xs:element name=\"items\" type=\"foo:itemGroupType\"/>\r\n" + |
||||
" <xs:element name=\"message\" type=\"xs:string\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:group>\r\n" + |
||||
"\r\n" + |
||||
" <xs:complexType name=\"itemGroupType\">\r\n" + |
||||
" <xs:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:element ref=\"foo:item\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"name\" type=\"xs:string\" use=\"optional\"/> \r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"item\" type=\"foo:itemType\" abstract=\"true\"/>\r\n" + |
||||
"\r\n" + |
||||
"<xs:complexType name=\"itemType\">\r\n" + |
||||
" <xs:attribute name=\"name\" type=\"xs:string\" use=\"optional\"/> \r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"reference\" substitutionGroup=\"foo:item\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:complexContent>\r\n" + |
||||
" <xs:extension base=\"foo:itemType\">\r\n" + |
||||
" <xs:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:choice>\r\n" + |
||||
" <xs:element name=\"name\"/>\r\n" + |
||||
" <xs:element name=\"location\"/> \r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"description\" type=\"xs:string\"/>\r\n" + |
||||
" </xs:extension>\r\n" + |
||||
" </xs:complexContent>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"file\" substitutionGroup=\"foo:item\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:complexContent>\r\n" + |
||||
" <xs:extension base=\"foo:itemType\">\r\n" + |
||||
" <xs:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:choice>\r\n" + |
||||
" <xs:element name=\"name\"/>\r\n" + |
||||
" <xs:element name=\"attributes\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"type\" type=\"xs:string\"/>\r\n" + |
||||
" </xs:extension>\r\n" + |
||||
" </xs:complexContent>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Helper class when testing a schema which includes
|
||||
/// another schema.
|
||||
/// </summary>
|
||||
public class SchemaIncludeTestFixtureHelper |
||||
{ |
||||
static string mainSchemaFileName = "main.xsd"; |
||||
static string includedSchemaFileName = "include.xsd"; |
||||
static readonly string schemaPath; |
||||
|
||||
SchemaIncludeTestFixtureHelper() |
||||
{ |
||||
} |
||||
|
||||
static SchemaIncludeTestFixtureHelper() |
||||
{ |
||||
schemaPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "XmlEditorTests"); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a schema with the given filename
|
||||
/// </summary>
|
||||
/// <param name="fileName">Filename of the schema that will be
|
||||
/// generated.</param>
|
||||
/// <param name="xml">The schema xml</param>
|
||||
public static void CreateSchema(string fileName, string xml) |
||||
{ |
||||
XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8); |
||||
writer.WriteRaw(xml); |
||||
writer.Close(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates two schemas, one which references the other via an
|
||||
/// xs:include. Both schemas will exist in the same folder.
|
||||
/// </summary>
|
||||
/// <param name="mainSchema">The main schema's xml.</param>
|
||||
/// <param name="includedSchema">The included schema's xml.</param>
|
||||
public static XmlSchemaCompletionData CreateSchemaCompletionDataObject(string mainSchema, string includedSchema) |
||||
{ |
||||
if (!Directory.Exists(schemaPath)) { |
||||
Directory.CreateDirectory(schemaPath); |
||||
} |
||||
|
||||
CreateSchema(Path.Combine(schemaPath, mainSchemaFileName), mainSchema); |
||||
CreateSchema(Path.Combine(schemaPath, includedSchemaFileName), includedSchema); |
||||
|
||||
// Parse schema.
|
||||
string schemaFileName = Path.Combine(schemaPath, mainSchemaFileName); |
||||
string baseUri = XmlSchemaCompletionData.GetUri(schemaFileName); |
||||
return new XmlSchemaCompletionData(baseUri, schemaFileName); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes any files generated for the test fixture.
|
||||
/// </summary>
|
||||
public static void FixtureTearDown() |
||||
{ |
||||
// Delete the created schemas.
|
||||
string fileName = Path.Combine(schemaPath, mainSchemaFileName); |
||||
if (File.Exists(fileName)) { |
||||
File.Delete(fileName); |
||||
} |
||||
|
||||
fileName = Path.Combine(schemaPath, includedSchemaFileName); |
||||
if (File.Exists(fileName)) { |
||||
File.Delete(fileName); |
||||
} |
||||
|
||||
if (Directory.Exists(schemaPath)) { |
||||
Directory.Delete(schemaPath); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue