3
// Copyright (c) 2005, Matthew J. Rutherford <rutherfo@cs.colorado.edu>
4
// Copyright (c) 2005, University of Colorado at Boulder
5
// All rights reserved.
7
// Redistribution and use in source and binary forms, with or without
8
// modification, are permitted provided that the following conditions are
11
// * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
14
// * Redistributions in binary form must reproduce the above copyright
15
// notice, this list of conditions and the following disclaimer in the
16
// documentation and/or other materials provided with the distribution.
18
// * Neither the name of the University of Colorado at Boulder nor the
19
// names of its contributors may be used to endorse or promote
20
// products derived from this software without specific prior written
23
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
package org.xbill.DNS;
37
import java.io.IOException;
38
import java.util.Arrays;
39
import junit.framework.Test;
40
import junit.framework.TestCase;
41
import junit.framework.TestSuite;
43
public class GPOSRecordTest extends TestCase
45
public void test_ctor_0arg()
47
GPOSRecord gr = new GPOSRecord();
48
assertNull(gr.getName());
49
assertEquals(0, gr.getType());
50
assertEquals(0, gr.getDClass());
51
assertEquals(0, gr.getTTL());
54
public void test_getObject()
56
GPOSRecord gr = new GPOSRecord();
57
Record r = gr.getObject();
58
assertTrue(r instanceof GPOSRecord);
61
public static class Test_Ctor_6arg_doubles extends TestCase
65
private double m_lat, m_long, m_alt;
67
protected void setUp() throws TextParseException
69
m_n = Name.fromString("The.Name.");
76
public void test_basic() throws TextParseException
78
GPOSRecord gr = new GPOSRecord(m_n, DClass.IN, m_ttl,
79
m_long, m_lat, m_alt);
80
assertEquals(m_n, gr.getName());
81
assertEquals(DClass.IN, gr.getDClass());
82
assertEquals(Type.GPOS, gr.getType());
83
assertEquals(m_ttl, gr.getTTL());
84
assertEquals(new Double(m_long), new Double(gr.getLongitude()));
85
assertEquals(new Double(m_lat), new Double(gr.getLatitude()));
86
assertEquals(new Double(m_alt), new Double(gr.getAltitude()));
87
assertEquals(new Double(m_long).toString(), gr.getLongitudeString());
88
assertEquals(new Double(m_lat).toString(), gr.getLatitudeString());
89
assertEquals(new Double(m_alt).toString(), gr.getAltitudeString());
92
public void test_toosmall_longitude() throws TextParseException
95
new GPOSRecord(m_n, DClass.IN, m_ttl,
96
-90.001, m_lat, m_alt);
97
fail("IllegalArgumentException not thrown");
99
catch(IllegalArgumentException e){}
102
public void test_toobig_longitude() throws TextParseException
105
new GPOSRecord(m_n, DClass.IN, m_ttl,
106
90.001, m_lat, m_alt);
107
fail("IllegalArgumentException not thrown");
109
catch(IllegalArgumentException e){}
112
public void test_toosmall_latitude() throws TextParseException
115
new GPOSRecord(m_n, DClass.IN, m_ttl,
116
m_long, -180.001, m_alt);
117
fail("IllegalArgumentException not thrown");
119
catch(IllegalArgumentException e){}
122
public void test_toobig_latitude() throws TextParseException
125
new GPOSRecord(m_n, DClass.IN, m_ttl,
126
m_long, 180.001, m_alt);
127
fail("IllegalArgumentException not thrown");
129
catch(IllegalArgumentException e){}
132
public void test_invalid_string()
135
new GPOSRecord(m_n, DClass.IN, m_ttl,
136
new Double(m_long).toString(),
137
"120.\\00ABC", new Double(m_alt).toString());
138
fail("IllegalArgumentException not thrown");
140
catch(IllegalArgumentException e){}
144
public static class Test_Ctor_6arg_Strings extends TestCase
148
private double m_lat, m_long, m_alt;
150
protected void setUp() throws TextParseException
152
m_n = Name.fromString("The.Name.");
159
public void test_basic() throws TextParseException
161
GPOSRecord gr = new GPOSRecord(m_n, DClass.IN, m_ttl,
162
new Double(m_long).toString(),
163
new Double(m_lat).toString(),
164
new Double(m_alt).toString());
165
assertEquals(m_n, gr.getName());
166
assertEquals(DClass.IN, gr.getDClass());
167
assertEquals(Type.GPOS, gr.getType());
168
assertEquals(m_ttl, gr.getTTL());
169
assertEquals(new Double(m_long), new Double(gr.getLongitude()));
170
assertEquals(new Double(m_lat), new Double(gr.getLatitude()));
171
assertEquals(new Double(m_alt), new Double(gr.getAltitude()));
172
assertEquals(new Double(m_long).toString(), gr.getLongitudeString());
173
assertEquals(new Double(m_lat).toString(), gr.getLatitudeString());
174
assertEquals(new Double(m_alt).toString(), gr.getAltitudeString());
177
public void test_toosmall_longitude() throws TextParseException
180
new GPOSRecord(m_n, DClass.IN, m_ttl,
181
"-90.001", new Double(m_lat).toString(),
182
new Double(m_alt).toString());
183
fail("IllegalArgumentException not thrown");
185
catch(IllegalArgumentException e){}
188
public void test_toobig_longitude() throws TextParseException
191
new GPOSRecord(m_n, DClass.IN, m_ttl,
192
"90.001", new Double(m_lat).toString(),
193
new Double(m_alt).toString());
194
fail("IllegalArgumentException not thrown");
196
catch(IllegalArgumentException e){}
199
public void test_toosmall_latitude() throws TextParseException
202
new GPOSRecord(m_n, DClass.IN, m_ttl,
203
new Double(m_long).toString(), "-180.001",
204
new Double(m_alt).toString());
205
fail("IllegalArgumentException not thrown");
207
catch(IllegalArgumentException e){}
210
public void test_toobig_latitude() throws TextParseException
213
new GPOSRecord(m_n, DClass.IN, m_ttl,
214
new Double(m_long).toString(), "180.001", new Double(m_alt).toString());
215
fail("IllegalArgumentException not thrown");
217
catch(IllegalArgumentException e){}
221
public static class Test_rrFromWire extends TestCase
223
public void test_basic() throws IOException
225
byte[] raw = new byte[] { 5, '-', '8', '.', '1', '2',
226
6, '1', '2', '3', '.', '0', '7',
228
DNSInput in = new DNSInput(raw);
230
GPOSRecord gr = new GPOSRecord();
232
assertEquals(new Double(-8.12), new Double(gr.getLongitude()));
233
assertEquals(new Double(123.07), new Double(gr.getLatitude()));
234
assertEquals(new Double(0.0), new Double(gr.getAltitude()));
237
public void test_longitude_toosmall() throws IOException
239
byte[] raw = new byte[] { 5, '-', '9', '5', '.', '0',
240
6, '1', '2', '3', '.', '0', '7',
242
DNSInput in = new DNSInput(raw);
244
GPOSRecord gr = new GPOSRecord();
247
fail("WireParseException not thrown");
249
catch(WireParseException e){}
252
public void test_longitude_toobig() throws IOException
254
byte[] raw = new byte[] { 5, '1', '8', '5', '.', '0',
255
6, '1', '2', '3', '.', '0', '7',
257
DNSInput in = new DNSInput(raw);
259
GPOSRecord gr = new GPOSRecord();
262
fail("WireParseException not thrown");
264
catch(WireParseException e){}
267
public void test_latitude_toosmall() throws IOException
269
byte[] raw = new byte[] { 5, '-', '8', '5', '.', '0',
270
6, '-', '1', '9', '0', '.', '0',
272
DNSInput in = new DNSInput(raw);
274
GPOSRecord gr = new GPOSRecord();
277
fail("WireParseException not thrown");
279
catch(WireParseException e){}
282
public void test_latitude_toobig() throws IOException
284
byte[] raw = new byte[] { 5, '-', '8', '5', '.', '0',
285
6, '2', '1', '9', '0', '.', '0',
287
DNSInput in = new DNSInput(raw);
289
GPOSRecord gr = new GPOSRecord();
292
fail("WireParseException not thrown");
294
catch(WireParseException e){}
298
public static class Test_rdataFromString extends TestCase
300
public void test_basic() throws IOException
302
Tokenizer t = new Tokenizer("10.45 171.121212 1010787");
304
GPOSRecord gr = new GPOSRecord();
305
gr.rdataFromString(t, null);
306
assertEquals(new Double(10.45), new Double(gr.getLongitude()));
307
assertEquals(new Double(171.121212), new Double(gr.getLatitude()));
308
assertEquals(new Double(1010787), new Double(gr.getAltitude()));
311
public void test_longitude_toosmall() throws IOException
313
Tokenizer t = new Tokenizer("-100.390 171.121212 1010787");
315
GPOSRecord gr = new GPOSRecord();
317
gr.rdataFromString(t, null);
318
fail("IOException not thrown");
320
catch(IOException e){}
323
public void test_longitude_toobig() throws IOException
325
Tokenizer t = new Tokenizer("90.00001 171.121212 1010787");
327
GPOSRecord gr = new GPOSRecord();
329
gr.rdataFromString(t, null);
330
fail("IOException not thrown");
332
catch(IOException e){}
335
public void test_latitude_toosmall() throws IOException
337
Tokenizer t = new Tokenizer("0.0 -180.01 1010787");
339
GPOSRecord gr = new GPOSRecord();
341
gr.rdataFromString(t, null);
342
fail("IOException not thrown");
344
catch(IOException e){}
347
public void test_latitude_toobig() throws IOException
349
Tokenizer t = new Tokenizer("0.0 180.01 1010787");
351
GPOSRecord gr = new GPOSRecord();
353
gr.rdataFromString(t, null);
354
fail("IOException not thrown");
356
catch(IOException e){}
359
public void test_invalid_string() throws IOException
361
Tokenizer t = new Tokenizer("1.0 2.0 \\435");
363
GPOSRecord gr = new GPOSRecord();
364
gr.rdataFromString(t, null);
366
catch(TextParseException e){}}
369
public void test_rrToString() throws TextParseException
371
String exp = "\"10.45\" \"171.121212\" \"1010787.0\"";
373
GPOSRecord gr = new GPOSRecord(Name.fromString("The.Name."), DClass.IN, 0x123,
374
10.45, 171.121212, 1010787);
375
assertEquals(exp, gr.rrToString());
378
public void test_rrToWire() throws TextParseException
380
GPOSRecord gr = new GPOSRecord(Name.fromString("The.Name."), DClass.IN, 0x123,
381
-10.45, 120.0, 111.0);
383
byte[] exp = new byte[] { 6, '-', '1', '0', '.', '4', '5',
384
5, '1', '2', '0', '.', '0',
385
5, '1', '1', '1', '.', '0' };
387
DNSOutput out = new DNSOutput();
388
gr.rrToWire(out, null, true);
390
byte[] bar = out.toByteArray();
392
assertEquals(exp.length, bar.length);
393
for( int i=0; i<exp.length; ++i){
394
assertEquals("i=" + i, exp[i], bar[i]);
398
public static Test suite()
400
TestSuite s = new TestSuite();
401
s.addTestSuite(Test_Ctor_6arg_doubles.class);
402
s.addTestSuite(Test_Ctor_6arg_Strings.class);
403
s.addTestSuite(Test_rrFromWire.class);
404
s.addTestSuite(Test_rdataFromString.class);
405
s.addTestSuite(GPOSRecordTest.class);