13
|
1 |
/** |
|
2 |
* Java RTP Library (jlibrtp) |
|
3 |
* Copyright (C) 2006 Arne Kepp |
|
4 |
* |
|
5 |
* This library is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU Lesser General Public |
|
7 |
* License as published by the Free Software Foundation; either |
|
8 |
* version 2.1 of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This library is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
* Lesser General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU Lesser General Public |
|
16 |
* License along with this library; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
*/ |
|
19 |
package jlibrtp; |
|
20 |
|
|
21 |
|
|
22 |
/** |
|
23 |
* Validates the StaticProcs. |
|
24 |
* |
|
25 |
* @author Arne Kepp |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class ValidateStaticProcs { |
|
29 |
|
|
30 |
/** |
|
31 |
* @param args |
|
32 |
*/ |
|
33 |
public static void main(String[] args) { |
|
34 |
// TODO Auto-generated method stub |
|
35 |
long one = 100; |
|
36 |
long two = 1; |
|
37 |
long three = 9999000; |
|
38 |
|
|
39 |
byte aByte = (byte) 7; |
|
40 |
System.out.println("aByte.hex: " + StaticProcs.hexOfByte(aByte)); |
|
41 |
|
|
42 |
//byte[] oneb = StaticProcs.longToByteWord(one); |
|
43 |
byte[] twob = StaticProcs.uIntLongToByteWord(two); |
|
44 |
//byte[] threeb = StaticProcs.longToByteWord(three); |
|
45 |
|
|
46 |
for(int i = 0; i< 4; i++) { |
|
47 |
StaticProcs.printBits(twob[i]); |
|
48 |
} |
|
49 |
//one = StaticProcs.combineBytes(oneb[0], oneb[1], oneb[2], oneb[3]); |
|
50 |
two = StaticProcs.bytesToUIntLong(twob,0); |
|
51 |
//three = StaticProcs.combineBytes(threeb[0], threeb[1], threeb[2], threeb[3]); |
|
52 |
|
|
53 |
System.out.println(" one " + one + " two " + two + " three " + three); |
|
54 |
|
|
55 |
twob = StaticProcs.uIntLongToByteWord(two); |
|
56 |
|
|
57 |
for(int i = 0; i< 4; i++) { |
|
58 |
StaticProcs.printBits(twob[i]); |
|
59 |
} |
|
60 |
|
|
61 |
byte[] bytes = new byte[2]; |
|
62 |
int check = 0; |
|
63 |
for(int i=0; i< 65536; i++) { |
|
64 |
bytes = StaticProcs.uIntIntToByteWord(i); |
|
65 |
check = StaticProcs.bytesToUIntInt(bytes, 0); |
|
66 |
if(check != i) { |
|
67 |
System.out.println(" oops:" + check +" != "+ i); |
|
68 |
StaticProcs.printBits(bytes[0]); |
|
69 |
StaticProcs.printBits(bytes[1]); |
|
70 |
} |
|
71 |
} |
|
72 |
int a = 65534; |
|
73 |
bytes = StaticProcs.uIntIntToByteWord(a); |
|
74 |
StaticProcs.printBits(bytes[0]); |
|
75 |
StaticProcs.printBits(bytes[1]); |
|
76 |
check = StaticProcs.bytesToUIntInt(bytes, 0); |
|
77 |
System.out.println(check); |
|
78 |
|
|
79 |
byte[] arbytes = new byte[22]; |
|
80 |
arbytes[13] = -127; |
|
81 |
arbytes[14] = 127; |
|
82 |
arbytes[15] = -1; |
|
83 |
arbytes[16] = 127; |
|
84 |
arbytes[17] = -127; |
|
85 |
System.out.println("arbitrary length:"); |
|
86 |
StaticProcs.printBits(arbytes[14]); |
|
87 |
StaticProcs.printBits(arbytes[15]); |
|
88 |
StaticProcs.printBits(arbytes[16]); |
|
89 |
//long arbTest = StaticProcs.bytesToUintLong(arbytes, 14, 16); |
|
90 |
//byte[] reArBytes = StaticProcs.uIntLongToByteWord(arbTest); |
|
91 |
//System.out.println("arbitrary length recode: " + Long.toString(arbTest)); |
|
92 |
//StaticProcs.printBits(reArBytes[0]); |
|
93 |
//StaticProcs.printBits(reArBytes[1]); |
|
94 |
//StaticProcs.printBits(reArBytes[2]); |
|
95 |
//StaticProcs.printBits(reArBytes[3]); |
|
96 |
|
|
97 |
byte[] tmp = new byte[4]; |
|
98 |
tmp[0] = -127; |
|
99 |
tmp[1] = 127; |
|
100 |
tmp[2] = -49; |
|
101 |
tmp[3] = -1; |
|
102 |
|
|
103 |
String str2 = ""; |
|
104 |
for(int i=0; i<tmp.length; i++) { |
|
105 |
str2 += StaticProcs.hexOfByte(tmp[i]); |
|
106 |
} |
|
107 |
System.out.println(str2); |
|
108 |
|
|
109 |
byte temp2[] = str2.getBytes(); |
|
110 |
byte temp4[] = new byte[temp2.length / 2]; |
|
111 |
byte[] temp3 = new byte[2]; |
|
112 |
|
|
113 |
for(int i=0; i<temp4.length; i++) { |
|
114 |
temp3[0] = temp2[i*2]; |
|
115 |
temp3[1] = temp2[i*2+1]; |
|
116 |
temp4[i] = StaticProcs.byteOfHex(temp3); |
|
117 |
} |
|
118 |
|
|
119 |
for(int i=0; i<tmp.length; i++) { |
|
120 |
if(tmp[i] == temp4[i]) { |
|
121 |
System.out.println("ok"); |
|
122 |
} else { |
|
123 |
System.out.println("nope"); |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
} |