Changeset 75c430e3 in mainline for uspace/lib/c/test/stdlib.c


Ignore:
Timestamp:
2018-06-19T11:48:03Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
47be512
Parents:
6c440362
git-author:
Jiri Svoboda <jiri@…> (2018-06-18 17:47:07)
git-committer:
Jiri Svoboda <jiri@…> (2018-06-19 11:48:03)
Message:

Bsearch, getenv, system need to go to libc. (although we might eventually want different implementation for POSIX mode.)

File:
1 edited

Legend:

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

    r6c440362 r75c430e3  
    282282}
    283283
     284/** getenv function */
     285PCUT_TEST(getenv)
     286{
     287        char *s;
     288
     289        s = getenv("FOO");
     290        PCUT_ASSERT_NULL(s);
     291}
     292
     293/** Test availability of command processor */
     294PCUT_TEST(system_null)
     295{
     296        int rc;
     297
     298        rc = system(NULL);
     299        PCUT_ASSERT_INT_EQUALS(0, rc);
     300}
     301
     302/** Test running a command */
     303PCUT_TEST(system_cmd)
     304{
     305        int rc;
     306
     307        /* This should fail as system is just a stub */
     308        rc = system("/app/bdsh");
     309        PCUT_ASSERT_INT_EQUALS(1, rc);
     310}
     311
     312/** Comparison function for bsearch test */
     313static int test_compar(const void *a, const void *b)
     314{
     315        const int *ia, *ib;
     316
     317        ia = (const int *)a;
     318        ib = (const int *)b;
     319
     320        return *ia - *ib;
     321}
     322
     323PCUT_TEST(bsearch)
     324{
     325        int numbers[] = { 1, 2, 6, 7, 7, 10, 100, 120 };
     326        int k;
     327        void *r;
     328
     329        k = 0;
     330        r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
     331            test_compar);
     332        PCUT_ASSERT_NULL(r);
     333
     334        k = 1;
     335        r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
     336            test_compar);
     337        PCUT_ASSERT_NOT_NULL(r);
     338        PCUT_ASSERT_INT_EQUALS(1, *(int *)r);
     339
     340        k = 3;
     341        r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
     342            test_compar);
     343        PCUT_ASSERT_NULL(r);
     344
     345        k = 6;
     346        r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
     347            test_compar);
     348        PCUT_ASSERT_NOT_NULL(r);
     349        PCUT_ASSERT_INT_EQUALS(6, *(int *)r);
     350
     351        k = 7;
     352        r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
     353            test_compar);
     354        PCUT_ASSERT_NOT_NULL(r);
     355        PCUT_ASSERT_INT_EQUALS(7, *(int *)r);
     356
     357        k = 200;
     358        r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
     359            test_compar);
     360        PCUT_ASSERT_NULL(r);
     361}
     362
    284363/** Integer division */
    285364PCUT_TEST(div_func)
Note: See TracChangeset for help on using the changeset viewer.