int main()
{
    __UHEAP_MARK;
    int retval =ESuccess;
    char* mycharstring = "Hello Char String";
    int char_length= strlen(mycharstring);
    TBufC16<17> buf;
    TPtr16 myTptr = buf.Des();
    wchar_t* temp = new wchar_t[30];
    retval = CharpToTptr16(mycharstring, myTptr);

    int buf_len = myTptr.Length();
    if (retval ==ESuccess &&\
    char_length == buf_len &&\
    buf_len == 17 )
    {
    printf("charptotptr16 boundary2 Passed\n");
    }
    else
    {
    assert_failed = true;
    printf("charptotptr16 boundar2 Failed\n");
    }      
    delete[] temp;
    __UHEAP_MARKEND;
    testResultXml("test_charptotptr16_boundary2");
    return 0;
}
int main()
{
    __UHEAP_MARK;
    int retval =ESuccess;
    char* mycharstring = "Hello Char String";
    int char_length= strlen(mycharstring);
    TBufC16<30> buf;
    TPtr16 myTptr = buf.Des();
    wchar_t* temp = new wchar_t[30];
    retval = CharpToTptr16(mycharstring, myTptr);

    int buf_len = myTptr.Length();
    if (retval ==ESuccess &&\
    char_length == buf_len &&\
    wcsncmp(L"Hello Char String",(wchar_t*)myTptr.Ptr() , 17) ==0 )
    {
    printf("charptotptr16 content check Passed\n");
    }
    else
    {
    assert_failed = true;
    printf("charptotptr16 content check Failed\n");
    }      
    delete[] temp;
    __UHEAP_MARKEND;
    testResultXml("test_charptotptr16_content_check");
    return 0;
}
int main()
{
    __UHEAP_MARK;
    int retval =ESuccess;
    char* mycharstring = "Hello Char String";
    TBufC16<30> buf;
    TPtr16 myTptr = buf.Des();
    wchar_t* temp = new wchar_t[30];
    retval = CharpToTptr16(mycharstring, myTptr);

    if (retval ==ESuccess)
    {
    printf("CharpToTptr16 positive Passed\n");
    }
    else
    {
    assert_failed = true;
    printf("CharpToTptr16 positive Failed\n");
    }      
    delete[] temp;
    __UHEAP_MARKEND;
    testResultXml("test_charptotptr16_positive1");
	return 0;
}
Ejemplo n.º 4
0
/**
 * After the player has received the update after the last iteration of the game.
 * We want to display the current game status, if there is only one player remaining then
 * the game has finished.
 */	
void CScabbyQueenPlayer::ReceiveNextRole()
	{
	if (iPlayerUpdate == iGameOverBuffer)
		{
		iConsole.Printf(_L("\nDealer Says: GAME OVER"));
		}
	else
		{
		// Break down the update descriptor and display the result
		TBufC<20> buffer;
		buffer.Des().Copy(iPlayerUpdate);	
		iConsole.Printf(_L("\n\nUpdate from the dealer...%S\n"), &buffer);
		TInt position;
		TPtrC8 ptr(iPlayerUpdate);
		TLex8 lex;
		TInt player;
		TBool stillIn = EFalse;
		iConsole.Printf(_L("\n	Number of players: %d\n"), iPlayerUpdate.Length()-1);
	
		TInt stillInCount = 0;
		for (TInt i=0; i<iPlayerUpdate.Length();i++)
			{
			TChar inspect = ptr[i];
		
			if (inspect != 'F')
				{
				TBuf8<2> buff;
				buff.Append(inspect);
				lex.Assign(buff);
				lex.Val(player);
				
				if (stillIn)
					{
					TBufC16<2> buff;
					buff.Des().Append(inspect);
					iConsole.Printf(_L("\n 	Player %S still in play"), &buff);
					stillInCount++;
					}
				else
					{
					position = i+1;
					if (i == 0)
						{
						iConsole.Printf(_L("\n The winner is player %d"), player);
						}
					else
						{
						iConsole.Printf(_L("\n 	In position %d is player %d"), position, player);
						}
					}		
				}
			else 
				{
				stillIn = ETrue;
				}
			}
	
		if (stillInCount == 1)
			{
			// If there is only one player left the game is over.
			iGameOver = ETrue;
			iConsole.Printf(_L("\nThe loser is player %d, give them a smack"), player);
			iConsole.Printf(_L("\n\nDealer Says: GAME OVER"));
			}
		iGameStatus = EReadyForToken;
		iSendMode = ESendReadyForToken;
		BaseSendTo(iGameStatus, KDealerIpAddr);
		}
	
	}
Ejemplo n.º 5
0
/**
 * Function called after the receipt of a game status from a player.
 * The game status is dealt with by placing the player number into an array of either
 * finished or current players. When both player have responded then we can construct
 * an update descriptor to send to all players.
 */
