Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
yenc.qh
Go to the documentation of this file.
1#pragma once
2
3#include "test.qh"
4
5#define yenc_single(c, ret) MACRO_BEGIN \
6 int conv = c; \
7 conv += 42; \
8 if (conv >= 256) \
9 conv -= 256; \
10 switch (conv) \
11 { \
12 default: \
13 { \
14 string yenc_it = chr2str(conv); \
15 ret = yenc_it; \
16 break; \
17 } \
18 case 0: \
19 case '\n': \
20 case '\r': \
21 case '=': \
22 { \
23 conv += 64; \
24 string yenc_it = chr2str('=', conv); \
25 ret = yenc_it; \
26 break; \
27 } \
28 } \
29MACRO_END
30
31#define ydec_single(stringiter, ret) MACRO_BEGIN \
32 int conv = STRING_ITERATOR_GET(stringiter); \
33 if (conv <= 0) \
34 ret = -1; \
35 else \
36 { \
37 if (conv == '=') \
38 { \
39 conv = STRING_ITERATOR_GET(stringiter); \
40 conv -= 64; \
41 } \
42 if (conv < 42) \
43 conv += 256; \
44 conv -= 42; \
45 ret = conv; \
46 } \
47MACRO_END
48
49TEST(yEnc, EncodeDecode)
50{
51 for (int i = 0; i <= 255; ++i)
52 {
53 int expect = i;
54
55 string fragment = string_null;
56 yenc_single(expect, fragment);
57
58 int encdec = 0;
59 STRING_ITERATOR(fragmentiterator, fragment, 0);
60 ydec_single(fragmentiterator, encdec);
61
62 EXPECT_EQ(expect, encdec);
63 }
64 SUCCEED();
65}
#define STRING_ITERATOR(this, s, i)
Definition iter.qh:45
string string_null
Definition nil.qh:9
#define TEST(suite, test)
Use UpperCamelCase for suite and test only.
Definition test.qh:6
#define EXPECT_EQ(expected_, actual_)
Definition test.qh:34
#define SUCCEED()
Must be present at the end of a test.
Definition test.qh:17
#define yenc_single(c, ret)
Definition yenc.qh:5
#define ydec_single(stringiter, ret)
Definition yenc.qh:31