Trival test of dna JNI command line entry point

This commit is contained in:
Andrew Bettison 2012-04-23 18:25:26 +09:30
parent a73916e85a
commit 1494172da6
9 changed files with 129 additions and 42 deletions

49
.gitignore vendored
View File

@ -1,27 +1,28 @@
*~
/win32/Debug
/win32/Release
*.user
*.ncb
*.o
*.suo
.*.sw?
configure
autom4te.cache
Makefile
config.log
config.status
config.guess
config.sub
install-sh
ltmain.sh
nacl/nacl-20110221/build
nacl/naclinc.txt
nacl/nacllib.txt
serval.c
dna
*.so
test.*.log
*~
/win32/Debug
/win32/Release
*.user
*.ncb
*.o
*.suo
.*.sw?
configure
autom4te.cache
Makefile
testconfig.sh
config.log
config.status
config.guess
config.sub
install-sh
ltmain.sh
nacl/nacl-20110221/build
nacl/naclinc.txt
nacl/nacllib.txt
serval.c
dna
*.so
test.*.log
config.guess
config.sub
install-sh

10
aclocal.m4 vendored
View File

@ -192,8 +192,14 @@ if test "x$JAVAPREFIX" = x; then
else
test "x$JAVAC" = x && AC_CHECK_PROGS(JAVAC, "gcj -C" guavac jikes javac, $JAVAPREFIX)
fi
test "x$JAVAC" = x && AC_MSG_ERROR([no acceptable Java compiler found in \$PATH])
AX_PROG_JAVAC_WORKS
if test "x$JAVAC" = x; then
AC_MSG_ERROR([no acceptable Java compiler found in \$PATH])
else
AX_PROG_JAVAC_WORKS
if test "x$ac_cv_prog_javac_works" != xyes; then
JAVAC=
fi
fi
AC_PROVIDE([$0])dnl
])
# ===========================================================================

View File

