svn-gvsig-desktop / trunk / libraries / libGPE / src-test / org / gvsig / gpe / writers / GPEWriterBaseTest.java @ 11178
History | View | Annotate | Download (4.15 KB)
1 | 11178 | jorpiell | package org.gvsig.gpe.writers; |
---|---|---|---|
2 | |||
3 | import java.io.File; |
||
4 | import java.io.IOException; |
||
5 | |||
6 | import junit.framework.TestCase; |
||
7 | |||
8 | import org.gvsig.gpe.GPEErrorHandler; |
||
9 | import org.gvsig.gpe.GPEErrorHandlerTest; |
||
10 | |||
11 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
12 | *
|
||
13 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
14 | *
|
||
15 | * This program is free software; you can redistribute it and/or
|
||
16 | * modify it under the terms of the GNU General Public License
|
||
17 | * as published by the Free Software Foundation; either version 2
|
||
18 | * of the License, or (at your option) any later version.
|
||
19 | *
|
||
20 | * This program is distributed in the hope that it will be useful,
|
||
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
23 | * GNU General Public License for more details.
|
||
24 | *
|
||
25 | * You should have received a copy of the GNU General Public License
|
||
26 | * along with this program; if not, write to the Free Software
|
||
27 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
28 | *
|
||
29 | * For more information, contact:
|
||
30 | *
|
||
31 | * Generalitat Valenciana
|
||
32 | * Conselleria d'Infraestructures i Transport
|
||
33 | * Av. Blasco Ib??ez, 50
|
||
34 | * 46010 VALENCIA
|
||
35 | * SPAIN
|
||
36 | *
|
||
37 | * +34 963862235
|
||
38 | * gvsig@gva.es
|
||
39 | * www.gvsig.gva.es
|
||
40 | *
|
||
41 | * or
|
||
42 | *
|
||
43 | * IVER T.I. S.A
|
||
44 | * Salamanca 50
|
||
45 | * 46005 Valencia
|
||
46 | * Spain
|
||
47 | *
|
||
48 | * +34 963163400
|
||
49 | * dac@iver.es
|
||
50 | */
|
||
51 | /* CVS MESSAGES:
|
||
52 | *
|
||
53 | * $Id$
|
||
54 | * $Log$
|
||
55 | * Revision 1.1 2007-04-13 07:17:54 jorpiell
|
||
56 | * Add the writting tests for the simple geometries
|
||
57 | *
|
||
58 | *
|
||
59 | */
|
||
60 | /**
|
||
61 | * This class must be implementend by all the classes that
|
||
62 | * implements a GPE writer Parser. It creates a writer, write some
|
||
63 | * features and then uses a reader to compare the writting
|
||
64 | * process
|
||
65 | * @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
||
66 | */
|
||
67 | public abstract class GPEWriterBaseTest extends TestCase{ |
||
68 | private GPEWriterHandler handler = null; |
||
69 | private File fileTemp = new File("testdata/tmp/filetemp"); |
||
70 | |||
71 | /**
|
||
72 | * Creates the writer
|
||
73 | */
|
||
74 | public void setUp(){ |
||
75 | try {
|
||
76 | handler = getWriter(fileTemp, new GPEErrorHandlerTest());
|
||
77 | } catch (IOException e) { |
||
78 | // TODO Auto-generated catch block
|
||
79 | e.printStackTrace(); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | /**
|
||
84 | * Delete the file
|
||
85 | */
|
||
86 | public void tearDown(){ |
||
87 | //fileTemp.delete();
|
||
88 | } |
||
89 | |||
90 | /**
|
||
91 | * This test writes some objects into the file and then
|
||
92 | * try to read the created file. It compare that the written
|
||
93 | * objects are the same that the read them
|
||
94 | */
|
||
95 | public void testWriter(){ |
||
96 | writeObjects(); |
||
97 | readObjects(); |
||
98 | } |
||
99 | |||
100 | /**
|
||
101 | * This method write somo objects into the writer handler
|
||
102 | */
|
||
103 | public abstract void writeObjects(); |
||
104 | |||
105 | /**
|
||
106 | * It read the objects and make all the comparations
|
||
107 | *
|
||
108 | */
|
||
109 | public abstract void readObjects(); |
||
110 | |||
111 | /**
|
||
112 | * It creates a writer handler.
|
||
113 | * @param file
|
||
114 | * @param errorHandler
|
||
115 | * @return
|
||
116 | */
|
||
117 | public abstract GPEWriterHandler getWriter(File file,GPEErrorHandler errorHandler) throws IOException; |
||
118 | |||
119 | /**
|
||
120 | * It creates a Random bbox coordinates. It return
|
||
121 | * 10 coordinates
|
||
122 | * @return
|
||
123 | */
|
||
124 | protected double[] generateRandomCoordinates(){ |
||
125 | return generateRandomCoordinates(10); |
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | * It creates a Random bbox coordinates
|
||
130 | * @param length
|
||
131 | * The number of coordinates
|
||
132 | * @return
|
||
133 | */
|
||
134 | protected double[] generateRandomCoordinates(int length){ |
||
135 | double[] coord = new double[length]; |
||
136 | for (int i=0 ; i<coord.length ; i++){ |
||
137 | coord[i] = Math.random();
|
||
138 | } |
||
139 | return coord;
|
||
140 | } |
||
141 | |||
142 | /**
|
||
143 | * It creates a Random linear ring. It return
|
||
144 | * 10 coordinates
|
||
145 | * @return
|
||
146 | */
|
||
147 | protected double[] generateRandomLinearRing(){ |
||
148 | return generateRandomLinearRing(10); |
||
149 | } |
||
150 | |||
151 | |||
152 | /**
|
||
153 | * It creates a random linear ring
|
||
154 | * @param length
|
||
155 | * @return
|
||
156 | */
|
||
157 | protected double[] generateRandomLinearRing(int length){ |
||
158 | double[] coord = new double[length]; |
||
159 | for (int i=0 ; i<coord.length-1 ; i++){ |
||
160 | coord[i] = Math.random();
|
||
161 | } |
||
162 | coord[length-1] = coord[0]; |
||
163 | return coord;
|
||
164 | } |
||
165 | |||
166 | /**
|
||
167 | * It creates a Random bbox coordinates
|
||
168 | * @return
|
||
169 | */
|
||
170 | protected double[] generateRandomBBox(){ |
||
171 | double[] coord = new double[2]; |
||
172 | for (int i=0 ; i<coord.length ; i++){ |
||
173 | coord[i] = Math.random();
|
||
174 | } |
||
175 | return coord;
|
||
176 | } |
||
177 | |||
178 | /**
|
||
179 | * @return the handler
|
||
180 | */
|
||
181 | public GPEWriterHandler getHandler() {
|
||
182 | return handler;
|
||
183 | } |
||
184 | } |