aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2017-11-10 13:13:06 -0800
committerCedric BAIL <cedric@osg.samsung.com>2017-11-10 13:13:44 -0800
commitb5333edd3ffe8c0379170a0e9d08ee05af439e2c (patch)
tree2baf5d8bf4e1ccecb5576a0f18a1be6f252f698e /src/tests
parentecore-wl2: Minor formatting fixes (diff)
downloadefl-b5333edd3ffe8c0379170a0e9d08ee05af439e2c.tar.gz
evil: add tests for Windows port.
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/evil/evil_suite.c4
-rw-r--r--src/tests/evil/evil_suite.h4
-rw-r--r--src/tests/evil/evil_test_stdio.c238
-rw-r--r--src/tests/evil/evil_test_stdlib.c317
4 files changed, 559 insertions, 4 deletions
diff --git a/src/tests/evil/evil_suite.c b/src/tests/evil/evil_suite.c
index aeae25ebe0..d8fc492a9a 100644
--- a/src/tests/evil/evil_suite.c
+++ b/src/tests/evil/evil_suite.c
@@ -37,8 +37,8 @@ static const Efl_Test_Case etc[] = {
{ "Main", evil_test_main },
/* { "Mman", evil_test_mman }, */
/* { "Pwd", evil_test_pwd }, */
- /* { "Stdio", evil_test_stdio }, */
- /* { "Stdlib", evil_test_stdlib }, */
+ { "Stdio", evil_test_stdio },
+ { "Stdlib", evil_test_stdlib },
/* { "String", evil_test_string }, */
/* { "Time", evil_test_time }, */
/* { "Unistd", evil_test_unistd }, */
diff --git a/src/tests/evil/evil_suite.h b/src/tests/evil/evil_suite.h
index 17222fcfec..c7220e0b80 100644
--- a/src/tests/evil/evil_suite.h
+++ b/src/tests/evil/evil_suite.h
@@ -31,8 +31,8 @@ void evil_test_dlfcn(TCase *tc);
void evil_test_main(TCase *tc);
/* void evil_test_mman(TCase *tc); */
/* void evil_test_pwd(TCase *tc); */
-/* void evil_test_stdio(TCase *tc); */
-/* void evil_test_stdlib(TCase *tc); */
+void evil_test_stdio(TCase *tc);
+void evil_test_stdlib(TCase *tc);
/* void evil_test_string(TCase *tc); */
/* void evil_test_time(TCase *tc); */
/* void evil_test_unistd(TCase *tc); */
diff --git a/src/tests/evil/evil_test_stdio.c b/src/tests/evil/evil_test_stdio.c
new file mode 100644
index 0000000000..eeab2d08e5
--- /dev/null
+++ b/src/tests/evil/evil_test_stdio.c
@@ -0,0 +1,238 @@
+/* EVIL - EFL library for Windows port
+ * Copyright (C) 2017 Vincent Torri
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <direct.h>
+
+#include <Evil.h>
+
+#include "evil_suite.h"
+
+static int
+_evil_test_stdio_file_new(const char *n, const char *t)
+{
+ FILE *f;
+
+ f = fopen(n, "wb");
+ if (!f)
+ return 0;
+ if (fwrite(t, 1, strlen(t), f) != strlen(t))
+ {
+ fclose(f);
+ _unlink(n);
+ return 0;
+ }
+
+ fclose(f);
+
+ return 1;
+}
+
+static FILE *
+_evil_test_stdio_file_new_and_opened(const char *n, const char *t)
+{
+ FILE *f;
+
+ f = fopen(n, "wb");
+ if (!f)
+ return NULL;
+ if (fwrite(t, 1, strlen(t), f) != strlen(t))
+ {
+ fclose(f);
+ _unlink(n);
+ return NULL;
+ }
+
+ return f;
+}
+
+START_TEST(evil_stdio_rename_src_file_none)
+{
+ int res;
+
+ res = rename(NULL, NULL);
+ fail_if(res != -1);
+
+ res = rename("evil_foo.txt", NULL);
+ fail_if(res != -1);
+}
+END_TEST
+
+START_TEST(evil_stdio_rename_dst_file_none)
+{
+ int res1;
+ int res2;
+ int res3;
+ int res4;
+
+ res1 = _evil_test_stdio_file_new("foo.txt", "test file none");
+ fail_if(res1 == 0);
+
+ res1 = rename("foo.txt", NULL);
+ res2 = rename("foo.txt", "bar.txt");
+ res3 = _unlink("bar.txt");
+ res4 = _unlink("foo.txt");
+
+ fail_if(res1 == 0);
+ fail_if(res2 == -1);
+ fail_if(res3 == -1);
+ fail_if(res4 == 0);
+}
+END_TEST
+
+START_TEST(evil_stdio_rename_dst_file_exists)
+{
+ int res1;
+ int res2;
+ int res3;
+
+ res1 = _evil_test_stdio_file_new("foo.txt", "test file exists foo");
+ fail_if(res1 == 0);
+
+ res2 = _evil_test_stdio_file_new("bar.txt", "test file exists bar");
+ if (res2 == 0)
+ _unlink("foo.txt");
+
+ fail_if(res2 == 0);
+
+ res1 = rename("foo.txt", "bar.txt");
+ res2 = _unlink("bar.txt");
+ res3 = _unlink("foo.txt");
+
+ fail_if(res1 == -1);
+ fail_if(res2 == -1);
+ fail_if(res3 == 0);
+}
+END_TEST
+
+START_TEST(evil_stdio_rename_dst_file_used)
+{
+ FILE *f;
+ int res1;
+ int res2;
+ int res3;
+
+ f = _evil_test_stdio_file_new_and_opened("foo.txt", "test file used foo");
+ fail_if(f == NULL);
+
+ res1 = _evil_test_stdio_file_new("bar.txt", "test file used bar");
+ if (res1 == 0)
+ {
+ fclose(f);
+ _unlink("foo.txt");
+ }
+
+ fail_if(res1 == 0);
+
+ res1 = rename("foo.txt", "bar.txt");
+ res2 = _unlink("bar.txt");
+ fclose(f);
+ res3 = _unlink("foo.txt");
+
+ fail_if(res1 == 0);
+ fail_if(res2 == -1);
+ fail_if(res3 == -1);
+}
+END_TEST
+
+START_TEST(evil_stdio_rename_dst_file_move_to_dir)
+{
+ int res1;
+ int res2;
+ int res3;
+ int res4;
+
+ res1 = _evil_test_stdio_file_new("foo.txt", "test file move foo");
+ fail_if(res1 == 0);
+
+ res2 = _mkdir("foo_dir");
+ fail_if(res2 == -1);
+
+ res1 = rename("foo.txt", "foo_dir/bar.txt");
+ res2 = _unlink("foo_dir/bar.txt");
+ res3 = _rmdir("foo_dir");
+ res4 = _unlink("foo.txt");
+
+ fail_if(res1 == -1);
+ fail_if(res2 == -1);
+ fail_if(res3 == -1);
+ fail_if(res4 == 0);
+}
+END_TEST
+
+START_TEST(evil_stdio_rename_dst_dir_none)
+{
+ int res1;
+ int res2;
+ int res3;
+
+ res1 = _mkdir("foo_dir");
+ fail_if(res1 == -1);
+
+ res1 = rename("foo_dir", "bar_dir");
+ res2 = _rmdir("bar_dir");
+ res3 = _rmdir("foo_dir");
+
+ fail_if(res1 == -1);
+ fail_if(res2 == -1);
+ fail_if(res3 == 0);
+}
+END_TEST
+
+START_TEST(evil_stdio_rename_dst_dir_exists)
+{
+ int res1;
+ int res2;
+ int res3;
+
+ res1 = _mkdir("foo_dir");
+ fail_if(res1 == -1);
+
+ res1 = _mkdir("bar_dir");
+ if (res1 == -1)
+ _rmdir("foo_dir");
+
+ fail_if(res1 == -1);
+
+ res1 = rename("foo_dir", "bar_dir");
+ res2 = _rmdir("bar_dir");
+ res3 = _rmdir("foo_dir");
+
+ fail_if(res1 == -1);
+ fail_if(res2 == -1);
+ fail_if(res3 == 0);
+}
+END_TEST
+
+void evil_test_stdio(TCase *tc)
+{
+ tcase_add_test(tc, evil_stdio_rename_src_file_none);
+
+ tcase_add_test(tc, evil_stdio_rename_dst_file_none);
+ tcase_add_test(tc, evil_stdio_rename_dst_file_exists);
+ tcase_add_test(tc, evil_stdio_rename_dst_file_used);
+ tcase_add_test(tc, evil_stdio_rename_dst_file_move_to_dir);
+
+ tcase_add_test(tc, evil_stdio_rename_dst_dir_none);
+ tcase_add_test(tc, evil_stdio_rename_dst_dir_exists);
+}
diff --git a/src/tests/evil/evil_test_stdlib.c b/src/tests/evil/evil_test_stdlib.c
new file mode 100644
index 0000000000..9de3a149ff
--- /dev/null
+++ b/src/tests/evil/evil_test_stdlib.c
@@ -0,0 +1,317 @@
+/* EVIL - EFL library for Windows port
+ * Copyright (C) 2017 Vincent Torri
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <Evil.h>
+
+#include "evil_suite.h"
+
+START_TEST(evil_stdlib_setenv_NULL)
+{
+ char *val;
+ int res;
+
+ res = setenv("EVIL_TEST_ENV", NULL, 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV");
+ fail_if(val != 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_setenv_NULL_after_set)
+{
+ char *val;
+ int res;
+
+ res = setenv("EVIL_TEST_ENV", "val", 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV");
+ fail_if(val == 0);
+
+ fail_if(strcmp(val, "val") != 0);
+
+ res = setenv("EVIL_TEST_ENV", NULL, 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV");
+ fail_if(val != 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_getenv_one)
+{
+ char *val;
+ int res;
+
+ res = setenv("EVIL_TEST_ENV", "val", 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV");
+ fail_if(val == 0);
+
+ fail_if(strcmp(val, "val") != 0);
+
+ res = setenv("EVIL_TEST_ENV", NULL, 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV");
+ fail_if(val != 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_getenv_two)
+{
+ char *val;
+ int res;
+
+ res = setenv("EVIL_TEST_ENV1", "val1", 1);
+ fail_if(res < 0);
+
+ res = setenv("EVIL_TEST_ENV2", "val2", 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV1");
+ fail_if(val == 0);
+
+ fail_if(strcmp(val, "val1") != 0);
+
+ val = getenv("EVIL_TEST_ENV2");
+ fail_if(val == 0);
+
+ fail_if(strcmp(val, "val2") != 0);
+
+ res = setenv("EVIL_TEST_ENV1", NULL, 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV1");
+ fail_if(val != 0);
+
+ res = setenv("EVIL_TEST_ENV2", NULL, 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV2");
+ fail_if(val != 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_getenv_two_swapped)
+{
+ char *val;
+ int res;
+
+ res = setenv("EVIL_TEST_ENV1", "val1", 1);
+ fail_if(res < 0);
+
+ res = setenv("EVIL_TEST_ENV2", "val2", 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV2");
+ fail_if(val == 0);
+
+ fail_if(strcmp(val, "val2") != 0);
+
+ val = getenv("EVIL_TEST_ENV1");
+ fail_if(val == 0);
+
+ fail_if(strcmp(val, "val1") != 0);
+
+ res = setenv("EVIL_TEST_ENV1", NULL, 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV1");
+ fail_if(val != 0);
+
+ res = setenv("EVIL_TEST_ENV2", NULL, 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV2");
+ fail_if(val != 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_unsetenv)
+{
+ char *val;
+ int res;
+
+ res = setenv("EVIL_TEST_ENV", "val", 1);
+ fail_if(res < 0);
+
+ val = getenv("EVIL_TEST_ENV");
+ fail_if(val == 0);
+
+ fail_if(unsetenv("EVIL_TEST_ENV") != 0);
+
+ val = getenv("EVIL_TEST_ENV");
+ fail_if(val != 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_mkdtemp)
+{
+ char template[] = "file_XXXXXX";
+ char *res;
+
+ res = mkdtemp(template);
+ fail_if(res == NULL);
+
+ fail_if(rmdir(res) < 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_mkdtemp_fail)
+{
+ char template[] = "file_XXX";
+ char *res;
+
+ res = mkdtemp(template);
+ fail_if(res != NULL);
+}
+END_TEST
+
+START_TEST(evil_stdlib_mkstemp)
+{
+ char template[] = "file_XXXXXX";
+ int fd;
+
+ fd = mkstemp(template);
+ fail_if(fd < 0);
+
+ fail_if(close(fd) == -1);
+
+ fail_if(unlink(template) == -1);
+}
+END_TEST
+
+START_TEST(evil_stdlib_mkstemp_fail)
+{
+ char template[] = "file_XXX";
+ int fd;
+
+ fd = mkstemp(template);
+ fail_if(fd >= 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_mkstemps)
+{
+ char template[] = "file_XXXXXX.ext";
+ int fd;
+
+ fd = mkstemps(template, 4);
+ fail_if(fd < 0);
+
+ fail_if(close(fd) == -1);
+
+ fail_if(unlink(template) == -1);
+}
+END_TEST
+
+START_TEST(evil_stdlib_mkstemps_fail_1)
+{
+ char template[] = "file_XXX.ext";
+ int fd;
+
+ fd = mkstemps(template, 4);
+ fail_if(fd >= 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_mkstemps_fail_2)
+{
+ char template[] = "file_XXX";
+ int fd;
+
+ fd = mkstemps(template, 4);
+ fail_if(fd >= 0);
+}
+END_TEST
+
+START_TEST(evil_stdlib_realpath_1)
+{
+ char buf[PATH_MAX];
+ char *filename = "C:\\Windows\\System32\\kernel32.dll";
+ char *res;
+
+ res = realpath(filename, buf);
+ fail_if(res == NULL);
+}
+END_TEST
+
+START_TEST(evil_stdlib_realpath_2)
+{
+ char buf[PATH_MAX];
+ char *filename = "C:\\Windows\\System32\\.\\kernel32.dll";
+ char *res;
+
+ res = realpath(filename, buf);
+ fail_if(res == NULL);
+}
+END_TEST
+
+START_TEST(evil_stdlib_realpath_3)
+{
+ char buf[PATH_MAX];
+ char *filename = "C:\\Windows\\System32\\..\\System32\\kernel32.dll";
+ char *res;
+
+ res = realpath(filename, buf);
+ fail_if(res == NULL);
+}
+END_TEST
+
+START_TEST(evil_stdlib_realpath_fail)
+{
+ char buf[PATH_MAX];
+ char *filename = "C:\\Windows\\System32\\System32\\kernel.dll";
+ char *res;
+
+ res = realpath(filename, buf);
+ fail_if(res != NULL);
+}
+END_TEST
+
+void evil_test_stdlib(TCase *tc)
+{
+ tcase_add_test(tc, evil_stdlib_setenv_NULL);
+ tcase_add_test(tc, evil_stdlib_setenv_NULL_after_set);
+ tcase_add_test(tc, evil_stdlib_getenv_one);
+ tcase_add_test(tc, evil_stdlib_getenv_two);
+ tcase_add_test(tc, evil_stdlib_getenv_two_swapped);
+ tcase_add_test(tc, evil_stdlib_unsetenv);
+
+ tcase_add_test(tc, evil_stdlib_mkdtemp);
+ tcase_add_test(tc, evil_stdlib_mkdtemp_fail);
+ tcase_add_test(tc, evil_stdlib_mkstemp);
+ tcase_add_test(tc, evil_stdlib_mkstemp_fail);
+ tcase_add_test(tc, evil_stdlib_mkstemps);
+ tcase_add_test(tc, evil_stdlib_mkstemps_fail_1);
+ tcase_add_test(tc, evil_stdlib_mkstemps_fail_2);
+
+ tcase_add_test(tc, evil_stdlib_realpath_1);
+ tcase_add_test(tc, evil_stdlib_realpath_2);
+ tcase_add_test(tc, evil_stdlib_realpath_3);
+ tcase_add_test(tc, evil_stdlib_realpath_fail);
+}