コード例 #1
0
bool IOPlatformExpert::configure( IOService * provider )
{
    OSSet *		topLevel;
    OSDictionary *	dict;
    IOService * 	nub;

    topLevel = OSDynamicCast( OSSet, getProperty("top-level"));

    if( topLevel) {
        while( (dict = OSDynamicCast( OSDictionary,
				topLevel->getAnyObject()))) {
            dict->retain();
            topLevel->removeObject( dict );
            nub = createNub( dict );
            if( 0 == nub)
                continue;
            dict->release();
            nub->attach( this );
            nub->registerService();
        }
    }

    return( true );
}
コード例 #2
0
ファイル: TestCollections.cpp プロジェクト: JackieXie168/xnu
void testIterator()
{
    bool res = true;
    void *spaceCheck;
    OSObject *cache[numStrCache];
    OSString *str = 0;
    const OSSymbol *symCache[numStrCache], *sym;
    OSDictionary *dict;
    OSSet *set;
    OSArray *array, *bigReturn;
    OSCollectionIterator *iter1, *iter2;
    int i, numSymbols, count1, count2, count3;

    // Setup symbol and string pools
    for (i = 0, numSymbols = 0; i < numStrCache; i++) {
        sym = OSSymbol::withCStringNoCopy(strCache[i]);
        if (1 == sym->getRetainCount()) {
            cache[numSymbols] = OSString::withCStringNoCopy(strCache[i]);
            symCache[numSymbols] = sym;
            numSymbols++;
        }
        else
            sym->release();
    }

    // Test the array iterator
    spaceCheck = checkPointSpace();
    iter1 = iter2 = 0;
    array = OSArray::withCapacity(numSymbols);
    TEST_ASSERT('I', "1a", array);
    if (array) {
        count1 = count2 = 0;
        for (i = numSymbols; --i >= 0; )
            count1 += array->setObject(cache[i], 0);
        TEST_ASSERT('I', "1b", count1 == numSymbols);

        iter1 = OSCollectionIterator::withCollection(array);
        iter2 = OSCollectionIterator::withCollection(array);
    }
    TEST_ASSERT('I', "1c", iter1);
    TEST_ASSERT('I', "1d", iter2);
    if (iter1 && iter2) {
        count1 = count2 = count3 = 0;
        for (i = 0; (str = (IOString *) iter1->getNextObject()); i++) {
            bigReturn = iter2->nextEntries();
            count1 += (bigReturn->getCount() == 1);
            count2 += (cache[i] == bigReturn->getObject(0));
            count3 += (cache[i] == str);
        }
        TEST_ASSERT('I', "1e", count1 == numSymbols);
        TEST_ASSERT('I', "1f", count2 == numSymbols);
        TEST_ASSERT('I', "1g", count3 == numSymbols);
        TEST_ASSERT('I', "1h", iter1->valid());
        TEST_ASSERT('I', "1i", iter2->valid());

        iter1->reset();
        str = (OSString *) array->__takeObject(0);
        array->setObject(str, 0);
        str->release();
        TEST_ASSERT('I', "1j", !iter1->getNextObject());
        TEST_ASSERT('I', "1k", !iter1->valid());

        iter1->reset();
        count1 = count2 = count3 = 0;
        for (i = 0; ; i++) {
            if (i & 1)
                str = (OSString *) iter1->getNextObject();
            else if ( (bigReturn = iter1->nextEntries()) )
                str = (OSString *) bigReturn->getObject(0);
            else
                str = 0;

            if (!str)
                break;
            count1 += (cache[i] == str);
        }
        TEST_ASSERT('I', "1l", count1 == numSymbols);
        TEST_ASSERT('I', "1m", i == numSymbols);
        TEST_ASSERT('I', "1n", iter1->valid());

        TEST_ASSERT('I', "1o", 3 == array->getRetainCount());
        array->release();
    }

    if (iter1) iter1->release();
    if (iter2) iter2->release();
    res = res && checkSpace("(I)1", spaceCheck, 0);

    // Test the set iterator
    spaceCheck = checkPointSpace();
    iter1 = 0;
    set = OSSet::withCapacity(numSymbols);
    TEST_ASSERT('I', "2a", set);
    if (set) {
        count1 = count2 = 0;
        for (i = 0; i < numSymbols; i++)
            count1 += set->setObject(cache[i]);
        TEST_ASSERT('I', "2b", count1 == numSymbols);

        iter1 = OSCollectionIterator::withCollection(set);
        iter2 = OSCollectionIterator::withCollection(set);
    }
    TEST_ASSERT('I', "2c", iter1);
    TEST_ASSERT('I', "2d", iter2);
    if (iter1 && iter2) {
        count1 = count2 = count3 = 0;
        for (i = 0; (str = (IOString *) iter1->getNextObject()); i++) {
            bigReturn = iter2->nextEntries();
            count1 += (bigReturn->getCount() == 1);
            count2 += (cache[i] == bigReturn->getObject(0));
            count3 += (cache[i] == str);
        }
        TEST_ASSERT('I', "2e", count1 == numSymbols);
        TEST_ASSERT('I', "2f", count2 == numSymbols);
        TEST_ASSERT('I', "2g", count3 == numSymbols);
        TEST_ASSERT('I', "2h", iter1->valid());
        TEST_ASSERT('I', "2i", iter2->valid());

        iter1->reset();
        count1 = count2 = count3 = 0;
        for (i = 0; ; i++) {
            if (i & 1)
                str = (OSString *) iter1->getNextObject();
            else if ( (bigReturn = iter1->nextEntries()) )
                str = (OSString *) bigReturn->getObject(0);
            else
                str = 0;

            if (!str)
                break;
            count1 += (cache[i] == str);
        }
        TEST_ASSERT('I', "2l", count1 == numSymbols);
        TEST_ASSERT('I', "2m", i == numSymbols);
        TEST_ASSERT('I', "2n", iter1->valid());

        iter1->reset();
        str = (OSString *) set->getAnyObject();
        (void) set->__takeObject(str);
        set->setObject(str);
        str->release();
        TEST_ASSERT('I', "2j", !iter1->getNextObject());
        TEST_ASSERT('I', "2k", !iter1->valid());

        TEST_ASSERT('I', "2o", 3 == set->getRetainCount());
        set->release();
    }

    if (iter1) iter1->release();
    if (iter2) iter2->release();
    res = res && checkSpace("(I)2", spaceCheck, 0);

    // Test the dictionary iterator
    spaceCheck = checkPointSpace();
    iter1 = 0;
    dict = OSDictionary::withCapacity(numSymbols);
    TEST_ASSERT('I', "3a", dict);
    if (dict) {
        count1 = count2 = 0;
        for (i = 0; i < numSymbols; i++)
            count1 += (0 != dict->setObject(cache[i], symCache[i]));
        TEST_ASSERT('I', "3b", count1 == numSymbols);

        iter1 = OSCollectionIterator::withCollection(dict);
        iter2 = OSCollectionIterator::withCollection(dict);
    }
    TEST_ASSERT('I', "3c", iter1);
    TEST_ASSERT('I', "3d", iter2);
    if (iter1 && iter2) {
        count1 = count2 = count3 = 0;
        for (i = 0; (sym = (const IOSymbol *) iter1->getNextObject()); i++) {
            bigReturn = iter2->nextEntries();
            count1 += (bigReturn->getCount() == 2);
            count2 += (cache[i] == bigReturn->getObject(1));
            count3 += (symCache[i] == sym);
        }
        TEST_ASSERT('I', "3e", count1 == numSymbols);
        TEST_ASSERT('I', "3f", count2 == numSymbols);
        TEST_ASSERT('I', "3g", count3 == numSymbols);
        TEST_ASSERT('I', "3h", iter1->valid());
        TEST_ASSERT('I', "3i", iter2->valid());

        iter1->reset();
        count1 = count2 = count3 = 0;
        i = 0;
        for (i = 0; ; i++) {
            if (i & 1) {
                sym = (const OSSymbol *) iter1->getNextObject();
                str = 0;
            }
            else if ( (bigReturn = iter1->nextEntries()) ) {
                sym = (const OSSymbol *) bigReturn->getObject(0);
                str = (OSString *) bigReturn->getObject(1);
            }
            else
                sym = 0;

            if (!sym)
                break;

            count1 += (symCache[i] == sym);
            count2 += (!str || cache[i] == str);
        }
        TEST_ASSERT('I', "3l", count1 == numSymbols);
        TEST_ASSERT('I', "3m", count2 == numSymbols);
        TEST_ASSERT('I', "3n", i == numSymbols);
        TEST_ASSERT('I', "3o", iter1->valid());

        iter1->reset();
        str = (OSString *) dict->__takeObject(symCache[numSymbols-1]);
        dict->setObject(str, symCache[numSymbols-1]);
        str->release();
        TEST_ASSERT('I', "3j", !iter1->getNextObject());
        TEST_ASSERT('I', "3k", !iter1->valid());

        TEST_ASSERT('I', "3p", 3 == dict->getRetainCount());
        dict->release();
    }

    if (iter1) iter1->release();
    if (iter2) iter2->release();
    res = res && checkSpace("(I)3", spaceCheck, 0);

    count1 = count2 = count3 = 0;
    for (i = 0; i < numSymbols; i++) {
        count1 += (1 == cache[i]->getRetainCount());
        count2 += (1 == symCache[i]->getRetainCount());
        cache[i]->release();
        symCache[i]->release();
    }
    TEST_ASSERT('I', "4a", count1 == numSymbols);
    TEST_ASSERT('I', "4b", count2 == numSymbols);

    if (res)
        verPrintf(("testIterator: All OSCollectionIterator Tests passed\n"));
    else
        logPrintf(("testIterator: Some OSCollectionIterator Tests failed\n"));
}