示例#1
0
int main()
{
	plusminus obj1(4, 7) ;
	std::cout << "Printing obj1" << std::endl ;
	obj1.print();

//	-obj1 ;
//	std::cout << "Printing obj1" << std::endl ;
//	std::cout << obj1.getter1() << " " << obj1.getter2() << " " << std::endl ;
//	obj1.print();

	plusminus obj2(5, 1) ;
	std::cout << "Printing obj2" << std::endl ;
	obj2.print();
	
	
	std::cout << "Printing obj1 + obj2" << std::endl ;
	(obj1 + obj2).print();

	std::cout << "Printing obj1" << std::endl ;
	(obj1).print();

//	std::cout << "Printing obj3 - obj4" << std::endl ;
//	plusminus obj3(5 , 10);
//	plusminus obj4(10 , 10);
//	(obj3 - obj4).print() ;
	
	plusminus obj5(44, 23);
	plusminus obj6(11, 22);
	plusminus obj7(0, 0);

	obj7 = (obj5 - obj6) ;
	std::cout << "Printing obj7" << std::endl ;
	obj7.print();

	plusminus obj8 = -obj6 ;
	std::cout << "Printing obj8" << std::endl ;
	obj8.print();

	//	std::cout << "Printing -obj1" << std::endl ;
//	std::cout << -obj1.getter1() << " " << -obj1.getter2() << std::endl ;
//	(-obj1).print();
//	std::cout << std::endl ;

//	plusminus obj2 ;
//	obj2 = -obj1 ;
//	plusminus obj3 = -obj1 ;

//	std::cout << "Printing obj1" << std::endl ;
//	std::cout << obj1.getter1() << " " << obj1.getter2() << std::endl ;
//	std::cout << std::endl ;


//	std::cout << "Printing obj3" << std::endl ;
//	std::cout << obj3.getter1() << " " << obj.getter2() << std::endl ;
//	std::cout << std::endl ;
}
示例#2
0
void tst_QSqlError::construction()
{
   QSqlError obj1("drivertext", "databasetext", QSqlError::UnknownError, 123);
   QCOMPARE(obj1.driverText(), QString("drivertext"));
   QCOMPARE(obj1.databaseText(), QString("databasetext"));
   QCOMPARE(obj1.type(), QSqlError::UnknownError);
   QCOMPARE(obj1.number(), 123);
   QCOMPARE(obj1.nativeErrorCode(), QStringLiteral("123"));
   QVERIFY(obj1.isValid());

   QSqlError obj2(obj1);
   QCOMPARE(obj2.driverText(), obj1.driverText());
   QCOMPARE(obj2.databaseText(), obj1.databaseText());
   QCOMPARE(obj2.type(), obj1.type());
   QCOMPARE(obj2.number(), obj1.number());
   QCOMPARE(obj2.nativeErrorCode(), obj1.nativeErrorCode());
   QVERIFY(obj2.isValid());

   QSqlError obj3 = obj2;
   QCOMPARE(obj3.driverText(), obj2.driverText());
   QCOMPARE(obj3.databaseText(), obj2.databaseText());
   QCOMPARE(obj3.type(), obj2.type());
   QCOMPARE(obj3.number(), obj2.number());
   QCOMPARE(obj3.nativeErrorCode(), obj2.nativeErrorCode());
   QVERIFY(obj3.isValid());

   QSqlError obj4;
   QVERIFY(!obj4.isValid());
   QCOMPARE(obj4.driverText(), QString());
   QCOMPARE(obj4.databaseText(), QString());
   QCOMPARE(obj4.type(), QSqlError::NoError);
   QCOMPARE(obj4.number(), -1);
   QCOMPARE(obj4.nativeErrorCode(), QString());

   QSqlError obj5(QStringLiteral("drivertext"), QStringLiteral("databasetext"),
                  QSqlError::UnknownError, QStringLiteral("123"));
   QCOMPARE(obj5.driverText(), QString("drivertext"));
   QCOMPARE(obj5.databaseText(), QString("databasetext"));
   QCOMPARE(obj5.type(), QSqlError::UnknownError);
   QCOMPARE(obj5.number(), 123);
   QCOMPARE(obj5.nativeErrorCode(), QStringLiteral("123"));
   QVERIFY(obj5.isValid());

   QSqlError obj6(QStringLiteral("drivertext"), QStringLiteral("databasetext"),
                  QSqlError::UnknownError, QStringLiteral("Err123"));
   QCOMPARE(obj6.driverText(), QString("drivertext"));
   QCOMPARE(obj6.databaseText(), QString("databasetext"));
   QCOMPARE(obj6.type(), QSqlError::UnknownError);
   QCOMPARE(obj6.number(), 0);
   QCOMPARE(obj6.nativeErrorCode(), QStringLiteral("Err123"));
   QVERIFY(obj6.isValid());

   // Default constructed object as constructed before Qt 5.3
   QSqlError obj7(QString(), QString(), QSqlError::NoError, -1);
   QVERIFY(!obj7.isValid());
   QCOMPARE(obj7.driverText(), QString());
   QCOMPARE(obj7.databaseText(), QString());
   QCOMPARE(obj7.type(), QSqlError::NoError);
   QCOMPARE(obj7.number(), -1);
   QCOMPARE(obj7.nativeErrorCode(), QString());

}