aboutsummaryrefslogtreecommitdiff
path: root/cs-dotnet/src/tests/packet.cs
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-15 22:24:09 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-15 22:24:09 +0000
commit052cbfd922a9512d1143fc10f5ab4c82b5470bcc (patch)
tree3d580e434f3efc8e069c5fc9de68c60cf905f75c /cs-dotnet/src/tests/packet.cs
parent862c485d46f3f8e992a9ca9fea40fb33f0b43959 (diff)
downloadlibgats-052cbfd922a9512d1143fc10f5ab4c82b5470bcc.tar.gz
libgats-052cbfd922a9512d1143fc10f5ab4c82b5470bcc.tar.bz2
libgats-052cbfd922a9512d1143fc10f5ab4c82b5470bcc.tar.xz
libgats-052cbfd922a9512d1143fc10f5ab4c82b5470bcc.zip
Ok, Packet based stream reading/writing works and is compliant.
Diffstat (limited to '')
-rw-r--r--cs-dotnet/src/tests/packet.cs70
1 files changed, 70 insertions, 0 deletions
diff --git a/cs-dotnet/src/tests/packet.cs b/cs-dotnet/src/tests/packet.cs
new file mode 100644
index 0000000..a572505
--- /dev/null
+++ b/cs-dotnet/src/tests/packet.cs
@@ -0,0 +1,70 @@
1using System;
2using System.IO;
3using Com.Xagasoft.Gats;
4
5public class Test
6{
7 public static void Write( GatsObject o, Stream s )
8 {
9 GatsStream gs = new GatsStream( s );
10 gs.WriteObject( o );
11 Console.WriteLine("Wrote: " + o );
12 }
13
14 public static GatsObject Read( Stream s )
15 {
16 GatsStream gs = new GatsStream( s );
17 GatsObject o = gs.ReadObject();
18 if( o == null )
19 Console.WriteLine("Nothing Read");
20 else
21 {
22 Console.WriteLine("Read type: " + o.GetType() );
23 Console.WriteLine("Read value: " + o );
24 }
25 return o;
26 }
27
28 public static void Main()
29 {
30 MemoryStream ms = new MemoryStream();
31 GatsDictionary d = new GatsDictionary();
32 GatsList l = new GatsList();
33 l.Add( new GatsFloat( Math.PI ) );
34 l.Add( new GatsInteger( 1337 ) );
35 l.Add( new GatsString("Hello") );
36 d.Add("list", l );
37 d.Add("int", new GatsInteger( 998877 ) );
38 d.Add("float", new GatsFloat( 87.332 ) );
39 d.Add("string", new GatsString("Yup, a string") );
40 d.Add("bool", new GatsBoolean( false ) );
41 Write( d, ms );
42 ms.Seek( 0, SeekOrigin.Begin );
43 Read( ms );
44
45 try
46 {
47 FileStream fs = new FileStream("packet.gats", FileMode.Open,
48 FileAccess.Read );
49 Console.WriteLine("===Reading from file===");
50 GatsStream gs = new GatsStream( fs );
51 GatsObject o = null;
52 do
53 {
54 o = gs.ReadObject();
55 if( o == null )
56 Console.WriteLine("Nothing Read");
57 else
58 {
59 Console.WriteLine("Read type: " + o.GetType() );
60 Console.WriteLine("Read value: " + o );
61 }
62 } while( o != null );
63 }
64 catch( Exception e )
65 {
66 Console.WriteLine("Can't test files: " + e.Message );
67 Console.WriteLine( e );
68 }
69 }
70}