1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Xunit;
using Xunit.Abstractions;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Xsl;
using OLEDB.Test.ModuleCore;
namespace System.Xml.Tests
{
//[TestCase(Name = "Load(Type) API Functional Tests", Desc = "This testcase exercises the API tests for the Load(Type) overload")]
public class XsltcAPITest : XsltcTestCaseBase
{
private ITestOutputHelper _output;
public XsltcAPITest(ITestOutputHelper output) : base(output)
{
_output = output;
}
//[Variation("1", Desc = "Pass null, Load((Type) null)", Pri = 0)]
[InlineData()]
[Theory]
public void Var1()
{
try
{
new XslCompiledTransform().Load((Type)null);
}
catch (ArgumentNullException)
{
return;
}
throw new CTestFailedException("Did not throw ArgumentException");
}
//[Variation("2", Desc = "Pass types that are not generated by xsltc.exe, Load(typeof(Object))", Pri = 1)]
[InlineData()]
[Theory]
public void Var2()
{
try
{
new XslCompiledTransform().Load(typeof(Object));
}
catch (ArgumentException)
{
return;
}
throw new CTestFailedException("Did not throw ArgumentException");
}
/*//[Variation("3", Desc = "Exercise loading from the same class within different threads", Pri = 1)]
[InlineData()]
[Theory]
public void Var3()
{
var xsltList = new SynchronizedCollection<XslCompiledTransform>();
var rThreads = new CThreads(_output);
for (int i = 0; i < 10; i++)
{
rThreads.Add(o =>
{
var xslt = new XslCompiledTransform();
xsltList.Add(xslt);
XsltcUtil.LoadFromAssembly(ref xslt, "IdentityTransform");
return;
}, i.ToString(CultureInfo.InvariantCulture));
}
//Wait until they are complete
rThreads.Start();
rThreads.Wait();
return Verify(xsltList);
}*/
//[Variation("4", Desc = "XSLCompiledTransform Load(Type) changes the static data of the Type to XmlILCommand", Pri = 1)]
[InlineData()]
//[Theory] //Disabled as it tries to load an assembly which does not exist on CoreFX anymore
public void Var4()
{
var xslt = new XslCompiledTransform();
Type t = Assembly.Load(new AssemblyName("TestStylesheet")).GetType("TestStylesheet");
BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Static;
Type beforeLoad = t.GetTypeInfo().GetField("staticData", bindingFlags).GetValue(null).GetType();
xslt.Load(t);
Type afterLoad = t.GetTypeInfo().GetField("staticData", bindingFlags).GetValue(null).GetType();
CError.Compare(beforeLoad, afterLoad, "Mismatch in type, before and after load");
return;
}
public void Verify(IList<XslCompiledTransform> xsltList)
{
var inputXml = new XmlDocument();
inputXml.LoadXml("<foo><bar>Hello, world!</bar></foo>");
foreach (XslCompiledTransform xslt in xsltList)
{
using (var actualStream = new MemoryStream())
using (var sw = new StreamWriter(actualStream) { AutoFlush = true })
{
xslt.Transform(inputXml, null, sw);
CompareOutput("<?xml version=\"1.0\" encoding=\"utf-8\"?><foo><bar>Hello, world!</bar></foo>", actualStream);
}
}
}
}
}
|