Example #1
0
void GenericAttributeTest::testBool() {
	const bool value = true;
	{ // Direct construction
		Util::BoolAttribute boolAttribute(value);
		testBoolGetters(boolAttribute, value, "true");

		const bool secondValue = false;
		boolAttribute.set(secondValue);
		testBoolGetters(boolAttribute, secondValue, "false");

		const bool thirdValue = true;
		boolAttribute = Util::BoolAttribute(thirdValue);
		testBoolGetters(boolAttribute, thirdValue, "true");
	}
	{ // Specific factory
		std::unique_ptr<Util::BoolAttribute> boolAttribute(Util::GenericAttribute::createBool(value));
		testBoolGetters(*boolAttribute, value, "true");

		const bool valueXor = value ^ value;
		boolAttribute->set(valueXor);
		testBoolGetters(*boolAttribute, valueXor, "false");

		std::unique_ptr<Util::BoolAttribute> clonedBoolAttribute(boolAttribute->clone());
		CPPUNIT_ASSERT(*boolAttribute == *clonedBoolAttribute);
		boolAttribute.reset();

		testBoolGetters(*clonedBoolAttribute, valueXor, "false");
	}
	{ // Generic factory
		std::unique_ptr<Util::GenericAttribute> genericBoolAttribute(Util::GenericAttribute::create(value));
		CPPUNIT_ASSERT(genericBoolAttribute->isA<Util::BoolAttribute>());
		CPPUNIT_ASSERT_EQUAL(value, genericBoolAttribute->toType<Util::BoolAttribute>()->get());
		CPPUNIT_ASSERT_EQUAL(true, genericBoolAttribute->toBool());
		CPPUNIT_ASSERT_EQUAL(static_cast<int>(value), genericBoolAttribute->toInt());
		CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(value), genericBoolAttribute->toUnsignedInt());
		CPPUNIT_ASSERT_EQUAL(static_cast<float>(value), genericBoolAttribute->toFloat());
		CPPUNIT_ASSERT_EQUAL(static_cast<double>(value), genericBoolAttribute->toDouble());
		CPPUNIT_ASSERT_EQUAL(std::string("true"), genericBoolAttribute->toString());
	}
}
	bool CLibraryParse_dcomImpl::ParseLibrary( XMLNode& xml, TLibrary& lib )
	{
		// parsing beans
		int i, pos, n = 0;
		XMLCSTR  beanDelayLoad = xml.getAttribute(_T("delayload"));
		if (!beanDelayLoad)
		{
			beanDelayLoad = _T("false");
		}
		lib.bDelayLoad = boolAttribute(beanDelayLoad);
		XMLCSTR  beanTag = _T("bean");
		XMLNode beans = xml.getChildNode(_T("beans"));

		n = beans.nChildNode(beanTag);
		DXMLPARSEFAILD(n, "beans is null");
		for (pos = 0, i = 0; i < n; i++)
		{
			auto   spBean = make_shared<TBean>();
			XMLNode beanNode = beans.getChildNode(beanTag, &pos);
			parseBean(beanNode, spBean);
			lib.vecBeans.push_back(spBean);
		}
		return true;
	}