示例#1
0
 public void SetFloatWithValueOfOneMatches()
 {
     FloatInfo fi = new FloatInfo();
     fi.SetFloat(1.0f);
     // Main values
     Assert.AreEqual(1065353216, fi.IntValue, "IntValue does not match");
     Assert.AreEqual(1.0f, fi.FloatValue, "FloatValue does not match");
     // Component value: sign, exponent, mantissa
     Assert.AreEqual(false, fi.IsSmallNumber, "IsSmallNumber does not match");
     Assert.AreEqual(false, fi.Sign, "Sign does not match");
     Assert.AreEqual(127, fi.Exponent, "Exponent does not match");
     Assert.AreEqual(0, fi.ExponentBiased, "ExponentBiased does not match");
     Assert.AreEqual(0, fi.Significand, "Significand does not match");
     // String values
     Assert.AreEqual("1", fi.FloatString, "FloatString does not match");
     Assert.AreEqual("1065353216", fi.IntString, "IntString does not match");
     Assert.AreEqual("3F800000", fi.HexString, "HexString does not match");
     // Bit values
 }
示例#2
0
        public void SetFloatWithValueOfOneMatches()
        {
            FloatInfo fi = new FloatInfo();

            fi.SetFloat(1.0f);
            // Main values
            Assert.AreEqual(1065353216, fi.IntValue, "IntValue does not match");
            Assert.AreEqual(1.0f, fi.FloatValue, "FloatValue does not match");
            // Component value: sign, exponent, mantissa
            Assert.AreEqual(false, fi.IsSmallNumber, "IsSmallNumber does not match");
            Assert.AreEqual(false, fi.Sign, "Sign does not match");
            Assert.AreEqual(127, fi.Exponent, "Exponent does not match");
            Assert.AreEqual(0, fi.ExponentBiased, "ExponentBiased does not match");
            Assert.AreEqual(0, fi.Significand, "Significand does not match");
            // String values
            Assert.AreEqual("1", fi.FloatString, "FloatString does not match");
            Assert.AreEqual("1065353216", fi.IntString, "IntString does not match");
            Assert.AreEqual("3F800000", fi.HexString, "HexString does not match");
            // Bit values
        }
示例#3
0
 public void SetInt32WithValueOfZeroMatches()
 {
     FloatInfo fi = new FloatInfo();
     fi.SetInt32(0);
     // Main values
     Assert.AreEqual(0, fi.IntValue, "IntValue does not match");
     Assert.AreEqual(0.0, fi.FloatValue, "FloatValue does not match");
     // Component value: sign, exponent, mantissa
     Assert.AreEqual(false, fi.Sign, "Sign does not match");
     Assert.AreEqual(0, fi.Exponent, "Exponent does not match");
     Assert.AreEqual(-127, fi.ExponentBiased, "ExponentBiased does not match");
     Assert.AreEqual(0, fi.Significand, "Significand does not match");
     // String values
     Assert.AreEqual("0", fi.FloatString, "FloatString does not match");
     Assert.AreEqual("0", fi.IntString, "IntString does not match");
     Assert.AreEqual("00000000", fi.HexString, "HexString does not match");
     // Bit values
     for (int ii = 0; ii < FloatInfo.TotalBits; ii++)
     {
         Assert.AreEqual(false, fi.Bits[ii], "Bits[" + ii.ToString() + "] does not match");
     }
 }
示例#4
0
        public void SetInt32WithValueOfZeroMatches()
        {
            FloatInfo fi = new FloatInfo();

            fi.SetInt32(0);
            // Main values
            Assert.AreEqual(0, fi.IntValue, "IntValue does not match");
            Assert.AreEqual(0.0, fi.FloatValue, "FloatValue does not match");
            // Component value: sign, exponent, mantissa
            Assert.AreEqual(false, fi.Sign, "Sign does not match");
            Assert.AreEqual(0, fi.Exponent, "Exponent does not match");
            Assert.AreEqual(-127, fi.ExponentBiased, "ExponentBiased does not match");
            Assert.AreEqual(0, fi.Significand, "Significand does not match");
            // String values
            Assert.AreEqual("0", fi.FloatString, "FloatString does not match");
            Assert.AreEqual("0", fi.IntString, "IntString does not match");
            Assert.AreEqual("00000000", fi.HexString, "HexString does not match");
            // Bit values
            for (int ii = 0; ii < FloatInfo.TotalBits; ii++)
            {
                Assert.AreEqual(false, fi.Bits[ii], "Bits[" + ii.ToString() + "] does not match");
            }
        }
示例#5
0
        private ConstantPoolInfo[] ParseConstantPool(ref ReadOnlySpan <byte> fileData)
        {
            ushort poolCount = fileData.ReadTwoBytes();

            var infos = new ConstantPoolInfo[poolCount];

            for (int i = 1; i < poolCount; i++)
            {
                var tag = (ConstantPoolTag)fileData.ReadOneByte();
                switch (tag)
                {
                case ConstantPoolTag.Class:
                    infos[i] = new ClassInfo(ref fileData);
                    break;

                case ConstantPoolTag.Fieldref:
                    infos[i] = new FieldrefInfo(ref fileData);
                    break;

                case ConstantPoolTag.Methodref:
                    infos[i] = new MethodrefInfo(ref fileData);
                    break;

                case ConstantPoolTag.InterfaceMethodref:
                    infos[i] = new InterfaceMethodrefInfo(ref fileData);
                    break;

                case ConstantPoolTag.String:
                    infos[i] = new StringInfo(ref fileData);
                    break;

                case ConstantPoolTag.Integer:
                    infos[i] = new IntegerInfo(ref fileData);
                    break;

                case ConstantPoolTag.Float:
                    infos[i] = new FloatInfo(ref fileData);
                    break;

                case ConstantPoolTag.Long:
                    infos[i] = new LongInfo(ref fileData);
                    i++;
                    break;

                case ConstantPoolTag.Double:
                    infos[i] = new DoubleInfo(ref fileData);
                    i++;
                    break;

                case ConstantPoolTag.NameAndType:
                    infos[i] = new NameAndTypeInfo(ref fileData);
                    break;

                case ConstantPoolTag.Utf8:
                    infos[i] = new Utf8Info(ref fileData);
                    break;

                case ConstantPoolTag.MethodHandle:
                    fileData.ReadOneByte();
                    fileData.ReadTwoBytes();
                    break;

                case ConstantPoolTag.MethodType:
                    fileData.ReadTwoBytes();
                    break;

                case ConstantPoolTag.InvokeDynamic:
                    fileData.ReadFourBytes();
                    break;

                default:
                    throw new InvalidDataException();
                }
            }

            foreach (ConstantPoolInfo info in infos)
            {
                info?.Init(infos);
            }

            return(infos);
        }