[ci] Fix netbsd job to upgrade existing packages
[xapian.git] / xapian-applications / omega / md5test.cc
blobdbebe426d7cea43d6da2af8bba4a8e41932fae33
1 /** @file
2 * @brief test cases for the MD5 code
3 */
4 /* Copyright (C) 2006,2023 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
23 #include <cstdlib>
24 #include <iostream>
25 #include <string>
27 #include "md5wrap.h"
29 using namespace std;
31 struct testcase {
32 const char * string;
33 const char * hash;
36 static testcase md5_testcases[] = {
37 { "", "d41d8cd98f00b204e9800998ecf8427e" },
38 { "test", "098f6bcd4621d373cade4e832627b4f6" },
39 { "\x80\x81\x82", "b385760a988b494d3f9df43456928176" },
40 { NULL, NULL }
43 int main() {
44 string md5;
45 for (testcase * t = md5_testcases; t->string; ++t) {
46 string hexhash;
47 md5_string(t->string, md5);
48 for (size_t i = 0; i < md5.size(); ++i) {
49 unsigned char b = static_cast<unsigned char>(md5[i]);
50 hexhash += "0123456789abcdef"[b >> 4];
51 hexhash += "0123456789abcdef"[b & 0x0f];
53 if (hexhash != t->hash) {
54 cerr << "md5 of \"" << t->string << "\" should be \"" << t->hash << "\" not \"" << hexhash << "\"" << endl;
55 exit(1);