2 * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
27 import java.io.ByteArrayInputStream;
28 import sun.util.xml.PrefsXmlSupport;
30 import java.io.ByteArrayOutputStream;
31 import java.util.prefs.Preferences;
33 /** Checks whether reading and writing via standard DOM and simplified API
34 * results in same results.
36 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
38 public class XMLPreferencesTest {
39 private static PrefsXmlSupport FULL = new com.sun.xml.internal.PrefsXmlSupportImpl();
40 private static PrefsXmlSupport SIMPLE = new sun.util.xml.DefaultPrefsXmlSupport();
43 public static void main(String[] args) throws Exception {
44 XMLPreferencesTest test = new XMLPreferencesTest();
45 test.testCompareOutput();
46 test.testCompareInput();
50 public XMLPreferencesTest() {
53 public void testCompareOutput() throws Exception {
54 Preferences p = Preferences.userRoot().node("a/b/c");
55 p.put("ahoj", "simple");
57 p.putBoolean("multi", true);
58 p.node("child").putBoolean("data", false);
60 p.parent().putDouble("visible", 1.0);
62 ByteArrayOutputStream full = new ByteArrayOutputStream();
63 FULL.export(full, p, true);
65 ByteArrayOutputStream simple = new ByteArrayOutputStream();
66 SIMPLE.export(simple, p, true);
67 if (full.toString().equals(simple.toString())) {
69 System.err.println("OK: testCompareOutput");
72 "Full version differs from simplified. Full:\n" + full + "\nSimple:\n" + simple;
76 public void testCompareInput() throws Exception {
80 Properties p1 = new Properties();
82 ByteArrayInputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
86 Properties p2 = new Properties();
88 ByteArrayInputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
92 assert p1.equals(p2) : "P1: " + p1 + "\nP2: " + p2;
93 System.err.println("OK: testCompareInput");