chiark / gitweb /
wip make it compile; add warnings to Makefile
[inn-innduct.git] / tests / lib / setenv-t.c
1 /* $Id: setenv-t.c 7492 2006-03-19 23:07:34Z eagle $ */
2 /* setenv test suite. */
3
4 #include "config.h"
5
6 #include <errno.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include "inn/messages.h"
11 #include "libinn.h"
12 #include "libtest.h"
13
14 int test_setenv(const char *name, const char *value, int overwrite);
15
16 static const char test_var[] = "SETENV_TEST";
17 static const char test_value1[] = "Do not taunt Happy Fun Ball.";
18 static const char test_value2[] = "Do not use Happy Fun Ball on concrete.";
19
20 int
21 main(void)
22 {
23     char *value;
24     int status;
25
26     if (getenv(test_var))
27         die("%s already in the environment!", test_var);
28
29     puts("12");
30
31     ok(1, test_setenv(test_var, test_value1, 0) == 0);
32     ok_string(2, test_value1, getenv(test_var));
33     ok(3, test_setenv(test_var, test_value2, 0) == 0);
34     ok_string(4, test_value1, getenv(test_var));
35     ok(5, test_setenv(test_var, test_value2, 1) == 0);
36     ok_string(6, test_value2, getenv(test_var));
37     ok(7, test_setenv(test_var, "", 1) == 0);
38     ok_string(8, "", getenv(test_var));
39
40     /* We're run by a shell script wrapper that sets resource limits such
41        that we can allocate one string of this size but not two.  Note that
42        Linux doesn't support data limits, so skip if we get an unexpected
43        success here. */
44     value = xmalloc(100 * 1024);
45     memset(value, 'A', 100 * 1024 - 1);
46     value[100 * 1024 - 1] = 0;
47     ok(9, test_setenv(test_var, value, 0) == 0);
48     ok_string(10, "", getenv(test_var));
49     status = test_setenv(test_var, value, 1);
50     if (status == 0) {
51         puts("ok 11 # skip - no data limit support");
52         puts("ok 12 # skip - no data limit support");
53     } else {
54         ok(11, (status == -1) && (errno == ENOMEM));
55         ok_string(12, "", getenv(test_var));
56     }
57
58     return 0;
59 }