PropertyTests.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. import XCTest
  19. import RealmSwift
  20. class PropertyTests: TestCase {
  21. var primitiveProperty: Property!
  22. var linkProperty: Property!
  23. var primaryProperty: Property!
  24. var optionalProperty: Property!
  25. override func setUp() {
  26. super.setUp()
  27. autoreleasepool {
  28. let schema = try! Realm().schema
  29. self.primitiveProperty = schema["SwiftObject"]!["intCol"]!
  30. self.linkProperty = schema["SwiftOptionalObject"]!["optObjectCol"]!
  31. self.primaryProperty = schema["SwiftPrimaryStringObject"]!["stringCol"]!
  32. self.optionalProperty = schema["SwiftOptionalObject"]!["optObjectCol"]!
  33. }
  34. }
  35. func testName() {
  36. XCTAssertEqual(primitiveProperty.name, "intCol")
  37. XCTAssertEqual(linkProperty.name, "optObjectCol")
  38. XCTAssertEqual(primaryProperty.name, "stringCol")
  39. }
  40. func testType() {
  41. XCTAssertEqual(primitiveProperty.type, PropertyType.int)
  42. XCTAssertEqual(linkProperty.type, PropertyType.object)
  43. XCTAssertEqual(primaryProperty.type, PropertyType.string)
  44. }
  45. func testIndexed() {
  46. XCTAssertFalse(primitiveProperty.isIndexed)
  47. XCTAssertFalse(linkProperty.isIndexed)
  48. XCTAssertTrue(primaryProperty.isIndexed)
  49. }
  50. func testOptional() {
  51. XCTAssertFalse(primitiveProperty.isOptional)
  52. XCTAssertTrue(optionalProperty.isOptional)
  53. }
  54. func testObjectClassName() {
  55. XCTAssertNil(primitiveProperty.objectClassName)
  56. XCTAssertEqual(linkProperty.objectClassName!, "SwiftBoolObject")
  57. XCTAssertNil(primaryProperty.objectClassName)
  58. }
  59. func testEquals() {
  60. XCTAssert(try! primitiveProperty == Realm().schema["SwiftObject"]!["intCol"]!)
  61. XCTAssert(primitiveProperty != linkProperty)
  62. }
  63. }