summaryrefslogtreecommitdiff
path: root/tests/port
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-03-24 11:51:12 +0100
committerAndreas Baumann <abaumann@yahoo.com>2009-03-24 11:51:12 +0100
commit8e3274f153f89ecf1611fa8468d2d7dbe596a23f (patch)
treed53ed483e4714599826dab45a82574b9a5be2a11 /tests/port
parent2f0a989a9ebd8d93fdcaf9a8530fea94877f607f (diff)
downloadwolfbones-8e3274f153f89ecf1611fa8468d2d7dbe596a23f.tar.gz
wolfbones-8e3274f153f89ecf1611fa8468d2d7dbe596a23f.tar.bz2
added strlcpy and strlcat (safe BSD C functions)
Diffstat (limited to 'tests/port')
-rw-r--r--tests/port/GNUmakefile8
-rw-r--r--tests/port/Makefile.W328
-rw-r--r--tests/port/test_strlcat.c29
-rw-r--r--tests/port/test_strlcpy.c26
4 files changed, 69 insertions, 2 deletions
diff --git a/tests/port/GNUmakefile b/tests/port/GNUmakefile
index a946ad7..0b0f30c 100644
--- a/tests/port/GNUmakefile
+++ b/tests/port/GNUmakefile
@@ -12,7 +12,9 @@ TEST_BINS = \
test_strcasecmp$(EXE) \
test_strncasecmp$(EXE) \
test_localtime_r$(EXE) \
- test_snprintf$(EXE)
+ test_snprintf$(EXE) \
+ test_strlcpy$(EXE) \
+ test_strlcat$(EXE)
-include $(TOPDIR)/makefiles/gmake/sub.mk
@@ -42,3 +44,7 @@ local_test:
@./test_localtime_r >/dev/null
@echo "Testing snprintf.."
@./test_snprintf > /dev/null
+ @echo "Testing strlcpy.."
+ @./test_strlcpy > /dev/null
+ @echo "Testing strlcat.."
+ @./test_strlcat > /dev/null
diff --git a/tests/port/Makefile.W32 b/tests/port/Makefile.W32
index befea27..958cbff 100644
--- a/tests/port/Makefile.W32
+++ b/tests/port/Makefile.W32
@@ -12,7 +12,9 @@ TEST_BINS = \
test_strcasecmp.exe \
test_strncasecmp.exe \
test_localtime_r.exe \
- test_snprintf.exe
+ test_snprintf.exe \
+ test_strlcpy.exe \
+ test_strlcat.exe
!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk
@@ -43,3 +45,7 @@ local_test:
@test_localtime_r >NUL 2>NUL
@echo Testing snprintf..
@test_snprintf >NUL 2>NUL
+ @echo Testing strlcpy..
+ @test_strlcpy >NUL 2>NUL
+ @echo Testing strlcat..
+ @test_strlcat >NUL 2>NUL
diff --git a/tests/port/test_strlcat.c b/tests/port/test_strlcat.c
new file mode 100644
index 0000000..402723e
--- /dev/null
+++ b/tests/port/test_strlcat.c
@@ -0,0 +1,29 @@
+#include "port/sys.h"
+
+#define TEST_STRLCAT
+#include "port/string.c" /* for strlcat */
+
+#include <stdlib.h> /* for exit, EXIT_SUCCESS, free */
+
+int main( void ) {
+ char s1[10] = "test";
+ char s2[10] = "test";
+ const char *a = "test";
+
+ wolf_port_strlcat( s1, a, 10 );
+ strlcat( s2, a, 10 );
+ if( strcmp( s1, "testtest" ) != 0 ) return EXIT_FAILURE;
+ if( strcmp( s2, s1 ) != 0 ) return EXIT_FAILURE;
+
+ wolf_port_strlcat( s1, a, 10 );
+ strlcat( s2, a, 10 );
+ if( strcmp( s1, "testtestt" ) != 0 ) return EXIT_FAILURE;
+ if( strcmp( s2, s1 ) != 0 ) return EXIT_FAILURE;
+
+ wolf_port_strlcat( s1, a, 10 );
+ strlcat( s2, a, 10 );
+ if( strcmp( s1, "testtestt" ) != 0 ) return EXIT_FAILURE;
+ if( strcmp( s2, s1 ) != 0 ) return EXIT_FAILURE;
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/port/test_strlcpy.c b/tests/port/test_strlcpy.c
new file mode 100644
index 0000000..d83ed58
--- /dev/null
+++ b/tests/port/test_strlcpy.c
@@ -0,0 +1,26 @@
+#include "port/sys.h"
+
+#define TEST_STRLCPY
+#include "port/string.c" /* for strlcpy */
+
+#include <stdlib.h> /* for exit, EXIT_SUCCESS, free */
+
+int main( void ) {
+ const char *s = "test";
+ char d11[10];
+ char d12[4];
+ char d21[10];
+ char d22[4];
+
+ wolf_port_strlcpy( d11, s, 10 );
+ strlcpy( d21, s, 10 );
+ if( strcmp( d11, s ) != 0 ) return EXIT_FAILURE;
+ if( strcmp( d11, d21 ) != 0 ) return EXIT_FAILURE;
+
+ wolf_port_strlcpy( d12, s, 4 );
+ strlcpy( d22, s, 4 );
+ if( strcmp( d12, "tes" ) != 0 ) return EXIT_FAILURE;
+ if( strcmp( d12, d22 ) != 0 ) return EXIT_FAILURE;
+
+ return EXIT_SUCCESS;
+}