1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
import java.nio.ByteBuffer;
import org.checkerframework.checker.signedness.SignednessUtil;
import org.checkerframework.checker.signedness.qual.*;
public class Utils {
public void getTests(
@Unsigned int uint,
@Signed int sint,
@Unsigned short ushort,
@Signed short sshort,
@Unsigned byte ubyte,
@Signed byte sbyte,
@Unsigned byte[] ubyteArr,
@Signed byte[] sbyteArr,
ByteBuffer b) {
// :: error: (assignment.type.incompatible)
sint = SignednessUtil.getUnsignedInt(b);
uint = SignednessUtil.getUnsignedInt(b);
// :: error: (assignment.type.incompatible)
sshort = SignednessUtil.getUnsignedShort(b);
ushort = SignednessUtil.getUnsignedShort(b);
// :: error: (assignment.type.incompatible)
sbyte = SignednessUtil.getUnsigned(b);
ubyte = SignednessUtil.getUnsigned(b);
// :: error: (argument.type.incompatible)
SignednessUtil.getUnsigned(b, sbyteArr);
SignednessUtil.getUnsigned(b, ubyteArr);
}
public void compTests(
@Unsigned long ulong,
@Signed long slong,
@Unsigned int uint,
@Signed int sint,
@Unsigned short ushort,
@Signed short sshort,
@Unsigned byte ubyte,
@Signed byte sbyte) {
int res;
// :: error: (argument.type.incompatible)
res = Long.compareUnsigned(slong, slong);
// :: error: (argument.type.incompatible)
res = Long.compareUnsigned(slong, ulong);
// :: error: (argument.type.incompatible)
res = Long.compareUnsigned(ulong, slong);
res = Long.compareUnsigned(ulong, ulong);
// :: error: (argument.type.incompatible)
res = Integer.compareUnsigned(sint, sint);
// :: error: (argument.type.incompatible)
res = Integer.compareUnsigned(sint, uint);
// :: error: (argument.type.incompatible)
res = Integer.compareUnsigned(uint, sint);
res = Integer.compareUnsigned(uint, uint);
// :: error: (argument.type.incompatible)
res = SignednessUtil.compareUnsigned(sshort, sshort);
// :: error: (argument.type.incompatible)
res = SignednessUtil.compareUnsigned(sshort, ushort);
// :: error: (argument.type.incompatible)
res = SignednessUtil.compareUnsigned(ushort, sshort);
res = SignednessUtil.compareUnsigned(ushort, ushort);
// :: error: (argument.type.incompatible)
res = SignednessUtil.compareUnsigned(sbyte, sbyte);
// :: error: (argument.type.incompatible)
res = SignednessUtil.compareUnsigned(sbyte, ubyte);
// :: error: (argument.type.incompatible)
res = SignednessUtil.compareUnsigned(ubyte, sbyte);
res = SignednessUtil.compareUnsigned(ubyte, ubyte);
}
public void stringTests(
@Unsigned long ulong,
@Signed long slong,
@Unsigned int uint,
@Signed int sint,
@Unsigned short ushort,
@Signed short sshort,
@Unsigned byte ubyte,
@Signed byte sbyte) {
String res;
// :: error: (argument.type.incompatible)
res = Long.toUnsignedString(slong);
res = Long.toUnsignedString(ulong);
// :: error: (argument.type.incompatible)
res = Long.toUnsignedString(slong, 10);
res = Long.toUnsignedString(ulong, 10);
// :: error: (argument.type.incompatible)
res = Integer.toUnsignedString(sint);
res = Integer.toUnsignedString(uint);
// :: error: (argument.type.incompatible)
res = Integer.toUnsignedString(sint, 10);
res = Integer.toUnsignedString(uint, 10);
// :: error: (argument.type.incompatible)
res = SignednessUtil.toUnsignedString(sshort);
res = SignednessUtil.toUnsignedString(ushort);
// :: error: (argument.type.incompatible)
res = SignednessUtil.toUnsignedString(sshort, 10);
res = SignednessUtil.toUnsignedString(ushort, 10);
// :: error: (argument.type.incompatible)
res = SignednessUtil.toUnsignedString(sbyte);
res = SignednessUtil.toUnsignedString(ubyte);
// :: error: (argument.type.incompatible)
res = SignednessUtil.toUnsignedString(sbyte, 10);
res = SignednessUtil.toUnsignedString(ubyte, 10);
}
public void floatingPointConversionTests(
@Unsigned long ulong,
@Unsigned int uint,
@Unsigned short ushort,
@Unsigned byte ubyte) {
float resFloat;
resFloat = SignednessUtil.toFloat(ubyte);
resFloat = SignednessUtil.toFloat(ushort);
resFloat = SignednessUtil.toFloat(uint);
resFloat = SignednessUtil.toFloat(ulong);
double resDouble;
resDouble = SignednessUtil.toDouble(ubyte);
resDouble = SignednessUtil.toDouble(ushort);
resDouble = SignednessUtil.toDouble(uint);
resDouble = SignednessUtil.toDouble(ulong);
}
}
|