File indexing completed on 2024-05-12 05:13:44

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <KAndroidExtras/Context>
0008 #include <KAndroidExtras/ContentResolver>
0009 
0010 #include <QJniObject>
0011 #include <QtTest/qtest.h>
0012 
0013 using namespace KAndroidExtras;
0014 
0015 class AndroidWrapperTest : public QObject
0016 {
0017     Q_OBJECT
0018 private Q_SLOTS:
0019     void testContext()
0020     {
0021 #ifndef Q_OS_ANDROID
0022         const auto pn = Context::getPackageName();
0023         QCOMPARE(pn.protocol().size(), 2);
0024         QCOMPARE(pn.protocol().at(0), QLatin1StringView("global androidContext()"));
0025         QCOMPARE(pn.protocol().at(1), QLatin1StringView("callObjectMethod: getPackageName ()Ljava/lang/String; ()"));
0026 #endif
0027     }
0028 
0029     void testContentResolver()
0030     {
0031 #ifndef Q_OS_ANDROID
0032         QCOMPARE(ContentResolver::fileName(QUrl()), QLatin1StringView(
0033             "global androidContext()\n"
0034             "callObjectMethod: getContentResolver ()Landroid/content/ContentResolver; ()\n"
0035             "callObjectMethod: query (Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor; (oIIII)\n"
0036             "callMethod: getColumnIndex (Ljava/lang/String;)I (o)\n"
0037             "callMethod: moveToFirst ()Z ()\n"
0038             "callObjectMethod: getString (I)Ljava/lang/String; (I)"
0039         ));
0040         QCOMPARE(QJniObject::m_staticProtocol.size(), 1);
0041         QCOMPARE(QJniObject::m_staticProtocol.at(0), QLatin1StringView("getStaticObjectField: android/provider/OpenableColumns DISPLAY_NAME Ljava/lang/String;"));
0042 #endif
0043     }
0044 };
0045 
0046 QTEST_GUILESS_MAIN(AndroidWrapperTest)
0047 
0048 #include "androidwrappertest.moc"