Apache HTTPD
testenv.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "apr_env.h"
18#include "apr_errno.h"
19#include "testutil.h"
20
21#define TEST_ENVVAR_NAME "apr_test_envvar"
22#define TEST_ENVVAR2_NAME "apr_test_envvar2"
23#define TEST_ENVVAR_VALUE "Just a value that we'll check"
24
25static int have_env_set;
26static int have_env_get;
27static int have_env_del;
28
29static void test_setenv(abts_case *tc, void *data)
30{
31 apr_status_t rv;
32
34 have_env_set = (rv != APR_ENOTIMPL);
35 if (!have_env_set) {
36 ABTS_NOT_IMPL(tc, "apr_env_set");
37 } else {
38 APR_ASSERT_SUCCESS(tc, "set environment variable", rv);
39 }
40}
41
42static void test_getenv(abts_case *tc, void *data)
43{
44 char *value;
45 apr_status_t rv;
46
47 if (!have_env_set) {
48 ABTS_NOT_IMPL(tc, "apr_env_set (skip test for apr_env_get)");
49 return;
50 }
51
53 have_env_get = (rv != APR_ENOTIMPL);
54 if (!have_env_get) {
55 ABTS_NOT_IMPL(tc, "apr_env_get");
56 return;
57 }
58 APR_ASSERT_SUCCESS(tc, "get environment variable", rv);
60}
61
62static void test_delenv(abts_case *tc, void *data)
63{
64 char *value;
65 apr_status_t rv;
66
67 if (!have_env_set) {
68 ABTS_NOT_IMPL(tc, "apr_env_set (skip test for apr_env_delete)");
69 return;
70 }
71
73 have_env_del = (rv != APR_ENOTIMPL);
74 if (!have_env_del) {
75 ABTS_NOT_IMPL(tc, "apr_env_delete");
76 return;
77 }
78 APR_ASSERT_SUCCESS(tc, "delete environment variable", rv);
79
80 if (!have_env_get) {
81 ABTS_NOT_IMPL(tc, "apr_env_get (skip sanity check for apr_env_delete)");
82 return;
83 }
86}
87
89static void test_emptyenv(abts_case *tc, void *data)
90{
91 char *value;
92 apr_status_t rv;
93
94 if (!(have_env_set && have_env_get)) {
95 ABTS_NOT_IMPL(tc, "apr_env_set (skip test_emptyenv)");
96 return;
97 }
100 APR_ASSERT_SUCCESS(tc, "set environment variable", rv);
102 APR_ASSERT_SUCCESS(tc, "get environment variable", rv);
103 ABTS_STR_EQUAL(tc, "", value);
104
105 if (!have_env_del) {
106 ABTS_NOT_IMPL(tc, "apr_env (skip recycle test_emptyenv)");
107 return;
108 }
111 APR_ASSERT_SUCCESS(tc, "delete environment variable", rv);
113 ABTS_INT_EQUAL(tc, APR_ENOENT, rv);
114
117 APR_ASSERT_SUCCESS(tc, "set second environment variable", rv);
119 APR_ASSERT_SUCCESS(tc, "get second environment variable", rv);
121
124 ABTS_INT_EQUAL(tc, APR_ENOENT, rv);
126 APR_ASSERT_SUCCESS(tc, "verify second environment variable", rv);
128
131}
132
134{
135 suite = ADD_SUITE(suite)
136
141
142 return suite;
143}
144
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_NOT_IMPL(a, b)
Definition abts.h:129
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
#define APR_ASSERT_SUCCESS(tc, ctxt, rv)
Definition testutil.h:58
APR Environment functions.
APR Error Codes.
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_ENOENT
Definition apr_errno.h:662
apr_size_t size
const char * value
Definition apr_env.h:51
int apr_status_t
Definition apr_errno.h:44
void * data
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
static int have_env_get
Definition testenv.c:26
abts_suite * testenv(abts_suite *suite)
Definition testenv.c:133
#define TEST_ENVVAR_VALUE
Definition testenv.c:23
#define TEST_ENVVAR_NAME
Definition testenv.c:21
static int have_env_set
Definition testenv.c:25
static void test_setenv(abts_case *tc, void *data)
Definition testenv.c:29
#define TEST_ENVVAR2_NAME
Definition testenv.c:22
static void test_getenv(abts_case *tc, void *data)
Definition testenv.c:42
static int have_env_del
Definition testenv.c:27
static void test_emptyenv(abts_case *tc, void *data)
Definition testenv.c:89
static void test_delenv(abts_case *tc, void *data)
Definition testenv.c:62