aboutsummaryrefslogtreecommitdiff
path: root/gnu/testlet/java/awt/image/ComponentSampleModel/setSample.java
blob: e051655eb320faa9739795a4197424ec3edf296c (plain)
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
/* setSample.java -- some checks for the setSample() method in the
       ComponentSampleModel class.
   Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.com>
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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

*/

// Tags: JDK1.4

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

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

import java.awt.image.ComponentSampleModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.DataBufferDouble;
import java.awt.image.DataBufferFloat;
import java.awt.image.DataBufferInt;

public class setSample implements Testlet
{
  public void test(TestHarness harness)
  {
    test1(harness);
    test2(harness);
    test3(harness);
  }
  
  private void test1(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, double, DataBuffer)");  
    DataBuffer db = new DataBufferDouble(12);
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE,
            3, 2, 2, 6, new int[] {0, 1});
    m.setSample(2, 1, 0, 99.9, db);
    harness.check(db.getElem(0, 10), 99.0d);
    m.setSample(2, 1, 1, 88.8, db);
    harness.check(db.getElem(0, 11), 88.0d);
    
    // what happens if the data buffer doesn't hold doubles?
    DataBuffer db2 = new DataBufferInt(12);
    m.setSample(2, 1, 0, 99.9d, db2);
    harness.check(db2.getElem(0, 10), 99);
    m.setSample(2, 1, 1, 88.8d, db2);
    harness.check(db2.getElem(0, 11), 88); 

    // check that a null data buffer generates a NullPointerException
    boolean pass = false;
    try
      {
        m.setSample(2, 1, 1, 77.7d, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
    harness.check(pass);
  }
  
  private void test2(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, float, DataBuffer)");  

    DataBuffer db = new DataBufferFloat(12);
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_FLOAT,
            3, 2, 2, 6, new int[] {0, 1});
    m.setSample(2, 1, 0, 99.9f, db);
    harness.check(db.getElem(0, 10), 99.0f);
    m.setSample(2, 1, 1, 88.8f, db);
    harness.check(db.getElem(0, 11), 88.0f);
    
    // what happens if the data buffer doesn't hold floats?
    DataBuffer db2 = new DataBufferInt(12);
    m.setSample(2, 1, 0, 99.9f, db2);
    harness.check(db2.getElem(0, 10), 99);
    m.setSample(2, 1, 1, 88.8f, db2);
    harness.check(db2.getElem(0, 11), 88); 
     
    // check that a null data buffer generates a NullPointerException
    boolean pass = false;
    try
      {
        m.setSample(2, 1, 1, 77.7f, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
    harness.check(pass);
  }
  
  private void test3(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, int, DataBuffer)");  
    
    DataBuffer db = new DataBufferInt(12);
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_INT,
            3, 2, 2, 6, new int[] {0, 1});
    m.setSample(2, 1, 0, 99, db);
    harness.check(db.getElem(0, 10), 99);
    m.setSample(2, 1, 1, 88, db);
    harness.check(db.getElem(0, 11), 88);
    
    // what happens if the data buffer doesn't hold integers?
    DataBuffer db2 = new DataBufferByte(12);
    m.setSample(2, 1, 0, 99, db2);
    harness.check(db2.getElem(0, 10), 99);
    m.setSample(2, 1, 1, 888, db2);
    harness.check(db2.getElem(0, 11), 120);  // (byte) 888
    
    // check that a null data buffer generates a NullPointerException
    boolean pass = false;
    try
      {
        m.setSample(2, 1, 1, 77, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
    harness.check(pass);
  }
}