diff --git a/Sources/MODCursor.m b/Sources/MODCursor.m index a5f6bc45..f9d056cd 100644 --- a/Sources/MODCursor.m +++ b/Sources/MODCursor.m @@ -113,7 +113,7 @@ - (MODSortedMutableDictionary *)nextDocumentWithBsonData:(NSData **)bsonData err result = [[_mongoCollection.mongoServer class] objectFromBson:&(mongoCursor->current)]; if (bsonData) { - *bsonData = [[[NSData alloc] initWithBytes:mongoCursor->current.data length:mongoCursor->current.dataSize] autorelease]; + *bsonData = [[[NSData alloc] initWithBytes:mongoCursor->current.data length:bson_size(&mongoCursor->current)] autorelease]; } } else if (((mongo_cursor *)_cursor)->err != MONGO_CURSOR_EXHAUSTED) { NSString *details = nil; diff --git a/Sources/MODServer.h b/Sources/MODServer.h index e468612c..f325c1c4 100644 --- a/Sources/MODServer.h +++ b/Sources/MODServer.h @@ -55,6 +55,7 @@ typedef struct mongo *mongo_ptr; + (NSString *)escapeQuotesForString:(NSString *)string; + (NSString *)escapeSlashesForString:(NSString *)string; + (NSString *)convertObjectToJson:(MODSortedMutableDictionary *)object pretty:(BOOL)pretty strictJson:(BOOL)strictJson; ++ (void)compareJson:(NSString *)json bsonData:(NSData *)document; + (void)compareJson:(NSString *)json document:(id)document; + (NSArray *)findAllDifferencesInObject1:(id)object1 object2:(id)object2; @end \ No newline at end of file diff --git a/Sources/MODServer_utils.m b/Sources/MODServer_utils.m index 38579e8b..930cddf3 100644 --- a/Sources/MODServer_utils.m +++ b/Sources/MODServer_utils.m @@ -618,6 +618,26 @@ + (NSString *)escapeSlashesForString:(NSString *)string return [result autorelease]; } ++ (void)compareJson:(NSString *)json bsonData:(NSData *)document +{ + bson bsonDocumentFromJson; + NSError *error; + + bson_init(&bsonDocumentFromJson); + [MODJsonToBsonParser bsonFromJson:&bsonDocumentFromJson json:json error:&error]; + bson_finish(&bsonDocumentFromJson); + NSAssert(error == nil, @"error with document %@", document); + if ([document length] != bson_size(&bsonDocumentFromJson) || memcmp([document bytes], bsonDocumentFromJson.data, [document length]) != 0) { + NSLog(@"%@", [NSData dataWithBytes:bsonDocumentFromJson.data length:bson_size(&bsonDocumentFromJson)]); + NSLog(@"error with this document %@", document); + NSLog(@"json %@", [MODServer convertObjectToJson:[MODServer objectFromBson:&bsonDocumentFromJson] pretty:YES strictJson:NO]); + NSAssert([document length] == bson_size(&bsonDocumentFromJson), @"not the same size with %@", document); + NSAssert(memcmp([document bytes], bsonDocumentFromJson.data, [document length]) == 0, @"not the same content %@", document); + } + + bson_destroy(&bsonDocumentFromJson); +} + + (void)compareJson:(NSString *)json document:(id)document { bson bsonDocument;