File: MessageWriterTest.cs

package info (click to toggle)
dbus-sharp 0.8.1-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 868 kB
  • sloc: cs: 7,690; sh: 494; makefile: 181
file content (57 lines) | stat: -rw-r--r-- 1,283 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

using System;
using System.Runtime.InteropServices;
using NUnit.Framework;
using DBus;
using DBus.Protocol;

namespace DBus.Tests
{
	[TestFixture]
	public class MessageWriterTest
	{
		DBus.Protocol.MessageWriter writer;

		[SetUp]
		public void Setup ()
		{
			writer = new DBus.Protocol.MessageWriter ();
		}

		[Test]
		public void WriteIntArrayTest ()
		{
			var initial = new int[] { 1, 2, 3, 4 };
			writer.WriteArray<int> (initial);
			byte[] result = writer.ToArray ();

			Assert.AreEqual (4 + initial.Length * 4, result.Length);
			uint length = BitConverter.ToUInt32 (result, 0);
			Assert.AreEqual (initial.Length * 4, length);
			for (int i = 0; i < initial.Length; i++)
				Assert.AreEqual (i + 1, BitConverter.ToInt32 (result, 4 + 4 * i), "#" + i);
		}

		struct TestStruct
		{
			public int bleh;
			public uint bloup;
			public float blop;
		}

		[Test]
		public void WriteStructTest ()
		{
			TestStruct stct = new TestStruct ();
			stct.bleh = 5;
			stct.bloup = 3;
			stct.blop = 5.5f;

			writer.WriteStructure<TestStruct> (stct);
			byte[] result = writer.ToArray ();
			Assert.AreEqual (5, BitConverter.ToInt32 (result, 0));
			Assert.AreEqual ((uint)3, BitConverter.ToUInt32 (result, 4));
			Assert.AreEqual (5.5f, BitConverter.ToSingle (result, 8));
		}
	}
}