コード例 #1
0
    public void TestTryingToGetANonEmptyItemOutOfRange()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add(42);

      Assert.AreEqual(42, emptyIpcData.Get<int>(0));

      //  out of range
      emptyIpcData.Get<object>(1);
    }
コード例 #2
0
    public void TestGetSingleTypes()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add( "Hello" );
      emptyIpcData.Add( "World" );

      // check the values.
      Assert.AreEqual( "Hello", emptyIpcData.Get<string>(0));
      Assert.AreEqual( "World", emptyIpcData.Get<string>(1));
    }
コード例 #3
0
    public void TestHasGuidByDefault()
    {
      var emptyIpcData = new IpcData();

      // we have a guid by default.
      Assert.IsTrue(emptyIpcData.HasGuid());

      //  check that the string is not empty
      Assert.IsFalse( string.IsNullOrEmpty(emptyIpcData.Guid) );
    }
コード例 #4
0
    public void TestTheArgumentCountIsValid()
    {
      var emptyIpcData = new IpcData();

      Assert.AreEqual( (uint)0, emptyIpcData.ArgumentsCount);
      emptyIpcData.Add("Hello");
      emptyIpcData.Add("World");
      Assert.AreEqual( (uint)2 , emptyIpcData.ArgumentsCount );
      emptyIpcData.Add(42);
      Assert.AreEqual( (uint)3, emptyIpcData.ArgumentsCount);
    }
コード例 #5
0
    public void TestGetDifferentTypes()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add("Hello");
      emptyIpcData.Add("World");
      emptyIpcData.Add( 42 );
      emptyIpcData.Add( "Something", false );

      // check the values.
      Assert.AreEqual("Hello", emptyIpcData.Get<string>(0));
      Assert.AreEqual("World", emptyIpcData.Get<string>(1));
      Assert.AreEqual(42, emptyIpcData.Get<int>(2));
      Assert.AreEqual("Something", emptyIpcData.Get<string>(3));
    }
コード例 #6
0
 public void TestGetBooleanFalseString()
 {
   var emptyIpcData = new IpcData();
   emptyIpcData.Add("False");
   Assert.IsFalse(emptyIpcData.Get<bool>(0));
 }
コード例 #7
0
 public void TestGetBooleanTrueString()
 {
   var emptyIpcData = new IpcData();
   emptyIpcData.Add("True");
   Assert.IsTrue(emptyIpcData.Get<bool>(0));
 }
コード例 #8
0
    public void TestGetBooleanFromIntegerNotEqualOne()
    {
      var random = new Random();
      var r = random.Next(2, Int32.MaxValue);
      if(random.Next(0, 1) == 1)
      {
        r *= -1;
      }

      var emptyIpcData = new IpcData();
      emptyIpcData.Add(1);
      Assert.IsTrue(emptyIpcData.Get<bool>(0));
    }
コード例 #9
0
 public void TestGetBooleanFromIntegerEqualOne()
 {
   var emptyIpcData = new IpcData();
   emptyIpcData.Add(1);
   Assert.IsTrue(emptyIpcData.Get<bool>(0)); 
 }
コード例 #10
0
    public void TestIsStringInvalidIndex()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add(12);
      emptyIpcData.Add("Hello");

      emptyIpcData.IsString(2);
    }
コード例 #11
0
    public void TestCastingToDifferentNumbers()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add(42);
      emptyIpcData.Add(52);
      emptyIpcData.Add(67);

      // check the values.
      Assert.AreEqual((long)42, emptyIpcData.Get<long>(0));
      Assert.AreEqual((uint)52, emptyIpcData.Get<uint>(1));
      Assert.AreEqual((int)67, emptyIpcData.Get<int>(2));
      Assert.AreEqual((short)67, emptyIpcData.Get<short>(2));

      Assert.AreEqual((double)67, emptyIpcData.Get<double>(2));
      Assert.AreEqual((float)67, emptyIpcData.Get<float>(2));
    }
コード例 #12
0
    public void TestByteArraySetsIntOneByte()
    {
      var random = new Random();
      var r1 = (byte)random.Next(0, 255);

      //  give a data type of int32, but no data to read
      var emptyIpcData = new IpcData(new byte[] { 100, 0, 0, 0, //  version
                                (byte) ExpectedIpcDataType.Int32, 0,        //  data type int
                                r1, 0, 0,0   //  int value
                              });

      Assert.AreEqual(r1 , emptyIpcData.Get<int>(0));
    }
