mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-08 23:53:31 +02:00
.github
autotools
cmake-proxies
dox2-src
help
images
include
lib-src
FileDialog
expat
ffmpeg
header-substitutes
lame
lib-widget-extra
libflac
libid3tag
libmad
libmp3lame
libnyquist
libogg
libscorealign
libsndfile
libsoxr
libvamp
libvorbis
lv2
mod-null
mod-nyq-bench
mod-script-pipe
mod-track-panel
mpglib
portaudio-v19
portburn
portmidi
autotools
pm_cl
pm_common
pm_csharp
pm_dylib
pm_java
pm_linux
pm_mac
pm_mingw
pm_python
pm_qt
pm_test
CMakeLists.txt
latency.c
latency.vcproj
midiclock.c
midiclock.vcproj
midithread.c
midithread.vcproj
midithru.c
midithru.vcproj
mm.c
mm.vcproj
qtest.c
qtest.vcproj
sysex.c
sysex.vcproj
test.c
test.vcproj
txdata.syx
pm_win
porttime
ALL_BUILD.vcproj
CHANGELOG.txt
CMakeLists.txt
Doxyfile
Makefile.am
Makefile.in
README.txt
ZERO_CHECK.vcproj
configure
configure.ac
license.txt
portmidi-uninstalled.pc.in
portmidi.pc.in
portmidi.sln
portmidi_cdt.zip
portmusic_logo.png
portmixer
portsmf
sbsms
soundtouch
twolame
CMakeLists.txt
Makefile.am
Makefile.in
audacity-patches.txt
dist-libsoxr.mk
dist-libvamp.mk
dist-portaudio.mk
linux
locale
m4
mac
nyq-po
nyquist
plug-ins
presets
qa
scripts
src
tests
win
.gitattributes
.gitignore
.travis.yml
ABOUT-NLS
CHANGELOG.txt
CMakeLists.txt
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Directory.Build.props
INSTALL
LICENSE.txt
Makefile.am
Makefile.in
PULL_REQUEST_TEMPLATE.md
README.md
README.txt
appveyor.yml
audacity.dox
configure
configure.ac
po
todo.txt
175 lines
4.6 KiB
C
175 lines
4.6 KiB
C
#include "portmidi.h"
|
|
#include "pmutil.h"
|
|
#include "stdlib.h"
|
|
#include "stdio.h"
|
|
|
|
|
|
/* make_msg -- make a psuedo-random message of length n whose content
|
|
* is purely a function of i
|
|
*/
|
|
void make_msg(long msg[], int n, int i)
|
|
{
|
|
int j;
|
|
for (j = 0; j < n; j++) {
|
|
msg[j] = i % (j + 5);
|
|
}
|
|
}
|
|
|
|
|
|
/* print_msg -- print the content of msg of length n to stdout */
|
|
/**/
|
|
void print_msg(long msg[], int n)
|
|
{
|
|
int i;
|
|
for (i = 0; i < n; i++) {
|
|
printf(" %li", msg[i]);
|
|
}
|
|
}
|
|
|
|
|
|
/* cmp_msg -- compare two messages of length n */
|
|
/**/
|
|
int cmp_msg(long msg[], long msg2[], int n, int i)
|
|
{
|
|
int j;
|
|
for (j = 0; j < n; j++) {
|
|
if (msg[j] != msg2[j]) {
|
|
printf("Received message %d doesn't match sent message\n", i);
|
|
printf("in: "); print_msg(msg, n); printf("\n");
|
|
printf("out:"); print_msg(msg2, n); printf("\n");
|
|
return FALSE;
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
int main()
|
|
{
|
|
int msg_len;
|
|
for (msg_len = 4; msg_len < 100; msg_len += 5) {
|
|
PmQueue *queue = Pm_QueueCreate(100, msg_len * sizeof(long));
|
|
int i;
|
|
long msg[100];
|
|
long msg2[100];
|
|
|
|
printf("msg_len = %d\n", msg_len);
|
|
if (!queue) {
|
|
printf("Could not allocate queue\n");
|
|
return 1;
|
|
}
|
|
|
|
/* insert/remove 1000 messages */
|
|
printf("test 1\n");
|
|
for (i = 0; i < 1357; i++) {
|
|
make_msg(msg, msg_len, i);
|
|
if (Pm_Enqueue(queue, msg)) {
|
|
printf("Pm_Enqueue error\n");
|
|
return 1;
|
|
}
|
|
if (Pm_Dequeue(queue, msg2) != 1) {
|
|
printf("Pm_Dequeue error\n");
|
|
return 1;
|
|
}
|
|
if (!cmp_msg(msg, msg2, msg_len, i)) {
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
/* make full */
|
|
printf("test 2\n");
|
|
for (i = 0; i < 100; i++) {
|
|
make_msg(msg, msg_len, i);
|
|
if (Pm_Enqueue(queue, msg)) {
|
|
printf("Pm_Enqueue error\n");
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
/* alternately remove and insert */
|
|
for (i = 100; i < 1234; i++) {
|
|
make_msg(msg, msg_len, i - 100); /* what we expect */
|
|
if (Pm_Dequeue(queue, msg2) != 1) {
|
|
printf("Pm_Dequeue error\n");
|
|
return 1;
|
|
}
|
|
if (!cmp_msg(msg, msg2, msg_len, i)) {
|
|
return 1;
|
|
}
|
|
make_msg(msg, msg_len, i);
|
|
if (Pm_Enqueue(queue, msg)) {
|
|
printf("Pm_Enqueue error\n");
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
/* remove all */
|
|
while (!Pm_QueueEmpty(queue)) {
|
|
make_msg(msg, msg_len, i - 100); /* what we expect */
|
|
if (Pm_Dequeue(queue, msg2) != 1) {
|
|
printf("Pm_Dequeue error\n");
|
|
return 1;
|
|
}
|
|
if (!cmp_msg(msg, msg2, msg_len, i)) {
|
|
return 1;
|
|
}
|
|
i++;
|
|
}
|
|
if (i != 1334) {
|
|
printf("Message count error\n");
|
|
return 1;
|
|
}
|
|
|
|
/* now test overflow */
|
|
printf("test 3\n");
|
|
for (i = 0; i < 110; i++) {
|
|
make_msg(msg, msg_len, i);
|
|
if (Pm_Enqueue(queue, msg) == pmBufferOverflow) {
|
|
break; /* this is supposed to execute after 100 messages */
|
|
}
|
|
}
|
|
for (i = 0; i < 100; i++) {
|
|
make_msg(msg, msg_len, i);
|
|
if (Pm_Dequeue(queue, msg2) != 1) {
|
|
printf("Pm_Dequeue error\n");
|
|
return 1;
|
|
}
|
|
if (!cmp_msg(msg, msg2, msg_len, i)) {
|
|
return 1;
|
|
}
|
|
}
|
|
/* we should detect overflow after removing 100 messages */
|
|
if (Pm_Dequeue(queue, msg2) != pmBufferOverflow) {
|
|
printf("Pm_Dequeue overflow expected\n");
|
|
return 1;
|
|
}
|
|
|
|
/* after overflow is detected (and cleared), sender can
|
|
* send again
|
|
*/
|
|
/* see if function is restored, also test peek */
|
|
printf("test 4\n");
|
|
for (i = 0; i < 1357; i++) {
|
|
long *peek;
|
|
make_msg(msg, msg_len, i);
|
|
if (Pm_Enqueue(queue, msg)) {
|
|
printf("Pm_Enqueue error\n");
|
|
return 1;
|
|
}
|
|
peek = (long *) Pm_QueuePeek(queue);
|
|
if (!cmp_msg(msg, peek, msg_len, i)) {
|
|
return 1;
|
|
}
|
|
if (Pm_Dequeue(queue, msg2) != 1) {
|
|
printf("Pm_Dequeue error\n");
|
|
return 1;
|
|
}
|
|
if (!cmp_msg(msg, msg2, msg_len, i)) {
|
|
return 1;
|
|
}
|
|
}
|
|
Pm_QueueDestroy(queue);
|
|
}
|
|
return 0;
|
|
}
|