ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ReentrantReadWriteLockTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ReentrantReadWriteLockTest.java (file contents):
Revision 1.17 by dl, Thu Jan 8 01:29:46 2004 UTC vs.
Revision 1.18 by dl, Sat Jan 10 01:41:59 2004 UTC

# Line 1224 | Line 1224 | public class ReentrantReadWriteLockTest
1224          }
1225      }
1226  
1227 +    /**
1228 +     * toString indicates current lock state
1229 +     */
1230 +    public void testToString() {
1231 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1232 +        String us = lock.toString();
1233 +        assertTrue(us.indexOf("Write locks = 0") >= 0);
1234 +        assertTrue(us.indexOf("Read locks = 0") >= 0);
1235 +        lock.writeLock().lock();
1236 +        String ws = lock.toString();
1237 +        assertTrue(ws.indexOf("Write locks = 1") >= 0);
1238 +        assertTrue(ws.indexOf("Read locks = 0") >= 0);
1239 +        lock.writeLock().unlock();
1240 +        lock.readLock().lock();
1241 +        lock.readLock().lock();
1242 +        String rs = lock.toString();
1243 +        assertTrue(rs.indexOf("Write locks = 0") >= 0);
1244 +        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1245 +    }
1246 +
1247 +    /**
1248 +     * readLock.toString indicates current lock state
1249 +     */
1250 +    public void testReadLockToString() {
1251 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1252 +        String us = lock.readLock().toString();
1253 +        assertTrue(us.indexOf("Read locks = 0") >= 0);
1254 +        lock.readLock().lock();
1255 +        lock.readLock().lock();
1256 +        String rs = lock.readLock().toString();
1257 +        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1258 +    }
1259 +
1260 +    /**
1261 +     * writeLock.toString indicates current lock state
1262 +     */
1263 +    public void testWriteLockToString() {
1264 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1265 +        String us = lock.writeLock().toString();
1266 +        assertTrue(us.indexOf("Unlocked") >= 0);
1267 +        lock.writeLock().lock();
1268 +        String ls = lock.writeLock().toString();
1269 +        assertTrue(ls.indexOf("Locked") >= 0);
1270 +    }
1271 +
1272   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines