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


C++ NameValueCollection::size方法代码示例

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


在下文中一共展示了NameValueCollection::size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

TEST(MessageHeader, testSplitParameters)
{
	std::string s;
	std::string v;
	NameValueCollection p;
	
	MessageHeader::splitParameters(s, v, p);
	EXPECT_TRUE (v.empty());
	EXPECT_TRUE (p.empty());
	
	s = "multipart/related";
	MessageHeader::splitParameters(s, v, p);
	EXPECT_TRUE (v == "multipart/related");
	EXPECT_TRUE (p.empty());
	
	s = "multipart/related; boundary=MIME_boundary_01234567";
	MessageHeader::splitParameters(s, v, p);
	EXPECT_TRUE (v == "multipart/related");
	EXPECT_TRUE (p.size() == 1);
	EXPECT_TRUE (p["boundary"] == "MIME_boundary_01234567");
	
	s = "multipart/related; boundary=\"MIME_boundary_76543210\"";
	MessageHeader::splitParameters(s, v, p);
	EXPECT_TRUE (v == "multipart/related");
	EXPECT_TRUE (p.size() == 1);
	EXPECT_TRUE (p["boundary"] == "MIME_boundary_76543210");
	
	s = "text/plain; charset=us-ascii";
	MessageHeader::splitParameters(s, v, p);
	EXPECT_TRUE (v == "text/plain");
	EXPECT_TRUE (p.size() == 1);
	EXPECT_TRUE (p["charset"] == "us-ascii");
	
	s = "value; p1=foo; p2=bar";
	MessageHeader::splitParameters(s, v, p);
	EXPECT_TRUE (v == "value");
	EXPECT_TRUE (p.size() == 2);
	EXPECT_TRUE (p["p1"] == "foo");
	EXPECT_TRUE (p["p2"] == "bar");
	
	s = "value; p1=\"foo; bar\"";
	MessageHeader::splitParameters(s, v, p);
	EXPECT_TRUE (v == "value");
	EXPECT_TRUE (p.size() == 1);
	EXPECT_TRUE (p["p1"] == "foo; bar");	

	s = "value ; p1=foo ; p2=bar ";
	MessageHeader::splitParameters(s, v, p);
	EXPECT_TRUE (v == "value");
	EXPECT_TRUE (p.size() == 2);
	EXPECT_TRUE (p["p1"] == "foo");
	EXPECT_TRUE (p["p2"] == "bar");
}
开发者ID:ichenq,项目名称:PocoNet,代码行数:53,代码来源:MessageHeaderTest.cpp

示例2: testNameValueCollection

void NameValueCollectionTest::testNameValueCollection()
{
	NameValueCollection nvc;
	
	assert (nvc.empty());
	assert (nvc.size() == 0);
	
	nvc.set("name", "value");
	assert (!nvc.empty());
	assert (nvc["name"] == "value");
	assert (nvc["Name"] == "value");
	
	nvc.set("name2", "value2");
	assert (nvc.get("name2") == "value2");
	assert (nvc.get("NAME2") == "value2");
	
	assert (nvc.size() == 2);
	
	try
	{
		std::string value = nvc.get("name3");
		fail("not found - must throw");
	}
	catch (NotFoundException&)
	{
	}

	try
	{
		std::string value = nvc["name3"];
		fail("not found - must throw");
	}
	catch (NotFoundException&)
	{
	}
	
	assert (nvc.get("name", "default") == "value");
	assert (nvc.get("name3", "default") == "default");

	assert (nvc.has("name"));
	assert (nvc.has("name2"));
	assert (!nvc.has("name3"));	
	
	nvc.add("name3", "value3");
	assert (nvc.get("name3") == "value3");
	
	nvc.add("name3", "value31");
	
	NameValueCollection::ConstIterator it = nvc.find("Name3");
	assert (it != nvc.end());
	std::string v1 = it->second;
	assert (it->first == "name3");
	++it;
	assert (it != nvc.end());
	std::string v2 = it->second;
	assert (it->first == "name3");
	
	assert ((v1 == "value3" && v2 == "value31") || (v1 == "value31" && v2 == "value3"));
	
	nvc.erase("name3");
	assert (!nvc.has("name3"));
	assert (nvc.find("name3") == nvc.end());
	
	it = nvc.begin();
	assert (it != nvc.end());
	++it;
	assert (it != nvc.end());
	++it;
	assert (it == nvc.end());
	
	nvc.clear();
	assert (nvc.empty());
	
	assert (nvc.size() == 0);
}
开发者ID:cshnick,项目名称:CommunicationModel,代码行数:75,代码来源:NameValueCollectionTest.cpp


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