CallSeq.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // MonoTests.Remoting.CallSeq.cs
  3. //
  4. // Author: Lluis Sanchez Gual ([email protected])
  5. //
  6. // 2003 (C) Copyright, Ximian, Inc.
  7. //
  8. using System;
  9. using System.Threading;
  10. using System.Collections;
  11. using NUnit.Framework;
  12. namespace MonoTests.Remoting
  13. {
  14. public class CallSeq
  15. {
  16. static ArrayList calls = new ArrayList();
  17. static int checkPos = 0;
  18. static int writePos = 0;
  19. static string name = "";
  20. static ArrayList contexts = new ArrayList ();
  21. static int domId = 1;
  22. public static void Add (string msg)
  23. {
  24. writePos++;
  25. msg = writePos.ToString ("000") + " (d" + CommonDomainId + ",c" + CommonContextId + ") " + msg;
  26. calls.Add (msg);
  27. }
  28. public static int CommonContextId
  29. {
  30. get
  31. {
  32. int id = Thread.CurrentContext.ContextID;
  33. int idc = contexts.IndexOf (id);
  34. if (idc == -1)
  35. {
  36. idc = contexts.Count;
  37. contexts.Add (id);
  38. }
  39. return idc;
  40. }
  41. }
  42. public static int CommonDomainId
  43. {
  44. get { return domId; }
  45. set { domId = value; }
  46. }
  47. public static void Init (string str)
  48. {
  49. calls = new ArrayList();
  50. contexts = new ArrayList ();
  51. name = str;
  52. checkPos = 0;
  53. writePos = 0;
  54. }
  55. public static void Check (string msg, int domain)
  56. {
  57. bool optional = false;
  58. if (msg.StartsWith ("#"))
  59. {
  60. optional = true;
  61. msg = msg.Substring (1);
  62. }
  63. if (msg[6].ToString() != domain.ToString()) return;
  64. if (checkPos >= calls.Count)
  65. {
  66. if (!optional) Assertion.Fail ("[" + name + "] Call check failed. Expected call not made: \"" + msg + "\"");
  67. else return;
  68. }
  69. string call = (string) calls[checkPos++];
  70. if (msg.Substring (3) != call.Substring (3))
  71. {
  72. if (optional) checkPos--;
  73. else Assertion.Fail ("[" + name + "] Call check failed in step " + (checkPos+1) + ". Expected \"" + msg + "\" found \"" + call + "\"");
  74. }
  75. }
  76. public static void Check (string[] msgs, int domain)
  77. {
  78. foreach (string msg in msgs)
  79. Check (msg, domain);
  80. }
  81. public static ArrayList Seq
  82. {
  83. get { return calls; }
  84. set { calls = value; }
  85. }
  86. }
  87. }