test/testautomation_audio.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 17 Aug 2016 21:04:50 +0200
changeset 10275 ba7dc3ebb81e
parent 9219 c65108ddbeb0
permissions -rw-r--r--
Emscripten: Fixed opening previously closed joystick.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     1
/**
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     2
 * Original code: automated SDL audio test written by Edgar Simo "bobbens"
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     3
 * New/updated tests: aschiffler at ferzkopp dot net
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     4
 */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     5
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
     6
/* quiet windows compiler warnings */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
     7
#define _CRT_SECURE_NO_WARNINGS
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
     8
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     9
#include <stdio.h>
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
    10
#include <string.h>
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    11
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    12
#include "SDL.h"
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    13
#include "SDL_test.h"
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    14
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    15
/* ================= Test Case Implementation ================== */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    16
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    17
/* Fixture */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    18
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    19
void
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    20
_audioSetUp(void *arg)
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    21
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    22
    /* Start SDL audio subsystem */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    23
    int ret = SDL_InitSubSystem( SDL_INIT_AUDIO );
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    24
        SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    25
    SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)");
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    26
    if (ret != 0) {
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    27
           SDLTest_LogError("%s", SDL_GetError());
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    28
        }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    29
}
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    30
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    31
void
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    32
_audioTearDown(void *arg)
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    33
{
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    34
    /* Remove a possibly created file from SDL disk writer audio driver; ignore errors */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    35
    remove("sdlaudio.raw");
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    36
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    37
    SDLTest_AssertPass("Cleanup of test files completed");
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    38
}
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    39
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    40
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    41
/* Global counter for callback invocation */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    42
int _audio_testCallbackCounter;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    43
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    44
/* Global accumulator for total callback length */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    45
int _audio_testCallbackLength;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    46
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    47
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    48
/* Test callback function */
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    49
void _audio_testCallback(void *userdata, Uint8 *stream, int len)
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    50
{
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    51
   /* track that callback was called */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    52
   _audio_testCallbackCounter++;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    53
   _audio_testCallbackLength += len;
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    54
}
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    55
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    56
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    57
/* Test case functions */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    58
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    59
/**
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    60
 * \brief Stop and restart audio subsystem
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    61
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    62
 * \sa https://wiki.libsdl.org/SDL_QuitSubSystem
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    63
 * \sa https://wiki.libsdl.org/SDL_InitSubSystem
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    64
 */
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    65
int audio_quitInitAudioSubSystem()
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    66
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    67
    /* Stop SDL audio subsystem */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    68
    SDL_QuitSubSystem( SDL_INIT_AUDIO );
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    69
        SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    70
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    71
        /* Restart audio again */
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    72
        _audioSetUp(NULL);
7126
6fce42265686 Added missing return statements in test suite for audio.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7094
diff changeset
    73
