Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.i18n / utils / test / src / org / gvsig / i18n / utils / TestUtils.java @ 40559

History | View | Annotate | Download (4.74 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.i18n.utils;
25

    
26
import java.io.File;
27
import java.io.IOException;
28

    
29
import junit.framework.TestCase;
30

    
31
/**
32
 * @author cesar
33
 *
34
 */
35
public class TestUtils extends TestCase {
36
        
37
        public ConfigOptions loadConfig() {
38
                ConfigOptions config = new ConfigOptions();
39
                config.setConfigFile("src-test"+File.separator+"org"+File.separator+"gvsig"+File.separator+"i18n"+File.separator+"utils"+File.separator+"config.xml");
40
                config.load();
41
                return config;
42
        }
43
        
44
        public void testConfigOptions() {
45
                ConfigOptions config = loadConfig();
46
                
47
                String databaseDir=null, basedir=null;
48
                try {
49
                        databaseDir = new File("test-data/database").getCanonicalPath();
50
                        basedir =  new File("test-data").getCanonicalPath();
51
                } catch (IOException e) {
52
                        // TODO Auto-generated catch block
53
                        e.printStackTrace();
54
                }
55
                
56
                // the values of the projects. They are pairs (dir, basename).
57
                String projectValues[]={"src/appgvSIG", "otro", "sources", "src/_fwAndami", "text", "sources"};
58
                for (int i=0; i<projectValues.length; i=i+3) {
59
                        try {
60
                                // set the canonical path
61
                                projectValues[i]= new File(basedir+File.separator+projectValues[i]).getCanonicalPath();
62
                        } catch (IOException e) {
63
                                // TODO Auto-generated catch block
64
                                e.printStackTrace();
65
                        }
66
                }
67
                
68
                TestCase.assertEquals(databaseDir, config.databaseDir);
69
                TestCase.assertEquals(basedir, config.defaultBaseDir);
70
                TestCase.assertEquals("text", config.defaultBaseName);
71
                
72
                String languages = config.languages[0];
73
                for (int i=1; i<config.languages.length; i++) {
74
                        languages=languages+";"+config.languages[i];
75
                }
76
                TestCase.assertEquals("ca;cs;de;en;es;eu;fr;gl;it;pt", languages);
77
                
78
                for (int i=0; i<config.projects.size(); i=i+3) {
79
                        Project project = (Project) config.projects.get(i);
80
                        TestCase.assertEquals(projectValues[i], project.dir);
81
                        TestCase.assertEquals(projectValues[i+1], project.basename);
82
                        TestCase.assertEquals(projectValues[i+2], project.sourceKeys);
83
                }
84
        }
85
        
86
        public void testTranslationDatabase() {
87
                ConfigOptions config = loadConfig();
88
                TranslationDatabase database = new TranslationDatabase(config);
89
                database.load();
90
                TestCase.assertEquals("A?adir Capa" , database.getTranslation("es", "Anadir_Capa"));
91
                TestCase.assertEquals("Add Layer" , database.getTranslation("en", "Anadir_Capa"));
92
                TestCase.assertEquals("Afegir Capa" , database.getTranslation("ca", "Anadir_Capa"));
93
                TestCase.assertEquals("Layer hinzuf?gen" , database.getTranslation("de", "Anadir_Capa"));
94
                TestCase.assertEquals("Ayuda" , database.getTranslation("es", "Ayuda"));
95
                TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe"));
96
                
97
                // add a translation
98
                database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe");
99
                // is it present now?
100
                TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe"));
101
                
102
                // remove the translation
103
                database.removeTranslation("es", "test_case.clave_que_no_existe");
104
                // was really removed?
105
                TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe"));
106
                
107
                // add the translation again
108
                database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe");
109
                // save to disk
110
                database.save();
111
                // load from disk
112
                database.load();
113
                // is the translation still there?
114
                TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe"));
115
                
116
                // remove the translation again and save to disk
117
                database.removeTranslation("es", "test_case.clave_que_no_existe");
118
                TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe"));
119
                TestCase.assertEquals("", database.getTranslation("es", "prueba"));
120
                database.save();
121
        }
122

    
123
        public void testKeys() {
124
                ConfigOptions config = loadConfig();
125
                Keys keys = new Keys(config);
126
                keys.load();
127
        }
128

    
129
}