[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>
|
---|
| 31 | #include <startmenu/startmenu.h>
|
---|
| 32 | #include <stdio.h>
|
---|
| 33 |
|
---|
| 34 | PCUT_INIT;
|
---|
| 35 |
|
---|
| 36 | PCUT_TEST_SUITE(startmenu);
|
---|
| 37 |
|
---|
| 38 | /** Opening and closing start menu */
|
---|
| 39 | PCUT_TEST(open_close)
|
---|
| 40 | {
|
---|
| 41 | errno_t rc;
|
---|
| 42 | startmenu_t *smenu;
|
---|
| 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 |
|
---|
| 55 | rc = startmenu_open("/tmp/test", &smenu);
|
---|
| 56 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 57 |
|
---|
| 58 | startmenu_close(smenu);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /** Iterating over start menu entries */
|
---|
| 62 | PCUT_TEST(first_next)
|
---|
| 63 | {
|
---|
| 64 | errno_t rc;
|
---|
| 65 | startmenu_t *smenu;
|
---|
| 66 | startmenu_entry_t *e;
|
---|
| 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 |
|
---|
| 82 | rc = startmenu_open("/tmp/test", &smenu);
|
---|
| 83 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 84 |
|
---|
| 85 | e = startmenu_first(smenu);
|
---|
| 86 | PCUT_ASSERT_NOT_NULL(e);
|
---|
| 87 | e = startmenu_next(e);
|
---|
| 88 | PCUT_ASSERT_NOT_NULL(e);
|
---|
| 89 | e = startmenu_next(e);
|
---|
| 90 | PCUT_ASSERT_NULL(e);
|
---|
| 91 |
|
---|
| 92 | startmenu_close(smenu);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | /** Getting menu entry properties */
|
---|
| 96 | PCUT_TEST(get_caption_cmd)
|
---|
| 97 | {
|
---|
| 98 | errno_t rc;
|
---|
| 99 | startmenu_t *smenu;
|
---|
| 100 | startmenu_entry_t *e;
|
---|
| 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 |
|
---|
| 117 | rc = startmenu_open("/tmp/test", &smenu);
|
---|
| 118 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 119 |
|
---|
| 120 | e = startmenu_first(smenu);
|
---|
| 121 | PCUT_ASSERT_NOT_NULL(e);
|
---|
| 122 |
|
---|
| 123 | caption = startmenu_entry_get_caption(e);
|
---|
| 124 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
| 125 | cmd = startmenu_entry_get_cmd(e);
|
---|
| 126 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
| 127 |
|
---|
| 128 | startmenu_close(smenu);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | PCUT_EXPORT(startmenu);
|
---|