From d74c02eaf2edf2a9911e641ab39b57f196c11fdc Mon Sep 17 00:00:00 2001 From: asanoaozora Date: Tue, 23 May 2017 18:06:26 +0200 Subject: refine organization of test scripts --- src/navigation/clone_and_build.sh | 2 +- src/navigation/update_navit.sh | 22 + test/navigation/Makefile | 53 --- test/navigation/README.md | 11 +- test/navigation/bustle.mk | 57 --- test/navigation/dltTrigger.py | 42 -- test/navigation/guidance.pdf | Bin 28432 -> 0 bytes test/navigation/location-input.pdf | Bin 204661 -> 0 bytes test/navigation/location.xml | 10 - test/navigation/location_tokyo.xml | 10 - test/navigation/locations.xml | 42 -- test/navigation/log/guidance.pdf | Bin 0 -> 28432 bytes test/navigation/log/location-input.pdf | Bin 0 -> 204661 bytes test/navigation/log/map-viewer-control.pdf | Bin 0 -> 51211 bytes test/navigation/log/route-calculation.pdf | Bin 0 -> 30751 bytes test/navigation/map-viewer-control.pdf | Bin 51211 -> 0 bytes test/navigation/patches/bustle_filter.patch | 138 ------ test/navigation/resource/location.xml | 10 + test/navigation/resource/location_tokyo.xml | 10 + test/navigation/resource/locations.xml | 42 ++ test/navigation/resource/route.xml | 17 + test/navigation/resource/route_tokyo.xml | 17 + test/navigation/resource/routes.xml | 43 ++ test/navigation/route-calculation.pdf | Bin 30751 -> 0 bytes test/navigation/route.xml | 17 - test/navigation/route_tokyo.xml | 17 - test/navigation/routes.xml | 43 -- test/navigation/run_bustle | 58 --- test/navigation/script-capi/dltTrigger.py | 42 ++ test/navigation/script-capi/lbs-api-test-capi.e4p | 42 ++ .../script-capi/test-address-input-capi.py | 413 +++++++++++++++++ test/navigation/script-capi/test-all-capi | 12 + test/navigation/script-capi/test-guidance-capi.py | 341 ++++++++++++++ .../script-capi/test-location-input-capi.py | 501 +++++++++++++++++++++ .../script-capi/test-map-viewer-control-capi.py | 192 ++++++++ .../script-capi/test-route-calculation-capi.py | 222 +++++++++ test/navigation/script/dltTrigger.py | 42 ++ test/navigation/script/lbs-api-test.e4p | 45 ++ test/navigation/script/test-address-input.py | 410 +++++++++++++++++ test/navigation/script/test-all | 11 + test/navigation/script/test-all_tokyo | 11 + test/navigation/script/test-guidance.py | 361 +++++++++++++++ test/navigation/script/test-location-input.py | 499 ++++++++++++++++++++ .../script/test-map-viewer-control-single.py | 193 ++++++++ test/navigation/script/test-map-viewer-control.py | 262 +++++++++++ test/navigation/script/test-poi.py | 177 ++++++++ test/navigation/script/test-route-calculation.py | 220 +++++++++ test/navigation/test-address-input-capi.py | 413 ----------------- test/navigation/test-address-input.py | 409 ----------------- test/navigation/test-all | 11 - test/navigation/test-all-capi | 12 - test/navigation/test-all_tokyo | 11 - test/navigation/test-guidance-capi.py | 341 -------------- test/navigation/test-guidance.py | 361 --------------- test/navigation/test-location-input-capi.py | 501 --------------------- test/navigation/test-location-input.py | 499 -------------------- test/navigation/test-map-viewer-control-capi.py | 192 -------- test/navigation/test-map-viewer-control.py | 236 ---------- test/navigation/test-poi.py | 177 -------- test/navigation/test-route-calculation-capi.py | 222 --------- test/navigation/test-route-calculation.py | 220 --------- 61 files changed, 4167 insertions(+), 4095 deletions(-) create mode 100755 src/navigation/update_navit.sh delete mode 100644 test/navigation/Makefile delete mode 100644 test/navigation/bustle.mk delete mode 100644 test/navigation/dltTrigger.py delete mode 100644 test/navigation/guidance.pdf delete mode 100644 test/navigation/location-input.pdf delete mode 100644 test/navigation/location.xml delete mode 100644 test/navigation/location_tokyo.xml delete mode 100644 test/navigation/locations.xml create mode 100644 test/navigation/log/guidance.pdf create mode 100644 test/navigation/log/location-input.pdf create mode 100644 test/navigation/log/map-viewer-control.pdf create mode 100644 test/navigation/log/route-calculation.pdf delete mode 100644 test/navigation/map-viewer-control.pdf delete mode 100644 test/navigation/patches/bustle_filter.patch create mode 100644 test/navigation/resource/location.xml create mode 100644 test/navigation/resource/location_tokyo.xml create mode 100644 test/navigation/resource/locations.xml create mode 100644 test/navigation/resource/route.xml create mode 100644 test/navigation/resource/route_tokyo.xml create mode 100644 test/navigation/resource/routes.xml delete mode 100644 test/navigation/route-calculation.pdf delete mode 100644 test/navigation/route.xml delete mode 100644 test/navigation/route_tokyo.xml delete mode 100644 test/navigation/routes.xml delete mode 100755 test/navigation/run_bustle create mode 100644 test/navigation/script-capi/dltTrigger.py create mode 100644 test/navigation/script-capi/lbs-api-test-capi.e4p create mode 100755 test/navigation/script-capi/test-address-input-capi.py create mode 100755 test/navigation/script-capi/test-all-capi create mode 100755 test/navigation/script-capi/test-guidance-capi.py create mode 100755 test/navigation/script-capi/test-location-input-capi.py create mode 100755 test/navigation/script-capi/test-map-viewer-control-capi.py create mode 100755 test/navigation/script-capi/test-route-calculation-capi.py create mode 100644 test/navigation/script/dltTrigger.py create mode 100644 test/navigation/script/lbs-api-test.e4p create mode 100755 test/navigation/script/test-address-input.py create mode 100755 test/navigation/script/test-all create mode 100755 test/navigation/script/test-all_tokyo create mode 100755 test/navigation/script/test-guidance.py create mode 100755 test/navigation/script/test-location-input.py create mode 100755 test/navigation/script/test-map-viewer-control-single.py create mode 100755 test/navigation/script/test-map-viewer-control.py create mode 100755 test/navigation/script/test-poi.py create mode 100755 test/navigation/script/test-route-calculation.py delete mode 100755 test/navigation/test-address-input-capi.py delete mode 100755 test/navigation/test-address-input.py delete mode 100755 test/navigation/test-all delete mode 100755 test/navigation/test-all-capi delete mode 100755 test/navigation/test-all_tokyo delete mode 100755 test/navigation/test-guidance-capi.py delete mode 100755 test/navigation/test-guidance.py delete mode 100755 test/navigation/test-location-input-capi.py delete mode 100755 test/navigation/test-location-input.py delete mode 100755 test/navigation/test-map-viewer-control-capi.py delete mode 100755 test/navigation/test-map-viewer-control.py delete mode 100755 test/navigation/test-poi.py delete mode 100755 test/navigation/test-route-calculation-capi.py delete mode 100755 test/navigation/test-route-calculation.py diff --git a/src/navigation/clone_and_build.sh b/src/navigation/clone_and_build.sh index 95ac4b3..49ed34e 100755 --- a/src/navigation/clone_and_build.sh +++ b/src/navigation/clone_and_build.sh @@ -2,7 +2,7 @@ build_option="" positioning_version='9725fe1f553197042d6445997690d452a73490c0' -navit_version='658060b86596efb270cfcd21e118a9071f5d5092' +navit_version='1e71b5fd4c0bf5ac96e5207c51db7d17057ed798' echo "version of positioning is: $positioning_version" echo "version of navit is: $navit_version" diff --git a/src/navigation/update_navit.sh b/src/navigation/update_navit.sh new file mode 100755 index 0000000..615fb40 --- /dev/null +++ b/src/navigation/update_navit.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +if [ $# -eq 0 ] + then + echo "Need navit commit version" + exit +fi + +navit_version=$1 + + +rm -rf build/navit +rm -rf navit + +git clone https://github.com/navit-gps/navit.git +cd navit +git checkout $navit_version +patch -p0 -i ../patches/search_list_get_unique.diff +patch -p0 -i ../patches/fsa_issue_padding.diff +cd ../ + + diff --git a/test/navigation/Makefile b/test/navigation/Makefile deleted file mode 100644 index 8297454..0000000 --- a/test/navigation/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# @licence app begin@ -# SPDX-License-Identifier: MPL-2.0 -# -# \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen -# -# \file Makefile -# -# \brief This file is part of the Build System. -# -# \author Philippe Colliot -# -# \version 1. -# -# This Source Code Form is subject to the terms of the -# Mozilla Public License (MPL), v. 2.0. -# If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. -# -# For further information see http://www.genivi.org/. -# -# List of changes: -# -# 19/8/2014, Philippe Colliot, creation -# -# @licence end@ - -SRC_DIR=$(CURDIR)/src -PATCH_DIR=$(CURDIR)/patches -BIN_DIR=$(CURDIR)/bin - -default: help - -help:: - @echo "The following targets exist" - @echo "all: Build $(ALL)" - @echo "all2: Install all necessary dependencies and build all" - @echo "clean: Clean up build dir" - @echo "src-clean: Clean up all checked out sources" - - -include *.mk - -all: $(ALL) - -src-clean: $(SRC_CLEAN) - -deps:: - sudo apt-get install $(DEPS) - -all2: deps all - -clean: - rm -rf $(BIN_DIR) diff --git a/test/navigation/README.md b/test/navigation/README.md index c43cbac..d32bfe4 100644 --- a/test/navigation/README.md +++ b/test/navigation/README.md @@ -1,16 +1,22 @@ # Test files for Navigation ## Synopsis These folders contain several files that allow to test the navigation. -Some are for the GlibDBus version: + +The folder ./script contains the ones for the GlibDBus version: test-location-input.py test-address-input.py test-map-viewer-control.py test-guidance.py test-route-calculation.py test-all -and others (*-capi.py) are for the CommonAPI version + +The folder ./script-capi contains the ones for the CommonAPI version NB: For the time being, only the GlibDBus version of navigation runs well +The folder ./resource contains the resource files (e.g. the address) used as input by the script + +The folder ./log contains the generated sequence charts (see below) + There's a mechanism to trig with DLT, so it's necessary to build some stuff before. ##How to build the trigger @@ -30,6 +36,7 @@ First, open a new terminal and launch the navigation by entering: ./run -r ``` Unitary tests: +(under ./script folder) ``` ./test-location-input.py -l locations.xml ./test-route-calculation.py -r routes.xml diff --git a/test/navigation/bustle.mk b/test/navigation/bustle.mk deleted file mode 100644 index 605eac1..0000000 --- a/test/navigation/bustle.mk +++ /dev/null @@ -1,57 +0,0 @@ -# @licence app begin@ -# SPDX-License-Identifier: MPL-2.0 -# -# \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen -# -# \file bustle.mk -# -# \brief This file is part of the Build System. -# -# \author Philippe Colliot -# -# \version 1.0 -# -# This Source Code Form is subject to the terms of the -# Mozilla Public License (MPL), v. 2.0. -# If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. -# -# For further information see http://www.genivi.org/. -# -# List of changes: -# -# , , -# -# @licence end@ -bustle_URL="https://github.com/wjt/bustle.git" -bustle_VERSION=0a426c396ee890bbde67791dbf8d2c21b9cc6a3c -bustle_SRC=$(SRC_DIR)/bustle -bustle_BIN=$(BIN_DIR)/bustle -bustle_DEPS+= gtk2.0-dev haskell-platform libghc-gtk-dev libpcap-dev language-pack-de language-pack-fr gtk2hs-buildtools libdbus-1-dev - -DEPS+=$(bustle_DEPS) -ALL+=bustle -SRC_CLEAN+=clean-bustle_SRC - -help:: - @echo "bustle: Build bustle with patches" - -clean-bustle_SRC:: - rm -rf $(SRC_DIR)/bustle_* - -$(bustle_SRC)/Makefile: - git clone $(bustle_URL) $(bustle_SRC) - cd $(bustle_SRC) && git checkout $(bustle_VERSION) - -$(bustle_SRC)/.patched: $(bustle_SRC)/Makefile - patch -d $(bustle_SRC) -p1 -s <$(PATCH_DIR)/bustle_filter.patch - touch $(bustle_SRC)/.patched - -$(HOME)/.cabal/packages/hackage.haskell.org/00-index.tar: - cabal update - -$(bustle_BIN)/bustle: $(bustle_SRC)/.patched $(HOME)/.cabal/packages/hackage.haskell.org/00-index.tar - cd $(bustle_SRC) && cabal install --builddir=$(bustle_BIN) && cabal build --builddir=$(bustle_BIN) - -bustle: $(bustle_BIN)/bustle - diff --git a/test/navigation/dltTrigger.py b/test/navigation/dltTrigger.py deleted file mode 100644 index 4a11cd8..0000000 --- a/test/navigation/dltTrigger.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 201, PSA GROUPE -* -* \file dlt-trigger.py -* -* \brief This script is part of the FSA scenario. -* -* \author Philippe Colliot -* -* \version 1.0 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -* List of changes: -* -* @licence end@ - -************************************************************************** -""" -import subprocess,os -from subprocess import call - -PATH_TEST_TRIGGER='./dlt-triggers/bin/' - -def startTrigger(name): - FNULL = open(os.devnull,'w') - test_trigger=PATH_TEST_TRIGGER + 'test-trigger' - call([test_trigger, "1", name]) - -def stopTrigger(name): - FNULL = open(os.devnull,'w') - test_trigger=PATH_TEST_TRIGGER + 'test-trigger' - call([test_trigger, "0", name]) - diff --git a/test/navigation/guidance.pdf b/test/navigation/guidance.pdf deleted file mode 100644 index e846ea7..0000000 Binary files a/test/navigation/guidance.pdf and /dev/null differ diff --git a/test/navigation/location-input.pdf b/test/navigation/location-input.pdf deleted file mode 100644 index 8dafd63..0000000 Binary files a/test/navigation/location-input.pdf and /dev/null differ diff --git a/test/navigation/location.xml b/test/navigation/location.xml deleted file mode 100644 index 6baddc7..0000000 --- a/test/navigation/location.xml +++ /dev/null @@ -1,10 +0,0 @@ - - -47.415637 -8.614971 -Switzerland -Zürich -In Lampitzäckern -24 - - diff --git a/test/navigation/location_tokyo.xml b/test/navigation/location_tokyo.xml deleted file mode 100644 index 8718582..0000000 --- a/test/navigation/location_tokyo.xml +++ /dev/null @@ -1,10 +0,0 @@ - - -35.660111 -139.699535 -Japan -東京 -井ノ頭通り -17 - - diff --git a/test/navigation/locations.xml b/test/navigation/locations.xml deleted file mode 100644 index d86e5fc..0000000 --- a/test/navigation/locations.xml +++ /dev/null @@ -1,42 +0,0 @@ - - -47.367264 -8.550330 -Switzerland -Zürich -Schanzengasse -11 - - -46.948108 -7.444643 -Switzerland -Bern -Marktgasse -46 - - -46.206659 -6.1410842 -Switzerland -Genève -Rue Vallin -11 - - -46.990585 -6.928453 -Switzerland -Neuchâtel -Place des Halles -8 - - -47.415637 -8.614971 -Switzerland -Zürich -In Lampitzäckern -24 - - diff --git a/test/navigation/log/guidance.pdf b/test/navigation/log/guidance.pdf new file mode 100644 index 0000000..e846ea7 Binary files /dev/null and b/test/navigation/log/guidance.pdf differ diff --git a/test/navigation/log/location-input.pdf b/test/navigation/log/location-input.pdf new file mode 100644 index 0000000..8dafd63 Binary files /dev/null and b/test/navigation/log/location-input.pdf differ diff --git a/test/navigation/log/map-viewer-control.pdf b/test/navigation/log/map-viewer-control.pdf new file mode 100644 index 0000000..3576c1f Binary files /dev/null and b/test/navigation/log/map-viewer-control.pdf differ diff --git a/test/navigation/log/route-calculation.pdf b/test/navigation/log/route-calculation.pdf new file mode 100644 index 0000000..120c51a Binary files /dev/null and b/test/navigation/log/route-calculation.pdf differ diff --git a/test/navigation/map-viewer-control.pdf b/test/navigation/map-viewer-control.pdf deleted file mode 100644 index 3576c1f..0000000 Binary files a/test/navigation/map-viewer-control.pdf and /dev/null differ diff --git a/test/navigation/patches/bustle_filter.patch b/test/navigation/patches/bustle_filter.patch deleted file mode 100644 index 9208abe..0000000 --- a/test/navigation/patches/bustle_filter.patch +++ /dev/null @@ -1,138 +0,0 @@ -diff -cr bustle-0.4.0/c-sources/pcap-monitor.c bustle-0.4.0.work/c-sources/pcap-monitor.c -*** bustle-0.4.0/c-sources/pcap-monitor.c Wed Jan 18 11:32:49 2012 ---- bustle-0.4.0.work/c-sources/pcap-monitor.c Thu Apr 19 13:59:23 2012 -*************** -*** 20,27 **** ---- 20,31 ---- - #include "pcap-monitor.h" - - #include -+ #include - #include - -+ const char *filter_str; -+ GHashTable *filter_hash; -+ - typedef struct { - struct timeval ts; - GByteArray *blob; -*************** -*** 230,235 **** ---- 234,240 ---- - - /* The cast is necessary because libpcap is weird. */ - pcap_dump ((u_char *) td->dumper, &hdr, message->blob->data); -+ pcap_dump_flush(td->dumper); - g_byte_array_unref (message->blob); - g_slice_free (Message, message); - } -*************** -*** 260,266 **** - } - - GDBusMessage * -! filter ( - GDBusConnection *connection, - GDBusMessage *message, - gboolean is_incoming, ---- 265,271 ---- - } - - GDBusMessage * -! filter_ok ( - GDBusConnection *connection, - GDBusMessage *message, - gboolean is_incoming, -*************** -*** 318,323 **** ---- 323,399 ---- - } - } - -+ gboolean -+ filter_match(GDBusMessage *message) -+ { -+ const char *method=g_strdup_printf("%s.%s",g_dbus_message_get_interface(message),g_dbus_message_get_member(message)); -+ const char *filter=filter_str; -+ gboolean match=FALSE; -+ while (*filter) { -+ int flen; -+ gboolean part_match=TRUE; -+ if (*filter=='-') { -+ filter++; -+ part_match=FALSE; -+ } -+ flen=strcspn(filter,","); -+ if (!strncmp(method, filter, flen)) -+ match=part_match; -+ filter+=flen; -+ if (*filter==',') -+ filter++; -+ } -+ g_free((gpointer)method); -+ return match; -+ } -+ -+ GDBusMessage * -+ filter( -+ GDBusConnection *connection, -+ GDBusMessage *message, -+ gboolean is_incoming, -+ gpointer user_data) -+ { -+ char *id, *reply_id, *found; -+ const gchar *dest; -+ if (!filter_str) -+ return filter_ok(connection, message, is_incoming, user_data); -+ dest = g_dbus_message_get_destination (message); -+ if (!is_incoming || g_strcmp0 (dest, g_dbus_connection_get_unique_name (connection)) == 0) -+ return message; -+ switch(g_dbus_message_get_message_type(message)) { -+ case G_DBUS_MESSAGE_TYPE_METHOD_CALL: -+ if (!filter_match(message)) { -+ g_clear_object (&message); -+ return NULL; -+ } -+ id=g_strdup_printf("%s:%u",g_dbus_message_get_sender(message), g_dbus_message_get_serial(message)); -+ g_hash_table_insert(filter_hash, id, id); -+ return filter_ok(connection, message, is_incoming, user_data); -+ case G_DBUS_MESSAGE_TYPE_SIGNAL: -+ if (!filter_match(message)) { -+ g_clear_object (&message); -+ return NULL; -+ } -+ case G_DBUS_MESSAGE_TYPE_INVALID: -+ return filter_ok(connection, message, is_incoming, user_data); -+ case G_DBUS_MESSAGE_TYPE_METHOD_RETURN: -+ case G_DBUS_MESSAGE_TYPE_ERROR: -+ reply_id=g_strdup_printf("%s:%u",g_dbus_message_get_destination(message), g_dbus_message_get_reply_serial(message)); -+ found=g_hash_table_lookup(filter_hash, reply_id); -+ g_free(reply_id); -+ if (found) { -+ g_hash_table_remove(filter_hash, found); -+ g_free(found); -+ return filter_ok(connection, message, is_incoming, user_data); -+ } -+ g_clear_object (&message); -+ return NULL; -+ } -+ g_clear_object (&message); -+ return NULL; -+ } -+ - static gboolean - match_everything ( - GDBusProxy *bus, -*************** -*** 565,570 **** ---- 641,649 ---- - const gchar *filename, - GError **error) - { -+ filter_str=getenv("BUSTLE_FILTER"); -+ if (!filter_hash) -+ filter_hash=g_hash_table_new(g_str_hash, g_str_equal); - return g_initable_new ( - BUSTLE_TYPE_PCAP_MONITOR, NULL, error, - "bus-type", bus_type, -Only in bustle-0.4.0.work: dist diff --git a/test/navigation/resource/location.xml b/test/navigation/resource/location.xml new file mode 100644 index 0000000..6baddc7 --- /dev/null +++ b/test/navigation/resource/location.xml @@ -0,0 +1,10 @@ + + +47.415637 +8.614971 +Switzerland +Zürich +In Lampitzäckern +24 + + diff --git a/test/navigation/resource/location_tokyo.xml b/test/navigation/resource/location_tokyo.xml new file mode 100644 index 0000000..8718582 --- /dev/null +++ b/test/navigation/resource/location_tokyo.xml @@ -0,0 +1,10 @@ + + +35.660111 +139.699535 +Japan +東京 +井ノ頭通り +17 + + diff --git a/test/navigation/resource/locations.xml b/test/navigation/resource/locations.xml new file mode 100644 index 0000000..d86e5fc --- /dev/null +++ b/test/navigation/resource/locations.xml @@ -0,0 +1,42 @@ + + +47.367264 +8.550330 +Switzerland +Zürich +Schanzengasse +11 + + +46.948108 +7.444643 +Switzerland +Bern +Marktgasse +46 + + +46.206659 +6.1410842 +Switzerland +Genève +Rue Vallin +11 + + +46.990585 +6.928453 +Switzerland +Neuchâtel +Place des Halles +8 + + +47.415637 +8.614971 +Switzerland +Zürich +In Lampitzäckern +24 + + diff --git a/test/navigation/resource/route.xml b/test/navigation/resource/route.xml new file mode 100644 index 0000000..eecf596 --- /dev/null +++ b/test/navigation/resource/route.xml @@ -0,0 +1,17 @@ + + +"Geneve" +"Neuchatel" +"Route GENEVE to NEUCHATEL" +0 + + +46.206659 +6.1410842 + + +46.990585 +6.928453 + + + diff --git a/test/navigation/resource/route_tokyo.xml b/test/navigation/resource/route_tokyo.xml new file mode 100644 index 0000000..439c2bc --- /dev/null +++ b/test/navigation/resource/route_tokyo.xml @@ -0,0 +1,17 @@ + + +"Hamura" +"Shibuya" +"Route HAMURA to SHIBUYA" +0 + + +35.758795 +139.316533 + + +35.660687 +139.699284 + + + diff --git a/test/navigation/resource/routes.xml b/test/navigation/resource/routes.xml new file mode 100644 index 0000000..aceb343 --- /dev/null +++ b/test/navigation/resource/routes.xml @@ -0,0 +1,43 @@ + + +"Zuerich" +"Bern" +"Route ZÜRICH to BERN" +0 + + +"Geneve" +"Neuchatel" +"Route GENEVE to NEUCHATEL" +0 + + +"Zuerich" +"Neuchatel" +"Route ZÜRICH to NEUCHATEL" +0 + + +"Bern" +"Geneve" +"Route BERN to GENEVE" +0 + + +47.367264 +8.550330 + + +46.948108 +7.444643 + + +46.206659 +6.1410842 + + +46.990585 +6.928453 + + + diff --git a/test/navigation/route-calculation.pdf b/test/navigation/route-calculation.pdf deleted file mode 100644 index 120c51a..0000000 Binary files a/test/navigation/route-calculation.pdf and /dev/null differ diff --git a/test/navigation/route.xml b/test/navigation/route.xml deleted file mode 100644 index eecf596..0000000 --- a/test/navigation/route.xml +++ /dev/null @@ -1,17 +0,0 @@ - - -"Geneve" -"Neuchatel" -"Route GENEVE to NEUCHATEL" -0 - - -46.206659 -6.1410842 - - -46.990585 -6.928453 - - - diff --git a/test/navigation/route_tokyo.xml b/test/navigation/route_tokyo.xml deleted file mode 100644 index 439c2bc..0000000 --- a/test/navigation/route_tokyo.xml +++ /dev/null @@ -1,17 +0,0 @@ - - -"Hamura" -"Shibuya" -"Route HAMURA to SHIBUYA" -0 - - -35.758795 -139.316533 - - -35.660687 -139.699284 - - - diff --git a/test/navigation/routes.xml b/test/navigation/routes.xml deleted file mode 100644 index aceb343..0000000 --- a/test/navigation/routes.xml +++ /dev/null @@ -1,43 +0,0 @@ - - -"Zuerich" -"Bern" -"Route ZÜRICH to BERN" -0 - - -"Geneve" -"Neuchatel" -"Route GENEVE to NEUCHATEL" -0 - - -"Zuerich" -"Neuchatel" -"Route ZÜRICH to NEUCHATEL" -0 - - -"Bern" -"Geneve" -"Route BERN to GENEVE" -0 - - -47.367264 -8.550330 - - -46.948108 -7.444643 - - -46.206659 -6.1410842 - - -46.990585 -6.928453 - - - diff --git a/test/navigation/run_bustle b/test/navigation/run_bustle deleted file mode 100755 index 155f0ff..0000000 --- a/test/navigation/run_bustle +++ /dev/null @@ -1,58 +0,0 @@ -#! /bin/sh - -# @licence app begin@ -# SPDX-License-Identifier: MPL-2.0 -# -# \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen -# -# \file run-bustle -# -# \brief This file is part of the test tool. -# -# \author Martin Schaller -# -# \version 1.1 -# -# This Source Code Form is subject to the terms of the -# Mozilla Public License (MPL), v. 2.0. -# If a copy of the MPL was not distributed with this file, -# You can obtain one at http://mozilla.org/MPL/2.0/. -# -# For further information see http://www.genivi.org/. -# -# List of changes: -# -# 19/8/2014, Philippe Colliot, update for the OSS migration -# -# @licence end@ - -if [ -z "$1" ] -then - cat <&2 -Usage: - $0 filter_expr - - filter_expr is a comma separated list of methods/signals to filter, with a prefix of '-' to exclude a method/signal -Examples: - # Only get methods/signals starting with org.genivi. - $0 org.genivi. - - # Like above, but exclude positioning - $0 org.genivi.,-org.genivi.positioning - - # Like above, but exclude positioning and mapmatching - $0 org.genivi.,-org.genivi.positioning.,-org.genivi.navigationcore.MapMatchedPosition. - - #Like above, but include GetPosition of mapmatching - $0 org.genivi.,-org.genivi.positioning.,-org.genivi.navigationcore.MapMatchedPosition.,org.genivi.navigationcore.MapMatchedPosition.GetPosition - -EOT - exit 1 -fi - -if [ ! -f ./bin/bustle/build/bustle/bustle ] -then - echo "Build bustle first: make bustle" -fi -export BUSTLE_FILTER=$1 -exec ./bin/bustle/build/bustle/bustle \ No newline at end of file diff --git a/test/navigation/script-capi/dltTrigger.py b/test/navigation/script-capi/dltTrigger.py new file mode 100644 index 0000000..efba2d7 --- /dev/null +++ b/test/navigation/script-capi/dltTrigger.py @@ -0,0 +1,42 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 201, PSA GROUPE +* +* \file dlt-trigger.py +* +* \brief This script is part of the FSA scenario. +* +* \author Philippe Colliot +* +* \version 1.0 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +* List of changes: +* +* @licence end@ + +************************************************************************** +""" +import subprocess,os +from subprocess import call + +PATH_TEST_TRIGGER='../dlt-triggers/bin/' + +def startTrigger(name): + FNULL = open(os.devnull,'w') + test_trigger=PATH_TEST_TRIGGER + 'test-trigger' + call([test_trigger, "1", name]) + +def stopTrigger(name): + FNULL = open(os.devnull,'w') + test_trigger=PATH_TEST_TRIGGER + 'test-trigger' + call([test_trigger, "0", name]) + diff --git a/test/navigation/script-capi/lbs-api-test-capi.e4p b/test/navigation/script-capi/lbs-api-test-capi.e4p new file mode 100644 index 0000000..8c4ecbe --- /dev/null +++ b/test/navigation/script-capi/lbs-api-test-capi.e4p @@ -0,0 +1,42 @@ + + + + + + + en_US + e44c04c1fa99fe4793858e9c2686862186b21e94 + Python3 + PyQt5 + + 0.1 + asanoaozora + + + test-guidance-capi.py + test-map-viewer-control-capi.py + test-address-input-capi.py + test-location-input-capi.py + test-route-calculation-capi.py + __init__.py + + + + + + + + None + + + + + + + + + + + + + diff --git a/test/navigation/script-capi/test-address-input-capi.py b/test/navigation/script-capi/test-address-input-capi.py new file mode 100755 index 0000000..0d538e6 --- /dev/null +++ b/test/navigation/script-capi/test-address-input-capi.py @@ -0,0 +1,413 @@ +#!/usr/bin/python +# -*- coding: latin-1 -*- + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* @copyright Copyright (C) 2014, Alpine Electronics R&D Europe GmbH +* +* @file test-address-input-capi.py +* +* @brief This simple test shows how the location input +* could be easily tested using a python script +* +* @author Stephan Wiehr +* @author Philippe Colliot +* +* @version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +* this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add status handler +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +from xml.dom.minidom import parse +import xml.dom.minidom +import argparse +import sys +import errno +from dltTrigger import * +#import pdb;pdb.set_trace() + +#name of the test +test_name = "address input" + +# constants as defined in the Navigation API +LATITUDE = 0x00a0 +LONGITUDE = 0x00a1 +ALTITUDE = 0x00a2 +FULL_ADDRESS = 0x00b2 +COUNTRY = 0x00a6 +STATE = 0x00a7 +CITY = 0x00a8 +ZIPCODE = 0x00a9 +STREET = 0x00aa +HOUSE_NUMBER = 0x00ab +CROSSING = 0x00ac +DISTRICT = 0x00ad +PHONE_NUMBER = 0x00ae +POI_NAME = 0x00af +TOWN_CENTER = 0x00b0 +FINISHED = 0x00c2 + +# List of addresses +COUNTRY_STRING = list() +CITY_STRING = list() +STREET_STRING = list() +HOUSE_NUMBER_STRING = list() + +# Default size of the list +WINDOW_SIZE = 20 + +print( '\n--------------------------\n' + \ + 'LocationInput Test' + \ + '\n--------------------------\n') + +parser = argparse.ArgumentParser(description='Location input Test for navigation PoC and FSA.') +parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') +parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') +args = parser.parse_args() + +if args.locations == None: + print('location file is missing') + sys.exit(1) +else: + try: + DOMTree = xml.dom.minidom.parse(args.locations) + except OSError as e: + if e.errno == errno.ENOENT: + print('file not exists') + sys.exit(1) + location_set = DOMTree.documentElement + +print("Area : %s" % location_set.getAttribute("area")) + +locations = location_set.getElementsByTagName("location") + +for location in location_set.getElementsByTagName("location"): + COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) + CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) + STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) + #HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) + HOUSE_NUMBER_STRING.append('') #there's a bug in the navigation core when the house number doesn't exist, so deactivated + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +# connect to session bus +bus = dbus.SessionBus() + +def vprint(text): + if args.verbose: + print(text) + +# Turn selection criteria values to their corresponding string description +def selection_criterion_to_string(selection_criterion): + return_value = '' + if selection_criterion == LATITUDE: + return_value += 'Latitude' + elif selection_criterion == LONGITUDE: + return_value += 'Longitude' + elif selection_criterion == COUNTRY: + return_value += 'Country' + elif selection_criterion == STATE: + return_value += 'State' + elif selection_criterion == CITY: + return_value += 'City' + elif selection_criterion == TOWN_CENTER: + return_value += 'City center' + elif selection_criterion == ZIPCODE: + return_value += 'ZipCode' + elif selection_criterion == STREET: + return_value += 'Street' + elif selection_criterion == HOUSE_NUMBER: + return_value += 'House number' + elif selection_criterion == CROSSING: + return_value += 'Crossing' + elif selection_criterion == FULL_ADDRESS: + return_value += 'Full address' + else: + return_value += str(selection_criterion) + + return return_value + + +# Prepare a dictionary array for pretty printing + +def dictionary_array_to_string(dict_array, linefeed, offset=0): + return_value = '' + i = offset + for item in dict_array: + return_value += str(i) + '. ' + unicode(dictionary_to_string(item)) + if i < offset + len(dict_array) - 1: + return_value += linefeed + i += 1 + + return return_value + + +# Prepare a dictionary for pretty printing +# NB: the value is supposed to be [UInt8, Variant], according to the DBus '(yv)', used by CommonAPI +def dictionary_to_string(dictionary): + return_value = '' + i = 0 + for key in dictionary.keys(): + value = dictionary[key][1] + return_value += selection_criterion_to_string(key) + ' = ' + unicode(value) + i += 1 + if i < len(dictionary): + return_value += ', ' + + return return_value + + +# Prepare a selection criteria array for pretty printing + +def selection_criteria_array_to_string(selection_criterion_array): + return_value = '' + i = 0 + for item in selection_criterion_array: + return_value += selection_criterion_to_string(item) + i += 1 + if i < len(selection_criterion_array): + return_value += ', ' + + return return_value + + +def print_current_context(): + vprint('\tACTIVE CONTEXT: selection criterion = ' + selection_criterion_to_string(current_selection_criterion) + \ + ', search string = \'' + entered_search_string + '\'') + + +def change_selection_criterion(selection_criterion): + global current_selection_criterion + + current_selection_criterion = selection_criterion + location_input_interface.setSelectionCriterion(dbus.UInt32(session_handle), dbus.UInt32(location_input_handle), + dbus.Int32(current_selection_criterion)) + + +# Full string search +def full_string_search(handle, search_string): + global entered_search_string + global found_exact_match + + entered_search_string = search_string + found_exact_match = 1 # Force exact match for full string search + vprint('\nACTION: Full string search, selection criterion = ' + \ + selection_criterion_to_string(current_selection_criterion) + ', trying \'' + search_string + '\'') + location_input_interface.search(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.String(search_string), + dbus.UInt16(20)) + + +def evaluate_address(address, guidable): + test_passed = 0 + print ('\nAddress complete!\nEvaluating...') + if COUNTRY_STRING[current_address_index] == '': + test_passed = 1 + elif address[COUNTRY][1] == COUNTRY_STRING[current_address_index]: + print ('Country\t\t\t-> ok (' + address[COUNTRY][1] + ')') + if CITY_STRING[current_address_index] == '': + test_passed = 1 + elif address[CITY][1] == CITY_STRING[current_address_index]: + print ('City\t\t\t-> ok (' + address[CITY][1] + ')') + if STREET_STRING[current_address_index] == '': + test_passed = 1 + elif address[STREET][1] == STREET_STRING[current_address_index]: + print ('Street\t\t\t-> ok (' + address[STREET][1] + ')') + if HOUSE_NUMBER_STRING[current_address_index] == '': + test_passed = 1 + elif address[HOUSE_NUMBER][1] == HOUSE_NUMBER_STRING[current_address_index]: + print ('House number\t-> ok (' + address[HOUSE_NUMBER][1] + ')') + test_passed = 1 + + if guidable == 1: + if test_passed == 1: + print ('TEST PASSED') + else: + print ('TEST FAILED (wrong address)') + exit() + else: + print ('TEST FAILED (non-guidable address)') + exit() + address_index = current_address_index + 1 + if address_index < len(COUNTRY_STRING): + startSearch(address_index) + else: + print('END OF THE TEST') + exit() + + +# Signal receiver + +# Handler for ContentUpdated callback + +def search_status_handler(handle,status): + vprint('\n::Search status ' + str(int(status))) + if status == FINISHED: + location_input_interface.requestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.UInt16(0), + dbus.UInt16(WINDOW_SIZE)) + + +def content_updated_handler(handle, guidable, available_selection_criteria, address): + global target_search_string + global entered_search_string + + vprint('\n::ContentUpdated for LocationInputHandle ' + str(int(handle))) + print_current_context() + vprint('\tGuidable = ' + str(guidable)) + vprint('\tAvailable selection criteria = ' + selection_criteria_array_to_string(available_selection_criteria)) + vprint('\tADDRESS: '+dictionary_to_string(address)) + + if current_selection_criterion == COUNTRY: + change_selection_criterion(CITY) + target_search_string = CITY_STRING[current_address_index] + elif current_selection_criterion == CITY: + change_selection_criterion(STREET) + target_search_string = STREET_STRING[current_address_index] + elif current_selection_criterion == STREET: + change_selection_criterion(HOUSE_NUMBER) + target_search_string = HOUSE_NUMBER_STRING[current_address_index] + elif current_selection_criterion == HOUSE_NUMBER: + target_search_string = '' + + entered_search_string = '' + + if target_search_string == '': + evaluate_address(address, guidable) + else: + full_string_search(handle, target_search_string) + +def search_result_list_handler(handle, total_size, window_offset, window_size, result_list_window): + global spell_next_character + global found_exact_match + + vprint('\n::SearchResultList for LocationInputHandle ' + str(int(handle))) + print_current_context() + vprint('\tTotal size = ' + str(int(total_size)) + ', Window offset = ' + str(int(window_offset)) + \ + ', Window size = ' + str(int(window_size))) + vprint('\t' + dictionary_array_to_string(result_list_window, '\n\t', window_offset)) + + if found_exact_match == 1: + found_exact_match = 0 + i = 0 + for address in result_list_window: + if unicode(address[current_selection_criterion][1]) == target_search_string: + vprint('\nACTION: Found exact match, selecting \''+unicode(address[current_selection_criterion][1]) + \ + '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.selectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(i)) + break + i += 1 + if i == window_size: + vprint('\nACTION: Found exact match, searching in next page (Session '+str(int(session_handle)) +\ + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.requestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.UInt16(window_offset + window_size), + dbus.UInt16(window_size)) + elif total_size == 1: + selection_name = result_list_window[0][current_selection_criterion] + if selection_name[1] == target_search_string: + vprint('\nACTION: Single entry list, selecting \'' + selection_name[1] + \ + '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.selectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(0)) + else: + print ('\nTEST FAILED (Unexpected single result list)') + exit() + elif spell_next_character == 1: + spell_next_character = 0 + spell_search(handle, entered_search_string, target_search_string, available_characters) + + +# add signal receiver +bus.add_signal_receiver(search_status_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', + signal_name='searchStatus') + +bus.add_signal_receiver(search_result_list_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', + signal_name='searchResultList') + +bus.add_signal_receiver(content_updated_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', + signal_name='contentUpdated') + + +# Timeout +def timeout(): + print('Timeout Expired') + print ('\nTEST FAILED\n') + exit() + +# Exit +def exit(): + error=location_input_interface.deleteLocationInput(dbus.UInt32(session_handle),dbus.UInt32(location_input_handle)) + print('Delete location input: '+str(int(error))) + error=session_interface.deleteSession(dbus.UInt32(session_handle)) + print('Delete session: '+str(int(error))) + stopTrigger(test_name) + loop.quit() + +def startSearch(address_index): + global entered_search_string + global spell_next_character + global found_exact_match + global available_characters + global target_search_string + global current_address_index + current_address_index = address_index + entered_search_string = '' + spell_next_character = 0 + found_exact_match = 0 + available_characters = '' + target_search_string = COUNTRY_STRING[current_address_index] + + change_selection_criterion(COUNTRY) + full_string_search(location_input_handle, target_search_string) + +startTrigger(test_name) + +session = bus.get_object('org.genivi.navigation.navigationcore.Session.v4_0_Session', '/Session') +session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session.v4_0') + +# Get SessionHandle +ret = session_interface.createSession(dbus.String('test location input')) +session_handle=ret[1] +print ('Session handle = ' + str(session_handle)) + +location_input_obj = bus.get_object('org.genivi.navigation.navigationcore.LocationInput.v4_0_LocationInput', '/LocationInput') +location_input_interface = dbus.Interface(location_input_obj, dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0') +# Get LocationInputHandle +ret = location_input_interface.createLocationInput(dbus.UInt32(session_handle)) +location_input_handle = ret[1] +print ('LocationInput handle = ' + str(location_input_handle)) + +attributes = location_input_interface.getSupportedAddressAttributes() +print ('Initially supported address attributes = ' + selection_criteria_array_to_string(attributes)) + +# Configuration +current_address_index = 0 +entered_search_string = '' +spell_next_character = 0 +found_exact_match = 0 +available_characters = '' +target_search_string = '' +current_selection_criterion = 0 + +startSearch(0) + +# Main loop +gobject.timeout_add(10000, timeout) +loop = gobject.MainLoop() +loop.run() diff --git a/test/navigation/script-capi/test-all-capi b/test/navigation/script-capi/test-all-capi new file mode 100755 index 0000000..b464713 --- /dev/null +++ b/test/navigation/script-capi/test-all-capi @@ -0,0 +1,12 @@ +#!/bin/bash + +./test-location-input-capi.py -l ../resource/locations.xml +sleep 2 +./test-route-calculation-capi.py -r ../resource/routes.xml +sleep 2 +./test-address-input-capi.py -l ../resource/location.xml +sleep 2 +./test-guidance-capi.py -r ../resource/route.xml +sleep 2 +./test-map-viewer-control-capi.py ../resource/location.xml + diff --git a/test/navigation/script-capi/test-guidance-capi.py b/test/navigation/script-capi/test-guidance-capi.py new file mode 100755 index 0000000..3e10065 --- /dev/null +++ b/test/navigation/script-capi/test-guidance-capi.py @@ -0,0 +1,341 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2016, XS Embedded GmbH, PCA Peugeot Citroen +* +* \file test-guidance-capi.py +* +* \brief This simple test shows how the guidance +* could be easily tested using a python script +* +* \author Marco Residori +* \author Philippe Colliot +* +* \version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +from collections import namedtuple,defaultdict +from _dbus_bindings import Int32 +from PIL.GimpGradientFile import SEGMENTS +from xml.dom.minidom import parse +import xml.dom.minidom +import argparse +import sys +import errno +import time +from dltTrigger import * +#import pdb; +#pdb.set_trace() + +from pip import locations + +#name of the test +test_name = "guidance" + +#constants as defined in the Navigation API +GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0 +GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1 +GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e +GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f +GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147 +GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141 +GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142 +GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143 +GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144 +GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148 +GENIVI_NAVIGATIONCORE_TIME = 0x0149 +GENIVI_NAVIGATIONCORE_SPEED = 0x00a4 +GENIVI_NAVIGATIONCORE_ACTIVE = 0x0060 + +#constants used into the script +TIME_OUT = 10000 +HORIZONTAL_SIZE = 800 +VERTICAL_SIZE = 480 +MAIN_MAP = 0x0010 +NUMBER_OF_SEGMENTS = 1000 + +#add signal receivers +def routing_routeCalculationProgressUpdate_handler(routeHandle, status, percentage): + print 'Route Calculation: ' + str(int(percentage)) + ' %' + +def routing_routeCalculationSuccessful_handler(routeHandle,unfullfilledPreferences): + global g_guidance_active + print 'Route Calculation Successfull: ' + str(routeHandle) + #get route overview + overview = g_routing_interface.getRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])) + #retrieve distance + totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)]) + print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km' + totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]) + m, s = divmod(totalTime[1], 60) + h, m = divmod(m, 60) + print "Total Time: %d:%02d:%02d" % (h, m, s) + #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) + valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME), + dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE), + dbus.Int32(GENIVI_NAVIGATIONCORE_TIME), + dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)] + numberOfSegments = NUMBER_OF_SEGMENTS + detailLevel = 0 + offset = 0 + ret = g_routing_interface.getRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(detailLevel),dbus.Array(valuesToReturn),dbus.UInt32(numberOfSegments),dbus.UInt32(offset)) + print "Total number of segments: " + str(ret[0]) + #len(ret[1]) is size + #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude + g_guidance_active = True +# pdb.set_trace() +# display_route(routeHandle) + launch_guidance(routeHandle) + +def session_sessionDeleted_handler(sessionHandle): + print('Session handle deleted: '+str(sessionHandle)) + if sessionHandle == g_navigationcore_session_handle: + print 'Test PASSED' + else: + print 'Test FAILED' + exit() + +def routing_routeDeleted_handler(routeHandle): + print('Route handle deleted: '+str(routeHandle)) + +def guidance_guidanceStatusChanged_handler(guidanceStatus,routeHandle): + global g_guidance_active + print('Guidance status changed: '+str(guidanceStatus)) + if guidanceStatus != GENIVI_NAVIGATIONCORE_ACTIVE and g_guidance_active == True: + g_guidance_active = False + route = g_current_route + 1 + if route < routes.length: + launch_route_calculation(route) + else: + for i in range(routes.length): + g_routing_interface.deleteRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data)) + g_navigationcore_session_interface.deleteSession(dbus.UInt32(g_navigationcore_session_handle)) + +def guidance_positionOnRouteChanged_handler(offsetOnRoute): + print "Offset on route: " +str(offsetOnRoute) + ret = g_guidance_interface.getDestinationInformation() + print "Travel time: " +str(ret[1]) + ret = g_guidance_interface.getManeuversList(dbus.UInt16(1),dbus.UInt32(0)) + print "Number of maneuvers: " +str(ret[1]) + print "Next road to turn: " +str(ret[2][0][4]) + g_mapmatchedposition_interface.setSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(False)) + g_guidance_interface.stopGuidance(dbus.UInt32(g_navigationcore_session_handle)) + +def mapmatchedposition_simulationStatusChanged_handler(simulationStatus): + print "Simulation status: " +str(simulationStatus) + +#timeout +def timeout(): + print 'Timeout Expired' + print '\nTest FAILED' + exit() + +def exit(): + stopTrigger(test_name) + loop.quit() + +def display_route(route): + g_mapviewercontrol_interface.displayRoute( \ + dbus.UInt32(g_mapviewer_sessionhandle), \ + dbus.UInt32(g_mapviewer_maphandle), \ + dbus.UInt32(route), \ + dbus.Boolean(True)) + +def launch_guidance(route): + g_mapmatchedposition_interface.setSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(True)) + g_guidance_interface.startGuidance(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(route)) +# g_mapmatchedposition_interface.startSimulation(g_navigationcore_session_handle) + +def launch_route_calculation(route): + global g_current_route + global g_route_handle + global g_routing_interface + global g_navigationcore_session_handle + g_current_route = route + print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data + #get route handle + ret = g_routing_interface.createRoute(dbus.UInt32(g_navigationcore_session_handle)) + g_route_handle=ret[1] + routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle + print 'Route handle: ' + str(g_route_handle) + start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data + dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data + print 'Calculating route from \ +'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \ +'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')' + #set waypoints + waypointDoubleCapiType = 0x03 + g_routing_interface.setWaypoints(dbus.UInt32(g_navigationcore_session_handle), \ + dbus.UInt32(g_route_handle), \ + dbus.Boolean(0), \ + dbus.Array([ \ + dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \ + dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \ + ]) \ + ) + + #calculate route + g_routing_interface.calculateRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(g_route_handle)) + +def createMapView(): + global g_mapviewer_sessionhandle + global g_mapviewer_sessionstatus + global g_mapviewer_sessionlist + global g_mapviewer_maphandle + + #get mapviewer session handle + ret = g_mapviewer_session_interface.createSession(dbus.String('test mapviewer')) + g_mapviewer_sessionhandle=ret[1] + print 'Mapviewer session handle: ' + str(g_mapviewer_sessionhandle) + + g_mapviewer_sessionstatus = g_mapviewer_session_interface.getSessionStatus(dbus.UInt32(g_mapviewer_sessionhandle)); + print 'Mapviewer session status: ' + str(g_mapviewer_sessionstatus) + + g_mapviewer_sessionlist = g_mapviewer_session_interface.getAllSessions(); + print 'Mapviewer active sessions = ' + str(len(g_mapviewer_sessionlist)) + + #get mapviewer handle + ret = g_mapviewercontrol_interface.createMapViewInstance( \ + dbus.UInt32(g_mapviewer_sessionhandle), \ + dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ + dbus.Int32(MAIN_MAP)) + g_mapviewer_maphandle=ret[1] + + print 'MapView handle: ' + str(g_mapviewer_maphandle) + + time.sleep(2) + + print 'Stop following the car position' + g_mapviewercontrol_interface.setFollowCarMode( \ + dbus.UInt32(g_mapviewer_sessionhandle), \ + dbus.UInt32(g_mapviewer_maphandle), \ + dbus.Boolean(False)) + +def deleteMapView(): + g_mapviewercontrol_interface.releaseMapViewInstance( \ + dbus.UInt32(g_mapviewer_sessionhandle), \ + dbus.UInt32(g_mapviewer_maphandle)) + + g_mapviewer_session_interface.deleteSession(g_mapviewer_sessionhandle) + + +print('--------------------------') +print('Guidance Test') +print('--------------------------') + +parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.') +parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format') +args = parser.parse_args() + +if args.routes == None: + print('route file is missing') + sys.exit(1) +else: + try: + DOMTree = xml.dom.minidom.parse(args.routes) + except OSError as e: + if e.errno == errno.ENOENT: + print('file not exists') + sys.exit(1) + route_set = DOMTree.documentElement + +print("Country : %s" % route_set.getAttribute("country")) + +routes = route_set.getElementsByTagName("route") + +#create dictionary with the locations +locations = {} +for location in route_set.getElementsByTagName("location"): + lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data] + locations[location.getAttribute("name")] = lat_long + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +#connect to session bus +bus = dbus.SessionBus() + +bus.add_signal_receiver(routing_routeCalculationProgressUpdate_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ + signal_name = "routeCalculationProgressUpdate") + +bus.add_signal_receiver(routing_routeCalculationSuccessful_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ + signal_name = "routeCalculationSuccessful") + +bus.add_signal_receiver(routing_routeDeleted_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ + signal_name = "routeDeleted") + +bus.add_signal_receiver(session_sessionDeleted_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Session.v4_0", \ + signal_name = "sessionDeleted") + +bus.add_signal_receiver(guidance_guidanceStatusChanged_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Guidance.v4_0", \ + signal_name = "guidanceStatusChanged") + +bus.add_signal_receiver(guidance_positionOnRouteChanged_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Guidance.v4_0", \ + signal_name = "positionOnRouteChanged") + +bus.add_signal_receiver(mapmatchedposition_simulationStatusChanged_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.MapMatchedPosition.v4_0", \ + signal_name = "simulationStatusChanged") + +startTrigger(test_name) + +navigationcore_session_obj = bus.get_object('org.genivi.navigation.navigationcore.Session.v4_0_Session','/Session') +g_navigationcore_session_interface = dbus.Interface(navigationcore_session_obj, dbus_interface='org.genivi.navigation.navigationcore.Session.v4_0') + +routing_obj = bus.get_object('org.genivi.navigation.navigationcore.Routing.v4_0_Routing','/Routing') +g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigation.navigationcore.Routing.v4_0') + +guidance_obj = bus.get_object('org.genivi.navigation.navigationcore.Guidance.v4_0_Guidance','/Guidance') +g_guidance_interface = dbus.Interface(guidance_obj, dbus_interface='org.genivi.navigation.navigationcore.Guidance.v4_0') + +mapviewer_session_obj = bus.get_object('org.genivi.navigation.mapviewer.Session.v4_0_Session','/Session') +g_mapviewer_session_interface = dbus.Interface(mapviewer_session_obj, dbus_interface='org.genivi.navigation.mapviewer.Session.v4_0') + +g_mapviewercontrol_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl.v4_0_MapViewerControl','/MapViewerControl') +g_mapviewercontrol_interface = dbus.Interface(g_mapviewercontrol_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl.v4_0') + +g_mapmatchedposition_obj = bus.get_object('org.genivi.navigation.navigationcore.MapMatchedPosition.v4_0_MapMatchedPosition','/MapMatchedPosition') +g_mapmatchedposition_interface = dbus.Interface(g_mapmatchedposition_obj, dbus_interface='org.genivi.navigation.navigationcore.MapMatchedPosition.v4_0') + +#get navigationcore session handle +ret = g_navigationcore_session_interface.createSession(dbus.String("test guidance")) +g_navigationcore_session_handle=ret[1] +print 'Navigation core session handle: ' + str(g_navigationcore_session_handle) + +#createMapView() + +g_current_route = 0 +g_guidance_active = False +launch_route_calculation(0) + +#main loop +gobject.timeout_add(TIME_OUT, timeout) +loop = gobject.MainLoop() +loop.run() + +#deleteMapView() diff --git a/test/navigation/script-capi/test-location-input-capi.py b/test/navigation/script-capi/test-location-input-capi.py new file mode 100755 index 0000000..74fd841 --- /dev/null +++ b/test/navigation/script-capi/test-location-input-capi.py @@ -0,0 +1,501 @@ +#!/usr/bin/python +# -*- coding: latin-1 -*- + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* @copyright Copyright (C) 2014, Alpine Electronics R&D Europe GmbH +* +* @file test-location-input.py +* +* @brief This simple test shows how the location input +* could be easily tested using a python script +* +* @author Stephan Wiehr +* @author Philippe Colliot +* +* @version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +* this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add status handler +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +from xml.dom.minidom import parse +import xml.dom.minidom +import argparse +import sys +import errno +from dltTrigger import * +#import pdb; +#pdb.set_trace() + +#name of the test +test_name = "location input" + +# constants as defined in the Navigation API +LATITUDE = 0x00a0 +LONGITUDE = 0x00a1 +ALTITUDE = 0x00a2 +FULL_ADDRESS = 0x00b2 +COUNTRY = 0x00a6 +STATE = 0x00a7 +CITY = 0x00a8 +ZIPCODE = 0x00a9 +STREET = 0x00aa +HOUSE_NUMBER = 0x00ab +CROSSING = 0x00ac +DISTRICT = 0x00ad +PHONE_NUMBER = 0x00ae +POI_NAME = 0x00af +TOWN_CENTER = 0x00b0 +FINISHED = 0x00c2 + +# List of addresses +COUNTRY_STRING = list() +CITY_STRING = list() +STREET_STRING = list() +HOUSE_NUMBER_STRING = list() + +# Default size of the list +WINDOW_SIZE = 20 + +# Search mode (0 = Spell, 1 = Full string search) +country_search_mode = 1 +city_search_mode = 0 +street_search_mode = 1 #set to full because of a bug to be fixed in the plug-in +house_number_search_mode = 1 + +print( '\n--------------------------\n' + \ + 'LocationInput Test' + \ + '\n--------------------------\n') + +parser = argparse.ArgumentParser(description='Location input Test for navigation PoC and FSA.') +parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') +parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') +args = parser.parse_args() + +if args.locations == None: + print('location file is missing') + sys.exit(1) +else: + try: + DOMTree = xml.dom.minidom.parse(args.locations) + except OSError as e: + if e.errno == errno.ENOENT: + print('file not exists') + sys.exit(1) + location_set = DOMTree.documentElement + +print("Area : %s" % location_set.getAttribute("area")) + +locations = location_set.getElementsByTagName("location") + +for location in location_set.getElementsByTagName("location"): + COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) + CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) + STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) + #HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) + HOUSE_NUMBER_STRING.append('') #there's a bug in the navigation core when the house number doesn't exist, so deactivated + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +# connect to session bus +bus = dbus.SessionBus() + +def vprint(text): + if args.verbose: + print(text) + +# Turn selection criteria values to their corresponding string description +def selection_criterion_to_string(selection_criterion): + return_value = '' + if selection_criterion == LATITUDE: + return_value += 'Latitude' + elif selection_criterion == LONGITUDE: + return_value += 'Longitude' + elif selection_criterion == COUNTRY: + return_value += 'Country' + elif selection_criterion == STATE: + return_value += 'State' + elif selection_criterion == CITY: + return_value += 'City' + elif selection_criterion == TOWN_CENTER: + return_value += 'City center' + elif selection_criterion == ZIPCODE: + return_value += 'ZipCode' + elif selection_criterion == STREET: + return_value += 'Street' + elif selection_criterion == HOUSE_NUMBER: + return_value += 'House number' + elif selection_criterion == CROSSING: + return_value += 'Crossing' + elif selection_criterion == FULL_ADDRESS: + return_value += 'Full address' + else: + return_value += str(selection_criterion) + + return return_value + + +# Prepare a dictionary array for pretty printing + +def dictionary_array_to_string(dict_array, linefeed, offset=0): + return_value = '' + i = offset + for item in dict_array: + return_value += str(i) + '. ' + unicode(dictionary_to_string(item)) + if i < offset + len(dict_array) - 1: + return_value += linefeed + i += 1 + + return return_value + + +# Prepare a dictionary for pretty printing +# NB: the value is supposed to be [UInt8, Variant], according to the DBus '(yv)', used by CommonAPI +def dictionary_to_string(dictionary): + return_value = '' + i = 0 + for key in dictionary.keys(): + value = dictionary[key][1] + return_value += selection_criterion_to_string(key) + ' = ' + unicode(value) + i += 1 + if i < len(dictionary): + return_value += ', ' + + return return_value + + +# Prepare a selection criteria array for pretty printing + +def selection_criteria_array_to_string(selection_criterion_array): + return_value = '' + i = 0 + for item in selection_criterion_array: + return_value += selection_criterion_to_string(item) + i += 1 + if i < len(selection_criterion_array): + return_value += ', ' + + return return_value + + +def print_current_context(): + vprint('\tACTIVE CONTEXT: selection criterion = ' + selection_criterion_to_string(current_selection_criterion) + \ + ', search string = \'' + entered_search_string + '\'') + + +def change_selection_criterion(selection_criterion): + global current_selection_criterion + + current_selection_criterion = selection_criterion + location_input_interface.setSelectionCriterion(dbus.UInt32(session_handle), dbus.UInt32(location_input_handle), + dbus.Int32(current_selection_criterion)) + + +# Spell search +def spell_search(handle, entered_string, search_string, valid_characters, first=0): + global entered_search_string + + vprint('-> SpellSearch - entered \'' + entered_string + '\' target \'' + search_string + '\'') + + if unicode(search_string) != unicode(entered_string): + found = unicode(search_string).lower().find(unicode(entered_string).lower()) + if found == 0: + is_valid = -1 + if first == 0: + spell_character = search_string[len(entered_string)] + is_valid = valid_characters.find(spell_character) + else: + spell_character='' + is_valid = 0 + if is_valid != -1: + entered_search_string = entered_string + spell_character + vprint('\nACTION: Spell search, selection criterion = ' + \ + selection_criterion_to_string(current_selection_criterion) + ', trying \'' + spell_character + \ + '\'') + location_input_interface.spell(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.String(spell_character), dbus.UInt16(20)) + else: + print ('TEST FAILED (Target character can not be entered)') + exit() + else: + print ('TEST FAILED (Unexpected completion)') + exit() + else: + print ('Full spell match') + + +# Full string search +def full_string_search(handle, search_string): + global entered_search_string + global found_exact_match + + entered_search_string = search_string + found_exact_match = 1 # Force exact match for full string search + vprint('\nACTION: Full string search, selection criterion = ' + \ + selection_criterion_to_string(current_selection_criterion) + ', trying \'' + search_string + '\'') + location_input_interface.search(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.String(search_string), + dbus.UInt16(20)) + + +def evaluate_address(address, guidable): + test_passed = 0 + print ('\nAddress complete!\nEvaluating...') + if COUNTRY_STRING[current_address_index] == '': + test_passed = 1 + elif address[COUNTRY][1] == COUNTRY_STRING[current_address_index]: + print ('Country\t\t\t-> ok (' + address[COUNTRY][1] + ')') + if CITY_STRING[current_address_index] == '': + test_passed = 1 + elif address[CITY][1] == CITY_STRING[current_address_index]: + print ('City\t\t\t-> ok (' + address[CITY][1] + ')') + if STREET_STRING[current_address_index] == '': + test_passed = 1 + elif address[STREET][1] == STREET_STRING[current_address_index]: + print ('Street\t\t\t-> ok (' + address[STREET][1] + ')') + if HOUSE_NUMBER_STRING[current_address_index] == '': + test_passed = 1 + elif address[HOUSE_NUMBER][1] == HOUSE_NUMBER_STRING[current_address_index]: + print ('House number\t-> ok (' + address[HOUSE_NUMBER][1] + ')') + test_passed = 1 + + if guidable == 1: + if test_passed == 1: + print ('TEST PASSED') + else: + print ('TEST FAILED (wrong address)') + exit() + else: + print ('TEST FAILED (non-guidable address)') + exit() + address_index = current_address_index + 1 + if address_index < len(COUNTRY_STRING): + startSearch(address_index) + else: + print('END OF THE TEST') + exit() + + +# Signal receiver + +# Handler for ContentUpdated callback + +def search_status_handler(handle,status): + vprint('\n::Search status ' + str(int(status))) + if status == FINISHED: + location_input_interface.requestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.UInt16(0), + dbus.UInt16(WINDOW_SIZE)) + + +def content_updated_handler(handle, guidable, available_selection_criteria, address): + global target_search_string + global entered_search_string + + vprint('\n::ContentUpdated for LocationInputHandle ' + str(int(handle))) + print_current_context() + vprint('\tGuidable = ' + str(guidable)) + vprint('\tAvailable selection criteria = ' + selection_criteria_array_to_string(available_selection_criteria)) + vprint('\tADDRESS: '+dictionary_to_string(address)) + + search_mode = -1 + + if current_selection_criterion == COUNTRY: + change_selection_criterion(CITY) + target_search_string = CITY_STRING[current_address_index] + search_mode = city_search_mode + elif current_selection_criterion == CITY: + change_selection_criterion(STREET) + target_search_string = STREET_STRING[current_address_index] + search_mode = street_search_mode + elif current_selection_criterion == STREET: + change_selection_criterion(HOUSE_NUMBER) + target_search_string = HOUSE_NUMBER_STRING[current_address_index] + search_mode = house_number_search_mode + elif current_selection_criterion == HOUSE_NUMBER: + target_search_string = '' + + entered_search_string = '' + + if target_search_string == '': + evaluate_address(address, guidable) + elif search_mode == 0: + spell_search(handle, entered_search_string, target_search_string, '', 1) + elif search_mode == 1: + full_string_search(handle, target_search_string) + else: + print ('\nTEST FAILED (Invalid search mode)') + exit() + +# Handler for SpellResult callback +def spell_result_handler(handle, unique_string, valid_characters, full_match): + global entered_search_string + global spell_next_character + global found_exact_match + global available_characters + + vprint('\n::SpellResult for LocationInputHandle '+str(int(handle))) + if unique_string != entered_search_string: + vprint('\tAUTOCOMPLETE: \'' + entered_search_string + '\' -> \'' + unique_string + '\'') + entered_search_string = unique_string + available_characters = valid_characters + print_current_context() + vprint('\tUnique string = \''+unique_string+'\'') + vprint('\tValid Characters = \''+valid_characters+'\'') + vprint('\tFull Match = '+str(full_match)) + + if len(valid_characters) == 1: + if unicode(valid_characters[0]) == u'\x08': + print ('\nTEST FAILED (Dead end spelling)') + exit() + + if unicode(entered_search_string) == unicode(target_search_string): + found_exact_match = 1 + + spell_next_character = 1 + + +# Handler for SearchResultList callback + +def search_result_list_handler(handle, total_size, window_offset, window_size, result_list_window): + global spell_next_character + global found_exact_match + + vprint('\n::SearchResultList for LocationInputHandle ' + str(int(handle))) + print_current_context() + vprint('\tTotal size = ' + str(int(total_size)) + ', Window offset = ' + str(int(window_offset)) + \ + ', Window size = ' + str(int(window_size))) + vprint('\t' + dictionary_array_to_string(result_list_window, '\n\t', window_offset)) + + if found_exact_match == 1: + found_exact_match = 0 + i = 0 + for address in result_list_window: + if unicode(address[current_selection_criterion][1]) == target_search_string: + vprint('\nACTION: Found exact match, selecting \''+unicode(address[current_selection_criterion][1]) + \ + '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.selectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(i)) + break + i += 1 + if i == window_size: + vprint('\nACTION: Found exact match, searching in next page (Session '+str(int(session_handle)) +\ + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.requestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.UInt16(window_offset + window_size), + dbus.UInt16(window_size)) + elif total_size == 1: + selection_name = result_list_window[0][current_selection_criterion] + if selection_name[1] == target_search_string: + vprint('\nACTION: Single entry list, selecting \'' + selection_name[1] + \ + '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.selectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(0)) + else: + print ('\nTEST FAILED (Unexpected single result list)') + exit() + elif spell_next_character == 1: + spell_next_character = 0 + spell_search(handle, entered_search_string, target_search_string, available_characters) + + +# add signal receiver +bus.add_signal_receiver(search_status_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', + signal_name='searchStatus') + +bus.add_signal_receiver(search_result_list_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', + signal_name='searchResultList') + +bus.add_signal_receiver(spell_result_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', + signal_name='spellResult') + +bus.add_signal_receiver(content_updated_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', + signal_name='contentUpdated') + + +# Timeout +def timeout(): + print('Timeout Expired') + print ('\nTEST FAILED\n') + exit() + +# Exit +def exit(): + error=location_input_interface.deleteLocationInput(dbus.UInt32(session_handle),dbus.UInt32(location_input_handle)) + print('Delete location input: '+str(int(error))) + error=session_interface.deleteSession(dbus.UInt32(session_handle)) + print('Delete session: '+str(int(error))) + stopTrigger(test_name) + loop.quit() + +def startSearch(address_index): + global entered_search_string + global spell_next_character + global found_exact_match + global available_characters + global target_search_string + global country_search_mode + global current_address_index + current_address_index = address_index + entered_search_string = '' + spell_next_character = 0 + found_exact_match = 0 + available_characters = '' + target_search_string = COUNTRY_STRING[current_address_index] + + change_selection_criterion(COUNTRY) + if country_search_mode == 0: + spell_search(location_input_handle, entered_search_string, target_search_string, available_characters, 1) + elif country_search_mode == 1: + full_string_search(location_input_handle, target_search_string) + +startTrigger(test_name) + +session = bus.get_object('org.genivi.navigation.navigationcore.Session.v4_0_Session', '/Session') +session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session.v4_0') + +# Get SessionHandle +ret = session_interface.createSession(dbus.String('test location input')) +session_handle=ret[1] +print ('Session handle = ' + str(session_handle)) + +location_input_obj = bus.get_object('org.genivi.navigation.navigationcore.LocationInput.v4_0_LocationInput', '/LocationInput') +location_input_interface = dbus.Interface(location_input_obj, dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0') +# Get LocationInputHandle +ret = location_input_interface.createLocationInput(dbus.UInt32(session_handle)) +location_input_handle = ret[1] +print ('LocationInput handle = ' + str(location_input_handle)) + +attributes = location_input_interface.getSupportedAddressAttributes() +print ('Initially supported address attributes = ' + selection_criteria_array_to_string(attributes)) + +# Configuration +current_address_index = 0 +entered_search_string = '' +spell_next_character = 0 +found_exact_match = 0 +available_characters = '' +target_search_string = '' +current_selection_criterion = 0 + +startSearch(0) + +# Main loop +gobject.timeout_add(10000, timeout) +loop = gobject.MainLoop() +loop.run() diff --git a/test/navigation/script-capi/test-map-viewer-control-capi.py b/test/navigation/script-capi/test-map-viewer-control-capi.py new file mode 100755 index 0000000..47da06d --- /dev/null +++ b/test/navigation/script-capi/test-map-viewer-control-capi.py @@ -0,0 +1,192 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2015, Mentor Graphics +* +* \file test-map-viewer-control.py +* +* \brief This simple test shows how the mapviewer +* could be easily tested using a python script +* +* \author Marco Residori +* \author Philippe Colliot +* +* \version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add some methods +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +import time +from dltTrigger import * +#import pdb +#pdb.set_trace() + +#name of the test +test_name = "map viewer" + +#constants as defined in the Navigation API +LATITUDE = 0x00a0 +LONGITUDE = 0x00a1 + +MAIN_MAP = 0x0010 +SPLIT_SCREEN = 0x0011 + +#constants used by the script +HORIZONTAL_SIZE = 800 +VERTICAL_SIZE = 480 +TIME_OUT = 10000 +MIN_SCALE = 0 +MAX_SCALE = 21 + +def mapviewer_mapViewScaleChanged_handler(mapViewInstanceHandle,scale,isMinMax): + global g_scale + new_scale=int(scale) + print("Scale: "+str(new_scale)) + print('Is min max: '+str(int(isMinMax))) + time.sleep(0.25) + if g_scale > new_scale and new_scale !=MIN_SCALE: + print("Zoom in") + g_scale=new_scale + MapViewerControl_interface.setMapViewScaleByDelta( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Int16(1)) + else: + if new_scale < MAX_SCALE: + print("Zoom out") + g_scale=new_scale + MapViewerControl_interface.setMapViewScaleByDelta( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Int16(-1)) + else: + print 'Test PASSED' + MapViewerControl_interface.releaseMapViewInstance( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle)) + session_interface.deleteSession(sessionhandle) + exit() + +#timeout +def timeout(): + print 'Timeout Expired' + print '\nTest FAILED' + exit() + +def exit(): + stopTrigger(test_name) + loop.quit() + +print '\n--------------------------' +print 'MapViewerControl Test' +print '--------------------------\n' + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +#connect to session bus +bus = dbus.SessionBus() + +bus.add_signal_receiver(mapviewer_mapViewScaleChanged_handler, \ + dbus_interface = "org.genivi.navigation.mapviewer.MapViewerControl.v4_0", \ + signal_name = "mapViewScaleChanged") + +startTrigger(test_name) + +session = bus.get_object('org.genivi.navigation.mapviewer.Session.v4_0_Session','/Session') +session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.mapviewer.Session.v4_0') + +#get session handle +ret = session_interface.createSession(dbus.String('test mapviewer')) +sessionhandle=ret[1] +print 'Session handle: ' + str(sessionhandle) + +sessionstatus = session_interface.getSessionStatus(dbus.UInt32(sessionhandle)); +print 'Session status: ' + str(sessionstatus) + +sessionlist = session_interface.getAllSessions(); +print 'Active sessions = ' + str(len(sessionlist)) + +MapViewerControl_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl.v4_0_MapViewerControl','/MapViewerControl') +MapViewerControl_interface = dbus.Interface(MapViewerControl_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl.v4_0') + +#get mapviewer handle +ret = MapViewerControl_interface.createMapViewInstance( \ + dbus.UInt32(sessionhandle), \ + dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ + dbus.Int32(MAIN_MAP)) +mapviewerhandle=ret[1] + +print 'MapView handle: ' + str(mapviewerhandle) + +# Bern +lat1 = 46.9479 +lon1 = 7.4446 +alt1 = 0 + +time.sleep(2) + +print 'Stop following the car position' +MapViewerControl_interface.setFollowCarMode( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Boolean(False)) + +print 'Set center in Bern(' + str(lat1) + ',' + str(lon1) + ')' +MapViewerControl_interface.setTargetPoint( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Struct((dbus.Double(lat1),dbus.Double(lon1),dbus.Double(alt1)))) + +# Get current position +targetPoint = MapViewerControl_interface.getTargetPoint( \ + dbus.UInt32(mapviewerhandle) ) + +lat2 = targetPoint[0] +lon2 = targetPoint[1] +alt2 = targetPoint[2] + +print 'Get center -> (' + str(lat2) + ',' + str(lon2) + ')' + +if round(lat1,4) != round(lat2,4) : + print '\nTest Failed:' + str(round(lat1,4)) + '!=' + str(round(lat2,4)) + '\n' + +if round(lon1,4) != round(lon2,4) : + print '\nTest Failed:' + str(round(lon1,4)) + '!=' + str(round(lon2,4)) + '\n' + +if round(alt1,4) != round(alt2,4) : + print '\nTest Failed:' + str(round(alt1,4)) + '!=' + str(round(alt2,4)) + '\n' + +ret=MapViewerControl_interface.getMapViewScale(dbus.UInt32(mapviewerhandle)) +print('Scale: '+str(int(ret[0]))) +print('Is min max: '+str(int(ret[1]))) + +g_scale=int(ret[0]) + +time.sleep(0.25) + +print 'Zoom in' +MapViewerControl_interface.setMapViewScaleByDelta(dbus.UInt32(sessionhandle), dbus.UInt32(mapviewerhandle), dbus.Int16(1)) + +#main loop +gobject.timeout_add(TIME_OUT, timeout) +loop = gobject.MainLoop() +loop.run() + + + + diff --git a/test/navigation/script-capi/test-route-calculation-capi.py b/test/navigation/script-capi/test-route-calculation-capi.py new file mode 100755 index 0000000..1c44d10 --- /dev/null +++ b/test/navigation/script-capi/test-route-calculation-capi.py @@ -0,0 +1,222 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2014, XS Embedded GmbH, PCA Peugeot Citroen +* +* \file test-route-calculation-capi.py +* +* \brief This simple test shows how the route calculation +* could be easily tested using a python script +* +* \author Marco Residori +* \author Philippe Colliot +* +* \version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants) +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +from collections import namedtuple,defaultdict +from _dbus_bindings import Int32 +from PIL.GimpGradientFile import SEGMENTS +from xml.dom.minidom import parse +import xml.dom.minidom +import argparse +import sys +import errno +#import pdb; +#pdb.set_trace() +from pip import locations +from dltTrigger import * + +#name of the test +test_name = "route calculation" + +#constants as defined in the Navigation API +GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0 +GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1 +GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e +GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f +GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147 +GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141 +GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142 +GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143 +GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144 +GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148 +GENIVI_NAVIGATIONCORE_TIME = 0x0149 +GENIVI_NAVIGATIONCORE_SPEED = 0x00a4 + +#constants used into the script +TIME_OUT = 10000 + +print('--------------------------') +print('Route Calculation Test') +print('--------------------------') + +parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.') +parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format') +args = parser.parse_args() + +if args.routes == None: + print('route file is missing') + sys.exit(1) +else: + try: + DOMTree = xml.dom.minidom.parse(args.routes) + except OSError as e: + if e.errno == errno.ENOENT: + print('file not exists') + sys.exit(1) + route_set = DOMTree.documentElement + +print("Country : %s" % route_set.getAttribute("country")) + +routes = route_set.getElementsByTagName("route") + +#create dictionary with the locations +locations = {} +for location in route_set.getElementsByTagName("location"): + lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data] + locations[location.getAttribute("name")] = lat_long + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +#connect to session bus +bus = dbus.SessionBus() + +#add signal receivers +def route_calculation_signals_handler(routeHandle, status, percentage): + print 'Route Calculation: ' + str(int(percentage)) + ' %' + if int(percentage) == 100: + #get route overview + overview = g_routing_interface.getRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])) + #retrieve distance + totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)]) + print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km' + totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]) + m, s = divmod(totalTime[1], 60) + h, m = divmod(m, 60) + print "Total Time: %d:%02d:%02d" % (h, m, s) + #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) + valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME), + dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE), + dbus.Int32(GENIVI_NAVIGATIONCORE_TIME), + dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)] + ret = g_routing_interface.getRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(0),dbus.Array(valuesToReturn),dbus.UInt32(500),dbus.UInt32(0)) + print "Total number of segments: " + str(ret[0]) + #len(ret[1]) is size + #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude +# pdb.set_trace() + route = g_current_route + 1 + if route < routes.length: + launch_route_calculation(route) + else: + for i in range(routes.length): + g_routing_interface.deleteRoute(dbus.UInt32(g_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data)) + g_session_interface.deleteSession(dbus.UInt32(g_session_handle)) + +def session_signals_handler(sessionHandle): + print('Session handle deleted: '+str(sessionHandle)) + if sessionHandle == g_session_handle: + print 'Test PASSED' + else: + print 'Test FAILED' + exit() + +def route_deleted_signals_handler(routeHandle): + print('Route handle deleted: '+str(routeHandle)) + +bus.add_signal_receiver(route_calculation_signals_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ + signal_name = "routeCalculationProgressUpdate") + +bus.add_signal_receiver(route_deleted_signals_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ + signal_name = "routeDeleted") + +bus.add_signal_receiver(session_signals_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Session.v4_0", \ + signal_name = "sessionDeleted") + +#timeout +def timeout(): + print 'Timeout Expired' + print '\nTest FAILED' + exit() + +def exit(): + stopTrigger(test_name) + loop.quit() + +def launch_route_calculation(route): + global g_current_route + global g_route_handle + global g_routing_interface + global g_session_handle + g_current_route = route + print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data + #get route handle + ret = g_routing_interface.createRoute(dbus.UInt32(g_session_handle)) + g_route_handle=ret[1] + routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle + print 'Route handle: ' + str(g_route_handle) + start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data + dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data + print 'Calculating route from \ +'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \ +'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')' + #set waypoints + waypointDoubleCapiType = 0x03 + g_routing_interface.setWaypoints(dbus.UInt32(g_session_handle), \ + dbus.UInt32(g_route_handle), \ + dbus.Boolean(0), \ + dbus.Array([ \ + dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \ + dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \ + ]) \ + ) + #calculate route + g_routing_interface.calculateRoute(dbus.UInt32(g_session_handle),dbus.UInt32(g_route_handle)) + +startTrigger(test_name) + +session = bus.get_object('org.genivi.navigation.navigationcore.Session.v4_0_Session','/Session') +g_session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session.v4_0') + +#get session handle +ret = g_session_interface.createSession(dbus.String("test route calculation")) +g_session_handle=ret[1] +print 'Session handle: ' + str(g_session_handle) + +routing_obj = bus.get_object('org.genivi.navigation.navigationcore.Routing.v4_0_Routing','/Routing') +g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigation.navigationcore.Routing.v4_0') + +g_current_route = 0 +launch_route_calculation(0) + + +#main loop +gobject.timeout_add(TIME_OUT, timeout) +loop = gobject.MainLoop() +loop.run() + + diff --git a/test/navigation/script/dltTrigger.py b/test/navigation/script/dltTrigger.py new file mode 100644 index 0000000..efba2d7 --- /dev/null +++ b/test/navigation/script/dltTrigger.py @@ -0,0 +1,42 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 201, PSA GROUPE +* +* \file dlt-trigger.py +* +* \brief This script is part of the FSA scenario. +* +* \author Philippe Colliot +* +* \version 1.0 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +* List of changes: +* +* @licence end@ + +************************************************************************** +""" +import subprocess,os +from subprocess import call + +PATH_TEST_TRIGGER='../dlt-triggers/bin/' + +def startTrigger(name): + FNULL = open(os.devnull,'w') + test_trigger=PATH_TEST_TRIGGER + 'test-trigger' + call([test_trigger, "1", name]) + +def stopTrigger(name): + FNULL = open(os.devnull,'w') + test_trigger=PATH_TEST_TRIGGER + 'test-trigger' + call([test_trigger, "0", name]) + diff --git a/test/navigation/script/lbs-api-test.e4p b/test/navigation/script/lbs-api-test.e4p new file mode 100644 index 0000000..d909056 --- /dev/null +++ b/test/navigation/script/lbs-api-test.e4p @@ -0,0 +1,45 @@ + + + + + + + en_US + 7f8a1c646125ed1d62f8723612a19e7cdc944025 + Python3 + PyQt5 + + 0.1 + asanoaozora + + + __init__.py + dltTrigger.py + test-poi.py + test-guidance.py + test-address-input.py + test-map-viewer-control.py + test-location-input.py + test-map-viewer-control-single.py + test-route-calculation.py + + + + + + + + None + + + + + + + + + + + + + diff --git a/test/navigation/script/test-address-input.py b/test/navigation/script/test-address-input.py new file mode 100755 index 0000000..a9b6ce6 --- /dev/null +++ b/test/navigation/script/test-address-input.py @@ -0,0 +1,410 @@ +#!/usr/bin/python +# -*- coding: latin-1 -*- + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* @copyright Copyright (C) 2014, Alpine Electronics R&D Europe GmbH +* +* @file test-address-input.py +* +* @brief This simple test shows how the address input +* could be easily tested using a python script +* +* @author Stephan Wiehr +* @author Philippe Colliot +* +* @version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add status handler +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +from xml.dom.minidom import parse +import xml.dom.minidom +import argparse +import sys +import errno +from dltTrigger import * +#import pdb;pdb.set_trace() + +#name of the test +test_name = "address input" + +# constants as defined in the Navigation API +LATITUDE = 0x00a0 +LONGITUDE = 0x00a1 +ALTITUDE = 0x00a2 +FULL_ADDRESS = 0x00b2 +COUNTRY = 0x00a6 +STATE = 0x00a7 +CITY = 0x00a8 +ZIPCODE = 0x00a9 +STREET = 0x00aa +HOUSE_NUMBER = 0x00ab +CROSSING = 0x00ac +DISTRICT = 0x00ad +PHONE_NUMBER = 0x00ae +POI_NAME = 0x00af +TOWN_CENTER = 0x00b0 +FINISHED = 0x00c2 + +# List of addresses +COUNTRY_STRING = list() +CITY_STRING = list() +STREET_STRING = list() +HOUSE_NUMBER_STRING = list() + +# Default size of the list +WINDOW_SIZE = 20 + +print('\n--------------------------\n' + \ + 'LocationInput Test' + \ + '\n--------------------------\n') + +parser = argparse.ArgumentParser(description='Location input Test for navigation PoC and FSA.') +parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') +parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') +args = parser.parse_args() + +if args.locations == None: + print('location file is missing') + sys.exit(1) +else: + try: + DOMTree = xml.dom.minidom.parse(args.locations) + except OSError as e: + if e.errno == errno.ENOENT: + print('file not exists') + sys.exit(1) + location_set = DOMTree.documentElement + +print("Area : %s" % location_set.getAttribute("area")) + +locations = location_set.getElementsByTagName("location") + +for location in location_set.getElementsByTagName("location"): + COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) + CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) + STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) + #HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) + HOUSE_NUMBER_STRING.append('') #there's a bug in the navigation core when the house number doesn't exist, so deactivated + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +# connect to session bus +bus = dbus.SessionBus() + +def vprint(text): + if args.verbose: + print(text) + +# Turn selection criteria values to their corresponding string description +def selection_criterion_to_string(selection_criterion): + return_value = '' + if selection_criterion == LATITUDE: + return_value += 'Latitude' + elif selection_criterion == LONGITUDE: + return_value += 'Longitude' + elif selection_criterion == COUNTRY: + return_value += 'Country' + elif selection_criterion == STATE: + return_value += 'State' + elif selection_criterion == CITY: + return_value += 'City' + elif selection_criterion == TOWN_CENTER: + return_value += 'City center' + elif selection_criterion == ZIPCODE: + return_value += 'ZipCode' + elif selection_criterion == STREET: + return_value += 'Street' + elif selection_criterion == HOUSE_NUMBER: + return_value += 'House number' + elif selection_criterion == CROSSING: + return_value += 'Crossing' + elif selection_criterion == FULL_ADDRESS: + return_value += 'Full address' + else: + return_value += str(selection_criterion) + + return return_value + + +# Prepare a dictionary array for pretty printing + +def dictionary_array_to_string(dict_array, linefeed, offset=0): + return_value = '' + i = offset + for item in dict_array: + return_value += str(i) + '. ' + unicode(dictionary_to_string(item)) + if i < offset + len(dict_array) - 1: + return_value += linefeed + i += 1 + + return return_value + + +# Prepare a dictionary for pretty printing +# NB: the value is supposed to be [UInt8, Variant], according to the DBus '(yv)', used by CommonAPI +def dictionary_to_string(dictionary): + return_value = '' + i = 0 + for key in dictionary.keys(): + value = dictionary[key][1] + return_value += selection_criterion_to_string(key) + ' = ' + unicode(value) + i += 1 + if i < len(dictionary): + return_value += ', ' + + return return_value + + +# Prepare a selection criteria array for pretty printing + +def selection_criteria_array_to_string(selection_criterion_array): + return_value = '' + i = 0 + for item in selection_criterion_array: + return_value += selection_criterion_to_string(item) + i += 1 + if i < len(selection_criterion_array): + return_value += ', ' + + return return_value + + +def print_current_context(): + vprint('\tACTIVE CONTEXT: selection criterion = ' + selection_criterion_to_string(current_selection_criterion) + \ + ', search string = \'' + entered_search_string + '\'') + + +def change_selection_criterion(selection_criterion): + global current_selection_criterion + + current_selection_criterion = selection_criterion + location_input_interface.SetSelectionCriterion(dbus.UInt32(session_handle), dbus.UInt32(location_input_handle), + dbus.UInt16(current_selection_criterion)) + + +# Full string search +def full_string_search(handle, search_string): + global entered_search_string + global found_exact_match + + entered_search_string = search_string + found_exact_match = 1 # Force exact match for full string search + vprint('\nACTION: Full string search, selection criterion = ' + \ + selection_criterion_to_string(current_selection_criterion) + ', trying \'' + search_string + '\'') + location_input_interface.Search(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.String(search_string), + dbus.UInt16(20)) + + +def evaluate_address(address, guidable): + test_passed = 0 + print('\nAddress complete!\nEvaluating...') + if COUNTRY_STRING[current_address_index] == '': + test_passed = 1 + elif address[COUNTRY][1] == COUNTRY_STRING[current_address_index]: + print ('Country\t\t\t-> ok (' + address[COUNTRY][1] + ')') + if CITY_STRING[current_address_index] == '': + test_passed = 1 + elif address[CITY][1] == CITY_STRING[current_address_index]: + print ('City\t\t\t-> ok (' + address[CITY][1] + ')') + if STREET_STRING[current_address_index] == '': + test_passed = 1 + elif address[STREET][1] == STREET_STRING[current_address_index]: + print ('Street\t\t\t-> ok (' + address[STREET][1] + ')') + if HOUSE_NUMBER_STRING[current_address_index] == '': + test_passed = 1 + elif address[HOUSE_NUMBER][1] == HOUSE_NUMBER_STRING[current_address_index]: + print ('House number\t-> ok (' + address[HOUSE_NUMBER][1] + ')') + test_passed = 1 + + if guidable == 1: + if test_passed == 1: + print ('TEST PASSED') + else: + print('TEST FAILED (wrong address)') + exit() + else: + print ('TEST FAILED (non-guidable address)') + exit() + address_index = current_address_index + 1 + if address_index < len(COUNTRY_STRING): + startSearch(address_index) + else: + print ('END OF THE TEST') + exit() + + +# Signal receiver + +# Handler for ContentUpdated callback + +def search_status_handler(handle,status): + vprint('\n::Search status ' + str(int(status))) + if status == FINISHED: + location_input_interface.RequestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.UInt16(0), + dbus.UInt16(WINDOW_SIZE)) + + +def content_updated_handler(handle, guidable, available_selection_criteria, address): + global target_search_string + global entered_search_string + + vprint('\n::ContentUpdated for LocationInputHandle ' + str(int(handle))) + print_current_context() + vprint('\tGuidable = ' + str(guidable)) + vprint('\tAvailable selection criteria = ' + selection_criteria_array_to_string(available_selection_criteria)) + vprint('\tADDRESS: '+dictionary_to_string(address)) + + if current_selection_criterion == COUNTRY: + change_selection_criterion(CITY) + target_search_string = CITY_STRING[current_address_index] + elif current_selection_criterion == CITY: + change_selection_criterion(STREET) + target_search_string = STREET_STRING[current_address_index] + elif current_selection_criterion == STREET: + change_selection_criterion(HOUSE_NUMBER) + target_search_string = HOUSE_NUMBER_STRING[current_address_index] + elif current_selection_criterion == HOUSE_NUMBER: + target_search_string = '' + entered_search_string = '' + if target_search_string == '': + evaluate_address(address, guidable) + else: + full_string_search(handle, target_search_string) + +def search_result_list_handler(handle, total_size, window_offset, window_size, result_list_window): + global spell_next_character + global found_exact_match + + vprint('\n::SearchResultList for LocationInputHandle ' + str(int(handle))) + print_current_context() + vprint('\tTotal size = ' + str(int(total_size)) + ', Window offset = ' + str(int(window_offset)) + \ + ', Window size = ' + str(int(window_size))) + vprint('\t' + dictionary_array_to_string(result_list_window, '\n\t', window_offset)) + + if found_exact_match == 1: + found_exact_match = 0 + i = 0 + for address in result_list_window: + if unicode(address[current_selection_criterion][1]) == target_search_string: + vprint('\nACTION: Found exact match, selecting \''+unicode(address[current_selection_criterion][1]) + \ + '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.SelectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(i)) + break + i += 1 + if i == window_size: + vprint('\nACTION: Found exact match, searching in next page (Session '+str(int(session_handle)) +\ + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.RequestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.UInt16(window_offset + window_size), + dbus.UInt16(window_size)) + elif total_size == 1: + selection_name = result_list_window[0][current_selection_criterion] + if selection_name[1] == target_search_string: + vprint('\nACTION: Single entry list, selecting \'' + selection_name[1] + \ + '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.SelectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(0)) + else: + print ('\nTEST FAILED (Unexpected single result list)') + exit() + elif spell_next_character == 1: + spell_next_character = 0 + spell_search(handle, entered_search_string, target_search_string, available_characters) + + +# add signal receiver +bus.add_signal_receiver(search_status_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput', + signal_name='SearchStatus') + +bus.add_signal_receiver(search_result_list_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput', + signal_name='SearchResultList') + +bus.add_signal_receiver(content_updated_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput', + signal_name='ContentUpdated') + + +# Timeout +def timeout(): + print ('Timeout Expired') + print ('\nTEST FAILED\n') + exit() + +# Exit +def exit(): + error=location_input_interface.DeleteLocationInput(dbus.UInt32(session_handle),dbus.UInt32(location_input_handle)) + print('Delete location input: '+str(int(error))) + error=session_interface.DeleteSession(dbus.UInt32(session_handle)) + print('Delete session: '+str(int(error))) + stopTrigger(test_name) + loop.quit() + + +def startSearch(address_index): + global found_exact_match + global available_characters + global target_search_string + global current_address_index + global entered_search_string + current_address_index = address_index + entered_search_string = '' + found_exact_match = 0 + available_characters = '' + target_search_string = COUNTRY_STRING[current_address_index] + + change_selection_criterion(COUNTRY) + full_string_search(location_input_handle, target_search_string) + +startTrigger(test_name) + +session = bus.get_object('org.genivi.navigation.navigationcore.Session', '/org/genivi/navigationcore') +session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session') + +# Get SessionHandle +ret = session_interface.CreateSession(dbus.String('test location input')) +session_handle=ret[1] +print ('Session handle = ' + str(session_handle)) + +location_input_obj = bus.get_object('org.genivi.navigation.navigationcore.LocationInput', '/org/genivi/navigationcore') +location_input_interface = dbus.Interface(location_input_obj, dbus_interface='org.genivi.navigation.navigationcore.LocationInput') + +# Get LocationInputHandle +ret = location_input_interface.CreateLocationInput(dbus.UInt32(session_handle)) +location_input_handle = ret[1] +print ('LocationInput handle = ' + str(location_input_handle)) + +attributes = location_input_interface.GetSupportedAddressAttributes() +print ('Initially supported address attributes = ' + selection_criteria_array_to_string(attributes)) + +# Configuration +current_address_index = 0 +entered_search_string = '' +spell_next_character = 0 +found_exact_match = 0 +available_characters = '' +target_search_string = '' + +startSearch(0) + +# Main loop +gobject.timeout_add(10000, timeout) +loop = gobject.MainLoop() +loop.run() diff --git a/test/navigation/script/test-all b/test/navigation/script/test-all new file mode 100755 index 0000000..f2c8dfa --- /dev/null +++ b/test/navigation/script/test-all @@ -0,0 +1,11 @@ +#!/bin/bash + +./test-location-input.py -l ../resource/locations.xml +sleep 2 +./test-route-calculation.py -r ../resource/routes.xml +sleep 2 +./test-address-input.py -l ../resource/location.xml +sleep 2 +./test-guidance.py -r ../resource/route.xml +sleep 2 +./test-map-viewer-control.py -l ../resource/location.xml diff --git a/test/navigation/script/test-all_tokyo b/test/navigation/script/test-all_tokyo new file mode 100755 index 0000000..d66e5a7 --- /dev/null +++ b/test/navigation/script/test-all_tokyo @@ -0,0 +1,11 @@ +#!/bin/bash + +./test-location-input.py -l ../resource/location_tokyo.xml +sleep 2 +./test-route-calculation.py -r ../resource/route_tokyo.xml +sleep 2 +./test-address-input.py -l ../resource/location_tokyo.xml +sleep 2 +./test-guidance.py -r ../resource/route_tokyo.xml +sleep 2 +./test-map-viewer-control.py -l ../resource/location_tokyo.xml diff --git a/test/navigation/script/test-guidance.py b/test/navigation/script/test-guidance.py new file mode 100755 index 0000000..be44295 --- /dev/null +++ b/test/navigation/script/test-guidance.py @@ -0,0 +1,361 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2016, XS Embedded GmbH, PCA Peugeot Citroen +* +* \file test-guidance.py +* +* \brief This simple test shows how the guidance +* could be easily tested using a python script +* +* \author Marco Residori +* \author Philippe Colliot +* +* \version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +from collections import namedtuple,defaultdict +from _dbus_bindings import Int32 +from PIL.GimpGradientFile import SEGMENTS +from xml.dom.minidom import parse +import xml.dom.minidom +import argparse +import sys +import errno +import time +from dltTrigger import * +#import pdb +#pdb.set_trace() + +from pip import locations + +#name of the test +test_name = "guidance" + +#constants as defined in the Navigation API +GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0 +GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1 +GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e +GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f +GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147 +GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141 +GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142 +GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143 +GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144 +GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148 +GENIVI_NAVIGATIONCORE_TIME = 0x0149 +GENIVI_NAVIGATIONCORE_SPEED = 0x00a4 +GENIVI_NAVIGATIONCORE_ACTIVE = 0x0060 + +#constants used into the script +TIME_OUT = 10000 +HORIZONTAL_SIZE = 800 +VERTICAL_SIZE = 480 +MAIN_MAP = 0x0010 +NUMBER_OF_SEGMENTS = 500 +ZOOM_GUIDANCE = 2 + +#add signal receivers +def routing_routeCalculationProgressUpdate_handler(routeHandle, status, percentage): + print 'Route Calculation: ' + str(int(percentage)) + ' %' + +def routing_routeCalculationSuccessful_handler(routeHandle,unfullfilledPreferences): + global g_guidance_active + print 'Route Calculation Successfull: ' + str(routeHandle) + #get route overview + overview = g_routing_interface.GetRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])) + #retrieve distance + totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)]) + print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km' + totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]) + m, s = divmod(totalTime[1], 60) + h, m = divmod(m, 60) + print "Total Time: %d:%02d:%02d" % (h, m, s) + #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) + valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME), + dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE), + dbus.Int32(GENIVI_NAVIGATIONCORE_TIME), + dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)] + numberOfSegments = NUMBER_OF_SEGMENTS + detailLevel = 0 + offset = 0 + ret = g_routing_interface.GetRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(detailLevel),dbus.Array(valuesToReturn),dbus.UInt32(numberOfSegments),dbus.UInt32(offset)) + print "Total number of segments: " + str(ret[0]) + #len(ret[1]) is size + #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude + g_guidance_active = True +# pdb.set_trace() + display_route(routeHandle) + launch_guidance(routeHandle) + +def session_sessionDeleted_handler(sessionHandle): + print('Session handle deleted: '+str(sessionHandle)) + if sessionHandle == g_navigationcore_session_handle: + print 'Test PASSED' + else: + print 'Test FAILED' + exit() + +def routing_routeDeleted_handler(routeHandle): + print('Route handle deleted: '+str(routeHandle)) + +def guidance_guidanceStatusChanged_handler(guidanceStatus,routeHandle): + global g_guidance_active + print('Guidance status changed: '+str(guidanceStatus)) + if guidanceStatus != GENIVI_NAVIGATIONCORE_ACTIVE and g_guidance_active == True: + g_guidance_active = False + route = g_current_route + 1 + if route < routes.length: + launch_route_calculation(route) + else: + for i in range(routes.length): + g_routing_interface.DeleteRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data)) + g_navigationcore_session_interface.DeleteSession(dbus.UInt32(g_navigationcore_session_handle)) + +def guidance_positionOnRouteChanged_handler(offsetOnRoute): + print "Offset on route: " +str(offsetOnRoute) + +def guidance_maneuverChanged_handler(maneuver): + print "Maneuver: " +str(maneuver) + ret = g_guidance_interface.GetDestinationInformation() + print "Travel time: " +str(ret[1]) + ret = g_guidance_interface.GetManeuversList(dbus.UInt16(10),dbus.UInt32(0)) + print "Number of maneuvers: " +str(ret[1]) + print "Next road to turn: " +str(ret[2][0][4]) + g_mapmatchedposition_interface.SetSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(False)) + g_guidance_interface.StopGuidance(dbus.UInt32(g_navigationcore_session_handle)) + +def mapmatchedposition_simulationStatusChanged_handler(simulationStatus): + print "Simulation status: " +str(simulationStatus) + +#timeout + +def timeout(): + print 'Timeout Expired' + print '\nTest FAILED' + exit() + +def exit(): + stopTrigger(test_name) + loop.quit() + +def display_route(route): + ret = g_routing_interface.GetRouteBoundingBox(dbus.UInt32(g_route_handle)) + g_mapviewercontrol_interface.SetMapViewBoundingBox(dbus.UInt32(g_mapviewer_sessionhandle),dbus.UInt32(g_mapviewer_maphandle),ret) + g_mapviewercontrol_interface.DisplayRoute( \ + dbus.UInt32(g_mapviewer_sessionhandle), \ + dbus.UInt32(g_mapviewer_maphandle), \ + dbus.UInt32(route), \ + dbus.Boolean(True)) + +def launch_guidance(route): + g_mapmatchedposition_interface.SetSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(True)) + g_guidance_interface.StartGuidance(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(route)) + g_mapviewercontrol_interface.SetFollowCarMode(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(g_mapviewer_maphandle),True) + g_mapviewercontrol_interface.SetMapViewScale(dbus.UInt32(g_mapviewer_sessionhandle),dbus.UInt32(g_mapviewer_maphandle),ZOOM_GUIDANCE) + g_mapviewercontrol_interface.SetTargetPoint(dbus.UInt32(g_mapviewer_sessionhandle),\ + dbus.UInt32(g_mapviewer_maphandle),\ + dbus.Struct((\ + dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]),\ + dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]),\ + dbus.Double(0)\ + ))) + g_mapmatchedposition_interface.StartSimulation(g_navigationcore_session_handle) + +def launch_route_calculation(route): + global g_current_route + global g_route_handle + global g_routing_interface + global g_navigationcore_session_handle + g_current_route = route + print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data + #get route handle + ret = g_routing_interface.CreateRoute(dbus.UInt32(g_navigationcore_session_handle)) + g_route_handle=ret[1] + routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle + print 'Route handle: ' + str(g_route_handle) + start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data + dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data + print 'Calculating route from \ +'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \ +'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')' + #set waypoints + waypointDoubleCapiType = 0x03 + g_routing_interface.SetWaypoints(dbus.UInt32(g_navigationcore_session_handle), \ + dbus.UInt32(g_route_handle), \ + dbus.Boolean(0), \ + dbus.Array([ \ + dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \ + dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \ + ]) \ + ) + + #calculate route + g_routing_interface.CalculateRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(g_route_handle)) + +def createMapView(): + global g_mapviewer_sessionhandle + global g_mapviewer_sessionstatus + global g_mapviewer_sessionlist + global g_mapviewer_maphandle + + #get mapviewer session handle + ret = g_mapviewer_session_interface.CreateSession(dbus.String('test mapviewer')) + g_mapviewer_sessionhandle=ret[1] + print 'Mapviewer session handle: ' + str(g_mapviewer_sessionhandle) + + g_mapviewer_sessionstatus = g_mapviewer_session_interface.GetSessionStatus(dbus.UInt32(g_mapviewer_sessionhandle)); + print 'Mapviewer session status: ' + str(g_mapviewer_sessionstatus) + + g_mapviewer_sessionlist = g_mapviewer_session_interface.GetAllSessions(); + print 'Mapviewer active sessions = ' + str(len(g_mapviewer_sessionlist)) + + #get mapviewer handle + ret = g_mapviewercontrol_interface.CreateMapViewInstance( \ + dbus.UInt32(g_mapviewer_sessionhandle), \ + dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ + dbus.Int32(MAIN_MAP)) + g_mapviewer_maphandle=ret[1] + + print 'MapView handle: ' + str(g_mapviewer_maphandle) + + time.sleep(2) + + print 'Stop following the car position' + g_mapviewercontrol_interface.SetFollowCarMode( \ + dbus.UInt32(g_mapviewer_sessionhandle), \ + dbus.UInt32(g_mapviewer_maphandle), \ + dbus.Boolean(False)) + +def deleteMapView(): + g_mapviewercontrol_interface.ReleaseMapViewInstance( \ + dbus.UInt32(g_mapviewer_sessionhandle), \ + dbus.UInt32(g_mapviewer_maphandle)) + + g_mapviewer_session_interface.DeleteSession(g_mapviewer_sessionhandle) + + +print('--------------------------') +print('Guidance Test') +print('--------------------------') + +parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.') +parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format') +args = parser.parse_args() + +if args.routes == None: + print('route file is missing') + sys.exit(1) +else: + try: + DOMTree = xml.dom.minidom.parse(args.routes) + except OSError as e: + if e.errno == errno.ENOENT: + print('file not exists') + sys.exit(1) + route_set = DOMTree.documentElement + +print("Country : %s" % route_set.getAttribute("country")) + +routes = route_set.getElementsByTagName("route") + +#create dictionary with the locations +locations = {} +for location in route_set.getElementsByTagName("location"): + lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data] + locations[location.getAttribute("name")] = lat_long + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +#connect to session bus +bus = dbus.SessionBus() + +bus.add_signal_receiver(routing_routeCalculationProgressUpdate_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ + signal_name = "RouteCalculationProgressUpdate") + +bus.add_signal_receiver(routing_routeCalculationSuccessful_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ + signal_name = "RouteCalculationSuccessful") + +bus.add_signal_receiver(routing_routeDeleted_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ + signal_name = "RouteDeleted") + +bus.add_signal_receiver(session_sessionDeleted_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Session", \ + signal_name = "SessionDeleted") + +bus.add_signal_receiver(guidance_guidanceStatusChanged_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Guidance", \ + signal_name = "GuidanceStatusChanged") + +bus.add_signal_receiver(guidance_positionOnRouteChanged_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Guidance", \ + signal_name = "PositionOnRouteChanged") + +bus.add_signal_receiver(guidance_maneuverChanged_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Guidance", \ + signal_name = "ManeuverChanged") + +bus.add_signal_receiver(mapmatchedposition_simulationStatusChanged_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.MapMatchedPosition", \ + signal_name = "SimulationStatusChanged") + +startTrigger(test_name) + +navigationcore_session_obj = bus.get_object('org.genivi.navigation.navigationcore.Session','/org/genivi/navigationcore') +g_navigationcore_session_interface = dbus.Interface(navigationcore_session_obj, dbus_interface='org.genivi.navigation.navigationcore.Session') + +routing_obj = bus.get_object('org.genivi.navigation.navigationcore.Routing','/org/genivi/navigationcore') +g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigation.navigationcore.Routing') + +guidance_obj = bus.get_object('org.genivi.navigation.navigationcore.Guidance','/org/genivi/navigationcore') +g_guidance_interface = dbus.Interface(guidance_obj, dbus_interface='org.genivi.navigation.navigationcore.Guidance') + +mapviewer_session_obj = bus.get_object('org.genivi.navigation.mapviewer.Session','/org/genivi/mapviewer') +g_mapviewer_session_interface = dbus.Interface(mapviewer_session_obj, dbus_interface='org.genivi.navigation.mapviewer.Session') + +g_mapviewercontrol_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl','/org/genivi/mapviewer') +g_mapviewercontrol_interface = dbus.Interface(g_mapviewercontrol_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl') + +g_mapmatchedposition_obj = bus.get_object('org.genivi.navigation.navigationcore.MapMatchedPosition','/org/genivi/navigationcore') +g_mapmatchedposition_interface = dbus.Interface(g_mapmatchedposition_obj, dbus_interface='org.genivi.navigation.navigationcore.MapMatchedPosition') + +#get navigationcore session handle +ret = g_navigationcore_session_handle = g_navigationcore_session_interface.CreateSession(dbus.String("test guidance")) +g_navigationcore_session_handle=ret[1] +print 'Navigation core session handle: ' + str(g_navigationcore_session_handle) + +createMapView() + +g_current_route = 0 +g_guidance_active = False +launch_route_calculation(0) + +#main loop +gobject.timeout_add(TIME_OUT, timeout) +loop = gobject.MainLoop() +loop.run() + +#deleteMapView() diff --git a/test/navigation/script/test-location-input.py b/test/navigation/script/test-location-input.py new file mode 100755 index 0000000..935c1f9 --- /dev/null +++ b/test/navigation/script/test-location-input.py @@ -0,0 +1,499 @@ +#!/usr/bin/python +# -*- coding: latin-1 -*- + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* @copyright Copyright (C) 2014, Alpine Electronics R&D Europe GmbH +* +* @file test-location-input.py +* +* @brief This simple test shows how the location input +* could be easily tested using a python script +* +* @author Stephan Wiehr +* @author Philippe Colliot +* +* @version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add status handler +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +from xml.dom.minidom import parse +import xml.dom.minidom +import argparse +import sys +import errno +from dltTrigger import * +#import pdb;pdb.set_trace() + +#name of the test +test_name = "location input" + +# constants as defined in the Navigation API +LATITUDE = 0x00a0 +LONGITUDE = 0x00a1 +ALTITUDE = 0x00a2 +FULL_ADDRESS = 0x00b2 +COUNTRY = 0x00a6 +STATE = 0x00a7 +CITY = 0x00a8 +ZIPCODE = 0x00a9 +STREET = 0x00aa +HOUSE_NUMBER = 0x00ab +CROSSING = 0x00ac +DISTRICT = 0x00ad +PHONE_NUMBER = 0x00ae +POI_NAME = 0x00af +TOWN_CENTER = 0x00b0 +FINISHED = 0x00c2 + +# List of addresses +COUNTRY_STRING = list() +CITY_STRING = list() +STREET_STRING = list() +HOUSE_NUMBER_STRING = list() + +# Default size of the list +WINDOW_SIZE = 20 + +# Search mode (0 = Spell, 1 = Full string search) +country_search_mode = 1 +city_search_mode = 0 +street_search_mode = 1 #set to full because of a bug to be fixed in the plug-in +house_number_search_mode = 1 + +print '\n--------------------------\n' + \ + 'LocationInput Test' + \ + '\n--------------------------\n' + +parser = argparse.ArgumentParser(description='Location input Test for navigation PoC and FSA.') +parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') +parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') +args = parser.parse_args() + +if args.locations == None: + print('location file is missing') + sys.exit(1) +else: + try: + DOMTree = xml.dom.minidom.parse(args.locations) + except OSError as e: + if e.errno == errno.ENOENT: + print('file not exists') + sys.exit(1) + location_set = DOMTree.documentElement + +print("Area : %s" % location_set.getAttribute("area")) + +locations = location_set.getElementsByTagName("location") + +for location in location_set.getElementsByTagName("location"): + COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) + CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) + STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) + #HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) + HOUSE_NUMBER_STRING.append('') #there's a bug in the navigation core when the house number doesn't exist, so deactivated + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +# connect to session bus +bus = dbus.SessionBus() + +def vprint(text): + if args.verbose: + print(text) + +# Turn selection criteria values to their corresponding string description +def selection_criterion_to_string(selection_criterion): + return_value = '' + if selection_criterion == LATITUDE: + return_value += 'Latitude' + elif selection_criterion == LONGITUDE: + return_value += 'Longitude' + elif selection_criterion == COUNTRY: + return_value += 'Country' + elif selection_criterion == STATE: + return_value += 'State' + elif selection_criterion == CITY: + return_value += 'City' + elif selection_criterion == TOWN_CENTER: + return_value += 'City center' + elif selection_criterion == ZIPCODE: + return_value += 'ZipCode' + elif selection_criterion == STREET: + return_value += 'Street' + elif selection_criterion == HOUSE_NUMBER: + return_value += 'House number' + elif selection_criterion == CROSSING: + return_value += 'Crossing' + elif selection_criterion == FULL_ADDRESS: + return_value += 'Full address' + else: + return_value += str(selection_criterion) + + return return_value + + +# Prepare a dictionary array for pretty printing + +def dictionary_array_to_string(dict_array, linefeed, offset=0): + return_value = '' + i = offset + for item in dict_array: + return_value += str(i) + '. ' + unicode(dictionary_to_string(item)) + if i < offset + len(dict_array) - 1: + return_value += linefeed + i += 1 + + return return_value + + +# Prepare a dictionary for pretty printing +# NB: the value is supposed to be [UInt8, Variant], according to the DBus '(yv)', used by CommonAPI +def dictionary_to_string(dictionary): + return_value = '' + i = 0 + for key in dictionary.keys(): + value = dictionary[key][1] + return_value += selection_criterion_to_string(key) + ' = ' + unicode(value) + i += 1 + if i < len(dictionary): + return_value += ', ' + + return return_value + + +# Prepare a selection criteria array for pretty printing + +def selection_criteria_array_to_string(selection_criterion_array): + return_value = '' + i = 0 + for item in selection_criterion_array: + return_value += selection_criterion_to_string(item) + i += 1 + if i < len(selection_criterion_array): + return_value += ', ' + + return return_value + + +def print_current_context(): + vprint('\tACTIVE CONTEXT: selection criterion = ' + selection_criterion_to_string(current_selection_criterion) + \ + ', search string = \'' + entered_search_string + '\'') + + +def change_selection_criterion(selection_criterion): + global current_selection_criterion + + current_selection_criterion = selection_criterion + location_input_interface.SetSelectionCriterion(dbus.UInt32(session_handle), dbus.UInt32(location_input_handle), + dbus.UInt16(current_selection_criterion)) + + +# Spell search +def spell_search(handle, entered_string, search_string, valid_characters, first=0): + global entered_search_string + + vprint('-> SpellSearch - entered \'' + entered_string + '\' target \'' + search_string + '\'') + + if unicode(search_string) != unicode(entered_string): + found = unicode(search_string).lower().find(unicode(entered_string).lower()) + if found == 0: + is_valid = -1 + if first == 0: + spell_character = search_string[len(entered_string)] + is_valid = valid_characters.find(spell_character) + else: + spell_character='' + is_valid = 0 + if is_valid != -1: + entered_search_string = entered_string + spell_character + vprint('\nACTION: Spell search, selection criterion = ' + \ + selection_criterion_to_string(current_selection_criterion) + ', trying \'' + spell_character + \ + '\'') + location_input_interface.Spell(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.String(spell_character), dbus.UInt16(20)) + else: + print 'TEST FAILED (Target character can not be entered)' + exit() + else: + print 'TEST FAILED (Unexpected completion)' + exit() + else: + print 'Full spell match' + + +# Full string search +def full_string_search(handle, search_string): + global entered_search_string + global found_exact_match + + entered_search_string = search_string + found_exact_match = 1 # Force exact match for full string search + vprint('\nACTION: Full string search, selection criterion = ' + \ + selection_criterion_to_string(current_selection_criterion) + ', trying \'' + search_string + '\'') + location_input_interface.Search(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.String(search_string), + dbus.UInt16(20)) + + +def evaluate_address(address, guidable): + test_passed = 0 + print '\nAddress complete!\nEvaluating...' + if COUNTRY_STRING[current_address_index] == '': + test_passed = 1 + elif address[COUNTRY][1] == COUNTRY_STRING[current_address_index]: + print 'Country\t\t\t-> ok (' + address[COUNTRY][1] + ')' + if CITY_STRING[current_address_index] == '': + test_passed = 1 + elif address[CITY][1] == CITY_STRING[current_address_index]: + print 'City\t\t\t-> ok (' + address[CITY][1] + ')' + if STREET_STRING[current_address_index] == '': + test_passed = 1 + elif address[STREET][1] == STREET_STRING[current_address_index]: + print 'Street\t\t\t-> ok (' + address[STREET][1] + ')' + if HOUSE_NUMBER_STRING[current_address_index] == '': + test_passed = 1 + elif address[HOUSE_NUMBER][1] == HOUSE_NUMBER_STRING[current_address_index]: + print 'House number\t-> ok (' + address[HOUSE_NUMBER][1] + ')' + test_passed = 1 + + if guidable == 1: + if test_passed == 1: + print 'TEST PASSED' + else: + print 'TEST FAILED (wrong address)' + exit() + else: + print 'TEST FAILED (non-guidable address)' + exit() + address_index = current_address_index + 1 + if address_index < len(COUNTRY_STRING): + startSearch(address_index) + else: + print 'END OF THE TEST' + exit() + + +# Signal receiver + +# Handler for ContentUpdated callback + +def search_status_handler(handle,status): + vprint('\n::Search status ' + str(int(status))) + if status == FINISHED: + location_input_interface.RequestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.UInt16(0), + dbus.UInt16(WINDOW_SIZE)) + + +def content_updated_handler(handle, guidable, available_selection_criteria, address): + global target_search_string + global entered_search_string + + vprint('\n::ContentUpdated for LocationInputHandle ' + str(int(handle))) + print_current_context() + vprint('\tGuidable = ' + str(guidable)) + vprint('\tAvailable selection criteria = ' + selection_criteria_array_to_string(available_selection_criteria)) + vprint('\tADDRESS: '+dictionary_to_string(address)) + + search_mode = -1 + + if current_selection_criterion == COUNTRY: + change_selection_criterion(CITY) + target_search_string = CITY_STRING[current_address_index] + search_mode = city_search_mode + elif current_selection_criterion == CITY: + change_selection_criterion(STREET) + target_search_string = STREET_STRING[current_address_index] + search_mode = street_search_mode + elif current_selection_criterion == STREET: + change_selection_criterion(HOUSE_NUMBER) + target_search_string = HOUSE_NUMBER_STRING[current_address_index] + search_mode = house_number_search_mode + elif current_selection_criterion == HOUSE_NUMBER: + target_search_string = '' + + entered_search_string = '' + + if target_search_string == '': + evaluate_address(address, guidable) + elif search_mode == 0: + spell_search(handle, entered_search_string, target_search_string, '', 1) + elif search_mode == 1: + full_string_search(handle, target_search_string) + else: + print '\nTEST FAILED (Invalid search mode)' + exit() + +# Handler for SpellResult callback +def spell_result_handler(handle, unique_string, valid_characters, full_match): + global entered_search_string + global spell_next_character + global found_exact_match + global available_characters + + vprint('\n::SpellResult for LocationInputHandle '+str(int(handle))) + if unique_string != entered_search_string: + vprint('\tAUTOCOMPLETE: \'' + entered_search_string + '\' -> \'' + unique_string + '\'') + entered_search_string = unique_string + available_characters = valid_characters + print_current_context() + vprint('\tUnique string = \''+unique_string+'\'') + vprint('\tValid Characters = \''+valid_characters+'\'') + vprint('\tFull Match = '+str(full_match)) + + if len(valid_characters) == 1: + if unicode(valid_characters[0]) == u'\x08': + print '\nTEST FAILED (Dead end spelling)' + exit() + + if unicode(entered_search_string) == unicode(target_search_string): + found_exact_match = 1 + + spell_next_character = 1 + + +# Handler for SearchResultList callback + +def search_result_list_handler(handle, total_size, window_offset, window_size, result_list_window): + global spell_next_character + global found_exact_match + + vprint('\n::SearchResultList for LocationInputHandle ' + str(int(handle))) + print_current_context() + vprint('\tTotal size = ' + str(int(total_size)) + ', Window offset = ' + str(int(window_offset)) + \ + ', Window size = ' + str(int(window_size))) + vprint('\t' + dictionary_array_to_string(result_list_window, '\n\t', window_offset)) + + if found_exact_match == 1: + found_exact_match = 0 + i = 0 + for address in result_list_window: + if unicode(address[current_selection_criterion][1]) == target_search_string: + vprint('\nACTION: Found exact match, selecting \''+unicode(address[current_selection_criterion][1]) + \ + '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.SelectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(i)) + break + i += 1 + if i == window_size: + vprint('\nACTION: Found exact match, searching in next page (Session '+str(int(session_handle)) +\ + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.RequestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), + dbus.UInt16(window_offset + window_size), + dbus.UInt16(window_size)) + elif total_size == 1: + selection_name = result_list_window[0][current_selection_criterion] + if selection_name[1] == target_search_string: + vprint('\nACTION: Single entry list, selecting \'' + selection_name[1] + \ + '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') + location_input_interface.SelectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(0)) + else: + print '\nTEST FAILED (Unexpected single result list)' + exit() + elif spell_next_character == 1: + spell_next_character = 0 + spell_search(handle, entered_search_string, target_search_string, available_characters) + + +# add signal receiver +bus.add_signal_receiver(search_status_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput', + signal_name='SearchStatus') + +bus.add_signal_receiver(search_result_list_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput', + signal_name='SearchResultList') + +bus.add_signal_receiver(spell_result_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput', + signal_name='SpellResult') + +bus.add_signal_receiver(content_updated_handler, + dbus_interface='org.genivi.navigation.navigationcore.LocationInput', + signal_name='ContentUpdated') + + +# Timeout +def timeout(): + print 'Timeout Expired' + print '\nTEST FAILED\n' + exit() + +def exit(): + error=location_input_interface.DeleteLocationInput(dbus.UInt32(session_handle),dbus.UInt32(location_input_handle)) + print('Delete location input: '+str(int(error))) + error=session_interface.DeleteSession(dbus.UInt32(session_handle)) + print('Delete session: '+str(int(error))) + stopTrigger(test_name) + loop.quit() + +def startSearch(address_index): + global entered_search_string + global spell_next_character + global found_exact_match + global available_characters + global target_search_string + global country_search_mode + global current_address_index + current_address_index = address_index + entered_search_string = '' + spell_next_character = 0 + found_exact_match = 0 + available_characters = '' + target_search_string = COUNTRY_STRING[current_address_index] + + change_selection_criterion(COUNTRY) + if country_search_mode == 0: + spell_search(location_input_handle, entered_search_string, target_search_string, available_characters, 1) + elif country_search_mode == 1: + full_string_search(location_input_handle, target_search_string) + +startTrigger(test_name) + +session = bus.get_object('org.genivi.navigation.navigationcore.Session', '/org/genivi/navigationcore') +session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session') + +# Get SessionHandle +ret = session_interface.CreateSession(dbus.String('test location input')) +session_handle=ret[1] +print 'Session handle = ' + str(session_handle) + +location_input_obj = bus.get_object('org.genivi.navigation.navigationcore.LocationInput', '/org/genivi/navigationcore') +location_input_interface = dbus.Interface(location_input_obj, dbus_interface='org.genivi.navigation.navigationcore.LocationInput') + +# Get LocationInputHandle +ret = location_input_interface.CreateLocationInput(dbus.UInt32(session_handle)) +location_input_handle = ret[1] +print 'LocationInput handle = ' + str(location_input_handle) + +attributes = location_input_interface.GetSupportedAddressAttributes() +print 'Initially supported address attributes = ' + selection_criteria_array_to_string(attributes) + +# Configuration +current_address_index = 0 +entered_search_string = '' +spell_next_character = 0 +found_exact_match = 0 +available_characters = '' +target_search_string = '' + +startSearch(0) + +# Main loop +gobject.timeout_add(10000, timeout) +loop = gobject.MainLoop() +loop.run() diff --git a/test/navigation/script/test-map-viewer-control-single.py b/test/navigation/script/test-map-viewer-control-single.py new file mode 100755 index 0000000..e7975d6 --- /dev/null +++ b/test/navigation/script/test-map-viewer-control-single.py @@ -0,0 +1,193 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2015, Mentor Graphics +* +* \file test-map-viewer-control.py +* +* \brief This simple test shows how the mapviewer +* could be easily tested using a python script +* +* \author Marco Residori +* \author Philippe Colliot +* +* \version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add some methods +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +import time +from dltTrigger import * +#import pdb; pdb.set_trace() + +#name of the test +test_name = "map viewer" + +#constants as defined in the Navigation API +LATITUDE = 0x00a0 +LONGITUDE = 0x00a1 + +MAIN_MAP = 0x0010 +SPLIT_SCREEN = 0x0011 + +#constants used by the script +HORIZONTAL_SIZE = 800 +VERTICAL_SIZE = 480 +TIME_OUT = 20000 +MIN_SCALE = 0 +MAX_SCALE = 21 + +def mapviewer_mapViewScaleChanged_handler(mapViewInstanceHandle,scale,isMinMax): + global g_scale + new_scale=int(scale) + print("Scale: "+str(new_scale)) + print('Is min max: '+str(int(isMinMax))) + time.sleep(0.25) + if g_scale > new_scale and new_scale !=MIN_SCALE: + print("Zoom in") + g_scale=new_scale + MapViewerControl_interface.SetMapViewScaleByDelta( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Int16(1)) + else: + if new_scale < MAX_SCALE: + print("Zoom out") + g_scale=new_scale + MapViewerControl_interface.SetMapViewScaleByDelta( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Int16(-1)) + else: + print 'Test PASSED' + MapViewerControl_interface.ReleaseMapViewInstance( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle)) + session_interface.DeleteSession(sessionhandle) + exit() + +#timeout +def timeout(): + print 'Timeout Expired' + print '\nTest FAILED' + exit() + +def exit(): + stopTrigger(test_name) + loop.quit() + +print '\n--------------------------' +print 'MapViewerControl Test' +print '--------------------------\n' + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + +#connect to session bus +bus = dbus.SessionBus() + +bus.add_signal_receiver(mapviewer_mapViewScaleChanged_handler, \ + dbus_interface = "org.genivi.navigation.mapviewer.MapViewerControl", \ + signal_name = "MapViewScaleChanged") + + +startTrigger(test_name) + +session = bus.get_object('org.genivi.navigation.mapviewer.Session','/org/genivi/mapviewer') +session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.mapviewer.Session') + +#get session handle +ret = session_interface.CreateSession(dbus.String("test mapviewer")) +sessionhandle=ret[1] +print 'Session handle: ' + str(sessionhandle) + +sessionstatus = session_interface.GetSessionStatus(dbus.UInt32(sessionhandle)); +print 'Session status: ' + str(sessionstatus) + +sessionlist = session_interface.GetAllSessions(); +print 'Active sessions = ' + str(len(sessionlist)) + +MapViewerControl_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl','/org/genivi/mapviewer') +MapViewerControl_interface = dbus.Interface(MapViewerControl_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl') + +#get mapviewer handle +ret = MapViewerControl_interface.CreateMapViewInstance( \ + dbus.UInt32(sessionhandle), \ + dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ + dbus.Int32(MAIN_MAP)) +mapviewerhandle=ret[1] + +print 'MapView handle: ' + str(mapviewerhandle) + +# Tokyo +lat1 = 35.70 +lon1 = 139.74 +alt1 = 0 + +time.sleep(2) + +print 'Stop following the car position' +MapViewerControl_interface.SetFollowCarMode( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Boolean(False)) + +print 'Set center in Tokyo(' + str(lat1) + ',' + str(lon1) + ')' +MapViewerControl_interface.SetTargetPoint( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Struct((dbus.Double(lat1),dbus.Double(lon1),dbus.Double(alt1)))) + +# Get current position +targetPoint = MapViewerControl_interface.GetTargetPoint( \ + dbus.UInt32(mapviewerhandle) ) + +lat2 = targetPoint[0] +lon2 = targetPoint[1] +alt2 = targetPoint[2] + +print 'Get center -> (' + str(lat2) + ',' + str(lon2) + ')' + +if round(lat1,4) != round(lat2,4) : + print '\nTest Failed:' + str(round(lat1,4)) + '!=' + str(round(lat2,4)) + '\n' + +if round(lon1,4) != round(lon2,4) : + print '\nTest Failed:' + str(round(lon1,4)) + '!=' + str(round(lon2,4)) + '\n' + +if round(alt1,4) != round(alt2,4) : + print '\nTest Failed:' + str(round(alt1,4)) + '!=' + str(round(alt2,4)) + '\n' + +ret=MapViewerControl_interface.GetMapViewScale(dbus.UInt32(mapviewerhandle)) +print('Scale: '+str(int(ret[0]))) +print('Is min max: '+str(int(ret[1]))) + +g_scale=int(ret[0]) + +print 'Zoom in' +MapViewerControl_interface.SetMapViewScaleByDelta( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Int16(1)) + +exit() + +#main loop +gobject.timeout_add(TIME_OUT, timeout) +loop = gobject.MainLoop() +loop.run() + diff --git a/test/navigation/script/test-map-viewer-control.py b/test/navigation/script/test-map-viewer-control.py new file mode 100755 index 0000000..5cc5515 --- /dev/null +++ b/test/navigation/script/test-map-viewer-control.py @@ -0,0 +1,262 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2015, Mentor Graphics +* +* \file test-map-viewer-control.py +* +* \brief This simple test shows how the mapviewer +* could be easily tested using a python script +* +* \author Marco Residori +* \author Philippe Colliot +* +* \version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add some methods +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +import time +from dltTrigger import * +from xml.dom.minidom import parse +import xml.dom.minidom +import argparse +import sys +import errno +#import pdb; pdb.set_trace() + +#name of the test +test_name = "map viewer" + +#constants as defined in the Navigation API +LATITUDE = 0x00a0 +LONGITUDE = 0x00a1 +MAPVIEWER_MAX = 0x0041 +MAPVIEWER_MIN = 0x0040 + +MAIN_MAP = 0x0010 +SPLIT_SCREEN = 0x0011 + +#constants used by the script +HORIZONTAL_SIZE = 800 +VERTICAL_SIZE = 480 +TIME_OUT = 20000 +INIT_SCALE=2 +TEST_STEP_START=0 +TEST_STEP_SCALE=1 +TEST_STEP_ROTATE=2 + +# List of coordinates +LATITUDE = list() +LONGITUDE = list() +ALTITUDE = list() +COUNTRY_STRING = list() +CITY_STRING = list() +STREET_STRING = list() +HOUSE_NUMBER_STRING = list() + +def mapviewer_mapViewScaleChanged_handler(mapViewInstanceHandle,scale,isMinMax): + global g_scale + global step + new_scale=int(scale) + print("Scale: "+str(new_scale)) + print('Is min max: '+str(int(isMinMax))) + if step ==TEST_STEP_SCALE: + time.sleep(0.25) + if g_scale > new_scale and isMinMax !=MAPVIEWER_MIN: + print("Zoom in") + g_scale=new_scale + MapViewerControl_interface.SetMapViewScaleByDelta( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Int16(-1)) + else: + if isMinMax !=MAPVIEWER_MAX: + print("Zoom out") + g_scale=new_scale + MapViewerControl_interface.SetMapViewScaleByDelta( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Int16(1)) + else: + print('Test scale PASSED') + next_step() + +#timeout +def timeout(): + print('Timeout Expired') + print ('\nTest FAILED') + exit() + + +def exit(): + MapViewerControl_interface.ReleaseMapViewInstance( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle)) + session_interface.DeleteSession(sessionhandle) + stopTrigger(test_name) + loop.quit() + +def next_step(): + global step + if step == TEST_STEP_START: + step=TEST_STEP_SCALE + print ('Test scale') + MapViewerControl_interface.SetMapViewScale( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.UInt16(INIT_SCALE)) + else: + if step ==TEST_STEP_SCALE: + step=TEST_STEP_ROTATE + print ('Test rotate') + MapViewerControl_interface.SetMapViewScale( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.UInt16(INIT_SCALE)) + exit() + else: + if step ==TEST_STEP_ROTATE: + exit() + +print('\n--------------------------') +print('MapViewerControl Test') +print('--------------------------\n') + +parser = argparse.ArgumentParser(description='Map Viewer Test for navigation PoC and FSA.') +parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') +parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') +args = parser.parse_args() + +if args.locations == None: + print('location file is missing') + sys.exit(1) +else: + try: + DOMTree = xml.dom.minidom.parse(args.locations) + except OSError as e: + if e.errno == errno.ENOENT: + print('file not exists') + sys.exit(1) + location_set = DOMTree.documentElement + +print("Area : %s" % location_set.getAttribute("area")) + +locations = location_set.getElementsByTagName("location") + +for location in location_set.getElementsByTagName("location"): + LATITUDE.append(location.getElementsByTagName("latitude")[0].childNodes[0].data) + LONGITUDE.append(location.getElementsByTagName("longitude")[0].childNodes[0].data) + ALTITUDE.append(0) + COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) + CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) + STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) + HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + +#connect to session bus +bus = dbus.SessionBus() + +bus.add_signal_receiver(mapviewer_mapViewScaleChanged_handler, \ + dbus_interface = "org.genivi.navigation.mapviewer.MapViewerControl", \ + signal_name = "MapViewScaleChanged") + + +startTrigger(test_name) + +session = bus.get_object('org.genivi.navigation.mapviewer.Session','/org/genivi/mapviewer') +session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.mapviewer.Session') + +#get session handle +ret = session_interface.CreateSession(dbus.String("test mapviewer")) +sessionhandle=ret[1] +print('Session handle: ' + str(sessionhandle)) + +sessionstatus = session_interface.GetSessionStatus(dbus.UInt32(sessionhandle)); +print ('Session status: ' + str(sessionstatus)) + +sessionlist = session_interface.GetAllSessions(); +print( 'Active sessions = ' + str(len(sessionlist))) + +MapViewerControl_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl','/org/genivi/mapviewer') +MapViewerControl_interface = dbus.Interface(MapViewerControl_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl') + +#get mapviewer handle +ret = MapViewerControl_interface.CreateMapViewInstance( \ + dbus.UInt32(sessionhandle), \ + dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ + dbus.Int32(MAIN_MAP)) +mapviewerhandle=ret[1] + +print('MapView handle: ' + str(mapviewerhandle)) + +index=0 + +lat1 = LATITUDE[index] +lon1 = LONGITUDE[index] +alt1 = ALTITUDE[index] + +time.sleep(2) + +print ('Stop following the car position') +MapViewerControl_interface.SetFollowCarMode( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Boolean(False)) + +print('Set center in '+ CITY_STRING[index]+ ' (' + str(lat1) + ',' + str(lon1) + ')') +MapViewerControl_interface.SetTargetPoint( \ + dbus.UInt32(sessionhandle), \ + dbus.UInt32(mapviewerhandle), \ + dbus.Struct((dbus.Double(lat1),dbus.Double(lon1),dbus.Double(alt1)))) + +# Get current position +targetPoint = MapViewerControl_interface.GetTargetPoint( \ + dbus.UInt32(mapviewerhandle) ) + +lat2 = targetPoint[0] +lon2 = targetPoint[1] +alt2 = targetPoint[2] + +print ('Get center -> (' + str(lat2) + ',' + str(lon2) + ')' ) + +if round(float(lat1),4) != round(float(lat2),4) : + print ('\nTest Failed:' + str(round(float(lat1),4)) + '!=' + str(round(float(lat2),4)) + '\n' ) + +if round(float(lon1),4) != round(float(lon2),4) : + print('\nTest Failed:' + str(round(float(lon1),4)) + '!=' + str(round(float(lon2),4)) + '\n' ) + +if round(float(alt1),4) != round(float(alt2),4) : + print('\nTest Failed:' + str(round(float(alt1),4)) + '!=' + str(round(float(alt2),4)) + '\n') + +ret=MapViewerControl_interface.GetMapViewScale(dbus.UInt32(mapviewerhandle)) +print('Scale: '+str(int(ret[0]))) +print('Is min max: '+str(int(ret[1]))) + +g_scale=int(ret[0]) + +step=TEST_STEP_START +next_step() + +#main loop +gobject.timeout_add(TIME_OUT, timeout) +loop = gobject.MainLoop() +loop.run() + diff --git a/test/navigation/script/test-poi.py b/test/navigation/script/test-poi.py new file mode 100755 index 0000000..a4b48c7 --- /dev/null +++ b/test/navigation/script/test-poi.py @@ -0,0 +1,177 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2016, PSA GROUP +* +* \file test-poi.py +* +* \brief This simple test shows how the poi search +* could be easily tested using a python script +* +* \author Philippe Colliot +* +* \version 1.0 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +import time + +import pdb; +#pdb.set_trace() +from dltTrigger import * + +#name of the test +test_name = "poi search" + +#constants as defined in the Navigation API +GENIVI_Configuration_Settings_LOCALE = 37 +GENIVI_SearchStatusState_FINISHED = 512 +GENIVI_SearchStatusState_NOT_STARTED = 510 + +#constants used into the script +TIME_OUT = 10000 +LATITUDE_PARIS = 48.8578 +LONGITUDE_PARIS = 2.3380 +ALTITUDE_PARIS = 30.0 +ID_HOTEL = 2 +ID_STATION = 6 +ATTRIBUTE_SOURCE = 0 +ATTRIBUTE_PHONE = 2 +RADIUS_HOTEL = 100 #in tenth of meter ! +RADIUS_STATION = 500 +STRING_TO_SEARCH = "Saint-Germain" + +def catch_poi_configurationChanged_signal_handler(changedSettings): + for changedSetting in changedSettings: + if changedSetting == GENIVI_Configuration_Settings_LOCALE: + ret=g_poiConfiguration_interface.GetLocale() + print("language: " + ret[0]) + print("country: " + ret[1]) + print("script: " + ret[2]) + +def catch_poi_poiStatus_signal_handler(poiSearchHandle,statusValue): + if poiSearchHandle == g_searchHandle: + if statusValue == GENIVI_SearchStatusState_FINISHED: + print("Search finished") + elif statusValue == GENIVI_SearchStatusState_NOT_STARTED: + g_poiSearch_interface.DeletePoiSearchHandle(poiSearchHandle) + print("Test PASSED") + exit() + +def catch_poi_resultListChanged_signal_handler(poiSearchHandle,resultListSize): + poiList=[] + if poiSearchHandle == g_searchHandle and resultListSize != 0: + ret=g_poiSearch_interface.RequestResultList(dbus.UInt32(poiSearchHandle),dbus.UInt16(0),dbus.UInt16(resultListSize),[ATTRIBUTE_SOURCE,ATTRIBUTE_PHONE]) + if ret[0] == GENIVI_SearchStatusState_FINISHED and ret[1] >= 0: + print("Results: "+str(int(ret[1]))) + for result in ret[2]: + poiList.append(result[0]) + ret=g_poiSearch_interface.GetPoiDetails(poiList) + for resultDetail in ret: + if resultDetail[1][0] == ID_HOTEL: + print("Hotel: " +resultDetail[0][1]) + elif resultDetail[1][0] == ID_STATION: + print("Station: " +resultDetail[0][1]) + g_poiSearch_interface.CancelPoiSearch(dbus.UInt32(poiSearchHandle)) + +#timeout +def timeout(): + print ('Timeout Expired') + print ('\nTest FAILED') + exit() + +def exit(): + stopTrigger(test_name) + loop.quit() + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +print("Search for hotel and station with keyword: "+ STRING_TO_SEARCH) + +#connect to session bus +bus = dbus.SessionBus() + +bus.add_signal_receiver(catch_poi_configurationChanged_signal_handler, \ + dbus_interface = "org.genivi.navigation.poiservice.POIConfiguration", \ + signal_name = "ConfigurationChanged") + +bus.add_signal_receiver(catch_poi_poiStatus_signal_handler, \ + dbus_interface = "org.genivi.navigation.poiservice.POISearch", \ + signal_name = "PoiStatus") + +bus.add_signal_receiver(catch_poi_resultListChanged_signal_handler, \ + dbus_interface = "org.genivi.navigation.poiservice.POISearch", \ + signal_name = "ResultListChanged") + +startTrigger(test_name) + +poiConfiguration = bus.get_object('org.genivi.navigation.poiservice.POIConfiguration','/org/genivi/poiservice/POIConfiguration') +g_poiConfiguration_interface = dbus.Interface(poiConfiguration, dbus_interface='org.genivi.navigation.poiservice.POIConfiguration') + +poiContentAccess = bus.get_object('org.genivi.navigation.poiservice.POIContentAccess','/org/genivi/poiservice/POIContentAccess') +g_poiContentAccess_interface = dbus.Interface(poiContentAccess, dbus_interface='org.genivi.navigation.poiservice.POIContentAccess') + +poiSearch = bus.get_object('org.genivi.navigation.poiservice.POISearch','/org/genivi/poiservice/POISearch') +g_poiSearch_interface = dbus.Interface(poiSearch, dbus_interface='org.genivi.navigation.poiservice.POISearch') + +g_poiConfiguration_interface.SetLocale(dbus.String("fra"),dbus.String("FRA"),dbus.String("Latn")) + +categories=[] +ret=g_poiSearch_interface.GetAvailableCategories() +for categoryAndName in ret: + if categoryAndName[0] == ID_HOTEL or categoryAndName[0] == ID_STATION: + print("Category ID: " + str(int(categoryAndName[0]))) + categories.append(categoryAndName[0]) + print("Name: " + categoryAndName[1]) + +attributes_hotel=[] +attributes_station=[] +attributesDetails=[] +ret=g_poiSearch_interface.GetCategoriesDetails(categories) +for results in ret: + if results[0][0] == ID_HOTEL: + for attribute in results[1]: + attributes_hotel.append(attribute[0]) + attributesDetails.append(dbus.Struct([dbus.UInt32(attribute[0]),dbus.UInt32(ID_HOTEL),dbus.Int32(1280),dbus.Struct([dbus.Byte(2),dbus.String("")]),dbus.Int32(1314),dbus.Boolean(False)])) + elif results[0][0] == ID_STATION: + for attribute in results[1]: + attributes_station.append(attribute[0]) + attributesDetails.append(dbus.Struct([dbus.UInt32(attribute[0]),dbus.UInt32(ID_STATION),dbus.Int32(1280),dbus.Struct([dbus.Byte(2),dbus.String("")]),dbus.Int32(1314),dbus.Boolean(False)])) + +ret=g_poiSearch_interface.GetRootCategory() + +g_searchHandle=g_poiSearch_interface.CreatePoiSearchHandle() +print("Search handle: " + str(int(g_searchHandle))) + +lat = LATITUDE_PARIS +lon = LONGITUDE_PARIS +alt = ALTITUDE_PARIS + +g_poiSearch_interface.SetCenter(g_searchHandle,dbus.Struct([lat,lon,alt])) + +g_poiSearch_interface.SetCategories(g_searchHandle,[dbus.Struct([dbus.UInt32(ID_HOTEL),dbus.UInt32(RADIUS_HOTEL)]),dbus.Struct([dbus.UInt32(ID_STATION),dbus.UInt32(RADIUS_STATION)])]) + +g_poiSearch_interface.SetAttributes(g_searchHandle,attributesDetails) + +g_poiSearch_interface.StartPoiSearch(g_searchHandle,dbus.String(STRING_TO_SEARCH),dbus.Int32(1376)) + + +#main loop +gobject.timeout_add(TIME_OUT, timeout) +loop = gobject.MainLoop() +loop.run() diff --git a/test/navigation/script/test-route-calculation.py b/test/navigation/script/test-route-calculation.py new file mode 100755 index 0000000..f0a5221 --- /dev/null +++ b/test/navigation/script/test-route-calculation.py @@ -0,0 +1,220 @@ +#!/usr/bin/python + +""" +************************************************************************** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2014, XS Embedded GmbH, PCA Peugeot Citroen +* +* \file test-route-calculation.py +* +* \brief This simple test shows how the route calculation +* could be easily tested using a python script +* +* \author Marco Residori +* \author Philippe Colliot +* +* \version 1.1 +* +* This Source Code Form is subject to the terms of the +* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +* List of changes: +* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants) +* +* @licence end@ +************************************************************************** +""" + +import dbus +import gobject +import dbus.mainloop.glib +from collections import namedtuple,defaultdict +from _dbus_bindings import Int32 +from PIL.GimpGradientFile import SEGMENTS +from xml.dom.minidom import parse +import xml.dom.minidom +import argparse +import sys +import errno +#import pdb;pdb.set_trace() +from pip import locations +from dltTrigger import * + +#name of the test +test_name = "route calculation" + +#constants as defined in the Navigation API +GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0 +GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1 +GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e +GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f +GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147 +GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141 +GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142 +GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143 +GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144 +GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148 +GENIVI_NAVIGATIONCORE_TIME = 0x0149 +GENIVI_NAVIGATIONCORE_SPEED = 0x00a4 + +#constants used into the script +TIME_OUT = 10000 + +print('--------------------------') +print('Route Calculation Test') +print('--------------------------') + +parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.') +parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format') +args = parser.parse_args() + +if args.routes == None: + print('route file is missing') + sys.exit(1) +else: + try: + DOMTree = xml.dom.minidom.parse(args.routes) + except OSError as e: + if e.errno == errno.ENOENT: + print('file not exists') + sys.exit(1) + route_set = DOMTree.documentElement + +print("Country : %s" % route_set.getAttribute("country")) + +routes = route_set.getElementsByTagName("route") + +#create dictionary with the locations +locations = {} +for location in route_set.getElementsByTagName("location"): + lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data] + locations[location.getAttribute("name")] = lat_long + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +#connect to session bus +bus = dbus.SessionBus() + +#add signal receivers +def catchall_route_calculation_signals_handler(routeHandle, status, percentage): + print 'Route Calculation: ' + str(int(percentage)) + ' %' + if int(percentage) == 100: + #get route overview + overview = g_routing_interface.GetRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])) + #retrieve distance + totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)]) + print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km' + totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]) + m, s = divmod(totalTime[1], 60) + h, m = divmod(m, 60) + print "Total Time: %d:%02d:%02d" % (h, m, s) + #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) + valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME), + dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE), + dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE), + dbus.Int32(GENIVI_NAVIGATIONCORE_TIME), + dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)] + ret = g_routing_interface.GetRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(0),dbus.Array(valuesToReturn),dbus.UInt32(500),dbus.UInt32(0)) + print "Total number of segments: " + str(ret[0]) + #len(ret[1]) is size + #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude +# pdb.set_trace() + route = g_current_route + 1 + if route < routes.length: + launch_route_calculation(route) + else: + for i in range(routes.length): + g_routing_interface.DeleteRoute(dbus.UInt32(g_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data)) + g_session_interface.DeleteSession(dbus.UInt32(g_session_handle)) + +def catchall_session_signals_handler(sessionHandle): + print('Session handle deleted: '+str(sessionHandle)) + if sessionHandle == g_session_handle: + print 'Test PASSED' + else: + print 'Test FAILED' + exit() + +def catchall_route_deleted_signals_handler(routeHandle): + print('Route handle deleted: '+str(routeHandle)) + +bus.add_signal_receiver(catchall_route_calculation_signals_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ + signal_name = "RouteCalculationProgressUpdate") + +bus.add_signal_receiver(catchall_route_deleted_signals_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ + signal_name = "RouteDeleted") + +bus.add_signal_receiver(catchall_session_signals_handler, \ + dbus_interface = "org.genivi.navigation.navigationcore.Session", \ + signal_name = "SessionDeleted") + +#timeout +def timeout(): + print 'Timeout Expired' + print '\nTest FAILED' + exit() + +def exit(): + stopTrigger(test_name) + loop.quit() + +def launch_route_calculation(route): + global g_current_route + global g_route_handle + global g_routing_interface + global g_session_handle + g_current_route = route + print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data + #get route handle + ret = g_routing_interface.CreateRoute(dbus.UInt32(g_session_handle)) + g_route_handle=ret[1] + routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle + print 'Route handle: ' + str(g_route_handle) + start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data + dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data + print 'Calculating route from \ +'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \ +'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')' + #set waypoints + g_routing_interface.SetWaypoints(dbus.UInt32(g_session_handle), \ + dbus.UInt32(g_route_handle), \ + dbus.Boolean(0), \ + dbus.Array([ \ + dbus.Dictionary({dbus.UInt16(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([0,dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.UInt16(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([0,dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \ + dbus.Dictionary({dbus.UInt16(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([0,dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.UInt16(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([0,dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \ + ]) \ + ) + #calculate route + g_routing_interface.CalculateRoute(dbus.UInt32(g_session_handle),dbus.UInt32(g_route_handle)) + +startTrigger(test_name) + +session = bus.get_object('org.genivi.navigation.navigationcore.Session','/org/genivi/navigationcore') +g_session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session') + +#get session handle +ret = g_session_interface.CreateSession(dbus.String("test route calculation")) +g_session_handle=ret[1] +print 'Session handle: ' + str(g_session_handle) + +routing_obj = bus.get_object('org.genivi.navigation.navigationcore.Routing','/org/genivi/navigationcore') +g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigation.navigationcore.Routing') + +g_current_route = 0 +launch_route_calculation(0) + + +#main loop +gobject.timeout_add(TIME_OUT, timeout) +loop = gobject.MainLoop() +loop.run() + + diff --git a/test/navigation/test-address-input-capi.py b/test/navigation/test-address-input-capi.py deleted file mode 100755 index 0d538e6..0000000 --- a/test/navigation/test-address-input-capi.py +++ /dev/null @@ -1,413 +0,0 @@ -#!/usr/bin/python -# -*- coding: latin-1 -*- - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* @copyright Copyright (C) 2014, Alpine Electronics R&D Europe GmbH -* -* @file test-address-input-capi.py -* -* @brief This simple test shows how the location input -* could be easily tested using a python script -* -* @author Stephan Wiehr -* @author Philippe Colliot -* -* @version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -* this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add status handler -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -from xml.dom.minidom import parse -import xml.dom.minidom -import argparse -import sys -import errno -from dltTrigger import * -#import pdb;pdb.set_trace() - -#name of the test -test_name = "address input" - -# constants as defined in the Navigation API -LATITUDE = 0x00a0 -LONGITUDE = 0x00a1 -ALTITUDE = 0x00a2 -FULL_ADDRESS = 0x00b2 -COUNTRY = 0x00a6 -STATE = 0x00a7 -CITY = 0x00a8 -ZIPCODE = 0x00a9 -STREET = 0x00aa -HOUSE_NUMBER = 0x00ab -CROSSING = 0x00ac -DISTRICT = 0x00ad -PHONE_NUMBER = 0x00ae -POI_NAME = 0x00af -TOWN_CENTER = 0x00b0 -FINISHED = 0x00c2 - -# List of addresses -COUNTRY_STRING = list() -CITY_STRING = list() -STREET_STRING = list() -HOUSE_NUMBER_STRING = list() - -# Default size of the list -WINDOW_SIZE = 20 - -print( '\n--------------------------\n' + \ - 'LocationInput Test' + \ - '\n--------------------------\n') - -parser = argparse.ArgumentParser(description='Location input Test for navigation PoC and FSA.') -parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') -parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') -args = parser.parse_args() - -if args.locations == None: - print('location file is missing') - sys.exit(1) -else: - try: - DOMTree = xml.dom.minidom.parse(args.locations) - except OSError as e: - if e.errno == errno.ENOENT: - print('file not exists') - sys.exit(1) - location_set = DOMTree.documentElement - -print("Area : %s" % location_set.getAttribute("area")) - -locations = location_set.getElementsByTagName("location") - -for location in location_set.getElementsByTagName("location"): - COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) - CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) - STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) - #HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) - HOUSE_NUMBER_STRING.append('') #there's a bug in the navigation core when the house number doesn't exist, so deactivated - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -# connect to session bus -bus = dbus.SessionBus() - -def vprint(text): - if args.verbose: - print(text) - -# Turn selection criteria values to their corresponding string description -def selection_criterion_to_string(selection_criterion): - return_value = '' - if selection_criterion == LATITUDE: - return_value += 'Latitude' - elif selection_criterion == LONGITUDE: - return_value += 'Longitude' - elif selection_criterion == COUNTRY: - return_value += 'Country' - elif selection_criterion == STATE: - return_value += 'State' - elif selection_criterion == CITY: - return_value += 'City' - elif selection_criterion == TOWN_CENTER: - return_value += 'City center' - elif selection_criterion == ZIPCODE: - return_value += 'ZipCode' - elif selection_criterion == STREET: - return_value += 'Street' - elif selection_criterion == HOUSE_NUMBER: - return_value += 'House number' - elif selection_criterion == CROSSING: - return_value += 'Crossing' - elif selection_criterion == FULL_ADDRESS: - return_value += 'Full address' - else: - return_value += str(selection_criterion) - - return return_value - - -# Prepare a dictionary array for pretty printing - -def dictionary_array_to_string(dict_array, linefeed, offset=0): - return_value = '' - i = offset - for item in dict_array: - return_value += str(i) + '. ' + unicode(dictionary_to_string(item)) - if i < offset + len(dict_array) - 1: - return_value += linefeed - i += 1 - - return return_value - - -# Prepare a dictionary for pretty printing -# NB: the value is supposed to be [UInt8, Variant], according to the DBus '(yv)', used by CommonAPI -def dictionary_to_string(dictionary): - return_value = '' - i = 0 - for key in dictionary.keys(): - value = dictionary[key][1] - return_value += selection_criterion_to_string(key) + ' = ' + unicode(value) - i += 1 - if i < len(dictionary): - return_value += ', ' - - return return_value - - -# Prepare a selection criteria array for pretty printing - -def selection_criteria_array_to_string(selection_criterion_array): - return_value = '' - i = 0 - for item in selection_criterion_array: - return_value += selection_criterion_to_string(item) - i += 1 - if i < len(selection_criterion_array): - return_value += ', ' - - return return_value - - -def print_current_context(): - vprint('\tACTIVE CONTEXT: selection criterion = ' + selection_criterion_to_string(current_selection_criterion) + \ - ', search string = \'' + entered_search_string + '\'') - - -def change_selection_criterion(selection_criterion): - global current_selection_criterion - - current_selection_criterion = selection_criterion - location_input_interface.setSelectionCriterion(dbus.UInt32(session_handle), dbus.UInt32(location_input_handle), - dbus.Int32(current_selection_criterion)) - - -# Full string search -def full_string_search(handle, search_string): - global entered_search_string - global found_exact_match - - entered_search_string = search_string - found_exact_match = 1 # Force exact match for full string search - vprint('\nACTION: Full string search, selection criterion = ' + \ - selection_criterion_to_string(current_selection_criterion) + ', trying \'' + search_string + '\'') - location_input_interface.search(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.String(search_string), - dbus.UInt16(20)) - - -def evaluate_address(address, guidable): - test_passed = 0 - print ('\nAddress complete!\nEvaluating...') - if COUNTRY_STRING[current_address_index] == '': - test_passed = 1 - elif address[COUNTRY][1] == COUNTRY_STRING[current_address_index]: - print ('Country\t\t\t-> ok (' + address[COUNTRY][1] + ')') - if CITY_STRING[current_address_index] == '': - test_passed = 1 - elif address[CITY][1] == CITY_STRING[current_address_index]: - print ('City\t\t\t-> ok (' + address[CITY][1] + ')') - if STREET_STRING[current_address_index] == '': - test_passed = 1 - elif address[STREET][1] == STREET_STRING[current_address_index]: - print ('Street\t\t\t-> ok (' + address[STREET][1] + ')') - if HOUSE_NUMBER_STRING[current_address_index] == '': - test_passed = 1 - elif address[HOUSE_NUMBER][1] == HOUSE_NUMBER_STRING[current_address_index]: - print ('House number\t-> ok (' + address[HOUSE_NUMBER][1] + ')') - test_passed = 1 - - if guidable == 1: - if test_passed == 1: - print ('TEST PASSED') - else: - print ('TEST FAILED (wrong address)') - exit() - else: - print ('TEST FAILED (non-guidable address)') - exit() - address_index = current_address_index + 1 - if address_index < len(COUNTRY_STRING): - startSearch(address_index) - else: - print('END OF THE TEST') - exit() - - -# Signal receiver - -# Handler for ContentUpdated callback - -def search_status_handler(handle,status): - vprint('\n::Search status ' + str(int(status))) - if status == FINISHED: - location_input_interface.requestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.UInt16(0), - dbus.UInt16(WINDOW_SIZE)) - - -def content_updated_handler(handle, guidable, available_selection_criteria, address): - global target_search_string - global entered_search_string - - vprint('\n::ContentUpdated for LocationInputHandle ' + str(int(handle))) - print_current_context() - vprint('\tGuidable = ' + str(guidable)) - vprint('\tAvailable selection criteria = ' + selection_criteria_array_to_string(available_selection_criteria)) - vprint('\tADDRESS: '+dictionary_to_string(address)) - - if current_selection_criterion == COUNTRY: - change_selection_criterion(CITY) - target_search_string = CITY_STRING[current_address_index] - elif current_selection_criterion == CITY: - change_selection_criterion(STREET) - target_search_string = STREET_STRING[current_address_index] - elif current_selection_criterion == STREET: - change_selection_criterion(HOUSE_NUMBER) - target_search_string = HOUSE_NUMBER_STRING[current_address_index] - elif current_selection_criterion == HOUSE_NUMBER: - target_search_string = '' - - entered_search_string = '' - - if target_search_string == '': - evaluate_address(address, guidable) - else: - full_string_search(handle, target_search_string) - -def search_result_list_handler(handle, total_size, window_offset, window_size, result_list_window): - global spell_next_character - global found_exact_match - - vprint('\n::SearchResultList for LocationInputHandle ' + str(int(handle))) - print_current_context() - vprint('\tTotal size = ' + str(int(total_size)) + ', Window offset = ' + str(int(window_offset)) + \ - ', Window size = ' + str(int(window_size))) - vprint('\t' + dictionary_array_to_string(result_list_window, '\n\t', window_offset)) - - if found_exact_match == 1: - found_exact_match = 0 - i = 0 - for address in result_list_window: - if unicode(address[current_selection_criterion][1]) == target_search_string: - vprint('\nACTION: Found exact match, selecting \''+unicode(address[current_selection_criterion][1]) + \ - '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.selectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(i)) - break - i += 1 - if i == window_size: - vprint('\nACTION: Found exact match, searching in next page (Session '+str(int(session_handle)) +\ - ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.requestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.UInt16(window_offset + window_size), - dbus.UInt16(window_size)) - elif total_size == 1: - selection_name = result_list_window[0][current_selection_criterion] - if selection_name[1] == target_search_string: - vprint('\nACTION: Single entry list, selecting \'' + selection_name[1] + \ - '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.selectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(0)) - else: - print ('\nTEST FAILED (Unexpected single result list)') - exit() - elif spell_next_character == 1: - spell_next_character = 0 - spell_search(handle, entered_search_string, target_search_string, available_characters) - - -# add signal receiver -bus.add_signal_receiver(search_status_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', - signal_name='searchStatus') - -bus.add_signal_receiver(search_result_list_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', - signal_name='searchResultList') - -bus.add_signal_receiver(content_updated_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', - signal_name='contentUpdated') - - -# Timeout -def timeout(): - print('Timeout Expired') - print ('\nTEST FAILED\n') - exit() - -# Exit -def exit(): - error=location_input_interface.deleteLocationInput(dbus.UInt32(session_handle),dbus.UInt32(location_input_handle)) - print('Delete location input: '+str(int(error))) - error=session_interface.deleteSession(dbus.UInt32(session_handle)) - print('Delete session: '+str(int(error))) - stopTrigger(test_name) - loop.quit() - -def startSearch(address_index): - global entered_search_string - global spell_next_character - global found_exact_match - global available_characters - global target_search_string - global current_address_index - current_address_index = address_index - entered_search_string = '' - spell_next_character = 0 - found_exact_match = 0 - available_characters = '' - target_search_string = COUNTRY_STRING[current_address_index] - - change_selection_criterion(COUNTRY) - full_string_search(location_input_handle, target_search_string) - -startTrigger(test_name) - -session = bus.get_object('org.genivi.navigation.navigationcore.Session.v4_0_Session', '/Session') -session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session.v4_0') - -# Get SessionHandle -ret = session_interface.createSession(dbus.String('test location input')) -session_handle=ret[1] -print ('Session handle = ' + str(session_handle)) - -location_input_obj = bus.get_object('org.genivi.navigation.navigationcore.LocationInput.v4_0_LocationInput', '/LocationInput') -location_input_interface = dbus.Interface(location_input_obj, dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0') -# Get LocationInputHandle -ret = location_input_interface.createLocationInput(dbus.UInt32(session_handle)) -location_input_handle = ret[1] -print ('LocationInput handle = ' + str(location_input_handle)) - -attributes = location_input_interface.getSupportedAddressAttributes() -print ('Initially supported address attributes = ' + selection_criteria_array_to_string(attributes)) - -# Configuration -current_address_index = 0 -entered_search_string = '' -spell_next_character = 0 -found_exact_match = 0 -available_characters = '' -target_search_string = '' -current_selection_criterion = 0 - -startSearch(0) - -# Main loop -gobject.timeout_add(10000, timeout) -loop = gobject.MainLoop() -loop.run() diff --git a/test/navigation/test-address-input.py b/test/navigation/test-address-input.py deleted file mode 100755 index e9ab02a..0000000 --- a/test/navigation/test-address-input.py +++ /dev/null @@ -1,409 +0,0 @@ -#!/usr/bin/python -# -*- coding: latin-1 -*- - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* @copyright Copyright (C) 2014, Alpine Electronics R&D Europe GmbH -* -* @file test-address-input.py -* -* @brief This simple test shows how the address input -* could be easily tested using a python script -* -* @author Stephan Wiehr -* @author Philippe Colliot -* -* @version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add status handler -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -from xml.dom.minidom import parse -import xml.dom.minidom -import argparse -import sys -import errno -from dltTrigger import * -#import pdb;pdb.set_trace() - -#name of the test -test_name = "address input" - -# constants as defined in the Navigation API -LATITUDE = 0x00a0 -LONGITUDE = 0x00a1 -ALTITUDE = 0x00a2 -FULL_ADDRESS = 0x00b2 -COUNTRY = 0x00a6 -STATE = 0x00a7 -CITY = 0x00a8 -ZIPCODE = 0x00a9 -STREET = 0x00aa -HOUSE_NUMBER = 0x00ab -CROSSING = 0x00ac -DISTRICT = 0x00ad -PHONE_NUMBER = 0x00ae -POI_NAME = 0x00af -TOWN_CENTER = 0x00b0 -FINISHED = 0x00c2 - -# List of addresses -COUNTRY_STRING = list() -CITY_STRING = list() -STREET_STRING = list() -HOUSE_NUMBER_STRING = list() - -# Default size of the list -WINDOW_SIZE = 20 - -print '\n--------------------------\n' + \ - 'LocationInput Test' + \ - '\n--------------------------\n' - -parser = argparse.ArgumentParser(description='Location input Test for navigation PoC and FSA.') -parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') -parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') -args = parser.parse_args() - -if args.locations == None: - print('location file is missing') - sys.exit(1) -else: - try: - DOMTree = xml.dom.minidom.parse(args.locations) - except OSError as e: - if e.errno == errno.ENOENT: - print('file not exists') - sys.exit(1) - location_set = DOMTree.documentElement - -print("Area : %s" % location_set.getAttribute("area")) - -locations = location_set.getElementsByTagName("location") - -for location in location_set.getElementsByTagName("location"): - COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) - CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) - STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) - #HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) - HOUSE_NUMBER_STRING.append('') #there's a bug in the navigation core when the house number doesn't exist, so deactivated - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -# connect to session bus -bus = dbus.SessionBus() - -def vprint(text): - if args.verbose: - print(text) - -# Turn selection criteria values to their corresponding string description -def selection_criterion_to_string(selection_criterion): - return_value = '' - if selection_criterion == LATITUDE: - return_value += 'Latitude' - elif selection_criterion == LONGITUDE: - return_value += 'Longitude' - elif selection_criterion == COUNTRY: - return_value += 'Country' - elif selection_criterion == STATE: - return_value += 'State' - elif selection_criterion == CITY: - return_value += 'City' - elif selection_criterion == TOWN_CENTER: - return_value += 'City center' - elif selection_criterion == ZIPCODE: - return_value += 'ZipCode' - elif selection_criterion == STREET: - return_value += 'Street' - elif selection_criterion == HOUSE_NUMBER: - return_value += 'House number' - elif selection_criterion == CROSSING: - return_value += 'Crossing' - elif selection_criterion == FULL_ADDRESS: - return_value += 'Full address' - else: - return_value += str(selection_criterion) - - return return_value - - -# Prepare a dictionary array for pretty printing - -def dictionary_array_to_string(dict_array, linefeed, offset=0): - return_value = '' - i = offset - for item in dict_array: - return_value += str(i) + '. ' + unicode(dictionary_to_string(item)) - if i < offset + len(dict_array) - 1: - return_value += linefeed - i += 1 - - return return_value - - -# Prepare a dictionary for pretty printing -# NB: the value is supposed to be [UInt8, Variant], according to the DBus '(yv)', used by CommonAPI -def dictionary_to_string(dictionary): - return_value = '' - i = 0 - for key in dictionary.keys(): - value = dictionary[key][1] - return_value += selection_criterion_to_string(key) + ' = ' + unicode(value) - i += 1 - if i < len(dictionary): - return_value += ', ' - - return return_value - - -# Prepare a selection criteria array for pretty printing - -def selection_criteria_array_to_string(selection_criterion_array): - return_value = '' - i = 0 - for item in selection_criterion_array: - return_value += selection_criterion_to_string(item) - i += 1 - if i < len(selection_criterion_array): - return_value += ', ' - - return return_value - - -def print_current_context(): - vprint('\tACTIVE CONTEXT: selection criterion = ' + selection_criterion_to_string(current_selection_criterion) + \ - ', search string = \'' + entered_search_string + '\'') - - -def change_selection_criterion(selection_criterion): - global current_selection_criterion - - current_selection_criterion = selection_criterion - location_input_interface.SetSelectionCriterion(dbus.UInt32(session_handle), dbus.UInt32(location_input_handle), - dbus.UInt16(current_selection_criterion)) - - -# Full string search -def full_string_search(handle, search_string): - global entered_search_string - global found_exact_match - - entered_search_string = search_string - found_exact_match = 1 # Force exact match for full string search - vprint('\nACTION: Full string search, selection criterion = ' + \ - selection_criterion_to_string(current_selection_criterion) + ', trying \'' + search_string + '\'') - location_input_interface.Search(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.String(search_string), - dbus.UInt16(20)) - - -def evaluate_address(address, guidable): - test_passed = 0 - print '\nAddress complete!\nEvaluating...' - if COUNTRY_STRING[current_address_index] == '': - test_passed = 1 - elif address[COUNTRY][1] == COUNTRY_STRING[current_address_index]: - print 'Country\t\t\t-> ok (' + address[COUNTRY][1] + ')' - if CITY_STRING[current_address_index] == '': - test_passed = 1 - elif address[CITY][1] == CITY_STRING[current_address_index]: - print 'City\t\t\t-> ok (' + address[CITY][1] + ')' - if STREET_STRING[current_address_index] == '': - test_passed = 1 - elif address[STREET][1] == STREET_STRING[current_address_index]: - print 'Street\t\t\t-> ok (' + address[STREET][1] + ')' - if HOUSE_NUMBER_STRING[current_address_index] == '': - test_passed = 1 - elif address[HOUSE_NUMBER][1] == HOUSE_NUMBER_STRING[current_address_index]: - print 'House number\t-> ok (' + address[HOUSE_NUMBER][1] + ')' - test_passed = 1 - - if guidable == 1: - if test_passed == 1: - print 'TEST PASSED' - else: - print 'TEST FAILED (wrong address)' - exit() - else: - print 'TEST FAILED (non-guidable address)' - exit() - address_index = current_address_index + 1 - if address_index < len(COUNTRY_STRING): - startSearch(address_index) - else: - print 'END OF THE TEST' - exit() - - -# Signal receiver - -# Handler for ContentUpdated callback - -def search_status_handler(handle,status): - vprint('\n::Search status ' + str(int(status))) - if status == FINISHED: - location_input_interface.RequestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.UInt16(0), - dbus.UInt16(WINDOW_SIZE)) - - -def content_updated_handler(handle, guidable, available_selection_criteria, address): - global target_search_string - global entered_search_string - - vprint('\n::ContentUpdated for LocationInputHandle ' + str(int(handle))) - print_current_context() - vprint('\tGuidable = ' + str(guidable)) - vprint('\tAvailable selection criteria = ' + selection_criteria_array_to_string(available_selection_criteria)) - vprint('\tADDRESS: '+dictionary_to_string(address)) - - if current_selection_criterion == COUNTRY: - change_selection_criterion(CITY) - target_search_string = CITY_STRING[current_address_index] - elif current_selection_criterion == CITY: - change_selection_criterion(STREET) - target_search_string = STREET_STRING[current_address_index] - elif current_selection_criterion == STREET: - change_selection_criterion(HOUSE_NUMBER) - target_search_string = HOUSE_NUMBER_STRING[current_address_index] - elif current_selection_criterion == HOUSE_NUMBER: - target_search_string = '' - entered_search_string = '' - if target_search_string == '': - evaluate_address(address, guidable) - else: - full_string_search(handle, target_search_string) - -def search_result_list_handler(handle, total_size, window_offset, window_size, result_list_window): - global spell_next_character - global found_exact_match - - vprint('\n::SearchResultList for LocationInputHandle ' + str(int(handle))) - print_current_context() - vprint('\tTotal size = ' + str(int(total_size)) + ', Window offset = ' + str(int(window_offset)) + \ - ', Window size = ' + str(int(window_size))) - vprint('\t' + dictionary_array_to_string(result_list_window, '\n\t', window_offset)) - - if found_exact_match == 1: - found_exact_match = 0 - i = 0 - for address in result_list_window: - if unicode(address[current_selection_criterion][1]) == target_search_string: - vprint('\nACTION: Found exact match, selecting \''+unicode(address[current_selection_criterion][1]) + \ - '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.SelectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(i)) - break - i += 1 - if i == window_size: - vprint('\nACTION: Found exact match, searching in next page (Session '+str(int(session_handle)) +\ - ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.RequestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.UInt16(window_offset + window_size), - dbus.UInt16(window_size)) - elif total_size == 1: - selection_name = result_list_window[0][current_selection_criterion] - if selection_name[1] == target_search_string: - vprint('\nACTION: Single entry list, selecting \'' + selection_name[1] + \ - '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.SelectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(0)) - else: - print '\nTEST FAILED (Unexpected single result list)' - exit() - elif spell_next_character == 1: - spell_next_character = 0 - spell_search(handle, entered_search_string, target_search_string, available_characters) - - -# add signal receiver -bus.add_signal_receiver(search_status_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput', - signal_name='SearchStatus') - -bus.add_signal_receiver(search_result_list_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput', - signal_name='SearchResultList') - -bus.add_signal_receiver(content_updated_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput', - signal_name='ContentUpdated') - - -# Timeout -def timeout(): - print 'Timeout Expired' - print '\nTEST FAILED\n' - exit() - -# Exit -def exit(): - error=location_input_interface.DeleteLocationInput(dbus.UInt32(session_handle),dbus.UInt32(location_input_handle)) - print('Delete location input: '+str(int(error))) - error=session_interface.DeleteSession(dbus.UInt32(session_handle)) - print('Delete session: '+str(int(error))) - stopTrigger(test_name) - loop.quit() - - -def startSearch(address_index): - global found_exact_match - global available_characters - global target_search_string - global current_address_index - current_address_index = address_index - entered_search_string = '' - found_exact_match = 0 - available_characters = '' - target_search_string = COUNTRY_STRING[current_address_index] - - change_selection_criterion(COUNTRY) - full_string_search(location_input_handle, target_search_string) - -startTrigger(test_name) - -session = bus.get_object('org.genivi.navigation.navigationcore.Session', '/org/genivi/navigationcore') -session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session') - -# Get SessionHandle -ret = session_interface.CreateSession(dbus.String('test location input')) -session_handle=ret[1] -print 'Session handle = ' + str(session_handle) - -location_input_obj = bus.get_object('org.genivi.navigation.navigationcore.LocationInput', '/org/genivi/navigationcore') -location_input_interface = dbus.Interface(location_input_obj, dbus_interface='org.genivi.navigation.navigationcore.LocationInput') - -# Get LocationInputHandle -ret = location_input_interface.CreateLocationInput(dbus.UInt32(session_handle)) -location_input_handle = ret[1] -print 'LocationInput handle = ' + str(location_input_handle) - -attributes = location_input_interface.GetSupportedAddressAttributes() -print 'Initially supported address attributes = ' + selection_criteria_array_to_string(attributes) - -# Configuration -current_address_index = 0 -entered_search_string = '' -spell_next_character = 0 -found_exact_match = 0 -available_characters = '' -target_search_string = '' - -startSearch(0) - -# Main loop -gobject.timeout_add(10000, timeout) -loop = gobject.MainLoop() -loop.run() diff --git a/test/navigation/test-all b/test/navigation/test-all deleted file mode 100755 index d2810d7..0000000 --- a/test/navigation/test-all +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -./test-location-input.py -l locations.xml -sleep 2 -./test-route-calculation.py -r routes.xml -sleep 2 -./test-address-input.py -l location.xml -sleep 2 -./test-guidance.py -r route.xml -sleep 2 -./test-map-viewer-control.py -l location.xml diff --git a/test/navigation/test-all-capi b/test/navigation/test-all-capi deleted file mode 100755 index 3e021c8..0000000 --- a/test/navigation/test-all-capi +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -./test-location-input-capi.py -l locations.xml -sleep 2 -./test-route-calculation-capi.py -r routes.xml -sleep 2 -./test-address-input-capi.py -l location.xml -sleep 2 -./test-guidance-capi.py -r route.xml -sleep 2 -./test-map-viewer-control-capi.py - diff --git a/test/navigation/test-all_tokyo b/test/navigation/test-all_tokyo deleted file mode 100755 index 1dce7b4..0000000 --- a/test/navigation/test-all_tokyo +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -./test-location-input.py -l location_tokyo.xml -sleep 2 -./test-route-calculation.py -r route_tokyo.xml -sleep 2 -./test-address-input.py -l location_tokyo.xml -sleep 2 -./test-guidance.py -r route_tokyo.xml -sleep 2 -./test-map-viewer-control.py -l location_tokyo.xml diff --git a/test/navigation/test-guidance-capi.py b/test/navigation/test-guidance-capi.py deleted file mode 100755 index 3e10065..0000000 --- a/test/navigation/test-guidance-capi.py +++ /dev/null @@ -1,341 +0,0 @@ -#!/usr/bin/python - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 2016, XS Embedded GmbH, PCA Peugeot Citroen -* -* \file test-guidance-capi.py -* -* \brief This simple test shows how the guidance -* could be easily tested using a python script -* -* \author Marco Residori -* \author Philippe Colliot -* -* \version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -from collections import namedtuple,defaultdict -from _dbus_bindings import Int32 -from PIL.GimpGradientFile import SEGMENTS -from xml.dom.minidom import parse -import xml.dom.minidom -import argparse -import sys -import errno -import time -from dltTrigger import * -#import pdb; -#pdb.set_trace() - -from pip import locations - -#name of the test -test_name = "guidance" - -#constants as defined in the Navigation API -GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0 -GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1 -GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e -GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f -GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147 -GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141 -GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142 -GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143 -GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144 -GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148 -GENIVI_NAVIGATIONCORE_TIME = 0x0149 -GENIVI_NAVIGATIONCORE_SPEED = 0x00a4 -GENIVI_NAVIGATIONCORE_ACTIVE = 0x0060 - -#constants used into the script -TIME_OUT = 10000 -HORIZONTAL_SIZE = 800 -VERTICAL_SIZE = 480 -MAIN_MAP = 0x0010 -NUMBER_OF_SEGMENTS = 1000 - -#add signal receivers -def routing_routeCalculationProgressUpdate_handler(routeHandle, status, percentage): - print 'Route Calculation: ' + str(int(percentage)) + ' %' - -def routing_routeCalculationSuccessful_handler(routeHandle,unfullfilledPreferences): - global g_guidance_active - print 'Route Calculation Successfull: ' + str(routeHandle) - #get route overview - overview = g_routing_interface.getRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])) - #retrieve distance - totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)]) - print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km' - totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]) - m, s = divmod(totalTime[1], 60) - h, m = divmod(m, 60) - print "Total Time: %d:%02d:%02d" % (h, m, s) - #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) - valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME), - dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE), - dbus.Int32(GENIVI_NAVIGATIONCORE_TIME), - dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)] - numberOfSegments = NUMBER_OF_SEGMENTS - detailLevel = 0 - offset = 0 - ret = g_routing_interface.getRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(detailLevel),dbus.Array(valuesToReturn),dbus.UInt32(numberOfSegments),dbus.UInt32(offset)) - print "Total number of segments: " + str(ret[0]) - #len(ret[1]) is size - #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude - g_guidance_active = True -# pdb.set_trace() -# display_route(routeHandle) - launch_guidance(routeHandle) - -def session_sessionDeleted_handler(sessionHandle): - print('Session handle deleted: '+str(sessionHandle)) - if sessionHandle == g_navigationcore_session_handle: - print 'Test PASSED' - else: - print 'Test FAILED' - exit() - -def routing_routeDeleted_handler(routeHandle): - print('Route handle deleted: '+str(routeHandle)) - -def guidance_guidanceStatusChanged_handler(guidanceStatus,routeHandle): - global g_guidance_active - print('Guidance status changed: '+str(guidanceStatus)) - if guidanceStatus != GENIVI_NAVIGATIONCORE_ACTIVE and g_guidance_active == True: - g_guidance_active = False - route = g_current_route + 1 - if route < routes.length: - launch_route_calculation(route) - else: - for i in range(routes.length): - g_routing_interface.deleteRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data)) - g_navigationcore_session_interface.deleteSession(dbus.UInt32(g_navigationcore_session_handle)) - -def guidance_positionOnRouteChanged_handler(offsetOnRoute): - print "Offset on route: " +str(offsetOnRoute) - ret = g_guidance_interface.getDestinationInformation() - print "Travel time: " +str(ret[1]) - ret = g_guidance_interface.getManeuversList(dbus.UInt16(1),dbus.UInt32(0)) - print "Number of maneuvers: " +str(ret[1]) - print "Next road to turn: " +str(ret[2][0][4]) - g_mapmatchedposition_interface.setSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(False)) - g_guidance_interface.stopGuidance(dbus.UInt32(g_navigationcore_session_handle)) - -def mapmatchedposition_simulationStatusChanged_handler(simulationStatus): - print "Simulation status: " +str(simulationStatus) - -#timeout -def timeout(): - print 'Timeout Expired' - print '\nTest FAILED' - exit() - -def exit(): - stopTrigger(test_name) - loop.quit() - -def display_route(route): - g_mapviewercontrol_interface.displayRoute( \ - dbus.UInt32(g_mapviewer_sessionhandle), \ - dbus.UInt32(g_mapviewer_maphandle), \ - dbus.UInt32(route), \ - dbus.Boolean(True)) - -def launch_guidance(route): - g_mapmatchedposition_interface.setSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(True)) - g_guidance_interface.startGuidance(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(route)) -# g_mapmatchedposition_interface.startSimulation(g_navigationcore_session_handle) - -def launch_route_calculation(route): - global g_current_route - global g_route_handle - global g_routing_interface - global g_navigationcore_session_handle - g_current_route = route - print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data - #get route handle - ret = g_routing_interface.createRoute(dbus.UInt32(g_navigationcore_session_handle)) - g_route_handle=ret[1] - routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle - print 'Route handle: ' + str(g_route_handle) - start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data - dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data - print 'Calculating route from \ -'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \ -'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')' - #set waypoints - waypointDoubleCapiType = 0x03 - g_routing_interface.setWaypoints(dbus.UInt32(g_navigationcore_session_handle), \ - dbus.UInt32(g_route_handle), \ - dbus.Boolean(0), \ - dbus.Array([ \ - dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \ - dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \ - ]) \ - ) - - #calculate route - g_routing_interface.calculateRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(g_route_handle)) - -def createMapView(): - global g_mapviewer_sessionhandle - global g_mapviewer_sessionstatus - global g_mapviewer_sessionlist - global g_mapviewer_maphandle - - #get mapviewer session handle - ret = g_mapviewer_session_interface.createSession(dbus.String('test mapviewer')) - g_mapviewer_sessionhandle=ret[1] - print 'Mapviewer session handle: ' + str(g_mapviewer_sessionhandle) - - g_mapviewer_sessionstatus = g_mapviewer_session_interface.getSessionStatus(dbus.UInt32(g_mapviewer_sessionhandle)); - print 'Mapviewer session status: ' + str(g_mapviewer_sessionstatus) - - g_mapviewer_sessionlist = g_mapviewer_session_interface.getAllSessions(); - print 'Mapviewer active sessions = ' + str(len(g_mapviewer_sessionlist)) - - #get mapviewer handle - ret = g_mapviewercontrol_interface.createMapViewInstance( \ - dbus.UInt32(g_mapviewer_sessionhandle), \ - dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ - dbus.Int32(MAIN_MAP)) - g_mapviewer_maphandle=ret[1] - - print 'MapView handle: ' + str(g_mapviewer_maphandle) - - time.sleep(2) - - print 'Stop following the car position' - g_mapviewercontrol_interface.setFollowCarMode( \ - dbus.UInt32(g_mapviewer_sessionhandle), \ - dbus.UInt32(g_mapviewer_maphandle), \ - dbus.Boolean(False)) - -def deleteMapView(): - g_mapviewercontrol_interface.releaseMapViewInstance( \ - dbus.UInt32(g_mapviewer_sessionhandle), \ - dbus.UInt32(g_mapviewer_maphandle)) - - g_mapviewer_session_interface.deleteSession(g_mapviewer_sessionhandle) - - -print('--------------------------') -print('Guidance Test') -print('--------------------------') - -parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.') -parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format') -args = parser.parse_args() - -if args.routes == None: - print('route file is missing') - sys.exit(1) -else: - try: - DOMTree = xml.dom.minidom.parse(args.routes) - except OSError as e: - if e.errno == errno.ENOENT: - print('file not exists') - sys.exit(1) - route_set = DOMTree.documentElement - -print("Country : %s" % route_set.getAttribute("country")) - -routes = route_set.getElementsByTagName("route") - -#create dictionary with the locations -locations = {} -for location in route_set.getElementsByTagName("location"): - lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data] - locations[location.getAttribute("name")] = lat_long - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -#connect to session bus -bus = dbus.SessionBus() - -bus.add_signal_receiver(routing_routeCalculationProgressUpdate_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ - signal_name = "routeCalculationProgressUpdate") - -bus.add_signal_receiver(routing_routeCalculationSuccessful_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ - signal_name = "routeCalculationSuccessful") - -bus.add_signal_receiver(routing_routeDeleted_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ - signal_name = "routeDeleted") - -bus.add_signal_receiver(session_sessionDeleted_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Session.v4_0", \ - signal_name = "sessionDeleted") - -bus.add_signal_receiver(guidance_guidanceStatusChanged_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Guidance.v4_0", \ - signal_name = "guidanceStatusChanged") - -bus.add_signal_receiver(guidance_positionOnRouteChanged_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Guidance.v4_0", \ - signal_name = "positionOnRouteChanged") - -bus.add_signal_receiver(mapmatchedposition_simulationStatusChanged_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.MapMatchedPosition.v4_0", \ - signal_name = "simulationStatusChanged") - -startTrigger(test_name) - -navigationcore_session_obj = bus.get_object('org.genivi.navigation.navigationcore.Session.v4_0_Session','/Session') -g_navigationcore_session_interface = dbus.Interface(navigationcore_session_obj, dbus_interface='org.genivi.navigation.navigationcore.Session.v4_0') - -routing_obj = bus.get_object('org.genivi.navigation.navigationcore.Routing.v4_0_Routing','/Routing') -g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigation.navigationcore.Routing.v4_0') - -guidance_obj = bus.get_object('org.genivi.navigation.navigationcore.Guidance.v4_0_Guidance','/Guidance') -g_guidance_interface = dbus.Interface(guidance_obj, dbus_interface='org.genivi.navigation.navigationcore.Guidance.v4_0') - -mapviewer_session_obj = bus.get_object('org.genivi.navigation.mapviewer.Session.v4_0_Session','/Session') -g_mapviewer_session_interface = dbus.Interface(mapviewer_session_obj, dbus_interface='org.genivi.navigation.mapviewer.Session.v4_0') - -g_mapviewercontrol_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl.v4_0_MapViewerControl','/MapViewerControl') -g_mapviewercontrol_interface = dbus.Interface(g_mapviewercontrol_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl.v4_0') - -g_mapmatchedposition_obj = bus.get_object('org.genivi.navigation.navigationcore.MapMatchedPosition.v4_0_MapMatchedPosition','/MapMatchedPosition') -g_mapmatchedposition_interface = dbus.Interface(g_mapmatchedposition_obj, dbus_interface='org.genivi.navigation.navigationcore.MapMatchedPosition.v4_0') - -#get navigationcore session handle -ret = g_navigationcore_session_interface.createSession(dbus.String("test guidance")) -g_navigationcore_session_handle=ret[1] -print 'Navigation core session handle: ' + str(g_navigationcore_session_handle) - -#createMapView() - -g_current_route = 0 -g_guidance_active = False -launch_route_calculation(0) - -#main loop -gobject.timeout_add(TIME_OUT, timeout) -loop = gobject.MainLoop() -loop.run() - -#deleteMapView() diff --git a/test/navigation/test-guidance.py b/test/navigation/test-guidance.py deleted file mode 100755 index be44295..0000000 --- a/test/navigation/test-guidance.py +++ /dev/null @@ -1,361 +0,0 @@ -#!/usr/bin/python - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 2016, XS Embedded GmbH, PCA Peugeot Citroen -* -* \file test-guidance.py -* -* \brief This simple test shows how the guidance -* could be easily tested using a python script -* -* \author Marco Residori -* \author Philippe Colliot -* -* \version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -from collections import namedtuple,defaultdict -from _dbus_bindings import Int32 -from PIL.GimpGradientFile import SEGMENTS -from xml.dom.minidom import parse -import xml.dom.minidom -import argparse -import sys -import errno -import time -from dltTrigger import * -#import pdb -#pdb.set_trace() - -from pip import locations - -#name of the test -test_name = "guidance" - -#constants as defined in the Navigation API -GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0 -GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1 -GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e -GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f -GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147 -GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141 -GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142 -GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143 -GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144 -GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148 -GENIVI_NAVIGATIONCORE_TIME = 0x0149 -GENIVI_NAVIGATIONCORE_SPEED = 0x00a4 -GENIVI_NAVIGATIONCORE_ACTIVE = 0x0060 - -#constants used into the script -TIME_OUT = 10000 -HORIZONTAL_SIZE = 800 -VERTICAL_SIZE = 480 -MAIN_MAP = 0x0010 -NUMBER_OF_SEGMENTS = 500 -ZOOM_GUIDANCE = 2 - -#add signal receivers -def routing_routeCalculationProgressUpdate_handler(routeHandle, status, percentage): - print 'Route Calculation: ' + str(int(percentage)) + ' %' - -def routing_routeCalculationSuccessful_handler(routeHandle,unfullfilledPreferences): - global g_guidance_active - print 'Route Calculation Successfull: ' + str(routeHandle) - #get route overview - overview = g_routing_interface.GetRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])) - #retrieve distance - totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)]) - print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km' - totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]) - m, s = divmod(totalTime[1], 60) - h, m = divmod(m, 60) - print "Total Time: %d:%02d:%02d" % (h, m, s) - #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) - valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME), - dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE), - dbus.Int32(GENIVI_NAVIGATIONCORE_TIME), - dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)] - numberOfSegments = NUMBER_OF_SEGMENTS - detailLevel = 0 - offset = 0 - ret = g_routing_interface.GetRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(detailLevel),dbus.Array(valuesToReturn),dbus.UInt32(numberOfSegments),dbus.UInt32(offset)) - print "Total number of segments: " + str(ret[0]) - #len(ret[1]) is size - #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude - g_guidance_active = True -# pdb.set_trace() - display_route(routeHandle) - launch_guidance(routeHandle) - -def session_sessionDeleted_handler(sessionHandle): - print('Session handle deleted: '+str(sessionHandle)) - if sessionHandle == g_navigationcore_session_handle: - print 'Test PASSED' - else: - print 'Test FAILED' - exit() - -def routing_routeDeleted_handler(routeHandle): - print('Route handle deleted: '+str(routeHandle)) - -def guidance_guidanceStatusChanged_handler(guidanceStatus,routeHandle): - global g_guidance_active - print('Guidance status changed: '+str(guidanceStatus)) - if guidanceStatus != GENIVI_NAVIGATIONCORE_ACTIVE and g_guidance_active == True: - g_guidance_active = False - route = g_current_route + 1 - if route < routes.length: - launch_route_calculation(route) - else: - for i in range(routes.length): - g_routing_interface.DeleteRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data)) - g_navigationcore_session_interface.DeleteSession(dbus.UInt32(g_navigationcore_session_handle)) - -def guidance_positionOnRouteChanged_handler(offsetOnRoute): - print "Offset on route: " +str(offsetOnRoute) - -def guidance_maneuverChanged_handler(maneuver): - print "Maneuver: " +str(maneuver) - ret = g_guidance_interface.GetDestinationInformation() - print "Travel time: " +str(ret[1]) - ret = g_guidance_interface.GetManeuversList(dbus.UInt16(10),dbus.UInt32(0)) - print "Number of maneuvers: " +str(ret[1]) - print "Next road to turn: " +str(ret[2][0][4]) - g_mapmatchedposition_interface.SetSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(False)) - g_guidance_interface.StopGuidance(dbus.UInt32(g_navigationcore_session_handle)) - -def mapmatchedposition_simulationStatusChanged_handler(simulationStatus): - print "Simulation status: " +str(simulationStatus) - -#timeout - -def timeout(): - print 'Timeout Expired' - print '\nTest FAILED' - exit() - -def exit(): - stopTrigger(test_name) - loop.quit() - -def display_route(route): - ret = g_routing_interface.GetRouteBoundingBox(dbus.UInt32(g_route_handle)) - g_mapviewercontrol_interface.SetMapViewBoundingBox(dbus.UInt32(g_mapviewer_sessionhandle),dbus.UInt32(g_mapviewer_maphandle),ret) - g_mapviewercontrol_interface.DisplayRoute( \ - dbus.UInt32(g_mapviewer_sessionhandle), \ - dbus.UInt32(g_mapviewer_maphandle), \ - dbus.UInt32(route), \ - dbus.Boolean(True)) - -def launch_guidance(route): - g_mapmatchedposition_interface.SetSimulationMode(dbus.UInt32(g_navigationcore_session_handle),dbus.Boolean(True)) - g_guidance_interface.StartGuidance(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(route)) - g_mapviewercontrol_interface.SetFollowCarMode(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(g_mapviewer_maphandle),True) - g_mapviewercontrol_interface.SetMapViewScale(dbus.UInt32(g_mapviewer_sessionhandle),dbus.UInt32(g_mapviewer_maphandle),ZOOM_GUIDANCE) - g_mapviewercontrol_interface.SetTargetPoint(dbus.UInt32(g_mapviewer_sessionhandle),\ - dbus.UInt32(g_mapviewer_maphandle),\ - dbus.Struct((\ - dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]),\ - dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]),\ - dbus.Double(0)\ - ))) - g_mapmatchedposition_interface.StartSimulation(g_navigationcore_session_handle) - -def launch_route_calculation(route): - global g_current_route - global g_route_handle - global g_routing_interface - global g_navigationcore_session_handle - g_current_route = route - print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data - #get route handle - ret = g_routing_interface.CreateRoute(dbus.UInt32(g_navigationcore_session_handle)) - g_route_handle=ret[1] - routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle - print 'Route handle: ' + str(g_route_handle) - start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data - dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data - print 'Calculating route from \ -'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \ -'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')' - #set waypoints - waypointDoubleCapiType = 0x03 - g_routing_interface.SetWaypoints(dbus.UInt32(g_navigationcore_session_handle), \ - dbus.UInt32(g_route_handle), \ - dbus.Boolean(0), \ - dbus.Array([ \ - dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \ - dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \ - ]) \ - ) - - #calculate route - g_routing_interface.CalculateRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(g_route_handle)) - -def createMapView(): - global g_mapviewer_sessionhandle - global g_mapviewer_sessionstatus - global g_mapviewer_sessionlist - global g_mapviewer_maphandle - - #get mapviewer session handle - ret = g_mapviewer_session_interface.CreateSession(dbus.String('test mapviewer')) - g_mapviewer_sessionhandle=ret[1] - print 'Mapviewer session handle: ' + str(g_mapviewer_sessionhandle) - - g_mapviewer_sessionstatus = g_mapviewer_session_interface.GetSessionStatus(dbus.UInt32(g_mapviewer_sessionhandle)); - print 'Mapviewer session status: ' + str(g_mapviewer_sessionstatus) - - g_mapviewer_sessionlist = g_mapviewer_session_interface.GetAllSessions(); - print 'Mapviewer active sessions = ' + str(len(g_mapviewer_sessionlist)) - - #get mapviewer handle - ret = g_mapviewercontrol_interface.CreateMapViewInstance( \ - dbus.UInt32(g_mapviewer_sessionhandle), \ - dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ - dbus.Int32(MAIN_MAP)) - g_mapviewer_maphandle=ret[1] - - print 'MapView handle: ' + str(g_mapviewer_maphandle) - - time.sleep(2) - - print 'Stop following the car position' - g_mapviewercontrol_interface.SetFollowCarMode( \ - dbus.UInt32(g_mapviewer_sessionhandle), \ - dbus.UInt32(g_mapviewer_maphandle), \ - dbus.Boolean(False)) - -def deleteMapView(): - g_mapviewercontrol_interface.ReleaseMapViewInstance( \ - dbus.UInt32(g_mapviewer_sessionhandle), \ - dbus.UInt32(g_mapviewer_maphandle)) - - g_mapviewer_session_interface.DeleteSession(g_mapviewer_sessionhandle) - - -print('--------------------------') -print('Guidance Test') -print('--------------------------') - -parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.') -parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format') -args = parser.parse_args() - -if args.routes == None: - print('route file is missing') - sys.exit(1) -else: - try: - DOMTree = xml.dom.minidom.parse(args.routes) - except OSError as e: - if e.errno == errno.ENOENT: - print('file not exists') - sys.exit(1) - route_set = DOMTree.documentElement - -print("Country : %s" % route_set.getAttribute("country")) - -routes = route_set.getElementsByTagName("route") - -#create dictionary with the locations -locations = {} -for location in route_set.getElementsByTagName("location"): - lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data] - locations[location.getAttribute("name")] = lat_long - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -#connect to session bus -bus = dbus.SessionBus() - -bus.add_signal_receiver(routing_routeCalculationProgressUpdate_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ - signal_name = "RouteCalculationProgressUpdate") - -bus.add_signal_receiver(routing_routeCalculationSuccessful_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ - signal_name = "RouteCalculationSuccessful") - -bus.add_signal_receiver(routing_routeDeleted_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ - signal_name = "RouteDeleted") - -bus.add_signal_receiver(session_sessionDeleted_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Session", \ - signal_name = "SessionDeleted") - -bus.add_signal_receiver(guidance_guidanceStatusChanged_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Guidance", \ - signal_name = "GuidanceStatusChanged") - -bus.add_signal_receiver(guidance_positionOnRouteChanged_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Guidance", \ - signal_name = "PositionOnRouteChanged") - -bus.add_signal_receiver(guidance_maneuverChanged_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Guidance", \ - signal_name = "ManeuverChanged") - -bus.add_signal_receiver(mapmatchedposition_simulationStatusChanged_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.MapMatchedPosition", \ - signal_name = "SimulationStatusChanged") - -startTrigger(test_name) - -navigationcore_session_obj = bus.get_object('org.genivi.navigation.navigationcore.Session','/org/genivi/navigationcore') -g_navigationcore_session_interface = dbus.Interface(navigationcore_session_obj, dbus_interface='org.genivi.navigation.navigationcore.Session') - -routing_obj = bus.get_object('org.genivi.navigation.navigationcore.Routing','/org/genivi/navigationcore') -g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigation.navigationcore.Routing') - -guidance_obj = bus.get_object('org.genivi.navigation.navigationcore.Guidance','/org/genivi/navigationcore') -g_guidance_interface = dbus.Interface(guidance_obj, dbus_interface='org.genivi.navigation.navigationcore.Guidance') - -mapviewer_session_obj = bus.get_object('org.genivi.navigation.mapviewer.Session','/org/genivi/mapviewer') -g_mapviewer_session_interface = dbus.Interface(mapviewer_session_obj, dbus_interface='org.genivi.navigation.mapviewer.Session') - -g_mapviewercontrol_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl','/org/genivi/mapviewer') -g_mapviewercontrol_interface = dbus.Interface(g_mapviewercontrol_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl') - -g_mapmatchedposition_obj = bus.get_object('org.genivi.navigation.navigationcore.MapMatchedPosition','/org/genivi/navigationcore') -g_mapmatchedposition_interface = dbus.Interface(g_mapmatchedposition_obj, dbus_interface='org.genivi.navigation.navigationcore.MapMatchedPosition') - -#get navigationcore session handle -ret = g_navigationcore_session_handle = g_navigationcore_session_interface.CreateSession(dbus.String("test guidance")) -g_navigationcore_session_handle=ret[1] -print 'Navigation core session handle: ' + str(g_navigationcore_session_handle) - -createMapView() - -g_current_route = 0 -g_guidance_active = False -launch_route_calculation(0) - -#main loop -gobject.timeout_add(TIME_OUT, timeout) -loop = gobject.MainLoop() -loop.run() - -#deleteMapView() diff --git a/test/navigation/test-location-input-capi.py b/test/navigation/test-location-input-capi.py deleted file mode 100755 index 74fd841..0000000 --- a/test/navigation/test-location-input-capi.py +++ /dev/null @@ -1,501 +0,0 @@ -#!/usr/bin/python -# -*- coding: latin-1 -*- - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* @copyright Copyright (C) 2014, Alpine Electronics R&D Europe GmbH -* -* @file test-location-input.py -* -* @brief This simple test shows how the location input -* could be easily tested using a python script -* -* @author Stephan Wiehr -* @author Philippe Colliot -* -* @version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -* this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add status handler -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -from xml.dom.minidom import parse -import xml.dom.minidom -import argparse -import sys -import errno -from dltTrigger import * -#import pdb; -#pdb.set_trace() - -#name of the test -test_name = "location input" - -# constants as defined in the Navigation API -LATITUDE = 0x00a0 -LONGITUDE = 0x00a1 -ALTITUDE = 0x00a2 -FULL_ADDRESS = 0x00b2 -COUNTRY = 0x00a6 -STATE = 0x00a7 -CITY = 0x00a8 -ZIPCODE = 0x00a9 -STREET = 0x00aa -HOUSE_NUMBER = 0x00ab -CROSSING = 0x00ac -DISTRICT = 0x00ad -PHONE_NUMBER = 0x00ae -POI_NAME = 0x00af -TOWN_CENTER = 0x00b0 -FINISHED = 0x00c2 - -# List of addresses -COUNTRY_STRING = list() -CITY_STRING = list() -STREET_STRING = list() -HOUSE_NUMBER_STRING = list() - -# Default size of the list -WINDOW_SIZE = 20 - -# Search mode (0 = Spell, 1 = Full string search) -country_search_mode = 1 -city_search_mode = 0 -street_search_mode = 1 #set to full because of a bug to be fixed in the plug-in -house_number_search_mode = 1 - -print( '\n--------------------------\n' + \ - 'LocationInput Test' + \ - '\n--------------------------\n') - -parser = argparse.ArgumentParser(description='Location input Test for navigation PoC and FSA.') -parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') -parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') -args = parser.parse_args() - -if args.locations == None: - print('location file is missing') - sys.exit(1) -else: - try: - DOMTree = xml.dom.minidom.parse(args.locations) - except OSError as e: - if e.errno == errno.ENOENT: - print('file not exists') - sys.exit(1) - location_set = DOMTree.documentElement - -print("Area : %s" % location_set.getAttribute("area")) - -locations = location_set.getElementsByTagName("location") - -for location in location_set.getElementsByTagName("location"): - COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) - CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) - STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) - #HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) - HOUSE_NUMBER_STRING.append('') #there's a bug in the navigation core when the house number doesn't exist, so deactivated - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -# connect to session bus -bus = dbus.SessionBus() - -def vprint(text): - if args.verbose: - print(text) - -# Turn selection criteria values to their corresponding string description -def selection_criterion_to_string(selection_criterion): - return_value = '' - if selection_criterion == LATITUDE: - return_value += 'Latitude' - elif selection_criterion == LONGITUDE: - return_value += 'Longitude' - elif selection_criterion == COUNTRY: - return_value += 'Country' - elif selection_criterion == STATE: - return_value += 'State' - elif selection_criterion == CITY: - return_value += 'City' - elif selection_criterion == TOWN_CENTER: - return_value += 'City center' - elif selection_criterion == ZIPCODE: - return_value += 'ZipCode' - elif selection_criterion == STREET: - return_value += 'Street' - elif selection_criterion == HOUSE_NUMBER: - return_value += 'House number' - elif selection_criterion == CROSSING: - return_value += 'Crossing' - elif selection_criterion == FULL_ADDRESS: - return_value += 'Full address' - else: - return_value += str(selection_criterion) - - return return_value - - -# Prepare a dictionary array for pretty printing - -def dictionary_array_to_string(dict_array, linefeed, offset=0): - return_value = '' - i = offset - for item in dict_array: - return_value += str(i) + '. ' + unicode(dictionary_to_string(item)) - if i < offset + len(dict_array) - 1: - return_value += linefeed - i += 1 - - return return_value - - -# Prepare a dictionary for pretty printing -# NB: the value is supposed to be [UInt8, Variant], according to the DBus '(yv)', used by CommonAPI -def dictionary_to_string(dictionary): - return_value = '' - i = 0 - for key in dictionary.keys(): - value = dictionary[key][1] - return_value += selection_criterion_to_string(key) + ' = ' + unicode(value) - i += 1 - if i < len(dictionary): - return_value += ', ' - - return return_value - - -# Prepare a selection criteria array for pretty printing - -def selection_criteria_array_to_string(selection_criterion_array): - return_value = '' - i = 0 - for item in selection_criterion_array: - return_value += selection_criterion_to_string(item) - i += 1 - if i < len(selection_criterion_array): - return_value += ', ' - - return return_value - - -def print_current_context(): - vprint('\tACTIVE CONTEXT: selection criterion = ' + selection_criterion_to_string(current_selection_criterion) + \ - ', search string = \'' + entered_search_string + '\'') - - -def change_selection_criterion(selection_criterion): - global current_selection_criterion - - current_selection_criterion = selection_criterion - location_input_interface.setSelectionCriterion(dbus.UInt32(session_handle), dbus.UInt32(location_input_handle), - dbus.Int32(current_selection_criterion)) - - -# Spell search -def spell_search(handle, entered_string, search_string, valid_characters, first=0): - global entered_search_string - - vprint('-> SpellSearch - entered \'' + entered_string + '\' target \'' + search_string + '\'') - - if unicode(search_string) != unicode(entered_string): - found = unicode(search_string).lower().find(unicode(entered_string).lower()) - if found == 0: - is_valid = -1 - if first == 0: - spell_character = search_string[len(entered_string)] - is_valid = valid_characters.find(spell_character) - else: - spell_character='' - is_valid = 0 - if is_valid != -1: - entered_search_string = entered_string + spell_character - vprint('\nACTION: Spell search, selection criterion = ' + \ - selection_criterion_to_string(current_selection_criterion) + ', trying \'' + spell_character + \ - '\'') - location_input_interface.spell(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.String(spell_character), dbus.UInt16(20)) - else: - print ('TEST FAILED (Target character can not be entered)') - exit() - else: - print ('TEST FAILED (Unexpected completion)') - exit() - else: - print ('Full spell match') - - -# Full string search -def full_string_search(handle, search_string): - global entered_search_string - global found_exact_match - - entered_search_string = search_string - found_exact_match = 1 # Force exact match for full string search - vprint('\nACTION: Full string search, selection criterion = ' + \ - selection_criterion_to_string(current_selection_criterion) + ', trying \'' + search_string + '\'') - location_input_interface.search(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.String(search_string), - dbus.UInt16(20)) - - -def evaluate_address(address, guidable): - test_passed = 0 - print ('\nAddress complete!\nEvaluating...') - if COUNTRY_STRING[current_address_index] == '': - test_passed = 1 - elif address[COUNTRY][1] == COUNTRY_STRING[current_address_index]: - print ('Country\t\t\t-> ok (' + address[COUNTRY][1] + ')') - if CITY_STRING[current_address_index] == '': - test_passed = 1 - elif address[CITY][1] == CITY_STRING[current_address_index]: - print ('City\t\t\t-> ok (' + address[CITY][1] + ')') - if STREET_STRING[current_address_index] == '': - test_passed = 1 - elif address[STREET][1] == STREET_STRING[current_address_index]: - print ('Street\t\t\t-> ok (' + address[STREET][1] + ')') - if HOUSE_NUMBER_STRING[current_address_index] == '': - test_passed = 1 - elif address[HOUSE_NUMBER][1] == HOUSE_NUMBER_STRING[current_address_index]: - print ('House number\t-> ok (' + address[HOUSE_NUMBER][1] + ')') - test_passed = 1 - - if guidable == 1: - if test_passed == 1: - print ('TEST PASSED') - else: - print ('TEST FAILED (wrong address)') - exit() - else: - print ('TEST FAILED (non-guidable address)') - exit() - address_index = current_address_index + 1 - if address_index < len(COUNTRY_STRING): - startSearch(address_index) - else: - print('END OF THE TEST') - exit() - - -# Signal receiver - -# Handler for ContentUpdated callback - -def search_status_handler(handle,status): - vprint('\n::Search status ' + str(int(status))) - if status == FINISHED: - location_input_interface.requestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.UInt16(0), - dbus.UInt16(WINDOW_SIZE)) - - -def content_updated_handler(handle, guidable, available_selection_criteria, address): - global target_search_string - global entered_search_string - - vprint('\n::ContentUpdated for LocationInputHandle ' + str(int(handle))) - print_current_context() - vprint('\tGuidable = ' + str(guidable)) - vprint('\tAvailable selection criteria = ' + selection_criteria_array_to_string(available_selection_criteria)) - vprint('\tADDRESS: '+dictionary_to_string(address)) - - search_mode = -1 - - if current_selection_criterion == COUNTRY: - change_selection_criterion(CITY) - target_search_string = CITY_STRING[current_address_index] - search_mode = city_search_mode - elif current_selection_criterion == CITY: - change_selection_criterion(STREET) - target_search_string = STREET_STRING[current_address_index] - search_mode = street_search_mode - elif current_selection_criterion == STREET: - change_selection_criterion(HOUSE_NUMBER) - target_search_string = HOUSE_NUMBER_STRING[current_address_index] - search_mode = house_number_search_mode - elif current_selection_criterion == HOUSE_NUMBER: - target_search_string = '' - - entered_search_string = '' - - if target_search_string == '': - evaluate_address(address, guidable) - elif search_mode == 0: - spell_search(handle, entered_search_string, target_search_string, '', 1) - elif search_mode == 1: - full_string_search(handle, target_search_string) - else: - print ('\nTEST FAILED (Invalid search mode)') - exit() - -# Handler for SpellResult callback -def spell_result_handler(handle, unique_string, valid_characters, full_match): - global entered_search_string - global spell_next_character - global found_exact_match - global available_characters - - vprint('\n::SpellResult for LocationInputHandle '+str(int(handle))) - if unique_string != entered_search_string: - vprint('\tAUTOCOMPLETE: \'' + entered_search_string + '\' -> \'' + unique_string + '\'') - entered_search_string = unique_string - available_characters = valid_characters - print_current_context() - vprint('\tUnique string = \''+unique_string+'\'') - vprint('\tValid Characters = \''+valid_characters+'\'') - vprint('\tFull Match = '+str(full_match)) - - if len(valid_characters) == 1: - if unicode(valid_characters[0]) == u'\x08': - print ('\nTEST FAILED (Dead end spelling)') - exit() - - if unicode(entered_search_string) == unicode(target_search_string): - found_exact_match = 1 - - spell_next_character = 1 - - -# Handler for SearchResultList callback - -def search_result_list_handler(handle, total_size, window_offset, window_size, result_list_window): - global spell_next_character - global found_exact_match - - vprint('\n::SearchResultList for LocationInputHandle ' + str(int(handle))) - print_current_context() - vprint('\tTotal size = ' + str(int(total_size)) + ', Window offset = ' + str(int(window_offset)) + \ - ', Window size = ' + str(int(window_size))) - vprint('\t' + dictionary_array_to_string(result_list_window, '\n\t', window_offset)) - - if found_exact_match == 1: - found_exact_match = 0 - i = 0 - for address in result_list_window: - if unicode(address[current_selection_criterion][1]) == target_search_string: - vprint('\nACTION: Found exact match, selecting \''+unicode(address[current_selection_criterion][1]) + \ - '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.selectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(i)) - break - i += 1 - if i == window_size: - vprint('\nACTION: Found exact match, searching in next page (Session '+str(int(session_handle)) +\ - ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.requestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.UInt16(window_offset + window_size), - dbus.UInt16(window_size)) - elif total_size == 1: - selection_name = result_list_window[0][current_selection_criterion] - if selection_name[1] == target_search_string: - vprint('\nACTION: Single entry list, selecting \'' + selection_name[1] + \ - '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.selectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(0)) - else: - print ('\nTEST FAILED (Unexpected single result list)') - exit() - elif spell_next_character == 1: - spell_next_character = 0 - spell_search(handle, entered_search_string, target_search_string, available_characters) - - -# add signal receiver -bus.add_signal_receiver(search_status_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', - signal_name='searchStatus') - -bus.add_signal_receiver(search_result_list_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', - signal_name='searchResultList') - -bus.add_signal_receiver(spell_result_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', - signal_name='spellResult') - -bus.add_signal_receiver(content_updated_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0', - signal_name='contentUpdated') - - -# Timeout -def timeout(): - print('Timeout Expired') - print ('\nTEST FAILED\n') - exit() - -# Exit -def exit(): - error=location_input_interface.deleteLocationInput(dbus.UInt32(session_handle),dbus.UInt32(location_input_handle)) - print('Delete location input: '+str(int(error))) - error=session_interface.deleteSession(dbus.UInt32(session_handle)) - print('Delete session: '+str(int(error))) - stopTrigger(test_name) - loop.quit() - -def startSearch(address_index): - global entered_search_string - global spell_next_character - global found_exact_match - global available_characters - global target_search_string - global country_search_mode - global current_address_index - current_address_index = address_index - entered_search_string = '' - spell_next_character = 0 - found_exact_match = 0 - available_characters = '' - target_search_string = COUNTRY_STRING[current_address_index] - - change_selection_criterion(COUNTRY) - if country_search_mode == 0: - spell_search(location_input_handle, entered_search_string, target_search_string, available_characters, 1) - elif country_search_mode == 1: - full_string_search(location_input_handle, target_search_string) - -startTrigger(test_name) - -session = bus.get_object('org.genivi.navigation.navigationcore.Session.v4_0_Session', '/Session') -session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session.v4_0') - -# Get SessionHandle -ret = session_interface.createSession(dbus.String('test location input')) -session_handle=ret[1] -print ('Session handle = ' + str(session_handle)) - -location_input_obj = bus.get_object('org.genivi.navigation.navigationcore.LocationInput.v4_0_LocationInput', '/LocationInput') -location_input_interface = dbus.Interface(location_input_obj, dbus_interface='org.genivi.navigation.navigationcore.LocationInput.v4_0') -# Get LocationInputHandle -ret = location_input_interface.createLocationInput(dbus.UInt32(session_handle)) -location_input_handle = ret[1] -print ('LocationInput handle = ' + str(location_input_handle)) - -attributes = location_input_interface.getSupportedAddressAttributes() -print ('Initially supported address attributes = ' + selection_criteria_array_to_string(attributes)) - -# Configuration -current_address_index = 0 -entered_search_string = '' -spell_next_character = 0 -found_exact_match = 0 -available_characters = '' -target_search_string = '' -current_selection_criterion = 0 - -startSearch(0) - -# Main loop -gobject.timeout_add(10000, timeout) -loop = gobject.MainLoop() -loop.run() diff --git a/test/navigation/test-location-input.py b/test/navigation/test-location-input.py deleted file mode 100755 index 935c1f9..0000000 --- a/test/navigation/test-location-input.py +++ /dev/null @@ -1,499 +0,0 @@ -#!/usr/bin/python -# -*- coding: latin-1 -*- - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* @copyright Copyright (C) 2014, Alpine Electronics R&D Europe GmbH -* -* @file test-location-input.py -* -* @brief This simple test shows how the location input -* could be easily tested using a python script -* -* @author Stephan Wiehr -* @author Philippe Colliot -* -* @version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add status handler -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -from xml.dom.minidom import parse -import xml.dom.minidom -import argparse -import sys -import errno -from dltTrigger import * -#import pdb;pdb.set_trace() - -#name of the test -test_name = "location input" - -# constants as defined in the Navigation API -LATITUDE = 0x00a0 -LONGITUDE = 0x00a1 -ALTITUDE = 0x00a2 -FULL_ADDRESS = 0x00b2 -COUNTRY = 0x00a6 -STATE = 0x00a7 -CITY = 0x00a8 -ZIPCODE = 0x00a9 -STREET = 0x00aa -HOUSE_NUMBER = 0x00ab -CROSSING = 0x00ac -DISTRICT = 0x00ad -PHONE_NUMBER = 0x00ae -POI_NAME = 0x00af -TOWN_CENTER = 0x00b0 -FINISHED = 0x00c2 - -# List of addresses -COUNTRY_STRING = list() -CITY_STRING = list() -STREET_STRING = list() -HOUSE_NUMBER_STRING = list() - -# Default size of the list -WINDOW_SIZE = 20 - -# Search mode (0 = Spell, 1 = Full string search) -country_search_mode = 1 -city_search_mode = 0 -street_search_mode = 1 #set to full because of a bug to be fixed in the plug-in -house_number_search_mode = 1 - -print '\n--------------------------\n' + \ - 'LocationInput Test' + \ - '\n--------------------------\n' - -parser = argparse.ArgumentParser(description='Location input Test for navigation PoC and FSA.') -parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') -parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') -args = parser.parse_args() - -if args.locations == None: - print('location file is missing') - sys.exit(1) -else: - try: - DOMTree = xml.dom.minidom.parse(args.locations) - except OSError as e: - if e.errno == errno.ENOENT: - print('file not exists') - sys.exit(1) - location_set = DOMTree.documentElement - -print("Area : %s" % location_set.getAttribute("area")) - -locations = location_set.getElementsByTagName("location") - -for location in location_set.getElementsByTagName("location"): - COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) - CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) - STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) - #HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) - HOUSE_NUMBER_STRING.append('') #there's a bug in the navigation core when the house number doesn't exist, so deactivated - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -# connect to session bus -bus = dbus.SessionBus() - -def vprint(text): - if args.verbose: - print(text) - -# Turn selection criteria values to their corresponding string description -def selection_criterion_to_string(selection_criterion): - return_value = '' - if selection_criterion == LATITUDE: - return_value += 'Latitude' - elif selection_criterion == LONGITUDE: - return_value += 'Longitude' - elif selection_criterion == COUNTRY: - return_value += 'Country' - elif selection_criterion == STATE: - return_value += 'State' - elif selection_criterion == CITY: - return_value += 'City' - elif selection_criterion == TOWN_CENTER: - return_value += 'City center' - elif selection_criterion == ZIPCODE: - return_value += 'ZipCode' - elif selection_criterion == STREET: - return_value += 'Street' - elif selection_criterion == HOUSE_NUMBER: - return_value += 'House number' - elif selection_criterion == CROSSING: - return_value += 'Crossing' - elif selection_criterion == FULL_ADDRESS: - return_value += 'Full address' - else: - return_value += str(selection_criterion) - - return return_value - - -# Prepare a dictionary array for pretty printing - -def dictionary_array_to_string(dict_array, linefeed, offset=0): - return_value = '' - i = offset - for item in dict_array: - return_value += str(i) + '. ' + unicode(dictionary_to_string(item)) - if i < offset + len(dict_array) - 1: - return_value += linefeed - i += 1 - - return return_value - - -# Prepare a dictionary for pretty printing -# NB: the value is supposed to be [UInt8, Variant], according to the DBus '(yv)', used by CommonAPI -def dictionary_to_string(dictionary): - return_value = '' - i = 0 - for key in dictionary.keys(): - value = dictionary[key][1] - return_value += selection_criterion_to_string(key) + ' = ' + unicode(value) - i += 1 - if i < len(dictionary): - return_value += ', ' - - return return_value - - -# Prepare a selection criteria array for pretty printing - -def selection_criteria_array_to_string(selection_criterion_array): - return_value = '' - i = 0 - for item in selection_criterion_array: - return_value += selection_criterion_to_string(item) - i += 1 - if i < len(selection_criterion_array): - return_value += ', ' - - return return_value - - -def print_current_context(): - vprint('\tACTIVE CONTEXT: selection criterion = ' + selection_criterion_to_string(current_selection_criterion) + \ - ', search string = \'' + entered_search_string + '\'') - - -def change_selection_criterion(selection_criterion): - global current_selection_criterion - - current_selection_criterion = selection_criterion - location_input_interface.SetSelectionCriterion(dbus.UInt32(session_handle), dbus.UInt32(location_input_handle), - dbus.UInt16(current_selection_criterion)) - - -# Spell search -def spell_search(handle, entered_string, search_string, valid_characters, first=0): - global entered_search_string - - vprint('-> SpellSearch - entered \'' + entered_string + '\' target \'' + search_string + '\'') - - if unicode(search_string) != unicode(entered_string): - found = unicode(search_string).lower().find(unicode(entered_string).lower()) - if found == 0: - is_valid = -1 - if first == 0: - spell_character = search_string[len(entered_string)] - is_valid = valid_characters.find(spell_character) - else: - spell_character='' - is_valid = 0 - if is_valid != -1: - entered_search_string = entered_string + spell_character - vprint('\nACTION: Spell search, selection criterion = ' + \ - selection_criterion_to_string(current_selection_criterion) + ', trying \'' + spell_character + \ - '\'') - location_input_interface.Spell(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.String(spell_character), dbus.UInt16(20)) - else: - print 'TEST FAILED (Target character can not be entered)' - exit() - else: - print 'TEST FAILED (Unexpected completion)' - exit() - else: - print 'Full spell match' - - -# Full string search -def full_string_search(handle, search_string): - global entered_search_string - global found_exact_match - - entered_search_string = search_string - found_exact_match = 1 # Force exact match for full string search - vprint('\nACTION: Full string search, selection criterion = ' + \ - selection_criterion_to_string(current_selection_criterion) + ', trying \'' + search_string + '\'') - location_input_interface.Search(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.String(search_string), - dbus.UInt16(20)) - - -def evaluate_address(address, guidable): - test_passed = 0 - print '\nAddress complete!\nEvaluating...' - if COUNTRY_STRING[current_address_index] == '': - test_passed = 1 - elif address[COUNTRY][1] == COUNTRY_STRING[current_address_index]: - print 'Country\t\t\t-> ok (' + address[COUNTRY][1] + ')' - if CITY_STRING[current_address_index] == '': - test_passed = 1 - elif address[CITY][1] == CITY_STRING[current_address_index]: - print 'City\t\t\t-> ok (' + address[CITY][1] + ')' - if STREET_STRING[current_address_index] == '': - test_passed = 1 - elif address[STREET][1] == STREET_STRING[current_address_index]: - print 'Street\t\t\t-> ok (' + address[STREET][1] + ')' - if HOUSE_NUMBER_STRING[current_address_index] == '': - test_passed = 1 - elif address[HOUSE_NUMBER][1] == HOUSE_NUMBER_STRING[current_address_index]: - print 'House number\t-> ok (' + address[HOUSE_NUMBER][1] + ')' - test_passed = 1 - - if guidable == 1: - if test_passed == 1: - print 'TEST PASSED' - else: - print 'TEST FAILED (wrong address)' - exit() - else: - print 'TEST FAILED (non-guidable address)' - exit() - address_index = current_address_index + 1 - if address_index < len(COUNTRY_STRING): - startSearch(address_index) - else: - print 'END OF THE TEST' - exit() - - -# Signal receiver - -# Handler for ContentUpdated callback - -def search_status_handler(handle,status): - vprint('\n::Search status ' + str(int(status))) - if status == FINISHED: - location_input_interface.RequestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.UInt16(0), - dbus.UInt16(WINDOW_SIZE)) - - -def content_updated_handler(handle, guidable, available_selection_criteria, address): - global target_search_string - global entered_search_string - - vprint('\n::ContentUpdated for LocationInputHandle ' + str(int(handle))) - print_current_context() - vprint('\tGuidable = ' + str(guidable)) - vprint('\tAvailable selection criteria = ' + selection_criteria_array_to_string(available_selection_criteria)) - vprint('\tADDRESS: '+dictionary_to_string(address)) - - search_mode = -1 - - if current_selection_criterion == COUNTRY: - change_selection_criterion(CITY) - target_search_string = CITY_STRING[current_address_index] - search_mode = city_search_mode - elif current_selection_criterion == CITY: - change_selection_criterion(STREET) - target_search_string = STREET_STRING[current_address_index] - search_mode = street_search_mode - elif current_selection_criterion == STREET: - change_selection_criterion(HOUSE_NUMBER) - target_search_string = HOUSE_NUMBER_STRING[current_address_index] - search_mode = house_number_search_mode - elif current_selection_criterion == HOUSE_NUMBER: - target_search_string = '' - - entered_search_string = '' - - if target_search_string == '': - evaluate_address(address, guidable) - elif search_mode == 0: - spell_search(handle, entered_search_string, target_search_string, '', 1) - elif search_mode == 1: - full_string_search(handle, target_search_string) - else: - print '\nTEST FAILED (Invalid search mode)' - exit() - -# Handler for SpellResult callback -def spell_result_handler(handle, unique_string, valid_characters, full_match): - global entered_search_string - global spell_next_character - global found_exact_match - global available_characters - - vprint('\n::SpellResult for LocationInputHandle '+str(int(handle))) - if unique_string != entered_search_string: - vprint('\tAUTOCOMPLETE: \'' + entered_search_string + '\' -> \'' + unique_string + '\'') - entered_search_string = unique_string - available_characters = valid_characters - print_current_context() - vprint('\tUnique string = \''+unique_string+'\'') - vprint('\tValid Characters = \''+valid_characters+'\'') - vprint('\tFull Match = '+str(full_match)) - - if len(valid_characters) == 1: - if unicode(valid_characters[0]) == u'\x08': - print '\nTEST FAILED (Dead end spelling)' - exit() - - if unicode(entered_search_string) == unicode(target_search_string): - found_exact_match = 1 - - spell_next_character = 1 - - -# Handler for SearchResultList callback - -def search_result_list_handler(handle, total_size, window_offset, window_size, result_list_window): - global spell_next_character - global found_exact_match - - vprint('\n::SearchResultList for LocationInputHandle ' + str(int(handle))) - print_current_context() - vprint('\tTotal size = ' + str(int(total_size)) + ', Window offset = ' + str(int(window_offset)) + \ - ', Window size = ' + str(int(window_size))) - vprint('\t' + dictionary_array_to_string(result_list_window, '\n\t', window_offset)) - - if found_exact_match == 1: - found_exact_match = 0 - i = 0 - for address in result_list_window: - if unicode(address[current_selection_criterion][1]) == target_search_string: - vprint('\nACTION: Found exact match, selecting \''+unicode(address[current_selection_criterion][1]) + \ - '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.SelectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(i)) - break - i += 1 - if i == window_size: - vprint('\nACTION: Found exact match, searching in next page (Session '+str(int(session_handle)) +\ - ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.RequestListUpdate(dbus.UInt32(session_handle), dbus.UInt32(handle), - dbus.UInt16(window_offset + window_size), - dbus.UInt16(window_size)) - elif total_size == 1: - selection_name = result_list_window[0][current_selection_criterion] - if selection_name[1] == target_search_string: - vprint('\nACTION: Single entry list, selecting \'' + selection_name[1] + \ - '\' (Session '+str(int(session_handle)) + ' LocationInputHandle ' + str(int(handle))+')') - location_input_interface.SelectEntry(dbus.UInt32(session_handle), dbus.UInt32(handle), dbus.UInt16(0)) - else: - print '\nTEST FAILED (Unexpected single result list)' - exit() - elif spell_next_character == 1: - spell_next_character = 0 - spell_search(handle, entered_search_string, target_search_string, available_characters) - - -# add signal receiver -bus.add_signal_receiver(search_status_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput', - signal_name='SearchStatus') - -bus.add_signal_receiver(search_result_list_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput', - signal_name='SearchResultList') - -bus.add_signal_receiver(spell_result_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput', - signal_name='SpellResult') - -bus.add_signal_receiver(content_updated_handler, - dbus_interface='org.genivi.navigation.navigationcore.LocationInput', - signal_name='ContentUpdated') - - -# Timeout -def timeout(): - print 'Timeout Expired' - print '\nTEST FAILED\n' - exit() - -def exit(): - error=location_input_interface.DeleteLocationInput(dbus.UInt32(session_handle),dbus.UInt32(location_input_handle)) - print('Delete location input: '+str(int(error))) - error=session_interface.DeleteSession(dbus.UInt32(session_handle)) - print('Delete session: '+str(int(error))) - stopTrigger(test_name) - loop.quit() - -def startSearch(address_index): - global entered_search_string - global spell_next_character - global found_exact_match - global available_characters - global target_search_string - global country_search_mode - global current_address_index - current_address_index = address_index - entered_search_string = '' - spell_next_character = 0 - found_exact_match = 0 - available_characters = '' - target_search_string = COUNTRY_STRING[current_address_index] - - change_selection_criterion(COUNTRY) - if country_search_mode == 0: - spell_search(location_input_handle, entered_search_string, target_search_string, available_characters, 1) - elif country_search_mode == 1: - full_string_search(location_input_handle, target_search_string) - -startTrigger(test_name) - -session = bus.get_object('org.genivi.navigation.navigationcore.Session', '/org/genivi/navigationcore') -session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session') - -# Get SessionHandle -ret = session_interface.CreateSession(dbus.String('test location input')) -session_handle=ret[1] -print 'Session handle = ' + str(session_handle) - -location_input_obj = bus.get_object('org.genivi.navigation.navigationcore.LocationInput', '/org/genivi/navigationcore') -location_input_interface = dbus.Interface(location_input_obj, dbus_interface='org.genivi.navigation.navigationcore.LocationInput') - -# Get LocationInputHandle -ret = location_input_interface.CreateLocationInput(dbus.UInt32(session_handle)) -location_input_handle = ret[1] -print 'LocationInput handle = ' + str(location_input_handle) - -attributes = location_input_interface.GetSupportedAddressAttributes() -print 'Initially supported address attributes = ' + selection_criteria_array_to_string(attributes) - -# Configuration -current_address_index = 0 -entered_search_string = '' -spell_next_character = 0 -found_exact_match = 0 -available_characters = '' -target_search_string = '' - -startSearch(0) - -# Main loop -gobject.timeout_add(10000, timeout) -loop = gobject.MainLoop() -loop.run() diff --git a/test/navigation/test-map-viewer-control-capi.py b/test/navigation/test-map-viewer-control-capi.py deleted file mode 100755 index 47da06d..0000000 --- a/test/navigation/test-map-viewer-control-capi.py +++ /dev/null @@ -1,192 +0,0 @@ -#!/usr/bin/python - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 2015, Mentor Graphics -* -* \file test-map-viewer-control.py -* -* \brief This simple test shows how the mapviewer -* could be easily tested using a python script -* -* \author Marco Residori -* \author Philippe Colliot -* -* \version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add some methods -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -import time -from dltTrigger import * -#import pdb -#pdb.set_trace() - -#name of the test -test_name = "map viewer" - -#constants as defined in the Navigation API -LATITUDE = 0x00a0 -LONGITUDE = 0x00a1 - -MAIN_MAP = 0x0010 -SPLIT_SCREEN = 0x0011 - -#constants used by the script -HORIZONTAL_SIZE = 800 -VERTICAL_SIZE = 480 -TIME_OUT = 10000 -MIN_SCALE = 0 -MAX_SCALE = 21 - -def mapviewer_mapViewScaleChanged_handler(mapViewInstanceHandle,scale,isMinMax): - global g_scale - new_scale=int(scale) - print("Scale: "+str(new_scale)) - print('Is min max: '+str(int(isMinMax))) - time.sleep(0.25) - if g_scale > new_scale and new_scale !=MIN_SCALE: - print("Zoom in") - g_scale=new_scale - MapViewerControl_interface.setMapViewScaleByDelta( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle), \ - dbus.Int16(1)) - else: - if new_scale < MAX_SCALE: - print("Zoom out") - g_scale=new_scale - MapViewerControl_interface.setMapViewScaleByDelta( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle), \ - dbus.Int16(-1)) - else: - print 'Test PASSED' - MapViewerControl_interface.releaseMapViewInstance( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle)) - session_interface.deleteSession(sessionhandle) - exit() - -#timeout -def timeout(): - print 'Timeout Expired' - print '\nTest FAILED' - exit() - -def exit(): - stopTrigger(test_name) - loop.quit() - -print '\n--------------------------' -print 'MapViewerControl Test' -print '--------------------------\n' - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -#connect to session bus -bus = dbus.SessionBus() - -bus.add_signal_receiver(mapviewer_mapViewScaleChanged_handler, \ - dbus_interface = "org.genivi.navigation.mapviewer.MapViewerControl.v4_0", \ - signal_name = "mapViewScaleChanged") - -startTrigger(test_name) - -session = bus.get_object('org.genivi.navigation.mapviewer.Session.v4_0_Session','/Session') -session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.mapviewer.Session.v4_0') - -#get session handle -ret = session_interface.createSession(dbus.String('test mapviewer')) -sessionhandle=ret[1] -print 'Session handle: ' + str(sessionhandle) - -sessionstatus = session_interface.getSessionStatus(dbus.UInt32(sessionhandle)); -print 'Session status: ' + str(sessionstatus) - -sessionlist = session_interface.getAllSessions(); -print 'Active sessions = ' + str(len(sessionlist)) - -MapViewerControl_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl.v4_0_MapViewerControl','/MapViewerControl') -MapViewerControl_interface = dbus.Interface(MapViewerControl_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl.v4_0') - -#get mapviewer handle -ret = MapViewerControl_interface.createMapViewInstance( \ - dbus.UInt32(sessionhandle), \ - dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ - dbus.Int32(MAIN_MAP)) -mapviewerhandle=ret[1] - -print 'MapView handle: ' + str(mapviewerhandle) - -# Bern -lat1 = 46.9479 -lon1 = 7.4446 -alt1 = 0 - -time.sleep(2) - -print 'Stop following the car position' -MapViewerControl_interface.setFollowCarMode( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle), \ - dbus.Boolean(False)) - -print 'Set center in Bern(' + str(lat1) + ',' + str(lon1) + ')' -MapViewerControl_interface.setTargetPoint( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle), \ - dbus.Struct((dbus.Double(lat1),dbus.Double(lon1),dbus.Double(alt1)))) - -# Get current position -targetPoint = MapViewerControl_interface.getTargetPoint( \ - dbus.UInt32(mapviewerhandle) ) - -lat2 = targetPoint[0] -lon2 = targetPoint[1] -alt2 = targetPoint[2] - -print 'Get center -> (' + str(lat2) + ',' + str(lon2) + ')' - -if round(lat1,4) != round(lat2,4) : - print '\nTest Failed:' + str(round(lat1,4)) + '!=' + str(round(lat2,4)) + '\n' - -if round(lon1,4) != round(lon2,4) : - print '\nTest Failed:' + str(round(lon1,4)) + '!=' + str(round(lon2,4)) + '\n' - -if round(alt1,4) != round(alt2,4) : - print '\nTest Failed:' + str(round(alt1,4)) + '!=' + str(round(alt2,4)) + '\n' - -ret=MapViewerControl_interface.getMapViewScale(dbus.UInt32(mapviewerhandle)) -print('Scale: '+str(int(ret[0]))) -print('Is min max: '+str(int(ret[1]))) - -g_scale=int(ret[0]) - -time.sleep(0.25) - -print 'Zoom in' -MapViewerControl_interface.setMapViewScaleByDelta(dbus.UInt32(sessionhandle), dbus.UInt32(mapviewerhandle), dbus.Int16(1)) - -#main loop -gobject.timeout_add(TIME_OUT, timeout) -loop = gobject.MainLoop() -loop.run() - - - - diff --git a/test/navigation/test-map-viewer-control.py b/test/navigation/test-map-viewer-control.py deleted file mode 100755 index 253b2f4..0000000 --- a/test/navigation/test-map-viewer-control.py +++ /dev/null @@ -1,236 +0,0 @@ -#!/usr/bin/python - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 2015, Mentor Graphics -* -* \file test-map-viewer-control.py -* -* \brief This simple test shows how the mapviewer -* could be easily tested using a python script -* -* \author Marco Residori -* \author Philippe Colliot -* -* \version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants), add some methods -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -import time -from dltTrigger import * -from xml.dom.minidom import parse -import xml.dom.minidom -import argparse -import sys -import errno -#import pdb; pdb.set_trace() - -#name of the test -test_name = "map viewer" - -#constants as defined in the Navigation API -LATITUDE = 0x00a0 -LONGITUDE = 0x00a1 -MAPVIEWER_MAX = 0x0041 -MAPVIEWER_MIN = 0x0040 - -MAIN_MAP = 0x0010 -SPLIT_SCREEN = 0x0011 - -#constants used by the script -HORIZONTAL_SIZE = 800 -VERTICAL_SIZE = 480 -TIME_OUT = 20000 - -# List of coordinates -LATITUDE = list() -LONGITUDE = list() -ALTITUDE = list() -COUNTRY_STRING = list() -CITY_STRING = list() -STREET_STRING = list() -HOUSE_NUMBER_STRING = list() - -def mapviewer_mapViewScaleChanged_handler(mapViewInstanceHandle,scale,isMinMax): - global g_scale - new_scale=int(scale) - print("Scale: "+str(new_scale)) - print('Is min max: '+str(int(isMinMax))) - time.sleep(0.25) - if g_scale > new_scale and isMinMax !=MAPVIEWER_MIN: - print("Zoom in") - g_scale=new_scale - MapViewerControl_interface.SetMapViewScaleByDelta( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle), \ - dbus.Int16(-1)) - else: - if isMinMax !=MAPVIEWER_MAX: - print("Zoom out") - g_scale=new_scale - MapViewerControl_interface.SetMapViewScaleByDelta( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle), \ - dbus.Int16(1)) - else: - print 'Test PASSED' - MapViewerControl_interface.ReleaseMapViewInstance( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle)) - session_interface.DeleteSession(sessionhandle) - exit() - -#timeout -def timeout(): - print 'Timeout Expired' - print '\nTest FAILED' - exit() - -def exit(): - stopTrigger(test_name) - loop.quit() - -print '\n--------------------------' -print 'MapViewerControl Test' -print '--------------------------\n' - -parser = argparse.ArgumentParser(description='Map Viewer Test for navigation PoC and FSA.') -parser.add_argument('-l','--loc',action='store', dest='locations', help='List of locations in xml format') -parser.add_argument("-v", "--verbose", action='store_true',help='print the whole log messages') -args = parser.parse_args() - -if args.locations == None: - print('location file is missing') - sys.exit(1) -else: - try: - DOMTree = xml.dom.minidom.parse(args.locations) - except OSError as e: - if e.errno == errno.ENOENT: - print('file not exists') - sys.exit(1) - location_set = DOMTree.documentElement - -print("Area : %s" % location_set.getAttribute("area")) - -locations = location_set.getElementsByTagName("location") - -for location in location_set.getElementsByTagName("location"): - LATITUDE.append(location.getElementsByTagName("latitude")[0].childNodes[0].data) - LONGITUDE.append(location.getElementsByTagName("longitude")[0].childNodes[0].data) - ALTITUDE.append(0) - COUNTRY_STRING.append(location.getElementsByTagName("country")[0].childNodes[0].data) - CITY_STRING.append(location.getElementsByTagName("city")[0].childNodes[0].data) - STREET_STRING.append(location.getElementsByTagName("street")[0].childNodes[0].data) - HOUSE_NUMBER_STRING.append(location.getElementsByTagName("number")[0].childNodes[0].data) - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - - -#connect to session bus -bus = dbus.SessionBus() - -bus.add_signal_receiver(mapviewer_mapViewScaleChanged_handler, \ - dbus_interface = "org.genivi.navigation.mapviewer.MapViewerControl", \ - signal_name = "MapViewScaleChanged") - - -startTrigger(test_name) - -session = bus.get_object('org.genivi.navigation.mapviewer.Session','/org/genivi/mapviewer') -session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.mapviewer.Session') - -#get session handle -ret = session_interface.CreateSession(dbus.String("test mapviewer")) -sessionhandle=ret[1] -print 'Session handle: ' + str(sessionhandle) - -sessionstatus = session_interface.GetSessionStatus(dbus.UInt32(sessionhandle)); -print 'Session status: ' + str(sessionstatus) - -sessionlist = session_interface.GetAllSessions(); -print 'Active sessions = ' + str(len(sessionlist)) - -MapViewerControl_obj = bus.get_object('org.genivi.navigation.mapviewer.MapViewerControl','/org/genivi/mapviewer') -MapViewerControl_interface = dbus.Interface(MapViewerControl_obj, dbus_interface='org.genivi.navigation.mapviewer.MapViewerControl') - -#get mapviewer handle -ret = MapViewerControl_interface.CreateMapViewInstance( \ - dbus.UInt32(sessionhandle), \ - dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ - dbus.Int32(MAIN_MAP)) -mapviewerhandle=ret[1] - -print 'MapView handle: ' + str(mapviewerhandle) - -index=0 - -lat1 = LATITUDE[index] -lon1 = LONGITUDE[index] -alt1 = ALTITUDE[index] - -time.sleep(2) - -print 'Stop following the car position' -MapViewerControl_interface.SetFollowCarMode( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle), \ - dbus.Boolean(False)) - -print 'Set center in '+ CITY_STRING[index]+ ' (' + str(lat1) + ',' + str(lon1) + ')' -MapViewerControl_interface.SetTargetPoint( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle), \ - dbus.Struct((dbus.Double(lat1),dbus.Double(lon1),dbus.Double(alt1)))) - -# Get current position -targetPoint = MapViewerControl_interface.GetTargetPoint( \ - dbus.UInt32(mapviewerhandle) ) - -lat2 = targetPoint[0] -lon2 = targetPoint[1] -alt2 = targetPoint[2] - -print 'Get center -> (' + str(lat2) + ',' + str(lon2) + ')' - -if round(float(lat1),4) != round(float(lat2),4) : - print '\nTest Failed:' + str(round(float(lat1),4)) + '!=' + str(round(float(lat2),4)) + '\n' - -if round(float(lon1),4) != round(float(lon2),4) : - print '\nTest Failed:' + str(round(float(lon1),4)) + '!=' + str(round(float(lon2),4)) + '\n' - -if round(float(alt1),4) != round(float(alt2),4) : - print '\nTest Failed:' + str(round(float(alt1),4)) + '!=' + str(round(float(alt2),4)) + '\n' - -ret=MapViewerControl_interface.GetMapViewScale(dbus.UInt32(mapviewerhandle)) -print('Scale: '+str(int(ret[0]))) -print('Is min max: '+str(int(ret[1]))) - -g_scale=int(ret[0]) - -print 'Zoom in' -MapViewerControl_interface.SetMapViewScaleByDelta( \ - dbus.UInt32(sessionhandle), \ - dbus.UInt32(mapviewerhandle), \ - dbus.Int16(-1)) - -#main loop -gobject.timeout_add(TIME_OUT, timeout) -loop = gobject.MainLoop() -loop.run() - diff --git a/test/navigation/test-poi.py b/test/navigation/test-poi.py deleted file mode 100755 index a4b48c7..0000000 --- a/test/navigation/test-poi.py +++ /dev/null @@ -1,177 +0,0 @@ -#!/usr/bin/python - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 2016, PSA GROUP -* -* \file test-poi.py -* -* \brief This simple test shows how the poi search -* could be easily tested using a python script -* -* \author Philippe Colliot -* -* \version 1.0 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -import time - -import pdb; -#pdb.set_trace() -from dltTrigger import * - -#name of the test -test_name = "poi search" - -#constants as defined in the Navigation API -GENIVI_Configuration_Settings_LOCALE = 37 -GENIVI_SearchStatusState_FINISHED = 512 -GENIVI_SearchStatusState_NOT_STARTED = 510 - -#constants used into the script -TIME_OUT = 10000 -LATITUDE_PARIS = 48.8578 -LONGITUDE_PARIS = 2.3380 -ALTITUDE_PARIS = 30.0 -ID_HOTEL = 2 -ID_STATION = 6 -ATTRIBUTE_SOURCE = 0 -ATTRIBUTE_PHONE = 2 -RADIUS_HOTEL = 100 #in tenth of meter ! -RADIUS_STATION = 500 -STRING_TO_SEARCH = "Saint-Germain" - -def catch_poi_configurationChanged_signal_handler(changedSettings): - for changedSetting in changedSettings: - if changedSetting == GENIVI_Configuration_Settings_LOCALE: - ret=g_poiConfiguration_interface.GetLocale() - print("language: " + ret[0]) - print("country: " + ret[1]) - print("script: " + ret[2]) - -def catch_poi_poiStatus_signal_handler(poiSearchHandle,statusValue): - if poiSearchHandle == g_searchHandle: - if statusValue == GENIVI_SearchStatusState_FINISHED: - print("Search finished") - elif statusValue == GENIVI_SearchStatusState_NOT_STARTED: - g_poiSearch_interface.DeletePoiSearchHandle(poiSearchHandle) - print("Test PASSED") - exit() - -def catch_poi_resultListChanged_signal_handler(poiSearchHandle,resultListSize): - poiList=[] - if poiSearchHandle == g_searchHandle and resultListSize != 0: - ret=g_poiSearch_interface.RequestResultList(dbus.UInt32(poiSearchHandle),dbus.UInt16(0),dbus.UInt16(resultListSize),[ATTRIBUTE_SOURCE,ATTRIBUTE_PHONE]) - if ret[0] == GENIVI_SearchStatusState_FINISHED and ret[1] >= 0: - print("Results: "+str(int(ret[1]))) - for result in ret[2]: - poiList.append(result[0]) - ret=g_poiSearch_interface.GetPoiDetails(poiList) - for resultDetail in ret: - if resultDetail[1][0] == ID_HOTEL: - print("Hotel: " +resultDetail[0][1]) - elif resultDetail[1][0] == ID_STATION: - print("Station: " +resultDetail[0][1]) - g_poiSearch_interface.CancelPoiSearch(dbus.UInt32(poiSearchHandle)) - -#timeout -def timeout(): - print ('Timeout Expired') - print ('\nTest FAILED') - exit() - -def exit(): - stopTrigger(test_name) - loop.quit() - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -print("Search for hotel and station with keyword: "+ STRING_TO_SEARCH) - -#connect to session bus -bus = dbus.SessionBus() - -bus.add_signal_receiver(catch_poi_configurationChanged_signal_handler, \ - dbus_interface = "org.genivi.navigation.poiservice.POIConfiguration", \ - signal_name = "ConfigurationChanged") - -bus.add_signal_receiver(catch_poi_poiStatus_signal_handler, \ - dbus_interface = "org.genivi.navigation.poiservice.POISearch", \ - signal_name = "PoiStatus") - -bus.add_signal_receiver(catch_poi_resultListChanged_signal_handler, \ - dbus_interface = "org.genivi.navigation.poiservice.POISearch", \ - signal_name = "ResultListChanged") - -startTrigger(test_name) - -poiConfiguration = bus.get_object('org.genivi.navigation.poiservice.POIConfiguration','/org/genivi/poiservice/POIConfiguration') -g_poiConfiguration_interface = dbus.Interface(poiConfiguration, dbus_interface='org.genivi.navigation.poiservice.POIConfiguration') - -poiContentAccess = bus.get_object('org.genivi.navigation.poiservice.POIContentAccess','/org/genivi/poiservice/POIContentAccess') -g_poiContentAccess_interface = dbus.Interface(poiContentAccess, dbus_interface='org.genivi.navigation.poiservice.POIContentAccess') - -poiSearch = bus.get_object('org.genivi.navigation.poiservice.POISearch','/org/genivi/poiservice/POISearch') -g_poiSearch_interface = dbus.Interface(poiSearch, dbus_interface='org.genivi.navigation.poiservice.POISearch') - -g_poiConfiguration_interface.SetLocale(dbus.String("fra"),dbus.String("FRA"),dbus.String("Latn")) - -categories=[] -ret=g_poiSearch_interface.GetAvailableCategories() -for categoryAndName in ret: - if categoryAndName[0] == ID_HOTEL or categoryAndName[0] == ID_STATION: - print("Category ID: " + str(int(categoryAndName[0]))) - categories.append(categoryAndName[0]) - print("Name: " + categoryAndName[1]) - -attributes_hotel=[] -attributes_station=[] -attributesDetails=[] -ret=g_poiSearch_interface.GetCategoriesDetails(categories) -for results in ret: - if results[0][0] == ID_HOTEL: - for attribute in results[1]: - attributes_hotel.append(attribute[0]) - attributesDetails.append(dbus.Struct([dbus.UInt32(attribute[0]),dbus.UInt32(ID_HOTEL),dbus.Int32(1280),dbus.Struct([dbus.Byte(2),dbus.String("")]),dbus.Int32(1314),dbus.Boolean(False)])) - elif results[0][0] == ID_STATION: - for attribute in results[1]: - attributes_station.append(attribute[0]) - attributesDetails.append(dbus.Struct([dbus.UInt32(attribute[0]),dbus.UInt32(ID_STATION),dbus.Int32(1280),dbus.Struct([dbus.Byte(2),dbus.String("")]),dbus.Int32(1314),dbus.Boolean(False)])) - -ret=g_poiSearch_interface.GetRootCategory() - -g_searchHandle=g_poiSearch_interface.CreatePoiSearchHandle() -print("Search handle: " + str(int(g_searchHandle))) - -lat = LATITUDE_PARIS -lon = LONGITUDE_PARIS -alt = ALTITUDE_PARIS - -g_poiSearch_interface.SetCenter(g_searchHandle,dbus.Struct([lat,lon,alt])) - -g_poiSearch_interface.SetCategories(g_searchHandle,[dbus.Struct([dbus.UInt32(ID_HOTEL),dbus.UInt32(RADIUS_HOTEL)]),dbus.Struct([dbus.UInt32(ID_STATION),dbus.UInt32(RADIUS_STATION)])]) - -g_poiSearch_interface.SetAttributes(g_searchHandle,attributesDetails) - -g_poiSearch_interface.StartPoiSearch(g_searchHandle,dbus.String(STRING_TO_SEARCH),dbus.Int32(1376)) - - -#main loop -gobject.timeout_add(TIME_OUT, timeout) -loop = gobject.MainLoop() -loop.run() diff --git a/test/navigation/test-route-calculation-capi.py b/test/navigation/test-route-calculation-capi.py deleted file mode 100755 index 1c44d10..0000000 --- a/test/navigation/test-route-calculation-capi.py +++ /dev/null @@ -1,222 +0,0 @@ -#!/usr/bin/python - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 2014, XS Embedded GmbH, PCA Peugeot Citroen -* -* \file test-route-calculation-capi.py -* -* \brief This simple test shows how the route calculation -* could be easily tested using a python script -* -* \author Marco Residori -* \author Philippe Colliot -* -* \version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants) -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -from collections import namedtuple,defaultdict -from _dbus_bindings import Int32 -from PIL.GimpGradientFile import SEGMENTS -from xml.dom.minidom import parse -import xml.dom.minidom -import argparse -import sys -import errno -#import pdb; -#pdb.set_trace() -from pip import locations -from dltTrigger import * - -#name of the test -test_name = "route calculation" - -#constants as defined in the Navigation API -GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0 -GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1 -GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e -GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f -GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147 -GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141 -GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142 -GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143 -GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144 -GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148 -GENIVI_NAVIGATIONCORE_TIME = 0x0149 -GENIVI_NAVIGATIONCORE_SPEED = 0x00a4 - -#constants used into the script -TIME_OUT = 10000 - -print('--------------------------') -print('Route Calculation Test') -print('--------------------------') - -parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.') -parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format') -args = parser.parse_args() - -if args.routes == None: - print('route file is missing') - sys.exit(1) -else: - try: - DOMTree = xml.dom.minidom.parse(args.routes) - except OSError as e: - if e.errno == errno.ENOENT: - print('file not exists') - sys.exit(1) - route_set = DOMTree.documentElement - -print("Country : %s" % route_set.getAttribute("country")) - -routes = route_set.getElementsByTagName("route") - -#create dictionary with the locations -locations = {} -for location in route_set.getElementsByTagName("location"): - lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data] - locations[location.getAttribute("name")] = lat_long - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -#connect to session bus -bus = dbus.SessionBus() - -#add signal receivers -def route_calculation_signals_handler(routeHandle, status, percentage): - print 'Route Calculation: ' + str(int(percentage)) + ' %' - if int(percentage) == 100: - #get route overview - overview = g_routing_interface.getRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])) - #retrieve distance - totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)]) - print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km' - totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]) - m, s = divmod(totalTime[1], 60) - h, m = divmod(m, 60) - print "Total Time: %d:%02d:%02d" % (h, m, s) - #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) - valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME), - dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE), - dbus.Int32(GENIVI_NAVIGATIONCORE_TIME), - dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)] - ret = g_routing_interface.getRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(0),dbus.Array(valuesToReturn),dbus.UInt32(500),dbus.UInt32(0)) - print "Total number of segments: " + str(ret[0]) - #len(ret[1]) is size - #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude -# pdb.set_trace() - route = g_current_route + 1 - if route < routes.length: - launch_route_calculation(route) - else: - for i in range(routes.length): - g_routing_interface.deleteRoute(dbus.UInt32(g_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data)) - g_session_interface.deleteSession(dbus.UInt32(g_session_handle)) - -def session_signals_handler(sessionHandle): - print('Session handle deleted: '+str(sessionHandle)) - if sessionHandle == g_session_handle: - print 'Test PASSED' - else: - print 'Test FAILED' - exit() - -def route_deleted_signals_handler(routeHandle): - print('Route handle deleted: '+str(routeHandle)) - -bus.add_signal_receiver(route_calculation_signals_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ - signal_name = "routeCalculationProgressUpdate") - -bus.add_signal_receiver(route_deleted_signals_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing.v4_0", \ - signal_name = "routeDeleted") - -bus.add_signal_receiver(session_signals_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Session.v4_0", \ - signal_name = "sessionDeleted") - -#timeout -def timeout(): - print 'Timeout Expired' - print '\nTest FAILED' - exit() - -def exit(): - stopTrigger(test_name) - loop.quit() - -def launch_route_calculation(route): - global g_current_route - global g_route_handle - global g_routing_interface - global g_session_handle - g_current_route = route - print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data - #get route handle - ret = g_routing_interface.createRoute(dbus.UInt32(g_session_handle)) - g_route_handle=ret[1] - routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle - print 'Route handle: ' + str(g_route_handle) - start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data - dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data - print 'Calculating route from \ -'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \ -'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')' - #set waypoints - waypointDoubleCapiType = 0x03 - g_routing_interface.setWaypoints(dbus.UInt32(g_session_handle), \ - dbus.UInt32(g_route_handle), \ - dbus.Boolean(0), \ - dbus.Array([ \ - dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \ - dbus.Dictionary({dbus.Int32(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.Int32(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \ - ]) \ - ) - #calculate route - g_routing_interface.calculateRoute(dbus.UInt32(g_session_handle),dbus.UInt32(g_route_handle)) - -startTrigger(test_name) - -session = bus.get_object('org.genivi.navigation.navigationcore.Session.v4_0_Session','/Session') -g_session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session.v4_0') - -#get session handle -ret = g_session_interface.createSession(dbus.String("test route calculation")) -g_session_handle=ret[1] -print 'Session handle: ' + str(g_session_handle) - -routing_obj = bus.get_object('org.genivi.navigation.navigationcore.Routing.v4_0_Routing','/Routing') -g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigation.navigationcore.Routing.v4_0') - -g_current_route = 0 -launch_route_calculation(0) - - -#main loop -gobject.timeout_add(TIME_OUT, timeout) -loop = gobject.MainLoop() -loop.run() - - diff --git a/test/navigation/test-route-calculation.py b/test/navigation/test-route-calculation.py deleted file mode 100755 index f0a5221..0000000 --- a/test/navigation/test-route-calculation.py +++ /dev/null @@ -1,220 +0,0 @@ -#!/usr/bin/python - -""" -************************************************************************** -* @licence app begin@ -* SPDX-License-Identifier: MPL-2.0 -* -* \copyright Copyright (C) 2014, XS Embedded GmbH, PCA Peugeot Citroen -* -* \file test-route-calculation.py -* -* \brief This simple test shows how the route calculation -* could be easily tested using a python script -* -* \author Marco Residori -* \author Philippe Colliot -* -* \version 1.1 -* -* This Source Code Form is subject to the terms of the -* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -* List of changes: -* 04-02-2016, Philippe Colliot, Update to the new API ('i' for enumerations and 'yv' for variants) -* -* @licence end@ -************************************************************************** -""" - -import dbus -import gobject -import dbus.mainloop.glib -from collections import namedtuple,defaultdict -from _dbus_bindings import Int32 -from PIL.GimpGradientFile import SEGMENTS -from xml.dom.minidom import parse -import xml.dom.minidom -import argparse -import sys -import errno -#import pdb;pdb.set_trace() -from pip import locations -from dltTrigger import * - -#name of the test -test_name = "route calculation" - -#constants as defined in the Navigation API -GENIVI_NAVIGATIONCORE_LATITUDE = 0x00a0 -GENIVI_NAVIGATIONCORE_LONGITUDE = 0x00a1 -GENIVI_NAVIGATIONCORE_TOTAL_TIME = 0x018e -GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE = 0x018f -GENIVI_NAVIGATIONCORE_ROAD_NAME = 0x0147 -GENIVI_NAVIGATIONCORE_START_LATITUDE = 0x0141 -GENIVI_NAVIGATIONCORE_END_LATITUDE = 0x0142 -GENIVI_NAVIGATIONCORE_START_LONGITUDE = 0x0143 -GENIVI_NAVIGATIONCORE_END_LONGITUDE = 0x0144 -GENIVI_NAVIGATIONCORE_DISTANCE = 0x0148 -GENIVI_NAVIGATIONCORE_TIME = 0x0149 -GENIVI_NAVIGATIONCORE_SPEED = 0x00a4 - -#constants used into the script -TIME_OUT = 10000 - -print('--------------------------') -print('Route Calculation Test') -print('--------------------------') - -parser = argparse.ArgumentParser(description='Route Calculation Test for navigation PoC and FSA.') -parser.add_argument('-r','--rou',action='store', dest='routes', help='List of routes in xml format') -args = parser.parse_args() - -if args.routes == None: - print('route file is missing') - sys.exit(1) -else: - try: - DOMTree = xml.dom.minidom.parse(args.routes) - except OSError as e: - if e.errno == errno.ENOENT: - print('file not exists') - sys.exit(1) - route_set = DOMTree.documentElement - -print("Country : %s" % route_set.getAttribute("country")) - -routes = route_set.getElementsByTagName("route") - -#create dictionary with the locations -locations = {} -for location in route_set.getElementsByTagName("location"): - lat_long = [location.getElementsByTagName("latitude")[0].childNodes[0].data,location.getElementsByTagName("longitude")[0].childNodes[0].data] - locations[location.getAttribute("name")] = lat_long - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -#connect to session bus -bus = dbus.SessionBus() - -#add signal receivers -def catchall_route_calculation_signals_handler(routeHandle, status, percentage): - print 'Route Calculation: ' + str(int(percentage)) + ' %' - if int(percentage) == 100: - #get route overview - overview = g_routing_interface.GetRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])) - #retrieve distance - totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)]) - print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km' - totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]) - m, s = divmod(totalTime[1], 60) - h, m = divmod(m, 60) - print "Total Time: %d:%02d:%02d" % (h, m, s) - #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) - valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME), - dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE), - dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE), - dbus.Int32(GENIVI_NAVIGATIONCORE_TIME), - dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)] - ret = g_routing_interface.GetRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(0),dbus.Array(valuesToReturn),dbus.UInt32(500),dbus.UInt32(0)) - print "Total number of segments: " + str(ret[0]) - #len(ret[1]) is size - #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude -# pdb.set_trace() - route = g_current_route + 1 - if route < routes.length: - launch_route_calculation(route) - else: - for i in range(routes.length): - g_routing_interface.DeleteRoute(dbus.UInt32(g_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data)) - g_session_interface.DeleteSession(dbus.UInt32(g_session_handle)) - -def catchall_session_signals_handler(sessionHandle): - print('Session handle deleted: '+str(sessionHandle)) - if sessionHandle == g_session_handle: - print 'Test PASSED' - else: - print 'Test FAILED' - exit() - -def catchall_route_deleted_signals_handler(routeHandle): - print('Route handle deleted: '+str(routeHandle)) - -bus.add_signal_receiver(catchall_route_calculation_signals_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ - signal_name = "RouteCalculationProgressUpdate") - -bus.add_signal_receiver(catchall_route_deleted_signals_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Routing", \ - signal_name = "RouteDeleted") - -bus.add_signal_receiver(catchall_session_signals_handler, \ - dbus_interface = "org.genivi.navigation.navigationcore.Session", \ - signal_name = "SessionDeleted") - -#timeout -def timeout(): - print 'Timeout Expired' - print '\nTest FAILED' - exit() - -def exit(): - stopTrigger(test_name) - loop.quit() - -def launch_route_calculation(route): - global g_current_route - global g_route_handle - global g_routing_interface - global g_session_handle - g_current_route = route - print 'Route name: '+routes[g_current_route].getElementsByTagName("name")[0].childNodes[0].data - #get route handle - ret = g_routing_interface.CreateRoute(dbus.UInt32(g_session_handle)) - g_route_handle=ret[1] - routes[g_current_route].getElementsByTagName("handle")[0].childNodes[0].data = g_route_handle - print 'Route handle: ' + str(g_route_handle) - start = routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data - dest = routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data - print 'Calculating route from \ -'+start+'(' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]) + ') to \ -'+dest+'(' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1]) + ')' - #set waypoints - g_routing_interface.SetWaypoints(dbus.UInt32(g_session_handle), \ - dbus.UInt32(g_route_handle), \ - dbus.Boolean(0), \ - dbus.Array([ \ - dbus.Dictionary({dbus.UInt16(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([0,dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.UInt16(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([0,dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \ - dbus.Dictionary({dbus.UInt16(GENIVI_NAVIGATIONCORE_LATITUDE):dbus.Struct([0,dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.UInt16(GENIVI_NAVIGATIONCORE_LONGITUDE):dbus.Struct([0,dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \ - ]) \ - ) - #calculate route - g_routing_interface.CalculateRoute(dbus.UInt32(g_session_handle),dbus.UInt32(g_route_handle)) - -startTrigger(test_name) - -session = bus.get_object('org.genivi.navigation.navigationcore.Session','/org/genivi/navigationcore') -g_session_interface = dbus.Interface(session, dbus_interface='org.genivi.navigation.navigationcore.Session') - -#get session handle -ret = g_session_interface.CreateSession(dbus.String("test route calculation")) -g_session_handle=ret[1] -print 'Session handle: ' + str(g_session_handle) - -routing_obj = bus.get_object('org.genivi.navigation.navigationcore.Routing','/org/genivi/navigationcore') -g_routing_interface = dbus.Interface(routing_obj, dbus_interface='org.genivi.navigation.navigationcore.Routing') - -g_current_route = 0 -launch_route_calculation(0) - - -#main loop -gobject.timeout_add(TIME_OUT, timeout) -loop = gobject.MainLoop() -loop.run() - - -- cgit v1.2.1