Repository: realm/realm-swift
File: Realm/Tests/SchemaTests.mm (Objective-C++)

Code before:
        XCTAssertEqualObjects(className, [objectSchema.standaloneClass className]);
        XCTAssertEqualObjects(className, [objectSchema.accessorClass className]);

        XCTAssertEqual(objectSchema.properties.count, properties.count);
        for (NSString *propName in properties) {
            XCTAssertEqualObjects(properties[propName], [objectSchema[propName] objectClassName]);
        }
    };

    // Test each permutation of loading orders and verify that all properties
    // are initialized correctly
    std::sort(testClasses, std::end(testClasses), pred);
    do @autoreleasepool {
        // Clean up any existing overridden things
        for (Class cls : testClasses) {
            NSString *className = NSStringFromClass(cls);
            if (Class subclass = NSClassFromString([@"RLMAccessor_" stringByAppendingString:className])) {
                objc_disposeClassPair(subclass);
            }
            if (Class subclass = NSClassFromString([@"RLMStandalone_" stringByAppendingString:className])) {
                objc_disposeClassPair(subclass);
            }

            // Ensure that the className method isn't used during schema init
            // as it may not be overriden yet
            Class metaClass = objc_getMetaClass(className.UTF8String);
            IMP imp = imp_implementationWithBlock(^{ return nil; });
            class_replaceMethod(metaClass, @selector(className), imp, "@:");
        }

        NSMutableArray *objectSchemas = [NSMutableArray arrayWithCapacity:4U];
        for (Class cls : testClasses) {
            [objectSchemas addObject:[RLMObjectSchema schemaForObjectClass:cls createAccessors:YES]];
        }

        RLMSchema *schema = [[RLMSchema alloc] init];
        schema.objectSchema = objectSchemas;

        for (RLMObjectSchema *objectSchema in objectSchemas) {
            objectSchema.accessorClass = RLMAccessorClassForObjectClass(objectSchema.objectClass, objectSchema);
        }

        // Verify that each class has the correct properties and className
        // for generated subclasses
        checkSchema(schema, @"SchemaTestClassBase", @{@"baseCol": @"IntObject"});
        checkSchema(schema, @"SchemaTestClassFirstChild", @{@"baseCol": @"IntObject",
                                                            @"firstChildCol": @"IntObject"});
        checkSchema(schema, @"SchemaTestClassSecondChild", @{@"baseCol": @"IntObject",
                                                            @"secondChildCol": @"IntObject"});
        checkSchema(schema, @"SchemaTestClassLink", @{@"base": @"SchemaTestClassBase",
                                                      @"baseArray": @"SchemaTestClassBase",

Review comment (suggestion):
Should do the same for the `sharedSchema` method.


Code after:
        XCTAssertEqualObjects(className, [objectSchema.standaloneClass className]);
        XCTAssertEqualObjects(className, [objectSchema.accessorClass className]);

        XCTAssertEqual(objectSchema.properties.count, properties.count);
        for (NSString *propName in properties) {
            XCTAssertEqualObjects(properties[propName], [objectSchema[propName] objectClassName]);
        }
    };

    // Test each permutation of loading orders and verify that all properties
    // are initialized correctly
    std::sort(testClasses, std::end(testClasses), pred);
    do @autoreleasepool {
        // Clean up any existing overridden things
        for (Class cls : testClasses) {
            NSString *className = NSStringFromClass(cls);
            if (Class subclass = NSClassFromString([@"RLMAccessor_" stringByAppendingString:className])) {
                objc_disposeClassPair(subclass);
            }
            if (Class subclass = NSClassFromString([@"RLMStandalone_" stringByAppendingString:className])) {
                objc_disposeClassPair(subclass);
            }

            // Ensure that the className method isn't used during schema init
            // as it may not be overriden yet
            Class metaClass = objc_getMetaClass(className.UTF8String);
            IMP imp = imp_implementationWithBlock(^{ return nil; });
            class_replaceMethod(metaClass, @selector(className), imp, "@:");
            class_replaceMethod(metaClass, @selector(sharedSchema), imp, "@:");
        }

        NSMutableArray *objectSchemas = [NSMutableArray arrayWithCapacity:4U];
        for (Class cls : testClasses) {
            [objectSchemas addObject:[RLMObjectSchema schemaForObjectClass:cls createAccessors:YES]];
        }

        RLMSchema *schema = [[RLMSchema alloc] init];
        schema.objectSchema = objectSchemas;

        for (RLMObjectSchema *objectSchema in objectSchemas) {
            objectSchema.accessorClass = RLMAccessorClassForObjectClass(objectSchema.objectClass, objectSchema);
        }

        // Verify that each class has the correct properties and className
        // for generated subclasses
        checkSchema(schema, @"SchemaTestClassBase", @{@"baseCol": @"IntObject"});
        checkSchema(schema, @"SchemaTestClassFirstChild", @{@"baseCol": @"IntObject",
                                                            @"firstChildCol": @"IntObject"});
        checkSchema(schema, @"SchemaTestClassSecondChild", @{@"baseCol": @"IntObject",
                                                            @"secondChildCol": @"IntObject"});
        checkSchema(schema, @"SchemaTestClassLink", @{@"base": @"SchemaTestClassBase",