コード例 #1
0
void MacroTests::testMacro()
{
	kdDebug()<<"===================== testMacro() ======================" << endl;

	QDomElement const domelement = d->doomdocument->documentElement();
	
	KSharedPtr<KoMacro::Macro> macro1 = KoMacro::Manager::self()->createMacro("testMacro");
	KSharedPtr<KoMacro::Macro> macro2 = KoMacro::Manager::self()->createMacro("testMacro");
	//Is our XML parseable ?
	KOMACROTEST_ASSERT(macro1->parseXML(domelement),true);
	KOMACROTEST_ASSERT(macro2->parseXML(domelement),true);

	//check that it is not null
	KOMACROTEST_XASSERT(sizetype(macro1.data()), sizetype(0));
	KOMACROTEST_XASSERT(sizetype(macro2.data()), sizetype(0));

	//check macro1 == macro2
	KOMACROTEST_ASSERT(macro1->name(), macro2->name() );

	//create list of KsharedPtr from the childs of the macro	
	QValueList< KSharedPtr<KoMacro::MacroItem> >& items1 = macro1->items();
	QValueList< KSharedPtr<KoMacro::MacroItem> >& items2 = macro2->items();
	
	//check that there is one
	KOMACROTEST_XASSERT( items1.count(), sizetype(0) );	
	KOMACROTEST_XASSERT( items2.count(), sizetype(0) );	

	//check macro1 == macro2	
	KOMACROTEST_ASSERT( items1.count(), items2.count() );
	
	//check the name
	KOMACROTEST_ASSERT( QString(macro1->name()), QString("testMacro") );
	
	{
		const QString tmp1 = QString("test");
		macro1->setName(tmp1);

		//check the name changed
		KOMACROTEST_XASSERT( QString(macro1->name()), QString("testMacro") );	
		//check the name
		KOMACROTEST_ASSERT( QString(macro1->name()), QString("test") );
	}
	
	//fetch the first one
	KSharedPtr<KoMacro::Action> actionptr = items1[0]->action();
	//check that it is not null
	KOMACROTEST_XASSERT(sizetype(actionptr.data()), sizetype(0));
	//check that it has the right name
	KOMACROTEST_ASSERT( QString(actionptr->name()), QString("testaction") );
	//check that it has the right text
	KOMACROTEST_ASSERT( actionptr->text(), QString("Test") );

	//try to clear items
	macro1->clearItems();
	//get items
	items1 = macro1->items();
	//check that they are deleted
	KOMACROTEST_ASSERT( items1.count(), sizetype(0) );
}
コード例 #2
0
ファイル: ksharedptrtest.cpp プロジェクト: vasi/kdelibs
void KSharedPtrTest::testDifferentTypes()
{
	dtor_called = 0;
	{
		Derived* obj = new Derived;
		KSharedPtr<Base> ptrBase(obj);
		// then we call some method that takes a KSharedPtr<Base> as argument
		// and there we downcast again:
		KSharedPtr<Derived> ptrDerived = KSharedPtr<Derived>::staticCast( ptrBase );
		QCOMPARE( dtor_called, 0 ); // no dtor called yet
		QCOMPARE( ptrDerived.data(), obj );

		// now test assignment operator
		ptrDerived = KSharedPtr<Derived>::dynamicCast( ptrBase );
		QCOMPARE( dtor_called, 0 ); // no dtor called yet
		QCOMPARE( ptrDerived.data(), obj );
	}
	QCOMPARE( dtor_called, 1 );
}
コード例 #3
0
ファイル: plasmahandlers.cpp プロジェクト: KDE/korundum
void marshall_PackageStructurePtr(Marshall *m) {
    switch(m->action()) {
    case Marshall::FromVALUE: 
    {
        break;
    }

    case Marshall::ToVALUE: 
    {
        KSharedPtr<Plasma::PackageStructure> *ptr = new KSharedPtr<Plasma::PackageStructure>(*(KSharedPtr<Plasma::PackageStructure>*)m->item().s_voidp);
        if (ptr == 0) {
            *(m->var()) = Qnil;
            break;
        }
        Plasma::PackageStructure * package = ptr->data();
 
        VALUE obj = getPointerObject(package);
        if (obj == Qnil) {
            smokeruby_object  * o = ALLOC(smokeruby_object);
            o->smoke = m->smoke();
            o->classId = m->smoke()->idClass("Plasma::PackageStructure").index;
            o->ptr = package;
            o->allocated = false;
            obj = set_obj_info("Plasma::PackageStructure", o);
        }

        *(m->var()) = obj;		

        if (m->cleanup()) {
        }
        break;
    }

    default:
        m->unsupported();
        break;
    }
}