internal static void ck(BufferN b, long got, long expected) { if (expected != got) { fail(b, expected, got); } }
internal static void fail(BufferN b, String expected, char expectedChar, String got, char gotChar) { if (b is ByteBufferN) { var bb = (ByteBufferN)b; int n = Math.Min(16, bb.limit()); for (int i = 0; i < n; i++) { outt.print(" " + Integer.toHexString(bb.get(i) & 0xff)); } outt.println(); } /*if (b is CharBuffer) { * CharBuffer bb = (CharBuffer)b; * int n = Math.min(16, bb.limit()); * for (int i = 0; i < n; i++) * outt.print(" " + Integer.toHexString(bb.get(i) & 0xffff)); * outt.println(); * }*/ throw new RuntimeException(toString(b) + ": Expected '" + expectedChar + "'=0x" + expected + ", got '" + gotChar + "'=0x" + got); }
internal static void ck(BufferN b, bool cond) { if (!cond) { fail("Condition failed", b); } }
internal static void show(int level, BufferN b) { for (int i = 0; i < level; i++) { outt.print(" "); } outt.println(toString(b) + " " + Integer.toHexString(b.GetHashCode())); }
internal static String toString(BufferN b) { return(b.GetType().Name + "[pos=" + b.position() + " lim=" + b.limit() + " cap=" + b.capacity() + "]"); }
private static void checkInvalidMarkException(BufferN b) { tryCatch(b, typeof(InvalidMarkException), () => { b.mark(); compact(b); b.reset(); }); }
internal static void ck(BufferN b, double got, double expected) { if (expected != got) { fail(b, Double.toString(expected), (char)expected, Double.toString(got), (char)got); } }
internal static void ck(BufferN b, float got, float expected) { if (expected != got) { fail(b, Float.toString(expected), (char)expected, Float.toString(got), (char)got); } }
private static void compact(BufferN b) { /* * try { * Class<?> cl = b.getClass(); * Method m = cl.getDeclaredMethod("compact"); * m.setAccessible(true); * m.invoke(b); * } catch (Exception e) { * fail(e.getMessage(), b); * } */ throw new NotImplementedException(); }
private static void tryCatch(BufferN b, Type ex, Action thunk) { bool caught = false; try { thunk(); } catch (Exception x) { if (ex.IsAssignableFrom(x.GetType())) { caught = true; } else { fail(x.Message + " not expected"); } } if (!caught) { fail(ex.Name + " not thrown", b); } }
internal static void fail(String s, BufferN b, BufferN b2) { throw new RuntimeException(s + ": " + toString(b) + ", " + toString(b2)); }
internal static void fail(BufferN b, long expected, long got) { fail(b, Long.toHexString(expected), (char)expected, Long.toHexString(got), (char)got); }