Home | History | Annotate | Download | only in EventModifiers
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  */
     18 
     19 package org.apache.harmony.jpda.tests.jdwp.EventModifiers;
     20 
     21 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     22 import org.apache.harmony.jpda.tests.share.SyncDebuggee;
     23 
     24 /**
     25  * Debuggee for InstanceOnlyModifierTest.
     26  */
     27 public class InstanceOnlyModifierDebuggee extends SyncDebuggee {
     28     static class TestException extends Exception {
     29     }
     30 
     31     static class TestClass {
     32         int watchedField = 0;
     33 
     34         public void eventTestMethod() {
     35             System.out.println(
     36                     "InstanceOnlyModifierDebuggee.TestClass.eventTestMethod()");
     37         }
     38 
     39         public void throwAndCatchException() {
     40             try {
     41                 throwException();
     42             } catch (TestException e) {
     43                 System.out.println("Catch TestException");
     44             }
     45         }
     46 
     47         public void readAndWriteField() {
     48             System.out.println(
     49                     "InstanceOnlyModifierDebuggee.TestClass.readAndWriteField()");
     50             watchedField = watchedField + 1;
     51         }
     52 
     53         private void throwException() throws TestException {
     54             System.out.println(
     55                     "InstanceOnlyModifierDebuggee.TestClass.throwException()");
     56             throw new TestException();
     57         }
     58     }
     59 
     60     static TestClass INSTANCE_ONLY;
     61 
     62     @SuppressWarnings("DeadException")
     63     @Override
     64     public void run() {
     65         new TestException();  // force class loading.
     66 
     67         logWriter.println("Create instances");
     68         final TestClass[] instances = new TestClass[10];
     69         for (int i = 0; i < instances.length; ++i) {
     70             instances[i] = new TestClass();
     71         }
     72 
     73         System.out.println("Set INSTANCE_ONLY to the last instance");
     74         INSTANCE_ONLY = instances[instances.length - 1];
     75         System.out.println("Set INSTANCE_ONLY to the last instance");
     76 
     77         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     78 
     79         logWriter.println("InstanceOnlyModifierDebuggee started");
     80 
     81         // Wait for test setup.
     82         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     83 
     84         System.out.println("Fire breakpoint, method entry/exit events");
     85         for (int i = 0; i < instances.length; ++i) {
     86             instances[i].eventTestMethod();
     87         }
     88 
     89         System.out.println("Fire caught exception events");
     90         for (int i = 0; i < instances.length; ++i) {
     91             instances[i].throwAndCatchException();
     92         }
     93 
     94         System.out.println("Fire field access/modification events");
     95         for (int i = 0; i < instances.length; ++i) {
     96             instances[i].readAndWriteField();
     97         }
     98 
     99         logWriter.println("InstanceOnlyModifierDebuggee finished");
    100     }
    101 
    102     public static void main(String[] args) {
    103         runDebuggee(InstanceOnlyModifierDebuggee.class);
    104     }
    105 
    106 }
    107