コード例 #1
0
ファイル: Query11.cpp プロジェクト: Cincinesh/angle
gl::Error Query11::flush(bool force)
{
    while (!mPendingQueries.empty())
    {
        QueryState *query = &mPendingQueries.front();

        do
        {
            gl::Error error = testQuery(query);
            if (error.isError())
            {
                return error;
            }
            if (!query->finished && !force)
            {
                return gl::Error(GL_NO_ERROR);
            }
        } while (!query->finished);

        mResultSum = MergeQueryResults(getType(), mResultSum, mResult);
        SafeRelease(query->beginTimestamp);
        SafeRelease(query->endTimestamp);
        SafeRelease(query->query);
        mPendingQueries.pop_front();
    }

    return gl::Error(GL_NO_ERROR);
}
コード例 #2
0
ファイル: Query.cpp プロジェクト: hgl888/RuntimeCanvas
GLboolean Query::isResultAvailable()
{
    if (mQuery != NULL)
    {
        testQuery();
    }
    
    return mStatus;
}
コード例 #3
0
ファイル: Query11.cpp プロジェクト: AOSC-Dev/Pale-Moon
gl::Error Query11::isResultAvailable(GLuint *available)
{
    gl::Error error = testQuery();
    if (error.isError())
    {
        return error;
    }

    *available = (mQueryFinished ? GL_TRUE : GL_FALSE);

    return gl::Error(GL_NO_ERROR);
}
コード例 #4
0
ファイル: Query11.cpp プロジェクト: RSATom/Qt
gl::Error Query11::isResultAvailable(bool *available)
{
    gl::Error error = testQuery();
    if (error.isError())
    {
        return error;
    }

    *available = mQueryFinished;

    return gl::Error(GL_NO_ERROR);
}
コード例 #5
0
ファイル: Query11.cpp プロジェクト: L2-D2/gecko-dev
GLuint Query11::getResult()
{
    if (mQuery != NULL)
    {
        while (!testQuery())
        {
            Sleep(0);
            // explicitly check for device loss, some drivers seem to return S_FALSE
            // if the device is lost
            if (mRenderer->testDeviceLost(true))
            {
                return gl::error(GL_OUT_OF_MEMORY, 0);
            }
        }
    }

    return mResult;
}
コード例 #6
0
ファイル: Query9.cpp プロジェクト: CodeSpeaker/gecko-dev
GLuint Query9::getResult()
{
    if (mQuery != NULL)
    {
        while (!testQuery())
        {
            Sleep(0);
            // explicitly check for device loss
            // some drivers seem to return S_FALSE even if the device is lost
            // instead of D3DERR_DEVICELOST like they should
            if (mRenderer->testDeviceLost(true))
            {
                return gl::error(GL_OUT_OF_MEMORY, 0);
            }
        }
    }

    return mResult;
}
コード例 #7
0
ファイル: Query.cpp プロジェクト: hgl888/RuntimeCanvas
GLuint Query::getResult()
{
    if (mQuery != NULL)
    {
        while (!testQuery())
        {
            Sleep(0);
            // explicitly check for device loss
            // some drivers seem to return S_FALSE even if the device is lost
            // instead of D3DERR_DEVICELOST like they should
            if (gl::getDisplay()->testDeviceLost())
            {
                gl::getDisplay()->notifyDeviceLost();
                return error(GL_OUT_OF_MEMORY, 0);
            }
        }
    }

    return (GLuint)mResult;
}
コード例 #8
0
ファイル: Query11.cpp プロジェクト: AOSC-Dev/Pale-Moon
gl::Error Query11::getResult(GLuint *params)
{
    while (!mQueryFinished)
    {
        gl::Error error = testQuery();
        if (error.isError())
        {
            return error;
        }

        if (!mQueryFinished)
        {
            Sleep(0);
        }
    }

    ASSERT(mQueryFinished);
    *params = mResult;

    return gl::Error(GL_NO_ERROR);
}
コード例 #9
0
ファイル: Query11.cpp プロジェクト: RSATom/Qt
gl::Error Query11::getResultBase(T *params)
{
    while (!mQueryFinished)
    {
        gl::Error error = testQuery();
        if (error.isError())
        {
            return error;
        }

        if (!mQueryFinished)
        {
            ScheduleYield();
        }
    }

    ASSERT(mQueryFinished);
    *params = static_cast<T>(mResult);

    return gl::Error(GL_NO_ERROR);
}
コード例 #10
0
ファイル: keydbx.c プロジェクト: ryankurte/cryptlib
int testKeysetQuery( void )
	{
	int status;

	puts( "Testing general certificate database query..." );
	status = testQuery( DATABASE_KEYSET_TYPE, DATABASE_KEYSET_NAME );
	if( status == CRYPT_ERROR_NOTAVAIL )
		{
		/* Database keyset access not available */
		return( CRYPT_ERROR_NOTAVAIL );
		}
	if( status == CRYPT_ERROR_FAILED )
		{
		puts( "This is probably because you haven't set up a database or "
			  "data source for use\nas a key database.  For this test to "
			  "work, you need to set up a database/data\nsource with the "
			  "name '" DATABASE_KEYSET_NAME_ASCII "'.\n" );
		return( FALSE );
		}
	if( !status )
		return( FALSE );
	puts( "Certificate database query succeeded.\n" );
	return( TRUE );
	}
