• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.serialization.json
6 
7 import kotlinx.serialization.Serializable
8 import kotlin.test.Test
9 
10 class JsonHugeDataSerializationTest : JsonTestBase() {
11 
12     @Serializable
13     private data class Node(
14         val children: List<Node>
15     )
16 
createNodesnull17     private fun createNodes(count: Int, depth: Int): List<Node> {
18         val ret = mutableListOf<Node>()
19         if (depth == 0) return ret
20         for (i in 0 until count) {
21             ret.add(Node(createNodes(1, depth - 1)))
22         }
23         return ret
24     }
25 
26     @Test
testnull27     fun test() {
28         // create some huge instance
29         val rootNode = Node(createNodes(1000, 10))
30 
31         val expectedJson = Json.encodeToString(Node.serializer(), rootNode)
32 
33         /*
34           The assertJsonFormAndRestored function, when checking the encoding, will call Json.encodeToString(...) for `JsonTestingMode.STREAMING`
35           since the string `expectedJson` was generated by the same function, the test will always consider
36           the encoding to the `STREAMING` mode is correct, even if there was actually an error there. So only TREE, JAVA_STREAMS and OKIO are actually being tested here
37          */
38         assertJsonFormAndRestored(Node.serializer(), rootNode, expectedJson)
39     }
40 }
41