Commit 080c6ae5 authored by Volker Krause's avatar Volker Krause
Browse files

Log method call argument types in the mock QAndroidJniObject as well

Helps testing implicit argument type conversions.
parent eff513f8
......@@ -22,7 +22,7 @@ private Q_SLOTS:
const auto pn = Context::getPackageName();
QCOMPARE(pn.protocol().size(), 2);
QCOMPARE(pn.protocol().at(0), QLatin1String("global androidContext()"));
QCOMPARE(pn.protocol().at(1), QLatin1String("callObjectMethod: getPackageName ()Ljava/lang/String;"));
QCOMPARE(pn.protocol().at(1), QLatin1String("callObjectMethod: getPackageName ()Ljava/lang/String; ()"));
#endif
}
......@@ -31,11 +31,11 @@ private Q_SLOTS:
#ifndef Q_OS_ANDROID
QCOMPARE(ContentResolver::fileName(QUrl()), QLatin1String(
"global androidContext()\n"
"callObjectMethod: getContentResolver ()Landroid/content/ContentResolver;\n"
"callObjectMethod: query (Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;\n"
"callMethod: getColumnIndex (Ljava/lang/String;)I\n"
"callMethod: moveToFirst ()Z\n"
"callObjectMethod: getString (I)Ljava/lang/String;"
"callObjectMethod: getContentResolver ()Landroid/content/ContentResolver; ()\n"
"callObjectMethod: query (Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor; (oIIII)\n"
"callMethod: getColumnIndex (Ljava/lang/String;)I (o)\n"
"callMethod: moveToFirst ()Z ()\n"
"callObjectMethod: getString (I)Ljava/lang/String; (I)"
));
QCOMPARE(QAndroidJniObject::m_staticProtocol.size(), 1);
QCOMPARE(QAndroidJniObject::m_staticProtocol.at(0), QLatin1String("getStaticObjectField: android/provider/OpenableColumns DISPLAY_NAME Ljava/lang/String;"));
......
......@@ -87,21 +87,21 @@ private Q_SLOTS:
obj.setFlags(Intent::FLAG_GRANT_READ_URI_PERMISSION);
QCOMPARE(obj.handle().protocol().size(), 14);
QCOMPARE(obj.handle().protocol()[0], QLatin1String("callObjectMethod: getName ()Ljava/lang/String;"));
QCOMPARE(obj.handle().protocol()[1], QLatin1String("callMethod: setName (Ljava/lang/String;)V"));
QCOMPARE(obj.handle().protocol()[2], QLatin1String("callMethod: setName (Ljava/lang/String;)V"));
QCOMPARE(obj.handle().protocol()[3], QLatin1String("callMethod: getFlags ()I"));
QCOMPARE(obj.handle().protocol()[4], QLatin1String("callMethod: setFlags (I)V"));
QCOMPARE(obj.handle().protocol()[5], QLatin1String("callMethod: start ()V"));
QCOMPARE(obj.handle().protocol()[6], QLatin1String("callMethod: setCoordinates (FF)Z"));
QCOMPARE(obj.handle().protocol()[7], QLatin1String("callMethod: setCoordinates (FF)Z"));
QCOMPARE(obj.handle().protocol()[0], QLatin1String("callObjectMethod: getName ()Ljava/lang/String; ()"));
QCOMPARE(obj.handle().protocol()[1], QLatin1String("callMethod: setName (Ljava/lang/String;)V (o)"));
QCOMPARE(obj.handle().protocol()[2], QLatin1String("callMethod: setName (Ljava/lang/String;)V (o)"));
QCOMPARE(obj.handle().protocol()[3], QLatin1String("callMethod: getFlags ()I ()"));
QCOMPARE(obj.handle().protocol()[4], QLatin1String("callMethod: setFlags (I)V (I)"));
QCOMPARE(obj.handle().protocol()[5], QLatin1String("callMethod: start ()V ()"));
QCOMPARE(obj.handle().protocol()[6], QLatin1String("callMethod: setCoordinates (FF)Z (FF)"));
QCOMPARE(obj.handle().protocol()[7], QLatin1String("callMethod: setCoordinates (FF)Z (FF)"));
QCOMPARE(obj.handle().protocol()[8], QLatin1String("getObjectField: name Ljava/lang/String;"));
QCOMPARE(obj.handle().protocol()[9], QLatin1String("callMethod: setName (Ljava/lang/String;)V"));
QCOMPARE(obj.handle().protocol()[10], QLatin1String("callMethod: startIntent (Landroid/content/Intent;)V"));
QCOMPARE(obj.handle().protocol()[11], QLatin1String("callObjectMethod: getIntent ()Landroid/content/Intent;"));
QCOMPARE(obj.handle().protocol()[12], QLatin1String("callMethod: setName (Ljava/lang/String;)V"));
QCOMPARE(obj.handle().protocol()[13], QLatin1String("callMethod: setFlags (I)V"));
QCOMPARE(obj.handle().protocol()[9], QLatin1String("callMethod: setName (Ljava/lang/String;)V (o)"));
QCOMPARE(obj.handle().protocol()[10], QLatin1String("callMethod: startIntent (Landroid/content/Intent;)V (o)"));
QCOMPARE(obj.handle().protocol()[11], QLatin1String("callObjectMethod: getIntent ()Landroid/content/Intent; ()"));
QCOMPARE(obj.handle().protocol()[12], QLatin1String("callMethod: setName (Ljava/lang/String;)V (o)"));
QCOMPARE(obj.handle().protocol()[13], QLatin1String("callMethod: setFlags (I)V (I)"));
#if 0
// stuff that must not compile
......
......@@ -18,6 +18,21 @@
class QAndroidJniObjectPrivate;
namespace KAndroidExtras {
namespace Internal {
template <typename T>
constexpr inline const char* argTypeToString()
{
return KAndroidExtras::Jni::signature<T>();
}
template <>
constexpr inline const char* argTypeToString<jobject>()
{
return "o";
}
}
}
/** Mock object for QAndroidJniObject outside of Android, for automated testing. */
class KANDROIDEXTRAS_EXPORT QAndroidJniObject {
public:
......@@ -44,18 +59,40 @@ public:
template <typename T>
T object() const { return {}; }
template <typename T, typename ...Args>
T callMethod(const char *methodName, const char *signature, Args...) const
{
const QString s = QLatin1String("callMethod: ") + QLatin1String(methodName) + QLatin1Char(' ') + QLatin1String(signature) + QLatin1String(" (")
+ (...+QLatin1String(KAndroidExtras::Internal::argTypeToString<Args>())) + QLatin1Char(')');
addToProtocol(s);
if constexpr (!std::is_same_v<T, void>) {
return {};
}
}
template <typename T>
T callMethod(const char *methodName, const char *signature, ...) const
T callMethod(const char *methodName, const char *signature) const
{
addToProtocol(QLatin1String("callMethod: ") + QLatin1String(methodName) + QLatin1Char(' ') + QLatin1String(signature));
const QString s = QLatin1String("callMethod: ") + QLatin1String(methodName) + QLatin1Char(' ') + QLatin1String(signature) + QLatin1String(" ()");
addToProtocol(s);
if constexpr (!std::is_same_v<T, void>) {
return {};
}
}
QAndroidJniObject callObjectMethod(const char *methodName, const char *signature, ...) const
template <typename ...Args>
QAndroidJniObject callObjectMethod(const char *methodName, const char *signature, Args...) const
{
const QString s = QLatin1String("callObjectMethod: ") + QLatin1String(methodName) + QLatin1Char(' ') + QLatin1String(signature) + QLatin1String(" (")
+ (...+QLatin1String(KAndroidExtras::Internal::argTypeToString<Args>())) + QLatin1Char(')');
addToProtocol(s);
QAndroidJniObject obj;
obj.setProtocol(protocol());
return obj;
}
QAndroidJniObject callObjectMethod(const char *methodName, const char *signature) const
{
addToProtocol(QLatin1String("callObjectMethod: ") + QLatin1String(methodName) + QLatin1Char(' ') + QLatin1String(signature));
addToProtocol(QLatin1String("callObjectMethod: ") + QLatin1String(methodName) + QLatin1Char(' ') + QLatin1String(signature) + QLatin1String(" ()"));
QAndroidJniObject obj;
obj.setProtocol(protocol());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment