void SqlBackendTest::allTests() { QString dbname = "test"; Classes::setup(); // Drop the database if already exists KProcess *proc = new KProcess; *proc << "dropdb"; *proc << dbname; proc->start(); proc->wait(); delete proc; // Create the database proc = new KProcess; *proc << "createdb"; *proc << dbname; CHECK( proc->start(), true ); proc->wait(); if ( ! proc->normalExit() || proc->exitStatus() != 0 ) { CHECK( true, false ); delete proc; return; } delete proc; QSqlDatabase *db = QSqlDatabase::addDatabase( "QPSQL7" ); db->setDatabaseName( dbname ); db->setUserName( "albert" ); db->setPassword( "" ); db->setHostName( "localhost" ); if ( ! db->open() ) { kdDebug() << "Failed to open database: " << db->lastError().text() << endl; return; } DbBackendIface *backend = new SqlDbBackend( db ); m_manager = new Manager( backend ); m_manager->createSchema(); transactions(); collections(); cache(); freeing(); testRelations(); delete m_manager; }
// if it's e.g. just 'www', try if it's a hostname in the local search domain bool LocalDomainURIFilter::isLocalDomainHost( QString& cmd ) const { // find() returns -1 when no match -> left()/truncate() are noops then QString host( cmd.left( cmd.find( '/' ) ) ); host.truncate( host.find( ':' ) ); // Remove port number if( !(host == last_host && last_time > time( NULL ) - 5 ) ) { QString helper = KStandardDirs::findExe(QString::fromLatin1( "klocaldomainurifilterhelper" )); if( helper.isEmpty()) return last_result = false; m_fullname = QString::null; KProcess proc; proc << helper << host; connect( &proc, SIGNAL(receivedStdout(KProcess *, char *, int)), SLOT(receiveOutput(KProcess *, char *, int)) ); if( !proc.start( KProcess::NotifyOnExit, KProcess::Stdout )) return last_result = false; last_host = host; last_time = time( (time_t *)0 ); last_result = proc.wait( 1 ) && proc.normalExit() && !proc.exitStatus(); if( !m_fullname.isEmpty() ) cmd.replace( 0, host.length(), m_fullname ); }
void MultipleBackendsTest::xml2sql() { QString dbname = "testmultiple"; // Drop the database if already exists KProcess *proc = new KProcess; *proc << "dropdb"; *proc << dbname; proc->start(); proc->wait(); delete proc; // Create the database proc = new KProcess; *proc << "createdb"; *proc << dbname; CHECK( proc->start(), true ); proc->wait(); if ( ! proc->normalExit() || proc->exitStatus() != 0 ) { CHECK( true, false ); delete proc; return; } delete proc; DbBackendIface *backend1 = new XmlDbBackend( "database.xml" ); Manager *manager1 = new Manager( backend1 ); manager1->createSchema(); QSqlDatabase *db = QSqlDatabase::addDatabase( "QPSQL7" ); db->setDatabaseName( dbname ); db->setUserName( "ak213" ); db->setPassword( "ak" ); db->setHostName( "localhost" ); if ( ! db->open() ) { kdDebug() << "Failed to open database: " << db->lastError().text() << endl; return; } DbBackendIface *backend2 = new SqlDbBackend( db ); Manager *manager2 = new Manager( backend2 ); manager2->createSchema(); manager1->copyTo( manager2 ); manager2->commit(); delete manager2; delete manager1; QSqlDatabase::removeDatabase( db ); }
void DeviceSettings::startDhcpcd() { KProcess startdhcpcd; startdhcpcd << "/sbin/dhcpcd" << _dev; startdhcpcd.start(); startdhcpcd.wait(); if ( !startdhcpcd.normalExit() ) printf( "failed (start)\n" ); }
void DynamicObjectsTest::allTests() { QString dbname = "testdynamic"; Classes::setup(); Classes::addClass( "Test", DynamicObject::createInstance, 0 ); ClassInfo *ci = Classes::classInfo( "Test" ); ci->addObject( "Customer", "Customer_Test", &Customer::createInstance ); ci->addCollection( "Article", "Article_Test" ); PropertyInfo *p; p = new PropertyInfo(); p->setName( "Property1" ); p->setType( QVariant::String ); ci->addProperty( p ); p = new PropertyInfo(); p->setName( "Property2" ); p->setType( QVariant::ULongLong ); ci->addProperty( p ); Classes::setupRelations(); // Drop the database if already exists KProcess *proc = new KProcess; *proc << "dropdb"; *proc << dbname; proc->start(); proc->wait(); delete proc; // Create the database proc = new KProcess; *proc << "createdb"; *proc << dbname; CHECK( proc->start(), true ); proc->wait(); if ( ! proc->normalExit() || proc->exitStatus() != 0 ) { CHECK( true, false ); delete proc; return; } delete proc; QSqlDatabase *db = QSqlDatabase::addDatabase( "QPSQL7" ); db->setDatabaseName( dbname ); db->setUserName( "ak213" ); db->setPassword( "ak" ); db->setHostName( "localhost" ); if ( ! db->open() ) { kdDebug() << "Failed to open database: " << db->lastError().text() << endl; return; } DbBackendIface *backend = new SqlDbBackend( db ); m_manager = new Manager( backend ); m_manager->setMaxObjects( 1 ); m_manager->createSchema(); ObjectRef<Customer> customer = Customer::create(); customer->setCustomerName( "Name of the customer" ); ObjectRef<Article> a1 = Article::create(); a1->setCode( "00001" ); ObjectRef<Article> a2 = Article::create(); a2->setCode( "00002" ); ObjectRef<Object> obj = Classes::classInfo( "Test" )->create(); CHECK( obj->property( "Property1" ).type(), QVariant::String ); CHECK( obj->property( "Property2" ).type(), QVariant::ULongLong ); CHECK( obj->containsObject( "Customer_Test" ), true ); CHECK( obj->containsCollection( "Article_Test" ), true ); obj->setProperty( "Property1", "Property number one" ); obj->setProperty( "Property2", 2 ); CHECK( obj->property( QString( "Property1" ) ).value().toString(), QString( "Property number one" ) ); CHECK( obj->property( QString( "Property2" ) ).value().toULongLong(), 2 ); obj->setObject( "Customer_Test", customer ); obj->collection( "Article_Test" )->add( a1 ); obj->collection( "Article_Test" )->add( a2 ); m_manager->commit(); CHECK( obj->property( "Property1" ).value().toString(), QString( "Property number one" ) ); delete m_manager; }
void DeviceSettings::slotApply() { bool succeed = true; /* Manual Settings */ if ( manualButton->isChecked() ) { // SET IP int ret = set_iface( _dev.ascii(), ipaddr->text().ascii(), // we can ommit broadcast and netmask. broadcast->text().length() ? broadcast->text().ascii() : 0, netmask->text().length() ? netmask->text().ascii() : 0 ); if ( ret < 0 ) succeed = false; // SET ROUTE if ( !defaultgw->text().isEmpty() ) { ret = set_default_route( defaultgw->text().ascii() ); if ( ret < 0 ) succeed = false; } ret = writeDnsList(); if ( ret < 0 ) succeed = false; } /* Automatic (DHCP) */ else if ( automaticButton->isChecked() ) { // I don't like to invoke programs directly // but we have no chance for now, // this is clearly a bad hack :(. QFile pidfile( "/var/run/dhcpcd-" + _dev + ".pid" ); if ( pidfile.exists() ) { KProcess killdhcpcd; killdhcpcd << "/sbin/dhcpcd" << "-k" << _dev; killdhcpcd.start(); killdhcpcd.wait(); // how ugly... wait 2 seconds to dhcpcd to finish its work... if ( killdhcpcd.normalExit() ) QTimer::singleShot( 2000, this, SLOT( startDhcpcd() ) ); else printf( "failed (kill)\n" ); } else startDhcpcd(); } writeSettings(); if ( succeed ) { QString msg = i18n( "Successfully configured device: " ) + _dev; KMessageBox::information( this, msg, i18n( "Done!" ) ); } else { QString msg = i18n( "Failed to configure device: " ) + _dev; KMessageBox::error( this, msg, i18n( "Error!" ) ); } done( 0 ); }