Пример #1
0
//---------------------------------------------------------------------------
//	@function:
//		CBitVectorTest::EresUnittest_Random
//
//	@doc:
//		Test with random bit vectors to avoid patterns
//
//---------------------------------------------------------------------------
GPOS_RESULT
CBitVectorTest::EresUnittest_Random()
{
	// create memory pool
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();

	// set up control vector
	ULONG cTotal = 10000;
	CHAR *rg = GPOS_NEW_ARRAY(pmp, CHAR, cTotal);
	
	CRandom rand;
	
	clib::PvMemSet(rg, 0 , cTotal);

	// set random chars in the control vector
	for (ULONG i = 0; i < cTotal * 0.2; i++)
	{
		ULONG index = rand.ULNext() % (cTotal - 1);
		GPOS_ASSERT(index < cTotal);
		rg[index] = 1;
	}

	ULONG cElements = 0;
	CBitVector bv(pmp, cTotal);
	for (ULONG i = 0; i < cTotal; i++)
	{
		if (1 == rg[i])
		{
			bv.FExchangeSet(i);
			cElements++;
		}
	}

	GPOS_ASSERT(cElements == bv.CElements());

	ULONG ulCursor = 0;
	while(bv.FNextBit(ulCursor + 1, ulCursor))
	{
		GPOS_ASSERT(1 == rg[ulCursor]);
		cElements--;
	}

	GPOS_ASSERT(0 == cElements);
	GPOS_DELETE_ARRAY(rg);

	return GPOS_OK;
}
Пример #2
0
//---------------------------------------------------------------------------
//	@function:
//		CXMLSerializerTest::EresUnittest_Base64
//
//	@doc:
//		Testing base64 encoding and decoding
//
//---------------------------------------------------------------------------
GPOS_RESULT
CXMLSerializerTest::EresUnittest_Base64()
{
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();

	const ULONG ulraSize=5;
	ULONG rgulRandArr[ulraSize];
	
	CRandom cr;
	for (ULONG i=0;i<ulraSize;i++)
	{
		rgulRandArr[i] = cr.ULNext();
	}
	
	CWStringDynamic *pstr = CDXLUtils::PstrFromByteArray(pmp, (BYTE *) rgulRandArr, sizeof(rgulRandArr));

	ULONG len;
	
	ULONG *pulRandArrCopy = (ULONG *) CDXLUtils::PByteArrayFromStr(pmp, pstr, &len);
	
	GPOS_ASSERT(len == sizeof(rgulRandArr));

	for (ULONG i=0;i<ulraSize;i++)
	{
		if (rgulRandArr[i] != pulRandArrCopy[i])
		{
			return GPOS_FAILED;
		}
	}

	GPOS_DELETE(pstr);
	GPOS_DELETE_ARRAY(pulRandArrCopy);

	INT i = 1000;
	pstr = CDXLUtils::PstrFromByteArray(pmp, (BYTE *) &i, sizeof(i));
	
	gpos::oswcout << "Base64 encoding of " << i << " is " << pstr->Wsz() << std::endl;
	
	GPOS_DELETE(pstr);
	
	return GPOS_OK;
}