void CScabbyQueenDealer::DealWithGameStatus(TGameStatus aGameStatus)
	{

	if (iResponseCount == 0)
		{
		// First response, reset Update
		iCurrentPlayers.Reset();
		iPlayerUpdate.Delete(0,iPlayerUpdate.Length());
		}
		
	iResponseCount++;
	
	// Check the enum status that we have received, and append the
	// appropriate player number to the appropriate array.
	switch(aGameStatus)
		{
		case EPlayingZero:
			iCurrentPlayers.Append(0);
		break;
		
		case EPlayingOne:
			iCurrentPlayers.Append(1);
		break;
		
		case EPlayingTwo:
			iCurrentPlayers.Append(2);	
		break;
		
		case EPlayingThree:
			iCurrentPlayers.Append(3);		
		break;
		
		case EPlayingFour:
			iCurrentPlayers.Append(4);		
		break;
		
		case EPlayingFive:		
			iCurrentPlayers.Append(5);
		break;
	
		case EPlayingSix:		
			iCurrentPlayers.Append(6);
		break;
		
		case EPlayingSeven:		
			iCurrentPlayers.Append(7);
		break;
	
		case EFinishedZero:		
			iFinishedPlayers.Append(0);
		break;

		case EFinishedOne:		
			iFinishedPlayers.Append(1);
		break;
		
		case EFinishedTwo:		
			iFinishedPlayers.Append(2);
		break;
		
		case EFinishedThree:		
			iFinishedPlayers.Append(3);
		break;
	
		case EFinishedFour:		
			iFinishedPlayers.Append(4);
		break;
	
		case EFinishedFive:		
			iFinishedPlayers.Append(5);
		break;

		case EFinishedSix:		
    		iFinishedPlayers.Append(6);
		break;
		
		case EFinishedSeven:		
			iFinishedPlayers.Append(7);
		break;
		
		default:
		break;
		}
			
	if (iResponseCount == 2)// heard back from both
		{
		if (iOldPlayerUpdate == KNullDesC8)// first time 
			{
			// as this is the first time we can construct the
			// update descriptor as follows
			// append any finished players
			for (TInt i=0;i<iFinishedPlayers.Count();i++)
				{
				iPlayerUpdate.AppendNum(iFinishedPlayers[i]);
				}
			// append the F that seperates In and Out Players.
			iPlayerUpdate.Append('F');
			
			// append the players that are still in
			for (TInt i=0;i<iCurrentPlayers.Count();i++)
				{
				iPlayerUpdate.AppendNum(iCurrentPlayers[i]);
				}
				
			// append all the players that didnt do nothing
			for (TInt i=0;i<iRemoteNames.Count();i++)
				{ 
				if (i == iPlayerToken || i == iSender)
					{	
					}
				else
					{
					iPlayerUpdate.AppendNum(i);
					}
				} 
			}
		else
			{

			// as oldupdate contains something then this isn't the first time
			// a card has been exchanged we need to inspect the finished array.
			// for each of the values in the array we need to check whether it is to the left of the 
			// F (we already know that they have finished) if it isn't then we need to add it.
			// and remove it from the right of the F (these are the current players)
			
			
			TInt index = 0;
			// locate where the F is
			while (iOldPlayerUpdate[index] != 'F')
				{
				index++;
				}
				
			// index is position of F
			// get a pointer to finished players
			TPtrC8 playersOut(iOldPlayerUpdate.Mid(0, index));


			for (TInt i=0; i<iFinishedPlayers.Count();i++)
				{
				// i is a finished player, check that we have this number to the left of the F
				// if we dont then add it.
				TBuf8<1> num;
				num.AppendNum(iFinishedPlayers[i]);
				TInt loc = playersOut.Find(num);// has num finished already
				if (loc == KErrNotFound)
					{
					// we have finished with i but it isnt in the finished descriptor list
					iPlayerUpdate.AppendNum(iFinishedPlayers[i]);
					TInt match = iOldPlayerUpdate.Find(num);
					if (match != KErrNotFound)
						{
						iOldPlayerUpdate.Delete(match, 1);
						}
					}
				}
			iPlayerUpdate.Insert(0, playersOut);
			index = 0;
			// locate where the F is
			while (iOldPlayerUpdate[index] != 'F')
				{
				index++;
				}
			iOldPlayerUpdate.Delete(0, index);
			}
	

		if (iOldPlayerUpdate.Length() == 2)//  we only have one char to the right of the F
			{
			// we have our loser. hopefully they will have the scabby queen!
			// instead of sending a ready inquiry send a notification that tells the user game has finished.
			iGameOver = ETrue;
			}
			
		iPlayerUpdate.Append(iOldPlayerUpdate);
		iOldPlayerUpdate.Copy(iPlayerUpdate);
		TBufC16<20> buffer;
		buffer.Des().Copy(iPlayerUpdate);
		iConsole.Printf(_L("Update : %S"), &buffer);
		
		iResponseCount=0;
		iCount = 0;
		SendReadyInquiry();
		}
	}