test/testautomation_stdlib.c
changeset 10782 1de6d4633ee6
parent 10189 4844b48eb17b
equal deleted inserted replaced
10781:7c19d6525105 10782:1de6d4633ee6
    23 
    23 
    24   result = SDL_strlcpy(text, "foo", sizeof(text));
    24   result = SDL_strlcpy(text, "foo", sizeof(text));
    25   expected = "foo";
    25   expected = "foo";
    26   SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
    26   SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
    27   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    27   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    28   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    28   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), (int) result);
    29 
    29 
    30   result = SDL_strlcpy(text, "foo", 2);
    30   result = SDL_strlcpy(text, "foo", 2);
    31   expected = "f";
    31   expected = "f";
    32   SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
    32   SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
    33   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    33   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    34   SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
    34   SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", (int) result);
    35 
    35 
    36   return TEST_COMPLETED;
    36   return TEST_COMPLETED;
    37 }
    37 }
    38 
    38 
    39 /**
    39 /**
    49 
    49 
    50   result = SDL_snprintf(text, sizeof(text), "%s", "foo");
    50   result = SDL_snprintf(text, sizeof(text), "%s", "foo");
    51   expected = "foo";
    51   expected = "foo";
    52   SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
    52   SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
    53   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    53   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    54   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    54   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
    55 
    55 
    56   result = SDL_snprintf(text, 2, "%s", "foo");
    56   result = SDL_snprintf(text, 2, "%s", "foo");
    57   expected = "f";
    57   expected = "f";
    58   SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
    58   SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
    59   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    59   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    64 
    64 
    65   result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
    65   result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
    66   expected = "1.000000";
    66   expected = "1.000000";
    67   SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
    67   SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
    68   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    68   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    69   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    69   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
    70 
    70 
    71   result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
    71   result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
    72   expected = "1";
    72   expected = "1";
    73   SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
    73   SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
    74   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    74   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    75   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    75   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
    76 
    76 
    77   result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
    77   result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
    78   expected = "1.";
    78   expected = "1.";
    79   SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
    79   SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
    80   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    80   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    81   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    81   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
    82 
    82 
    83   result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
    83   result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
    84   expected = "1.333333";
    84   expected = "1.333333";
    85   SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
    85   SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
    86   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    86   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    87   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    87   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
    88 
    88 
    89   result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
    89   result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
    90   expected = "+1.333333";
    90   expected = "+1.333333";
    91   SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
    91   SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
    92   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    92   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    93   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    93   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
    94 
    94 
    95   result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
    95   result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
    96   expected = "1.33";
    96   expected = "1.33";
    97   SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
    97   SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
    98   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    98   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    99   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    99   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
   100 
   100 
   101   result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
   101   result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
   102   expected = "  1.33";
   102   expected = "  1.33";
   103   SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
   103   SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
   104   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
   104   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
   105   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
   105   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
   106 
   106 
   107   result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
   107   result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
   108   expected = "001.33";
   108   expected = "001.33";
   109   SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
   109   SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
   110   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
   110   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
   111   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
   111   SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
   112 
   112 
   113   result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
   113   result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
   114   expected = "001.";
   114   expected = "001.";
   115   SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
   115   SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
   116   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
   116   SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
   144     name[nameLen] = '\0';
   144     name[nameLen] = '\0';
   145     
   145     
   146     text = SDL_getenv(name);
   146     text = SDL_getenv(name);
   147     SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
   147     SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
   148     if (text != NULL) {
   148     if (text != NULL) {
   149       SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, SDL_strlen(text));
   149       SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int) SDL_strlen(text));
   150     }
   150     }
   151   } while (text != NULL);
   151   } while (text != NULL);
   152    
   152    
   153   /* Create random values to set */                    
   153   /* Create random values to set */                    
   154   value1 = SDLTest_RandomAsciiStringOfSize(10);
   154   value1 = SDLTest_RandomAsciiStringOfSize(10);