1 /* 2 * Copyright 2014 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 17 import MyGame.Example.* 18 import optional_scalars.* 19 import com.google.flatbuffers.ByteBufferUtil 20 import com.google.flatbuffers.FlatBufferBuilder 21 import NamespaceA.* 22 import NamespaceA.NamespaceB.* 23 import NamespaceA.NamespaceB.TableInNestedNS 24 import java.io.File 25 import java.io.FileOutputStream 26 import java.io.InputStream 27 import java.io.RandomAccessFile 28 import java.nio.ByteBuffer 29 import java.nio.ByteOrder 30 import java.nio.channels.FileChannel 31 32 import com.google.flatbuffers.Constants.SIZE_PREFIX_LENGTH 33 34 @kotlin.ExperimentalUnsignedTypes 35 class KotlinTest { 36 37 companion object { 38 @JvmStatic mainnull39 fun main(args: Array<String>) { 40 41 // First, let's test reading a FlatBuffer generated by C++ code: 42 // This file was generated from monsterdata_test.json 43 44 val data = RandomAccessFile(File("monsterdata_test.mon"), "r").use { 45 val temp = ByteArray(it.length().toInt()) 46 it.readFully(temp) 47 temp 48 } 49 50 // Now test it: 51 52 val bb = ByteBuffer.wrap(data) 53 TestBuffer(bb) 54 55 // Second, let's create a FlatBuffer from scratch in Java, and test it also. 56 // We use an initial size of 1 to exercise the reallocation algorithm, 57 // normally a size larger than the typical FlatBuffer you generate would be 58 // better for performance. 59 val fbb = FlatBufferBuilder(1) 60 61 TestBuilderBasics(fbb, true) 62 TestBuilderBasics(fbb, false) 63 64 TestExtendedBuffer(fbb.dataBuffer().asReadOnlyBuffer()) 65 66 TestNamespaceNesting() 67 68 TestNestedFlatBuffer() 69 70 TestCreateByteVector() 71 72 TestCreateUninitializedVector() 73 74 TestByteBufferFactory() 75 76 TestSizedInputStream() 77 78 TestVectorOfUnions() 79 80 TestSharedStringPool() 81 TestScalarOptional() 82 println("FlatBuffers test: completed successfully") 83 } 84 TestEnumsnull85 fun TestEnums() { 86 assert(Color.name(Color.Red.toInt()) == "Red") 87 assert(Color.name(Color.Blue.toInt()) == "Blue") 88 assert(Any_.name(Any_.NONE.toInt()) == "NONE") 89 assert(Any_.name(Any_.Monster.toInt()) == "Monster") 90 } 91 TestBuffernull92 fun TestBuffer(bb: ByteBuffer) { 93 assert(Monster.MonsterBufferHasIdentifier(bb) == true) 94 95 val monster = Monster.getRootAsMonster(bb) 96 97 assert(monster.hp == 80.toShort()) 98 assert(monster.mana == 150.toShort()) // default 99 100 assert(monster.name == "MyMonster") 101 // monster.friendly() // can't access, deprecated 102 103 val pos = monster.pos!! 104 assert(pos.x == 1.0f) 105 assert(pos.y == 2.0f) 106 assert(pos.z == 3.0f) 107 assert(pos.test1 == 3.0) 108 // issue: int != byte 109 assert(pos.test2 == Color.Green) 110 val t = pos.test3!! 111 assert(t.a == 5.toShort()) 112 assert(t.b == 6.toByte()) 113 114 assert(monster.testType == Any_.Monster) 115 val monster2 = Monster() 116 assert(monster.test(monster2) != null == true) 117 assert(monster2.name == "Fred") 118 119 assert(monster.inventoryLength == 5) 120 var invsum = 0u 121 for (i in 0 until monster.inventoryLength) 122 invsum += monster.inventory(i) 123 assert(invsum == 10u) 124 125 // Alternative way of accessing a vector: 126 val ibb = monster.inventoryAsByteBuffer 127 invsum = 0u 128 while (ibb.position() < ibb.limit()) 129 invsum += ibb.get().toUInt() 130 assert(invsum == 10u) 131 132 133 val test_0 = monster.test4(0)!! 134 val test_1 = monster.test4(1)!! 135 assert(monster.test4Length == 2) 136 assert(test_0.a + test_0.b + test_1.a + test_1.b == 100) 137 138 assert(monster.testarrayofstringLength == 2) 139 assert(monster.testarrayofstring(0) == "test1") 140 assert(monster.testarrayofstring(1) == "test2") 141 142 assert(monster.testbool == true) 143 } 144 145 // this method checks additional fields not present in the binary buffer read from file 146 // these new tests are performed on top of the regular tests TestExtendedBuffernull147 fun TestExtendedBuffer(bb: ByteBuffer) { 148 TestBuffer(bb) 149 150 val monster = Monster.getRootAsMonster(bb) 151 152 assert(monster.testhashu32Fnv1 == (Integer.MAX_VALUE + 1L).toUInt()) 153 } 154 TestNamespaceNestingnull155 fun TestNamespaceNesting() { 156 // reference / manipulate these to verify compilation 157 val fbb = FlatBufferBuilder(1) 158 159 TableInNestedNS.startTableInNestedNS(fbb) 160 TableInNestedNS.addFoo(fbb, 1234) 161 val nestedTableOff = TableInNestedNS.endTableInNestedNS(fbb) 162 163 TableInFirstNS.startTableInFirstNS(fbb) 164 TableInFirstNS.addFooTable(fbb, nestedTableOff) 165 } 166 TestNestedFlatBuffernull167 fun TestNestedFlatBuffer() { 168 val nestedMonsterName = "NestedMonsterName" 169 val nestedMonsterHp: Short = 600 170 val nestedMonsterMana: Short = 1024 171 172 var fbb1: FlatBufferBuilder? = FlatBufferBuilder(16) 173 val str1 = fbb1!!.createString(nestedMonsterName) 174 Monster.startMonster(fbb1) 175 Monster.addName(fbb1, str1) 176 Monster.addHp(fbb1, nestedMonsterHp) 177 Monster.addMana(fbb1, nestedMonsterMana) 178 val monster1 = Monster.endMonster(fbb1) 179 Monster.finishMonsterBuffer(fbb1, monster1) 180 val fbb1Bytes = fbb1.sizedByteArray() 181 182 val fbb2 = FlatBufferBuilder(16) 183 val str2 = fbb2.createString("My Monster") 184 val nestedBuffer = Monster.createTestnestedflatbufferVector(fbb2, fbb1Bytes.asUByteArray()) 185 Monster.startMonster(fbb2) 186 Monster.addName(fbb2, str2) 187 Monster.addHp(fbb2, 50.toShort()) 188 Monster.addMana(fbb2, 32.toShort()) 189 Monster.addTestnestedflatbuffer(fbb2, nestedBuffer) 190 val monster = Monster.endMonster(fbb2) 191 Monster.finishMonsterBuffer(fbb2, monster) 192 193 // Now test the data extracted from the nested buffer 194 val mons = Monster.getRootAsMonster(fbb2.dataBuffer()) 195 val nestedMonster = mons.testnestedflatbufferAsMonster!! 196 197 assert(nestedMonsterMana == nestedMonster.mana) 198 assert(nestedMonsterHp == nestedMonster.hp) 199 assert(nestedMonsterName == nestedMonster.name) 200 } 201 TestCreateByteVectornull202 fun TestCreateByteVector() { 203 val fbb = FlatBufferBuilder(16) 204 val str = fbb.createString("MyMonster") 205 val inventory = byteArrayOf(0, 1, 2, 3, 4) 206 val vec = fbb.createByteVector(inventory) 207 Monster.startMonster(fbb) 208 Monster.addInventory(fbb, vec) 209 Monster.addName(fbb, str) 210 val monster1 = Monster.endMonster(fbb) 211 Monster.finishMonsterBuffer(fbb, monster1) 212 val monsterObject = Monster.getRootAsMonster(fbb.dataBuffer()) 213 214 assert(monsterObject.inventory(1) == inventory[1].toUByte()) 215 assert(monsterObject.inventoryLength == inventory.size) 216 assert(ByteBuffer.wrap(inventory) == monsterObject.inventoryAsByteBuffer) 217 } 218 TestCreateUninitializedVectornull219 fun TestCreateUninitializedVector() { 220 val fbb = FlatBufferBuilder(16) 221 val str = fbb.createString("MyMonster") 222 val inventory = byteArrayOf(0, 1, 2, 3, 4) 223 val bb = fbb.createUnintializedVector(1, inventory.size, 1) 224 for (i in inventory) { 225 bb.put(i) 226 } 227 val vec = fbb.endVector() 228 Monster.startMonster(fbb) 229 Monster.addInventory(fbb, vec) 230 Monster.addName(fbb, str) 231 val monster1 = Monster.endMonster(fbb) 232 Monster.finishMonsterBuffer(fbb, monster1) 233 val monsterObject = Monster.getRootAsMonster(fbb.dataBuffer()) 234 235 assert(monsterObject.inventory(1) == inventory[1].toUByte()) 236 assert(monsterObject.inventoryLength == inventory.size) 237 assert(ByteBuffer.wrap(inventory) == monsterObject.inventoryAsByteBuffer) 238 } 239 TestByteBufferFactorynull240 fun TestByteBufferFactory() { 241 class MappedByteBufferFactory : FlatBufferBuilder.ByteBufferFactory() { 242 override fun newByteBuffer(capacity: Int): ByteBuffer? { 243 var bb: ByteBuffer? 244 try { 245 bb = RandomAccessFile("javatest.bin", "rw").channel.map( 246 FileChannel.MapMode.READ_WRITE, 247 0, 248 capacity.toLong() 249 ).order(ByteOrder.LITTLE_ENDIAN) 250 } catch (e: Throwable) { 251 println("FlatBuffers test: couldn't map ByteBuffer to a file") 252 bb = null 253 } 254 255 return bb 256 } 257 } 258 259 val fbb = FlatBufferBuilder(1, MappedByteBufferFactory()) 260 261 TestBuilderBasics(fbb, false) 262 } 263 TestSizedInputStreamnull264 fun TestSizedInputStream() { 265 // Test on default FlatBufferBuilder that uses HeapByteBuffer 266 val fbb = FlatBufferBuilder(1) 267 268 TestBuilderBasics(fbb, false) 269 270 val `in` = fbb.sizedInputStream() 271 val array = fbb.sizedByteArray() 272 var count = 0 273 var currentVal = 0 274 275 while (currentVal != -1 && count < array.size) { 276 try { 277 currentVal = `in`.read() 278 } catch (e: java.io.IOException) { 279 println("FlatBuffers test: couldn't read from InputStream") 280 return 281 } 282 283 assert(currentVal.toByte() == array[count]) 284 count++ 285 } 286 assert(count == array.size) 287 } 288 TestBuilderBasicsnull289 fun TestBuilderBasics(fbb: FlatBufferBuilder, sizePrefix: Boolean) { 290 val names = intArrayOf(fbb.createString("Frodo"), fbb.createString("Barney"), fbb.createString("Wilma")) 291 val off = IntArray(3) 292 Monster.startMonster(fbb) 293 Monster.addName(fbb, names[0]) 294 off[0] = Monster.endMonster(fbb) 295 Monster.startMonster(fbb) 296 Monster.addName(fbb, names[1]) 297 off[1] = Monster.endMonster(fbb) 298 Monster.startMonster(fbb) 299 Monster.addName(fbb, names[2]) 300 off[2] = Monster.endMonster(fbb) 301 val sortMons = fbb.createSortedVectorOfTables(Monster(), off) 302 303 // We set up the same values as monsterdata.json: 304 305 val str = fbb.createString("MyMonster") 306 307 val inv = Monster.createInventoryVector(fbb, byteArrayOf(0, 1, 2, 3, 4).asUByteArray()) 308 309 val fred = fbb.createString("Fred") 310 Monster.startMonster(fbb) 311 Monster.addName(fbb, fred) 312 val mon2 = Monster.endMonster(fbb) 313 314 Monster.startTest4Vector(fbb, 2) 315 Test.createTest(fbb, 10.toShort(), 20.toByte()) 316 Test.createTest(fbb, 30.toShort(), 40.toByte()) 317 val test4 = fbb.endVector() 318 319 val testArrayOfString = 320 Monster.createTestarrayofstringVector(fbb, intArrayOf(fbb.createString("test1"), fbb.createString("test2"))) 321 322 Monster.startMonster(fbb) 323 Monster.addPos( 324 fbb, Vec3.createVec3( 325 fbb, 1.0f, 2.0f, 3.0f, 3.0, 326 Color.Green, 5.toShort(), 6.toByte() 327 ) 328 ) 329 Monster.addHp(fbb, 80.toShort()) 330 Monster.addName(fbb, str) 331 Monster.addInventory(fbb, inv) 332 Monster.addTestType(fbb, Any_.Monster) 333 Monster.addTest(fbb, mon2) 334 Monster.addTest4(fbb, test4) 335 Monster.addTestarrayofstring(fbb, testArrayOfString) 336 Monster.addTestbool(fbb, true) 337 Monster.addTesthashu32Fnv1(fbb, (Integer.MAX_VALUE + 1L).toUInt()) 338 Monster.addTestarrayoftables(fbb, sortMons) 339 val mon = Monster.endMonster(fbb) 340 341 if (sizePrefix) { 342 Monster.finishSizePrefixedMonsterBuffer(fbb, mon) 343 } else { 344 Monster.finishMonsterBuffer(fbb, mon) 345 } 346 347 // Write the result to a file for debugging purposes: 348 // Note that the binaries are not necessarily identical, since the JSON 349 // parser may serialize in a slightly different order than the above 350 // Java code. They are functionally equivalent though. 351 352 try { 353 val filename = "monsterdata_java_wire" + (if (sizePrefix) "_sp" else "") + ".mon" 354 val fc = FileOutputStream(filename).channel 355 fc.write(fbb.dataBuffer().duplicate()) 356 fc.close() 357 } catch (e: java.io.IOException) { 358 println("FlatBuffers test: couldn't write file") 359 return 360 } 361 362 // Test it: 363 var dataBuffer = fbb.dataBuffer() 364 if (sizePrefix) { 365 assert( 366 ByteBufferUtil.getSizePrefix(dataBuffer) + SIZE_PREFIX_LENGTH == 367 dataBuffer.remaining() 368 ) 369 dataBuffer = ByteBufferUtil.removeSizePrefix(dataBuffer) 370 } 371 TestExtendedBuffer(dataBuffer) 372 373 // Make sure it also works with read only ByteBuffers. This is slower, 374 // since creating strings incurs an additional copy 375 // (see Table.__string). 376 TestExtendedBuffer(dataBuffer.asReadOnlyBuffer()) 377 378 TestEnums() 379 380 //Attempt to mutate Monster fields and check whether the buffer has been mutated properly 381 // revert to original values after testing 382 val monster = Monster.getRootAsMonster(dataBuffer) 383 384 // mana is optional and does not exist in the buffer so the mutation should fail 385 // the mana field should retain its default value 386 assert(monster.mutateMana(10.toShort()) == false) 387 assert(monster.mana == 150.toShort()) 388 389 // Accessing a vector of sorted by the key tables 390 assert(monster.testarrayoftables(0)!!.name == "Barney") 391 assert(monster.testarrayoftables(1)!!.name == "Frodo") 392 assert(monster.testarrayoftables(2)!!.name == "Wilma") 393 394 // Example of searching for a table by the key 395 assert(monster.testarrayoftablesByKey("Frodo")!!.name == "Frodo") 396 assert(monster.testarrayoftablesByKey("Barney")!!.name == "Barney") 397 assert(monster.testarrayoftablesByKey("Wilma")!!.name == "Wilma") 398 399 // testType is an existing field and mutating it should succeed 400 assert(monster.testType == Any_.Monster) 401 assert(monster.mutateTestType(Any_.NONE) == true) 402 assert(monster.testType == Any_.NONE) 403 assert(monster.mutateTestType(Any_.Monster) == true) 404 assert(monster.testType == Any_.Monster) 405 406 //mutate the inventory vector 407 assert(monster.mutateInventory(0, 1u) == true) 408 assert(monster.mutateInventory(1, 2u) == true) 409 assert(monster.mutateInventory(2, 3u) == true) 410 assert(monster.mutateInventory(3, 4u) == true) 411 assert(monster.mutateInventory(4, 5u) == true) 412 413 for (i in 0 until monster.inventoryLength) { 414 assert(monster.inventory(i) == (i.toUByte() + 1u).toUByte()) 415 } 416 417 //reverse mutation 418 assert(monster.mutateInventory(0, 0u) == true) 419 assert(monster.mutateInventory(1, 1u) == true) 420 assert(monster.mutateInventory(2, 2u) == true) 421 assert(monster.mutateInventory(3, 3u) == true) 422 assert(monster.mutateInventory(4, 4u) == true) 423 424 // get a struct field and edit one of its fields 425 val pos = monster.pos!! 426 assert(pos.x == 1.0f) 427 pos.mutateX(55.0f) 428 assert(pos.x == 55.0f) 429 pos.mutateX(1.0f) 430 assert(pos.x == 1.0f) 431 } 432 TestVectorOfUnionsnull433 fun TestVectorOfUnions() { 434 val fbb = FlatBufferBuilder() 435 436 val swordAttackDamage = 1 437 438 val characterVector = intArrayOf(Attacker.createAttacker(fbb, swordAttackDamage)) 439 440 val characterTypeVector = ubyteArrayOf(Character_.MuLan) 441 442 Movie.finishMovieBuffer( 443 fbb, 444 Movie.createMovie( 445 fbb, 446 0u, 447 0, 448 Movie.createCharactersTypeVector(fbb, characterTypeVector), 449 Movie.createCharactersVector(fbb, characterVector) 450 ) 451 ) 452 453 val movie = Movie.getRootAsMovie(fbb.dataBuffer()) 454 455 assert(movie.charactersTypeLength == characterTypeVector.size) 456 assert(movie.charactersLength == characterVector.size) 457 458 assert(movie.charactersType(0) == characterTypeVector[0]) 459 460 assert((movie.characters(Attacker(), 0) as Attacker).swordAttackDamage == swordAttackDamage) 461 } 462 TestSharedStringPoolnull463 fun TestSharedStringPool() { 464 val fb = FlatBufferBuilder(1); 465 val testString = "My string"; 466 val offset = fb.createSharedString(testString); 467 for (i in 0..10) { 468 assert(offset == fb.createSharedString(testString)); 469 } 470 } 471 TestScalarOptionalnull472 fun TestScalarOptional() { 473 val fbb = FlatBufferBuilder(1) 474 ScalarStuff.startScalarStuff(fbb) 475 var pos = ScalarStuff.endScalarStuff(fbb) 476 fbb.finish(pos) 477 478 var scalarStuff = ScalarStuff.getRootAsScalarStuff(fbb.dataBuffer()) 479 480 assert(scalarStuff.justI8 == 0.toByte()) 481 assert(scalarStuff.maybeI8 == null) 482 assert(scalarStuff.defaultI8 == 42.toByte()) 483 assert(scalarStuff.justU8 == 0.toUByte()) 484 assert(scalarStuff.maybeU8 == null) 485 assert(scalarStuff.defaultU8 == 42.toUByte()) 486 assert(scalarStuff.justI16 == 0.toShort()) 487 assert(scalarStuff.maybeI16 == null) 488 assert(scalarStuff.defaultI16 == 42.toShort()) 489 assert(scalarStuff.justU16 == 0.toUShort()) 490 assert(scalarStuff.maybeU16 == null) 491 assert(scalarStuff.defaultU16 == 42.toUShort()) 492 assert(scalarStuff.justI32 == 0) 493 assert(scalarStuff.maybeI32 == null) 494 assert(scalarStuff.defaultI32 == 42) 495 assert(scalarStuff.justU32 == 0.toUInt()) 496 assert(scalarStuff.maybeU32 == null) 497 assert(scalarStuff.defaultU32 == 42U) 498 assert(scalarStuff.justI64 == 0L) 499 assert(scalarStuff.maybeI64 == null) 500 assert(scalarStuff.defaultI64 == 42L) 501 assert(scalarStuff.justU64 == 0UL) 502 assert(scalarStuff.maybeU64 == null) 503 assert(scalarStuff.defaultU64 == 42UL) 504 assert(scalarStuff.justF32 == 0.0f) 505 assert(scalarStuff.maybeF32 == null) 506 assert(scalarStuff.defaultF32 == 42.0f) 507 assert(scalarStuff.justF64 == 0.0) 508 assert(scalarStuff.maybeF64 == null) 509 assert(scalarStuff.defaultF64 == 42.0) 510 assert(scalarStuff.justBool == false) 511 assert(scalarStuff.maybeBool == null) 512 assert(scalarStuff.defaultBool == true) 513 assert(scalarStuff.justEnum == OptionalByte.None) 514 assert(scalarStuff.maybeEnum == null) 515 assert(scalarStuff.defaultEnum == OptionalByte.One) 516 517 fbb.clear() 518 519 ScalarStuff.startScalarStuff(fbb) 520 ScalarStuff.addJustI8(fbb, 5.toByte()) 521 ScalarStuff.addMaybeI8(fbb, 5.toByte()) 522 ScalarStuff.addDefaultI8(fbb, 5.toByte()) 523 ScalarStuff.addJustU8(fbb, 6.toUByte()) 524 ScalarStuff.addMaybeU8(fbb, 6.toUByte()) 525 ScalarStuff.addDefaultU8(fbb, 6.toUByte()) 526 ScalarStuff.addJustI16(fbb, 7.toShort()) 527 ScalarStuff.addMaybeI16(fbb, 7.toShort()) 528 ScalarStuff.addDefaultI16(fbb, 7.toShort()) 529 ScalarStuff.addJustU16(fbb, 8.toUShort()) 530 ScalarStuff.addMaybeU16(fbb, 8.toUShort()) 531 ScalarStuff.addDefaultU16(fbb, 8.toUShort()) 532 ScalarStuff.addJustI32(fbb, 9) 533 ScalarStuff.addMaybeI32(fbb, 9) 534 ScalarStuff.addDefaultI32(fbb, 9) 535 ScalarStuff.addJustU32(fbb, 10.toUInt()) 536 ScalarStuff.addMaybeU32(fbb, 10.toUInt()) 537 ScalarStuff.addDefaultU32(fbb, 10.toUInt()) 538 ScalarStuff.addJustI64(fbb, 11L) 539 ScalarStuff.addMaybeI64(fbb, 11L) 540 ScalarStuff.addDefaultI64(fbb, 11L) 541 ScalarStuff.addJustU64(fbb, 12UL) 542 ScalarStuff.addMaybeU64(fbb, 12UL) 543 ScalarStuff.addDefaultU64(fbb, 12UL) 544 ScalarStuff.addJustF32(fbb, 13.0f) 545 ScalarStuff.addMaybeF32(fbb, 13.0f) 546 ScalarStuff.addDefaultF32(fbb, 13.0f) 547 ScalarStuff.addJustF64(fbb, 14.0) 548 ScalarStuff.addMaybeF64(fbb, 14.0) 549 ScalarStuff.addDefaultF64(fbb, 14.0) 550 ScalarStuff.addJustBool(fbb, true) 551 ScalarStuff.addMaybeBool(fbb, true) 552 ScalarStuff.addDefaultBool(fbb, true) 553 ScalarStuff.addJustEnum(fbb, OptionalByte.Two) 554 ScalarStuff.addMaybeEnum(fbb, OptionalByte.Two) 555 ScalarStuff.addDefaultEnum(fbb, OptionalByte.Two) 556 557 pos = ScalarStuff.endScalarStuff(fbb) 558 559 fbb.finish(pos) 560 561 scalarStuff = ScalarStuff.getRootAsScalarStuff(fbb.dataBuffer()) 562 563 assert(scalarStuff.justI8 == 5.toByte()) 564 assert(scalarStuff.maybeI8 == 5.toByte()) 565 assert(scalarStuff.defaultI8 == 5.toByte()) 566 assert(scalarStuff.justU8 == 6.toUByte()) 567 assert(scalarStuff.maybeU8 == 6.toUByte()) 568 assert(scalarStuff.defaultU8 == 6.toUByte()) 569 assert(scalarStuff.justI16 == 7.toShort()) 570 assert(scalarStuff.maybeI16 == 7.toShort()) 571 assert(scalarStuff.defaultI16 == 7.toShort()) 572 assert(scalarStuff.justU16 == 8.toUShort()) 573 assert(scalarStuff.maybeU16 == 8.toUShort()) 574 assert(scalarStuff.defaultU16 == 8.toUShort()) 575 assert(scalarStuff.justI32 == 9) 576 assert(scalarStuff.maybeI32 == 9) 577 assert(scalarStuff.defaultI32 == 9) 578 assert(scalarStuff.justU32 == 10u) 579 assert(scalarStuff.maybeU32 == 10u) 580 assert(scalarStuff.defaultU32 == 10u) 581 assert(scalarStuff.justI64 == 11L) 582 assert(scalarStuff.maybeI64 == 11L) 583 assert(scalarStuff.defaultI64 == 11L) 584 assert(scalarStuff.justU64 == 12UL) 585 assert(scalarStuff.maybeU64 == 12UL) 586 assert(scalarStuff.defaultU64 == 12UL) 587 assert(scalarStuff.justF32 == 13.0f) 588 assert(scalarStuff.maybeF32 == 13.0f) 589 assert(scalarStuff.defaultF32 == 13.0f) 590 assert(scalarStuff.justF64 == 14.0) 591 assert(scalarStuff.maybeF64 == 14.0) 592 assert(scalarStuff.defaultF64 == 14.0) 593 assert(scalarStuff.justBool == true) 594 assert(scalarStuff.maybeBool == true) 595 assert(scalarStuff.defaultBool == true) 596 assert(scalarStuff.justEnum == OptionalByte.Two) 597 assert(scalarStuff.maybeEnum == OptionalByte.Two) 598 assert(scalarStuff.defaultEnum == OptionalByte.Two) 599 } 600 } 601 } 602