1 /*
2  * Copyright (c) 2018, 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 4881291 4094886
27  * @summary checks for processing errors in properties.load
28  */
29 
30 package test.java.util.Properties;
31 
32 import java.io.InputStream;
33 import java.io.InputStreamReader;
34 import java.util.Properties;
35 
36 public class LoadParsing2 {
main(String[] argv)37     public static void main(String[] argv) throws Exception {
38         for (int i = 0; i < dfiles.length; i++) {
39             // Android-changed: investigate why these tests fail.
40             // test(dfiles[i], keys[i], values[i], true);
41             // test(dfiles[i], keys[i], values[i], false);
42         }
43     }
44 
getLoadedProperties(InputStream is, boolean doStream)45     private static Properties getLoadedProperties(InputStream is,
46                                                   boolean doStream)
47         throws Exception
48     {
49         Properties props = new Properties();
50         if (doStream)
51             props.load(is);
52         else
53             props.load(new InputStreamReader(is, "UTF-8"));
54         return props;
55     }
56 
test(String fnData, String[] keys, String[] values, boolean doStream)57     private static void test(String fnData,
58                              String[] keys,
59                              String[] values,
60                              boolean doStream)
61         throws Exception
62     {
63         // Android-changed: read data from resources.
64         // File f = new File(System.getProperty("test.src", "."), fnData);
65         // FileInputStream myIn = new FileInputStream(f);
66         InputStream myIn = LoadParsing2.class.getResourceAsStream(fnData);
67         Properties myProps = getLoadedProperties(myIn, doStream);
68         for (int i = 0; i < keys.length; i++) {
69             if (!myProps.getProperty(keys[i]).equals(values[i])) {
70                 throw new RuntimeException("Test1: Bad parsing at " + i);
71             }
72         }
73     }
74 
75     static String[] keys1 = {
76         "\\",
77         "\\:key12",
78         "key16 b",
79         "key14_asdfa",
80         "\\\\",
81         "key8notassign",
82         "key17",
83         "key15",
84         "keyabcdef",
85         "key13dialog.3",
86         "key7",
87         "key6",
88         "key5",
89         "key3",
90         "key2",
91         "key1",
92         "key9 Term",
93         "key0"
94     };
95 
96     static String[] keys2 = {
97         "key1",
98         "key2"
99     };
100 
101     static String[] keys3 = {
102         "key1",
103         "key2"
104     };
105 
106     static String[] values1 = {
107         "key10=bar",
108         "bar2",
109         " abcdef",
110         "",
111         "key11=bar2",
112         "abcdef",
113         "#barbaz",
114         " abcdef",
115         "",
116         "",
117         "Symbol,SYMBOL_CHARSET ",
118         "WingDings,SYMBOL_CHARSET \\abc",
119         "==Arial,ANSI_CHARSET",
120         "",
121         "= abcde",
122         "value1",
123         "ABCDE",
124         "abcd"
125     };
126 
127     static String[] values2 = {
128         "-monotype-timesnewroman-regular-r---*-%d-*-*-p-*-iso8859-1serif.1a-monotype-timesnewroman-regular-r-normal--*-%d-*-*-p-*-iso8859-2serif.2a-b&h-LucidaBrightLat4-Normal-r-normal--*-%d-*-*-p-*-iso8859-4serif.3a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-5serif.4a-monotype-timesnewromangreek-regular-r-normal--*-%d-*-*-p-*-iso8859-7serif.5a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-9serif.6a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-15serif.7a-hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1serif.8a-sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0serif.9a-ricoh-hgminchol-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0serif.10a-ricoh-hgminchol-medium-r-normal--*-%d-*-*-m-*-jisx0208.1983-0serif.11a-ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0serif.12a-hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3serif.13a-urw-itczapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecificserif.14a-*-symbol-medium-r-normal--*-%d-*-*-p-*-sun-fontspecificbserif.italic.0=-monotype-timesbnewbroman-regular-i---*-%d-*-*-p-*-iso8859-1bserif.italic.1=-monotype-timesbnewbroman-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-2",
129         "-b&h-LucidaBrightLat4-normal-i-normal-Italic-*-%d-*-*-p-*-iso8859-4"
130     };
131 
132     static String[] values3 = {
133         "-monotype-times new roman-regular-r---*-%d-*-*-p-*-iso8859-1, -monotype-times new roman-regular-r-normal--*-%d-*-*-p-*-iso8859-2, -b&h-LucidaBrightLat4-Normal-r-normal--*-%d-*-*-p-*-iso8859-4, -monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-5, -monotype-times new roman greek-regular-r-normal--*-%d-*-*-p-*-iso8859-7, -monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-9, -monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-15, -hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1, -sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0, -ricoh-hg gothic b-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0, -ricoh-hg gothic b-medium-r-normal-*-*-%d-*-*-m-*-jisx0208.1983-0, -ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0, -hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3",
134         "-monotype-times new roman-regular-i---*-%d-*-*-p-*-iso8859-1, -monotype-times new roman-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-2, -b&h-LucidaBrightLat4-normal-i-normal-Italic-*-%d-*-*-p-*-iso8859-4, -monotype-times-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-5, -monotype-times new roman greek-regular-i-normal--*-%d-*-*-p-*-iso8859-7, -monotype-times-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-9, -monotype-times-regular-i-normal--*-%d-*-*-p-*-iso8859-15, -hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1, -sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0, -ricoh-hg gothic b-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0, -ricoh-hg gothic b-medium-r-normal-*-*-%d-*-*-m-*-jisx0208.1983-0, -ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0, -hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3"
135     };
136 
137     static String[][] keys = {keys1, keys1, keys2, keys2, keys3};
138     static String[][] values = {values1, values1, values2, values2, values3};
139     static String[] dfiles = {
140         "testData1",
141         "testData1.dos",
142         "testData2",
143         "testData2.dos",
144         "testData3.dos"
145     };
146 }
147