Fix issue in test and add a test for Json canonicalization (will pass when reply_e2e branch will be merged)

This commit is contained in:
Benoit Marty 2019-06-28 14:27:08 +02:00
parent 13a0b809e1
commit cea8abb9b1
4 changed files with 66 additions and 56 deletions

View File

@ -56,6 +56,14 @@ internal class JsonCanonicalizerTest : InstrumentedTest {
JsonCanonicalizer.canonicalize("""{"algorithms":["m.megolm.v1.aes-sha2","m.olm.v1.curve25519-aes-sha2"],"device_id":"VSCUNFSOUI","user_id":"@benoitx:matrix.org","keys":{"curve25519:VSCUNFSOUI":"utyOjnhiQ73qNhi9HlN0OgWIowe5gthTS8r0r9TcJ3o","ed25519:VSCUNFSOUI":"qNhEt+Yggaajet0hX/FjTRLfySgs65ldYyomm7PIx6U"}}""")) JsonCanonicalizer.canonicalize("""{"algorithms":["m.megolm.v1.aes-sha2","m.olm.v1.curve25519-aes-sha2"],"device_id":"VSCUNFSOUI","user_id":"@benoitx:matrix.org","keys":{"curve25519:VSCUNFSOUI":"utyOjnhiQ73qNhi9HlN0OgWIowe5gthTS8r0r9TcJ3o","ed25519:VSCUNFSOUI":"qNhEt+Yggaajet0hX/FjTRLfySgs65ldYyomm7PIx6U"}}"""))
} }


@Test
fun doubleQuoteTest() {
assertEquals("{\"a\":\"\\\"\"}",
JsonCanonicalizer.canonicalize("{\"a\":\"\\\"\"}"))
}



/* ========================================================================================== /* ==========================================================================================
* Test from https://matrix.org/docs/spec/appendices.html#examples * Test from https://matrix.org/docs/spec/appendices.html#examples
* ========================================================================================== */ * ========================================================================================== */

View File

@ -19,11 +19,10 @@ package im.vector.matrix.android.session.room.timeline
import arrow.core.Try import arrow.core.Try
import im.vector.matrix.android.internal.session.room.timeline.GetContextOfEventTask import im.vector.matrix.android.internal.session.room.timeline.GetContextOfEventTask
import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection
import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEvent
import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor
import kotlin.random.Random import kotlin.random.Random


