123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- ////////////////////////////////////////////////////////////////////////////
- //
- // Copyright 2015 Realm Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- //
- ////////////////////////////////////////////////////////////////////////////
- import XCTest
- import RealmSwift
- class ObjectSchemaTests: TestCase {
- var objectSchema: ObjectSchema!
- var swiftObjectSchema: ObjectSchema {
- return try! Realm().schema["SwiftObject"]!
- }
- func testProperties() {
- let objectSchema = swiftObjectSchema
- let propertyNames = objectSchema.properties.map { $0.name }
- XCTAssertEqual(propertyNames,
- ["boolCol", "intCol", "floatCol", "doubleCol", "stringCol", "binaryCol", "dateCol", "objectCol", "arrayCol"]
- )
- }
- // Cannot name testClassName() because it interferes with the method on XCTest
- func testClassNameProperty() {
- let objectSchema = swiftObjectSchema
- XCTAssertEqual(objectSchema.className, "SwiftObject")
- }
- func testPrimaryKeyProperty() {
- let objectSchema = swiftObjectSchema
- XCTAssertNil(objectSchema.primaryKeyProperty)
- XCTAssertEqual(try! Realm().schema["SwiftPrimaryStringObject"]!.primaryKeyProperty!.name, "stringCol")
- }
- func testDescription() {
- let objectSchema = swiftObjectSchema
- let expected =
- "SwiftObject {\n" +
- " boolCol {\n" +
- " type = bool;\n" +
- " objectClassName = (null);\n" +
- " linkOriginPropertyName = (null);\n" +
- " indexed = NO;\n" +
- " isPrimary = NO;\n" +
- " array = NO;\n" +
- " optional = NO;\n" +
- " }\n" +
- " intCol {\n" +
- " type = int;\n" +
- " objectClassName = (null);\n" +
- " linkOriginPropertyName = (null);\n" +
- " indexed = NO;\n" +
- " isPrimary = NO;\n" +
- " array = NO;\n" +
- " optional = NO;\n" +
- " }\n" +
- " floatCol {\n" +
- " type = float;\n" +
- " objectClassName = (null);\n" +
- " linkOriginPropertyName = (null);\n" +
- " indexed = NO;\n" +
- " isPrimary = NO;\n" +
- " array = NO;\n" +
- " optional = NO;\n" +
- " }\n" +
- " doubleCol {\n" +
- " type = double;\n" +
- " objectClassName = (null);\n" +
- " linkOriginPropertyName = (null);\n" +
- " indexed = NO;\n" +
- " isPrimary = NO;\n" +
- " array = NO;\n" +
- " optional = NO;\n" +
- " }\n" +
- " stringCol {\n" +
- " type = string;\n" +
- " objectClassName = (null);\n" +
- " linkOriginPropertyName = (null);\n" +
- " indexed = NO;\n" +
- " isPrimary = NO;\n" +
- " array = NO;\n" +
- " optional = NO;\n" +
- " }\n" +
- " binaryCol {\n" +
- " type = data;\n" +
- " objectClassName = (null);\n" +
- " linkOriginPropertyName = (null);\n" +
- " indexed = NO;\n" +
- " isPrimary = NO;\n" +
- " array = NO;\n" +
- " optional = NO;\n" +
- " }\n" +
- " dateCol {\n" +
- " type = date;\n" +
- " objectClassName = (null);\n" +
- " linkOriginPropertyName = (null);\n" +
- " indexed = NO;\n" +
- " isPrimary = NO;\n" +
- " array = NO;\n" +
- " optional = NO;\n" +
- " }\n" +
- " objectCol {\n" +
- " type = object;\n" +
- " objectClassName = SwiftBoolObject;\n" +
- " linkOriginPropertyName = (null);\n" +
- " indexed = NO;\n" +
- " isPrimary = NO;\n" +
- " array = NO;\n" +
- " optional = YES;\n" +
- " }\n" +
- " arrayCol {\n" +
- " type = object;\n" +
- " objectClassName = SwiftBoolObject;\n" +
- " linkOriginPropertyName = (null);\n" +
- " indexed = NO;\n" +
- " isPrimary = NO;\n" +
- " array = YES;\n" +
- " optional = NO;\n" +
- " }\n" +
- "}"
- XCTAssertEqual(objectSchema.description, expected.replacingOccurrences(of: " ", with: "\t"))
- }
- func testSubscript() {
- let objectSchema = swiftObjectSchema
- XCTAssertNil(objectSchema["noSuchProperty"])
- XCTAssertEqual(objectSchema["boolCol"]!.name, "boolCol")
- }
- func testEquals() {
- let objectSchema = swiftObjectSchema
- XCTAssert(try! objectSchema == Realm().schema["SwiftObject"]!)
- XCTAssert(try! objectSchema != Realm().schema["SwiftStringObject"]!)
- }
- }
|