RealmConfigurationTests.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. import class Realm.Private.RLMRealmConfiguration
  21. class RealmConfigurationTests: TestCase {
  22. func testDefaultConfiguration() {
  23. let defaultConfiguration = Realm.Configuration.defaultConfiguration
  24. XCTAssertEqual(defaultConfiguration.fileURL, try! Realm().configuration.fileURL)
  25. XCTAssertNil(defaultConfiguration.inMemoryIdentifier)
  26. XCTAssertNil(defaultConfiguration.encryptionKey)
  27. XCTAssertFalse(defaultConfiguration.readOnly)
  28. XCTAssertEqual(defaultConfiguration.schemaVersion, 0)
  29. XCTAssert(defaultConfiguration.migrationBlock == nil)
  30. }
  31. func testSetDefaultConfiguration() {
  32. let fileURL = Realm.Configuration.defaultConfiguration.fileURL
  33. let configuration = Realm.Configuration(fileURL: URL(fileURLWithPath: "/dev/null"))
  34. Realm.Configuration.defaultConfiguration = configuration
  35. XCTAssertEqual(Realm.Configuration.defaultConfiguration.fileURL, URL(fileURLWithPath: "/dev/null"))
  36. Realm.Configuration.defaultConfiguration.fileURL = fileURL
  37. }
  38. func testCannotSetMutuallyExclusiveProperties() {
  39. var configuration = Realm.Configuration()
  40. configuration.readOnly = true
  41. configuration.deleteRealmIfMigrationNeeded = true
  42. assertThrows(try! Realm(configuration: configuration),
  43. reason: "Cannot set `deleteRealmIfMigrationNeeded` when `readOnly` is set.")
  44. }
  45. }