summaryrefslogtreecommitdiffhomepage
path: root/test/bitbuf.test.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2023-07-29 14:32:06 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2023-08-02 21:02:31 +0100
commit9a0d8730fa977f666b5c12e4c5901e7d0391e245 (patch)
tree87eebcdcef04ae1e7348ef80e972c08aa4783649 /test/bitbuf.test.c
parentd337b09936ecd90bad07b28b48b7103395d97ce5 (diff)
Make various preparations for upcoming features
A lot of this is random WIP from a while back, at least a month ago, and is being committed now to get it out of the way so that other patches can be brought in and integrated against it without causing headaches. Also rolled into this commit is a way to distinguish plugin_unload from exiting the game. This is required for another soon-to-be-integrated feature to avoid crashing on exit, and could in theory also be used to speed up unloading on exit in future. While we're at it, this also avoids the need to linearly scan through the plugin list to do the old branch unloading fix, because we can. Rough summary of the other smaller stuff I can remember doing: - Rework bitbuf a bit - Add some cryptographic nonsense in ac.c (not final at all) - Introduce the first couple of "chunklets" libraries as a sort-of subproject of this one - Tidy up random small bits and bobs - Add source for a small keypair generation tool - Rework democustom to be very marginally more useful
Diffstat (limited to 'test/bitbuf.test.c')
-rw-r--r--test/bitbuf.test.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/test/bitbuf.test.c b/test/bitbuf.test.c
index 324a7f6..554d3a2 100644
--- a/test/bitbuf.test.c
+++ b/test/bitbuf.test.c
@@ -15,15 +15,11 @@ static union {
static struct bitbuf bb = {bb_buf.buf, 512, 512 * 8, 0, false, false, "test"};
TEST("The possible UB in bitbuf_appendbuf shouldn't trigger horrible bugs") {
- char unalign[3] = {'X', 'X', 'X'};
- char _buf[32 + sizeof(bitbuf_cell)];
- char *buf = _buf;
- if (bitbuf_align <= 1) {
- // *shouldn't* happen
+ if (bitbuf_align <= 1) { // *shouldn't* happen
fputs("what's going on with the alignment???\n", stderr);
return false;
}
- // make sure the pointer is definitely misaligned
+ char _buf[32 + _Alignof(bitbuf_cell)], *buf = _buf;
while (!((usize)buf % bitbuf_align)) ++buf;
memcpy(buf, "Misaligned test buffer contents!", 32);
@@ -31,4 +27,18 @@ TEST("The possible UB in bitbuf_appendbuf shouldn't trigger horrible bugs") {
return !memcmp(bb.buf, buf, 32);
}
+TEST("Aligning to the next byte should work as intended") {
+ for (int i = 0; i < 65535; i += 8) {
+ bb.curbit = i;
+ bitbuf_roundup(&bb);
+ if (bb.curbit != i) return false; // don't round if already rounded
+ for (int j = i + 1; j < i + 8; ++j) {
+ bb.curbit = j;
+ bitbuf_roundup(&bb);
+ if (bb.curbit != i + 8) return false;
+ }
+ }
+ return true;
+}
+
// vi: sw=4 ts=4 noet tw=80 cc=80