Changeset ea4910b in mainline for uspace/lib/c/test/string.c


Ignore:
Timestamp:
2018-11-30T10:04:57Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
26f5bdf, 4aba581
Parents:
c483fca
git-author:
Jiri Svoboda <jiri@…> (2018-11-29 18:02:24)
git-committer:
Jiri Svoboda <jiri@…> (2018-11-30 10:04:57)
Message:

strdup(), strndup(), strnlen() are commonly used extensions so move them to libc (native ports can use these).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/test/string.c

    rc483fca rea4910b  
    722722}
    723723
     724/** strlen function with empty string and non-zero limit */
     725PCUT_TEST(strnlen_empty_short)
     726{
     727        PCUT_ASSERT_INT_EQUALS(0, strnlen("", 1));
     728}
     729
     730/** strlen function with empty string and zero limit */
     731PCUT_TEST(strnlen_empty_eq)
     732{
     733        PCUT_ASSERT_INT_EQUALS(0, strnlen("", 0));
     734}
     735
     736/** strlen function with non empty string below limit */
     737PCUT_TEST(strnlen_nonempty_short)
     738{
     739        PCUT_ASSERT_INT_EQUALS(3, strnlen("abc", 5));
     740}
     741
     742/** strlen function with non empty string just below limit */
     743PCUT_TEST(strnlen_nonempty_just_short)
     744{
     745        PCUT_ASSERT_INT_EQUALS(3, strnlen("abc", 4));
     746}
     747
     748/** strlen function with non empty string of length equal to limit */
     749PCUT_TEST(strnlen_nonempty_eq)
     750{
     751        PCUT_ASSERT_INT_EQUALS(3, strnlen("abc", 3));
     752}
     753
     754/** strlen function with non empty string of length above limit */
     755PCUT_TEST(strnlen_nonempty_long)
     756{
     757        PCUT_ASSERT_INT_EQUALS(2, strnlen("abc", 2));
     758}
     759
     760/** strdup function with empty string */
     761PCUT_TEST(strdup_empty)
     762{
     763        char *d = strdup("");
     764        PCUT_ASSERT_NOT_NULL(d);
     765        PCUT_ASSERT_TRUE(d[0] == '\0');
     766        free(d);
     767}
     768
     769/** strdup function with non-empty string */
     770PCUT_TEST(strdup_nonempty)
     771{
     772        char *d = strdup("abc");
     773        PCUT_ASSERT_NOT_NULL(d);
     774        PCUT_ASSERT_TRUE(d[0] == 'a');
     775        PCUT_ASSERT_TRUE(d[1] == 'b');
     776        PCUT_ASSERT_TRUE(d[2] == 'c');
     777        PCUT_ASSERT_TRUE(d[3] == '\0');
     778        free(d);
     779}
     780
     781/** strndup function with empty string and non-zero limit */
     782PCUT_TEST(strndup_empty_short)
     783{
     784        char *d = strndup("", 1);
     785        PCUT_ASSERT_NOT_NULL(d);
     786        PCUT_ASSERT_TRUE(d[0] == '\0');
     787        free(d);
     788}
     789
     790/** strndup function with empty string and zero limit */
     791PCUT_TEST(strndup_empty_eq)
     792{
     793        char *d = strndup("", 0);
     794        PCUT_ASSERT_NOT_NULL(d);
     795        PCUT_ASSERT_TRUE(d[0] == '\0');
     796        free(d);
     797}
     798
     799/** strndup function with non-empty string of length below limit */
     800PCUT_TEST(strndup_nonempty_short)
     801{
     802        char *d = strndup("abc", 5);
     803        PCUT_ASSERT_NOT_NULL(d);
     804        PCUT_ASSERT_TRUE(d[0] == 'a');
     805        PCUT_ASSERT_TRUE(d[1] == 'b');
     806        PCUT_ASSERT_TRUE(d[2] == 'c');
     807        PCUT_ASSERT_TRUE(d[3] == '\0');
     808        free(d);
     809}
     810
     811/** strndup function with non-empty string of length equal to limit */
     812PCUT_TEST(strndup_nonempty_eq)
     813{
     814        char *d = strndup("abc", 3);
     815        PCUT_ASSERT_NOT_NULL(d);
     816        PCUT_ASSERT_TRUE(d[0] == 'a');
     817        PCUT_ASSERT_TRUE(d[1] == 'b');
     818        PCUT_ASSERT_TRUE(d[2] == 'c');
     819        PCUT_ASSERT_TRUE(d[3] == '\0');
     820        free(d);
     821}
     822
     823/** strndup function with non-empty string of length above limit */
     824PCUT_TEST(strndup_nonempty_long)
     825{
     826        char *d = strndup("abc", 2);
     827        PCUT_ASSERT_NOT_NULL(d);
     828        PCUT_ASSERT_TRUE(d[0] == 'a');
     829        PCUT_ASSERT_TRUE(d[1] == 'b');
     830        PCUT_ASSERT_TRUE(d[2] == '\0');
     831        free(d);
     832}
     833
    724834PCUT_EXPORT(string);
Note: See TracChangeset for help on using the changeset viewer.