1 | /* |
---|
2 | * setenv test suite. |
---|
3 | * |
---|
4 | * Written by Russ Allbery <rra@stanford.edu> |
---|
5 | * Copyright 2009 Board of Trustees, Leland Stanford Jr. University |
---|
6 | * Copyright (c) 2004, 2005, 2006 |
---|
7 | * by Internet Systems Consortium, Inc. ("ISC") |
---|
8 | * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
---|
9 | * 2002, 2003 by The Internet Software Consortium and Rich Salz |
---|
10 | * |
---|
11 | * See LICENSE for licensing terms. |
---|
12 | */ |
---|
13 | |
---|
14 | #include <config.h> |
---|
15 | #include <portable/system.h> |
---|
16 | |
---|
17 | #include <errno.h> |
---|
18 | |
---|
19 | #include <tests/tap/basic.h> |
---|
20 | #include <util/util.h> |
---|
21 | |
---|
22 | int test_setenv(const char *name, const char *value, int overwrite); |
---|
23 | |
---|
24 | static const char test_var[] = "SETENV_TEST"; |
---|
25 | static const char test_value1[] = "Do not taunt Happy Fun Ball."; |
---|
26 | static const char test_value2[] = "Do not use Happy Fun Ball on concrete."; |
---|
27 | |
---|
28 | |
---|
29 | int |
---|
30 | main(void) |
---|
31 | { |
---|
32 | plan(8); |
---|
33 | |
---|
34 | if (getenv(test_var)) |
---|
35 | bail("%s already in the environment!", test_var); |
---|
36 | |
---|
37 | ok(test_setenv(test_var, test_value1, 0) == 0, "set string 1"); |
---|
38 | is_string(test_value1, getenv(test_var), "...and getenv correct"); |
---|
39 | ok(test_setenv(test_var, test_value2, 0) == 0, "set string 2"); |
---|
40 | is_string(test_value1, getenv(test_var), "...and getenv unchanged"); |
---|
41 | ok(test_setenv(test_var, test_value2, 1) == 0, "overwrite string 2"); |
---|
42 | is_string(test_value2, getenv(test_var), "...and getenv changed"); |
---|
43 | ok(test_setenv(test_var, "", 1) == 0, "overwrite with empty string"); |
---|
44 | is_string("", getenv(test_var), "...and getenv correct"); |
---|
45 | |
---|
46 | return 0; |
---|
47 | } |
---|