6fce42265686 Added missing return statements in test suite for audio.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7094
diff changeset
    74
    return TEST_COMPLETED;
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    75
}
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    76
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    77
/**
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    78
 * \brief Start and stop audio directly
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    79
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    80
 * \sa https://wiki.libsdl.org/SDL_InitAudio
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
    81
 * \sa https://wiki.libsdl.org/SDL_QuitAudio
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    82
 */
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    83
int audio_initQuitAudio()
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    84
{
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    85
        int result;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    86
    int i, iMax;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    87
    const char* audioDriver;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    88
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    89
    /* Stop SDL audio subsystem */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    90
    SDL_QuitSubSystem( SDL_INIT_AUDIO );
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    91
        SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    92
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    93
        /* Loop over all available audio drivers */
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    94
        iMax = SDL_GetNumAudioDrivers();
9219
c65108ddbeb0 Added missing brackets in test source assert messages.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8994
diff changeset
    95
        SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    96
        SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
    97
        for (i = 0; i < iMax; i++) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    98
            audioDriver = SDL_GetAudioDriver(i);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
    99
            SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   100
            SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
7721
bdf8c2c84e14 Christoph Mallon: Replace strlen(x) == 0 (O(n)) by x[0] == '\0' (O(1)).
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   101
            SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   102
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   103
            /* Call Init */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   104
            result = SDL_AudioInit(audioDriver);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   105
            SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   106
            SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   107
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   108
            /* Call Quit */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   109
            SDL_AudioQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   110
            SDLTest_AssertPass("Call to SDL_AudioQuit()");
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   111
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   112
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   113
    /* NULL driver specification */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   114
    audioDriver = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   115
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   116
    /* Call Init */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   117
    result = SDL_AudioInit(audioDriver);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   118
    SDLTest_AssertPass("Call to SDL_AudioInit(NULL)");
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   119
    SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   120
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   121
    /* Call Quit */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   122
    SDL_AudioQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   123
    SDLTest_AssertPass("Call to SDL_AudioQuit()");
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   124
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   125
        /* Restart audio again */
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   126
        _audioSetUp(NULL);
7126
6fce42265686 Added missing return statements in test suite for audio.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7094
diff changeset
   127
6fce42265686 Added missing return statements in test suite for audio.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7094
diff changeset
   128
    return TEST_COMPLETED;
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   129
}
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   130
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   131
/**
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   132
 * \brief Start, open, close and stop audio
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   133
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   134
 * \sa https://wiki.libsdl.org/SDL_InitAudio
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   135
 * \sa https://wiki.libsdl.org/SDL_OpenAudio
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   136
 * \sa https://wiki.libsdl.org/SDL_CloseAudio
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   137
 * \sa https://wiki.libsdl.org/SDL_QuitAudio
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   138
 */
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   139
int audio_initOpenCloseQuitAudio()
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   140
{
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   141
    int result, expectedResult;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   142
    int i, iMax, j, k;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   143
    const char* audioDriver;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   144
    SDL_AudioSpec desired;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   145
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   146
    /* Stop SDL audio subsystem */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   147
    SDL_QuitSubSystem( SDL_INIT_AUDIO );
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   148
        SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   149
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   150
        /* Loop over all available audio drivers */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   151
        iMax = SDL_GetNumAudioDrivers();
9219
c65108ddbeb0 Added missing brackets in test source assert messages.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8994
diff changeset
   152
        SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   153
        SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   154
        for (i = 0; i < iMax; i++) {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   155
            audioDriver = SDL_GetAudioDriver(i);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   156
            SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   157
            SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   158
            SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   159
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   160
            /* Change specs */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   161
            for (j = 0; j < 2; j++) {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   162
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   163
                /* Call Init */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   164
                result = SDL_AudioInit(audioDriver);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   165
                SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   166
                SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   167
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   168
                /* Set spec */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   169
                SDL_memset(&desired, 0, sizeof(desired));
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   170
                switch (j) {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   171
                    case 0:
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   172
                    /* Set standard desired spec */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   173
                    desired.freq = 22050;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   174
                    desired.format = AUDIO_S16SYS;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   175
                    desired.channels = 2;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   176
                    desired.samples = 4096;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   177
                    desired.callback = _audio_testCallback;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   178
                    desired.userdata = NULL;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   179
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   180
                    case 1:
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   181
                    /* Set custom desired spec */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   182
                    desired.freq = 48000;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   183
                    desired.format = AUDIO_F32SYS;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   184
                    desired.channels = 2;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   185
                    desired.samples = 2048;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   186
                    desired.callback = _audio_testCallback;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   187
                    desired.userdata = NULL;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   188
                    break;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   189
            }
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   190
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   191
            /* Call Open (maybe multiple times) */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   192
            for (k=0; k <= j; k++) {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   193
                result = SDL_OpenAudio(&desired, NULL);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   194
                SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL), call %d", j, k+1);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   195
                expectedResult = (k==0) ? 0 : -1;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   196
                SDLTest_AssertCheck(result == expectedResult, "Verify return value; expected: %d, got: %d", expectedResult, result);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   197
            }
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   198
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   199
            /* Call Close (maybe multiple times) */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   200
            for (k=0; k <= j; k++) {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   201
                SDL_CloseAudio();
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   202
                SDLTest_AssertPass("Call to SDL_CloseAudio(), call %d", k+1);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   203
            }
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   204
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   205
            /* Call Quit (maybe multiple times) */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   206
            for (k=0; k <= j; k++) {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   207
                SDL_AudioQuit();
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   208
                SDLTest_AssertPass("Call to SDL_AudioQuit(), call %d", k+1);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   209
            }
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   210
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   211
        } /* spec loop */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   212
    } /* driver loop */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   213
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   214
        /* Restart audio again */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   215
        _audioSetUp(NULL);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   216
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   217
    return TEST_COMPLETED;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   218
}
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   219
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   220
/**
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   221
 * \brief Pause and unpause audio
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   222
 *
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   223
 * \sa https://wiki.libsdl.org/SDL_PauseAudio
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   224
 */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   225
