miniupnpc: validate upnpreplyparse.c code with "make check"
This commit is contained in:
parent
0f401fe2d5
commit
59d98199c5
|
@ -20,3 +20,5 @@ _jnaerator.*
|
|||
out.errors.txt
|
||||
jnaerator-*.jar
|
||||
miniupnpc.h.bak
|
||||
testupnpreplyparse
|
||||
validateupnpreplyparse
|
||||
|
|
|
@ -3,6 +3,7 @@ miniUPnP client Changelog.
|
|||
|
||||
2013/05/14:
|
||||
Update upnpreplyparse to take into account "empty" elements
|
||||
validate upnpreplyparse.c code with "make check"
|
||||
|
||||
2013/05/03:
|
||||
Fix Solaris build thanks to Maciej Małecki
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $Id: Makefile,v 1.103 2013/03/23 09:05:07 nanard Exp $
|
||||
# $Id: Makefile,v 1.105 2013/05/14 20:37:36 nanard Exp $
|
||||
# MiniUPnP Project
|
||||
# http://miniupnp.free.fr/
|
||||
# http://miniupnp.tuxfamily.org/
|
||||
|
@ -139,7 +139,7 @@ all: $(LIBRARY) $(EXECUTABLES)
|
|||
|
||||
test: check
|
||||
|
||||
check: validateminixml validateminiwget
|
||||
check: validateminixml validateminiwget validateupnpreplyparse
|
||||
|
||||
everything: all $(EXECUTABLES_ADDTESTS)
|
||||
|
||||
|
@ -167,6 +167,11 @@ validateminiwget: testminiwget minihttptestserver testminiwget.sh
|
|||
./testminiwget.sh
|
||||
touch $@
|
||||
|
||||
validateupnpreplyparse: testupnpreplyparse testupnpreplyparse.sh
|
||||
@echo "upnpreplyparse validation test"
|
||||
./testupnpreplyparse.sh
|
||||
touch $@
|
||||
|
||||
clean:
|
||||
$(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) miniupnpcstrings.h
|
||||
# clean python stuff
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
NewRemoteHost=
|
||||
NewExternalPort=123
|
||||
NewProtocol=TCP
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:DeletePortMapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"><NewRemoteHost></NewRemoteHost><NewExternalPort>123</NewExternalPort>
|
||||
<NewProtocol>TCP</NewProtocol></u:DeletePortMapping></s:Body>
|
||||
|
||||
</s:Envelope>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
NewExternalIPAddress=1.2.3.4
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetExternalIPAddressResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"><NewExternalIPAddress>1.2.3.4</NewExternalIPAddress></u:GetExternalIPAddressResponse></s:Body></s:Envelope>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
This directory contains files used for validation of upnpreplyparse.c code.
|
||||
|
||||
Each .xml file to parse should give the results which are in the .namevalue
|
||||
file.
|
||||
|
||||
A .namevalue file contain name=value lines.
|
||||
|
|
@ -1,19 +1,55 @@
|
|||
/* $Id: testupnpreplyparse.c,v 1.2 2008/02/21 13:05:27 nanard Exp $ */
|
||||
/* $Id: testupnpreplyparse.c,v 1.3 2013/05/14 20:37:36 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2007 Thomas Bernard
|
||||
* (c) 2006-2013 Thomas Bernard
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "upnpreplyparse.h"
|
||||
|
||||
void
|
||||
test_parsing(const char * buf, int len)
|
||||
int
|
||||
test_parsing(const char * buf, int len, FILE * f)
|
||||
{
|
||||
char line[1024];
|
||||
struct NameValueParserData pdata;
|
||||
int ok = 1;
|
||||
ParseNameValue(buf, len, &pdata);
|
||||
/* check result */
|
||||
if(f != NULL)
|
||||
{
|
||||
while(fgets(line, sizeof(line), f))
|
||||
{
|
||||
char * value;
|
||||
char * equal;
|
||||
char * parsedvalue;
|
||||
int l;
|
||||
l = strlen(line);
|
||||
while((l > 0) && ((line[l-1] == '\r') || (line[l-1] == '\n')))
|
||||
line[--l] = '\0';
|
||||
/* skip empty lines */
|
||||
if(l == 0)
|
||||
continue;
|
||||
equal = strchr(line, '=');
|
||||
if(equal == NULL)
|
||||
{
|
||||
fprintf(stderr, "Warning, line does not contain '=' : %s\n", line);
|
||||
continue;
|
||||
}
|
||||
*equal = '\0';
|
||||
value = equal + 1;
|
||||
parsedvalue = GetValueFromNameValueList(&pdata, line);
|
||||
if((parsedvalue == NULL) || (strcmp(parsedvalue, value) != 0))
|
||||
{
|
||||
fprintf(stderr, "Element <%s> : expecting value '%s', got '%s'\n",
|
||||
line, value, parsedvalue ? parsedvalue : "<null string>");
|
||||
ok = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
ClearNameValueList(&pdata);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
|
@ -21,9 +57,11 @@ int main(int argc, char * * argv)
|
|||
FILE * f;
|
||||
char buffer[4096];
|
||||
int l;
|
||||
int ok;
|
||||
|
||||
if(argc<2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
|
||||
fprintf(stderr, "Usage: %s file.xml [file.namevalues]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
f = fopen(argv[1], "r");
|
||||
|
@ -34,11 +72,25 @@ int main(int argc, char * * argv)
|
|||
}
|
||||
l = fread(buffer, 1, sizeof(buffer)-1, f);
|
||||
fclose(f);
|
||||
f = NULL;
|
||||
buffer[l] = '\0';
|
||||
if(argc >= 2)
|
||||
{
|
||||
f = fopen(argv[2], "r");
|
||||
if(!f)
|
||||
{
|
||||
fprintf(stderr, "Error : can not open file %s\n", argv[2]);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
DisplayNameValueList(buffer, l);
|
||||
#endif
|
||||
test_parsing(buffer, l);
|
||||
return 0;
|
||||
ok = test_parsing(buffer, l, f);
|
||||
if(f)
|
||||
{
|
||||
fclose(f);
|
||||
}
|
||||
return ok ? 0 : 3;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
for f in testreplyparse/*.xml ; do
|
||||
bf="`dirname $f`/`basename $f .xml`"
|
||||
if ./testupnpreplyparse $f $bf.namevalue ; then
|
||||
echo "$f : passed"
|
||||
else
|
||||
echo "$f : FAILED"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue