1 // jsontests.cpp - Tests for json.{h,cpp} code and BSONObj::jsonString()
2 //
3 
4 
5 /**
6  *    Copyright (C) 2018-present MongoDB, Inc.
7  *
8  *    This program is free software: you can redistribute it and/or modify
9  *    it under the terms of the Server Side Public License, version 1,
10  *    as published by MongoDB, Inc.
11  *
12  *    This program is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    Server Side Public License for more details.
16  *
17  *    You should have received a copy of the Server Side Public License
18  *    along with this program. If not, see
19  *    <http://www.mongodb.com/licensing/server-side-public-license>.
20  *
21  *    As a special exception, the copyright holders give permission to link the
22  *    code of portions of this program with the OpenSSL library under certain
23  *    conditions as described in each individual source file and distribute
24  *    linked combinations including the program with the OpenSSL library. You
25  *    must comply with the Server Side Public License in all respects for
26  *    all of the code used other than as permitted herein. If you modify file(s)
27  *    with this exception, you may extend this exception to your version of the
28  *    file(s), but you are not obligated to do so. If you do not wish to do so,
29  *    delete this exception statement from your version. If you delete this
30  *    exception statement from all source files in the program, then also delete
31  *    it in the license file.
32  */
33 
34 #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
35 
36 #include "mongo/platform/basic.h"
37 
38 #include <limits>
39 
40 #include "mongo/db/jsobj.h"
41 #include "mongo/db/json.h"
42 #include "mongo/dbtests/dbtests.h"
43 #include "mongo/platform/decimal128.h"
44 #include "mongo/util/log.h"
45 
46 
47 namespace JsonTests {
48 
49 using std::cout;
50 using std::endl;
51 using std::numeric_limits;
52 using std::string;
53 using std::stringstream;
54 using std::vector;
55 
56 namespace JsonStringTests {
57 
58 class Empty {
59 public:
run()60     void run() {
61         ASSERT_EQUALS("{}", BSONObj().jsonString(Strict));
62     }
63 };
64 
65 class SingleStringMember {
66 public:
run()67     void run() {
68         ASSERT_EQUALS("{ \"a\" : \"b\" }",
69                       BSON("a"
70                            << "b")
71                           .jsonString(Strict));
72     }
73 };
74 
75 class EscapedCharacters {
76 public:
run()77     void run() {
78         BSONObjBuilder b;
79         b.append("a", "\" \\ / \b \f \n \r \t");
80         ASSERT_EQUALS("{ \"a\" : \"\\\" \\\\ / \\b \\f \\n \\r \\t\" }",
81                       b.done().jsonString(Strict));
82     }
83 };
84 
85 // per http://www.ietf.org/rfc/rfc4627.txt, control characters are
86 // (U+0000 through U+001F).  U+007F is not mentioned as a control character.
87 class AdditionalControlCharacters {
88 public:
run()89     void run() {
90         BSONObjBuilder b;
91         b.append("a", "\x1 \x1f");
92         ASSERT_EQUALS("{ \"a\" : \"\\u0001 \\u001f\" }", b.done().jsonString(Strict));
93     }
94 };
95 
96 class ExtendedAscii {
97 public:
run()98     void run() {
99         BSONObjBuilder b;
100         b.append("a", "\x80");
101         ASSERT_EQUALS("{ \"a\" : \"\x80\" }", b.done().jsonString(Strict));
102     }
103 };
104 
105 class EscapeFieldName {
106 public:
run()107     void run() {
108         BSONObjBuilder b;
109         b.append("\t", "b");
110         ASSERT_EQUALS("{ \"\\t\" : \"b\" }", b.done().jsonString(Strict));
111     }
112 };
113 
114 class SingleIntMember {
115 public:
run()116     void run() {
117         BSONObjBuilder b;
118         b.append("a", 1);
119         ASSERT_EQUALS("{ \"a\" : 1 }", b.done().jsonString(Strict));
120     }
121 };
122 
123 class SingleNumberMember {
124 public:
run()125     void run() {
126         BSONObjBuilder b;
127         b.append("a", 1.5);
128         ASSERT_EQUALS("{ \"a\" : 1.5 }", b.done().jsonString(Strict));
129     }
130 };
131 
132 class InvalidNumbers {
133 public:
run()134     void run() {
135         BSONObjBuilder c;
136         c.append("a", numeric_limits<double>::quiet_NaN());
137         string s = c.done().jsonString(Strict);
138         // Note there is no NaN in the JSON RFC but what would be the alternative?
139         ASSERT(str::contains(s, "NaN"));
140 
141         // commented out assertion as it doesn't throw anymore:
142         // ASSERT_THROWS( c.done().jsonString( Strict ), AssertionException );
143 
144         BSONObjBuilder d;
145         d.append("a", numeric_limits<double>::signaling_NaN());
146         // ASSERT_THROWS( d.done().jsonString( Strict ), AssertionException );
147         s = d.done().jsonString(Strict);
148         ASSERT(str::contains(s, "NaN"));
149     }
150 };
151 
152 class NumberPrecision {
153 public:
run()154     void run() {
155         BSONObjBuilder b;
156         b.append("a", 123456789);
157         ASSERT_EQUALS("{ \"a\" : 123456789 }", b.done().jsonString(Strict));
158     }
159 };
160 
161 class NegativeNumber {
162 public:
run()163     void run() {
164         BSONObjBuilder b;
165         b.append("a", -1);
166         ASSERT_EQUALS("{ \"a\" : -1 }", b.done().jsonString(Strict));
167     }
168 };
169 
170 class NumberLongStrictZero {
171 public:
run()172     void run() {
173         BSONObjBuilder b;
174         b.append("a", 0LL);
175         ASSERT_EQUALS("{ \"a\" : { \"$numberLong\" : \"0\" } }", b.done().jsonString(Strict));
176     }
177 };
178 
179 class NumberLongStrict {
180 public:
run()181     void run() {
182         BSONObjBuilder b;
183         b.append("a", 20000LL);
184         ASSERT_EQUALS("{ \"a\" : { \"$numberLong\" : \"20000\" } }", b.done().jsonString(Strict));
185     }
186 };
187 
188 // Test a NumberLong that is too big to fit into a 32 bit integer
189 class NumberLongStrictLarge {
190 public:
run()191     void run() {
192         BSONObjBuilder b;
193         b.append("a", 9223372036854775807LL);
194         ASSERT_EQUALS("{ \"a\" : { \"$numberLong\" : \"9223372036854775807\" } }",
195                       b.done().jsonString(Strict));
196     }
197 };
198 
199 class NumberLongStrictNegative {
200 public:
run()201     void run() {
202         BSONObjBuilder b;
203         b.append("a", -20000LL);
204         ASSERT_EQUALS("{ \"a\" : { \"$numberLong\" : \"-20000\" } }", b.done().jsonString(Strict));
205     }
206 };
207 
208 class NumberDecimal {
209 public:
run()210     void run() {
211         BSONObjBuilder b;
212         b.append("a", mongo::Decimal128("123456789.12345"));
213         ASSERT_EQUALS("{ \"a\" : NumberDecimal(\"123456789.12345\") }",
214                       b.done().jsonString(TenGen));
215     }
216 };
217 
218 class NumberDecimalStrict {
219 public:
run()220     void run() {
221         BSONObjBuilder b;
222         b.append("a", mongo::Decimal128("123456789.12345"));
223         ASSERT_EQUALS("{ \"a\" : { \"$numberDecimal\" : \"123456789.12345\" } }",
224                       b.done().jsonString(Strict));
225     }
226 };
227 
228 class NumberDoubleNaN {
229 public:
run()230     void run() {
231         BSONObjBuilder b;
232         b.append("a", std::numeric_limits<double>::quiet_NaN());
233         ASSERT_EQUALS("{ \"a\" : NaN }", b.done().jsonString(Strict));
234     }
235 };
236 
237 class NumberDoubleInfinity {
238 public:
run()239     void run() {
240         BSONObjBuilder b;
241         b.append("a", std::numeric_limits<double>::infinity());
242         ASSERT_EQUALS("{ \"a\" : Infinity }", b.done().jsonString(Strict));
243     }
244 };
245 
246 class NumberDoubleNegativeInfinity {
247 public:
run()248     void run() {
249         BSONObjBuilder b;
250         b.append("a", -std::numeric_limits<double>::infinity());
251         ASSERT_EQUALS("{ \"a\" : -Infinity }", b.done().jsonString(Strict));
252     }
253 };
254 
255 class SingleBoolMember {
256 public:
run()257     void run() {
258         BSONObjBuilder b;
259         b.appendBool("a", true);
260         ASSERT_EQUALS("{ \"a\" : true }", b.done().jsonString(Strict));
261 
262         BSONObjBuilder c;
263         c.appendBool("a", false);
264         ASSERT_EQUALS("{ \"a\" : false }", c.done().jsonString(Strict));
265     }
266 };
267 
268 class SingleNullMember {
269 public:
run()270     void run() {
271         BSONObjBuilder b;
272         b.appendNull("a");
273         ASSERT_EQUALS("{ \"a\" : null }", b.done().jsonString(Strict));
274     }
275 };
276 
277 class SingleUndefinedMember {
278 public:
run()279     void run() {
280         BSONObjBuilder b;
281         b.appendUndefined("a");
282         ASSERT_EQUALS("{ \"a\" : { \"$undefined\" : true } }", b.done().jsonString(Strict));
283         ASSERT_EQUALS("{ \"a\" : undefined }", b.done().jsonString(TenGen));
284     }
285 };
286 
287 class SingleObjectMember {
288 public:
run()289     void run() {
290         BSONObjBuilder b, c;
291         b.append("a", c.done());
292         ASSERT_EQUALS("{ \"a\" : {} }", b.done().jsonString(Strict));
293     }
294 };
295 
296 class TwoMembers {
297 public:
run()298     void run() {
299         BSONObjBuilder b;
300         b.append("a", 1);
301         b.append("b", 2);
302         ASSERT_EQUALS("{ \"a\" : 1, \"b\" : 2 }", b.done().jsonString(Strict));
303     }
304 };
305 
306 class EmptyArray {
307 public:
run()308     void run() {
309         vector<int> arr;
310         BSONObjBuilder b;
311         b.append("a", arr);
312         ASSERT_EQUALS("{ \"a\" : [] }", b.done().jsonString(Strict));
313     }
314 };
315 
316 class Array {
317 public:
run()318     void run() {
319         vector<int> arr;
320         arr.push_back(1);
321         arr.push_back(2);
322         BSONObjBuilder b;
323         b.append("a", arr);
324         ASSERT_EQUALS("{ \"a\" : [ 1, 2 ] }", b.done().jsonString(Strict));
325     }
326 };
327 
328 class DBRef {
329 public:
run()330     void run() {
331         char OIDbytes[OID::kOIDSize];
332         memset(&OIDbytes, 0xff, OID::kOIDSize);
333         OID oid = OID::from(OIDbytes);
334         BSONObjBuilder b;
335         b.appendDBRef("a", "namespace", oid);
336         BSONObj built = b.done();
337         ASSERT_EQUALS(
338             "{ \"a\" : { \"$ref\" : \"namespace\", \"$id\" : \"ffffffffffffffffffffffff\" } }",
339             built.jsonString(Strict));
340         ASSERT_EQUALS("{ \"a\" : Dbref( \"namespace\", \"ffffffffffffffffffffffff\" ) }",
341                       built.jsonString(TenGen));
342     }
343 };
344 
345 class DBRefZero {
346 public:
run()347     void run() {
348         char OIDbytes[OID::kOIDSize];
349         memset(&OIDbytes, 0, OID::kOIDSize);
350         OID oid = OID::from(OIDbytes);
351         BSONObjBuilder b;
352         b.appendDBRef("a", "namespace", oid);
353         ASSERT_EQUALS(
354             "{ \"a\" : { \"$ref\" : \"namespace\", \"$id\" : \"000000000000000000000000\" } }",
355             b.done().jsonString(Strict));
356     }
357 };
358 
359 class ObjectId {
360 public:
run()361     void run() {
362         char OIDbytes[OID::kOIDSize];
363         memset(&OIDbytes, 0xff, OID::kOIDSize);
364         OID oid = OID::from(OIDbytes);
365         BSONObjBuilder b;
366         b.appendOID("a", &oid);
367         BSONObj built = b.done();
368         ASSERT_EQUALS("{ \"a\" : { \"$oid\" : \"ffffffffffffffffffffffff\" } }",
369                       built.jsonString(Strict));
370         ASSERT_EQUALS("{ \"a\" : ObjectId( \"ffffffffffffffffffffffff\" ) }",
371                       built.jsonString(TenGen));
372     }
373 };
374 
375 class BinData {
376 public:
run()377     void run() {
378         char z[3];
379         z[0] = 'a';
380         z[1] = 'b';
381         z[2] = 'c';
382         BSONObjBuilder b;
383         b.appendBinData("a", 3, BinDataGeneral, z);
384 
385         string o = b.done().jsonString(Strict);
386 
387         ASSERT_EQUALS("{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"00\" } }", o);
388 
389         BSONObjBuilder c;
390         c.appendBinData("a", 2, BinDataGeneral, z);
391         ASSERT_EQUALS("{ \"a\" : { \"$binary\" : \"YWI=\", \"$type\" : \"00\" } }",
392                       c.done().jsonString(Strict));
393 
394         BSONObjBuilder d;
395         d.appendBinData("a", 1, BinDataGeneral, z);
396         ASSERT_EQUALS("{ \"a\" : { \"$binary\" : \"YQ==\", \"$type\" : \"00\" } }",
397                       d.done().jsonString(Strict));
398     }
399 };
400 
401 class Symbol {
402 public:
run()403     void run() {
404         BSONObjBuilder b;
405         b.appendSymbol("a", "b");
406         ASSERT_EQUALS("{ \"a\" : \"b\" }", b.done().jsonString(Strict));
407     }
408 };
409 
410 #ifdef _WIN32
411 char tzEnvString[] = "TZ=EST+5EDT";
412 #else
413 char tzEnvString[] = "TZ=America/New_York";
414 #endif
415 
416 class Date {
417 public:
Date()418     Date() {
419         char* _oldTimezonePtr = getenv("TZ");
420         _oldTimezone = std::string(_oldTimezonePtr ? _oldTimezonePtr : "");
421         if (-1 == putenv(tzEnvString)) {
422             FAIL(errnoWithDescription());
423         }
424         tzset();
425     }
~Date()426     ~Date() {
427         if (!_oldTimezone.empty()) {
428 #ifdef _WIN32
429             errno_t ret = _putenv_s("TZ", _oldTimezone.c_str());
430             if (0 != ret) {
431                 StringBuilder sb;
432                 sb << "Error setting TZ environment variable to:  " << _oldTimezone
433                    << ".  Error code:  " << ret;
434                 FAIL(sb.str());
435             }
436 #else
437             if (-1 == setenv("TZ", _oldTimezone.c_str(), 1)) {
438                 FAIL(errnoWithDescription());
439             }
440 #endif
441         } else {
442 #ifdef _WIN32
443             errno_t ret = _putenv_s("TZ", "");
444             if (0 != ret) {
445                 StringBuilder sb;
446                 sb << "Error unsetting TZ environment variable.  Error code:  " << ret;
447                 FAIL(sb.str());
448             }
449 #else
450             if (-1 == unsetenv("TZ")) {
451                 FAIL(errnoWithDescription());
452             }
453 #endif
454         }
455         tzset();
456     }
457 
run()458     void run() {
459         BSONObjBuilder b;
460         b.appendDate("a", Date_t());
461         BSONObj built = b.done();
462         ASSERT_EQUALS("{ \"a\" : { \"$date\" : \"1969-12-31T19:00:00.000-0500\" } }",
463                       built.jsonString(Strict));
464         ASSERT_EQUALS("{ \"a\" : Date( 0 ) }", built.jsonString(TenGen));
465 
466         // Test dates above our maximum formattable date.  See SERVER-13760.
467         BSONObjBuilder b2;
468         b2.appendDate("a", Date_t::fromMillisSinceEpoch(32535262800000LL));
469         BSONObj built2 = b2.done();
470         ASSERT_EQUALS("{ \"a\" : { \"$date\" : { \"$numberLong\" : \"32535262800000\" } } }",
471                       built2.jsonString(Strict));
472     }
473 
474 private:
475     std::string _oldTimezone;
476 };
477 
478 class DateNegative {
479 public:
run()480     void run() {
481         BSONObjBuilder b;
482         b.appendDate("a", Date_t::fromMillisSinceEpoch(-1));
483         BSONObj built = b.done();
484         ASSERT_EQUALS("{ \"a\" : { \"$date\" : { \"$numberLong\" : \"-1\" } } }",
485                       built.jsonString(Strict));
486         ASSERT_EQUALS("{ \"a\" : Date( -1 ) }", built.jsonString(TenGen));
487     }
488 };
489 
490 class Regex {
491 public:
run()492     void run() {
493         BSONObjBuilder b;
494         b.appendRegex("a", "abc", "i");
495         BSONObj built = b.done();
496         ASSERT_EQUALS("{ \"a\" : { \"$regex\" : \"abc\", \"$options\" : \"i\" } }",
497                       built.jsonString(Strict));
498         ASSERT_EQUALS("{ \"a\" : /abc/i }", built.jsonString(TenGen));
499     }
500 };
501 
502 class RegexEscape {
503 public:
run()504     void run() {
505         BSONObjBuilder b;
506         b.appendRegex("a", "/\"", "i");
507         BSONObj built = b.done();
508         ASSERT_EQUALS("{ \"a\" : { \"$regex\" : \"/\\\"\", \"$options\" : \"i\" } }",
509                       built.jsonString(Strict));
510         ASSERT_EQUALS("{ \"a\" : /\\/\\\"/i }", built.jsonString(TenGen));
511     }
512 };
513 
514 class RegexManyOptions {
515 public:
run()516     void run() {
517         BSONObjBuilder b;
518         b.appendRegex("a", "z", "abcgimx");
519         BSONObj built = b.done();
520         ASSERT_EQUALS("{ \"a\" : { \"$regex\" : \"z\", \"$options\" : \"abcgimx\" } }",
521                       built.jsonString(Strict));
522         ASSERT_EQUALS("{ \"a\" : /z/gim }", built.jsonString(TenGen));
523     }
524 };
525 
526 class CodeTests {
527 public:
run()528     void run() {
529         BSONObjBuilder b;
530         b.appendCode("x", "function(arg){ var string = \"\\n\"; return 1; }");
531         BSONObj o = b.obj();
532         ASSERT_EQUALS(
533             "{ \"x\" : \"function(arg){ var string = \\\"\\\\n\\\"; "
534             "return 1; }\" }",
535             o.jsonString());
536     }
537 };
538 
539 class CodeWScopeTests {
540 public:
run()541     void run() {
542         BSONObjBuilder b;
543         b.appendCodeWScope("x", "function(arg){ var string = \"\\n\"; return x; }", BSON("x" << 1));
544         BSONObj o = b.obj();
545         ASSERT_EQUALS(
546             "{ \"x\" : "
547             "{ \"$code\" : "
548             "\"function(arg){ var string = \\\"\\\\n\\\"; return x; }\" , "
549             "\"$scope\" : { \"x\" : 1 } } }",
550             o.jsonString());
551     }
552 };
553 
554 class TimestampTests {
555 public:
run()556     void run() {
557         BSONObjBuilder b;
558         b.append("x", Timestamp(4, 10));
559         BSONObj o = b.obj();
560         ASSERT_EQUALS("{ \"x\" : { \"$timestamp\" : { \"t\" : 4, \"i\" : 10 } } }",
561                       o.jsonString(Strict));
562         ASSERT_EQUALS("{ \"x\" : Timestamp( 4, 10 ) }", o.jsonString(TenGen));
563     }
564 };
565 
566 class NullString {
567 public:
run()568     void run() {
569         BSONObjBuilder b;
570         b.append("x", "a\0b", 4);
571         BSONObj o = b.obj();
572         ASSERT_EQUALS("{ \"x\" : \"a\\u0000b\" }", o.jsonString());
573     }
574 };
575 
576 class AllTypes {
577 public:
run()578     void run() {
579         OID oid;
580         oid.init();
581 
582         BSONObjBuilder b;
583         b.appendMinKey("a");
584         b.append("b", 5.5);
585         b.append("c", "abc");
586         b.append("e", BSON("x" << 1));
587         b.append("f", BSON_ARRAY(1 << 2 << 3));
588         b.appendBinData("g", sizeof(AllTypes), bdtCustom, (const void*)this);
589         b.appendUndefined("h");
590         b.append("i", oid);
591         b.appendBool("j", 1);
592         b.appendDate("k", Date_t::fromMillisSinceEpoch(123));
593         b.appendNull("l");
594         b.appendRegex("m", "a");
595         b.appendDBRef("n", "foo", oid);
596         b.appendCode("o", "function(){}");
597         b.appendSymbol("p", "foo");
598         b.appendCodeWScope("q", "function(){}", BSON("x" << 1));
599         b.append("r", (int)5);
600         b.appendTimestamp("s", 123123123123123LL);
601         b.append("t", 12321312312LL);
602         b.append("u", "123456789.12345");
603         b.appendMaxKey("v");
604 
605         BSONObj o = b.obj();
606         o.jsonString();
607         // cout << o.jsonString() << endl;
608     }
609 };
610 
611 }  // namespace JsonStringTests
612 
613 namespace FromJsonTests {
614 
615 class Base {
616 public:
~Base()617     virtual ~Base() {}
run()618     void run() {
619         ASSERT(fromjson(json()).valid(BSONVersion::kLatest));
620         assertEquals(bson(), fromjson(json()), "mode: json-to-bson");
621         assertEquals(bson(), fromjson(tojson(bson())), "mode: <default>");
622         assertEquals(bson(), fromjson(tojson(bson(), Strict)), "mode: strict");
623         assertEquals(bson(), fromjson(tojson(bson(), TenGen)), "mode: tengen");
624     }
625 
626 protected:
627     virtual BSONObj bson() const = 0;
628     virtual string json() const = 0;
629 
630 private:
assertEquals(const BSONObj & expected,const BSONObj & actual,const char * msg)631     void assertEquals(const BSONObj& expected, const BSONObj& actual, const char* msg) {
632         const bool bad = expected.woCompare(actual);
633         if (bad) {
634             ::mongo::log() << "want:" << expected.jsonString() << " size: " << expected.objsize()
635                            << endl;
636             ::mongo::log() << "got :" << actual.jsonString() << " size: " << actual.objsize()
637                            << endl;
638             ::mongo::log() << expected.hexDump() << endl;
639             ::mongo::log() << actual.hexDump() << endl;
640             ::mongo::log() << msg << endl;
641             ::mongo::log() << "orig json:" << this->json();
642         }
643         ASSERT(!bad);
644     }
645 };
646 
647 class Bad {
648 public:
~Bad()649     virtual ~Bad() {}
run()650     void run() {
651         ASSERT_THROWS(fromjson(json()), AssertionException);
652     }
653 
654 protected:
655     virtual string json() const = 0;
656 };
657 
658 class Empty : public Base {
bson() const659     virtual BSONObj bson() const {
660         BSONObjBuilder b;
661         return b.obj();
662     }
json() const663     virtual string json() const {
664         return "{}";
665     }
666 };
667 
668 class EmptyWithSpace : public Base {
bson() const669     virtual BSONObj bson() const {
670         BSONObjBuilder b;
671         return b.obj();
672     }
json() const673     virtual string json() const {
674         return "{ }";
675     }
676 };
677 
678 class SingleString : public Base {
bson() const679     virtual BSONObj bson() const {
680         BSONObjBuilder b;
681         b.append("a", "b");
682         return b.obj();
683     }
json() const684     virtual string json() const {
685         return "{ \"a\" : \"b\" }";
686     }
687 };
688 
689 class EmptyStrings : public Base {
bson() const690     virtual BSONObj bson() const {
691         BSONObjBuilder b;
692         b.append("", "");
693         return b.obj();
694     }
json() const695     virtual string json() const {
696         return "{ \"\" : \"\" }";
697     }
698 };
699 
700 class ReservedFieldName : public Bad {
json() const701     virtual string json() const {
702         return "{ \"$oid\" : \"b\" }";
703     }
704 };
705 
706 class ReservedFieldName1 : public Bad {
json() const707     virtual string json() const {
708         return "{ \"$ref\" : \"b\" }";
709     }
710 };
711 
712 class NumberFieldName : public Bad {
json() const713     virtual string json() const {
714         return "{ 0 : \"b\" }";
715     }
716 };
717 
718 class InvalidFieldName : public Bad {
json() const719     virtual string json() const {
720         return "{ test.test : \"b\" }";
721     }
722 };
723 
724 class QuotedNullName : public Bad {
json() const725     virtual string json() const {
726         return "{ \"nc\0nc\" : \"b\" }";
727     }
728 };
729 
730 class NoValue : public Bad {
json() const731     virtual string json() const {
732         return "{ a : }";
733     }
734 };
735 
736 class InvalidValue : public Bad {
json() const737     virtual string json() const {
738         return "{ a : a }";
739     }
740 };
741 
742 class OkDollarFieldName : public Base {
bson() const743     virtual BSONObj bson() const {
744         BSONObjBuilder b;
745         b.append("$where", 1);
746         return b.obj();
747     }
json() const748     virtual string json() const {
749         return "{ \"$where\" : 1 }";
750     }
751 };
752 
753 class SingleNumber : public Base {
bson() const754     virtual BSONObj bson() const {
755         BSONObjBuilder b;
756         b.append("a", 1);
757         return b.obj();
758     }
json() const759     virtual string json() const {
760         return "{ \"a\" : 1 }";
761     }
762 };
763 
764 class RealNumber : public Base {
bson() const765     virtual BSONObj bson() const {
766         BSONObjBuilder b;
767         b.append("a", strtod("0.7", 0));
768         return b.obj();
769     }
json() const770     virtual string json() const {
771         return "{ \"a\" : 0.7 }";
772     }
773 };
774 
775 class FancyNumber : public Base {
bson() const776     virtual BSONObj bson() const {
777         BSONObjBuilder b;
778         b.append("a", strtod("-4.4433e-2", 0));
779         return b.obj();
780     }
json() const781     virtual string json() const {
782         return "{ \"a\" : -4.4433e-2 }";
783     }
784 };
785 
786 class TwoElements : public Base {
bson() const787     virtual BSONObj bson() const {
788         BSONObjBuilder b;
789         b.append("a", 1);
790         b.append("b", "foo");
791         return b.obj();
792     }
json() const793     virtual string json() const {
794         return "{ \"a\" : 1, \"b\" : \"foo\" }";
795     }
796 };
797 
798 class Subobject : public Base {
bson() const799     virtual BSONObj bson() const {
800         BSONObjBuilder b;
801         b.append("a", 1);
802         BSONObjBuilder c;
803         c.append("z", b.done());
804         return c.obj();
805     }
json() const806     virtual string json() const {
807         return "{ \"z\" : { \"a\" : 1 } }";
808     }
809 };
810 
811 class DeeplyNestedObject : public Base {
buildJson(int depth) const812     virtual string buildJson(int depth) const {
813         if (depth == 0) {
814             return "{\"0\":true}";
815         } else {
816             std::stringstream ss;
817             ss << "{\"" << depth << "\":" << buildJson(depth - 1) << "}";
818             depth--;
819             return ss.str();
820         }
821     }
buildBson(int depth) const822     virtual BSONObj buildBson(int depth) const {
823         BSONObjBuilder builder;
824         if (depth == 0) {
825             builder.append("0", true);
826             return builder.obj();
827         } else {
828             std::stringstream ss;
829             ss << depth;
830             depth--;
831             builder.append(ss.str(), buildBson(depth));
832             return builder.obj();
833         }
834     }
bson() const835     virtual BSONObj bson() const {
836         return buildBson(35);
837     }
json() const838     virtual string json() const {
839         return buildJson(35);
840     }
841 };
842 
843 class ArrayEmpty : public Base {
bson() const844     virtual BSONObj bson() const {
845         vector<int> arr;
846         BSONObjBuilder b;
847         b.append("a", arr);
848         return b.obj();
849     }
json() const850     virtual string json() const {
851         return "{ \"a\" : [] }";
852     }
853 };
854 
855 class TopLevelArrayEmpty : public Base {
bson() const856     virtual BSONObj bson() const {
857         return BSONArray();
858     }
json() const859     virtual string json() const {
860         return "[]";
861     }
862 };
863 
864 class TopLevelArray : public Base {
bson() const865     virtual BSONObj bson() const {
866         BSONArrayBuilder builder;
867         builder.append(123);
868         builder.append("abc");
869         return builder.arr();
870     }
json() const871     virtual string json() const {
872         return "[ 123, \"abc\" ]";
873     }
874 };
875 
876 class Array : public Base {
bson() const877     virtual BSONObj bson() const {
878         vector<int> arr;
879         arr.push_back(1);
880         arr.push_back(2);
881         arr.push_back(3);
882         BSONObjBuilder b;
883         b.append("a", arr);
884         return b.obj();
885     }
json() const886     virtual string json() const {
887         return "{ \"a\" : [ 1, 2, 3 ] }";
888     }
889 };
890 
891 class True : public Base {
bson() const892     virtual BSONObj bson() const {
893         BSONObjBuilder b;
894         b.appendBool("a", true);
895         return b.obj();
896     }
json() const897     virtual string json() const {
898         return "{ \"a\" : true }";
899     }
900 };
901 
902 class False : public Base {
bson() const903     virtual BSONObj bson() const {
904         BSONObjBuilder b;
905         b.appendBool("a", false);
906         return b.obj();
907     }
json() const908     virtual string json() const {
909         return "{ \"a\" : false }";
910     }
911 };
912 
913 class Null : public Base {
bson() const914     virtual BSONObj bson() const {
915         BSONObjBuilder b;
916         b.appendNull("a");
917         return b.obj();
918     }
json() const919     virtual string json() const {
920         return "{ \"a\" : null }";
921     }
922 };
923 
924 class Undefined : public Base {
bson() const925     virtual BSONObj bson() const {
926         BSONObjBuilder b;
927         b.appendUndefined("a");
928         return b.obj();
929     }
json() const930     virtual string json() const {
931         return "{ \"a\" : undefined }";
932     }
933 };
934 
935 class UndefinedStrict : public Base {
bson() const936     virtual BSONObj bson() const {
937         BSONObjBuilder b;
938         b.appendUndefined("a");
939         return b.obj();
940     }
json() const941     virtual string json() const {
942         return "{ \"a\" : { \"$undefined\" : true } }";
943     }
944 };
945 
946 class UndefinedStrictBad : public Bad {
json() const947     virtual string json() const {
948         return "{ \"a\" : { \"$undefined\" : false } }";
949     }
950 };
951 
952 class EscapedCharacters : public Base {
bson() const953     virtual BSONObj bson() const {
954         BSONObjBuilder b;
955         b.append("a", "\" \\ / \b \f \n \r \t \v");
956         return b.obj();
957     }
json() const958     virtual string json() const {
959         return "{ \"a\" : \"\\\" \\\\ \\/ \\b \\f \\n \\r \\t \\v\" }";
960     }
961 };
962 
963 class NonEscapedCharacters : public Base {
bson() const964     virtual BSONObj bson() const {
965         BSONObjBuilder b;
966         b.append("a", "% { a z $ # '  ");
967         return b.obj();
968     }
json() const969     virtual string json() const {
970         return "{ \"a\" : \"\\% \\{ \\a \\z \\$ \\# \\' \\ \" }";
971     }
972 };
973 
974 class AllowedControlCharacter : public Base {
bson() const975     virtual BSONObj bson() const {
976         BSONObjBuilder b;
977         b.append("a", "\x7f");
978         return b.obj();
979     }
json() const980     virtual string json() const {
981         return "{ \"a\" : \"\x7f\" }";
982     }
983 };
984 
985 class InvalidControlCharacter : public Bad {
json() const986     virtual string json() const {
987         return "{ \"a\" : \"\x1f\" }";
988     }
989 };
990 
991 class NumbersInFieldName : public Base {
bson() const992     virtual BSONObj bson() const {
993         BSONObjBuilder b;
994         b.append("b1", "b");
995         return b.obj();
996     }
json() const997     virtual string json() const {
998         return "{ b1 : \"b\" }";
999     }
1000 };
1001 
1002 class EscapeFieldName : public Base {
bson() const1003     virtual BSONObj bson() const {
1004         BSONObjBuilder b;
1005         b.append("\n", "b");
1006         return b.obj();
1007     }
json() const1008     virtual string json() const {
1009         return "{ \"\\n\" : \"b\" }";
1010     }
1011 };
1012 
1013 class EscapedUnicodeToUtf8 : public Base {
bson() const1014     virtual BSONObj bson() const {
1015         BSONObjBuilder b;
1016         unsigned char u[7];
1017         u[0] = 0xe0 | 0x0a;
1018         u[1] = 0x80;
1019         u[2] = 0x80;
1020         u[3] = 0xe0 | 0x0a;
1021         u[4] = 0x80;
1022         u[5] = 0x80;
1023         u[6] = 0;
1024         b.append("a", (char*)u);
1025         BSONObj built = b.obj();
1026         ASSERT_EQUALS(string((char*)u), built.firstElement().valuestr());
1027         return built;
1028     }
json() const1029     virtual string json() const {
1030         return "{ \"a\" : \"\\ua000\\uA000\" }";
1031     }
1032 };
1033 
1034 class Utf8AllOnes : public Base {
bson() const1035     virtual BSONObj bson() const {
1036         BSONObjBuilder b;
1037         unsigned char u[8];
1038         u[0] = 0x01;
1039 
1040         u[1] = 0x7f;
1041 
1042         u[2] = 0xdf;
1043         u[3] = 0xbf;
1044 
1045         u[4] = 0xef;
1046         u[5] = 0xbf;
1047         u[6] = 0xbf;
1048 
1049         u[7] = 0;
1050 
1051         b.append("a", (char*)u);
1052         return b.obj();
1053     }
json() const1054     virtual string json() const {
1055         return "{ \"a\" : \"\\u0001\\u007f\\u07ff\\uffff\" }";
1056     }
1057 };
1058 
1059 class Utf8FirstByteOnes : public Base {
bson() const1060     virtual BSONObj bson() const {
1061         BSONObjBuilder b;
1062         unsigned char u[6];
1063         u[0] = 0xdc;
1064         u[1] = 0x80;
1065 
1066         u[2] = 0xef;
1067         u[3] = 0xbc;
1068         u[4] = 0x80;
1069 
1070         u[5] = 0;
1071 
1072         b.append("a", (char*)u);
1073         return b.obj();
1074     }
json() const1075     virtual string json() const {
1076         return "{ \"a\" : \"\\u0700\\uff00\" }";
1077     }
1078 };
1079 
1080 class Utf8Invalid : public Bad {
json() const1081     virtual string json() const {
1082         return "{ \"a\" : \"\\u0ZZZ\" }";
1083     }
1084 };
1085 
1086 class Utf8TooShort : public Bad {
json() const1087     virtual string json() const {
1088         return "{ \"a\" : \"\\u000\" }";
1089     }
1090 };
1091 
1092 class DBRefConstructor : public Base {
bson() const1093     virtual BSONObj bson() const {
1094         BSONObjBuilder b;
1095         BSONObjBuilder subBuilder(b.subobjStart("a"));
1096         subBuilder.append("$ref", "ns");
1097         subBuilder.append("$id", "000000000000000000000000");
1098         subBuilder.done();
1099         return b.obj();
1100     }
json() const1101     virtual string json() const {
1102         return "{ \"a\" : Dbref( \"ns\", \"000000000000000000000000\" ) }";
1103     }
1104 };
1105 
1106 // Added for consistency with the mongo shell
1107 class DBRefConstructorCapitals : public Base {
bson() const1108     virtual BSONObj bson() const {
1109         BSONObjBuilder b;
1110         BSONObjBuilder subBuilder(b.subobjStart("a"));
1111         subBuilder.append("$ref", "ns");
1112         subBuilder.append("$id", "000000000000000000000000");
1113         subBuilder.done();
1114         return b.obj();
1115     }
json() const1116     virtual string json() const {
1117         return "{ \"a\" : DBRef( \"ns\", \"000000000000000000000000\" ) }";
1118     }
1119 };
1120 
1121 class DBRefConstructorDbName : public Base {
bson() const1122     virtual BSONObj bson() const {
1123         BSONObjBuilder b;
1124         BSONObjBuilder subBuilder(b.subobjStart("a"));
1125         subBuilder.append("$ref", "ns");
1126         subBuilder.append("$id", "000000000000000000000000");
1127         subBuilder.append("$db", "dbname");
1128         subBuilder.done();
1129         return b.obj();
1130     }
json() const1131     virtual string json() const {
1132         return "{ \"a\" : Dbref( \"ns\", \"000000000000000000000000\", \"dbname\" ) }";
1133     }
1134 };
1135 
1136 class DBRefConstructorNumber : public Base {
bson() const1137     virtual BSONObj bson() const {
1138         BSONObjBuilder b;
1139         BSONObjBuilder subBuilder(b.subobjStart("a"));
1140         subBuilder.append("$ref", "ns");
1141         subBuilder.append("$id", 1);
1142         subBuilder.done();
1143         return b.obj();
1144     }
json() const1145     virtual string json() const {
1146         return "{ \"a\" : Dbref( \"ns\", 1 ) }";
1147     }
1148 };
1149 
1150 class DBRefConstructorObject : public Base {
bson() const1151     virtual BSONObj bson() const {
1152         BSONObjBuilder b;
1153         BSONObjBuilder subBuilder(b.subobjStart("a"));
1154         subBuilder.append("$ref", "ns");
1155         BSONObjBuilder idSubBuilder(subBuilder.subobjStart("$id"));
1156         idSubBuilder.append("b", true);
1157         idSubBuilder.done();
1158         subBuilder.done();
1159         return b.obj();
1160     }
json() const1161     virtual string json() const {
1162         return "{ \"a\" : Dbref( \"ns\", { \"b\" : true } ) }";
1163     }
1164 };
1165 
1166 class DBRefNumberId : public Base {
bson() const1167     virtual BSONObj bson() const {
1168         BSONObjBuilder b;
1169         BSONObjBuilder subBuilder(b.subobjStart("a"));
1170         subBuilder.append("$ref", "ns");
1171         subBuilder.append("$id", 1);
1172         subBuilder.done();
1173         return b.obj();
1174     }
json() const1175     virtual string json() const {
1176         return "{ \"a\" : { \"$ref\" : \"ns\", \"$id\" : 1 } }";
1177     }
1178 };
1179 
1180 class DBRefObjectAsId : public Base {
bson() const1181     virtual BSONObj bson() const {
1182         BSONObjBuilder b;
1183         BSONObjBuilder subBuilder(b.subobjStart("a"));
1184         subBuilder.append("$ref", "ns");
1185         BSONObjBuilder idSubBuilder(subBuilder.subobjStart("$id"));
1186         idSubBuilder.append("b", true);
1187         idSubBuilder.done();
1188         subBuilder.done();
1189         return b.obj();
1190     }
json() const1191     virtual string json() const {
1192         return "{ \"a\" : { \"$ref\" : \"ns\", \"$id\" : { \"b\" : true } } }";
1193     }
1194 };
1195 
1196 class DBRefStringId : public Base {
bson() const1197     virtual BSONObj bson() const {
1198         BSONObjBuilder b;
1199         BSONObjBuilder subBuilder(b.subobjStart("a"));
1200         subBuilder.append("$ref", "ns");
1201         subBuilder.append("$id", "000000000000000000000000");
1202         subBuilder.done();
1203         return b.obj();
1204     }
json() const1205     virtual string json() const {
1206         return "{ \"a\" : { \"$ref\" : \"ns\", \"$id\" : \"000000000000000000000000\" } }";
1207     }
1208 };
1209 
1210 class DBRefObjectIDObject : public Base {
bson() const1211     virtual BSONObj bson() const {
1212         BSONObjBuilder b;
1213         OID o;
1214         BSONObjBuilder subBuilder(b.subobjStart("a"));
1215         subBuilder.append("$ref", "ns");
1216         subBuilder.append("$id", o);
1217         subBuilder.done();
1218         return b.obj();
1219     }
json() const1220     virtual string json() const {
1221         return "{ \"a\" : { \"$ref\" : \"ns\", \"$id\" : { \"$oid\" : \"000000000000000000000000\" "
1222                "} } }";
1223     }
1224 };
1225 
1226 class DBRefObjectIDConstructor : public Base {
bson() const1227     virtual BSONObj bson() const {
1228         BSONObjBuilder b;
1229         OID o;
1230         BSONObjBuilder subBuilder(b.subobjStart("a"));
1231         subBuilder.append("$ref", "ns");
1232         subBuilder.append("$id", o);
1233         subBuilder.done();
1234         return b.obj();
1235     }
json() const1236     virtual string json() const {
1237         return "{ \"a\" : { \"$ref\" : \"ns\", \"$id\" : ObjectId( \"000000000000000000000000\" ) "
1238                "} }";
1239     }
1240 };
1241 
1242 class DBRefDbName : public Base {
bson() const1243     virtual BSONObj bson() const {
1244         BSONObjBuilder b;
1245         BSONObjBuilder subBuilder(b.subobjStart("a"));
1246         subBuilder.append("$ref", "ns");
1247         subBuilder.append("$id", "000000000000000000000000");
1248         subBuilder.append("$db", "dbname");
1249         subBuilder.done();
1250         return b.obj();
1251     }
json() const1252     virtual string json() const {
1253         return "{ \"a\" : { \"$ref\" : \"ns\", \"$id\" : \"000000000000000000000000\""
1254                ", \"$db\" : \"dbname\" } }";
1255     }
1256 };
1257 
1258 class Oid : public Base {
bson() const1259     virtual BSONObj bson() const {
1260         BSONObjBuilder b;
1261         b.appendOID("_id");
1262         return b.obj();
1263     }
json() const1264     virtual string json() const {
1265         return "{ \"_id\" : { \"$oid\" : \"000000000000000000000000\" } }";
1266     }
1267 };
1268 
1269 class Oid2 : public Base {
bson() const1270     virtual BSONObj bson() const {
1271         BSONObjBuilder b;
1272         char OIDbytes[OID::kOIDSize];
1273         memset(&OIDbytes, 0x0f, OID::kOIDSize);
1274         OID o = OID::from(OIDbytes);
1275         b.appendOID("_id", &o);
1276         return b.obj();
1277     }
json() const1278     virtual string json() const {
1279         return "{ \"_id\" : ObjectId( \"0f0f0f0f0f0f0f0f0f0f0f0f\" ) }";
1280     }
1281 };
1282 
1283 class OidTooLong : public Bad {
json() const1284     virtual string json() const {
1285         return "{ \"_id\" : { \"$oid\" : \"0000000000000000000000000\" } }";
1286     }
1287 };
1288 
1289 class Oid2TooLong : public Bad {
json() const1290     virtual string json() const {
1291         return "{ \"_id\" : ObjectId( \"0f0f0f0f0f0f0f0f0f0f0f0f0\" ) }";
1292     }
1293 };
1294 
1295 class OidTooShort : public Bad {
json() const1296     virtual string json() const {
1297         return "{ \"_id\" : { \"$oid\" : \"00000000000000000000000\" } }";
1298     }
1299 };
1300 
1301 class Oid2TooShort : public Bad {
json() const1302     virtual string json() const {
1303         return "{ \"_id\" : ObjectId( \"0f0f0f0f0f0f0f0f0f0f0f0\" ) }";
1304     }
1305 };
1306 
1307 class OidInvalidChar : public Bad {
json() const1308     virtual string json() const {
1309         return "{ \"_id\" : { \"$oid\" : \"00000000000Z000000000000\" } }";
1310     }
1311 };
1312 
1313 class Oid2InvalidChar : public Bad {
json() const1314     virtual string json() const {
1315         return "{ \"_id\" : ObjectId( \"0f0f0f0f0f0fZf0f0f0f0f0f\" ) }";
1316     }
1317 };
1318 
1319 class StringId : public Base {
bson() const1320     virtual BSONObj bson() const {
1321         BSONObjBuilder b;
1322         b.append("_id", "000000000000000000000000");
1323         return b.obj();
1324     }
json() const1325     virtual string json() const {
1326         return "{ \"_id\" : \"000000000000000000000000\" }";
1327     }
1328 };
1329 
1330 class BinData : public Base {
bson() const1331     virtual BSONObj bson() const {
1332         char z[3];
1333         z[0] = 'a';
1334         z[1] = 'b';
1335         z[2] = 'c';
1336         BSONObjBuilder b;
1337         b.appendBinData("a", 3, BinDataGeneral, z);
1338         return b.obj();
1339     }
json() const1340     virtual string json() const {
1341         return "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"00\" } }";
1342     }
1343 };
1344 
1345 class BinData1 : public Base {
bson() const1346     virtual BSONObj bson() const {
1347         char z[3];
1348         z[0] = 'a';
1349         z[1] = 'b';
1350         z[2] = 'c';
1351         BSONObjBuilder b;
1352         b.appendBinData("a", 3, Function, z);
1353         return b.obj();
1354     }
json() const1355     virtual string json() const {
1356         return "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"01\" } }";
1357     }
1358 };
1359 
1360 class BinData2 : public Base {
bson() const1361     virtual BSONObj bson() const {
1362         char z[3];
1363         z[0] = 'a';
1364         z[1] = 'b';
1365         z[2] = 'c';
1366         BSONObjBuilder b;
1367         b.appendBinData("a", 3, ByteArrayDeprecated, z);
1368         return b.obj();
1369     }
json() const1370     virtual string json() const {
1371         return "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"02\" } }";
1372     }
1373 };
1374 
1375 class BinData3 : public Base {
bson() const1376     virtual BSONObj bson() const {
1377         char z[3];
1378         z[0] = 'a';
1379         z[1] = 'b';
1380         z[2] = 'c';
1381         BSONObjBuilder b;
1382         b.appendBinData("a", 3, bdtUUID, z);
1383         return b.obj();
1384     }
json() const1385     virtual string json() const {
1386         return "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"03\" } }";
1387     }
1388 };
1389 
1390 class BinData4 : public Base {
bson() const1391     virtual BSONObj bson() const {
1392         char z[3];
1393         z[0] = 'a';
1394         z[1] = 'b';
1395         z[2] = 'c';
1396         BSONObjBuilder b;
1397         b.appendBinData("a", 3, newUUID, z);
1398         return b.obj();
1399     }
json() const1400     virtual string json() const {
1401         return "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"04\" } }";
1402     }
1403 };
1404 
1405 class BinData5 : public Base {
bson() const1406     virtual BSONObj bson() const {
1407         char z[3];
1408         z[0] = 'a';
1409         z[1] = 'b';
1410         z[2] = 'c';
1411         BSONObjBuilder b;
1412         b.appendBinData("a", 3, MD5Type, z);
1413         return b.obj();
1414     }
json() const1415     virtual string json() const {
1416         return "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"05\" } }";
1417     }
1418 };
1419 
1420 class BinData80 : public Base {
bson() const1421     virtual BSONObj bson() const {
1422         char z[3];
1423         z[0] = 'a';
1424         z[1] = 'b';
1425         z[2] = 'c';
1426         BSONObjBuilder b;
1427         b.appendBinData("a", 3, bdtCustom, z);
1428         return b.obj();
1429     }
json() const1430     virtual string json() const {
1431         return "{ \"a\" : { \"$binary\" : \"YWJj\", \"$type\" : \"80\" } }";
1432     }
1433 };
1434 
1435 class BinDataPaddedSingle : public Base {
bson() const1436     virtual BSONObj bson() const {
1437         char z[2];
1438         z[0] = 'a';
1439         z[1] = 'b';
1440         BSONObjBuilder b;
1441         b.appendBinData("a", 2, BinDataGeneral, z);
1442         return b.obj();
1443     }
json() const1444     virtual string json() const {
1445         return "{ \"a\" : { \"$binary\" : \"YWI=\", \"$type\" : \"00\" } }";
1446     }
1447 };
1448 
1449 class BinDataPaddedDouble : public Base {
bson() const1450     virtual BSONObj bson() const {
1451         char z[1];
1452         z[0] = 'a';
1453         BSONObjBuilder b;
1454         b.appendBinData("a", 1, BinDataGeneral, z);
1455         return b.obj();
1456     }
json() const1457     virtual string json() const {
1458         return "{ \"a\" : { \"$binary\" : \"YQ==\", \"$type\" : \"00\" } }";
1459     }
1460 };
1461 
1462 class BinDataAllChars : public Base {
bson() const1463     virtual BSONObj bson() const {
1464         unsigned char z[] = {0x00, 0x10, 0x83, 0x10, 0x51, 0x87, 0x20, 0x92, 0x8B, 0x30,
1465                              0xD3, 0x8F, 0x41, 0x14, 0x93, 0x51, 0x55, 0x97, 0x61, 0x96,
1466                              0x9B, 0x71, 0xD7, 0x9F, 0x82, 0x18, 0xA3, 0x92, 0x59, 0xA7,
1467                              0xA2, 0x9A, 0xAB, 0xB2, 0xDB, 0xAF, 0xC3, 0x1C, 0xB3, 0xD3,
1468                              0x5D, 0xB7, 0xE3, 0x9E, 0xBB, 0xF3, 0xDF, 0xBF};
1469         BSONObjBuilder b;
1470         b.appendBinData("a", 48, BinDataGeneral, z);
1471         return b.obj();
1472     }
json() const1473     virtual string json() const {
1474         return "{ \"a\" : { \"$binary\" : "
1475                "\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\", \"$type\" : "
1476                "\"00\" } }";
1477     }
1478 };
1479 
1480 class BinDataBadLength : public Bad {
json() const1481     virtual string json() const {
1482         return "{ \"a\" : { \"$binary\" : \"YQ=\", \"$type\" : \"00\" } }";
1483     }
1484 };
1485 
1486 class BinDataBadLength1 : public Bad {
json() const1487     virtual string json() const {
1488         return "{ \"a\" : { \"$binary\" : \"YQ\", \"$type\" : \"00\" } }";
1489     }
1490 };
1491 
1492 class BinDataBadLength2 : public Bad {
json() const1493     virtual string json() const {
1494         return "{ \"a\" : { \"$binary\" : \"YQX==\", \"$type\" : \"00\" } }";
1495     }
1496 };
1497 
1498 class BinDataBadLength3 : public Bad {
json() const1499     virtual string json() const {
1500         return "{ \"a\" : { \"$binary\" : \"YQX\", \"$type\" : \"00\" } }";
1501     }
1502 };
1503 
1504 class BinDataBadLength4 : public Bad {
json() const1505     virtual string json() const {
1506         return "{ \"a\" : { \"$binary\" : \"YQXZ=\", \"$type\" : \"00\" } }";
1507     }
1508 };
1509 
1510 class BinDataBadLength5 : public Bad {
json() const1511     virtual string json() const {
1512         return "{ \"a\" : { \"$binary\" : \"YQXZ==\", \"$type\" : \"00\" } }";
1513     }
1514 };
1515 
1516 class BinDataBadChars : public Bad {
json() const1517     virtual string json() const {
1518         return "{ \"a\" : { \"$binary\" : \"a...\", \"$type\" : \"00\" } }";
1519     }
1520 };
1521 
1522 class BinDataTypeTooShort : public Bad {
json() const1523     virtual string json() const {
1524         return "{ \"a\" : { \"$binary\" : \"AAAA\", \"$type\" : \"0\" } }";
1525     }
1526 };
1527 
1528 class BinDataTypeTooLong : public Bad {
json() const1529     virtual string json() const {
1530         return "{ \"a\" : { \"$binary\" : \"AAAA\", \"$type\" : \"000\" } }";
1531     }
1532 };
1533 
1534 class BinDataTypeBadChars : public Bad {
json() const1535     virtual string json() const {
1536         return "{ \"a\" : { \"$binary\" : \"AAAA\", \"$type\" : \"ZZ\" } }";
1537     }
1538 };
1539 
1540 class BinDataEmptyType : public Bad {
json() const1541     virtual string json() const {
1542         return "{ \"a\" : { \"$binary\" : \"AAAA\", \"$type\" : \"\" } }";
1543     }
1544 };
1545 
1546 class BinDataNoType : public Bad {
json() const1547     virtual string json() const {
1548         return "{ \"a\" : { \"$binary\" : \"AAAA\" } }";
1549     }
1550 };
1551 
1552 class BinDataInvalidType : public Bad {
json() const1553     virtual string json() const {
1554         return "{ \"a\" : { \"$binary\" : \"AAAA\", \"$type\" : \"100\" } }";
1555     }
1556 };
1557 
1558 class Date : public Base {
bson() const1559     virtual BSONObj bson() const {
1560         BSONObjBuilder b;
1561         b.appendDate("a", Date_t());
1562         return b.obj();
1563     }
json() const1564     virtual string json() const {
1565         return "{ \"a\" : { \"$date\" : 0 } }";
1566     }
1567 };
1568 
1569 class DateNonzero : public Base {
bson() const1570     virtual BSONObj bson() const {
1571         BSONObjBuilder b;
1572         b.appendDate("a", Date_t::fromMillisSinceEpoch(1000000000));
1573         return b.obj();
1574     }
json() const1575     virtual string json() const {
1576         return "{ \"a\" : { \"$date\" : 1000000000 } }";
1577     }
1578 };
1579 
1580 class DateStrictTooLong : public Bad {
json() const1581     virtual string json() const {
1582         stringstream ss;
1583         ss << "{ \"a\" : { \"$date\" : " << ~(0ULL) << "1"
1584            << " } }";
1585         return ss.str();
1586     }
1587 };
1588 
1589 class DateTooLong : public Bad {
json() const1590     virtual string json() const {
1591         stringstream ss;
1592         ss << "{ \"a\" : Date( " << ~(0ULL) << "1"
1593            << " ) }";
1594         return ss.str();
1595     }
1596 };
1597 
1598 class DateIsString : public Bad {
json() const1599     virtual string json() const {
1600         stringstream ss;
1601         ss << "{ \"a\" : { \"$date\" : \"100\" } }";
1602         return ss.str();
1603     }
1604 };
1605 
1606 class DateIsString1 : public Bad {
json() const1607     virtual string json() const {
1608         stringstream ss;
1609         ss << "{ \"a\" : Date(\"a\") }";
1610         return ss.str();
1611     }
1612 };
1613 
1614 class DateIsString2 : public Bad {
json() const1615     virtual string json() const {
1616         stringstream ss;
1617         ss << "{ \"a\" : new Date(\"a\") }";
1618         return ss.str();
1619     }
1620 };
1621 
1622 class DateIsFloat : public Bad {
json() const1623     virtual string json() const {
1624         stringstream ss;
1625         ss << "{ \"a\" : { \"$date\" : 1.1 } }";
1626         return ss.str();
1627     }
1628 };
1629 
1630 class DateIsFloat1 : public Bad {
json() const1631     virtual string json() const {
1632         stringstream ss;
1633         ss << "{ \"a\" : Date(1.1) }";
1634         return ss.str();
1635     }
1636 };
1637 
1638 class DateIsFloat2 : public Bad {
json() const1639     virtual string json() const {
1640         stringstream ss;
1641         ss << "{ \"a\" : new Date(1.1) }";
1642         return ss.str();
1643     }
1644 };
1645 
1646 class DateIsExponent : public Bad {
json() const1647     virtual string json() const {
1648         stringstream ss;
1649         ss << "{ \"a\" : { \"$date\" : 10e3 } }";
1650         return ss.str();
1651     }
1652 };
1653 
1654 class DateIsExponent1 : public Bad {
json() const1655     virtual string json() const {
1656         stringstream ss;
1657         ss << "{ \"a\" : Date(10e3) }";
1658         return ss.str();
1659     }
1660 };
1661 
1662 class DateIsExponent2 : public Bad {
json() const1663     virtual string json() const {
1664         stringstream ss;
1665         ss << "{ \"a\" : new Date(10e3) }";
1666         return ss.str();
1667     }
1668 };
1669 /* Need to handle this because jsonString outputs the value of Date_t as unsigned.
1670  * See SERVER-8330 and SERVER-8573 */
1671 class DateStrictMaxUnsigned : public Base {
bson() const1672     virtual BSONObj bson() const {
1673         BSONObjBuilder b;
1674         b.appendDate("a", Date_t::fromMillisSinceEpoch(-1));
1675         return b.obj();
1676     }
json() const1677     virtual string json() const {
1678         stringstream ss;
1679         ss << "{ \"a\" : { \"$date\" : " << std::numeric_limits<unsigned long long>::max()
1680            << " } }";
1681         return ss.str();
1682     }
1683 };
1684 
1685 class DateMaxUnsigned : public Base {
bson() const1686     virtual BSONObj bson() const {
1687         BSONObjBuilder b;
1688         b.appendDate("a", Date_t::fromMillisSinceEpoch(-1));
1689         return b.obj();
1690     }
json() const1691     virtual string json() const {
1692         stringstream ss;
1693         ss << "{ \"a\" : Date( " << std::numeric_limits<unsigned long long>::max() << " ) }";
1694         return ss.str();
1695     }
1696 };
1697 
1698 class DateStrictNegative : public Base {
bson() const1699     virtual BSONObj bson() const {
1700         BSONObjBuilder b;
1701         b.appendDate("a", Date_t::fromMillisSinceEpoch(-1));
1702         return b.obj();
1703     }
json() const1704     virtual string json() const {
1705         return "{ \"a\" : { \"$date\" : -1 } }";
1706     }
1707 };
1708 
1709 class DateNegative : public Base {
bson() const1710     virtual BSONObj bson() const {
1711         BSONObjBuilder b;
1712         b.appendDate("a", Date_t::fromMillisSinceEpoch(-1));
1713         return b.obj();
1714     }
json() const1715     virtual string json() const {
1716         return "{ \"a\" : Date( -1 ) }";
1717     }
1718 };
1719 
1720 class NumberLongTest : public Base {
bson() const1721     virtual BSONObj bson() const {
1722         BSONObjBuilder b;
1723         b.append("a", 20000LL);
1724         return b.obj();
1725     }
json() const1726     virtual string json() const {
1727         return "{ \"a\" : NumberLong( 20000 ) }";
1728     }
1729 };
1730 
1731 class NumberLongMin : public Base {
bson() const1732     virtual BSONObj bson() const {
1733         BSONObjBuilder b;
1734         b.append("a", std::numeric_limits<long long>::min());
1735         return b.obj();
1736     }
json() const1737     virtual string json() const {
1738         std::stringstream ss;
1739         ss << "{'a': NumberLong(";
1740         ss << std::numeric_limits<long long>::min();
1741         ss << ") }";
1742         return ss.str();
1743     }
1744 };
1745 
1746 class NumberIntTest : public Base {
bson() const1747     virtual BSONObj bson() const {
1748         BSONObjBuilder b;
1749         b.appendNumber("a", 20000);
1750         return b.obj();
1751     }
json() const1752     virtual string json() const {
1753         return "{ \"a\" : NumberInt( 20000 ) }";
1754     }
1755 };
1756 
1757 class NumberLongNeg : public Base {
bson() const1758     virtual BSONObj bson() const {
1759         BSONObjBuilder b;
1760         b.append("a", -20000LL);
1761         return b.obj();
1762     }
json() const1763     virtual string json() const {
1764         return "{ \"a\" : NumberLong( -20000 ) }";
1765     }
1766 };
1767 
1768 class NumberIntNeg : public Base {
bson() const1769     virtual BSONObj bson() const {
1770         BSONObjBuilder b;
1771         b.appendNumber("a", -20000);
1772         return b.obj();
1773     }
json() const1774     virtual string json() const {
1775         return "{ \"a\" : NumberInt( -20000 ) }";
1776     }
1777 };
1778 
1779 class NumberLongBad : public Bad {
json() const1780     virtual string json() const {
1781         return "{ \"a\" : NumberLong( 'sdf' ) }";
1782     }
1783 };
1784 
1785 class NumberIntBad : public Bad {
json() const1786     virtual string json() const {
1787         return "{ \"a\" : NumberInt( 'sdf' ) }";
1788     }
1789 };
1790 
1791 class JSTimestamp : public Base {
bson() const1792     virtual BSONObj bson() const {
1793         BSONObjBuilder b;
1794         b.append("a", Timestamp(20, 5));
1795         return b.obj();
1796     }
json() const1797     virtual string json() const {
1798         return "{ \"a\" : Timestamp( 20, 5 ) }";
1799     }
1800 };
1801 
1802 class TimestampNoIncrement : public Bad {
json() const1803     virtual string json() const {
1804         return "{ \"a\" : Timestamp( 20 ) }";
1805     }
1806 };
1807 
1808 class TimestampZero : public Base {
bson() const1809     virtual BSONObj bson() const {
1810         BSONObjBuilder b;
1811         b.append("a", Timestamp());
1812         return b.obj();
1813     }
json() const1814     virtual string json() const {
1815         return "{ \"a\" : Timestamp( 0, 0 ) }";
1816     }
1817 };
1818 
1819 class TimestampNoArgs : public Bad {
json() const1820     virtual string json() const {
1821         return "{ \"a\" : Timestamp() }";
1822     }
1823 };
1824 
1825 class TimestampFloatSeconds : public Bad {
json() const1826     virtual string json() const {
1827         return "{ \"a\" : Timestamp( 20.0, 1 ) }";
1828     }
1829 };
1830 
1831 class TimestampFloatIncrement : public Bad {
json() const1832     virtual string json() const {
1833         return "{ \"a\" : Timestamp( 20, 1.0 ) }";
1834     }
1835 };
1836 
1837 class TimestampNegativeSeconds : public Bad {
json() const1838     virtual string json() const {
1839         return "{ \"a\" : Timestamp( -20, 5 ) }";
1840     }
1841 };
1842 
1843 class TimestampNegativeIncrement : public Bad {
json() const1844     virtual string json() const {
1845         return "{ \"a\" : Timestamp( 20, -5 ) }";
1846     }
1847 };
1848 
1849 class TimestampInvalidSeconds : public Bad {
json() const1850     virtual string json() const {
1851         return "{ \"a\" : Timestamp( q, 5 ) }";
1852     }
1853 };
1854 
1855 class TimestampObject : public Base {
bson() const1856     virtual BSONObj bson() const {
1857         BSONObjBuilder b;
1858         b.append("a", Timestamp(20, 5));
1859         return b.obj();
1860     }
json() const1861     virtual string json() const {
1862         return "{ \"a\" : { \"$timestamp\" : { \"t\" : 20 , \"i\" : 5 } } }";
1863     }
1864 };
1865 
1866 class TimestampObjectInvalidFieldName : public Bad {
json() const1867     virtual string json() const {
1868         return "{ \"a\" : { \"$timestamp\" : { \"time\" : 20 , \"increment\" : 5 } } }";
1869     }
1870 };
1871 
1872 class TimestampObjectNoIncrement : public Bad {
json() const1873     virtual string json() const {
1874         return "{ \"a\" : { \"$timestamp\" : { \"t\" : 20 } } }";
1875     }
1876 };
1877 
1878 class TimestampObjectNegativeSeconds : public Bad {
json() const1879     virtual string json() const {
1880         return "{ \"a\" : { \"$timestamp\" : { \"t\" : -20 , \"i\" : 5 } } }";
1881     }
1882 };
1883 
1884 class TimestampObjectNegativeIncrement : public Bad {
json() const1885     virtual string json() const {
1886         return "{ \"a\" : { \"$timestamp\" : { \"t\" : 20 , \"i\" : -5 } } }";
1887     }
1888 };
1889 
1890 class TimestampObjectInvalidSeconds : public Bad {
json() const1891     virtual string json() const {
1892         return "{ \"a\" : { \"$timestamp\" : { \"t\" : q , \"i\" : 5 } } }";
1893     }
1894 };
1895 
1896 class TimestampObjectZero : public Base {
bson() const1897     virtual BSONObj bson() const {
1898         BSONObjBuilder b;
1899         b.append("a", Timestamp());
1900         return b.obj();
1901     }
json() const1902     virtual string json() const {
1903         return "{ \"a\" : { \"$timestamp\" : { \"t\" : 0, \"i\" : 0} } }";
1904     }
1905 };
1906 
1907 class TimestampObjectNoArgs : public Bad {
json() const1908     virtual string json() const {
1909         return "{ \"a\" : { \"$timestamp\" : { } } }";
1910     }
1911 };
1912 
1913 class TimestampObjectFloatSeconds : public Bad {
json() const1914     virtual string json() const {
1915         return "{ \"a\" : { \"$timestamp\" : { \"t\" : 1.0, \"i\" : 0} } }";
1916     }
1917 };
1918 
1919 class TimestampObjectFloatIncrement : public Bad {
json() const1920     virtual string json() const {
1921         return "{ \"a\" : { \"$timestamp\" : { \"t\" : 20, \"i\" : 1.0} } }";
1922     }
1923 };
1924 
1925 class Regex : public Base {
bson() const1926     virtual BSONObj bson() const {
1927         BSONObjBuilder b;
1928         b.appendRegex("a", "b", "i");
1929         return b.obj();
1930     }
json() const1931     virtual string json() const {
1932         return "{ \"a\" : { \"$regex\" : \"b\", \"$options\" : \"i\" } }";
1933     }
1934 };
1935 
1936 class RegexNoOptionField : public Base {
bson() const1937     virtual BSONObj bson() const {
1938         BSONObjBuilder b;
1939         b.appendRegex("a", "b", "");
1940         return b.obj();
1941     }
json() const1942     virtual string json() const {
1943         return "{ \"a\" : { \"$regex\" : \"b\" } }";
1944     }
1945 };
1946 
1947 class RegexEscape : public Base {
bson() const1948     virtual BSONObj bson() const {
1949         BSONObjBuilder b;
1950         b.appendRegex("a", "\t", "i");
1951         return b.obj();
1952     }
json() const1953     virtual string json() const {
1954         return "{ \"a\" : { \"$regex\" : \"\\t\", \"$options\" : \"i\" } }";
1955     }
1956 };
1957 
1958 class RegexWithQuotes : public Base {
bson() const1959     virtual BSONObj bson() const {
1960         BSONObjBuilder b;
1961         b.appendRegex("a", "\"", "");
1962         return b.obj();
1963     }
json() const1964     virtual string json() const {
1965         return "{ \"a\" : /\"/ }";
1966     }
1967 };
1968 
1969 class RegexWithQuotes1 : public Base {
bson() const1970     virtual BSONObj bson() const {
1971         BSONObjBuilder b;
1972         b.appendRegex("a", "\"", "");
1973         return b.obj();
1974     }
json() const1975     virtual string json() const {
1976         return "{ \"a\" : { $regex : \"\\\"\" }}";
1977     }
1978 };
1979 
1980 class RegexInvalidField : public Bad {
json() const1981     virtual string json() const {
1982         return "{ \"a\" : { \"$regex\" : \"b\", \"field\" : \"i\" } }";
1983     }
1984 };
1985 
1986 class RegexInvalidOption : public Bad {
json() const1987     virtual string json() const {
1988         return "{ \"a\" : { \"$regex\" : \"b\", \"$options\" : \"1\" } }";
1989     }
1990 };
1991 
1992 class RegexInvalidOption2 : public Bad {
json() const1993     virtual string json() const {
1994         return "{ \"a\" : /b/c }";
1995     }
1996 };
1997 
1998 class RegexInvalidOption3 : public Bad {
json() const1999     virtual string json() const {
2000         return "{ \"a\" : /b/ic }";
2001     }
2002 };
2003 
2004 class RegexInvalidOption4 : public Bad {
json() const2005     virtual string json() const {
2006         return "{ \"a\" : { \"$regex\" : \"b\", \"$options\" : \"a\" } }";
2007     }
2008 };
2009 
2010 class RegexInvalidOption5 : public Bad {
json() const2011     virtual string json() const {
2012         return "{ \"a\" : /b/a }";
2013     }
2014 };
2015 
2016 class RegexEmptyOption : public Base {
bson() const2017     virtual BSONObj bson() const {
2018         BSONObjBuilder b;
2019         b.appendRegex("a", "b", "");
2020         return b.obj();
2021     }
json() const2022     virtual string json() const {
2023         return "{ \"a\" : { \"$regex\" : \"b\", \"$options\" : \"\" } }";
2024     }
2025 };
2026 
2027 class RegexEmpty : public Base {
bson() const2028     virtual BSONObj bson() const {
2029         BSONObjBuilder b;
2030         b.appendRegex("a", "", "");
2031         return b.obj();
2032     }
json() const2033     virtual string json() const {
2034         return "{ \"a\" : { \"$regex\" : \"\", \"$options\" : \"\"} }";
2035     }
2036 };
2037 
2038 class RegexEmpty1 : public Base {
bson() const2039     virtual BSONObj bson() const {
2040         BSONObjBuilder b;
2041         b.appendRegex("a", "", "");
2042         return b.obj();
2043     }
json() const2044     virtual string json() const {
2045         return "{ \"a\" :  //  }";
2046     }
2047 };
2048 
2049 class RegexOverlap : public Bad {
json() const2050     virtual string json() const {
2051         return "{ \"a\" : { \"$regex\" : // } }";
2052     }
2053 };
2054 
2055 class Malformed : public Bad {
json() const2056     string json() const {
2057         return "{";
2058     }
2059 };
2060 
2061 class Malformed1 : public Bad {
json() const2062     string json() const {
2063         return "}";
2064     }
2065 };
2066 
2067 class Malformed2 : public Bad {
json() const2068     string json() const {
2069         return "{test}";
2070     }
2071 };
2072 
2073 class Malformed3 : public Bad {
json() const2074     string json() const {
2075         return "{test";
2076     }
2077 };
2078 
2079 class Malformed4 : public Bad {
json() const2080     string json() const {
2081         return "{ test : 1";
2082     }
2083 };
2084 
2085 class Malformed5 : public Bad {
json() const2086     string json() const {
2087         return "{ test : 1 , }";
2088     }
2089 };
2090 
2091 class Malformed6 : public Bad {
json() const2092     string json() const {
2093         return "{ test : 1 , tst}";
2094     }
2095 };
2096 
2097 class Malformed7 : public Bad {
json() const2098     string json() const {
2099         return "{ a : []";
2100     }
2101 };
2102 
2103 class Malformed8 : public Bad {
json() const2104     string json() const {
2105         return "{ a : { test : 1 }";
2106     }
2107 };
2108 
2109 class Malformed9 : public Bad {
json() const2110     string json() const {
2111         return "{ a : [ { test : 1]}";
2112     }
2113 };
2114 
2115 class Malformed10 : public Bad {
json() const2116     string json() const {
2117         return "{ a : [ { test : 1], b : 2}";
2118     }
2119 };
2120 
2121 class Malformed11 : public Bad {
json() const2122     string json() const {
2123         return "{ a : \"test\"string }";
2124     }
2125 };
2126 
2127 class Malformed12 : public Bad {
json() const2128     string json() const {
2129         return "{ a : test\"string\" }";
2130     }
2131 };
2132 
2133 class Malformed13 : public Bad {
json() const2134     string json() const {
2135         return "{ a\"bad\" : \"teststring\" }";
2136     }
2137 };
2138 
2139 class Malformed14 : public Bad {
json() const2140     string json() const {
2141         return "{ \"a\"test : \"teststring\" }";
2142     }
2143 };
2144 
2145 class Malformed15 : public Bad {
json() const2146     string json() const {
2147         return "{ \"atest : \"teststring\" }";
2148     }
2149 };
2150 
2151 class Malformed16 : public Bad {
json() const2152     string json() const {
2153         return "{ atest\" : \"teststring\" }";
2154     }
2155 };
2156 
2157 class Malformed17 : public Bad {
json() const2158     string json() const {
2159         return "{ atest\" : 1 }";
2160     }
2161 };
2162 
2163 class Malformed18 : public Bad {
json() const2164     string json() const {
2165         return "{ atest : \"teststring }";
2166     }
2167 };
2168 
2169 class Malformed19 : public Bad {
json() const2170     string json() const {
2171         return "{ atest : teststring\" }";
2172     }
2173 };
2174 
2175 class UnquotedFieldName : public Base {
bson() const2176     virtual BSONObj bson() const {
2177         BSONObjBuilder b;
2178         b.append("a_b", 1);
2179         return b.obj();
2180     }
json() const2181     virtual string json() const {
2182         return "{ a_b : 1 }";
2183     }
2184 };
2185 
2186 class UnquotedFieldNameBad : public Bad {
json() const2187     string json() const {
2188         return "{ 123 : 1 }";
2189     }
2190 };
2191 
2192 class UnquotedFieldNameBad1 : public Bad {
json() const2193     string json() const {
2194         return "{ -123 : 1 }";
2195     }
2196 };
2197 
2198 class UnquotedFieldNameBad2 : public Bad {
json() const2199     string json() const {
2200         return "{ .123 : 1 }";
2201     }
2202 };
2203 
2204 class UnquotedFieldNameBad3 : public Bad {
json() const2205     string json() const {
2206         return "{ -.123 : 1 }";
2207     }
2208 };
2209 
2210 class UnquotedFieldNameBad4 : public Bad {
json() const2211     string json() const {
2212         return "{ -1.23 : 1 }";
2213     }
2214 };
2215 
2216 class UnquotedFieldNameBad5 : public Bad {
json() const2217     string json() const {
2218         return "{ 1e23 : 1 }";
2219     }
2220 };
2221 
2222 class UnquotedFieldNameBad6 : public Bad {
json() const2223     string json() const {
2224         return "{ -1e23 : 1 }";
2225     }
2226 };
2227 
2228 class UnquotedFieldNameBad7 : public Bad {
json() const2229     string json() const {
2230         return "{ -1e-23 : 1 }";
2231     }
2232 };
2233 
2234 class UnquotedFieldNameBad8 : public Bad {
json() const2235     string json() const {
2236         return "{ -hello : 1 }";
2237     }
2238 };
2239 
2240 class UnquotedFieldNameBad9 : public Bad {
json() const2241     string json() const {
2242         return "{ il.legal : 1 }";
2243     }
2244 };
2245 
2246 class UnquotedFieldNameBad10 : public Bad {
json() const2247     string json() const {
2248         return "{ 10gen : 1 }";
2249     }
2250 };
2251 
2252 class UnquotedFieldNameBad11 : public Bad {
json() const2253     string json() const {
2254         return "{ _123. : 1 }";
2255     }
2256 };
2257 
2258 class UnquotedFieldNameBad12 : public Bad {
json() const2259     string json() const {
2260         return "{ he-llo : 1 }";
2261     }
2262 };
2263 
2264 class UnquotedFieldNameBad13 : public Bad {
json() const2265     string json() const {
2266         return "{ bad\nchar : 1 }";
2267     }
2268 };
2269 
2270 class UnquotedFieldNameBad14 : public Bad {
json() const2271     string json() const {
2272         return "{ thiswill\fail : 1 }";
2273     }
2274 };
2275 
2276 class UnquotedFieldNameBad15 : public Bad {
json() const2277     string json() const {
2278         return "{ failu\re : 1 }";
2279     }
2280 };
2281 
2282 class UnquotedFieldNameBad16 : public Bad {
json() const2283     string json() const {
2284         return "{ t\test : 1 }";
2285     }
2286 };
2287 
2288 class UnquotedFieldNameBad17 : public Bad {
json() const2289     string json() const {
2290         return "{ \break: 1 }";
2291     }
2292 };
2293 
2294 class UnquotedFieldNameBad18 : public Bad {
json() const2295     string json() const {
2296         // here we fill the memory directly to test unicode values
2297         // In this case we set \u0700 and \uFF00
2298         // Setting it directly in memory avoids MSVC error c4566
2299         unsigned char u[6];
2300         u[0] = 0xdc;
2301         u[1] = 0x80;
2302 
2303         u[2] = 0xef;
2304         u[3] = 0xbc;
2305         u[4] = 0x80;
2306 
2307         u[5] = 0;
2308         std::stringstream ss;
2309         ss << "{ " << u << " : 1 }";
2310         return ss.str();
2311     }
2312 };
2313 
2314 class UnquotedFieldNameBad19 : public Bad {
json() const2315     string json() const {
2316         return "{ bl\\u3333p: 1 }";
2317     }
2318 };
2319 
2320 class UnquotedFieldNameBad20 : public Bad {
json() const2321     string json() const {
2322         return "{ bl-33p: 1 }";
2323     }
2324 };
2325 
2326 class UnquotedFieldNameDollar : public Base {
bson() const2327     virtual BSONObj bson() const {
2328         BSONObjBuilder b;
2329         b.append("$a_b", 1);
2330         return b.obj();
2331     }
json() const2332     virtual string json() const {
2333         return "{ $a_b : 1 }";
2334     }
2335 };
2336 
2337 class SingleQuotes : public Base {
bson() const2338     virtual BSONObj bson() const {
2339         BSONObjBuilder b;
2340         b.append("ab'c\"", "bb\b '\"");
2341         return b.obj();
2342     }
json() const2343     virtual string json() const {
2344         return "{ 'ab\\'c\"' : 'bb\\b \\'\"' }";
2345     }
2346 };
2347 
2348 class QuoteTest : public Base {
bson() const2349     virtual BSONObj bson() const {
2350         BSONObjBuilder b;
2351         b.append("\"", "test");
2352         return b.obj();
2353     }
json() const2354     virtual string json() const {
2355         return "{ '\"' : \"test\" }";
2356     }
2357 };
2358 
2359 class QuoteTest1 : public Base {
bson() const2360     virtual BSONObj bson() const {
2361         BSONObjBuilder b;
2362         b.append("'", "test");
2363         return b.obj();
2364     }
json() const2365     virtual string json() const {
2366         return "{ \"'\" : \"test\" }";
2367     }
2368 };
2369 
2370 class QuoteTest2 : public Base {
bson() const2371     virtual BSONObj bson() const {
2372         BSONObjBuilder b;
2373         b.append("\"", "test");
2374         return b.obj();
2375     }
json() const2376     virtual string json() const {
2377         return "{ '\"' : \"test\" }";
2378     }
2379 };
2380 
2381 class QuoteTest3 : public Base {
bson() const2382     virtual BSONObj bson() const {
2383         BSONObjBuilder b;
2384         b.append("\"'\"", "test");
2385         return b.obj();
2386     }
json() const2387     virtual string json() const {
2388         return "{ '\"\\\'\"' : \"test\" }";
2389     }
2390 };
2391 
2392 class QuoteTest4 : public Base {
bson() const2393     virtual BSONObj bson() const {
2394         BSONObjBuilder b;
2395         b.append("'\"'", "test");
2396         return b.obj();
2397     }
json() const2398     virtual string json() const {
2399         return "{ \"'\\\"'\" : \"test\" }";
2400     }
2401 };
2402 
2403 class QuoteTest5 : public Base {
bson() const2404     virtual BSONObj bson() const {
2405         BSONObjBuilder b;
2406         b.append("test", "'");
2407         return b.obj();
2408     }
json() const2409     virtual string json() const {
2410         return "{ \"test\" : \"'\" }";
2411     }
2412 };
2413 
2414 class QuoteTest6 : public Base {
bson() const2415     virtual BSONObj bson() const {
2416         BSONObjBuilder b;
2417         b.append("test", "\"");
2418         return b.obj();
2419     }
json() const2420     virtual string json() const {
2421         return "{ \"test\" : '\"' }";
2422     }
2423 };
2424 
2425 class ObjectId : public Base {
bson() const2426     virtual BSONObj bson() const {
2427         OID id;
2428         id.init("deadbeeff00ddeadbeeff00d");
2429         BSONObjBuilder b;
2430         b.appendOID("_id", &id);
2431         return b.obj();
2432     }
json() const2433     virtual string json() const {
2434         return "{ \"_id\": ObjectId( \"deadbeeff00ddeadbeeff00d\" ) }";
2435     }
2436 };
2437 
2438 class ObjectId2 : public Base {
bson() const2439     virtual BSONObj bson() const {
2440         OID id;
2441         id.init("deadbeeff00ddeadbeeff00d");
2442         BSONObjBuilder b;
2443         b.appendOID("foo", &id);
2444         return b.obj();
2445     }
json() const2446     virtual string json() const {
2447         return "{ \"foo\": ObjectId( \"deadbeeff00ddeadbeeff00d\" ) }";
2448     }
2449 };
2450 
2451 class NumericTypes : public Base {
2452 public:
run()2453     void run() {
2454         Base::run();
2455 
2456         BSONObj o = fromjson(json());
2457 
2458         ASSERT(o["int"].type() == NumberInt);
2459         ASSERT(o["long"].type() == NumberLong);
2460         ASSERT(o["double"].type() == NumberDouble);
2461 
2462         ASSERT(o["long"].numberLong() == 9223372036854775807ll);
2463     }
2464 
bson() const2465     virtual BSONObj bson() const {
2466         return BSON("int" << 123 << "long" << 9223372036854775807ll  // 2**63 - 1
2467                           << "double"
2468                           << 3.14);
2469     }
json() const2470     virtual string json() const {
2471         return "{ \"int\": 123, \"long\": 9223372036854775807, \"double\": 3.14 }";
2472     }
2473 };
2474 
2475 class NumericTypesJS : public Base {
2476 public:
run()2477     void run() {
2478         Base::run();
2479 
2480         BSONObj o = fromjson(json());
2481 
2482         ASSERT(o["int"].type() == NumberInt);
2483         ASSERT(o["long"].type() == NumberLong);
2484         ASSERT(o["double"].type() == NumberDouble);
2485 
2486         ASSERT(o["long"].numberLong() == 9223372036854775807ll);
2487     }
2488 
bson() const2489     virtual BSONObj bson() const {
2490         return BSON("int" << 123 << "long" << 9223372036854775807ll  // 2**63 - 1
2491                           << "double"
2492                           << 3.14);
2493     }
json() const2494     virtual string json() const {
2495         return "{ 'int': NumberInt(123), "
2496                "'long': NumberLong(9223372036854775807), "
2497                "'double': 3.14 }";
2498     }
2499 };
2500 
2501 class NumericLongMin : public Base {
bson() const2502     virtual BSONObj bson() const {
2503         BSONObjBuilder b;
2504         b.append("a", std::numeric_limits<long long>::min());
2505         return b.obj();
2506     }
json() const2507     virtual string json() const {
2508         std::stringstream ss;
2509         ss << "{'a': ";
2510         ss << std::numeric_limits<long long>::min();
2511         ss << " }";
2512         return ss.str();
2513     }
2514 };
2515 
2516 class NumericIntMin : public Base {
bson() const2517     virtual BSONObj bson() const {
2518         BSONObjBuilder b;
2519         b.appendNumber("a", std::numeric_limits<int>::min());
2520         return b.obj();
2521     }
json() const2522     virtual string json() const {
2523         std::stringstream ss;
2524         ss << "{'a': ";
2525         ss << std::numeric_limits<int>::min();
2526         ss << " }";
2527         return ss.str();
2528     }
2529 };
2530 
2531 
2532 class NumericLimits : public Base {
bson() const2533     virtual BSONObj bson() const {
2534         BSONObjBuilder builder;
2535         BSONArrayBuilder numArray(builder.subarrayStart(""));
2536         numArray.append(std::numeric_limits<long long>::max());
2537         numArray.append(std::numeric_limits<long long>::min());
2538         numArray.append(std::numeric_limits<int>::max());
2539         numArray.append(std::numeric_limits<int>::min());
2540         numArray.done();
2541         return builder.obj();
2542     }
json() const2543     virtual string json() const {
2544         std::stringstream ss;
2545         ss << "{'': [";
2546         ss << std::numeric_limits<long long>::max() << ",";
2547         ss << std::numeric_limits<long long>::min() << ",";
2548         ss << std::numeric_limits<int>::max() << ",";
2549         ss << std::numeric_limits<int>::min();
2550         ss << "] }";
2551         return ss.str();
2552     }
2553 };
2554 
2555 // Overflows double by giving it an exponent that is too large
2556 class NumericLimitsBad : public Bad {
json() const2557     virtual string json() const {
2558         std::stringstream ss;
2559         ss << "{ test : ";
2560         ss << std::numeric_limits<double>::max() << "1111111111";
2561         ss << "}";
2562         return ss.str();
2563     }
2564 };
2565 
2566 class NumericLimitsBad1 : public Bad {
json() const2567     virtual string json() const {
2568         std::stringstream ss;
2569         ss << "{ test : ";
2570         ss << std::numeric_limits<double>::min() << "11111111111";
2571         ss << "}";
2572         return ss.str();
2573     }
2574 };
2575 
2576 class NegativeNumericTypes : public Base {
2577 public:
run()2578     void run() {
2579         Base::run();
2580 
2581         BSONObj o = fromjson(json());
2582 
2583         ASSERT(o["int"].type() == NumberInt);
2584         ASSERT(o["long"].type() == NumberLong);
2585         ASSERT(o["double"].type() == NumberDouble);
2586 
2587         ASSERT(o["long"].numberLong() == -9223372036854775807ll);
2588     }
2589 
bson() const2590     virtual BSONObj bson() const {
2591         return BSON("int" << -123 << "long" << -9223372036854775807ll  // -1 * (2**63 - 1)
2592                           << "double"
2593                           << -3.14);
2594     }
json() const2595     virtual string json() const {
2596         return "{ \"int\": -123, \"long\": -9223372036854775807, \"double\": -3.14 }";
2597     }
2598 };
2599 
2600 class EmbeddedDatesBase : public Base {
2601 public:
run()2602     virtual void run() {
2603         BSONObj o = fromjson(json());
2604         ASSERT_EQUALS(3, (o["time.valid"].type()));
2605         BSONObj e = o["time.valid"].embeddedObjectUserCheck();
2606         ASSERT_EQUALS(9, e["$gt"].type());
2607         ASSERT_EQUALS(9, e["$lt"].type());
2608         Base::run();
2609     }
2610 
bson() const2611     BSONObj bson() const {
2612         BSONObjBuilder e;
2613         e.appendDate("$gt", Date_t::fromMillisSinceEpoch(1257829200000LL));
2614         e.appendDate("$lt", Date_t::fromMillisSinceEpoch(1257829200100LL));
2615 
2616         BSONObjBuilder b;
2617         b.append("time.valid", e.obj());
2618         return b.obj();
2619     }
2620     virtual string json() const = 0;
2621 };
2622 
2623 struct EmbeddedDatesFormat1 : EmbeddedDatesBase {
jsonJsonTests::FromJsonTests::EmbeddedDatesFormat12624     string json() const {
2625         return "{ \"time.valid\" : { $gt : { \"$date\" :  1257829200000 } , $lt : { \"$date\" : "
2626                "1257829200100 } } }";
2627     }
2628 };
2629 struct EmbeddedDatesFormat2 : EmbeddedDatesBase {
jsonJsonTests::FromJsonTests::EmbeddedDatesFormat22630     string json() const {
2631         return "{ \"time.valid\" : { $gt : Date(1257829200000) , $lt : Date( 1257829200100 ) } }";
2632     }
2633 };
2634 struct EmbeddedDatesFormat3 : EmbeddedDatesBase {
jsonJsonTests::FromJsonTests::EmbeddedDatesFormat32635     string json() const {
2636         return "{ \"time.valid\" : { $gt : new Date(1257829200000) , $lt : new Date( 1257829200100 "
2637                ") } }";
2638     }
2639 };
2640 
2641 class NullString : public Base {
bson() const2642     virtual BSONObj bson() const {
2643         BSONObjBuilder b;
2644         b.append("x", "a\0b", 4);
2645         return b.obj();
2646     }
json() const2647     virtual string json() const {
2648         return "{ \"x\" : \"a\\u0000b\" }";
2649     }
2650 };
2651 
2652 class NullFieldUnquoted : public Bad {
json() const2653     virtual string json() const {
2654         return "{ x\\u0000y : \"a\" }";
2655     }
2656 };
2657 
2658 class MinKeyAlone : public Bad {
json() const2659     virtual string json() const {
2660         return "{ \"$minKey\" : 1 }";
2661     }
2662 };
2663 
2664 class MaxKeyAlone : public Bad {
json() const2665     virtual string json() const {
2666         return "{ \"$maxKey\" : 1 }";
2667     }
2668 };
2669 
2670 class MinKey : public Base {
bson() const2671     virtual BSONObj bson() const {
2672         BSONObjBuilder b;
2673         b.appendMinKey("a");
2674         return b.obj();
2675     }
json() const2676     virtual string json() const {
2677         return "{ \"a\" : { \"$minKey\" : 1 } }";
2678     }
2679 };
2680 
2681 class MaxKey : public Base {
bson() const2682     virtual BSONObj bson() const {
2683         BSONObjBuilder b;
2684         b.appendMaxKey("a");
2685         return b.obj();
2686     }
json() const2687     virtual string json() const {
2688         return "{ \"a\" : { \"$maxKey\" : 1 } }";
2689     }
2690 };
2691 
2692 }  // namespace FromJsonTests
2693 
2694 class All : public Suite {
2695 public:
All()2696     All() : Suite("json") {}
2697 
setupTests()2698     void setupTests() {
2699         add<JsonStringTests::Empty>();
2700         add<JsonStringTests::SingleStringMember>();
2701         add<JsonStringTests::EscapedCharacters>();
2702         add<JsonStringTests::AdditionalControlCharacters>();
2703         add<JsonStringTests::ExtendedAscii>();
2704         add<JsonStringTests::EscapeFieldName>();
2705         add<JsonStringTests::SingleIntMember>();
2706         add<JsonStringTests::SingleNumberMember>();
2707         add<JsonStringTests::InvalidNumbers>();
2708         add<JsonStringTests::NumberPrecision>();
2709         add<JsonStringTests::NegativeNumber>();
2710         add<JsonStringTests::NumberLongStrictZero>();
2711         add<JsonStringTests::NumberLongStrict>();
2712         add<JsonStringTests::NumberLongStrictLarge>();
2713         add<JsonStringTests::NumberLongStrictNegative>();
2714         add<JsonStringTests::NumberDecimal>();
2715         add<JsonStringTests::NumberDecimalStrict>();
2716         add<JsonStringTests::NumberDoubleNaN>();
2717         add<JsonStringTests::NumberDoubleInfinity>();
2718         add<JsonStringTests::NumberDoubleNegativeInfinity>();
2719         add<JsonStringTests::SingleBoolMember>();
2720         add<JsonStringTests::SingleNullMember>();
2721         add<JsonStringTests::SingleUndefinedMember>();
2722         add<JsonStringTests::SingleObjectMember>();
2723         add<JsonStringTests::TwoMembers>();
2724         add<JsonStringTests::EmptyArray>();
2725         add<JsonStringTests::Array>();
2726         add<JsonStringTests::DBRef>();
2727         add<JsonStringTests::DBRefZero>();
2728         add<JsonStringTests::ObjectId>();
2729         add<JsonStringTests::BinData>();
2730         add<JsonStringTests::Symbol>();
2731         add<JsonStringTests::Date>();
2732         add<JsonStringTests::DateNegative>();
2733         add<JsonStringTests::Regex>();
2734         add<JsonStringTests::RegexEscape>();
2735         add<JsonStringTests::RegexManyOptions>();
2736         add<JsonStringTests::CodeTests>();
2737         add<JsonStringTests::CodeWScopeTests>();
2738         add<JsonStringTests::TimestampTests>();
2739         add<JsonStringTests::NullString>();
2740         add<JsonStringTests::AllTypes>();
2741 
2742         add<FromJsonTests::Empty>();
2743         add<FromJsonTests::EmptyWithSpace>();
2744         add<FromJsonTests::SingleString>();
2745         add<FromJsonTests::EmptyStrings>();
2746         add<FromJsonTests::ReservedFieldName>();
2747         add<FromJsonTests::ReservedFieldName1>();
2748         add<FromJsonTests::NumberFieldName>();
2749         add<FromJsonTests::InvalidFieldName>();
2750         add<FromJsonTests::QuotedNullName>();
2751         add<FromJsonTests::NoValue>();
2752         add<FromJsonTests::InvalidValue>();
2753         add<FromJsonTests::InvalidValue>();
2754         add<FromJsonTests::OkDollarFieldName>();
2755         add<FromJsonTests::SingleNumber>();
2756         add<FromJsonTests::RealNumber>();
2757         add<FromJsonTests::FancyNumber>();
2758         add<FromJsonTests::TwoElements>();
2759         add<FromJsonTests::Subobject>();
2760         add<FromJsonTests::DeeplyNestedObject>();
2761         add<FromJsonTests::ArrayEmpty>();
2762         add<FromJsonTests::TopLevelArrayEmpty>();
2763         add<FromJsonTests::TopLevelArray>();
2764         add<FromJsonTests::Array>();
2765         add<FromJsonTests::True>();
2766         add<FromJsonTests::False>();
2767         add<FromJsonTests::Null>();
2768         add<FromJsonTests::Undefined>();
2769         add<FromJsonTests::UndefinedStrict>();
2770         add<FromJsonTests::UndefinedStrictBad>();
2771         add<FromJsonTests::EscapedCharacters>();
2772         add<FromJsonTests::NonEscapedCharacters>();
2773         add<FromJsonTests::AllowedControlCharacter>();
2774         add<FromJsonTests::InvalidControlCharacter>();
2775         add<FromJsonTests::NumbersInFieldName>();
2776         add<FromJsonTests::EscapeFieldName>();
2777         add<FromJsonTests::EscapedUnicodeToUtf8>();
2778         add<FromJsonTests::Utf8AllOnes>();
2779         add<FromJsonTests::Utf8FirstByteOnes>();
2780         add<FromJsonTests::Utf8Invalid>();
2781         add<FromJsonTests::Utf8TooShort>();
2782         add<FromJsonTests::DBRefConstructor>();
2783         add<FromJsonTests::DBRefConstructorCapitals>();
2784         add<FromJsonTests::DBRefConstructorDbName>();
2785         add<FromJsonTests::DBRefConstructorNumber>();
2786         add<FromJsonTests::DBRefConstructorObject>();
2787         add<FromJsonTests::DBRefNumberId>();
2788         add<FromJsonTests::DBRefObjectAsId>();
2789         add<FromJsonTests::DBRefStringId>();
2790         add<FromJsonTests::DBRefObjectIDObject>();
2791         add<FromJsonTests::DBRefObjectIDConstructor>();
2792         add<FromJsonTests::DBRefDbName>();
2793         add<FromJsonTests::Oid>();
2794         add<FromJsonTests::Oid2>();
2795         add<FromJsonTests::OidTooLong>();
2796         add<FromJsonTests::Oid2TooLong>();
2797         add<FromJsonTests::OidTooShort>();
2798         add<FromJsonTests::Oid2TooShort>();
2799         add<FromJsonTests::OidInvalidChar>();
2800         add<FromJsonTests::Oid2InvalidChar>();
2801         add<FromJsonTests::StringId>();
2802         add<FromJsonTests::BinData>();
2803         add<FromJsonTests::BinData1>();
2804         add<FromJsonTests::BinData2>();
2805         add<FromJsonTests::BinData3>();
2806         add<FromJsonTests::BinData4>();
2807         add<FromJsonTests::BinData5>();
2808         add<FromJsonTests::BinData80>();
2809         add<FromJsonTests::BinDataPaddedSingle>();
2810         add<FromJsonTests::BinDataPaddedDouble>();
2811         add<FromJsonTests::BinDataAllChars>();
2812         add<FromJsonTests::BinDataBadLength>();
2813         add<FromJsonTests::BinDataBadLength1>();
2814         add<FromJsonTests::BinDataBadLength2>();
2815         add<FromJsonTests::BinDataBadLength3>();
2816         add<FromJsonTests::BinDataBadLength4>();
2817         add<FromJsonTests::BinDataBadLength5>();
2818         add<FromJsonTests::BinDataBadChars>();
2819         add<FromJsonTests::BinDataTypeTooShort>();
2820         add<FromJsonTests::BinDataTypeTooLong>();
2821         add<FromJsonTests::BinDataTypeBadChars>();
2822         add<FromJsonTests::BinDataEmptyType>();
2823         add<FromJsonTests::BinDataNoType>();
2824         add<FromJsonTests::BinDataInvalidType>();
2825         // DOCS-2539:  We cannot parse dates generated with a Unix timestamp of zero in local
2826         // time, since the body of the date may be before the Unix Epoch.  This causes parsing
2827         // to fail even if the offset would properly adjust the time.  For example,
2828         // "1969-12-31T19:00:00-05:00" actually represents the Unix timestamp of zero, but we
2829         // cannot parse it because the body of the date is before 1970.
2830         // add< FromJsonTests::Date >();
2831         add<FromJsonTests::DateNonzero>();
2832         add<FromJsonTests::DateStrictTooLong>();
2833         add<FromJsonTests::DateTooLong>();
2834         add<FromJsonTests::DateIsString>();
2835         add<FromJsonTests::DateIsString1>();
2836         add<FromJsonTests::DateIsString2>();
2837         add<FromJsonTests::DateIsFloat>();
2838         add<FromJsonTests::DateIsFloat1>();
2839         add<FromJsonTests::DateIsFloat2>();
2840         add<FromJsonTests::DateIsExponent>();
2841         add<FromJsonTests::DateIsExponent1>();
2842         add<FromJsonTests::DateIsExponent2>();
2843         add<FromJsonTests::DateStrictMaxUnsigned>();
2844         add<FromJsonTests::DateMaxUnsigned>();
2845         add<FromJsonTests::DateStrictNegative>();
2846         add<FromJsonTests::DateNegative>();
2847         add<FromJsonTests::NumberLongTest>();
2848         add<FromJsonTests::NumberLongMin>();
2849         add<FromJsonTests::NumberIntTest>();
2850         add<FromJsonTests::NumberLongNeg>();
2851         add<FromJsonTests::NumberIntNeg>();
2852         add<FromJsonTests::NumberLongBad>();
2853         add<FromJsonTests::NumberIntBad>();
2854         add<FromJsonTests::JSTimestamp>();
2855         add<FromJsonTests::TimestampNoIncrement>();
2856         add<FromJsonTests::TimestampZero>();
2857         add<FromJsonTests::TimestampNoArgs>();
2858         add<FromJsonTests::TimestampFloatSeconds>();
2859         add<FromJsonTests::TimestampFloatIncrement>();
2860         add<FromJsonTests::TimestampNegativeSeconds>();
2861         add<FromJsonTests::TimestampNegativeIncrement>();
2862         add<FromJsonTests::TimestampInvalidSeconds>();
2863         add<FromJsonTests::TimestampObject>();
2864         add<FromJsonTests::TimestampObjectInvalidFieldName>();
2865         add<FromJsonTests::TimestampObjectNoIncrement>();
2866         add<FromJsonTests::TimestampObjectNegativeSeconds>();
2867         add<FromJsonTests::TimestampObjectNegativeIncrement>();
2868         add<FromJsonTests::TimestampObjectInvalidSeconds>();
2869         add<FromJsonTests::TimestampObjectZero>();
2870         add<FromJsonTests::TimestampObjectNoArgs>();
2871         add<FromJsonTests::TimestampObjectFloatSeconds>();
2872         add<FromJsonTests::TimestampObjectFloatIncrement>();
2873         add<FromJsonTests::Regex>();
2874         add<FromJsonTests::RegexNoOptionField>();
2875         add<FromJsonTests::RegexEscape>();
2876         add<FromJsonTests::RegexWithQuotes>();
2877         add<FromJsonTests::RegexWithQuotes1>();
2878         add<FromJsonTests::RegexInvalidField>();
2879         add<FromJsonTests::RegexInvalidOption>();
2880         add<FromJsonTests::RegexInvalidOption2>();
2881         add<FromJsonTests::RegexInvalidOption3>();
2882         add<FromJsonTests::RegexInvalidOption4>();
2883         add<FromJsonTests::RegexInvalidOption5>();
2884         add<FromJsonTests::RegexEmptyOption>();
2885         add<FromJsonTests::RegexEmpty>();
2886         add<FromJsonTests::RegexEmpty1>();
2887         add<FromJsonTests::RegexOverlap>();
2888         add<FromJsonTests::Malformed>();
2889         add<FromJsonTests::Malformed1>();
2890         add<FromJsonTests::Malformed2>();
2891         add<FromJsonTests::Malformed3>();
2892         add<FromJsonTests::Malformed4>();
2893         add<FromJsonTests::Malformed5>();
2894         add<FromJsonTests::Malformed6>();
2895         add<FromJsonTests::Malformed7>();
2896         add<FromJsonTests::Malformed8>();
2897         add<FromJsonTests::Malformed9>();
2898         add<FromJsonTests::Malformed10>();
2899         add<FromJsonTests::Malformed11>();
2900         add<FromJsonTests::Malformed12>();
2901         add<FromJsonTests::Malformed13>();
2902         add<FromJsonTests::Malformed14>();
2903         add<FromJsonTests::Malformed15>();
2904         add<FromJsonTests::Malformed16>();
2905         add<FromJsonTests::Malformed17>();
2906         add<FromJsonTests::Malformed18>();
2907         add<FromJsonTests::Malformed19>();
2908         add<FromJsonTests::UnquotedFieldName>();
2909         add<FromJsonTests::UnquotedFieldNameBad>();
2910         add<FromJsonTests::UnquotedFieldNameBad1>();
2911         add<FromJsonTests::UnquotedFieldNameBad2>();
2912         add<FromJsonTests::UnquotedFieldNameBad3>();
2913         add<FromJsonTests::UnquotedFieldNameBad4>();
2914         add<FromJsonTests::UnquotedFieldNameBad5>();
2915         add<FromJsonTests::UnquotedFieldNameBad6>();
2916         add<FromJsonTests::UnquotedFieldNameBad7>();
2917         add<FromJsonTests::UnquotedFieldNameBad8>();
2918         add<FromJsonTests::UnquotedFieldNameBad9>();
2919         add<FromJsonTests::UnquotedFieldNameBad10>();
2920         add<FromJsonTests::UnquotedFieldNameBad11>();
2921         add<FromJsonTests::UnquotedFieldNameBad12>();
2922         add<FromJsonTests::UnquotedFieldNameBad13>();
2923         add<FromJsonTests::UnquotedFieldNameBad14>();
2924         add<FromJsonTests::UnquotedFieldNameBad15>();
2925         add<FromJsonTests::UnquotedFieldNameBad16>();
2926         add<FromJsonTests::UnquotedFieldNameBad17>();
2927         add<FromJsonTests::UnquotedFieldNameBad18>();
2928         add<FromJsonTests::UnquotedFieldNameBad19>();
2929         add<FromJsonTests::UnquotedFieldNameBad20>();
2930         add<FromJsonTests::UnquotedFieldNameDollar>();
2931         add<FromJsonTests::SingleQuotes>();
2932         add<FromJsonTests::QuoteTest>();
2933         add<FromJsonTests::QuoteTest1>();
2934         add<FromJsonTests::QuoteTest2>();
2935         add<FromJsonTests::QuoteTest3>();
2936         add<FromJsonTests::QuoteTest4>();
2937         add<FromJsonTests::QuoteTest5>();
2938         add<FromJsonTests::QuoteTest6>();
2939         add<FromJsonTests::ObjectId>();
2940         add<FromJsonTests::ObjectId2>();
2941         add<FromJsonTests::NumericIntMin>();
2942         add<FromJsonTests::NumericLongMin>();
2943         add<FromJsonTests::NumericTypes>();
2944         add<FromJsonTests::NumericTypesJS>();
2945         add<FromJsonTests::NumericLimits>();
2946         add<FromJsonTests::NumericLimitsBad>();
2947         add<FromJsonTests::NumericLimitsBad1>();
2948         add<FromJsonTests::NegativeNumericTypes>();
2949         add<FromJsonTests::EmbeddedDatesFormat1>();
2950         add<FromJsonTests::EmbeddedDatesFormat2>();
2951         add<FromJsonTests::EmbeddedDatesFormat3>();
2952         add<FromJsonTests::NullString>();
2953         add<FromJsonTests::NullFieldUnquoted>();
2954         add<FromJsonTests::MinKey>();
2955         add<FromJsonTests::MaxKey>();
2956     }
2957 };
2958 
2959 SuiteInstance<All> myall;
2960 
2961 }  // namespace JsonTests
2962