You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/07/01 07:05:21 UTC
[lucy-commits] svn commit: r1141798 - in /incubator/lucy/branches/0.1: ./
core/Lucy/Test/Store/TestFSFolder.c
Author: marvin
Date: Fri Jul 1 05:05:20 2011
New Revision: 1141798
URL: http://svn.apache.org/viewvc?rev=1141798&view=rev
Log:
LUCY-160 Always disable symlink tests on Windows.
Disable tests requiring symlinks whenever _WIN32 is defined. Add a test which
substitutes CreateSymbolicLink() from windows.h for symlink() from unistd.h,
but leave it disabled by default because CreateSymbolicLink() fails unless the
user has administrator privileges.
Modified:
incubator/lucy/branches/0.1/ (props changed)
incubator/lucy/branches/0.1/core/Lucy/Test/Store/TestFSFolder.c
Propchange: incubator/lucy/branches/0.1/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul 1 05:05:20 2011
@@ -1 +1 @@
-/incubator/lucy/trunk:1126586,1134011,1134355,1134472,1134843-1134848,1134953,1134956
+/incubator/lucy/trunk:1126586,1134011,1134355,1134472,1134843-1134848,1134953,1134956,1139709
Modified: incubator/lucy/branches/0.1/core/Lucy/Test/Store/TestFSFolder.c
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/0.1/core/Lucy/Test/Store/TestFSFolder.c?rev=1141798&r1=1141797&r2=1141798&view=diff
==============================================================================
--- incubator/lucy/branches/0.1/core/Lucy/Test/Store/TestFSFolder.c (original)
+++ incubator/lucy/branches/0.1/core/Lucy/Test/Store/TestFSFolder.c Fri Jul 1 05:05:20 2011
@@ -37,6 +37,13 @@
#include "Lucy/Store/FSFolder.h"
#include "Lucy/Store/OutStream.h"
+/* The tests involving symlinks have to be run with administrator privileges
+ * under Windows, so disable by default.
+ */
+#ifndef _WIN32
+ #define ENABLE_SYMLINK_TESTS
+#endif
+
static Folder*
S_set_up() {
rmdir("_fstest");
@@ -73,9 +80,13 @@ test_Initialize_and_Check(TestBatch *bat
S_tear_down();
}
+// Creae the symlinks needed by test_protect_symlinks().
+static bool_t
+S_create_test_symlinks(void);
+
static void
test_protect_symlinks(TestBatch *batch) {
-#ifdef CHY_HAS_UNISTD_H
+#ifdef ENABLE_SYMLINK_TESTS
FSFolder *folder = (FSFolder*)S_set_up();
CharBuf *foo = (CharBuf*)ZCB_WRAP_STR("foo", 3);
CharBuf *bar = (CharBuf*)ZCB_WRAP_STR("bar", 3);
@@ -86,14 +97,15 @@ test_protect_symlinks(TestBatch *batch)
OutStream *outstream = FSFolder_Open_Out(folder, foo_boffo);
DECREF(outstream);
- if (symlink("_fstest/foo/boffo", "_fstest/bar/banana")
- || symlink("_fstest/foo", "_fstest/bar/bazooka")
- ) {
- FAIL(batch, "symlink() failed");
- FAIL(batch, "symlink() failed");
- FAIL(batch, "symlink() failed");
- FAIL(batch, "symlink() failed");
- FAIL(batch, "symlink() failed");
+ if (!S_create_test_symlinks()) {
+ FAIL(batch, "symlink creation failed");
+ FAIL(batch, "symlink creation failed");
+ FAIL(batch, "symlink creation failed");
+ FAIL(batch, "symlink creation failed");
+ FAIL(batch, "symlink creation failed");
+ // Try to clean up anyway.
+ FSFolder_Delete_Tree(folder, foo);
+ FSFolder_Delete_Tree(folder, bar);
}
else {
VArray *list = FSFolder_List_R(folder, NULL);
@@ -121,13 +133,12 @@ test_protect_symlinks(TestBatch *batch)
DECREF(folder);
S_tear_down();
#else
- // TODO: Add test for Windows.
- SKIP(batch, "No symlink() function");
- SKIP(batch, "No symlink() function");
- SKIP(batch, "No symlink() function");
- SKIP(batch, "No symlink() function");
- SKIP(batch, "No symlink() function");
-#endif // CHY_HAS_UNISTD_H
+ SKIP(batch, "Tests requiring symlink() disabled");
+ SKIP(batch, "Tests requiring symlink() disabled");
+ SKIP(batch, "Tests requiring symlink() disabled");
+ SKIP(batch, "Tests requiring symlink() disabled");
+ SKIP(batch, "Tests requiring symlink() disabled");
+#endif // ENABLE_SYMLINK_TESTS
}
void
@@ -166,4 +177,29 @@ TestFSFolder_run_tests() {
DECREF(batch);
}
+#ifdef CHY_HAS_WINDOWS_H
+#include "windows.h"
+#elif defined(CHY_HAS_UNISTD_H)
+#include <unistd.h>
+#else
+#error "Don't have either windows.h or unistd.h"
+#endif
+
+static bool_t
+S_create_test_symlinks(void) {
+#ifdef CHY_HAS_WINDOWS_H
+ if (!CreateSymbolicLink("_fstest\\bar\\banana", "_fstest\\foo\\boffo", 0)
+ || !CreateSymbolicLink("_fstest\\bar\\bazooka", "_fstest\\foo", 1)
+ ) {
+ return false;
+ }
+#else
+ if (symlink("_fstest/foo/boffo", "_fstest/bar/banana")
+ || symlink("_fstest/foo", "_fstest/bar/bazooka")
+ ) {
+ return false;
+ }
+#endif
+ return true;
+}