blob: 6d4057a8ec6022e68b7fb184aa5170f3de2a68d0 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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 <stdio.h>
18#include <stdlib.h>
19
20#include "abts.h"
21#include "testutil.h"
22
23
24cwmp_t * gcwmp;
25pool_t * gpool;
26
27static char *native_strerror(int statcode, char *buf,
28 size_t bufsize)
29{
30 const char *err = strerror(statcode);
31 if (err) {
32 return strncpy(buf, err, bufsize);
33 } else {
34 return strncpy(buf, "APR does not understand this error code", bufsize);
35 }
36}
37
38void assert_success(abts_case* tc, const char* context, int rv,
39 int lineno)
40{
41 if (rv == 500) {
42 abts_not_impl(tc, context, lineno);
43 } else if (rv != CWMP_OK) {
44 char buf[STRING_MAX], ebuf[128];
45 snprintf(buf, STRING_MAX, "%s (%d): %s\n", context, rv,
46 native_strerror(rv, ebuf, sizeof ebuf));
47 abts_fail(tc, buf, lineno);
48 }
49}
50
51void initialize(void) {
52
53 cwmp_log_init(NULL, CWMP_LOG_DEBUG);
54
55 gpool = (pool_t*)pool_create(POOL_DEFAULT_SIZE);
56 if(NULL == gpool)
57 {
58 cwmp_log_error("pool create return null, size: POOL_DEFAULT_SIZE");
59 exit(-1);
60 }
61
62
63 gcwmp = (cwmp_t*)pool_palloc(gpool, sizeof(cwmp_t));
64 if(!gcwmp)
65 {
66 cwmp_log_error("create cwmp_t error!");
67 exit(-1);
68 }
69 cwmp_log_debug("cwmp at %p", gcwmp);
70 if(!gcwmp->pool)
71 {
72 cwmp_log_debug("cwmp pool at %p", gpool);
73 gcwmp->pool = gpool;
74 }
75
76 cwmp_model_load_xml(gcwmp, "device.xml", NULL, 0);
77
78 char * envstr;
79 char * encstr;
80
81 envstr = "SOAP-ENV"; //cwmp_conf_get("cwmp:soap_env");
82 encstr = "SOAP-ENC"; // cwmp_conf_get("cwmp:soap_enc");
83
84 cwmp_set_envelope_ns(envstr, encstr);
85
86}