Search in sources :

Example 1 with HashElement

use of com.oracle.truffle.api.debug.test.TestHashObject.HashElement in project graal by oracle.

the class DebugValueHashMapTest method testHashInsertable.

@Test
public void testHashInsertable() throws Throwable {
    Map<HashElement, Object> map = TestHashObject.createTestMap();
    Object hash = new TestHashObject(map, true);
    checkDebugValueOf(hash, value -> {
        assertTrue(value.hasHashEntries());
        assertEquals(8, value.getHashSize());
        DebuggerSession s = value.getSession();
        DebugValue v10 = s.createPrimitiveValue(10, null);
        checkHashEntry(value, v10, true, true, true, true, false, true);
        // Insert a new entry <42, 420>
        DebugValue v42 = s.createPrimitiveValue(42, null);
        checkHashEntry(value, v42, false, false, true, false, true, false);
        value.putHashEntry(v42, s.createPrimitiveValue(420, null));
        checkHashEntry(value, v42, true, true, true, true, false, true);
        assertEquals(9, value.getHashSize());
        // Remove an existing entry
        DebugValue v20 = s.createPrimitiveValue(20, null);
        assertTrue(value.removeHashEntry(v20));
        assertEquals(8, value.getHashSize());
        DebugValue iterator = value.getHashKeysIterator();
        DebugValueIteratorTest.checkIntIterator(iterator, Arrays.asList(10, 30, 40, 50, 60, 70, 80, 42));
    });
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) HashElement(com.oracle.truffle.api.debug.test.TestHashObject.HashElement) Test(org.junit.Test)

Example 2 with HashElement

use of com.oracle.truffle.api.debug.test.TestHashObject.HashElement in project graal by oracle.

the class DebugValueHashMapTest method testHashRWEntries.

@Test
public void testHashRWEntries() throws Throwable {
    Map<HashElement, Object> map = TestHashObject.createTestMap();
    Object hash = new TestHashObject(map, false);
    checkDebugValueOf(hash, value -> {
        assertEquals(8, value.getHashSize());
        DebuggerSession s = value.getSession();
        DebugValue v10 = s.createPrimitiveValue(10, null);
        DebugValue v20 = s.createPrimitiveValue(20, null);
        DebugValue v30 = s.createPrimitiveValue(30, null);
        DebugValue v40 = s.createPrimitiveValue(40, null);
        DebugValue v50 = s.createPrimitiveValue(50, null);
        DebugValue v60 = s.createPrimitiveValue(60, null);
        DebugValue v70 = s.createPrimitiveValue(70, null);
        DebugValue v80 = s.createPrimitiveValue(80, null);
        checkHashEntry(value, v10, true, true, true, true, false, true);
        checkHashEntry(value, v20, true, true, false, false, false, true);
        checkHashEntry(value, v30, true, true, true, true, false, false);
        checkHashEntry(value, v40, true, true, false, false, false, false);
        checkHashEntry(value, v50, true, false, true, true, false, true);
        checkHashEntry(value, v60, true, false, false, false, false, true);
        checkHashEntry(value, v70, true, false, true, true, false, false);
        checkHashEntry(value, v80, false, false, false, false, false, false);
        assertEquals(100, value.getHashValue(v10).asInt());
        assertEquals(400, value.getHashValue(v40).asInt());
        assertEquals(400, value.getHashValueOrDefault(v40, v10).asInt());
        assertEquals(null, value.getHashValue(v50));
        assertEquals(10, value.getHashValueOrDefault(v50, v10).asInt());
        DebugValue v42 = s.createPrimitiveValue(42, null);
        assertEquals(null, value.getHashValue(v42));
        assertEquals(v42, value.getHashValueOrDefault(value, v42));
        DebugValue iterator = value.getHashKeysIterator();
        DebugValueIteratorTest.checkIntIterator(iterator, Arrays.asList(10, 20, 30, 40, 50, 60, 70, 80));
        iterator = value.getHashValuesIterator();
        DebugValueIteratorTest.checkIntIterator(iterator, Arrays.asList(100, 200, 300, 400), true);
        // Entries iterator:
        iterator = value.getHashEntriesIterator();
        checkIntEntriesIterator(iterator, map.entrySet());
    });
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) HashElement(com.oracle.truffle.api.debug.test.TestHashObject.HashElement) Test(org.junit.Test)

Example 3 with HashElement

use of com.oracle.truffle.api.debug.test.TestHashObject.HashElement in project graal by oracle.

the class DebugValueHashMapTest method checkIntEntriesIterator.

static void checkIntEntriesIterator(DebugValue iterator, Collection<Map.Entry<HashElement, Object>> entries) {
    assertTrue(iterator.isIterator());
    // it's not iterable
    assertFalse(iterator.hasIterator());
    try {
        iterator.getIterator();
        fail();
    } catch (DebugException ex) {
    // O.K.
    }
    for (Map.Entry<HashElement, Object> entry : entries) {
        assertTrue(iterator.hasIteratorNextElement());
        DebugValue entryArray = iterator.getIteratorNextElement();
        assertTrue(entryArray.isArray());
        List<DebugValue> array = entryArray.getArray();
        assertEquals(2, array.size());
        DebugValue key = array.get(0);
        DebugValue value = array.get(1);
        assertTrue(key.isReadable());
        assertEquals(entry.getKey().isRemovable(), key.isWritable());
        assertEquals(entry.getKey().getKey(), key.asInt());
        assertEquals(entry.getKey().isReadable(), value.isReadable());
        assertEquals(entry.getKey().isWritable(), value.isWritable());
        if (entry.getKey().isReadable()) {
            assertEquals(entry.getValue(), value.asInt());
        } else {
            try {
                value.asInt();
                fail();
            } catch (UnsupportedOperationException ex) {
            // O.K.
            }
        }
    }
    assertFalse(iterator.hasIteratorNextElement());
    try {
        iterator.getIteratorNextElement();
        fail();
    } catch (NoSuchElementException ex) {
    // O.K.
    }
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue) HashElement(com.oracle.truffle.api.debug.test.TestHashObject.HashElement) DebugException(com.oracle.truffle.api.debug.DebugException) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

DebugValue (com.oracle.truffle.api.debug.DebugValue)3 HashElement (com.oracle.truffle.api.debug.test.TestHashObject.HashElement)3 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)2 Test (org.junit.Test)2 DebugException (com.oracle.truffle.api.debug.DebugException)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1