48664
|
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 5087448
|
|
27 |
* @summary Verify that property.save saves comments correctly
|
|
28 |
*/
|
|
29 |
|
|
30 |
import java.io.ByteArrayInputStream;
|
|
31 |
import java.io.ByteArrayOutputStream;
|
|
32 |
import java.io.IOException;
|
|
33 |
import java.util.Properties;
|
|
34 |
|
|
35 |
public class SaveComments {
|
|
36 |
|
|
37 |
public static void main(String[] argv) throws IOException {
|
|
38 |
String ls = System.getProperty("line.separator");
|
|
39 |
String[] input = new String[] {
|
|
40 |
"Comments with \u4e2d\u6587\u6c49\u5b57 included",
|
|
41 |
"Comments with \n Second comments line",
|
|
42 |
"Comments with \n# Second comments line",
|
|
43 |
"Comments with \n! Second comments line",
|
|
44 |
"Comments with last character is \n",
|
|
45 |
"Comments with last character is \r\n",
|
|
46 |
"Comments with last two characters are \n\n",
|
|
47 |
"Comments with last four characters are \r\n\r\n",
|
|
48 |
"Comments with \nkey4=value4",
|
|
49 |
"Comments with \n#key4=value4"};
|
|
50 |
|
|
51 |
String[] output = new String[] {
|
|
52 |
"#Comments with \\u4E2D\\u6587\\u6C49\\u5B57 included" + ls,
|
|
53 |
"#Comments with " + ls + "# Second comments line" + ls,
|
|
54 |
"#Comments with " + ls + "# Second comments line" + ls,
|
|
55 |
"#Comments with " + ls + "! Second comments line" + ls,
|
|
56 |
"#Comments with last character is " + ls+"#"+ls,
|
|
57 |
"#Comments with last character is " + ls+"#"+ls,
|
|
58 |
"#Comments with last two characters are " + ls+"#"+ls+"#"+ls,
|
|
59 |
"#Comments with last four characters are " + ls+"#"+ls+"#"+ls};
|
|
60 |
|
|
61 |
Properties props = new Properties();
|
|
62 |
boolean failed = false;
|
|
63 |
int i = 0;
|
|
64 |
for (i = 0; i < output.length; i++) {
|
|
65 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(200);
|
|
66 |
props.store(baos, input[i]);
|
|
67 |
String result = baos.toString("iso8859-1");
|
|
68 |
if (result.indexOf(output[i]) == -1) {
|
|
69 |
System.out.println("Wrong \"store()\" output:");
|
|
70 |
System.out.println(result);
|
|
71 |
failed = true;
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
props.put("key1", "value1");
|
|
76 |
props.put("key2", "value2");
|
|
77 |
props.put("key3", "value3");
|
|
78 |
for (; i < input.length; i++) {
|
|
79 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(200);
|
|
80 |
props.store(baos, input[i]);
|
|
81 |
Properties propsNew = new Properties();
|
|
82 |
propsNew.load(new ByteArrayInputStream(baos.toByteArray()));
|
|
83 |
/*
|
|
84 |
Set<Map.Entry<Object, Object>> kvsetNew = propsNew.entrySet();
|
|
85 |
Set<Map.Entry<Object, Object>> kvset = props.entrySet();
|
|
86 |
if (!kvsetNew.containsAll(kvset) || !kvset.containsAll(kvsetNew)) {
|
|
87 |
*/
|
|
88 |
if (!props.equals (propsNew)) {
|
|
89 |
System.out.println("Wrong output:");
|
|
90 |
System.out.println(baos.toString("iso8859-1"));
|
|
91 |
failed = true;
|
|
92 |
}
|
|
93 |
}
|
|
94 |
if (failed)
|
|
95 |
throw new RuntimeException("Incorrect Properties Comment Output.");
|
|
96 |
}
|
|
97 |
}
|