Skip to content

Commit 9501733

Browse files
committed
Make the autopilot tests work when the service is installed
1 parent d813a6e commit 9501733

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

src/service/VoiceService.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,16 @@ arg_t VoiceService::sphinx_cmd_ln[] = { POCKETSPHINX_OPTIONS, { "-adcdev",
2929
CMDLN_EMPTY_OPTION };
3030

3131
VoiceService::VoiceService(const QDBusConnection &connection,
32-
const QString &deviceName, QObject *parent) :
32+
const char *deviceName, QObject *parent) :
3333
QObject(parent), m_adaptor(new VoiceAdaptor(this)), m_connection(
3434
connection) {
3535

36-
QString name = deviceName;
37-
38-
if (!deviceName.isEmpty()) {
39-
config = cmd_ln_init(0, sphinx_cmd_ln, TRUE, "-hmm", HMM_PATH, "-dict",
40-
DICT_PATH, "-adcdev", name.toUtf8().data(), 0);
36+
if (deviceName != nullptr) {
37+
config = cmd_ln_init(nullptr, sphinx_cmd_ln, TRUE, "-hmm", HMM_PATH, "-dict",
38+
DICT_PATH, "-adcdev", deviceName, nullptr);
4139
} else {
42-
config = cmd_ln_init(0, sphinx_cmd_ln, TRUE, "-hmm", HMM_PATH, "-dict",
43-
DICT_PATH, 0);
40+
config = cmd_ln_init(nullptr, sphinx_cmd_ln, TRUE, "-hmm", HMM_PATH, "-dict",
41+
DICT_PATH, nullptr);
4442
}
4543

4644
if (config == NULL) {

src/service/VoiceService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class VoiceService: public QObject, protected QDBusContext {
3737
Q_OBJECT
3838
public:
3939
explicit VoiceService(const QDBusConnection &connection,
40-
const QString &deviceName, QObject *parent = 0);
40+
const char *deviceName, QObject *parent = 0);
4141

4242
virtual ~VoiceService();
4343

src/service/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ int main(int argc, char *argv[]) {
4444
QDBusConnection connection = QDBusConnection::sessionBus();
4545
connection.registerService("com.canonical.Unity.Voice");
4646

47-
QString deviceName("");
47+
char *deviceName = nullptr;
4848
if (argc == 2) {
49-
deviceName = QString::fromUtf8(argv[1]);
49+
deviceName = argv[1];
5050
}
5151

5252
VoiceService voiceService(QDBusConnection::sessionBus(), deviceName);

tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ execute_process(COMMAND python -c "from distutils.sysconfig import get_python_li
5959
install(DIRECTORY ${AUTOPILOT_DIR}
6060
DESTINATION ${PYTHON_PACKAGE_DIR}
6161
)
62+
63+
install(
64+
DIRECTORY "data/sounds"
65+
DESTINATION "${PYTHON_PACKAGE_DIR}/unity_voice/"
66+
)

tests/TestPronounceDict.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Author: Marcus Tomlinson <[email protected]>
1717
*/
1818

19-
#include <libunityvoice/PronounceDict.h>
19+
#include <service/PronounceDict.h>
2020

2121
#include <gtest/gtest.h>
2222
#include <iostream>

tests/autopilot/unity_voice/dbus_interface/tests/test_voice.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# by the Free Software Foundation.
77

88
from autopilot.testcase import AutopilotTestCase
9-
from os.path import abspath, dirname, join
9+
from os.path import abspath, dirname, join, isdir
1010
from autopilot.matchers import Eventually
1111
from testtools.matchers import Equals
1212
import dbus
@@ -15,6 +15,7 @@
1515
import gobject
1616
import glob
1717
import subprocess
18+
import sys
1819

1920
from unity_voice import DBusTestCase
2021

@@ -52,9 +53,14 @@ def setUp(self):
5253

5354
self.result = ""
5455
self.sound_file = ""
55-
56+
57+
# First try the in-source path
5658
self.sound_dir = abspath(join(dirname(__file__), '..', '..', '..', '..', 'data', 'sounds'))
5759

60+
# Now try the install path
61+
if not isdir(self.sound_dir):
62+
self.sound_dir = join(dirname(sys.modules['unity_voice'].__file__), 'sounds')
63+
5864
def application_binary(self):
5965
cmds = glob.glob('/usr/lib/*/unity-voice-service')
6066
self.assertThat(len(cmds), Equals(1))

0 commit comments

Comments
 (0)