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 8641 2012-09-27 06:45:17Z schulte $ |
32 | */ |
33 | public class MemoryManagerTest extends RuntimeTest |
34 | { |
35 | //--MemoryManagerTest------------------------------------------------------- |
36 | |
37 | /** Implementation to test. */ |
38 | private MemoryManager manager; |
39 | |
40 | /** |
41 | * Gets the {@code MemoryManager} implementation tests are performed with. |
42 | * |
43 | * @return the {@code MemoryManager} implementation tests are performed |
44 | * with. |
45 | */ |
46 | public MemoryManager getMemoryManager() |
47 | { |
48 | return this.manager; |
49 | } |
50 | |
51 | /** |
52 | * Sets the {@code MemoryManager} implementation tests are performed with. |
53 | * |
54 | * @param value the {@code MemoryManager} implementation to perform tests |
55 | * with. |
56 | */ |
57 | public final void setMemoryManager( final MemoryManager value ) |
58 | { |
59 | this.manager = value; |
60 | this.setRuntime( value ); |
61 | } |
62 | |
63 | //-------------------------------------------------------MemoryManagerTest-- |
64 | //--Tests------------------------------------------------------------------- |
65 | |
66 | /** |
67 | * Tests the {@link MemoryManager#allocateBytes(int) acclocateXxx()} methods |
68 | * to handle illegal arguments correctly. |
69 | */ |
70 | public void testIllegalArguments() throws Exception |
71 | { |
72 | assert this.getMemoryManager() != null; |
73 | |
74 | try |
75 | { |
76 | this.getMemoryManager().allocateBoolean( Integer.MIN_VALUE ); |
77 | throw new AssertionError(); |
78 | } |
79 | catch ( IllegalArgumentException e ) |
80 | { |
81 | Assert.assertNotNull( e.getMessage() ); |
82 | System.out.println( e.toString() ); |
83 | } |
84 | |
85 | try |
86 | { |
87 | this.getMemoryManager().allocateBytes( Integer.MIN_VALUE ); |
88 | throw new AssertionError(); |
89 | } |
90 | catch ( IllegalArgumentException e ) |
91 | { |
92 | Assert.assertNotNull( e.getMessage() ); |
93 | System.out.println( e.toString() ); |
94 | } |
95 | |
96 | try |
97 | { |
98 | this.getMemoryManager().allocateChars( Integer.MIN_VALUE ); |
99 | 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 | } |