test/testautomation_stdlib.c
author Edward Rudd <urkle@outoforder.cc>
Sat, 12 Oct 2013 11:21:40 -0400
changeset 7807 73da2747c268
parent 7219 c577dfb69153
child 8645 d69fdbefeecf
permissions -rw-r--r--
added simple Drag & drop test
slouken@7216
     1
/**
slouken@7216
     2
 * Standard C library routine test suite
slouken@7216
     3
 */
slouken@7216
     4
slouken@7216
     5
#include <stdio.h>
slouken@7216
     6
slouken@7216
     7
#include "SDL.h"
slouken@7216
     8
#include "SDL_test.h"
slouken@7216
     9
slouken@7216
    10
slouken@7216
    11
/* Test case functions */
slouken@7216
    12
slouken@7216
    13
/**
slouken@7216
    14
 * @brief Call to SDL_strlcpy
slouken@7216
    15
 */
slouken@7216
    16
#undef SDL_strlcpy
slouken@7216
    17
int
slouken@7216
    18
stdlib_strlcpy(void *arg)
slouken@7216
    19
{
slouken@7216
    20
  size_t result;
slouken@7216
    21
  char text[1024];
slouken@7216
    22
  const char *expected;
slouken@7216
    23
slouken@7216
    24
  result = SDL_strlcpy(text, "foo", sizeof(text));
slouken@7216
    25
  expected = "foo";
slouken@7216
    26
  SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
slouken@7216
    27
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    28
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
    29
slouken@7216
    30
  result = SDL_strlcpy(text, "foo", 2);
slouken@7216
    31
  expected = "f";
slouken@7216
    32
  SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
slouken@7216
    33
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    34
  SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
slouken@7216
    35
slouken@7216
    36
  return TEST_COMPLETED;
slouken@7216
    37
}
slouken@7216
    38
slouken@7216
    39
/**
slouken@7216
    40
 * @brief Call to SDL_snprintf
slouken@7216
    41
 */
slouken@7216
    42
#undef SDL_snprintf
slouken@7216
    43
int
slouken@7216
    44
stdlib_snprintf(void *arg)
slouken@7216
    45
{
slouken@7216
    46
  int result;
slouken@7216
    47
  char text[1024];
slouken@7216
    48
  const char *expected;
slouken@7216
    49
slouken@7216
    50
  result = SDL_snprintf(text, sizeof(text), "%s", "foo");
slouken@7216
    51
  expected = "foo";
slouken@7216
    52
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
slouken@7216
    53
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    54
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
    55
slouken@7216
    56
  result = SDL_snprintf(text, 2, "%s", "foo");
slouken@7216
    57
  expected = "f";
slouken@7216
    58
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
slouken@7216
    59
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    60
  SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
slouken@7216
    61
slouken@7216
    62
  result = SDL_snprintf(NULL, 0, "%s", "foo");
slouken@7216
    63
  SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
slouken@7216
    64
slouken@7216
    65
  result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
slouken@7216
    66
  expected = "1.000000";
slouken@7216
    67
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
slouken@7216
    68
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    69
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
    70
slouken@7216
    71
  result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
slouken@7216
    72
  expected = "1";
slouken@7216
    73
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
slouken@7216
    74
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    75
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
    76
slouken@7216
    77
  result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
slouken@7216
    78
  expected = "1.";
slouken@7216
    79
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
slouken@7216
    80
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    81
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
    82
slouken@7216
    83
  result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
slouken@7216
    84
  expected = "1.333333";
slouken@7216
    85
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
slouken@7216
    86
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    87
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
    88
slouken@7216
    89
  result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
slouken@7216
    90
  expected = "+1.333333";
slouken@7216
    91
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
slouken@7216
    92
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    93
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
    94
slouken@7216
    95
  result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
slouken@7216
    96
  expected = "1.33";
slouken@7216
    97
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
slouken@7216
    98
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
slouken@7216
    99
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
   100
slouken@7216
   101
  result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
slouken@7216
   102
  expected = "  1.33";
slouken@7216
   103
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
slouken@7216
   104
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
slouken@7216
   105
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
   106
slouken@7216
   107
  result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
slouken@7216
   108
  expected = "001.33";
slouken@7216
   109
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
slouken@7216
   110
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
slouken@7216
   111
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
slouken@7216
   112
slouken@7216
   113
  result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
slouken@7216
   114
  expected = "001.";
slouken@7216
   115
  SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
slouken@7216
   116
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
slouken@7216
   117
  SDLTest_AssertCheck(result == 6, "Check result value, expected: 6, got: %d", result);
slouken@7216
   118
slouken@7216
   119
  return TEST_COMPLETED;
slouken@7216
   120
}
slouken@7216
   121
slouken@7216
   122
/* ================= Test References ================== */
slouken@7216
   123
slouken@7216
   124
/* Standard C routine test cases */
slouken@7216
   125
static const SDLTest_TestCaseReference stdlibTest1 =
slouken@7216
   126
        { (SDLTest_TestCaseFp)stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED };
slouken@7216
   127
slouken@7216
   128
static const SDLTest_TestCaseReference stdlibTest2 =
philipp@7219
   129
        { (SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED };
slouken@7216
   130
slouken@7216
   131
/* Sequence of Standard C routine test cases */
slouken@7216
   132
static const SDLTest_TestCaseReference *stdlibTests[] =  {
slouken@7216
   133
    &stdlibTest1, &stdlibTest2, NULL
slouken@7216
   134
};
slouken@7216
   135
slouken@7216
   136
/* Timer test suite (global) */
slouken@7216
   137
SDLTest_TestSuiteReference stdlibTestSuite = {
slouken@7216
   138
    "Standard C routines",
slouken@7216
   139
    NULL,
slouken@7216
   140
    stdlibTests,
slouken@7216
   141
    NULL
slouken@7216
   142
};