source: mainline/uspace/lib/c/test/loc.c

Last change on this file was ca48672, checked in by Jiri Svoboda <jiri@…>, 8 days ago

loc_service_register() needs to take a port ID argument.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2025 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <errno.h>
30#include <loc.h>
31#include <pcut/pcut.h>
32
33PCUT_INIT;
34
35PCUT_TEST_SUITE(loc);
36
37/** loc_server_register() can be called multiple times */
38PCUT_TEST(server_register)
39{
40 errno_t rc;
41 loc_srv_t *sa, *sb;
42 service_id_t svca, svcb;
43 char *na, *nb;
44 char *sna, *snb;
45
46 rc = loc_server_register("test-a", &sa);
47 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
48
49 rc = loc_server_register("test-b", &sb);
50 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
51
52 // XXX Without a unique name this is not reentrant
53 rc = loc_service_register(sa, "test/libc-service-a",
54 fallback_port_id, &svca);
55 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
56
57 // XXX Without a unique name this is not reentrant
58 rc = loc_service_register(sb, "test/libc-service-b",
59 fallback_port_id, &svcb);
60 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
61
62 rc = loc_service_get_name(svca, &na);
63 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
64 PCUT_ASSERT_STR_EQUALS("test/libc-service-a", na);
65
66 rc = loc_service_get_server_name(svca, &sna);
67 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
68 PCUT_ASSERT_STR_EQUALS("test-a", sna);
69
70 rc = loc_service_get_name(svcb, &nb);
71 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
72 PCUT_ASSERT_STR_EQUALS("test/libc-service-b", nb);
73
74 rc = loc_service_get_server_name(svcb, &snb);
75 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
76 PCUT_ASSERT_STR_EQUALS("test-b", snb);
77
78 rc = loc_service_unregister(sa, svca);
79 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
80 rc = loc_service_unregister(sb, svcb);
81 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
82
83 loc_server_unregister(sa);
84 loc_server_unregister(sb);
85}
86
87PCUT_EXPORT(loc);
Note: See TracBrowser for help on using the repository browser.