001: /*
002: *
003: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025:
026: package tests.ixcpermission;
027:
028: import javax.microedition.xlet.ixc.IxcPermission;
029: import gunit.framework.*;
030:
031: // Just a test to check for equals() and implies() on
032: // various IxcPermission instances.
033:
034: public class IxcPermissionTest extends TestCase {
035:
036: public void test_ixcPermissions() {
037:
038: String[] bindActions = { "BIND", "Bind", "bind", "bInD" };
039: String[] lookupActions = { "LOOKUP", "Lookup", "lookup",
040: "lOOkUp" };
041:
042: IxcPermission[] bindPerms = new IxcPermission[bindActions.length];
043: for (int i = 0; i < bindPerms.length; i++) {
044: bindPerms[i] = new IxcPermission("*", bindActions[i]);
045: }
046:
047: IxcPermission[] lookupPerms = new IxcPermission[lookupActions.length];
048: for (int i = 0; i < lookupPerms.length; i++) {
049: lookupPerms[i] = new IxcPermission("*", lookupActions[i]);
050: }
051:
052: for (int i = 0; i < 4; i++) {
053: for (int j = 0; j < 4; j++) {
054: if (!bindPerms[i].equals(bindPerms[j])
055: || !bindPerms[i].implies(bindPerms[j])) {
056: System.out.println(bindPerms[i]);
057: System.out.println(bindPerms[j]);
058: throw new RuntimeException("Failed");
059: }
060: }
061: }
062:
063: for (int i = 0; i < 4; i++) {
064: for (int j = 0; j < 4; j++) {
065: if (!lookupPerms[i].equals(lookupPerms[j])
066: || !lookupPerms[i].implies(lookupPerms[j])) {
067: System.out.println(lookupPerms[i]);
068: System.out.println(lookupPerms[j]);
069: throw new RuntimeException("Failed");
070: }
071: }
072: }
073:
074: IxcPermission[] allPerms = new IxcPermission[bindActions.length];
075: for (int i = 0; i < allPerms.length; i++) {
076: allPerms[i] = new IxcPermission("*", new String(
077: bindActions[i] + "," + lookupActions[i]));
078: }
079:
080: for (int i = 0; i < 4; i++) {
081: for (int j = 0; j < 4; j++) {
082: if (allPerms[i].equals(bindPerms[j])
083: || !allPerms[i].implies(bindPerms[j])) {
084: System.out.println(allPerms[i]);
085: System.out.println(bindPerms[j]);
086: throw new RuntimeException("Failed");
087: }
088: }
089: }
090:
091: for (int i = 0; i < 4; i++) {
092: for (int j = 0; j < 4; j++) {
093: if (allPerms[i].equals(lookupPerms[j])
094: || !allPerms[i].implies(lookupPerms[j])) {
095: System.out.println(allPerms[i]);
096: System.out.println(lookupPerms[j]);
097: throw new RuntimeException("Failed");
098: }
099: }
100: }
101:
102: IxcPermission[] allPermsABC = new IxcPermission[bindActions.length];
103: for (int i = 0; i < allPermsABC.length; i++) {
104: allPermsABC[i] = new IxcPermission("ABC", new String(
105: bindActions[i] + " , " + lookupActions[i]));
106: }
107:
108: for (int i = 0; i < 4; i++) {
109: for (int j = 0; j < 4; j++) {
110: if (allPerms[i].equals(allPermsABC[j])
111: || !allPerms[i].implies(allPermsABC[j])) {
112: System.out.println(allPerms[i]);
113: System.out.println(allPermsABC[j]);
114: System.out.println("Equals : "
115: + allPerms[i].equals(allPermsABC[j]));
116: System.out.println("Implies: "
117: + allPerms[i].implies(allPermsABC[j]));
118: throw new RuntimeException("Failed");
119: }
120: }
121: }
122:
123: IxcPermission[] bindPermsABC = new IxcPermission[bindActions.length];
124: for (int i = 0; i < bindPermsABC.length; i++) {
125: bindPermsABC[i] = new IxcPermission("ABC", bindActions[i]);
126: }
127:
128: for (int i = 0; i < 4; i++) {
129: for (int j = 0; j < 4; j++) {
130: if (bindPerms[i].equals(bindPermsABC[j])
131: || !bindPerms[i].implies(bindPermsABC[j])) {
132: System.out.println(bindPerms[i]);
133: System.out.println(bindPermsABC[j]);
134: throw new RuntimeException("Failed");
135: }
136: }
137: }
138:
139: for (int i = 0; i < 4; i++) {
140: for (int j = 0; j < 4; j++) {
141: if (bindPerms[i].equals(lookupPerms[j])
142: || bindPerms[i].implies(lookupPerms[j])) {
143: System.out.println(bindPerms[i]);
144: System.out.println(lookupPerms[j]);
145: throw new RuntimeException("Failed");
146: }
147: }
148: }
149:
150: IxcPermission[] lookupPermsABC = new IxcPermission[bindActions.length];
151: for (int i = 0; i < lookupPermsABC.length; i++) {
152: lookupPermsABC[i] = new IxcPermission("ABC",
153: lookupActions[i]);
154: }
155:
156: for (int i = 0; i < 4; i++) {
157: for (int j = 0; j < 4; j++) {
158: if (bindPermsABC[i].equals(lookupPermsABC[j])
159: || bindPermsABC[i].implies(lookupPermsABC[j])) {
160: System.out.println(bindPermsABC[i]);
161: System.out.println(lookupPermsABC[j]);
162: throw new RuntimeException("Failed");
163: }
164: }
165: }
166:
167: // make the previous imply the follower
168: String[] variousPath = { "*", "xlet://*", "xlet://tmp/*",
169: "xlet://tmp/ABC" };
170: IxcPermission[] lookupPermsVAR = new IxcPermission[variousPath.length];
171: for (int i = 0; i < lookupPermsABC.length; i++) {
172: lookupPermsVAR[i] = new IxcPermission(variousPath[i],
173: "lookup");
174: }
175: for (int i = 0; i < 4; i++) {
176: for (int j = i + 1; j < 4; j++) {
177: if (lookupPermsVAR[i].equals(lookupPermsVAR[j])
178: || !lookupPermsVAR[i]
179: .implies(lookupPermsVAR[j])) {
180: System.out.println(lookupPermsVAR[i]);
181: System.out.println(lookupPermsVAR[j]);
182: System.out.println("Equals : "
183: + lookupPermsVAR[i]
184: .equals(lookupPermsVAR[j]));
185: System.out.println("Implies: "
186: + lookupPermsVAR[i]
187: .implies(lookupPermsVAR[j]));
188: throw new RuntimeException("Failed");
189: }
190: }
191: }
192: System.out.println("OK");
193:
194: }
195: }
|