• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * 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 
17 import Foundation
18 import XCTest
19 @testable import FlatBuffers
20 
21 class FlatBuffersMoreDefaults: XCTestCase {
22 
testFlatbuffersObjectnull23   func testFlatbuffersObject() {
24     var fbb = FlatBufferBuilder()
25     let root = MoreDefaults.createMoreDefaults(&fbb)
26     fbb.finish(offset: root)
27     let defaults = MoreDefaults.getRootAsMoreDefaults(bb: fbb.sizedBuffer)
28     XCTAssertEqual(defaults.emptyString, "")
29     XCTAssertEqual(defaults.someString, "some")
30     XCTAssertEqual(defaults.ints, [])
31     XCTAssertEqual(defaults.floats, [])
32     XCTAssertEqual(defaults.bools, [])
33     XCTAssertEqual(defaults.intsCount, 0)
34     XCTAssertEqual(defaults.floatsCount, 0)
35     XCTAssertEqual(defaults.abcsCount, 0)
36     XCTAssertEqual(defaults.boolsCount, 0)
37   }
38 
testFlatbuffersObjectAPInull39   func testFlatbuffersObjectAPI() {
40     var fbb = FlatBufferBuilder()
41     let defaults = MoreDefaultsT()
42     XCTAssertEqual(defaults.emptyString, "")
43     XCTAssertEqual(defaults.someString, "some")
44     XCTAssertEqual(defaults.ints, [])
45     XCTAssertEqual(defaults.floats, [])
46     XCTAssertEqual(defaults.abcs, [])
47     XCTAssertEqual(defaults.bools, [])
48 
49     let buffer = defaults.serialize(builder: &fbb, type: MoreDefaults.self)
50     let fDefaults = MoreDefaults.getRootAsMoreDefaults(bb: buffer)
51     XCTAssertEqual(fDefaults.emptyString, "")
52     XCTAssertEqual(fDefaults.someString, "some")
53     XCTAssertEqual(fDefaults.ints, [])
54     XCTAssertEqual(fDefaults.floats, [])
55     XCTAssertEqual(fDefaults.intsCount, 0)
56     XCTAssertEqual(fDefaults.floatsCount, 0)
57     XCTAssertEqual(fDefaults.abcsCount, 0)
58     XCTAssertEqual(fDefaults.boolsCount, 0)
59   }
60 }
61