Merge pull request #1390 from woodsb02/FreeBSDMacNetworkInterfaces
[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
18         {
19                 ObjectIDGenerator generator;
20
21                 string obj1 = "obj1";
22                 int obj2 = 42;          
23                 long id;
24
25                 [SetUp]
26                 protected void SetUp ()
27                 {
28                         generator = new ObjectIDGenerator ();
29                 }
30
31                 //
32                 // Tests adding an ID for a new object
33                 //
34                 public void TestGetId1 ()
35                 {
36                         bool testBool1;
37                         id = generator.GetId (obj1, out testBool1);
38
39                         Assert.AreEqual (1L, id); // should start at 1, "A1");
40                         Assert.AreEqual (true, testBool1);      // firstTime should be true, "A2");
41                 }
42
43                 //
44                 // Tests getting the ID for an existing object
45                 //
46                 public void TestGetId2 ()
47                 {
48                         bool testBool1;
49                         bool testBool2;
50                         id = generator.GetId (obj1, out testBool1);
51                         long testId1 = generator.GetId (obj1, out testBool2);
52
53                         Assert.AreEqual (testId1, id); // same object, same ID, "B1");
54                         Assert.AreEqual (false, testBool2); // no longer firstTime, "B2");
55                 }
56
57                 //
58                 // Tests getting the ID for an existing object
59                 //
60                 public void TestHasId1 ()
61                 {
62                         bool testBool1;
63                         bool testBool3;
64                         id = generator.GetId (obj1, out testBool1);
65                         long testId2 = generator.HasId (obj1, out testBool3);
66
67                         Assert.AreEqual (false, testBool3); // this has been inserted before, "C1");
68                         Assert.AreEqual (id, testId2); // we should get the same ID, "C2");
69                 }
70
71                 //
72                 // Tests getting the ID for a non-existent object
73                 //
74                 public void TestHasId2 ()
75                 {
76                         bool testBool4;
77                         long testId3 = generator.HasId (obj2, out testBool4);
78
79                         Assert.AreEqual (0L, testId3, "D1");
80                         Assert.AreEqual (true, testBool4, "D2");
81                 }
82         }
83 }