示例#1
0
void Trigger::potentialEnterObject(GameBase* enter)
{
   if( (!mDataBlock || mDataBlock->isClientSide) && isServerObject() )
      return;
   if( (mDataBlock && !mDataBlock->isClientSide) && isGhost() )
      return;

   for (U32 i = 0; i < mObjects.size(); i++) {
      if (mObjects[i] == enter)
         return;
   }

   if (testObject(enter) == true) {
      mObjects.push_back(enter);
      deleteNotify(enter);

      if(!mEnterCommand.isEmpty())
      {
         String command = String("%obj = ") + enter->getIdString() + ";" + mEnterCommand;
         Con::evaluate(command.c_str());
      }

      if( mDataBlock )
         mDataBlock->onEnterTrigger_callback( this, enter );
   }
}
示例#2
0
void
test_server_abyss(void) {

    TServer abyssServer;

    printf("Running Abyss XML-RPC server tests...\n");

    ServerCreate(&abyssServer, "testserver", 8080, NULL, NULL);
    
    testSetHandlers(&abyssServer);

    ServerSetKeepaliveTimeout(&abyssServer, 60);
    ServerSetKeepaliveMaxConn(&abyssServer, 10);
    ServerSetTimeout(&abyssServer, 0);
    ServerSetAdvertise(&abyssServer, FALSE);

    ServerFree(&abyssServer);

    testServerParms();

    testObject();

    printf("\n");
    printf("Abyss XML-RPC server tests done.\n");
}
示例#3
0
int main(int argc, char *argv[])
{
    testArray();
    testPlugin();
    testList();
    return 0;
    testByteArray();
    testHash();
    testImage();
    testIO();
    testMap();
    testString();
    testStringList();
    testStruct();
    testThreads();
    testVariant1();
    testVariant2();
    testVariant3();
    testVector();
    testVectorOfList();

    testObject(argc, argv);

    QColor color(255,128,10);
    QFont font;

    while(true)
        ;

    return 0;
}
void SessionObjectTests::testMixedAttr()
{
	ByteString value3 = "BDEBDBEDBBDBEBDEBE792759537328";

    SessionObject testObject(NULL, 1, 1);

	CPPUNIT_ASSERT(testObject.isValid());

	bool value1 = true;
	unsigned long value2 = 0x87654321;

	OSAttribute attr1(value1);
	OSAttribute attr2(value2);
	OSAttribute attr3(value3);

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));

	CPPUNIT_ASSERT(testObject.isValid());

	CPPUNIT_ASSERT(testObject.attributeExists(CKA_TOKEN));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_PRIME_BITS));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_VALUE_BITS));
	CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN)->isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS)->isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS)->isByteStringAttribute());

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN)->getBooleanValue() == true);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS)->getUnsignedLongValue() == 0x87654321);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS)->getByteStringValue() == value3);
}
示例#5
0
文件: main.cpp 项目: patyork/project2
int main(int argc, char **argv) {

  // create a simulator
  simphys::SimEngine sim;

  auto clock_ptr = std::make_shared< simphys::Clock<fseconds> >(fseconds{0.0f});
  sim.setClock(clock_ptr);

  // create a world to simulate
  auto world_ptr = std::make_shared<simphys::SimWorld>(); 
  sim.setSimWorld(world_ptr);

  // create and initialize an object
  simphys::RigidBody p;
  simphys::Mesh s;
  simphys::SimObject3D testObject(p,s);
  auto obj_ptr = std::make_shared<simphys::SimObject3D>(testObject);
  auto objState = testObject.getState();
  objState->setPosition(simphys::vec3{0, 5, 0});
  //objState->setVelocity(simphys::vec3{40.0, 60.0, 0});
  objState->setAcceleration(simphys::vec3{0, -9.8, 0});

  // add object to the world.
  world_ptr->add(obj_ptr);

  // initialize the simulator and run it.
  sim.init();
  sim.run();

}
示例#6
0
QSharedPointer<VSearchResult> VSearch::search(VDirectory *p_directory)
{
    Q_ASSERT(!askedToStop());

    QSharedPointer<VSearchResult> result(new VSearchResult(this));

    if (!p_directory || m_config->isEmpty()) {
        result->m_state = VSearchState::Success;
        return result;
    }

    if ((!testTarget(VSearchConfig::Note)
         && !testTarget(VSearchConfig::Folder))
        || testObject(VSearchConfig::Outline)) {
        qDebug() << "search is not applicable for folder";
        result->m_state = VSearchState::Success;
        return result;
    }

    result->m_state = VSearchState::Busy;

    searchFirstPhase(p_directory, result);

    if (result->hasSecondPhaseItems()) {
        searchSecondPhase(result);
    } else if (result->m_state == VSearchState::Busy) {
        result->m_state = VSearchState::Success;
    }

    return result;
}
void SessionObjectTests::testDoubleAttr()
{
	ByteString value3 = "BDEBDBEDBBDBEBDEBE792759537328";
	ByteString value3a = "466487346943785684957634";

    SessionObject testObject(NULL, 1, 1);

	CPPUNIT_ASSERT(testObject.isValid());

	bool value1 = true;
	unsigned long value2 = 0x87654321;

	OSAttribute attr1(value1);
	OSAttribute attr2(value2);
	OSAttribute attr3(value3);

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));

	CPPUNIT_ASSERT(testObject.isValid());

	CPPUNIT_ASSERT(testObject.attributeExists(CKA_TOKEN));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_PRIME_BITS));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_VALUE_BITS));
	CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN)->isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS)->isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS)->isByteStringAttribute());

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN)->getBooleanValue() == true);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS)->getUnsignedLongValue() == 0x87654321);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS)->getByteStringValue() == value3);

	bool value1a = false;
	unsigned long value2a = 0x76767676;

	OSAttribute attr1a(value1a);
	OSAttribute attr2a(value2a);
	OSAttribute attr3a(value3a);

	// Change the attributes
	CPPUNIT_ASSERT(testObject.isValid());

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1a));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2a));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3a));

	// Check the attributes
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN)->isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS)->isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS)->isByteStringAttribute());

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN)->getBooleanValue() == value1a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS)->getUnsignedLongValue() == value2a);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS)->getByteStringValue() == value3a);

	CPPUNIT_ASSERT(testObject.isValid());
}
示例#8
0
void test_a_dbobject_with_an_object::should_store_array_attributes()
{
    bool value1 = true;
    unsigned long value2 = 0x87654321;
    ByteString value3 = "BDEBDBEDBBDBEBDEBE792759537328";

    // Create the test object
    {
        DBObject testObject(connection);
        CPPUNIT_ASSERT(testObject.find(1));
        CPPUNIT_ASSERT(testObject.isValid());

        OSAttribute attr1(value1);
        OSAttribute attr2(value2);
        OSAttribute attr3(value3);

        std::map<CK_ATTRIBUTE_TYPE,OSAttribute> mattr;
        mattr.insert(std::pair<CK_ATTRIBUTE_TYPE,OSAttribute> (CKA_TOKEN, attr1));
        mattr.insert(std::pair<CK_ATTRIBUTE_TYPE,OSAttribute> (CKA_PRIME_BITS, attr2));
        mattr.insert(std::pair<CK_ATTRIBUTE_TYPE,OSAttribute> (CKA_VALUE_BITS, attr3));
        OSAttribute attra(mattr);

        CPPUNIT_ASSERT(testObject.setAttribute(CKA_WRAP_TEMPLATE, attra));
    }

    // Now read back the object
    {
        DBObject testObject(connection);
        CPPUNIT_ASSERT(testObject.find(1));
        CPPUNIT_ASSERT(testObject.isValid());

        CPPUNIT_ASSERT(testObject.attributeExists(CKA_WRAP_TEMPLATE));
        CPPUNIT_ASSERT(!testObject.attributeExists(CKA_UNWRAP_TEMPLATE));

        std::map<CK_ATTRIBUTE_TYPE,OSAttribute> mattrb = testObject.getAttribute(CKA_WRAP_TEMPLATE).getArrayValue();
        CPPUNIT_ASSERT(mattrb.size() == 3);
        CPPUNIT_ASSERT(mattrb.find(CKA_TOKEN) != mattrb.end());
        CPPUNIT_ASSERT(mattrb.at(CKA_TOKEN).isBooleanAttribute());
        CPPUNIT_ASSERT(mattrb.at(CKA_TOKEN).getBooleanValue() == true);
        CPPUNIT_ASSERT(mattrb.find(CKA_PRIME_BITS) != mattrb.end());
        CPPUNIT_ASSERT(mattrb.at(CKA_PRIME_BITS).isUnsignedLongAttribute());
        CPPUNIT_ASSERT(mattrb.at(CKA_PRIME_BITS).getUnsignedLongValue() == 0x87654321);
        CPPUNIT_ASSERT(mattrb.find(CKA_VALUE_BITS) != mattrb.end());
        CPPUNIT_ASSERT(mattrb.at(CKA_VALUE_BITS).isByteStringAttribute());
        CPPUNIT_ASSERT(mattrb.at(CKA_VALUE_BITS).getByteStringValue() == value3);
    }
}
示例#9
0
void test_a_dbobject_with_an_object::should_fail_to_delete()
{
    DBObject testObject(connection);
    CPPUNIT_ASSERT(testObject.find(1));
    CPPUNIT_ASSERT(testObject.isValid());
    // We don't attach the object to a token, and therefore should not be able to destroy it.
    CPPUNIT_ASSERT(!testObject.destroyObject());
}
示例#10
0
int main(int argc, char **argv) {

  // create a simulator
  simphys::SimEngine sim;

  auto clock_ptr = std::make_shared< simphys::Clock<fseconds> >(fseconds{0.0f});
  clock_ptr->setScale(0.01f);
  sim.setClock(clock_ptr);

  // create a world to simulate
  auto world_ptr = std::make_shared<simphys::SimWorld>(); 
  sim.setSimWorld(world_ptr);

  // create and initialize an object
  simphys::Particle p;
  simphys::Sprite s;
  simphys::SimObject2D testObject(p,s);
  auto obj_ptr = std::make_shared<simphys::SimObject2D>(testObject);
  auto objState = testObject.getState();
  objState->setPosition(simphys::vec3{40, 50, 0});
  objState->setVelocity(simphys::vec3{50.0, 100.0, 0});
  objState->setAcceleration(simphys::vec3{0, -20.0, 0});
  objState->setMass(10000.0f);
  
  // create and initialize another object
  simphys::Particle p2;
  simphys::Sprite s2;
  simphys::SimObject2D testObject2(p2,s2);
  auto obj_ptr2 = std::make_shared<simphys::SimObject2D>(testObject2);
  auto objState2 = testObject2.getState();
  objState2->setPosition(simphys::vec3{550, 50, 0});
  objState2->setVelocity(simphys::vec3{-50.0, 100.0, 0});
  objState2->setAcceleration(simphys::vec3{0, -20.0, 0});
  objState2->setMass(100.0f);
  objState2->setColor(1.0f,0.0f,0.0f);
  objState2->setRadius(45.0f);
  
  // Command line velocity setting
  if( argc == 4 )
  {
  	objState->setVelocity(simphys::vec3{ float(atof(argv[1])), float(atof(argv[2])), 0});
  	objState2->setVelocity(simphys::vec3{ float(atof(argv[1]) * -1), float(atof(argv[2])), 0});
  }
  if( argc == 3 )
  {
  	objState->setVelocity(simphys::vec3{ float(atof(argv[1])), float(atof(argv[2])), 0});
  	objState2->setVelocity(simphys::vec3{ float(atof(argv[1]) * -1), float(atof(argv[2])), 0});
  }

  // add objects to the world.
  world_ptr->add(obj_ptr);
  world_ptr->add(obj_ptr2);

  // initialize the simulator and run it.
  sim.init();
  sim.run();

}
示例#11
0
void test_a_dbobject_with_an_object::should_cleanup_statements_during_transactions()
{
    // Create an object for accessing object 1 on the first connection.
    DBObject testObject(connection);
    // check transaction start(ro)/abort sequence
    CPPUNIT_ASSERT(testObject.startTransaction(OSObject::ReadOnly));
    CPPUNIT_ASSERT(testObject.find(1));
    CPPUNIT_ASSERT(testObject.isValid());
    CPPUNIT_ASSERT(testObject.abortTransaction());
}
示例#12
0
void SessionObjectTests::testDestroyObjectFails()
{
	// Create test object instance
    SessionObject testObject(NULL, 1, 1);

	CPPUNIT_ASSERT(testObject.isValid());

	OSObject* testIF = (OSObject*) &testObject;

	CPPUNIT_ASSERT(!testIF->destroyObject());
}
示例#13
0
void test_a_dbobject_with_an_object::should_store_mixed_attributes()
{
    bool value1 = true;
    unsigned long value2 = 0x87654321;
    unsigned long value3 = 0xBDEBDBED;

    // Create the test object
    {
        DBObject testObject(connection);
        CPPUNIT_ASSERT(testObject.find(1));
        CPPUNIT_ASSERT(testObject.isValid());

        OSAttribute attr1(value1);
        OSAttribute attr2(value2);
        OSAttribute attr3(value3);

        CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
        CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
        CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
    }

    // Now read back the object
    {
        DBObject testObject(connection);
        CPPUNIT_ASSERT(testObject.find(1));
        CPPUNIT_ASSERT(testObject.isValid());

        CPPUNIT_ASSERT(testObject.attributeExists(CKA_TOKEN));
        CPPUNIT_ASSERT(testObject.attributeExists(CKA_PRIME_BITS));
        CPPUNIT_ASSERT(testObject.attributeExists(CKA_VALUE_BITS));
        CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

        CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
        CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
        CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());

        CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue());
        CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue(), value2);
        CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
    }
}
示例#14
0
void SessionObjectTests::testBoolAttr()
{
    SessionObject testObject(NULL, 1, 1);

	CPPUNIT_ASSERT(testObject.isValid());

	bool value1 = true;
	bool value2 = false;
	bool value3 = true;
	bool value4 = true;
	bool value5 = false;

	OSAttribute attr1(value1);
	OSAttribute attr2(value2);
	OSAttribute attr3(value3);
	OSAttribute attr4(value4);
	OSAttribute attr5(value5);

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_SENSITIVE, attr2));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_EXTRACTABLE, attr3));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_NEVER_EXTRACTABLE, attr4));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_SIGN, attr5));

	CPPUNIT_ASSERT(testObject.isValid());

	CPPUNIT_ASSERT(testObject.attributeExists(CKA_TOKEN));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_SENSITIVE));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_EXTRACTABLE));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_NEVER_EXTRACTABLE));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_SIGN));
	CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN)->isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_SENSITIVE)->isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_EXTRACTABLE)->isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_NEVER_EXTRACTABLE)->isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN)->isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID) == NULL);

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN)->getBooleanValue() == true);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_SENSITIVE)->getBooleanValue() == false);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_EXTRACTABLE)->getBooleanValue() == true);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_NEVER_EXTRACTABLE)->getBooleanValue() == true);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_SIGN)->getBooleanValue() == false);

	bool value6 = true;
	OSAttribute attr6(value6);

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_VERIFY, attr6));
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VERIFY)->isBooleanAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VERIFY)->getBooleanValue() == value6);
}
示例#15
0
void VSearch::searchFirstPhaseFile(const QString &p_basePath,
                                   const QString &p_filePath,
                                   const QSharedPointer<VSearchResult> &p_result)
{
    Q_ASSERT(testTarget(VSearchConfig::Note));

    QString name = VUtils::fileNameFromPath(p_filePath);
    if (!matchPattern(name)) {
        return;
    }

    if (testObject(VSearchConfig::Name)) {
        if (matchNonContent(name)) {
            VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Note,
                                                            VSearchResultItem::LineNumber,
                                                            name,
                                                            p_filePath);
            QSharedPointer<VSearchResultItem> pitem(item);
            emit resultItemAdded(pitem);
        }
    }

    if (testObject(VSearchConfig::Path)) {
        QString normFilePath(QDir(p_basePath).relativeFilePath(p_filePath));
        removeSlashFromPath(normFilePath);
        if (matchNonContent(normFilePath)) {
            VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Note,
                                                            VSearchResultItem::LineNumber,
                                                            name,
                                                            p_filePath);
            QSharedPointer<VSearchResultItem> pitem(item);
            emit resultItemAdded(pitem);
        }
    }

    if (testObject(VSearchConfig::Content)) {
        // Add an item for second phase process.
        p_result->addSecondPhaseItem(p_filePath);
    }
}
示例#16
0
void SessionObjectTests::testULongAttr()
{
    SessionObject testObject(NULL, 1, 1);

	CPPUNIT_ASSERT(testObject.isValid());

	unsigned long value1 = 0x12345678;
	unsigned long value2 = 0x87654321;
	unsigned long value3 = 0x01010101;
	unsigned long value4 = 0x10101010;
	unsigned long value5 = 0xABCDEF;

	OSAttribute attr1(value1);
	OSAttribute attr2(value2);
	OSAttribute attr3(value3);
	OSAttribute attr4(value4);
	OSAttribute attr5(value5);

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_MODULUS_BITS, attr1));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_AUTH_PIN_FLAGS, attr3));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUBPRIME_BITS, attr4));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_KEY_TYPE, attr5));
		
	CPPUNIT_ASSERT(testObject.isValid());

	CPPUNIT_ASSERT(testObject.attributeExists(CKA_MODULUS_BITS));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_PRIME_BITS));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_AUTH_PIN_FLAGS));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUBPRIME_BITS));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_KEY_TYPE));
	CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS_BITS)->isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS)->isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_AUTH_PIN_FLAGS)->isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBPRIME_BITS)->isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_KEY_TYPE)->isUnsignedLongAttribute());

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS_BITS)->getUnsignedLongValue() == 0x12345678);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS)->getUnsignedLongValue() == 0x87654321);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_AUTH_PIN_FLAGS)->getUnsignedLongValue() == 0x01010101);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBPRIME_BITS)->getUnsignedLongValue() == 0x10101010);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_KEY_TYPE)->getUnsignedLongValue() == 0xABCDEF);

	unsigned long value6 = 0x90909090;
	OSAttribute attr6(value6);

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_CLASS, attr6));
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_CLASS)->isUnsignedLongAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_CLASS)->getUnsignedLongValue() == value6);
}
示例#17
0
void SessionObjectTests::testByteStrAttr()
{
	ByteString value1 = "010203040506070809";
	ByteString value2 = "ABABABABABABABABABABABABABABABABAB";
	ByteString value3 = "BDEBDBEDBBDBEBDEBE792759537328";
	ByteString value4 = "98A7E5D798A7E5D798A7E5D798A7E5D798A7E5D798A7E5D7";
	ByteString value5 = "ABCDABCDABCDABCDABCDABCDABCDABCD";

    SessionObject testObject(NULL, 1, 1);

	CPPUNIT_ASSERT(testObject.isValid());

	OSAttribute attr1(value1);
	OSAttribute attr2(value2);
	OSAttribute attr3(value3);
	OSAttribute attr4(value4);
	OSAttribute attr5(value5);

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_MODULUS, attr1));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_COEFFICIENT, attr2));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_PUBLIC_EXPONENT, attr4));
	CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUBJECT, attr5));

	CPPUNIT_ASSERT(testObject.isValid());

	CPPUNIT_ASSERT(testObject.attributeExists(CKA_MODULUS));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_COEFFICIENT));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_VALUE_BITS));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_PUBLIC_EXPONENT));
	CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUBJECT));
	CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS)->isByteStringAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_COEFFICIENT)->isByteStringAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS)->isByteStringAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PUBLIC_EXPONENT)->isByteStringAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBJECT)->isByteStringAttribute());

	CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS)->getByteStringValue() == value1);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_COEFFICIENT)->getByteStringValue() == value2);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS)->getByteStringValue() == value3);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_PUBLIC_EXPONENT)->getByteStringValue() == value4);
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBJECT)->getByteStringValue() == value5);

	ByteString value6 = "909090908080808080807070707070FF";
	OSAttribute attr6(value6);

	CPPUNIT_ASSERT(testObject.setAttribute(CKA_ISSUER, attr6));
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ISSUER)->isByteStringAttribute());
	CPPUNIT_ASSERT(testObject.getAttribute(CKA_ISSUER)->getByteStringValue() == value6);
}
示例#18
0
 void run () override
 {
     testTrivial ();
     testNearTrivial ();
     testPrimitives ();
     testEmpty ();
     testEscaping ();
     testArray ();
     testLongArray ();
     testEmbeddedArraySimple ();
     testObject ();
     testComplexObject ();
     testJson();
 }
