Skip to content

Commit f3b02c3

Browse files
chiranmoyfCommitfest Bot
authored andcommitted
hex coding regress test
1 parent f727b63 commit f3b02c3

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
--
2+
-- tests for hex_encode and hex_decode in encode.c
3+
--
4+
-- Build table for testing
5+
CREATE TABLE BYTEA_TABLE(data BYTEA);
6+
-- hex_decode is used for inserting into bytea column
7+
-- Set bytea_output to hex so that hex_encode is used and tested
8+
SET bytea_output = 'hex';
9+
INSERT INTO BYTEA_TABLE VALUES ('\xAB');
10+
INSERT INTO BYTEA_TABLE VALUES ('\x01ab');
11+
INSERT INTO BYTEA_TABLE VALUES ('\xDEADC0DE');
12+
INSERT INTO BYTEA_TABLE VALUES ('\xbaadf00d');
13+
INSERT INTO BYTEA_TABLE VALUES ('\x C001 c0ffee '); -- hex string with whitespaces
14+
-- errors checking
15+
INSERT INTO BYTEA_TABLE VALUES ('\xbadf00d'); -- odd number of hex digits
16+
ERROR: invalid hexadecimal data: odd number of digits
17+
LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xbadf00d');
18+
^
19+
INSERT INTO BYTEA_TABLE VALUES ('\xdeadcode'); -- invalid hexadecimal digit: "o"
20+
ERROR: invalid hexadecimal digit: "o"
21+
LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xdeadcode');
22+
^
23+
INSERT INTO BYTEA_TABLE VALUES ('\xC00LC0FFEE'); -- invalid hexadecimal digit: "L"
24+
ERROR: invalid hexadecimal digit: "L"
25+
LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xC00LC0FFEE');
26+
^
27+
INSERT INTO BYTEA_TABLE VALUES ('\xC00LC*DE'); -- invalid hexadecimal digit: "*"
28+
ERROR: invalid hexadecimal digit: "L"
29+
LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xC00LC*DE');
30+
^
31+
INSERT INTO BYTEA_TABLE VALUES ('\xbad f00d'); -- invalid hexadecimal digit: " "
32+
ERROR: invalid hexadecimal digit: " "
33+
LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xbad f00d');
34+
^
35+
-- long hex strings to test SIMD implementation
36+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8))::bytea;
37+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || repeat('baadf00d', 8))::bytea;
38+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || ' ' || repeat('baad f00d', 8))::bytea; -- hex string with whitespaces
39+
-- errors checking for SIMD implementation
40+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'badf00d' || repeat('DEADC0DE', 4))::bytea; -- odd number of hex digits
41+
ERROR: invalid hexadecimal data: odd number of digits
42+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'baadfood'|| repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "o"
43+
ERROR: invalid hexadecimal digit: "o"
44+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'C00LC0FFEE' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "L"
45+
ERROR: invalid hexadecimal digit: "L"
46+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || 'C00LC*DE' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "*"
47+
ERROR: invalid hexadecimal digit: "L"
48+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || 'bad f00d' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: " "
49+
ERROR: invalid hexadecimal digit: " "
50+
SELECT encode(data, 'hex') FROM BYTEA_TABLE;
51+
encode
52+
----------------------------------------------------------------------------------------------------------------------------------
53+
ab
54+
01ab
55+
deadc0de
56+
baadf00d
57+
c001c0ffee
58+
deadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de
59+
deadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0debaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00d
60+
deadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0debaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00d
61+
(8 rows)
62+
63+
DROP TABLE BYTEA_TABLE;

src/test/regress/parallel_schedule

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ test: select_views portals_p2 foreign_key cluster dependency guc bitmapops combo
109109
# ----------
110110
test: json jsonb json_encoding jsonpath jsonpath_encoding jsonb_jsonpath sqljson sqljson_queryfuncs sqljson_jsontable
111111

112+
# ----------
113+
# Another group of parallel tests for hex encode/decode
114+
# ----------
115+
test: hex_coding
116+
112117
# ----------
113118
# Another group of parallel tests
114119
# with depends on create_misc

src/test/regress/sql/hex_coding.sql

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--
2+
-- tests for hex_encode and hex_decode in encode.c
3+
--
4+
5+
-- Build table for testing
6+
CREATE TABLE BYTEA_TABLE(data BYTEA);
7+
8+
-- hex_decode is used for inserting into bytea column
9+
-- Set bytea_output to hex so that hex_encode is used and tested
10+
SET bytea_output = 'hex';
11+
12+
INSERT INTO BYTEA_TABLE VALUES ('\xAB');
13+
INSERT INTO BYTEA_TABLE VALUES ('\x01ab');
14+
INSERT INTO BYTEA_TABLE VALUES ('\xDEADC0DE');
15+
INSERT INTO BYTEA_TABLE VALUES ('\xbaadf00d');
16+
INSERT INTO BYTEA_TABLE VALUES ('\x C001 c0ffee '); -- hex string with whitespaces
17+
18+
-- errors checking
19+
INSERT INTO BYTEA_TABLE VALUES ('\xbadf00d'); -- odd number of hex digits
20+
INSERT INTO BYTEA_TABLE VALUES ('\xdeadcode'); -- invalid hexadecimal digit: "o"
21+
INSERT INTO BYTEA_TABLE VALUES ('\xC00LC0FFEE'); -- invalid hexadecimal digit: "L"
22+
INSERT INTO BYTEA_TABLE VALUES ('\xC00LC*DE'); -- invalid hexadecimal digit: "*"
23+
INSERT INTO BYTEA_TABLE VALUES ('\xbad f00d'); -- invalid hexadecimal digit: " "
24+
25+
-- long hex strings to test SIMD implementation
26+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8))::bytea;
27+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || repeat('baadf00d', 8))::bytea;
28+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || ' ' || repeat('baad f00d', 8))::bytea; -- hex string with whitespaces
29+
30+
-- errors checking for SIMD implementation
31+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'badf00d' || repeat('DEADC0DE', 4))::bytea; -- odd number of hex digits
32+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'baadfood'|| repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "o"
33+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'C00LC0FFEE' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "L"
34+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || 'C00LC*DE' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "*"
35+
INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || 'bad f00d' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: " "
36+
37+
SELECT encode(data, 'hex') FROM BYTEA_TABLE;
38+
39+
DROP TABLE BYTEA_TABLE;

0 commit comments

Comments
 (0)