コード例 #11
0
ファイル: testQuery.c プロジェクト: alisonberkowitz/LKMHW3
int main()
{
	testQuery();
	return 0;
}
コード例 #12
0
ファイル: Parser.cpp プロジェクト: deleisha/neopegasus
/*
    Executes all of the individual tests against the provided FQL
    source instance.
*/
void executeTests(FQLInstancePropertySource src)
{

    ///////////////////////////////////////////////////////////////////////
    /// Some general tests.  These should be moved to proper section
    //////////////////////////////////////////////////////////////////////


    testQuery(src, "IntArrayProp1 = {4, 5, 7}", true);
    testQuery(src, "IntArrayProp1[2] = 7", true);
    testQuery(src, "ANY IntArrayProp1 = 7",true);
    testQuery(src, "ANY IntArrayProp1 = IntScal1",true);
    testQuery(src, "EVERY IntArrayProp1 < 90",true);
    testQuery(src, "NOT ANY IntArrayProp1 = 7",false);
    testQuery(src, "NOT EVERY IntArrayProp1 = 7",true);

    /////////////////////////////////////////////////////////////////
    // Boolean property tests
    /////////////////////////////////////////////////////////////////

    // boolean-scalar-property op literal
    testQuery(src, "BoolScal1 = true", true);
    testQuery(src, "BoolScal1 <> true", false);
    testQuery(src, "BoolScal1 = true", true);
    testQuery(src, "BoolScal2 = true", false);
    testQuery(src, "BoolScal2 <> true", true);

    // boolean-scalar-property op boolean-scalar-property
    testQuery(src, "BoolScal1 = BoolScal1", true);
    testQuery(src, "BoolScal1 <> BoolScal2", true);
    testQuery(src, "BoolScal1 > BoolScal2", true, true);
    testQuery(src, "BoolScal1 < BoolScal2", true, true);
    testQuery(src, "BoolScal1 >= BoolScal2", true, true);
    testQuery(src, "BoolScal1 <= BoolScal2", true, true);

    testQuery(src, "BoolScal1 > BoolScal2", true, true);

    // Bool array to literal
    testQuery(src, "BoolArrayProp1 = {true, false, true }", true);
    testQuery(src, "BoolArrayProp2 = {true, false, true }", true);

        // test Bool array to array comparisons
    testQuery(src, "BoolArrayProp2 = BoolArrayProp2", true);
    testQuery(src, "BoolArrayProp2 <> BoolArrayProp2", false);

    testQuery(src, "BoolArrayProp1 = BoolArrayProp2", true);
    testQuery(src, "BoolArrayProp2 <>  BoolArrayProp2", false);

    testQuery(src, "BoolArrayProp1 = BoolArrayProp3", true);
    testQuery(src, "BoolArrayProp1 <>  BoolArrayProp3", false);

    // test invalid property name
    testQuery(src, "BoolArrayProp2 =  BoolArrayProp9", true, true);

    // test invalid operators
    testQuery(src, "BoolArrayProp2 < BoolArrayProp2", true, true);

    // Invalid bool array compares

    testQuery(src, "BoolArrayProp2 > {true, false, true }", true, true);
    testQuery(src, "BoolArrayProp2 < {true, false, true }", true, true);
    testQuery(src, "BoolArrayProp2 >= {true, false, true }", true, true);
    testQuery(src, "BoolArrayProp2 <= {true, false, true }", true, true);

    // bool aray[x] to literal TODO
    // bool array[x] to boolscalar TODO

    //////////////////////////////////////////////////////////
    // String property tests
    /////////////////////////////////////////////////////////

    // test String-scalar-property op  literal
    testQuery(src,"strScal1 = \'Test\'", true);
    testQuery(src,"strScal1 <> \'Test\'", false);
    testQuery(src,"strScal1 <> \'Testx\'", true);
    testQuery(src,"strScal1 <> \'test\'", true);
    testQuery(src,"strScal1 <> \'Tes\'", true);

    // test String-array-property op  array literal
    testQuery(src, "StrArrayProp1 ="
              "{\'zero\', \'one\', \'two\', \'three\'}",true);
    testQuery(src, "StrArrayProp1 <>"
                   "{\'zero\', \'one\', \'two\', \'three\'}",false);
    testQuery(src, "StrArrayProp1 =  {\'zero\', \'one\', \'two\'}",false);
    testQuery(src, "StrArrayProp1 <> {\'zero\', \'one\', \'two\'}",true);

    // String-array-Property[index] op scalar literal
    testQuery(src, "StrArrayProp1[0] = \'zero\'",true);
    testQuery(src, "StrArrayProp1[1] = \'one\'",true);
    testQuery(src, "StrArrayProp1[2] = \'two\'",true);
    testQuery(src, "StrArrayProp1[3] = \'three\'",true);
    testQuery(src, "StrArrayProp1[1] = \'One\'",false);
    testQuery(src, "StrArrayProp1[1] <> \'One\'",true);
    testQuery(src, "StrArrayProp1[1] <> \'\'", true);
    testQuery(src, "StrArrayProp1[1] = \'\'", false);

    // String-array-Property[index] op scalar property
    // TODO
    // String ANY and EVERY

    // TODO add < and > ops
    testQuery(src," ANY StrArrayProp1 = \'zero\'",true);
    testQuery(src," ANY StrArrayProp1 = \'three\'",true);
    testQuery(src," ANY StrArrayProp1 = \'notAProperty\'",false);
    testQuery(src," EVERY StrArrayProp1 = \'three\'",false);

    // Test LIKE operation
    testQuery(src,"strScal1 LIKE \'Test\'", true);
    testQuery(src,"strScal1 LIKE \'T...\'", true);
    testQuery(src,"strScal1 LIKE \'Tes.\'", true);

    testQuery(src,"strScal1 LIKE \'.est\'", true);
    testQuery(src,"strScal1 LIKE \'.*\'", true);

    testQuery(src,"strScal1 NOT LIKE \'.est\'", false);
    testQuery(src,"strScal1 NOT LIKE \'.*\'", false);

    testQuery(src, "StrArrayProp1[1] LIKE \'one\'",true);
    testQuery(src, "StrArrayProp1[1] LIKE \'.ne\'",true);

    ////////////////////////////////////////////////////////
    // Integer properties tests
    ////////////////////////////////////////////////////////
    // integer-scalar-property op literal
    testQuery(src, "IntScal1 = 5", true);
    testQuery(src, "IntScal2 = 25", true);
    testQuery(src, "IntScal1 <> 5", false);
    testQuery(src, "IntScal2 <> 25", false);
    testQuery(src, "IntScal1 <> 9", true);
    testQuery(src, "IntScal1 > 4", true);
    testQuery(src, "IntScal1 < 6", true);
    testQuery(src, "IntScal2 <> 0", true);
    testQuery(src, "IntScal3 = -25123", true);
    testQuery(src, "IntScal4 = 0", true);
    testQuery(src, "Int64Scal5 = 7340031", true);
    testQuery(src, "Int64Scal6 = 2147483647", true);
    testQuery(src, "Int64Scal7 = 4067", true);

    // tests against hex and binary scalar integer defintions
    testQuery(src, "IntScal1 = 0X5", true);
    testQuery(src, "IntScal1 = 101B", true);
    testQuery(src, "IntScal2 = 0X19", true);
    testQuery(src, "IntScal2 < 0X1A", true);
    testQuery(src, "IntScal2 = 0X1A", false);
    testQuery(src, "IntScal2 = 11001B", true);
    testQuery(src, "IntScal3 = -0x6223", true);
    testQuery(src, "IntScal3 = -110001000100011B", true);
    testQuery(src, "IntScal4 = 0X0", true);
    testQuery(src, "IntScal4 = 0B", true);
    testQuery(src, "Int64Scal5 = 0X6fffff", true);
    testQuery(src, "Int64Scal6 = 2147483647", true);

    // TODO create an array property with single entry.
    // TODO create array property that is empty

    // test integerArray op array literal
    testQuery(src, "IntArrayProp1 = {3}", false);
    testQuery(src, "IntArrayProp1 = {4, 5, 7}", true);
    testQuery(src, "IntArrayProp1 = {4, 5, 8}", false);
    testQuery(src, "IntArrayProp1 = {4, 5, 8, 9}", false);
    testQuery(src, "IntArrayProp1 = {4, 5}", false);

    // test integer Array[x] op scalar
    testQuery(src,"IntArrayProp1[2] = 7", true);
    testQuery(src,"IntArrayProp1[1] = 5", true);
    testQuery(src,"IntArrayProp1[0] = 4", true);
    testQuery(src,"IntArrayProp1[2] = 8", false);
    testQuery(src,"IntArrayProp1[2] > 7", false);
    testQuery(src,"IntArrayProp1[2] < 3", false);

    // scalar one property against another
    testQuery(src, "IntScal1 = IntScal2", false);
    testQuery(src, "IntScal1 <> IntScal2", true);
    testQuery(src, "IntScal1 < IntScal2", true);
    testQuery(src, "IntScal1 <= IntScal2", true);
    testQuery(src, "IntScal1 > IntScal2", false);
    testQuery(src, "IntScal1 >= IntScal2", false);

    testQuery(src, "IntScal1 < IntScal1", false);
    testQuery(src, "IntScal1 > IntScal1", false);

    testQuery(src, "IntScal1 < Int64Scal7", true);
    testQuery(src, "IntScal4 = Int64Scal8", true);

    testQuery(src,"ANY IntArrayProp1 < 90",true);
    testQuery(src,"NOT EVERY IntArrayProp1 < 90",false);
    testQuery(src,"EVERY IntArrayProp1 < 90",true);
    testQuery(src,"EVERY IntArrayProp1 > 90",false);
    testQuery(src,"ANY IntArrayProp1 = 7",true);
    testQuery(src,"ANY IntArrayProp1 = 5",true);
    testQuery(src,"ANY IntArrayProp1 = 4",true);
    testQuery(src,"ANY IntArrayProp1 = 3",false);
    testQuery(src,"NOT ANY IntArrayProp1 = 99999",true);

    testQuery(src," ANY IntArrayProp1 = 99",false);
    testQuery(src," EVERY IntArrayProp1 = 7",false);

    testQuery(src,"ANY IntArrayProp1 = IntArrayProp1[0]",true);
    testQuery(src,"ANY IntArrayProp1 = IntArrayProp1[1]",true);
    testQuery(src,"ANY IntArrayProp1 = IntArrayProp1[2]",true);

    testQuery(src,"ANY IntArrayProp1 = IntArrayProp2[0]",true);
    testQuery(src,"ANY IntArrayProp1 <> IntArrayProp2[2]",true);

    testQuery(src,"EVERY IntArrayProp1 >= IntArrayProp1[0]",true);
    testQuery(src,"EVERY IntArrayProp1 <= IntArrayProp1[2]",true);

    testQuery(src, "IntArrayProp1[1] = IntArrayProp1[1]", true);

    // Generate exception error because index out of bounds
    testQuery(src,"ANY IntArrayProp1 = IntArrayProp1[3]",true, true);

    // Property Index out of bounds. Fails test since that value
    // does not exist
    testQuery(src, "IntArrayProp1[20] = 7", false);

    /////////////////////////////////////////////////////////
    // Double type
    /////////////////////////////////////////////////////////
    // real-scalar-property op real-literal
    testQuery(src,"DoubleScal1 = 20.9", true);
    testQuery(src,"DoubleScal1 > 0.1", true);
    testQuery(src,"DoubleScal1 <> 0.1", true);
    testQuery(src,"DoubleScal1 < 0.1", false);
    testQuery(src,"DoubleScal1 < 1.2", false);
    testQuery(src,"DoubleScal1 > 1.2", true);
    testQuery(src,"DoubleScal1 = 0.9", false);
    testQuery(src,"DoubleScal1 = 1.2", false);
    testQuery(src,"DoubleScal1 = 20.9999", false);
    // real array
    testQuery(src,"DoubleArrayProp1 = {1011.04, 123456.8, 0.1 }", true);
    testQuery(src,"DoubleArrayProp1 <> {1011.04, 123456.8, 0.1 }", false);
    testQuery(src,"DoubleArrayProp1[0] <>1011.04", true);

    testQuery(src,"ANY DoubleArrayProp1 <> 20.9", true);
    testQuery(src,"ANY DoubleArrayProp1 > 1011.04", true);
    testQuery(src,"EVERY DoubleArrayProp1 <> 99999.0", true);
    testQuery(src,"EVERY DoubleArrayProp1 < 999999.1", true);
    testQuery(src,"ANY DoubleArrayProp1 > 0.0 AND"
                  " ANY DoubleArrayProp1 < 9.1", true );
    /////////////////////////////////////////////////////////
    //  DateTime property type tests
    ////////////////////////////////////////////////////////
    // Datetime scalar tests
    testQuery(src, "dateTimeScal1 = \'19991224120000.000000+360\'", true);
    testQuery(src, "dateTimeScal1 <> \'19991224120000.000000+360\'", false);
    testQuery(src, "dateTimeScal1 <> \'20131224120000.000000+360\'", true);
    testQuery(src, "dateTimeScal1 < \'20131224120000.000000+360\'", true);
    testQuery(src, "dateTimeScal1 > \'19981224120000.000000+360\'", true);

    // TODO add tests for various timezones, etc.
    // dateTime Indexed array tests
    testQuery(src, "dateTimeArray1[0] = \'19991224120000.000000+360\'",true);
    testQuery(src, "dateTimeArray1[1] = \'20131224120000.000000+360\'",true);
    testQuery(src, "dateTimeArray1[0] < \'20131224120000.000000+360\'",true);

    // DateTime array tests
    testQuery(src, "dateTimeArray1 = {\'19991224120000.000000+360\'}", false);
    testQuery(src, "dateTimeArray1 = {\'19991224120000.000000+360\',"
                   "\'20131224120000.000000+360\',"
                    "\'20021224120000.000000+360\'}", false);

    testQuery(src, "dateTimeArray1 = {\'19991224120000.000000+360\',"
                   "\'20131224120000.000000+360\',"
                    "\'20011224120000.000000+360\'}", true);
    testQuery(src, "dateTimeArray1 <> {\'19991224120000.000000+360\',"
                   "\'20131224120000.000000+360\',"
                    "\'20011224120000.000000+360\'}", false);
    // Repeat the above for single quote literal
    testQuery(src, "dateTimeArray1 = {\'19991224120000.000000+360\'}", false);
    testQuery(src, "dateTimeArray1 = {\'19991224120000.000000+360\',"
                   "\'20131224120000.000000+360\',"
                    "\'20021224120000.000000+360\'}", false);

    testQuery(src, "dateTimeArray1 = {\'19991224120000.000000+360\',"
                   "\'20131224120000.000000+360\',"
                    "\'20011224120000.000000+360\'}", true);
    testQuery(src, "dateTimeArray1 <> {\'19991224120000.000000+360\',"
                   "\'20131224120000.000000+360\',"
                    "\'20011224120000.000000+360\'}", false);

    testQuery(src, "ANY dateTimeArray1 = '20011224120000.000000+360\'", true);
    testQuery(src,"EVERY dateTimeArray1 = '20011224120000.000000+360\'", false);

    ///////////////////////////////////////////////////////////////////
    //  Tests where property named does not exist.  The spec defines the
    //  results of these tests to be result of treating the non-existent
    //  property as NULL and comparing it with the right side property.
    //  NOTE: There is ambiguity as to what <= >=, like would mean and
    //  we treat these so they fail the tests.
    ///////////////////////////////////////////////////////////////////
    testQuery(src, "nosuchproperty1 = 3",false);
    testQuery(src, "nosuchproperty2 <> 3", true);
    testQuery(src, "nosuchproperty3 = NULL",true);
    testQuery(src, "nosuchProperty4 <> NULL", false);
    testQuery(src, "nosuchProperty4 = \'blah\'", false);
    testQuery(src, "nosuchProperty4 <= \'blah\'", false);

    ///////////////////////////////////////////////////////////////////
    //  Embedded Instance tests
    ///////////////////////////////////////////////////////////////////

    testQuery(src, "embeddedInstance1.noSuchName = true",false);
    testQuery(src, "embeddedInstance1.embedBool.noSuchName = true",false);
    testQuery(src, "embeddedInstance1.embedBool = true",true);
    testQuery(src, "embeddedInstance1.embedInt = 5",true);

    /////////////////////////////////////////////////////////
    //          Reference property type tests
    ////////////////////////////////////////////////////////
    // KS_TODO TODO Add more tests.
    testQuery(src,"referenceScal4 = \'myclassname.p1=1\'", true);
    testQuery(src, "referenceScal4 <> referenceScal3", true);
    testQuery(src, "referenceScal4 = referenceScal3", false);

    // KS_TODO add test to be sure that < > etc. do not work

    ///////////////////////////////////////////////////////////
    // AND and OR Tests
    //////////////////////////////////////////////////////////
    testQuery(src,"IntArrayProp1[1] = 5 AND IntArrayProp1[2] = 7", true);
    testQuery(src, "IntScal1 = 5 OR IntScal1 = 26", true);

    //////////////////////////////////////////////////////////
    // Error tests
    // //////////////////////////////////////////////////////

    // Expect exception from the query, property.
    // IntArrayNOExist does not exist.
    testQuery(src, "IntArrayNoExist[1] = IntArrayProp1[1]", false);
    // test invalid characters on integer literals
    testQuery(src, "IntScal1 = 0xabcdefg", true, true);
    testQuery(src, "IntScal1 = 0xabcdefg", true, true);
    testQuery(src, "IntScal1 = 123x", true, true);

    //The following is illegal in the FQL spec
    // array-literal = "{" [scalar-literal *( "." scalar-literal ) ] "}"
    testQuery(src, "IntArrayProp1 = {}", false, true);

    // Test invalid datetime literal
    testQuery(src, "dateTimeScal1 = \'19991224120000.000000+abc\'", true, true);

    // The following generates an error it mixes types.  Note that the
    // spec does not allow an integer as real.
    // The throw statement from this causes a secondary exception which
    // kills off the test (Unexpected Exception: parse error: syntax error
    // unexpected $end)
    //testQuery(src,"DoubleArrayProp1 <> {1.00, 123457, 0.1 }", false, true);

    //////////////////////////////////////////////////////////
    // Test of complex queries
    // //////////////////////////////////////////////////////
    // Tests for OR
    testQuery(src,"IntScal1 = 5 OR intScal2= 26", true);
    testQuery(src,"IntScal1 = 6 OR intScal2= 25", true);
    testQuery(src,"IntScal1 = 6 OR intScal2= 26", false);

    // Tests for AND
    testQuery(src,"IntScal1 = 5 AND intScal2= 25", true);
    testQuery(src,"IntScal1 = 6 AND intScal2= 25", false);
    testQuery(src,"IntScal1 = 5 AND intScal2= 26", false);
    testQuery(src,"( IntScal1 = 5 AND intScal2 = 25 )", true);

    // Tests of complex definitions involving parenthesis
    testQuery(src,"(IntScal1 = 5) AND (intScal2 = 25)", true);
    testQuery(src,"(( IntScal1 = 5) AND (intScal2 = 25 ))", true);
    testQuery(src,"IntScal1 = 5 AND intScal2 = 25 AND DoubleScal1 > 1.2 "
                  "AND strScal1 = \'Test\'", true);
    testQuery(src,"(IntScal1 = 5 AND intScal2= 25) OR (DoubleScal1 < 1.2 "
                  "AND strScal1= \'Test\')", true);
}
コード例 #13
0
void testSearch(struct DHTMessage** outMessagePtr,
                struct RouterModule* routerModule,
                struct DHTModuleRegistry* registry,
                struct Allocator* allocator)
{
    *outMessagePtr = NULL;

