[PATCH 1/4] msvcrt: Add tests for _searchenv and _searchenv_s

Kirill Erofeev erofeev.info at gmail.com
Wed Feb 14 06:28:14 CST 2018


Signed-off-by: Kirill Erofeev <erofeev.info at gmail.com>
---
 dlls/msvcrt/tests/dir.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)

diff --git a/dlls/msvcrt/tests/dir.c b/dlls/msvcrt/tests/dir.c
index aa273ea..0750b34 100644
--- a/dlls/msvcrt/tests/dir.c
+++ b/dlls/msvcrt/tests/dir.c
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
+#include <direct.h>
 #include <sys/stat.h>
 #include <io.h>
 #include <mbctype.h>
@@ -416,6 +417,112 @@ static void test_splitpath(void)
     _setmbcp(prev_cp);
 }
 
+static void test_search_environment(void)
+{
+    const char* dirs[] = {
+     "c:\\search_env_test",
+     "c:\\search_env_test\\dir1",
+     "c:\\search_env_test\\dir2",
+     "c:\\search_env_test\\dir3longer",
+     NULL };
+
+    const char* files[] = {
+     "c:\\search_env_test\\dir1\\1.dat",
+     "c:\\search_env_test\\dir1\\2.dat",
+     "c:\\search_env_test\\dir2\\1.dat",
+     "c:\\search_env_test\\dir2\\3.dat",
+     "c:\\search_env_test\\dir3longer\\3.dat",
+     NULL };
+
+    FILE* tmp_file = NULL;
+    const char** file_name = files;
+    const char** dir_name = dirs;
+    char result[MAX_PATH];
+
+    const char eraser[] = "TEST_PATH=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+    while (*dir_name){
+	ok(!mkdir(*dir_name), "Failed to setup test environment (dir = %s)\n", *dir_name);
+        dir_name++;
+    }
+
+    while (*file_name){
+        tmp_file = fopen(*file_name, "wb");
+	ok(tmp_file != NULL, "Failed to setup test environment (file = %s)\n", *file_name);
+        if (tmp_file)
+            fclose(tmp_file);
+        file_name++;
+    }
+
+
+    /*To catch some errors (usage of uninitialized memory) we will trick searchenv to set up memory to predefined values*/
+    putenv(eraser);
+    _searchenv("1.dat", "TEST_PATH", result);
+    putenv("TEST_PATH=c:\\search_env_test\\dir1;c:\\search_env_test\\dir2;c:\\search_env_test\\dir3longer");
+    _searchenv("1.dat", "TEST_PATH", result);
+    ok(!strcmp(result, "c:\\search_env_test\\dir1\\1.dat"), "Failed to found %s in %s got in %s\n", "1.dat", "c:\\search_env_test\\dir1", result);
+
+    putenv(eraser);
+    _searchenv("1.dat", "TEST_PATH", result);
+    putenv("TEST_PATH=c:\\search_env_test\\dir1;c:\\search_env_test\\dir2;c:\\search_env_test\\dir3longer");
+    _searchenv("3.dat", "TEST_PATH", result);
+    ok(!strcmp(result, "c:\\search_env_test\\dir2\\3.dat"), "Failed to found %s in %s got in %s\n", "3.dat", "c:\\search_env_test\\dir2", result);
+
+    putenv(eraser);
+    _searchenv("1.dat", "TEST_PATH", result);
+    putenv("TEST_PATH=;c:\\search_env_test\\dir1;c:\\search_env_test\\dir2;c:\\search_env_test\\dir3longer");
+    _searchenv("1.dat", "TEST_PATH", result);
+    ok(!strcmp(result, "c:\\search_env_test\\dir1\\1.dat"), "Failed to found %s in %s got in %s\n", "1.dat", "c:\\search_env_test\\dir1", result);
+
+    putenv(eraser);
+    _searchenv("1.dat", "TEST_PATH", result);
+    putenv("TEST_PATH=c:\\search_env_test\\dir1;;c:\\search_env_test\\dir2;c:\\search_env_test\\dir3longer");
+    _searchenv("3.dat", "TEST_PATH", result);
+    ok(!strcmp(result, "c:\\search_env_test\\dir2\\3.dat"), "Failed to found %s in %s got in %s\n", "3.dat", "c:\\search_env_test\\dir2", result);
+
+
+
+
+
+    putenv(eraser);
+    _searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH);
+    putenv("TEST_PATH=c:\\search_env_test\\dir1;c:\\search_env_test\\dir2;c:\\search_env_test\\dir3longer");
+    _searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH);
+    ok(!strcmp(result, "c:\\search_env_test\\dir1\\1.dat"), "Failed to found %s in %s got in %s\n", "1.dat", "c:\\search_env_test\\dir1", result);
+
+    putenv(eraser);
+    _searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH);
+    putenv("TEST_PATH=c:\\search_env_test\\dir1;c:\\search_env_test\\dir2;c:\\search_env_test\\dir3longer");
+    _searchenv_s("3.dat", "TEST_PATH", result, MAX_PATH);
+    ok(!strcmp(result, "c:\\search_env_test\\dir2\\3.dat"), "Failed to found %s in %s got in %s\n", "3.dat", "c:\\search_env_test\\dir2", result);
+
+    putenv(eraser);
+    _searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH);
+    putenv("TEST_PATH=;c:\\search_env_test\\dir1;c:\\search_env_test\\dir2;c:\\search_env_test\\dir3longer");
+    _searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH);
+    ok(!strcmp(result, "c:\\search_env_test\\dir1\\1.dat"), "Failed to found %s in %s got in %s\n", "1.dat", "c:\\search_env_test\\dir1", result);
+
+    putenv(eraser);
+    _searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH);
+    putenv("TEST_PATH=c:\\search_env_test\\dir1;;c:\\search_env_test\\dir2;c:\\search_env_test\\dir3longer");
+    _searchenv_s("3.dat", "TEST_PATH", result, MAX_PATH);
+    ok(!strcmp(result, "c:\\search_env_test\\dir2\\3.dat"), "Failed to found %s in %s got in %s\n", "3.dat", "c:\\search_env_test\\dir2", result);
+
+
+
+
+    putenv("TEST_PATH=");
+
+    do {
+        file_name--;
+        ok(!remove(*file_name), "Failed cleanup test (file = %s)\n", *file_name);
+    }while(files != file_name);
+
+    do {
+        dir_name--;
+        ok(!rmdir(*dir_name), "Failed cleanup test (dir = %s)\n", *dir_name);
+    }while(dirs != dir_name);
+}
+
 START_TEST(dir)
 {
     init();
@@ -424,4 +531,6 @@ START_TEST(dir)
     test_makepath();
     test_makepath_s();
     test_splitpath();
+
+    test_search_environment();
 }
-- 
2.7.4




More information about the wine-devel mailing list