| 21 | typename base64 |
| 22 | > |
| 23 | void base64_kernel_test ( |
| 24 | ) |
| 25 | /*! |
| 26 | requires |
| 27 | - base64 is an implementation of base64/base64_kernel_abstract.h |
| 28 | ensures |
| 29 | - runs tests on base64 for compliance with the specs |
| 30 | !*/ |
| 31 | { |
| 32 | |
| 33 | const unsigned int seed = static_cast<unsigned int>(time(0)); |
| 34 | try |
| 35 | { |
| 36 | |
| 37 | srand(seed); |
| 38 | |
| 39 | base64 test; |
| 40 | |
| 41 | const string wiki_normal = "\ |
| 42 | Man is distinguished, not only by his reason, but by this singular passion from other \ |
| 43 | animals, which is a lust of the mind, that by a perseverance of delight in the continued \ |
| 44 | and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."; |
| 45 | |
| 46 | const string wiki_encoded = "\ |
| 47 | TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0\n\ |
| 48 | aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1\n\ |
| 49 | c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0\n\ |
| 50 | aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdl\n\ |
| 51 | LCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="; |
| 52 | |
| 53 | |
| 54 | |
| 55 | string str; |
| 56 | |
| 57 | istringstream sin; |
| 58 | ostringstream sout; |
| 59 | |
| 60 | sin.str(wiki_encoded); |
| 61 | test.decode(sin,sout); |
| 62 | DLIB_TEST_MSG(sout.str() == wiki_normal, |
| 63 | "sout.str(): " << sout.str() << |
| 64 | "\nwiki_normal: " << wiki_normal); |
| 65 | |
| 66 | |
| 67 | sout.str(""); |
| 68 | sin.str(wiki_normal); |
| 69 | sin.clear(); |
| 70 | test.encode(sin,sout); |
| 71 | |
| 72 | string a(sout.str()), b(wiki_encoded); |
| 73 | // we want to strip all the whitespace from a and b now |
| 74 | sin.str(a); |
| 75 | a.clear(); |
| 76 | sin >> str; |
| 77 | while (sin) |
| 78 | { |
| 79 | a += str; |
| 80 | sin >> str; |