UnicodeTests.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 "RLMTestCase.h"
  19. NSString * const kUTF8TestString = @"值значен™👍☞⎠‱௹♣︎☐▼❒∑⨌⧭иеمرحبا";
  20. @interface UnicodeTests : RLMTestCase
  21. @end
  22. @implementation UnicodeTests
  23. - (void)testUTF8StringContents
  24. {
  25. RLMRealm *realm = self.realmWithTestPath;
  26. [realm beginWriteTransaction];
  27. [StringObject createInRealm:realm withValue:@[kUTF8TestString]];
  28. [realm commitWriteTransaction];
  29. StringObject *obj1 = [[StringObject allObjectsInRealm:realm] firstObject];
  30. XCTAssertEqualObjects(obj1.stringCol, kUTF8TestString, @"Storing and retrieving a string with UTF8 content should work");
  31. StringObject *obj2 = [[StringObject objectsInRealm:realm where:@"stringCol == %@", kUTF8TestString] firstObject];
  32. XCTAssertTrue([obj1 isEqualToObject:obj2], @"Querying a realm searching for a string with UTF8 content should work");
  33. }
  34. - (void)testUTF8PropertyWithUTF8StringContents
  35. {
  36. RLMRealm *realm = self.realmWithTestPath;
  37. [realm beginWriteTransaction];
  38. [UTF8Object createInRealm:realm withValue:@[kUTF8TestString]];
  39. [realm commitWriteTransaction];
  40. UTF8Object *obj1 = [[UTF8Object allObjectsInRealm:realm] firstObject];
  41. XCTAssertEqualObjects(obj1.柱колоéнǢкƱаم, kUTF8TestString, @"Storing and retrieving a string with UTF8 content should work");
  42. // Test fails because of rdar://17735684
  43. // NSPredicate does not support UTF8 keypaths
  44. // UTF8Object *obj2 = [[StringObject objectsInRealm:realm where:@"柱колоéнǢкƱаم == %@", kUTF8TestString] firstObject];
  45. // XCTAssertEqualObjects(obj1, obj2, @"Querying a realm searching for a string with UTF8 content should work");
  46. }
  47. @end