Generated from /home/galaxyng/NG/Source/selftest.c with ROBODoc v4.0.18 on Mon Jan 05 22:26:08 2004

TABLE OF CONTENTS


GalaxyNG/SelfTest

NAME

   SelfTest -- 

PURPOSE

   A number of funtions to test the engine for bugs.
   
   The main test is a series of functions that transferse the
   game structure and do various tests on the data.

   There are also some functions that test some key functions
   of the engine.

SelfTest/checkIntegrity

NAME

   checkIntegrity -- check integrity of game structure.

SYNOPSIS

   int      checkIntegrity(game *)
   result = checkIntegrity(aGame)

FUNCTION

   Check the integrity of the game structure. This is done
   going over the whole game structure and checking whether
   parameters have sensible values and pointers point to
   valid structures (using the COOKIE values).

DIAGNOSTICS

   All errors that are encountered are reported in the log file.
   Set logLevel to LFULL to get detailed output on the location
   of the error.

RESULT

   TRUE  -- All OK
   FALSE -- Something is terribly wrong.

SOURCE

    int checkIntegrity(game *aGame)
    {
      planet         *aPlanet;
      player         *aPlayer;
      battle         *aBattle;
      int             check;
    
      plog(LFULL, "Checking Integrity\n");
    
      check = TRUE && checkStrlist(aGame->messages);
    
      for (aPlanet = aGame->planets; 
           aPlanet; 
           aPlanet = aPlanet->next) {
        check = check && checkPlanet(aPlanet);
      }
    
      for (aPlayer = aGame->players; aPlayer; aPlayer = aPlayer->next) {
        if (checkPlayer(aPlayer)) {
          plog(LFULL, "\n** %s **\n", aPlayer->name);
          plog(LFULL, "GROUPS:   ");
          check = checkGroups(aPlayer->groups) && check;
          plog(LFULL, "FLEET:    ");
          check = checkFleetNames(aPlayer->fleetnames) && check;
          plog(LFULL, "FLEETS:   ");
          check = checkFleets(aPlayer) && check;
          plog(LFULL, "MESSAGES: ");
          check = checkStrlist(aPlayer->messages) && check;
          plog(LFULL, "MISTAKES: ");
          check = checkStrlist(aPlayer->mistakes) && check;
          plog(LFULL, "ORDERS:   ");
          check = checkStrlist(aPlayer->orders) && check;
        } else {
          check = FALSE;
        }
      }
    
      for (aBattle = aGame->battles; 
           aBattle; 
           aBattle = aBattle->next) {
        plog(LFULL, "o battle\n");
        check = checkBattle(aBattle) && check;
        plog(LFULL, "o participants\n");
        check = checkParticipants(aBattle->participants) && check;
      }
      
      if (!check) {
        plog(LBRIEF, "One of the integrity checks failed!\n");
      }
      return check;
    }
    

SelfTest/checkFleets

NAME

   checkFleets -- check the speeds of all fleets.

FUNCTION

   Checks if a fleet has groups with a speed that is slower
   that the given fleet speed.

SelfTest/checkStrlist

NAME

   checkStrlist -- check all strings in a string list.

FUNCTION

   Check if the list of strings is really a list of string.

SelfTest/checkParticipants

NAME

   checkParticipants --

SelfTest/checkPlanet

NAME

   checkPlanet --

SelfTest/checkPlayer

NAME

   checkPlayer --

SOURCE

    int
    checkPlayer(player *aPlayer)
    {
      if (!isStruct(player, aPlayer)) {
        plog(LBRIEF, "!!not a player");
        return FALSE;
      }
      return TRUE;
    }
    

SelfTest/checkFleetNames

NAME

   checkFleetNames --

