Permalink
Browse files

The approach using /bin/ping and QProcess was fatally flawed, but is …

…worth preserving.
  • Loading branch information...
Sturmflut committed Jan 16, 2015
1 parent 6085f9c commit 854ef64b468299005dd0754c000455c7706b0bda
View
@@ -25,17 +25,18 @@ set(QT_IMPORTS_DIR "lib/${ARCH_TRIPLET}")
option(INSTALL_TESTS "Install the tests on make install" on)
set(APP_NAME NetworkScanner)
-set(NetworkScanner_DIR "share/qml/NetworkScanner")
-set(MAIN_QML "networkscanner.qml")
-set(ICON "graphics/networkscanner.png")
+set(APP_ID "networkscanner.sturmflut")
+set(NETWORKSCANNER_DIR "share/qml/NetworkScanner")
+set(MAIN_QML "NetworkScanner.qml")
+set(ICON "graphics/NetworkScanner.png")
# Set install paths
set(CMAKE_INSTALL_PREFIX /)
set(DATA_DIR /)
set(DESKTOP_DIR ${DATA_DIR})
set(DESKTOP_FILE_NAME "networkscanner.desktop")
-set(EXEC "qmlscene $@ ${NetworkScanner_DIR}/${MAIN_QML}")
+set(EXEC "qmlscene $@ ${NETWORKSCANNER_DIR}/${MAIN_QML}")
# This command figures out the target architecture for use in the manifest file
execute_process(
@@ -69,5 +70,5 @@ add_custom_target("run" /usr/bin/qmlscene -I ${CMAKE_BINARY_DIR}/backend ${CMAK
WORKING_DIRECTORY ./app)
# No op custom target for all not compiled files, so they show up in the QtCreator project tree
-add_custom_target("NetworkScanner_ClickFiles" ALL SOURCES "networkscanner.apparmor" "manifest.json.in")
+add_custom_target("networkscanner_ClickFiles" ALL SOURCES "networkscanner.apparmor" "manifest.json.in")
View
@@ -1,13 +1,13 @@
file(GLOB QML_JS_FILES *.qml *.js)
# Make the files visible on qtcreator
-add_custom_target(NetworkScanner_QMlFiles ALL SOURCES ${QML_JS_FILES})
+add_custom_target(networkscanner_QMlFiles ALL SOURCES ${QML_JS_FILES})
# Substitute variables in the desktop file
configure_file(${DESKTOP_FILE_NAME}.in ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE_NAME}.in)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE_NAME} DESTINATION ${DESKTOP_DIR})
-install(FILES ${QML_JS_FILES} DESTINATION ${NetworkScanner_DIR})
+install(FILES ${QML_JS_FILES} DESTINATION ${NETWORKSCANNER_DIR})
add_subdirectory(components)
add_subdirectory(ui)
File renamed without changes.
@@ -1,7 +1,7 @@
file(GLOB COMPONENTS_QML_JS_FILES *.qml *.js)
# Make the files visible in the qtcreator tree
-add_custom_target(NetworkScanner_components_QMlFiles ALL SOURCES ${COMPONENTS_QML_JS_FILES})
+add_custom_target(networkscanner_components_QMlFiles ALL SOURCES ${COMPONENTS_QML_JS_FILES})
install(FILES ${COMPONENTS_QML_JS_FILES} DESTINATION ${NETWORKSCANNER_DIR}/components)
File renamed without changes.
@@ -1,6 +1,6 @@
[Desktop Entry]
-_Name=Network Scanner
-Comment=A simple network scanner
+_Name=NetworkScanner
+Comment=My project description
Exec=@EXEC@
Icon=@ICON@
Terminal=false
@@ -0,0 +1,133 @@
+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
+
+"""Ubuntu Touch App autopilot tests."""
+
+from os import remove
+import os.path
+from tempfile import mktemp
+import subprocess
+
+from autopilot.input import Mouse, Touch, Pointer
+from autopilot.matchers import Eventually
+from autopilot.platform import model
+from testtools.matchers import Is, Not, Equals
+from autopilot.testcase import AutopilotTestCase
+
+def get_module_include_path():
+ return os.path.abspath(
+ os.path.join(
+ os.path.dirname(__file__),
+ '..',
+ '..',
+ '..',
+ '..',
+ 'backend',
+ 'modules')
+ )
+
+
+class UbuntuTouchAppTestCase(AutopilotTestCase):
+ """A common test case class that provides several useful methods for the tests."""
+
+ if model() == 'Desktop':
+ scenarios = [
+ ('with mouse', dict(input_device_class=Mouse))
+ ]
+ else:
+ scenarios = [
+ ('with touch', dict(input_device_class=Touch))
+ ]
+
+ @property
+ def main_window(self):
+ return MainWindow(self.app)
+
+
+ def setUp(self):
+ self.pointing_device = Pointer(self.input_device_class.create())
+ super(UbuntuTouchAppTestCase, self).setUp()
+ self.launch_test_qml()
+
+
+ def launch_test_qml(self):
+ # If the test class has defined a 'test_qml' class attribute then we
+ # write it to disk and launch it inside the QML Scene. If not, then we
+ # silently do nothing (presumably the test has something else planned).
+ arch = subprocess.check_output(["dpkg-architecture",
+ "-qDEB_HOST_MULTIARCH"]).strip()
+ if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):
+ qml_path = mktemp(suffix='.qml')
+ open(qml_path, 'w').write(self.test_qml)
+ self.addCleanup(remove, qml_path)
+
+ self.app = self.launch_test_application(
+ "/usr/lib/" + arch + "/qt5/bin/qmlscene",
+ "-I", get_module_include_path(),
+ qml_path,
+ app_type='qt')
+
+ if hasattr(self, 'test_qml_file') and isinstance(self.test_qml_file, basestring):
+ qml_path = self.test_qml_file
+ self.app = self.launch_test_application(
+ "/usr/lib/" + arch + "/qt5/bin/qmlscene",
+ "-I", get_module_include_path(),
+ qml_path,
+ app_type='qt')
+
+ self.assertThat(self.get_qml_view().visible, Eventually(Equals(True)))
+
+
+ def get_qml_view(self):
+ """Get the main QML view"""
+
+ return self.app.select_single("QQuickView")
+
+ def get_mainview(self):
+ """Get the QML MainView"""
+
+ mainView = self.app.select_single("MainView")
+ self.assertThat(mainView, Not(Is(None)))
+ return mainView
+
+
+ def get_object(self,objectName):
+ """Get a object based on the objectName"""
+
+ obj = self.app.select_single(objectName=objectName)
+ self.assertThat(obj, Not(Is(None)))
+ return obj
+
+
+ def mouse_click(self,objectName):
+ """Move mouse on top of the object and click on it"""
+
+ obj = self.get_object(objectName)
+ self.pointing_device.move_to_object(obj)
+ self.pointing_device.click()
+
+
+ def mouse_press(self,objectName):
+ """Move mouse on top of the object and press mouse button (without releasing it)"""
+
+ obj = self.get_object(objectName)
+ self.pointing_device.move_to_object(obj)
+ self.pointing_device.press()
+
+
+ def mouse_release(self):
+ """Release mouse button"""
+
+ self.pointing_device.release()
+
+
+ def type_string(self, string):
+ """Type a string with keyboard"""
+
+ self.keyboard.type(string)
+
+
+ def type_key(self, key):
+ """Type a single key with keyboard"""
+
+ self.keyboard.key(key)
+
@@ -0,0 +1,2 @@
+""" A main.qml test suite """
+
@@ -0,0 +1,24 @@
+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
+
+"""Tests for the Hello World"""
+
+from autopilot.matchers import Eventually
+from textwrap import dedent
+from testtools.matchers import Is, Not, Equals
+from testtools import skip
+import os
+from NetworkScanner import UbuntuTouchAppTestCase
+
+
+class MainTests(UbuntuTouchAppTestCase):
+ """Generic tests for the Hello World"""
+
+ test_qml_file = "%s/%s.qml" % (os.path.dirname(os.path.realpath(__file__)),"../../../../NetworkScanner")
+
+ def test_0_can_select_mainView(self):
+ """Must be able to select the mainview."""
+
+ mainView = self.get_mainview()
+ self.assertThat(mainView.visible,Eventually(Equals(True)))
+
+
View
@@ -7,6 +7,6 @@ fi
SCRIPTPATH=`dirname $0`
pushd ${SCRIPTPATH}
-autopilot run networkscanner
+autopilot run NetworkScanner
popd
View
@@ -1,7 +1,7 @@
file(GLOB UI_QML_JS_FILES *.qml *.js)
# Make the files visible in the qtcreator tree
-add_custom_target(NetworkScanner_ui_QMlFiles ALL SOURCES ${UI_QML_JS_FILES})
+add_custom_target(networkscanner_ui_QMlFiles ALL SOURCES ${UI_QML_JS_FILES})
install(FILES ${UI_QML_JS_FILES} DESTINATION ${NETWORKSCANNER_DIR}/ui)
View
@@ -3,7 +3,7 @@ import QtQuick 2.0
import Ubuntu.Components 1.1
import Ubuntu.Components.Popups 1.0
-import NetworkScanner 1.0
+import Networkscanner 1.0
import "../components"
@@ -30,6 +30,8 @@ Tab {
}
onError: {
+ outputLabel.text = reason
+
startButton.iconName = "media-playback-start"
}
}
View
@@ -3,30 +3,30 @@ include_directories(
)
set(
- NetworkScannerbackend_SRCS
- modules/NetworkScanner/backend.cpp
- modules/NetworkScanner/pingprocess.cpp
- modules/NetworkScanner/pingscanner.cpp
- modules/NetworkScanner/networkinfo.cpp
- modules/NetworkScanner/networkaddress.cpp
+ Networkscannerbackend_SRCS
+ modules/Networkscanner/backend.cpp
+ modules/Networkscanner/pingprocess.cpp
+ modules/Networkscanner/pingscanner.cpp
+ modules/Networkscanner/networkinfo.cpp
+ modules/Networkscanner/networkaddress.cpp
)
-add_library(NetworkScannerbackend MODULE
- ${NetworkScannerbackend_SRCS}
+add_library(Networkscannerbackend MODULE
+ ${Networkscannerbackend_SRCS}
)
-set_target_properties(NetworkScannerbackend PROPERTIES
- LIBRARY_OUTPUT_DIRECTORY NetworkScanner)
+set_target_properties(Networkscannerbackend PROPERTIES
+ LIBRARY_OUTPUT_DIRECTORY Networkscanner)
-qt5_use_modules(NetworkScannerbackend Gui Qml Quick)
+qt5_use_modules(Networkscannerbackend Gui Qml Quick)
# Copy qmldir file to build dir for running in QtCreator
-add_custom_target(NetworkScannerbackend-qmldir ALL
- COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/modules/NetworkScanner/qmldir ${CMAKE_CURRENT_BINARY_DIR}/NetworkScanner
+add_custom_target(Networkscannerbackend-qmldir ALL
+ COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/modules/Networkscanner/qmldir ${CMAKE_CURRENT_BINARY_DIR}/Networkscanner
DEPENDS ${QMLFILES}
)
# Install plugin file
-install(TARGETS NetworkScannerbackend DESTINATION ${QT_IMPORTS_DIR}/NetworkScanner/)
-install(FILES modules/NetworkScanner/qmldir DESTINATION ${QT_IMPORTS_DIR}/NetworkScanner/)
+install(TARGETS Networkscannerbackend DESTINATION ${QT_IMPORTS_DIR}/Networkscanner/)
+install(FILES modules/Networkscanner/qmldir DESTINATION ${QT_IMPORTS_DIR}/Networkscanner/)
@@ -0,0 +1,25 @@
+#include <QtQml>
+#include <QtQml/QQmlContext>
+
+#include "backend.h"
+
+#include "pingscanner.h"
+#include "networkinfo.h"
+#include "networkaddress.h"
+
+
+void BackendPlugin::registerTypes(const char *uri)
+{
+ Q_ASSERT(uri == QLatin1String("NetworkScanner"));
+
+ qmlRegisterType<PingProcess>(uri, 1, 0, "PingProcess");
+ qmlRegisterType<PingScanner>(uri, 1, 0, "PingScanner");
+ qmlRegisterType<NetworkInfo>(uri, 1, 0, "NetworkInfo");
+ qmlRegisterType<NetworkAddress>(uri, 1, 0, "NetworkAddress");
+}
+
+void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
+{
+ QQmlExtensionPlugin::initializeEngine(engine, uri);
+}
+
@@ -0,0 +1,39 @@
+#ifndef BACKEND_PLUGIN_H
+#define BACKEND_PLUGIN_H
+
+#include <QtQml/QQmlEngine>
+#include <QtQml/QQmlExtensionPlugin>
+
+/*
+ ----8<-----
+
+ import NetworkScanner 1.0
+
+ Rectangle {
+ width: 200
+ height: 200
+
+ MyType {
+ id: helloType
+ }
+
+ Text {
+ anchors.centerIn: parent
+ text: helloType.helloworld
+ }
+ }
+
+ -----8<------
+*/
+class BackendPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
+
+public:
+ void registerTypes(const char *uri);
+ void initializeEngine(QQmlEngine *engine, const char *uri);
+};
+#endif // BACKEND_PLUGIN_H
+
+
@@ -0,0 +1,13 @@
+#include "networkaddress.h"
+
+
+NetworkAddress::NetworkAddress() :
+ QObject(NULL)
+{
+
+}
+
+
+NetworkAddress::~NetworkAddress() {
+
+}
Oops, something went wrong.

0 comments on commit 854ef64

Please sign in to comment.