aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorlotanrm <lotanrm@b956fd51-792f-4845-bead-9b4dfca2ff2c>2013-07-11 08:49:22 +0000
committerlotanrm <lotanrm@b956fd51-792f-4845-bead-9b4dfca2ff2c>2013-07-11 08:49:22 +0000
commit2596ea5ea76e3a6bb46ce1c7c5da3ea33bcda031 (patch)
tree047d0e7e28195c110f7ea38f84cc7df3ffc49db3 /test
parentcc0b72e5e5e1c620b654ecf14d89ac9c4706e4e6 (diff)
downloadusdx-2596ea5ea76e3a6bb46ce1c7c5da3ea33bcda031.tar.gz
usdx-2596ea5ea76e3a6bb46ce1c7c5da3ea33bcda031.tar.xz
usdx-2596ea5ea76e3a6bb46ce1c7c5da3ea33bcda031.zip
Added test to compare ffmpeg type sizes between pascal and c.
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2997 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'test')
-rw-r--r--test/ffmpeg_structs/Makefile22
-rw-r--r--test/ffmpeg_structs/README22
-rwxr-xr-xtest/ffmpeg_structs/find_avtypes57
3 files changed, 101 insertions, 0 deletions
diff --git a/test/ffmpeg_structs/Makefile b/test/ffmpeg_structs/Makefile
new file mode 100644
index 00000000..11e87cf0
--- /dev/null
+++ b/test/ffmpeg_structs/Makefile
@@ -0,0 +1,22 @@
+FFMPEG_VERSION=1.0
+
+all: ffmpeg_c ffmpeg_pas
+ @./ffmpeg_c >ffmpeg_c.txt
+ @./ffmpeg_pas >ffmpeg_pas.txt
+ @diff ffmpeg_c.txt ffmpeg_pas.txt
+
+ffmpeg_c: ffmpeg_c.c
+ @gcc -o $@ $^
+
+ffmpeg_pas: ffmpeg_pas.pas
+ @fpc -v0 -Fi../../src $^ >/dev/null 2>&1
+
+ffmpeg_c.c:
+ @FFMPEG_VERSION=$(FFMPEG_VERSION) ./find_avtypes
+
+ffmpeg_pas.pas:
+ @FFMPEG_VERSION=$(FFMPEG_VERSION) ./find_avtypes
+
+.PHONY: clean
+clean:
+ @rm -f ffmpeg_c* ffmpeg_pas*
diff --git a/test/ffmpeg_structs/README b/test/ffmpeg_structs/README
new file mode 100644
index 00000000..cba407d7
--- /dev/null
+++ b/test/ffmpeg_structs/README
@@ -0,0 +1,22 @@
+This test scans through the source files in order to find types
+and pointers to types from the pascal port of the ffmpeg
+libraries (TAV..., PAV...).
+
+It generates source files for pascal and c that print the sizes
+of the types used in the sources.
+
+The concluding comparison shows the size differences between the
+pascal types and the c structs:
+- type is bigger than struct
+- type is smaller than struct
+
+If struct members' names have changed, the compiler will complain.
+
+The test doesn't, however, show if struct members have been swapped
+with the size staying exactly the same. Hopefully, that scenario
+isn't too likely.
+
+With the exception of the last point, if this test doesn't yield
+a result (the types and structs have the same size), it is quite
+plausible that the pascal port of the c structs has been done
+correctly.
diff --git a/test/ffmpeg_structs/find_avtypes b/test/ffmpeg_structs/find_avtypes
new file mode 100755
index 00000000..c13672f5
--- /dev/null
+++ b/test/ffmpeg_structs/find_avtypes
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+SRC_DIR='../../src'
+PAS='ffmpeg_pas.pas'
+C='ffmpeg_c.c'
+
+types=$(find $SRC_DIR -path "$SRC_DIR/lib" -prune -o -name "*.pas" -print0|xargs -0 grep --files-with-match '\bavcodec\b'|xargs grep --no-filename --only-matching '\b[PT]AV\w\+'|sed 's/^P/T/'|sort|uniq)
+
+# swscale doesn't seem to contain noteworthy types, thus it's not considered
+
+cat >$PAS <<EOL
+program ffmpeg_pas;
+
+uses
+ avcodec in '$SRC_DIR/lib/ffmpeg-$FFMPEG_VERSION/avcodec.pas',
+ avformat in '$SRC_DIR/lib/ffmpeg-$FFMPEG_VERSION/avformat.pas',
+ avutil in '$SRC_DIR/lib/ffmpeg-$FFMPEG_VERSION/avutil.pas',
+ rational in '$SRC_DIR/lib/ffmpeg-$FFMPEG_VERSION/rational.pas',
+ avio in '$SRC_DIR/lib/ffmpeg-$FFMPEG_VERSION/avio.pas',
+ UConfig in '$SRC_DIR/base/UConfig',
+ SysUtils;
+
+begin
+EOL
+
+for t in $types
+do
+ echo " WriteLn('$t: ' + IntToStr(SizeOf($t)));" >>$PAS
+done
+
+cat >>$PAS <<EOL
+end.
+EOL
+
+cat >$C <<EOL
+#include "libavcodec/avcodec.h"
+#include "libavformat/avformat.h"
+#include "libavutil/samplefmt.h"
+#include "libavutil/avutil.h"
+#include "libavformat/avio.h"
+
+// workaround for enum
+typedef enum AVSampleFormat AVSampleFormat;
+
+int main(int argc, char *argv[]) {
+EOL
+
+for t in $types
+do
+ tt=$(echo $t|sed 's/^T//')
+ echo " printf(\"$t: %ld\\n\", sizeof($tt));" >>$C
+done
+
+cat >>$C <<EOL
+ return 0;
+}
+EOL