Esempio n. 1
0
        public static void DoTestLong(long value)
        {
            String     b   = "i" + TestCommon.LongToString(value) + "e";
            CBORObject beo = EncodingFromBytes(DataUtilities.GetUtf8Bytes(b, false));

            Assert.AreEqual(value, beo.AsInt64());
            String newb = DataUtilities.GetUtf8String(EncodingToBytes(beo), false);

            Assert.AreEqual(b, newb);
        }
Esempio n. 2
0
#pragma warning disable CS0618
        public static void TestNumber(CBORObject o)
        {
            if (o.Type != CBORType.Number)
            {
                return;
            }
            if (o.IsPositiveInfinity() || o.IsNegativeInfinity() ||
                o.IsNaN())
            {
                try {
                    o.AsByte();
                    Assert.Fail("Should have failed");
                } catch (OverflowException) {
                    // NOTE: Intentionally empty
                } catch (Exception ex) {
                    Assert.Fail("Object: " + o + ", " + ex);
                    throw new InvalidOperationException(String.Empty, ex);
                }
                try {
                    o.AsInt16();
                    Assert.Fail("Should have failed");
                } catch (OverflowException) {
                    // NOTE: Intentionally empty
                } catch (Exception ex) {
                    Assert.Fail("Object: " + o + ", " + ex);
                    throw new InvalidOperationException(String.Empty, ex);
                }
                try {
                    o.AsInt32();
                    Assert.Fail("Should have failed");
                } catch (OverflowException) {
                    // NOTE: Intentionally empty
                } catch (Exception ex) {
                    Assert.Fail("Object: " + o + ", " + ex);
                    throw new InvalidOperationException(String.Empty, ex);
                }
                try {
                    o.AsInt64();
                    Assert.Fail("Should have failed");
                } catch (OverflowException) {
                    // NOTE: Intentionally empty
                } catch (Exception ex) {
                    Assert.Fail("Object: " + o + ", " + ex);
                    throw new InvalidOperationException(String.Empty, ex);
                }
                try {
                    o.AsSingle();
                } catch (Exception ex) {
                    Assert.Fail(ex.ToString());
                    throw new InvalidOperationException(String.Empty, ex);
                }
                try {
                    o.AsDouble();
                } catch (Exception ex) {
                    Assert.Fail(ex.ToString());
                    throw new InvalidOperationException(String.Empty, ex);
                }
                try {
                    o.AsEInteger();
                    Assert.Fail("Should have failed");
                } catch (OverflowException) {
                    // NOTE: Intentionally empty
                } catch (Exception ex) {
                    Assert.Fail("Object: " + o + ", " + ex);
                    throw new InvalidOperationException(String.Empty, ex);
                }
                return;
            }
            try {
                o.AsSingle();
            } catch (Exception ex) {
                Assert.Fail("Object: " + o + ", " + ex);
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                o.AsDouble();
            } catch (Exception ex) {
                Assert.Fail("Object: " + o + ", " + ex);
                throw new InvalidOperationException(String.Empty, ex);
            }
        }
Esempio n. 3
0
 public static void TestNumber(CBORObject o)
 {
     if (o.Type != CBORType.Number) {
     return;
       }
       if (o.IsPositiveInfinity() || o.IsNegativeInfinity() ||
       o.IsNaN()) {
     try {
       o.AsByte();
       Assert.Fail("Should have failed");
     } catch (OverflowException) {
       new Object();
     } catch (Exception ex) {
       Assert.Fail("Object: " + o + ", " + ex); throw new
     InvalidOperationException(String.Empty, ex);
     }
     try {
       o.AsInt16();
       Assert.Fail("Should have failed");
     } catch (OverflowException) {
       new Object();
     } catch (Exception ex) {
       Assert.Fail("Object: " + o + ", " + ex); throw new
     InvalidOperationException(String.Empty, ex);
     }
     try {
       o.AsInt32();
       Assert.Fail("Should have failed");
     } catch (OverflowException) {
       new Object();
     } catch (Exception ex) {
       Assert.Fail("Object: " + o + ", " + ex); throw new
     InvalidOperationException(String.Empty, ex);
     }
     try {
       o.AsInt64();
       Assert.Fail("Should have failed");
     } catch (OverflowException) {
       new Object();
     } catch (Exception ex) {
       Assert.Fail("Object: " + o + ", " + ex); throw new
     InvalidOperationException(String.Empty, ex);
     }
     try {
       o.AsSingle();
     } catch (Exception ex) {
       Assert.Fail(ex.ToString());
       throw new InvalidOperationException(String.Empty, ex);
     }
     try {
       o.AsDouble();
     } catch (Exception ex) {
       Assert.Fail(ex.ToString());
       throw new InvalidOperationException(String.Empty, ex);
     }
     try {
       o.AsEInteger();
       Assert.Fail("Should have failed");
     } catch (OverflowException) {
       new Object();
     } catch (Exception ex) {
       Assert.Fail("Object: " + o + ", " + ex); throw new
     InvalidOperationException(String.Empty, ex);
     }
     return;
       }
       try {
     o.AsSingle();
       } catch (Exception ex) {
     Assert.Fail("Object: " + o + ", " + ex); throw new
       InvalidOperationException(String.Empty, ex);
       }
       try {
     o.AsDouble();
       } catch (Exception ex) {
     Assert.Fail("Object: " + o + ", " + ex); throw new
       InvalidOperationException(String.Empty, ex);
       }
 }