int audio_pauseUnpauseAudio()
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   226
{
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   227
    int result;
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   228
    int i, iMax, j, k, l;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   229
    int totalDelay;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   230
    int pause_on;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   231
    int originalCounter;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   232
    const char* audioDriver;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   233
    SDL_AudioSpec desired;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   234
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   235
    /* Stop SDL audio subsystem */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   236
    SDL_QuitSubSystem( SDL_INIT_AUDIO );
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   237
        SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   238
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   239
        /* Loop over all available audio drivers */
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   240
        iMax = SDL_GetNumAudioDrivers();
9219
c65108ddbeb0 Added missing brackets in test source assert messages.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8994
diff changeset
   241
        SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   242
        SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   243
        for (i = 0; i < iMax; i++) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   244
            audioDriver = SDL_GetAudioDriver(i);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   245
            SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   246
            SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
7721
bdf8c2c84e14 Christoph Mallon: Replace strlen(x) == 0 (O(n)) by x[0] == '\0' (O(1)).
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   247
            SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   248
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   249
            /* Change specs */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   250
            for (j = 0; j < 2; j++) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   251
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   252
                /* Call Init */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   253
                result = SDL_AudioInit(audioDriver);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   254
                SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   255
                SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   256
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   257
                /* Set spec */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   258
                SDL_memset(&desired, 0, sizeof(desired));
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   259
                switch (j) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   260
                    case 0:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   261
                    /* Set standard desired spec */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   262
                    desired.freq = 22050;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   263
                    desired.format = AUDIO_S16SYS;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   264
                    desired.channels = 2;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   265
                    desired.samples = 4096;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   266
                    desired.callback = _audio_testCallback;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   267
                    desired.userdata = NULL;
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   268
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   269
                    case 1:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   270
                    /* Set custom desired spec */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   271
                    desired.freq = 48000;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   272
                    desired.format = AUDIO_F32SYS;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   273
                    desired.channels = 2;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   274
                    desired.samples = 2048;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   275
                    desired.callback = _audio_testCallback;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   276
                    desired.userdata = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   277
                    break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   278
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   279
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   280
            /* Call Open */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   281
            result = SDL_OpenAudio(&desired, NULL);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   282
            SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL)", j);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   283
            SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0 got: %d", result);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   284
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   285
            /* Start and stop audio multiple times */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   286
            for (l=0; l<3; l++) {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   287
                SDLTest_Log("Pause/Unpause iteration: %d", l+1);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   288
            
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   289
                /* Reset callback counters */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   290
                _audio_testCallbackCounter = 0;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   291
                _audio_testCallbackLength = 0;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   292
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   293
                /* Un-pause audio to start playing (maybe multiple times) */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   294
                pause_on = 0;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   295
                for (k=0; k <= j; k++) {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   296
                    SDL_PauseAudio(pause_on);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   297
                    SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   298
                }
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   299
            
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   300
                /* Wait for callback */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   301
                totalDelay = 0;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   302
                do {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   303
                    SDL_Delay(10);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   304
                    totalDelay += 10;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   305
                } 
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   306
                while (_audio_testCallbackCounter == 0 && totalDelay < 1000);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   307
                SDLTest_AssertCheck(_audio_testCallbackCounter > 0, "Verify callback counter; expected: >0 got: %d", _audio_testCallbackCounter);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   308
                SDLTest_AssertCheck(_audio_testCallbackLength > 0, "Verify callback length; expected: >0 got: %d", _audio_testCallbackLength);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   309
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   310
                /* Pause audio to stop playing (maybe multiple times) */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   311
                for (k=0; k <= j; k++) {
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   312
                    pause_on = (k==0) ? 1 : SDLTest_RandomIntegerInRange(99, 9999);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   313
                    SDL_PauseAudio(pause_on);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   314
                    SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   315
                }
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   316
            
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   317
                /* Ensure callback is not called again */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   318
                originalCounter = _audio_testCallbackCounter;
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   319
                SDL_Delay(totalDelay + 10);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   320
                SDLTest_AssertCheck(originalCounter == _audio_testCallbackCounter, "Verify callback counter; expected: %d, got: %d", originalCounter, _audio_testCallbackCounter);
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   321
            }
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   322
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   323
            /* Call Close */
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   324
            SDL_CloseAudio();
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   325
            SDLTest_AssertPass("Call to SDL_CloseAudio()");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   326
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   327
            /* Call Quit */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   328
            SDL_AudioQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   329
            SDLTest_AssertPass("Call to SDL_AudioQuit()");
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   330
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   331
        } /* spec loop */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   332
    } /* driver loop */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   333
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   334
    /* Restart audio again */
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   335
    _audioSetUp(NULL);
7126
6fce42265686 Added missing return statements in test suite for audio.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7094
diff changeset
   336
6fce42265686 Added missing return statements in test suite for audio.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7094
diff changeset
   337
    return TEST_COMPLETED;
7093
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   338
}
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   339
f0ede46d5ee7 Add tests to audio suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6897
diff changeset
   340
/**
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   341
 * \brief Enumerate and name available audio devices (output and capture).
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   342
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   343
 * \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   344
 * \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   345
 */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   346
