/* * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * Tests around null/"" arguments for public methods. * * You may think that so elaborate testing for such a part is not necessary. * But I actually detected a bug by this program during my porting work.
*/ publicclass NormalizerAPITest extends IntlTest {
publicstaticvoid main(String[] args) throws Exception { new NormalizerAPITest().run(args);
}
/* * Check if normalize(null) throws NullPointerException as expected.
*/ publicvoid Test_NullPointerException_java_normalize() { boolean error = false;
/* Check null as String to be normalized */ for (int i = 0; i < forms.length; i++) { try {
String s = Normalizer.normalize(null, forms[i]);
error = true;
} catch (NullPointerException e) {
}
}
/* Check null as a Normalization form */ try {
String s = Normalizer.normalize(nonNullStr, NULL);
error = true;
} catch (NullPointerException e) {
}
if (error) {
errln("normalize(null) should throw NullPointerException.");
}
}
/* * Check if normalize(null) throws NullPointerException as expected.
*/ publicvoid Test_NullPointerException_sun_normalize() { boolean error = false;
for (int j = 0; j < options.length; j++) { for (int i = 0; i < forms.length; i++) { /* Check null as a String to be normalized */ try {
String s = sun.text.Normalizer.normalize(null, forms[i], options[j]);
error = true;
} catch (NullPointerException e) {
}
}
/* Check null as a Normalization form */ try {
String s = sun.text.Normalizer.normalize(nonNullStr, NULL, options[j]);
error = true;
} catch (NullPointerException e) {
}
}
if (error) {
errln("normalize(null) should throw NullPointerException.");
}
}
/* * Check if isNormalized(null) throws NullPointerException as expected.
*/ publicvoid Test_NullPointerException_java_isNormalized() { boolean error = false;
for (int i = 0; i < forms.length; i++) { try { /* Check null as a String to be scanned */ boolean b = Normalizer.isNormalized(null, forms[i]);
error = true;
} catch (NullPointerException e) {
}
}
/* Check null as a String to be scanned */ try { boolean b = Normalizer.isNormalized(nonNullStr, NULL);
error = true;
}
catch (NullPointerException e) {
} if (error) {
errln("isNormalized(null) should throw NullPointerException.");
}
}
/* * Check if isNormalized(null) throws NullPointerException as expected.
*/ publicvoid Test_NullPointerException_sun_isNormalized() { boolean error = false;
for (int j = 0; j < options.length; j++) { for (int i = 0; i < forms.length; i++) { try { /* Check null as a String to be scanned */ boolean b = sun.text.Normalizer.isNormalized(null, forms[i], options[j]);
error = true;
} catch (NullPointerException e) {
}
}
/* Check null as a String to be scanned */ try { boolean b = sun.text.Normalizer.isNormalized(nonNullStr, NULL, options[j]);
error = true;
} catch (NullPointerException e) {
}
}
if (error) {
errln("isNormalized(null) should throw NullPointerException.");
}
}
/* * Check if isNormalized("") doesn't throw NullPointerException and returns * "" as expected.
*/ publicvoid Test_No_NullPointerException_java_normalize() { boolean error = false;
for (int i = 0; i < forms.length; i++) { try {
String s = Normalizer.normalize("", forms[i]); if (!s.equals("")) {
error = true;
}
} catch (NullPointerException e) {
error = true;
}
}
if (error) {
errln("normalize() for String(\"\") should return \"\".");
}
}
/* * Check if isNormalized("") doesn't throw NullPointerException and returns * "" as expected.
*/ publicvoid Test_No_NullPointerException_sun_normalize() { boolean error = false;
for (int j = 0; j < options.length; j++) { for (int i = 0; i < forms.length; i++) { try {
String s = sun.text.Normalizer.normalize("", forms[i], options[j]); if (!s.equals("")) {
error = true;
}
} catch (NullPointerException e) {
error = true;
}
}
} if (error) {
errln("normalize() for String(\"\") should return \"\".");
}
}
/* * Check if isNormalized("") doesn't throw NullPointerException and returns * "" as expected.
*/ publicvoid Test_No_NullPointerException_java_isNormalized() { boolean error = false;
for (int i = 0; i < forms.length; i++) { try { boolean b = Normalizer.isNormalized("", forms[i]); if (!b) {
error = true;
}
} catch (NullPointerException e) {
error = true;
}
} if (error) {
errln("isNormalized() for String(\"\") should not return true.");
}
}
/* * Check if isNormalized("") doesn't throw NullPointerException and returns * "" as expected.
*/ publicvoid Test_No_NullPointerException_sun_isNormalized() { boolean error = false;
for (int j = 0; j < options.length; j++) { for (int i = 0; i < forms.length; i++) { try { boolean b = sun.text.Normalizer.isNormalized("", forms[i], options[j]); if (!b) {
error = true;
}
} catch (NullPointerException e) {
error = true;
}
}
} if (error) {
errln("isNormalized() for String(\"\") should not return true.");
}
}
/* * Check if normalize() and isNormalized() work as expected for every * known class which implement CharSequence Interface.
*/ publicvoid Test_CharSequence() {
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.