001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.mif;
017:
018: import com.vividsolutions.jts.io.ParseException;
019: import junit.framework.TestCase;
020: import junit.framework.TestSuite;
021:
022: /**
023: * DOCUMENT ME!
024: *
025: * @author Luca S. Percich, AMA-MI
026: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/mif/src/test/java/org/geotools/data/mif/MIFStringTokenizerTest.java $
027: */
028: public class MIFStringTokenizerTest extends TestCase {
029: private MIFStringTokenizer tok = null;
030:
031: /**
032: * DOCUMENT ME!
033: *
034: * @param args DOCUMENT ME!
035: *
036: * @throws Exception DOCUMENT ME!
037: */
038: public static void main(java.lang.String[] args) throws Exception {
039: junit.textui.TestRunner.run(new TestSuite(
040: MIFStringTokenizerTest.class));
041: }
042:
043: /**
044: * DOCUMENT ME!
045: *
046: * @throws Exception DOCUMENT ME!
047: */
048: protected void setUp() throws Exception {
049: super .setUp();
050: tok = new MIFStringTokenizer();
051: }
052:
053: /**
054: * DOCUMENT ME!
055: *
056: * @throws Exception DOCUMENT ME!
057: */
058: protected void tearDown() throws Exception {
059: tok = null;
060: super .tearDown();
061: }
062:
063: /*
064: * Class under test for boolean readLine(String)
065: */
066: public void testReadLineString() {
067: assertEquals(false, tok.readLine(""));
068: assertEquals(true, tok.readLine("foo"));
069: }
070:
071: /*
072: * Class under test for boolean readLine()
073: */
074: public void testReadLine() {
075: assertEquals(false, tok.readLine());
076: }
077:
078: /*
079: * Class under test for String getToken(char, boolean, boolean)
080: */
081: public void testGetTokencharbooleanboolean() {
082: tok.readLine("\"foo bar\" next");
083:
084: try {
085: assertEquals("foo bar", tok.getToken(' ', false, true));
086: } catch (ParseException e) {
087: fail(e.getMessage());
088: }
089: }
090:
091: /*
092: * Class under test for String getToken(char, boolean)
093: */
094: public void testGetTokencharboolean() {
095: tok.readLine("foo bar");
096:
097: try {
098: assertEquals("foo", tok.getToken(' ', true));
099: } catch (ParseException e) {
100: fail(e.getMessage());
101: }
102: }
103:
104: /*
105: * Class under test for String getToken(char, boolean, boolean)
106: */
107: public void testGetTokencharbooleanbooleanInQuote() {
108: tok.readLine("\"foo \"quote inside quoted string\" bar\",next");
109:
110: try {
111: assertEquals("foo \"quote inside quoted string\" bar", tok
112: .getToken(',', false, true));
113: } catch (ParseException e) {
114: fail(e.getMessage());
115: }
116: }
117:
118: /*
119: * Class under test for String getToken(char, boolean, boolean)
120: */
121: public void testGetTokencharbooleanbooleanInQuoteEnd() {
122: tok.readLine("\"foo \"quote inside quoted string\"\"");
123:
124: try {
125: assertEquals("foo \"quote inside quoted string\"", tok
126: .getToken(',', false, true));
127: } catch (ParseException e) {
128: fail(e.getMessage());
129: }
130: }
131:
132: /*
133: * Class under test for String getToken(char)
134: */
135: public void testGetTokenchar() {
136: tok.readLine("foo bar");
137:
138: try {
139: assertEquals("foo", tok.getToken(' '));
140: } catch (ParseException e) {
141: fail(e.getMessage());
142: }
143: }
144:
145: /*
146: * Class under test for String getToken()
147: */
148: public void testGetToken() {
149: tok.readLine("foo bar");
150:
151: try {
152: assertEquals("foo", tok.getToken());
153: } catch (ParseException e) {
154: fail(e.getMessage());
155: }
156: }
157:
158: /**
159: * DOCUMENT ME!
160: */
161: public void testStrQuote() {
162: assertEquals("\"an \"\"unquoted\"\" string\"",
163: MIFStringTokenizer.strQuote("an \"unquoted\" string"));
164: }
165:
166: /**
167: * DOCUMENT ME!
168: */
169: public void testStrUnquote() {
170: assertEquals("simple", MIFStringTokenizer
171: .strUnquote("\"simple\""));
172: assertEquals("a \"quoted\" string", MIFStringTokenizer
173: .strUnquote("\"a \"\"quoted\"\" string\""));
174: }
175:
176: /**
177: * DOCUMENT ME!
178: */
179: public void testLtrim() {
180: assertEquals("string", MIFStringTokenizer.ltrim(" string"));
181: }
182:
183: /**
184: * DOCUMENT ME!
185: */
186: public void testGetLine() {
187: tok.readLine("foo");
188: assertEquals("foo", tok.getLine());
189: }
190:
191: /**
192: * DOCUMENT ME!
193: */
194: public void testIsEmpty() {
195: tok.readLine("foo");
196: assertEquals(false, tok.isEmpty());
197:
198: tok.readLine();
199: assertEquals(true, tok.isEmpty());
200: }
201: }
|