1 /* <lambda>null2 * Copyright 2021 Google Inc. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.flatbuffers.kotlin 17 18 import org.junit.Test 19 import kotlin.test.assertEquals 20 21 class Utf8Test { 22 23 @Test 24 fun testUtf8EncodingDecoding() { 25 val utf8Lines = String(this.javaClass.classLoader.getResourceAsStream("utf8_sample.txt")!!.readBytes()) 26 .split("\n") 27 .filter { it.trim().isNotEmpty() } 28 29 val utf8Bytes = utf8Lines.map { s -> ByteArray(Utf8.encodedLength(s)).also { Utf8.encodeUtf8Array(s, it) } } 30 utf8Bytes.indices.forEach { 31 assertArrayEquals(utf8Lines[it].encodeToByteArray(), utf8Bytes[it]) 32 assertEquals(utf8Lines[it], Utf8.decodeUtf8Array(utf8Bytes[it])) 33 } 34 } 35 } 36