示例#19
0
int main()
{
    enabledebug();
    puts("----begin----");
    testNumber();
    testString();
    testArray();
    testSymbol();
    testObject();
    // testParse();
    puts("----parser done----");
    puts("----over ----");
    return 0;
}
示例#20
0
void Trigger::processTick(const Move* move)
{
   Parent::processTick(move);

   if (!mDataBlock)
      return;
   if (mDataBlock->isClientSide && isServerObject())
      return;
   if (!mDataBlock->isClientSide && isClientObject())
      return;

   //
   if (mObjects.size() == 0)
      return;

   if (mLastThink + mDataBlock->tickPeriodMS < mCurrTick)
   {
      mCurrTick  = 0;
      mLastThink = 0;

      for (S32 i = S32(mObjects.size() - 1); i >= 0; i--)
      {
         if (testObject(mObjects[i]) == false)
         {
            GameBase* remove = mObjects[i];
            mObjects.erase(i);
            clearNotify(remove);
            
            if (!mLeaveCommand.isEmpty())
            {
               String command = String("%obj = ") + remove->getIdString() + ";" + mLeaveCommand;
               Con::evaluate(command.c_str());
            }

            mDataBlock->onLeaveTrigger_callback( this, remove );
         }
      }

      if (!mTickCommand.isEmpty())
         Con::evaluate(mTickCommand.c_str());

      if (mObjects.size() != 0)
         mDataBlock->onTickTrigger_callback( this );
   }
   else
   {
      mCurrTick += TickMs;
   }
}
示例#21
0
void test_a_dbobject::setUp()
{
    CPPUNIT_ASSERT(!system("mkdir testdir"));
    connection = DB::Connection::Create("testdir","TestToken");
    CPPUNIT_ASSERT(connection != NULL);
    CPPUNIT_ASSERT(connection->connect("<1>"));
    connection->setBusyTimeout(10);

    DBObject testObject(connection);
    CPPUNIT_ASSERT(testObject.startTransaction(DBObject::ReadWrite));
    CPPUNIT_ASSERT(testObject.createTables());
    CPPUNIT_ASSERT(testObject.commitTransaction());

    connection2 = DB::Connection::Create("testdir","TestToken");
    CPPUNIT_ASSERT(connection2 != NULL);
    CPPUNIT_ASSERT(connection2->connect("<2>"));
    connection2->setBusyTimeout(10);
}
示例#22
0
void VSearch::searchFirstPhase(VNotebook *p_notebook,
                               const QSharedPointer<VSearchResult> &p_result)
{
    bool opened = p_notebook->isOpened();
    if (!opened && !p_notebook->open()) {
        p_result->logError(QString("Fail to open notebook %1.").arg(p_notebook->getName()));
        p_result->m_state = VSearchState::Fail;
        return;
    }

    if (testTarget(VSearchConfig::Notebook)
        && testObject(VSearchConfig::Name)) {
        QString text = p_notebook->getName();
        if (matchNonContent(text)) {
            VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Notebook,
                                                            VSearchResultItem::LineNumber,
                                                            text,
                                                            p_notebook->getPath());
            QSharedPointer<VSearchResultItem> pitem(item);
            emit resultItemAdded(pitem);
        }
    }

    if (!testTarget(VSearchConfig::Note)
        && !testTarget(VSearchConfig::Folder)) {
        goto exit;
    }

    // Search for subfolders.
    for (auto const & dir : p_notebook->getRootDir()->getSubDirs()) {
        if (askedToStop()) {
            qDebug() << "asked to cancel the search";
            p_result->m_state = VSearchState::Cancelled;
            goto exit;
        }

        searchFirstPhase(dir, p_result);
    }

