source: mainline/uspace/lib/tbarcfg/test/tbarcfg.c@ d4643db

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d4643db was b279899, checked in by Jiri Svoboda <jiri@…>, 21 months ago

Rename startmenu library to tbarcfg

There may be other aspects of task bar that will need configuring
so let's widen the scope of the library a bit.

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[7d78e466]1/*
2 * Copyright (c) 2023 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 <pcut/pcut.h>
[b279899]31#include <tbarcfg/tbarcfg.h>
[7d78e466]32#include <stdio.h>
33
34PCUT_INIT;
35
[b279899]36PCUT_TEST_SUITE(tbarcfg);
[7d78e466]37
[b279899]38/** Opening and closing task bar configuration */
[7d78e466]39PCUT_TEST(open_close)
40{
41 errno_t rc;
[b279899]42 tbarcfg_t *tbcfg;
[7d78e466]43 FILE *f;
44 int rv;
45
46 f = fopen("/tmp/test", "wt");
47 PCUT_ASSERT_NOT_NULL(f);
48
49 rv = fputs("[sif](){[entries](){}}", f);
50 PCUT_ASSERT_TRUE(rv >= 0);
51
52 rv = fclose(f);
53 PCUT_ASSERT_INT_EQUALS(0, rv);
54
[b279899]55 rc = tbarcfg_open("/tmp/test", &tbcfg);
[7d78e466]56 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
57
[b279899]58 tbarcfg_close(tbcfg);
[7d78e466]59}
60
61/** Iterating over start menu entries */
62PCUT_TEST(first_next)
63{
64 errno_t rc;
[b279899]65 tbarcfg_t *tbcfg;
66 smenu_entry_t *e;
[7d78e466]67 FILE *f;
68 int rv;
69
70 f = fopen("/tmp/test", "wt");
71 PCUT_ASSERT_NOT_NULL(f);
72
73 rv = fputs("[sif](){[entries](){"
74 "[entry]([caption]=[A][cmd]=[a]){}"
75 "[entry]([caption]=[B][cmd]=[b]){}"
76 "}}", f);
77 PCUT_ASSERT_TRUE(rv >= 0);
78
79 rv = fclose(f);
80 PCUT_ASSERT_INT_EQUALS(0, rv);
81
[b279899]82 rc = tbarcfg_open("/tmp/test", &tbcfg);
[7d78e466]83 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
84
[b279899]85 e = tbarcfg_smenu_first(tbcfg);
[7d78e466]86 PCUT_ASSERT_NOT_NULL(e);
[b279899]87 e = tbarcfg_smenu_next(e);
[7d78e466]88 PCUT_ASSERT_NOT_NULL(e);
[b279899]89 e = tbarcfg_smenu_next(e);
[7d78e466]90 PCUT_ASSERT_NULL(e);
91
[b279899]92 tbarcfg_close(tbcfg);
[7d78e466]93}
94
95/** Getting menu entry properties */
96PCUT_TEST(get_caption_cmd)
97{
98 errno_t rc;
[b279899]99 tbarcfg_t *tbcfg;
100 smenu_entry_t *e;
[7d78e466]101 const char *caption;
102 const char *cmd;
103 FILE *f;
104 int rv;
105
106 f = fopen("/tmp/test", "wt");
107 PCUT_ASSERT_NOT_NULL(f);
108
109 rv = fputs("[sif](){[entries](){"
110 "[entry]([caption]=[A][cmd]=[a]){}"
111 "}}", f);
112 PCUT_ASSERT_TRUE(rv >= 0);
113
114 rv = fclose(f);
115 PCUT_ASSERT_INT_EQUALS(0, rv);
116
[b279899]117 rc = tbarcfg_open("/tmp/test", &tbcfg);
[7d78e466]118 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
119
[b279899]120 e = tbarcfg_smenu_first(tbcfg);
[7d78e466]121 PCUT_ASSERT_NOT_NULL(e);
122
[b279899]123 caption = smenu_entry_get_caption(e);
[7d78e466]124 PCUT_ASSERT_STR_EQUALS("A", caption);
[b279899]125 cmd = smenu_entry_get_cmd(e);
[7d78e466]126 PCUT_ASSERT_STR_EQUALS("a", cmd);
127
[b279899]128 tbarcfg_close(tbcfg);
[7d78e466]129}
130
[b279899]131PCUT_EXPORT(tbarcfg);
Note: See TracBrowser for help on using the repository browser.