int audio_enumerateAndNameAudioDevices()
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   347
{
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   348
   int t, tt;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   349
   int i, n, nn;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   350
   const char *name, *nameAgain;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   351
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   352
   /* Iterate over types: t=0 output device, t=1 input/capture device */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   353
   for (t=0; t<2; t++) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   354
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   355
      /* Get number of devices. */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   356
      n = SDL_GetNumAudioDevices(t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   357
      SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
6897
865811c9f372 Fix bug 1723: flipped log text in audio suite - thanks P. Wiesemann
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6839
diff changeset
   358
      SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   359
      SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   360
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   361
      /* Variation of non-zero type */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   362
      if (t==1) {
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   363
         tt = t + SDLTest_RandomIntegerInRange(1,10);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   364
         nn = SDL_GetNumAudioDevices(tt);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   365
         SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   366
         nn = SDL_GetNumAudioDevices(-tt);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   367
         SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   368
      }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   369
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   370
      /* List devices. */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   371
      if (n>0) {
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   372
         for (i=0; i<n; i++) {
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   373
            name = SDL_GetAudioDeviceName(i, t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   374
            SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   375
            SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   376
            if (name != NULL) {
7721
bdf8c2c84e14 Christoph Mallon: Replace strlen(x) == 0 (O(n)) by x[0] == '\0' (O(1)).
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   377
              SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   378
              if (t==1) {
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   379
                  /* Also try non-zero type */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   380
                  tt = t + SDLTest_RandomIntegerInRange(1,10);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   381
                  nameAgain = SDL_GetAudioDeviceName(i, tt);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   382
                  SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   383
                  if (nameAgain != NULL) {
7721
bdf8c2c84e14 Christoph Mallon: Replace strlen(x) == 0 (O(n)) by x[0] == '\0' (O(1)).
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   384
                    SDLTest_AssertCheck(nameAgain[0] != '\0', "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   385
                    SDLTest_AssertCheck(SDL_strcmp(name, nameAgain)==0,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   386
                      "Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   387
                      i, t, i, tt);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   388
                  }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   389
               }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   390
            }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   391
         }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   392
      }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   393
   }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   394
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   395
   return TEST_COMPLETED;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   396
}
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   397
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   398
/**
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   399
 * \brief Negative tests around enumeration and naming of audio devices.
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   400
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   401
 * \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   402
 * \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   403
 */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   404
int audio_enumerateAndNameAudioDevicesNegativeTests()
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   405
{
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   406
   int t;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   407
   int i, j, no, nc;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   408
   const char *name;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   409
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   410
   /* Get number of devices. */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   411
   no = SDL_GetNumAudioDevices(0);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   412
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   413
   nc = SDL_GetNumAudioDevices(1);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   414
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   415
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   416
   /* Invalid device index when getting name */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   417
   for (t=0; t<2; t++) {
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   418
      /* Negative device index */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   419
      i = SDLTest_RandomIntegerInRange(-10,-1);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   420
      name = SDL_GetAudioDeviceName(i, t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   421
      SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   422
      SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   423
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   424
      /* Device index past range */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   425
      for (j=0; j<3; j++) {
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   426
         i = (t) ? nc+j : no+j;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   427
         name = SDL_GetAudioDeviceName(i, t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   428
         SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   429
         SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   430
      }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   431
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   432
      /* Capture index past capture range but within output range */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   433
      if ((no>0) && (no>nc) && (t==1)) {
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   434
         i = no-1;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   435
         name = SDL_GetAudioDeviceName(i, t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   436
         SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   437
         SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   438
      }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   439
   }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   440
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   441
   return TEST_COMPLETED;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   442
}
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   443
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   444
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   445
/**
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   446
 * \brief Checks available audio driver names.
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   447
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   448
 * \sa https://wiki.libsdl.org/SDL_GetNumAudioDrivers
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   449
 * \sa https://wiki.libsdl.org/SDL_GetAudioDriver
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   450
 */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   451
int audio_printAudioDrivers()
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   452
{
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   453
   int i, n;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   454
   const char *name;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   455
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   456
   /* Get number of drivers */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   457
   n = SDL_GetNumAudioDrivers();
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   458
   SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   459
   SDLTest_AssertCheck(n>=0, "Verify number of audio drivers >= 0, got: %i", n);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   460
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   461
   /* List drivers. */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   462
   if (n>0)
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   463
   {
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   464
      for (i=0; i<n; i++) {
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   465
         name = SDL_GetAudioDriver(i);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   466
         SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   467
         SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   468
         if (name != NULL) {
7721
bdf8c2c84e14 Christoph Mallon: Replace strlen(x) == 0 (O(n)) by x[0] == '\0' (O(1)).
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   469
            SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   470
         }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   471
      }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   472
   }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   473
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   474
   return TEST_COMPLETED;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   475
}
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   476
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   477
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   478
/**
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   479
 * \brief Checks current audio driver name with initialized audio.
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   480
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   481
 * \sa https://wiki.libsdl.org/SDL_GetCurrentAudioDriver
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   482
 */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   483
int audio_printCurrentAudioDriver()
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   484
{
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   485
   /* Check current audio driver */
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   486
   const char *name = SDL_GetCurrentAudioDriver();
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   487
   SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()");
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   488
   SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   489
   if (name != NULL) {
7721
bdf8c2c84e14 Christoph Mallon: Replace strlen(x) == 0 (O(n)) by x[0] == '\0' (O(1)).
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   490
      SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   491
   }
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   492
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   493
   return TEST_COMPLETED;
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   494
}
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   495
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   496
/* Definition of all formats, channels, and frequencies used to test audio conversions */
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   497
const int _numAudioFormats = 18;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   498
SDL_AudioFormat _audioFormats[] = { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S16SYS, AUDIO_S16, AUDIO_U16LSB,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   499
                AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32,
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   500
                                AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   501
char *_audioFormatsVerbose[] = { "AUDIO_S8", "AUDIO_U8", "AUDIO_S16LSB", "AUDIO_S16MSB", "AUDIO_S16SYS", "AUDIO_S16", "AUDIO_U16LSB",
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   502
                "AUDIO_U16MSB", "AUDIO_U16SYS", "AUDIO_U16", "AUDIO_S32LSB", "AUDIO_S32MSB", "AUDIO_S32SYS", "AUDIO_S32",
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   503
                                "AUDIO_F32LSB", "AUDIO_F32MSB", "AUDIO_F32SYS", "AUDIO_F32" };
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   504
const int _numAudioChannels = 4;
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   505
Uint8 _audioChannels[] = { 1, 2, 4, 6 };
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   506
const int _numAudioFrequencies = 4;
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   507
int _audioFrequencies[] = { 11025, 22050, 44100, 48000 };
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   508
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   509
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   510
/**
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   511
 * \brief Builds various audio conversion structures
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   512
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   513
 * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   514
 */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   515
int audio_buildAudioCVT()
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   516
{
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   517
  int result;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   518
  SDL_AudioCVT  cvt;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   519
  SDL_AudioSpec spec1;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   520
  SDL_AudioSpec spec2;
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   521
  int i, ii, j, jj, k, kk;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   522
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   523
  /* No conversion needed */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   524
  spec1.format = AUDIO_S16LSB;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   525
  spec1.channels = 2;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   526
  spec1.freq = 22050;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   527
  result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   528
                                   spec1.format, spec1.channels, spec1.freq);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   529
  SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec1)");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   530
  SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0, got: %i", result);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   531
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   532
  /* Typical conversion */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   533
  spec1.format = AUDIO_S8;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   534
  spec1.channels = 1;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   535
  spec1.freq = 22050;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   536
  spec2.format = AUDIO_S16LSB;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   537
  spec2.channels = 2;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   538
  spec2.freq = 44100;
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   539
  result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   540
                                   spec2.format, spec2.channels, spec2.freq);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   541
  SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   542
  SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   543
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   544
  /* All source conversions with random conversion targets, allow 'null' conversions */
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   545
  for (i = 0; i < _numAudioFormats; i++) {
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   546
    for (j = 0; j < _numAudioChannels; j++) {
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   547
      for (k = 0; k < _numAudioFrequencies; k++) {
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   548
        spec1.format = _audioFormats[i];
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   549
        spec1.channels = _audioChannels[j];
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   550
        spec1.freq = _audioFrequencies[k];
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   551
        ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   552
        jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   553
        kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   554
        spec2.format = _audioFormats[ii];
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   555
        spec2.channels = _audioChannels[jj];
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   556
        spec2.freq = _audioFrequencies[kk];
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   557
        result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   558
                                         spec2.format, spec2.channels, spec2.freq);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   559
        SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   560
            i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   561
        SDLTest_AssertCheck(result == 0 || result == 1, "Verify result value; expected: 0 or 1, got: %i", result);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   562
        if (result<0) {
8853
a25dcbe4fb02 Fixed format string faults in audio tests.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7721
diff changeset
   563
          SDLTest_LogError("%s", SDL_GetError());
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   564
        } else {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   565
          SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   566
        }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   567
      }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   568
    }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   569
  }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   570
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   571
   return TEST_COMPLETED;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   572
}
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   573
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   574
/**
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   575
 * \brief Checkes calls with invalid input to SDL_BuildAudioCVT
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   576
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   577
 * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   578
 */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   579
int audio_buildAudioCVTNegative()
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   580
{
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   581
  const char *expectedError = "Parameter 'cvt' is invalid";
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   582
  const char *error;
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   583
  int result;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   584
  SDL_AudioCVT  cvt;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   585
  SDL_AudioSpec spec1;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   586
  SDL_AudioSpec spec2;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   587
  int i;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   588
  char message[256];
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   589
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   590
  /* Valid format */
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   591
  spec1.format = AUDIO_S8;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   592
  spec1.channels = 1;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   593
  spec1.freq = 22050;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   594
  spec2.format = AUDIO_S16LSB;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   595
  spec2.channels = 2;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   596
  spec2.freq = 44100;
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   597
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   598
  SDL_ClearError();
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   599
  SDLTest_AssertPass("Call to SDL_ClearError()");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   600
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   601
  /* NULL input for CVT buffer */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   602
  result = SDL_BuildAudioCVT((SDL_AudioCVT *)NULL, spec1.format, spec1.channels, spec1.freq,
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   603
                                                   spec2.format, spec2.channels, spec2.freq);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   604
  SDLTest_AssertPass("Call to SDL_BuildAudioCVT(NULL,...)");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   605
  SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   606
  error = SDL_GetError();
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   607
  SDLTest_AssertPass("Call to SDL_GetError()");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   608
  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   609
  if (error != NULL) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   610
      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   611
          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   612
  }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   613
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   614
  /* Invalid conversions */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   615
  for (i = 1; i < 64; i++) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   616
    /* Valid format to start with */
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   617
    spec1.format = AUDIO_S8;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   618
    spec1.channels = 1;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   619
    spec1.freq = 22050;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   620
    spec2.format = AUDIO_S16LSB;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   621
    spec2.channels = 2;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   622
    spec2.freq = 44100;
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   623
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   624
    SDL_ClearError();
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   625
    SDLTest_AssertPass("Call to SDL_ClearError()");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   626
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   627
    /* Set various invalid format inputs */
6822
18f6818ba281 Add mouse tests; update test suites
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6821
diff changeset
   628
    SDL_strlcpy(message, "Invalid: ", 256);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   629
    if (i & 1) {
6822
18f6818ba281 Add mouse tests; update test suites
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6821
diff changeset
   630
        SDL_strlcat(message, " spec1.format", 256);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   631
        spec1.format = 0;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   632
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   633
    if (i & 2) {
6822
18f6818ba281 Add mouse tests; update test suites
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6821
diff changeset
   634
        SDL_strlcat(message, " spec1.channels", 256);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   635
        spec1.channels = 0;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   636
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   637
    if (i & 4) {
6822
18f6818ba281 Add mouse tests; update test suites
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6821
diff changeset
   638
        SDL_strlcat(message, " spec1.freq", 256);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   639
        spec1.freq = 0;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   640
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   641
    if (i & 8) {
6822
18f6818ba281 Add mouse tests; update test suites
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6821
diff changeset
   642
        SDL_strlcat(message, " spec2.format", 256);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   643
        spec2.format = 0;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   644
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   645
    if (i & 16) {
6822
18f6818ba281 Add mouse tests; update test suites
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6821
diff changeset
   646
        SDL_strlcat(message, " spec2.channels", 256);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   647
        spec2.channels = 0;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   648
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   649
    if (i & 32) {
6822
18f6818ba281 Add mouse tests; update test suites
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6821
diff changeset
   650
        SDL_strlcat(message, " spec2.freq", 256);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   651
        spec2.freq = 0;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   652
    }
8853
a25dcbe4fb02 Fixed format string faults in audio tests.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7721
diff changeset
   653
    SDLTest_Log("%s", message);
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   654
    result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   655
                                   spec2.format, spec2.channels, spec2.freq);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   656
    SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   657
    SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   658
    error = SDL_GetError();
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   659
    SDLTest_AssertPass("Call to SDL_GetError()");
7721
bdf8c2c84e14 Christoph Mallon: Replace strlen(x) == 0 (O(n)) by x[0] == '\0' (O(1)).
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   660
    SDLTest_AssertCheck(error != NULL && error[0] != '\0', "Validate that error message was not NULL or empty");
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   661
  }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   662
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   663
  SDL_ClearError();
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   664
  SDLTest_AssertPass("Call to SDL_ClearError()");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   665
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   666
  return TEST_COMPLETED;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   667
}
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   668
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   669
/**
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   670
 * \brief Checks current audio status.
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   671
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   672
 * \sa https://wiki.libsdl.org/SDL_GetAudioStatus
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   673
 */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   674
int audio_getAudioStatus()
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   675
{
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   676
   SDL_AudioStatus result;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   677
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   678
   /* Check current audio status */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   679
   result = SDL_GetAudioStatus();
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   680
   SDLTest_AssertPass("Call to SDL_GetAudioStatus()");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   681
   SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   682
        "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   683
        SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   684
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   685
   return TEST_COMPLETED;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   686
}
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   687
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   688
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   689
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   690
/**
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   691
 * \brief Opens, checks current audio status, and closes a device.
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   692
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   693
 * \sa https://wiki.libsdl.org/SDL_GetAudioStatus
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   694
 */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   695
int audio_openCloseAndGetAudioStatus()
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   696
{
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   697
   SDL_AudioStatus result;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   698
   int i;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   699
   int count;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   700
   char *device;
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   701
   SDL_AudioDeviceID id;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   702
   SDL_AudioSpec desired, obtained;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   703
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   704
   /* Get number of devices. */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   705
   count = SDL_GetNumAudioDevices(0);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   706
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   707
   if (count > 0) {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   708
     for (i = 0; i < count; i++) {
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   709
       /* Get device name */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   710
       device = (char *)SDL_GetAudioDeviceName(i, 0);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   711
       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   712
       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   713
       if (device == NULL) return TEST_ABORTED;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   714
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   715
       /* Set standard desired spec */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   716
       desired.freq=22050;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   717
       desired.format=AUDIO_S16SYS;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   718
       desired.channels=2;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   719
       desired.samples=4096;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   720
       desired.callback=_audio_testCallback;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   721
       desired.userdata=NULL;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   722
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   723
       /* Open device */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   724
       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   725
       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   726
       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   727
       if (id > 1) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   728
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   729
         /* Check device audio status */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   730
         result = SDL_GetAudioDeviceStatus(id);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   731
         SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   732
         SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   733
            "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   734
            SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   735
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   736
         /* Close device again */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   737
         SDL_CloseAudioDevice(id);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   738
         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   739
       }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   740
     }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   741
   } else {
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   742
     SDLTest_Log("No devices to test with");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   743
   }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   744
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   745
   return TEST_COMPLETED;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   746
}
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   747
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   748
/**
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   749
 * \brief Locks and unlocks open audio device.
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   750
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   751
 * \sa https://wiki.libsdl.org/SDL_LockAudioDevice
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   752
 * \sa https://wiki.libsdl.org/SDL_UnlockAudioDevice
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   753
 */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   754
int audio_lockUnlockOpenAudioDevice()
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   755
{
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   756
   int i;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   757
   int count;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   758
   char *device;
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   759
   SDL_AudioDeviceID id;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   760
   SDL_AudioSpec desired, obtained;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   761
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   762
   /* Get number of devices. */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   763
   count = SDL_GetNumAudioDevices(0);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   764
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   765
   if (count > 0) {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   766
     for (i = 0; i < count; i++) {
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   767
       /* Get device name */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   768
       device = (char *)SDL_GetAudioDeviceName(i, 0);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   769
       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   770
       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   771
       if (device == NULL) return TEST_ABORTED;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   772
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   773
       /* Set standard desired spec */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   774
       desired.freq=22050;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   775
       desired.format=AUDIO_S16SYS;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   776
       desired.channels=2;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   777
       desired.samples=4096;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   778
       desired.callback=_audio_testCallback;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   779
       desired.userdata=NULL;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   780
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   781
       /* Open device */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   782
       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   783
       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   784
       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   785
       if (id > 1) {
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   786
         /* Lock to protect callback */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   787
         SDL_LockAudioDevice(id);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   788
         SDLTest_AssertPass("SDL_LockAudioDevice(%i)", id);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   789
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   790
         /* Simulate callback processing */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   791
         SDL_Delay(10);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   792
         SDLTest_Log("Simulate callback processing - delay");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   793
7677
871d43c6968a OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   794
         /* Unlock again */
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   795
         SDL_UnlockAudioDevice(id);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   796
         SDLTest_AssertPass("SDL_UnlockAudioDevice(%i)", id);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   797
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   798
         /* Close device again */
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   799
         SDL_CloseAudioDevice(id);
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   800
         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   801
       }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   802
     }
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   803
   } else {
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   804
     SDLTest_Log("No devices to test with");
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   805
   }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   806
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   807
   return TEST_COMPLETED;
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   808
}
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   809
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   810
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   811
/**
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   812
 * \brief Convert audio using various conversion structures
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   813
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   814
 * \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   815
 * \sa https://wiki.libsdl.org/SDL_ConvertAudio
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   816
 */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   817
int audio_convertAudio()
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   818
{
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   819
  int result;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   820
  SDL_AudioCVT  cvt;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   821
  SDL_AudioSpec spec1;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   822
  SDL_AudioSpec spec2;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   823
  int c;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   824
  char message[128];
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   825
  int i, ii, j, jj, k, kk, l, ll;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   826
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   827
  /* Iterate over bitmask that determines which parameters are modified in the conversion */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   828
  for (c = 1; c < 8; c++) {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   829
    SDL_strlcpy(message, "Changing:", 128);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   830
    if (c & 1) {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   831
      SDL_strlcat(message, " Format", 128);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   832
    }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   833
    if (c & 2) {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   834
      SDL_strlcat(message, " Channels", 128);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   835
    }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   836
    if (c & 4) {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   837
      SDL_strlcat(message, " Frequencies", 128);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   838
    }
8853
a25dcbe4fb02 Fixed format string faults in audio tests.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7721
diff changeset
   839
    SDLTest_Log("%s", message);
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   840
    /* All source conversions with random conversion targets */
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   841
    for (i = 0; i < _numAudioFormats; i++) {
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   842
      for (j = 0; j < _numAudioChannels; j++) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   843
        for (k = 0; k < _numAudioFrequencies; k++) {
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   844
          spec1.format = _audioFormats[i];
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   845
          spec1.channels = _audioChannels[j];
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   846
          spec1.freq = _audioFrequencies[k];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   847
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   848
          /* Ensure we have a different target format */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   849
          do {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   850
            if (c & 1) {
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   851
              ii = SDLTest_RandomIntegerInRange(0, _numAudioFormats - 1);
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   852
            } else {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   853
              ii = 1;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   854
            }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   855
            if (c & 2) {
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   856
              jj = SDLTest_RandomIntegerInRange(0, _numAudioChannels - 1);
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   857
            } else {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   858
              jj= j;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   859
            }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   860
            if (c & 4) {
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   861
              kk = SDLTest_RandomIntegerInRange(0, _numAudioFrequencies - 1);
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   862
            } else {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   863
              kk = k;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   864
            }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   865
          } while ((i == ii) && (j == jj) && (k == kk));
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   866
          spec2.format = _audioFormats[ii];
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   867
          spec2.channels = _audioChannels[jj];
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   868
          spec2.freq = _audioFrequencies[kk];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   869
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   870
          result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   871
                                           spec2.format, spec2.channels, spec2.freq);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   872
          SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
7134
09ee216e6a25 Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7126
diff changeset
   873
            i, _audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   874
          SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   875
          if (result != 1) {
8853
a25dcbe4fb02 Fixed format string faults in audio tests.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7721
diff changeset
   876
            SDLTest_LogError("%s", SDL_GetError());
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   877
          } else {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   878
            SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   879
            if (cvt.len_mult < 1) return TEST_ABORTED;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   880
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   881
            /* Create some random data to convert */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   882
            l = 64;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   883
            ll = l * cvt.len_mult;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   884
            SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, ll);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   885
            cvt.len = l;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   886
            cvt.buf = (Uint8 *)SDL_malloc(ll);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   887
            SDLTest_AssertCheck(cvt.buf != NULL, "Check data buffer to convert is not NULL");
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   888
            if (cvt.buf == NULL) return TEST_ABORTED;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   889
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   890
            /* Convert the data */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   891
            result = SDL_ConvertAudio(&cvt);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   892
            SDLTest_AssertPass("Call to SDL_ConvertAudio()");
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   893
            SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0; got: %i", result);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   894
            SDLTest_AssertCheck(cvt.buf != NULL, "Verify conversion buffer is not NULL");
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   895
            SDLTest_AssertCheck(cvt.len_ratio > 0.0, "Verify conversion length ratio; expected: >0; got: %f", cvt.len_ratio);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   896
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   897
            /* Free converted buffer */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   898
            SDL_free(cvt.buf);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   899
            cvt.buf = NULL;
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7677
diff changeset
   900
          }
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   901
        }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   902
      }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   903
    }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   904
  }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   905
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   906
   return TEST_COMPLETED;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   907
}
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   908
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   909
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   910
/**
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   911
 * \brief Opens, checks current connected status, and closes a device.
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   912
 *
8994
b80b0595975c Update audio testautomation: more coverage; added SDL_PauseAudio test /w callback coverage
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 8989
diff changeset
   913
 * \sa https://wiki.libsdl.org/SDL_AudioDeviceConnected
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   914
 */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   915
