Example #1
0
 public static void AssertRoundTrip(CBORObject o)
 {
     CBORObject o2 = FromBytesTestAB(o.EncodeToBytes());
       if (o2.Type == CBORType.Map && o.Type == CBORType.Map) {
     // Skip because key order may be different
       } else {
     if (!o.ToString().Equals(o2.ToString()))
       Assert.AreEqual(o.ToString(), o2.ToString(), "o2 is not equal to o");
       }
       TestNumber(o);
       AssertEqualsHashCode(o, o2);
 }
Example #2
0
 public static string ToByteArrayString(CBORObject obj)
 {
     byte[] bytes = obj.EncodeToBytes();
       StringBuilder sb = new StringBuilder();
       string hex = "0123456789ABCDEF";
       sb.Append("CBORObject.DecodeFromBytes(new byte[]{");
       for (int i = 0; i < bytes.Length; i++) {
     if (i > 0)
       sb.Append(",");
     if ((bytes[i] & 0x80) != 0)
       sb.Append("(byte)0x");
     else
       sb.Append("0x");
     sb.Append(hex[(bytes[i] >> 4) & 0xF]);
     sb.Append(hex[(bytes[i]) & 0xF]);
       }
       sb.Append("})");
       return sb.ToString();
 }
Example #3
0
 public static void AssertSer(CBORObject o, String s)
 {
     if (!s.Equals(o.ToString()))
     Assert.AreEqual(s, o.ToString(), "o is not equal to s");
       // Test round-tripping
       CBORObject o2 = FromBytesTestAB(o.EncodeToBytes());
       if (!s.Equals(o2.ToString()))
     Assert.AreEqual(s, o2.ToString(), "o2 is not equal to s");
       TestNumber(o);
       AssertEqualsHashCode(o, o2);
 }