| 1 | #cxx . . $ `<file>/t/system.cc`/include <opustags.h>cxx . . $ `<file>/src/opustags.h`/ |
| 2 | #include "tap.h"cxx . . $ `<file>/t/tap.h`/ |
| 3 | |
| 4 | #include <string.h> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | void check_partial_filescxx . . $ check_partial_files(49f6e7a06ebc5aa8).() |
| 8 | { |
| 9 | static const char* result = "partial_file.test"; |
| 10 | stdcxx . . $ std/::stringcxx . . $ std/string# namecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 11 | { |
| 12 | otcxx . . $ ot/::partial_filecxx . . $ ot/partial_file# bad_tmp; |
| 13 | try { |
| 14 | bad_tmp.opencxx . . $ ot/partial_file#open(85c52e162fed56f9).("/dev/null"); |
| 15 | throw failurecxx . . $ tap/failure#("opening a device as a partial file should fail"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 16 | } catch (const otcxx . . $ ot/::statuscxx . . $ ot/status#& rc) { |
| 17 | iscxx . . $ tap/is(e56f9d162936dca9).(rc, otcxx . . $ ot/::stcxx . . $ ot/st#::standard_errorcxx . . $ ot/st#standard_error., "opening a device as a partial file fails"); |
| 18 | } |
| 19 | |
| 20 | bad_tmp.opencxx . . $ ot/partial_file#open(85c52e162fed56f9).(result); |
| 21 | name =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). bad_tmp.namecxx . . $ ot/partial_file#name(a9f41ea0e82d88cf).(); |
| 22 | if (name.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).() != strlen(result) + 12 || |
| 23 | name.comparecxx . . $ std/__cxx11/basic_string#compare(a77748ade175f708).(0, strlen(result), result) != 0) |
| 24 | throw failurecxx . . $ tap/failure#("the temporary name is surprising: " +cxx . . $ std/operator+(42c652dfebe55ad7). name); |
| 25 | } |
| 26 | iscxx . . $ tap/is(e56f9d162936dca9).(access(name.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), F_OKcxx . . $ `<external>/12628407106812493757/unistd.h:284:9`!), -1, "expect the temporary file is deleted"); |
| 27 | |
| 28 | otcxx . . $ ot/::partial_filecxx . . $ ot/partial_file# good_tmp; |
| 29 | good_tmp.opencxx . . $ ot/partial_file#open(85c52e162fed56f9).(result); |
| 30 | name =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). good_tmp.namecxx . . $ ot/partial_file#name(a9f41ea0e82d88cf).(); |
| 31 | good_tmp.commitcxx . . $ ot/partial_file#commit(49f6e7a06ebc5aa8).(); |
| 32 | iscxx . . $ tap/is(e56f9d162936dca9).(access(name.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), F_OKcxx . . $ `<external>/12628407106812493757/unistd.h:284:9`!), -1, "expect the temporary file is deleted"); |
| 33 | iscxx . . $ tap/is(e56f9d162936dca9).(access(result, F_OKcxx . . $ `<external>/12628407106812493757/unistd.h:284:9`!), 0, "expect the final result file"); |
| 34 | iscxx . . $ tap/is(e56f9d162936dca9).(remove(result), 0, "remove the result file"); |
| 35 | } |
| 36 | |
| 37 | void check_slurpcxx . . $ check_slurp(49f6e7a06ebc5aa8).() |
| 38 | { |
| 39 | static const otcxx . . $ ot/::byte_string_viewcxx . . $ ot/byte_string_view# pixel = ""_bsvcxx . . $ `operator""_bsv`(630326791a3f0367). |
| 40 | "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d" |
| 41 | "\x49\x48\x44\x52\x00\x00\x00\x01\x00\x00\x00\x01" |
| 42 | "\x08\x02\x00\x00\x00\x90\x77\x53\xde\x00\x00\x00" |
| 43 | "\x0c\x49\x44\x41\x54\x08\xd7\x63\xf8\xff\xff\x3f" |
| 44 | "\x00\x05\xfe\x02\xfe\xdc\xcc\x59\xe7\x00\x00\x00" |
| 45 | "\x00\x49\x45\x4e\x44\xae\x42\x60\x82"; |
| 46 | opaque_iscxx . . $ tap/opaque_is(e56f9d162936dca9).(otcxx . . $ ot/::slurp_binary_filecxx . . $ ot/slurp_binary_file(568fd295d03a71e1).("pixel.png"), pixel, "loads a whole file"); |
| 47 | } |
| 48 | |
| 49 | void check_convertercxx . . $ check_converter(49f6e7a06ebc5aa8).() |
| 50 | { |
| 51 | setlocale(LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, ""); |
| 52 | iscxx . . $ tap/is(e56f9d162936dca9).(otcxx . . $ ot/::decode_utf8cxx . . $ ot/decode_utf8(249f514546b71f2d).(otcxx . . $ ot/::encode_utf8cxx . . $ ot/encode_utf8(4bb652cfea9d987a).("Éphémère"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).)), "Éphémère", "decode_utf8 reverts encode_utf8"); |
| 53 | opaque_iscxx . . $ tap/opaque_is(e56f9d162936dca9).(otcxx . . $ ot/::encode_utf8cxx . . $ ot/encode_utf8(4bb652cfea9d987a).(otcxx . . $ ot/::decode_utf8cxx . . $ ot/decode_utf8(249f514546b71f2d).(u8"Éphémère"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).)), u8"Éphémère", |
| 54 | "encode_utf8 reverts decode_utf8"); |
| 55 | |
| 56 | try { |
| 57 | otcxx . . $ ot/::decode_utf8cxx . . $ ot/decode_utf8(249f514546b71f2d).((cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).char8_t*) "\xFF\xFF"); |
| 58 | throw failurecxx . . $ tap/failure#("conversion from bad UTF-8 did not fail"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 59 | } catch (const otcxx . . $ ot/::statuscxx . . $ ot/status#&) {} |
| 60 | } |
| 61 | |
| 62 | void check_shell_esapecxx . . $ check_shell_esape(49f6e7a06ebc5aa8).() |
| 63 | { |
| 64 | iscxx . . $ tap/is(e56f9d162936dca9).(otcxx . . $ ot/::shell_escapecxx . . $ ot/shell_escape(6ccff4770ff7ddc3).("foo"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).), "'foo'", "simple string"); |
| 65 | iscxx . . $ tap/is(e56f9d162936dca9).(otcxx . . $ ot/::shell_escapecxx . . $ ot/shell_escape(6ccff4770ff7ddc3).("a'b"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).), "'a'\\''b'", "string with a simple quote"); |
| 66 | iscxx . . $ tap/is(e56f9d162936dca9).(otcxx . . $ ot/::shell_escapecxx . . $ ot/shell_escape(6ccff4770ff7ddc3).("a!b"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).), "'a'\\!'b'", "string with a bang"); |
| 67 | iscxx . . $ tap/is(e56f9d162936dca9).(otcxx . . $ ot/::shell_escapecxx . . $ ot/shell_escape(6ccff4770ff7ddc3).("a!b'c!d'e"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).), "'a'\\!'b'\\''c'\\!'d'\\''e'", "string with a bang"); |
| 68 | } |
| 69 | |
| 70 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 71 | { |
| 72 | plancxx . . $ tap/plan(d4f767463ce0a6b3).(4); |
| 73 | runcxx . . $ tap/run(7ee90fd1703d5d92).(check_partial_filescxx . . $ check_partial_files(49f6e7a06ebc5aa8)., "test partial files"); |
| 74 | runcxx . . $ tap/run(7ee90fd1703d5d92).(check_slurpcxx . . $ check_slurp(49f6e7a06ebc5aa8)., "file slurping"); |
| 75 | runcxx . . $ tap/run(7ee90fd1703d5d92).(check_convertercxx . . $ check_converter(49f6e7a06ebc5aa8)., "test encoding converter"); |
| 76 | runcxx . . $ tap/run(7ee90fd1703d5d92).(check_shell_esapecxx . . $ check_shell_esape(49f6e7a06ebc5aa8)., "test shell escaping"); |
| 77 | return 0; |
| 78 | } |