test/testautomation_stdlib.c
changeset 8645 d69fdbefeecf
parent 7219 c577dfb69153
child 8646 0a20fff4de3c
     1.1 --- a/test/testautomation_stdlib.c	Wed Mar 19 22:43:30 2014 -0400
     1.2 +++ b/test/testautomation_stdlib.c	Wed Mar 19 21:39:55 2014 -0700
     1.3 @@ -119,6 +119,140 @@
     1.4    return TEST_COMPLETED;
     1.5  }
     1.6  
     1.7 +/**
     1.8 + * @brief Call to SDL_getenv and SDL_setenv
     1.9 + */
    1.10 +int
    1.11 +stdlib_getsetenv(void *arg)
    1.12 +{
    1.13 +  const int nameLen = 16;
    1.14 +  int counter;
    1.15 +  int result;
    1.16 +  char name[nameLen + 1];
    1.17 +  char * value1;
    1.18 +  char * value2;
    1.19 +  char * expected;
    1.20 +  int overwrite;
    1.21 +  char * text;
    1.22 +
    1.23 +  /* Create a random name. This tests SDL_getenv, since we need to */
    1.24 +  /* make sure the variable is not set yet (it shouldn't). */
    1.25 +  do {
    1.26 +    for(counter = 0; counter < nameLen; counter++) {
    1.27 +      name[counter] = (char)SDLTest_RandomIntegerInRange(65, 90);
    1.28 +    }
    1.29 +    name[nameLen] = '\0';
    1.30 +    
    1.31 +    text = SDL_getenv(name);
    1.32 +    SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
    1.33 +    if (text != NULL) {
    1.34 +      SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, SDL_strlen(text));
    1.35 +    }
    1.36 +  } while (text != NULL);
    1.37 +   
    1.38 +  /* Create random values to set */                    
    1.39 +  value1 = SDLTest_RandomAsciiStringOfSize(10);
    1.40 +  value2 = SDLTest_RandomAsciiStringOfSize(10);
    1.41 +
    1.42 +  /* Set value 1 without overwrite */
    1.43 +  overwrite = 0;
    1.44 +  expected = value1;
    1.45 +  result = SDL_setenv(name, value1, overwrite);
    1.46 +  SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
    1.47 +  SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
    1.48 +
    1.49 +  /* Check value */
    1.50 +  text = SDL_getenv(name);
    1.51 +  SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
    1.52 +  SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
    1.53 +  if (text != NULL) {
    1.54 +    SDLTest_AssertCheck(
    1.55 +      SDL_strcmp(text, expected) == 0, 
    1.56 +      "Verify returned text, expected: %s, got: %s",
    1.57 +      expected,
    1.58 +      text);
    1.59 +  }
    1.60 +  
    1.61 +  /* Set value 2 with overwrite */
    1.62 +  overwrite = 1;
    1.63 +  expected = value2;    
    1.64 +  result = SDL_setenv(name, value2, overwrite);
    1.65 +  SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value2, overwrite);
    1.66 +  SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
    1.67 +
    1.68 +  /* Check value */
    1.69 +  text = SDL_getenv(name);
    1.70 +  SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
    1.71 +  SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
    1.72 +  if (text != NULL) {
    1.73 +    SDLTest_AssertCheck(
    1.74 +      SDL_strcmp(text, expected) == 0, 
    1.75 +      "Verify returned text, expected: %s, got: %s",
    1.76 +      expected,
    1.77 +      text);
    1.78 +  }
    1.79 +
    1.80 +  /* Set value 1 without overwrite */
    1.81 +  overwrite = 0;
    1.82 +  expected = value2;    
    1.83 +  result = SDL_setenv(name, value1, overwrite);
    1.84 +  SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
    1.85 +  SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
    1.86 +
    1.87 +  /* Check value */
    1.88 +  text = SDL_getenv(name);
    1.89 +  SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
    1.90 +  SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
    1.91 +  if (text != NULL) {
    1.92 +    SDLTest_AssertCheck(
    1.93 +      SDL_strcmp(text, expected) == 0, 
    1.94 +      "Verify returned text, expected: %s, got: %s",
    1.95 +      expected,
    1.96 +      text);
    1.97 +  }
    1.98 +  
    1.99 +  /* Set value 1 without overwrite */
   1.100 +  overwrite = 1;
   1.101 +  expected = value1;
   1.102 +  result = SDL_setenv(name, value1, overwrite);
   1.103 +  SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
   1.104 +  SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
   1.105 +
   1.106 +  /* Check value */
   1.107 +  text = SDL_getenv(name);
   1.108 +  SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
   1.109 +  SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
   1.110 +  if (text != NULL) {
   1.111 +    SDLTest_AssertCheck(
   1.112 +      SDL_strcmp(text, expected) == 0, 
   1.113 +      "Verify returned text, expected: %s, got: %s",
   1.114 +      expected,
   1.115 +      text);
   1.116 +  }
   1.117 +
   1.118 +  /* Negative cases */
   1.119 +  for (overwrite=0; overwrite <= 1; overwrite++) { 
   1.120 +    result = SDL_setenv(NULL, value1, overwrite);
   1.121 +    SDLTest_AssertPass("Call to SDL_setenv(NULL,'%s', %i)", value1, overwrite);
   1.122 +    SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
   1.123 +    result = SDL_setenv("", value1, overwrite);
   1.124 +    SDLTest_AssertPass("Call to SDL_setenv('','%s', %i)", value1, overwrite);
   1.125 +    SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
   1.126 +    result = SDL_setenv("=", value1, overwrite);
   1.127 +    SDLTest_AssertPass("Call to SDL_setenv('=','%s', %i)", value1, overwrite);
   1.128 +    SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
   1.129 +    result = SDL_setenv(name, NULL, overwrite);
   1.130 +    SDLTest_AssertPass("Call to SDL_setenv('%s', NULL, %i)", name, overwrite);
   1.131 +    SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
   1.132 +  }
   1.133 +
   1.134 +  /* Clean up */
   1.135 +  SDL_free(value1);
   1.136 +  SDL_free(value2);
   1.137 +    
   1.138 +  return TEST_COMPLETED;
   1.139 +}
   1.140 +
   1.141  /* ================= Test References ================== */
   1.142  
   1.143  /* Standard C routine test cases */
   1.144 @@ -128,14 +262,17 @@
   1.145  static const SDLTest_TestCaseReference stdlibTest2 =
   1.146          { (SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED };
   1.147  
   1.148 +static const SDLTest_TestCaseReference stdlibTest3 =
   1.149 +        { (SDLTest_TestCaseFp)stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED };
   1.150 +
   1.151  /* Sequence of Standard C routine test cases */
   1.152  static const SDLTest_TestCaseReference *stdlibTests[] =  {
   1.153 -    &stdlibTest1, &stdlibTest2, NULL
   1.154 +    &stdlibTest1, &stdlibTest2, &stdlibTest3, NULL
   1.155  };
   1.156  
   1.157  /* Timer test suite (global) */
   1.158  SDLTest_TestSuiteReference stdlibTestSuite = {
   1.159 -    "Standard C routines",
   1.160 +    "Stdlib",
   1.161      NULL,
   1.162      stdlibTests,
   1.163      NULL