SOURCE

    int
    checkFleetNames(fleetname *aFleetName)
    {
      int result = TRUE;
      for (; aFleetName; aFleetName = aFleetName->next) {
        plog(LFULL, "(");
        if (!isStruct(fleetname, aFleetName)) {
          plog(LBRIEF, "!!not a fleetname");
          result = FALSE;
        } else {
          plog(LFULL, "%s)", aFleetName->name);
        }
      }
      plog(LFULL, "\n");
      return TRUE;
    }
    

SelfTest/checkGroups

NAME

   checkGroups --

SOURCE

    int
    checkGroups(group *aGroup)
    {
      int result = TRUE;
    
      for (; aGroup; aGroup = aGroup->next) {
        plog(LFULL, "(%d", aGroup->number);
        if (!isStruct(group, aGroup)) {
          plog(LBRIEF, "!!not a group\n");
          result = FALSE;
        }
        if (!isStruct(shiptype, aGroup->type)) {
          plog(LBRIEF, "!!group.shiptype is not a shiptype");
          result = FALSE;
        }
        if (aGroup->from) {
          if (!checkPlanet(aGroup->from)) {
            plog(LBRIEF, "!!group.from is not a planet");
            result = FALSE;
          }
        }
        if (aGroup->where) {
          if (!checkPlanet(aGroup->where)) {
            plog(LBRIEF, "!!group.where is not a planet");
            result = FALSE;
          }
        }
        if (aGroup->location) {
          if (!checkPlanet(aGroup->location)) {
            plog(LBRIEF, "!!group.location is not a planet");
            result = FALSE;
          }
        }
        if (aGroup->thefleet) {
          if (!isStruct(fleetname, aGroup->thefleet)) {
            plog(LBRIEF, "!!group.thefleet is not a fleetname");
            result = FALSE;
          }
        }
        if (aGroup->ships < 0) {
          plog(LBRIEF, "!!group.ships < 0");
          result = FALSE;
        }
        if (aGroup->left < 0) {
          plog(LBRIEF, "!!group.left < 0");
          result = FALSE;
        }
        if (aGroup->defense < 0.0) {
          plog(LBRIEF, "!!group.defense < 0");
          result = FALSE;
        }
        if (aGroup->attack < 0.0) {
          plog(LBRIEF, "!!group.attack < 0");
          result = FALSE;
        }
        plog(LFULL, ")", aGroup->number);
      }
      plog(LFULL, "\n");
      return result;
    }
    

SelfTest/checkBattle

NAME

   checkBattle --

SOURCE

    int
    checkBattle(battle *aBattle)
    {
      if (!isStruct(battle, aBattle)) {
        plog(LBRIEF, "  not a battle\n");
        return FALSE;
      }
      return TRUE;
    }
    

SelfTest/getstrTest

NAME

   getstrTest -- Test getstr() function.

FUNCTION

   The getstr() function is one of the most used function of the
   server. Most of the input passes through this function. This
   performs some sanity checks on this function.

RESULT

   The program aborts if an error was found.

SOURCE

    char *tststr1 = "word1  word2,word3  word4\n";
    char *tststr2 = "  \"Word Word 1 <<;; <\" \"; a remark ;\n";
    
    void getstrTest(void)
    {
      char *word;
      int result;
      
      result = TRUE;
      printf("---- Testing: getstr() ----\n");
      printf("  with string:   %s", tststr1);
      word = getstr(tststr1);
      assert (strcmp(word, "word1") == 0);
      word = getstr(NULL);
      assert (strcmp(word, "word2") == 0);
      word = getstr(NULL);
      assert (strcmp(word, "word3") == 0);
      word = getstr(NULL);
      assert (strcmp(word, "word4") == 0); 
      printf("  string is now: %s", tststr1);
      printf("  with string:   %s", tststr2);
      word = getstr(tststr2);
      assert (strcmp(word, "Word_Word_1__") == 0);
      word = getstr(NULL);
      assert (strcmp(word, "_a_remark__") == 0);
      printf("  string is now: %s", tststr2);
      printf("---- completed ----\n");
    }
    

SelfTest/frandTest

NAME

   frandTest