aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2018-12-05 17:48:36 +0100
committerMarco Paland <marco@paland.com>2018-12-05 17:48:36 +0100
commitd46b3d2b253776a332f0f0a115a5a71a2f34e923 (patch)
tree30b025ae38b00b24d371060578d37a3f11fb29ef /test
parent4b60eb6973b384bf12223a923d24865ddbe97778 (diff)
downloadprintf-d46b3d2b253776a332f0f0a115a5a71a2f34e923.tar.gz
printf-d46b3d2b253776a332f0f0a115a5a71a2f34e923.tar.bz2
printf-d46b3d2b253776a332f0f0a115a5a71a2f34e923.zip
chore(printf): cleanup secure strlen() function, added test cases
Diffstat (limited to 'test')
-rw-r--r--test/test_suite.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/test_suite.cpp b/test/test_suite.cpp
index 272f4c4..bcddd4f 100644
--- a/test/test_suite.cpp
+++ b/test/test_suite.cpp
@@ -1187,6 +1187,32 @@ TEST_CASE("unknown flag", "[]" ) {
}
+TEST_CASE("string length", "[]" ) {
+ char buffer[100];
+
+ test::sprintf(buffer, "%.4s", "This is a test");
+ REQUIRE(!strcmp(buffer, "This"));
+
+ test::sprintf(buffer, "%.4s", "test");
+ REQUIRE(!strcmp(buffer, "test"));
+
+ test::sprintf(buffer, "%.7s", "123");
+ REQUIRE(!strcmp(buffer, "123"));
+
+ test::sprintf(buffer, "%.7s", "");
+ REQUIRE(!strcmp(buffer, ""));
+
+ test::sprintf(buffer, "%.4s%.2s", "123456", "abcdef");
+ REQUIRE(!strcmp(buffer, "1234ab"));
+
+ test::sprintf(buffer, "%.4.2s", "123456");
+ REQUIRE(!strcmp(buffer, ".2s"));
+
+ test::sprintf(buffer, "%.*s", 3, "123456");
+ REQUIRE(!strcmp(buffer, "123"));
+}
+
+
TEST_CASE("buffer length", "[]" ) {
char buffer[100];
int ret;