1 /* contributor license agreements.
2  * The ASF licenses this file to You under the Apache License, Version 2.0
3  * (the "License"); you may not use this file except in compliance with
4  * the License.  You may obtain a copy of the License at
5  *
6  *     http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 
15 /**
16  * @file
17  *
18  * @Author christian liesch <liesch@gmx.ch>
19  *
20  * Store unit test
21  */
22 
23 /* affects include files on Solaris */
24 #define BSD_COMP
25 
26 /************************************************************************
27  * Includes
28  ***********************************************************************/
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 #include <stdio.h>
33 #include <assert.h>
34 #include "defines.h"
35 
36 #include <apr.h>
37 #include <apr_pools.h>
38 #include <apr_strings.h>
39 
40 #include "store.h"
41 
42 /************************************************************************
43  * Defines
44  ***********************************************************************/
45 
46 /************************************************************************
47  * Typedefs
48  ***********************************************************************/
49 
50 /************************************************************************
51  * Implementation
52  ***********************************************************************/
main(int argc,const char * const argv[])53 int main(int argc, const char *const argv[]) {
54   apr_pool_t *pool;
55   apr_pool_t *subpool;
56   store_t *store;
57   int i;
58   const char *var;
59   const char *val;
60   const char *ref;
61 
62   /** init store */
63   apr_app_initialize(&argc, &argv, NULL);
64   apr_pool_create(&pool, NULL);
65   store = store_make(pool);
66 
67   fprintf(stdout, "add 1000 items\n");
68   for (i = 0; i < 1000; i++) {
69     apr_pool_create(&subpool, pool);
70     var = apr_psprintf(pool, "myVar%d", i);
71     ref = apr_psprintf(pool, "mYvAr%d", i);
72     store_set(store, var, ref);
73     val = store_get(store, var);
74     assert(val != NULL);
75     assert(strcmp(val, ref) == 0);
76     apr_pool_destroy(subpool);
77   }
78 
79   fprintf(stdout, "get all 1000 items\n");
80   for (i = 0; i < 1000; i++) {
81     apr_pool_create(&subpool, pool);
82     var = apr_psprintf(pool, "myVar%d", i);
83     ref = apr_psprintf(pool, "mYvAr%d", i);
84     val = store_get(store, var);
85     assert(val != NULL);
86     assert(strcmp(val, ref) == 0);
87     apr_pool_destroy(subpool);
88   }
89 
90   fprintf(stdout, "set all 1000 items to different value\n");
91   for (i = 0; i < 1000; i++) {
92     apr_pool_create(&subpool, pool);
93     var = apr_psprintf(pool, "myVar%d", i);
94     ref = apr_psprintf(pool, "MyVaR%d", i);
95     store_set(store, var, ref);
96     val = store_get(store, var);
97     assert(val != NULL);
98     assert(strcmp(val, ref) == 0);
99     apr_pool_destroy(subpool);
100   }
101 
102   fprintf(stdout, "get all 1000 items with different value\n");
103   for (i = 0; i < 1000; i++) {
104     apr_pool_create(&subpool, pool);
105     /* name case sensitive */
106     var = apr_psprintf(pool, "MYvAR%d", i);
107     val = store_get(store, var);
108     assert(val == NULL);
109     /* value case sensitive */
110     var = apr_psprintf(pool, "myVar%d", i);
111     ref = apr_psprintf(pool, "mYvAr%d", i);
112     val = store_get(store, var);
113     assert(val != NULL);
114     assert(strcmp(val, ref) != 0);
115     /* get it */
116     var = apr_psprintf(pool, "myVar%d", i);
117     ref = apr_psprintf(pool, "MyVaR%d", i);
118     val = store_get(store, var);
119     assert(val != NULL);
120     assert(strcmp(val, ref) == 0);
121     apr_pool_destroy(subpool);
122   }
123 
124   return 0;
125 }
126 
127