1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // This test contains common things needed by both escaping_test.cc and
16 // escaping_benchmark.cc.
17 
18 #ifndef ABSL_STRINGS_INTERNAL_ESCAPING_TEST_COMMON_H_
19 #define ABSL_STRINGS_INTERNAL_ESCAPING_TEST_COMMON_H_
20 
21 #include <array>
22 #include "absl/strings/string_view.h"
23 
24 namespace absl {
25 ABSL_NAMESPACE_BEGIN
26 namespace strings_internal {
27 
28 struct base64_testcase {
29   absl::string_view plaintext;
30   absl::string_view cyphertext;
31 };
32 
base64_strings()33 inline const std::array<base64_testcase, 5>& base64_strings() {
34   static const std::array<base64_testcase, 5> testcase{{
35       // Some google quotes
36       // Cyphertext created with "uuencode (GNU sharutils) 4.6.3"
37       // (Note that we're testing the websafe encoding, though, so if
38       // you add messages, be sure to run "tr -- '+/' '-_'" on the output)
39       { "I was always good at math and science, and I never realized "
40         "that was unusual or somehow undesirable. So one of the things "
41         "I care a lot about is helping to remove that stigma, "
42         "to show girls that you can be feminine, you can like the things "
43         "that girls like, but you can also be really good at technology. "
44         "You can be really good at building things."
45         " - Marissa Meyer, Newsweek, 2010-12-22" "\n",
46 
47         "SSB3YXMgYWx3YXlzIGdvb2QgYXQgbWF0aCBhbmQgc2NpZW5jZSwgYW5kIEkg"
48         "bmV2ZXIgcmVhbGl6ZWQgdGhhdCB3YXMgdW51c3VhbCBvciBzb21laG93IHVu"
49         "ZGVzaXJhYmxlLiBTbyBvbmUgb2YgdGhlIHRoaW5ncyBJIGNhcmUgYSBsb3Qg"
50         "YWJvdXQgaXMgaGVscGluZyB0byByZW1vdmUgdGhhdCBzdGlnbWEsIHRvIHNo"
51         "b3cgZ2lybHMgdGhhdCB5b3UgY2FuIGJlIGZlbWluaW5lLCB5b3UgY2FuIGxp"
52         "a2UgdGhlIHRoaW5ncyB0aGF0IGdpcmxzIGxpa2UsIGJ1dCB5b3UgY2FuIGFs"
53         "c28gYmUgcmVhbGx5IGdvb2QgYXQgdGVjaG5vbG9neS4gWW91IGNhbiBiZSBy"
54         "ZWFsbHkgZ29vZCBhdCBidWlsZGluZyB0aGluZ3MuIC0gTWFyaXNzYSBNZXll"
55         "ciwgTmV3c3dlZWssIDIwMTAtMTItMjIK" },
56 
57       { "Typical first year for a new cluster: "
58         "~0.5 overheating "
59         "~1 PDU failure "
60         "~1 rack-move "
61         "~1 network rewiring "
62         "~20 rack failures "
63         "~5 racks go wonky "
64         "~8 network maintenances "
65         "~12 router reloads "
66         "~3 router failures "
67         "~dozens of minor 30-second blips for dns "
68         "~1000 individual machine failures "
69         "~thousands of hard drive failures "
70         "slow disks, bad memory, misconfigured machines, flaky machines, etc."
71         " - Jeff Dean, The Joys of Real Hardware" "\n",
72 
73         "VHlwaWNhbCBmaXJzdCB5ZWFyIGZvciBhIG5ldyBjbHVzdGVyOiB-MC41IG92"
74         "ZXJoZWF0aW5nIH4xIFBEVSBmYWlsdXJlIH4xIHJhY2stbW92ZSB-MSBuZXR3"
75         "b3JrIHJld2lyaW5nIH4yMCByYWNrIGZhaWx1cmVzIH41IHJhY2tzIGdvIHdv"
76         "bmt5IH44IG5ldHdvcmsgbWFpbnRlbmFuY2VzIH4xMiByb3V0ZXIgcmVsb2Fk"
77         "cyB-MyByb3V0ZXIgZmFpbHVyZXMgfmRvemVucyBvZiBtaW5vciAzMC1zZWNv"
78         "bmQgYmxpcHMgZm9yIGRucyB-MTAwMCBpbmRpdmlkdWFsIG1hY2hpbmUgZmFp"
79         "bHVyZXMgfnRob3VzYW5kcyBvZiBoYXJkIGRyaXZlIGZhaWx1cmVzIHNsb3cg"
80         "ZGlza3MsIGJhZCBtZW1vcnksIG1pc2NvbmZpZ3VyZWQgbWFjaGluZXMsIGZs"
81         "YWt5IG1hY2hpbmVzLCBldGMuIC0gSmVmZiBEZWFuLCBUaGUgSm95cyBvZiBS"
82         "ZWFsIEhhcmR3YXJlCg" },
83 
84       { "I'm the head of the webspam team at Google.  "
85         "That means that if you type your name into Google and get porn back, "
86         "it's my fault. Unless you're a porn star, in which case porn is a "
87         "completely reasonable response."
88         " - Matt Cutts, Google Plus" "\n",
89 
90         "SSdtIHRoZSBoZWFkIG9mIHRoZSB3ZWJzcGFtIHRlYW0gYXQgR29vZ2xlLiAg"
91         "VGhhdCBtZWFucyB0aGF0IGlmIHlvdSB0eXBlIHlvdXIgbmFtZSBpbnRvIEdv"
92         "b2dsZSBhbmQgZ2V0IHBvcm4gYmFjaywgaXQncyBteSBmYXVsdC4gVW5sZXNz"
93         "IHlvdSdyZSBhIHBvcm4gc3RhciwgaW4gd2hpY2ggY2FzZSBwb3JuIGlzIGEg"
94         "Y29tcGxldGVseSByZWFzb25hYmxlIHJlc3BvbnNlLiAtIE1hdHQgQ3V0dHMs"
95         "IEdvb2dsZSBQbHVzCg" },
96 
97       { "It will still be a long time before machines approach human "
98         "intelligence. "
99         "But luckily, machines don't actually have to be intelligent; "
100         "they just have to fake it. Access to a wealth of information, "
101         "combined with a rudimentary decision-making capacity, "
102         "can often be almost as useful. Of course, the results are better yet "
103         "when coupled with intelligence. A reference librarian with access to "
104         "a good search engine is a formidable tool."
105         " - Craig Silverstein, Siemens Pictures of the Future, Spring 2004"
106         "\n",
107 
108         "SXQgd2lsbCBzdGlsbCBiZSBhIGxvbmcgdGltZSBiZWZvcmUgbWFjaGluZXMg"
109         "YXBwcm9hY2ggaHVtYW4gaW50ZWxsaWdlbmNlLiBCdXQgbHVja2lseSwgbWFj"
110         "aGluZXMgZG9uJ3QgYWN0dWFsbHkgaGF2ZSB0byBiZSBpbnRlbGxpZ2VudDsg"
111         "dGhleSBqdXN0IGhhdmUgdG8gZmFrZSBpdC4gQWNjZXNzIHRvIGEgd2VhbHRo"
112         "IG9mIGluZm9ybWF0aW9uLCBjb21iaW5lZCB3aXRoIGEgcnVkaW1lbnRhcnkg"
113         "ZGVjaXNpb24tbWFraW5nIGNhcGFjaXR5LCBjYW4gb2Z0ZW4gYmUgYWxtb3N0"
114         "IGFzIHVzZWZ1bC4gT2YgY291cnNlLCB0aGUgcmVzdWx0cyBhcmUgYmV0dGVy"
115         "IHlldCB3aGVuIGNvdXBsZWQgd2l0aCBpbnRlbGxpZ2VuY2UuIEEgcmVmZXJl"
116         "bmNlIGxpYnJhcmlhbiB3aXRoIGFjY2VzcyB0byBhIGdvb2Qgc2VhcmNoIGVu"
117         "Z2luZSBpcyBhIGZvcm1pZGFibGUgdG9vbC4gLSBDcmFpZyBTaWx2ZXJzdGVp"
118         "biwgU2llbWVucyBQaWN0dXJlcyBvZiB0aGUgRnV0dXJlLCBTcHJpbmcgMjAw"
119         "NAo" },
120 
121       // Degenerate edge case
122       { "",
123         "" },
124   }};
125 
126   return testcase;
127 }
128 
129 }  // namespace strings_internal
130 ABSL_NAMESPACE_END
131 }  // namespace absl
132 
133 #endif  // ABSL_STRINGS_INTERNAL_ESCAPING_TEST_COMMON_H_
134