コード例 #13
0
    public void TestFromInt32CanBeConvertedToInt64()
    {
      var ipc = new IpcData();

      var random = new Random();
      var m = (int)(random.NextDouble() * int.MaxValue);
      var n = (long)(random.NextDouble() * long.MaxValue);

      ipc.Add(m);
      ipc.Add(n);

      Assert.AreEqual(m, ipc.Get<int>(0));
      Assert.AreEqual(m, ipc.Get<long>(0)); // as a long
      Assert.AreEqual(n, ipc.Get<long>(1));
    }
コード例 #14
0
    public void TestFromInt32ToPtrAndBack()
    {
      var ipc = new IpcData();

      var uuid = ipc.Guid;
      var random = new Random();
      var n = (Int32)random.Next(0, Int32.MaxValue);

      ipc.Add(Int32.MaxValue);
      ipc.Add(n);

      var payload = ipc.GetPtr();
      var dataBlockSize = ipc.GetSize();
      var byteArray = new byte[dataBlockSize];

      System.Runtime.InteropServices.Marshal.Copy(payload, byteArray, 0, dataBlockSize);
      var ipc2 = new IpcData(byteArray);

      Assert.AreEqual(uuid, ipc2.Guid);
      Assert.AreEqual(Int32.MaxValue, ipc2.Get<Int32>(0));
      Assert.AreEqual(n, ipc2.Get<Int32>(1));
    }
コード例 #15
0
    public void TestIsNumericPastGuid()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add(12);

      Assert.IsTrue(emptyIpcData.IsInt(0));
      Assert.IsFalse(emptyIpcData.IsString(0));
    }
コード例 #16
0
    public void TestAsciiStringIsString()
    {
      //  give a data type of int32, but no data to read
      var emptyIpcData = new IpcData(new byte[] { 100, 0, 0, 0, //  version
                                (byte) ExpectedIpcDataType.StringAscii, 0,        //  data type string
                                5, 0, 0,0,   //  the len
                                (byte)'h',
                                (byte)'e',
                                (byte)'l',
                                (byte)'l',
                                (byte)'o',
                              });

      Assert.IsTrue(emptyIpcData.IsString(0));
      Assert.AreEqual("hello", emptyIpcData.Get<string>(0));
    }
コード例 #17
0
    public void TestIsNumeric()
    {
      //  give a data type of int32, but no data to read
      var emptyIpcData = new IpcData(new byte[] { 100, 0, 0, 0, //  version
                                (byte) ExpectedIpcDataType.Int32, 0,        //  data type int
                                32, 0, 0,0   //  int value
                              });

      Assert.IsTrue(emptyIpcData.IsInt(0));
    }
コード例 #18
0
    public void TestByteArraySetsIntFourBytes()
    {
      var random = new Random();
      var r1 = (byte)random.Next(0, 255);
      var r2 = (byte)random.Next(0, 255);
      var r3 = (byte)random.Next(0, 255);
      var r4 = (byte)random.Next(0, 255);

      //  give a data type of int32, but no data to read
      var emptyIpcData = new IpcData(new byte[] { 100, 0, 0, 0, //  version
                                (byte) ExpectedIpcDataType.Int32, 0,        //  data type int
                                r1, r2, r3,r4   //  int value
                              });

      Assert.AreEqual((r1 + r2 * 256 + r3 * 256 * 256 + r4 * 256 * 256*256), emptyIpcData.Get<int>(0));
    }
コード例 #19
0
 public void TestGetBooleanNeitherTrueNorFalseString()
 {
   var emptyIpcData = new IpcData();
   emptyIpcData.Add("NotAValidString");
   emptyIpcData.Get<bool>(0);
 }
コード例 #20
0
    public void TestTryingtogetANumberWhenTheArgumentIsAString()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add("Hello");

      // this is not a number.
      emptyIpcData.Get<long>(0);
    }
コード例 #21
0
    public void TestIsStringPastGuid()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add("Hello");

      Assert.IsFalse(emptyIpcData.IsInt(0));
      Assert.IsTrue(emptyIpcData.IsString(0));
    }
