Refactor tests to run again inside Xcode

Added a CommonJS module loader that is used by XCTestCase subclass to load and run the tests.
This commit is contained in:
Scott Kyle 2015-10-06 00:57:35 -07:00
parent 22076933ad
commit db80c3a89a
16 changed files with 416 additions and 265 deletions

View File

@ -47,8 +47,8 @@
0270BC821B7D020100010E03 /* RealmJSTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0270BC7B1B7D020100010E03 /* RealmJSTests.mm */; };
0270BC831B7D020100010E03 /* RealmTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7C1B7D020100010E03 /* RealmTests.js */; };
0270BC841B7D020100010E03 /* ResultsTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7D1B7D020100010E03 /* ResultsTests.js */; };
0270BC851B7D020100010E03 /* TestCase.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7E1B7D020100010E03 /* TestCase.js */; };
0270BC861B7D020100010E03 /* TestObjects.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7F1B7D020100010E03 /* TestObjects.js */; };
0270BC851B7D020100010E03 /* asserts.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7E1B7D020100010E03 /* asserts.js */; };
0270BC861B7D020100010E03 /* schemas.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7F1B7D020100010E03 /* schemas.js */; };
0270BC871B7D023200010E03 /* RealmJS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CB11AE99CEC009B348C /* RealmJS.framework */; };
0270BCD11B7D067300010E03 /* RealmReactModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 0270BCD01B7D067300010E03 /* RealmReactModule.m */; };
02A3C7971BC4318600B1A7BE /* GCDWebServers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02A3C7941BC4317A00B1A7BE /* GCDWebServers.framework */; };
@ -56,6 +56,9 @@
02B58CCE1AE99D4D009B348C /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 02D456D91B7E59A500EE1299 /* ArrayTests.js */; };
02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
F64E1EF11BC3510E00E0E150 /* util.js in Resources */ = {isa = PBXBuildFile; fileRef = F64E1EF01BC3510E00E0E150 /* util.js */; settings = {ASSET_TAGS = (); }; };
F68A278C1BC2722A0063D40A /* RJSModuleLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */; settings = {ASSET_TAGS = (); }; };
F68A278E1BC30F0A0063D40A /* index.js in Resources */ = {isa = PBXBuildFile; fileRef = F68A278D1BC30F0A0063D40A /* index.js */; settings = {ASSET_TAGS = (); }; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -166,8 +169,8 @@
0270BC7B1B7D020100010E03 /* RealmJSTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RealmJSTests.mm; path = tests/RealmJSTests.mm; sourceTree = SOURCE_ROOT; };
0270BC7C1B7D020100010E03 /* RealmTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = RealmTests.js; path = tests/RealmTests.js; sourceTree = SOURCE_ROOT; };
0270BC7D1B7D020100010E03 /* ResultsTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = ResultsTests.js; path = tests/ResultsTests.js; sourceTree = SOURCE_ROOT; };
0270BC7E1B7D020100010E03 /* TestCase.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = TestCase.js; path = tests/TestCase.js; sourceTree = SOURCE_ROOT; };
0270BC7F1B7D020100010E03 /* TestObjects.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = TestObjects.js; path = tests/TestObjects.js; sourceTree = SOURCE_ROOT; };
0270BC7E1B7D020100010E03 /* asserts.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = asserts.js; path = tests/asserts.js; sourceTree = SOURCE_ROOT; };
0270BC7F1B7D020100010E03 /* schemas.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = schemas.js; path = tests/schemas.js; sourceTree = SOURCE_ROOT; };
0270BCCF1B7D067300010E03 /* RealmReactModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RealmReactModule.h; path = ReactNative/RealmReactModule.h; sourceTree = "<group>"; };
0270BCD01B7D067300010E03 /* RealmReactModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RealmReactModule.m; path = ReactNative/RealmReactModule.m; sourceTree = "<group>"; };
02A3C7841BC4317A00B1A7BE /* GCDWebServer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GCDWebServer.xcodeproj; path = vendor/GCDWebServer/GCDWebServer.xcodeproj; sourceTree = "<group>"; };
@ -177,6 +180,10 @@
02B58CBC1AE99CEC009B348C /* RealmJSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RealmJSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
02D456D91B7E59A500EE1299 /* ArrayTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = ArrayTests.js; path = tests/ArrayTests.js; sourceTree = SOURCE_ROOT; };
F64E1EF01BC3510E00E0E150 /* util.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = util.js; path = tests/util.js; sourceTree = SOURCE_ROOT; };
F68A278A1BC2722A0063D40A /* RJSModuleLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RJSModuleLoader.h; path = tests/RJSModuleLoader.h; sourceTree = SOURCE_ROOT; };
F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RJSModuleLoader.m; path = tests/RJSModuleLoader.m; sourceTree = SOURCE_ROOT; };
F68A278D1BC30F0A0063D40A /* index.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = index.js; path = tests/index.js; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -299,15 +306,19 @@
02B58CC01AE99CEC009B348C /* RealmJSTests */ = {
isa = PBXGroup;
children = (
02D456D91B7E59A500EE1299 /* ArrayTests.js */,
0270BC781B7D020100010E03 /* Info.plist */,
F68A278D1BC30F0A0063D40A /* index.js */,
0270BC7E1B7D020100010E03 /* asserts.js */,
0270BC7F1B7D020100010E03 /* schemas.js */,
F64E1EF01BC3510E00E0E150 /* util.js */,
02D456D91B7E59A500EE1299 /* ArrayTests.js */,
0270BC791B7D020100010E03 /* ObjectTests.js */,
0270BC7A1B7D020100010E03 /* RealmJSTests.h */,
0270BC7B1B7D020100010E03 /* RealmJSTests.mm */,
0270BC7C1B7D020100010E03 /* RealmTests.js */,
0270BC7D1B7D020100010E03 /* ResultsTests.js */,
0270BC7F1B7D020100010E03 /* TestObjects.js */,
0270BC7E1B7D020100010E03 /* TestCase.js */,
0270BC7A1B7D020100010E03 /* RealmJSTests.h */,
0270BC7B1B7D020100010E03 /* RealmJSTests.mm */,
F68A278A1BC2722A0063D40A /* RJSModuleLoader.h */,
F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */,
);
path = RealmJSTests;
sourceTree = "<group>";
@ -503,10 +514,12 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0270BC851B7D020100010E03 /* TestCase.js in Resources */,
F64E1EF11BC3510E00E0E150 /* util.js in Resources */,
0270BC851B7D020100010E03 /* asserts.js in Resources */,
0270BC811B7D020100010E03 /* ObjectTests.js in Resources */,
02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */,
0270BC861B7D020100010E03 /* TestObjects.js in Resources */,
0270BC861B7D020100010E03 /* schemas.js in Resources */,
F68A278E1BC30F0A0063D40A /* index.js in Resources */,
0270BC831B7D020100010E03 /* RealmTests.js in Resources */,
0270BC841B7D020100010E03 /* ResultsTests.js in Resources */,
);
@ -568,6 +581,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F68A278C1BC2722A0063D40A /* RJSModuleLoader.m in Sources */,
0270BC821B7D020100010E03 /* RealmJSTests.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -18,9 +18,12 @@
'use strict';
var ArrayTests = {
var TestCase = require('./asserts');
var schemas = require('./schemas');
module.exports = {
testLinkTypesPropertySetters: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
var obj = null;
realm.write(function() {
obj = realm.create('LinkTypesObject', [[1], undefined, [[3]]]);
@ -51,7 +54,7 @@ var ArrayTests = {
},
testArrayLength: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
realm.write(function() {
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
TestCase.assertEqual(obj.arrayCol.length, 1);
@ -65,7 +68,7 @@ var ArrayTests = {
},
testArraySubscript: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
realm.write(function() { realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]); });
var array = realm.objects('LinkTypesObject')[0].arrayCol;
@ -76,7 +79,7 @@ var ArrayTests = {
},
testArrayInvalidProperty: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
realm.write(function() { realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]); });
var array = realm.objects('LinkTypesObject')[0].arrayCol;
@ -84,7 +87,7 @@ var ArrayTests = {
},
testArrayEnumerate: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
realm.write(function() { realm.create('LinkTypesObject', [[1], [2], []]); });
var obj = realm.objects('LinkTypesObject')[0];
@ -106,7 +109,7 @@ var ArrayTests = {
},
testPush: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
var array;
realm.write(function() {
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
@ -134,7 +137,7 @@ var ArrayTests = {
},
testPop: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
var array;
realm.write(function() {
var obj = realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]);
@ -157,7 +160,7 @@ var ArrayTests = {
},
testUnshift: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
var array;
realm.write(function() {
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
@ -181,7 +184,7 @@ var ArrayTests = {
},
testShift: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
var array;
realm.write(function() {
var obj = realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]);
@ -204,7 +207,7 @@ var ArrayTests = {
},
testSplice: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
realm.write(function() {
var obj = realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]);
@ -250,5 +253,3 @@ var ArrayTests = {
});
},
};
module.exports = ArrayTests;

View File

@ -18,17 +18,20 @@
'use strict';
var ObjectTests = {
var TestCase = require('./asserts');
var schemas = require('./schemas');
module.exports = {
testBasicTypesPropertyGetters: function() {
var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];
var realm = new Realm({schema: [BasicTypesObjectSchema]});
var realm = new Realm({schema: [schemas.BasicTypes]});
var object = null;
realm.write(function() {
object = realm.create('BasicTypesObject', basicTypesValues);
});
for (var i = 0; i < BasicTypesObjectSchema.properties.length; i++) {
var prop = BasicTypesObjectSchema.properties[i];
for (var i = 0; i < schemas.BasicTypes.properties.length; i++) {
var prop = schemas.BasicTypes.properties[i];
if (prop.type == Realm.Types.FLOAT) {
TestCase.assertEqualWithTolerance(object[prop.name], basicTypesValues[i], 0.000001);
}
@ -42,7 +45,7 @@ var ObjectTests = {
},
testBasicTypesPropertySetters: function() {
var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];
var realm = new Realm({schema: [BasicTypesObjectSchema]});
var realm = new Realm({schema: [schemas.BasicTypes]});
var obj = null;
realm.write(function() {
obj = realm.create('BasicTypesObject', basicTypesValues);
@ -63,7 +66,7 @@ var ObjectTests = {
TestCase.assertEqual(obj.dataCol, 'b', 'wrong data value');
},
testLinkTypesPropertyGetters: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
var obj = null;
realm.write(function() {
obj = realm.create('LinkTypesObject', [[1], null, [[3]]]);
@ -83,7 +86,7 @@ var ObjectTests = {
TestCase.assertEqual(arrayVal[0].doubleCol, 3);
},
testLinkTypesPropertySetters: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
var obj = null;
realm.write(function() {
obj = realm.create('LinkTypesObject', [[1], null, [[3]]]);
@ -122,4 +125,3 @@ var ObjectTests = {
TestCase.assertEqual(obj.arrayCol[2].doubleCol, 2);
},
};
module.exports = ObjectTests;

30
tests/RJSModuleLoader.h Normal file
View File

@ -0,0 +1,30 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <JavaScriptCore/JavaScriptCore.h>
@interface RJSModuleLoader : NSObject
- (instancetype)initWithContext:(JSContext *)context;
- (void)addGlobalModuleObject:(id)object forName:(NSString *)name;
- (JSValue *)loadModuleFromURL:(NSURL *)url error:(NSError **)error;
@end

183
tests/RJSModuleLoader.m Normal file
View File

@ -0,0 +1,183 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
#import "RJSModuleLoader.h"
static NSString * const RJSModuleLoaderErrorDomain = @"RJSModuleLoaderErrorDomain";
@interface RJSModuleLoader ()
@property (nonatomic, strong) JSContext *context;
@property (nonatomic, strong) NSMutableDictionary *modules;
@property (nonatomic, strong) NSMutableDictionary *globalModules;
@end
@implementation RJSModuleLoader
- (instancetype)initWithContext:(JSContext *)context {
self = [super init];
if (!self) {
return nil;
}
_context = context;
_modules = [[NSMutableDictionary alloc] init];
_globalModules = [[NSMutableDictionary alloc] init];
return self;
}
- (void)addGlobalModuleObject:(id)object forName:(NSString *)name {
self.globalModules[name] = [JSValue valueWithObject:object inContext:self.context];
}
- (JSValue *)loadModule:(NSString *)name relativeToURL:(NSURL *)baseURL error:(NSError **)error
{
if (![name hasPrefix:@"./"] && ![name hasPrefix:@"../"]) {
return [self loadGlobalModule:name relativeToURL:baseURL error:error];
}
NSURL *url = [[NSURL URLWithString:name relativeToURL:baseURL] absoluteURL];
BOOL isDirectory;
if ([[NSFileManager defaultManager] fileExistsAtPath:url.path isDirectory:&isDirectory]) {
if (!isDirectory) {
return nil;
}
url = [url URLByAppendingPathComponent:@"index.js"];
} else {
url = [url URLByAppendingPathExtension:@"js"];
}
return [self loadModuleFromURL:url error:error];
}
- (JSValue *)loadModuleFromURL:(NSURL *)url error:(NSError **)error {
url = url.absoluteURL;
url = url.standardizedURL ?: url;
NSString *path = url.path;
JSValue *exports = self.modules[path];
if (exports) {
return exports;
}
NSString *source = [NSString stringWithContentsOfURL:url usedEncoding:NULL error:error];
if (!source) {
return nil;
}
JSContext *context = self.context;
JSValue *module = [JSValue valueWithNewObjectInContext:context];
exports = [JSValue valueWithNewObjectInContext:context];
module[@"exports"] = exports;
__weak __typeof__(self) weakSelf = self;
JSValue *require = [JSValue valueWithObject:^JSValue *(NSString *name) {
NSError *error;
JSValue *result = [weakSelf loadModule:name relativeToURL:url error:&error];
if (!result) {
NSString *message = [NSString stringWithFormat:@"Error requiring module '%@': %@", name, error ?: @"Not found"];
JSContext *context = [JSContext currentContext];
context.exception = [JSValue valueWithNewErrorFromMessage:message inContext:context];
return nil;
}
return result;
} inContext:context];
JSStringRef jsParameterNames[] = {JSStringCreateWithUTF8CString("module"), JSStringCreateWithUTF8CString("exports"), JSStringCreateWithUTF8CString("require")};
JSStringRef jsSource = JSStringCreateWithCFString((__bridge CFStringRef)source);
JSStringRef jsSourceURL = JSStringCreateWithCFString((__bridge CFStringRef)path);
JSValueRef jsException;
JSObjectRef jsModuleFunction = JSObjectMakeFunction(context.JSGlobalContextRef, NULL, 3, jsParameterNames, jsSource, jsSourceURL, 1, &jsException);
JSStringRelease(jsParameterNames[0]);
JSStringRelease(jsParameterNames[1]);
JSStringRelease(jsParameterNames[2]);
JSStringRelease(jsSource);
JSStringRelease(jsSourceURL);
// Start with the original exports for circular dependendies and in case of an error.
self.modules[path] = exports;
JSValue *exception;
if (jsModuleFunction) {
JSValue *moduleFunction = [JSValue valueWithJSValueRef:jsModuleFunction inContext:context];
[moduleFunction callWithArguments:@[module, exports, require]];
exception = context.exception;
} else {
exception = [JSValue valueWithJSValueRef:jsException inContext:context];
}
exports = module[@"exports"];
self.modules[path] = exports;
if (exception) {
*error = [NSError errorWithDomain:RJSModuleLoaderErrorDomain code:1 userInfo:@{
NSLocalizedDescriptionKey: exception.description,
NSURLErrorKey: url,
@"JSException": exception,
}];
return nil;
}
return exports;
}
- (JSValue *)loadGlobalModule:(NSString *)name relativeToURL:(NSURL *)baseURL error:(NSError **)error {
JSValue *exports = self.globalModules[name];
if (exports || !baseURL) {
return exports;
}
NSURL *bundleResourcesURL = [[NSBundle bundleForClass:self.class] resourceURL];
NSFileManager *fileManager = [NSFileManager defaultManager];
while (YES) {
NSURL *moduleURL = [NSURL URLWithString:[@"node_modules" stringByAppendingPathComponent:name] relativeToURL:baseURL];
BOOL isDirectory;
if ([fileManager fileExistsAtPath:moduleURL.path isDirectory:&isDirectory] && isDirectory) {
return [self loadModuleFromURL:moduleURL error:error];
}
// Remove last two path components (node_modules/name) and make absolute.
baseURL = moduleURL.URLByDeletingLastPathComponent.URLByDeletingLastPathComponent.absoluteURL;
if ([baseURL isEqual:bundleResourcesURL] || !baseURL.path.length) {
break;
}
// Retry with parent directory.
baseURL = baseURL.URLByDeletingLastPathComponent;
}
return nil;
}
@end

View File

@ -6,13 +6,13 @@
var React = require('react-native');
var Realm = require('realm');
var RealmTestSuite = require('RealmTestSuite');
var RealmTests = require('realm-tests');
RealmTestSuite.tests.forEach(function(suite, name) {
for (var name in suite) {
suite[name]();
}
});
for (var suiteName in RealmTests) {
for (var testName in RealmTests[suiteName]) {
RealmTests[suiteName][testName]();
}
}
var {
AppRegistry,

View File

@ -8,6 +8,6 @@
"dependencies": {
"react-native": "^0.11.4",
"realm": "file:../../lib",
"RealmTestSuite": "file:.."
"realm-tests": "file:.."
}
}

View File

@ -24,8 +24,4 @@ extern NSString *TestRealmPath();
@interface RealmJSTests : XCTestCase
+ (NSString *)jsSuiteName;
@property (nonatomic, readonly) JSContext *context;
@end

View File

@ -16,9 +16,12 @@
//
////////////////////////////////////////////////////////////////////////////
#import <objc/runtime.h>
#import "RealmJSTests.h"
#import "RJSUtil.hpp"
#import "RJSRealm.hpp"
#import "RJSModuleLoader.h"
NSString *RealmPathForFile(NSString *fileName) {
#if TARGET_OS_IPHONE
@ -53,20 +56,27 @@ static void DeleteRealmFilesAtPath(NSString *path) {
DeleteOrThrow([path stringByAppendingString:@".note"]);
}
static JSClassRef s_globalClass;
@interface RealmJSTests ()
@property (nonatomic, strong) JSContext *context;
@property (nonatomic, strong) JSValue *testObject;
@end
@implementation RealmJSTests
+ (void)initialize {
JSClassDefinition globalDefinition = kJSClassDefinitionEmpty;
globalDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
s_globalClass = JSClassCreate(&globalDefinition);
- (instancetype)initWithJSTestObject:(JSValue *)testObject methodName:(NSString *)methodName {
self = [super initWithSelector:NSSelectorFromString(methodName)];
if (!self) {
return nil;
}
_testObject = testObject;
return self;
}
- (JSContext *)context {
return self.testObject.context;
}
- (void)setUp {
@ -77,20 +87,10 @@ static JSClassRef s_globalClass;
[[NSFileManager defaultManager] createDirectoryAtPath:defaultDir withIntermediateDirectories:YES attributes:nil error:nil];
RJSSetDefaultPath([defaultDir stringByAppendingPathComponent:@"default.realm"].UTF8String);
JSGlobalContextRef ctx = JSGlobalContextCreateInGroup(NULL, s_globalClass);
self.context = [JSContext contextWithJSGlobalContextRef:ctx];
[RealmJS initializeContext:ctx];
[self evaluateScript:@"var exports = {};" fromURL:nil];
[self evaluateScriptWithName:@"TestCase"];
[self evaluateScriptWithName:@"TestObjects"];
[self evaluateScriptWithName:self.class.jsSuiteName];
self.context.exception = nil;
}
- (void)tearDown {
self.context = nil;
DeleteRealmFilesAtPath(TestRealmPath());
DeleteRealmFilesAtPath(@(RJSDefaultPath().c_str()));
@ -103,107 +103,33 @@ static JSClassRef s_globalClass;
}
}
- (void)evaluateScriptWithName:(NSString *)name {
NSURL *url = [self.class scriptURLWithName:name];
NSString *script = [self.class loadScriptWithURL:url];
[self evaluateScript:script fromURL:url];
}
- (void)evaluateScript:(NSString *)script fromURL:(NSURL *)url {
JSValue *exception;
[self.class evaluateScript:script fromURL:url inContext:self.context exception:&exception];
if (exception) {
JSValue *message = [exception hasProperty:@"message"] ? exception[@"message"] : exception;
NSString *source = [exception hasProperty:@"sourceURL"] ? [exception[@"sourceURL"] toString] : nil;
NSUInteger line = [exception hasProperty:@"line"] ? [exception[@"line"] toUInt32] : 0;
NSURL *sourceURL = source ? [NSURL URLWithString:source.lastPathComponent relativeToURL:[NSURL URLWithString:@(__FILE__)]] : nil;
const char *sourcePath = sourceURL.absoluteString.UTF8String;
_XCTFailureHandler(self, YES, sourcePath ?: __FILE__, sourcePath ? line : __LINE__, @"JS", @"%@", message);
}
}
+ (JSValue *)evaluateScript:(NSString *)script fromURL:(NSURL *)url inContext:(JSContext *)context exception:(JSValue **)exception {
JSStringRef jsScript = JSStringCreateWithUTF8CString(script.UTF8String);
JSStringRef jsURL = url ? JSStringCreateWithUTF8CString(url.absoluteString.UTF8String) : NULL;
JSValueRef jsException = NULL;
JSValueRef jsResult = JSEvaluateScript(context.JSGlobalContextRef, jsScript, NULL, jsURL, 1, &jsException);
JSStringRelease(jsScript);
if (jsURL) {
JSStringRelease(jsURL);
}
if (jsException) {
*exception = [JSValue valueWithJSValueRef:jsException inContext:context];
return NULL;
}
return [JSValue valueWithJSValueRef:jsResult inContext:context];
}
+ (NSURL *)scriptURLWithName:(NSString *)name {
NSURL *url = [[NSBundle bundleForClass:self] URLForResource:name withExtension:@"js"];
if (!url) {
NSLog(@"JS file does not exist: %@", url);
exit(1);
}
return url;
}
+ (NSString *)loadScriptWithURL:(NSURL *)url {
NSError *error;
NSString *script = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
if (!script) {
NSLog(@"Error reading JS file (%@): %@", url, error);
exit(1);
}
return script;
}
+ (NSString *)jsSuiteName {
return nil;
}
+ (NSString *)jsSuiteScript {
NSString *name = [self jsSuiteName];
return name ? [self loadScriptWithURL:[self scriptURLWithName:name]] : nil;
}
+ (XCTestSuite *)defaultTestSuite {
XCTestSuite *suite = [super defaultTestSuite];
NSString *suiteName = [self jsSuiteName];
NSURL *scriptURL = suiteName ? [self scriptURLWithName:suiteName] : nil;
NSString *script = scriptURL ? [self loadScriptWithURL:scriptURL] : nil;
if (!script) {
return suite;
}
JSContext *context = [[JSContext alloc] init];
JSValue *exception;
RJSModuleLoader *moduleLoader = [[RJSModuleLoader alloc] initWithContext:context];
NSURL *scriptURL = [[NSBundle bundleForClass:self] URLForResource:@"index" withExtension:@"js"];
[self evaluateScript:@"var exports = {};" fromURL:nil inContext:context exception:&exception];
[self evaluateScript:script fromURL:scriptURL inContext:context exception:&exception];
if (exception) {
NSLog(@"%@.js - %@", suiteName, exception);
[RealmJS initializeContext:context.JSGlobalContextRef];
NSError *error;
JSValue *testObjects = [moduleLoader loadModuleFromURL:scriptURL error:&error];
if (!testObjects) {
NSLog(@"index.js - %@", error);
exit(1);
}
JSValue *suiteObject = [self evaluateScript:suiteName fromURL:nil inContext:context exception:&exception];
if (exception) {
NSLog(@"%@.js - %@", suiteName, exception);
exit(1);
}
for (NSString *testName in [testObjects toDictionary]) {
JSValue *testObject = testObjects[testName];
XCTestSuite *testSuite = [[XCTestSuite alloc] initWithName:testName];
Class testClass = objc_allocateClassPair(self, testName.UTF8String, 0);
if (![suiteObject isObject]) {
NSLog(@"%@.js - JS test suite is not an object: %@", suiteName, suiteObject);
exit(1);
}
for (NSString *methodName in [testObject toDictionary]) {
XCTestCase *testCase = [[testClass alloc] initWithJSTestObject:testObject methodName:methodName];
[testSuite addTest:testCase];
}
for (NSString *testName in [suiteObject toDictionary]) {
[suite addTest:[self testCaseWithSelector:NSSelectorFromString(testName)]];
[suite addTest:testSuite];
}
return suite;
@ -211,48 +137,28 @@ static JSClassRef s_globalClass;
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
NSMethodSignature *sig = [super methodSignatureForSelector:aSelector];
if (sig) {
return sig;
}
return [NSMethodSignature signatureWithObjCTypes:"v@:"];
return sig ?: [NSMethodSignature signatureWithObjCTypes:"v@:"];
}
- (void)forwardInvocation:(NSInvocation *)anInvocation {
NSString *script = [NSString stringWithFormat:@"%@.%@();", [self.class jsSuiteName], NSStringFromSelector(anInvocation.selector)];
[self evaluateScript:script fromURL:nil];
JSValue *testObject = self.testObject;
JSContext *context = testObject.context;
[testObject invokeMethod:NSStringFromSelector(anInvocation.selector) withArguments:nil];
JSValue *exception = context.exception;
if (exception) {
JSValue *message = [exception hasProperty:@"message"] ? exception[@"message"] : exception;
NSString *source = [exception hasProperty:@"sourceURL"] ? [exception[@"sourceURL"] toString] : nil;
NSUInteger line = [exception hasProperty:@"line"] ? [exception[@"line"] toUInt32] - 1 : 0;
NSURL *sourceURL = source ? [NSURL URLWithString:source.lastPathComponent relativeToURL:[NSURL URLWithString:@(__FILE__)]] : nil;
[self recordFailureWithDescription:message.description
inFile:sourceURL ? sourceURL.absoluteString : @(__FILE__)
atLine:sourceURL ? line : __LINE__
expected:YES];
}
}
@end
@interface RJSResultsTests : RealmJSTests
@end
@implementation RJSResultsTests
+ (NSString *)jsSuiteName {
return @"ResultsTests";
}
@end
@interface RJSObjectTests : RealmJSTests
@end
@implementation RJSObjectTests
+ (NSString *)jsSuiteName {
return @"ObjectTests";
}
@end
@interface RJSArrayTests : RealmJSTests
@end
@implementation RJSArrayTests
+ (NSString *)jsSuiteName {
return @"ArrayTests";
}
@end
@interface RJSRealmTests : RealmJSTests
@end
@implementation RJSRealmTests
+ (NSString *)jsSuiteName {
return @"RealmTests";
}
@end

View File

@ -18,10 +18,14 @@
'use strict';
var RealmTests = {
var TestCase = require('./asserts');
var schemas = require('./schemas');
var util = require('./util');
module.exports = {
testRealmConstructorPath: function() {
TestCase.assertThrows(function() { new Realm('/invalidpath'); });
TestCase.assertThrows(function() { new Realm(TestUtil.realmPathForFile('test1.realm'), 'invalidArgument'); });
TestCase.assertThrows(function() { new Realm(util.realmPathForFile('test1.realm'), 'invalidArgument'); });
var defaultRealm = new Realm({schema: []});
TestCase.assertEqual(defaultRealm.path, Realm.defaultPath);
@ -29,12 +33,12 @@ var RealmTests = {
var defaultRealm2 = new Realm();
TestCase.assertEqual(defaultRealm2.path, Realm.defaultPath);
var testPath = TestUtil.realmPathForFile('test1.realm');
var testPath = util.realmPathForFile('test1.realm');
var realm = new Realm({schema: [], path: testPath});
//TestCase.assertTrue(realm instanceof Realm);
TestCase.assertEqual(realm.path, testPath);
var testPath2 = TestUtil.realmPathForFile('test2.realm');
var testPath2 = util.realmPathForFile('test2.realm');
var realm2 = new Realm({schema: [], path: testPath2});
//TestCase.assertTrue(realm2 instanceof Realm);
TestCase.assertEqual(realm2.path, testPath2);
@ -51,7 +55,7 @@ var RealmTests = {
TestCase.assertEqual(new Realm().schemaVersion, 0);
TestCase.assertEqual(new Realm({schemaVersion: 0}).schemaVersion, 0);
var testPath = TestUtil.realmPathForFile('test1.realm');
var testPath = util.realmPathForFile('test1.realm');
var realm = new Realm({path: testPath, schema: [], schemaVersion: 1});
TestCase.assertEqual(realm.schemaVersion, 1);
@ -63,7 +67,7 @@ var RealmTests = {
var defaultRealm = new Realm({schema: []});
TestCase.assertEqual(defaultRealm.path, Realm.defaultPath);
var newPath = TestUtil.realmPathForFile('default2.realm');
var newPath = util.realmPathForFile('default2.realm');
Realm.defaultPath = newPath;
defaultRealm = new Realm({schema: []});
TestCase.assertEqual(defaultRealm.path, newPath);
@ -72,7 +76,7 @@ var RealmTests = {
},
testRealmCreate: function() {
var realm = new Realm({schema: [IntPrimaryObjectSchema, AllTypesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.IntPrimary, schemas.AllTypes, schemas.TestObject]});
realm.write(function() {
realm.create('TestObject', [1]);
realm.create('TestObject', {'doubleCol': 2});
@ -143,25 +147,25 @@ var RealmTests = {
},
testRealmCreateWithDefaults: function() {
var realm = new Realm({schema: [DefaultValuesObjectSchema, TestObjectSchema]});
var realm = new Realm({schema: [schemas.DefaultValues, schemas.TestObject]});
realm.write(function() {
var obj = realm.create('DefaultValuesObject', {});
TestCase.assertEqual(obj.boolCol, DefaultValuesObjectSchema.properties[0].default);
TestCase.assertEqual(obj.intCol, DefaultValuesObjectSchema.properties[1].default);
TestCase.assertEqualWithTolerance(obj.floatCol, DefaultValuesObjectSchema.properties[2].default, 0.000001);
TestCase.assertEqual(obj.doubleCol, DefaultValuesObjectSchema.properties[3].default);
TestCase.assertEqual(obj.stringCol, DefaultValuesObjectSchema.properties[4].default);
TestCase.assertEqual(obj.dateCol.getTime(), DefaultValuesObjectSchema.properties[5].default.getTime());
TestCase.assertEqual(obj.dataCol, DefaultValuesObjectSchema.properties[6].default);
TestCase.assertEqual(obj.objectCol.doubleCol, DefaultValuesObjectSchema.properties[7].default[0]);
TestCase.assertEqual(obj.boolCol, schemas.DefaultValues.properties[0].default);
TestCase.assertEqual(obj.intCol, schemas.DefaultValues.properties[1].default);
TestCase.assertEqualWithTolerance(obj.floatCol, schemas.DefaultValues.properties[2].default, 0.000001);
TestCase.assertEqual(obj.doubleCol, schemas.DefaultValues.properties[3].default);
TestCase.assertEqual(obj.stringCol, schemas.DefaultValues.properties[4].default);
TestCase.assertEqual(obj.dateCol.getTime(), schemas.DefaultValues.properties[5].default.getTime());
TestCase.assertEqual(obj.dataCol, schemas.DefaultValues.properties[6].default);
TestCase.assertEqual(obj.objectCol.doubleCol, schemas.DefaultValues.properties[7].default[0]);
TestCase.assertEqual(obj.nullObjectCol, null);
TestCase.assertEqual(obj.arrayCol.length, DefaultValuesObjectSchema.properties[9].default.length);
TestCase.assertEqual(obj.arrayCol[0].doubleCol, DefaultValuesObjectSchema.properties[9].default[0][0]);
TestCase.assertEqual(obj.arrayCol.length, schemas.DefaultValues.properties[9].default.length);
TestCase.assertEqual(obj.arrayCol[0].doubleCol, schemas.DefaultValues.properties[9].default[0][0]);
});
},
testRealmDelete: function() {
var realm = new Realm({schema: [TestObjectSchema]});
var realm = new Realm({schema: [schemas.TestObject]});
realm.write(function() {
for (var i = 0; i < 10; i++) {
realm.create('TestObject', [i]);
@ -197,7 +201,7 @@ var RealmTests = {
},
testDeleteAll: function() {
var realm = new Realm({schema: [TestObjectSchema, IntPrimaryObjectSchema]});
var realm = new Realm({schema: [schemas.TestObject, schemas.IntPrimary]});
realm.write(function() {
realm.create('TestObject', [1]);
realm.create('TestObject', [2]);
@ -219,7 +223,7 @@ var RealmTests = {
},
testRealmObjects: function() {
var realm = new Realm({schema: [PersonObject]});
var realm = new Realm({schema: [schemas.PersonObject]});
realm.write(function() {
realm.create('PersonObject', ['Ari', 10]);
realm.create('PersonObject', ['Tim', 11]);
@ -266,5 +270,3 @@ var RealmTests = {
TestCase.assertEqual(notificationCount, 1);
},
};
module.exports = RealmTests;

View File

@ -18,9 +18,12 @@
'use strict';
var ResultsTests = {
var TestCase = require('./asserts');
var schemas = require('./schemas');
module.exports = {
testResultsLength: function() {
var realm = new Realm({schema: [TestObjectSchema]});
var realm = new Realm({schema: [schemas.TestObject]});
var objects = realm.objects('TestObject');
TestCase.assertEqual(objects.length, 0);
@ -31,7 +34,7 @@ var ResultsTests = {
TestCase.assertEqual(objects.length, 1);
},
testResultsSubscript: function() {
var realm = new Realm({schema: [PersonObject]});
var realm = new Realm({schema: [schemas.PersonObject]});
realm.write(function() {
realm.create('PersonObject', ['name1', 1]);
realm.create('PersonObject', ['name2', 2]);
@ -42,21 +45,21 @@ var ResultsTests = {
TestCase.assertEqual(people[1].age, 2);
TestCase.assertThrows(function() { people[2]; }, 'Invalid index');
TestCase.assertThrows(function() { people[-1]; }, 'Invalid index');
TestCase.assertTrue(Object.getPrototypeOf(people[0]) === PersonObject.prototype);
TestCase.assertTrue(Object.getPrototypeOf(people[0]) === schemas.PersonObject.prototype);
},
testResultsInvalidProperty: function() {
var realm = new Realm({schema: [TestObjectSchema]});
var realm = new Realm({schema: [schemas.TestObject]});
var objects = realm.objects('TestObject');
TestCase.assertEqual(undefined, objects.ablasdf);
},
testResultsInvalidObjectType: function() {
var realm = new Realm({schema: [TestObjectSchema]});
var realm = new Realm({schema: [schemas.TestObject]});
TestCase.assertThrows(function() {
var objects = realm.objects('NotTestObject');
});
},
testResultsEnumerate: function() {
var realm = new Realm({schema: [TestObjectSchema]});
var realm = new Realm({schema: [schemas.TestObject]});
var objects = realm.objects('TestObject');
for (var object in objects) {
TestCase.assertTrue(false, "No objects should have been enumerated");
@ -75,7 +78,7 @@ var ResultsTests = {
TestCase.assertEqual(1, count);
},
testSort: function() {
var realm = new Realm({schema: [TestObjectSchema]});
var realm = new Realm({schema: [schemas.TestObject]});
var objects = realm.objects('TestObject');
realm.write(function() {
realm.create('TestObject', [2]);
@ -99,5 +102,4 @@ var ResultsTests = {
TestCase.assertEqual(objects[3].doubleCol, 1);
TestCase.assertEqual(objects[4].doubleCol, 0);
},
}
module.exports = ResultsTests;
};

View File

@ -18,15 +18,7 @@
'use strict';
var TestUtil = {
realmPathForFile: function(str) {
var path = Realm.defaultPath;
return path.substring(0, path.lastIndexOf("/") + 1) + str;
},
};
exports.TestUtil = TestUtil;
var TestCase = {
module.exports = {
assertEqual: function(val1, val2, errorMessage) {
if (val1 !== val2) {
var message = "'" + val1 + "' does not equal expected value '" + val2 + "'";
@ -76,8 +68,7 @@ var TestCase = {
throw new TestFailureError(errorMessage || 'Condition expected to be true');
};
},
}
exports.TestCase = TestCase;
};
function TestFailureError(message) {
var error;
@ -103,5 +94,3 @@ function TestFailureError(message) {
this.__proto__ = error;
}
exports.TestFailureError = TestFailureError;

View File

@ -1,22 +1,24 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
'use strict';
var TestCase = require('./TestCase');
var {
LinkTypesObjectSchema,
TestObjectSchema,
IntPrimaryObjectSchema,
AllTypesObjectSchema,
DefaultValuesObjectSchema,
PersonObject,
} = require('./TestObjects');
var RealmTestSuite = {
tests: [
require('./ArrayTests.js'),
require('./ObjectTests.js'),
require('./RealmTests.js'),
require('./ResultsTests.js'),
],
testObjects: require('./TestObjects'),
}
module.exports = RealmTestSuite; // eslint-disable-line no-undef
exports.ArrayTests = require('./ArrayTests');
exports.ObjectTests = require('./ObjectTests');
exports.RealmTests = require('./RealmTests');
exports.ResultsTests = require('./ResultsTests');

View File

@ -1,5 +1,5 @@
{
"name": "RealmTestSuite",
"name": "realm-tests",
"version": "0.0.1",
"private": true
}

View File

@ -24,7 +24,7 @@ var TestObjectSchema = {
{name: 'doubleCol', type: Realm.Types.DOUBLE},
]
};
exports.TestObjectSchema = TestObjectSchema;
exports.TestObject = TestObjectSchema;
function PersonObject() {}
PersonObject.prototype.schema = {
@ -51,7 +51,7 @@ var BasicTypesObjectSchema = {
{name: 'dataCol', type: Realm.Types.DATA},
]
};
exports.BasicTypesObjectSchema = BasicTypesObjectSchema;
exports.BasicTypes = BasicTypesObjectSchema;
var LinkTypesObjectSchema = {
name: 'LinkTypesObject',
@ -61,7 +61,7 @@ var LinkTypesObjectSchema = {
{name: 'arrayCol', type: Realm.Types.LIST, objectType: 'TestObject'},
]
};
exports.LinkTypesObjectSchema = LinkTypesObjectSchema;
exports.LinkTypes = LinkTypesObjectSchema;
var IntPrimaryObjectSchema = {
name: 'IntPrimaryObject',
@ -71,7 +71,7 @@ var IntPrimaryObjectSchema = {
{name: 'valueCol', type: Realm.Types.STRING},
]
};
exports.IntPrimaryObjectSchema = IntPrimaryObjectSchema;
exports.IntPrimary = IntPrimaryObjectSchema;
var AllTypesObjectSchema = {
name: 'AllTypesObject',
@ -89,7 +89,7 @@ var AllTypesObjectSchema = {
{name: 'arrayCol', type: Realm.Types.LIST, objectType: 'TestObject'},
]
};
exports.AllTypesObjectSchema = AllTypesObjectSchema;
exports.AllTypes = AllTypesObjectSchema;
var DefaultValuesObjectSchema = {
name: 'DefaultValuesObject',
@ -106,5 +106,5 @@ var DefaultValuesObjectSchema = {
{name: 'arrayCol', type: Realm.Types.LIST, objectType: 'TestObject', default: [[2]]},
]
};
exports.DefaultValuesObjectSchema = DefaultValuesObjectSchema;
exports.DefaultValues = DefaultValuesObjectSchema;

24
tests/util.js Normal file
View File

@ -0,0 +1,24 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
'use strict';
exports.realmPathForFile = function(str) {
var path = Realm.defaultPath;
return path.substring(0, path.lastIndexOf("/") + 1) + str;
};