File: InternalSoapValuesTest.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (92 lines) | stat: -rw-r--r-- 2,194 bytes parent folder | download | duplicates (2)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.IO;
using NUnit.Framework;
using System.Runtime.Serialization.Formatters.Soap;

namespace SoapShared
{
	/// <summary>
	/// Summary description for InternalSoapValuesTest.
	/// </summary>
	[TestFixture]
	public class InternalSoapValuesTest
	{
		private MemoryStream ms;
		private SoapFormatter sf;
		

		public InternalSoapValuesTest()
		{
			ms = new MemoryStream();
			sf = new SoapFormatter();
		}

		[Test]
		public void WriteReadData()
		{
			SerializedClass c = new SerializedClass();
			
			SerializeDeserialize(c);
			SerializeDeserialize(new SerializedClass[]{c,c});
			SerializeDeserialize(c.str);
			SerializeDeserialize(c.m_bool);
			SerializeDeserialize(c.m_byte);
			SerializeDeserialize(c.m_bytes);
			SerializeDeserialize(c.m_decimal);
			SerializeDeserialize(c.m_double);
			SerializeDeserialize(c.m_float);
			SerializeDeserialize(c.m_int);
			SerializeDeserialize(c.m_long);
			SerializeDeserialize(c.m_object);
			SerializeDeserialize(c.m_sbyte);
			SerializeDeserialize(c.m_short);
			//SerializeDeserialize(c.m_time);
			SerializeDeserialize(c.m_timeSpan);
			SerializeDeserialize(c.m_uint);
			SerializeDeserialize(c.m_ulong);
			SerializeDeserialize(c.m_ushort);
		}

		private void SerializeDeserialize(object obj)
		{
			ms = new MemoryStream();
			Serialize(obj, ms);
			ms.Position = 0;
			Object des = Deserialize(ms);
			Assertion.AssertEquals(obj.GetType(), des.GetType());
		}

		private void Serialize(object ob, Stream stream)
		{
			sf.Serialize(stream, ob);
		}

		private object Deserialize(Stream stream)
		{
			Object obj = sf.Deserialize(stream);
			return obj;
		}
	}
	
	[Serializable]
	class SerializedClass
	{
		public string str = "rrr";
		public bool m_bool;
		public sbyte m_sbyte;
		public byte m_byte;
		public long m_long;
		public ulong m_ulong;
		public int m_int;
		public uint m_uint;
		public float m_float;
		public double m_double;
		public decimal m_decimal;
		public short m_short;
		public ushort m_ushort;
		public object m_object = new object();
		public TimeSpan m_timeSpan = TimeSpan.FromTicks(TimeSpan.TicksPerDay);
		public byte[] m_bytes = new byte[10];
		//public DateTime m_time = DateTime.Now;
	}
}