on xenial help sign in
Add missing files
commitbeb293ce9d81061eb38887eae6369265bfc0df12 authorMichael Terry <michael.terry@canonical.com> dateThu 26 May 2016, 17:02 (10 years ago) parent5c22355
8 files changed+341
tests/mocks/Biometryd/MockBiometryd.cpp+42 tests/mocks/Biometryd/MockBiometryd.h+44 tests/mocks/Biometryd/MockDevice.cpp+29 tests/mocks/Biometryd/MockDevice.h+40 tests/mocks/Biometryd/MockIdentifier.cpp+28 tests/mocks/Biometryd/MockIdentifier.h+36 tests/mocks/Biometryd/MockOperation.cpp+74 tests/mocks/Biometryd/MockOperation.h+48
tests/mocks/Biometryd/MockBiometryd.cppnew file+42
@@ -0,0 +1,42 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "MockBiometryd.h"
18+#include "MockDevice.h"
19+
20+MockBiometryd::MockBiometryd(QObject *parent)
21+ : QObject(parent)
22+ , m_device(nullptr)
23+{
24+}
25+
26+MockDevice *MockBiometryd::defaultDevice() const
27+{
28+ return m_device;
29+}
30+
31+void MockBiometryd::reset(bool devicePresent)
32+{
33+ if (m_device) {
34+ delete m_device;
35+ m_device = nullptr;
36+ }
37+
38+ if (devicePresent)
39+ m_device = new MockDevice(this);
40+
41+ Q_EMIT defaultDeviceChanged();
42+}
tests/mocks/Biometryd/MockBiometryd.hnew file+44
@@ -0,0 +1,44 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef MOCK_BIOMETRYD_H
18+#define MOCK_BIOMETRYD_H
19+
20+#include <QObject>
21+
22+#include "MockDevice.h"
23+
24+class MockBiometryd : public QObject
25+{
26+ Q_OBJECT
27+ Q_DISABLE_COPY(MockBiometryd)
28+ Q_PROPERTY(MockDevice *defaultDevice READ defaultDevice NOTIFY defaultDeviceChanged)
29+
30+public:
31+ explicit MockBiometryd(QObject *parent = 0);
32+
33+ MockDevice *defaultDevice() const;
34+
35+ Q_INVOKABLE void reset(bool devicePresent); // only in mock
36+
37+Q_SIGNALS:
38+ void defaultDeviceChanged();
39+
40+private:
41+ MockDevice *m_device;
42+};
43+
44+#endif // MOCK_BIOMETRYD_H
tests/mocks/Biometryd/MockDevice.cppnew file+29
@@ -0,0 +1,29 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "MockDevice.h"
18+#include "MockIdentifier.h"
19+
20+MockDevice::MockDevice(QObject *parent)
21+ : QObject(parent)
22+ , m_identifier(new MockIdentifier(this))
23+{
24+}
25+
26+MockIdentifier *MockDevice::identifier() const
27+{
28+ return m_identifier;
29+}
tests/mocks/Biometryd/MockDevice.hnew file+40
@@ -0,0 +1,40 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef MOCK_DEVICE_H
18+#define MOCK_DEVICE_H
19+
20+#include <QObject>
21+
22+#include "MockIdentifier.h"
23+
24+class MockDevice : public QObject
25+{
26+ Q_OBJECT
27+ Q_PROPERTY(MockIdentifier *identifier READ identifier CONSTANT)
28+
29+public:
30+ explicit MockDevice(QObject *parent = 0);
31+
32+ MockIdentifier *identifier() const;
33+
34+private:
35+ MockIdentifier *m_identifier;
36+};
37+
38+Q_DECLARE_METATYPE(MockDevice*)
39+
40+#endif // MOCK_DEVICE_H
tests/mocks/Biometryd/MockIdentifier.cppnew file+28
@@ -0,0 +1,28 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "MockIdentifier.h"
18+#include "MockOperation.h"
19+
20+MockIdentifier::MockIdentifier(QObject *parent)
21+ : QObject(parent)
22+{
23+}
24+
25+MockOperation *MockIdentifier::identifyUser()
26+{
27+ return new MockOperation(this);
28+}
tests/mocks/Biometryd/MockIdentifier.hnew file+36
@@ -0,0 +1,36 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef MOCK_IDENTIFIER_H
18+#define MOCK_IDENTIFIER_H
19+
20+#include <QObject>
21+
22+#include "MockOperation.h"
23+
24+class MockIdentifier : public QObject
25+{
26+ Q_OBJECT
27+
28+public:
29+ explicit MockIdentifier(QObject *parent = 0);
30+
31+ Q_INVOKABLE MockOperation *identifyUser();
32+};
33+
34+Q_DECLARE_METATYPE(MockIdentifier*)
35+
36+#endif // MOCK_IDENTIFIER_H
tests/mocks/Biometryd/MockOperation.cppnew file+74
@@ -0,0 +1,74 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include <QString>
18+#include <QVariant>
19+
20+#include "MockOperation.h"
21+
22+class Result : public QObject
23+{
24+ Q_OBJECT
25+ Q_PROPERTY(unsigned int uid READ uid CONSTANT)
26+
27+public:
28+ explicit Result(unsigned int uid, QObject *parent = 0)
29+ : QObject(parent), m_uid(uid)
30+ {}
31+
32+ unsigned int uid() const { return m_uid; }
33+
34+private:
35+ unsigned int m_uid;
36+};
37+
38+MockOperation::MockOperation(QObject *parent)
39+ : QObject(parent)
40+ , m_observer(nullptr)
41+{
42+}
43+
44+bool MockOperation::running() const
45+{
46+ return m_observer != nullptr;
47+}
48+
49+void MockOperation::start(QObject *observer)
50+{
51+ if (!m_observer)
52+ m_observer = observer;
53+}
54+
55+void MockOperation::cancel()
56+{
57+ m_observer = nullptr;
58+}
59+
60+void MockOperation::mockSuccess(unsigned int uid)
61+{
62+ if (m_observer)
63+ QMetaObject::invokeMethod(m_observer, "succeeded", Qt::DirectConnection,
64+ Q_ARG(QVariant, QVariant::fromValue(new Result(uid, this))));
65+}
66+
67+void MockOperation::mockFailure(const QString &reason)
68+{
69+ if (m_observer)
70+ QMetaObject::invokeMethod(m_observer, "failed", Qt::DirectConnection,
71+ Q_ARG(QString, reason));
72+}
73+
74+#include "MockOperation.moc"
tests/mocks/Biometryd/MockOperation.hnew file+48
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef MOCK_OPERATION_H
18+#define MOCK_OPERATION_H
19+
20+#include <QObject>
21+
22+class MockOperation : public QObject
23+{
24+ Q_OBJECT
25+ Q_PROPERTY(bool running READ running NOTIFY runningChanged) // only in mock
26+
27+public:
28+ explicit MockOperation(QObject *parent = 0);
29+
30+ Q_INVOKABLE void start(QObject *observer);
31+ Q_INVOKABLE void cancel();
32+
33+ Q_INVOKABLE void mockSuccess(unsigned int uid); // only in mock
34+ Q_INVOKABLE void mockFailure(const QString &reason); // only in mock
35+
36+ bool running() const; // only in mock
37+
38+Q_SIGNALS:
39+ void runningChanged();
40+
41+private:
42+ QObject *m_observer;
43+ bool m_running;
44+};
45+
46+Q_DECLARE_METATYPE(MockOperation*)
47+
48+#endif // MOCK_OPERATION_H