summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2014-02-26 07:07:09 +0000
committerMarcus Meissner <marcus@jet.franken.de>2014-02-26 07:07:09 +0000
commitac04ac3bf40ba69e165ef0fcd8d7ab2dca7b1a6d (patch)
tree325f171b07a878ca55e1543cb9ed02b43443adf4 /tests
parente7373010129b3b87cc395f5fde2e6bad53403270 (diff)
downloadlibgphoto2-ac04ac3bf40ba69e165ef0fcd8d7ab2dca7b1a6d.tar.gz
added a test-endian to check our endianess macros
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@14797 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/test-endian.c66
2 files changed, 75 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9896c937e..1358d20a1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,15 @@ AM_CPPFLAGS += -I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/libgphoto2_por
CLEANFILES = $(check_SCRIPTS)
+noinst_PROGRAMS += test-endian
+test_endian_SOURCE = test-endian.c
+test_endian_LDADD = \
+ $(top_builddir)/libgphoto2/libgphoto2.la \
+ $(top_builddir)/libgphoto2_port/libgphoto2_port/libgphoto2_port.la \
+ $(LIBLTDL) \
+ $(LIBEXIF_LIBS) \
+ $(INTLLIBS)
+
noinst_PROGRAMS += test-gphoto2
test_gphoto2_SOURCE = test-gphoto2.c
test_gphoto2_LDADD = \
diff --git a/tests/test-endian.c b/tests/test-endian.c
new file mode 100644
index 000000000..9f084f2ce
--- /dev/null
+++ b/tests/test-endian.c
@@ -0,0 +1,66 @@
+
+/* test-filesys.c
+ *
+ * Copyright © 2001 Lutz Müller <lutz@users.sf.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <gphoto2-endian.h>
+#include <gphoto2/gphoto2-filesys.h>
+#include <gphoto2/gphoto2-result.h>
+#include <gphoto2/gphoto2-port-log.h>
+
+
+#define CHECK(r) if (!(r)) { fprintf(stderr,"%s:%d: result unexpected.\n",__FILE__,__LINE__); exit(1); }
+
+int
+main ()
+{
+ unsigned char buf[16];
+ unsigned long long t;
+
+ t = swap16(0x1234);
+ CHECK(t == 0x3412);
+ t = swap32(0x12345678);
+ CHECK(t == 0x78563412);
+ t = swap64(0x0123456789abcdefULL);
+ CHECK(t == 0xefcdab8967452301ULL);
+
+ t = htobe16(0x1234); memcpy(buf,&t,2); CHECK((buf[0]==0x12)&&(buf[1]==0x34));
+ t = htobe32(0x12345678); memcpy(buf,&t,4); CHECK((buf[0]==0x12)&&(buf[1]==0x34)&&(buf[2]==0x56)&&(buf[3]==0x78));
+ t = htobe64(0x0123456789abcdefULL); memcpy(buf,&t,8);
+ CHECK((buf[0]==0x01)&&(buf[1]==0x23)&&(buf[2]==0x45)&&(buf[3]==0x67));
+ CHECK((buf[4]==0x89)&&(buf[5]==0xab)&&(buf[6]==0xcd)&&(buf[7]==0xef));
+
+ t = htole16(0x1234); memcpy(buf,&t,2); CHECK((buf[0]==0x34)&&(buf[1]==0x12));
+ t = htole32(0x12345678); memcpy(buf,&t,4); CHECK((buf[0]==0x78)&&(buf[1]==0x56)&&(buf[2]==0x34)&&(buf[3]==0x12));
+ t = htole64(0x0123456789abcdefULL); memcpy(buf,&t,8);
+ CHECK((buf[7]==0x01)&&(buf[6]==0x23)&&(buf[5]==0x45)&&(buf[4]==0x67));
+ CHECK((buf[3]==0x89)&&(buf[2]==0xab)&&(buf[1]==0xcd)&&(buf[0]==0xef));
+ return (0);
+}
+
+/*
+ * Local variables:
+ * compile-command: "gcc -pedantic -Wstrict-prototypes -O2 -g test-filesys.c -o test-filesys `gphoto2-config --cflags --libs` && export MALLOC_TRACE=test-filesys.log && ./test-filesys && mtrace ./test-filesys test-filesys.log"
+ * End:
+ */