[SCM] libopenmpt/master: Add autopkgtest for libmodplug compat layer

jcowgill at users.alioth.debian.org jcowgill at users.alioth.debian.org
Sun Jan 8 11:38:49 UTC 2017


The following commit has been merged in the master branch:
commit b613aa8635519a7bb1e75cce388713f90b6a9c94
Author: James Cowgill <jcowgill at debian.org>
Date:   Sat Jan 7 22:33:57 2017 +0000

    Add autopkgtest for libmodplug compat layer

diff --git a/debian/tests/build-modplug b/debian/tests/build-modplug
new file mode 100644
index 0000000..a31a5aa
--- /dev/null
+++ b/debian/tests/build-modplug
@@ -0,0 +1,36 @@
+#!/bin/sh
+# autopkgtest check: Build and run simple programs against libmodplug
+#  This test should pass when built against either libopenmpt-modplug or
+#  libmodplug.
+
+set -e
+
+# Require $ADTTMP for temporary build files
+if [ -z "$ADTTMP" ]
+then
+	echo 'Required envvar "$ADTTMP" is not set' >&2
+	exit 1
+fi
+
+cd debian/tests
+
+# Runs argument on the test data and ensures it's matches expected result
+run_dump() {
+	RESULT=$($1 data/test.xm)
+	if [ "$RESULT" != "$(cat data/test.expected)" ]; then
+		echo "bad result: $RESULT" 1>&2
+		exit 1
+	fi
+}
+
+# Build programs
+gcc -Wall -o "$ADTTMP/pattern-dump-modplug1" pattern-dump-modplug.c -lmodplug
+echo "build1: OK"
+gcc -Wall -o "$ADTTMP/pattern-dump-modplug2" pattern-dump-modplug.c $(pkg-config --cflags --libs libmodplug)
+echo "build2: OK"
+
+# Run them
+run_dump "$ADTTMP/pattern-dump-modplug1"
+echo "run1: OK"
+run_dump "$ADTTMP/pattern-dump-modplug2"
+echo "run2: OK"
diff --git a/debian/tests/control b/debian/tests/control
index d545333..598c628 100644
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -1,2 +1,11 @@
+# Main build tests
 Tests: build
 Depends: gcc, g++, libopenmpt-dev, pkg-config
+
+# Test modplug compatability layer
+Tests: build-modplug
+Depends: gcc, libopenmpt-modplug-dev, pkg-config
+
+# Control - identical code should work with old modplug
+Tests: build-modplug
+Depends: gcc, libmodplug-dev, pkg-config
diff --git a/debian/tests/pattern-dump-modplug.c b/debian/tests/pattern-dump-modplug.c
new file mode 100644
index 0000000..0d054f8
--- /dev/null
+++ b/debian/tests/pattern-dump-modplug.c
@@ -0,0 +1,92 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libmodplug/modplug.h>
+
+struct var_buffer
+{
+    void* buf;
+    int length;
+};
+
+// Read entire file into buffer
+//  buf is NULL on failure
+struct var_buffer read_file(const char* filename)
+{
+    struct var_buffer result = { NULL, 0 };
+    FILE* in_file = fopen(filename, "rb");
+    if (in_file == NULL)
+    {
+        perror("Error opening input file");
+        return result;
+    }
+
+    // Get file size
+    fseek(in_file, 0, SEEK_END);
+    int size = ftell(in_file);
+    rewind(in_file);
+
+    // Allocate buffer and read data into it
+    void* buf = malloc(size);
+    if (buf == NULL)
+    {
+        fputs("Error allocating memory", stderr);
+        goto done;
+    }
+
+    if (fread(buf, size, 1, in_file) != 1)
+    {
+        perror("Error reading file");
+        goto done;
+    }
+
+    result.buf = buf;
+    result.length = size;
+
+done:
+    fclose(in_file);
+    return result;
+}
+
+int main(int argc, char* argv[])
+{
+    if (argc != 2)
+    {
+        fprintf(stderr, "Usage: %s <module>\n", argv[0]);
+        return 1;
+    }
+
+    // Read entire input file into buffer
+    struct var_buffer buffer = read_file(argv[1]);
+    if (buffer.buf == NULL)
+        return 1;
+
+    // Load module
+    ModPlugFile* mod = ModPlug_Load(buffer.buf, buffer.length);
+    if (mod == NULL)
+    {
+        fputs("Error loading module", stderr);
+        free(buffer.buf);
+        return 1;
+    }
+
+    // Get first pattern number
+    ModPlug_SeekOrder(mod, 0);
+    int pattern = ModPlug_GetCurrentPattern(mod);
+
+    // Dump first line of first pattern
+    int channels = ModPlug_NumChannels(mod);
+    const ModPlugNote* note_data = ModPlug_GetPattern(mod, pattern, NULL);
+
+    for (int i = 0; i < channels; i++)
+    {
+        printf("%d %d%c",
+                note_data[i].Note,
+                note_data[i].Instrument,
+                (i == channels - 1) ? '\n' : ',');
+    }
+
+    ModPlug_Unload(mod);
+    free(buffer.buf);
+    return 0;
+}

-- 
libopenmpt packaging



More information about the pkg-multimedia-commits mailing list