summaryrefslogtreecommitdiff
path: root/lib/replace/test
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-03-07 17:00:49 +1100
committerAndrew Tridgell <tridge@samba.org>2010-04-06 20:26:43 +1000
commitd40b396ad835f77878aefda8624d53b9112c1ebb (patch)
tree203e2f51762c20cdcb21fbd0e46c043cba128a40 /lib/replace/test
parenteadf918402996d7f9d737679c958f2dc1b6f8783 (diff)
downloadsamba-d40b396ad835f77878aefda8624d53b9112c1ebb.tar.gz
samba-d40b396ad835f77878aefda8624d53b9112c1ebb.tar.bz2
samba-d40b396ad835f77878aefda8624d53b9112c1ebb.zip
build: added interface checking and nicer snprintf checking
use CHECK_CODE()
Diffstat (limited to 'lib/replace/test')
-rw-r--r--lib/replace/test/snprintf.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/replace/test/snprintf.c b/lib/replace/test/snprintf.c
new file mode 100644
index 0000000000..d06630bcc9
--- /dev/null
+++ b/lib/replace/test/snprintf.c
@@ -0,0 +1,29 @@
+void foo(const char *format, ...)
+{
+ va_list ap;
+ int len;
+ char buf[20];
+ long long l = 1234567890;
+ l *= 100;
+
+ va_start(ap, format);
+ len = vsnprintf(buf, 0, format, ap);
+ va_end(ap);
+ if (len != 5) exit(1);
+
+ va_start(ap, format);
+ len = vsnprintf(0, 0, format, ap);
+ va_end(ap);
+ if (len != 5) exit(2);
+
+ if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
+
+ if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
+ if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
+ if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
+ if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
+
+ printf("1");
+ exit(0);
+}
+main() { foo("hello"); }