Revision 13424
trunk/libraries/libInternationalization/.classpath | ||
---|---|---|
3 | 3 |
<classpathentry kind="src" path="src"/> |
4 | 4 |
<classpathentry kind="src" output="bin-utils" path="src-utils"/> |
5 | 5 |
<classpathentry kind="src" output="bin-test" path="src-test"/> |
6 |
<classpathentry kind="src" path="src-utils-test"/> |
|
6 | 7 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
7 | 8 |
<classpathentry kind="lib" path="/_fwAndami/lib/log4j-1.2.8.jar"/> |
8 | 9 |
<classpathentry kind="var" path="JUNIT_HOME/junit.jar"/> |
trunk/libraries/libInternationalization/src-utils-test/org/gvsig/i18n/utils/TestProperties.java | ||
---|---|---|
1 |
package org.gvsig.i18n.utils; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.io.FileNotFoundException; |
|
6 |
import java.io.FileOutputStream; |
|
7 |
import java.io.IOException; |
|
8 |
import java.io.InputStream; |
|
9 |
import java.io.OutputStream; |
|
10 |
|
|
11 |
import junit.framework.TestCase; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author cesar |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class TestProperties extends TestCase { |
|
18 |
static final String fileName = "TestProperties-file"; |
|
19 |
InputStream is; |
|
20 |
OutputStream os; |
|
21 |
|
|
22 |
public void initOutputStream() { |
|
23 |
try { |
|
24 |
os = new FileOutputStream(fileName); |
|
25 |
} catch (FileNotFoundException e) { |
|
26 |
TestCase.fail(e.getLocalizedMessage()); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
public void discardOutputStream() { |
|
31 |
try { |
|
32 |
os.close(); |
|
33 |
File file = new File(fileName); |
|
34 |
file.delete(); |
|
35 |
} catch (IOException e) { |
|
36 |
TestCase.fail(e.getLocalizedMessage()); |
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
public void initInputStream() { |
|
41 |
try { |
|
42 |
is = new FileInputStream(fileName); |
|
43 |
} catch (FileNotFoundException e) { |
|
44 |
TestCase.fail(e.getLocalizedMessage()); |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
public void discardInputStream() { |
|
49 |
try { |
|
50 |
is.close(); |
|
51 |
} catch (IOException e) { |
|
52 |
TestCase.fail(e.getLocalizedMessage()); |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
public void testOrderedPropertiesBasic() { |
|
57 |
// write file |
|
58 |
OrderedProperties props1 = new OrderedProperties(); |
|
59 |
props1.setProperty("prueba", "hola"); |
|
60 |
props1.setProperty("prueba2", "holas"); |
|
61 |
props1.setProperty("abrir", "cerrar"); |
|
62 |
props1.setProperty("puerta", "hembrilla"); |
|
63 |
props1.setProperty("12libros", "quijote"); |
|
64 |
props1.setProperty("ca?uto", "\u20acuropeo"); |
|
65 |
props1.setProperty("confli=cto", "amigo"); |
|
66 |
props1.setProperty(" confli = :cto mayor ", " peque?o conflicto"); |
|
67 |
initOutputStream(); |
|
68 |
try { |
|
69 |
props1.store(os, "header"); |
|
70 |
} catch (IOException e) { |
|
71 |
TestCase.fail(e.getLocalizedMessage()); |
|
72 |
} |
|
73 |
|
|
74 |
// read file |
|
75 |
OrderedProperties props2 = new OrderedProperties(); |
|
76 |
initInputStream(); |
|
77 |
try { |
|
78 |
props2.load(is); |
|
79 |
} catch (IOException e) { |
|
80 |
TestCase.fail(e.getLocalizedMessage()); |
|
81 |
} |
|
82 |
TestCase.assertEquals("\u20acuropeo", props2.getProperty("ca?uto")); |
|
83 |
TestCase.assertEquals("amigo", props2.getProperty("confli=cto")); |
|
84 |
TestCase.assertEquals(" peque?o conflicto", props2.getProperty(" confli = :cto mayor ")); |
|
85 |
TestCase.assertEquals("hola", props2.getProperty("prueba")); |
|
86 |
TestCase.assertEquals("holas", props2.getProperty("prueba2")); |
|
87 |
TestCase.assertEquals("cerrar", props2.getProperty("abrir")); |
|
88 |
TestCase.assertEquals("hembrilla", props2.getProperty("puerta")); |
|
89 |
TestCase.assertEquals("quijote", props2.getProperty("12libros")); |
|
90 |
discardInputStream(); |
|
91 |
discardOutputStream(); |
|
92 |
} |
|
93 |
|
|
94 |
|
|
95 |
public void testOrderedProperties() { |
|
96 |
// write file |
|
97 |
OrderedProperties props1 = new OrderedProperties(); |
|
98 |
props1.setProperty("prueba", "hola"); |
|
99 |
props1.setProperty("prueba2", "holas"); |
|
100 |
props1.setProperty("ca?uto", "\u20acuropeo"); |
|
101 |
props1.setProperty("confli=cto", "amigo"); |
|
102 |
props1.setProperty(" conflis = :cto mayor ", " peque?o conflicto"); |
|
103 |
props1.setProperty("abrir", "cerrar"); |
|
104 |
props1.setProperty("puerta", "hembrilla"); |
|
105 |
props1.setProperty("12libros", "quijote"); |
|
106 |
initOutputStream(); |
|
107 |
try { |
|
108 |
props1.store(os, "header", "8859_15"); |
|
109 |
} catch (IOException e) { |
|
110 |
TestCase.fail(e.getLocalizedMessage()); |
|
111 |
} |
|
112 |
|
|
113 |
// read file |
|
114 |
OrderedProperties props2 = new OrderedProperties(); |
|
115 |
initInputStream(); |
|
116 |
try { |
|
117 |
props2.load(is, "8859_15"); |
|
118 |
} catch (IOException e) { |
|
119 |
TestCase.fail(e.getLocalizedMessage()); |
|
120 |
} |
|
121 |
// estos deber?an salir igual |
|
122 |
TestCase.assertEquals("hola", props2.getProperty("prueba")); |
|
123 |
TestCase.assertEquals("holas", props2.getProperty("prueba2")); |
|
124 |
TestCase.assertEquals("cerrar", props2.getProperty("abrir")); |
|
125 |
TestCase.assertEquals("hembrilla", props2.getProperty("puerta")); |
|
126 |
TestCase.assertEquals("quijote", props2.getProperty("12libros")); |
|
127 |
// con estos en cambio no obtenemos los mismos valores que escribimos anteriormente. Es normal, porque incluimos |
|
128 |
// caracteres especiales como ":" y "=". Para manejarlos correctamente necesitamos usas los m?todos load/store |
|
129 |
// sin encoding, los cuales s? escapan los caracteres especiales |
|
130 |
TestCase.assertEquals("\u20acuropeo", props2.getProperty("ca?uto")); |
|
131 |
TestCase.assertEquals("cto=amigo", props2.getProperty("confli")); |
|
132 |
TestCase.assertEquals(":cto mayor = peque?o conflicto", props2.getProperty("conflis")); |
|
133 |
|
|
134 |
discardInputStream(); |
|
135 |
discardOutputStream(); |
|
136 |
|
|
137 |
// write file |
|
138 |
props1 = new OrderedProperties(); |
|
139 |
props1.setProperty("Prueba", "hola"); |
|
140 |
props1.setProperty("prueba2", "holas"); |
|
141 |
props1.setProperty("ca?uto", "\u20acuropeo"); |
|
142 |
props1.setProperty("confli=cto", "amigo"); |
|
143 |
props1.setProperty(" conflis = :cto mayor ", " peque?o conflicto"); |
|
144 |
props1.setProperty("abrir", "cerrar"); |
|
145 |
props1.setProperty("puerta", "hembrilla"); |
|
146 |
props1.setProperty("12libros", "quijote"); |
|
147 |
initOutputStream(); |
|
148 |
try { |
|
149 |
props1.store(os, "header", "UTF8"); |
|
150 |
} catch (IOException e) { |
|
151 |
TestCase.fail(e.getLocalizedMessage()); |
|
152 |
} |
|
153 |
|
|
154 |
// read file |
|
155 |
props2 = new OrderedProperties(); |
|
156 |
initInputStream(); |
|
157 |
try { |
|
158 |
props2.load(is, "UTF8"); |
|
159 |
} catch (IOException e) { |
|
160 |
TestCase.fail(e.getLocalizedMessage()); |
|
161 |
} |
|
162 |
// estos deber?an salir igual |
|
163 |
TestCase.assertEquals("hola", props2.getProperty("Prueba")); |
|
164 |
TestCase.assertEquals("holas", props2.getProperty("prueba2")); |
|
165 |
TestCase.assertEquals("cerrar", props2.getProperty("abrir")); |
|
166 |
TestCase.assertEquals("hembrilla", props2.getProperty("puerta")); |
|
167 |
TestCase.assertEquals("quijote", props2.getProperty("12libros")); |
|
168 |
// con estos en cambio no obtenemos los mismos valores que escribimos anteriormente. Es normal, porque incluimos |
|
169 |
// caracteres especiales como ":" y "=". Para manejarlos correctamente necesitamos usas los m?todos load/store |
|
170 |
// sin encoding, los cuales s? escapan los caracteres especiales |
|
171 |
TestCase.assertEquals("\u20acuropeo", props2.getProperty("ca?uto")); |
|
172 |
TestCase.assertEquals("cto=amigo", props2.getProperty("confli")); |
|
173 |
TestCase.assertEquals(":cto mayor = peque?o conflicto", props2.getProperty("conflis")); |
|
174 |
|
|
175 |
discardInputStream(); |
|
176 |
discardOutputStream(); |
|
177 |
} |
|
178 |
|
|
179 |
} |
|
0 | 180 |
trunk/libraries/libInternationalization/src-utils-test/org/gvsig/i18n/utils/TestUtils.java | ||
---|---|---|
1 |
package org.gvsig.i18n.utils; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
|
|
6 |
import junit.framework.TestCase; |
|
7 |
|
|
8 |
/** |
|
9 |
* @author cesar |
|
10 |
* |
|
11 |
*/ |
|
12 |
public class TestUtils extends TestCase { |
|
13 |
|
|
14 |
public ConfigOptions loadConfig() { |
|
15 |
ConfigOptions config = new ConfigOptions(); |
|
16 |
config.setConfigFile("src-test"+File.separator+"org"+File.separator+"gvsig"+File.separator+"i18n"+File.separator+"utils"+File.separator+"config.xml"); |
|
17 |
config.load(); |
|
18 |
return config; |
|
19 |
} |
|
20 |
|
|
21 |
public void testConfigOptions() { |
|
22 |
ConfigOptions config = loadConfig(); |
|
23 |
|
|
24 |
String databaseDir=null, basedir=null; |
|
25 |
try { |
|
26 |
databaseDir = new File("test-data/database").getCanonicalPath(); |
|
27 |
basedir = new File("test-data").getCanonicalPath(); |
|
28 |
} catch (IOException e) { |
|
29 |
// TODO Auto-generated catch block |
|
30 |
e.printStackTrace(); |
|
31 |
} |
|
32 |
|
|
33 |
// the values of the projects. They are pairs (dir, basename). |
|
34 |
String projectValues[]={"src/appgvSIG", "otro", "sources", "src/_fwAndami", "text", "sources"}; |
|
35 |
for (int i=0; i<projectValues.length; i=i+3) { |
|
36 |
try { |
|
37 |
// set the canonical path |
|
38 |
projectValues[i]= new File(basedir+File.separator+projectValues[i]).getCanonicalPath(); |
|
39 |
} catch (IOException e) { |
|
40 |
// TODO Auto-generated catch block |
|
41 |
e.printStackTrace(); |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
TestCase.assertEquals(databaseDir, config.databaseDir); |
|
46 |
TestCase.assertEquals(basedir, config.defaultBaseDir); |
|
47 |
TestCase.assertEquals("text", config.defaultBaseName); |
|
48 |
|
|
49 |
String languages = config.languages[0]; |
|
50 |
for (int i=1; i<config.languages.length; i++) { |
|
51 |
languages=languages+";"+config.languages[i]; |
|
52 |
} |
|
53 |
TestCase.assertEquals("ca;cs;de;en;es;eu;fr;gl;it;pt", languages); |
|
54 |
|
|
55 |
for (int i=0; i<config.projects.size(); i=i+3) { |
|
56 |
Project project = (Project) config.projects.get(i); |
|
57 |
TestCase.assertEquals(projectValues[i], project.dir); |
|
58 |
TestCase.assertEquals(projectValues[i+1], project.basename); |
|
59 |
TestCase.assertEquals(projectValues[i+2], project.sourceKeys); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
public void testTranslationDatabase() { |
|
64 |
ConfigOptions config = loadConfig(); |
|
65 |
TranslationDatabase database = new TranslationDatabase(config); |
|
66 |
database.load(); |
|
67 |
TestCase.assertEquals("A?adir Capa" , database.getTranslation("es", "Anadir_Capa")); |
|
68 |
TestCase.assertEquals("Add Layer" , database.getTranslation("en", "Anadir_Capa")); |
|
69 |
TestCase.assertEquals("Afegir Capa" , database.getTranslation("ca", "Anadir_Capa")); |
|
70 |
TestCase.assertEquals("Layer hinzuf?gen" , database.getTranslation("de", "Anadir_Capa")); |
|
71 |
TestCase.assertEquals("Ayuda" , database.getTranslation("es", "Ayuda")); |
|
72 |
TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
73 |
|
|
74 |
// add a translation |
|
75 |
database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe"); |
|
76 |
// is it present now? |
|
77 |
TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
78 |
|
|
79 |
// remove the translation |
|
80 |
database.removeTranslation("es", "test_case.clave_que_no_existe"); |
|
81 |
// was really removed? |
|
82 |
TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
83 |
|
|
84 |
// add the translation again |
|
85 |
database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe"); |
|
86 |
// save to disk |
|
87 |
database.save(); |
|
88 |
// load from disk |
|
89 |
database.load(); |
|
90 |
// is the translation still there? |
|
91 |
TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
92 |
|
|
93 |
// remove the translation again and save to disk |
|
94 |
database.removeTranslation("es", "test_case.clave_que_no_existe"); |
|
95 |
TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
96 |
TestCase.assertEquals("", database.getTranslation("es", "prueba")); |
|
97 |
database.save(); |
|
98 |
} |
|
99 |
|
|
100 |
public void testKeys() { |
|
101 |
ConfigOptions config = loadConfig(); |
|
102 |
Keys keys = new Keys(config); |
|
103 |
keys.load(); |
|
104 |
} |
|
105 |
|
|
106 |
} |
|
0 | 107 |
trunk/libraries/libInternationalization/src-utils-test/org/gvsig/i18n/utils/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<config> |
|
3 |
<!-- Aquí especificamos algunas variables de configuración --> |
|
4 |
<!-- En este fichero se muestran todas las opciones posibles, en sus valores por defecto --> |
|
5 |
|
|
6 |
<!-- Nombre base por defecto de los ficheros con las traducciones. En nuestro caso suele ser "text", |
|
7 |
de forma que los ficheros toman nombres como "text.properties", "text_en.properties". Nótese |
|
8 |
que sólo es el nombre por defecto. Cada proyecto puede especificar un baseName distinto --> |
|
9 |
<variable name="basename" value="text" /> |
|
10 |
|
|
11 |
<!-- Directorio base. Las rutas relativas especificadas en otras variables (databaseDir, directorios |
|
12 |
de proyecto) tomarán este directorio como directorio base. Por defecto es el directorio |
|
13 |
desde el que se llama a la aplicación --> |
|
14 |
<variable name="basedir" value="test-data" /> |
|
15 |
|
|
16 |
<!-- Lista de idiomas que se tendrán en cuenta --> |
|
17 |
<variable name="languages" value="ca;cs;de;en;es;eu;fr;gl;it;pt" /> |
|
18 |
|
|
19 |
<!-- El directorio que contendrá la base de datos de traducciones por idioma. Por defecto es el |
|
20 |
directorio "database", relativo al directorio especificado en la variable "basedir". --> |
|
21 |
<variable name="databaseDir" value="database" /> |
|
22 |
|
|
23 |
<!-- El directorio por defecto que contendrá los property files que almacenan las claves de cada |
|
24 |
proyecto". Esto se usa en los proyectos que no especifican un atributo "propertyDir". Si el |
|
25 |
directorio no es absoluto, entonces es relativo al directorio de cada proyecto. --> |
|
26 |
<variable name="defaultPropertyDir" value="config" /> |
|
27 |
|
|
28 |
<variable name="sourceKeys" value="sources" /> |
|
29 |
</config> |
|
30 |
<projects> |
|
31 |
<!-- Los proyectos que se van a leer. Es necesario especificar un directorio (relativo o absoluto), |
|
32 |
y opcionalmente se puede incluir un atributo "basename" para especificar un nombre base |
|
33 |
distinto del nombre base por defecto --> |
|
34 |
<!-- The projects which are going to be read. An absolute or relative directory name must be specified, |
|
35 |
in which the property files are located. An optional "basename" attribute is also accepted, |
|
36 |
to override the default basename --> |
|
37 |
<project dir="src/appgvSIG" basename="otro" sourceKeys="sources" propertyDir="config" /> |
|
38 |
<project dir="src/_fwAndami" /> |
|
39 |
</projects> |
|
0 | 40 |
trunk/libraries/libInternationalization/build.xml | ||
---|---|---|
4 | 4 |
</description> |
5 | 5 |
<!-- set global properties for this build --> |
6 | 6 |
<property name="src" location="src"/> |
7 |
<property name="src-test" location="src-test"/> |
|
7 | 8 |
<property name="build" location="bin"/> |
9 |
<property name="build-test" location="bin-test"/> |
|
8 | 10 |
<property name="andamiLibs" location="../_fwAndami/lib"/> |
9 | 11 |
<property name="dist" location="dist"/> |
10 | 12 |
<property name="lib" location="lib"/> |
... | ... | |
83 | 85 |
<delete dir="${dist}"/> |
84 | 86 |
</target> |
85 | 87 |
|
86 |
<target name="run-tests"> |
|
88 |
<target name="run-tests" depends="batch-build,compile-tests">
|
|
87 | 89 |
<antcall target="generic-run-tests"> |
88 | 90 |
<param name="TestSuite.Name" value="org.gvsig.i18n.AllTests"/> |
89 | 91 |
</antcall> |
Also available in: Unified diff