KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > martiansoftware > nailgun > TestLongUtils


1 /*
2
3   Copyright 2004, Martian Software, Inc.
4
5   Licensed under the Apache License, Version 2.0 (the "License");
6   you may not use this file except in compliance with the License.
7   You may obtain a copy of the License at
8
9   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, byte b3) {
30         byte[] buf = new byte[4];
31         LongUtils.toArray(l, buf, 0);
32         assertEquals(b0, buf[0]);
33         assertEquals(b1, buf[1]);
34         assertEquals(b2, buf[2]);
35         assertEquals(b3, buf[3]);
36         assertEquals(l, LongUtils.fromArray(buf, 0));
37     }
38     
39     public void testLongUtils() {
40         testToFromArray(0, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00);
41         testToFromArray(4294967295l, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff);
42         testToFromArray(305419896l, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78);
43     }
44
45 }
46
Popular Tags