-
Notifications
You must be signed in to change notification settings - Fork 0
/
MD5.cpp
91 lines (66 loc) · 2.01 KB
/
MD5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* MD5.cpp - boost unit test for RBX::MD5
*
* Copyright 2010 ROBLOX, INC. All rights reserved.
*
*/
#include <boost/test/unit_test.hpp>
#include <boost/scoped_ptr.hpp>
#include "util/MD5hasher.h"
static const char *ZERO_LENGTH_HASH = "d41d8cd98f00b204e9800998ecf8427e";
static const char *QBF_HASH = "bfb85e401a205cde01d17164bd3de689";
BOOST_AUTO_TEST_SUITE(MD5Suite)
BOOST_AUTO_TEST_CASE(MD5_CreateThenDestroy)
{
{
boost::scoped_ptr<RBX::MD5Hasher> hasher(RBX::MD5Hasher::create());
const char *result = hasher->c_str();
BOOST_CHECK_EQUAL(result, ZERO_LENGTH_HASH);
}
}
BOOST_AUTO_TEST_CASE(MD5_HashSimpleString)
{
{
boost::scoped_ptr<RBX::MD5Hasher> hasher(RBX::MD5Hasher::create());
hasher->addData("The quick brown fox jumps over the lazy dog. 1234567890");
const char *result = hasher->c_str();
// do it twice, first time should create
BOOST_CHECK_EQUAL(result, QBF_HASH);
result = hasher->c_str();
// second time uses cached value
BOOST_CHECK_EQUAL(result, QBF_HASH);
}
}
BOOST_AUTO_TEST_CASE(MD5_HashMultipleSimpleString)
{
{
boost::scoped_ptr<RBX::MD5Hasher> hasher(RBX::MD5Hasher::create());
hasher->addData("The quick brown fox");
hasher->addData(" jumps over the lazy dog.");
hasher->addData(" 1234567890");
const char *result = hasher->c_str();
// do it twice, first time should create
BOOST_CHECK_EQUAL(result, QBF_HASH);
result = hasher->c_str();
// second time uses cached value
BOOST_CHECK_EQUAL(result, QBF_HASH);
}
}
BOOST_AUTO_TEST_CASE(MD5_IStream)
{
{
boost::scoped_ptr<RBX::MD5Hasher> hasher(RBX::MD5Hasher::create());
std::stringstream ss;
ss << "The quick brown fox";
ss << " jumps over the lazy dog.";
ss << " 1234567890";
hasher->addData(ss);
const char *result = hasher->c_str();
// do it twice, first time should create
BOOST_CHECK_EQUAL(result, QBF_HASH);
result = hasher->c_str();
// second time uses cached value
BOOST_CHECK_EQUAL(result, QBF_HASH);
}
}
BOOST_AUTO_TEST_SUITE_END()