2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / Test / System.Runtime.Serialization / ObjectIDGeneratorTests.cs
1 //
2 // System.Runtime.Serialization.ObjectIDGeneratorTests.cs
3 //
4 // Author: Duncan Mak  (duncan@ximian.com)
5 //
6 // (C) Ximian, Inc.
7 //
8
9 using System;
10 using System.Diagnostics;
11 using System.Runtime.Serialization;
12
13 using NUnit.Framework;
14
15 namespace MonoTests.System.Runtime.Serialization
16 {
17         public class ObjectIDGeneratorTests : TestCase
18         {
19                 ObjectIDGenerator generator;
20
21                 string obj1 = "obj1";
22                 int obj2 = 42;          
23                 long id;
24
25                 protected override void SetUp ()
26                 {
27                         generator = new ObjectIDGenerator ();
28                 }
29
30                 //
31                 // Tests adding an ID for a new object
32                 //
33                 public void TestGetId1 ()
34                 {
35                         bool testBool1;
36                         id = generator.GetId (obj1, out testBool1);
37
38                         AssertEquals ("A1", 1L, id); // should start at 1
39                         AssertEquals ("A2", true, testBool1);   // firstTime should be true
40                 }
41
42                 //
43                 // Tests getting the ID for an existing object
44                 //
45                 public void TestGetId2 ()
46                 {
47                         bool testBool1;
48                         bool testBool2;
49                         id = generator.GetId (obj1, out testBool1);
50                         long testId1 = generator.GetId (obj1, out testBool2);
51
52                         AssertEquals ("B1", testId1, id); // same object, same ID
53                         AssertEquals ("B2", false, testBool2); // no longer firstTime
54                 }
55
56                 //
57                 // Tests getting the ID for an existing object
58                 //
59                 public void TestHasId1 ()
60                 {
61                         bool testBool1;
62                         bool testBool3;
63                         id = generator.GetId (obj1, out testBool1);
64                         long testId2 = generator.HasId (obj1, out testBool3);
65
66                         AssertEquals ("C1", false, testBool3); // this has been inserted before
67                         AssertEquals ("C2", id, testId2); // we should get the same ID
68                 }
69
70                 //
71                 // Tests getting the ID for a non-existent object
72                 //
73                 public void TestHasId2 ()
74                 {
75                         bool testBool4;
76                         long testId3 = generator.HasId (obj2, out testBool4);
77
78                         AssertEquals ("D1", 0L, testId3);
79                         AssertEquals ("D2", true, testBool4);
80                 }
81         }
82 }