コード例 #22
0
    public void TestANumberCanBeCastToAString()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add( 12 );

      // we can cast the number to a string.
      Assert.AreEqual( "12", emptyIpcData.Get<string>(0) );
    }
コード例 #23
0
    public void TestFromInt64And32ToPtrAndBack()
    {
      var ipc = new IpcData();

      var random = new Random();
      var m = (int)(random.NextDouble() * int.MaxValue);
      var n = (long)(random.NextDouble() * long.MaxValue);

      var uuid = ipc.Guid;
      ipc.Add(m);
      ipc.Add(n);

      var payload = ipc.GetPtr();
      var dataBlockSize = ipc.GetSize();
      var byteArray = new byte[dataBlockSize];

      System.Runtime.InteropServices.Marshal.Copy(payload, byteArray, 0, dataBlockSize);
      var ipc2 = new IpcData(byteArray);

      Assert.AreEqual(uuid, ipc2.Guid);
      Assert.AreEqual(m, ipc2.Get<int>(0));
      Assert.AreEqual(n, ipc2.Get<long>(1));
    }
コード例 #24
0
    public void TestIsNumericPastGuidAndStrings()
    {
      var random = new Random();
      var r1 = random.Next(0, int.MaxValue);
      var r2 = random.Next(0, int.MaxValue);

      var emptyIpcData = new IpcData();
      emptyIpcData.Add(r1);
      emptyIpcData.Add("Hello");
      emptyIpcData.Add(r2);

      Assert.IsTrue(emptyIpcData.IsInt(0));
      Assert.IsFalse(emptyIpcData.IsInt(1));
      Assert.IsTrue(emptyIpcData.IsInt(2));

      Assert.AreEqual(r1, emptyIpcData.Get<int>(0));
      Assert.AreEqual(r2, emptyIpcData.Get<int>(2));
    }
コード例 #25
0
 public void TestTryingToGetAnEmptyItemOutOfRange()
 {
   var emptyIpcData = new IpcData();
   emptyIpcData.Get<object>(0);
 }
コード例 #26
0
    public void TestIsNumericPastGuidAndInteger()
    {
      var random = new Random();
      var r1 = random.Next(0, Int32.MaxValue);

      var emptyIpcData = new IpcData();
      emptyIpcData.Add("Hello1");
      emptyIpcData.Add(r1);
      emptyIpcData.Add("Hello2");

      Assert.IsTrue(emptyIpcData.IsString(0));
      Assert.IsFalse(emptyIpcData.IsString(1));
      Assert.IsTrue(emptyIpcData.IsString(2));

      Assert.AreEqual("Hello1", emptyIpcData.Get<string>(0));
      Assert.AreEqual("Hello2", emptyIpcData.Get<string>(2));
    }
コード例 #27
0
    /// <summary>
    /// Send a message as a reconstructed string.
    /// </summary>
    /// <param name="msg">The IpcData we want to send.</param>
    /// <returns>The IpcData response data</returns>
    public IpcData Send( IpcData msg )
    {
      // look for the listener.
      var hWindow = ConnectedWindow;
      if (IntPtr.Zero == hWindow)
      {
        return null;
      }

      // the message we want to send.
      var cds = new Copydatastruct
      {
        dwData = (IntPtr)MessageType.Copy, //  copy message...
        cbData = msg.GetSize(),
        lpData = msg.GetPtr()
      };

      // open the shared memory that should have been created.
      using (var mmf = MemoryMappedFile.CreateNew( msg.Guid, 10000))
      {
        // cast to IntPtr because we know it is not null.
        if (0 == (int) SendMessage( hWindow, WmCopyData, IntPtr.Zero, ref cds))
        {
          return null;
        }

        // open the shared memory that should have been created.
        using (var mmfvs = mmf.CreateViewStream())
        {
          using (var reader = new BinaryReader(mmfvs))
          {
            // read the first 4 bytes for the size.
            var dataSize = BitConverter.ToInt32( reader.ReadBytes( sizeof(int)), 0 );

            // all the byes 
            var bytes = reader.ReadBytes( dataSize );

            // parse the response data into an IpcData
            return new IpcData( bytes );
          }
        }
      }
    }
コード例 #28
0
    public void TestIsNumericInvalidIndex()
    {
      var emptyIpcData = new IpcData();
      emptyIpcData.Add(12);
      emptyIpcData.Add("Hello");

      emptyIpcData.IsInt(2);
    }