summaryrefslogtreecommitdiff
path: root/lib/ccan/cast/test
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-06-20 16:54:15 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-06-20 11:18:34 +0200
commit754c677b0bbf3ea6c7d2a73c93848f1b0d68c91e (patch)
tree54d99c9f66d5a57bf7f70d53e744a31df18f9e0e /lib/ccan/cast/test
parenta8c3d38bc806c6972d10b6a371de8941da25a9ae (diff)
downloadsamba-754c677b0bbf3ea6c7d2a73c93848f1b0d68c91e.tar.gz
samba-754c677b0bbf3ea6c7d2a73c93848f1b0d68c91e.tar.bz2
samba-754c677b0bbf3ea6c7d2a73c93848f1b0d68c91e.zip
lib: import ccan modules for tdb2
Imported from git://git.ozlabs.org/~ccan/ccan init-1161-g661d41f Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ccan/cast/test')
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_const.c29
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_const2.c29
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_const3.c29
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_signed-const.c22
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c29
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_signed.c17
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_static-2.c23
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_static-3.c21
-rw-r--r--lib/ccan/cast/test/compile_fail-cast_static.c17
-rw-r--r--lib/ccan/cast/test/compile_ok-cast_void.c12
10 files changed, 228 insertions, 0 deletions
diff --git a/lib/ccan/cast/test/compile_fail-cast_const.c b/lib/ccan/cast/test/compile_fail-cast_const.c
new file mode 100644
index 0000000000..277f3de1c4
--- /dev/null
+++ b/lib/ccan/cast/test/compile_fail-cast_const.c
@@ -0,0 +1,29 @@
+#include <ccan/cast/cast.h>
+#include <stdlib.h>
+
+/* Note: this *isn't* sizeof(char) on all platforms. */
+struct char_struct {
+ char c;
+};
+
+int main(int argc, char *argv[])
+{
+ char *uc;
+ const
+#ifdef FAIL
+ struct char_struct
+#else
+ char
+#endif
+ *p = NULL;
+
+ uc = cast_const(char *, p);
+ (void) uc; /* Suppress unused-but-set-variable warning. */
+ return 0;
+}
+
+#ifdef FAIL
+#if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P
+#error "Unfortunately we don't fail if cast_const can only use size"
+#endif
+#endif
diff --git a/lib/ccan/cast/test/compile_fail-cast_const2.c b/lib/ccan/cast/test/compile_fail-cast_const2.c
new file mode 100644
index 0000000000..e671e88eda
--- /dev/null
+++ b/lib/ccan/cast/test/compile_fail-cast_const2.c
@@ -0,0 +1,29 @@
+#include <ccan/cast/cast.h>
+#include <stdlib.h>
+
+/* Note: this *isn't* sizeof(char) on all platforms. */
+struct char_struct {
+ char c;
+};
+
+int main(int argc, char *argv[])
+{
+ char **uc;
+ const
+#ifdef FAIL
+ struct char_struct
+#else
+ char
+#endif
+ **p = NULL;
+
+ uc = cast_const2(char **, p);
+ (void) uc; /* Suppress unused-but-set-variable warning. */
+ return 0;
+}
+
+#ifdef FAIL
+#if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P
+#error "Unfortunately we don't fail if cast_const can only use size"
+#endif
+#endif
diff --git a/lib/ccan/cast/test/compile_fail-cast_const3.c b/lib/ccan/cast/test/compile_fail-cast_const3.c
new file mode 100644
index 0000000000..e958e2dde5
--- /dev/null
+++ b/lib/ccan/cast/test/compile_fail-cast_const3.c
@@ -0,0 +1,29 @@
+#include <ccan/cast/cast.h>
+#include <stdlib.h>
+
+/* Note: this *isn't* sizeof(char) on all platforms. */
+struct char_struct {
+ char c;
+};
+
+int main(int argc, char *argv[])
+{
+ char ***uc;
+ const
+#ifdef FAIL
+ struct char_struct
+#else
+ char
+#endif
+ ***p = NULL;
+
+ uc = cast_const3(char ***, p);
+ (void) uc; /* Suppress unused-but-set-variable warning. */
+ return 0;
+}
+
+#ifdef FAIL
+#if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P
+#error "Unfortunately we don't fail if cast_const can only use size"
+#endif
+#endif
diff --git a/lib/ccan/cast/test/compile_fail-cast_signed-const.c b/lib/ccan/cast/test/compile_fail-cast_signed-const.c
new file mode 100644
index 0000000000..9971dc8eb3
--- /dev/null
+++ b/lib/ccan/cast/test/compile_fail-cast_signed-const.c
@@ -0,0 +1,22 @@
+#include <ccan/cast/cast.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+ unsigned char *uc;
+#ifdef FAIL
+ const
+#endif
+ char
+ *p = NULL;
+
+ uc = cast_signed(unsigned char *, p);
+ (void) uc; /* Suppress unused-but-set-variable warning. */
+ return 0;
+}
+
+#ifdef FAIL
+#if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P
+#error "Unfortunately we don't fail if cast_const can only use size"
+#endif
+#endif
diff --git a/lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c b/lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c
new file mode 100644
index 0000000000..2bc40b2f46
--- /dev/null
+++ b/lib/ccan/cast/test/compile_fail-cast_signed-sizesame.c
@@ -0,0 +1,29 @@
+#include <ccan/cast/cast.h>
+#include <stdlib.h>
+
+/* Note: this *isn't* sizeof(char) on all platforms. */
+struct char_struct {
+ char c;
+};
+
+int main(int argc, char *argv[])
+{
+ unsigned char *uc;
+#ifdef FAIL
+ struct char_struct
+#else
+ char
+#endif
+ *p = NULL;
+
+ uc = cast_signed(unsigned char *, p);
+
+ (void) uc; /* Suppress unused-but-set-variable warning. */
+ return 0;
+}
+
+#ifdef FAIL
+#if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P
+#error "Unfortunately we don't fail if cast_signed can only use size"
+#endif
+#endif
diff --git a/lib/ccan/cast/test/compile_fail-cast_signed.c b/lib/ccan/cast/test/compile_fail-cast_signed.c
new file mode 100644
index 0000000000..66bcc0a1b5
--- /dev/null
+++ b/lib/ccan/cast/test/compile_fail-cast_signed.c
@@ -0,0 +1,17 @@
+#include <ccan/cast/cast.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+ unsigned char *uc;
+#ifdef FAIL
+ int
+#else
+ char
+#endif
+ *p = NULL;
+
+ uc = cast_signed(unsigned char *, p);
+ (void) uc; /* Suppress unused-but-set-variable warning. */
+ return 0;
+}
diff --git a/lib/ccan/cast/test/compile_fail-cast_static-2.c b/lib/ccan/cast/test/compile_fail-cast_static-2.c
new file mode 100644
index 0000000000..8a12025384
--- /dev/null
+++ b/lib/ccan/cast/test/compile_fail-cast_static-2.c
@@ -0,0 +1,23 @@
+#include <ccan/cast/cast.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+ char *c;
+#ifdef FAIL
+ long
+#else
+ char
+#endif
+ *p = 0;
+
+ c = cast_static(char *, p);
+ (void) c; /* Suppress unused-but-set-variable warning. */
+ return 0;
+}
+
+#ifdef FAIL
+#if !HAVE_COMPOUND_LITERALS
+#error "Unfortunately we don't fail if cast_static is a noop"
+#endif
+#endif
diff --git a/lib/ccan/cast/test/compile_fail-cast_static-3.c b/lib/ccan/cast/test/compile_fail-cast_static-3.c
new file mode 100644
index 0000000000..6296b75276
--- /dev/null
+++ b/lib/ccan/cast/test/compile_fail-cast_static-3.c
@@ -0,0 +1,21 @@
+#include <ccan/cast/cast.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+ char *c;
+#ifdef FAIL
+ const
+#endif
+ char *p = 0;
+
+ c = cast_static(char *, p);
+ (void) c; /* Suppress unused-but-set-variable warning. */
+ return 0;
+}
+
+#ifdef FAIL
+#if !HAVE_COMPOUND_LITERALS
+#error "Unfortunately we don't fail if cast_static is a noop"
+#endif
+#endif
diff --git a/lib/ccan/cast/test/compile_fail-cast_static.c b/lib/ccan/cast/test/compile_fail-cast_static.c
new file mode 100644
index 0000000000..0f9e478047
--- /dev/null
+++ b/lib/ccan/cast/test/compile_fail-cast_static.c
@@ -0,0 +1,17 @@
+#include <ccan/cast/cast.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+ char c;
+#ifdef FAIL
+ char *
+#else
+ long
+#endif
+ x = 0;
+
+ c = cast_static(char, x);
+ (void) c; /* Suppress unused-but-set-variable warning. */
+ return 0;
+}
diff --git a/lib/ccan/cast/test/compile_ok-cast_void.c b/lib/ccan/cast/test/compile_ok-cast_void.c
new file mode 100644
index 0000000000..c649d283b3
--- /dev/null
+++ b/lib/ccan/cast/test/compile_ok-cast_void.c
@@ -0,0 +1,12 @@
+#include <ccan/cast/cast.h>
+
+static void *remove_void(const void *p)
+{
+ return cast_const(void *, p);
+}
+
+int main(void)
+{
+ void *p = remove_void("foo");
+ return !p;
+}