jtulach@1263: /* jtulach@1263: * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved. jtulach@1263: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jtulach@1263: * jtulach@1263: * This code is free software; you can redistribute it and/or modify it jtulach@1263: * under the terms of the GNU General Public License version 2 only, as jtulach@1263: * published by the Free Software Foundation. Sun designates this jtulach@1263: * particular file as subject to the "Classpath" exception as provided jtulach@1263: * by Sun in the LICENSE file that accompanied this code. jtulach@1263: * jtulach@1263: * This code is distributed in the hope that it will be useful, but WITHOUT jtulach@1263: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jtulach@1263: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jtulach@1263: * version 2 for more details (a copy is included in the LICENSE file that jtulach@1263: * accompanied this code). jtulach@1263: * jtulach@1263: * You should have received a copy of the GNU General Public License version jtulach@1263: * 2 along with this work; if not, write to the Free Software Foundation, jtulach@1263: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jtulach@1263: * jtulach@1263: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jtulach@1263: * CA 95054 USA or visit www.sun.com if you need additional information or jtulach@1263: * have any questions. jtulach@1263: */ jtulach@1263: jtulach@1263: jtulach@1263: import java.io.ByteArrayInputStream; jtulach@1263: import sun.util.xml.PrefsXmlSupport; jtulach@1263: jtulach@1263: import java.io.ByteArrayOutputStream; jtulach@1263: import java.util.prefs.Preferences; jtulach@1263: jtulach@1263: /** Checks whether reading and writing via standard DOM and simplified API jtulach@1263: * results in same results. jtulach@1263: * jtulach@1263: * @author Jaroslav Tulach jtulach@1263: */ jtulach@1263: public class XMLPreferencesTest { jtulach@1263: private static PrefsXmlSupport FULL = new com.sun.xml.internal.PrefsXmlSupportImpl(); jtulach@1263: private static PrefsXmlSupport SIMPLE = new sun.util.xml.DefaultPrefsXmlSupport(); jtulach@1263: jtulach@1263: jtulach@1263: public static void main(String[] args) throws Exception { jtulach@1263: XMLPreferencesTest test = new XMLPreferencesTest(); jtulach@1263: test.testCompareOutput(); jtulach@1263: test.testCompareInput(); jtulach@1263: } jtulach@1263: jtulach@1263: jtulach@1263: public XMLPreferencesTest() { jtulach@1263: } jtulach@1263: jtulach@1263: public void testCompareOutput() throws Exception { jtulach@1263: Preferences p = Preferences.userRoot().node("a/b/c"); jtulach@1263: p.put("ahoj", "simple"); jtulach@1263: p.putInt("kuk", 1); jtulach@1263: p.putBoolean("multi", true); jtulach@1263: p.node("child").putBoolean("data", false); jtulach@1263: p.node("empty"); jtulach@1263: p.parent().putDouble("visible", 1.0); jtulach@1263: jtulach@1263: ByteArrayOutputStream full = new ByteArrayOutputStream(); jtulach@1263: FULL.export(full, p, true); jtulach@1263: jtulach@1263: ByteArrayOutputStream simple = new ByteArrayOutputStream(); jtulach@1263: SIMPLE.export(simple, p, true); jtulach@1263: if (full.toString().equals(simple.toString())) { jtulach@1263: // OK jtulach@1263: System.err.println("OK: testCompareOutput"); jtulach@1263: } else { jtulach@1263: assert false : jtulach@1263: "Full version differs from simplified. Full:\n" + full + "\nSimple:\n" + simple; jtulach@1263: } jtulach@1263: } jtulach@1263: jtulach@1263: public void testCompareInput() throws Exception { jtulach@1263: /* jtulach@1263: String text = ""; jtulach@1263: jtulach@1263: Properties p1 = new Properties(); jtulach@1263: { jtulach@1263: ByteArrayInputStream is = new ByteArrayInputStream(text.getBytes("UTF-8")); jtulach@1263: FULL.load(p1, is); jtulach@1263: } jtulach@1263: jtulach@1263: Properties p2 = new Properties(); jtulach@1263: { jtulach@1263: ByteArrayInputStream is = new ByteArrayInputStream(text.getBytes("UTF-8")); jtulach@1263: SIMPLE.load(p2, is); jtulach@1263: } jtulach@1263: jtulach@1263: assert p1.equals(p2) : "P1: " + p1 + "\nP2: " + p2; jtulach@1263: System.err.println("OK: testCompareInput"); jtulach@1263: */ jtulach@1263: } jtulach@1263: jtulach@1263: }