public inbox for mauve-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: mauve-discuss@sourceware.org
Cc: David Gilbert <david.gilbert@object-refinery.com>
Subject: registerValidation update
Date: Wed, 12 Oct 2005 17:44:00 -0000	[thread overview]
Message-ID: <1129139080.5922.20.camel@localhost.localdomain> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 861 bytes --]

Hi,

This updates the ObjectInputStream.registerValidation() test to test
whether it is only called one in the deserialization tree (the this
reference) and whether you can add validators at any time and whether
the priority order is observed.

2005-10-12  Mark Wielaard  <mark@klomp.org>

    * gnu/testlet/java/io/ObjectInputStream/registerValidation.java:
    Check fields and priority order.
    * gnu/testlet/java/io/ObjectInputStream/TestObjectInputValidation.java:
    Add self reference, register multiple times with different priorities,
    add equals().

I am currently testing a patch for GNU Classpath.
David since you wrote the original test you might have seen a real world
program using this feature. If so and this is a Free Software program
could you let me know so I can also test my patch against that.

Thanks,

Mark

[-- Attachment #1.2: registerValidation.patch --]
[-- Type: text/x-patch, Size: 4274 bytes --]

Index: gnu/testlet/java/io/ObjectInputStream/TestObjectInputValidation.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/io/ObjectInputStream/TestObjectInputValidation.java,v
retrieving revision 1.1
diff -u -r1.1 TestObjectInputValidation.java
--- gnu/testlet/java/io/ObjectInputStream/TestObjectInputValidation.java	5 Jul 2005 12:22:39 -0000	1.1
+++ gnu/testlet/java/io/ObjectInputStream/TestObjectInputValidation.java	12 Oct 2005 17:44:08 -0000
@@ -33,32 +33,61 @@
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.util.ArrayList;
 
 class TestObjectInputValidation implements ObjectInputValidation, Serializable {
-  private boolean validated;
+  ArrayList validated;
   private String name;
+  private int priority;
+  TestObjectInputValidation object;
+
   public TestObjectInputValidation(String name) 
   {      
     this.name = name;
-    this.validated = false;
+    this.priority = 10;
+    this.object = this;
   }
-  public boolean isValidated() 
+
+  // Registers with priority for given object.
+  public TestObjectInputValidation(int priority,
+				   TestObjectInputValidation object)
   {
-    return this.validated;
+    this.priority = priority;
+    this.object = object;
   }
+
   public void validateObject()
   {
-    this.validated = true;
+    if (object.validated == null)
+      object.validated = new ArrayList();
+    object.validated.add(new Integer(priority));
   }
+
   private void writeObject(ObjectOutputStream stream) throws IOException 
   {
     stream.defaultWriteObject();
   }
+
   private void readObject(ObjectInputStream stream) 
       throws IOException, ClassNotFoundException 
   {
-    stream.defaultReadObject();
     stream.registerValidation(this, 10);
+    stream.registerValidation(new TestObjectInputValidation(-10, this), -10);
+    stream.defaultReadObject();
+    stream.registerValidation(this, 12); // Again with other priority
+    stream.registerValidation(new TestObjectInputValidation(-12, this), -12);
+    stream.registerValidation(new TestObjectInputValidation(11, this), 11);
   }
 
+  // Ignores validated list and object.
+  public boolean equals(Object o)
+  {
+    if (o instanceof TestObjectInputValidation)
+      {
+	TestObjectInputValidation other = (TestObjectInputValidation) o;
+	return this.name.equals(other.name)
+	  && this.priority == other.priority;
+      }
+    return false;
+  }
 }
Index: gnu/testlet/java/io/ObjectInputStream/registerValidation.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/io/ObjectInputStream/registerValidation.java,v
retrieving revision 1.2
diff -u -r1.2 registerValidation.java
--- gnu/testlet/java/io/ObjectInputStream/registerValidation.java	5 Jul 2005 12:22:39 -0000	1.2
+++ gnu/testlet/java/io/ObjectInputStream/registerValidation.java	12 Oct 2005 17:44:08 -0000
@@ -34,6 +34,7 @@
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.util.ArrayList;
 
 /**
  * Some checks for registerValidation() method of the {@link ObjectInputStream} class.
@@ -62,11 +63,27 @@
       );
       t2 = (TestObjectInputValidation) in.readObject();
       in.close();
+
+      harness.check(t2, t1); // name and priority the same
+      harness.check(t2.object, t2); // has self-reference
+      harness.check(t2.validated != null);
+
+      Object[] ps = t2.validated.toArray();
+      int[] priorities = new int[ps.length];
+      for (int i = 0; i < ps.length; i++)
+	priorities[i] = ((Integer) ps[i]).intValue();
+      harness.check(priorities != null);
+      harness.check(priorities.length, 5);
+      harness.check(priorities[0], -12);
+      harness.check(priorities[1], -10);
+      harness.check(priorities[2], 10);
+      harness.check(priorities[3], 11);
+      harness.check(priorities[4], 10); // The priority 12 "this" again.
     }
     catch (Exception e) {
       harness.debug(e);
+      harness.check(false, e.toString());
     }
-    harness.check(t2.isValidated());
   }
   
 }

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2005-10-12 17:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-12 17:44 Mark Wielaard [this message]
2005-10-12 18:02 ` David Gilbert
2005-10-12 19:38   ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1129139080.5922.20.camel@localhost.localdomain \
    --to=mark@klomp.org \
    --cc=david.gilbert@object-refinery.com \
    --cc=mauve-discuss@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).