gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] storm/org/nongnu/storm BlockId.java BlockId.test


From: Tuukka Hastrup
Subject: [Gzz-commits] storm/org/nongnu/storm BlockId.java BlockId.test
Date: Fri, 25 Apr 2003 08:46:34 -0400

CVSROOT:        /cvsroot/storm
Module name:    storm
Changes by:     Tuukka Hastrup <address@hidden> 03/04/25 08:46:34

Modified files:
        org/nongnu/storm: BlockId.java BlockId.test 

Log message:
        more content type tests

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/BlockId.java.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/BlockId.test.diff?tr1=1.10&tr2=1.11&r1=text&r2=text

Patches:
Index: storm/org/nongnu/storm/BlockId.java
diff -u storm/org/nongnu/storm/BlockId.java:1.13 
storm/org/nongnu/storm/BlockId.java:1.14
--- storm/org/nongnu/storm/BlockId.java:1.13    Wed Apr 23 13:27:47 2003
+++ storm/org/nongnu/storm/BlockId.java Fri Apr 25 08:46:34 2003
@@ -170,9 +170,16 @@
        if(s.equals("")) return;
        
        s = s.toLowerCase();
-       int slash = s.indexOf('/');
-       if(s.substring(slash+1, slash+3).equals("x-") ||
-          s.substring(slash+1, slash+3).equals("x."))
+       int slash = s.indexOf('/'); 
+       if(slash == -1 ||               // There must be a slash,
+          s.lastIndexOf('/') != slash) // and only one slash
+           throw new IllegalArgumentException("Content type must have "+
+                                              "exactly 1 slash");
+       if(slash == 0 || slash == s.length()-1)
+           throw new IllegalArgumentException("Content type must have two "+
+                                              "non-empty parts");
+       if(s.substring(slash+1).startsWith("x-") ||
+          s.substring(slash+1).startsWith("x."))
            throw new IllegalArgumentException("x- and x. content types "
                                               + "not allowed in "
                                               + "Storm URNs");
Index: storm/org/nongnu/storm/BlockId.test
diff -u storm/org/nongnu/storm/BlockId.test:1.10 
storm/org/nongnu/storm/BlockId.test:1.11
--- storm/org/nongnu/storm/BlockId.test:1.10    Wed Apr 23 13:27:47 2003
+++ storm/org/nongnu/storm/BlockId.test Fri Apr 25 08:46:34 2003
@@ -40,6 +40,9 @@
 lower_3 = uri_3.lower()
 data_3 = 1025 * 'A'
 
+contenttest = ("urn:x-storm:1.0:%s,"
+               "u7uu5zpmkoeykkwhxd4unlqycc36gvl7."
+               "jtlcbiy2r6gfsznbgj42yzqbqk4ti373bqs5qyy")
 
 def testConstructor():
     id = BlockId(uri_1)
@@ -84,15 +87,40 @@
     else: assert 0
 # XXX test other wrong lengths too
 
+def testContentType():
+    """Malformed content types must throw exceptions"""
+
+    BlockId(contenttest % 'text/html')
+    BlockId(contenttest % 'a/a')
+    BlockId(contenttest % 'x/x')
+
+    try: BlockId(contenttest % '/html')
+    except java.lang.IllegalArgumentException: pass
+    else: assert 0
+
+    try: BlockId(contenttest % 'text/')
+    except java.lang.IllegalArgumentException: pass
+    else: assert 0
+
+    try: BlockId(contenttest % '/')
+    except java.lang.IllegalArgumentException: pass
+    else: assert 0
+
+    try: BlockId(contenttest % 'text/html/myextension')
+    except java.lang.IllegalArgumentException: pass
+    else: assert 0
+
+    try: BlockId(contenttest % 'mytype')
+    except java.lang.IllegalArgumentException: pass
+    else: assert 0
+
+
 def testSpaces():
     """Spaces in content types must throw exceptions"""
-    str = ("urn:x-storm:1.0:%s,"
-           "u7uu5zpmkoeykkwhxd4unlqycc36gvl7."
-           "jtlcbiy2r6gfsznbgj42yzqbqk4ti373bqs5qyy")
 
-    BlockId(str % 'text/plain;charset=UTF-8')
+    BlockId(contenttest % 'text/plain;charset=UTF-8')
 
-    try: BlockId(str % 'text/plain; charset=UTF-8')
+    try: BlockId(contenttest % 'text/plain; charset=UTF-8')
     except java.lang.IllegalArgumentException: pass
     else: assert 0
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]