SwiftUnicodeTests.swift 3.9 KB

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