|
| 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; |
0 commit comments