root / trunk / libraries / libRaster / src-test / org / gvsig / raster / grid / filter / TestRasterFilterList.java @ 17108
History | View | Annotate | Download (4.69 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.grid.filter; |
20 |
|
21 |
import junit.framework.TestCase; |
22 |
|
23 |
import org.gvsig.raster.RasterLibrary; |
24 |
/**
|
25 |
* Este test prueba la lista de filtros.
|
26 |
* Mete n filtros en la lista y asigna prioridades para comprobar luego que la lista
|
27 |
* est? en el orden correcto. Se comprueban las operaciones de eliminar filtro por
|
28 |
* prioridad, por nombre y por objeto y sustituir filtro por posici?n y por nombre.
|
29 |
*
|
30 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
31 |
*/
|
32 |
public class TestRasterFilterList extends TestCase{ |
33 |
|
34 |
private boolean show = true; |
35 |
private int nFilters = 7; |
36 |
private RasterFilterForTest[] filterList = null; |
37 |
private RasterFilterList list = new RasterFilterList(); |
38 |
|
39 |
static {
|
40 |
RasterLibrary.wakeUp(); |
41 |
} |
42 |
|
43 |
public void setUp() { |
44 |
System.err.println("TestRasterFilterList running..."); |
45 |
try {
|
46 |
initList(); |
47 |
} catch (FilterTypeException e) {
|
48 |
e.printStackTrace(); |
49 |
} |
50 |
} |
51 |
|
52 |
public void start() { |
53 |
this.setUp();
|
54 |
this.testStack();
|
55 |
} |
56 |
|
57 |
public void testStack() { |
58 |
if (show)
|
59 |
System.out.println("Lista completa"); |
60 |
for (int i = 0; i < list.lenght(); i++) { |
61 |
if (show)
|
62 |
System.out.println(" Name: " |
63 |
+ ((RasterFilter) list.get(i)).getName()); |
64 |
assertEquals(((RasterFilter) list.get(i)).getName(), "filtro"
|
65 |
+ (i + 1));
|
66 |
} |
67 |
try {
|
68 |
initList(); |
69 |
|
70 |
list.remove("filtro5");
|
71 |
|
72 |
list.remove("filtro2");
|
73 |
if (show)
|
74 |
System.out.println("Completa menos filtros 5 y 2"); |
75 |
for (int i = 0; i < list.lenght(); i++) { |
76 |
if (show)
|
77 |
System.out.println(" Name: " |
78 |
+ ((RasterFilter) list.get(i)).getName()); |
79 |
switch (i) {
|
80 |
case 0: |
81 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
82 |
"filtro1");
|
83 |
break;
|
84 |
case 1: |
85 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
86 |
"filtro3");
|
87 |
break;
|
88 |
case 2: |
89 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
90 |
"filtro4");
|
91 |
break;
|
92 |
case 3: |
93 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
94 |
"filtro6");
|
95 |
break;
|
96 |
case 4: |
97 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
98 |
"filtro7");
|
99 |
break;
|
100 |
} |
101 |
} |
102 |
|
103 |
initList(); |
104 |
RasterFilter rf = new RasterFilterForTest();
|
105 |
rf.setName("filtroNew");
|
106 |
list.replace(rf, "filtro3");
|
107 |
if (show)
|
108 |
System.out
|
109 |
.println("Completa reemplazando el filtro3 por filtroNew");
|
110 |
for (int i = 0; i < list.lenght(); i++) { |
111 |
if (show)
|
112 |
System.out.println("Name: " |
113 |
+ ((RasterFilter) list.get(i)).getName()); |
114 |
switch (i) {
|
115 |
case 0: |
116 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
117 |
"filtro1");
|
118 |
break;
|
119 |
case 1: |
120 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
121 |
"filtro2");
|
122 |
break;
|
123 |
case 2: |
124 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
125 |
"filtroNew");
|
126 |
break;
|
127 |
case 3: |
128 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
129 |
"filtro4");
|
130 |
break;
|
131 |
case 4: |
132 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
133 |
"filtro5");
|
134 |
break;
|
135 |
case 5: |
136 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
137 |
"filtro6");
|
138 |
break;
|
139 |
case 6: |
140 |
assertEquals(((RasterFilter) list.get(i)).getName(), |
141 |
"filtro7");
|
142 |
break;
|
143 |
} |
144 |
} |
145 |
|
146 |
initList(); |
147 |
list.remove(RasterFilterForTest.class); |
148 |
if (show)
|
149 |
System.out.println("Eliminar por clase"); |
150 |
for (int i = 0; i < list.lenght(); i++) |
151 |
if (show)
|
152 |
System.out.println("Name: " |
153 |
+ ((RasterFilter) list.get(i)).getName()); |
154 |
assertEquals(list.lenght(), 0);
|
155 |
} catch (FilterTypeException e) {
|
156 |
e.printStackTrace(); |
157 |
} |
158 |
} |
159 |
|
160 |
/**
|
161 |
* Crea la lista
|
162 |
* @throws FilterTypeException
|
163 |
*/
|
164 |
private void initList() throws FilterTypeException { |
165 |
list.clear(); |
166 |
filterList = new RasterFilterForTest[nFilters];
|
167 |
for (int i = 0; i < nFilters; i++) { |
168 |
filterList[i] = new RasterFilterForTest();
|
169 |
filterList[i].setName("filtro" + (i + 1)); |
170 |
} |
171 |
|
172 |
for (int i = 0; i < nFilters; i++) |
173 |
list.add(filterList[i]); |
174 |
} |
175 |
} |