bson 0.1.8 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -1
- package/browser_build/bson.js +205 -176
- package/build/Release/bson.exp +0 -0
- package/build/Release/bson.lib +0 -0
- package/build/Release/bson.node +0 -0
- package/build/Release/bson.pdb +0 -0
- package/build/Release/obj/bson/bson.lastbuildstate +2 -0
- package/build/Release/obj/bson/bson.node.intermediate.manifest +10 -0
- package/build/Release/obj/bson/bson.obj +0 -0
- package/build/Release/obj/bson/bson.vcxprojResolveAssemblyReference.cache +0 -0
- package/build/Release/obj/bson/bson.write.1.tlog +3 -0
- package/build/Release/obj/bson/cl.command.1.tlog +0 -0
- package/build/Release/obj/bson/cl.read.1.tlog +0 -0
- package/build/Release/obj/bson/cl.write.1.tlog +0 -0
- package/build/Release/obj/bson/link.command.1.tlog +0 -0
- package/build/Release/obj/bson/link.read.1.tlog +0 -0
- package/build/Release/obj/bson/link.write.1.tlog +0 -0
- package/build/Release/obj/bson/mt.command.1.tlog +0 -0
- package/build/Release/obj/bson/mt.read.1.tlog +0 -0
- package/build/Release/obj/bson/mt.write.1.tlog +0 -0
- package/build/Release/obj/bson/vcwindows7.1sdk.pdb +0 -0
- package/build/binding.sln +21 -0
- package/build/bson.vcxproj +127 -0
- package/build/bson.vcxproj.filters +19 -0
- package/build/config.gypi +17 -8
- package/ext/bson.cc +68 -29
- package/ext/bson.h +9 -5
- package/ext/win32/ia32/bson.node +0 -0
- package/ext/win32/x64/bson.node +0 -0
- package/lib/bson/bson.js +192 -172
- package/lib/bson/objectid.js +4 -4
- package/package.json +2 -2
- package/benchmarks/benchmarks.js +0 -130
- package/build/Makefile +0 -355
- package/build/Release/.deps/Release/bson.node.d +0 -1
- package/build/Release/.deps/Release/obj.target/bson/ext/bson.o.d +0 -34
- package/build/Release/linker.lock +0 -0
- package/build/Release/obj.target/bson/ext/bson.o +0 -0
- package/build/binding.Makefile +0 -6
- package/build/bson.target.mk +0 -154
- package/build/gyp-mac-tool +0 -211
- package/test/browser/browser_example.htm +0 -19
- package/test/browser/bson_test.js +0 -260
- package/test/browser/nodeunit.js +0 -2034
- package/test/browser/suite2.js +0 -13
- package/test/browser/suite3.js +0 -7
- package/test/browser/test.html +0 -30
- package/test/node/bson_array_test.js +0 -240
- package/test/node/bson_parser_comparision_test.js +0 -493
- package/test/node/bson_test.js +0 -1694
- package/test/node/bson_typed_array_test.js +0 -392
- package/test/node/data/test_gs_weird_bug.png +0 -0
- package/test/node/test_full_bson.js +0 -315
- package/test/node/to_bson_test.js +0 -109
- package/test/node/tools/utils.js +0 -80
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
var sys = require('util'),
|
|
2
|
-
debug = require('util').debug,
|
|
3
|
-
inspect = require('util').inspect,
|
|
4
|
-
Buffer = require('buffer').Buffer,
|
|
5
|
-
BSON = require('../../ext').BSON,
|
|
6
|
-
Buffer = require('buffer').Buffer,
|
|
7
|
-
BSONJS = require('../../lib/bson/bson').BSON,
|
|
8
|
-
BinaryParser = require('../../lib/bson/binary_parser').BinaryParser,
|
|
9
|
-
Long = require('../../lib/bson/long').Long,
|
|
10
|
-
ObjectID = require('../../lib/bson/bson').ObjectID,
|
|
11
|
-
Binary = require('../../lib/bson/bson').Binary,
|
|
12
|
-
Code = require('../../lib/bson/bson').Code,
|
|
13
|
-
DBRef = require('../../lib/bson/bson').DBRef,
|
|
14
|
-
Symbol = require('../../lib/bson/bson').Symbol,
|
|
15
|
-
Double = require('../../lib/bson/bson').Double,
|
|
16
|
-
MaxKey = require('../../lib/bson/bson').MaxKey,
|
|
17
|
-
MinKey = require('../../lib/bson/bson').MinKey,
|
|
18
|
-
Timestamp = require('../../lib/bson/bson').Timestamp,
|
|
19
|
-
gleak = require('../../tools/gleak'),
|
|
20
|
-
assert = require('assert');
|
|
21
|
-
|
|
22
|
-
// Long/ObjectID/Binary/Code/DbRef/Symbol/Double/Timestamp/MinKey/MaxKey
|
|
23
|
-
var bsonC = new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
|
|
24
|
-
var bsonJS = new BSONJS([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey]);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Retrieve the server information for the current
|
|
28
|
-
* instance of the db client
|
|
29
|
-
*
|
|
30
|
-
* @ignore
|
|
31
|
-
*/
|
|
32
|
-
exports.setUp = function(callback) {
|
|
33
|
-
callback();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Retrieve the server information for the current
|
|
38
|
-
* instance of the db client
|
|
39
|
-
*
|
|
40
|
-
* @ignore
|
|
41
|
-
*/
|
|
42
|
-
exports.tearDown = function(callback) {
|
|
43
|
-
callback();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @ignore
|
|
48
|
-
*/
|
|
49
|
-
exports['Should Correctly Serialize and Deserialize simple edge value'] = function(test) {
|
|
50
|
-
// Simple serialization and deserialization of edge value
|
|
51
|
-
var doc = {doc:0x1ffffffffffffe};
|
|
52
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
53
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
54
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
55
|
-
|
|
56
|
-
var doc = {doc:-0x1ffffffffffffe};
|
|
57
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
58
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
59
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
60
|
-
test.done();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @ignore
|
|
65
|
-
*/
|
|
66
|
-
exports['Should Correctly execute toJSON'] = function(test) {
|
|
67
|
-
var a = Long.fromNumber(10);
|
|
68
|
-
assert.equal(10, a);
|
|
69
|
-
|
|
70
|
-
var a = Long.fromNumber(9223372036854775807);
|
|
71
|
-
assert.equal(9223372036854775807, a);
|
|
72
|
-
|
|
73
|
-
// Simple serialization and deserialization test for a Single String value
|
|
74
|
-
var doc = {doc:'Serialize'};
|
|
75
|
-
var simple_string_serialized = bsonC.serialize(doc, true, false);
|
|
76
|
-
|
|
77
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
78
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
79
|
-
test.done();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @ignore
|
|
84
|
-
*/
|
|
85
|
-
exports['Should Serialize and Deserialize nested document'] = function(test) {
|
|
86
|
-
// Nested doc
|
|
87
|
-
var doc = {a:{b:{c:1}}};
|
|
88
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
89
|
-
|
|
90
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
91
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
92
|
-
test.done();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @ignore
|
|
97
|
-
*/
|
|
98
|
-
exports['Simple integer serialization/deserialization test, including testing boundary conditions'] = function(test) {
|
|
99
|
-
var doc = {doc:-1};
|
|
100
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
101
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
102
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
103
|
-
|
|
104
|
-
var doc = {doc:2147483648};
|
|
105
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
106
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
107
|
-
|
|
108
|
-
var doc = {doc:-2147483648};
|
|
109
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
110
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
111
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
112
|
-
test.done();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @ignore
|
|
117
|
-
*/
|
|
118
|
-
exports['Simple serialization and deserialization test for a Long value'] = function(test) {
|
|
119
|
-
var doc = {doc:Long.fromNumber(9223372036854775807)};
|
|
120
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
121
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize({doc:Long.fromNumber(9223372036854775807)}, false, true));
|
|
122
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
123
|
-
|
|
124
|
-
var doc = {doc:Long.fromNumber(-9223372036854775807)};
|
|
125
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
126
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize({doc:Long.fromNumber(-9223372036854775807)}, false, true));
|
|
127
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
128
|
-
test.done();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @ignore
|
|
133
|
-
*/
|
|
134
|
-
exports['Simple serialization and deserialization for a Float value'] = function(test) {
|
|
135
|
-
var doc = {doc:2222.3333};
|
|
136
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
137
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
138
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
139
|
-
|
|
140
|
-
var doc = {doc:-2222.3333};
|
|
141
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
142
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
143
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
144
|
-
test.done();
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @ignore
|
|
149
|
-
*/
|
|
150
|
-
exports['Simple serialization and deserialization for a null value'] = function(test) {
|
|
151
|
-
var doc = {doc:null};
|
|
152
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
153
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
154
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
155
|
-
test.done();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* @ignore
|
|
160
|
-
*/
|
|
161
|
-
exports['Simple serialization and deserialization for a boolean value'] = function(test) {
|
|
162
|
-
var doc = {doc:true};
|
|
163
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
164
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
165
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
166
|
-
test.done();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* @ignore
|
|
171
|
-
*/
|
|
172
|
-
exports['Simple serialization and deserialization for a date value'] = function(test) {
|
|
173
|
-
var date = new Date();
|
|
174
|
-
var doc = {doc:date};
|
|
175
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
176
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
177
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')), bsonC.deserialize(simple_string_serialized));
|
|
178
|
-
test.done();
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @ignore
|
|
183
|
-
*/
|
|
184
|
-
exports['Simple serialization and deserialization for a boolean value'] = function(test) {
|
|
185
|
-
var doc = {doc:/abcd/mi};
|
|
186
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
187
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
188
|
-
assert.equal(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.toString(), bsonC.deserialize(simple_string_serialized).doc.toString());
|
|
189
|
-
|
|
190
|
-
var doc = {doc:/abcd/};
|
|
191
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
192
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc, false, true));
|
|
193
|
-
assert.equal(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.toString(), bsonC.deserialize(simple_string_serialized).doc.toString());
|
|
194
|
-
test.done();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* @ignore
|
|
199
|
-
*/
|
|
200
|
-
exports['Simple serialization and deserialization for a objectId value'] = function(test) {
|
|
201
|
-
var doc = {doc:new ObjectID()};
|
|
202
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
203
|
-
var doc2 = {doc:ObjectID.createFromHexString(doc.doc.toHexString())};
|
|
204
|
-
|
|
205
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize(doc2, false, true));
|
|
206
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.toString(), bsonC.deserialize(simple_string_serialized).doc.toString());
|
|
207
|
-
test.done();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* @ignore
|
|
212
|
-
*/
|
|
213
|
-
exports['Simple serialization and deserialization for a Binary value'] = function(test) {
|
|
214
|
-
var binary = new Binary();
|
|
215
|
-
var string = 'binstring'
|
|
216
|
-
for(var index = 0; index < string.length; index++) { binary.put(string.charAt(index)); }
|
|
217
|
-
|
|
218
|
-
var simple_string_serialized = bsonC.serialize({doc:binary}, false, true);
|
|
219
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize({doc:binary}, false, true));
|
|
220
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.value(), bsonC.deserialize(simple_string_serialized).doc.value());
|
|
221
|
-
test.done();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* @ignore
|
|
226
|
-
*/
|
|
227
|
-
exports['Simple serialization and deserialization for a Binary value of type 2'] = function(test) {
|
|
228
|
-
var binary = new Binary(new Buffer('binstring'), Binary.SUBTYPE_BYTE_ARRAY);
|
|
229
|
-
var simple_string_serialized = bsonC.serialize({doc:binary}, false, true);
|
|
230
|
-
assert.deepEqual(simple_string_serialized, bsonJS.serialize({doc:binary}, false, true));
|
|
231
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized, 'binary')).doc.value(), bsonC.deserialize(simple_string_serialized).doc.value());
|
|
232
|
-
test.done();
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* @ignore
|
|
237
|
-
*/
|
|
238
|
-
exports['Simple serialization and deserialization for a Code value'] = function(test) {
|
|
239
|
-
var code = new Code('this.a > i', {'i': 1});
|
|
240
|
-
var simple_string_serialized_2 = bsonJS.serialize({doc:code}, false, true);
|
|
241
|
-
var simple_string_serialized = bsonC.serialize({doc:code}, false, true);
|
|
242
|
-
|
|
243
|
-
assert.deepEqual(simple_string_serialized, simple_string_serialized_2);
|
|
244
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary')).doc.scope, bsonC.deserialize(simple_string_serialized).doc.scope);
|
|
245
|
-
test.done();
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @ignore
|
|
250
|
-
*/
|
|
251
|
-
exports['Simple serialization and deserialization for an Object'] = function(test) {
|
|
252
|
-
var simple_string_serialized = bsonC.serialize({doc:{a:1, b:{c:2}}}, false, true);
|
|
253
|
-
var simple_string_serialized_2 = bsonJS.serialize({doc:{a:1, b:{c:2}}}, false, true);
|
|
254
|
-
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
|
255
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary')).doc, bsonC.deserialize(simple_string_serialized).doc);
|
|
256
|
-
|
|
257
|
-
// Simple serialization and deserialization for an Array
|
|
258
|
-
var simple_string_serialized = bsonC.serialize({doc:[9, 9, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1]}, false, true);
|
|
259
|
-
var simple_string_serialized_2 = bsonJS.serialize({doc:[9, 9, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1]}, false, true);
|
|
260
|
-
|
|
261
|
-
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
|
262
|
-
assert.deepEqual(bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary')).doc, bsonC.deserialize(simple_string_serialized).doc);
|
|
263
|
-
test.done();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* @ignore
|
|
268
|
-
*/
|
|
269
|
-
exports['Simple serialization and deserialization for a DBRef'] = function(test) {
|
|
270
|
-
var oid = new ObjectID()
|
|
271
|
-
var oid2 = new ObjectID.createFromHexString(oid.toHexString())
|
|
272
|
-
var simple_string_serialized = bsonJS.serialize({doc:new DBRef('namespace', oid2, 'integration_tests_')}, false, true);
|
|
273
|
-
var simple_string_serialized_2 = bsonC.serialize({doc:new DBRef('namespace', oid, 'integration_tests_')}, false, true);
|
|
274
|
-
|
|
275
|
-
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
|
276
|
-
// Ensure we have the same values for the dbref
|
|
277
|
-
var object_js = bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary'));
|
|
278
|
-
var object_c = bsonC.deserialize(simple_string_serialized);
|
|
279
|
-
|
|
280
|
-
assert.equal(object_js.doc.namespace, object_c.doc.namespace);
|
|
281
|
-
assert.equal(object_js.doc.oid.toHexString(), object_c.doc.oid.toHexString());
|
|
282
|
-
assert.equal(object_js.doc.db, object_c.doc.db);
|
|
283
|
-
test.done();
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* @ignore
|
|
288
|
-
*/
|
|
289
|
-
exports['Should correctly deserialize bytes array'] = function(test) {
|
|
290
|
-
// Serialized document
|
|
291
|
-
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];
|
|
292
|
-
var serialized_data = '';
|
|
293
|
-
// Convert to chars
|
|
294
|
-
for(var i = 0; i < bytes.length; i++) {
|
|
295
|
-
serialized_data = serialized_data + BinaryParser.fromByte(bytes[i]);
|
|
296
|
-
}
|
|
297
|
-
var object = bsonC.deserialize(new Buffer(serialized_data, 'binary'));
|
|
298
|
-
assert.equal('Patty', object.name)
|
|
299
|
-
assert.equal(34, object.age)
|
|
300
|
-
assert.equal('4c640c170b1e270859000001', object._id.toHexString())
|
|
301
|
-
test.done();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* @ignore
|
|
306
|
-
*/
|
|
307
|
-
exports['Serialize utf8'] = function(test) {
|
|
308
|
-
var doc = { "name" : "本荘由利地域に洪水警報", "name1" : "öüóőúéáűíÖÜÓŐÚÉÁŰÍ", "name2" : "abcdedede"};
|
|
309
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
310
|
-
var simple_string_serialized2 = bsonJS.serialize(doc, false, true);
|
|
311
|
-
assert.deepEqual(simple_string_serialized, simple_string_serialized2)
|
|
312
|
-
|
|
313
|
-
var object = bsonC.deserialize(simple_string_serialized);
|
|
314
|
-
assert.equal(doc.name, object.name)
|
|
315
|
-
assert.equal(doc.name1, object.name1)
|
|
316
|
-
assert.equal(doc.name2, object.name2)
|
|
317
|
-
test.done();
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* @ignore
|
|
322
|
-
*/
|
|
323
|
-
exports['Serialize object with array'] = function(test) {
|
|
324
|
-
var doc = {b:[1, 2, 3]};
|
|
325
|
-
var simple_string_serialized = bsonC.serialize(doc, false, true);
|
|
326
|
-
var simple_string_serialized_2 = bsonJS.serialize(doc, false, true);
|
|
327
|
-
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
|
328
|
-
|
|
329
|
-
var object = bsonC.deserialize(simple_string_serialized);
|
|
330
|
-
assert.deepEqual(doc, object)
|
|
331
|
-
test.done();
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* @ignore
|
|
336
|
-
*/
|
|
337
|
-
exports['Test equality of an object ID'] = function(test) {
|
|
338
|
-
var object_id = new ObjectID();
|
|
339
|
-
var object_id_2 = new ObjectID();
|
|
340
|
-
assert.ok(object_id.equals(object_id));
|
|
341
|
-
assert.ok(!(object_id.equals(object_id_2)))
|
|
342
|
-
test.done();
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* @ignore
|
|
347
|
-
*/
|
|
348
|
-
exports['Test same serialization for Object ID'] = function(test) {
|
|
349
|
-
var object_id = new ObjectID();
|
|
350
|
-
var object_id2 = ObjectID.createFromHexString(object_id.toString())
|
|
351
|
-
var simple_string_serialized = bsonJS.serialize({doc:object_id}, false, true);
|
|
352
|
-
var simple_string_serialized_2 = bsonC.serialize({doc:object_id2}, false, true);
|
|
353
|
-
|
|
354
|
-
assert.equal(simple_string_serialized_2.length, simple_string_serialized.length);
|
|
355
|
-
assert.deepEqual(simple_string_serialized, simple_string_serialized_2)
|
|
356
|
-
var object = bsonJS.deserialize(new Buffer(simple_string_serialized_2, 'binary'));
|
|
357
|
-
var object2 = bsonC.deserialize(simple_string_serialized);
|
|
358
|
-
assert.equal(object.doc.id, object2.doc.id)
|
|
359
|
-
test.done();
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* @ignore
|
|
364
|
-
*/
|
|
365
|
-
exports['Complex object serialization'] = function(test) {
|
|
366
|
-
// JS Object
|
|
367
|
-
var c1 = { _id: new ObjectID, comments: [], title: 'number 1' };
|
|
368
|
-
var c2 = { _id: new ObjectID, comments: [], title: 'number 2' };
|
|
369
|
-
var doc = {
|
|
370
|
-
numbers: []
|
|
371
|
-
, owners: []
|
|
372
|
-
, comments: [c1, c2]
|
|
373
|
-
, _id: new ObjectID
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
var simple_string_serialized = bsonJS.serialize(doc, false, true);
|
|
377
|
-
|
|
378
|
-
// C++ Object
|
|
379
|
-
var c1 = { _id: ObjectID.createFromHexString(c1._id.toHexString()), comments: [], title: 'number 1' };
|
|
380
|
-
var c2 = { _id: ObjectID.createFromHexString(c2._id.toHexString()), comments: [], title: 'number 2' };
|
|
381
|
-
var doc = {
|
|
382
|
-
numbers: []
|
|
383
|
-
, owners: []
|
|
384
|
-
, comments: [c1, c2]
|
|
385
|
-
, _id: ObjectID.createFromHexString(doc._id.toHexString())
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
var simple_string_serialized_2 = bsonC.serialize(doc, false, true);
|
|
389
|
-
|
|
390
|
-
for(var i = 0; i < simple_string_serialized_2.length; i++) {
|
|
391
|
-
// debug(i + "[" + simple_string_serialized_2[i] + "] = [" + simple_string_serialized[i] + "]")
|
|
392
|
-
assert.equal(simple_string_serialized_2[i], simple_string_serialized[i]);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
var doc1 = bsonJS.deserialize(new Buffer(simple_string_serialized_2));
|
|
396
|
-
var doc2 = bsonC.deserialize(new Buffer(simple_string_serialized_2));
|
|
397
|
-
assert.equal(doc._id.id, doc1._id.id)
|
|
398
|
-
assert.equal(doc._id.id, doc2._id.id)
|
|
399
|
-
assert.equal(doc1._id.id, doc2._id.id)
|
|
400
|
-
|
|
401
|
-
var doc = {
|
|
402
|
-
_id: 'testid',
|
|
403
|
-
key1: { code: 'test1', time: {start:1309323402727,end:1309323402727}, x:10, y:5 },
|
|
404
|
-
key2: { code: 'test1', time: {start:1309323402727,end:1309323402727}, x:10, y:5 }
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
var simple_string_serialized = bsonJS.serialize(doc, false, true);
|
|
408
|
-
var simple_string_serialized_2 = bsonC.serialize(doc, false, true);
|
|
409
|
-
test.done();
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* @ignore
|
|
414
|
-
*/
|
|
415
|
-
exports['Serialize function'] = function(test) {
|
|
416
|
-
var doc = {
|
|
417
|
-
_id: 'testid',
|
|
418
|
-
key1: function() {}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
var simple_string_serialized = bsonJS.serialize(doc, false, true, true);
|
|
422
|
-
var simple_string_serialized_2 = bsonC.serialize(doc, false, true, true);
|
|
423
|
-
|
|
424
|
-
// Deserialize the string
|
|
425
|
-
var doc1 = bsonJS.deserialize(new Buffer(simple_string_serialized_2));
|
|
426
|
-
var doc2 = bsonC.deserialize(new Buffer(simple_string_serialized_2));
|
|
427
|
-
assert.equal(doc1.key1.code.toString(), doc2.key1.code.toString())
|
|
428
|
-
test.done();
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* @ignore
|
|
433
|
-
*/
|
|
434
|
-
exports['Serialize document with special operators'] = function(test) {
|
|
435
|
-
var doc = {"user_id":"4e9fc8d55883d90100000003","lc_status":{"$ne":"deleted"},"owner_rating":{"$exists":false}};
|
|
436
|
-
var simple_string_serialized = bsonJS.serialize(doc, false, true, true);
|
|
437
|
-
var simple_string_serialized_2 = bsonC.serialize(doc, false, true, true);
|
|
438
|
-
|
|
439
|
-
// Should serialize to the same value
|
|
440
|
-
assert.equal(simple_string_serialized_2.toString('base64'), simple_string_serialized.toString('base64'))
|
|
441
|
-
var doc1 = bsonJS.deserialize(simple_string_serialized_2);
|
|
442
|
-
var doc2 = bsonC.deserialize(simple_string_serialized);
|
|
443
|
-
assert.deepEqual(doc1, doc2)
|
|
444
|
-
test.done();
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* @ignore
|
|
449
|
-
*/
|
|
450
|
-
exports['Create ObjectID from hex string'] = function(test) {
|
|
451
|
-
// Hex Id
|
|
452
|
-
var hexId = new ObjectID().toString();
|
|
453
|
-
var docJS = {_id: ObjectID.createFromHexString(hexId), 'funds.remaining': {$gte: 1.222}, 'transactions.id': {$ne: ObjectID.createFromHexString(hexId)}};
|
|
454
|
-
var docC = {_id: ObjectID.createFromHexString(hexId), 'funds.remaining': {$gte: 1.222}, 'transactions.id': {$ne: ObjectID.createFromHexString(hexId)}};
|
|
455
|
-
var docJSBin = bsonJS.serialize(docJS, false, true, true);
|
|
456
|
-
var docCBin = bsonC.serialize(docC, false, true, true);
|
|
457
|
-
assert.equal(docCBin.toString('base64'), docJSBin.toString('base64'));
|
|
458
|
-
test.done();
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* @ignore
|
|
463
|
-
*/
|
|
464
|
-
exports['Serialize big complex document'] = function(test) {
|
|
465
|
-
// Complex document serialization
|
|
466
|
-
var 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")}
|
|
467
|
-
var docJSBin = bsonJS.serialize(doc, false, true, true);
|
|
468
|
-
var docCBin = bsonC.serialize(doc, false, true, true);
|
|
469
|
-
assert.equal(docCBin.toString('base64'), docJSBin.toString('base64'));
|
|
470
|
-
test.done();
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* @ignore
|
|
475
|
-
*/
|
|
476
|
-
exports['Should error out due to 24 characters but not valid hexstring for ObjectID'] = function(test) {
|
|
477
|
-
try {
|
|
478
|
-
var oid = new ObjectID("tttttttttttttttttttttttt");
|
|
479
|
-
test.ok(false);
|
|
480
|
-
} catch(err) {}
|
|
481
|
-
|
|
482
|
-
test.done();
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* @ignore
|
|
488
|
-
*/
|
|
489
|
-
exports.noGlobalsLeaked = function(test) {
|
|
490
|
-
var leaks = gleak.detectNew();
|
|
491
|
-
test.equal(0, leaks.length, "global var leak detected: " + leaks.join(', '));
|
|
492
|
-
test.done();
|
|
493
|
-
}
|