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 8743 2012-10-07 03:06:20Z schulte $
032 */
033public class MemoryManagerTest extends RuntimeTest
034{
035    //--MemoryManagerTest-------------------------------------------------------
036
037    /** Implementation to test. */
038    private MemoryManager manager;
039
040    /** Creates a new {@code MemoryManagerTest} instance. */
041    public MemoryManagerTest()
042    {
043        super();
044    }
045
046    /**
047     * Gets the {@code MemoryManager} implementation tests are performed with.
048     *
049     * @return the {@code MemoryManager} implementation tests are performed
050     * with.
051     */
052    public MemoryManager getMemoryManager()
053    {
054        return this.manager;
055    }
056
057    /**
058     * Sets the {@code MemoryManager} implementation tests are performed with.
059     *
060     * @param value the {@code MemoryManager} implementation to perform tests
061     * with.
062     */
063    public final void setMemoryManager( final MemoryManager value )
064    {
065        this.manager = value;
066        this.setRuntime( value );
067    }
068
069    //-------------------------------------------------------MemoryManagerTest--
070    //--Tests-------------------------------------------------------------------
071
072    /**
073     * Tests the {@link MemoryManager#allocateBytes(int) acclocateXxx()} methods
074     * to handle illegal arguments correctly.
075     */
076    public void testIllegalArguments() throws Exception
077    {
078        assert this.getMemoryManager() != null;
079
080        try
081        {
082            this.getMemoryManager().allocateBoolean( Integer.MIN_VALUE );
083            throw new AssertionError();
084        }
085        catch ( final IllegalArgumentException e )
086        {
087            Assert.assertNotNull( e.getMessage() );
088            System.out.println( e.toString() );
089        }
090
091        try
092        {
093            this.getMemoryManager().allocateBytes( Integer.MIN_VALUE );
094            throw new AssertionError();
095        }
096        catch ( final IllegalArgumentException e )
097        {
098            Assert.assertNotNull( e.getMessage() );
099            System.out.println( e.toString() );
100        }
101
102        try
103        {
104            this.getMemoryManager().allocateChars( Integer.MIN_VALUE );
105            throw new AssertionError();
106        }
107        catch ( final IllegalArgumentException e )
108        {
109            Assert.assertNotNull( e.getMessage() );
110            System.out.println( e.toString() );
111        }
112
113        try
114        {
115            this.getMemoryManager().allocateDoubles( Integer.MIN_VALUE );
116            throw new AssertionError();
117        }
118        catch ( final IllegalArgumentException e )
119        {
120            Assert.assertNotNull( e.getMessage() );
121            System.out.println( e.toString() );
122        }
123
124        try
125        {
126            this.getMemoryManager().allocateFloats( Integer.MIN_VALUE );
127            throw new AssertionError();
128        }
129        catch ( final IllegalArgumentException e )
130        {
131            Assert.assertNotNull( e.getMessage() );
132            System.out.println( e.toString() );
133        }
134
135        try
136        {
137            this.getMemoryManager().allocateIntegers( Integer.MIN_VALUE );
138            throw new AssertionError();
139        }
140        catch ( final IllegalArgumentException e )
141        {
142            Assert.assertNotNull( e.getMessage() );
143            System.out.println( e.toString() );
144        }
145
146        try
147        {
148            this.getMemoryManager().allocateLongs( Integer.MIN_VALUE );
149            throw new AssertionError();
150        }
151        catch ( final IllegalArgumentException e )
152        {
153            Assert.assertNotNull( e.getMessage() );
154            System.out.println( e.toString() );
155        }
156
157        try
158        {
159            this.getMemoryManager().allocateShorts( Integer.MIN_VALUE );
160            throw new AssertionError();
161        }
162        catch ( final IllegalArgumentException e )
163        {
164            Assert.assertNotNull( e.getMessage() );
165            System.out.println( e.toString() );
166        }
167
168    }
169
170    //-------------------------------------------------------------------Tests--
171}