##############################################################################
# JBoss, Home of Professional Open Source
# Copyright 2009, Red Hat and individual contributors
# by the @authors tag. See the copyright.txt in the distribution for a
# full listing of individual contributors.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
#
# @authors Andrew Dinn
#

RULE test array declarations and accesses
CLASS TestArray
METHOD triggerMethod1(int[], Object[][])
HELPER org.jboss.byteman.tests.helpers.Default
AFTER CALL log
BIND test : Test = $0;
     iarray : int[] = $1;
     oarray : Object[][] = $2;
     iarray2 : int[] = { 1, 2, 3};
     oarray2 : Object[] = { $0, $1, $2 };
     oarray3 : int[][] = { $1 };
     mtarray1 :Object[] = {};
     mtarray2 : int[] = {};
     nested : Object[][] = { new Object[] { "foo" } , new Object[] { "bar" } };
     nested2 : Object[][] = { { "foo" }, { "bar" } }
IF TRUE
DO test.log("triggerMethod1 : iarray[0] == " + iarray[0]);
   test.log("triggerMethod1 : oarray[0][0] == " + oarray[0][0]);
   test.log( "triggerMethod1 : iarray2[0] == " +  iarray2[0]);
   test.log( "triggerMethod1 : oarray2[1] == " +  oarray2[1]);
   test.log( "triggerMethod1 : oarray3[0][0] == " +  oarray3[0][0]);
   test.log( "triggerMethod1 : mtarray1.length == " +  mtarray1.length);
   test.log( "triggerMethod1 : mtarray2.length == " +  mtarray2.length);
   test.log( "triggerMethod1 : nested.length == " + nested.length);
   test.log( "triggerMethod1 : nested[0].length == " + nested[0].length);
   test.log( "triggerMethod1 : nested[1].length == " + nested[1].length);
   test.log( "triggerMethod1 : nested[0][0] == " + nested[0][0]);
   test.log( "triggerMethod1 : nested[1][0] == " + nested[1][0]);
   test.log( "triggerMethod1 : nested2.length == " + nested2.length);
   test.log( "triggerMethod1 : nested2[0].length == " + nested2[0].length);
   test.log( "triggerMethod1 : nested2[1].length == " + nested2[1].length);
   test.log( "triggerMethod1 : nested2[0][0] == " + nested2[0][0]);
   test.log( "triggerMethod1 : nested2[1][0] == " + nested2[1][0]);
   # at present nested arrays may have different dimensions -- fixme?
   nested2 = new Object[][][]  { { { 1 } }, { { 2 } }, { {}, {} }, { } };
   test.log( "triggerMethod1 : nested2.length == " + nested2.length);
   test.log( "triggerMethod1 : nested2[0].length == " + nested2[0].length);
   test.log( "triggerMethod1 : nested2[1].length == " + nested2[1].length);
   test.log( "triggerMethod1 : nested2[2].length == " + nested2[2].length);
   test.log( "triggerMethod1 : nested2[3].length == " + nested2[3].length);
   return oarray[0]
ENDRULE

RULE test array length and array updates
CLASS TestArray
METHOD triggerMethod2(int[], Object[][])
HELPER org.jboss.byteman.tests.helpers.Default
AFTER CALL log
BIND test : Test = $0;
     iarray : int[] = $1;
     oarray : Object[][] = $2;
     l : int = oarray[0].length
IF TRUE
DO test.log("triggerMethod2 : iarray.length == " + iarray.length);
   test.log("triggerMethod2 : oarray[0].length == " + l);
   test.log("triggerMethod2 : oarray[0][" + (l - 1) + "] == " + oarray[0][l - 1]);
   oarray[0][l - 1] = "goodbye";
ENDRULE

