mirror of
https://github.com/sstent/node.git
synced 2026-01-27 15:41:43 +00:00
added todo and studff to test in app for tempdir detection
This commit is contained in:
45
app/node_modules/mongodb/external-libs/bson/Makefile
generated
vendored
Normal file
45
app/node_modules/mongodb/external-libs/bson/Makefile
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
NODE = node
|
||||
name = all
|
||||
JOBS = 1
|
||||
|
||||
all:
|
||||
rm -rf build .lock-wscript bson.node
|
||||
node-waf configure build
|
||||
cp -R ./build/Release/bson.node . || true
|
||||
@$(NODE) --expose-gc test/test_bson.js
|
||||
@$(NODE) --expose-gc test/test_full_bson.js
|
||||
# @$(NODE) --expose-gc test/test_stackless_bson.js
|
||||
|
||||
all_debug:
|
||||
rm -rf build .lock-wscript bson.node
|
||||
node-waf --debug configure build
|
||||
cp -R ./build/Release/bson.node . || true
|
||||
@$(NODE) --expose-gc test/test_bson.js
|
||||
@$(NODE) --expose-gc test/test_full_bson.js
|
||||
# @$(NODE) --expose-gc test/test_stackless_bson.js
|
||||
|
||||
test:
|
||||
@$(NODE) --expose-gc test/test_bson.js
|
||||
@$(NODE) --expose-gc test/test_full_bson.js
|
||||
# @$(NODE) --expose-gc test/test_stackless_bson.js
|
||||
|
||||
clang:
|
||||
rm -rf build .lock-wscript bson.node
|
||||
CXX=clang node-waf configure build
|
||||
cp -R ./build/Release/bson.node . || true
|
||||
@$(NODE) --expose-gc test/test_bson.js
|
||||
@$(NODE) --expose-gc test/test_full_bson.js
|
||||
# @$(NODE) --expose-gc test/test_stackless_bson.js
|
||||
|
||||
clang_debug:
|
||||
rm -rf build .lock-wscript bson.node
|
||||
CXX=clang node-waf --debug configure build
|
||||
cp -R ./build/Release/bson.node . || true
|
||||
@$(NODE) --expose-gc test/test_bson.js
|
||||
@$(NODE) --expose-gc test/test_full_bson.js
|
||||
# @$(NODE) --expose-gc test/test_stackless_bson.js
|
||||
|
||||
clean:
|
||||
rm -rf build .lock-wscript bson.node
|
||||
|
||||
.PHONY: all
|
||||
2165
app/node_modules/mongodb/external-libs/bson/bson.cc
generated
vendored
Normal file
2165
app/node_modules/mongodb/external-libs/bson/bson.cc
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
105
app/node_modules/mongodb/external-libs/bson/bson.h
generated
vendored
Normal file
105
app/node_modules/mongodb/external-libs/bson/bson.h
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
#ifndef BSON_H_
|
||||
#define BSON_H_
|
||||
|
||||
#include <node.h>
|
||||
#include <node_object_wrap.h>
|
||||
#include <v8.h>
|
||||
|
||||
using namespace v8;
|
||||
using namespace node;
|
||||
|
||||
class BSON : public ObjectWrap {
|
||||
public:
|
||||
BSON() : ObjectWrap() {}
|
||||
~BSON() {}
|
||||
|
||||
static void Initialize(Handle<Object> target);
|
||||
static Handle<Value> BSONDeserializeStream(const Arguments &args);
|
||||
|
||||
// JS based objects
|
||||
static Handle<Value> BSONSerialize(const Arguments &args);
|
||||
static Handle<Value> BSONDeserialize(const Arguments &args);
|
||||
|
||||
// Calculate size of function
|
||||
static Handle<Value> CalculateObjectSize(const Arguments &args);
|
||||
static Handle<Value> SerializeWithBufferAndIndex(const Arguments &args);
|
||||
|
||||
// Experimental
|
||||
static Handle<Value> CalculateObjectSize2(const Arguments &args);
|
||||
static Handle<Value> BSONSerialize2(const Arguments &args);
|
||||
|
||||
// Constructor used for creating new BSON objects from C++
|
||||
static Persistent<FunctionTemplate> constructor_template;
|
||||
|
||||
private:
|
||||
static Handle<Value> New(const Arguments &args);
|
||||
static Handle<Value> deserialize(BSON *bson, char *data, uint32_t dataLength, uint32_t startIndex, bool is_array_item);
|
||||
static uint32_t serialize(BSON *bson, char *serialized_object, uint32_t index, Handle<Value> name, Handle<Value> value, bool check_key, bool serializeFunctions);
|
||||
|
||||
static char* extract_string(char *data, uint32_t offset);
|
||||
static const char* ToCString(const v8::String::Utf8Value& value);
|
||||
static uint32_t calculate_object_size(BSON *bson, Handle<Value> object, bool serializeFunctions);
|
||||
|
||||
static void write_int32(char *data, uint32_t value);
|
||||
static void write_int64(char *data, int64_t value);
|
||||
static void write_double(char *data, double value);
|
||||
static uint16_t deserialize_int8(char *data, uint32_t offset);
|
||||
static uint32_t deserialize_int32(char* data, uint32_t offset);
|
||||
static char *check_key(Local<String> key);
|
||||
|
||||
// BSON type instantiate functions
|
||||
Persistent<Function> longConstructor;
|
||||
Persistent<Function> objectIDConstructor;
|
||||
Persistent<Function> binaryConstructor;
|
||||
Persistent<Function> codeConstructor;
|
||||
Persistent<Function> dbrefConstructor;
|
||||
Persistent<Function> symbolConstructor;
|
||||
Persistent<Function> doubleConstructor;
|
||||
Persistent<Function> timestampConstructor;
|
||||
Persistent<Function> minKeyConstructor;
|
||||
Persistent<Function> maxKeyConstructor;
|
||||
|
||||
// Equality Objects
|
||||
Persistent<String> longString;
|
||||
Persistent<String> objectIDString;
|
||||
Persistent<String> binaryString;
|
||||
Persistent<String> codeString;
|
||||
Persistent<String> dbrefString;
|
||||
Persistent<String> symbolString;
|
||||
Persistent<String> doubleString;
|
||||
Persistent<String> timestampString;
|
||||
Persistent<String> minKeyString;
|
||||
Persistent<String> maxKeyString;
|
||||
|
||||
// Equality speed up comparision objects
|
||||
Persistent<String> _bsontypeString;
|
||||
Persistent<String> _longLowString;
|
||||
Persistent<String> _longHighString;
|
||||
Persistent<String> _objectIDidString;
|
||||
Persistent<String> _binaryPositionString;
|
||||
Persistent<String> _binarySubTypeString;
|
||||
Persistent<String> _binaryBufferString;
|
||||
Persistent<String> _doubleValueString;
|
||||
Persistent<String> _symbolValueString;
|
||||
|
||||
Persistent<String> _dbRefRefString;
|
||||
Persistent<String> _dbRefIdRefString;
|
||||
Persistent<String> _dbRefDbRefString;
|
||||
Persistent<String> _dbRefNamespaceString;
|
||||
Persistent<String> _dbRefDbString;
|
||||
Persistent<String> _dbRefOidString;
|
||||
|
||||
// Decode JS function
|
||||
static Handle<Value> decodeLong(BSON *bson, char *data, uint32_t index);
|
||||
static Handle<Value> decodeTimestamp(BSON *bson, char *data, uint32_t index);
|
||||
static Handle<Value> decodeOid(BSON *bson, char *oid);
|
||||
static Handle<Value> decodeBinary(BSON *bson, uint32_t sub_type, uint32_t number_of_bytes, char *data);
|
||||
static Handle<Value> decodeCode(BSON *bson, char *code, Handle<Value> scope);
|
||||
static Handle<Value> decodeDBref(BSON *bson, Local<Value> ref, Local<Value> oid, Local<Value> db);
|
||||
|
||||
// Experimental
|
||||
static uint32_t calculate_object_size2(Handle<Value> object);
|
||||
static uint32_t serialize2(char *serialized_object, uint32_t index, Handle<Value> name, Handle<Value> value, uint32_t object_size, bool check_key);
|
||||
};
|
||||
|
||||
#endif // BSON_H_
|
||||
20
app/node_modules/mongodb/external-libs/bson/index.js
generated
vendored
Normal file
20
app/node_modules/mongodb/external-libs/bson/index.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var bson = require('./bson');
|
||||
exports.BSON = bson.BSON;
|
||||
exports.Long = require('../../lib/mongodb/bson/long').Long;
|
||||
exports.ObjectID = require('../../lib/mongodb/bson/objectid').ObjectID;
|
||||
exports.DBRef = require('../../lib/mongodb/bson/db_ref').DBRef;
|
||||
exports.Code = require('../../lib/mongodb/bson/code').Code;
|
||||
exports.Timestamp = require('../../lib/mongodb/bson/timestamp').Timestamp;
|
||||
exports.Binary = require('../../lib/mongodb/bson/binary').Binary;
|
||||
exports.Double = require('../../lib/mongodb/bson/double').Double;
|
||||
exports.MaxKey = require('../../lib/mongodb/bson/max_key').MaxKey;
|
||||
exports.MinKey = require('../../lib/mongodb/bson/min_key').MinKey;
|
||||
exports.Symbol = require('../../lib/mongodb/bson/symbol').Symbol;
|
||||
|
||||
// Just add constants tot he Native BSON parser
|
||||
exports.BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
||||
exports.BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1;
|
||||
exports.BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
|
||||
exports.BSON.BSON_BINARY_SUBTYPE_UUID = 3;
|
||||
exports.BSON.BSON_BINARY_SUBTYPE_MD5 = 4;
|
||||
exports.BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
|
||||
349
app/node_modules/mongodb/external-libs/bson/test/test_bson.js
generated
vendored
Normal file
349
app/node_modules/mongodb/external-libs/bson/test/test_bson.js
generated
vendored
Normal file
@@ -0,0 +1,349 @@
|
||||
var sys = require('util'),
|
||||
debug = require('util').debug,
|
||||
inspect = require('util').inspect,
|
||||
Buffer = require('buffer').Buffer,
|
||||
BSON = require('../bson').BSON,
|
||||
Buffer = require('buffer').Buffer,
|
||||
BSONJS = require('../../../lib/mongodb/bson/bson').BSON,
|
||||
BinaryParser = require('../../../lib/mongodb/bson/binary_parser').BinaryParser,
|
||||
Long = require('../../../lib/mongodb/bson/long').Long,
|
||||
ObjectID = require('../../../lib/mongodb/bson/bson').ObjectID,
|
||||
Binary = require('../../../lib/mongodb/bson/bson').Binary,
|
||||
Code = require('../../../lib/mongodb/bson/bson').Code,
|
||||
DBRef = require('../../../lib/mongodb/bson/bson').DBRef,
|
||||
Symbol = require('../../../lib/mongodb/bson/bson').Symbol,
|
||||
Double = require('../../../lib/mongodb/bson/bson').Double,
|
||||
MaxKey = require('../../../lib/mongodb/bson/bson').MaxKey,
|
||||
MinKey = require('../../../lib/mongodb/bson/bson').MinKey,
|
||||
Timestamp = require('../../../lib/mongodb/bson/bson').Timestamp,
|
||||
assert = require('assert');
|
||||
|
||||
if(process.env['npm_package_config_native'] != null) return;
|
||||
|
||||
sys.puts("=== EXECUTING TEST_BSON ===");
|
||||
|
||||
// Should fail due to illegal key
|
||||
assert.throws(function() { new ObjectID('foo'); })
|
||||
assert.throws(function() { new ObjectID('foo'); })
|
||||
|
||||
// Parsers
|
||||
var bsonC = new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
|
||||
var bsonJS = new BSONJS([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
|
||||
|
||||
// Simple serialization and deserialization of edge value
|
||||
var doc = {doc:0x1ffffffffffffe};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
var doc = {doc:-0x1ffffffffffffe};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
//
|
||||
// Assert correct toJSON
|
||||
//
|
||||
var a = Long.fromNumber(10);
|
||||
assert.equal(10, a);
|
||||
|
||||
var a = Long.fromNumber(9223372036854775807);
|
||||
assert.equal(9223372036854775807, a);
|
||||
|
||||
// Simple serialization and deserialization test for a Single String value
|
||||
var doc = {doc:'Serialize'};
|
||||
var simple_string_serialized = bsonC.serialize(doc, true, false);
|
||||
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
// Nested doc
|
||||
var doc = {a:{b:{c:1}}};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
// Simple integer serialization/deserialization test, including testing boundary conditions
|
||||
var doc = {doc:-1};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
var doc = {doc:2147483648};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
var doc = {doc:-2147483648};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
// Simple serialization and deserialization test for a Long value
|
||||
var doc = {doc:Long.fromNumber(9223372036854775807)};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize({doc:Long.fromNumber(9223372036854775807)}, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
var doc = {doc:Long.fromNumber(-9223372036854775807)};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize({doc:Long.fromNumber(-9223372036854775807)}, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
// Simple serialization and deserialization for a Float value
|
||||
var doc = {doc:2222.3333};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
var doc = {doc:-2222.3333};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
// Simple serialization and deserialization for a null value
|
||||
var doc = {doc:null};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
// Simple serialization and deserialization for a boolean value
|
||||
var doc = {doc:true};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
// Simple serialization and deserialization for a date value
|
||||
var date = new Date();
|
||||
var doc = {doc:date};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
||||
|
||||
// Simple serialization and deserialization for a boolean value
|
||||
var doc = {doc:/abcd/mi};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.equal(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.toString(), bsonC.deserialize(simple_string_serialized).doc.toString());
|
||||
|
||||
var doc = {doc:/abcd/};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
||||
assert.equal(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.toString(), bsonC.deserialize(simple_string_serialized).doc.toString());
|
||||
|
||||
// Simple serialization and deserialization for a objectId value
|
||||
var doc = {doc:new ObjectID()};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
var doc2 = {doc:ObjectID.createFromHexString(doc.doc.toHexString())};
|
||||
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc2, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.toString(), bsonC.deserialize(simple_string_serialized).doc.toString());
|
||||
|
||||
// Simple serialization and deserialization for a Binary value
|
||||
var binary = new Binary();
|
||||
var string = 'binstring'
|
||||
for(var index = 0; index < string.length; index++) { binary.put(string.charAt(index)); }
|
||||
|
||||
var Binary = new Binary();
|
||||
var string = 'binstring'
|
||||
for(var index = 0; index < string.length; index++) { Binary.put(string.charAt(index)); }
|
||||
|
||||
var simple_string_serialized = bsonC.serialize({doc:binary}, false, true);
|
||||
assert.deepEqual(simple_string_serialized, bsonJS.serialize({doc:Binary}, false, true));
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.value(), bsonC.deserialize(simple_string_serialized).doc.value());
|
||||
|
||||
// Simple serialization and deserialization for a Code value
|
||||
var code = new Code('this.a > i', {'i': 1});
|
||||
var Code = new Code('this.a > i', {'i': 1});
|
||||
var simple_string_serialized_2 = bsonJS.serialize({doc:Code}, false, true);
|
||||
var simple_string_serialized = bsonC.serialize({doc:code}, false, true);
|
||||
|
||||
assert.deepEqual(simple_string_serialized, simple_string_serialized_2);
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary')).doc.scope, bsonC.deserialize(simple_string_serialized).doc.scope);
|
||||
|
||||
// Simple serialization and deserialization for an Object
|
||||
var simple_string_serialized = bsonC.serialize({doc:{a:1, b:{c:2}}}, false, true);
|
||||
var simple_string_serialized_2 = bsonJS.serialize({doc:{a:1, b:{c:2}}}, false, true);
|
||||
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary')).doc, bsonC.deserialize(simple_string_serialized).doc);
|
||||
|
||||
// Simple serialization and deserialization for an Array
|
||||
var simple_string_serialized = bsonC.serialize({doc:[9, 9, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1]}, false, true);
|
||||
var simple_string_serialized_2 = bsonJS.serialize({doc:[9, 9, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1]}, false, true);
|
||||
|
||||
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
||||
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary')).doc, bsonC.deserialize(simple_string_serialized).doc);
|
||||
|
||||
// Simple serialization and deserialization for a DBRef
|
||||
var oid = new ObjectID()
|
||||
var oid2 = new ObjectID.createFromHexString(oid.toHexString())
|
||||
var simple_string_serialized = bsonJS.serialize({doc:new DBRef('namespace', oid2, 'integration_tests_')}, false, true);
|
||||
var simple_string_serialized_2 = bsonC.serialize({doc:new DBRef('namespace', oid, 'integration_tests_')}, false, true);
|
||||
|
||||
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
||||
// Ensure we have the same values for the dbref
|
||||
var object_js = bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary'));
|
||||
var object_c = bsonC.deserialize(simple_string_serialized);
|
||||
|
||||
assert.equal(object_js.doc.namespace, object_c.doc.namespace);
|
||||
assert.equal(object_js.doc.oid.toHexString(), object_c.doc.oid.toHexString());
|
||||
assert.equal(object_js.doc.db, object_c.doc.db);
|
||||
|
||||
// Serialized document
|
||||
var bytes = [47,0,0,0,2,110,97,109,101,0,6,0,0,0,80,97,116,116,121,0,16,97,103,101,0,34,0,0,0,7,95,105,100,0,76,100,12,23,11,30,39,8,89,0,0,1,0];
|
||||
var serialized_data = '';
|
||||
// Convert to chars
|
||||
for(var i = 0; i < bytes.length; i++) {
|
||||
serialized_data = serialized_data + BinaryParser.fromByte(bytes[i]);
|
||||
}
|
||||
var object = bsonC.deserialize(new Buffer(serialized_data, 'binary'));
|
||||
assert.equal('Patty', object.name)
|
||||
assert.equal(34, object.age)
|
||||
assert.equal('4c640c170b1e270859000001', object._id.toHexString())
|
||||
|
||||
// Serialize utf8
|
||||
var doc = { "name" : "本荘由利地域に洪水警報", "name1" : "öüóőúéáűíÖÜÓŐÚÉÁŰÍ", "name2" : "abcdedede"};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
var simple_string_serialized2 = bsonJS.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, simple_string_serialized2)
|
||||
|
||||
var object = bsonC.deserialize(simple_string_serialized);
|
||||
assert.equal(doc.name, object.name)
|
||||
assert.equal(doc.name1, object.name1)
|
||||
assert.equal(doc.name2, object.name2)
|
||||
|
||||
// Serialize object with array
|
||||
var doc = {b:[1, 2, 3]};
|
||||
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
||||
var simple_string_serialized_2 = bsonJS.serialize(doc, false, true);
|
||||
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
||||
|
||||
var object = bsonC.deserialize(simple_string_serialized);
|
||||
assert.deepEqual(doc, object)
|
||||
|
||||
// Test equality of an object ID
|
||||
var object_id = new ObjectID();
|
||||
var object_id_2 = new ObjectID();
|
||||
assert.ok(object_id.equals(object_id));
|
||||
assert.ok(!(object_id.equals(object_id_2)))
|
||||
|
||||
// Test same serialization for Object ID
|
||||
var object_id = new ObjectID();
|
||||
var object_id2 = ObjectID.createFromHexString(object_id.toString())
|
||||
var simple_string_serialized = bsonJS.serialize({doc:object_id}, false, true);
|
||||
var simple_string_serialized_2 = bsonC.serialize({doc:object_id2}, false, true);
|
||||
|
||||
assert.equal(simple_string_serialized_2.length, simple_string_serialized.length);
|
||||
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
||||
var object = bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary'));
|
||||
var object2 = bsonC.deserialize(simple_string_serialized);
|
||||
assert.equal(object.doc.id, object2.doc.id)
|
||||
|
||||
// JS Object
|
||||
var c1 = { _id: new ObjectID, comments: [], title: 'number 1' };
|
||||
var c2 = { _id: new ObjectID, comments: [], title: 'number 2' };
|
||||
var doc = {
|
||||
numbers: []
|
||||
, owners: []
|
||||
, comments: [c1, c2]
|
||||
, _id: new ObjectID
|
||||
};
|
||||
|
||||
var simple_string_serialized = bsonJS.serialize(doc, false, true);
|
||||
|
||||
// C++ Object
|
||||
var c1 = { _id: ObjectID.createFromHexString(c1._id.toHexString()), comments: [], title: 'number 1' };
|
||||
var c2 = { _id: ObjectID.createFromHexString(c2._id.toHexString()), comments: [], title: 'number 2' };
|
||||
var doc = {
|
||||
numbers: []
|
||||
, owners: []
|
||||
, comments: [c1, c2]
|
||||
, _id: ObjectID.createFromHexString(doc._id.toHexString())
|
||||
};
|
||||
|
||||
var simple_string_serialized_2 = bsonC.serialize(doc, false, true);
|
||||
|
||||
for(var i = 0; i < simple_string_serialized_2.length; i++) {
|
||||
// debug(i + "[" + simple_string_serialized_2[i] + "] = [" + simple_string_serialized[i] + "]")
|
||||
assert.equal(simple_string_serialized_2[i], simple_string_serialized[i]);
|
||||
}
|
||||
|
||||
// Deserialize the string
|
||||
var doc1 = bsonJS.deserialize(new Buffer(simple_string_serialized_2));
|
||||
var doc2 = bsonC.deserialize(new Buffer(simple_string_serialized_2));
|
||||
assert.equal(doc._id.id, doc1._id.id)
|
||||
assert.equal(doc._id.id, doc2._id.id)
|
||||
assert.equal(doc1._id.id, doc2._id.id)
|
||||
|
||||
var doc = {
|
||||
_id: 'testid',
|
||||
key1: { code: 'test1', time: {start:1309323402727,end:1309323402727}, x:10, y:5 },
|
||||
key2: { code: 'test1', time: {start:1309323402727,end:1309323402727}, x:10, y:5 }
|
||||
};
|
||||
|
||||
var simple_string_serialized = bsonJS.serialize(doc, false, true);
|
||||
var simple_string_serialized_2 = bsonC.serialize(doc, false, true);
|
||||
|
||||
// Deserialize the string
|
||||
var doc1 = bsonJS.deserialize(new Buffer(simple_string_serialized_2));
|
||||
var doc2 = bsonC.deserialize(new Buffer(simple_string_serialized_2));
|
||||
assert.deepEqual(doc2, doc1)
|
||||
assert.deepEqual(doc, doc2)
|
||||
assert.deepEqual(doc, doc1)
|
||||
|
||||
// Serialize function
|
||||
var doc = {
|
||||
_id: 'testid',
|
||||
key1: function() {}
|
||||
}
|
||||
|
||||
var simple_string_serialized = bsonJS.serialize(doc, false, true, true);
|
||||
var simple_string_serialized_2 = bsonC.serialize(doc, false, true, true);
|
||||
|
||||
// Deserialize the string
|
||||
var doc1 = bsonJS.deserialize(new Buffer(simple_string_serialized_2));
|
||||
var doc2 = bsonC.deserialize(new Buffer(simple_string_serialized_2));
|
||||
assert.equal(doc1.key1.code.toString(), doc2.key1.code.toString())
|
||||
|
||||
var doc = {"user_id":"4e9fc8d55883d90100000003","lc_status":{"$ne":"deleted"},"owner_rating":{"$exists":false}};
|
||||
var simple_string_serialized = bsonJS.serialize(doc, false, true, true);
|
||||
var simple_string_serialized_2 = bsonC.serialize(doc, false, true, true);
|
||||
|
||||
// Should serialize to the same value
|
||||
assert.equal(simple_string_serialized_2.toString('base64'), simple_string_serialized.toString('base64'))
|
||||
var doc1 = bsonJS.deserialize(simple_string_serialized_2);
|
||||
var doc2 = bsonC.deserialize(simple_string_serialized);
|
||||
assert.deepEqual(doc1, doc2)
|
||||
|
||||
// Hex Id
|
||||
var hexId = new ObjectID().toString();
|
||||
var docJS = {_id: ObjectID.createFromHexString(hexId), 'funds.remaining': {$gte: 1.222}, 'transactions.id': {$ne: ObjectID.createFromHexString(hexId)}};
|
||||
var docC = {_id: ObjectID.createFromHexString(hexId), 'funds.remaining': {$gte: 1.222}, 'transactions.id': {$ne: ObjectID.createFromHexString(hexId)}};
|
||||
var docJSBin = bsonJS.serialize(docJS, false, true, true);
|
||||
var docCBin = bsonC.serialize(docC, false, true, true);
|
||||
assert.equal(docCBin.toString('base64'), docJSBin.toString('base64'));
|
||||
|
||||
// // Complex document serialization
|
||||
// doc = {"DateTime": "Tue Nov 40 2011 17:27:55 GMT+0000 (WEST)","isActive": true,"Media": {"URL": "http://videos.sapo.pt/Tc85NsjaKjj8o5aV7Ubb"},"Title": "Lisboa fecha a ganhar 0.19%","SetPosition": 60,"Type": "videos","Thumbnail": [{"URL": "http://rd3.videos.sapo.pt/Tc85NsjaKjj8o5aV7Ubb/pic/320x240","Dimensions": {"Height": 240,"Width": 320}}],"Source": {"URL": "http://videos.sapo.pt","SetID": "1288","SourceID": "http://videos.sapo.pt/tvnet/rss2","SetURL": "http://noticias.sapo.pt/videos/tv-net_1288/","ItemID": "Tc85NsjaKjj8o5aV7Ubb","Name": "SAPO VÃdeos"},"Category": "Tec_ciencia","Description": "Lisboa fecha a ganhar 0.19%","GalleryID": new ObjectID("4eea2a634ce8573200000000"),"InternalRefs": {"RegisterDate": "Thu Dec 15 2011 17:12:51 GMT+0000 (WEST)","ChangeDate": "Thu Dec 15 2011 17:12:51 GMT+0000 (WEST)","Hash": 332279244514},"_id": new ObjectID("4eea2a96e52778160000003a")}
|
||||
// var docJSBin = bsonJS.serialize(docJS, false, true, true);
|
||||
// var docCBin = bsonC.serialize(docC, false, true, true);
|
||||
//
|
||||
//
|
||||
|
||||
// // Force garbage collect
|
||||
// global.gc();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
218
app/node_modules/mongodb/external-libs/bson/test/test_full_bson.js
generated
vendored
Normal file
218
app/node_modules/mongodb/external-libs/bson/test/test_full_bson.js
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
var sys = require('util'),
|
||||
fs = require('fs'),
|
||||
Buffer = require('buffer').Buffer,
|
||||
BSON = require('../bson').BSON,
|
||||
Buffer = require('buffer').Buffer,
|
||||
assert = require('assert'),
|
||||
BinaryParser = require('../../../lib/mongodb/bson/binary_parser').BinaryParser,
|
||||
BSONJS = require('../../../lib/mongodb/bson/bson').BSON,
|
||||
Long = require('../../../lib/mongodb/bson/long').Long,
|
||||
ObjectID = require('../../../lib/mongodb/bson/bson').ObjectID,
|
||||
Binary = require('../../../lib/mongodb/bson/bson').Binary,
|
||||
Code = require('../../../lib/mongodb/bson/bson').Code,
|
||||
DBRef = require('../../../lib/mongodb/bson/bson').DBRef,
|
||||
Symbol = require('../../../lib/mongodb/bson/bson').Symbol,
|
||||
Double = require('../../../lib/mongodb/bson/bson').Double,
|
||||
MaxKey = require('../../../lib/mongodb/bson/bson').MaxKey,
|
||||
MinKey = require('../../../lib/mongodb/bson/bson').MinKey,
|
||||
Timestamp = require('../../../lib/mongodb/bson/bson').Timestamp;
|
||||
|
||||
if(process.env['npm_package_config_native'] != null) return;
|
||||
|
||||
sys.puts("=== EXECUTING TEST_FULL_BSON ===");
|
||||
|
||||
// Parsers
|
||||
var bsonC = new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
|
||||
var bsonJS = new BSONJS([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
|
||||
|
||||
// Should Correctly Deserialize object
|
||||
var bytes = [95,0,0,0,2,110,115,0,42,0,0,0,105,110,116,101,103,114,97,116,105,111,110,95,116,101,115,116,115,95,46,116,101,115,116,95,105,110,100,101,120,95,105,110,102,111,114,109,97,116,105,111,110,0,8,117,110,105,113,117,101,0,0,3,107,101,121,0,12,0,0,0,16,97,0,1,0,0,0,0,2,110,97,109,101,0,4,0,0,0,97,95,49,0,0];
|
||||
var serialized_data = '';
|
||||
// Convert to chars
|
||||
for(var i = 0; i < bytes.length; i++) {
|
||||
serialized_data = serialized_data + BinaryParser.fromByte(bytes[i]);
|
||||
}
|
||||
var object = bsonC.deserialize(serialized_data);
|
||||
assert.equal("a_1", object.name);
|
||||
assert.equal(false, object.unique);
|
||||
assert.equal(1, object.key.a);
|
||||
|
||||
// Should Correctly Deserialize object with all types
|
||||
var bytes = [26,1,0,0,7,95,105,100,0,161,190,98,75,118,169,3,0,0,3,0,0,4,97,114,114,97,121,0,26,0,0,0,16,48,0,1,0,0,0,16,49,0,2,0,0,0,16,50,0,3,0,0,0,0,2,115,116,114,105,110,103,0,6,0,0,0,104,101,108,108,111,0,3,104,97,115,104,0,19,0,0,0,16,97,0,1,0,0,0,16,98,0,2,0,0,0,0,9,100,97,116,101,0,161,190,98,75,0,0,0,0,7,111,105,100,0,161,190,98,75,90,217,18,0,0,1,0,0,5,98,105,110,97,114,121,0,7,0,0,0,2,3,0,0,0,49,50,51,16,105,110,116,0,42,0,0,0,1,102,108,111,97,116,0,223,224,11,147,169,170,64,64,11,114,101,103,101,120,112,0,102,111,111,98,97,114,0,105,0,8,98,111,111,108,101,97,110,0,1,15,119,104,101,114,101,0,25,0,0,0,12,0,0,0,116,104,105,115,46,120,32,61,61,32,51,0,5,0,0,0,0,3,100,98,114,101,102,0,37,0,0,0,2,36,114,101,102,0,5,0,0,0,116,101,115,116,0,7,36,105,100,0,161,190,98,75,2,180,1,0,0,2,0,0,0,10,110,117,108,108,0,0];
|
||||
var serialized_data = '';
|
||||
// Convert to chars
|
||||
for(var i = 0; i < bytes.length; i++) {
|
||||
serialized_data = serialized_data + BinaryParser.fromByte(bytes[i]);
|
||||
}
|
||||
|
||||
var object = bsonJS.deserialize(new Buffer(serialized_data, 'binary'));
|
||||
assert.equal("hello", object.string);
|
||||
assert.deepEqual([1, 2, 3], object.array);
|
||||
assert.equal(1, object.hash.a);
|
||||
assert.equal(2, object.hash.b);
|
||||
assert.ok(object.date != null);
|
||||
assert.ok(object.oid != null);
|
||||
assert.ok(object.binary != null);
|
||||
assert.equal(42, object.int);
|
||||
assert.equal(33.3333, object.float);
|
||||
assert.ok(object.regexp != null);
|
||||
assert.equal(true, object.boolean);
|
||||
assert.ok(object.where != null);
|
||||
assert.ok(object.dbref != null);
|
||||
assert.ok(object['null'] == null);
|
||||
|
||||
// Should Serialize and Deserialze String
|
||||
var test_string = {hello: 'world'}
|
||||
var serialized_data = bsonC.serialize(test_string)
|
||||
assert.deepEqual(test_string, bsonC.deserialize(serialized_data));
|
||||
|
||||
// Should Correctly Serialize and Deserialize Integer
|
||||
var test_number = {doc: 5}
|
||||
var serialized_data = bsonC.serialize(test_number)
|
||||
assert.deepEqual(test_number, bsonC.deserialize(serialized_data));
|
||||
|
||||
// Should Correctly Serialize and Deserialize null value
|
||||
var test_null = {doc:null}
|
||||
var serialized_data = bsonC.serialize(test_null)
|
||||
var object = bsonC.deserialize(serialized_data);
|
||||
assert.deepEqual(test_null, object);
|
||||
|
||||
// Should Correctly Serialize and Deserialize undefined value
|
||||
var test_undefined = {doc:undefined}
|
||||
var serialized_data = bsonC.serialize(test_undefined)
|
||||
var object = bsonJS.deserialize(new Buffer(serialized_data, 'binary'));
|
||||
assert.equal(null, object.doc)
|
||||
|
||||
// Should Correctly Serialize and Deserialize Number
|
||||
var test_number = {doc: 5.5}
|
||||
var serialized_data = bsonC.serialize(test_number)
|
||||
assert.deepEqual(test_number, bsonC.deserialize(serialized_data));
|
||||
|
||||
// Should Correctly Serialize and Deserialize Integer
|
||||
var test_int = {doc: 42}
|
||||
var serialized_data = bsonC.serialize(test_int)
|
||||
assert.deepEqual(test_int, bsonC.deserialize(serialized_data));
|
||||
|
||||
test_int = {doc: -5600}
|
||||
serialized_data = bsonC.serialize(test_int)
|
||||
assert.deepEqual(test_int, bsonC.deserialize(serialized_data));
|
||||
|
||||
test_int = {doc: 2147483647}
|
||||
serialized_data = bsonC.serialize(test_int)
|
||||
assert.deepEqual(test_int, bsonC.deserialize(serialized_data));
|
||||
|
||||
test_int = {doc: -2147483648}
|
||||
serialized_data = bsonC.serialize(test_int)
|
||||
assert.deepEqual(test_int, bsonC.deserialize(serialized_data));
|
||||
|
||||
// Should Correctly Serialize and Deserialize Object
|
||||
var doc = {doc: {age: 42, name: 'Spongebob', shoe_size: 9.5}}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
assert.deepEqual(doc, bsonC.deserialize(serialized_data));
|
||||
|
||||
// Should Correctly Serialize and Deserialize Array
|
||||
var doc = {doc: [1, 2, 'a', 'b']}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
assert.deepEqual(doc, bsonC.deserialize(serialized_data));
|
||||
|
||||
// Should Correctly Serialize and Deserialize Array with added on functions
|
||||
var doc = {doc: [1, 2, 'a', 'b']}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
assert.deepEqual(doc, bsonC.deserialize(serialized_data));
|
||||
|
||||
// Should Correctly Serialize and Deserialize A Boolean
|
||||
var doc = {doc: true}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
assert.deepEqual(doc, bsonC.deserialize(serialized_data));
|
||||
|
||||
// Should Correctly Serialize and Deserialize a Date
|
||||
var date = new Date()
|
||||
//(2009, 11, 12, 12, 00, 30)
|
||||
date.setUTCDate(12)
|
||||
date.setUTCFullYear(2009)
|
||||
date.setUTCMonth(11 - 1)
|
||||
date.setUTCHours(12)
|
||||
date.setUTCMinutes(0)
|
||||
date.setUTCSeconds(30)
|
||||
var doc = {doc: date}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
assert.deepEqual(doc, bsonC.deserialize(serialized_data));
|
||||
|
||||
// // Should Correctly Serialize and Deserialize Oid
|
||||
var doc = {doc: new ObjectID()}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
assert.deepEqual(doc.doc.toHexString(), bsonC.deserialize(serialized_data).doc.toHexString())
|
||||
|
||||
// Should Correctly encode Empty Hash
|
||||
var test_code = {}
|
||||
var serialized_data = bsonC.serialize(test_code)
|
||||
assert.deepEqual(test_code, bsonC.deserialize(serialized_data));
|
||||
|
||||
// Should Correctly Serialize and Deserialize Ordered Hash
|
||||
var doc = {doc: {b:1, a:2, c:3, d:4}}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
var decoded_hash = bsonC.deserialize(serialized_data).doc
|
||||
var keys = []
|
||||
for(name in decoded_hash) keys.push(name)
|
||||
assert.deepEqual(['b', 'a', 'c', 'd'], keys)
|
||||
|
||||
// Should Correctly Serialize and Deserialize Regular Expression
|
||||
// Serialize the regular expression
|
||||
var doc = {doc: /foobar/mi}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
var doc2 = bsonC.deserialize(serialized_data);
|
||||
assert.equal(doc.doc.toString(), doc2.doc.toString())
|
||||
|
||||
// Should Correctly Serialize and Deserialize a Binary object
|
||||
var bin = new Binary()
|
||||
var string = 'binstring'
|
||||
for(var index = 0; index < string.length; index++) {
|
||||
bin.put(string.charAt(index))
|
||||
}
|
||||
var doc = {doc: bin}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
var deserialized_data = bsonC.deserialize(serialized_data);
|
||||
assert.equal(doc.doc.value(), deserialized_data.doc.value())
|
||||
|
||||
// Should Correctly Serialize and Deserialize a big Binary object
|
||||
var data = fs.readFileSync("../../test/gridstore/test_gs_weird_bug.png", 'binary');
|
||||
var bin = new Binary()
|
||||
bin.write(data)
|
||||
var doc = {doc: bin}
|
||||
var serialized_data = bsonC.serialize(doc)
|
||||
var deserialized_data = bsonC.deserialize(serialized_data);
|
||||
assert.equal(doc.doc.value(), deserialized_data.doc.value())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
132
app/node_modules/mongodb/external-libs/bson/test/test_stackless_bson.js
generated
vendored
Normal file
132
app/node_modules/mongodb/external-libs/bson/test/test_stackless_bson.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
var Buffer = require('buffer').Buffer,
|
||||
BSON = require('../bson').BSON,
|
||||
Buffer = require('buffer').Buffer,
|
||||
BSONJS = require('../../../lib/mongodb/bson/bson').BSON,
|
||||
BinaryParser = require('../../../lib/mongodb/bson/binary_parser').BinaryParser,
|
||||
Long = require('../../../lib/mongodb/bson/long').Long,
|
||||
ObjectID = require('../../../lib/mongodb/bson/bson').ObjectID,
|
||||
Binary = require('../../../lib/mongodb/bson/bson').Binary,
|
||||
Code = require('../../../lib/mongodb/bson/bson').Code,
|
||||
DBRef = require('../../../lib/mongodb/bson/bson').DBRef,
|
||||
Symbol = require('../../../lib/mongodb/bson/bson').Symbol,
|
||||
Double = require('../../../lib/mongodb/bson/bson').Double,
|
||||
MaxKey = require('../../../lib/mongodb/bson/bson').MaxKey,
|
||||
MinKey = require('../../../lib/mongodb/bson/bson').MinKey,
|
||||
Timestamp = require('../../../lib/mongodb/bson/bson').Timestamp;
|
||||
assert = require('assert');
|
||||
|
||||
if(process.env['npm_package_config_native'] != null) return;
|
||||
|
||||
console.log("=== EXECUTING TEST_STACKLESS_BSON ===");
|
||||
|
||||
// Parsers
|
||||
var bsonC = new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
|
||||
var bsonJS = new BSONJS([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
|
||||
|
||||
// Number of iterations for the benchmark
|
||||
var COUNT = 10000;
|
||||
// var COUNT = 1;
|
||||
// Sample simple doc
|
||||
var doc = {key:"Hello world", key2:"šđžčćŠĐŽČĆ", key3:'客家话', key4:'how are you doing dog!!'};
|
||||
// var doc = {};
|
||||
// for(var i = 0; i < 100; i++) {
|
||||
// doc['string' + i] = "dumdyms fsdfdsfdsfdsfsdfdsfsdfsdfsdfsdfsdfsdfsdffsfsdfs";
|
||||
// }
|
||||
|
||||
// // Calculate size
|
||||
console.log(bsonC.calculateObjectSize2(doc));
|
||||
console.log(bsonJS.calculateObjectSize(doc));
|
||||
// assert.equal(bsonJS.calculateObjectSize(doc), bsonC.calculateObjectSize2(doc));
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
// Benchmark calculateObjectSize
|
||||
// ----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Benchmark 1 JS BSON
|
||||
console.log(COUNT + "x (objectBSON = bsonC.calculateObjectSize(object))")
|
||||
start = new Date
|
||||
|
||||
for (j=COUNT; --j>=0; ) {
|
||||
var objectBSON = bsonJS.calculateObjectSize(doc);
|
||||
}
|
||||
|
||||
end = new Date
|
||||
var opsprsecond = COUNT / ((end - start)/1000);
|
||||
console.log("time = ", end - start, "ms -", COUNT / ((end - start)/1000), " ops/sec");
|
||||
|
||||
// Benchmark 2 C++ BSON calculateObjectSize
|
||||
console.log(COUNT + "x (objectBSON = bsonC.calculateObjectSize(object))")
|
||||
start = new Date
|
||||
|
||||
for (j=COUNT; --j>=0; ) {
|
||||
var objectBSON = bsonC.calculateObjectSize(doc);
|
||||
}
|
||||
|
||||
end = new Date
|
||||
var opsprsecond = COUNT / ((end - start)/1000);
|
||||
console.log("time = ", end - start, "ms -", COUNT / ((end - start)/1000), " ops/sec");
|
||||
|
||||
// Benchmark 3 C++ BSON calculateObjectSize2
|
||||
console.log(COUNT + "x (objectBSON = bsonC.calculateObjectSize2(object))")
|
||||
start = new Date
|
||||
|
||||
for (j=COUNT; --j>=0; ) {
|
||||
var objectBSON = bsonC.calculateObjectSize2(doc);
|
||||
}
|
||||
|
||||
end = new Date
|
||||
var opsprsecond = COUNT / ((end - start)/1000);
|
||||
console.log("time = ", end - start, "ms -", COUNT / ((end - start)/1000), " ops/sec");
|
||||
|
||||
// // Serialize the content
|
||||
// var _serializedDoc1 = bsonJS.serialize(doc, true, false);
|
||||
// var _serializedDoc2 = bsonC.serialize2(doc, true, false);
|
||||
// console.dir(_serializedDoc1);
|
||||
// console.dir(_serializedDoc2);
|
||||
// assert.equal(_serializedDoc1.toString('base64'), _serializedDoc2.toString('base64'))
|
||||
//
|
||||
//
|
||||
// // Benchmark 1
|
||||
// console.log(COUNT + "x (objectBSON = bsonC.serialize(object))")
|
||||
// start = new Date
|
||||
//
|
||||
// for (j=COUNT; --j>=0; ) {
|
||||
// // var objectBSON = bsonC.serialize2(doc, true, false);
|
||||
// var objectBSON = bsonJS.serialize(doc, true, false);
|
||||
// }
|
||||
//
|
||||
// end = new Date
|
||||
// var opsprsecond = COUNT / ((end - start)/1000);
|
||||
// console.log("bson size (bytes): ", objectbsonC.length);
|
||||
// console.log("time = ", end - start, "ms -", COUNT / ((end - start)/1000), " ops/sec");
|
||||
// console.log("MB/s = " + ((opsprsecond*objectbsonC.length)/1024));
|
||||
//
|
||||
// // Benchmark 2
|
||||
// console.log(COUNT + "x (objectBSON = bsonC.serialize(object))")
|
||||
// start = new Date
|
||||
//
|
||||
// for (j=COUNT; --j>=0; ) {
|
||||
// var objectBSON = bsonC.serialize2(doc, true, false);
|
||||
// }
|
||||
//
|
||||
// end = new Date
|
||||
// var opsprsecond = COUNT / ((end - start)/1000);
|
||||
// console.log("bson size (bytes): ", objectbsonC.length);
|
||||
// console.log("time = ", end - start, "ms -", COUNT / ((end - start)/1000), " ops/sec");
|
||||
// console.log("MB/s = " + ((opsprsecond*objectbsonC.length)/1024));
|
||||
//
|
||||
// // Benchmark 3
|
||||
// console.log(COUNT + "x (objectBSON = bsonC.serialize(object))")
|
||||
// start = new Date
|
||||
//
|
||||
// for (j=COUNT; --j>=0; ) {
|
||||
// var objectBSON = bsonC.serialize(doc, true, false);
|
||||
// }
|
||||
//
|
||||
// end = new Date
|
||||
// var opsprsecond = COUNT / ((end - start)/1000);
|
||||
// console.log("bson size (bytes): ", objectbsonC.length);
|
||||
// console.log("time = ", end - start, "ms -", COUNT / ((end - start)/1000), " ops/sec");
|
||||
// console.log("MB/s = " + ((opsprsecond*objectbsonC.length)/1024));
|
||||
39
app/node_modules/mongodb/external-libs/bson/wscript
generated
vendored
Normal file
39
app/node_modules/mongodb/external-libs/bson/wscript
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import Options
|
||||
from os import unlink, symlink, popen
|
||||
from os.path import exists
|
||||
|
||||
srcdir = "."
|
||||
blddir = "build"
|
||||
VERSION = "0.1.0"
|
||||
|
||||
def set_options(opt):
|
||||
opt.tool_options("compiler_cxx")
|
||||
opt.add_option( '--debug'
|
||||
, action='store_true'
|
||||
, default=False
|
||||
, help='Build debug variant [Default: False]'
|
||||
, dest='debug'
|
||||
)
|
||||
|
||||
def configure(conf):
|
||||
conf.check_tool("compiler_cxx")
|
||||
conf.check_tool("node_addon")
|
||||
conf.env.append_value('CXXFLAGS', ['-O3', '-funroll-loops'])
|
||||
|
||||
# conf.env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
|
||||
# conf.check(lib='node', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='NODE')
|
||||
|
||||
def build(bld):
|
||||
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
|
||||
obj.target = "bson"
|
||||
obj.source = ["bson.cc"]
|
||||
# obj.uselib = "NODE"
|
||||
|
||||
def shutdown():
|
||||
# HACK to get compress.node out of build directory.
|
||||
# better way to do this?
|
||||
if Options.commands['clean']:
|
||||
if exists('bson.node'): unlink('bson.node')
|
||||
else:
|
||||
if exists('build/default/bson.node') and not exists('bson.node'):
|
||||
symlink('build/default/bson.node', 'bson.node')
|
||||
Reference in New Issue
Block a user