tests/test_utils.cpp

Tue, 20 Jun 2023 18:26:35 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 20 Jun 2023 18:26:35 +0200
changeset 711
71b2f3f63182
parent 674
dc514a5d42a5
permissions
-rw-r--r--

update Doxyfile to Doxygen 1.9.6

633
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63a692642aa2 add utils tests
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
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/utils.h"
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
674
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
31 #include "cx/buffer.h"
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
32
633
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 #include <gtest/gtest.h>
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34
674
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
35 TEST(Utils, cx_stream_bncopy) {
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
36 CxBuffer source, target;
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
37 char sbuf[32], tbuf[32];
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
38 memset(tbuf, 0, 32);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
39 cxBufferInit(&source, sbuf, 32, nullptr, 0);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
40 cxBufferInit(&target, tbuf, 32, nullptr, 0);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
41 cxBufferPutString(&source, "This is a stream copy test.");
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
42 cxBufferSeek(&source, 0, SEEK_SET);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
43
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
44 char tmp[4];
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
45 size_t result = cx_stream_bncopy(&source, &target,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
46 (cx_read_func) cxBufferRead,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
47 (cx_write_func) cxBufferWrite,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
48 tmp, 4, 20);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
49 EXPECT_EQ(20, result);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
50 EXPECT_EQ(20, target.size);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
51 EXPECT_STREQ("This is a stream cop\0", tbuf);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
52
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
53 result = cx_stream_bcopy(&source, &target,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
54 (cx_read_func) cxBufferRead,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
55 (cx_write_func) cxBufferWrite,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
56 nullptr, 16);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
57
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
58 EXPECT_EQ(7, result);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
59 EXPECT_EQ(27, target.size);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
60 EXPECT_STREQ("This is a stream copy test.\0", tbuf);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
61
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
62 cxBufferDestroy(&source);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
63 cxBufferDestroy(&target);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
64 }
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
65
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
66 TEST(Utils, cx_stream_ncopy) {
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
67 CxBuffer source, target;
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
68 char sbuf[32], tbuf[32];
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
69 memset(tbuf, 0, 32);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
70 cxBufferInit(&source, sbuf, 32, nullptr, 0);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
71 cxBufferInit(&target, tbuf, 32, nullptr, 0);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
72 cxBufferPutString(&source, "This is a stream copy test.");
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
73 cxBufferSeek(&source, 0, SEEK_SET);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
74
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
75 size_t result = cx_stream_ncopy(&source, &target,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
76 (cx_read_func) cxBufferRead,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
77 (cx_write_func) cxBufferWrite,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
78 20);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
79 EXPECT_EQ(20, result);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
80 EXPECT_EQ(20, target.size);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
81 EXPECT_STREQ("This is a stream cop\0", tbuf);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
82
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
83 result = cx_stream_copy(&source, &target,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
84 (cx_read_func) cxBufferRead,
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
85 (cx_write_func) cxBufferWrite);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
86
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
87 EXPECT_EQ(7, result);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
88 EXPECT_EQ(27, target.size);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
89 EXPECT_STREQ("This is a stream copy test.\0", tbuf);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
90
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
91 cxBufferDestroy(&source);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
92 cxBufferDestroy(&target);
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
93 }
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
94
633
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 TEST(Utils, ForN) {
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 unsigned j;
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 j = 0;
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 cx_for_n(i, 50) {
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 EXPECT_EQ(i, j);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 j++;
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 }
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 }
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103
646
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
104 TEST(Utils, swap_ptr) {
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
105 int i = 5;
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
106 int j = 8;
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
107 int *ip = &i;
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
108 int *jp = &j;
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
109 cx_swap_ptr(ip, jp);
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
110 EXPECT_EQ(ip, &j);
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
111 EXPECT_EQ(jp, &i);
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
112 }
dfd0403ff8b6 add pointer swap utility
Mike Becker <universe@uap-core.de>
parents: 633
diff changeset
113
633
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 TEST(Utils, szmul) {
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 size_t r;
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 int e;
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 e = cx_szmul(5, 7, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 EXPECT_EQ(35, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 size_t s = SIZE_MAX & ~3;
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 e = cx_szmul(s / 4, 2, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 EXPECT_EQ(s / 2, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 e = cx_szmul(2, s / 4, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 EXPECT_EQ(s / 2, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 e = cx_szmul(s / 4, 4, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 EXPECT_EQ(s, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 e = cx_szmul(4, s / 4, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 EXPECT_EQ(s, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 e = cx_szmul(s / 4, 5, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 EXPECT_NE(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 e = cx_szmul(5, s / 4, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 EXPECT_NE(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 e = cx_szmul(SIZE_MAX - 4, 0, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 e = cx_szmul(0, SIZE_MAX - 1, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 e = cx_szmul(SIZE_MAX, 0, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 e = cx_szmul(0, SIZE_MAX, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 e = cx_szmul(0, 0, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 }
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 #ifdef CX_SZMUL_BUILTIN
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 // also test the custom implementation
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 struct Utils_szmul_impl : ::testing::Test {
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 #undef CX_SZMUL_BUILTIN
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170
674
dc514a5d42a5 add stream copy utils - fixes #254
Mike Becker <universe@uap-core.de>
parents: 654
diff changeset
171 #include "../src/szmul.c"
633
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 #define CX_SZMUL_BUILTIN
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 };
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 TEST_F(Utils_szmul_impl, Test) {
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 size_t r;
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 int e;
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 e = cx_szmul_impl(5, 7, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 EXPECT_EQ(35, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 size_t s = SIZE_MAX & ~3;
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 e = cx_szmul_impl(s / 4, 2, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187 EXPECT_EQ(s / 2, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188 e = cx_szmul_impl(2, s / 4, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190 EXPECT_EQ(s / 2, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 e = cx_szmul_impl(s / 4, 4, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194 EXPECT_EQ(s, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 e = cx_szmul_impl(4, s / 4, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 EXPECT_EQ(s, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 e = cx_szmul_impl(s / 4, 5, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 EXPECT_NE(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203 e = cx_szmul_impl(5, s / 4, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 EXPECT_NE(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206 e = cx_szmul_impl(SIZE_MAX - 4, 0, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 e = cx_szmul_impl(0, SIZE_MAX - 1, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214 e = cx_szmul_impl(SIZE_MAX, 0, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 e = cx_szmul_impl(0, SIZE_MAX, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 e = cx_szmul_impl(0, 0, &r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 EXPECT_EQ(0, e);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 EXPECT_EQ(0, r);
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 }
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226
63a692642aa2 add utils tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 #endif // CX_SZMUL_BUILTIN

mercurial