summaryrefslogtreecommitdiff
path: root/portmidi/pm_test/qtest.c
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-10-07 19:30:56 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-10-07 19:30:56 +0200
commit40a899bd6ee536eae093337bf2d0dcc8db4e46f1 (patch)
tree485ace3e6fd28b91f394efd277732651e10824d8 /portmidi/pm_test/qtest.c
parent6fc4bddfdf8e056469f316c1a0fe488efbb4253a (diff)
downloadttdaw-40a899bd6ee536eae093337bf2d0dcc8db4e46f1.tar.gz
Moved example code examples folder
Diffstat (limited to 'portmidi/pm_test/qtest.c')
-rw-r--r--portmidi/pm_test/qtest.c174
1 files changed, 0 insertions, 174 deletions
diff --git a/portmidi/pm_test/qtest.c b/portmidi/pm_test/qtest.c
deleted file mode 100644
index 14d803e..0000000
--- a/portmidi/pm_test/qtest.c
+++ /dev/null
@@ -1,174 +0,0 @@
-#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;
-}