MongoDB  2.7.0
mutable_bson_test_utils.h
1 /* Copyright 2013 10gen Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <iosfwd>
17 
18 #include "mongo/bson/mutable/document.h"
19 
20 namespace mongo {
21 
22  class BSONObj;
23 
24 namespace mutablebson {
25 
26  //
27  // Utilities for mutable BSON unit tests.
28  //
29 
35  bool checkDoc(const Document& lhs, const BSONObj& rhs);
36  bool checkDoc(const Document& lhs, const Document& rhs);
37 
38  inline bool operator==(const Document& lhs, const Document& rhs) {
39  return checkDoc(lhs, rhs);
40  }
41 
42  inline bool operator==(const BSONObj& lhs, const Document& rhs) {
43  return checkDoc(rhs, lhs);
44  }
45 
46  inline bool operator==(const Document& lhs, const BSONObj& rhs) {
47  return checkDoc(lhs, rhs);
48  }
49 
51  std::ostream& operator<<(std::ostream& stream, const Document& doc);
52 
54  std::ostream& operator<<(std::ostream& stream, const ConstElement& elt);
55 
59  bool checkEqualNoOrdering(const Document& lhs, const Document& rhs);
60 
62  inline explicit UnorderedWrapper_Obj(const BSONObj& o)
63  : obj(o) {}
64  const BSONObj& obj;
65  };
66 
68  inline explicit UnorderedWrapper_Doc(const Document& d)
69  : doc(d) {}
70  const Document& doc;
71  };
72 
73  inline UnorderedWrapper_Doc unordered(const Document& d) {
74  return UnorderedWrapper_Doc(d);
75  }
76 
77  inline UnorderedWrapper_Obj unordered(const BSONObj& o) {
78  return UnorderedWrapper_Obj(o);
79  }
80 
81  inline bool operator==(const UnorderedWrapper_Doc& lhs, const UnorderedWrapper_Doc& rhs) {
82  return checkEqualNoOrdering(lhs.doc, rhs.doc);
83  }
84 
85  inline bool operator!=(const UnorderedWrapper_Doc& lhs, const UnorderedWrapper_Doc& rhs) {
86  return !(lhs == rhs);
87  }
88 
89 
90  inline bool operator==(const UnorderedWrapper_Obj& lhs, const UnorderedWrapper_Obj& rhs) {
91  const Document dlhs(lhs.obj);
92  const Document drhs(rhs.obj);
93  return checkEqualNoOrdering(dlhs, drhs);
94  }
95 
96  inline bool operator!=(const UnorderedWrapper_Obj& lhs, const UnorderedWrapper_Obj& rhs) {
97  return !(lhs == rhs);
98  }
99 
100 
101  inline bool operator==(const UnorderedWrapper_Doc& lhs, const UnorderedWrapper_Obj& rhs) {
102  const Document drhs(rhs.obj);
103  return checkEqualNoOrdering(lhs.doc, drhs);
104  }
105 
106  inline bool operator!=(const UnorderedWrapper_Doc& lhs, const UnorderedWrapper_Obj& rhs) {
107  return !(lhs == rhs);
108  }
109 
110 
111  inline bool operator==(const UnorderedWrapper_Obj& lhs, const UnorderedWrapper_Doc& rhs) {
112  const Document dlhs(lhs.obj);
113  return checkEqualNoOrdering(dlhs, rhs.doc);
114  }
115 
116  inline bool operator!=(const UnorderedWrapper_Obj& lhs, const UnorderedWrapper_Doc& rhs) {
117  return !(lhs == rhs);
118  }
119 
120  std::ostream& operator<<(std::ostream& stream, const UnorderedWrapper_Doc& uw_d);
121  std::ostream& operator<<(std::ostream& stream, const UnorderedWrapper_Obj& uw_o);
122 
123 } // namespace mutablebson
124 } // namespace mongo
Definition: mutable_bson_test_utils.h:67
Definition: mutable_bson_test_utils.h:61
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition: bsonobj.h:77
Mutable BSON Overview.
Definition: document.h:221