    #define REQUEST_HASH "\xfc\x01\x01\x01\x01\x01\x01\x01\x21\x01\x01\x01\x01\x01\x01\x01"

    struct DHTMessage* callbackMessage = NULL;

    RouterModule_beginSearch((uint8_t*) REQUEST_HASH,
                             testSearch_callback,
                             &callbackMessage,
                             routerModule);

    struct DHTMessage* outMessage = *outMessagePtr;
    assert(outMessage != NULL);

    // Need to be able to work around the fact that the string contains nulls.
    #define EXPECTED_OUTPUT(tid) \
        "d"                                     \
          "1:q" "2:fn"                          \
          "3:tar" "16:" REQUEST_HASH            \
          "4:txid" "2:" tid                     \
        "e"

    for (uint32_t i = 0; i < (uint32_t) outMessage->length; i++) {
      //printf("%.2X", (unsigned int) outMessage->bytes[i] & 0xFF);
    }
    //printf("\n%s\n", outMessage->bytes);
    //printf("\n%s\n", outMessage->peerAddress);

    assert(outMessage->length == strlen(EXPECTED_OUTPUT("xx")));
    assert(memcmp(outMessage->bytes, EXPECTED_OUTPUT("8\x00"), outMessage->length) == 0);
    //assert(strcmp(outMessage->address->networkAddress, " 00014  ") == 0);
    // In a normal DHT, 00014 is the closest node, however, 00011 has sent us a message in
    // testQuery() and thus his reach is 1 and he beats all other nodes which are 0-reach.
    // Search queries are allowed to select nodes which are further from the target than us.
    assert(strcmp((char*) &outMessage->address->networkAddress_be, " 00011  ") == 0);

