From 1e96ef200c2427a27c97b9d0e9deeb23931f9f19 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 27 Jul 2020 22:00:28 +1000 Subject: [PATCH] Add test/data/cbor-rfc-7049-examples.* --- script/extract-cbor-rfc-7049-examples.go | 28 ++- test/c/std/cbor.c | 16 +- test/data/README.md | 3 + test/data/cbor-rfc-7049-examples.cbor | Bin 0 -> 511 bytes .../cbor-rfc-7049-examples.sans-comments.json | 224 ++++++++++++++++++ test/data/cbor-rfc-7049-examples.tokens | Bin 0 -> 4784 bytes .../cbor-rfc-7049-examples.with-comments.json | 224 ++++++++++++++++++ 7 files changed, 490 insertions(+), 5 deletions(-) create mode 100644 test/data/cbor-rfc-7049-examples.cbor create mode 100644 test/data/cbor-rfc-7049-examples.sans-comments.json create mode 100644 test/data/cbor-rfc-7049-examples.tokens create mode 100644 test/data/cbor-rfc-7049-examples.with-comments.json diff --git a/script/extract-cbor-rfc-7049-examples.go b/script/extract-cbor-rfc-7049-examples.go index 3ef9de9c..be10da22 100644 --- a/script/extract-cbor-rfc-7049-examples.go +++ b/script/extract-cbor-rfc-7049-examples.go @@ -17,8 +17,10 @@ package main // extract-cbor-rfc-7049-examples.go extracts the examples (Appendix A) from -// RFC 7049 "Concise Binary Object Representation (CBOR)". Each example is -// written to a separate file under a "cbor-rfc-7049-examples" directory. +// RFC 7049 "Concise Binary Object Representation (CBOR)". If the -concat flag +// is passed, a single CBOR array containing all of the examples are written to +// stdout. Otherwise, each example is written to a separate file under a +// "cbor-rfc-7049-examples" directory. // // Usage: // go run extract-cbor-rfc-7049-examples.go < rfc7049-errata-corrected.txt @@ -31,11 +33,14 @@ package main import ( "bytes" + "flag" "fmt" "io/ioutil" "os" ) +var concat = flag.Bool("concat", false, "output one monolithic CBOR file") + func main() { if err := main1(); err != nil { os.Stderr.WriteString(err.Error() + "\n") @@ -48,7 +53,10 @@ func main1() error { if err != nil { return err } - if err := os.Mkdir("cbor-rfc-7049-examples", 0755); err != nil { + if *concat { + // Start of CBOR indefinite-length array. + os.Stdout.Write([]byte("\x9F")) + } else if err := os.Mkdir("cbor-rfc-7049-examples", 0755); err != nil { return err } for remaining := []byte(nil); len(src) > 0; src = remaining { @@ -78,7 +86,14 @@ func main1() error { contents = append(contents, (unhex(src[0])<<4)|unhex(src[1])) } } - return emit() + if err := emit(); err != nil { + return err + } + if *concat { + // End of CBOR indefinite-length array. + os.Stdout.Write([]byte("\xFF")) + } + return nil } var ( @@ -90,6 +105,11 @@ func emit() error { if len(contents) == 0 { return nil } + if *concat { + os.Stdout.Write(contents) + contents = nil + return nil + } filename := fmt.Sprintf("cbor-rfc-7049-examples/%02d.cbor", fileNumber) fileNumber++ err := ioutil.WriteFile(filename, contents, 0644) diff --git a/test/c/std/cbor.c b/test/c/std/cbor.c index e903a637..18a73eac 100644 --- a/test/c/std/cbor.c +++ b/test/c/std/cbor.c @@ -67,13 +67,27 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the // No mimic library. #endif +// ---------------- Golden Tests + +golden_test g_cbor_cbor_rfc_7049_examples_gt = { + .want_filename = "test/data/cbor-rfc-7049-examples.tokens", + .src_filename = "test/data/cbor-rfc-7049-examples.cbor", +}; + // ---------------- CBOR Tests const char* // test_wuffs_cbor_decode_interface() { CHECK_FOCUS(__func__); - // TODO. + wuffs_cbor__decoder dec; + CHECK_STATUS("initialize", + wuffs_cbor__decoder__initialize( + &dec, sizeof dec, WUFFS_VERSION, + WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED)); + CHECK_STRING(do_test__wuffs_base__token_decoder( + wuffs_cbor__decoder__upcast_as__wuffs_base__token_decoder(&dec), + &g_cbor_cbor_rfc_7049_examples_gt)); return NULL; } diff --git a/test/data/README.md b/test/data/README.md index 94dc0705..ba678007 100644 --- a/test/data/README.md +++ b/test/data/README.md @@ -33,6 +33,9 @@ world examples of various file formats, or deriviations of them. `bricks-*` are various encodings of an original photo by Nigel Tao . +`cbor-rfc-7049-examples.cbor` is the concatenated examples from RFC 7049. The +`cbor-rfc-7049-examples.*.json` files were then generated by `example/jsonptr`. + `crude-flag.*` is an original animation by Nigel Tao . See the `lib/nie` documentation. diff --git a/test/data/cbor-rfc-7049-examples.cbor b/test/data/cbor-rfc-7049-examples.cbor new file mode 100644 index 0000000000000000000000000000000000000000..51a2fc9a4927340f68e1a942e4388b1f3edf246c GIT binary patch literal 511 zcmbQwz{n*oAt50tks`_bLW+Uk$w8Wdf#JoKr2-7n|DoWJCnEzCSVM*WA4Z5NXj&v& zGC%*x!0@wy;inD5Z~KokL15NTJBFXt|9`n34q*6IU;qFA?>h4*HXRJ5bAB=~{$yeJ zd4%Ej0f96y_*uj7vyS2CABJD`4Gavw>JKn5{QBR(!0@~N1H|Uv^*^AD|4@-HU%!3- z@I&Iq{{tmP28PDE2FAKZh9O1n@B;%q%w~ zTvI$mClx38Z6j77UZPrCFkclfR!aACW4hEDa9lm-jn=n!Y4oCdo54Inq@_$oe;(m||{_jtA PE6w|w?3i1k`2RluYFD@a literal 0 HcmV?d00001 diff --git a/test/data/cbor-rfc-7049-examples.sans-comments.json b/test/data/cbor-rfc-7049-examples.sans-comments.json new file mode 100644 index 00000000..419f2cb2 --- /dev/null +++ b/test/data/cbor-rfc-7049-examples.sans-comments.json @@ -0,0 +1,224 @@ +[ + 0, + 1, + 10, + 23, + 24, + 25, + 100, + 1000, + 1000000, + 1000000000000, + 18446744073709551615, + "AQAAAAAAAAAA", + -18446744073709551616, + "AQAAAAAAAAAA", + -1, + -10, + -100, + -1000, + 0, + -0, + 1, + 1.1, + 1.5, + 65504, + 100000, + 3.4028234663852886e+38, + 1e+300, + 5.960464477539063e-08, + 6.103515625e-05, + -4, + -4.1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + false, + true, + null, + null, + null, + null, + null, + "2013-03-21T20:04:00Z", + 1363896240, + 1.3638962405e+09, + "AQIDBA", + "ZElFVEY", + "http://www.example.com", + "", + "AQIDBA", + "", + "a", + "IETF", + "\"\\", + "ü", + "水", + "𐅑", + [], + [ + 1, + 2, + 3 + ], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25 + ], + {}, + { + "1": 2, + "3": 4 + }, + { + "a": 1, + "b": [ + 2, + 3 + ] + }, + [ + "a", + { + "b": "c" + } + ], + { + "a": "A", + "b": "B", + "c": "C", + "d": "D", + "e": "E" + }, + "AQIDBAU", + "streaming", + [], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25 + ], + { + "a": 1, + "b": [ + 2, + 3 + ] + }, + [ + "a", + { + "b": "c" + } + ], + { + "Fun": true, + "Amt": -2 + } +] diff --git a/test/data/cbor-rfc-7049-examples.tokens b/test/data/cbor-rfc-7049-examples.tokens new file mode 100644 index 0000000000000000000000000000000000000000..0a3d3797877c29cae5be8c0e2d74c8a5b802b518 GIT binary patch literal 4784 zcmZPo0Y(tPz`)3$AjklspnP_SFcSlU4`MMR@wpfn7+8?_;tUK7tPD&LjqD5z5)2Fs z>_~h`1_lOBBz_750|Pe$GfX}63kC)TKCm0W8o}ax46GnWF)%RjJ2@~gFbJc`3o~$n zVWpDtyM2&$FEW!Zws5(eJ$RH-L zG=l+{&%-7Q@;n0rgC$rsL_f&oR%rUI!Ri?p7@+!H!0H(o7}(^&?r}xpe`8=^aD!L_ zmY>7Gz~BK34>tKfpz!mC@mU!JK~C^P;|HSgLtyqp)yJaAC!q0@LE#JXFI0U78b24! zyfQTXm1z7LG=4pr{th(xZZv)$8h;|1d#0iBXQS~KpxL()jlT(vzZ(`GETFW^z_162 z&%waJuosCBO4<96_@MaM59Wi?LjwaS0UiLyCxj1*ze7lTPdKT@&%(1l6sI=g;CwZD2}8aq+bF_J%}%fkY@t%rO@Q1k<0_h%cIFFfZY#v4_Lnv zn!GZaJg7VYIUH1efXq{arC%lnuzpQ6{aR@D>%rX1$e^Iez`&>v2^~Uafq@ZTezSw>G6qIB zB=uYj42fLdCN@b)>> ze0cjDsvpumN3=fN(6uORJvh<%{&1hwx$ z#xp>}>ll)HPm6^GJM9`{M!XVhRH+Azb7z0wElkz<3rQuGbBDJ{-4A6j11uV{{?~%u5Vu=@j>|))IS5KI3@;g z`3mZvfzuDv{x=BqVE?^EbMHHtJXHOAH2Du`@*iP*Mh38ZK7lQRVKlC{{vIcCjb8*0|Vn<7$54Me+a&S5&%ZW-su1U literal 0 HcmV?d00001 diff --git a/test/data/cbor-rfc-7049-examples.with-comments.json b/test/data/cbor-rfc-7049-examples.with-comments.json new file mode 100644 index 00000000..b35a4734 --- /dev/null +++ b/test/data/cbor-rfc-7049-examples.with-comments.json @@ -0,0 +1,224 @@ +[ + 0, + 1, + 10, + 23, + 24, + 25, + 100, + 1000, + 1000000, + 1000000000000, + 18446744073709551615, + /*cbor:tag2*//*cbor:base64url*/"AQAAAAAAAAAA", + -18446744073709551616, + /*cbor:tag3*//*cbor:base64url*/"AQAAAAAAAAAA", + -1, + -10, + -100, + -1000, + 0, + -0, + 1, + 1.1, + 1.5, + 65504, + 100000, + 3.4028234663852886e+38, + 1e+300, + 5.960464477539063e-08, + 6.103515625e-05, + -4, + -4.1, + /*cbor:Inf*/null, + /*cbor:NaN*/null, + /*cbor:-Inf*/null, + /*cbor:Inf*/null, + /*cbor:NaN*/null, + /*cbor:-Inf*/null, + /*cbor:Inf*/null, + /*cbor:NaN*/null, + /*cbor:-Inf*/null, + false, + true, + null, + /*cbor:undefined*/null, + /*cbor:simple16*/null, + /*cbor:simple24*/null, + /*cbor:simple255*/null, + /*cbor:tag0*/"2013-03-21T20:04:00Z", + /*cbor:tag1*/1363896240, + /*cbor:tag1*/1.3638962405e+09, + /*cbor:tag23*//*cbor:base64url*/"AQIDBA", + /*cbor:tag24*//*cbor:base64url*/"ZElFVEY", + /*cbor:tag32*/"http://www.example.com", + /*cbor:base64url*/"", + /*cbor:base64url*/"AQIDBA", + "", + "a", + "IETF", + "\"\\", + "ü", + "水", + "𐅑", + [], + [ + 1, + 2, + 3 + ], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25 + ], + {}, + { + "1": 2, + "3": 4 + }, + { + "a": 1, + "b": [ + 2, + 3 + ] + }, + [ + "a", + { + "b": "c" + } + ], + { + "a": "A", + "b": "B", + "c": "C", + "d": "D", + "e": "E" + }, + /*cbor:base64url*/"AQIDBAU", + "streaming", + [], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ], + [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25 + ], + { + "a": 1, + "b": [ + 2, + 3 + ] + }, + [ + "a", + { + "b": "c" + } + ], + { + "Fun": true, + "Amt": -2 + } +]