public void FromUTF8ByteArrayTest() { foreach (string s in SAMPLES) { byte[] utf8 = IRecordUtil.ToUTF8(s); string ret = IRecordUtil.FromUTF8(utf8); Assert.AreEqual(s, ret); } }
public void CStringLengthByteArrayIntTest() { for (int i = 2; i < 16; i++) { // The null terminated string byte[] s = new byte[i + 1]; FillRandomNonZero(s); s[i] = 0; Assert.AreEqual(i - 1, IRecordUtil.CStringLength(s, 1)); } }
public void ToUTF8Test() { foreach (string s in SAMPLES) { byte[] ret = IRecordUtil.ToUTF8(s); byte[] tmp = Encoding.UTF8.GetBytes(s); byte[] exp = new byte[tmp.Length + 1]; Assert.AreEqual(exp.Length, ret.Length); tmp.CopyTo(exp, 0); Assert.True(exp.SequenceEqual(ret)); } }
public void FromUTF8ByteArrayIntIntTest() { foreach (string s in SAMPLES) { byte[] tmp = IRecordUtil.ToUTF8(s); byte[] utf8 = new byte[tmp.Length + 2]; tmp.CopyTo(utf8, 1); string ret = IRecordUtil.FromUTF8(utf8, 1, tmp.Length - 1); Assert.AreEqual(s, ret); } }
public void CStringLengthByteArrayTest() { Random rand = new Random(); for (int i = 0; i < 16; i++) { // The null terminated string byte[] s = new byte[i + 1]; for (int j = 0; j < i; j++) { s[j] = (byte)(rand.Next(255) + 1); } Assert.AreEqual(i, IRecordUtil.CStringLength(s)); } }
public void IRGetVersionTest() { int retval; byte[] version; int versionSize = 0; retval = IRecordDll.IRGetVersion(ref versionSize, null); Assert.AreEqual(IRErrorCode.IRE_BUFFER_TOO_SHORT, (IRErrorCode)retval); version = new byte[versionSize]; retval = IRecordDll.IRGetVersion(ref versionSize, version); Assert.AreEqual(IRErrorCode.IRE_SUCCESS, (IRErrorCode)retval); Assert.AreEqual(versionSize - 1, IRecordUtil.CStringLength(version)); Assert.AreEqual("0.1.0.0", IRecordUtil.FromUTF8(version)); }