SwiftUnicodeTests.swift 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2014 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 Realm
  20. import RealmTestSupport
  21. let utf8TestString = "值значен™👍☞⎠‱௹♣︎☐▼❒∑⨌⧭иеمرحبا"
  22. class SwiftRLMUnicodeTests: RLMTestCase {
  23. // Swift models
  24. func testUTF8StringContents() {
  25. let realm = realmWithTestPath()
  26. realm.beginWriteTransaction()
  27. _ = SwiftRLMStringObject.create(in: realm, withValue: [utf8TestString])
  28. try! realm.commitWriteTransaction()
  29. let obj1 = SwiftRLMStringObject.allObjects(in: realm).firstObject() as! SwiftRLMStringObject
  30. XCTAssertEqual(obj1.stringCol, utf8TestString, "Storing and retrieving a string with UTF8 content should work")
  31. let obj2 = SwiftRLMStringObject.objects(in: realm, where: "stringCol == %@", utf8TestString).firstObject() as! SwiftRLMStringObject
  32. XCTAssertTrue(obj1.isEqual(to: obj2), "Querying a realm searching for a string with UTF8 content should work")
  33. }
  34. func testUTF8PropertyWithUTF8StringContents() {
  35. let realm = realmWithTestPath()
  36. realm.beginWriteTransaction()
  37. _ = SwiftRLMUTF8Object.create(in: realm, withValue: [utf8TestString])
  38. try! realm.commitWriteTransaction()
  39. let obj1 = SwiftRLMUTF8Object.allObjects(in: realm).firstObject() as! SwiftRLMUTF8Object
  40. XCTAssertEqual(obj1.柱колоéнǢкƱаم👍, utf8TestString, "Storing and retrieving a string with UTF8 content should work")
  41. // Test fails because of rdar://17735684
  42. // let obj2 = SwiftRLMUTF8Object.objectsInRealm(realm, "柱колоéнǢкƱаم👍 == %@", utf8TestString).firstObject() as SwiftRLMUTF8Object
  43. // XCTAssertEqual(obj1, obj2, "Querying a realm searching for a string with UTF8 content should work")
  44. }
  45. // Objective-C models
  46. func testUTF8StringContents_objc() {
  47. let realm = realmWithTestPath()
  48. realm.beginWriteTransaction()
  49. _ = StringObject.create(in: realm, withValue: [utf8TestString])
  50. try! realm.commitWriteTransaction()
  51. let obj1 = StringObject.allObjects(in: realm).firstObject() as! StringObject
  52. XCTAssertEqual(obj1.stringCol, utf8TestString, "Storing and retrieving a string with UTF8 content should work")
  53. // Temporarily commented out because variadic import seems broken
  54. let obj2 = StringObject.objects(in: realm, where: "stringCol == %@", utf8TestString).firstObject() as! StringObject
  55. XCTAssertTrue(obj1.isEqual(to: obj2), "Querying a realm searching for a string with UTF8 content should work")
  56. }
  57. func testUTF8PropertyWithUTF8StringContents_objc() {
  58. let realm = realmWithTestPath()
  59. realm.beginWriteTransaction()
  60. _ = UTF8Object.create(in: realm, withValue: [utf8TestString])
  61. try! realm.commitWriteTransaction()
  62. let obj1 = UTF8Object.allObjects(in: realm).firstObject() as! UTF8Object
  63. XCTAssertEqual(obj1.柱колоéнǢкƱаم, utf8TestString, "Storing and retrieving a string with UTF8 content should work")
  64. // Test fails because of rdar://17735684
  65. // let obj2 = UTF8Object.objectsInRealm(realm, "柱колоéнǢкƱаم == %@", utf8TestString).firstObject() as UTF8Object
  66. // XCTAssertEqual(obj1, obj2, "Querying a realm searching for a string with UTF8 content should work")
  67. }
  68. }