1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/java/util/prefs/Preferences/XMLPreferencesTest.java Wed Jun 24 17:29:29 2009 +0200
1.3 @@ -0,0 +1,97 @@
1.4 +/*
1.5 + * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Sun designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Sun in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
1.26 + * have any questions.
1.27 + */
1.28 +
1.29 +
1.30 +import java.io.ByteArrayInputStream;
1.31 +import sun.util.xml.PrefsXmlSupport;
1.32 +
1.33 +import java.io.ByteArrayOutputStream;
1.34 +import java.util.prefs.Preferences;
1.35 +
1.36 +/** Checks whether reading and writing via standard DOM and simplified API
1.37 + * results in same results.
1.38 + *
1.39 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.40 + */
1.41 +public class XMLPreferencesTest {
1.42 + private static PrefsXmlSupport FULL = new com.sun.xml.internal.PrefsXmlSupportImpl();
1.43 + private static PrefsXmlSupport SIMPLE = new sun.util.xml.DefaultPrefsXmlSupport();
1.44 +
1.45 +
1.46 + public static void main(String[] args) throws Exception {
1.47 + XMLPreferencesTest test = new XMLPreferencesTest();
1.48 + test.testCompareOutput();
1.49 + test.testCompareInput();
1.50 + }
1.51 +
1.52 +
1.53 + public XMLPreferencesTest() {
1.54 + }
1.55 +
1.56 + public void testCompareOutput() throws Exception {
1.57 + Preferences p = Preferences.userRoot().node("a/b/c");
1.58 + p.put("ahoj", "simple");
1.59 + p.putInt("kuk", 1);
1.60 + p.putBoolean("multi", true);
1.61 + p.node("child").putBoolean("data", false);
1.62 + p.node("empty");
1.63 + p.parent().putDouble("visible", 1.0);
1.64 +
1.65 + ByteArrayOutputStream full = new ByteArrayOutputStream();
1.66 + FULL.export(full, p, true);
1.67 +
1.68 + ByteArrayOutputStream simple = new ByteArrayOutputStream();
1.69 + SIMPLE.export(simple, p, true);
1.70 + if (full.toString().equals(simple.toString())) {
1.71 + // OK
1.72 + System.err.println("OK: testCompareOutput");
1.73 + } else {
1.74 + assert false :
1.75 + "Full version differs from simplified. Full:\n" + full + "\nSimple:\n" + simple;
1.76 + }
1.77 + }
1.78 +
1.79 + public void testCompareInput() throws Exception {
1.80 + /*
1.81 + String text = "";
1.82 +
1.83 + Properties p1 = new Properties();
1.84 + {
1.85 + ByteArrayInputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
1.86 + FULL.load(p1, is);
1.87 + }
1.88 +
1.89 + Properties p2 = new Properties();
1.90 + {
1.91 + ByteArrayInputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
1.92 + SIMPLE.load(p2, is);
1.93 + }
1.94 +
1.95 + assert p1.equals(p2) : "P1: " + p1 + "\nP2: " + p2;
1.96 + System.err.println("OK: testCompareInput");
1.97 + */
1.98 + }
1.99 +
1.100 +}
1.101 \ No newline at end of file