[2/2] attrib/tests: added tests for some flags
K. Wartke
kwartke at gmail.com
Sun Sep 5 12:45:43 CDT 2010
---
configure | 1 +
configure.ac | 1 +
programs/attrib/tests/Makefile.in | 11 +++
programs/attrib/tests/attrib.c | 157 +++++++++++++++++++++++++++++++++++++
4 files changed, 170 insertions(+), 0 deletions(-)
create mode 100644 programs/attrib/tests/Makefile.in
create mode 100644 programs/attrib/tests/attrib.c
diff --git a/configure b/configure
index c47168d..fec6335 100755
--- a/configure
+++ b/configure
@@ -14987,6 +14987,7 @@ wine_fn_config_makefile libs/wine enable_libs_wine
wine_fn_config_makefile libs/wpp enable_libs_wpp
wine_fn_config_makefile loader enable_loader
wine_fn_config_program attrib enable_attrib install
+wine_fn_config_test programs/attrib/tests attrib.exe_test
wine_fn_config_program cacls enable_cacls install
wine_fn_config_program clock enable_clock install
wine_fn_config_program cmd enable_cmd install
diff --git a/configure.ac b/configure.ac
index 0fe8ebe..9945628 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2766,6 +2766,7 @@ WINE_CONFIG_MAKEFILE([libs/wine])
WINE_CONFIG_MAKEFILE([libs/wpp])
WINE_CONFIG_MAKEFILE([loader])
WINE_CONFIG_PROGRAM(attrib,install)
+WINE_CONFIG_TEST(programs/attrib/tests)
WINE_CONFIG_PROGRAM(cacls,install)
WINE_CONFIG_PROGRAM(clock,install)
WINE_CONFIG_PROGRAM(cmd,install)
diff --git a/programs/attrib/tests/Makefile.in b/programs/attrib/tests/Makefile.in
new file mode 100644
index 0000000..8c371bf
--- /dev/null
+++ b/programs/attrib/tests/Makefile.in
@@ -0,0 +1,11 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR = @srcdir@
+VPATH = @srcdir@
+TESTDLL = attrib.exe
+IMPORTS = kernel32
+
+C_SRCS = \
+ attrib.c
+
+ at MAKE_TEST_RULES@
\ No newline at end of file
diff --git a/programs/attrib/tests/attrib.c b/programs/attrib/tests/attrib.c
new file mode 100644
index 0000000..55bf7b6
--- /dev/null
+++ b/programs/attrib/tests/attrib.c
@@ -0,0 +1,157 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+#include "wine/test.h"
+
+const char testfilename[] = "test.txt";
+const char anotherfilename[] = "text.txt";
+const char namewildcard1[] = "t?st.txt";
+const char namewildcard2[] = "t*t";
+const char testdirname[] = "dir";
+
+BOOL test_attrib(void);
+
+BOOL test_attrib()
+{
+ DWORD attributes;
+ char cmd[30] = "attrib.exe %c%c %s %s";
+ char cmd2[30];
+ STARTUPINFOA si = {sizeof(STARTUPINFOA)};
+ PROCESS_INFORMATION pi;
+
+ /* sets all attributes and unsets them */
+ sprintf(cmd2, cmd, '+', 'r', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ attributes = GetFileAttributesA(testfilename);
+ ok(attributes & FILE_ATTRIBUTE_READONLY, "Cannot set read-only mode!\n");
+ if(!(attributes & FILE_ATTRIBUTE_READONLY))
+ {
+ sprintf(cmd2, cmd, '-', 'r', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ ok(!(attributes & FILE_ATTRIBUTE_READONLY), "Cannot unset read-only mode!\n");
+ }
+
+ sprintf(cmd2, cmd, '+', 'a', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ attributes = GetFileAttributesA(testfilename);
+ ok(attributes & FILE_ATTRIBUTE_ARCHIVE, "Cannot set archive mode!\n");
+ if(!(attributes & FILE_ATTRIBUTE_ARCHIVE))
+ {
+ sprintf(cmd2, cmd, '-', 'a', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ ok(!(attributes & FILE_ATTRIBUTE_ARCHIVE), "Cannot unset archive mode!\n");
+ }
+
+ sprintf(cmd2, cmd, '+', 'h', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ attributes = GetFileAttributesA(testfilename);
+ todo_wine ok(attributes & FILE_ATTRIBUTE_HIDDEN, "Cannot set hidden mode!\n");
+ if(!(attributes & FILE_ATTRIBUTE_HIDDEN))
+ {
+ sprintf(cmd2, cmd, '-', 'h', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ ok(!(attributes & FILE_ATTRIBUTE_HIDDEN), "Cannot unset hidden mode!\n");
+ }
+
+ sprintf(cmd2, cmd, '+', 's', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ attributes = GetFileAttributesA(testfilename);
+ todo_wine ok(attributes & FILE_ATTRIBUTE_SYSTEM, "Cannot set systen file mode!\n");
+ if(!(attributes & FILE_ATTRIBUTE_SYSTEM))
+ {
+ sprintf(cmd2, cmd, '-', 's', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ ok(!(attributes & FILE_ATTRIBUTE_SYSTEM), "Cannot unset system mode!\n");
+ }
+
+ sprintf(cmd2, cmd, '+', 'c', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ attributes = GetFileAttributesA(testfilename);
+ todo_wine ok(attributes & FILE_ATTRIBUTE_COMPRESSED, "Cannot set compressed mode!\n");
+ if(!(attributes & FILE_ATTRIBUTE_COMPRESSED))
+ {
+ sprintf(cmd2, cmd, '-', 'c', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ ok(!(attributes & FILE_ATTRIBUTE_COMPRESSED), "Cannot unset compressed mode!\n");
+ }
+
+ /* tests wildcards in name */
+ sprintf(cmd2, cmd, '+', 'r', namewildcard1, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ attributes = GetFileAttributesA(testfilename);
+ ok(attributes & FILE_ATTRIBUTE_READONLY, "Cannot change mode when using wildcard '?'!\n");
+ sprintf(cmd2, cmd, '-', 'r', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+
+ sprintf(cmd2, cmd, '+', 'r', namewildcard2, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ attributes = GetFileAttributesA(testfilename);
+ ok(attributes & FILE_ATTRIBUTE_READONLY, "Cannot change mode when using wildcard '*'!\n");
+ attributes = GetFileAttributesA(anotherfilename);
+ ok(attributes & FILE_ATTRIBUTE_READONLY, "Cannot change mode when using wildcard '*'!\n");
+ sprintf(cmd2, cmd, '-', 'r', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ sprintf(cmd2, cmd, '-', 'r', anotherfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+
+ /* tests the other flags */
+ sprintf(cmd2, cmd, '+', 'r', testfilename, "/d");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ attributes = GetFileAttributesA(testdirname);
+ todo_wine ok(attributes & FILE_ATTRIBUTE_READONLY, "Cannot change mode on directories!\n");
+ sprintf(cmd2, cmd, '-', 'r', testfilename, "\0");
+ if(!CreateProcessA(NULL, cmd2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return FALSE;
+ return TRUE;
+}
+
+START_TEST(attrib)
+{
+ HANDLE file;
+ BOOL dir;
+
+ file = CreateFileA(testfilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ ok(file != INVALID_HANDLE_VALUE, "CreateFile failed!\n");
+ file = CreateFileA(anotherfilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ ok(file != INVALID_HANDLE_VALUE, "CreateFile failed!\n");
+ dir = CreateDirectoryA(testdirname, 0);
+ ok(dir != 0, "CreateDirectory failed!\n");
+
+ test_attrib();
+
+ RemoveDirectoryA(testdirname);
+ DeleteFileA(testfilename);
+ DeleteFileA(anotherfilename);
+}
--
1.7.2.3.392.g02377
------------AqU6293WZwXeB47uMp0HZ2--
More information about the wine-patches
mailing list