Added unit testing

This commit is contained in:
Matt Hill
2014-10-23 17:21:25 -04:00
parent f18a3b5c54
commit cb5812bcbd
4 changed files with 9100 additions and 2 deletions

View File

@@ -82,8 +82,7 @@ IF (NOT WIN32)
add_subdirectory(misc_utilities) add_subdirectory(misc_utilities)
ENDIF() ENDIF()
add_subdirectory(tests)
add_subdirectory(openalpr) add_subdirectory(openalpr)
add_subdirectory(video) add_subdirectory(video)

11
src/tests/CMakeLists.txt Normal file
View File

@@ -0,0 +1,11 @@
enable_testing()
ADD_EXECUTABLE( unittests runtests.cpp )
TARGET_LINK_LIBRARIES(unittests
openalpr
)
add_test(unittests unittests)

8997
src/tests/catch.hpp Normal file

File diff suppressed because it is too large Load Diff

91
src/tests/runtests.cpp Normal file
View File

@@ -0,0 +1,91 @@
/*
* File: runtests.cpp
* Author: mhill
*
* Created on October 22, 2014, 11:11 PM
*/
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <cstdlib>
#include "catch.hpp"
#include "alpr.h"
#include "support/timing.h"
using namespace std;
TEST_CASE( "JSON Serialization/Deserialization", "[json]" ) {
Alpr alpr("us");
AlprResults origResults;
origResults.epoch_time = getEpochTime();
origResults.img_width = 640;
origResults.img_height = 480;
origResults.total_processing_time_ms = 100;
origResults.regionsOfInterest.push_back(AlprRegionOfInterest(0,0,100,200));
origResults.regionsOfInterest.push_back(AlprRegionOfInterest(259,260,50,150));
AlprPlateResult apr;
for (int i = 0; i < 3; i++)
{
AlprPlate ap;
ap.characters = "abc";
ap.matches_template = i%2;
ap.overall_confidence = i * 10;
apr.topNPlates.push_back(ap);
}
apr.bestPlate = apr.topNPlates[0];
for (int i = 0; i < 4; i++)
{
AlprCoordinate ac;
ac.x = i;
ac.y = i;
apr.plate_points[i] = ac;
}
apr.processing_time_ms = 30;
apr.requested_topn = 10;
apr.region = "mo";
apr.regionConfidence = 80;
origResults.plates.push_back(apr);
std::string resultsJson = alpr.toJson(origResults);
AlprResults roundTrip = alpr.fromJson(resultsJson);
REQUIRE( roundTrip.epoch_time == origResults.epoch_time );
REQUIRE( roundTrip.img_width == origResults.img_width );
REQUIRE( roundTrip.img_height == origResults.img_height );
REQUIRE( roundTrip.total_processing_time_ms == origResults.total_processing_time_ms );
REQUIRE( roundTrip.regionsOfInterest.size() == origResults.regionsOfInterest.size() );
for (int i = 0; i < roundTrip.regionsOfInterest.size(); i++)
{
REQUIRE( roundTrip.regionsOfInterest[i].x == origResults.regionsOfInterest[i].x);
REQUIRE( roundTrip.regionsOfInterest[i].y == origResults.regionsOfInterest[i].y);
REQUIRE( roundTrip.regionsOfInterest[i].width == origResults.regionsOfInterest[i].width);
REQUIRE( roundTrip.regionsOfInterest[i].height == origResults.regionsOfInterest[i].height);
}
REQUIRE( roundTrip.plates.size() == origResults.plates.size() );
for (int i = 0; i < roundTrip.plates.size(); i++)
{
REQUIRE( roundTrip.plates[i].processing_time_ms == origResults.plates[i].processing_time_ms);
REQUIRE( roundTrip.plates[i].region == origResults.plates[i].region);
REQUIRE( roundTrip.plates[i].regionConfidence == origResults.plates[i].regionConfidence);
REQUIRE( roundTrip.plates[i].requested_topn == origResults.plates[i].requested_topn);
REQUIRE( roundTrip.plates[i].topNPlates.size() == origResults.plates[i].topNPlates.size());
for (int j = 0; j < roundTrip.plates[i].topNPlates.size(); j++)
{
REQUIRE( roundTrip.plates[i].topNPlates[j].characters == origResults.plates[i].topNPlates[j].characters);
REQUIRE( roundTrip.plates[i].topNPlates[j].matches_template == origResults.plates[i].topNPlates[j].matches_template);
REQUIRE( roundTrip.plates[i].topNPlates[j].overall_confidence == origResults.plates[i].topNPlates[j].overall_confidence);
}
}
}