constinfo for unittest too
[xapian.git] / xapian-applications / omega / md5test.cc
blob52af3e758e993ab62c5cb94f6afa8a55a5053381
1 /* md5test.cc: test cases for the MD5 code
3 * Copyright (C) 2006 Olly Betts
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <config.h>
22 #include <cstdlib>
23 #include <iostream>
24 #include <string>
26 #include <cstdio>
28 #include "md5wrap.h"
30 using namespace std;
32 struct testcase {
33 const char * string;
34 const char * hash;
37 static testcase md5_testcases[] = {
38 { "", "d41d8cd98f00b204e9800998ecf8427e" },
39 { "test", "098f6bcd4621d373cade4e832627b4f6" },
40 { "\x80\x81\x82", "b385760a988b494d3f9df43456928176" },
41 { NULL, NULL }
44 int main() {
45 string md5;
46 for (testcase * t = md5_testcases; t->string; ++t) {
47 string hexhash;
48 md5_string(t->string, md5);
49 for (size_t i = 0; i < md5.size(); ++i) {
50 char buf[16];
51 sprintf(buf, "%02x", static_cast<unsigned char>(md5[i]));
52 hexhash += buf;
54 if (hexhash != t->hash) {
55 cerr << "md5 of \"" << t->string << "\" should be \"" << t->hash << "\" not \"" << hexhash << "\"" << endl;
56 exit(1);