Exemplo n.º 1
0
void MenuTreeTest::runTests()
{
  menuTree->build();
  WsTreeSerializer mts(menuTree);
  assert(mts.serialize() == SUCCESS);
  WsTreeDeserializer mtds(mts.getSerializedForm());
  assert(mtds.deserialize() == SUCCESS);
  cout << "Path for root in " << mtds.getMenuRoot()->getFullPath() << endl;
  assert(mtds.getMenuRoot()->getPath() == "/");
  assert( mtds.getMenuRoot()->getDirectories().size() == 2);
  WsDirNode* root = static_cast<WsDirNode*>(mtds.getMenuRoot());
  WsDirNode* test1 = static_cast<WsDirNode*>(root->getDirectories().front());
  assert(test1->getName() == "test1");
  assert(test1->getDirectories().size() == 3);
  WsDirNode* test3 = static_cast<WsDirNode*>(root->getDirectories().back());
  assert(test3->getName() == "test3");
  assert(test3->getDirectories().size() == 0);
  set<string> groups;
  groups.insert("Guest");
  string p("test1/");
  WsDirContentsSerializer dcs(fsTree , groups, p );
  assert(dcs.serialize() == SUCCESS);
  WsDirContentsDeserializer dcds(dcs.getSerializedForm());
  dcds.deserialize();
  assert(dcds.getContents().size() == 2);
  WsDirNode* products = static_cast<WsDirNode*>(dcds.getContents().front());
  assert( products->getName() == "products");
  WsDirNode* references = static_cast<WsDirNode*>(dcds.getContents().back());
  assert( references->getName() == "references");
  assert(products->getDirectories().size() == 0);
}
Exemplo n.º 2
0
Arquivo: find.cpp Projeto: noj/CodeDB
void find(const bfs::path& cdb_path, const options& opt)
{
    config cfg = load_config(cdb_path / "config");

    const bfs::path cdb_root = cdb_path.parent_path();
    const bfs::path search_root = bfs::initial_path();

    std::size_t prefix_size = 0;
    std::string file_match;
    if(opt.m_options.count("-a") == 0 && search_root != cdb_root)
    {
        file_match = "^" + escape_regex(
            search_root.generic_string().substr(cdb_root.string().size() + 1) + "/") + ".*";
        prefix_size = search_root.string().size() - cdb_root.string().size();
    }

    file_lock lock(cdb_path / "lock");
    lock.lock_sharable();

    const char* find_regex_options =
        opt.m_options.count("-i") ? "i" : "";
    const char* file_regex_options =
        cfg.get_value("nocase-file-match") == "on" ? "i" : "";

    bool trim = cfg.get_value("find-trim-ws") == "on";
    unsigned thread_count = get_thread_count(cfg);
    unsigned buffer_count = get_buffer_count(thread_count);

    for(unsigned i = 0; i != opt.m_args.size(); ++i)
    {
        database_ptr db = open_database(cdb_path / "db");

        std::string pattern = opt.m_args[i];
        if(opt.m_options.count("-v"))
            pattern = escape_regex(pattern);

        mt_search mts(*db, trim, prefix_size, buffer_count);

        auto worker = [&]
        {
            mts.search_db(compile_regex(pattern, 0, find_regex_options),
                          compile_regex(file_match, 0, file_regex_options));
        };

        boost::thread_group workers;
        for(unsigned i = 0; i != thread_count-1; ++i)
            workers.create_thread(worker);

        worker();

        workers.join_all();
    }
}
Exemplo n.º 3
0
void EFXFixture_Test::stop()
{
    QList<Universe*> ua;
    ua.append(new Universe(0, new GrandMaster()));
    MasterTimerStub mts(m_doc, ua);

    EFX e(m_doc);
    e.setFadeInSpeed(1000);
    e.setFadeOutSpeed(2000);
    EFXFixture* ef = new EFXFixture(&e);
    ef->setHead(GroupHead(0,0));
    e.addFixture(ef);

    Fixture* fxi = m_doc->fixture(0);
    QVERIFY(fxi != NULL);

    e.preRun(&mts);

    // Not started yet
    ef->stop(&mts, ua);
    QCOMPARE(e.m_fader->m_channels.size(), 0);
    QCOMPARE(mts.fader()->m_channels.size(), 0);

    // Start
    ef->start(&mts, ua);
    QCOMPARE(e.m_fader->m_channels.size(), 1);
    FadeChannel fc;
    fc.setFixture(m_doc, fxi->id());
    fc.setChannel(fxi->masterIntensityChannel());
    QVERIFY(e.m_fader->m_channels.contains(fc) == true);

    // Then stop
    ef->stop(&mts, ua);
    QCOMPARE(e.m_fader->m_channels.size(), 0);

    // FadeChannels are handed over to MasterTimer's GenericFader
    QCOMPARE(mts.fader()->m_channels.size(), 1);
    QVERIFY(e.m_fader->m_channels.contains(fc) == false);
    QVERIFY(mts.m_fader->m_channels.contains(fc) == true);
    QCOMPARE(mts.m_fader->m_channels[fc].fadeTime(), uint(2000));

    e.postRun(&mts, ua);
}
Exemplo n.º 4
0
void EFXFixture_Test::nextStepSingleShot()
{
    QList<Universe*> ua;
    ua.append(new Universe(0, new GrandMaster()));
    MasterTimerStub mts(m_doc, ua);

    EFX e(m_doc);
    e.setDuration(1000); // 1s
    e.setRunOrder(EFX::SingleShot);

    EFXFixture* ef = new EFXFixture(&e);
    ef->setHead(GroupHead(0,0));
    e.addFixture(ef);

    /* Initialize the EFXFixture so that it can do math */
    ef->setSerialNumber(0);
    QVERIFY(ef->isValid() == true);
    QVERIFY(ef->isReady() == false);
    QVERIFY(ef->m_elapsed == 0);

    e.preRun(&mts);

    ef->reset();

    /* Run one cycle (50 steps) */
    uint max = MasterTimer::tick() * MasterTimer::frequency();
    for (uint i = MasterTimer::tick(); i < max; i += MasterTimer::tick())
    {
        ef->nextStep(&mts, ua);
        QVERIFY(ef->isReady() == false);
        QCOMPARE(ef->m_elapsed, i);
    }

    ef->nextStep(&mts, ua);

    /* Single-shot EFX should now be ready */
    QVERIFY(ef->isReady() == true);

    e.postRun(&mts, ua);
}
Exemplo n.º 5
0
void EFXFixture_Test::nextStepLoopZeroDuration()
{
    QList<Universe*> ua;
    ua.append(new Universe(0, new GrandMaster()));
    MasterTimerStub mts(m_doc, ua);

    EFX e(m_doc);
    e.setDuration(0); // 0s

    EFXFixture* ef = new EFXFixture(&e);
    ef->setHead(GroupHead(0,0));
    e.addFixture(ef);

    /* Initialize the EFXFixture so that it can do math */
    ef->setSerialNumber(0);
    QVERIFY(ef->isValid() == true);
    QVERIFY(ef->isReady() == false);
    QVERIFY(ef->m_elapsed == 0);

    e.preRun(&mts);

    /* Run two cycles (2 * tickms * freq) to see that Loop never quits */
    uint max = MasterTimer::tick() * MasterTimer::frequency();
    uint i = MasterTimer::tick();
    for (uint times = 0; times < 2; times++)
    {
        for (; i < max; i += MasterTimer::tick())
        {
            ef->nextStep(&mts, ua);
            QVERIFY(ef->isReady() == false); // Loop is never ready
            QCOMPARE(ef->m_elapsed, i);
        }

        // m_elapsed is NOT zeroed since there are no "rounds" when duration == 0
    }

    e.postRun(&mts, ua);
}
Exemplo n.º 6
0
void EFXFixture_Test::start()
{
    QList<Universe*> ua;
    ua.append(new Universe(0, new GrandMaster()));
    MasterTimerStub mts(m_doc, ua);

    EFX e(m_doc);
    e.setFadeInSpeed(1000);
    e.setFadeOutSpeed(2000);
    EFXFixture* ef = new EFXFixture(&e);
    ef->setHead(GroupHead(0,0));
    e.addFixture(ef);

    Fixture* fxi = m_doc->fixture(0);
    QVERIFY(fxi != NULL);

    e.preRun(&mts);

    // Fade intensity == 0, no need to do fade-in
    ef->setFadeIntensity(0);
    ef->start(&mts, ua);
    QCOMPARE(e.m_fader->m_channels.size(), 0);
    ef->m_started = false;

    // Fade intensity > 0, need to do fade-in
    ef->setFadeIntensity(1);
    ef->start(&mts, ua);
    QCOMPARE(e.m_fader->m_channels.size(), 1);

    FadeChannel fc;
    fc.setFixture(m_doc, fxi->id());
    fc.setChannel(fxi->masterIntensityChannel());
    QVERIFY(e.m_fader->m_channels.contains(fc) == true);
    QCOMPARE(e.m_fader->m_channels[fc].fadeTime(), uint(1000));

    e.postRun(&mts, ua);
}
Exemplo n.º 7
0
void EFXFixture_Test::nextStepLoop()
{
    UniverseArray array(512 * 4);
    MasterTimerStub mts(m_doc, array);

    EFX e(m_doc);
    e.setDuration(1000); // 1s

    EFXFixture* ef = new EFXFixture(&e);
    ef->setFixture(0);
    e.addFixture(ef);

    /* Initialize the EFXFixture so that it can do math */
    ef->setSerialNumber(0);
    QVERIFY(ef->isValid() == true);
    QVERIFY(ef->isReady() == false);
    QVERIFY(ef->m_elapsed == 0);

    e.preRun(&mts);

    /* Run two cycles (2 * tickms * freq) to see that Loop never quits */
    uint max = MasterTimer::tick() * MasterTimer::frequency();
    uint i = MasterTimer::tick();
    for (uint times = 0; times < 2; times++)
    {
        for (; i < max; i += MasterTimer::tick())
        {
            ef->nextStep(&mts, &array);
            QVERIFY(ef->isReady() == false); // Loop is never ready
            QCOMPARE(ef->m_elapsed, i);
        }

        i = 0; // m_elapsed is zeroed after a full pass
    }

    e.postRun(&mts, &array);
}
Exemplo n.º 8
0
void EFXFixture_Test::start()
{
    UniverseArray array(512 * 4);
    MasterTimerStub mts(m_doc, array);

    EFX e(m_doc);
    e.setFadeInSpeed(1000);
    e.setFadeOutSpeed(2000);
    EFXFixture* ef = new EFXFixture(&e);
    ef->setFixture(0);
    e.addFixture(ef);

    Fixture* fxi = m_doc->fixture(0);
    QVERIFY(fxi != NULL);

    e.preRun(&mts);

    // Fade intensity == 0, no need to do fade-in
    ef->setFadeIntensity(0);
    ef->start(&mts, &array);
    QCOMPARE(e.m_fader->m_channels.size(), 0);
    ef->m_started = false;

    // Fade intensity > 0, need to do fade-in
    ef->setFadeIntensity(1);
    ef->start(&mts, &array);
    QCOMPARE(e.m_fader->m_channels.size(), 1);

    FadeChannel fc;
    fc.setFixture(fxi->id());
    fc.setChannel(fxi->masterIntensityChannel());
    QVERIFY(e.m_fader->m_channels.contains(fc) == true);
    QCOMPARE(e.m_fader->m_channels[fc].fadeTime(), uint(1000));

    e.postRun(&mts, &array);
}
Exemplo n.º 9
0
Arquivo: smtTest.C Projeto: jimix/k42
int
main(int argc, char *argv[])
{
    NativeProcess();

    const char *optlet = "acA";
    int c;
    int server=0;
    int alloc_test=0;
    while ((c = getopt(argc, argv, optlet)) != EOF) {
	switch (c) {
	    case 'c':
		server=0;
		break;
	    case 'a':
		server=1;
		break;
	    case 'A':
		alloc_test =1;
		break;
	}
    }

    ProcessID pid = DREFGOBJ(TheProcessRef)->getPID();
    if (server) {
	printf("Pid is:%ld\n",pid);
	startupSecondaryProcessors();
	MetaObj::init();
	MetaMemTrans::init();
	ObjectHandle fake;
	XHandle partner;
	MemTransRef mtr;
	fake.init();

	MTHandlerSrv mts(Scheduler::GetCurThread());

	SysStatus rc = MemTrans::Create(mtr, fake, 64*PAGE_SIZE, partner, &mts);
	printf("MemTrans::Create: %016ld\n",rc);

	if (alloc_test) {

#define A(spot,count) (((spot)<<12) | (count))
#define D(spot,count) ((1<<11) | ((spot)<<12) | (count))
	    uval sequence[15] = { A(0,9), A(1,9), A(2,9), A(3,9), A(4,9),
				  A(5,9), A(6,9),
				  D(1,9), D(3,9), D(2,9),
				  A(1,25), A(2,1), A(3,1),0};

	    void *allocs[8]={NULL,};
	    uval slot = 0;
	    while (sequence[slot]!=0) {

		uval spot = (sequence[slot] & ~((1<<12) - 1))>>12;
		uval count= sequence[slot] & ((1<<11) - 1);
		if ( sequence[slot] & 1<<11 ) {
		    DREF(mtr)->freePagePtr(allocs[spot]);
		    printf("Free: %ld %p %ld\n",spot,allocs[spot],count);
		} else {
		    uval addr;
		    DREF(mtr)->allocPagesLocal(addr, count);
		    allocs[slot]=(void*)addr;
		    printf("Alloc: %ld %p %ld\n",spot,allocs[slot],count);
		}

		++slot;
	    }
	}
	mts.waitForNext();
	printf("Received connection: %016lx\n",mts.other);

	mts.waitForNext();
	printf("Received ring: %016lx %ld\n",mts.other,mts.ring);

	for (uval i=0; i<1001; ++i) {
	    while (1) {
		rc = DREF(mtr)->insertToRing(mts.ring, i);
		if (_FAILURE(rc)) {
		    printf("insert failure: %016lx\n",rc);
		    mts.waitForNext();
		} else {
		    break;
		}
	    }
	}
    } else {