exit:
    if (!opened) {
        p_notebook->close();
    }
}
示例#23
0
    void test_object_should_register_added_accessories_as_handlers_and_set_physicalmodel_reference()
    {
      sc::phi::Sector sector;

      test::TestObject* testObject(
          new test::TestObject( sector, sc::phi::ObjectProperties( m_start_coordinate, m_speed_still, 0.0, 10, 1 ) ) );
      sc::phi::ObjectRef object( testObject );

      test::TestAccessory* testAccessory( new test::TestAccessory( 1 ) );
      sc::phi::AccessoryRef accessory( testAccessory );

      object->addAccessory( accessory );
      testAccessory->assertHasBeenInitialized();

      sc::evt::BinaryEvent event( 1 );
      testObject->dispatchEvent( event );

      testAccessory->assertHandlerNotified( true );
    }
示例#24
0
    void test_object_is_responsible_to_keep_accessories_alive()
    {
      sc::phi::Sector sector;

      test::TestObject* testObject(
          new test::TestObject( sector, sc::phi::ObjectProperties( m_start_coordinate, m_speed_still, 0.0, 10, 1 ) ) );
      sc::phi::ObjectRef object( testObject );

      test::TestAccessory* testAccessory( new test::TestAccessory( 1 ) );

      {
        sc::phi::AccessoryRef accessory( testAccessory );
        object->addAccessory( accessory );
        testAccessory->assertHasBeenInitialized();
      }

      sc::evt::BinaryEvent event( 1 );
      testObject->dispatchEvent( event );
      testAccessory->assertHandlerNotified( true );
    }
