2 *******************************************************************************
3 * Copyright (C) 2009, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.dev.test.stringprep;
9 import com.ibm.icu.dev.test.TestFmwk;
10 import com.ibm.icu.text.StringPrep;
11 import com.ibm.icu.text.StringPrepParseException;
17 public class TestStringPrepProfiles extends TestFmwk {
18 public static void main(String[] args) throws Exception {
19 new TestStringPrepProfiles().run(args);
23 * The format of the test cases should be the following:
33 * *Note: For expected failures add FAIL to beginning of the source string and for expected result use "FAIL".
35 private static String[][] testCases = {
38 "user:\u00A0\u0AC6\u1680\u00ADpassword1",
39 "user: \u0AC6 password1"
43 "Policy\u034F\u200DBase\u0020d\u1806\u200C",
48 "Anony\u0020\u00A0mous\u3000\u0B9D\u034F\u00AD",
49 "Anony\u0020\u00A0mous\u3000\u0B9D\u034F\u00AD"
53 "Ldap\uFB01\u00ADTest\u0020\u00A0\u2062ing",
58 "Ldap\uFB01\u00ADTest\u0020\u00A0\u2062ing12345",
62 "RFC3920_RESOURCEPREP",
63 "ServerXM\u2060\uFE00\uFE09PP s p ",
68 "Server\u200DXMPPGreEK\u03D0",
69 "serverxmppgreek\u03B2"
73 "InternetSmallComputer\uFB01\u0032\u2075Interface",
74 "internetsmallcomputerfi25interface",
75 "FAILThisShouldFailBecauseOfThis\u002F",
79 "RFC3530_NFS4_CS_PREP",
80 "\u00ADUser\u2060Name@ \u06DDDOMAIN.com",
81 "UserName@ \u06DDDOMAIN.com"
84 "RFC3530_NFS4_CS_PREP_CI",
85 "\u00ADUser\u2060Name@ \u06DDDOMAIN.com",
86 "username@ \u06DDdomain.com"
89 "RFC3530_NFS4_CIS_PREP",
90 "AA\u200C\u200D @@DomAin.org",
94 "RFC3530_NFS4_MIXED_PREP_PREFIX",
95 "PrefixUser \u007F\uFB01End",
96 "PrefixUser \u007FfiEnd"
99 "RFC3530_NFS4_MIXED_PREP_SUFFIX",
100 "SuffixDomain \u007F\uFB01EnD",
101 "suffixdomain \u007Ffiend"
105 private int getOptionFromProfileName(String profileName) {
106 if (profileName.equals("RFC4013_SASLPREP")) {
107 return StringPrep.RFC4013_SASLPREP;
108 } else if (profileName.equals("RFC4011_MIB")) {
109 return StringPrep.RFC4011_MIB;
110 } else if (profileName.equals("RFC4505_TRACE")) {
111 return StringPrep.RFC4505_TRACE;
112 } else if (profileName.equals("RFC4518_LDAP")) {
113 return StringPrep.RFC4518_LDAP;
114 } else if (profileName.equals("RFC4518_LDAP_CI")) {
115 return StringPrep.RFC4518_LDAP_CI;
116 } else if (profileName.equals("RFC3920_RESOURCEPREP")) {
117 return StringPrep.RFC3920_RESOURCEPREP;
118 } else if (profileName.equals("RFC3920_NODEPREP")) {
119 return StringPrep.RFC3920_NODEPREP;
120 } else if (profileName.equals("RFC3722_ISCSI")) {
121 return StringPrep.RFC3722_ISCSI;
122 } else if (profileName.equals("RFC3530_NFS4_CS_PREP")) {
123 return StringPrep.RFC3530_NFS4_CS_PREP;
124 } else if (profileName.equals("RFC3530_NFS4_CS_PREP_CI")) {
125 return StringPrep.RFC3530_NFS4_CS_PREP_CI;
126 } else if (profileName.equals("RFC3530_NFS4_CIS_PREP")) {
127 return StringPrep.RFC3530_NFS4_CIS_PREP;
128 } else if (profileName.equals("RFC3530_NFS4_MIXED_PREP_PREFIX")) {
129 return StringPrep.RFC3530_NFS4_MIXED_PREP_PREFIX;
130 } else if (profileName.equals("RFC3530_NFS4_MIXED_PREP_SUFFIX")) {
131 return StringPrep.RFC3530_NFS4_MIXED_PREP_SUFFIX;
134 // Should not happen.
138 public void TestProfiles() {
139 String profileName = null;
140 StringPrep sprep = null;
141 String result = null;
143 String expected = null;
145 for (int i = 0; i < testCases.length; i++) {
146 for (int j = 0; j < testCases[i].length; j++) {
148 profileName = testCases[i][j];
150 sprep = StringPrep.getInstance(getOptionFromProfileName(profileName));
152 src = testCases[i][j];
153 expected = testCases[i][++j];
155 result = sprep.prepare(src, StringPrep.ALLOW_UNASSIGNED);
156 if (src.startsWith("FAIL")) {
157 errln("Failed: Expected error for Test[" + i +"] Profile: " + profileName);
158 } else if (!result.equals(expected)) {
159 errln("Failed: Test[" + i + "] Result string does not match expected string for StringPrep test for profile: " + profileName);
161 } catch (StringPrepParseException ex) {
162 if (!src.startsWith("FAIL")) {
163 errln("Failed: Test[" + i + "] StringPrep profile " + profileName + " got error: " + ex);