-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XMP : Anchor namespace declarations to custom nodes + XmlArray unit t…
…ests
- Loading branch information
Showing
11 changed files
with
337 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
using ATL.AudioData; | ||
using ATL.AudioData.IO; | ||
using System.IO; | ||
|
||
namespace ATL.test | ||
{ | ||
[TestClass] | ||
public class XmlArrayTest | ||
{ | ||
private static string getFrom(string name) | ||
{ | ||
var dataPath = TestUtils.GetResourceLocationRoot() + "_Xml" + Path.DirectorySeparatorChar + name; | ||
using (var source = new FileStream(dataPath, FileMode.Open)) | ||
{ | ||
var reader = new StreamReader(source); | ||
return reader.ReadToEnd().ReplaceLineEndings("").Replace("\t", ""); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void XmlArray_writeBasic() | ||
{ | ||
var xmlArray = new XmlArray( | ||
"root", | ||
"test", | ||
_ => false, | ||
_ => false | ||
); | ||
|
||
TagHolder holder = new TagHolder(); | ||
var data = new Dictionary<string, string>(); | ||
data["test.one"] = "aaa"; | ||
data["test.two"] = "bbb"; | ||
holder.AdditionalFields = data; | ||
|
||
var memStream = new MemoryStream(); | ||
xmlArray.ToStream(memStream, holder); | ||
var reader = new StreamReader(memStream); | ||
memStream.Position = 0; | ||
string result = reader.ReadToEnd(); | ||
|
||
Assert.IsTrue(result.Length > 0); | ||
|
||
var expected = getFrom("basic.xml"); | ||
Assert.AreEqual(expected, result); | ||
} | ||
|
||
[TestMethod] | ||
public void XmlArray_writeAttributes() | ||
{ | ||
var xmlArray = new XmlArray( | ||
"root", | ||
"test", | ||
_ => false, | ||
_ => false | ||
); | ||
xmlArray.setStructuralAttributes(new HashSet<string> { "hey", "PIP" }); | ||
|
||
TagHolder holder = new TagHolder(); | ||
var data = new Dictionary<string, string>(); | ||
data["test.one.hey"] = "ho"; | ||
data["test.one"] = "aaa"; | ||
data["test.two.pip"] = "boy"; | ||
data["test.two"] = "bbb"; | ||
holder.AdditionalFields = data; | ||
|
||
var memStream = new MemoryStream(); | ||
xmlArray.ToStream(memStream, holder); | ||
var reader = new StreamReader(memStream); | ||
memStream.Position = 0; | ||
string result = reader.ReadToEnd(); | ||
|
||
Assert.IsTrue(result.Length > 0); | ||
|
||
var expected = getFrom("attributes.xml"); | ||
Assert.AreEqual(expected, result); | ||
} | ||
|
||
[TestMethod] | ||
public void XmlArray_writeCollections() | ||
{ | ||
var xmlArray = new XmlArray( | ||
"root", | ||
"test", | ||
e => e.EndsWith("LIST", StringComparison.OrdinalIgnoreCase), | ||
_ => false | ||
); | ||
|
||
TagHolder holder = new TagHolder(); | ||
var data = new Dictionary<string, string>(); | ||
data["test.one"] = "aaa"; | ||
data["test.two"] = "bbb"; | ||
data["test.theList.elt[0].value"] = "11"; | ||
data["test.theList.elt[1].value"] = "22"; | ||
data["test.theList.elt[2].value"] = "33"; | ||
holder.AdditionalFields = data; | ||
|
||
var memStream = new MemoryStream(); | ||
xmlArray.ToStream(memStream, holder); | ||
var reader = new StreamReader(memStream); | ||
memStream.Position = 0; | ||
string result = reader.ReadToEnd(); | ||
|
||
Assert.IsTrue(result.Length > 0); | ||
|
||
var expected = getFrom("collection.xml"); | ||
Assert.AreEqual(expected, result); | ||
} | ||
|
||
[TestMethod] | ||
public void XmlArray_writeRootNs() | ||
{ | ||
IDictionary<string, string> DEFAULT_NAMESPACES = new Dictionary<string, string> { { "pap", "test:ns:meta/" } }; | ||
var xmlArray = new XmlArray( | ||
"root", | ||
"test", | ||
_ => false, | ||
_ => false | ||
); | ||
// No namespace anchors (=> default anchor goes to root) | ||
xmlArray.setDefaultNamespaces(DEFAULT_NAMESPACES); | ||
|
||
TagHolder holder = new TagHolder(); | ||
var data = new Dictionary<string, string>(); | ||
data["test.pap:one"] = "aaa"; | ||
data["test.pap:two"] = "bbb"; | ||
holder.AdditionalFields = data; | ||
|
||
var memStream = new MemoryStream(); | ||
xmlArray.ToStream(memStream, holder); | ||
var reader = new StreamReader(memStream); | ||
memStream.Position = 0; | ||
string result = reader.ReadToEnd(); | ||
|
||
Assert.IsTrue(result.Length > 0); | ||
|
||
var expected = getFrom("rootNs.xml"); | ||
Assert.AreEqual(expected, result); | ||
|
||
|
||
// All namespaces explicitly anchored to root | ||
IDictionary<string, ISet<string>> NAMESPACE_ANCHORS = new Dictionary<string, ISet<string>> { { "root", new HashSet<string> { "" } } }; | ||
xmlArray.setNamespaceAnchors(NAMESPACE_ANCHORS); | ||
|
||
memStream = new MemoryStream(); | ||
xmlArray.ToStream(memStream, holder); | ||
reader = new StreamReader(memStream); | ||
memStream.Position = 0; | ||
result = reader.ReadToEnd(); | ||
|
||
Assert.IsTrue(result.Length > 0); | ||
|
||
Assert.AreEqual(expected, result); | ||
|
||
|
||
// Specific namespace explicitly anchored to root | ||
IDictionary<string, ISet<string>> NAMESPACE_ANCHORS2 = new Dictionary<string, ISet<string>> { { "root", new HashSet<string> { "pap" } } }; | ||
xmlArray.setNamespaceAnchors(NAMESPACE_ANCHORS2); | ||
|
||
memStream = new MemoryStream(); | ||
xmlArray.ToStream(memStream, holder); | ||
reader = new StreamReader(memStream); | ||
memStream.Position = 0; | ||
result = reader.ReadToEnd(); | ||
|
||
Assert.IsTrue(result.Length > 0); | ||
|
||
Assert.AreEqual(expected, result); | ||
} | ||
|
||
[TestMethod] | ||
public void XmlArray_writeAnchoredNs() | ||
{ | ||
IDictionary<string, string> DEFAULT_NAMESPACES = new Dictionary<string, string> { { "pap", "test:ns:meta/" } }; | ||
// Anchor one specific ns to one specific node | ||
IDictionary<string, ISet<string>> NAMESPACE_ANCHORS = new Dictionary<string, ISet<string>> { { "container", new HashSet<string> { "pap" } } }; | ||
var xmlArray = new XmlArray( | ||
"root", | ||
"test", | ||
_ => false, | ||
_ => false | ||
); | ||
xmlArray.setDefaultNamespaces(DEFAULT_NAMESPACES); | ||
xmlArray.setNamespaceAnchors(NAMESPACE_ANCHORS); | ||
|
||
TagHolder holder = new TagHolder(); | ||
var data = new Dictionary<string, string>(); | ||
data["test.container.pap:one"] = "aaa"; | ||
data["test.container.pap:two"] = "bbb"; | ||
holder.AdditionalFields = data; | ||
|
||
var memStream = new MemoryStream(); | ||
xmlArray.ToStream(memStream, holder); | ||
var reader = new StreamReader(memStream); | ||
memStream.Position = 0; | ||
string result = reader.ReadToEnd(); | ||
|
||
Assert.IsTrue(result.Length > 0); | ||
|
||
var expected = getFrom("anchoredNs.xml"); | ||
Assert.AreEqual(expected, result); | ||
|
||
// Anchor all ns'es to one specific node | ||
IDictionary<string, ISet<string>> NAMESPACE_ANCHORS2 = new Dictionary<string, ISet<string>> { { "container", new HashSet<string> { "" } } }; | ||
xmlArray.setNamespaceAnchors(NAMESPACE_ANCHORS2); | ||
|
||
memStream = new MemoryStream(); | ||
xmlArray.ToStream(memStream, holder); | ||
reader = new StreamReader(memStream); | ||
memStream.Position = 0; | ||
result = reader.ReadToEnd(); | ||
|
||
Assert.IsTrue(result.Length > 0); | ||
|
||
Assert.AreEqual(expected, result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<container xmlns:pap="test:ns:meta/"> | ||
<pap:one>aaa</pap:one> | ||
<pap:two>bbb</pap:two> | ||
</container> | ||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<one hey="ho">aaa</one> | ||
<two pip="boy">bbb</two> | ||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<one>aaa</one> | ||
<two>bbb</two> | ||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<one>aaa</one> | ||
<two>bbb</two> | ||
<theList> | ||
<elt><value>11</value></elt> | ||
<elt><value>22</value></elt> | ||
<elt><value>33</value></elt> | ||
</theList> | ||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root xmlns:pap="test:ns:meta/"> | ||
<pap:one>aaa</pap:one> | ||
<pap:two>bbb</pap:two> | ||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.