diff --git a/src/functional/argv.c b/src/functional/argv.c new file mode 100644 index 0000000..487f68d --- /dev/null +++ b/src/functional/argv.c @@ -0,0 +1,17 @@ +#include +#include +#include "test.h" + +#define TEST(c, ...) \ + ( (c) || (t_error(#c " failed: " __VA_ARGS__),0) ) + +int main(int argc, char **argv) +{ + char buf[PATH_MAX]; + TEST(argc == 1, "argc should be 1\n"); + TEST(argv[0] != 0, "argv[0] should not be NULL\n"); + TEST(argv[1] == 0, "argv[1] should be NULL\n"); + TEST(argv[0][0] != 0, "argv[0] should not be empty\n"); + TEST(snprintf(buf, sizeof buf, "%s", argv[0]) < sizeof buf, "argv[0] is not a valid path\n"); + return t_status; +} diff --git a/src/functional/env.c b/src/functional/env.c index ab36381..ab1f6e4 100644 --- a/src/functional/env.c +++ b/src/functional/env.c @@ -14,10 +14,14 @@ int main() char *s; int r; + if (!environ) + t_error("environ is NULL\n"); if (clearenv() || (environ && *environ)) t_error("clrearenv: %s\n", strerror(errno)); if (putenv("TEST=1")) t_error("putenv: %s\n", strerror(errno)); + if (strcmp(environ[0],"TEST=1") != 0) + t_error("putenv failed: environ[0]: %s, wanted \"TEST=1\"\n", environ[0]); if ((s=environ[1])) t_error("environ[1]: %p, wanted 0\n", s); if (!(s=getenv("TEST"))) @@ -30,21 +34,28 @@ int main() t_error("*environ: %p != 0\n", s); if ((s=getenv("TEST"))) t_error("getenv(\"TEST\"): %p, wanted 0\n", s); + errno = 0; if (setenv("TEST", "2", 0)) t_error("setenv: %s\n", strerror(errno)); if (strcmp(s=getenv("TEST"),"2") != 0) t_error("getenv(\"TEST\"): \"%s\", wanted \"2\"\n", s); + if (strcmp(environ[0], "TEST=2") != 0) + t_error("setenv failed: environ[0]: %s, wanted \"TEST=2\"\n", environ[0]); + errno = 0; if (setenv("TEST", "3", 0)) t_error("setenv: %s\n", strerror(errno)); if (strcmp(s=getenv("TEST"),"2") != 0) t_error("getenv(\"TEST\"): \"%s\", wanted \"2\"\n", s); + errno = 0; if (setenv("TEST", "3", 1)) t_error("setenv: %s\n", strerror(errno)); if (strcmp(s=getenv("TEST"),"3") != 0) t_error("getenv(\"TEST\"): \"%s\", wanted \"3\"\n", s); /* test failures */ + errno = 0; if ((r=setenv("","",0)) != -1 || errno != EINVAL) t_error("setenv(\"\",\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL); + errno = 0; if ((r=setenv(0,"",0)) != -1 || errno != EINVAL) t_error("setenv(0,\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL); return t_status;