本文整理汇总了C++中RepoBSON::hasField方法的典型用法代码示例。如果您正苦于以下问题:C++ RepoBSON::hasField方法的具体用法?C++ RepoBSON::hasField怎么用?C++ RepoBSON::hasField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RepoBSON
的用法示例。
在下文中一共展示了RepoBSON::hasField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: binBson
TEST(RepoBSONTest, CloneAndShrink)
{
//shrinking a bson without any binary fields should yield an identical bson
RepoBSON shrunkBson = testBson.cloneAndShrink();
EXPECT_EQ(testBson, shrunkBson);
EXPECT_EQ(testBson.getFilesMapping().size(), shrunkBson.getFilesMapping().size());
mongo::BSONObjBuilder builder;
std::vector < uint8_t > in, out, ref;
size_t size = 100;
in.resize(size);
ref.resize(size);
builder << "stringTest" << "hello";
builder << "numTest" << 1.35;
builder.appendBinData("binDataTest", in.size(), mongo::BinDataGeneral, in.data());
std::unordered_map < std::string, std::pair<std::string, std::vector<uint8_t>>> mapping, outMapping;
mapping["orgRef"] = std::pair<std::string, std::vector<uint8_t>>("blah", ref);
RepoBSON binBson(builder.obj(), mapping);
shrunkBson = binBson.cloneAndShrink();
outMapping = shrunkBson.getFilesMapping();
EXPECT_NE(shrunkBson, binBson);
EXPECT_FALSE(shrunkBson.hasField("binDataTest"));
EXPECT_EQ(2, outMapping.size());
EXPECT_TRUE(outMapping.find("orgRef") != outMapping.end());
//Check the binary still obtainable
EXPECT_TRUE(shrunkBson.getBinaryFieldAsVector("binDataTest", out));
ASSERT_EQ(in.size(), out.size());
for (size_t i = 0; i < out.size(); ++i)
{
EXPECT_EQ(in[i], out[i]);
}
//Check the out referenced bigfile is still sane
EXPECT_EQ(ref.size(), outMapping["orgRef"].second.size());
for (size_t i = 0; i < ref.size(); ++i)
{
EXPECT_EQ(ref[i], outMapping["orgRef"].second[i]);
}
}