public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: SocketPermission action check tests
@ 2006-01-16 11:13 Gary Benson
  0 siblings, 0 replies; only message in thread
From: Gary Benson @ 2006-01-16 11:13 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 237 bytes --]

Hi all,

This test checks that all possible action lists are handled correctly
by java.net.SocketPermission's implies method.  There's more to come,
but I'm committing now as it tests the fix I just committed to
Classpath.

Cheers,
Gary

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 3223 bytes --]

Index: ChangeLog
===================================================================
RCS file: /cvs/mauve/mauve/ChangeLog,v
retrieving revision 1.1347
diff -u -r1.1347 ChangeLog
--- ChangeLog	15 Jan 2006 19:48:29 -0000	1.1347
+++ ChangeLog	16 Jan 2006 11:06:22 -0000
@@ -1,3 +1,7 @@
+2006-01-16  Gary Benson <gbenson@redhat.com>
+
+	* gnu/testlet/java/net/SocketPermission/implies.java: New test.
+
 2006-01-16  Raif S. Naffah  <raif@swiftdsl.com.au>
 
 	* gnu/testlet/javax/security/auth/login/TestOfPR25202.java: New file.
Index: gnu/testlet/java/net/SocketPermission/implies.java
===================================================================
RCS file: gnu/testlet/java/net/SocketPermission/implies.java
diff -N gnu/testlet/java/net/SocketPermission/implies.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/net/SocketPermission/implies.java	16 Jan 2006 11:06:22 -0000
@@ -0,0 +1,76 @@
+// Copyright (C) 2006 Red Hat, Inc.
+// Written by Gary Benson <gbenson@redhat.com>
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve 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 for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING.  If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.java.net.SocketPermission;
+
+import java.net.SocketPermission;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+
+public class implies implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    harness.checkPoint("action checking");
+    for (int i = 1; i < 1 << actions.length; i++) {
+      for (int j = 1; j < 1 << actions.length; j++) {
+	SocketPermission pi = new SocketPermission("localhost", makeAction(i));
+	SocketPermission pj = new SocketPermission("localhost", makeAction(j));
+
+	harness.checkPoint(pi.getActions() + " implies " + pj.getActions());
+	
+	harness.check(pi.implies(pj) == ((maybeAddResolve(i) & j) == j));
+      }
+    }
+  }
+
+  // stuff for action checking
+  private static String[] actions = {"accept", "connect", "listen", "resolve"};
+  private static String makeAction(int mask)
+  {
+    String result = "";
+    for (int i = 0; i < actions.length; i++) {
+      if ((mask & (1 << i)) != 0) {
+	if (result.length() > 0)
+	  result += ",";
+	result += actions[i];
+      }
+    }
+    return result;
+  }
+  
+  // All other actions imply resolve
+  private static int maybeAddResolve(int mask)
+  {
+    boolean addit = false;
+    int addwhat = 0;
+    
+    for (int i = 0; i < actions.length; i++) {
+      if (actions[i].equals("resolve"))
+	addwhat = 1 << i;
+      else if ((mask & (1 << i)) != 0)
+	addit = true;
+    }
+    if (addit)
+      mask |= addwhat;
+    return mask;
+  }
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-01-16 11:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-16 11:13 FYI: SocketPermission action check tests Gary Benson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).