Example #1
0
void viewMatrix(int* matrix, int size1, int size2)
{
	for(size_t i = 0; i < size2+1; i++)
	{
		int* ref = &(matrix[i*(size1+1)]);
		PRINT_LINE(ref, size1+1, 1);
	}
}
Example #2
0
void CreateWatchWithCallback(PmSockIOChannel * const pOnChannel, GIOCondition ioCondition,
		PmSockWatch **pWatchToCreate, GSourceFunc CallbackForWatch,
		gpointer dataPassedToCallback, const char * myName)
{
	GMainContext *pGMainContext = PmSockThreadCtxPeekGMainContext(PmSockPeekThreadContext(pOnChannel)); //this should be the same as gMainContext_
    assert(pGMainContext);

	assert(*pWatchToCreate==NULL);
	PslError pslError = PmSockCreateWatch(pOnChannel, ioCondition, pWatchToCreate);
	UTIL_ASSERT_THROW_FATAL(!pslError, myName, Err("PmSockCreateWatch failed:", pslError).c_str() );

    g_source_set_can_recurse((GSource *)*pWatchToCreate, false);
    g_source_set_callback((GSource *)*pWatchToCreate, CallbackForWatch, dataPassedToCallback, /*notify*/NULL);
    g_source_attach((GSource *)*pWatchToCreate, pGMainContext);

    PRINT_LINE("%s watch for ioCondition==%s created", myName, IOConditionToString(ioCondition));
}
bool TestCertnameHostnameMatch::CnHnEq(const char* const cnStr, unsigned const cnStrLen,
            const char* const hnStr, unsigned const hnStrLen,
            bool* const pMatched)
{
	PRINT("%s: Comparing: cn=", myName_);

	if (cnStr) {
		PRINT("\"");

		//code fragment borrowed from pslTestBlade
		//@todo need to replace with proper hex-dump common function
		for (unsigned i=0; i < cnStrLen; i++) {
			if ('\0' == cnStr[i]) {
				PRINT("\\0");
			}
			else if ('\\' == cnStr[i]) {
				PRINT("\\\\");
			}
			else {
				PRINT("%c", cnStr[i]);
			}
		}
		PRINT("\"");

	} else {
		PRINT("<NULL>");
	}

	PRINT(" versus hn=");
	if (hnStr) {
		PRINT("\"");

		for (unsigned i=0; i < hnStrLen; i++) {
			if ('\0' == hnStr[i]) {
				PRINT("\\0");
			}
			else if ('\\' == hnStr[i]) {
				PRINT("\\\\");
			}
			else {
				PRINT("%c", hnStr[i]);
			}
		}
		PRINT("\"");

	} else {
		PRINT("<NULL>");
	}

	PRINT("\n");


    PslError const pslerr = PmSockX509CheckCertHostNameMatch(
        cnStr, cnStrLen,
        hnStr, hnStrLen,
        (PmSockX509HostnameMatchOpts)0,
        pMatched);

    bool apiSuccess;
    if (pslerr) {
        PRINT_LINE(
            "%s: ERROR: PmSockX509CheckCertHostNameMatch() failed: PslError=%d (%s)",
            myName_, pslerr, PmSockErrStringFromError(pslerr));
        apiSuccess = false;

    } else {
    	PRINT("%s: result=%s\n", myName_, *pMatched ? "matched" : "not matched");
    	apiSuccess=true;
    }

    return apiSuccess;
}
void TestCertnameHostnameMatch::Execute() {
    int     failCount = 0;
    bool    matched;

    // Expect API failure
    const unsigned apiFailureNum = sizeof(stringsExpectingAPIFailure)/sizeof(Str);
    for(unsigned i=0; i<apiFailureNum; i++) {
    	Str& str=stringsExpectingAPIFailure[i];

		bool apiSuccess = CnHnEq(
			str.cnStr, str.cnStrLen,
			str.hnStr, str.hnStrLen,
			&matched);

		TS_ASSERT(!apiSuccess);
		if (!apiSuccess) {
			PRINT_LINE("%s: PASS: expected API failure; got API failure\n", myName_);

		} else {
			failCount++;
			PRINT_LINE("%s: FAIL: expected API failure; got API success\n", myName_);
		}
    }

    // Expect no match
    const unsigned noMatchNum = sizeof(stringsExpectingNoMatch)/sizeof(Str);
    for(unsigned int i=0; i<noMatchNum; i++) {
    	Str& str=stringsExpectingNoMatch[i];

        bool matched;
        bool const apiSuccess = CnHnEq(
        		str.cnStr, str.cnStrLen,
        		str.hnStr, str.hnStrLen,
        		&matched);

        TS_ASSERT(apiSuccess && !matched);
        if (apiSuccess) {
            if (!matched) {
            	PRINT_LINE("%s: PASS: expected no match; got no match\n", myName_);
            } else {
            	PRINT_LINE("%s: FAIL: expected no match; got match\n", myName_);
            	failCount++;
            }

        } else {
        	PRINT_LINE("%s: FAIL: expected API success; got API failure\n", myName_);
        	failCount++;
        }
    }

    // Expect match
    const unsigned matchNum = sizeof(stringsExpectingMatch)/sizeof(Str);
    for(unsigned int i=0; i<matchNum; i++) {
    	Str& str=stringsExpectingMatch[i];

        bool matched;
        bool const apiSuccess = CnHnEq(
        		str.cnStr, str.cnStrLen,
        		str.hnStr, str.hnStrLen,
        		&matched);

        TS_ASSERT(apiSuccess && matched);
        if (apiSuccess) {
            if (matched) {
            	PRINT_LINE("%s: PASS: expected match; got match\n", myName_);
            } else {
            	PRINT_LINE("%s: FAIL: expected match; got no match\n", myName_);
            	failCount++;
            }
        } else {
        	PRINT_LINE("%s: FAIL: expected API success; got API failure\n", myName_);
        	failCount++;
        }
    }

    PRINT_LINE("\n%s: SUMMARY: %s: %d failures detected.",
    		myName_, failCount ? "FAIL" : "PASS", failCount);
}
Example #5
0
int nw_temp(
		char* seq1, 	size_t size1, 
		char* seq2, 	size_t size2,
		char* matsub, 	size_t sizeM,
		short gapVal, 	short expandGap, int* temp)
{
	initArrayTmp(temp, size1, gapVal, expandGap);
	int* cur;
	int* gapColSaveIndice = &(temp[2*SIZE]);
	int* gapColSaveValue  = &(temp[2*SIZE+size1]);
	initArrayTmp(gapColSaveIndice, 2*size1-1, 0, 0);
	int result = INT_MIN;
#ifdef DEBUG 
	printf("        ");
	PRINT_LINE(seq1, size1, 1);
#endif
	for(size_t j = 0; j < size2; j++)
	{
		int* ref = &(temp[(   j %2)*SIZE]);
	int gapLigSaveIndice = 0;
	int gapLigSaveValue = 0;
		cur = &(temp[((1+j)%2)*SIZE]);
		cur[0] = 0;
#ifdef DEBUG	
		if( j > 0 ) 
		{
			char* t = &(seq2[j-1]);
			PRINT_LINE(t, 1, 0);
		}
		else printf("    ");
		PRINT_LINE(ref, SIZE, 1);
#endif
		for(size_t i = 0; i < size1; i++)
		{
			int val =  (gapLigSaveValue+(i-gapLigSaveIndice)*expandGap) ;
			if( (cur[i]) > val) 
			{
				gapLigSaveValue = cur[i];
				gapLigSaveIndice= i;				
			}
			val =  (gapColSaveValue[i]+(j-gapColSaveIndice[i])*expandGap) ;
			if( (ref[i+1]) > val) 
			{
				gapColSaveValue [i] = ref[i+1];
				gapColSaveIndice[i] = j;				
			}
			val = MAX_BASE( gapColSaveValue[i] + gapVal + (j-gapColSaveIndice[i])*expandGap,
					ref[i]+blosumValue(matsub, sizeM, seq1[i], seq2[j])
					);
			cur[i+1]  = MAX_BASE(
					gapLigSaveValue + gapVal + (i-gapLigSaveIndice)*expandGap,
					val
					);
		}
		CHECK_RESULT(VAL(cur[size1]));
	}
	for(size_t i = 0; i < size1; i++)
	{
		CHECK_RESULT(VAL(cur[i+1]));
	}
#ifdef DEBUG 
	char* t = &(seq2[size2-1]);
	PRINT_LINE(t, 1, 0);
	PRINT_LINE(cur, SIZE, 1);
#endif
	return result; 
}