13df0c797781000302737ead55196b6e110d8db9cSebastien Hertz/*
23df0c797781000302737ead55196b6e110d8db9cSebastien Hertz * Licensed to the Apache Software Foundation (ASF) under one or more
33df0c797781000302737ead55196b6e110d8db9cSebastien Hertz * contributor license agreements.  See the NOTICE file distributed with
43df0c797781000302737ead55196b6e110d8db9cSebastien Hertz * this work for additional information regarding copyright ownership.
53df0c797781000302737ead55196b6e110d8db9cSebastien Hertz * The ASF licenses this file to You under the Apache License, Version 2.0
63df0c797781000302737ead55196b6e110d8db9cSebastien Hertz * (the "License"); you may not use this file except in compliance with
73df0c797781000302737ead55196b6e110d8db9cSebastien Hertz * the License.  You may obtain a copy of the License at
83df0c797781000302737ead55196b6e110d8db9cSebastien Hertz *
93df0c797781000302737ead55196b6e110d8db9cSebastien Hertz *     http://www.apache.org/licenses/LICENSE-2.0
103df0c797781000302737ead55196b6e110d8db9cSebastien Hertz *
113df0c797781000302737ead55196b6e110d8db9cSebastien Hertz *  Unless required by applicable law or agreed to in writing, software
123df0c797781000302737ead55196b6e110d8db9cSebastien Hertz *  distributed under the License is distributed on an "AS IS" BASIS,
133df0c797781000302737ead55196b6e110d8db9cSebastien Hertz *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
143df0c797781000302737ead55196b6e110d8db9cSebastien Hertz *
153df0c797781000302737ead55196b6e110d8db9cSebastien Hertz *  See the License for the specific language governing permissions and
163df0c797781000302737ead55196b6e110d8db9cSebastien Hertz *  limitations under the License.
173df0c797781000302737ead55196b6e110d8db9cSebastien Hertz */
183df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
193df0c797781000302737ead55196b6e110d8db9cSebastien Hertzpackage org.apache.harmony.jpda.tests.jdwp.EventModifiers;
203df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
213df0c797781000302737ead55196b6e110d8db9cSebastien Hertzimport org.apache.harmony.jpda.tests.framework.Breakpoint;
223df0c797781000302737ead55196b6e110d8db9cSebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.Event;
233df0c797781000302737ead55196b6e110d8db9cSebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.EventBuilder;
243df0c797781000302737ead55196b6e110d8db9cSebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
253df0c797781000302737ead55196b6e110d8db9cSebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.Value;
263df0c797781000302737ead55196b6e110d8db9cSebastien Hertzimport org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
273df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
283df0c797781000302737ead55196b6e110d8db9cSebastien Hertz/**
293df0c797781000302737ead55196b6e110d8db9cSebastien Hertz * JDWP Unit test for Count event modifier.
303df0c797781000302737ead55196b6e110d8db9cSebastien Hertz */
313df0c797781000302737ead55196b6e110d8db9cSebastien Hertzpublic class CountModifierTest extends JDWPEventModifierTestCase {
323df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private static final
333df0c797781000302737ead55196b6e110d8db9cSebastien Hertz            String DEBUGGEE_SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/EventModifiers/CountModifierDebuggee;";
343df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private static final
353df0c797781000302737ead55196b6e110d8db9cSebastien Hertz            String TEST_CLASS_SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/EventModifiers/CountModifierDebuggee$TestClass;";
363df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private static final
373df0c797781000302737ead55196b6e110d8db9cSebastien Hertz            String TEST_CLASS_NAME = "org.apache.harmony.jpda.tests.jdwp.EventModifiers.CountModifierDebuggee$TestClass";
383df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private static final
393df0c797781000302737ead55196b6e110d8db9cSebastien Hertz            String EXCEPTION_SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/EventModifiers/CountModifierDebuggee$TestException;";
403df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
413df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    // The name of the test method where we set our event requests.
423df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private static final String METHOD_NAME = "eventTestMethod";
433df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
443df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    // The name of the test method where we set our event requests.
453df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private static final String WATCHED_FIELD_NAME = "watchedField";
463df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
473df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    // Fields for verifying events count.
483df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private static final String
493df0c797781000302737ead55196b6e110d8db9cSebastien Hertz            LOCATION_COUNT_FIELD_NAME = "locationEventCount";
503df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private static final String
513df0c797781000302737ead55196b6e110d8db9cSebastien Hertz            EXCEPTION_EVENT_COUNT_FIELD_NAME = "exceptionEventCount";
523df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private static final String
533df0c797781000302737ead55196b6e110d8db9cSebastien Hertz            FIELD_READ_WRITE_COUNT_FIELD_NAME = "fieldReadWriteCount";
543df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
553df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    @Override
563df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    protected String getDebuggeeClassName() {
573df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        return CountModifierDebuggee.class.getName();
583df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
593df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
603df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    /**
613df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * This testcase is for BREAKPOINT event with Count modifier.
623df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>It runs CountModifierDebuggee and sets BREAKPOINT to its
633df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee.TestClass#eventTestMethod()} method.
643df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>Then calls this method multiple times and verifies that requested
653df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * BREAKPOINT event occurs once after having called the method (count - 1)
663df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * times. We check this by looking at the value in the field
673df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee#locationEventCount}.
683df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     */
693df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    public void testBreakpoint() {
703df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testBreakpoint started");
713df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
723df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
733df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
743df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        // Breakpoint at start of test method.
753df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        byte typeTag = JDWPConstants.TypeTag.CLASS;
763df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        Breakpoint breakpoint = new Breakpoint(TEST_CLASS_SIGNATURE,
773df0c797781000302737ead55196b6e110d8db9cSebastien Hertz                METHOD_NAME, 0);
783df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        EventBuilder builder = createBreakpointEventBuilder(typeTag,
793df0c797781000302737ead55196b6e110d8db9cSebastien Hertz                breakpoint);
803df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        testEventWithCountModifier(builder, LOCATION_COUNT_FIELD_NAME);
813df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
823df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testBreakpoint done");
833df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
843df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
853df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    /**
863df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * This testcase is for METHOD_ENTRY event with Count modifier.
873df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>It runs CountModifierDebuggee and sets METHOD_ENTRY to the
883df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee.TestClass} class.
893df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>Then calls {@link CountModifierDebuggee.TestClass#eventTestMethod()}
903df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * method multiple times and verifies that requested METHOD_ENTRY event
913df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * occurs once after having called the method (count - 1) times. We check
923df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * this by looking at the value in the field
933df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee#locationEventCount}.
943df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     */
953df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    public void testMethodEntry() {
963df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testMethodEntry started");
973df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
983df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
993df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        EventBuilder builder = createMethodEntryEventBuilder(TEST_CLASS_NAME);
1003df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        testEventWithCountModifier(builder, LOCATION_COUNT_FIELD_NAME);
1013df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1023df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testMethodEntry done");
1033df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
1043df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1053df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    /**
1063df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * This testcase is for METHOD_EXIT event with Count modifier.
1073df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>It runs CountModifierDebuggee and sets METHOD_EXIT to the
1083df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee.TestClass} class.
1093df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>Then calls {@link CountModifierDebuggee.TestClass#eventTestMethod()}
1103df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * method multiple times and verifies that requested METHOD_EXIT event
1113df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * occurs once after having called the method (count - 1) times. We check
1123df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * this by looking at the value in the field
1133df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee#locationEventCount}.
1143df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     */
1153df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    public void testMethodExit() {
1163df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testMethodExit started");
1173df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1183df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
1193df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        EventBuilder builder = createMethodExitEventBuilder(TEST_CLASS_NAME);
1203df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        testEventWithCountModifier(builder, LOCATION_COUNT_FIELD_NAME);
1213df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1223df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testMethodExit done");
1233df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
1243df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1253df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1263df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    /**
1273df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * This testcase is for METHOD_EXIT_WITH_RETURN_VALUE event with Count
1283df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * modifier.
1293df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>It runs CountModifierDebuggee and sets METHOD_EXIT_WITH_RETURN_VALUE
1303df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * to the {@link CountModifierDebuggee.TestClass} class.
1313df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>Then calls {@link CountModifierDebuggee.TestClass#eventTestMethod()}
1323df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * method multiple times and verifies that requested
1333df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * METHOD_EXIT_WITH_RETURN_VALUE event occurs once after having called the
1343df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * method (count - 1) times. We check this by looking at the value in the
1353df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * field {@link CountModifierDebuggee#locationEventCount}.
1363df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     */
1373df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    public void testMethodExitWithReturnValue() {
1383df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testMethodExitWithReturnValue started");
1393df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1403df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
1413df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        EventBuilder builder = createMethodExitWithReturnValueEventBuilder(TEST_CLASS_NAME);
1423df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        testEventWithCountModifier(builder, LOCATION_COUNT_FIELD_NAME);
1433df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1443df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testMethodExitWithReturnValue done");
1453df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
1463df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1473df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    /**
1483df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * This testcase is for EXCEPTION event with Count modifier.
1493df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>It runs CountModifierDebuggee and sets EXCEPTION to the
1503df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee.TestException} class but only for caught
1513df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * exceptions.
1523df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>Then calls {@link CountModifierDebuggee.TestClass#throwException}
1533df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * method multiple times and verifies that requested EXCEPTION event
1543df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * occurs once after having called the method (count - 1) times. We check
1553df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * this by looking at the value in the field
1563df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee#exceptionEventCount}.
1573df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     */
1583df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    public void testException() {
1593df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testException started");
1603df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1613df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
1623df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        EventBuilder builder = createExceptionEventBuilder(EXCEPTION_SIGNATURE,
1633df0c797781000302737ead55196b6e110d8db9cSebastien Hertz                true, false);
1643df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        testEventWithCountModifier(builder,
1653df0c797781000302737ead55196b6e110d8db9cSebastien Hertz                EXCEPTION_EVENT_COUNT_FIELD_NAME);
1663df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1673df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testException done");
1683df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
1693df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1703df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    /**
1713df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * This testcase is for FIELD_ACCESS event with Count modifier.
1723df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>It runs CountModifierDebuggee and requests FIELD_ACCESS event for
1733df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee#watchedField}.
1743df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>Then calls {@link CountModifierDebuggee#readAndWriteField()}
1753df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * method multiple times and verifies that requested FIELD_ACCESS event
1763df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * occurs once after having called the method (count - 1) times. We check
1773df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * this by looking at the value in the field
1783df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee#fieldReadWriteCount}.
1793df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>Note: if the VM does not support the canWatchFieldAccess capability,
1803df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * the test succeeds.
1813df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     */
1823df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    public void testFieldAccess() {
1833df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testFieldAccess started");
1843df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1853df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
1863df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1873df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        EventBuilder builder = createFieldAccessEventBuilder(
1883df0c797781000302737ead55196b6e110d8db9cSebastien Hertz                JDWPConstants.TypeTag.CLASS, DEBUGGEE_SIGNATURE,
1893df0c797781000302737ead55196b6e110d8db9cSebastien Hertz                WATCHED_FIELD_NAME);
1903df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        testEventWithCountModifier(builder, FIELD_READ_WRITE_COUNT_FIELD_NAME);
1913df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1923df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testFieldAccess done");
1933df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
1943df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
1953df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    /**
1963df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * This testcase is for FIELD_MODIFICATION event with Count modifier.
1973df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>It runs CountModifierDebuggee and requests FIELD_MODIFICATION event
1983df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * for {@link CountModifierDebuggee#watchedField}.
1993df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>Then calls {@link CountModifierDebuggee#readAndWriteField()}
2003df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * method multiple times and verifies that requested FIELD_MODIFICATION
2013df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * event occurs once after having called the method (count - 1) times. We
2023df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * check this by looking at the value in the field
2033df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * {@link CountModifierDebuggee#fieldReadWriteCount}.
2043df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * <BR>Note: if the VM does not support the canWatchFieldModification
2053df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     * capability, the test succeeds.
2063df0c797781000302737ead55196b6e110d8db9cSebastien Hertz     */
2073df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    public void testFieldModification() {
2083df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testFieldModification started");
2093df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
2103df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
2113df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
2123df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        EventBuilder builder = createFieldModificationEventBuilder(
2133df0c797781000302737ead55196b6e110d8db9cSebastien Hertz                JDWPConstants.TypeTag.CLASS, DEBUGGEE_SIGNATURE,
2143df0c797781000302737ead55196b6e110d8db9cSebastien Hertz                WATCHED_FIELD_NAME);
2153df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        testEventWithCountModifier(builder, FIELD_READ_WRITE_COUNT_FIELD_NAME);
2163df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
2173df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        logWriter.println("testFieldModification done");
2183df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
2193df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
2203df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private void testEventWithCountModifier(EventBuilder builder,
2213df0c797781000302737ead55196b6e110d8db9cSebastien Hertz            String countFieldName) {
2223df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        // Add count modifier and build the event.
2233df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        builder.setCount(CountModifierDebuggee.EVENT_COUNT);
2243df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        Event event = builder.build();
2253df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        int requestID = requestEvent(event);
2263df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
2273df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        waitForEvent(event.eventKind, requestID);
2283df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
2293df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        // Check we properly ignore the (count - 1) previous events.
2303df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        int expectedCount = CountModifierDebuggee.EVENT_COUNT;
2313df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        int actualCount = getStaticIntField(DEBUGGEE_SIGNATURE, countFieldName);
2323df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        assertEquals("Invalid event count", expectedCount, actualCount);
2333df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
2343df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        clearAndResume(event.eventKind, requestID);
2353df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
2363df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
2373df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    private int getStaticIntField(String classSignature, String fieldName) {
2383df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        Value fieldValue = getFieldValue(classSignature, fieldName);
2393df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        assertEquals("Invalid field value tag", JDWPConstants.Tag.INT_TAG,
2403df0c797781000302737ead55196b6e110d8db9cSebastien Hertz                fieldValue.getTag());
2413df0c797781000302737ead55196b6e110d8db9cSebastien Hertz        return fieldValue.getIntValue();
2423df0c797781000302737ead55196b6e110d8db9cSebastien Hertz    }
2433df0c797781000302737ead55196b6e110d8db9cSebastien Hertz
2443df0c797781000302737ead55196b6e110d8db9cSebastien Hertz}
245