| 1 |
/* |
| 2 |
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2020 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 2 мар. 2020 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <lsp-plug.in/test-fw/utest.h> |
| 23 |
#include <lsp-plug.in/i18n/Dictionary.h> |
| 24 |
|
| 25 |
using namespace lsp; |
| 26 |
|
| 27 |
UTEST_BEGIN("runtime.i18n", dictionary) |
| 28 |
|
| 29 |
void ck_lookup(i18n::IDictionary *d, const char *name, const char *value) |
| 30 |
{ |
| 31 |
LSPString v; |
| 32 |
printf(" lookup %s ...\n", name, value); |
| 33 |
UTEST_ASSERT(d->lookup(name, &v) == STATUS_OK); |
| 34 |
printf(" got %s -> %s...\n", name, v.get_utf8()); |
| 35 |
UTEST_ASSERT(v.equals_utf8(value)); |
| 36 |
} |
| 37 |
|
| 38 |
UTEST_MAIN |
| 39 |
{ |
| 40 |
i18n::Dictionary d; |
| 41 |
i18n::IDictionary *xd; |
| 42 |
|
| 43 |
printf("Creating dictionary...\n"); |
| 44 |
UTEST_ASSERT(d.init(resources()) == STATUS_OK); |
| 45 |
|
| 46 |
printf("Testing dictionary lookup...\n"); |
| 47 |
UTEST_ASSERT(d.lookup("i18n.k1", &xd) == STATUS_NOT_FOUND); |
| 48 |
UTEST_ASSERT(d.lookup("i18n.valid", &xd) == STATUS_OK); |
| 49 |
ck_lookup(xd, "k1", "v1"); |
| 50 |
ck_lookup(xd, "k8.k1.k2", "z2"); |
| 51 |
ck_lookup(xd, "k7.a3", "x3"); |
| 52 |
ck_lookup(xd, "k2", "special_case"); |
| 53 |
ck_lookup(xd, "k8.k1", "special_case2"); |
| 54 |
|
| 55 |
printf("Testing parameter access...\n"); |
| 56 |
LSPString v; |
| 57 |
UTEST_ASSERT(d.lookup("i18n", &v) == STATUS_NOT_FOUND); |
| 58 |
UTEST_ASSERT(d.lookup("i18n.valid", &v) == STATUS_NOT_FOUND); |
| 59 |
UTEST_ASSERT(d.lookup("i18n.valid.k3", &v) == STATUS_NOT_FOUND); |
| 60 |
|
| 61 |
ck_lookup(&d, "i18n.valid.k1", "v1"); |
| 62 |
ck_lookup(&d, "i18n.valid.k8.k1.k2", "z2"); |
| 63 |
ck_lookup(&d, "i18n.valid.k7.a3", "x3"); |
| 64 |
|
| 65 |
UTEST_ASSERT(d.lookup("x.a", &v) == STATUS_NOT_FOUND); |
| 66 |
UTEST_ASSERT(d.lookup("x.a", &v) == STATUS_NOT_FOUND); |
| 67 |
|
| 68 |
ck_lookup(&d, "i18n.valid.k2", "special_case"); |
| 69 |
ck_lookup(&d, "i18n.valid.k8.k1", "special_case2"); |
| 70 |
} |
| 71 |
|
| 72 |
UTEST_END |
| 73 |
|
| 74 |
|