Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/xml/jaxp/transform/8062923/XslSubstringTest.java
41154 views
1
/*
2
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 8062923 8062924 8074297 8076290
27
* @run testng XslSubstringTest
28
* @summary Test xsl substring function with negative, Inf and
29
* NaN length and few other use cases. Also test proper
30
* processing of supplementary characters by substring function.
31
*/
32
33
import java.io.StringReader;
34
import java.io.StringWriter;
35
import javax.xml.transform.Source;
36
import javax.xml.transform.Templates;
37
import javax.xml.transform.Transformer;
38
import javax.xml.transform.TransformerFactory;
39
import javax.xml.transform.stream.StreamResult;
40
import javax.xml.transform.stream.StreamSource;
41
42
import static org.testng.Assert.assertEquals;
43
import org.testng.annotations.DataProvider;
44
import org.testng.annotations.Test;
45
46
public class XslSubstringTest {
47
48
final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><test></test>";
49
final String xslPre = "<xsl:stylesheet version='1.0'"
50
+ " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"
51
+ "<xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>"
52
+ "<xsl:template match='/'><t>";
53
final String xslPost = "</t></xsl:template></xsl:stylesheet>";
54
55
@DataProvider(name = "GeneralTestsData")
56
private Object[][] xmls() {
57
return new Object[][] {
58
{ "|<xsl:value-of select=\"substring('asdf',2, 1)\"/>|", "<t>|s|</t>"},
59
{ "|<xsl:value-of select=\"substring('asdf',2, 1 div 0)\"/>|", "<t>|sdf|</t>"},
60
{ "|<xsl:value-of select=\"substring('asdf',2, -0 div 0)\"/>|", "<t>||</t>" },
61
{ "|<xsl:value-of select=\"substring('asdf',2, 1 div 0)\"/>|", "<t>|sdf|</t>" },
62
// 8076290 bug test case
63
{ "|<xsl:value-of select=\"substring('123', 0, 3)\"/>|", "<t>|12|</t>"},
64
};
65
}
66
67
@DataProvider(name = "SupplementaryCharactersTestData")
68
private Object[][] dataSupplementaryCharacters() {
69
return new Object[][] {
70
// 8074297 bug test cases
71
{ "|<xsl:value-of select=\"substring('&#131083;ABC', 3)\"/>|", "<t>|BC|</t>"},
72
{ "|<xsl:value-of select=\"substring('&#131083;ABC', 3, 1)\"/>|", "<t>|B|</t>" },
73
{ "|<xsl:value-of select=\"substring('&#131083;ABC', 2, 2)\"/>|", "<t>|AB|</t>"},
74
{ "|<xsl:value-of select=\"substring('&#131083;ABC', 3, 2)\"/>|", "<t>|BC|</t>"},
75
{ "|<xsl:value-of select=\"substring('&#131083;ABC', 3, 4)\"/>|", "<t>|BC|</t>"},
76
{ "|<xsl:value-of select=\"substring('&#131083;ABC', 1, 1)\"/>|", "<t>|&#131083;|</t>"},
77
{ "|<xsl:value-of select=\"substring('&#131083;ABC', 2, 1)\"/>|", "<t>|A|</t>"},
78
{ "|<xsl:value-of select=\"substring('&#131083;ABC', 1, 1 div 0)\"/>|", "<t>|&#131083;ABC|</t>"},
79
{ "|<xsl:value-of select=\"substring('&#131083;ABC', -10, 1 div 0)\"/>|", "<t>|&#131083;ABC|</t>"},
80
// 8076290 bug test case
81
{ "|<xsl:value-of select=\"substring('&#131083;ABC', 0, 2)\"/>|", "<t>|&#131083;|</t>"},
82
};
83
}
84
85
private String testTransform(String xsl) throws Exception {
86
//Prepare sources for transormation
87
Source src = new StreamSource(new StringReader(xml));
88
Source xslsrc = new StreamSource(new StringReader(xslPre + xsl + xslPost));
89
//Create factory, template and transformer
90
TransformerFactory tf = TransformerFactory.newInstance();
91
Templates tmpl = tf.newTemplates(xslsrc);
92
Transformer t = tmpl.newTransformer();
93
//Prepare output stream
94
StringWriter xmlResultString = new StringWriter();
95
StreamResult xmlResultStream = new StreamResult(xmlResultString);
96
//Transform
97
t.transform(src, xmlResultStream);
98
return xmlResultString.toString().trim();
99
}
100
101
@Test
102
public void test8062923() throws Exception {
103
assertEquals(testTransform("|<xsl:value-of select=\"substring('asdf',2,-1)\"/>|"),
104
"<t>||</t>");
105
}
106
107
@Test
108
public void test8062924() throws Exception {
109
assertEquals(testTransform("|<xsl:value-of select=\"substring('asdf',2,-1 div 0)\"/>|"),
110
"<t>||</t>");
111
}
112
113
@Test(dataProvider = "GeneralTestsData")
114
public void testGeneralAll(String xsl, String result) throws Exception {
115
assertEquals(testTransform(xsl), result);
116
}
117
118
@Test(dataProvider = "SupplementaryCharactersTestData")
119
public void testSupplementCharacters(String xsl, String result) throws Exception {
120
assertEquals(testTransform(xsl), result);
121
}
122
123
}
124
125