diff options
Diffstat (limited to 'cs-dotnet/src/tests/packet.cs')
-rw-r--r-- | cs-dotnet/src/tests/packet.cs | 70 |
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 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using Com.Xagasoft.Gats; | ||
4 | |||
5 | public 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 | } | ||