Beispiel #1
0
#pragma warning restore CS0618

        public static byte[] CheckEncodeToBytes(CBORObject o)
        {
            byte[] bytes = o.EncodeToBytes();
            if (bytes.Length != o.CalcEncodedSize())
            {
                string msg = "encoded size doesn't match:\no = " +
                             TestCommon.ToByteArrayString(bytes) + "\nostring = " + o.ToString();
                Assert.AreEqual(bytes.Length, o.CalcEncodedSize(), msg);
            }
            return(bytes);
        }
Beispiel #2
0
        public static void AssertJSONSer(CBORObject o, String s)
        {
            if (!s.Equals(o.ToJSONString(), StringComparison.Ordinal))
            {
                Assert.AreEqual(s, o.ToJSONString(), "o is not equal to s");
            }
            // Test round-tripping
            CBORObject o2 = FromBytesTestAB(o.EncodeToBytes());

            if (!s.Equals(o2.ToJSONString(), StringComparison.Ordinal))
            {
                string msg = "o2 is not equal to s:\no = " +
                             TestCommon.ToByteArrayString(o.EncodeToBytes()) +
                             "\no2 = " + TestCommon.ToByteArrayString(o2.EncodeToBytes()) +
                             "\no2string = " + o2.ToString();
                Assert.AreEqual(s, o2.ToJSONString(), msg);
            }
            TestNumber(o);
            TestCommon.AssertEqualsHashCode(o, o2);
        }