Esempio n. 1
0
int checkRandomVillage(int p, struct gameState *postTest, int handPos)
{
  int fail = 0;
  struct gameState preTest;

  memset(&preTest, 23, sizeof(struct gameState)); 
  memcpy(&preTest, postTest, sizeof(struct gameState));

  playVillage(p, postTest, handPos);

  //ensure the hand is the correct size
  if (preTest.handCount[p] != postTest->handCount[p])
  {
    printFailure(p, preTest.handCount[p], handPos, __LINE__);
    fail++;
  }
  //ensure the number of actions are correct
  if (postTest->numActions != preTest.numActions + 2)
  {
    printFailure(p, preTest.handCount[p], handPos, __LINE__);
    fail++;
  }

  //ensure a card is discarded
  if (postTest->discardCount[p] != preTest.discardCount[p] + 1)
  {
    printFailure(p, preTest.handCount[p], handPos, __LINE__);
    fail++;
  }

  //ensure the correct card is discarded
  if (postTest->discard[p][postTest->discardCount[p] - 1] != village)
  {
    printFailure(p, preTest.handCount[p], handPos, __LINE__);
    fail++;
  }

  return fail;
}
Esempio n. 2
0
void echoFailure()
{
	if (isTTY)
	{
		CONSOLE_SCREEN_BUFFER_INFO cursor;
		GetConsoleScreenBufferInfo(console, &cursor);
		cursor.dwCursorPosition.X = COL(getColumns());
		SetConsoleCursorPosition(console, cursor.dwCursorPosition);
		SetConsoleTextAttribute(console, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
		testPrintf("[");
		SetConsoleTextAttribute(console, FOREGROUND_RED | FOREGROUND_INTENSITY);
		testPrintf(" FAIL ");
		SetConsoleTextAttribute(console, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
		testPrintf("]");
		SetConsoleTextAttribute(console, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
		testPrintf("\n");
	}
	else
		printFailure();
	failures++;
}
static PKIX_PL_Cert *
createCert(char *inFileName)
{
        PKIX_PL_ByteArray *byteArray = NULL;
        PKIX_PL_Cert *cert = NULL;
        PKIX_Error *error = NULL;
        PRFileDesc *inFile = NULL;
        SECItem certDER;
        void *buf = NULL;
        PKIX_UInt32 len;
        SECStatus rv = SECFailure;

        certDER.data = NULL;

        inFile = PR_Open(inFileName, PR_RDONLY, 0);

        if (!inFile){
                printFailure("Unable to open cert file");
                goto cleanup;
        } else {
                rv = SECU_ReadDERFromFile(&certDER, inFile, PR_FALSE);
                if (!rv){
                        buf = (void *)certDER.data;
                        len = certDER.len;

                        error = PKIX_PL_ByteArray_Create
                                (buf, len, &byteArray, plContext);

                        if (error){
                                printFailure("PKIX_PL_ByteArray_Create failed");
                                goto cleanup;
                        }

                        error = PKIX_PL_Cert_Create
                                (byteArray, &cert, plContext);

                        if (error){
                                printFailure("PKIX_PL_Cert_Create failed");
                                goto cleanup;
                        }
                } else {
                        printFailure("Unable to read DER from cert file");
                        goto cleanup;
                }
        }

cleanup:

        if (inFile){
                PR_Close(inFile);
        }

        if (rv == SECSuccess){
                SECITEM_FreeItem(&certDER, PR_FALSE);
        }

        if (byteArray){
                PKIX_PL_Object_DecRef((PKIX_PL_Object *)(byteArray), plContext);
        }

        return (cert);
}
int dumpcert(int argc, char *argv[])
{

        PKIX_PL_String *string = NULL;
        PKIX_PL_Cert *cert = NULL;
        PKIX_Error *error = NULL;
        char *ascii = NULL;
        PKIX_UInt32 length = 0;
        PKIX_UInt32 j = 0;
	PKIX_Boolean useArenas = PKIX_FALSE;
        PKIX_UInt32 actualMinorVersion;

        PKIX_TEST_STD_VARS();

        if (argc == 1){
                printUsage();
                return (0);
        }

        useArenas = PKIX_TEST_ARENAS_ARG(argv[1]);

        PKIX_Initialize
                (PKIX_TRUE, /* nssInitNeeded */
                useArenas,
                PKIX_MAJOR_VERSION,
                PKIX_MINOR_VERSION,
                PKIX_MINOR_VERSION,
                &actualMinorVersion,
                &plContext);

        cert = createCert(argv[1+j]);

        if (cert){

                error = PKIX_PL_Object_ToString
                        ((PKIX_PL_Object *)cert, &string, plContext);

                if (error){
                        printFailure("Unable to get string representation "
                                    "of cert");
                        goto cleanup;
                }

                error = PKIX_PL_String_GetEncoded
                        (string,
                        PKIX_ESCASCII,
                        (void **)&ascii,
                        &length,
                        plContext);

                if (error || !ascii){
                        printFailure("Unable to get ASCII encoding of string");
                        goto cleanup;
                }

                (void) printf("OUTPUT:\n%s\n", ascii);

        } else {
                printFailure("Unable to create certificate");
                goto cleanup;
        }

cleanup:

        if (cert){
                PKIX_PL_Object_DecRef((PKIX_PL_Object *)(cert), plContext);
        }

        if (string){
                PKIX_PL_Object_DecRef((PKIX_PL_Object *)(string), plContext);
        }

        if (ascii){
                PKIX_PL_Free((PKIX_PL_Object *)(ascii), plContext);
        }

        PKIX_Shutdown(plContext);

        PKIX_TEST_RETURN();

        endTests("DUMPCERT");

        return (0);
}
Esempio n. 5
0
int main(int argc, char const *argv[])
{
  printf("Testing playVillage().\n");
  int i, p, r, j;
  int k[10] = {adventurer, council_room, feast, gardens, mine, smithy, village, baron, great_hall, tribute};
  int fail = 0;
  int tempHand[5];
  int tempDeck[20];
  int handSize = 5;
  int deckSize = 20;
  struct gameState G;

  for (i = 0; i < handSize; ++i)
  {
    tempHand[i] = village;
  }

  for (i = 0; i < deckSize; ++i)
  {
    if (i % 2 == 0)
    {
      tempDeck[i] = copper;
    }else if (i % 3 == 0)
    {
      tempDeck[i] = silver;
    }else if (i % 7 == 0)
    {
      tempDeck[i] = estate;
    }else
    {
      tempDeck[i] = gold;
    }
  }

  /*set up the game*/
  memset(&G, 0, sizeof(struct gameState));
  r = initializeGame(NUM_PLAYERS, k, SEED_NUMBER, &G);

  for (p = 0; p < NUM_PLAYERS; ++p)
  {
    memcpy(G.hand[p], tempHand, sizeof(int) * handSize);
    memcpy(G.deck[p], tempDeck, sizeof(int) * deckSize);
    G.handCount[p] = handSize;
    G.deckCount[p] = deckSize;
    for ( j = handSize -1; j >= 0; --j)
    {
      int oldHandCount = G.handCount[p];
      int oldDiscardCount = G.discardCount[p];
      int oldNumActions = G.numActions;
      playVillage(p, &G, j);
      
      //ensure the hand is the correct size
      if (oldHandCount != G.handCount[p])
      {
        printFailure(p, j, oldHandCount);
        ID_LINE;
        fail++;
      }

      //ensure the number of actions are correct
      if (G.numActions != oldNumActions + 2)
      {
        printFailure(p, j, oldHandCount);
        ID_LINE;
        fail++;
      }

      //ensure a card is discarded
      if (G.discardCount[p] != oldDiscardCount + 1)
      {
        printFailure(p, j, oldHandCount);
        ID_LINE;
        fail++;
      }

      //ensure the correct card is discarded
      if (G.discard[p][G.discardCount[p] - 1] != village)
      {
        printFailure(p, j, oldHandCount);
        ID_LINE;
        fail++;
      }
    }
  }
  
  if (fail > 0)
  {
    printf("%d tests failed.\n", fail);
  }else
  {
    printf("ALL TESTS PASSED!\n");
  }
  return 0;
}