Skip to content

Commit aa636ed

Browse files
committed
Assertions
1 parent 6c5ecf1 commit aa636ed

4 files changed

Lines changed: 285 additions & 4 deletions

File tree

src/request_context.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ char *request_parser_util(CWS_CONFIG *config)
3939
if (config->xmlSoapSize > soapLenTmp)
4040
goto request_parser_util_copy;
4141

42-
if ((xmlSoapTmp=cws_realloc((void *)config->xmlSoap, ++soapLenTmp))) {
42+
if ((xmlSoapTmp=cws_realloc((void *)config->xmlSoap, soapLenTmp+1))) {
4343
config->xmlSoap=xmlSoapTmp;
44-
config->xmlSoapSize=soapLenTmp;
44+
config->xmlSoapSize=soapLenTmp+1;
4545

4646
goto request_parser_util_copy;
4747
}
@@ -56,6 +56,8 @@ char *request_parser_util(CWS_CONFIG *config)
5656
p=&((char *)memcpy(p, MESSAGE_REQUEST_END, MESSAGE_REQUEST_END_LEN))[MESSAGE_REQUEST_END_LEN];
5757
*p=0;
5858

59+
config->xmlSoapLen=soapLenTmp;
60+
5961
return config->xmlSoap;
6062
} else
6163
config->xmlSoapSize=0;
@@ -66,7 +68,7 @@ char *request_parser_util(CWS_CONFIG *config)
6668
return NULL;
6769
}
6870

69-
char *cws_parse_XML_soap_envelope(struct soap *soap_internal, char *xmlIn, size_t xmlInLen/*, unsigned int action*/)
71+
char *cws_parse_XML_soap_envelope(struct soap *soap_internal, char *xmlIn, size_t xmlInLen)
7072
{
7173
CWS_CONFIG *config=(CWS_CONFIG *)soap_internal->user;
7274

@@ -169,6 +171,11 @@ void cws_recycle_config(CWS_CONFIG *cws_config)
169171
cws_config->c_json_str.json_len=0;
170172
}
171173

174+
if (cws_config->xmlSoap) {
175+
cws_config->xmlSoapLen=0;
176+
cws_config->xmlSoap[0]=0;
177+
}
178+
172179
cws_config->internal_soap_error=0;
173180
cws_config->WitsmlObject=NULL;
174181
cws_config->xmlIn="";

tests/C/include/pointers_asserts.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define POINTER_ASSERTS_H
33

44
void test_pointer_assert();
5+
void test_object_assert();
56

67
#define DECLARE_SOAP_INTERNAL struct soap *soap_internal;
78

@@ -20,5 +21,21 @@ void test_pointer_assert();
2021
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel) \
2122
))
2223

