Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKelly Washington <kelly@lindenlab.com>2016-07-08 01:22:03 +0300
committerKelly Washington <kelly@lindenlab.com>2016-07-08 01:39:03 +0300
commitb4a00d1ea3b67a6f7ea1d97b61acf80c7092d682 (patch)
treeff36c0a42b0db9c726f0b1f91ce7d08a1650e64f /mcs/class/Mono.Tasklets
parent39ebee1253ab4d09af77c49595ccf31c46b4ef93 (diff)
Add ContinuationsTest for Mono.Tasklets
Diffstat (limited to 'mcs/class/Mono.Tasklets')
-rw-r--r--mcs/class/Mono.Tasklets/Makefile4
-rw-r--r--mcs/class/Mono.Tasklets/Mono.Tasklets_test.dll.sources1
-rw-r--r--mcs/class/Mono.Tasklets/Test/Mono.Tasklets/ContinuationsTest.cs83
3 files changed, 87 insertions, 1 deletions
diff --git a/mcs/class/Mono.Tasklets/Makefile b/mcs/class/Mono.Tasklets/Makefile
index 8883dbaf834..19a6cc1ceed 100644
--- a/mcs/class/Mono.Tasklets/Makefile
+++ b/mcs/class/Mono.Tasklets/Makefile
@@ -3,7 +3,9 @@ SUBDIRS =
include ../../build/rules.make
LIBRARY = Mono.Tasklets.dll
-NO_TEST = yes
+
+LIB_MCS_FLAGS =
+TEST_MCS_FLAGS = $(LIB_MCS_FLAGS)
include ../../build/library.make
diff --git a/mcs/class/Mono.Tasklets/Mono.Tasklets_test.dll.sources b/mcs/class/Mono.Tasklets/Mono.Tasklets_test.dll.sources
new file mode 100644
index 00000000000..f994ee35b3d
--- /dev/null
+++ b/mcs/class/Mono.Tasklets/Mono.Tasklets_test.dll.sources
@@ -0,0 +1 @@
+Mono.Tasklets/ContinuationsTest.cs
diff --git a/mcs/class/Mono.Tasklets/Test/Mono.Tasklets/ContinuationsTest.cs b/mcs/class/Mono.Tasklets/Test/Mono.Tasklets/ContinuationsTest.cs
new file mode 100644
index 00000000000..5f75664666b
--- /dev/null
+++ b/mcs/class/Mono.Tasklets/Test/Mono.Tasklets/ContinuationsTest.cs
@@ -0,0 +1,83 @@
+using NUnit.Framework;
+
+using System;
+using Mono.Tasklets;
+
+namespace MonoTests.System
+{
+ [TestFixture]
+ public class ContinuationsTest {
+
+ private Continuation _contA = new Continuation();
+
+ private int total = 0;
+
+ [Test]
+ public void TestContinuationsLoop() {
+ _contA.Mark();
+ int value = 0;
+ int ret = _contA.Store(0);
+ for(int i = ret; i < 10; i++) {
+ value += i;
+ }
+
+ if(value > 0) {
+ total += value;
+ _contA.Restore(ret + 1);
+ }
+
+ Assert.AreEqual(total,330);
+ }
+
+ [Test]
+ public void Yielding() {
+ Continuation baseCont = new Continuation();
+ Continuation taskCont = new Continuation();
+ int yields = 0;
+ baseCont.Mark();
+ taskCont.Mark();
+
+ // Store the base continuation to start the task
+ if (baseCont.Store(0) == 0) {
+ bool done = false;
+ int count = 0;
+
+ while (!done) {
+ // Do stuff for the task.
+ ++count;
+
+ // This task is counting to 100.
+ if (count == 100) {
+ done = true;
+ }
+
+ // Yield every 10 loops
+ else if (count % 10 == 0) {
+
+ // To yield, store the task continuation then restore
+ // the base continuation.
+ if (taskCont.Store(0) == 0) {
+ baseCont.Restore(1);
+ }
+ }
+ }
+ }
+ // When restored, 'Store' will return what was passed to Restore, in this case 1 so fall here.
+ else {
+ // Count the yields, then go back to the task.
+ ++yields;
+ taskCont.Restore(1);
+ }
+
+ Assert.AreEqual(yields,9);
+ }
+
+
+ }
+}
+// vim: noexpandtab
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// End: