From e4b4230bcfbd46b716c6aa744abb00793b1b4d55 Mon Sep 17 00:00:00 2001 From: John Beard Date: Thu, 24 Jan 2019 12:12:25 +0000 Subject: [PATCH] QA: Put UTILITY_PROGRAM in KI_TEST Also expand some documentation of some other KI_TEST functions. --- qa/common_tools/main.cpp | 4 +-- .../tools/coroutines/coroutine_tools.h | 2 +- .../tools/coroutines/coroutines.cpp | 6 ++-- .../tools/io_benchmark/io_benchmark.cpp | 6 ++-- .../tools/io_benchmark/io_benchmark.h | 2 +- qa/pcbnew_tools/pcbnew_tools.cpp | 4 +-- qa/pcbnew_tools/tools/drc_tool/drc_tool.cpp | 8 ++--- qa/pcbnew_tools/tools/drc_tool/drc_tool.h | 2 +- .../tools/pcb_parser/pcb_parser_tool.cpp | 8 ++--- .../tools/pcb_parser/pcb_parser_tool.h | 2 +- .../polygon_generator/polygon_generator.cpp | 2 +- .../polygon_generator/polygon_generator.h | 2 +- qa/qa_utils/utility_program.cpp | 14 +++----- qa/qa_utils/utility_program.h | 5 +++ .../include/unit_test_utils/unit_test_utils.h | 32 ++++++++++++++++--- 15 files changed, 61 insertions(+), 38 deletions(-) diff --git a/qa/common_tools/main.cpp b/qa/common_tools/main.cpp index c6a6a0d96c..f42f83d409 100644 --- a/qa/common_tools/main.cpp +++ b/qa/common_tools/main.cpp @@ -32,7 +32,7 @@ * This is a pretty rudimentary way to register, but for a simple purpose, * it's effective enough. When you have a new tool, add it to this list. */ -const static std::vector known_tools = { +const static std::vector known_tools = { &coroutine_tool, &io_benchmark_tool, }; @@ -40,7 +40,7 @@ const static std::vector known_tools = { int main( int argc, char** argv ) { - COMBINED_UTILITY c_util( known_tools ); + KI_TEST::COMBINED_UTILITY c_util( known_tools ); return c_util.HandleCommandLine( argc, argv ); } \ No newline at end of file diff --git a/qa/common_tools/tools/coroutines/coroutine_tools.h b/qa/common_tools/tools/coroutines/coroutine_tools.h index 414d0acbf7..89f54501e0 100644 --- a/qa/common_tools/tools/coroutines/coroutine_tools.h +++ b/qa/common_tools/tools/coroutines/coroutine_tools.h @@ -5,6 +5,6 @@ #include /// A tool to test a simple coroutine -extern UTILITY_PROGRAM coroutine_tool; +extern KI_TEST::UTILITY_PROGRAM coroutine_tool; #endif \ No newline at end of file diff --git a/qa/common_tools/tools/coroutines/coroutines.cpp b/qa/common_tools/tools/coroutines/coroutines.cpp index 0bea0ce8d6..e9b63eac97 100644 --- a/qa/common_tools/tools/coroutines/coroutines.cpp +++ b/qa/common_tools/tools/coroutines/coroutines.cpp @@ -114,7 +114,7 @@ static int coroutine_main_func( int argc, char** argv ) if( cmd_parsed_ok != 0 ) { // Help and invalid input both stop here - return ( cmd_parsed_ok == -1 ) ? RET_CODES::OK : RET_CODES::BAD_CMDLINE; + return ( cmd_parsed_ok == -1 ) ? KI_TEST::RET_CODES::OK : KI_TEST::RET_CODES::BAD_CMDLINE; } long count = 5; @@ -124,14 +124,14 @@ static int coroutine_main_func( int argc, char** argv ) obj.Run(); - return RET_CODES::OK; + return KI_TEST::RET_CODES::OK; } /* * Define the tool interface */ -UTILITY_PROGRAM coroutine_tool = { +KI_TEST::UTILITY_PROGRAM coroutine_tool = { "coroutine", "Test a simple coroutine", coroutine_main_func, diff --git a/qa/common_tools/tools/io_benchmark/io_benchmark.cpp b/qa/common_tools/tools/io_benchmark/io_benchmark.cpp index ce919c01d1..a1df3f2803 100644 --- a/qa/common_tools/tools/io_benchmark/io_benchmark.cpp +++ b/qa/common_tools/tools/io_benchmark/io_benchmark.cpp @@ -388,7 +388,7 @@ int io_benchmark_func( int argc, char* argv[] ) os << "Usage: " << argv[0] << " [" << getBenchFlags() << "]\n\n"; os << "Benchmarks:\n"; os << getBenchDescriptions(); - return RET_CODES::BAD_CMDLINE; + return KI_TEST::RET_CODES::BAD_CMDLINE; } wxFileName inFile( argv[1] ); @@ -419,11 +419,11 @@ int io_benchmark_func( int argc, char* argv[] ) << std::endl;; } - return RET_CODES::OK; + return KI_TEST::RET_CODES::OK; } -UTILITY_PROGRAM io_benchmark_tool = { +KI_TEST::UTILITY_PROGRAM io_benchmark_tool = { "io_benchmark", "Benchmark various kinds of IO methods", io_benchmark_func, diff --git a/qa/common_tools/tools/io_benchmark/io_benchmark.h b/qa/common_tools/tools/io_benchmark/io_benchmark.h index e3493a80d7..b115ce744a 100644 --- a/qa/common_tools/tools/io_benchmark/io_benchmark.h +++ b/qa/common_tools/tools/io_benchmark/io_benchmark.h @@ -26,6 +26,6 @@ #include -extern UTILITY_PROGRAM io_benchmark_tool; +extern KI_TEST::UTILITY_PROGRAM io_benchmark_tool; #endif // IO_BENCHMARK_H \ No newline at end of file diff --git a/qa/pcbnew_tools/pcbnew_tools.cpp b/qa/pcbnew_tools/pcbnew_tools.cpp index dc19d03553..0753e4f8f8 100644 --- a/qa/pcbnew_tools/pcbnew_tools.cpp +++ b/qa/pcbnew_tools/pcbnew_tools.cpp @@ -33,7 +33,7 @@ * This is a pretty rudimentary way to register, but for a simple purpose, * it's effective enough. When you have a new tool, add it to this list. */ -const static std::vector known_tools = { +const static std::vector known_tools = { &drc_tool, &pcb_parser_tool, &polygon_generator_tool, @@ -42,7 +42,7 @@ const static std::vector known_tools = { int main( int argc, char** argv ) { - COMBINED_UTILITY c_util( known_tools ); + KI_TEST::COMBINED_UTILITY c_util( known_tools ); return c_util.HandleCommandLine( argc, argv ); } \ No newline at end of file diff --git a/qa/pcbnew_tools/tools/drc_tool/drc_tool.cpp b/qa/pcbnew_tools/tools/drc_tool/drc_tool.cpp index 6af5db505d..060da344be 100644 --- a/qa/pcbnew_tools/tools/drc_tool/drc_tool.cpp +++ b/qa/pcbnew_tools/tools/drc_tool/drc_tool.cpp @@ -304,7 +304,7 @@ static const wxCmdLineEntryDesc g_cmdLineDesc[] = { */ enum PARSER_RET_CODES { - PARSE_FAILED = RET_CODES::TOOL_SPECIFIC, + PARSE_FAILED = KI_TEST::RET_CODES::TOOL_SPECIFIC, }; @@ -325,7 +325,7 @@ int drc_main_func( int argc, char** argv ) if( cmd_parsed_ok != 0 ) { // Help and invalid input both stop here - return ( cmd_parsed_ok == -1 ) ? RET_CODES::OK : RET_CODES::BAD_CMDLINE; + return ( cmd_parsed_ok == -1 ) ? KI_TEST::RET_CODES::OK : KI_TEST::RET_CODES::BAD_CMDLINE; } const bool verbose = cl_parser.Found( "verbose" ); @@ -380,14 +380,14 @@ int drc_main_func( int argc, char** argv ) runner.Execute( *board ); } - return RET_CODES::OK; + return KI_TEST::RET_CODES::OK; } /* * Define the tool interface */ -UTILITY_PROGRAM drc_tool = { +KI_TEST::UTILITY_PROGRAM drc_tool = { "drc", "Run selected DRC function on a PCB", drc_main_func, diff --git a/qa/pcbnew_tools/tools/drc_tool/drc_tool.h b/qa/pcbnew_tools/tools/drc_tool/drc_tool.h index aa4804994c..accb2e97ba 100644 --- a/qa/pcbnew_tools/tools/drc_tool/drc_tool.h +++ b/qa/pcbnew_tools/tools/drc_tool/drc_tool.h @@ -27,6 +27,6 @@ #include /// A tool to run DRC tools on KiCad PCBs from the command line -extern UTILITY_PROGRAM drc_tool; +extern KI_TEST::UTILITY_PROGRAM drc_tool; #endif //PCBNEW_TOOLS_DRC_TOOL_H \ No newline at end of file diff --git a/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.cpp b/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.cpp index 3e763a5073..e29447bc80 100644 --- a/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.cpp +++ b/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.cpp @@ -95,7 +95,7 @@ static const wxCmdLineEntryDesc g_cmdLineDesc[] = { enum PARSER_RET_CODES { - PARSE_FAILED = RET_CODES::TOOL_SPECIFIC, + PARSE_FAILED = KI_TEST::RET_CODES::TOOL_SPECIFIC, }; @@ -117,7 +117,7 @@ int pcb_parser_main_func( int argc, char** argv ) if( cmd_parsed_ok != 0 ) { // Help and invalid input both stop here - return ( cmd_parsed_ok == -1 ) ? RET_CODES::OK : RET_CODES::BAD_CMDLINE; + return ( cmd_parsed_ok == -1 ) ? KI_TEST::RET_CODES::OK : KI_TEST::RET_CODES::BAD_CMDLINE; } const bool verbose = cl_parser.Found( "verbose" ); @@ -157,14 +157,14 @@ int pcb_parser_main_func( int argc, char** argv ) if( !ok ) return PARSER_RET_CODES::PARSE_FAILED; - return RET_CODES::OK; + return KI_TEST::RET_CODES::OK; } /* * Define the tool interface */ -UTILITY_PROGRAM pcb_parser_tool = { +KI_TEST::UTILITY_PROGRAM pcb_parser_tool = { "pcb_parser", "Parse a KiCad PCB file", pcb_parser_main_func, diff --git a/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.h b/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.h index ddab182d7e..cfbe4fb574 100644 --- a/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.h +++ b/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.h @@ -27,6 +27,6 @@ #include /// A tool to parse kicad PCBs from the command line -extern UTILITY_PROGRAM pcb_parser_tool; +extern KI_TEST::UTILITY_PROGRAM pcb_parser_tool; #endif //PCBNEW_TOOLS_PCB_PARSER_UTILITY_H \ No newline at end of file diff --git a/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.cpp b/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.cpp index 09af991443..593314392b 100644 --- a/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.cpp +++ b/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.cpp @@ -118,7 +118,7 @@ int polygon_gererator_main( int argc, char* argv[] ) /* * Define the tool interface */ -UTILITY_PROGRAM polygon_generator_tool = { +KI_TEST::UTILITY_PROGRAM polygon_generator_tool = { "polygon_generator", "Dump board geometry as a set of polygons", polygon_gererator_main, diff --git a/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.h b/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.h index a1faee2988..bab141224d 100644 --- a/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.h +++ b/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.h @@ -27,6 +27,6 @@ #include /// A tool to parse kicad PCBs from the command line -extern UTILITY_PROGRAM polygon_generator_tool; +extern KI_TEST::UTILITY_PROGRAM polygon_generator_tool; #endif //PCBNEW_TOOLS_POLYGON_GENERATOR_UTILITY_H \ No newline at end of file diff --git a/qa/qa_utils/utility_program.cpp b/qa/qa_utils/utility_program.cpp index 0da346e4d2..39457c44a1 100644 --- a/qa/qa_utils/utility_program.cpp +++ b/qa/qa_utils/utility_program.cpp @@ -24,15 +24,14 @@ #include +namespace KI_TEST +{ COMBINED_UTILITY::COMBINED_UTILITY( const UTIL_LIST& aSubUtils ) : m_subUtils( aSubUtils ) { } -/** - * Print the names and descriptions of the registered tools - */ void COMBINED_UTILITY::showSubUtilityList( std::ostream& os ) const { for( const auto& tool : m_subUtils ) @@ -42,11 +41,6 @@ void COMBINED_UTILITY::showSubUtilityList( std::ostream& os ) const } -/** - * Get the utility program that matches a tool name - * @param aName the name to look for - * @return the tool function - */ UTILITY_PROGRAM::FUNC* COMBINED_UTILITY::findSubUtility( const std::string& aName ) const { for( const auto& tool : m_subUtils ) @@ -112,4 +106,6 @@ int COMBINED_UTILITY::HandleCommandLine( int argc, char** argv ) const // pass on the rest of the commands return ( *func )( argc - 1, argv + 1 ); -} \ No newline at end of file +} + +} // namespace KI_TEST \ No newline at end of file diff --git a/qa/qa_utils/utility_program.h b/qa/qa_utils/utility_program.h index b862bbe625..dec1417683 100644 --- a/qa/qa_utils/utility_program.h +++ b/qa/qa_utils/utility_program.h @@ -29,6 +29,9 @@ #include #include +namespace KI_TEST +{ + /** * Return codes for tools */ @@ -127,4 +130,6 @@ private: const UTIL_LIST& m_subUtils; }; +} // namespace KI_TEST + #endif // UTILITY_PROGRAM_H \ No newline at end of file diff --git a/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h b/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h index e6523ea96c..e11f33bf5f 100644 --- a/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h +++ b/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h @@ -80,6 +80,29 @@ namespace KI_TEST { + +template using EXP_OBJ = typename EXP_CONT::value_type; +template using FOUND_OBJ = typename FOUND_CONT::value_type; + +/** + * A match predicate: check that a "found" object is equivalent to or represents + * an "expected" object, perhaps of a different type. + * + * Exactly what "equivalent to" means depends heavily on the context and what + * is care about. For example, if you only care about a #MODULE's refdes, + * std::string is sufficient to indicate a "match". + * + * This can be used, for example, for checking a set of results without having + * to instantiate a full result object for checking by equality. + * + * @tparam EXP_OBJ the "expected" object type + * @tparam FOUND_OBJ the "found" object type + * + * @return true if the "found" object represents the "expected" object + */ +template +using MATCH_PRED = std::function; + /** * Check that a container of "found" objects matches a container of "expected" * objects. This means that: @@ -91,7 +114,7 @@ namespace KI_TEST * and a function to check if a given "found" object corresponds to a given * "expected object". Conditions: * - * * The expected object type needs operator<< + * * The expected object type needs `operator<<` (for logging) * * The expected object container does not contain multiple references to the * same object. * * Identical values are also can't be present as the predicate can't tell which @@ -105,16 +128,15 @@ namespace KI_TEST * lists and checking element-by-element matches. However, it can tell you * exactly which objects are problematic, as well as a simple go/no-go. * + * When you have two containers of identical types (or you have a suitable + * `operator==`) and ordering is important, you can use `BOOST_CHECK_EQUAL_COLLECTIONS` + * *@param aExpected a container of "expected" items, usually from a test case *@param aMatched a container of "found" items, usually the result of some * routine under test *@param aMatchPredicate a predicate that determines if a given "found" object * matches a given "expected" object. */ -template using EXP_OBJ = typename EXP_CONT::value_type; -template using FOUND_OBJ = typename FOUND_CONT::value_type; -template -using MATCH_PRED = std::function; template void CheckUnorderedMatches( const EXP_CONT& aExpected, const FOUND_CONT& aFound, MATCH_PRED aMatchPredicate )