1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00
esp8266/tests/host/core/test_md5builder.cpp
Earle F. Philhower, III 03ea61a32a Add valgrind and string tests to host_tests (#4939)
* Add valgrind and string tests to host_tests

Valgrind identified an error that was causing intermittent failures in
the host tests, and can check for subtle memory access and allocation bugs.
Add it to the standard host_test suite, and any errors will cause test
failure.

Also start adding string tests, since two undefined behaviors have been
found so far just by inspection.

* Add additional String tests

Looks like a possible bug in the concatenation operator, need to verify
expected behavior.

* Remove verbose from valgrind run

No need to be so chatty on the test.  Errors were a little hard to spot.
Go to normal verbosity.

* Add lcov and more string tests

LCOV and genhtml can generate nice HTML coverage charts hilighting test
coverage issues in a much simpler way than gcov text format.  Generate these
automatically from gcov output.

Add additional string creation and comparison tests.

* Move String coverage to >50%

Additional string tests and checks

* 66% test coverage in String

* Add allocation-unit-sized strings test

Ensure that strings that are right on the edge of the allocation
size are handled properly and account for trailing 0.
2018-07-27 13:10:55 -04:00

84 lines
2.8 KiB
C++

/*
test_md5builder.cpp - MD5Builder tests
Copyright © 2016 Ivan Grokhotkov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
*/
#include <catch.hpp>
#include <string.h>
#include <MD5Builder.h>
#include <StreamString.h>
TEST_CASE("MD5Builder::add works as expected", "[core][MD5Builder]")
{
MD5Builder builder;
builder.begin();
builder.add("short");
builder.calculate();
REQUIRE(builder.toString() == "4f09daa9d95bcb166a302407a0e0babe");
builder.begin();
builder.add("longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong");
builder.calculate();
REQUIRE(builder.toString() == "9edb67f2b22c604fab13e2fd1d6056d7");
}
TEST_CASE("MD5Builder::addHexString works as expected", "[core][MD5Builder]")
{
WHEN("A char array is parsed"){
MD5Builder builder;
builder.begin();
const char * myPayload = "1234567890abcdeffedcba98765432106469676974616c7369676e61747572656170706c69636174696F6e73";
builder.addHexString(myPayload);
builder.calculate();
REQUIRE(builder.toString() == "47b937a6f9f12a4c389fa5854e023efb");
}
WHEN("A Arduino String is parsed"){
MD5Builder builder;
builder.begin();
builder.addHexString(String("1234567890abcdeffedcba98765432106469676974616c7369676e61747572656170706c69636174696f6e73"));
builder.calculate();
REQUIRE(builder.toString() == "47b937a6f9f12a4c389fa5854e023efb");
}
}
TEST_CASE("MD5Builder::addStream works", "[core][MD5Builder]"){
MD5Builder builder;
const char* str = "MD5Builder::addStream_works_longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong";
{
StreamString stream;
stream.print(str);
builder.begin();
builder.addStream(stream, stream.available());
builder.calculate();
REQUIRE(builder.toString() == "bc4a2006e9d7787ee15fe3d4ef9cdb46");
}
{
StreamString stream;
stream.print(str);
builder.begin();
builder.addStream(stream, 20);
builder.calculate();
REQUIRE(builder.toString() == "c9ad2a3d64b9a877831a67b3bfd34228");
}
{
StreamString stream;
stream.print(str);
builder.begin();
builder.addStream(stream, 120);
builder.calculate();
REQUIRE(builder.toString() == "bc4a2006e9d7787ee15fe3d4ef9cdb46");
}
}