Esempio n. 1
0
    public static void TestCompareTo()
    {
        EI8 e = EI8.One;
        int result;

        // Special case: All values are "greater than" null.
        Object other = null;

        result = e.CompareTo(other);
        Assert.Equal(result, 1);

        try
        {
            sbyte b = 1;
            result = e.CompareTo(b);
            Assert.True(false, "CompareTo should have failed.");
        }
        catch (ArgumentException)
        {
        }

        other  = EI8.One;
        result = e.CompareTo(other);
        Assert.Equal(result, 0);
        other  = (EI8)(0);
        result = e.CompareTo(other);
        Assert.True(result > 0);
        other  = (EI8)(2);
        result = e.CompareTo(other);
        Assert.True(result < 0);
    }
Esempio n. 2
0
    public static void TestToObject()
    {
        Object o;

        o = 3;

        try
        {
            Enum.ToObject(null, o);
            Assert.True(false, "ToObject() should have thrown.");
        }
        catch (ArgumentNullException)
        {
        }

        o = null;
        try
        {
            Enum.ToObject(typeof(EI8), o);
            Assert.True(false, "ToObject() should have thrown.");
        }
        catch (ArgumentNullException)
        {
        }

        o = 1;
        try
        {
            Enum.ToObject(typeof(Enum), o);
            Assert.True(false, "ToObject() should have thrown.");
        }
        catch (ArgumentException)
        {
        }

        try
        {
            o = "Hello";
            Enum.ToObject(typeof(EI8), o);
            Assert.True(false, "ToObject() should have thrown.");
        }
        catch (ArgumentException)
        {
        }

        TestToObjectVerifySuccess <EI8, sbyte>(42);
        TestToObjectVerifySuccess <EI8, EI8>((EI8)0x42);
        TestToObjectVerifySuccess <EU64, ulong>(0x0123456789abcdefL);

        ulong l = 0x0ccccccccccccc2aL;
        EI8   e = (EI8)(Enum.ToObject(typeof(EI8), l));

        Assert.True((sbyte)e == 0x2a);
    }
Esempio n. 3
0
    public static void TestCompareTo()
    {
        EI8 e = EI8.One;

        // Special case: All values are "greater than" null.
        Assert.Equal(1, e.CompareTo(null));

        Assert.Throws <ArgumentException>(() => e.CompareTo((sbyte)1));

        Assert.Equal(0, e.CompareTo(EI8.One));
        Assert.InRange(e.CompareTo((EI8)0), 1, int.MaxValue);
        Assert.InRange(e.CompareTo((EI8)2), int.MinValue, -1);
    }
Esempio n. 4
0
    public static void TestToObject()
    {
        Assert.Throws <ArgumentNullException>(() => Enum.ToObject(null, 3));
        Assert.Throws <ArgumentNullException>(() => Enum.ToObject(typeof(EI8), null));
        Assert.Throws <ArgumentException>(() => Enum.ToObject(typeof(Enum), 1));
        Assert.Throws <ArgumentException>(() => Enum.ToObject(typeof(EI8), "Hello"));

        TestToObjectVerifySuccess <EI8, sbyte>(42);
        TestToObjectVerifySuccess <EI8, EI8>((EI8)0x42);
        TestToObjectVerifySuccess <EU64, ulong>(0x0123456789abcdefL);

        ulong l = 0x0ccccccccccccc2aL;
        EI8   e = (EI8)(Enum.ToObject(typeof(EI8), l));

        Assert.True((sbyte)e == 0x2a);
    }