M
magnus.moraberg
Hi,
I'm testing a class who's objects relate to nodes within an xml file.
For example, my Class called "FireNode" has an object which relates to
this line in my xml doc -
<FireNode DEF='FireNode' firstField = '64 128 192 255' secondField =
'1 2 3 4'></FireNode>
I can also create an object and initialize it as follows -
auto_ptr<Node> node = populateNodeFromXmlFile("fireNode.xml");
FireNode* fireNode = dynamic_cast<FireNode*>(node.get());
where fireNode.xml contains only that xml line presented above and
populateNodeFromXmlFile is a static function provided my the api I'm
using.
In order to test FireNode, I what to carry out unit tests on objects
which I can initialize using different versions of "fireNode.xml".
However, there is also this static function available with the API -
populateNodeFromSTRING("<FireNode DEF=\'FireNode\' firstField = \'64
128 192 255\' secondField = \'1 2 3 4\'></FireNode>");
I like this function because it means that I have my xml code directly
in the c++ code and it will be easier for me to keep an eye on what
I'm testing. However, I don't like that I have to escape quotes etc.
In python you can do this -
str = r"<FireNode DEF='FireNode' firstField = '64 128 192 255'
secondField = '1 2 3 4'></FireNode>"
and eveything gets automatically escaped. C# has something similar. Is
there anyway of doing this is C++ or any suggestions of what I could
do?
Thanks,
Barry
I'm testing a class who's objects relate to nodes within an xml file.
For example, my Class called "FireNode" has an object which relates to
this line in my xml doc -
<FireNode DEF='FireNode' firstField = '64 128 192 255' secondField =
'1 2 3 4'></FireNode>
I can also create an object and initialize it as follows -
auto_ptr<Node> node = populateNodeFromXmlFile("fireNode.xml");
FireNode* fireNode = dynamic_cast<FireNode*>(node.get());
where fireNode.xml contains only that xml line presented above and
populateNodeFromXmlFile is a static function provided my the api I'm
using.
In order to test FireNode, I what to carry out unit tests on objects
which I can initialize using different versions of "fireNode.xml".
However, there is also this static function available with the API -
populateNodeFromSTRING("<FireNode DEF=\'FireNode\' firstField = \'64
128 192 255\' secondField = \'1 2 3 4\'></FireNode>");
I like this function because it means that I have my xml code directly
in the c++ code and it will be easier for me to keep an eye on what
I'm testing. However, I don't like that I have to escape quotes etc.
In python you can do this -
str = r"<FireNode DEF='FireNode' firstField = '64 128 192 255'
secondField = '1 2 3 4'></FireNode>"
and eveything gets automatically escaped. C# has something similar. Is
there anyway of doing this is C++ or any suggestions of what I could
do?
Thanks,
Barry