    #undef EXPECTED_OUTPUT

    #define CRAFTED_REPLY(tid) \
        "d"                                                    \
          "1:n" "200:"                                         \
            "97bkjs8qpd5hc1mubj3qbfyqzmzxp3rg" " 00017  "      \
            "by1szn122nqk1vncjtm612444rlh6ztr" " 00018  "      \
            "u42wbyr0wznhkbqr1r7u627dwsvb8853" " 00019  "      \
            "97bkjs8qpd5hc1mubj3qbfyqzmzxp3rg" " 00020  "      \
            "2lr8w01hhrxqng8mm8nf3nlwh5nyxzyl" " 00021  "      \
          "4:txid" "2:" tid                                    \
        "e"

    struct Address address = {
        .key = "ponmlkjihgzyxwvutsrq           \0"
    };
    memcpy(&address.networkAddress_be, " 00011  ", 8);

    struct DHTMessage message =
    {
        .length = strlen(CRAFTED_REPLY("xx")),
        .allocator = allocator,
        .address = &address
    };
    memcpy(message.bytes, CRAFTED_REPLY("8\x00"), message.length);
   // memcpy(message.peerAddress, peerAddress, 18);

    *outMessagePtr = NULL;

    DHTModules_handleIncoming(&message, registry);

    // Make sure the callback was called.
    assert(callbackMessage != NULL);

