当前位置: 首页>>代码示例>>C++>>正文


C++ RepoBSON::getBinaryFieldAsVector方法代码示例

本文整理汇总了C++中RepoBSON::getBinaryFieldAsVector方法的典型用法代码示例。如果您正苦于以下问题:C++ RepoBSON::getBinaryFieldAsVector方法的具体用法?C++ RepoBSON::getBinaryFieldAsVector怎么用?C++ RepoBSON::getBinaryFieldAsVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RepoBSON的用法示例。


在下文中一共展示了RepoBSON::getBinaryFieldAsVector方法的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]);
	}

}
开发者ID:hyhylee,项目名称:3drepobouncer,代码行数:52,代码来源:ut_repo_bson.cpp


注:本文中的RepoBSON::getBinaryFieldAsVector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。