001/*
002 *  jDTAUS Core Test Suite
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.core.lang.spi.it;
022
023import junit.framework.Assert;
024import org.jdtaus.core.lang.it.RuntimeTest;
025import org.jdtaus.core.lang.spi.MemoryManager;
026
027/**
028 * Testcase for {@code MemoryManager} implementations.
029 *
030 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
031 * @version $JDTAUS: MemoryManagerTest.java 8641 2012-09-27 06:45:17Z schulte $
032 */
033public class MemoryManagerTest extends RuntimeTest
034{
035    //--MemoryManagerTest-------------------------------------------------------
036
037    /** Implementation to test. */
038    private MemoryManager manager;
039
040    /**
041     * Gets the {@code MemoryManager} implementation tests are performed with.
042     *
043     * @return the {@code MemoryManager} implementation tests are performed
044     * with.
045     */
046    public MemoryManager getMemoryManager()
047    {
048        return this.manager;
049    }
050
051    /**
052     * Sets the {@code MemoryManager} implementation tests are performed with.
053     *
054     * @param value the {@code MemoryManager} implementation to perform tests
055     * with.
056     */
057    public final void setMemoryManager( final MemoryManager value )
058    {
059        this.manager = value;
060        this.setRuntime( value );
061    }
062
063    //-------------------------------------------------------MemoryManagerTest--
064    //--Tests-------------------------------------------------------------------
065
066    /**
067     * Tests the {@link MemoryManager#allocateBytes(int) acclocateXxx()} methods
068     * to handle illegal arguments correctly.
069     */
070    public void testIllegalArguments() throws Exception
071    {
072        assert this.getMemoryManager() != null;
073
074        try
075        {
076            this.getMemoryManager().allocateBoolean( Integer.MIN_VALUE );
077            throw new AssertionError();
078        }
079        catch ( IllegalArgumentException e )
080        {
081            Assert.assertNotNull( e.getMessage() );
082            System.out.println( e.toString() );
083        }
084
085        try
086        {
087            this.getMemoryManager().allocateBytes( Integer.MIN_VALUE );
088            throw new AssertionError();
089        }
090        catch ( IllegalArgumentException e )
091        {
092            Assert.assertNotNull( e.getMessage() );
093            System.out.println( e.toString() );
094        }
095
096        try
097        {
098            this.getMemoryManager().allocateChars( Integer.MIN_VALUE );
099            throw new AssertionError();
100        }
101        catch ( IllegalArgumentException e )
102        {
103            Assert.assertNotNull( e.getMessage() );
104            System.out.println( e.toString() );
105        }
106
107        try
108        {
109            this.getMemoryManager().allocateDoubles( Integer.MIN_VALUE );
110            throw new AssertionError();
111        }
112        catch ( IllegalArgumentException e )
113        {
114            Assert.assertNotNull( e.getMessage() );
115            System.out.println( e.toString() );
116        }
117
118        try
119        {
120            this.getMemoryManager().allocateFloats( Integer.MIN_VALUE );
121            throw new AssertionError();
122        }
123        catch ( IllegalArgumentException e )
124        {
125            Assert.assertNotNull( e.getMessage() );
126            System.out.println( e.toString() );
127        }
128
129        try
130        {
131            this.getMemoryManager().allocateIntegers( Integer.MIN_VALUE );
132            throw new AssertionError();
133        }
134        catch ( IllegalArgumentException e )
135        {
136            Assert.assertNotNull( e.getMessage() );
137            System.out.println( e.toString() );
138        }
139
140        try
141        {
142            this.getMemoryManager().allocateLongs( Integer.MIN_VALUE );
143            throw new AssertionError();
144        }
145        catch ( IllegalArgumentException e )
146        {
147            Assert.assertNotNull( e.getMessage() );
148            System.out.println( e.toString() );
149        }
150
151        try
152        {
153            this.getMemoryManager().allocateShorts( Integer.MIN_VALUE );
154            throw new AssertionError();
155        }
156        catch ( IllegalArgumentException e )
157        {
158            Assert.assertNotNull( e.getMessage() );
159            System.out.println( e.toString() );
160        }
161
162    }
163
164    //-------------------------------------------------------------------Tests--
165}