Ejemplo n.º 1
0
        public void EraseTest()
        {
            DataInInt target = new DataInInt();

             // fill with random values
             byte[] buffer = new byte[4];
             Random r = new Random();
             r.NextBytes(buffer);
             for (int i = 0; i < 4; i++)
             {
            target.StoreByte(buffer[i], i * 8);
             }

             // full erase test
             target.Erase(0, 32);
             CheckErased(target);

             // partial erase test
             for (int pass = 1; pass < 4; pass++)
             {
            r.NextBytes(buffer);
            for (int i = 0; i < 4; i++)
            {
               target.StoreByte(buffer[i], i * 8);
            }

            for (int i = 0; i < 4; i++)
            {
               target.Erase(i * 8, 8);
               byte received = target.GetByte(i * 8);
               Assert.IsTrue(received == 0, "Erase failed at position " + (i * 8));
            }
             }
        }
Ejemplo n.º 2
0
        public void GetSetBoolTest()
        {
            DataInInt target = new DataInInt();

             // prepare random bool array and write to target
             bool[] expected = new bool[32];
             Random r = new Random();
             for (int pass = 1; pass < 4; pass++)
             {
            for (int i = 0; i < 32; i++)
            {
               expected[i] = (r.Next(2) == 1);
               target.StoreBool(expected[i], i);
            }

            // read the values and compare with the expected
            for (int i = 0; i < 32; i++)
            {
               bool received = target.GetBool(i);
               Assert.IsTrue(received == expected[i], "Stored data do not match at index " + i + "; pass: "******"; received: " + received.ToString() + "; expected: " + expected[i]);
            }
             }
        }
Ejemplo n.º 3
0
        public void DataInUintConstructorTest()
        {
            DataInInt target = new DataInInt();

             CheckErased(target);
        }
Ejemplo n.º 4
0
 private void CheckErased(DataInInt target)
 {
     for (int i = 0; i < 32; i++)
      {
     Assert.IsFalse(target.GetBool(i), "Data not erased at index: " + i);
      }
 }
Ejemplo n.º 5
0
        public void GetSetUshortTest()
        {
            DataInInt target = new DataInInt();

             // prepare random short array and write to target
             ushort[] expected = new ushort[2];
             Random r = new Random();
             for (int pass = 1; pass < 4; pass++)
             {
            for (int i = 0; i < 2; i++)
            {
               expected[i] = (ushort)r.Next(65536);
               target.StoreUShort(expected[i], i * 16);
            }

            // read the values and compare with the expected
            for (int i = 0; i < 2; i++)
            {
               ushort received = target.GetUShort(i * 16);
               Assert.IsTrue(received == expected[i], "Stored data do not match at index " + i + "; pass: "******"; received: " + received.ToString() + "; expected: " + expected[i]);
            }
             }
        }
Ejemplo n.º 6
0
        public void GetSetByteTest()
        {
            DataInInt target = new DataInInt();

             // prepare random bool array and write to target
             byte[] expected = new byte[4];
             Random r = new Random();
             for (int pass = 1; pass < 4; pass++)
             {
            r.NextBytes(expected);
            for (int i = 0; i < 4; i++)
            {
               target.StoreByte(expected[i], i * 8);
            }

            // read the values and compare with the expected
            for (int i = 0; i < 4; i++)
            {
               byte received = target.GetByte(i * 8);
               Assert.IsTrue(received == expected[i], "Stored data do not match at index " + i + "; pass: "******"; received: " + received.ToString() + "; expected: " + expected[i]);
            }
             }
        }