@ -231,9 +231,13 @@ int parseCommandLine(int argc, const char *const *args)
int mandatory = 0;
for (j = 0; (word = command_line_options[i].words[j]); ++j) {
int wordlen = strlen(word);
if (!( (wordlen > 2 && word[0] == '<' && word[wordlen-1] == '>')
|| (wordlen > 4 && word[0] == '[' && word[1] == '<' && word[wordlen-2] == '>' && word[wordlen-1] == ']')
|| (wordlen > 0)
if (optional < 0) {
fprintf(stderr,"Internal error: command_line_options[%d].word[%d]=\"%s\" not allowed after \"...\"\n", i, j, word);
break;
}
else if (!( (wordlen > 2 && word[0] == '<' && word[wordlen-1] == '>')
|| (wordlen > 4 && word[0] == '[' && word[1] == '<' && word[wordlen-2] == '>' && word[wordlen-1] == ']')
|| (wordlen > 0)
)) {
fprintf(stderr,"Internal error: command_line_options[%d].word[%d]=\"%s\" is malformed\n", i, j, word);
break;
@ -245,13 +249,15 @@ int parseCommandLine(int argc, const char *const *args)
}
} else if (word[0] == '[') {
++optional;
} else if (wordlen == 3 && word[0] == '.' && word[1] == '.' && word[2] == '.') {
optional = -1;
} else {
++mandatory;
if (j < argc && strcasecmp(word, args[j])) // literal words don't match
break;
}
}
if (!word && argc >= mandatory && argc <= mandatory + optional) {
if (!word && argc >= mandatory && (optional < 0 || argc <= mandatory + optional)) {
/* A match! We got through the command definition with no internal errors and all literal
args matched and we have a proper number of args. If we have multiple matches, then note
that the call is ambiguous. */
@ -403,6 +409,16 @@ int cli_delim()
return 0;
}
int app_echo(int argc, const char *const *argv, struct command_line_option *o)
{
int i;
for (i = 1; i < argc; ++i) {
cli_puts(argv[i]);
cli_delim();
}
return 0;
}
int app_dna_lookup(int argc, const char *const *argv, struct command_line_option *o)
{
/* Create the instance directory if it does not yet exist */
@ -1048,6 +1064,8 @@ command_line_option command_line_options[]={
"Lookup the SIP/MDP address of the supplied telephone number (DID)."},
{cli_usage,{"help",NULL},0,
"Display command usage."},
{app_echo,{"echo","...",NULL},CLIFLAG_STANDALONE,
"Lookup the SIP/MDP address of the supplied telephone number (DID)."},
{app_server_start,{"node","start",NULL},CLIFLAG_STANDALONE,
"Start Serval Mesh node process with instance path taken from SERVALINSTANCE_PATH environment variable."},
{app_server_start,{"node","start","in","<instance path>",NULL},CLIFLAG_STANDALONE,

View File

@ -11,14 +11,17 @@ dnl Check for a working Java compiler, keep going if unsuccessful.
pushdef([AC_MSG_ERROR], defn([AC_MSG_WARN]))
AC_PROG_JAVAC
popdef([AC_MSG_ERROR])
AC_SUBST([JAVAC])
dnl Check for JNI includes, keep going if not present.
pushdef([AC_MSG_ERROR], defn([AC_MSG_WARN]))
AC_JNI_INCLUDE_DIR
for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS; do
CPPFLAGS="$CPPFLAGS -I$JNI_INCLUDE_DIR"
done
popdef([AC_MSG_ERROR])
if test -n "$JAVAC"; then
pushdef([AC_MSG_ERROR], defn([AC_MSG_WARN]))
AC_JNI_INCLUDE_DIR
for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS; do
CPPFLAGS="$CPPFLAGS -I$JNI_INCLUDE_DIR"
done
popdef([AC_MSG_ERROR])
fi
AC_CHECK_LIB(c,srandomdev)
@ -40,4 +43,7 @@ AC_CHECK_LIB(dl,dlopen,[LDFLAGS="$LDFLAGS -ldl"])
AC_CHECK_LIB(pthread,pthread_create,[LDFLAGS="$LDFLAGS -lpthread"])
AC_CHECK_LIB(portaudio,Pa_Terminate,[LDFLAGS="$LDFLAGS -lportaudio"; CFLAGS="$CFLAGS -DWITH_PORTAUDIO"])
AC_OUTPUT(Makefile)
AC_OUTPUT([
Makefile
testconfig.sh
])

View File

@ -73,7 +73,13 @@ if test "x$JAVAPREFIX" = x; then
else
test "x$JAVAC" = x && AC_CHECK_PROGS(JAVAC, "gcj -C" guavac jikes javac, $JAVAPREFIX)
fi
test "x$JAVAC" = x && AC_MSG_ERROR([no acceptable Java compiler found in \$PATH])
AX_PROG_JAVAC_WORKS
if test "x$JAVAC" = x; then
AC_MSG_ERROR([no acceptable Java compiler found in \$PATH])
else
AX_PROG_JAVAC_WORKS
if test "x$ac_cv_prog_javac_works" != xyes; then
JAVAC=
fi
fi
AC_PROVIDE([$0])dnl
])

4
testconfig.sh.in Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# This file is sourced by some of the test scripts in ./tests.
# It defines some settings that were established by ./configure.
JAVAC="@JAVAC@"

View File

@ -1,6 +1,7 @@
# Common definitions for all test suites in test/*
this=$(abspath "${BASH_SOURCE[0]}")
here="${this%/*}"
# Utility function for setting up a fixture with a DNA server process:
# - Ensure that no dna processes are running

45
tests/dna_jni Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
# Tests for Serval DNA JNI entry points.
#
# Copyright 2012 Paul Gardner-Stephen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
source "${0%/*}/../testframework.sh"
source "${0%/*}/../testdefs.sh"
source "${0%/*}/../testconfig.sh"
setup() {
setup_dna
compile_java_classes
}
compile_java_classes() {
local batphone_source=$(abspath "$here/../..")
assert [ "$JAVAC" ]
mkdir classes
assert $JAVAC -d classes "$batphone_source"/src/org/servalproject/servald/*.java
assert [ -r classes/org/servalproject/servald/ServalD.class ]
}
doc_Echo="Serval echo command works via JNI"
test_Echo() {
execute $dna echo "Hello," "world!"
assertStdoutIs -e 'Hello,\nworld!\n'
}
runTests "$@"

6
vomp.c
View File

@ -1023,7 +1023,7 @@ int app_vomp_status(int argc, const char *const *argv, struct command_line_optio
int app_vomp_dial(int argc, const char *const *argv, struct command_line_option *o)
{
char *sid,*did,*callerid;
const char *sid,*did,*callerid;
cli_arg(argc, argv, o, "sid", &sid, NULL, "");
cli_arg(argc, argv, o, "did", &did, NULL, "");
cli_arg(argc, argv, o, "callerid", &callerid, NULL, NULL);
@ -1055,7 +1055,7 @@ int app_vomp_dial(int argc, const char *const *argv, struct command_line_option
int app_vomp_pickup(int argc, const char *const *argv, struct command_line_option *o)
{
char *call_token;
const char *call_token;
cli_arg(argc, argv, o, "call", &call_token, NULL, "");
overlay_mdp_frame mdp;
@ -1080,7 +1080,7 @@ int app_vomp_pickup(int argc, const char *const *argv, struct command_line_optio
int app_vomp_hangup(int argc, const char *const *argv, struct command_line_option *o)
{
char *call_token;
const char *call_token;
cli_arg(argc, argv, o, "call", &call_token, NULL, "");
overlay_mdp_frame mdp;