From f934c79078fcaf049c3ed27ed7fc9c96fd30dc23 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Thu, 2 Feb 2023 17:38:21 +1100 Subject: [PATCH] fix: fix tests, don't use iterables --- .../libsession_util/InstrumentedTests.kt | 23 +++++++-------- libsession-util/src/main/cpp/conversation.cpp | 29 +++++++++++++++++++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt b/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt index 5783a7972f..6272eac39c 100644 --- a/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt +++ b/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt @@ -13,6 +13,7 @@ import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith import org.session.libsignal.utilities.Hex +import org.session.libsignal.utilities.Log /** * Instrumented test, which will execute on an Android device. @@ -491,7 +492,7 @@ class InstrumentedTests { assertTrue(x2.unread) val anotherId = "051111111111111111111111111111111111111111111111111111111111111111" - val c2 = convos.getOrConstructLegacyClosedGroup(anotherId) + val c2 = convos.getOrConstructOneToOne(anotherId) c2.unread = true convos2.set(c2) @@ -513,29 +514,27 @@ class InstrumentedTests { assertEquals(seqNo2, convos.push().seqNo) val seen = mutableListOf() - for (conv in listOf(convos, convos2)) { + for ((ind, conv) in listOf(convos, convos2).withIndex()) { + Log.e("Test","Testing seen from convo #$ind") seen.clear() assertEquals(4, conv.size()) assertEquals(2, conv.sizeOneToOnes()) assertEquals(1, conv.sizeOpenGroups()) assertEquals(1, conv.sizeLegacyClosedGroups()) assertFalse(conv.empty()) - for (convo in conv.all()) { + val allConvos = conv.all() + for (convo in allConvos) { when (convo) { is Conversation.OneToOne -> seen.add("1-to-1: ${convo.sessionId}") is Conversation.OpenGroup -> seen.add("og: ${convo.baseUrl}/r/${convo.room}") is Conversation.LegacyClosedGroup -> seen.add("cl: ${convo.groupId}") } } - assertEquals(listOf( - "1-to-1: " + - "051111111111111111111111111111111111111111111111111111111111111111", - "1-to-1: " + - "055000000000000000000000000000000000000000000000000000000000000000", - "og: http://example.org:5678/r/sudokuroom", - "cl: " + - "05ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - ), seen) + + assertTrue(seen.contains("1-to-1: 051111111111111111111111111111111111111111111111111111111111111111")) + assertTrue(seen.contains("1-to-1: 055000000000000000000000000000000000000000000000000000000000000000")) + assertTrue(seen.contains("og: http://example.org:5678/r/sudokuroom")) + assertTrue(seen.contains("cl: 05cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc")) } assertFalse(convos.needsPush()) diff --git a/libsession-util/src/main/cpp/conversation.cpp b/libsession-util/src/main/cpp/conversation.cpp index 79d4b5a1bc..684f473ada 100644 --- a/libsession-util/src/main/cpp/conversation.cpp +++ b/libsession-util/src/main/cpp/conversation.cpp @@ -304,4 +304,33 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_erase(JN auto deserialized = deserialize_any(env, conversation); if (deserialized == nullptr) return false; return convos->erase(*deserialized); +} +extern "C" +JNIEXPORT jint JNICALL +Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeOpenGroups(JNIEnv *env, + jobject thiz) { + auto convos = ptrToConvoInfo(env, thiz); + return convos->size_open(); +} +extern "C" +JNIEXPORT jint JNICALL +Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeLegacyClosedGroups( + JNIEnv *env, jobject thiz) { + auto convos = ptrToConvoInfo(env, thiz); + return convos->size_open(); +} +extern "C" +JNIEXPORT jobject JNICALL +Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_all(JNIEnv *env, + jobject thiz) { + auto contacts = ptrToConvoInfo(env, thiz); + jclass stack = env->FindClass("java/util/Stack"); + jmethodID init = env->GetMethodID(stack, "", "()V"); + jobject our_stack = env->NewObject(stack, init); + jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;"); + for (const auto& contact : *contacts) { + auto contact_obj = serialize_any(env, contact); + env->CallObjectMethod(our_stack, push, contact_obj); + } + return our_stack; } \ No newline at end of file