Skip to content

Commit

Permalink
Add a minimal test program for the C API. (thestk#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
radarsat1 authored Aug 11, 2021
1 parent 439f049 commit 99c4a3b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

# Define a C++ project.
project(RtMidi LANGUAGES CXX)
project(RtMidi LANGUAGES CXX C)

# standards version
set(CMAKE_CXX_STANDARD 11)
Expand Down Expand Up @@ -200,6 +200,7 @@ target_link_libraries(rtmidi PUBLIC ${PUBLICLINKLIBS}
include(GNUInstallDirs)

# Add tests if requested.
option(RTMIDI_BUILD_TESTING "Build test programs" ON)
if (NOT DEFINED RTMIDI_BUILD_TESTING OR RTMIDI_BUILD_TESTING STREQUAL "")
set(RTMIDI_BUILD_TESTING ${BUILD_TESTING})
endif()
Expand All @@ -212,8 +213,9 @@ if (RTMIDI_BUILD_TESTING)
add_executable(qmidiin tests/qmidiin.cpp)
add_executable(sysextest tests/sysextest.cpp)
add_executable(apinames tests/apinames.cpp)
add_executable(testcapi tests/testcapi.c)
list(GET LIB_TARGETS 0 LIBRTMIDI)
set_target_properties(cmidiin midiclock midiout midiprobe qmidiin sysextest apinames
set_target_properties(cmidiin midiclock midiout midiprobe qmidiin sysextest apinames testcapi
PROPERTIES RUNTIME_OUTPUT_DIRECTORY tests
INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}
LINK_LIBRARIES ${LIBRTMIDI})
Expand Down
7 changes: 6 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

noinst_PROGRAMS = midiprobe midiout qmidiin cmidiin sysextest midiclock_in midiclock_out apinames
noinst_PROGRAMS = midiprobe midiout qmidiin cmidiin sysextest midiclock_in midiclock_out \
apinames testcapi

AM_CXXFLAGS = -Wall -I$(top_srcdir)
AM_CFLAGS = -Wall -I$(top_srcdir)

midiprobe_SOURCES = midiprobe.cpp
midiprobe_LDADD = $(top_builddir)/librtmidi.la
Expand All @@ -27,6 +29,9 @@ midiclock_out_LDADD = $(top_builddir)/librtmidi.la
apinames_SOURCES = apinames.cpp
apinames_LDADD = $(top_builddir)/librtmidi.la

testcapi_SOURCES = testcapi.c
testcapi_LDADD = $(top_builddir)/librtmidi.la

EXTRA_DIST = cmidiin.dsp midiout.dsp midiprobe.dsp qmidiin.dsp \
sysextest.dsp RtMidi.dsw

Expand Down
26 changes: 26 additions & 0 deletions tests/testcapi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#include <stdio.h>
#include "rtmidi_c.h"

/* Test that the C API for RtMidi is working. */

struct RtMidiWrapper *midiin;
struct RtMidiWrapper *midiout;

int main() {
if ((midiin = rtmidi_in_create_default())) {
unsigned int ports = rtmidi_get_port_count(midiin);
printf("MIDI input ports found: %u\n", ports);
rtmidi_close_port(midiin);
rtmidi_in_free(midiin);
}

if ((midiout = rtmidi_out_create_default())) {
unsigned int ports = rtmidi_get_port_count(midiout);
printf("MIDI output ports found: %u\n", ports);
rtmidi_close_port(midiout);
rtmidi_out_free(midiout);
}

return 0;
}

0 comments on commit 99c4a3b

Please sign in to comment.