Threads tests for Windows

Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/d33f93b9
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/d33f93b9
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/d33f93b9

Branch: refs/heads/thread_safe_errors
Commit: d33f93b96a2fe8fcf9ec95bf8ef6045dd2ecf309
Parents: 8abf8ed
Author: Nick Wellnhofer <[email protected]>
Authored: Sat Dec 27 14:29:32 2014 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Sat Dec 27 14:29:32 2014 +0100

----------------------------------------------------------------------
 runtime/c/src/Clownfish/Test/TestThreads.c | 26 ++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d33f93b9/runtime/c/src/Clownfish/Test/TestThreads.c
----------------------------------------------------------------------
diff --git a/runtime/c/src/Clownfish/Test/TestThreads.c 
b/runtime/c/src/Clownfish/Test/TestThreads.c
index f64f30a..bf4a203 100644
--- a/runtime/c/src/Clownfish/Test/TestThreads.c
+++ b/runtime/c/src/Clownfish/Test/TestThreads.c
@@ -36,9 +36,33 @@ test_threads(TestBatchRunner *runner) {
 /********************************** Windows ********************************/
 #elif defined(CHY_HAS_WINDOWS_H)
 
+#include <windows.h>
+
+static DWORD
+S_err_thread(void *arg) {
+    TestBatchRunner *runner = (TestBatchRunner*)arg;
+
+    TEST_TRUE(runner, Err_get_error() == NULL,
+              "global error in thread initialized to null");
+
+    Err_set_error(Err_new(Str_newf("thread")));
+
+    return 0;
+}
+
 static void
 test_threads(TestBatchRunner *runner) {
-    SKIP(runner, 4, "TODO: test threads on Windows");
+    Err_set_error(Err_new(Str_newf("main")));
+
+    HANDLE thread = CreateThread(NULL, 0, S_err_thread, runner, 0, NULL);
+    TEST_TRUE(runner, thread != NULL, "CreateThread succeeds");
+    DWORD event = WaitForSingleObject(thread, INFINITE);
+    TEST_INT_EQ(runner, event, WAIT_OBJECT_0, "WaitForSingleObject succeeds");
+    CloseHandle(thread);
+
+    String *mess = Err_Get_Mess(Err_get_error());
+    TEST_TRUE(runner, Str_Equals_Utf8(mess, "main", 4),
+              "thread doesn't clobber global error");
 }
 
 /******************************** pthreads *********************************/

Reply via email to