Commits

Anonymous committed b327ab1

sb135: #i116046# fixed jurt.com.sun.star.lib.uno.protocols.urp.Cache typo, adapted corresponding tests plus solenv/inc/javaunittest.mk to JUnit framework

  • Participants
  • Parent commits f9dc0c7

Comments (0)

Files changed (7)

File jurt/com/sun/star/lib/uno/protocols/urp/Cache.java

         if (e == null) {
             if (map.size() < maxSize) {
                 // There is still room for a new entry at the front:
-                e = new Entry(content, map.size(), last, null);
+                e = new Entry(content, map.size(), null, first);
                 if (first == null) {
                     last = e;
                 } else {

File jurt/prj/build.lst

 ju	jurt\source\pipe			nmake	-	all	ju_src_pipe NULL
 ju  jurt\source\pipe\wrapper nmake - w ju_src_pipe_wrapper NULL
 ju	jurt\util								nmake	-	all	ju_ut ju_brid_jrm ju_co_bfactr ju_con ju_con_sock ju_con_pipe ju_cssl_uno ju_env_java ju_prot_urp ju_servman ju_urlres ju_src_pipe ju_libutil ju_uno NULL
+ju jurt\test\com\sun\star\lib\uno\protocols\urp nmake - all ju_test_css_lib_uno_protocols_urp NULL

File jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java

 
 package com.sun.star.lib.uno.protocols.urp;
 
-import complexlib.ComplexTestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
 
-public final class Cache_Test extends ComplexTestCase {
-    public String[] getTestMethodNames() {
-        return new String[] { "test0", "test1", "test2", "test3" };
-    }
-
-    public void test0() {
+public final class Cache_Test {
+    @Test public void test0() {
         Cache c = new Cache(0);
         boolean[] f = new boolean[1];
         int i;
         i = c.add(f, "a");
-        assure("1", i == Cache.NOT_CACHED && !f[0]);
+        assertTrue(i == Cache.NOT_CACHED && !f[0]);
         i = c.add(f, "a");
-        assure("2", i == Cache.NOT_CACHED && !f[0]);
+        assertTrue(i == Cache.NOT_CACHED && !f[0]);
         i = c.add(f, "b");
-        assure("3", i == Cache.NOT_CACHED && !f[0]);
+        assertTrue(i == Cache.NOT_CACHED && !f[0]);
         i = c.add(f, "a");
-        assure("4", i == Cache.NOT_CACHED && !f[0]);
+        assertTrue(i == Cache.NOT_CACHED && !f[0]);
     }
 
-    public void test1() {
+    @Test public void test1() {
         Cache c = new Cache(1);
         boolean[] f = new boolean[1];
         int i;
         i = c.add(f, "a");
-        assure("1", i == 0 && !f[0]);
+        assertTrue(i == 0 && !f[0]);
         i = c.add(f, "a");
-        assure("2", i == 0 && f[0]);
+        assertTrue(i == 0 && f[0]);
         i = c.add(f, "b");
-        assure("3", i == 0 && !f[0]);
+        assertTrue(i == 0 && !f[0]);
         i = c.add(f, "b");
-        assure("4", i == 0 && f[0]);
+        assertTrue(i == 0 && f[0]);
         i = c.add(f, "a");
-        assure("5", i == 0 && !f[0]);
+        assertTrue(i == 0 && !f[0]);
     }
 
-    public void test2() {
+    @Test public void test2() {
         Cache c = new Cache(2);
         boolean[] f = new boolean[1];
         int i;
         i = c.add(f, "a");
-        assure("1", i == 0 && !f[0]);
+        assertTrue(i == 0 && !f[0]);
         i = c.add(f, "a");
-        assure("2", i == 0 && f[0]);
+        assertTrue(i == 0 && f[0]);
         i = c.add(f, "b");
-        assure("3", i == 1 && !f[0]);
+        assertTrue(i == 1 && !f[0]);
         i = c.add(f, "b");
-        assure("4", i == 1 && f[0]);
+        assertTrue(i == 1 && f[0]);
         i = c.add(f, "a");
-        assure("5", i == 0 && f[0]);
+        assertTrue(i == 0 && f[0]);
         i = c.add(f, "c");
-        assure("6", i == 1 && !f[0]);
+        assertTrue(i == 1 && !f[0]);
         i = c.add(f, "b");
-        assure("7", i == 0 && !f[0]);
+        assertTrue(i == 0 && !f[0]);
     }
 
-    public void test3() {
+    @Test public void test3() {
         Cache c = new Cache(3);
         boolean[] f = new boolean[1];
         int i;
         i = c.add(f, "a");
-        assure("1", i == 0 && !f[0]);
+        assertTrue(i == 0 && !f[0]);
         i = c.add(f, "a");
-        assure("3", i == 0 && f[0]);
+        assertTrue(i == 0 && f[0]);
         i = c.add(f, "b");
-        assure("5", i == 1 && !f[0]);
+        assertTrue(i == 1 && !f[0]);
         i = c.add(f, "a");
-        assure("3", i == 0 && f[0]);
+        assertTrue(i == 0 && f[0]);
         i = c.add(f, "c");
-        assure("7", i == 2 && !f[0]);
+        assertTrue(i == 2 && !f[0]);
         i = c.add(f, "d");
-        assure("9", i == 1 && !f[0]);
+        assertTrue(i == 1 && !f[0]);
         i = c.add(f, "d");
-        assure("11", i == 1 && f[0]);
+        assertTrue(i == 1 && f[0]);
+    }
+
+    @Test public void testNothingLostFromLruList() {
+        // Regardless in what order arbitrary values from 0, ..., 3 are inserted
+        // into a size-4 cache, afterwards adding -1, ..., -4 must return each
+        // possible index in the range from 0, ..., 3 exactly once (so their sum
+        // must be 6); this code systematically tests all such arbitrary ways up
+        // to length 8 (the code arguably violates recommendations for writing
+        // good tests, but actually helped track down an error in the Cache
+        // implementation):
+        int[] a = new int[8];
+        for (int i = 0; i < a.length; ++i) {
+            for (int j = 0; j < i; ++j) {
+                a[j] = 0;
+            }
+            for (;;) {
+                Cache c = new Cache(4);
+                for (int k = 0; k < i; ++k) {
+                    c.add(new boolean[1], a[k]);
+                }
+                assertEquals(
+                    6,
+                    (c.add(new boolean[1], -1) + c.add(new boolean[1], -2) +
+                     c.add(new boolean[1], -3) + c.add(new boolean[1], -4)));
+                int j = i - 1;
+                while (j >= 0 && a[j] == 3) {
+                    --j;
+                }
+                if (j < 0) {
+                    break;
+                }
+                ++a[j];
+                for (int k = j + 1; k < i; ++k) {
+                    a[k] = 0;
+                }
+            }
+        }
     }
 }

File jurt/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test.java

 import com.sun.star.uno.Type;
 import com.sun.star.uno.TypeClass;
 import com.sun.star.uno.XInterface;
-import complexlib.ComplexTestCase;
 import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import org.junit.Test;
+import static org.junit.Assert.*;
 
-public final class Marshaling_Test extends ComplexTestCase {
-    public String getTestObjectName() {
-        return getClass().getName();
-    }
-
-    public String[] getTestMethodNames() {
-        return new String[] { "test" };
-    }
-
-    public void test() throws Exception {
+public final class Marshaling_Test {
+    @Test public void test() throws Exception {
         short cacheSize = (short)256;
         TestBridge testBridge = new TestBridge();
         Marshal marshal = new Marshal(testBridge, cacheSize);
             if(op1 instanceof Any)
                 op1 = ((Any)op1).getObject();
 
-            assure("", compareObjects(op1, op2));
+            assertTrue(compareObjects(op1, op2));
         }
     }
 

File jurt/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java

 import com.sun.star.uno.IBridge;
 import com.sun.star.uno.Type;
 import com.sun.star.uno.XInterface;
-import complexlib.ComplexTestCase;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
 import java.util.LinkedList;
+import org.junit.Test;
+import static org.junit.Assert.*;
 
-public final class Protocol_Test extends ComplexTestCase {
-    public String[] getTestMethodNames() {
-        return new String[] { "test" };
-    }
-
-    public void test() throws Exception {
+public final class Protocol_Test {
+    @Test public void test() throws Exception {
         IBridge iBridge = new TestBridge();
         PipedInputStream inA = new PipedInputStream();
         PipedOutputStream outA = new PipedOutputStream(inA);
             new Object[] { "hallo" });
         Message iMessage = iReceiver.readMessage();
         Object[] t_params = iMessage.getArguments();
-        assure("", "hallo".equals((String)t_params[0]));
+        assertEquals("hallo", (String)t_params[0]);
 
         // send a reply
         iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null);
         iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null);
         iSender.readMessage();
 
-        assure("", "testString".equals(((String [])params[0])[0]));
+        assertEquals("testString", ((String [])params[0])[0]);
     }
 
     public void testCallWithInOutParameter(
 
 
         Object[] t_params = iMessage.getArguments();
-        assure("", "inString".equals(((String [])t_params[0])[0]));
+        assertEquals("inString", ((String [])t_params[0])[0]);
 
         // provide reply
         ((String [])t_params[0])[0] = "outString";
         iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null);
         iSender.readMessage();
 
-        assure("", "outString".equals(((String [])params[0])[0]));
+        assertEquals("outString", ((String [])params[0])[0]);
     }
 
     public void testCallWithResult(
         Message iMessage = iSender.readMessage();
         Object result = iMessage.getResult();
 
-        assure("", "resultString".equals(result));
+        assertEquals("resultString", result);
     }
 
     public void testCallWhichRaisesException(
 
         Object result = iMessage.getResult();
 
-        assure("", result instanceof com.sun.star.uno.RuntimeException);
+        assertTrue(result instanceof com.sun.star.uno.RuntimeException);
     }
 
     public void testCallWithIn_Out_InOut_Paramters_and_result(
 
         Object[] t_params = iMessage.getArguments();
 
-        assure("", "hallo".equals((String)t_params[0]));
+        assertEquals("hallo", (String)t_params[0]);
 
-        assure("", "inOutString".equals(((String [])t_params[2])[0]));
+        assertEquals("inOutString", ((String [])t_params[2])[0]);
 
         ((String [])t_params[1])[0] = "outString";
         ((String [])t_params[2])[0] = "inOutString_res";
         iMessage = iSender.readMessage();
 
         Object result = iMessage.getResult();
-        assure("", "outString".equals(((String [])params[1])[0]));
+        assertEquals("outString", ((String [])params[1])[0]);
 
-        assure("", "inOutString_res".equals(((String [])params[2])[0]));
+        assertEquals("inOutString_res", ((String [])params[2])[0]);
 
-        assure("", "resultString".equals(result));
+        assertEquals("resultString", result);
     }
 
     public void testCallWhichReturnsAny(
             false, new ThreadId(new byte[] { 0, 1 }), Any.VOID);
         Message iMessage = iSender.readMessage();
         Object result = iMessage.getResult();
-        assure("", result instanceof Any
-               && (TypeDescription.getTypeDescription(((Any) result).getType()).
-                   getZClass() == void.class));
+        assertTrue(
+            result instanceof Any &&
+            ((TypeDescription.getTypeDescription(((Any) result).getType()).
+              getZClass()) ==
+             void.class));
 
         // send an ordinary request
         iSender.writeRequest(
             new Any(XInterface.class, null));
         iMessage = iSender.readMessage();
         result = iMessage.getResult();
-        assure("", result == null);
+        assertNull(result);
 
         // send an ordinary request
         iSender.writeRequest(
             false, new ThreadId(new byte[] { 0, 1 }), new Integer(501));
         iMessage = iSender.readMessage();
         result = iMessage.getResult();
-        assure("", result.equals(new Integer(501)));
+        assertEquals(501, result);
     }
 
     private static final class Endpoint {

File jurt/test/com/sun/star/lib/uno/protocols/urp/makefile.mk

 # for a copy of the LGPLv3 License.
 #
 #*************************************************************************
+
+.IF "$(OOO_SUBSEQUENT_TESTS)" == ""
+nothing .PHONY:
+.ELSE
+
 PRJ := ..$/..$/..$/..$/..$/..$/..$/..
 PRJNAME := jurt
 TARGET := test_com_sun_star_lib_uno_protocols_urp
 
+.IF "$(OOO_JUNIT_JAR)" != ""
 PACKAGE := com$/sun$/star$/lib$/uno$/protocols$/urp
 JAVATESTFILES := \
     Cache_Test.java \
     TestObject.java
 JARFILES := ridl.jar
 IDLTESTFILES := interfaces.idl
+.END
 
 .INCLUDE: javaunittest.mk
+
+.END

File solenv/inc/javaunittest.mk

 # <platform>/class/, so that they are not accidentally included in jar files
 # packed from <platform>/class/ subdirectories.
 
-TESTS := $(subst,.java,.test $(JAVATESTFILES))
 JAVAFILES +:= $(JAVATESTFILES)
-JARFILES +:= OOoRunner.jar
+EXTRAJARFILES += $(OOO_JUNIT_JAR)
 
 .INCLUDE: settings.mk
 
 
 .INCLUDE: target.mk
 
-ALLTAR: $(TESTS)
-
-$(JAVAFILES): $(MISC)/$(TARGET).classdir.flag
+$(JAVATARGET) : $(MISC)/$(TARGET).classdir.flag
 
 $(MISC)/$(TARGET).classdir.flag:
     - $(MKDIR) $(CLASSDIR)
     $(TOUCH) $@
 
-.IF "$(TESTS)" != ""
-$(TESTS): $(JAVACLASSFILES)
-.ENDIF
+.IF "$(JAVATESTFILES)" != ""
+ALLTAR : test
+.END
 
-%.test .PHONY: %.java
-    $(JAVAI) $(JAVAIFLAGS) $(JAVACPS) $(CLASSPATH) org.openoffice.Runner \
-        -TestBase java_complex -NoOffice yes \
-        -o $(subst,/,. $(subst,.test, $(PACKAGE).$@))
+.IF "$(SOLAR_JAVA)" == "TRUE" && "$(OOO_JUNIT_JAR)" != ""
+test .PHONY : $(JAVATARGET)
+    $(JAVAI) $(JAVAIFLAGS) $(JAVACPS) \
+        '$(OOO_JUNIT_JAR)$(PATH_SEPERATOR)$(CLASSPATH)' \
+        org.junit.runner.JUnitCore \
+        $(foreach,i,$(JAVATESTFILES) $(subst,/,. $(PACKAGE)).$(i:s/.java//))
+.ELSE
+test .PHONY :
+    echo 'test needs SOLAR_JAVA=TRUE and OOO_JUNIT_JAR'
+.END
 
 .IF "$(IDLTESTFILES)" != ""