File: getElem.java

package info (click to toggle)
mauve 20120103-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 28,504 kB
  • sloc: java: 250,155; sh: 2,834; xml: 208; makefile: 66
file content (198 lines) | stat: -rw-r--r-- 5,035 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Tags: JDK1.2

// Copyright (C) 2004 Sascha Brawer <brawer@dandelis.ch>

// This file is part of Mauve.

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve 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 General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

package gnu.testlet.java.awt.image.DataBufferShort;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.image.DataBuffer;
import java.awt.image.DataBufferShort;


/**
 * @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
 */
public class getElem
  implements Testlet
{
  public void test(TestHarness h)
  {
    DataBuffer buf;
    short[] data = new short[] { -11, -22, -33, -44 };
    
    buf = new DataBufferShort(new short[][] { data, data }, 2,
                              new int[] { 2, 0 });

    h.check(buf.getElem(0), -33);    // Check #1.
    h.check(buf.getElem(1), -44);    // Check #2.
    h.check(buf.getElem(0, 0), -33); // Check #3.
    h.check(buf.getElem(0, 1), -44); // Check #4.
    h.check(buf.getElem(1, 0), -11); // Check #5.
    h.check(buf.getElem(1, 1), -22); // Check #6.
    
    // new tests added by David Gilbert
    testGetElem1(h);
    testGetElem2(h);
    
  }
  
  private void testGetElem1(TestHarness harness) 
  {
    harness.checkPoint("getElem(int)");  
      
    // test where supplied array is bigger than 'size'
    short[] source = new short[] {1, 2, 3};
    DataBufferShort b = new DataBufferShort(source, 2);
    harness.check(b.getElem(0) == 1);
    harness.check(b.getElem(1) == 2);
    harness.check(b.getElem(2) == 3);
    
    boolean pass = false;
    try
    {
      b.getElem(-1);
    }
    catch (ArrayIndexOutOfBoundsException e) 
    {
      pass = true;
    }
    harness.check(pass);
    
    pass = false;
    try
    {
      b.getElem(3);
    }
    catch (ArrayIndexOutOfBoundsException e) 
    {
      pass = true;
    }
    harness.check(pass);
    
    // test where offsets are specified
    source = new short[] {1, 2, 3, 4};
    b = new DataBufferShort(source, 2, 1);
    harness.check(b.getElem(-1) == 1);
    harness.check(b.getElem(0) == 2);
    harness.check(b.getElem(1) == 3);
    harness.check(b.getElem(2) == 4);

    pass = false;
    try
    {
      b.getElem(3);
    }
    catch (ArrayIndexOutOfBoundsException e) 
    {
      pass = true;
    }
    harness.check(pass);

    pass = false;
    try
    {
      b.getElem(-2);
    }
    catch (ArrayIndexOutOfBoundsException e) 
    {
      pass = true;
    }
    harness.check(pass);
  }

  private void testGetElem2(TestHarness harness) {
    harness.checkPoint("getElem(int, int)");  
    
    short[][] source = new short[][] {{1, 2}, {3, 4}};
    DataBufferShort b = new DataBufferShort(source, 2);
    harness.check(b.getElem(1, 0) == 3);
    harness.check(b.getElem(1, 1) == 4);
    
    // test where supplied array is bigger than 'size'
    source = new short[][] {{1, 2, 3}, {4, 5, 6}};
    b = new DataBufferShort(source, 2);
    harness.check(b.getElem(1, 2) == 6);
      
    // test where offsets are specified
    source = new short[][] {{1, 2, 3, 4}, {5, 6, 7, 8}};
    b = new DataBufferShort(source, 2, new int[] {1, 2});
    harness.check(b.getElem(1, -2) == 5);
    harness.check(b.getElem(1, -1) == 6);
    harness.check(b.getElem(1, 0) == 7);
    harness.check(b.getElem(1, 1) == 8);
       
    // does a change to the source affect the DataBuffer? Yes
    source[1][2] = 99;
    harness.check(source[1][2] == 99);
    harness.check(b.getElem(1, 0) == 99);
        
    // test when the bank index is out of bounds
    boolean pass = true;
    try
    {
      b.getElem(-1, 0);
    }
    catch (ArrayIndexOutOfBoundsException e) 
    {
      pass = true;
    }
    harness.check(pass);
        
    pass = false;
    try 
    {
      b.getElem(2, 0);
    }
    catch (ArrayIndexOutOfBoundsException e) 
    {
      pass = true;
    }
    harness.check(pass);
    
    // test when the item index is out of bounds
    pass = true;
    try
    {
      b.getElem(0, -2);
    }
    catch (ArrayIndexOutOfBoundsException e) 
    {
      pass = true;
    }
    harness.check(pass);
        
    pass = false;
    try 
    {
      b.getElem(1, 5);
    }
    catch (ArrayIndexOutOfBoundsException e) 
    {
      pass = true;
    }
    harness.check(pass);
    
    // the array of arrays should reflect the single dimension array
    DataBufferShort b2 = new DataBufferShort(new short[] {1, 2, 3}, 3);
    harness.check(b2.getElem(0, 1) == 2);
  }
}