1 /*
2  * JaLingo, http://jalingo.sourceforge.net/
3  *
4  * Copyright (c) 2002-2006 Oleksandr Shyshko
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 
21 package ja.lingo.readers.ptkdictmysql;
22 
23 import junit.framework.TestCase;
24 import ja.lingo.engine.reader.IConverter;
25 import ja.lingo.engine.beans.Info;
26 
27 public class PtkDictMySqlConverterTest extends TestCase {
28     private IConverter converter;
29 
setUp()30     protected void setUp() throws Exception {
31         super.setUp();
32 
33         Info i = new Info();
34         i.setDataFileEncoding( "ISO-8859-1" );
35         converter = new PtkDictMySqlConverter( i );
36     }
37 
testGetTitle()38     public void testGetTitle() {
39         checkTitle( "\"\'\n", "\\\"\\'\\n" );
40     }
41 
testGetBody()42     public void testGetBody() {
43         checkBody( "body\"'<br>", "title", "body\\\"\\'\\n" );
44 
45         checkBody( "body", "title", "body" );
46         checkBody( "body", "title", "title: body" );
47         checkBody( "body", "title", "title:\\nbody" );
48         checkBody( "body", "title", "title body" );
49     }
50 
checkTitle( String expectedTitle, String rawTitle )51     private void checkTitle( String expectedTitle, String rawTitle ) {
52         byte[] titleBytes = rawTitle.getBytes();
53         assertEquals( expectedTitle, converter.getTitle( titleBytes, 0, titleBytes.length ) );
54     }
checkBody( String expectedBody, String rawTitle, String rawBody )55     private void checkBody( String expectedBody, String rawTitle, String rawBody ) {
56         byte[] titleBytes = rawTitle.getBytes();
57         byte[] bodyBytes = rawBody.getBytes();
58         assertEquals( expectedBody, converter.getBody(
59                 titleBytes, 0, titleBytes.length,
60                 bodyBytes, 0, bodyBytes.length ) );
61     }
62 }