01: /*
02:
03: Copyright 2004, Martian Software, Inc.
04:
05: Licensed under the Apache License, Version 2.0 (the "License");
06: you may not use this file except in compliance with the License.
07: You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16:
17: */
18:
19: package com.martiansoftware.nailgun;
20:
21: import junit.framework.TestCase;
22:
23: /**
24: *
25: * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
26: */
27: public class TestLongUtils extends TestCase {
28:
29: private void testToFromArray(long l, byte b0, byte b1, byte b2,
30: byte b3) {
31: byte[] buf = new byte[4];
32: LongUtils.toArray(l, buf, 0);
33: assertEquals(b0, buf[0]);
34: assertEquals(b1, buf[1]);
35: assertEquals(b2, buf[2]);
36: assertEquals(b3, buf[3]);
37: assertEquals(l, LongUtils.fromArray(buf, 0));
38: }
39:
40: public void testLongUtils() {
41: testToFromArray(0, (byte) 0x00, (byte) 0x00, (byte) 0x00,
42: (byte) 0x00);
43: testToFromArray(4294967295l, (byte) 0xff, (byte) 0xff,
44: (byte) 0xff, (byte) 0xff);
45: testToFromArray(305419896l, (byte) 0x12, (byte) 0x34,
46: (byte) 0x56, (byte) 0x78);
47: }
48:
49: }
|