Exemplo n.º 1
0
TEST(RepoBSONTest, Swap)
{
	RepoBSON test = testBson;

	//Test with bigfile mapping
	std::vector < uint8_t > in;

	in.resize(100);

	std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>> map, mapout;
	map["testingfile"] = std::pair<std::string, std::vector<uint8_t>>("blah", in);

	RepoBSON testDiff_org(BSON("entirely" << "different"), map);
	RepoBSON testDiff = testDiff_org;

	EXPECT_TRUE(testDiff_org.toString() == testDiff.toString());
	EXPECT_TRUE(testDiff_org.getFilesMapping().size() == testDiff.getFilesMapping().size());


	test.swap(testDiff);
	EXPECT_EQ(testDiff_org.toString(), test.toString());


	mapout = test.getFilesMapping();
	ASSERT_EQ(map.size(), mapout.size());

	auto mapIt = map.begin();
	auto mapoutIt = mapout.begin();

	for (; mapIt != map.end(); ++mapIt, ++mapoutIt)
	{
		EXPECT_EQ(mapIt->first, mapIt->first);
		EXPECT_EQ(mapIt->second.first, mapIt->second.first);
		std::vector<uint8_t> dataOut = mapoutIt->second.second;
		std::vector<uint8_t> dataIn = mapIt->second.second;
		EXPECT_EQ(dataIn.size(), dataOut.size());
		if (dataIn.size()>0)
			EXPECT_EQ(0, strncmp((char*)dataOut.data(), (char*)dataIn.data(), dataIn.size()));
	}
}
Exemplo n.º 2
0
TEST(RepoBSONTest, AssignOperator)
{
	RepoBSON test = testBson;

	EXPECT_TRUE(test.toString() == testBson.toString());

	EXPECT_EQ(test.getFilesMapping().size(), testBson.getFilesMapping().size());
	
	//Test with bigfile mapping
	std::vector < uint8_t > in;

	in.resize(100);

	std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>> map, mapout;
	map["testingfile"] = std::pair<std::string, std::vector<uint8_t>>( "field", in);

	RepoBSON test2(testBson, map);


	mapout = test2.getFilesMapping();
	ASSERT_EQ(mapout.size(), map.size());
	
	auto mapIt = map.begin();
	auto mapoutIt = mapout.begin();

	for (; mapIt != map.end(); ++mapIt, ++mapoutIt)
	{
		EXPECT_EQ(mapIt->first, mapIt->first);
		EXPECT_EQ(mapIt->second.first, mapIt->second.first);
		std::vector<uint8_t> dataOut = mapoutIt->second.second;
		std::vector<uint8_t> dataIn = mapIt->second.second;
		EXPECT_EQ(dataOut.size(), dataIn.size());
		if (dataIn.size()>0)
			EXPECT_EQ(0, strncmp((char*)&dataOut[0], (char*)&dataIn[0], dataIn.size()));
	}

}
Exemplo n.º 3
0
TEST(RepoBSONFactoryTest, MakeMetaDataNodeTest)
{
	RepoBSON data = BSON("something" << "Something else" << "something2" << "somethingelse2");
	std::string mimeType = "application/x-mswrite";
	std::string name = "MetaTest";

	MetadataNode metaNode = RepoBSONFactory::makeMetaDataNode(data, mimeType, name);

	EXPECT_FALSE(metaNode.isEmpty());
	EXPECT_EQ(name, metaNode.getName());
	EXPECT_EQ(metaNode.getTypeAsEnum(), NodeType::METADATA);

	EXPECT_EQ(mimeType, metaNode.getStringField(REPO_LABEL_MEDIA_TYPE));

	EXPECT_EQ(data.toString(), metaNode.getObjectField(REPO_NODE_LABEL_METADATA).toString());
}