fix: fix tests, don't use iterables

This commit is contained in:
0x330a 2023-02-02 17:38:21 +11:00
parent 665a69a0df
commit f934c79078
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
2 changed files with 40 additions and 12 deletions

View File

@ -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<String>()
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())

View File

@ -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, "<init>", "()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;
}