Exemplo n.º 1
0
        public void TestOidParser(Byte[] expectedBytes, String oidString)
        {
            oidBytes.Clear();
            Console.WriteLine("Testing '{0}'", oidString);
            Snmp.ParseOid(oidString, oidBytes);

            Byte[] actual = oidBytes.ToArray();
            String diff   = Sos.Diff(expectedBytes, actual);

            if (diff != null)
            {
                Console.WriteLine("Expected: " + expectedBytes.SerializeObject());
                Console.WriteLine("Actual  : " + actual.SerializeObject());
                Assert.Fail(diff);
            }
        }
Exemplo n.º 2
0
        public void TestHexStrings()
        {
            Byte[][] testArrays = new Byte[][] {
                new Byte[] {},
                new Byte[] { 0 },
                new Byte[] { 0, 1, 2, 3 },
                new Byte[] { 0xFF, 0xFE },
                new Byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 },
            };

            for (int i = 0; i < testArrays.Length; i++)
            {
                Byte[] testArray = testArrays[i];

                String hexString = testArray.ToHexString(0, testArray.Length);
                Console.WriteLine("Testing {0}", hexString);

                Byte[] deserializeCopy = new Byte[testArray.Length];
                deserializeCopy.ParseHex(0, hexString, 0, hexString.Length);

                Sos.Diff(testArray, deserializeCopy);
            }
        }
Exemplo n.º 3
0
        public void TestKnownHashes()
        {
            TestClass[] tests = new TestClass[] {
                new TestClass("abc", 0xA9993E36, 0x4706816A, 0xBA3E2571, 0x7850C26C, 0x9Cd0d89D),
                new TestClass("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
                              0x84983E44, 0x1C3BD26E, 0xBAAE4AA1, 0xF95129E5, 0xE54670F1),
                new TestClass("12345678901234567890123456789012345678901234567890123456789012345678901234567890",
                              0x50ABF570, 0x6A150990, 0xA08B2C5E, 0xA40FA0E5, 0x85554732),
                new TestClass("jafdnznjkl89fn4q3poiunqn8vrnaru8apr8umpau8rfpnu312--1-0-139-110un45paiouwepiourpoqiwrud0-ur238901unmxd-0r1u-rdu0-12u3rm-u-uqfoprufquwioperupauwperuq2cfurq2urduq;w3uirmparuw390peuaf;wuir;oui;avuwao; aro aruawrv au;ru ;aweuriafuwer23f0quprmpuqpuqurq[0q5tau=53una54fion[5cnuq30m5uq903uqncf4",
                              0xEEC53E5E, 0x78191154, 0x0A073AE1, 0x39743E68, 0x8A6CD077),
            };

            Sha1Builder reusedShaBuilder = new Sha1Builder();

            for (int i = 0; i < tests.Length; i++)
            {
                TestClass test = tests[i];

                //
                // Test using 1 call
                //
                {
                    Sha1Builder newShaBuilder = new Sha1Builder();

                    newShaBuilder.Add(test.contentBytes, 0, test.contentBytes.Length);
                    reusedShaBuilder.Add(test.contentBytes, 0, test.contentBytes.Length);

                    var newFinished    = newShaBuilder.Finish(false);
                    var reusedFinished = reusedShaBuilder.Finish(true);

                    Console.WriteLine("Content '{0}'", test.contentString);
                    Console.WriteLine("    Expected {0}", test.expectedHash);
                    Console.WriteLine("    Actual   {0}", newFinished);
                    Console.WriteLine("    Reused   {0}", reusedFinished);

                    Assert.AreEqual(test.expectedHash, newFinished);
                    Assert.AreEqual(test.expectedHash, reusedFinished);
                    //String sosDiff = Sos.Diff(test.expectedHash, finished);
                    //Assert.IsNull(sosDiff, sosDiff);
                }

                //
                // Test using multiple calls
                //
                for (int addLength = 1; addLength < test.contentBytes.Length; addLength++)
                {
                    Console.WriteLine("Test AddLength {0}", addLength);
                    Sha1Builder shaBuilder = new Sha1Builder();

                    // Add the bytes
                    Int32 bytesToWrite       = test.contentBytes.Length;
                    Int32 contentBytesOffset = 0;
                    while (bytesToWrite > 0)
                    {
                        Int32 writeLength = Math.Min(bytesToWrite, addLength);
                        shaBuilder.Add(test.contentBytes, contentBytesOffset, writeLength);
                        reusedShaBuilder.Add(test.contentBytes, contentBytesOffset, writeLength);
                        contentBytesOffset += writeLength;
                        bytesToWrite       -= writeLength;
                    }

                    var shaFinished       = shaBuilder.Finish(false);
                    var reusedShaFinished = reusedShaBuilder.Finish(true);

                    var sosDiff = Sos.Diff(test.expectedHash, shaFinished);
                    if (sosDiff != null)
                    {
                        Console.WriteLine("Content '{0}'", test.contentString);
                        Console.WriteLine("    Expected {0}", test.expectedHash);
                        Console.WriteLine("    Actual   {0}", shaFinished);
                        Assert.Fail();
                    }
                    Assert.AreEqual(test.expectedHash, shaFinished);
                    Assert.AreEqual(test.expectedHash, reusedShaFinished);
                }
            }
        }