int audio_openCloseAudioDeviceConnected()
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   916
{
6839
2494f667555c Add SDL_test test suite; add fuzzer test cases; fix fuzzer bug; fix compiler warnings
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6830
diff changeset
   917
   int result = -1;
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   918
   int i;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   919
   int count;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   920
   char *device;
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   921
   SDL_AudioDeviceID id;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   922
   SDL_AudioSpec desired, obtained;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   923
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   924
   /* Get number of devices. */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   925
   count = SDL_GetNumAudioDevices(0);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   926
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   927
   if (count > 0) {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   928
     for (i = 0; i < count; i++) {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   929
       /* Get device name */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   930
       device = (char *)SDL_GetAudioDeviceName(i, 0);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   931
       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   932
       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   933
       if (device == NULL) return TEST_ABORTED;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   934
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   935
       /* Set standard desired spec */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   936
       desired.freq=22050;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   937
       desired.format=AUDIO_S16SYS;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   938
       desired.channels=2;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   939
       desired.samples=4096;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   940
       desired.callback=_audio_testCallback;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   941
       desired.userdata=NULL;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   942
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   943
       /* Open device */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   944
       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   945
       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
6839
2494f667555c Add SDL_test test suite; add fuzzer test cases; fix fuzzer bug; fix compiler warnings
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6830
diff changeset
   946
       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %i", id);
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   947
       if (id > 1) {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   948
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   949
/* TODO: enable test code when function is available in SDL2 */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   950
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   951
#ifdef AUDIODEVICECONNECTED_DEFINED
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   952
         /* Get connected status */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   953
         result = SDL_AudioDeviceConnected(id);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   954
         SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   955
#endif
6839
2494f667555c Add SDL_test test suite; add fuzzer test cases; fix fuzzer bug; fix compiler warnings
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6830
diff changeset
   956
         SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   957
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   958
         /* Close device again */
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   959
         SDL_CloseAudioDevice(id);
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   960
         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   961
       }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   962
     }
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   963
   } else {
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   964
     SDLTest_Log("No devices to test with");
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   965
   }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   966
6830
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   967
   return TEST_COMPLETED;
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   968
}
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   969
0cd3e2e9b2c5 Add tests to audio suite; update harness filter logic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6822
diff changeset
   970
6819
afef68703f54 Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6772
diff changeset
   971
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   972
/* ================= Test Case References ================== */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   973
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   974
/* Audio test cases */
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   975
static const SDLTest_TestCaseReference audioTest1 =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   976
        { (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED };
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   977
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   978
static const SDLTest_TestCaseReference audioTest2 =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7134
diff changeset
   979
        { (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevicesNegativeTests, "audio_enumerateAndNameAudioDevicesNegativeTests", "Negative tests around enumeration and naming of audio devices.", TEST_ENABLED };
6772
5229a117ef97 Added audio test suite; minor code cleanups in test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset