Statistics
| Revision:

root / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataaccess / TestDataSourceMultiFile.java @ 10960

History | View | Annotate | Download (6.11 KB)

1
/*
2
 * Created on 19-jul-2006
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 */
25
package org.gvsig.raster.dataaccess;
26

    
27
import junit.framework.TestCase;
28

    
29
import org.gvsig.raster.RasterLibrary;
30
import org.gvsig.raster.dataaccess.DataSource;
31
import org.gvsig.raster.dataset.NotSupportedExtensionException;
32
import org.gvsig.raster.dataset.RasterDataset;
33
import org.gvsig.raster.dataset.RasterDriverException;
34
import org.gvsig.raster.dataset.io.EcwDriver;
35
import org.gvsig.raster.dataset.io.GdalDriver;
36
import org.gvsig.raster.grid.Grid;
37

    
38
/**
39
 * Este test prueba la gesti?n de multifichero de la clase RasterMultiFile
40
 * y que incorpora un Grid, as? como la gesti?n de bandas que tiene BandList
41
 * y que incorpora GeoRasterMultiFile.
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 *
44
 */
45
public class TestDataSourceMultiFile extends TestCase{
46
        private String baseDir = "./test-images/";
47

    
48
        private String path1 = baseDir + "band1-30x28byte.tif";
49
        private String path2 = baseDir + "band2-30x28byte.tif";
50
        private String path3 = baseDir + "band3-30x28byte.tif";
51
        
52
        private RasterDataset f1 = null;
53
        private RasterDataset f2 = null;
54
        private RasterDataset f3 = null;
55
        
56
        private DataSource ds = null;
57
        
58
        public void start(){
59
                this.setUp();
60
                this.testStack();
61
        }
62
        
63
        static{
64
                RasterLibrary.wakeUp();
65
        }
66
        
67
        public void setUp() {
68
                System.err.println("TestDataSourceMultiFile running...");
69
                try {
70
                        f1 = RasterDataset.openFile(null, path1);
71
                        f2 = RasterDataset.openFile(null, path2);
72
                        f3 = RasterDataset.openFile(null, path3);
73
                        //f4 = RasterDataset.openFile(null, path4);
74
                } catch (NotSupportedExtensionException e) {
75
                        e.printStackTrace();
76
                } catch (RasterDriverException e) {
77
                        e.printStackTrace();
78
                }
79
        }
80
        
81
        public void testStack(){
82
        
83
                //EL CONSTRUCTOR A?ADE FICHERO 1
84
                ds = new DataSource(f1);
85
                //Comprobaci?n de n?mero y nombre de ficheros
86
                String[] fileList = ds.getGeoRasterMultiFile().getNameDatasetStringList();
87
                assertEquals(fileList.length, 1);
88
                assertEquals(fileList[0], path1);
89
                //Comprobaci?n de bandas
90
                String[] bandList = ds.getGeoRasterMultiFile().getBands().getBandStringList();
91
                assertEquals(bandList.length, 1);
92
                assertEquals(bandList[0], path1);
93
                
94
                //A?ADIMOS FICHERO 2
95
                ds.addFile(f2);
96
                fileList = ds.getGeoRasterMultiFile().getNameDatasetStringList();
97
                //Comprobaci?n de n?mero y nombre de ficheros
98
                assertEquals(fileList.length, 2);
99
                assertEquals(fileList[0], path1);
100
                assertEquals(fileList[1], path2);
101
                //Comprobaci?n de bandas
102
                bandList = ds.getGeoRasterMultiFile().getBands().getBandStringList();
103
                assertEquals(bandList.length, 2);
104
                assertEquals(bandList[0], path1);
105
                assertEquals(bandList[1], path2);
106
                
107
                //A?ADIMOS FICHERO 3
108
                ds.addFile(f3);
109
                fileList = ds.getGeoRasterMultiFile().getNameDatasetStringList();
110
                //Comprobaci?n de n?mero y nombre de ficheros
111
                assertEquals(fileList.length, 3);
112
                assertEquals(fileList[0], path1);
113
                assertEquals(fileList[1], path2);
114
                assertEquals(fileList[2], path3);
115
                //Comprobaci?n de bandas
116
                bandList = ds.getGeoRasterMultiFile().getBands().getBandStringList();
117
                assertEquals(bandList.length, 3);
118
                assertEquals(bandList[0], path1);
119
                assertEquals(bandList[1], path2);
120
                assertEquals(bandList[2], path3);
121
                //Posicion dentro del fichero
122
                int[] bandPos = ds.getGeoRasterMultiFile().getBands().getBandPositionList();
123
                for(int i = 0; i < bandPos.length; i++)
124
                        assertEquals(bandPos[i], 0);
125
                
126
                //ELIMINAMOS FICHERO 2
127
                ds.removeFile(f2);
128
                fileList = ds.getGeoRasterMultiFile().getNameDatasetStringList();
129
                //Comprobaci?n de n?mero y nombre de ficheros
130
                assertEquals(fileList.length, 2);
131
                assertEquals(fileList[0], path1);
132
                assertEquals(fileList[1], path3);
133
                //Comprobaci?n de bandas
134
                bandList = ds.getGeoRasterMultiFile().getBands().getBandStringList();
135
                assertEquals(bandList.length, 2);
136
                assertEquals(bandList[0], path1);
137
                assertEquals(bandList[1], path3);
138
                
139
                //ELIMINAMOS FICHERO 1
140
                ds.removeFile(f1);
141
                fileList = ds.getGeoRasterMultiFile().getNameDatasetStringList();
142
                //Comprobaci?n de n?mero y nombre de ficheros
143
                assertEquals(fileList.length, 1);
144
                assertEquals(fileList[0], path3);
145
                //Comprobaci?n de bandas
146
                bandList = ds.getGeoRasterMultiFile().getBands().getBandStringList();
147
                assertEquals(bandList.length, 1);
148
                assertEquals(bandList[0], path3);
149
                
150
                //ELIMINAMOS FICHERO 3
151
                ds.removeFile(f3);
152
                fileList = ds.getGeoRasterMultiFile().getNameDatasetStringList();
153
                //Comprobaci?n de n?mero y nombre de ficheros
154
                assertEquals(fileList.length, 0);
155
                //Comprobaci?n de bandas
156
                bandList = ds.getGeoRasterMultiFile().getBands().getBandStringList();
157
                assertEquals(bandList.length, 0);
158

    
159
                //A?ADIMOS FICHERO 4
160
                /*ds.addFile(f4);
161
                fileList = ds.getGeoRasterMultiFile().getNameDatasetStringList();
162
                //Comprobaci?n de n?mero y nombre de ficheros
163
                assertEquals(fileList.length, 1);
164
                assertEquals(fileList[0], path4);
165
                //Comprobaci?n de bandas
166
                bandList = ds.getGeoRasterMultiFile().getBands().getBandStringList();
167
                assertEquals(bandList.length, 4);
168
                assertEquals(bandList[0], path4);
169
                assertEquals(bandList[1], path4);
170
                assertEquals(bandList[2], path4);
171
                assertEquals(bandList[3], path4);
172
                //Posicion dentro del fichero
173
                bandPos = ds.getGeoRasterMultiFile().getBands().getBandPositionList();
174
                for(int i = 0; i < bandPos.length; i++)
175
                        assertEquals(bandPos[i], i);*/
176
        }
177

    
178
}