internal class FakeGetContextOfEventTask @Inject constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : GetContextOfEventTask { internal class FakeGetContextOfEventTask constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : GetContextOfEventTask {


override suspend fun execute(params: GetContextOfEventTask.Params): Try<TokenChunkEventPersistor.Result> { override suspend fun execute(params: GetContextOfEventTask.Params): Try<TokenChunkEventPersistor.Result> {
val fakeEvents = RoomDataHelper.createFakeListOfEvents(30) val fakeEvents = RoomDataHelper.createFakeListOfEvents(30)

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.session.room.timeline
import arrow.core.Try import arrow.core.Try
import im.vector.matrix.android.internal.session.room.timeline.PaginationTask import im.vector.matrix.android.internal.session.room.timeline.PaginationTask
import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor
import javax.inject.Inject
import kotlin.random.Random import kotlin.random.Random


internal class FakePaginationTask @Inject constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : PaginationTask { internal class FakePaginationTask @Inject constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : PaginationTask {

View File

@ -18,8 +18,10 @@ package im.vector.matrix.android.session.room.timeline


import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.InstrumentedTest import im.vector.matrix.android.InstrumentedTest
import im.vector.matrix.android.api.session.crypto.CryptoService
import im.vector.matrix.android.api.session.room.timeline.Timeline import im.vector.matrix.android.api.session.room.timeline.Timeline
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.matrix.android.internal.crypto.CryptoManager
import im.vector.matrix.android.internal.database.model.SessionRealmModule import im.vector.matrix.android.internal.database.model.SessionRealmModule
import im.vector.matrix.android.internal.session.room.EventRelationExtractor import im.vector.matrix.android.internal.session.room.EventRelationExtractor
import im.vector.matrix.android.internal.session.room.membership.SenderRoomMemberExtractor import im.vector.matrix.android.internal.session.room.membership.SenderRoomMemberExtractor
@ -44,60 +46,60 @@ internal class TimelineTest : InstrumentedTest {


private lateinit var monarchy: Monarchy private lateinit var monarchy: Monarchy


@Before // @Before
fun setup() { // fun setup() {
Timber.plant(Timber.DebugTree()) // Timber.plant(Timber.DebugTree())
Realm.init(context()) // Realm.init(context())
val testConfiguration = RealmConfiguration.Builder().name("test-realm") // val testConfiguration = RealmConfiguration.Builder().name("test-realm")
.modules(SessionRealmModule()).build() // .modules(SessionRealmModule()).build()

//
Realm.deleteRealm(testConfiguration) // Realm.deleteRealm(testConfiguration)
monarchy = Monarchy.Builder().setRealmConfiguration(testConfiguration).build() // monarchy = Monarchy.Builder().setRealmConfiguration(testConfiguration).build()
RoomDataHelper.fakeInitialSync(monarchy, ROOM_ID) // RoomDataHelper.fakeInitialSync(monarchy, ROOM_ID)
} // }

//
private fun createTimeline(initialEventId: String? = null): Timeline { // private fun createTimeline(initialEventId: String? = null): Timeline {
val taskExecutor = TaskExecutor(testCoroutineDispatchers) // val taskExecutor = TaskExecutor(testCoroutineDispatchers)
val tokenChunkEventPersistor = TokenChunkEventPersistor(monarchy) // val tokenChunkEventPersistor = TokenChunkEventPersistor(monarchy)
val paginationTask = FakePaginationTask @Inject constructor(tokenChunkEventPersistor) // val paginationTask = FakePaginationTask @Inject constructor(tokenChunkEventPersistor)
val getContextOfEventTask = FakeGetContextOfEventTask @Inject constructor(tokenChunkEventPersistor) // val getContextOfEventTask = FakeGetContextOfEventTask @Inject constructor(tokenChunkEventPersistor)
val roomMemberExtractor = SenderRoomMemberExtractor(ROOM_ID) // val roomMemberExtractor = SenderRoomMemberExtractor(ROOM_ID)
val timelineEventFactory = TimelineEventFactory(roomMemberExtractor, EventRelationExtractor()) // val timelineEventFactory = TimelineEventFactory(roomMemberExtractor, EventRelationExtractor())
return DefaultTimeline( // return DefaultTimeline(
ROOM_ID, // ROOM_ID,
initialEventId, // initialEventId,
monarchy.realmConfiguration, // monarchy.realmConfiguration,
taskExecutor, // taskExecutor,
getContextOfEventTask, // getContextOfEventTask,
timelineEventFactory, // timelineEventFactory,
paginationTask, // paginationTask,
null) // null)
} // }

//
@Test // @Test
fun backPaginate_shouldLoadMoreEvents_whenPaginateIsCalled() { // fun backPaginate_shouldLoadMoreEvents_whenPaginateIsCalled() {
val timeline = createTimeline() // val timeline = createTimeline()
timeline.start() // timeline.start()
val paginationCount = 30 // val paginationCount = 30
var initialLoad = 0 // var initialLoad = 0
val latch = CountDownLatch(2) // val latch = CountDownLatch(2)
var timelineEvents: List<TimelineEvent> = emptyList() // var timelineEvents: List<TimelineEvent> = emptyList()
timeline.listener = object : Timeline.Listener { // timeline.listener = object : Timeline.Listener {
override fun onUpdated(snapshot: List<TimelineEvent>) { // override fun onUpdated(snapshot: List<TimelineEvent>) {
if (snapshot.isNotEmpty()) { // if (snapshot.isNotEmpty()) {
if (initialLoad == 0) { // if (initialLoad == 0) {
initialLoad = snapshot.size // initialLoad = snapshot.size
} // }
timelineEvents = snapshot // timelineEvents = snapshot
latch.countDown() // latch.countDown()
timeline.paginate(Timeline.Direction.BACKWARDS, paginationCount) // timeline.paginate(Timeline.Direction.BACKWARDS, paginationCount)
} // }
} // }
} // }
latch.await() // latch.await()
timelineEvents.size shouldEqual initialLoad + paginationCount // timelineEvents.size shouldEqual initialLoad + paginationCount
timeline.dispose() // timeline.dispose()
} // }




} }