void bson_eq_stream(const bson_t* bson, const bsoncxx::builder::stream::document& builder) {
    using namespace bsoncxx;

    document::view expected(bson_get_data(bson), bson->len);
    document::view test(builder.view());

    INFO("expected = " << to_json(expected));
    INFO("builder = " << to_json(test));
    REQUIRE(expected.length() == test.length());
    REQUIRE(std::memcmp(expected.data(), test.data(), expected.length()) == 0);
}
Example #2
0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "catch.hpp"
#include "helpers.hpp"

#include <bsoncxx/builder/stream/document.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/result/replace_one.hpp>

TEST_CASE("replace_one", "[replace_one][result]") {
    mongocxx::instance::current();

    bsoncxx::builder::stream::document build;
    build << "_id" << bsoncxx::oid{bsoncxx::oid::init_tag} << "nMatched"
          << bsoncxx::types::b_int32{2} << "nModified" << bsoncxx::types::b_int32{1};

    mongocxx::result::bulk_write b(bsoncxx::document::value(build.view()));

    mongocxx::result::replace_one replace_one(std::move(b));

    SECTION("returns correct matched and modified count") {
        REQUIRE(replace_one.matched_count() == 2);
        REQUIRE(replace_one.modified_count() == 1);
    }
}