[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [jungle/mockPoc] /: Add a GuessItJob
From: Vishesh Handa <me () vhanda ! in>
Date: 2014-10-01 0:18:32
Message-ID: E1XZ7cm-00045S-0y () scm ! kde ! org
[Download RAW message or body]
Git commit 4fd6c016327a794f31992de1279a8bbf9d58b42a by Vishesh Handa.
Committed on 04/09/2014 at 23:29.
Pushed by vhanda into branch 'mockPoc'.
Add a GuessItJob
M +1 -1 CMakeLists.txt
M +8 -1 autotest/CMakeLists.txt
A +70 -0 autotest/guessitjobtest.cpp [License: LGPL (v2.1+)]
M +3 -0 autotest/shared.h
A +34 -0 src/guess.py
A +72 -0 src/guessitjob.cpp [License: LGPL (v2.1+)]
C +30 -9 src/guessitjob.h [from: autotest/shared.h - 060% similarity]
C +13 -10 src/interfaces/dataqueueinterface.h [from: autotest/shared.h - 070% similarity]
http://commits.kde.org/jungle/4fd6c016327a794f31992de1279a8bbf9d58b42a
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f4671a6..32b453c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src
)
-# add_subdirectory(src)
+add_subdirectory(src)
add_subdirectory(autotest)
# add_subdirectory(qml)
diff --git a/autotest/CMakeLists.txt b/autotest/CMakeLists.txt
index eb14ea4..2552047 100644
--- a/autotest/CMakeLists.txt
+++ b/autotest/CMakeLists.txt
@@ -53,4 +53,11 @@ ecm_add_test(junglenormalruntest.cpp
TEST_NAME "jungleNormalRunTest"
LINK_LIBRARIES ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} Qt5::Test pthread KF5::ConfigCore
-)
\ No newline at end of file
+)
+
+ecm_add_test(guessitjobtest.cpp
+ ../src/guessitjob.cpp
+
+ TEST_NAME "guessItJobTest"
+ LINK_LIBRARIES ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} Qt5::Test pthread
+)
diff --git a/autotest/guessitjobtest.cpp b/autotest/guessitjobtest.cpp
new file mode 100644
index 0000000..f682494
--- /dev/null
+++ b/autotest/guessitjobtest.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2014 Vishesh Handa <me@vhanda.in>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "guessitjob.h"
+#include "interfaces/dataqueueinterface.h"
+#include "shared.h"
+
+#include <QTest>
+#include <QVariantMap>
+#include <QDebug>
+
+class GuessItJobTest : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void test();
+};
+
+class MockDataQueue : public DataQueueInterface
+{
+public:
+ MOCK_METHOD1(add, void(const QVariantMap&));
+};
+
+void GuessItJobTest::test()
+{
+ QVariantMap data;
+ data["type"] = "episode";
+ data["releaseGroup"] = "KILLERS";
+ data["mimetype"] = "video/mp4";
+ data["series"] = "Outlander";
+ data["episodeNumber"] = 5;
+ data["videoCodec"] = "h264";
+ data["format"] = "HDTV";
+ data["season"] = 1;
+ data["container"] = "mp4";
+
+ MockDataQueue dataQueue;
+ EXPECT_CALL(dataQueue, add(data)).Times(1);
+
+ QList<DataQueueInterface*> queues;
+ queues << &dataQueue;
+
+ const QString url("/home/vishesh/Outlander.S01E05.HDTV.x264-KILLERS.mp4");
+
+ Jungle::GuessItJob guessItJob(url, queues);
+ guessItJob.start();
+
+ QTest::qWait(500);
+}
+
+QTEST_GMOCK_MAIN(GuessItJobTest);
+
+#include "guessitjobtest.moc"
diff --git a/autotest/shared.h b/autotest/shared.h
index 9f936be..73a1c55 100644
--- a/autotest/shared.h
+++ b/autotest/shared.h
@@ -17,10 +17,13 @@
*
*/
+#include "gmock/gmock.h"
+
#define QTEST_GMOCK_MAIN(TestObject) \
int main(int argc, char *argv[]) \
{ \
QCoreApplication app(argc, argv); \
+ app.setApplicationName("jungle"); \
app.setAttribute(Qt::AA_Use96Dpi, true); \
::testing::GTEST_FLAG(throw_on_failure) = true; \
::testing::InitGoogleMock(&argc, argv); \
diff --git a/src/guess.py b/src/guess.py
new file mode 100644
index 0000000..50bd25a
--- /dev/null
+++ b/src/guess.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+##
+## Copyright (C) 2014 Vishesh Handa <me@vhanda.in>
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+##
+##
+
+from guessit import guess_file_info
+from optparse import OptionParser
+
+def fetchData(filename):
+ filetype = "autodetect"
+ info = ['filename']
+ result = guess_file_info(filename, filetype, info)
+ return result
+
+parser = OptionParser()
+options, args = parser.parse_args()
+
+for filename in args:
+ print(fetchData(filename))
diff --git a/src/guessitjob.cpp b/src/guessitjob.cpp
new file mode 100644
index 0000000..bd543b4
--- /dev/null
+++ b/src/guessitjob.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2014 Vishesh Handa <me@vhanda.in>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "guessitjob.h"
+#include "interfaces/dataqueueinterface.h"
+
+#include <QStandardPaths>
+#include <QJsonDocument>
+#include <QDebug>
+
+using namespace Jungle;
+
+GuessItJob::GuessItJob(const QString& filePath, const QList<DataQueueInterface*>& queues)
+ : m_filePath(filePath)
+ , m_queues(queues)
+{
+}
+
+void GuessItJob::start()
+{
+ QString guessItPath = QStandardPaths::locate(QStandardPaths::DataLocation, "guess.py");
+ QString pythonPath = QStandardPaths::findExecutable("python3");
+
+ Q_ASSERT(!guessItPath.isEmpty());
+ Q_ASSERT(!pythonPath.isEmpty());
+
+ m_process.setProgram(pythonPath);
+ m_process.setArguments(QStringList() << guessItPath << m_filePath);
+ connect(&m_process, SIGNAL(finished(int)), this, SLOT(slotProcessFinished(int)));
+ m_process.start();
+}
+
+void GuessItJob::slotProcessFinished(int exitCode)
+{
+ if (exitCode) {
+ return;
+ }
+
+ QByteArray json = m_process.readAllStandardOutput();
+ json.replace('\'', '"');
+
+ QJsonParseError error;
+ QJsonDocument doc = QJsonDocument::fromJson(json, &error);
+ if (error.error) {
+ qCritical() << error.errorString() << error.offset;
+ }
+ QVariantMap map = doc.toVariant().toMap();
+
+ for (DataQueueInterface* queue : m_queues) {
+ queue->add(map);
+ }
+
+ // Should mark the original queue with job done!
+}
+
+
diff --git a/autotest/shared.h b/src/guessitjob.h
similarity index 60%
copy from autotest/shared.h
copy to src/guessitjob.h
index 9f936be..04b2442 100644
--- a/autotest/shared.h
+++ b/src/guessitjob.h
@@ -17,13 +17,34 @@
*
*/
-#define QTEST_GMOCK_MAIN(TestObject) \
-int main(int argc, char *argv[]) \
-{ \
- QCoreApplication app(argc, argv); \
- app.setAttribute(Qt::AA_Use96Dpi, true); \
- ::testing::GTEST_FLAG(throw_on_failure) = true; \
- ::testing::InitGoogleMock(&argc, argv); \
- TestObject tc; \
- return QTest::qExec(&tc, argc, argv); \
+#ifndef JUNGLE_GUESSITJOB_H
+#define JUNGLE_GUESSITJOB_H
+
+#include <QObject>
+#include <QVariantMap>
+#include <QProcess>
+
+class DataQueueInterface;
+
+namespace Jungle {
+
+class GuessItJob : public QObject
+{
+ Q_OBJECT
+public:
+ GuessItJob(const QString& filePath, const QList<DataQueueInterface*>& queues);
+
+ void start();
+
+private Q_SLOTS:
+ void slotProcessFinished(int exitCode);
+
+private:
+ QString m_filePath;
+ QProcess m_process;
+
+ QList<DataQueueInterface*> m_queues;
+};
}
+
+#endif // JUNGLE_GUESSITJOB_H
diff --git a/autotest/shared.h b/src/interfaces/dataqueueinterface.h
similarity index 70%
copy from autotest/shared.h
copy to src/interfaces/dataqueueinterface.h
index 9f936be..2f323ab 100644
--- a/autotest/shared.h
+++ b/src/interfaces/dataqueueinterface.h
@@ -17,13 +17,16 @@
*
*/
-#define QTEST_GMOCK_MAIN(TestObject) \
-int main(int argc, char *argv[]) \
-{ \
- QCoreApplication app(argc, argv); \
- app.setAttribute(Qt::AA_Use96Dpi, true); \
- ::testing::GTEST_FLAG(throw_on_failure) = true; \
- ::testing::InitGoogleMock(&argc, argv); \
- TestObject tc; \
- return QTest::qExec(&tc, argc, argv); \
-}
+#ifndef DATAQUEUEINTERFACE_H
+#define DATAQUEUEINTERFACE_H
+
+#include <QVariantMap>
+
+class DataQueueInterface
+{
+public:
+ virtual ~DataQueueInterface() {}
+ virtual void add(const QVariantMap& map) = 0;
+};
+
+#endif // DATAQUEUEINTERFACE_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic