1
0
mirror of https://github.com/ErnyTech/Open-USB-Extreme synced 2024-08-20 06:10:41 +02:00

Add C ABI test for prevent C ABI breakage

Signed-off-by: Ernesto Castellotti <erny.castell@gmail.com>
This commit is contained in:
Ernesto Castellotti 2019-08-26 01:39:58 +02:00
parent 082d4663fd
commit 62f3e85393
3 changed files with 47 additions and 1 deletions

View File

@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 2.8.9)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/cmake-d")
project(Open-USB-Extreme D)
project(Open-USB-Extreme C D)
enable_testing()
file(GLOB SOURCES "lib/*.d")
file(GLOB HEADERS "include/*.h" "include/*.di")
@ -11,9 +12,14 @@ include_directories(include)
set(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -betterC -O -release -L-rpath=.")
add_library(${PROJECT_NAME} SHARED ${SOURCES})
add_executable(open-usbextreme-example ${EXAMPLE_SOURCES})
target_link_libraries(open-usbextreme-example ${PROJECT_NAME})
add_executable(cabitest "tests/cabitest.c")
target_link_libraries(cabitest ${PROJECT_NAME})
add_test (NAME CABI_TEST COMMAND cabitest /home/erny/Desktop/ul.cfg)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
)

40
tests/cabitest.c Normal file
View File

@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <usbextreme.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: open-usbextreme-example <path/to/ul.cfg>\n");
return 1;
}
FILE *f = fopen(argv[1], "rb");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
if (fsize <= 0) {
return 1;
}
unsigned long size = *(unsigned long*) &fsize;
fseek(f, 0, SEEK_SET);
void *data = malloc(size + 1);
fread(data, size, 1, f);
fclose(f);
usb_extreme_headers headers;
if(oue_read_headers(&headers, data, size) <= 0) {
return 1;
}
usb_extreme_filestat filestats[10];
int nstats = oue_read(filestats, headers, 10);
int i;
for(i = 0; i < nstats; i++) {
printf("Game name [%d]: %s\n", filestats[i].offset, filestats[i].name);
}
return 0;
}

BIN
tests/ul.cfg Normal file

Binary file not shown.