24+
#define CLEAN_TEST_POINTER_ASSERT memset((void *)&test_pointer_assert_rel, 0, sizeof(test_pointer_assert_rel));
25+
26+
#define CHECK_EQ(a, b) a==b
27+
#define CHECK_NEQ(a, b) a!=b
28+
#define CHECK_GT(a, b) a>b
29+
#define CHECK_LT(a, b) a<b
30+
31+
#define COMP_VAL(a, b, cond) \
32+
C_ASSERT_TRUE(CHECK_##cond(a, b), CTEST_SETTER( \
33+
CTEST_TITLE("Testing " #a " is " #cond " " #b), \
34+
CTEST_INFO(#a " value SHOULD be " #cond " " #b), \
35+
CTEST_ON_SUCCESS(#a " " #cond " " #b " SUCCESS"), \
36+
CTEST_ON_ERROR(#a " " #cond " " #b " FAIL"), \
37+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel) \
38+
))
39+
2340
#endif
2441

tests/C/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ int main(int argc, char **argv)
55
{
66
TITLE_MSG("Begin C Witsml 2.1 parser tests ...")
77
test_pointer_assert();
8+
test_object_assert();
89
end_tests();
910
return 0;
1011
}

tests/C/pointers_assert.c

Lines changed: 257 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void test_pointer_assert()
3535
struct test_pointer_assert_rel_t test_pointer_assert_rel;
3636
DECLARE_SOAP_INTERNAL
3737

38-
memset((void *)&test_pointer_assert_rel, 0, sizeof(test_pointer_assert_rel));
38+
CLEAN_TEST_POINTER_ASSERT
3939

4040
C_ASSERT_NOT_NULL((void *)config, CTEST_SETTER(
4141
CTEST_TITLE("Testing CWS config pointer"),
@@ -124,6 +124,262 @@ void test_pointer_assert()
124124

125125
}
126126

127+
void test_object_assert()
128+
{
129+
int err;
130+
char *thisXml;
131+
CWS_CONFIG *config=cws_config_new("This is an instance");
132+
struct test_pointer_assert_rel_t test_pointer_assert_rel;
133+
DECLARE_SOAP_INTERNAL
134+
135+
CLEAN_TEST_POINTER_ASSERT
136+
137+
C_ASSERT_NOT_NULL((void *)config, CTEST_SETTER(
138+
CTEST_TITLE("Testing CWS config pointer @ test_object_assert"),
139+
CTEST_WARN("test_object_assert: This is a main pointer. soap_internal pointer must this config to initialize"),
140+
CTEST_ON_ERROR("Was expected NOT NULL pointer at config"),
141+
CTEST_ON_SUCCESS("CWS config pointer SUCCESS")
142+
))
143+
144+
err=cws_internal_soap_new(&soap_internal, config, NULL);
145+
146+
test_pointer_assert_rel.config=config;
147+
test_pointer_assert_rel.soap_internal=soap_internal;
148+
149+
C_ASSERT_EQUAL_INT(0, err, CTEST_SETTER(
150+
CTEST_TITLE("Testing cws_internal_soap_new result @ test_object_assert"),
151+
CTEST_INFO("Return value SHOULD be 0"),
152+
CTEST_ON_ERROR("Was expected value equal 0"),
153+
CTEST_ON_SUCCESS("cws_internal_soap_new SUCCESS"),
154+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel)
155+
))
156+
157+
C_ASSERT_NOT_NULL((void *)soap_internal, CTEST_SETTER(
158+
CTEST_TITLE("Testing soap_internal is NOT NULL"),
159+
CTEST_INFO("Return value SHOULD be NOT NULL"),
160+
CTEST_ON_SUCCESS("soap_internal pointer NOT NULL SUCCESS"),
161+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel)
162+
))
163+
164+
#define BHA_RUN_XML "examples/xmls/BhaRun.xml"
165+
err=readText(&test_pointer_assert_rel.text, &test_pointer_assert_rel.textLen, BHA_RUN_XML);
166+
167+
C_ASSERT_EQUAL_INT(0, err, CTEST_SETTER(
168+
CTEST_TITLE("Opening file " BHA_RUN_XML "..."),
169+
CTEST_INFO("Return value SHOULD be 0"),
170+
CTEST_ON_SUCCESS("readText SUCCESS"),
171+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel)
172+
))
173+
#undef BHA_RUN_XML
174+
CHECK_CFG_P(soap_internal, soap_internal, EQ)
175+
CHECK_CFG_P(internal_soap_error, 0, EQ)
176+
CHECK_CFG_P(internalInitFlag, 0, GT)
177+
CHECK_CFG_P(xmlIn, NULL, EQ)
178+
CHECK_CFG_P(xmlLen, 0, EQ)
179+
CHECK_CFG_P(xmlSoap, NULL, EQ)
180+
CHECK_CFG_P(xmlSoapLen, 0, EQ)
181+
CHECK_CFG_P(xmlSoapSize, 0, EQ)
182+
CHECK_CFG_P(internal_os, NULL, EQ)
183+
CHECK_CFG_P(WitsmlObject, NULL, EQ)
184+
CHECK_CFG_P(witsml_version, VERSION_UNKNOWN, EQ)
185+
CHECK_CFG_P(object, NULL, EQ)
186+
CHECK_CFG_P(c_bson_serialized.bson, NULL, EQ)
187+
CHECK_CFG_P(c_bson_serialized.bson_size, 0, EQ)
188+
CHECK_CFG_P(c_json_str.json, NULL, EQ)
189+
CHECK_CFG_P(c_json_str.json_len, 0, EQ)
190+
CHECK_CFG_P(object_type, TYPE_None, EQ)
191+
CHECK_CFG_P(object_name, NULL, EQ)
192+
CHECK_CFG_P(cws_soap_fault.faultstring, NULL, EQ)
193+
CHECK_CFG_P(cws_soap_fault.faultstring_len, 0, EQ)
194+
CHECK_CFG_P(cws_soap_fault.XMLfaultdetail, NULL, EQ)
195+
CHECK_CFG_P(cws_soap_fault.XMLfaultdetail_len, 0, EQ)
196+
CHECK_CFG_P(statistics.costs, 0, EQ)
197+
CHECK_CFG_P(statistics.strings, 0, EQ)
198+
CHECK_CFG_P(statistics.shorts, 0, EQ)
199+
CHECK_CFG_P(statistics.ints, 0, EQ)
200+
CHECK_CFG_P(statistics.long64s, 0, EQ)
201+
CHECK_CFG_P(statistics.enums, 0, EQ)
202+
CHECK_CFG_P(statistics.arrays, 0, EQ)
203+
CHECK_CFG_P(statistics.booleans, 0, EQ)
204+
CHECK_CFG_P(statistics.doubles, 0, EQ)
205+
CHECK_CFG_P(statistics.date_times, 0, EQ)
206+
CHECK_CFG_P(statistics.measures, 0, EQ)
207+
CHECK_CFG_P(statistics.event_types, 0, EQ)
208+
CHECK_CFG_P(statistics.total, 0, EQ)
209+
CHECK_CFG_P(statistics.used_memory, 0, EQ)
210+
CHECK_CFG_P(initial_resource_size, 0, NEQ)
211+
212+
thisXml=cws_parse_XML_soap_envelope(test_pointer_assert_rel.soap_internal, (char *)test_pointer_assert_rel.text, test_pointer_assert_rel.textLen);
213+
214+
C_ASSERT_NOT_NULL((void *)thisXml, CTEST_SETTER(
215+
CTEST_TITLE("Checking cws_parse_XML_soap_envelope is NOT NULL"),
216+
CTEST_INFO("Return value SHOULD be NOT NULL"),
217+
CTEST_ON_SUCCESS("cws_parse_XML_soap_envelope SUCCESS"),
218+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel)
219+
))
220+
221+
CHECK_CFG_P(internal_soap_error, 0, EQ)
222+
CHECK_CFG_P(internalInitFlag, 0, GT)
223+
CHECK_CFG_P(xmlIn, NULL, NEQ)
224+
CHECK_CFG_P(xmlLen, 0, NEQ)
225+
CHECK_CFG_P(xmlSoap, NULL, NEQ)
226+
CHECK_CFG_P(xmlSoapLen, 0, NEQ)
227+
CHECK_CFG_P(xmlSoapSize, 0, NEQ)
228+
CHECK_CFG_P(internal_os, NULL, EQ)
229+
230+
COMP_VAL(config->xmlLen, test_pointer_assert_rel.textLen, EQ)
231+
COMP_VAL(config->xmlSoapLen, config->xmlLen, GT)
232+
COMP_VAL(config->xmlSoapLen, config->xmlSoapSize, LT)
233+
234+
CHECK_CFG_P(WitsmlObject, NULL, EQ)
235+
CHECK_CFG_P(witsml_version, VERSION_UNKNOWN, EQ)
236+
CHECK_CFG_P(object, NULL, EQ)
237+
CHECK_CFG_P(c_bson_serialized.bson, NULL, EQ)
238+
CHECK_CFG_P(c_bson_serialized.bson_size, 0, EQ)
239+
CHECK_CFG_P(c_json_str.json, NULL, EQ)
240+
CHECK_CFG_P(c_json_str.json_len, 0, EQ)
241+
CHECK_CFG_P(object_type, TYPE_None, EQ)
242+
CHECK_CFG_P(object_name, NULL, EQ)
243+
CHECK_CFG_P(cws_soap_fault.faultstring, NULL, EQ)
244+
CHECK_CFG_P(cws_soap_fault.faultstring_len, 0, EQ)
245+
CHECK_CFG_P(cws_soap_fault.XMLfaultdetail, NULL, EQ)
246+
CHECK_CFG_P(cws_soap_fault.XMLfaultdetail_len, 0, EQ)
247+
CHECK_CFG_P(statistics.costs, 0, EQ)
248+
CHECK_CFG_P(statistics.strings, 0, EQ)
249+
CHECK_CFG_P(statistics.shorts, 0, EQ)
250+
CHECK_CFG_P(statistics.ints, 0, EQ)
251+
CHECK_CFG_P(statistics.long64s, 0, EQ)
252+
CHECK_CFG_P(statistics.enums, 0, EQ)
253+
CHECK_CFG_P(statistics.arrays, 0, EQ)
254+
CHECK_CFG_P(statistics.booleans, 0, EQ)
255+
CHECK_CFG_P(statistics.doubles, 0, EQ)
256+
CHECK_CFG_P(statistics.date_times, 0, EQ)
257+
CHECK_CFG_P(statistics.measures, 0, EQ)
258+
CHECK_CFG_P(statistics.event_types, 0, EQ)
259+
CHECK_CFG_P(statistics.total, 0, EQ)
260+
CHECK_CFG_P(statistics.used_memory, 0, EQ)
261+
CHECK_CFG_P(initial_resource_size, 0, NEQ)
262+
263+
err=cws_soap_serve(soap_internal);
264+
265+
C_ASSERT_EQUAL_INT(SOAP_OK, err, CTEST_SETTER(
266+
CTEST_TITLE("Checking cws_soap_serve is SOAP_OK"),
267+
CTEST_INFO("Return value SHOULD be SOAP_OK"),
268+
CTEST_ON_SUCCESS("cws_soap_serve SUCCESS"),
269+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel)
270+
))
271+
272+
CHECK_CFG_P(internal_soap_error, 0, EQ)
273+
CHECK_CFG_P(internalInitFlag, 0, GT)
274+
CHECK_CFG_P(xmlIn, NULL, NEQ)
275+
CHECK_CFG_P(xmlLen, 0, NEQ)
276+
CHECK_CFG_P(xmlSoap, NULL, NEQ)
277+
CHECK_CFG_P(xmlSoapLen, 0, NEQ)
278+
CHECK_CFG_P(xmlSoapSize, 0, NEQ)
279+
CHECK_CFG_P(internal_os, NULL, NEQ)
280+
281+
COMP_VAL(config->xmlLen, test_pointer_assert_rel.textLen, EQ)
282+
COMP_VAL(config->xmlSoapLen, config->xmlLen, GT)
283+
COMP_VAL(config->xmlSoapLen, config->xmlSoapSize, LT)
284+
285+
CHECK_CFG_P(WitsmlObject, NULL, NEQ)
286+
CHECK_CFG_P(witsml_version, VERSION_UNKNOWN, EQ) //TODO will be deprecated. ALWAYS VERSION_UNKNOWN
287+
CHECK_CFG_P(object, NULL, NEQ)
288+
CHECK_CFG_P(c_bson_serialized.bson, NULL, EQ)
289+
CHECK_CFG_P(c_bson_serialized.bson_size, 0, EQ)
290+
CHECK_CFG_P(c_json_str.json, NULL, EQ)
291+
CHECK_CFG_P(c_json_str.json_len, 0, EQ)
292+
CHECK_CFG_P(object_type, TYPE_BhaRun, EQ)
293+
CHECK_CFG_P(object_name, NULL, NEQ)
294+
C_ASSERT_EQUAL_STRING("BhaRun", config->object_name, CTEST_SETTER(
295+
CTEST_TITLE("Checking config->object_name is BhaRun"),
296+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel)
297+
))
298+
CHECK_CFG_P(cws_soap_fault.faultstring, NULL, EQ)
299+
CHECK_CFG_P(cws_soap_fault.faultstring_len, 0, EQ)
300+
CHECK_CFG_P(cws_soap_fault.XMLfaultdetail, NULL, EQ)
301+
CHECK_CFG_P(cws_soap_fault.XMLfaultdetail_len, 0, EQ)
302+
CHECK_CFG_P(statistics.costs, 0, EQ)
303+
CHECK_CFG_P(statistics.strings, 83, EQ)
304+
CHECK_CFG_P(statistics.shorts, 0, EQ)
305+
CHECK_CFG_P(statistics.ints, 0, EQ)
306+
CHECK_CFG_P(statistics.long64s, 5, EQ)
307+
CHECK_CFG_P(statistics.enums, 9, EQ)
308+
CHECK_CFG_P(statistics.arrays, 10, EQ)
309+
CHECK_CFG_P(statistics.booleans, 0, EQ)
310+
CHECK_CFG_P(statistics.doubles, 0, EQ)
311+
CHECK_CFG_P(statistics.date_times, 15, EQ)
312+
CHECK_CFG_P(statistics.measures, 63, EQ)
313+
CHECK_CFG_P(statistics.event_types, 0, EQ)
314+
CHECK_CFG_P(statistics.total, 0, EQ)
315+
CHECK_CFG_P(statistics.used_memory, 0, EQ)
316+
CHECK_CFG_P(initial_resource_size, 0, NEQ)
317+
318+
C_ASSERT_NOT_NULL((void *)getStatistics(soap_internal), CTEST_SETTER(
319+
CTEST_TITLE("Checking getStatistics(soap_internal) is NOT NULL"),
320+
CTEST_INFO("Return value SHOULD be NOT NULL"),
321+
CTEST_ON_SUCCESS("getStatistics(soap_internal) SUCCESS"),
322+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel)
323+
))
324+
325+
CHECK_CFG_P(statistics.costs, 0, EQ)
326+
CHECK_CFG_P(statistics.strings, 83, EQ)
327+
CHECK_CFG_P(statistics.shorts, 0, EQ)
328+
CHECK_CFG_P(statistics.ints, 0, EQ)
329+
CHECK_CFG_P(statistics.long64s, 5, EQ)
330+
CHECK_CFG_P(statistics.enums, 9, EQ)
331+
CHECK_CFG_P(statistics.arrays, 10, EQ)
332+
CHECK_CFG_P(statistics.booleans, 0, EQ)
333+
CHECK_CFG_P(statistics.doubles, 0, EQ)
334+
CHECK_CFG_P(statistics.date_times, 15, EQ)
335+
CHECK_CFG_P(statistics.measures, 63, EQ)
336+
CHECK_CFG_P(statistics.event_types, 0, EQ)
337+
CHECK_CFG_P(statistics.total, 185, EQ)
338+
CHECK_CFG_P(statistics.used_memory, 0, NEQ)
339+
CHECK_CFG_P(initial_resource_size, 0, NEQ)
340+
341+
C_ASSERT_NOT_NULL((void *)bsonSerialize(soap_internal), CTEST_SETTER(
342+
CTEST_TITLE("Checking bsonSerialize(soap_internal) is NOT NULL"),
343+
CTEST_INFO("Return value SHOULD be NOT NULL"),
344+
CTEST_ON_SUCCESS("bsonSerialize(soap_internal) SUCCESS"),
345+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel)
346+
))
347+
348+
CHECK_CFG_P(c_bson_serialized.bson, NULL, NEQ)
349+
CHECK_CFG_P(c_bson_serialized.bson_size, 0, NEQ)
350+
351+
C_ASSERT_NOT_NULL((void *)getJson(soap_internal), CTEST_SETTER(
352+
CTEST_TITLE("Checking getJson(soap_internal) is NOT NULL"),
353+
CTEST_INFO("Return value SHOULD be NOT NULL"),
354+
CTEST_ON_SUCCESS("getJson(soap_internal) SUCCESS"),
355+
CTEST_ON_ERROR_CB(test_pointer_assert_RELEASE, (void *)&test_pointer_assert_rel)
356+
))
357+
358+
CHECK_CFG_P(c_json_str.json, NULL, NEQ)
359+
CHECK_CFG_P(c_json_str.json_len, 0, NEQ)
360+
361+
test_pointer_assert_RELEASE((void *)&test_pointer_assert_rel);
362+
363+
C_ASSERT_NULL((void *)test_pointer_assert_rel.soap_internal, CTEST_SETTER(
364+
CTEST_TITLE("Testing soap_internal is NULL"),
365+
CTEST_INFO("Return value SHOULD be NULL"),
366+
CTEST_ON_SUCCESS("soap_internal pointer NULL SUCCESS")
367+
))
368+
369+
C_ASSERT_NULL((void *)test_pointer_assert_rel.config, CTEST_SETTER(
370+
CTEST_TITLE("Testing config is NULL"),
371+
CTEST_INFO("Return config value SHOULD be NULL"),
372+
CTEST_ON_SUCCESS("config pointer NULL SUCCESS")
373+
))
374+
375+
C_ASSERT_NULL((void *)test_pointer_assert_rel.text, CTEST_SETTER(
376+
CTEST_TITLE("Testing text is NULL"),
377+
CTEST_INFO("Return text value SHOULD be NULL"),
378+
CTEST_ON_SUCCESS("text pointer NULL SUCCESS")
379+
))
380+
381+
}
382+
127383
// TODO add tests in parsers and vectors internal_soap pointers
128384

129385
/////////////////////////////////////////////////////// C Witsml Parser ///////////////////////////////////////////////////////

0 commit comments

Comments
 (0)