示例#25
0
const InvokeResult QtTestStep::invokeStepBody() {
    QTemporaryFile file;
    if (!file.open()) {
        return InvokeResult::failure("Unable to open temporary file needed for this test");
    }
    file.close();

    QtTestObject testObject(this);
    int returnValue = QTest::qExec(&testObject,
                                   QStringList() << "test"
                                                 << "-o"
                                                 << file.fileName());
    if (returnValue == 0) {
        return InvokeResult::success();
    } else {
        file.open();
        QTextStream ts(&file);
        return InvokeResult::failure(ts.readAll().toLocal8Bit());
    }
}
示例#26
0
QSharedPointer<VSearchResult> VSearch::search(const QVector<VNotebook *> &p_notebooks)
{
    Q_ASSERT(!askedToStop());

    QSharedPointer<VSearchResult> result(new VSearchResult(this));

    if (p_notebooks.isEmpty() || m_config->isEmpty()) {
        result->m_state = VSearchState::Success;
        return result;
    }

    if (testObject(VSearchConfig::Outline)) {
        qDebug() << "search is not applicable for notebook";
        result->m_state = VSearchState::Success;
        return result;
    }

    result->m_state = VSearchState::Busy;

    for (auto const & nb : p_notebooks) {
        if (!nb) {
            continue;
        }

        searchFirstPhase(nb, result);

        if (askedToStop()) {
            qDebug() << "asked to cancel the search";
            result->m_state = VSearchState::Cancelled;
            break;
        }
    }

    if (result->hasSecondPhaseItems()) {
        searchSecondPhase(result);
    } else if (result->m_state == VSearchState::Busy) {
        result->m_state = VSearchState::Success;
    }

    return result;
}
示例#27
0
void test_a_dbobject_with_an_object::should_use_transactions()
{
    DBObject testObject(connection);
    CPPUNIT_ASSERT(testObject.find(1));
    CPPUNIT_ASSERT(testObject.isValid());

    bool value1 = true;
    unsigned long value2 = 0x87654321;
    unsigned long value3 = 0xBDEBDBED;
    ByteString value4 = "AAAAAAAAAAAAAAAFFFFFFFFFFFFFFF";

    OSAttribute attr1(value1);
    OSAttribute attr2(value2);
    OSAttribute attr3(value3);
    OSAttribute attr4(value4);

    CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr4));

    // Create secondary instance for the same object.
    // This needs to have a different connection to the database to simulate
    // another process accessing the data.
    DBObject testObject2(connection2);
    CPPUNIT_ASSERT(testObject2.find(1));
    CPPUNIT_ASSERT(testObject2.isValid());

    // Check that it has the same attributes
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());

    // Check that the attributes have the same values as set on testObject.
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).getBooleanValue() == value1);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value4);

    // New values
    bool value1a = false;
    unsigned long value2a = 0x12345678;
    unsigned long value3a = 0xABABABAB;
    ByteString value4a = "EDEDEDEDEDEDEDEDEDEDEDEDEDEDED";

    OSAttribute attr1a(value1a);
    OSAttribute attr2a(value2a);
    OSAttribute attr3a(value3a);
    OSAttribute attr4a(value4a);

    // Start transaction on object
    CPPUNIT_ASSERT(testObject.startTransaction(DBObject::ReadWrite));

    // Change the attributes
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1a));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2a));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3a));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr4a));

    // Verify that the attributes were set
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());

    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value4a);

    // Verify that they are unchanged on the other instance
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());

    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).getBooleanValue() == value1);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value4);

    // Commit the transaction
    CPPUNIT_ASSERT(testObject.commitTransaction());

    // Verify that non-modifiable attributes did not propagate but modifiable attributes
    // have now changed on the other instance
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());

    // NOTE: 3 attributes below cannot be modified after creation and therefore are not required to propagate.
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).getBooleanValue() != value1a);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() != value2a);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() != value3a);

    // CKA_ID attribute can be modified after creation and therefore should have propagated.
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value4a);

    // Start transaction on object
    CPPUNIT_ASSERT(testObject.startTransaction(DBObject::ReadWrite));

    // Change the attributes
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr4));

    // Verify that the attributes were set
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());

    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue() == value1);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value4);

    // Create a fresh third instance for the same object to force the data to be retrieved from the database.
    DBObject testObject3(connection2);
    CPPUNIT_ASSERT(testObject3.find(1));
    CPPUNIT_ASSERT(testObject3.isValid());

    // Verify that they are unchanged on the other instance, while the transaction is still in progress.
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).isByteStringAttribute());

    // Verify that the attributes from the database are still hodling the same value as when the transaction started.
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).getByteStringValue() == value4a);

    // Abort the transaction
    CPPUNIT_ASSERT(testObject.abortTransaction());

    // Verify that after aborting the transaction the values in testObject have reverted back to their
    // original state.
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());

    // After aborting a transaction the testObject should be back to pre transaction state.
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value4a);

    // Verify that testObject3 still has the original values.
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).isByteStringAttribute());

    // Verify that testObject3 still has the original values.
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).getByteStringValue() == value4a);
}
示例#28
0
void VSearch::searchFirstPhase(VFile *p_file,
                               const QSharedPointer<VSearchResult> &p_result,
                               bool p_searchContent)
{
    Q_ASSERT(testTarget(VSearchConfig::Note));

    QString name = p_file->getName();
    if (!matchPattern(name)) {
        return;
    }

    QString filePath = p_file->fetchPath();
    if (testObject(VSearchConfig::Name)) {
        if (matchNonContent(name)) {
            VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Note,
                                                            VSearchResultItem::LineNumber,
                                                            name,
                                                            filePath);
            QSharedPointer<VSearchResultItem> pitem(item);
            emit resultItemAdded(pitem);
        }
    }

    if (testObject(VSearchConfig::Path)) {
        QString normFilePath;
        if (p_file->getType() == FileType::Note) {
            normFilePath = static_cast<VNoteFile *>(p_file)->fetchRelativePath();
        } else {
            normFilePath = filePath;
        }

        removeSlashFromPath(normFilePath);
        if (matchNonContent(normFilePath)) {
            VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Note,
                                                            VSearchResultItem::LineNumber,
                                                            name,
                                                            filePath);
            QSharedPointer<VSearchResultItem> pitem(item);
            emit resultItemAdded(pitem);
        }
    }

    if (testObject(VSearchConfig::Outline)) {
        VSearchResultItem *item = searchForOutline(p_file);
        if (item) {
            QSharedPointer<VSearchResultItem> pitem(item);
            emit resultItemAdded(pitem);
        }
    }

    if (testObject(VSearchConfig::Tag)) {
        VSearchResultItem *item = searchForTag(p_file);
        if (item) {
            QSharedPointer<VSearchResultItem> pitem(item);
            emit resultItemAdded(pitem);
        }
    }

    if (testObject(VSearchConfig::Content)) {
        // Search content in first phase.
        if (p_searchContent) {
            VSearchResultItem *item = searchForContent(p_file);
            if (item) {
                QSharedPointer<VSearchResultItem> pitem(item);
                emit resultItemAdded(pitem);
            }
        } else {
            // Add an item for second phase process.
            p_result->addSecondPhaseItem(filePath);
        }
    }
}
示例#29
0
void VSearch::searchFirstPhase(VDirectory *p_directory,
                               const QSharedPointer<VSearchResult> &p_result)
{
    Q_ASSERT(testTarget(VSearchConfig::Note) || testTarget(VSearchConfig::Folder));

    bool opened = p_directory->isOpened();
    if (!opened && !p_directory->open()) {
        p_result->logError(QString("Fail to open folder %1.").arg(p_directory->fetchRelativePath()));
        p_result->m_state = VSearchState::Fail;
        return;
    }

    if (testTarget(VSearchConfig::Folder)) {
        QString name = p_directory->getName();
        QString dirPath = p_directory->fetchPath();
        if (testObject(VSearchConfig::Name)) {
            if (matchNonContent(name)) {
                VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
                                                                VSearchResultItem::LineNumber,
                                                                name,
                                                                dirPath);
                QSharedPointer<VSearchResultItem> pitem(item);
                emit resultItemAdded(pitem);
            }
        }

        if (testObject(VSearchConfig::Path)) {
            QString normPath(p_directory->fetchRelativePath());
            removeSlashFromPath(normPath);
            if (matchNonContent(normPath)) {
                VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
                                                                VSearchResultItem::LineNumber,
                                                                name,
                                                                dirPath);
                QSharedPointer<VSearchResultItem> pitem(item);
                emit resultItemAdded(pitem);
            }
        }
    }

    // Search files.
    if (testTarget(VSearchConfig::Note)) {
        for (auto const & file : p_directory->getFiles()) {
            if (askedToStop()) {
                qDebug() << "asked to cancel the search";
                p_result->m_state = VSearchState::Cancelled;
                goto exit;
            }

            searchFirstPhase(file, p_result);
        }
    }

    // Search subfolders.
    for (auto const & dir : p_directory->getSubDirs()) {
        if (askedToStop()) {
            qDebug() << "asked to cancel the search";
            p_result->m_state = VSearchState::Cancelled;
            goto exit;
        }

        searchFirstPhase(dir, p_result);
    }

