1*22c3edb3SPhilip Paeps /* Tests related to the XCS (XML character string) functionality
2*22c3edb3SPhilip Paeps __ __ _
3*22c3edb3SPhilip Paeps ___\ \/ /_ __ __ _| |_
4*22c3edb3SPhilip Paeps / _ \\ /| '_ \ / _` | __|
5*22c3edb3SPhilip Paeps | __// \| |_) | (_| | |_
6*22c3edb3SPhilip Paeps \___/_/\_\ .__/ \__,_|\__|
7*22c3edb3SPhilip Paeps |_| XML parser
8*22c3edb3SPhilip Paeps
9*22c3edb3SPhilip Paeps Copyright (c) 2026 Sebastian Pipping <sebastian@pipping.org>
10*22c3edb3SPhilip Paeps Licensed under the MIT license:
11*22c3edb3SPhilip Paeps
12*22c3edb3SPhilip Paeps Permission is hereby granted, free of charge, to any person obtaining
13*22c3edb3SPhilip Paeps a copy of this software and associated documentation files (the
14*22c3edb3SPhilip Paeps "Software"), to deal in the Software without restriction, including
15*22c3edb3SPhilip Paeps without limitation the rights to use, copy, modify, merge, publish,
16*22c3edb3SPhilip Paeps distribute, sublicense, and/or sell copies of the Software, and to permit
17*22c3edb3SPhilip Paeps persons to whom the Software is furnished to do so, subject to the
18*22c3edb3SPhilip Paeps following conditions:
19*22c3edb3SPhilip Paeps
20*22c3edb3SPhilip Paeps The above copyright notice and this permission notice shall be included
21*22c3edb3SPhilip Paeps in all copies or substantial portions of the Software.
22*22c3edb3SPhilip Paeps
23*22c3edb3SPhilip Paeps THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24*22c3edb3SPhilip Paeps EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25*22c3edb3SPhilip Paeps MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
26*22c3edb3SPhilip Paeps NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27*22c3edb3SPhilip Paeps DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28*22c3edb3SPhilip Paeps OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
29*22c3edb3SPhilip Paeps USE OR OTHER DEALINGS IN THE SOFTWARE.
30*22c3edb3SPhilip Paeps
31*22c3edb3SPhilip Paeps SPDX-License-Identifier: MIT
32*22c3edb3SPhilip Paeps */
33*22c3edb3SPhilip Paeps
34*22c3edb3SPhilip Paeps #include "xcs_tests.h"
35*22c3edb3SPhilip Paeps
36*22c3edb3SPhilip Paeps #include "ascii.h"
37*22c3edb3SPhilip Paeps #include "common.h" // for g_chunkSize
38*22c3edb3SPhilip Paeps #include "xcs.h" // for xcslen, xcscmp, xcsncmp
39*22c3edb3SPhilip Paeps
40*22c3edb3SPhilip Paeps static const XML_Char empty[] = {'\0'};
41*22c3edb3SPhilip Paeps static const XML_Char test[] = {ASCII_T, ASCII_E, ASCII_S, ASCII_T, '\0'};
42*22c3edb3SPhilip Paeps static const XML_Char testing[]
43*22c3edb3SPhilip Paeps = {ASCII_T, ASCII_E, ASCII_S, ASCII_T, ASCII_I, ASCII_N, ASCII_G, '\0'};
44*22c3edb3SPhilip Paeps
START_TEST(test_xcs_len)45*22c3edb3SPhilip Paeps START_TEST(test_xcs_len) {
46*22c3edb3SPhilip Paeps if (g_chunkSize != 0)
47*22c3edb3SPhilip Paeps return;
48*22c3edb3SPhilip Paeps
49*22c3edb3SPhilip Paeps assert_true(xcslen(empty) == 0);
50*22c3edb3SPhilip Paeps assert_true(xcslen(test) == 4);
51*22c3edb3SPhilip Paeps }
52*22c3edb3SPhilip Paeps END_TEST
53*22c3edb3SPhilip Paeps
START_TEST(test_xcs_cmp)54*22c3edb3SPhilip Paeps START_TEST(test_xcs_cmp) {
55*22c3edb3SPhilip Paeps if (g_chunkSize != 0)
56*22c3edb3SPhilip Paeps return;
57*22c3edb3SPhilip Paeps
58*22c3edb3SPhilip Paeps assert_true(xcscmp(test, test) == 0);
59*22c3edb3SPhilip Paeps assert_true(xcscmp(test, testing) < 0);
60*22c3edb3SPhilip Paeps assert_true(xcscmp(testing, test) > 0);
61*22c3edb3SPhilip Paeps }
62*22c3edb3SPhilip Paeps END_TEST
63*22c3edb3SPhilip Paeps
START_TEST(test_xcs_ncmp)64*22c3edb3SPhilip Paeps START_TEST(test_xcs_ncmp) {
65*22c3edb3SPhilip Paeps if (g_chunkSize != 0)
66*22c3edb3SPhilip Paeps return;
67*22c3edb3SPhilip Paeps
68*22c3edb3SPhilip Paeps assert_true(xcsncmp(test, test, 0) == 0);
69*22c3edb3SPhilip Paeps assert_true(xcsncmp(test, test, 4) == 0);
70*22c3edb3SPhilip Paeps
71*22c3edb3SPhilip Paeps assert_true(xcsncmp(test, testing, 4) == 0);
72*22c3edb3SPhilip Paeps assert_true(xcsncmp(testing, test, 4) == 0);
73*22c3edb3SPhilip Paeps
74*22c3edb3SPhilip Paeps assert_true(xcsncmp(test, testing, 5) < 0);
75*22c3edb3SPhilip Paeps assert_true(xcsncmp(testing, test, 5) > 0);
76*22c3edb3SPhilip Paeps }
77*22c3edb3SPhilip Paeps END_TEST
78*22c3edb3SPhilip Paeps
79*22c3edb3SPhilip Paeps void
make_xcs_test_case(Suite * s)80*22c3edb3SPhilip Paeps make_xcs_test_case(Suite *s) {
81*22c3edb3SPhilip Paeps TCase *const tc_xcs = tcase_create("xcs tests");
82*22c3edb3SPhilip Paeps suite_add_tcase(s, tc_xcs);
83*22c3edb3SPhilip Paeps tcase_add_test(tc_xcs, test_xcs_len);
84*22c3edb3SPhilip Paeps tcase_add_test(tc_xcs, test_xcs_cmp);
85*22c3edb3SPhilip Paeps tcase_add_test(tc_xcs, test_xcs_ncmp);
86*22c3edb3SPhilip Paeps }
87