Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matrix-org
Olm
Commits
0e13cd35
Commit
0e13cd35
authored
Feb 24, 2015
by
Mark Haines
Browse files
Move unit test code into a separate header
parent
7c1da489
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/include/unittest.hh
0 → 100644
View file @
0e13cd35
#include <cstring>
#include <iostream>
#include <iomanip>
#include <cstdlib>
std
::
ostream
&
print_hex
(
std
::
ostream
&
os
,
std
::
uint8_t
const
*
data
,
std
::
size_t
length
)
{
for
(
std
::
size_t
i
=
0
;
i
<
length
;
i
++
)
{
os
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
std
::
right
<<
std
::
hex
<<
(
int
)
data
[
i
];
}
return
os
;
}
char
const
*
TEST_CASE
;
template
<
typename
T
>
void
assert_equals
(
const
T
&
expected
,
const
T
&
actual
)
{
if
(
expected
!=
actual
)
{
std
::
cout
<<
"FAILED: "
<<
TEST_CASE
<<
std
::
endl
;
std
::
cout
<<
"Expected: "
<<
expected
<<
std
::
endl
;
std
::
cout
<<
"Actual: "
<<
actual
<<
std
::
endl
;
std
::
exit
(
1
);
}
}
void
assert_equals
(
std
::
uint8_t
*
expected
,
std
::
uint8_t
*
actual
,
std
::
size_t
length
)
{
if
(
std
::
memcmp
(
expected
,
actual
,
length
))
{
std
::
cout
<<
"FAILED: "
<<
TEST_CASE
<<
std
::
endl
;
print_hex
(
std
::
cout
<<
"Expected: "
,
expected
,
length
)
<<
std
::
endl
;
print_hex
(
std
::
cout
<<
"Actual: "
,
actual
,
length
)
<<
std
::
endl
;
std
::
exit
(
1
);
}
}
class
TestCase
{
public:
TestCase
(
const
char
*
name
)
{
TEST_CASE
=
name
;
}
~
TestCase
()
{
std
::
cout
<<
"PASSED: "
<<
TEST_CASE
<<
std
::
endl
;
}
};
tests/test_crypto.cpp
View file @
0e13cd35
#include "axolotl/crypto.hh"
#include <cstring>
#include <iostream>
#include <iomanip>
#include <cstdlib>
std
::
ostream
&
print_hex
(
std
::
ostream
&
os
,
std
::
uint8_t
const
*
data
,
std
::
size_t
length
)
{
for
(
std
::
size_t
i
=
0
;
i
<
length
;
i
++
)
{
os
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
std
::
right
<<
std
::
hex
<<
(
int
)
data
[
i
];
}
return
os
;
}
char
const
*
TEST_CASE
;
void
assert_equals
(
std
::
uint8_t
*
expected
,
std
::
uint8_t
*
actual
,
std
::
size_t
length
)
{
if
(
std
::
memcmp
(
expected
,
actual
,
length
))
{
std
::
cout
<<
"FAILED :"
<<
TEST_CASE
<<
std
::
endl
;
print_hex
(
std
::
cout
<<
"Expected: "
,
expected
,
length
)
<<
std
::
endl
;
print_hex
(
std
::
cout
<<
"Actual: "
,
actual
,
length
)
<<
std
::
endl
;
std
::
exit
(
1
);
}
}
void
pass
()
{
std
::
cout
<<
"PASSED: "
<<
TEST_CASE
<<
std
::
endl
;
}
#include "unittest.hh"
int
main
()
{
{
/* Curve25529 Test Case 1 */
T
EST_CASE
=
"Curve25529 Test Case 1"
;
T
estCase
test_case
(
"Curve25529 Test Case 1"
)
;
std
::
uint8_t
alice_private
[
32
]
=
{
0x77
,
0x07
,
0x6D
,
0x0A
,
0x73
,
0x18
,
0xA5
,
0x7D
,
...
...
@@ -103,14 +64,12 @@ axolotl::curve25519_shared_secret(bob_pair, alice_pair, actual_agreement);
assert_equals
(
expected_agreement
,
actual_agreement
,
32
);
pass
();
}
/* Curve25529 Test Case 1 */
{
/* AES Test Case 1 */
T
EST_CASE
=
"AES Test Case 1"
;
T
estCase
test_case
(
"AES Test Case 1"
)
;
axolotl
::
Aes256Key
key
=
{};
axolotl
::
Aes256Iv
iv
=
{};
...
...
@@ -133,14 +92,12 @@ axolotl::aes_decrypt_cbc(key, iv, expected, sizeof(expected), actual);
assert_equals
(
input
,
actual
,
32
);
pass
();
}
/* AES Test Case 1 */
{
/* SHA 256 Test Case 1 */
T
EST_CASE
=
"SHA 256 Test Case 1"
;
T
estCase
test_case
(
"SHA 256 Test Case 1"
)
;
std
::
uint8_t
input
[
0
]
=
{};
...
...
@@ -157,13 +114,11 @@ axolotl::sha256(input, sizeof(input), actual);
assert_equals
(
expected
,
actual
,
32
);
pass
();
}
/* SHA 256 Test Case 1 */
{
/* HMAC Test Case 1 */
T
EST_CASE
=
"HMAC Test Case 1"
;
T
estCase
test_case
(
"HMAC Test Case 1"
)
;
std
::
uint8_t
input
[
0
]
=
{};
...
...
@@ -180,13 +135,11 @@ axolotl::hmac_sha256(input, sizeof(input), input, sizeof(input), actual);
assert_equals
(
expected
,
actual
,
32
);
pass
();
}
/* HMAC Test Case 1 */
{
/* HDKF Test Case 1 */
T
EST_CASE
=
"HDKF Test Case 1"
;
T
estCase
test_case
(
"HDKF Test Case 1"
)
;
std
::
uint8_t
input
[
22
]
=
{
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
...
...
@@ -241,8 +194,6 @@ axolotl::hkdf_sha256(
assert_equals
(
hkdf_expected_output
,
hkdf_actual_output
,
42
);
pass
();
}
/* HDKF Test Case 1 */
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment