#include "Foo.h" #include int main (int argc, char **argv) { { FooBase base ("12345"); assert (5 == base.getLength ()); FooBase *copy = base.clone (); assert (5 == copy->getLength ()); delete copy; } { FooChild *child = new FooChild ("12345"); assert (0 == child->getCalls ()); int length = child->getLength (); assert (9 == length); assert (1 == child->getCalls ()); FooBase *copy = child->clone (); delete child; length = copy->getLength (); assert (9 == length); FooChild *childcopy = dynamic_cast < FooChild * >(copy); assert (2 == childcopy->getCalls ()); delete copy; } { try { FooChild (""); // should throw exception assert (0); } catch (FooBase::BadArg) { } } { FooBase base ("1234567890"); // Maximum length FooChild child (std::string ("123456")); // Maximum length } { try { FooBase base ("12345678901"); // Too long assert (0); } catch (FooBase::BadArg) { } try { FooChild child ("1234567"); // Too long after adjustment assert (0); } catch (FooBase::BadArg) { } } }