private static void WriteThreadFunc(object state) { int index = (int)state; for (int i = 0; i < CheckCount; i++) { int value = (int)CheckCount * index + i; ypipe.Write(ref value); } }
public void TestApi() { ypipe = new CachePipe <int>(); int valueResult; valueResult = ypipe.Peek(); Assert.AreEqual(valueResult, default(int)); int value = 1; var rc = ypipe.Write(ref value); Assert.IsTrue(rc); Assert.AreEqual(ypipe.Count, 1); valueResult = ypipe.Peek(); Assert.AreEqual(valueResult, value); rc = ypipe.CheckRead(); Assert.IsTrue(rc); rc = ypipe.Unwrite(out valueResult); Assert.IsFalse(rc); Assert.AreEqual(valueResult, default(int)); rc = ypipe.Read(out valueResult); Assert.IsTrue(rc); Assert.AreEqual(valueResult, value); rc = ypipe.CheckRead(); Assert.IsFalse(rc); rc = ypipe.Read(out valueResult); Assert.IsFalse(rc); Assert.AreEqual(valueResult, default(int)); ypipe.WriteBegin(ref value); rc = ypipe.CheckRead(); Assert.IsFalse(rc); rc = ypipe.Read(out valueResult); Assert.IsFalse(rc); rc = ypipe.Write(ref value); Assert.IsFalse(rc); rc = ypipe.CheckRead(); Assert.IsFalse(rc); rc = ypipe.Read(out valueResult); Assert.IsFalse(rc); rc = ypipe.Unwrite(out valueResult); Assert.IsTrue(rc); Assert.AreEqual(valueResult, value); rc = ypipe.WriteEnd(ref value); Assert.IsTrue(rc); rc = ypipe.CheckRead(); Assert.IsTrue(rc); rc = ypipe.Unwrite(out valueResult); Assert.IsFalse(rc); Assert.AreEqual(valueResult, default(int)); ypipe.Clear(); Assert.AreEqual(ypipe.Count, 0); rc = ypipe.Write(ref value); Assert.IsTrue(rc); rc = ypipe.Write(ref value); Assert.IsTrue(rc); var array = ypipe.ReadAll(); Assert.AreEqual(array.Length, 2); for (int i = 0; i < array.Length; i++) { Assert.AreEqual(array[i], value); } Assert.AreEqual(ypipe.Count, 0); }