Esempio n. 1
0
        public void Xor()
        {
            var a = new TestingCollection <byte[], byte[], byte[]>
            {
                new BaBaBaTestItem(Ba(0x01), Ba(0x00), Ba(0x01)),
                new BaBaBaTestItem(Ba(0x00), Ba(0x01), Ba(0x01)),
                new BaBaBaTestItem(Ba(0x00), Ba(0x00), Ba(0x00)),
                new BaBaBaTestItem(Ba(0x01), Ba(0x01), Ba(0x00)),
                new BaBaBaTestItem(Ba(0x00, 0x00), Ba(0x00, 0x00), Ba(0x00, 0x00)),
                new BaBaBaTestItem(Ba(0x00, 0x00), Ba(0x00, 0x01), Ba(0x00, 0x01)),
                new BaBaBaTestItem(Ba(0x00, 0x01), Ba(0x00, 0x00), Ba(0x00, 0x01)),
                new BaBaBaTestItem(Ba(0x00, 0x01), Ba(0x00, 0x00), Ba(0x00, 0x01)),
                new BaBaBaTestItem(Ba(0x00, 0x00), Ba(0x00, 0x01), Ba(0x00, 0x01)),
                new BaBaBaTestItem(Ba(0x01, 0x01), Ba(0x01, 0x00), Ba(0x00, 0x01)),
                new BaBaBaTestItem(Ba(0xF0, 0x00), Ba(0x0F, 0x01), Ba(0xFF, 0x01)),
                new BaBaBaTestItem(Ba(0x80, 0xF1), Ba(0x00, 0x0E), Ba(0x80, 0xFF)),
                new BaBaBaTestItem(Ba(0x00, 0xF1, 0x00), Ba(0x00, 0x00, 0x00), Ba(0x00, 0xF1, 0x00)),
                new BaBaBaTestItem(Ba(0x00, 0xF1, 0x00, 0x01), Ba(0x00, 0x00, 0x00, 0x00), Ba(0x00, 0xF1, 0x00, 0x01)),
                new BaBaBaTestItem(Ba(0x00, 0xF1, 0x00, 0x00), Ba(0x00, 0x0E, 0x00, 0x00), Ba(0x00, 0xFF, 0x00, 0x00)),
                new BaBaBaTestItem(Ba(0x00, 0xF1, 0x01, 0xF0), Ba(0x00, 0x00, 0x0E, 0x00), Ba(0x00, 0xF1, 0x0F, 0xF0)),
                new BaBaBaTestItem(Ba(0x00, 0xF1, 0x00, 0x0F), Ba(0x00, 0xF1, 0x00, 0x00), Ba(0x00, 0x00, 0x00, 0x0F))
            };

            foreach (var i in a)
            {
                byte[] actual = i.ToTest1.Xor(i.ToTest2);
                Debug.WriteLine("Testing: " + BitConverter.ToString(i.ToTest1));
                Debug.WriteLine("       ^ " + BitConverter.ToString(i.ToTest2));
                Debug.WriteLine("     --> " + BitConverter.ToString(actual));
                Assert.AreEqual(i.Expected.Length, actual.Length);
                Assert.IsTrue(i.Expected.SequenceEqual(actual));
            }
        }
Esempio n. 2
0
        public void Not()
        {
            var a = new TestingCollection <byte[], byte[]> {
                new BaBaTestItem(Ba(0xFF, 0xFF, 0xFF, 0x00), Ba(0x00, 0x00, 0x00, 0xFF)),
                new BaBaTestItem(Ba(0xFF, 0xFF, 0xFF, 0x01), Ba(0x00, 0x00, 0x00, 0xFE)),
                new BaBaTestItem(Ba(0xFF, 0xFF, 0xFF, 0xF0), Ba(0x00, 0x00, 0x00, 0x0F)),
                new BaBaTestItem(Ba(0xFF, 0xFF, 0xFF, 0xF9), Ba(0x00, 0x00, 0x00, 0x06)),
                new BaBaTestItem(Ba(0xFF, 0xFF, 0xFF, 0xF0), Ba(0x00, 0x00, 0x00, 0x0F)),
                new BaBaTestItem(Ba(0xFF, 0xFF, 0xFF, 0xF2), Ba(0x00, 0x00, 0x00, 0x0D)),
                new BaBaTestItem(Ba(0xFF, 0xFF, 0x00, 0x00), Ba(0x00, 0x00, 0xFF, 0xFF)),
                new BaBaTestItem(Ba(0xFF, 0xFF, 0x01, 0x00), Ba(0x00, 0x00, 0xFE, 0xFF)),
                new BaBaTestItem(Ba(0xFF, 0x00, 0xFF, 0xF2), Ba(0x00, 0xFF, 0x00, 0x0D)),
                new BaBaTestItem(Ba(0x00, 0xFF, 0xFF, 0xFF), Ba(0xFF, 0x00, 0x00, 0x00)),
                new BaBaTestItem(Ba(0x00, 0x00, 0xFF, 0xF2), Ba(0xFF, 0xFF, 0x00, 0x0D)),
                new BaBaTestItem(Ba(0xAA, 0xAA, 0xAA, 0xAA), Ba(0x55, 0x55, 0x55, 0x55)),
                new BaBaTestItem(Ba(0x0F, 0x00, 0x10), Ba(0xF0, 0xFF, 0xEF)),
                new BaBaTestItem(Ba(0x0F, 0xF0), Ba(0xF0, 0x0F)),
                new BaBaTestItem(Ba(0x1F, 0x13), Ba(0xE0, 0xEC)),
                new BaBaTestItem(Ba(0x00), Ba(0xFF)),
                new BaBaTestItem(Ba(0x0F), Ba(0xF0))
            };

            foreach (var i in a)
            {
                byte[] inversed = i.ToTest1.Not();
                Debug.WriteLine("Testing: " + BitConverter.ToString(i.Expected) + "\r\n     --> " + BitConverter.ToString(inversed));
                Assert.AreEqual(i.Expected.Length, inversed.Length);
                Assert.IsTrue(i.Expected.SequenceEqual(inversed), BitConverter.ToString(inversed) + " != " + BitConverter.ToString(i.Expected));
            }
        }
