Explorar el Código

libcompat: Make the library testable

This will allow us to guarantee the compatibility implementations at
least build, and can eventually be tested.
Guillem Jover hace 12 años
padre
commit
f45bc2de51

+ 2 - 0
debian/changelog

@@ -5,6 +5,8 @@ dpkg (1.17.11) UNRELEASED; urgency=low
     latter is available (round two). This includes the quilt patch header
     latter is available (round two). This includes the quilt patch header
     templates, and examples in man pages.
     templates, and examples in man pages.
   * Update some dpkg git URLs to the new and newer (cgit switch) scheme.
   * Update some dpkg git URLs to the new and newer (cgit switch) scheme.
+  * Changes to libcompat:
+    - Make the library testable.
 
 
   [ Updated programs translations ]
   [ Updated programs translations ]
   * Danish (Joe Dalton). Closes: #754127
   * Danish (Joe Dalton). Closes: #754127

+ 14 - 1
lib/compat/Makefile.am

@@ -5,7 +5,20 @@ AM_CPPFLAGS = \
 	-I$(top_builddir)
 	-I$(top_builddir)
 
 
 
 
-noinst_LTLIBRARIES = libcompat.la
+noinst_LTLIBRARIES = libcompat-test.la libcompat.la
+
+libcompat_test_la_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_LIBCOMPAT=1
+libcompat_test_la_SOURCES = \
+	compat.h \
+	strnlen.c \
+	strndup.c \
+	strerror.c \
+	strsignal.c \
+	snprintf.c vsnprintf.c \
+	asprintf.c vasprintf.c \
+	alphasort.c \
+	scandir.c \
+	unsetenv.c
 
 
 libcompat_la_SOURCES = \
 libcompat_la_SOURCES = \
 	empty.c \
 	empty.c \

+ 2 - 0
lib/compat/alphasort.c

@@ -22,6 +22,8 @@
 #include <string.h>
 #include <string.h>
 #include <dirent.h>
 #include <dirent.h>
 
 
