aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>2019-12-28 18:38:51 -0300
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2020-03-13 10:49:04 +0100
commit0c6eefa72ccebed094c272e2b115df4c79816338 (patch)
tree712687484c6278ad8d521bfd5b1fedf8ca374c7f
parent0b52328f983fc78b6234d19b03c2816afc724dbd (diff)
test: verify binary data received via D-Bus
The D-Bus test program and script now reads and verifies binary data. Text and binary data are written to separate log files which must be specified by the test script. The checksums of these log files will be compared against the expected value. Signed-off-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
-rw-r--r--test/check_dbus.sh.in19
-rw-r--r--test/test_dbus.c44
2 files changed, 50 insertions, 13 deletions
diff --git a/test/check_dbus.sh.in b/test/check_dbus.sh.in
index 3468073..3b97b36 100644
--- a/test/check_dbus.sh.in
+++ b/test/check_dbus.sh.in
@@ -3,27 +3,36 @@
DIR="@abs_top_srcdir@"
BDIR="@abs_top_builddir@"
LOG="/tmp/zbar_dbus_test_$$.log"
+LOG_BIN="/tmp/zbar_dbus_test_$$.bin"
-EXPECTED="7bfb83f7d54763ddb5841f0892e79071d4bb2c70"
+EXPECTED="7294377b69fb00c7e0811429ab7a42cc8cecfda0"
+EXPECTED_BIN="df896e459e47a7d392031a7d4962722a143e276b"
-$BDIR/test/test_dbus -c1 -t5 >$LOG &
+$BDIR/test/test_dbus -c2 -t5 --log=$LOG --bin-log=$LOG_BIN &
PID=$!
-trap "rm -r $LOG" EXIT
+trap "rm -r $LOG $LOG_BIN" EXIT
$BDIR/zbarimg/zbarimg $DIR/examples/code-128.png 2>/dev/null >/dev/null
+$BDIR/zbarimg/zbarimg -Sbinary $DIR/examples/qr-code-binary.png 2>/dev/null >/dev/null
wait $PID
-if [ ! -s $LOG ]; then
+if [ ! -s $LOG ] || [ ! -s $LOG_BIN ]; then
echo "FAILED: nothing received via D-Bus"
exit -2
fi
CK="`cat $LOG |sha1sum |cut -d" " -f 1`"
if [ "x$CK" != "x$EXPECTED" ]; then
- echo "FAILED: $CK instead of $EXPECTED"
+ echo "FAILED: $CK instead of $EXPECTED"
+ exit -2
+fi
+
+CK_BIN="`cat $LOG_BIN |sha1sum |cut -d" " -f 1`"
+if [ "x$CK_BIN" != "x$EXPECTED_BIN" ]; then
+ echo "FAILED: $CK_BIN instead of $EXPECTED_BIN"
exit -2
fi
diff --git a/test/test_dbus.c b/test/test_dbus.c
index 40632fc..a1af111 100644
--- a/test/test_dbus.c
+++ b/test/test_dbus.c
@@ -26,21 +26,26 @@
#define ZBAR_SIGNAL_CODE "Code"
#define ZBAR_SIGNAL_TYPE "Type"
#define ZBAR_SIGNAL_DATA "Data"
+#define ZBAR_SIGNAL_BINARY_DATA "BinaryData"
#define PROGRAM_NAME "test_dbus"
static const char doc[] = "\nTest if ZBar is sending codes via D-Bus\n";
static const struct argp_option options[] = {
- {"count", 'c', "#codes", 0, "Stop after received #codes", 0},
- {"time", 't', "#seconds", 0, "Stop after #seconds", 0},
- {"help", '?', 0, 0, "Give this help list", -1},
- {"usage", -3, 0, 0, "Give a short usage message", 0},
+ {"count", 'c', "#codes", 0, "Stop after received #codes", 0},
+ {"time", 't', "#seconds", 0, "Stop after #seconds", 0},
+ {"log", 'l', "#file", 0, "Write log to #file", 0},
+ {"bin-log", 'b', "#file", 0, "Write binary log to #file", 0},
+ {"help", '?', 0, 0, "Give this help list", -1},
+ {"usage", -3, 0, 0, "Give a short usage message", 0},
{ 0 }
};
static int max_msg = 0;
static int timeout = 0;
+static FILE *log = NULL;
+static FILE *bin_log = NULL;
static error_t parse_opt(int k, char *optarg, struct argp_state *state)
{
@@ -51,6 +56,12 @@ static error_t parse_opt(int k, char *optarg, struct argp_state *state)
case 't':
timeout = strtoul(optarg, NULL, 0);
break;
+ case 'l':
+ log = fopen(optarg, "wb");
+ break;
+ case 'b':
+ bin_log = fopen(optarg, "wb");
+ break;
case '?':
argp_state_help(state, state->out_stream,
ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG |
@@ -78,13 +89,18 @@ int main(int argc, char *argv[])
DBusConnection* conn;
DBusError err;
char *str, *property;
- int count = 0;
+ int count = 0, length = 0;
if (argp_parse(&argp, argc, argv, ARGP_NO_HELP | ARGP_NO_EXIT, 0, 0)) {
argp_help(&argp, stderr, ARGP_HELP_SHORT_USAGE, PROGRAM_NAME);
return -1;
}
+ if (log == NULL || bin_log == NULL) {
+ fprintf(stderr, "Log files not specified\n");
+ return -1;
+ }
+
// initialise the error value
dbus_error_init(&err);
@@ -112,7 +128,7 @@ int main(int argc, char *argv[])
alarm(timeout);
/* loop listening for signals being emitted */
- printf("Waiting for Zbar events\n");
+ fprintf(stderr, "Waiting for Zbar events\n");
while (true) {
// non blocking read of the next available message
dbus_connection_read_write(conn, 0);
@@ -147,12 +163,20 @@ int main(int argc, char *argv[])
dbus_message_iter_next(&dict);
dbus_message_iter_recurse(&dict, &val);
dbus_message_iter_get_basic(&val, &str);
- printf("Type = %s\n", str);
+ fprintf(stderr, "Type = %s\n", str);
} else if (strcmp(property, ZBAR_SIGNAL_DATA) == 0) {
dbus_message_iter_next(&dict);
dbus_message_iter_recurse(&dict, &val);
dbus_message_iter_get_basic(&val, &str);
- printf("Value = %s\n", str);
+ fprintf(stderr, "Value = %s\n", str);
+ fprintf(log, "%s\n", str);
+ } else if (strcmp(property, ZBAR_SIGNAL_BINARY_DATA) == 0) {
+ dbus_message_iter_next(&dict);
+ dbus_message_iter_recurse(&dict, &val);
+ dbus_message_iter_recurse(&val, &val);
+ dbus_message_iter_get_fixed_array(&val, &str, &length);
+ fprintf(stderr, "BinaryData[%d]\n", length);
+ fwrite(str, sizeof(*str), length, bin_log);
}
}
dbus_message_iter_next(&entry);
@@ -170,5 +194,9 @@ int main(int argc, char *argv[])
// free the message
dbus_message_unref(msg);
}
+
+ fclose(log);
+ fclose(bin_log);
+
return 0;
}

Privacy Policy