1 | /* |
2 | * jDTAUS Core Test Suite |
3 | * Copyright (C) 2005 Christian Schulte |
4 | * <cs@schulte.it> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2.1 of the License, or any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this library; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * |
20 | */ |
21 | package org.jdtaus.core.lang.spi.it; |
22 | |
23 | import junit.framework.Assert; |
24 | import org.jdtaus.core.lang.it.RuntimeTest; |
25 | import org.jdtaus.core.lang.spi.MemoryManager; |
26 | |
27 | /** |
28 | * Testcase for {@code MemoryManager} implementations. |
29 | * |
30 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
31 | * @version $JDTAUS: MemoryManagerTest.java 8743 2012-10-07 03:06:20Z schulte $ |
32 | */ |
33 | public class MemoryManagerTest extends RuntimeTest |
34 | { |
35 | //--MemoryManagerTest------------------------------------------------------- |
36 | |
37 | /** Implementation to test. */ |
38 | private MemoryManager manager; |
39 | |
40 | /** Creates a new {@code MemoryManagerTest} instance. */ |
41 | public MemoryManagerTest() |
42 | { |
43 | super(); |
44 | } |
45 | |
46 | /** |
47 | * Gets the {@code MemoryManager} implementation tests are performed with. |
48 | * |
49 | * @return the {@code MemoryManager} implementation tests are performed |
50 | * with. |
51 | */ |
52 | public MemoryManager getMemoryManager() |
53 | { |
54 | return this.manager; |
55 | } |
56 | |
57 | /** |
58 | * Sets the {@code MemoryManager} implementation tests are performed with. |
59 | * |
60 | * @param value the {@code MemoryManager} implementation to perform tests |
61 | * with. |
62 | */ |
63 | public final void setMemoryManager( final MemoryManager value ) |
64 | { |
65 | this.manager = value; |
66 | this.setRuntime( value ); |
67 | } |
68 | |
69 | //-------------------------------------------------------MemoryManagerTest-- |
70 | //--Tests------------------------------------------------------------------- |
71 | |
72 | /** |
73 | * Tests the {@link MemoryManager#allocateBytes(int) acclocateXxx()} methods |
74 | * to handle illegal arguments correctly. |
75 | */ |
76 | public void testIllegalArguments() throws Exception |
77 | { |
78 | assert this.getMemoryManager() != null; |
79 | |
80 | try |
81 | { |
82 | this.getMemoryManager().allocateBoolean( Integer.MIN_VALUE ); |
83 | throw new AssertionError(); |
84 | } |
85 | catch ( final IllegalArgumentException e ) |
86 | { |
87 | Assert.assertNotNull( e.getMessage() ); |
88 | System.out.println( e.toString() ); |
89 | } |
90 | |
91 | try |
92 | { |
93 | this.getMemoryManager().allocateBytes( Integer.MIN_VALUE ); |
94 | throw new AssertionError(); |
95 | } |
96 | catch ( final IllegalArgumentException e ) |
97 | { |
98 | Assert.assertNotNull( e.getMessage() ); |
99 | 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 | } |