Path: blob/master/test/jdk/java/util/Properties/LoadParsing2.java
41149 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4881291 409488626* @summary checks for processing errors in properties.load27*/2829import java.io.File;30import java.io.FileInputStream;31import java.io.InputStream;32import java.io.InputStreamReader;33import java.util.Properties;3435public class LoadParsing2 {36public static void main(String[] argv) throws Exception {37for (int i = 0; i < dfiles.length; i++) {38test(dfiles[i], keys[i], values[i], true);39test(dfiles[i], keys[i], values[i], false);40}41}4243private static Properties getLoadedProperties(InputStream is,44boolean doStream)45throws Exception46{47Properties props = new Properties();48if (doStream)49props.load(is);50else51props.load(new InputStreamReader(is, "UTF-8"));52return props;53}5455private static void test(String fnData,56String[] keys,57String[] values,58boolean doStream)59throws Exception60{61File f = new File(System.getProperty("test.src", "."), fnData);62FileInputStream myIn = new FileInputStream(f);63Properties myProps = getLoadedProperties(myIn, doStream);64for (int i = 0; i < keys.length; i++) {65if (!myProps.getProperty(keys[i]).equals(values[i])) {66throw new RuntimeException("Test1: Bad parsing at " + i);67}68}69}7071static String[] keys1 = {72"\\",73"\\:key12",74"key16 b",75"key14_asdfa",76"\\\\",77"key8notassign",78"key17",79"key15",80"keyabcdef",81"key13dialog.3",82"key7",83"key6",84"key5",85"key3",86"key2",87"key1",88"key9 Term",89"key0"90};9192static String[] keys2 = {93"key1",94"key2"95};9697static String[] keys3 = {98"key1",99"key2"100};101102static String[] values1 = {103"key10=bar",104"bar2",105" abcdef",106"",107"key11=bar2",108"abcdef",109"#barbaz",110" abcdef",111"",112"",113"Symbol,SYMBOL_CHARSET ",114"WingDings,SYMBOL_CHARSET \\abc",115"==Arial,ANSI_CHARSET",116"",117"= abcde",118"value1",119"ABCDE",120"abcd"121};122123static String[] values2 = {124"-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",125"-b&h-LucidaBrightLat4-normal-i-normal-Italic-*-%d-*-*-p-*-iso8859-4"126};127128static String[] values3 = {129"-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",130"-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"131};132133static String[][] keys = {keys1, keys1, keys2, keys2, keys3};134static String[][] values = {values1, values1, values2, values2, values3};135static String[] dfiles = {136"testData1",137"testData1.dos",138"testData2",139"testData2.dos",140"testData3.dos"141};142}143144145