Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / kwsys / testEncode.c
blob5ea180d512fc3806663a742117b79d2887bf81fb
1 /*=========================================================================
3 Program: KWSys - Kitware System Library
4 Module: $RCSfile: testEncode.c,v $
6 Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
13 =========================================================================*/
14 #include "kwsysPrivate.h"
15 #include KWSYS_HEADER(MD5.h)
17 /* Work-around CMake dependency scanning limitation. This must
18 duplicate the above list of headers. */
19 #if 0
20 # include "MD5.h.in"
21 #endif
23 #include <stdio.h>
24 #include <string.h>
26 static const unsigned char testMD5input1[] =
27 " Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.\n"
28 " See Copyright.txt or http://www.kitware.com/Copyright.htm for details.\n";
29 static const char testMD5output1[] = "04051e509e81ef0b1612ddf0e52ca89e";
31 static const int testMD5input2len = 28;
32 static const unsigned char testMD5input2[] = "the cow jumped over the moon";
33 static const char testMD5output2[] = "a2ad137b746138fae4e5adca9c85d3ae";
35 static int testMD5_1(kwsysMD5* md5)
37 char md5out[33];
38 kwsysMD5_Initialize(md5);
39 kwsysMD5_Append(md5, testMD5input1, -1);
40 kwsysMD5_FinalizeHex(md5, md5out);
41 md5out[32] = 0;
42 printf("md5sum 1: expected [%s]\n"
43 " got [%s]\n",
44 testMD5output1, md5out);
45 return (strcmp(md5out, testMD5output1) != 0)? 1:0;
48 static int testMD5_2(kwsysMD5* md5)
50 unsigned char digest[16];
51 char md5out[33];
52 kwsysMD5_Initialize(md5);
53 kwsysMD5_Append(md5, testMD5input2, testMD5input2len);
54 kwsysMD5_Finalize(md5, digest);
55 kwsysMD5_DigestToHex(digest, md5out);
56 md5out[32] = 0;
57 printf("md5sum 2: expected [%s]\n"
58 " got [%s]\n",
59 testMD5output2, md5out);
60 return (strcmp(md5out, testMD5output2) != 0)? 1:0;
63 int testEncode(int argc, char* argv[])
65 int result = 0;
66 (void)argc;
67 (void)argv;
69 /* Test MD5 digest. */
71 kwsysMD5* md5 = kwsysMD5_New();
72 result |= testMD5_1(md5);
73 result |= testMD5_2(md5);
74 kwsysMD5_Delete(md5);
77 return result;