Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
       }
 }