[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,6 +2,6 @@
<service name="tar_git">
<param name="url">https://github.com/monich/sailfish-qrshare.git</param>
<param name="branch">master</param>
- <param name="revision">fb4485d</param>
+ <param name="revision">e17035d</param>
</service>
</services>
\ No newline at end of file
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/harbour-lib.pro
^
|
@@ -24,14 +24,17 @@
SOURCES += \
src/HarbourBase32.cpp \
+ src/HarbourBase45.cpp \
src/HarbourClipboard.cpp \
src/HarbourDisplayBlanking.cpp \
src/HarbourJson.cpp \
src/HarbourLib.cpp \
src/HarbourMce.cpp \
src/HarbourMediaPlugin.cpp \
+ src/HarbourObject.cpp \
src/HarbourOrganizeListModel.cpp \
src/HarbourPolicyPlugin.cpp \
+ src/HarbourProcessState.cpp \
src/HarbourSelectionListModel.cpp \
src/HarbourSigChildHandler.cpp \
src/HarbourSingleImageProvider.cpp \
@@ -54,14 +57,17 @@
INCLUDEPATH += include
PUBLIC_HEADERS += \
include/HarbourBase32.h \
+ include/HarbourBase45.h \
include/HarbourClipboard.h \
include/HarbourDebug.h \
include/HarbourDisplayBlanking.h \
include/HarbourJson.h \
include/HarbourLib.h \
include/HarbourMediaPlugin.h \
+ include/HarbourObject.h \
include/HarbourOrganizeListModel.h \
include/HarbourPolicyPlugin.h \
+ include/HarbourProcessState.h \
include/HarbourSelectionListModel.h \
include/HarbourSigChildHandler.h \
include/HarbourSingleImageProvider.h \
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/include/HarbourAztecCodeGenerator.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -11,8 +11,8 @@
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
* distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
@@ -39,25 +39,42 @@
class HarbourAztecCodeGenerator : public QObject {
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
+ Q_PROPERTY(int ecLevel READ ecLevel WRITE setEcLevel NOTIFY ecLevelChanged)
Q_PROPERTY(QString code READ code NOTIFY codeChanged)
Q_PROPERTY(bool running READ running NOTIFY runningChanged)
+ Q_ENUMS(ECLevel)
public:
+ enum ECLevel {
+ ECLevelDefault = -1,
+ ECLevelLowest = 5,
+ ECLevelLow = 10,
+ ECLevelMedium = 23,
+ ECLevelHigh = 36,
+ ECLevelVeryHigh = 50,
+ ECLevelHighest = 95,
+ ECLevelCount
+ };
+
HarbourAztecCodeGenerator(QObject* aParent = Q_NULLPTR);
QString text() const;
void setText(QString aValue);
+ int ecLevel() const;
+ void setEcLevel(int aValue);
+
QString code() const;
bool running() const;
- static QByteArray generate(QString aText);
+ static QByteArray generate(QString aText, int aEcLevel = ECLevelDefault);
// Callback for qmlRegisterSingletonType<HarbourAztecCodeGenerator>
static QObject* createSingleton(QQmlEngine* aEngine, QJSEngine* aScript);
Q_SIGNALS:
void textChanged();
+ void ecLevelChanged();
void codeChanged();
void runningChanged();
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/include/HarbourBase32.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -31,8 +31,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef HARBOUR_IMAGE_BASE32_H
-#define HARBOUR_IMAGE_BASE32_H
+#ifndef HARBOUR_BASE32_H
+#define HARBOUR_BASE32_H
#include <QString>
#include <QByteArray>
@@ -46,4 +46,4 @@
static bool isValidBase32(QString aBase32);
};
-#endif // HARBOUR_IMAGE_BASE32_H
+#endif // HARBOUR_BASE32_H
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/include/HarbourBase45.h
^
|
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef HARBOUR_BASE45_H
+#define HARBOUR_BASE45_H
+
+#include <QString>
+#include <QByteArray>
+
+class HarbourBase45 {
+ class Private;
+ HarbourBase45();
+public:
+ static bool isValidBase45(QString aBase45);
+ static QByteArray fromBase45(QString aBase45);
+ static QString toBase45(QByteArray aBinary);
+};
+
+#endif // HARBOUR_BASE45_H
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/include/HarbourObject.h
^
|
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef HARBOUR_OBJECT_H
+#define HARBOUR_OBJECT_H
+
+#include <QObject>
+#include <QList>
+#include <QQmlListProperty>
+
+// Fixes the "Cannot assign to non-existent default property" problem
+// with QtObject in QML.
+class HarbourObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QQmlListProperty<QObject> children READ children)
+ Q_CLASSINFO("DefaultProperty", "children")
+
+public:
+ HarbourObject(QObject* aParent = Q_NULLPTR);
+
+ QQmlListProperty<QObject> children();
+
+private:
+ QList<QObject*> iChidren;
+};
+
+#endif // HARBOUR_OBJECT_H
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/include/HarbourProcessState.h
^
|
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef HARBOUR_PROCESS_STATE_H
+#define HARBOUR_PROCESS_STATE_H
+
+#include <QObject>
+
+class QQmlEngine;
+class QJSEngine;
+
+class HarbourProcessState: public QObject
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(HarbourProcessState)
+ Q_PROPERTY(bool jailedApp READ isJailedApp CONSTANT)
+
+public:
+ explicit HarbourProcessState(QObject* aParent = Q_NULLPTR);
+
+ // Callback for qmlRegisterSingletonType<HarbourProcessState>
+ static QObject* createSingleton(QQmlEngine* aEngine, QJSEngine* aScript);
+
+ static bool isJailedApp();
+};
+
+#endif // HARBOUR_PROCESS_STATE_H
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/include/HarbourQrCodeGenerator.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -39,26 +39,43 @@
class HarbourQrCodeGenerator : public QObject {
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
+ Q_PROPERTY(int ecLevel READ ecLevel WRITE setEcLevel NOTIFY ecLevelChanged)
Q_PROPERTY(QString code READ code NOTIFY codeChanged)
Q_PROPERTY(QString qrcode READ code NOTIFY codeChanged)
Q_PROPERTY(bool running READ running NOTIFY runningChanged)
+ Q_ENUMS(ECLevel)
public:
+ enum ECLevel {
+ ECLevelDefault = -1,
+ ECLevelLowest = 0,
+ ECLevel_L = ECLevelLowest,
+ ECLevel_M,
+ ECLevel_Q,
+ ECLevel_H,
+ ECLevelHighest = ECLevel_H,
+ ECLevelCount
+ };
+
HarbourQrCodeGenerator(QObject* aParent = Q_NULLPTR);
QString text() const;
void setText(QString aValue);
+ ECLevel ecLevel() const;
+ void setEcLevel(int aValue);
+
QString code() const;
bool running() const;
- static QByteArray generate(QString aText);
+ static QByteArray generate(QString aText, ECLevel aEcLevel = ECLevelDefault);
// Callback for qmlRegisterSingletonType<HarbourQrCodeGenerator>
static QObject* createSingleton(QQmlEngine* aEngine, QJSEngine* aScript);
Q_SIGNALS:
void textChanged();
+ void ecLevelChanged();
void codeChanged();
void runningChanged();
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/include/HarbourSystemInfo.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2020 Jolla Ltd.
- * Copyright (C) 2020 Slava Monich <slava@monich.com>
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -61,7 +61,11 @@
QString osName() const;
QString osVersion() const;
+ Q_INVOKABLE QString packageVersion(QString aPackage);
Q_INVOKABLE int osVersionCompare(QString aVersion);
+ Q_INVOKABLE static int compareVersions(QString aVersion1, QString aVersion2);
+
+ static QString queryPackageVersion(QString aVersion);
static int osVersionCompareWith(QString aVersion);
private:
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/src/HarbourAztecCodeGenerator.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -11,8 +11,8 @@
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
* distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
@@ -48,22 +48,25 @@
class HarbourAztecCodeGenerator::Task : public HarbourTask {
Q_OBJECT
public:
- Task(QThreadPool* aPool, QString aText);
+ Task(QThreadPool* aPool, QString aText, int aEcLevel);
void performTask() Q_DECL_OVERRIDE;
public:
QString iText;
QString iCode;
+ int iEcLevel;
};
-HarbourAztecCodeGenerator::Task::Task(QThreadPool* aPool, QString aText) :
+HarbourAztecCodeGenerator::Task::Task(QThreadPool* aPool, QString aText,
+ int aEcLevel) :
HarbourTask(aPool),
- iText(aText)
+ iText(aText),
+ iEcLevel(aEcLevel)
{
}
void HarbourAztecCodeGenerator::Task::performTask()
{
- QByteArray bytes(generate(iText));
+ QByteArray bytes(generate(iText, iEcLevel));
if (!bytes.isEmpty()) {
iCode = HarbourBase32::toBase32(bytes);
}
@@ -82,6 +85,10 @@
HarbourAztecCodeGenerator* parentObject() const;
void setText(QString aValue);
+ void setEcLevel(int aValue);
+ void regenerate();
+
+ static int realEcLevel(int aEcLevel);
public Q_SLOTS:
void onTaskDone();
@@ -89,6 +96,7 @@
public:
QThreadPool* iThreadPool;
Task* iTask;
+ int iEcLevel;
QString iText;
QString iCode;
};
@@ -96,7 +104,8 @@
HarbourAztecCodeGenerator::Private::Private(HarbourAztecCodeGenerator* aParent) :
QObject(aParent),
iThreadPool(new QThreadPool(this)),
- iTask(Q_NULLPTR)
+ iTask(Q_NULLPTR),
+ iEcLevel(ECLevelDefault)
{
// Serialize the tasks:
iThreadPool->setMaxThreadCount(1);
@@ -112,19 +121,45 @@
return qobject_cast<HarbourAztecCodeGenerator*>(parent());
}
+int HarbourAztecCodeGenerator::Private::realEcLevel(int aEcLevel)
+{
+ return (aEcLevel == ECLevelDefault) ? AZTEC_CORRECTION_DEFAULT :
+ (aEcLevel < ECLevelLowest) ? ECLevelLowest :
+ (aEcLevel > ECLevelHighest) ? ECLevelHighest :
+ aEcLevel;
+}
+
void HarbourAztecCodeGenerator::Private::setText(QString aText)
{
if (iText != aText) {
iText = aText;
- HarbourAztecCodeGenerator* obj = parentObject();
- const bool wasRunning = (iTask != Q_NULLPTR);
- if (iTask) iTask->release(this);
- iTask = new Task(iThreadPool, aText);
- iTask->submit(this, SLOT(onTaskDone()));
- Q_EMIT obj->textChanged();
- if (!wasRunning) {
- Q_EMIT obj->runningChanged();
+ regenerate();
+ Q_EMIT parentObject()->textChanged();
+ }
+}
+
+void HarbourAztecCodeGenerator::Private::setEcLevel(int aValue)
+{
+ const int level = (aValue == ECLevelDefault) ? ECLevelDefault : realEcLevel(aValue);
+ if (iEcLevel != level) {
+ const int prevRealLevel = realEcLevel(iEcLevel);
+ iEcLevel = level;
+ HDEBUG(level);
+ if (realEcLevel(level) != prevRealLevel) {
+ regenerate();
}
+ Q_EMIT parentObject()->ecLevelChanged();
+ }
+}
+
+void HarbourAztecCodeGenerator::Private::regenerate()
+{
+ const bool wasRunning = (iTask != Q_NULLPTR);
+ if (iTask) iTask->release(this);
+ iTask = new Task(iThreadPool, iText, iEcLevel);
+ iTask->submit(this, SLOT(onTaskDone()));
+ if (!wasRunning) {
+ Q_EMIT parentObject()->runningChanged();
}
}
@@ -169,6 +204,16 @@
iPrivate->setText(aValue);
}
+int HarbourAztecCodeGenerator::ecLevel() const
+{
+ return iPrivate->iEcLevel;
+}
+
+void HarbourAztecCodeGenerator::setEcLevel(int aValue)
+{
+ iPrivate->setEcLevel(aValue);
+}
+
QString HarbourAztecCodeGenerator::code() const
{
return iPrivate->iCode;
@@ -179,12 +224,12 @@
return iPrivate->iTask != Q_NULLPTR;
}
-QByteArray HarbourAztecCodeGenerator::generate(QString aText)
+QByteArray HarbourAztecCodeGenerator::generate(QString aText, int aEcLevel)
{
HDEBUG(aText);
QByteArray in(aText.toUtf8()), out;
AztecSymbol* aztec = aztec_encode_inv(in.constData(), in.size(),
- AZTEC_CORRECTION_DEFAULT);
+ Private::realEcLevel(aEcLevel));
if (aztec) {
const int bytesPerRow = (aztec->size + 7) / 8;
out.reserve(bytesPerRow * aztec->size);
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/src/HarbourBase45.cpp
^
|
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "HarbourBase45.h"
+
+#include "HarbourDebug.h"
+
+// ==========================================================================
+// HarbourBase45::Private
+// ==========================================================================
+
+class HarbourBase45::Private {
+public:
+ enum {
+ BASE = 45,
+ BASE2 = BASE * BASE,
+ REVERSE_MAP_SIZE = 91
+ };
+ static const char mapBase45[BASE];
+ static const int reverseMapBase45[REVERSE_MAP_SIZE];
+ static bool isValidChar(uint x);
+};
+
+const char HarbourBase45::Private::mapBase45[HarbourBase45::Private::BASE] = {
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
+ 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
+ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
+ 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*',
+ '+', '-', '.', '/', ':'
+};
+
+const int HarbourBase45::Private::reverseMapBase45[HarbourBase45::Private::REVERSE_MAP_SIZE] = {
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ 36, -1, -1, -1, 37, 38, -1, -1,
+ -1, -1, 39, 40, -1, 41, 42, 43,
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 44, -1, -1, -1, -1, -1,
+ -1, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35
+};
+
+inline bool HarbourBase45::Private::isValidChar(uint x)
+{
+ return (x < Private::REVERSE_MAP_SIZE) && Private::reverseMapBase45[x] >= 0;
+}
+
+// ==========================================================================
+// HarbourBase45::Private
+// ==========================================================================
+
+bool HarbourBase45::isValidBase45(QString aBase45)
+{
+ const int len = aBase45.length();
+
+ if (!((len % 3) % 2)) {
+ const QChar* chars = aBase45.constData();
+ int i = 0;
+
+ while ((i + 2) < len) {
+ const uint c = chars[i++].unicode();
+ const uint d = chars[i++].unicode();
+ const uint e = chars[i++].unicode();
+
+ if (!Private::isValidChar(c) ||
+ !Private::isValidChar(d) ||
+ !Private::isValidChar(e) ||
+ (Private::reverseMapBase45[c] +
+ Private::reverseMapBase45[d] * Private::BASE +
+ Private::reverseMapBase45[e] * Private::BASE2) > 0xffff) {
+ return false;
+ }
+ }
+
+ if (i < len) {
+ const uint c = chars[i++].unicode();
+ const uint d = chars[i++].unicode();
+
+ if (!Private::isValidChar(c) ||
+ !Private::isValidChar(d) ||
+ (Private::reverseMapBase45[c] +
+ Private::reverseMapBase45[d] * Private::BASE) > 0xff) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+}
+
+QByteArray HarbourBase45::fromBase45(QString aBase45)
+{
+ QByteArray out;
+ const int len = aBase45.length();
+ const int tail = (len % 3);
+
+ if (!(tail % 2)) {
+ const QChar* chars = aBase45.constData();
+ int i = 0;
+
+ out.reserve(len/3*2 + tail/2);
+ while ((i + 2) < len) {
+ const uint c = chars[i++].unicode();
+ const uint d = chars[i++].unicode();
+ const uint e = chars[i++].unicode();
+
+ if (!Private::isValidChar(c) ||
+ !Private::isValidChar(d) ||
+ !Private::isValidChar(e)) {
+ return QByteArray();
+ }
+ const uint n = Private::reverseMapBase45[c] +
+ Private::reverseMapBase45[d] * Private::BASE +
+ Private::reverseMapBase45[e] * Private::BASE2;
+ if (n > 0xffff) {
+ return QByteArray();
+ }
+ char ab[2];
+ ab[0] = (char)(n >> 8);
+ ab[1] = (char)n;
+ out.append(ab, sizeof(ab));
+ }
+
+ if (i < len) {
+ const uint c = chars[i++].unicode();
+ const uint d = chars[i++].unicode();
+
+ if (!Private::isValidChar(c) ||
+ !Private::isValidChar(d)) {
+ return QByteArray();
+ }
+ const uint a = Private::reverseMapBase45[c] +
+ Private::reverseMapBase45[d] * Private::BASE;
+ if (a > 0xff) {
+ return QByteArray();
+ }
+ out.append((char)a);
+ }
+ }
+ return out;
+}
+
+QString HarbourBase45::toBase45(QByteArray aBinary)
+{
+ const uchar* ptr = (uchar*)aBinary.constData();
+ const int n = aBinary.size();
+ int i;
+
+ QString str;
+ str.reserve(3 * (n / 2) + 2 * (n % 2));
+ for (i = 0; (i + 1) < n; i += 2) {
+ uint e = (uint)(ptr[i]) * 256 + ptr[i+1];
+ const uchar c = (uchar)(e % Private::BASE);
+ e = (e - c)/Private::BASE;
+ const uchar d = (uchar)(e % Private::BASE);
+ e = (e - d)/Private::BASE;
+ str.append(QChar::fromLatin1(Private::mapBase45[c]));
+ str.append(QChar::fromLatin1(Private::mapBase45[d]));
+ str.append(QChar::fromLatin1(Private::mapBase45[e]));
+ }
+ if (i < n) {
+ uchar d = ptr[i];
+ const uchar c = d % Private::BASE;
+ d = (d - c)/Private::BASE;
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/src/HarbourObject.cpp
^
|
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "HarbourObject.h"
+
+HarbourObject::HarbourObject(QObject* aParent) :
+ QObject(aParent)
+{
+}
+
+QQmlListProperty<QObject> HarbourObject::children()
+{
+ return QQmlListProperty<QObject>(this, iChidren);
+}
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/src/HarbourProcessState.cpp
^
|
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "HarbourProcessState.h"
+#include "HarbourDebug.h"
+
+#include <unistd.h>
+
+HarbourProcessState::HarbourProcessState(QObject* aParent) :
+ QObject(aParent)
+{
+}
+
+// Callback for qmlRegisterSingletonType<HarbourProcessState>
+QObject* HarbourProcessState::createSingleton(QQmlEngine*, QJSEngine*)
+{
+ return new HarbourProcessState;
+}
+
+bool HarbourProcessState::isJailedApp()
+{
+ static int processJailed = -1;
+
+ // Apps are not supposed to be started by the root systemd process.
+ // Firejail tells us that our parent pid is 1.
+ // We could additionally check that /proc contains only our and
+ // parent pids, if ppid check becomes not reliable enough.
+ if (processJailed < 0) {
+ bool simulate = false;
+ const char* var = "HARBOUR_JAIL_STATE";
+ processJailed = QString(qgetenv(var)).toInt(&simulate);
+ if (!simulate || processJailed < 0) {
+ if (getppid() == 1) {
+ HWARN("We are jailed!");
+ processJailed = 1;
+ } else{
+ HDEBUG("Cool, we are free!");
+ processJailed = 0;
+ }
+ } else {
+ HWARN(var << processJailed);
+ }
+ }
+ return processJailed > 0;
+}
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/src/HarbourQrCodeGenerator.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2021 Jolla Ltd.
+ * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -11,8 +11,8 @@
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
* distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
@@ -45,25 +45,31 @@
// HarbourQrCodeGenerator::Task
// ==========================================================================
-class HarbourQrCodeGenerator::Task : public HarbourTask {
+class HarbourQrCodeGenerator::Task : public HarbourTask
+{
Q_OBJECT
+
public:
- Task(QThreadPool* aPool, QString aText);
+ Task(QThreadPool* aPool, QString aText, ECLevel aEcLevel);
void performTask() Q_DECL_OVERRIDE;
+
public:
QString iText;
QString iCode;
+ ECLevel iEcLevel;
};
-HarbourQrCodeGenerator::Task::Task(QThreadPool* aPool, QString aText) :
+HarbourQrCodeGenerator::Task::Task(QThreadPool* aPool, QString aText,
+ ECLevel aEcLevel) :
HarbourTask(aPool),
- iText(aText)
+ iText(aText),
+ iEcLevel(aEcLevel)
{
}
void HarbourQrCodeGenerator::Task::performTask()
{
- QByteArray bytes(generate(iText));
+ QByteArray bytes(generate(iText, iEcLevel));
if (!bytes.isEmpty()) {
iCode = HarbourBase32::toBase32(bytes);
}
@@ -73,7 +79,8 @@
// HarbourQrCodeGenerator::Private
// ==========================================================================
-class HarbourQrCodeGenerator::Private : public QObject {
+class HarbourQrCodeGenerator::Private : public QObject
+{
Q_OBJECT
public:
@@ -82,6 +89,10 @@
HarbourQrCodeGenerator* parentObject() const;
void setText(QString aValue);
+ void setEcLevel(int aValue);
+ void regenerate();
+
+ static QRecLevel realEcLevel(ECLevel aEcLevel);
public Q_SLOTS:
void onTaskDone();
@@ -89,6 +100,7 @@
public:
QThreadPool* iThreadPool;
Task* iTask;
+ ECLevel iEcLevel;
QString iText;
QString iCode;
};
@@ -96,7 +108,8 @@
HarbourQrCodeGenerator::Private::Private(HarbourQrCodeGenerator* aParent) :
QObject(aParent),
iThreadPool(new QThreadPool(this)),
- iTask(Q_NULLPTR)
+ iTask(Q_NULLPTR),
+ iEcLevel(ECLevelDefault)
{
// Serialize the tasks:
iThreadPool->setMaxThreadCount(1);
@@ -104,6 +117,7 @@
HarbourQrCodeGenerator::Private::~Private()
{
+ if (iTask) iTask->release();
iThreadPool->waitForDone();
}
@@ -112,19 +126,52 @@
return qobject_cast<HarbourQrCodeGenerator*>(parent());
}
+QRecLevel HarbourQrCodeGenerator::Private::realEcLevel(ECLevel aEcLevel)
+{
+ switch (aEcLevel) {
+ case ECLevel_L: return QR_ECLEVEL_L;
+ case ECLevel_M: return QR_ECLEVEL_M;
+ case ECLevel_Q: return QR_ECLEVEL_Q;
+ case ECLevel_H: return QR_ECLEVEL_H;
+ case ECLevelDefault:
+ case ECLevelCount:
+ break;
+ }
+ return QR_ECLEVEL_M; // default
+}
+
void HarbourQrCodeGenerator::Private::setText(QString aText)
{
if (iText != aText) {
iText = aText;
- HarbourQrCodeGenerator* obj = parentObject();
- const bool wasRunning = (iTask != Q_NULLPTR);
- if (iTask) iTask->release(this);
- iTask = new Task(iThreadPool, aText);
- iTask->submit(this, SLOT(onTaskDone()));
- Q_EMIT obj->textChanged();
- if (!wasRunning) {
- Q_EMIT obj->runningChanged();
+ regenerate();
+ Q_EMIT parentObject()->textChanged();
+ }
+}
+
+void HarbourQrCodeGenerator::Private::setEcLevel(int aValue)
+{
+ const ECLevel level = (aValue < ECLevelDefault) ? ECLevelDefault :
+ (aValue > ECLevelHighest) ? ECLevelHighest : (ECLevel)aValue;
+ if (iEcLevel != level) {
+ const QRecLevel prevRealLevel = realEcLevel(iEcLevel);
+ iEcLevel = level;
+ if (realEcLevel(level) != prevRealLevel) {
+ regenerate();
}
+ Q_EMIT parentObject()->ecLevelChanged();
+ }
+}
+
+void HarbourQrCodeGenerator::Private::regenerate()
+{
+ HarbourQrCodeGenerator* obj = parentObject();
+ const bool wasRunning = (iTask != Q_NULLPTR);
+ if (iTask) iTask->release();
+ iTask = new Task(iThreadPool, iText, iEcLevel);
+ iTask->submit(this, SLOT(onTaskDone()));
+ if (!wasRunning) {
+ Q_EMIT obj->runningChanged();
}
}
@@ -156,7 +203,7 @@
// Callback for qmlRegisterSingletonType<HarbourQrCodeGenerator>
QObject* HarbourQrCodeGenerator::createSingleton(QQmlEngine* aEngine, QJSEngine*)
{
- return new HarbourQrCodeGenerator(aEngine);
+ return new HarbourQrCodeGenerator(); // Singleton doesn't need a parent
}
QString HarbourQrCodeGenerator::text() const
@@ -169,6 +216,16 @@
iPrivate->setText(aValue);
}
+HarbourQrCodeGenerator::ECLevel HarbourQrCodeGenerator::ecLevel() const
+{
+ return iPrivate->iEcLevel;
+}
+
+void HarbourQrCodeGenerator::setEcLevel(int aValue)
+{
+ iPrivate->setEcLevel(aValue);
+}
+
QString HarbourQrCodeGenerator::code() const
{
return iPrivate->iCode;
@@ -179,10 +236,11 @@
return iPrivate->iTask != Q_NULLPTR;
}
-QByteArray HarbourQrCodeGenerator::generate(QString aText)
+QByteArray HarbourQrCodeGenerator::generate(QString aText, ECLevel aEcLevel)
{
QByteArray in(aText.toUtf8()), out;
- QRcode* code = QRcode_encodeString(in.constData(), 0, QR_ECLEVEL_M, QR_MODE_8, true);
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/src/HarbourSystemInfo.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2020 Jolla Ltd.
- * Copyright (C) 2020 Slava Monich <slava@monich.com>
+ * Copyright (C) 2020-2021 Jolla Ltd.
+ * Copyright (C) 2020-2021 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -44,6 +44,11 @@
#include <QFile>
#include <QTextStream>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
// ==========================================================================
// HarbourSystemInfo::Private
// ==========================================================================
@@ -63,10 +68,13 @@
static int compareVersions(const QVector<uint> aVersion1, const QVector<uint> aVersion2);
static int compareVersions(const QVector<uint> aVersion1, const QString aVersion2);
+ QString getPackageVersion(QString aPackage);
+
public:
QString iName;
QString iVersion;
QVector<uint> iParsedVersion;
+ QMap<QString,QString> iPackageVersions;
};
const QString HarbourSystemInfo::Private::NAME("NAME");
@@ -159,6 +167,21 @@
return compareVersions(aVersion1, Private::parseVersion(aVersion2));
}
+QString HarbourSystemInfo::Private::getPackageVersion(QString aPackage)
+{
+ QString version;
+ if (!aPackage.isEmpty()) {
+ version = iPackageVersions.value(aPackage);
+ if (version.isEmpty()) {
+ version = HarbourSystemInfo::queryPackageVersion(aPackage);
+ if (!version.isEmpty()) {
+ iPackageVersions.insert(aPackage, version);
+ }
+ }
+ }
+ return version;
+}
+
// ==========================================================================
// HarbourSystemInfo
// ==========================================================================
@@ -192,6 +215,11 @@
return iPrivate->iVersion;
}
+QString HarbourSystemInfo::packageVersion(QString aPackage)
+{
+ return iPrivate->getPackageVersion(aPackage);
+}
+
int HarbourSystemInfo::osVersionCompare(QString aVersion)
{
return Private::compareVersions(iPrivate->iParsedVersion, aVersion);
@@ -203,3 +231,52 @@
const QString os(Private::parseOsRelease(keys).value(Private::VERSION_ID));
return Private::compareVersions(Private::parseVersion(os), aVersion);
}
+
+int HarbourSystemInfo::compareVersions(QString aVersion1, QString aVersion2)
+{
+ return Private::compareVersions(Private::parseVersion(aVersion1),
+ Private::parseVersion(aVersion2));
+}
+
+QString HarbourSystemInfo::queryPackageVersion(QString aPackage)
+{
+ QString version;
+ int fds[2];
+ if (pipe(fds) == 0) {
+ pid_t pid = fork();
+ if (!pid) {
+ const QByteArray package(aPackage.toLatin1());
+ const char* argv[6];
+ argv[0] = "rpm";
+ argv[1] = "-q";
+ argv[2] = "--qf";
+ argv[3] = "%{version}";
+ argv[4] = package.constData();
+ argv[5] = NULL;
+ while ((dup2(fds[1], STDOUT_FILENO) == -1) && (errno == EINTR));
+ execvp(argv[0], (char**)argv);
+ exit(1);
+ }
+ close(fds[1]);
+
+ // There shouldn't be much output
+ QByteArray out;
+ const int chunk = 16;
+ ssize_t n = 0;
+ do {
+ const int size = out.size();
+ out.resize(size + chunk);
+ while ((n = read(fds[0], out.data() + size, chunk)) == -1 && (errno == EINTR));
+ out.resize(size + qMax(n, (ssize_t)0));
+ } while (n > 0);
+
+ // Parse the version
+ if (out.size() > 0) {
+ version = QString::fromLatin1(out);
+ HDEBUG(qPrintable(aPackage) << qPrintable(version));
+ }
+ waitpid(pid, NULL, 0);
+ close(fds[0]);
+ }
+ return version;
+}
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/test/Makefile
^
|
@@ -0,0 +1,6 @@
+# -*- Mode: makefile-gmake -*-
+
+all:
+%:
+ @$(MAKE) -C TestHarbourBase32 $*
+ @$(MAKE) -C TestHarbourBase45 $*
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/test/Makefile.common
^
|
@@ -0,0 +1,200 @@
+# -*- Mode: makefile-gmake -*-
+
+.PHONY: clean all debug release coverage
+
+#
+# Real test makefile defines EXE (and possibly SRC) and includes this one.
+#
+
+ifndef EXE
+${error EXE not defined}
+endif
+
+SRC ?= $(EXE).cpp
+
+#
+# Required packages
+#
+
+PKGS += Qt5Core glib-2.0
+
+#
+# Default target
+#
+
+all: debug release
+
+#
+# Directories
+#
+
+SRC_DIR = .
+TOP_DIR = ../..
+HARBOUR_DIR = $(TOP_DIR)
+BUILD_DIR = build
+DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
+RELEASE_BUILD_DIR = $(BUILD_DIR)/release
+COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage
+
+#
+# Tools and flags
+#
+
+CC = $(CROSS_COMPILE)gcc
+LD = $(CC)
+MOC = qtchooser -run-tool=moc -qt=5
+WARNINGS = -Wall
+INCLUDES = -I$(BUILD_DIR) -I$(HARBOUR_DIR)/include
+BASE_FLAGS = -fPIC
+BASE_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS)
+BASE_CFLAGS = $(BASE_FLAGS) $(CFLAGS)
+FULL_CFLAGS = $(BASE_CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \
+ $(shell pkg-config --cflags $(PKGS))
+FULL_LDFLAGS = $(BASE_LDFLAGS)
+LIBS = $(shell pkg-config --libs $(PKGS)) -lstdc++
+QUIET_MAKE = make --no-print-directory
+DEBUG_FLAGS = -g
+RELEASE_FLAGS =
+COVERAGE_FLAGS = -g
+
+DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS)
+RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS)
+COVERAGE_LDFLAGS = $(FULL_LDFLAGS) $(COVERAGE_FLAGS) --coverage
+
+DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG -DHARBOUR_DEBUG
+RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
+COVERAGE_CFLAGS = $(FULL_CFLAGS) $(COVERAGE_FLAGS) --coverage
+
+#
+# Files
+#
+
+DEBUG_OBJS = \
+ $(MOC_H:%.h=$(DEBUG_BUILD_DIR)/moc_h_%.o) \
+ $(MOC_CPP:%.cpp=$(DEBUG_BUILD_DIR)/moc_cpp_%.o) \
+ $(SRC:%.cpp=$(DEBUG_BUILD_DIR)/%.o) \
+ $(HARBOUR_SRC:%.cpp=$(DEBUG_BUILD_DIR)/harbour_%.o)
+RELEASE_OBJS = \
+ $(MOC_H:%.h=$(RELEASE_BUILD_DIR)/moc_h_%.o) \
+ $(MOC_CPP:%.cpp=$(RELEASE_BUILD_DIR)/moc_cpp_%.o) \
+ $(SRC:%.cpp=$(RELEASE_BUILD_DIR)/%.o) \
+ $(HARBOUR_SRC:%.cpp=$(RELEASE_BUILD_DIR)/harbour_%.o)
+COVERAGE_OBJS = \
+ $(MOC_H:%.h=$(COVERAGE_BUILD_DIR)/moc_h_%.o) \
+ $(MOC_CPP:%.cpp=$(COVERAGE_BUILD_DIR)/moc_cpp_%.o) \
+ $(SRC:%.cpp=$(COVERAGE_BUILD_DIR)/%.o) \
+ $(HARBOUR_SRC:%.cpp=$(COVERAGE_BUILD_DIR)/harbour_%.o)
+
+#
+# Dependencies
+#
+
+DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d) $(COVERAGE_OBJS:%.o=%.d)
+ifneq ($(MAKECMDGOALS),clean)
+ifneq ($(strip $(DEPS)),)
+-include $(DEPS)
+endif
+endif
+
+$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
+$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
+$(COVERAGE_OBJS): | $(COVERAGE_BUILD_DIR)
+
+#
+# Rules
+#
+
+DEBUG_EXE = $(DEBUG_BUILD_DIR)/$(EXE)
+RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
+COVERAGE_EXE = $(COVERAGE_BUILD_DIR)/$(EXE)
+
+debug: $(DEBUG_EXE)
+
+release: $(RELEASE_EXE)
+
+coverage: $(COVERAGE_EXE)
+
+clean:
+ rm -f *~
+ rm -fr $(BUILD_DIR)
+
+test_banner:
+ @echo "===========" $(EXE) "=========== "
+
+test: test_banner debug
+ @$(DEBUG_EXE)
+
+valgrind: test_banner debug
+ @G_DEBUG=gc-friendly G_SLICE=always-malloc valgrind --tool=memcheck --leak-check=full --show-possibly-lost=no $(DEBUG_EXE)
+
+$(BUILD_DIR):
+ mkdir -p $@
+
+$(DEBUG_BUILD_DIR):
+ mkdir -p $@
+
+$(RELEASE_BUILD_DIR):
+ mkdir -p $@
+
+$(COVERAGE_BUILD_DIR):
+ mkdir -p $@
+
+$(BUILD_DIR)/moc_%.cpp : $(APP_DIR)/%.h
+ $(MOC) $< -o $@
+
+$(BUILD_DIR)/%.moc : $(APP_DIR)/%.cpp
+ $(MOC) $< -o $@
+
+$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.cpp
+ $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.cpp
+ $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(COVERAGE_BUILD_DIR)/%.o : $(SRC_DIR)/%.cpp
+ $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_BUILD_DIR)/moc_h_%.o : $(BUILD_DIR)/moc_%.cpp $(BUILD_DIR)
+ $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/moc_h_%.o : $(BUILD_DIR)/moc_%.cpp $(BUILD_DIR)
+ $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(COVERAGE_BUILD_DIR)/moc_h_%.o : $(BUILD_DIR)/moc_%.cpp $(BUILD_DIR)
+ $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_DIR)/%.cpp $(BUILD_DIR)/%.moc
+ $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_DIR)/%.cpp $(BUILD_DIR)/%.moc
+ $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(COVERAGE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_DIR)/%.cpp $(BUILD_DIR)/%.moc
+ $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_BUILD_DIR)/app_%.o : $(APP_DIR)/%.cpp
+ $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/app_%.o : $(APP_DIR)/%.cpp
+ $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(COVERAGE_BUILD_DIR)/app_%.o : $(APP_DIR)/%.cpp
+ $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_BUILD_DIR)/harbour_%.o : $(HARBOUR_DIR)/src/%.cpp
+ $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(RELEASE_BUILD_DIR)/harbour_%.o : $(HARBOUR_DIR)/src/%.cpp
+ $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(COVERAGE_BUILD_DIR)/harbour_%.o : $(HARBOUR_DIR)/src/%.cpp
+ $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
+
+$(DEBUG_EXE): $(DEBUG_OBJS)
+ $(LD) $(DEBUG_LDFLAGS) $^ $(LIBS) -o $@
+
+$(RELEASE_EXE): $(RELEASE_OBJS)
+ $(LD) $(RELEASE_LDFLAGS) $^ $(LIBS) -o $@
+
+$(COVERAGE_EXE): $(COVERAGE_OBJS)
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/test/TestHarbourBase32/Makefile
^
|
@@ -0,0 +1,6 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = TestHarbourBase32
+HARBOUR_SRC = HarbourBase32.cpp
+
+include ../Makefile.common
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/test/TestHarbourBase32/TestHarbourBase32.cpp
^
|
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "HarbourBase32.h"
+#include "HarbourDebug.h"
+
+#include <glib.h>
+
+/*==========================================================================*
+ * isValidBase45
+ *==========================================================================*/
+
+static
+void
+test_isValidBase32(
+ void)
+{
+ g_assert(HarbourBase32::isValidBase32("AEBAGBAFAYDQQCIKBMGA2DQPCAIREEYUCULBOGI2DMOB2HQ7"));
+ g_assert(HarbourBase32::isValidBase32("aebagbaf aydqqcik bmga2dqp caireeyu culbogi2 dmob2hq7"));
+ g_assert(HarbourBase32::isValidBase32("ae"));
+ g_assert(!HarbourBase32::isValidBase32("aeb"));
+ g_assert(HarbourBase32::isValidBase32("aeba"));
+ g_assert(HarbourBase32::isValidBase32("aebag"));
+ g_assert(!HarbourBase32::isValidBase32("aebagb"));
+ g_assert(!HarbourBase32::isValidBase32("aebagb= x"));
+ g_assert(HarbourBase32::isValidBase32("aebagba"));
+ g_assert(HarbourBase32::isValidBase32("aebagbaf"));
+ g_assert(HarbourBase32::isValidBase32("aebagbafa"));
+ g_assert(HarbourBase32::isValidBase32("aebagbafay"));
+ g_assert(!HarbourBase32::isValidBase32(QString()));
+ g_assert(!HarbourBase32::isValidBase32(" "));
+ g_assert(!HarbourBase32::isValidBase32("01234567"));
+ g_assert(!HarbourBase32::isValidBase32("88888888"));
+ g_assert(!HarbourBase32::isValidBase32("{}"));
+ g_assert(!HarbourBase32::isValidBase32("[]"));
+}
+
+/*==========================================================================*
+ * fromBase32
+ *==========================================================================*/
+
+static
+void
+test_fromBase32(
+ void)
+{
+ static const char out[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
+ 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
+ 0x15, 0x16, 0x17, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
+ };
+ QString in1("AEBAGBAFAYDQQCIKBMGA2DQPCAIREEYUCULBOGI2DMOB2HQ7");
+ QString in2("aebagbaf aydqqcik bmga2dqp caireeyu culbogi2 dmob2hq7");
+ QByteArray out1(HarbourBase32::fromBase32(in1));
+ QByteArray out2(HarbourBase32::fromBase32(in2));
+ g_assert(out1 == out2);
+ g_assert(out1 == QByteArray(out, sizeof(out)));
+ g_assert(HarbourBase32::fromBase32("ae") == QByteArray(out, 1));
+ g_assert(HarbourBase32::fromBase32("aeb").isEmpty());
+ g_assert(HarbourBase32::fromBase32("aeba") == QByteArray(out, 2));
+ g_assert(HarbourBase32::fromBase32("aebag") == QByteArray(out, 3));
+ g_assert(HarbourBase32::fromBase32("aebagb").isEmpty());
+ g_assert(HarbourBase32::fromBase32("aebagb=x").isEmpty());
+ g_assert(HarbourBase32::fromBase32("aebagb= x").isEmpty());
+ g_assert(HarbourBase32::fromBase32("aebagba") == QByteArray(out, 4));
+ g_assert(HarbourBase32::fromBase32("aebagbaf") == QByteArray(out, 5));
+ g_assert(HarbourBase32::fromBase32("aebagbafa") == QByteArray(out, 5));
+ g_assert(HarbourBase32::fromBase32("aebagbafay") == QByteArray(out, 6));
+ g_assert(HarbourBase32::fromBase32(QString()).isEmpty());
+ g_assert(HarbourBase32::fromBase32(" ").isEmpty());
+ g_assert(HarbourBase32::fromBase32("01234567").isEmpty());
+ g_assert(HarbourBase32::fromBase32("88888888").isEmpty());
+ g_assert(HarbourBase32::fromBase32("{}").isEmpty());
+ g_assert(HarbourBase32::fromBase32("[]").isEmpty());
+}
+
+/*==========================================================================*
+ * base32pad
+ *==========================================================================*/
+
+static
+void
+test_base32pad(
+ void)
+{
+ static const char out[] = {
+ 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23
+ };
+ QString in1("DMOB2HQ7EA====="); // One pad character missing
+ QString in2("DMOB2HQ7EAQQ====="); // One extra pagging character
+ QString in3("DMOB2HQ7EAQSE== ="); // Space is ignored
+ QString in4("DMOB2HQ7EAQSEIY=");
+ g_assert(HarbourBase32::fromBase32(in1) == QByteArray(out, sizeof(out) - 3));
+ g_assert(HarbourBase32::fromBase32(in2) == QByteArray(out, sizeof(out) - 2));
+ g_assert(HarbourBase32::fromBase32(in3) == QByteArray(out, sizeof(out) - 1));
+ g_assert(HarbourBase32::fromBase32(in4) == QByteArray(out, sizeof(out)));
+ g_assert(HarbourBase32::fromBase32(QString("=================")).isEmpty());
+ g_assert(HarbourBase32::fromBase32(QString("=DMOB2HQ7EAQSEIY=")).isEmpty());
+ g_assert(HarbourBase32::fromBase32(QString("DMOB2HQ7EB=")).isEmpty());
+}
+
+/*==========================================================================*
+ * toBase32
+ *==========================================================================*/
+
+static
+void
+test_toBase32(
+ void)
+{
+ static const char in[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
+ 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
+ 0x15, 0x16, 0x17, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
+ };
+ QString out("aebagbafaydqqcikbmga2dqpcaireeyuculbogi2dmob2hq7");
+ g_assert(HarbourBase32::toBase32(QByteArray()).isEmpty());
+ g_assert(HarbourBase32::toBase32(QByteArray(in, sizeof(in))) == out);
+}
+
+/*==========================================================================*
+ * rfc4648
+ *==========================================================================*/
+
+static
+void
+test_rfc4648(
+ void)
+{
+ // Test vectors from RFC 4648
+ static const char* test[][2] = {
+ { "f", "MY======" },
+ { "fo", "MZXQ====" },
+ { "foo", "MZXW6===" },
+ { "foob", "MZXW6YQ=" },
+ { "fooba", "MZXW6YTB" },
+ { "foobar", "MZXW6YTBOI======" }
+ };
+
+ for (guint i = 0; i < G_N_ELEMENTS(test); i++) {
+ QByteArray data(test[i][0]);
+ QString base32(test[i][1]);
+ g_assert(HarbourBase32::isValidBase32(base32));
+ g_assert(HarbourBase32::fromBase32(base32) == data);
+ g_assert(HarbourBase32::toBase32(data, false) == base32);
+ }
+}
+
+/*==========================================================================*
+ * Common
+ *==========================================================================*/
+
+#define TEST_(name) "/HarbourBase32/" name
+
+int main(int argc, char* argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+ g_test_add_func(TEST_("isValidBase32"), test_isValidBase32);
+ g_test_add_func(TEST_("fromBase32"), test_fromBase32);
+ g_test_add_func(TEST_("base32pad"), test_base32pad);
+ g_test_add_func(TEST_("rfc4648"), test_rfc4648);
+ g_test_add_func(TEST_("toBase32"), test_toBase32);
+ return g_test_run();
+}
+
+/*
+ * Local Variables:
+ * mode: C++
+ * c-basic-offset: 4
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/test/TestHarbourBase45/Makefile
^
|
@@ -0,0 +1,6 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = TestHarbourBase45
+HARBOUR_SRC = HarbourBase45.cpp
+
+include ../Makefile.common
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/test/TestHarbourBase45/TestHarbourBase45.cpp
^
|
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2021 Jolla Ltd.
+ * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "HarbourBase45.h"
+#include "HarbourDebug.h"
+
+#include <glib.h>
+
+/*==========================================================================*
+ * isValidBase45
+ *==========================================================================*/
+
+static
+void
+test_isValidBase45(
+ void)
+{
+ g_assert(HarbourBase45::isValidBase45("")); // Empty is considered valid
+ g_assert(HarbourBase45::isValidBase45("BB8"));
+ g_assert(HarbourBase45::isValidBase45("%69 VD92EX0"));
+ g_assert(HarbourBase45::isValidBase45("UJCLQE7W581"));
+ g_assert(!HarbourBase45::isValidBase45("AA("));
+ g_assert(!HarbourBase45::isValidBase45("A(A"));
+ g_assert(!HarbourBase45::isValidBase45("(AA"));
+ g_assert(!HarbourBase45::isValidBase45("A("));
+ g_assert(!HarbourBase45::isValidBase45("A["));
+ g_assert(!HarbourBase45::isValidBase45("[A"));
+ g_assert(!HarbourBase45::isValidBase45("A"));
+ g_assert(!HarbourBase45::isValidBase45("ZZ"));
+ g_assert(!HarbourBase45::isValidBase45("ZZZ"));
+}
+
+/*==========================================================================*
+ * toBase45
+ *==========================================================================*/
+
+static
+void
+test_toBase45(
+ void)
+{
+ g_assert(HarbourBase45::toBase45(QByteArray()).isEmpty());
+ // Examples from draft-faltstrom-base45-07
+ g_assert(HarbourBase45::toBase45(QByteArray("AB")) == QString("BB8"));
+ g_assert(HarbourBase45::toBase45(QByteArray("Hello!!")) == QString("%69 VD92EX0"));
+ g_assert(HarbourBase45::toBase45(QByteArray("base-45")) == QString("UJCLQE7W581"));
+}
+
+/*==========================================================================*
+ * fromBase45
+ *==========================================================================*/
+
+static
+void
+test_fromBase45(
+ void)
+{
+ // Invalid
+ g_assert(HarbourBase45::fromBase45(QByteArray("AA[")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("A[A")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("[AA")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("AA(")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("A(A")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("(AA")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("A(")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("A[")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("[A")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("A")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("ZZ")).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("ZZZ")).isEmpty());
+ // Valid
+ g_assert(HarbourBase45::fromBase45(QByteArray()).isEmpty());
+ g_assert(HarbourBase45::fromBase45(QByteArray("BB8")) == QByteArray("AB"));
+ g_assert(HarbourBase45::fromBase45(QByteArray("%69 VD92EX0")) == QByteArray("Hello!!"));
+ g_assert(HarbourBase45::fromBase45(QByteArray("UJCLQE7W581")) == QByteArray("base-45"));
+}
+
+/*==========================================================================*
+ * Common
+ *==========================================================================*/
+
+#define TEST_(name) "/HarbourBase45/" name
+
+int main(int argc, char* argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+ g_test_add_func(TEST_("isValidBase45"), test_isValidBase45);
+ g_test_add_func(TEST_("fromBase45"), test_fromBase45);
+ g_test_add_func(TEST_("toBase45"), test_toBase45);
+ return g_test_run();
+}
+
+/*
+ * Local Variables:
+ * mode: C++
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/test/coverage/.gitignore
^
|
@@ -0,0 +1,4 @@
+app.gcov
+full.gcov
+report
+*~
|
[-]
[+]
|
Added |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/qmlplugin/harbour-lib/test/coverage/run
^
|
@@ -0,0 +1,55 @@
+#!/bin/bash
+#
+# This script requires lcov, dirname
+#
+
+TESTS="\
+TestHarbourBase32 \
+TestHarbourBase45"
+
+function err() {
+ echo "*** ERROR!" $1
+ exit 1
+}
+
+# Check the required tools
+which lcov >> /dev/null || err "Please install lcov"
+which dirname >> /dev/null || err "Please install dirname"
+
+# LCOV 1.10 has branch coverage disabled per default
+# Previous versions didn't have the --rc option
+if [ ! -z "$(lcov --help | grep ' --rc ')" ] ; then
+ LCOV_OPT="--rc lcov_branch_coverage=1"
+ GENHTML_OPT="--branch-coverage"
+fi
+
+pushd `dirname $0` > /dev/null
+COV_DIR="$PWD"
+pushd .. > /dev/null
+TEST_DIR="$PWD"
+pushd .. > /dev/null
+TOP_DIR="$PWD"
+popd > /dev/null
+popd > /dev/null
+popd > /dev/null
+
+FULL_COV="$COV_DIR/full.gcov"
+APP_COV="$COV_DIR/app.gcov"
+
+make -C "$TEST_DIR" clean
+rm -f "$FULL_COV" "$APP_COV"
+TESTS_COV=
+
+for t in $TESTS ; do
+ pushd "$TEST_DIR/$t"
+ make -C "$TEST_DIR/$t" clean coverage || exit 1
+ build/coverage/$t || exit 1
+ TEST_COV="$TEST_DIR/$t/build/coverage/$t.cov"
+ lcov $LCOV_OPT -c -d build/coverage -o "$TEST_COV" || exit 1
+ TESTS_COV+="-a $TEST_COV "
+ popd
+done
+
+lcov $LCOV_OPT $TESTS_COV -o "$FULL_COV" || exit 1
+lcov $LCOV_OPT -e "$FULL_COV" "$TOP_DIR/src/*" -o "$APP_COV" || exit 1
+genhtml $GENHTML_OPT "$APP_COV" -t "HarbourLib" --output-directory "$COV_DIR/report" || exit 1
|
[-]
[+]
|
Changed |
_service:tar_git:sailfish-qrshare-1.1.2.tar.gz/shareplugin/qml/QRShare.qml
^
|
@@ -19,6 +19,7 @@
id: qrCodeGenerator
text: page.text
+ ecLevel: QrCodeGenerator.ECLevelLowest
readonly property string name: "QR code"
readonly property string baseName: "qr-code"
//: Placeholder text
@@ -30,6 +31,7 @@
id: aztecCodeGenerator
text: page.text
+ ecLevel: AztecCodeGenerator.ECLevelLowest
readonly property string name: "Aztec"
readonly property string baseName: "aztec-code"
//: Placeholder text
|