Пример #1
0
int main()
{
  Toy toto;
  Toy ET(Toy::ALIEN, "green", "./alien.txt");

  toto.setName("TOTO !");

  Toy moi = ET;
  if (toto.getType() == Toy::BASIC_TOY)
    std::cout << "basic toy: " << toto.getName() << std::endl;
  std::cout  << toto.getAscii() << std::endl;
  if (moi.getType() == Toy::ALIEN)
    std::cout << "this alien is: " << moi.getName() << std::endl
  	      << moi.getAscii() << std::endl;
  return 1337;
}
Пример #2
0
int main()
{
	// PICTURE
	Tester 	*tester = new Tester("Picture");
	Picture p;

	tester->test(p.data, std::string(""),
		"constructor without filename make an empty string");

	p.getPictureFromFile(std::string("file.test"));
	tester->test(p.data, std::string("this is a test\ncool"),
		"when a correct filename is provided, it correctly reads the file");

	p.getPictureFromFile(std::string("notExistingFile.test"));
	tester->test(p.data, std::string("ERROR"),
		"when there is an error, the string is set to ERROR");

	delete tester;
	// PICTURE

	// TOY
	tester = new Tester("Toy");
	Toy		t;

	tester->test(t.getType(), Toy::BASIC_TOY,
		"default constructor set the type to BASIC_TOY");
	tester->test(t.getName(), std::string("toy"),
		"default constructor set the name to toy");
	tester->test(t.getAscii(), std::string(""),
		"default constructor set the ascii to ''");

	Toy 	t2(Toy::ALIEN, std::string("E.T"), std::string("file.test"));

	tester->test(t2.getType(), Toy::ALIEN,
		"constructor set the type correctly");
	tester->test(t2.getName(), std::string("E.T"),
		"constructor set the name correctly");
	tester->test(t2.getAscii(), std::string("this is a test\ncool"),
		"constructor set the ascii correctly");

	t = t2;

	tester->test(t.getType(), t2.getType() ,
		"operator= set the type correctly");
	tester->test(t.getName(), t2.getName(),
		"operator= set the name correctly");
	tester->test(t.getAscii(), t2.getAscii(),
		"operator= set the ascii correctly");

	delete tester;
	// TOY

	// BUZZ + WOODY
	tester = new Tester("Buzz and Woody");

	Buzz 	buzz(std::string("foo"));
	Woody 	woody(std::string("bar"), std::string("file.test"));

	tester->test(buzz.getType(), Toy::BUZZ,
		"Buzz constructor (no file) set the type correctly");
	tester->test(buzz.getName(), std::string("foo"),
		"Buzz constructor (no file) set the name correctly");
	tester->test(buzz.getAscii(), std::string("Buzz !!!"),
		"Buzz constructor (no file) set the ascii correctly");	

	tester->test(woody.getType(), Toy::WOODY,
		"Woody constructor set the type correctly");
	tester->test(woody.getName(), std::string("bar"),
		"Woody constructor set the name correctly");
	tester->test(woody.getAscii(), std::string("this is a test\ncool"),
		"Woody constructor set the ascii correctly");


	tester->warn("The following tests cannot be unit tested, please check by hand");
	t.speak("I cannot unit test this... Does it work ? (toy)");
	buzz.speak("I cannot unit test this... Does it work ? (buzz)");
	woody.speak("I cannot unit test this... Does it work ? (woody)");

	delete tester;
	// BUZZ + WOODY

	// OPERATOR<<
	tester = new Tester("operator<<");

	t << "woohoo";

	tester->test(t.getAscii(), std::string("woohoo"),
		"operator<< with TOY and STRING");

	tester->warn("The following test cannot be unit tested, please check by hand");
	std::cout << t;

	delete tester;
	// OPERATOR<<

	return 0;
}
Пример #3
0
Toy::Toy(const Toy &c)
{
  this->Type = c.getType();
  this->Name = c.getName();
}
Пример #4
0
Toy::Toy(const Toy &ty) {
    _name = ty.getName();
    _pic.data = ty.getAscii();
    _type = ty.getType();
}
Пример #5
0
Toy::Toy(Toy const &cls)
{
  _type = cls.getType();
  _name = cls.getName();
  _picture = cls.getPicture();
}