示例#1
0
        public void TestConstructorSignificantDigits(int significantDigits)
        {
            const float Value1 = 1.234567f;
            const float Value2 = 7.654321f;

            var sut = new FloatMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, significantDigits, Value1, Value2, BitConverter);

            Check.That(sut.Value1).IsEqualTo((float)Math.Round(Value1, significantDigits, MidpointRounding.AwayFromZero));
            Check.That(sut.Value2).IsEqualTo((float)Math.Round(Value2, significantDigits, MidpointRounding.AwayFromZero));
        }
示例#2
0
        public void TestConstructor(ScanCompareType compareType, ScanRoundMode roundMode, float value1, float value2)
        {
            var sut = new FloatMemoryComparer(compareType, roundMode, 1, value1, value2, BitConverter);

            Check.That(sut.CompareType).IsEqualTo(compareType);
            Check.That(sut.RoundType).IsEqualTo(roundMode);
            Check.That(sut.ValueSize).IsEqualTo(sizeof(float));
            Check.That(sut.Value1).IsOneOf(value1, value2);
            Check.That(sut.Value2).IsOneOf(value1, value2);
        }
示例#3
0
        public void TestCompare(ScanCompareType compareType, float value1, float value2, byte[] data, bool expectedResult, ScanResult expectedScanResult)
        {
            var sut = new FloatMemoryComparer(compareType, ScanRoundMode.Normal, 1, value1, value2, BitConverter);

            Check.That(sut.Compare(data, 0, out var scanResult)).IsEqualTo(expectedResult);
            Check.That(scanResult).IsEqualTo(expectedScanResult);
            if (scanResult != null)
            {
                Check.That(scanResult).IsInstanceOf <FloatScanResult>();
            }
        }
示例#4
0
        private void searchForEqualValuesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var selectedNode = memoryViewControl.GetSelectedNodes().FirstOrDefault();

            if (selectedNode == null)
            {
                return;
            }

            IScanComparer comparer;

            switch (selectedNode.Node)
            {
            case BaseHexNode node:
                comparer = new ArrayOfBytesMemoryComparer(node.ReadValueFromMemory(selectedNode.Memory));
                break;

            case FloatNode node:
                comparer = new FloatMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case DoubleNode node:
                comparer = new DoubleMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case Int8Node node:
                comparer = new ByteMemoryComparer(ScanCompareType.Equal, (byte)node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case UInt8Node node:
                comparer = new ByteMemoryComparer(ScanCompareType.Equal, node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case Int16Node node:
                comparer = new ShortMemoryComparer(ScanCompareType.Equal, node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case UInt16Node node:
                comparer = new ShortMemoryComparer(ScanCompareType.Equal, (short)node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case Int32Node node:
                comparer = new IntegerMemoryComparer(ScanCompareType.Equal, node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case UInt32Node node:
                comparer = new IntegerMemoryComparer(ScanCompareType.Equal, (int)node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case Int64Node node:
                comparer = new LongMemoryComparer(ScanCompareType.Equal, node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case UInt64Node node:
                comparer = new LongMemoryComparer(ScanCompareType.Equal, (long)node.ReadValueFromMemory(selectedNode.Memory), 0);
                break;

            case Utf8TextNode node:
                comparer = new StringMemoryComparer(node.ReadValueFromMemory(selectedNode.Memory), Encoding.UTF8, true);
                break;

            case Utf16TextNode node:
                comparer = new StringMemoryComparer(node.ReadValueFromMemory(selectedNode.Memory), Encoding.Unicode, true);
                break;

            case Utf32TextNode node:
                comparer = new StringMemoryComparer(node.ReadValueFromMemory(selectedNode.Memory), Encoding.UTF32, true);
                break;

            default:
                return;
            }

            LinkedWindowFeatures.StartMemoryScan(comparer);
        }
示例#5
0
        public void TestCompareInvalidCompareTypeThrows(ScanCompareType compareType)
        {
            var sut = new FloatMemoryComparer(compareType, ScanRoundMode.Normal, 1, 0.0f, 0.0f, BitConverter);

            Check.ThatCode(() => sut.Compare(BitConverter.GetBytes(0.0f), 0, out _)).Throws <InvalidCompareTypeException>();
        }
示例#6
0
        public void TestCompareWithPreviousThrows()
        {
            var sut = new FloatMemoryComparer(ScanCompareType.Unknown, ScanRoundMode.Normal, 1, 0, 0, BitConverter);

            Check.ThatCode(() => sut.Compare(BitConverter.GetBytes(0.0f), 0, new FloatScanResult(0.0f), out _)).Throws <InvalidCompareTypeException>();
        }
示例#7
0
        public void TestCompareInvalidDataThrows(byte[] data, int index, Type expectedExceptionType)
        {
            var sut = new FloatMemoryComparer(ScanCompareType.Unknown, ScanRoundMode.Normal, 1, 0.0f, 0.0f, BitConverter);

            Check.ThatCode(() => sut.Compare(data, index, out _)).ThrowsType(expectedExceptionType);
        }