Thu, 10 Oct 2024 18:40:27 +0200
add ucx2.1 style interface for a properties parser
relates to #429
766
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved. |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | |
767
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
29 | #include "cx/test.h" |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
30 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
31 | #include "cx/utils.h" |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
32 | #include "cx/buffer.h" |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
33 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
34 | CX_TEST(test_stream_bncopy) { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
35 | CxBuffer source, target; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
36 | char sbuf[32], tbuf[32]; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
37 | memset(tbuf, 0, 32); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
38 | cxBufferInit(&source, sbuf, 32, NULL, 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
39 | cxBufferInit(&target, tbuf, 32, NULL, 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
40 | cxBufferPutString(&source, "This is a stream copy test."); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
41 | cxBufferSeek(&source, 0, SEEK_SET); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
42 | char tmp[4]; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
43 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
44 | CX_TEST_DO { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
45 | size_t result = cx_stream_bncopy(&source, &target, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
46 | (cx_read_func) cxBufferRead, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
47 | (cx_write_func) cxBufferWrite, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
48 | tmp, 4, 20); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
49 | CX_TEST_ASSERT(result == 20); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
50 | CX_TEST_ASSERT(target.size == 20); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
51 | CX_TEST_ASSERT(strcmp("This is a stream cop\0", tbuf) == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
52 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
53 | result = cx_stream_bcopy(&source, &target, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
54 | (cx_read_func) cxBufferRead, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
55 | (cx_write_func) cxBufferWrite, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
56 | NULL, 16); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
57 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
58 | CX_TEST_ASSERT(result == 7); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
59 | CX_TEST_ASSERT(target.size == 27); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
60 | CX_TEST_ASSERT(strcmp("This is a stream copy test.\0", tbuf) == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
61 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
62 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
63 | cxBufferDestroy(&source); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
64 | cxBufferDestroy(&target); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
65 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
66 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
67 | CX_TEST(test_stream_ncopy) { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
68 | CxBuffer source, target; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
69 | char sbuf[32], tbuf[32]; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
70 | memset(tbuf, 0, 32); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
71 | cxBufferInit(&source, sbuf, 32, NULL, 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
72 | cxBufferInit(&target, tbuf, 32, NULL, 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
73 | cxBufferPutString(&source, "This is a stream copy test."); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
74 | cxBufferSeek(&source, 0, SEEK_SET); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
75 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
76 | CX_TEST_DO { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
77 | size_t result = cx_stream_ncopy(&source, &target, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
78 | (cx_read_func) cxBufferRead, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
79 | (cx_write_func) cxBufferWrite, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
80 | 20); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
81 | CX_TEST_ASSERT(result == 20); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
82 | CX_TEST_ASSERT(target.size == 20); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
83 | CX_TEST_ASSERT(strcmp("This is a stream cop\0", tbuf) == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
84 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
85 | result = cx_stream_copy(&source, &target, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
86 | (cx_read_func) cxBufferRead, |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
87 | (cx_write_func) cxBufferWrite); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
88 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
89 | CX_TEST_ASSERT(result == 7); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
90 | CX_TEST_ASSERT(target.size == 27); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
91 | CX_TEST_ASSERT(strcmp("This is a stream copy test.\0", tbuf) == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
92 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
93 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
94 | cxBufferDestroy(&source); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
95 | cxBufferDestroy(&target); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
96 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
97 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
98 | CX_TEST(test_forn) { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
99 | unsigned j; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
100 | j = 0; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
101 | CX_TEST_DO { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
102 | cx_for_n(i, 50) { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
103 | CX_TEST_ASSERT(i == j); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
104 | j++; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
105 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
106 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
107 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
108 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
109 | CX_TEST(test_swap_ptr) { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
110 | int i = 5; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
111 | int j = 8; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
112 | int *ip = &i; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
113 | int *jp = &j; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
114 | CX_TEST_DO { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
115 | cx_swap_ptr(ip, jp); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
116 | CX_TEST_ASSERT(ip == &j); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
117 | CX_TEST_ASSERT(jp == &i); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
118 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
119 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
120 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
121 | CX_TEST(test_szmul) { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
122 | size_t r; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
123 | int e; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
124 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
125 | CX_TEST_DO { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
126 | e = cx_szmul(5, 7, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
127 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
128 | CX_TEST_ASSERT(r == 35); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
129 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
130 | size_t s = SIZE_MAX & ~3; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
131 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
132 | e = cx_szmul(s / 4, 2, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
133 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
134 | CX_TEST_ASSERT(r == s / 2); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
135 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
136 | e = cx_szmul(2, s / 4, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
137 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
138 | CX_TEST_ASSERT(r == s / 2); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
139 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
140 | e = cx_szmul(s / 4, 4, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
141 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
142 | CX_TEST_ASSERT(r == s); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
143 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
144 | e = cx_szmul(4, s / 4, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
145 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
146 | CX_TEST_ASSERT(r == s); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
147 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
148 | e = cx_szmul(s / 4, 5, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
149 | CX_TEST_ASSERT(e != 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
150 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
151 | e = cx_szmul(5, s / 4, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
152 | CX_TEST_ASSERT(e != 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
153 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
154 | e = cx_szmul(SIZE_MAX - 4, 0, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
155 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
156 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
157 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
158 | e = cx_szmul(0, SIZE_MAX - 1, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
159 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
160 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
161 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
162 | e = cx_szmul(SIZE_MAX, 0, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
163 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
164 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
165 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
166 | e = cx_szmul(0, SIZE_MAX, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
167 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
168 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
169 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
170 | e = cx_szmul(0, 0, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
171 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
172 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
173 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
174 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
175 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
176 | #ifdef CX_SZMUL_BUILTIN |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
177 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
178 | // also test the custom implementation |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
179 | #undef CX_SZMUL_BUILTIN |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
180 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
181 | #include "../src/szmul.c" |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
182 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
183 | #define CX_SZMUL_BUILTIN |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
184 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
185 | CX_TEST(test_szmul_impl) { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
186 | size_t r; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
187 | int e; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
188 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
189 | CX_TEST_DO { |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
190 | e = cx_szmul_impl(5, 7, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
191 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
192 | CX_TEST_ASSERT(r == 35); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
193 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
194 | size_t s = SIZE_MAX & ~3; |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
195 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
196 | e = cx_szmul_impl(s / 4, 2, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
197 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
198 | CX_TEST_ASSERT(r == s / 2); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
199 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
200 | e = cx_szmul_impl(2, s / 4, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
201 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
202 | CX_TEST_ASSERT(r == s / 2); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
203 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
204 | e = cx_szmul_impl(s / 4, 4, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
205 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
206 | CX_TEST_ASSERT(r == s); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
207 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
208 | e = cx_szmul_impl(4, s / 4, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
209 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
210 | CX_TEST_ASSERT(r == s); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
211 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
212 | e = cx_szmul_impl(s / 4, 5, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
213 | CX_TEST_ASSERT(e != 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
214 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
215 | e = cx_szmul_impl(5, s / 4, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
216 | CX_TEST_ASSERT(e != 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
217 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
218 | e = cx_szmul_impl(SIZE_MAX - 4, 0, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
219 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
220 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
221 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
222 | e = cx_szmul_impl(0, SIZE_MAX - 1, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
223 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
224 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
225 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
226 | e = cx_szmul_impl(SIZE_MAX, 0, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
227 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
228 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
229 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
230 | e = cx_szmul_impl(0, SIZE_MAX, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
231 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
232 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
233 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
234 | e = cx_szmul_impl(0, 0, &r); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
235 | CX_TEST_ASSERT(e == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
236 | CX_TEST_ASSERT(r == 0); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
237 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
238 | } |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
239 | |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
240 | #endif // CX_SZMUL_BUILTIN |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
241 | |
766
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
242 | |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
243 | CxTestSuite *cx_test_suite_utils(void) { |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | CxTestSuite *suite = cx_test_suite_new("utils"); |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
245 | |
767
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
246 | cx_test_register(suite, test_stream_bncopy); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
247 | cx_test_register(suite, test_stream_ncopy); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
248 | cx_test_register(suite, test_forn); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
249 | cx_test_register(suite, test_swap_ptr); |
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
250 | cx_test_register(suite, test_szmul); |
841
93851c0babe4
fix build in case CX_SZMUL_BUILTIN is undefined
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
768
diff
changeset
|
251 | #ifdef CX_SZMUL_BUILTIN |
767
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
252 | cx_test_register(suite, test_szmul_impl); |
841
93851c0babe4
fix build in case CX_SZMUL_BUILTIN is undefined
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
768
diff
changeset
|
253 | #endif |
767
d31f4d4075dc
migrate utils tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
766
diff
changeset
|
254 | |
766
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
255 | return suite; |
e59b76889f00
bring back UCX test - fixes #341
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
256 | } |