exit:
    if (!opened) {
        p_directory->close();
    }
}
示例#30
0
void VSearch::searchFirstPhase(const QString &p_basePath,
                               const QString &p_directoryPath,
                               const QSharedPointer<VSearchResult> &p_result)
{
    Q_ASSERT(testTarget(VSearchConfig::Note) || testTarget(VSearchConfig::Folder));
    Q_ASSERT(!p_directoryPath.isEmpty());

    QDir dir(p_directoryPath);
    if (!dir.exists()) {
        p_result->logError(QString("Directory %1 does not exist.").arg(p_directoryPath));
        p_result->m_state = VSearchState::Fail;
        return;
    }

    Q_ASSERT(dir.isAbsolute());

    if (testTarget(VSearchConfig::Folder)) {
        QString name = dir.dirName();
        if (testObject(VSearchConfig::Name)) {
            if (matchNonContent(name)) {
                VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
                                                                VSearchResultItem::LineNumber,
                                                                name,
                                                                p_directoryPath);
                QSharedPointer<VSearchResultItem> pitem(item);
                emit resultItemAdded(pitem);
            }
        }

        if (testObject(VSearchConfig::Path)) {
            QString normPath(QDir(p_basePath).relativeFilePath(p_directoryPath));
            removeSlashFromPath(normPath);
            if (matchNonContent(normPath)) {
                VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
                                                                VSearchResultItem::LineNumber,
                                                                name,
                                                                p_directoryPath);
                QSharedPointer<VSearchResultItem> pitem(item);
                emit resultItemAdded(pitem);
            }
        }
    }

    if (testTarget(VSearchConfig::Note)) {
        QStringList files = dir.entryList(QDir::Files);
        for (auto const & file : files) {
            if (askedToStop()) {
                qDebug() << "asked to cancel the search";
                p_result->m_state = VSearchState::Cancelled;
                return;
            }

            searchFirstPhaseFile(p_basePath, dir.absoluteFilePath(file), p_result);
        }
    }

    // Search subfolders.
    QStringList subdirs = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
    for (auto const & sub : subdirs) {
        if (askedToStop()) {
            qDebug() << "asked to cancel the search";
            p_result->m_state = VSearchState::Cancelled;
            return;
        }

        searchFirstPhase(p_basePath, dir.absoluteFilePath(sub), p_result);
    }
}