Example #1
0
void
CCar::clone_into (CDatabase &db) const
{
	for (int i = 0; i < m_LogNr; i++)
	{
		const TLog &log = m_Log[i];
		db.Add (log.m_Date,
			log.m_Driver->m_Name, log.m_Driver->m_Surname, m_RZ);
	}
}
Example #2
0
int
main (int argc, char *argv[])
{
	CDatabase *a, *b, *c;

	a = new CDatabase;
	assert (a->Add ("2012-03-01", "John", "Nowak", "ABC-12-34"));
	assert (a->Add ("2012-03-02", "John", "Nowak", "ABC-12-34"));
	assert (a->Add ("2012-03-03", "John", "Nowak", "DEF-56-67"));
	assert (a->Add ("2012-03-02", "George", "Smith", "DEF-56-67"));

	cout << *a;
	cout << a->FindCar ("ABC-12-34");
	cout << a->FindDriver ("John", "Nowak");

	try {
		cout << a->FindCar ("XYZ-99-88");
		abort ();
	} catch (const InvalidCarException &e) {
		ostringstream ss;
		ss << e;
		assert (ss.str () == "XYZ-99-88");
	}

	try {
		cout << a->FindDriver ("John", "Smith");
		abort ();
	} catch (const InvalidDriverException &e) {
		ostringstream ss;
		ss << e;
		assert (ss.str () == "John Smith");
	}

	delete a;


	a = new CDatabase;
	assert (a->Add ("2012-03-01", "John", "Nowak", "ABC-12-34"));
	assert (a->Add ("2012-03-02", "George", "Smith", "DEF-56-67"));
	cout << *a;
	assert (!a->Add ("2012-03-01", "John", "Nowak", "XYZ-99-99"));
	assert (!a->Add ("2012-03-02", "Peter", "McDonald", "DEF-56-67"));
	cout << *a;

	delete a;


	a = new CDatabase;
	b = new CDatabase;
	assert (a->Add ("2012-03-01", "John", "Nowak", "ABC-12-34"));
	assert (a->Add ("2012-03-02", "John", "Nowak", "DEF-56-67"));
	assert (a->Add ("2012-03-01", "George", "Smith", "DEF-56-67"));
	assert (a->Add ("2012-03-02", "George", "Smith", "ABC-12-34"));
	cout << *a;

	*b = *a;
	c = new CDatabase (*a);
	assert (b->Add ("2012-03-03", "Homer", "Simpson", "ABC-12-34"));
	assert (c->Add ("2012-03-03", "Homer", "Simpson", "DEF-56-67"));
	delete a;
	cout << *b;
	cout << *c;

	delete b;
	delete c;


	CDatabase *db;

	db = new CDatabase;
	const char *names[] = {"A", "B", "C", "D", "E", "F"};
	char buf[40];
	srand (8);
	for (int i = 1000; i < 2000; i++)
	{
		string rz = "ABC-";
		sprintf (buf, "%d", rand () % 100);
		rz += buf;

		string name (names[rand () % 6]);
		string surname (names[rand () % 6]);

		string date = "2012-";
		sprintf (buf, "%d", i);
		date += buf;

		db->Add (date, name, surname, rz);
	}

	ostringstream outa, outb;
	outa << *db;
	outb << CDatabase (*db);
	assert (outa.str () == outb.str ());

	delete db;

	return 0;
}