about summary refs log tree commit diff
path: root/src/rt/test/rust_test_util.cpp
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-06-28 12:54:41 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-06-28 16:12:34 -0700
commitf6f8a06d6bf010b8d30c23786976792cccfbd6de (patch)
tree7aeb93091cdb19e6ac3b2a63fd7f828a4b3c1499 /src/rt/test/rust_test_util.cpp
parent657e5a2bd579f7f1698f8ba88cb1142ced7a477f (diff)
downloadrust-f6f8a06d6bf010b8d30c23786976792cccfbd6de.tar.gz
rust-f6f8a06d6bf010b8d30c23786976792cccfbd6de.zip
Resurrecting the runtime unit tests, and modifying them so they compile under the latest refactoring changes.
Diffstat (limited to 'src/rt/test/rust_test_util.cpp')
-rw-r--r--src/rt/test/rust_test_util.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/rt/test/rust_test_util.cpp b/src/rt/test/rust_test_util.cpp
new file mode 100644
index 00000000000..2e9d764f69b
--- /dev/null
+++ b/src/rt/test/rust_test_util.cpp
@@ -0,0 +1,78 @@
+#include "../rust_internal.h"
+
+#define COUNT 1000
+#define LARGE_COUNT 10000
+#define THREADS 10
+
+bool
+rust_array_list_test::run() {
+    array_list<int> list;
+
+    for (int i = 0; i < COUNT; i++) {
+        list.append(i);
+    }
+
+    for (int i = 0; i < COUNT; i++) {
+        CHECK (list[i] == i);
+    }
+
+    for (int i = 0; i < COUNT; i++) {
+        CHECK (list.index_of(i) == i);
+    }
+
+    for (int i = 0; i < COUNT; i++) {
+        CHECK (list.replace(i, -i));
+        CHECK (list.replace(-i, i));
+        CHECK (list.index_of(i) == i);
+    }
+
+    for (int i = COUNT - 1; i >= 0; i--) {
+        CHECK (list.pop(NULL));
+    }
+
+    return true;
+}
+
+bool
+rust_synchronized_indexed_list_test::run() {
+    array_list<worker*> workers;
+
+    for (int i = 0; i < THREADS; i++) {
+        worker *worker =
+            new rust_synchronized_indexed_list_test::worker(this);
+        workers.append(worker);
+    }
+
+    for (uint32_t i = 0; i < workers.size(); i++) {
+        workers[i]->start();
+    }
+
+    while(workers.is_empty() == false) {
+        worker *worker;
+        workers.pop(&worker);
+        worker->join();
+        delete worker;
+    }
+
+    long long expected_items = LARGE_COUNT * THREADS;
+
+    CHECK(list.length() == expected_items);
+
+    long long sum = 0;
+    for (size_t i = 0; i < list.length(); i++) {
+        sum += list[i]->value;
+    }
+
+    long long expected_sum = LARGE_COUNT;
+    expected_sum = expected_sum * (expected_sum - 1) / 2 * THREADS;
+    CHECK (sum == expected_sum);
+    return true;
+}
+
+void
+rust_synchronized_indexed_list_test::worker::run() {
+    for (int i = 0; i < LARGE_COUNT; i++) {
+        parent->list.append(new indexed_list_element<int>(i));
+    }
+    return;
+}