<commit_before>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library 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 any later version.
 *
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://www.inria.fr/oasis/ProActive/contacts.html
 *  Contributor(s):
 *
 * ################################################################
 */
package nonregressiontest.activeobject.generics;

import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
import org.objectweb.proactive.core.group.Group;
import org.objectweb.proactive.core.group.ProActiveGroup;
import org.objectweb.proactive.core.util.wrapper.IntWrapper;
import org.objectweb.proactive.core.util.wrapper.StringWrapper;

import testsuite.test.Assertions;
import testsuite.test.FunctionalTest;


/**
 * Checks that ProActive correctly handles generics.
 *
 * 1. Stubs on generic return types are correctly typed with the parameterizing type.
 * 2. Groups correctly handle generics, including for reifiable parameterizing return types.
 *
 *
 * @author <NAME>
 */
public class Test extends FunctionalTest {
    ProActiveDescriptor descriptor;

    public Test() {
        super("Generic types", "Generic types");
    }

    /**
     * @see testsuite.test.FunctionalTest#action()
     */
    public void action() throws Exception {

    	
    	// new active with reifiable parameter types
    	// test before non reifiable return types to verify caching of synchronous/asynchrous method calls 
    	// works fine with parameterized types
        Pair<StringWrapper, IntWrapper> b = (Pair<StringWrapper, IntWrapper>) ProActive.newActive(Pair.class.getName(),
                new Class[] { StringWrapper.class, IntWrapper.class },
                new Object[] { new StringWrapper("toto"), new IntWrapper(12) });
        Assertions.assertTrue(StringWrapper.class.isAssignableFrom(
                b.getFirst().getClass()));
        Assertions.assertTrue(IntWrapper.class.isAssignableFrom(
                b.getSecond().getClass()));
        Assertions.assertEquals("toto", b.getFirst().stringValue());
        Assertions.assertEquals(12, b.getSecond().intValue());

        
    	// new active with non reifiable parameter types
        Pair<String, Integer> a = (Pair<String, Integer>) ProActive.newActive(Pair.class.getName(),
                new Class[] { String.class, Integer.class },
                new Object[] { "A", 42 });
        Assertions.assertTrue(String.class.isAssignableFrom(
                a.getFirst().getClass()));
        Assertions.assertTrue(Integer.class.isAssignableFrom(
                a.getSecond().getClass()));
        Assertions.assertEquals("A", a.getFirst());
        Assertions.assertEquals(42, a.getSecond());

        
        // turn active
        Pair<Integer, String> pair = new Pair<Integer, String>(42, "X");
        Assertions.assertEquals(42, pair.getFirst());
        Assertions.assertEquals("X", pair.getSecond());

        Pair<Integer, String> activePair = (Pair<Integer, String>)ProActive.turnActive(pair, new Class[] {Integer.class, String.class});
        Assertions.assertTrue(Integer.class.isAssignableFrom(
        		activePair.getFirst().getClass()));
        Assertions.assertTrue(String.class.isAssignableFrom(
        		activePair.getSecond().getClass()));
        Assertions.assertEquals(42, activePair.getFirst());
        Assertions.assertEquals("X", activePair.getSecond());
        

        
        // new active group with reifiable parameter types
        Pair<StringWrapper, IntWrapper> gb = (Pair<StringWrapper, IntWrapper>) ProActiveGroup.newGroup(Pair.class.getName(),
                new Class[] { StringWrapper.class, IntWrapper.class },
                new Object[][] {
                    { new StringWrapper("A"), new IntWrapper(1) },
                    { new StringWrapper("B"), new IntWrapper(2) }
                });
        Assertions.assertTrue(StringWrapper.class.isAssignableFrom(
                gb.getFirst().getClass()));
        Assertions.assertTrue(IntWrapper.class.isAssignableFrom(
                gb.getSecond().getClass()));

        StringWrapper stringWrapperResult = gb.getFirst();
        Group stringWrapperResultGroup = ProActiveGroup.getGroup(stringWrapperResult);
        IntWrapper intWrapperResult = gb.getSecond();
        Group intWrapperResultGroup = ProActiveGroup.getGroup(intWrapperResult);

        Assertions.assertEquals(new StringWrapper("A"),
            stringWrapperResultGroup.get(0));
        Assertions.assertEquals(new StringWrapper("B"),
            stringWrapperResultGroup.get(1));
        Assertions.assertEquals(new IntWrapper(1), intWrapperResultGroup.get(0));
        Assertions.assertEquals(new IntWrapper(2), intWrapperResultGroup.get(1));

        
        // new active group with non reifiable parameter types (which is not allowed with groups)
        boolean invocationTargetException = false;
        Pair<String, Integer> ga = (Pair<String, Integer>) ProActiveGroup.newGroup(Pair.class.getName(),
                new Class[] { String.class, Integer.class },
                new Object[][] {
                    { "A", 1 },
                    { "B", 2 }
                });
        try {
            // verify this invocation is not possible
            ga.getFirst();
        } catch (Throwable e) {
            invocationTargetException = true;
        }
        Assertions.assertTrue(invocationTargetException);
    }

    /**
     * @see testsuite.test.AbstractTest#initTest()
     */
    public void initTest() throws Exception {
    }

    /**
     * @see testsuite.test.AbstractTest#endTest()
     */
    public void endTest() throws Exception {
    }

    public boolean postConditions() throws Exception {
        return true;
    }

    public static void main(String[] args) {
        Test test = new Test();
        try {
            test.action();
            if (test.postConditions()) {
                System.out.println("TEST SUCCEEDED");
            } else {
                System.out.println("TEST FAILED");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}<commit_msg>update and extends nonregression tests on reified classes generation<commit_after>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library 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 any later version.
 *
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://www.inria.fr/oasis/ProActive/contacts.html
 *  Contributor(s):
 *
 * ################################################################
 */
package nonregressiontest.activeobject.generics;

import java.util.Arrays;

import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
import org.objectweb.proactive.core.group.Group;
import org.objectweb.proactive.core.group.ProActiveGroup;
import org.objectweb.proactive.core.mop.Utils;
import org.objectweb.proactive.core.util.wrapper.IntWrapper;
import org.objectweb.proactive.core.util.wrapper.StringWrapper;

import testsuite.test.Assertions;
import testsuite.test.FunctionalTest;


/**
 * Checks that ProActive correctly handles generics.
 *
 * 1. Stubs on generic return types are correctly typed with the parameterizing type.
 * 2. Groups correctly handle generics, including for reifiable parameterizing return types.
 *
 *
 * @author <NAME>
 */
public class Test extends FunctionalTest {
    ProActiveDescriptor descriptor;

    public Test() {
        super("Generic types", "Generic types");
    }

    /**
     * @see testsuite.test.FunctionalTest#action()
     */
    public void action() throws Exception {
        //      new active with '_' in classname of a parametized type.
        //pa.stub.parameterized.nonregressiontest.activeobject.generics.Stub_Pair_Generics_[nonregressiontest_activeobject_generics_My_Type5org_objectweb_proactive_core_util_wrapper_IntWrapper]
        Pair<My_DType, IntWrapper> p_ = (Pair<My_DType, IntWrapper>) ProActive.newActive(Pair.class.getName(),
                new Class[] { My_DType.class, IntWrapper.class },
                new Object[] { new My_DType("toto"), new IntWrapper(12) });
        Assertions.assertTrue(My_DType.class.isAssignableFrom(
                p_.getFirst().getClass()));
        Assertions.assertTrue(IntWrapper.class.isAssignableFrom(
                p_.getSecond().getClass()));
        Assertions.assertEquals("toto", p_.getFirst().toString());
        Assertions.assertEquals(12, p_.getSecond().intValue());

        // new active with reifiable parameter types
        // test before non reifiable return types to verify caching of synchronous/asynchrous method calls 
        // works fine with parameterized types
        Pair<StringWrapper, IntWrapper> b = (Pair<StringWrapper, IntWrapper>) ProActive.newActive(Pair.class.getName(),
                new Class[] { StringWrapper.class, IntWrapper.class },
                new Object[] { new StringWrapper("toto"), new IntWrapper(12) });
        Assertions.assertTrue(StringWrapper.class.isAssignableFrom(
                b.getFirst().getClass()));
        Assertions.assertTrue(IntWrapper.class.isAssignableFrom(
                b.getSecond().getClass()));
        Assertions.assertEquals("toto", b.getFirst().stringValue());
        Assertions.assertEquals(12, b.getSecond().intValue());

        // new active with non reifiable parameter types
        Pair<String, Integer> a = (Pair<String, Integer>) ProActive.newActive(Pair.class.getName(),
                new Class[] { String.class, Integer.class },
                new Object[] { "A", 42 });
        Assertions.assertTrue(String.class.isAssignableFrom(
                a.getFirst().getClass()));
        Assertions.assertTrue(Integer.class.isAssignableFrom(
                a.getSecond().getClass()));
        Assertions.assertEquals("A", a.getFirst());
        Assertions.assertEquals(42, a.getSecond());

        // turn active
        Pair<Integer, String> pair = new Pair<Integer, String>(42, "X");
        Assertions.assertEquals(42, pair.getFirst());
        Assertions.assertEquals("X", pair.getSecond());

        Pair<Integer, String> activePair = (Pair<Integer, String>) ProActive.turnActive(pair,
                new Class[] { Integer.class, String.class });
        Assertions.assertTrue(Integer.class.isAssignableFrom(
                activePair.getFirst().getClass()));
        Assertions.assertTrue(String.class.isAssignableFrom(
                activePair.getSecond().getClass()));
        Assertions.assertEquals(42, activePair.getFirst());
        Assertions.assertEquals("X", activePair.getSecond());

        // new active group with reifiable parameter types
        Pair<StringWrapper, IntWrapper> gb = (Pair<StringWrapper, IntWrapper>) ProActiveGroup.newGroup(Pair.class.getName(),
                new Class[] { StringWrapper.class, IntWrapper.class },
                new Object[][] {
                    { new StringWrapper("A"), new IntWrapper(1) },
                    { new StringWrapper("B"), new IntWrapper(2) }
                });
        Assertions.assertTrue(StringWrapper.class.isAssignableFrom(
                gb.getFirst().getClass()));
        Assertions.assertTrue(IntWrapper.class.isAssignableFrom(
                gb.getSecond().getClass()));

        StringWrapper stringWrapperResult = gb.getFirst();
        Group stringWrapperResultGroup = ProActiveGroup.getGroup(stringWrapperResult);
        IntWrapper intWrapperResult = gb.getSecond();
        Group intWrapperResultGroup = ProActiveGroup.getGroup(intWrapperResult);

        Assertions.assertEquals(new StringWrapper("A"),
            stringWrapperResultGroup.get(0));
        Assertions.assertEquals(new StringWrapper("B"),
            stringWrapperResultGroup.get(1));
        Assertions.assertEquals(new IntWrapper(1), intWrapperResultGroup.get(0));
        Assertions.assertEquals(new IntWrapper(2), intWrapperResultGroup.get(1));

        // new active group with non reifiable parameter types (which is not allowed with groups)
        boolean invocationTargetException = false;
        Pair<String, Integer> ga = (Pair<String, Integer>) ProActiveGroup.newGroup(Pair.class.getName(),
                new Class[] { String.class, Integer.class },
                new Object[][] {
                    { "A", 1 },
                    { "B", 2 }
                });
        try {
            // verify this invocation is not possible
            ga.getFirst();
        } catch (Throwable e) {
            invocationTargetException = true;
        }
        Assertions.assertTrue(invocationTargetException);

        // test name escaping with generics, main test are done in nonregressiontest.stub.stubgeneration
        Assertions.assertEquals("pa.stub._StubMy__P__DType",
            Utils.convertClassNameToStubClassName("My_P_DType", new Class[] {  }));
        String escape = Utils.convertClassNameToStubClassName(Pair.class.getName(),
                new Class[] { My_DType.class, IntWrapper.class });
        Assertions.assertEquals(escape,
            "pa.stub.parameterized.nonregressiontest.activeobject.generics._StubPair_Genericsnonregressiontest_Pactiveobject_Pgenerics_PMy__DType_Dorg_Pobjectweb_Pproactive_Pcore_Putil_Pwrapper_PIntWrapper");

        String[] unescape = Utils.getNamesOfParameterizingTypesFromStubClassName(escape);
        String[] result = new String[] {
                "nonregressiontest.activeobject.generics.My_DType",
                "org.objectweb.proactive.core.util.wrapper.IntWrapper"
            };
        Assertions.assertTrue(Arrays.equals(unescape, result));
    }

    /**
     * @see testsuite.test.AbstractTest#initTest()
     */
    public void initTest() throws Exception {
    }

    /**
     * @see testsuite.test.AbstractTest#endTest()
     */
    public void endTest() throws Exception {
    }

    public boolean postConditions() throws Exception {
        return true;
    }

    public static void main(String[] args) {
        Test test = new Test();
        try {
            test.initTest();
            test.action();
            if (test.postConditions()) {
                System.out.println("TEST SUCCEEDED");
            } else {
                System.out.println("TEST FAILED");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                test.endTest();
                System.exit(0);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.1211641500243546, 'fraction_numerical': 0.006575742815392109, 'mean_word_length': 2.7517131110095936, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1082311', 'n_tokens_mistral': 4338, 'n_tokens_neox': 4174, 'n_words': 1021}