001: // -*- Java -*-
002: //
003: // Copyright (c) 2005, Matthew J. Rutherford <rutherfo@cs.colorado.edu>
004: // Copyright (c) 2005, University of Colorado at Boulder
005: // All rights reserved.
006: //
007: // Redistribution and use in source and binary forms, with or without
008: // modification, are permitted provided that the following conditions are
009: // met:
010: //
011: // * Redistributions of source code must retain the above copyright
012: // notice, this list of conditions and the following disclaimer.
013: //
014: // * Redistributions in binary form must reproduce the above copyright
015: // notice, this list of conditions and the following disclaimer in the
016: // documentation and/or other materials provided with the distribution.
017: //
018: // * Neither the name of the University of Colorado at Boulder nor the
019: // names of its contributors may be used to endorse or promote
020: // products derived from this software without specific prior written
021: // permission.
022: //
023: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
024: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
025: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
026: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
027: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
028: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
029: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
030: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
031: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
032: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
033: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
034: //
035: package org.xbill.DNS;
036:
037: import junit.framework.TestCase;
038:
039: public class SerialTest extends TestCase {
040: public void test_compare_NegativeArg1() {
041: long arg1 = -1;
042: long arg2 = 1;
043: try {
044: Serial.compare(arg1, arg2);
045: fail("compare accepted negative argument 1");
046: } catch (IllegalArgumentException e) {
047: // pass
048: }
049: }
050:
051: public void test_compare_OOBArg1() {
052: long arg1 = 0xFFFFFFFFL + 1;
053: long arg2 = 1;
054: try {
055: Serial.compare(arg1, arg2);
056: fail("compare accepted out-of-bounds argument 1");
057: } catch (IllegalArgumentException e) {
058: // pass
059: }
060: }
061:
062: public void test_compare_NegativeArg2() {
063: long arg1 = 1;
064: long arg2 = -1;
065: try {
066: Serial.compare(arg1, arg2);
067: fail("compare accepted negative argument 2");
068: } catch (IllegalArgumentException e) {
069: // pass
070: }
071: }
072:
073: public void test_compare_OOBArg2() {
074: long arg1 = 1;
075: long arg2 = 0xFFFFFFFFL + 1;
076: try {
077: Serial.compare(arg1, arg2);
078: fail("compare accepted out-of-bounds argument 1");
079: } catch (IllegalArgumentException e) {
080: // pass
081: }
082: }
083:
084: public void test_compare_Arg1Greater() {
085: long arg1 = 10;
086: long arg2 = 9;
087: int ret = Serial.compare(arg1, arg2);
088: assertTrue(ret > 0);
089: }
090:
091: public void test_compare_Arg2Greater() {
092: long arg1 = 9;
093: long arg2 = 10;
094: int ret = Serial.compare(arg1, arg2);
095: assertTrue(ret < 0);
096: }
097:
098: public void test_compare_ArgsEqual() {
099: long arg1 = 10;
100: long arg2 = 10;
101: int ret = Serial.compare(arg1, arg2);
102: assertEquals(ret, 0);
103: }
104:
105: public void test_compare_boundary() {
106: long arg1 = 0xFFFFFFFFL;
107: long arg2 = 0;
108: int ret = Serial.compare(arg1, arg2);
109: assertEquals(-1, ret);
110: ret = Serial.compare(arg2, arg1);
111: assertEquals(1, ret);
112: }
113:
114: public void test_increment_NegativeArg() {
115: long arg = -1;
116: try {
117: Serial.increment(arg);
118: fail("increment accepted negative argument");
119: } catch (IllegalArgumentException e) {
120: // pass
121: }
122: }
123:
124: public void test_increment_OOBArg() {
125: long arg = 0xFFFFFFFFL + 1;
126: try {
127: Serial.increment(arg);
128: fail("increment accepted out-of-bounds argument");
129: } catch (IllegalArgumentException e) {
130: // pass
131: }
132: }
133:
134: public void test_increment_reset() {
135: long arg = 0xFFFFFFFFL;
136: long ret = Serial.increment(arg);
137: assertEquals(0, ret);
138: }
139:
140: public void test_increment_normal() {
141: long arg = 10;
142: long ret = Serial.increment(arg);
143: assertEquals(arg + 1, ret);
144: }
145: }
|