Esempio n. 3
0
        public void BitStreamFromRight()
        {
            var a = new TestingCollection <byte[], string> {
                new BaSTestItem(Ba(0x00, 0x00, 0x00, 0x01), "00000000000000000000000000000001"),
                new BaSTestItem(Ba(0x00, 0x00, 0x00, 0x80), "00000000000000000000000010000000"),
                new BaSTestItem(Ba(0x80, 0x00, 0x00, 0x80), "10000000000000000000000010000000"),
                new BaSTestItem(Ba(0xFF, 0x00, 0x00, 0x80), "11111111000000000000000010000000"),
                new BaSTestItem(Ba(0xFF, 0x00, 0x01, 0x80), "11111111000000000000000110000000"),
                new BaSTestItem(Ba(0xFF, 0x02, 0x01, 0x80), "11111111000000100000000110000000")
            };

            foreach (var item in a)
            {
                byte[] mask = item.ToTest1;
                var    str  = item.Expected.Reverse();
                int    i    = 0;
                var    bits = mask.ToBitStream(false);
                foreach (var b in bits)
                {
                    Debug.Write(b ? '1' : '0');
                    Assert.AreEqual(str[i], b ? '1' : '0');
                    ++i;
                }
                Debug.WriteLine(".");
            }
        }
Esempio n. 4
0
        public void RepresentsValidNetMask()
        {
            var a = new TestingCollection <byte[], bool> {
                new BaBTestItem(Ba(0xFF, 0xFF, 0xFF, 0x00), true),
                new BaBTestItem(Ba(0xFF, 0xFF, 0xFF, 0x01), false),
                new BaBTestItem(Ba(0xFF, 0xFF, 0xFF, 0xF8), true),
                new BaBTestItem(Ba(0xFF, 0xFF, 0xFF, 0xF9), false),
                new BaBTestItem(Ba(0xFF, 0xFF, 0xFF, 0xF0), true),
                new BaBTestItem(Ba(0xFF, 0xFF, 0xFF, 0xF2), false),
                new BaBTestItem(Ba(0xFF, 0xFF, 0x00, 0x00), true),
                new BaBTestItem(Ba(0xFF, 0xFF, 0x01, 0x00), false),
                new BaBTestItem(Ba(0xFF, 0x00, 0xFF, 0xF2), false),
                new BaBTestItem(Ba(0x00, 0xFF, 0xFF, 0xFF), false),
                new BaBTestItem(Ba(0x00, 0x00, 0xFF, 0xF2), false)
            };
            int index = 0;

            foreach (var i in a)
            {
                bool isValid = i.ToTest1.RepresentsValidNetMask();
                Debug.WriteLine("Testing " + BitConverter.ToString(i.ToTest1));
                Assert.AreEqual(i.Expected, isValid);
                ++index;
            }
        }
Esempio n. 5
0
        public void Cidr()
        {
            var a = new TestingCollection <byte[], int> {
                new BaITestItem(Ba(0x00, 0x00, 0x00, 0x00), 0),
                new BaITestItem(Ba(0xFF, 0x00, 0x00, 0x00), 8),
                new BaITestItem(Ba(0xFF, 0xFF, 0x00, 0x00), 16),
                new BaITestItem(Ba(0xFF, 0xFF, 0xFF, 0x00), 24),
                new BaITestItem(Ba(0xFF, 0xFF, 0xFF, 0xFF), 32),
                new BaITestItem(Ba(0xFF, 0xFF, 0xFE, 0x00), 23),
                new BaITestItem(Ba(0xFF, 0x80, 0x00, 0x00), 9),
                new BaITestItem(Ba(0xFF, 0xFF, 0x80, 0x00), 17),
                new BaITestItem(Ba(0xFF, 0xFF, 0xFE, 0x00), 23),
                new BaITestItem(Ba(0xFF, 0xFF, 0xFF, 0xF8), 29),
                new BaITestItem(Ba(0xFF, 0xFF, 0xFF, 0xFC), 30)
            };

            foreach (var i in a)
            {
                var nm   = new NetMask(i.ToTest1);
                int cidr = nm.Cidr;
                Assert.AreEqual(i.Expected, cidr);
            }
        }