    // Make sure the node was promoted for it's fine service :P
    struct Address addr;
    memset(&addr, 0, sizeof(struct Address));
    memcpy(&addr.key, "ponmlkjihgzyxwvutsrq           \0", 32);
    struct Node* node1 =
        NodeStore_getNode(routerModule->nodeStore, &addr);
    //printf("node reach = %d", node1->reach);
    assert(node1->reach == 1601894175);

 /*   outMessage = *outMessagePtr;
    assert(outMessage != NULL);

    assert(strcmp("000022", outMessage->peerAddress) == 0);*/
}

int main()
{
    char buffer[1<<20];
    struct Allocator* allocator = BufferAllocator_new(buffer, 1<<20);
    struct DHTModuleRegistry* registry = DHTModules_new(allocator);

    ReplyModule_register(registry, allocator);
    struct RouterModule* routerModule =
        RouterModule_register(registry, allocator, (uint8_t*) MY_ADDRESS, event_base_new(), NULL);

    SerializationModule_register(registry, allocator);

    struct DHTMessage* outMessage;
    // dummy "network module" which just catches outgoing messages and makes them available.
    TestFramework_registerOutputCatcher(&outMessage, registry, allocator);

    struct Address addr;

    // damn this \0, was a mistake but to fix it would break all of the hashes :(
    #define ADD_NODE(address, netAddr) \
        memset(&addr, 0, sizeof(struct Address));                             \
        memcpy(&addr.networkAddress_be, netAddr "  ", 8);                     \
        memcpy(&addr.key, (uint8_t*) address "           \0", 32);            \
        RouterModule_addNode(&addr, routerModule)

//                                             most significant byte --vv
    ADD_NODE("qponmlkjihgzyxwvutsr", " 00001"); // fce8:573b:d230:ca3b 1c4e:f9d6 0632:9445
    ADD_NODE("bcdefghijklmnopqrstu", " 00002"); // fc65:9f4c:c061:84f9 2018:6e31 de3d:3bcf
    ADD_NODE("onmlkjihgzyxwvutsrqp", " 00003"); // fcbe:26ce:5c7a:9a0f 205b:358c b8f8:08bb
//                               search target --> fc01:0101:0101:0101 2101:0101 0101:0101
    ADD_NODE("mlkjihgzyxwvutsrqpon", " 00004"); // fc08:d8e6:e000:c95c 2192:d676 94f9:63a7
    ADD_NODE("lkjihgzyxwvutsrqponm", " 00005"); // fc7c:6c8d:e5ee:cf99 2f16:06c7 95ca:0c0b
    ADD_NODE("fghijklmnopqrstuvwxy", " 00006"); // fcac:3963:cbd1:6390 3e83:be89 a23f:ce66
    ADD_NODE("jihgzyxwvutsrqponmlk", " 00007"); // fc2e:3a5e:5e47:9769 4964:8f7f 3894:8c07
    ADD_NODE("kjihgzyxwvutsrqponml", " 00008"); // fc37:10aa:39ed:12bf 4a70:1507 dbe9:a054
    ADD_NODE("cdefghijklmnopqrstuv", " 00009"); // fcaa:113e:88da:d432 65f0:1c14 38d9:b656
//                                   this node --> fc39:c3ba:c711:00aa 666d:90b0 1ab6:e8c3
    ADD_NODE("rqponmlkjihgzyxwvuts", " 00010"); // fc43:41e7:2adc:d13b 78ce:1959 e4cc:c76e
    ADD_NODE("ponmlkjihgzyxwvutsrq", " 00011"); // fc83:2ab3:b65b:9ad1 7e7b:f61f e0fa:cb40
    ADD_NODE("efghijklmnopqrstuvwx", " 00012"); // fc08:0ba6:a8e2:7731 9dae:f9fd e502:767c
    ADD_NODE("abcdefghijklmnopqrst", " 00013"); // fc81:cab3:eda0:61aa 9fff:bdde 0168:f0dd
    ADD_NODE("ihgzyxwvutsrqponmlkj", " 00014"); // fc49:8fc7:7e43:981a bac1:0b5d 77fb:8818
    ADD_NODE("nmlkjihgzyxwvutsrqpo", " 00015"); // fc69:61a1:2bec:1444 bb9e:47d1 f8b3:a6a0
    ADD_NODE("defghijklmnopqrstuvw", " 00016"); // fc40:1d18:89a6:9a7e c8af:20fd 5c9f:8140
    ADD_NODE("ghijklmnopqrstuvwxyz", " 00017"); // fc74:0f2e:d77a:e5e7 cf4e:8fe9 7791:98e1


    #undef ADD_NODE

    testQuery(&outMessage, registry, allocator);
    testSearch(&outMessage, routerModule, registry, allocator);

    return 0;
}