*** /dev/null Sat Nov 23 06:18:20 2024
--- - Sat Nov 23 06:18:31 2024
***************
*** 0 ****
--- 1,150 ----
+ /*
+ XDS - OSSP Extensible Data Serialization Library
+ Copyright (c) 2001 The OSSP Project (http://www.ossp.org/)
+ Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/)
+
+ This file is part of OSSP XDS, an extensible data serialization
+ library which can be found at http://www.ossp.com/pkg/xds/.
+
+ Permission to use, copy, modify, and distribute this software for
+ any purpose with or without fee is hereby granted, provided that
+ the above copyright notice and this permission notice appear in all
+ copies.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ */
+
+ #include <stdio.h>
+ #include "../internal.h"
+
+ int main()
+ {
+ const engine_map_t engines[] =
+ {
+ { "alan", NULL, 0 },
+ { "berta", NULL, 0 },
+ { "caesar", NULL, 0 },
+ { "doris", NULL, 0 },
+ { "egon", NULL, 0 },
+ { "franziska", NULL, 0 },
+ { "gudrun", NULL, 0 },
+ { "heinz", NULL, 0 },
+ { "igor", NULL, 0 },
+ { "jamila", NULL, 0 },
+ { "karin", NULL, 0 },
+ { "louis", NULL, 0 },
+ };
+ size_t engines_len = sizeof(engines) / sizeof(engine_map_t);
+ size_t pos;
+ size_t i;
+
+ /* Search for every single entry in the array and check the
+ results. */
+
+ for (i = 0; i < engines_len; ++i)
+ {
+ if (!xds_find_engine(engines, engines_len, engines[i].name, &pos))
+ {
+ printf("xds_find_engine() said '%s' wouldn't be in the array, but that's wrong.\n",
+ engines[i].name);
+ exit(1);
+ }
+ if (pos != i)
+ {
+ printf("xds_find_engine() would insert '%s' at position %d, but %d is correct.\n",
+ engines[i].name, pos, i);
+ exit(1);
+ }
+ }
+
+ /* Search for non-existing name that would be inserted at the
+ first position. */
+
+ if (xds_find_engine(engines, engines_len, "aaron", &pos))
+ {
+ printf("xds_find_engine() said 'aaron' would be in the array, but that's wrong.\n");
+ exit(1);
+ }
+ if (pos != 0)
+ {
+ printf("xds_find_engine() would insert 'aaron' at position %d, but 0 is correct.\n", pos);
+ exit(1);
+ }
+
+ /* Search for non-existing name that would be inserted at last
+ position. */
+
+ if (xds_find_engine(engines, engines_len, "zerberos", &pos))
+ {
+ printf("xds_find_engine() said 'zerberos' would be in the array, but that's wrong.\n");
+ exit(1);
+ }
+ if (pos != engines_len)
+ {
+ printf("xds_find_engine() would insert 'zerberos' at position %d, but %d is correct.\n",
+ pos, engines_len);
+ exit(1);
+ }
+
+ /* Search for non-existing names that would be inserted at random
+ positions. */
+
+ if (xds_find_engine(engines, engines_len, "balthasar", &pos))
+ {
+ printf("xds_find_engine() said 'balthasar' would be in the array, but that's wrong.\n");
+ exit(1);
+ }
+ if (pos != 1)
+ {
+ printf("xds_find_engine() would insert 'balthasar' at position %d, but 1 is correct.\n", pos);
+ exit(1);
+ }
+
+ if (xds_find_engine(engines, engines_len, "bulli", &pos))
+ {
+ printf("xds_find_engine() said 'bulli' would be in the array, but that's wrong.\n");
+ exit(1);
+ }
+ if (pos != 2)
+ {
+ printf("xds_find_engine() would insert 'bulli' at position %d, but 2 is correct.\n", pos);
+ exit(1);
+ }
+
+ if (xds_find_engine(engines, engines_len, "hildegard", &pos))
+ {
+ printf("xds_find_engine() said 'hildegard' would be in the array, but that's wrong.\n");
+ exit(1);
+ }
+ if (pos != 8)
+ {
+ printf("xds_find_engine() would insert 'hildegard' at position %d, but 8 is correct.\n", pos);
+ exit(1);
+ }
+
+ if (xds_find_engine(engines, engines_len, "harald", &pos))
+ {
+ printf("xds_find_engine() said 'harald' would be in the array, but that's wrong.\n");
+ exit(1);
+ }
+ if (pos != 7)
+ {
+ printf("xds_find_engine() would insert 'harald' at position %d, but 7 is correct.\n", pos);
+ exit(1);
+ }
+
+ /* Everything went fine. */
+
+ return 0;
+ }
|