Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/stdlib add a clearenv test.
details: https://anonhg.NetBSD.org/src/rev/6c2f420e3237
branches: trunk
changeset: 758366:6c2f420e3237
user: christos <christos%NetBSD.org@localhost>
date: Wed Nov 03 16:09:43 2010 +0000
description:
add a clearenv test.
diffstat:
tests/lib/libc/stdlib/t_environment.c | 41 +++++++++++++++++++++++++++++++---
1 files changed, 37 insertions(+), 4 deletions(-)
diffs (82 lines):
diff -r bda31e532fb1 -r 6c2f420e3237 tests/lib/libc/stdlib/t_environment.c
--- a/tests/lib/libc/stdlib/t_environment.c Wed Nov 03 15:01:07 2010 +0000
+++ b/tests/lib/libc/stdlib/t_environment.c Wed Nov 03 16:09:43 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_environment.c,v 1.4 2010/10/25 20:35:36 njoly Exp $ */
+/* $NetBSD: t_environment.c,v 1.5 2010/11/03 16:09:43 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_environment.c,v 1.4 2010/10/25 20:35:36 njoly Exp $");
+__RCSID("$NetBSD: t_environment.c,v 1.5 2010/11/03 16:09:43 christos Exp $");
#include <atf-c.h>
#include <errno.h>
@@ -42,6 +42,7 @@
ATF_TC(t_setenv);
ATF_TC(t_putenv);
+ATF_TC(t_clearenv);
ATF_TC_HEAD(t_setenv, tc)
{
@@ -55,6 +56,12 @@
"Test putenv(3), getenv(3), unsetenv(3)");
}
+ATF_TC_HEAD(t_clearenv, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test user clearing environment directly");
+}
+
ATF_TC_BODY(t_setenv, tc)
{
size_t i;
@@ -97,14 +104,40 @@
ATF_CHECK(getenv("crap") == NULL);
ATF_CHECK_ERRNO(EINVAL, putenv(NULL) == -1);
- ATF_CHECK_ERRNO(EINVAL, putenv("val") == -1);
- ATF_CHECK_ERRNO(EINVAL, putenv("=val") == -1);
+ ATF_CHECK_ERRNO(EINVAL, putenv(__UNCONST("val")) == -1);
+ ATF_CHECK_ERRNO(EINVAL, putenv(__UNCONST("=val")) == -1);
+}
+
+extern char **environ;
+
+ATF_TC_BODY(t_clearenv, tc)
+{
+ char name[1024], value[1024];
+
+ for (size_t i = 0; i < 1024; i++) {
+ snprintf(name, sizeof(name), "crap%zu", i);
+ snprintf(value, sizeof(value), "%zu", i);
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ }
+
+ *environ = NULL;
+
+ for (size_t i = 0; i < 1; i++) {
+ snprintf(name, sizeof(name), "crap%zu", i);
+ snprintf(value, sizeof(value), "%zu", i);
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ }
+
+ ATF_CHECK_STREQ(getenv("crap0"), "0");
+ ATF_CHECK(getenv("crap1") == NULL);
+ ATF_CHECK(getenv("crap2") == NULL);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, t_setenv);
ATF_TP_ADD_TC(tp, t_putenv);
+ ATF_TP_ADD_TC(tp, t_clearenv);
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index