+#include "compat.h"
+
 int
 int
 alphasort(const void *a, const void *b)
 alphasort(const void *a, const void *b)
 {
 {

+ 2 - 0
lib/compat/asprintf.c

@@ -22,6 +22,8 @@
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
+#include "compat.h"
+
 int
 int
 asprintf(char **strp, char const *fmt, ...)
 asprintf(char **strp, char const *fmt, ...)
 {
 {

+ 51 - 18
lib/compat/compat.h

@@ -22,6 +22,23 @@
 #ifndef COMPAT_H
 #ifndef COMPAT_H
 #define COMPAT_H
 #define COMPAT_H
 
 
+#ifndef TEST_LIBCOMPAT
+#define TEST_LIBCOMPAT 0
+#endif
+
+#if TEST_LIBCOMPAT || !defined(HAVE_STRNLEN) || !defined(HAVE_STRNDUP) || \
+    !defined(HAVE_C99_SNPRINTF)
+#include <stddef.h>
+#endif
+
+#if TEST_LIBCOMPAT || !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_SNPRINTF)
+#include <stdarg.h>
+#endif
+
+#if  TEST_LIBCOMPAT || !defined(HAVE_VA_COPY)
+#include <string.h>
+#endif
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
 #endif
 #endif
@@ -51,56 +68,72 @@ extern "C" {
 #endif
 #endif
 
 
 #ifndef HAVE_VA_COPY
 #ifndef HAVE_VA_COPY
-#include <string.h>
 #define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
 #define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
 #endif
 #endif
 
 
-#ifndef HAVE_C99_SNPRINTF
-#include <stddef.h>
-#include <stdarg.h>
-
+#if TEST_LIBCOMPAT
+#undef snprintf
+#define snprintf test_snprintf
+#undef vsnprintf
+#define vsnprintf test_vsnprintf
+#undef asprintf
+#define asprintf test_asprintf
+#undef vasprintf
+#define vasprintf test_vasprintf
+#undef strndup
+#define strndup test_strndup
+#undef strnlen
+#define strnlen test_strnlen
+#undef strerror
+#define strerror test_strerror
+#undef strsignal
+#define strsignal test_strsignal
+#undef scandir
+#define scandir test_scandir
+#undef alphasort
+#define alphasort test_alphasort
+#undef unsetenv
+#define unsetenv test_unsetenv
+#endif
+
+#if TEST_LIBCOMPAT || !defined(HAVE_C99_SNPRINTF)
 int snprintf(char *str, size_t n, char const *fmt, ...);
 int snprintf(char *str, size_t n, char const *fmt, ...);
 int vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list args);
 int vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list args);
 #endif
 #endif
 
 
-#ifndef HAVE_ASPRINTF
-#include <stdarg.h>
-
+#if TEST_LIBCOMPAT || !defined(HAVE_ASPRINTF)
 int asprintf(char **str, char const *fmt, ...);
 int asprintf(char **str, char const *fmt, ...);
 int vasprintf(char **str, const char *fmt, va_list args);
 int vasprintf(char **str, const char *fmt, va_list args);
 #endif
 #endif
 
 
-#ifndef HAVE_STRNLEN
+#if TEST_LIBCOMPAT || !defined(HAVE_STRNLEN)
 size_t strnlen(const char *s, size_t n);
 size_t strnlen(const char *s, size_t n);
 #endif
 #endif
 
 
-#ifndef HAVE_STRNDUP
-#include <stddef.h>
-
-#undef strndup
+#if TEST_LIBCOMPAT || !defined(HAVE_STRNDUP)
 char *strndup(const char *s, size_t n);
 char *strndup(const char *s, size_t n);
 #endif
 #endif
 
 
-#ifndef HAVE_STRERROR
+#if TEST_LIBCOMPAT || !defined(HAVE_STRERROR)
 const char *strerror(int);
 const char *strerror(int);
 #endif
 #endif
 
 
-#ifndef HAVE_STRSIGNAL
+#if TEST_LIBCOMPAT || !defined(HAVE_STRSIGNAL)
 const char *strsignal(int);
 const char *strsignal(int);
 #endif
 #endif
 
 
-#ifndef HAVE_SCANDIR
+#if TEST_LIBCOMPAT || !defined(HAVE_SCANDIR)
 struct dirent;
 struct dirent;
 int scandir(const char *dir, struct dirent ***namelist,
 int scandir(const char *dir, struct dirent ***namelist,
             int (*filter)(const struct dirent *),
             int (*filter)(const struct dirent *),
             int (*cmp)(const void *, const void *));
             int (*cmp)(const void *, const void *));
 #endif
 #endif
 
 
-#ifndef HAVE_ALPHASORT
+#if TEST_LIBCOMPAT || !defined(HAVE_ALPHASORT)
 int alphasort(const void *a, const void *b);
 int alphasort(const void *a, const void *b);
 #endif
 #endif
 
 
-#ifndef HAVE_UNSETENV
+#if TEST_LIBCOMPAT || !defined(HAVE_UNSETENV)
 int unsetenv(const char *x);
 int unsetenv(const char *x);
 #endif
 #endif
 
 

+ 2 - 0
lib/compat/scandir.c

@@ -26,6 +26,8 @@
 #include <dirent.h>
 #include <dirent.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
+#include "compat.h"
+
 static int
 static int
 cleanup(DIR *dir, struct dirent **dirlist, int used)
 cleanup(DIR *dir, struct dirent **dirlist, int used)
 {
 {

+ 2 - 1
lib/compat/snprintf.c

@@ -18,12 +18,13 @@
  */
  */
 
 
 #include <config.h>
 #include <config.h>
-#include <compat.h>
 
 
 #include <stddef.h>
 #include <stddef.h>
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
+#include "compat.h"
+
 int
 int
 snprintf(char *str, size_t n, char const *fmt, ...)
 snprintf(char *str, size_t n, char const *fmt, ...)
 {
 {

+ 4 - 0
lib/compat/strerror.c

@@ -22,10 +22,14 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <gettext.h>
 #include <gettext.h>
 
 
+#include "compat.h"
+
 #define _(str) gettext(str)
 #define _(str) gettext(str)
 
 
+#ifndef HAVE_STRERROR
 extern const char *const sys_errlist[];
 extern const char *const sys_errlist[];
 extern const int sys_nerr;
 extern const int sys_nerr;
+#endif
 
 
 const char *
 const char *
 strerror(int e)
 strerror(int e)

+ 1 - 2
lib/compat/strndup.c

@@ -18,12 +18,11 @@
  */
  */
 
 
 #include <config.h>
 #include <config.h>
-#include <compat.h>
 
 
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
-#undef strndup
+#include "compat.h"
 
 
 char *
 char *
 strndup(const char *s, size_t n)
 strndup(const char *s, size_t n)

+ 2 - 0
lib/compat/strsignal.c

@@ -24,6 +24,8 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <gettext.h>
 #include <gettext.h>
 
 
+#include "compat.h"
+
 #define _(str) gettext(str)
 #define _(str) gettext(str)
 
 
 #ifndef HAVE_DECL_SYS_SIGLIST
 #ifndef HAVE_DECL_SYS_SIGLIST

+ 2 - 0
lib/compat/unsetenv.c

@@ -22,6 +22,8 @@
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
+#include "compat.h"
+
 int
 int
 unsetenv(const char *p)
 unsetenv(const char *p)
 {
 {

+ 2 - 0
lib/compat/vasprintf.c

@@ -23,6 +23,8 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
+#include "compat.h"
+
 int
 int
 vasprintf(char **strp, char const *fmt, va_list args)
 vasprintf(char **strp, char const *fmt, va_list args)
 {
 {

+ 2 - 0
lib/compat/vsnprintf.c

@@ -26,6 +26,8 @@
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
+#include "compat.h"
+
 int
 int
 vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list args)
 vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list args)
 {
 {